package m4;

import k4.AbstractC2390c;
import k4.AbstractC2400m;
import k4.C2394g;
import k4.C2407u;

/* JADX INFO: renamed from: m4.g1, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C2508g1 extends AbstractC2390c {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final InterfaceC2556x f21031a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final k4.i0 f21032b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final k4.g0 f21033c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final C2394g f21034d;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final l2.c f21036f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final AbstractC2400m[] f21037g;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public InterfaceC2547u f21039i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f21040j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public Q f21041k;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final Object f21038h = new Object();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final C2407u f21035e = C2407u.b();

    public C2508g1(InterfaceC2556x interfaceC2556x, k4.i0 i0Var, k4.g0 g0Var, C2394g c2394g, l2.c cVar, AbstractC2400m[] abstractC2400mArr) {
        this.f21031a = interfaceC2556x;
        this.f21032b = i0Var;
        this.f21033c = g0Var;
        this.f21034d = c2394g;
        this.f21036f = cVar;
        this.f21037g = abstractC2400mArr;
    }

    @Override // k4.AbstractC2390c
    public final void a(k4.g0 g0Var) {
        A4.g.t(!this.f21040j, "apply() or fail() already called");
        k4.g0 g0Var2 = this.f21033c;
        g0Var2.d(g0Var);
        C2407u c2407u = this.f21035e;
        C2407u c2407uA = c2407u.a();
        try {
            InterfaceC2547u interfaceC2547uC = this.f21031a.c(this.f21032b, g0Var2, this.f21034d, this.f21037g);
            c2407u.c(c2407uA);
            c(interfaceC2547uC);
        } catch (Throwable th) {
            c2407u.c(c2407uA);
            throw th;
        }
    }

    @Override // k4.AbstractC2390c
    public final void b(k4.r0 r0Var) {
        A4.g.l(!r0Var.e(), "Cannot fail with OK status");
        A4.g.t(!this.f21040j, "apply() or fail() already called");
        c(new X(AbstractC2504f0.h(r0Var), EnumC2550v.f21201a, this.f21037g));
    }

    public final void c(InterfaceC2547u interfaceC2547u) {
        boolean z6;
        A4.g.t(!this.f21040j, "already finalized");
        this.f21040j = true;
        synchronized (this.f21038h) {
            try {
                if (this.f21039i == null) {
                    this.f21039i = interfaceC2547u;
                    z6 = true;
                } else {
                    z6 = false;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        if (z6) {
            C2518k c2518k = (C2518k) this.f21036f.f20267b;
            if (c2518k.f21070b.decrementAndGet() == 0) {
                C2518k.h(c2518k);
                return;
            }
            return;
        }
        A4.g.t(this.f21041k != null, "delayedStream is null");
        O oS = this.f21041k.s(interfaceC2547u);
        if (oS != null) {
            oS.run();
        }
        C2518k c2518k2 = (C2518k) this.f21036f.f20267b;
        if (c2518k2.f21070b.decrementAndGet() == 0) {
            C2518k.h(c2518k2);
        }
    }
}
