package Z0;

import C3.G;
import C3.W;
import L0.o0;
import L4.h;
import T0.AbstractC0302b;
import T0.C0301a;
import T0.C0303c;
import T0.H;
import T0.j;
import T0.l;
import T0.m;
import T0.n;
import T0.q;
import T0.w;
import d5.AbstractC0844a;
import java.io.EOFException;
import java.io.InterruptedIOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import u0.C1578n;
import u0.E;
import u0.F;
import x0.AbstractC1709a;
import x0.o;

/* JADX INFO: loaded from: classes.dex */
public final class b implements m {

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

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public T0.o f7370f;

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

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

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

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

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public long f7376m;

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public a f7378o;

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

    public b() {
        c cVar = new c(new l());
        cVar.f7380r = -9223372036854775807L;
        cVar.f7381s = new long[0];
        cVar.f7382t = new long[0];
        this.f7369e = cVar;
        this.f7371g = 1;
    }

    public final o b(j jVar) throws EOFException, InterruptedIOException {
        int i = this.f7375l;
        o oVar = this.f7368d;
        byte[] bArr = oVar.f18539a;
        if (i > bArr.length) {
            oVar.D(0, new byte[Math.max(bArr.length * 2, i)]);
        } else {
            oVar.F(0);
        }
        oVar.E(this.f7375l);
        jVar.c(oVar.f18539a, 0, this.f7375l, false);
        return oVar;
    }

    @Override // T0.m
    public final m c() {
        return this;
    }

    /* JADX WARN: Removed duplicated region for block: B:100:0x02ae  */
    /* JADX WARN: Removed duplicated region for block: B:145:0x03ae  */
    /* JADX WARN: Removed duplicated region for block: B:146:0x03b2  */
    /* JADX WARN: Removed duplicated region for block: B:184:0x03bc A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:194:0x0007 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:59:0x0176  */
    /* JADX WARN: Removed duplicated region for block: B:95:0x0299  */
    @Override // T0.m
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int e(n nVar, h hVar) throws F, EOFException, InterruptedIOException {
        long j8;
        long j9;
        int i;
        long j10;
        boolean z8;
        boolean z9;
        AbstractC1709a.k(this.f7370f);
        while (true) {
            int i5 = this.f7371g;
            if (i5 == 1) {
                o oVar = this.f7366b;
                if (!((j) nVar).c(oVar.f18539a, 0, 9, true)) {
                    return -1;
                }
                oVar.F(0);
                oVar.G(4);
                int iT = oVar.t();
                boolean z10 = (iT & 4) != 0;
                boolean z11 = (iT & 1) != 0;
                if (z10 && this.f7378o == null) {
                    this.f7378o = new a(this.f7370f.j(8, 1));
                }
                if (z11 && this.f7379p == null) {
                    this.f7379p = new d(this.f7370f.j(9, 2));
                }
                this.f7370f.h();
                this.f7373j = oVar.g() - 5;
                this.f7371g = 2;
            } else if (i5 == 2) {
                ((j) nVar).b(this.f7373j);
                this.f7373j = 0;
                this.f7371g = 3;
            } else if (i5 == 3) {
                o oVar2 = this.f7367c;
                if (!((j) nVar).c(oVar2.f18539a, 0, 11, true)) {
                    return -1;
                }
                oVar2.F(0);
                this.f7374k = oVar2.t();
                this.f7375l = oVar2.w();
                this.f7376m = oVar2.w();
                this.f7376m = (((long) (oVar2.t() << 24)) | this.f7376m) * 1000;
                oVar2.G(3);
                this.f7371g = 4;
            } else {
                if (i5 != 4) {
                    throw new IllegalStateException();
                }
                boolean z12 = this.f7372h;
                long j11 = -9223372036854775807L;
                c cVar = this.f7369e;
                if (z12) {
                    j8 = this.i + this.f7376m;
                } else if (cVar.f7380r == -9223372036854775807L) {
                    j9 = 0;
                    i = this.f7374k;
                    if (i == 8 || this.f7378o == null) {
                        if (i == 9 || this.f7379p == null) {
                            j10 = -9223372036854775807L;
                            if (i == 18 || this.f7377n) {
                                ((j) nVar).b(this.f7375l);
                                z8 = false;
                                z9 = false;
                            } else {
                                o oVarB = b((j) nVar);
                                cVar.getClass();
                                cVar.getClass();
                                if (oVarB.t() == 2 && "onMetaData".equals(c.H(oVarB)) && oVarB.a() != 0 && oVarB.t() == 8) {
                                    HashMap mapG = c.G(oVarB);
                                    Object obj = mapG.get("duration");
                                    double d8 = 1000000.0d;
                                    if (obj instanceof Double) {
                                        double dDoubleValue = ((Double) obj).doubleValue();
                                        if (dDoubleValue > 0.0d) {
                                            cVar.f7380r = (long) (dDoubleValue * 1000000.0d);
                                        }
                                    }
                                    Object obj2 = mapG.get("keyframes");
                                    if (obj2 instanceof Map) {
                                        Map map = (Map) obj2;
                                        Object obj3 = map.get("filepositions");
                                        Object obj4 = map.get("times");
                                        if ((obj3 instanceof List) && (obj4 instanceof List)) {
                                            List list = (List) obj3;
                                            List list2 = (List) obj4;
                                            int size = list2.size();
                                            cVar.f7381s = new long[size];
                                            cVar.f7382t = new long[size];
                                            int i8 = 0;
                                            while (i8 < size) {
                                                Object obj5 = list.get(i8);
                                                Object obj6 = list2.get(i8);
                                                if (!(obj6 instanceof Double) || !(obj5 instanceof Double)) {
                                                    cVar.f7381s = new long[0];
                                                    cVar.f7382t = new long[0];
                                                    break;
                                                }
                                                double d9 = d8;
                                                cVar.f7381s[i8] = (long) (((Double) obj6).doubleValue() * d9);
                                                cVar.f7382t[i8] = ((Double) obj5).longValue();
                                                i8++;
                                                d8 = d9;
                                            }
                                        }
                                    }
                                }
                                long j12 = cVar.f7380r;
                                if (j12 != -9223372036854775807L) {
                                    this.f7370f.v(new w(j12, cVar.f7382t, cVar.f7381s));
                                    this.f7377n = true;
                                }
                            }
                        } else {
                            if (!this.f7377n) {
                                this.f7370f.v(new q(-9223372036854775807L));
                                this.f7377n = true;
                            }
                            d dVar = this.f7379p;
                            o oVarB2 = b((j) nVar);
                            dVar.getClass();
                            int iT2 = oVarB2.t();
                            int i9 = (iT2 >> 4) & 15;
                            int i10 = iT2 & 15;
                            if (i10 != 7) {
                                throw new o0(AbstractC0844a.j("Video format not supported: ", i10));
                            }
                            dVar.f7388w = i9;
                            if (i9 != 5) {
                                int iT3 = oVarB2.t();
                                byte[] bArr = oVarB2.f18539a;
                                int i11 = oVarB2.f18540b;
                                int i12 = i11 + 1;
                                oVarB2.f18540b = i12;
                                int i13 = ((bArr[i11] & 255) << 24) >> 8;
                                int i14 = i11 + 2;
                                oVarB2.f18540b = i14;
                                int i15 = ((bArr[i12] & 255) << 8) | i13;
                                oVarB2.f18540b = i11 + 3;
                                long j13 = (((long) ((bArr[i14] & 255) | i15)) * 1000) + j9;
                                boolean z13 = true;
                                T0.F f3 = (T0.F) dVar.f5146q;
                                if (iT3 == 0 && !dVar.f7386u) {
                                    byte[] bArr2 = new byte[oVarB2.a()];
                                    o oVar3 = new o(bArr2);
                                    oVarB2.e(bArr2, 0, oVarB2.a());
                                    C0303c c0303cA = C0303c.a(oVar3);
                                    dVar.f7385t = c0303cA.f6391b;
                                    C1578n c1578n = new C1578n();
                                    c1578n.f17319l = E.m("video/x-flv");
                                    c1578n.f17320m = E.m("video/avc");
                                    c1578n.f17317j = c0303cA.f6400l;
                                    c1578n.f17327t = c0303cA.f6392c;
                                    c1578n.f17328u = c0303cA.f6393d;
                                    c1578n.f17331x = c0303cA.f6399k;
                                    c1578n.f17323p = c0303cA.f6390a;
                                    I1.a.w(c1578n, f3);
                                    dVar.f7386u = true;
                                } else if (iT3 == 1 && dVar.f7386u) {
                                    int i16 = dVar.f7388w == 1 ? 1 : 0;
                                    if (dVar.f7387v || i16 != 0) {
                                        o oVar4 = dVar.f7384s;
                                        byte[] bArr3 = oVar4.f18539a;
                                        bArr3[0] = 0;
                                        bArr3[1] = 0;
                                        bArr3[2] = 0;
                                        int i17 = 4 - dVar.f7385t;
                                        int i18 = 0;
                                        while (oVarB2.a() > 0) {
                                            long j14 = j11;
                                            oVarB2.e(oVar4.f18539a, i17, dVar.f7385t);
                                            oVar4.F(0);
                                            int iX = oVar4.x();
                                            o oVar5 = dVar.f7383r;
                                            oVar5.F(0);
                                            f3.c(4, oVar5);
                                            f3.c(iX, oVarB2);
                                            i18 = i18 + 4 + iX;
                                            j11 = j14;
                                        }
                                        j10 = j11;
                                        ((T0.F) dVar.f5146q).a(j13, i16, i18, 0, null);
                                        dVar.f7387v = true;
                                    }
                                    if (!z13) {
                                        z9 = true;
                                    }
                                    z8 = true;
                                }
                                j10 = -9223372036854775807L;
                                z13 = false;
                                if (!z13) {
                                }
                                z8 = true;
                            } else {
                                j10 = -9223372036854775807L;
                            }
                        }
                        z9 = false;
                        z8 = true;
                    } else {
                        if (!this.f7377n) {
                            this.f7370f.v(new q(-9223372036854775807L));
                            this.f7377n = true;
                        }
                        a aVar = this.f7378o;
                        o oVarB3 = b((j) nVar);
                        if (aVar.f7362r) {
                            oVarB3.G(1);
                        } else {
                            int iT4 = oVarB3.t();
                            int i19 = (iT4 >> 4) & 15;
                            aVar.f7364t = i19;
                            T0.F f7 = (T0.F) aVar.f5146q;
                            if (i19 == 2) {
                                int i20 = a.f7361u[(iT4 >> 2) & 3];
                                C1578n c1578n2 = new C1578n();
                                c1578n2.f17319l = E.m("video/x-flv");
                                c1578n2.f17320m = E.m("audio/mpeg");
                                c1578n2.f17301C = 1;
                                c1578n2.D = i20;
                                I1.a.w(c1578n2, f7);
                                aVar.f7363s = true;
                            } else if (i19 == 7 || i19 == 8) {
                                String str = i19 == 7 ? "audio/g711-alaw" : "audio/g711-mlaw";
                                C1578n c1578n3 = new C1578n();
                                c1578n3.f17319l = E.m("video/x-flv");
                                c1578n3.f17320m = E.m(str);
                                c1578n3.f17301C = 1;
                                c1578n3.D = 8000;
                                I1.a.w(c1578n3, f7);
                                aVar.f7363s = true;
                            } else if (i19 != 10) {
                                throw new o0("Audio format not supported: " + aVar.f7364t);
                            }
                            aVar.f7362r = true;
                        }
                        int i21 = aVar.f7364t;
                        T0.F f8 = (T0.F) aVar.f5146q;
                        z9 = true;
                        if (i21 == 2) {
                            int iA = oVarB3.a();
                            f8.c(iA, oVarB3);
                            ((T0.F) aVar.f5146q).a(j9, 1, iA, 0, null);
                        } else {
                            int iT5 = oVarB3.t();
                            if (iT5 == 0 && !aVar.f7363s) {
                                int iA2 = oVarB3.a();
                                byte[] bArr4 = new byte[iA2];
                                oVarB3.e(bArr4, 0, iA2);
                                C0301a c0301aN = AbstractC0302b.n(new H(iA2, bArr4), false);
                                C1578n c1578n4 = new C1578n();
                                c1578n4.f17319l = E.m("video/x-flv");
                                c1578n4.f17320m = E.m("audio/mp4a-latm");
                                c1578n4.f17317j = c0301aN.f6363a;
                                c1578n4.f17301C = c0301aN.f6365c;
                                c1578n4.D = c0301aN.f6364b;
                                c1578n4.f17323p = Collections.singletonList(bArr4);
                                I1.a.w(c1578n4, f8);
                                aVar.f7363s = true;
                            } else if (aVar.f7364t != 10 || iT5 == 1) {
                                int iA3 = oVarB3.a();
                                f8.c(iA3, oVarB3);
                                ((T0.F) aVar.f5146q).a(j9, 1, iA3, 0, null);
                            }
                            z9 = false;
                        }
                        z8 = true;
                        j10 = -9223372036854775807L;
                    }
                    if (!this.f7372h && z9) {
                        this.f7372h = true;
                        this.i = cVar.f7380r != j10 ? -this.f7376m : 0L;
                    }
                    this.f7373j = 4;
                    this.f7371g = 2;
                    if (!z8) {
                        return 0;
                    }
                } else {
                    j8 = this.f7376m;
                }
                j9 = j8;
                i = this.f7374k;
                if (i == 8) {
                    if (i == 9) {
                        j10 = -9223372036854775807L;
                        if (i == 18) {
                        }
                        ((j) nVar).b(this.f7375l);
                        z8 = false;
                        z9 = false;
                        if (!this.f7372h) {
                            this.f7372h = true;
                            this.i = cVar.f7380r != j10 ? -this.f7376m : 0L;
                        }
                        this.f7373j = 4;
                        this.f7371g = 2;
                        if (!z8) {
                        }
                    }
                }
            }
        }
    }

    @Override // T0.m
    public final boolean f(n nVar) throws EOFException, InterruptedIOException {
        o oVar = this.f7365a;
        j jVar = (j) nVar;
        jVar.f(oVar.f18539a, 0, 3, false);
        oVar.F(0);
        if (oVar.w() == 4607062) {
            jVar.f(oVar.f18539a, 0, 2, false);
            oVar.F(0);
            if ((oVar.z() & 250) == 0) {
                jVar.f(oVar.f18539a, 0, 4, false);
                oVar.F(0);
                int iG = oVar.g();
                jVar.f6430v = 0;
                jVar.h(iG, false);
                jVar.f(oVar.f18539a, 0, 4, false);
                oVar.F(0);
                if (oVar.g() == 0) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override // T0.m
    public final void i(long j8, long j9) {
        if (j8 == 0) {
            this.f7371g = 1;
            this.f7372h = false;
        } else {
            this.f7371g = 3;
        }
        this.f7373j = 0;
    }

    @Override // T0.m
    public final void l(T0.o oVar) {
        this.f7370f = oVar;
    }

    @Override // T0.m
    public final List m() {
        C3.E e8 = G.f1197r;
        return W.f1225u;
    }

    @Override // T0.m
    public final void a() {
    }
}
