package n4;

import I2.O;
import androidx.leanback.widget.C1077i;
import java.io.IOException;
import m4.AbstractC2488a;
import p5.C2740j;

/* JADX INFO: loaded from: classes3.dex */
public final class w {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final int f21771b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f21772c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f21773d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final v f21774e;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final /* synthetic */ O f21776g;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final C2740j f21770a = new C2740j();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f21775f = false;

    public w(O o6, int i6, int i7, v vVar) {
        this.f21776g = o6;
        this.f21771b = i6;
        this.f21772c = i7;
        this.f21774e = vVar;
    }

    public final int a(int i6) {
        if (i6 <= 0 || Integer.MAX_VALUE - i6 >= this.f21772c) {
            int i7 = this.f21772c + i6;
            this.f21772c = i7;
            return i7;
        }
        throw new IllegalArgumentException("Window size overflow for stream: " + this.f21771b);
    }

    public final void b(int i6, C2740j c2740j, boolean z6) {
        boolean zE;
        do {
            int iMin = Math.min(i6, ((C2626d) this.f21776g.f2525c).f21641b.f21625a.f23033d);
            int i7 = -iMin;
            ((w) this.f21776g.f2526d).a(i7);
            a(i7);
            try {
                boolean z7 = false;
                ((C2626d) this.f21776g.f2525c).a(c2740j.f23100b == ((long) iMin) && z6, this.f21771b, c2740j, iMin);
                AbstractC2488a abstractC2488a = (AbstractC2488a) this.f21774e;
                synchronized (abstractC2488a.f20926b) {
                    A4.g.t(abstractC2488a.f20930f, "onStreamAllocated was not called, but it seems the stream is active");
                    int i8 = abstractC2488a.f20929e;
                    boolean z8 = i8 < 32768;
                    int i9 = i8 - iMin;
                    abstractC2488a.f20929e = i9;
                    boolean z9 = i9 < 32768;
                    if (!z8 && z9) {
                        z7 = true;
                    }
                }
                if (z7) {
                    synchronized (abstractC2488a.f20926b) {
                        zE = abstractC2488a.e();
                    }
                    if (zE) {
                        abstractC2488a.f20934j.d();
                    }
                }
                i6 -= iMin;
            } catch (IOException e6) {
                throw new RuntimeException(e6);
            }
        } while (i6 > 0);
    }

    public final void c(int i6, C1077i c1077i) {
        int i7 = this.f21772c;
        O o6 = this.f21776g;
        int iMin = Math.min(i6, Math.min(i7, ((w) o6.f2526d).f21772c));
        int i8 = 0;
        while (true) {
            C2740j c2740j = this.f21770a;
            long j4 = c2740j.f23100b;
            if (j4 <= 0 || iMin <= 0) {
                return;
            }
            if (iMin >= j4) {
                int i9 = (int) j4;
                i8 += i9;
                b(i9, c2740j, this.f21775f);
            } else {
                i8 += iMin;
                b(iMin, c2740j, false);
            }
            c1077i.f11981a++;
            iMin = Math.min(i6 - i8, Math.min(this.f21772c, ((w) o6.f2526d).f21772c));
        }
    }
}
