package q1;

import T0.E;
import T0.F;
import java.io.EOFException;
import u0.C1578n;
import u0.C1579o;
import u0.InterfaceC1571g;
import x0.AbstractC1709a;
import x0.o;
import x0.v;

/* JADX INFO: renamed from: q1.n, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1457n implements F {

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public InterfaceC1456m f16230g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public C1579o f16231h;
    public boolean i;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f16228e = 0;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public byte[] f16229f = v.f18555c;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final o f16226c = new o();

    public C1457n(F f3, InterfaceC1454k interfaceC1454k) {
        this.f16224a = f3;
        this.f16225b = interfaceC1454k;
    }

    @Override // T0.F
    public final void a(long j8, int i, int i5, int i8, E e8) {
        if (this.f16230g == null) {
            this.f16224a.a(j8, i, i5, i8, e8);
            return;
        }
        AbstractC1709a.c("DRM on subtitles is not supported", e8 == null);
        int i9 = (this.f16228e - i8) - i5;
        try {
            this.f16230g.a(this.f16229f, i9, i5, C1455l.f16221c, new C0.e(this, j8, i));
        } catch (RuntimeException e9) {
            if (!this.i) {
                throw e9;
            }
            AbstractC1709a.C("SubtitleTranscodingTO", "Parsing subtitles failed, ignoring sample.", e9);
        }
        int i10 = i9 + i5;
        this.f16227d = i10;
        if (i10 == this.f16228e) {
            this.f16227d = 0;
            this.f16228e = 0;
        }
    }

    @Override // T0.F
    public final void b(o oVar, int i, int i5) {
        if (this.f16230g == null) {
            this.f16224a.b(oVar, i, i5);
            return;
        }
        g(i);
        oVar.e(this.f16229f, this.f16228e, i);
        this.f16228e += i;
    }

    @Override // T0.F
    public final void c(int i, o oVar) {
        b(oVar, i, 0);
    }

    @Override // T0.F
    public final int d(InterfaceC1571g interfaceC1571g, int i, boolean z8) throws EOFException {
        if (this.f16230g == null) {
            return this.f16224a.d(interfaceC1571g, i, z8);
        }
        g(i);
        int iP = interfaceC1571g.p(this.f16229f, this.f16228e, i);
        if (iP != -1) {
            this.f16228e += iP;
            return iP;
        }
        if (z8) {
            return -1;
        }
        throw new EOFException();
    }

    @Override // T0.F
    public final void e(C1579o c1579o) {
        c1579o.f17358n.getClass();
        String str = c1579o.f17358n;
        AbstractC1709a.d(u0.E.h(str) == 3);
        boolean zEquals = c1579o.equals(this.f16231h);
        InterfaceC1454k interfaceC1454k = this.f16225b;
        if (!zEquals) {
            this.f16231h = c1579o;
            this.f16230g = interfaceC1454k.l(c1579o) ? interfaceC1454k.g(c1579o) : null;
        }
        InterfaceC1456m interfaceC1456m = this.f16230g;
        F f3 = this.f16224a;
        if (interfaceC1456m == null) {
            f3.e(c1579o);
            return;
        }
        C1578n c1578nA = c1579o.a();
        c1578nA.f17320m = u0.E.m("application/x-media3-cues");
        c1578nA.f17317j = str;
        c1578nA.f17325r = Long.MAX_VALUE;
        c1578nA.f17305I = interfaceC1454k.i(c1579o);
        I1.a.w(c1578nA, f3);
    }

    @Override // T0.F
    public final int f(InterfaceC1571g interfaceC1571g, int i, boolean z8) {
        return d(interfaceC1571g, i, z8);
    }

    public final void g(int i) {
        int length = this.f16229f.length;
        int i5 = this.f16228e;
        if (length - i5 >= i) {
            return;
        }
        int i8 = i5 - this.f16227d;
        int iMax = Math.max(i8 * 2, i + i8);
        byte[] bArr = this.f16229f;
        byte[] bArr2 = iMax <= bArr.length ? bArr : new byte[iMax];
        System.arraycopy(bArr, this.f16227d, bArr2, 0, i8);
        this.f16227d = 0;
        this.f16228e = i8;
        this.f16229f = bArr2;
    }
}
