package A1;

import C3.W;
import com.google.android.gms.internal.measurement.C1;
import n4.u0;
import u0.C1578n;
import u0.C1579o;
import x0.AbstractC1709a;

/* JADX INFO: loaded from: classes.dex */
public final class v implements InterfaceC0008i {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public String f337e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public T0.F f338f;
    public boolean i;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final x0.o f333a = new x0.o(2, new byte[15]);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final T0.H f334b = new T0.H();

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

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final w f347p = new w();

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public int f348q = -2147483647;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public int f349r = -1;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public long f351t = -1;

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public boolean f344m = true;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public double f339g = -9.223372036854776E18d;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public double f340h = -9.223372036854776E18d;

    @Override // A1.InterfaceC0008i
    public final void a() {
        this.f336d = 0;
        this.f343l = 0;
        this.f333a.C(2);
        this.f345n = 0;
        this.f346o = 0;
        this.f348q = -2147483647;
        this.f349r = -1;
        this.f350s = 0;
        this.f351t = -1L;
        this.f352u = false;
        this.i = false;
        this.f344m = true;
        this.f341j = true;
        this.f339g = -9.223372036854776E18d;
        this.f340h = -9.223372036854776E18d;
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Removed duplicated region for block: B:157:0x02bd  */
    /* JADX WARN: Removed duplicated region for block: B:217:0x0420  */
    /* JADX WARN: Removed duplicated region for block: B:237:0x0460  */
    /* JADX WARN: Removed duplicated region for block: B:238:0x046c  */
    /* JADX WARN: Removed duplicated region for block: B:241:0x0488  */
    /* JADX WARN: Removed duplicated region for block: B:282:0x046f A[SYNTHETIC] */
    @Override // A1.InterfaceC0008i
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void e(x0.o oVar) throws u0.F {
        int i;
        int i5;
        int i8;
        int i9;
        int i10;
        int i11;
        byte[] bArr;
        long j8;
        long j9;
        char c3;
        int i12;
        w wVar;
        long j10;
        boolean z8;
        int i13;
        int i14;
        int i15 = 4;
        int i16 = 1;
        AbstractC1709a.k(this.f338f);
        while (oVar.a() > 0) {
            int i17 = this.f336d;
            if (i17 != 0) {
                w wVar2 = this.f347p;
                x0.o oVar2 = this.f335c;
                if (i17 == i16) {
                    int iA = oVar.a();
                    x0.o oVar3 = this.f333a;
                    int iMin = Math.min(iA, oVar3.a());
                    oVar.e(oVar3.f18539a, oVar3.f18540b, iMin);
                    oVar3.G(iMin);
                    if (oVar3.a() == 0) {
                        int i18 = oVar3.f18541c;
                        byte[] bArr2 = oVar3.f18539a;
                        T0.H h8 = this.f334b;
                        h8.o(i18, bArr2);
                        h8.f();
                        int iK = U2.a.K(h8, 3, 8, 8);
                        wVar2.f353a = iK;
                        if (iK == -1) {
                            wVar = wVar2;
                        } else {
                            AbstractC1709a.d(Math.max(Math.max(2, 8), 32) <= 63);
                            wVar = wVar2;
                            C1.f(C1.f(3L, 255L), 4294967296L);
                            if (h8.b() < 2) {
                                j10 = -1;
                                wVar.f354b = j10;
                                if (j10 != -1) {
                                    if (j10 > 16) {
                                        throw u0.F.c("Contains sub-stream with an invalid packet label " + wVar.f354b);
                                    }
                                    if (j10 == 0) {
                                        int i19 = wVar.f353a;
                                        if (i19 == 1) {
                                            throw u0.F.a(null, "Mpegh3daConfig packet with invalid packet label 0");
                                        }
                                        if (i19 == 2) {
                                            throw u0.F.a(null, "Mpegh3daFrame packet with invalid packet label 0");
                                        }
                                        if (i19 == 17) {
                                            throw u0.F.a(null, "AudioTruncation packet with invalid packet label 0");
                                        }
                                    }
                                    int iK2 = U2.a.K(h8, 11, 24, 24);
                                    wVar.f355c = iK2;
                                    z8 = iK2 != -1;
                                    if (z8) {
                                        i13 = 0;
                                    } else {
                                        i13 = 0;
                                        this.f345n = 0;
                                        this.f346o = wVar.f355c + i18 + this.f346o;
                                    }
                                    if (z8) {
                                        i8 = 1;
                                        int i20 = oVar3.f18541c;
                                        if (i20 < 15) {
                                            oVar3.E(i20 + 1);
                                            this.f344m = false;
                                        }
                                    } else {
                                        oVar3.F(i13);
                                        this.f338f.c(oVar3.f18541c, oVar3);
                                        oVar3.C(2);
                                        oVar2.C(wVar.f355c);
                                        i8 = 1;
                                        this.f344m = true;
                                        this.f336d = 2;
                                    }
                                }
                            } else {
                                long jK = h8.k(2);
                                if (jK == 3) {
                                    if (h8.b() >= 8) {
                                        long jK2 = h8.k(8);
                                        jK += jK2;
                                        if (jK2 == 255) {
                                            if (h8.b() >= 32) {
                                                jK = h8.k(32) + jK;
                                            }
                                        }
                                    }
                                    j10 = -1;
                                    wVar.f354b = j10;
                                    if (j10 != -1) {
                                    }
                                }
                                j10 = jK;
                                wVar.f354b = j10;
                                if (j10 != -1) {
                                }
                            }
                        }
                        if (z8) {
                        }
                        if (z8) {
                        }
                    } else {
                        this.f344m = false;
                    }
                    i15 = 4;
                    i16 = 1;
                } else {
                    if (i17 != 2) {
                        throw new IllegalStateException();
                    }
                    int i21 = wVar2.f353a;
                    if (i21 == i16 || i21 == 17) {
                        int i22 = oVar.f18540b;
                        int iMin2 = Math.min(oVar.a(), oVar2.a());
                        oVar.e(oVar2.f18539a, oVar2.f18540b, iMin2);
                        oVar2.G(iMin2);
                        oVar.F(i22);
                    }
                    int iMin3 = Math.min(oVar.a(), wVar2.f355c - this.f345n);
                    this.f338f.c(iMin3, oVar);
                    int i23 = this.f345n + iMin3;
                    this.f345n = i23;
                    if (i23 != wVar2.f355c) {
                        continue;
                    } else {
                        int i24 = wVar2.f353a;
                        if (i24 == i16) {
                            byte[] bArr3 = oVar2.f18539a;
                            T0.H h9 = new T0.H(bArr3.length, bArr3);
                            int i25 = h9.i(8);
                            char c8 = 5;
                            int i26 = h9.i(5);
                            if (i26 != 31) {
                                switch (i26) {
                                    case u0.f15495q /* 0 */:
                                        i9 = 96000;
                                        break;
                                    case 1:
                                        i9 = 88200;
                                        break;
                                    case 2:
                                        i9 = 64000;
                                        break;
                                    case 3:
                                        i9 = 48000;
                                        break;
                                    case 4:
                                        i9 = 44100;
                                        break;
                                    case 5:
                                        i9 = 32000;
                                        break;
                                    case Z.g.STRING_SET_FIELD_NUMBER /* 6 */:
                                        i9 = 24000;
                                        break;
                                    case Z.g.DOUBLE_FIELD_NUMBER /* 7 */:
                                        i9 = 22050;
                                        break;
                                    case Z.g.BYTES_FIELD_NUMBER /* 8 */:
                                        i9 = 16000;
                                        break;
                                    case 9:
                                        i9 = 12000;
                                        break;
                                    case 10:
                                        i9 = 11025;
                                        break;
                                    case 11:
                                        i9 = 8000;
                                        break;
                                    case 12:
                                        i9 = 7350;
                                        break;
                                    case 13:
                                    case 14:
                                    default:
                                        throw u0.F.c("Unsupported sampling rate index " + i26);
                                    case 15:
                                        i9 = 57600;
                                        break;
                                    case 16:
                                        i9 = 51200;
                                        break;
                                    case 17:
                                        i9 = 40000;
                                        break;
                                    case 18:
                                        i9 = 38400;
                                        break;
                                    case 19:
                                        i9 = 34150;
                                        break;
                                    case 20:
                                        i9 = 28800;
                                        break;
                                    case 21:
                                        i9 = 25600;
                                        break;
                                    case 22:
                                        i9 = 20000;
                                        break;
                                    case 23:
                                        i9 = 19200;
                                        break;
                                    case 24:
                                        i9 = 17075;
                                        break;
                                    case 25:
                                        i9 = 14400;
                                        break;
                                    case 26:
                                        i9 = 12800;
                                        break;
                                    case 27:
                                        i9 = 9600;
                                        break;
                                }
                            } else {
                                i9 = h9.i(24);
                            }
                            int i27 = h9.i(3);
                            if (i27 == 0) {
                                i10 = 768;
                            } else if (i27 == i16) {
                                i10 = 1024;
                            } else if (i27 == 2 || i27 == 3) {
                                i10 = 2048;
                            } else {
                                if (i27 != i15) {
                                    throw u0.F.c("Unsupported coreSbrFrameLengthIndex " + i27);
                                }
                                i10 = 4096;
                            }
                            int i28 = i10;
                            if (i27 == 0 || i27 == i16) {
                                i11 = 0;
                            } else if (i27 == 2) {
                                i11 = 2;
                            } else if (i27 == 3) {
                                i11 = 3;
                            } else {
                                if (i27 != i15) {
                                    throw u0.F.c("Unsupported coreSbrFrameLengthIndex " + i27);
                                }
                                i11 = i16;
                            }
                            h9.t(2);
                            U2.a.M(h9);
                            int i29 = h9.i(5);
                            int i30 = 0;
                            int iK3 = 0;
                            while (true) {
                                int i31 = i16;
                                int i32 = 16;
                                if (i30 < i29 + 1) {
                                    int i33 = h9.i(3);
                                    iK3 = U2.a.K(h9, 5, 8, 16) + 1 + iK3;
                                    if ((i33 == 0 || i33 == 2) && h9.h()) {
                                        U2.a.M(h9);
                                    }
                                    i30++;
                                    i16 = i31;
                                } else {
                                    int iK4 = U2.a.K(h9, i15, 8, 16) + 1;
                                    h9.s();
                                    int i34 = 0;
                                    while (true) {
                                        double d8 = 2.0d;
                                        if (i34 < iK4) {
                                            int i35 = h9.i(2);
                                            if (i35 == 0) {
                                                c3 = c8;
                                                h9.t(3);
                                                if (h9.h()) {
                                                    h9.t(13);
                                                }
                                                if (i11 > 0) {
                                                    U2.a.L(h9);
                                                }
                                            } else if (i35 != i31) {
                                                if (i35 == 3) {
                                                    U2.a.K(h9, i15, 8, i32);
                                                    int iK5 = U2.a.K(h9, i15, 8, i32);
                                                    if (h9.h()) {
                                                        U2.a.K(h9, 8, i32, 0);
                                                    }
                                                    h9.s();
                                                    if (iK5 > 0) {
                                                        h9.t(iK5 * 8);
                                                    }
                                                }
                                                c3 = 5;
                                            } else {
                                                h9.t(3);
                                                boolean zH = h9.h();
                                                if (zH) {
                                                    h9.t(13);
                                                }
                                                if (zH) {
                                                    h9.s();
                                                }
                                                if (i11 > 0) {
                                                    U2.a.L(h9);
                                                    i12 = h9.i(2);
                                                } else {
                                                    i12 = 0;
                                                }
                                                if (i12 > 0) {
                                                    h9.t(6);
                                                    int i36 = h9.i(2);
                                                    h9.t(i15);
                                                    c3 = 5;
                                                    if (h9.h()) {
                                                        h9.t(5);
                                                    }
                                                    if (i12 == 2 || i12 == 3) {
                                                        h9.t(6);
                                                    }
                                                    if (i36 == 2) {
                                                        h9.s();
                                                    }
                                                } else {
                                                    c3 = 5;
                                                }
                                                int iFloor = ((int) Math.floor(Math.log(iK3 - 1) / Math.log(2.0d))) + 1;
                                                int i37 = h9.i(2);
                                                if (i37 > 0 && h9.h()) {
                                                    h9.t(iFloor);
                                                }
                                                if (h9.h()) {
                                                    h9.t(iFloor);
                                                }
                                                if (i11 == 0 && i37 == 0) {
                                                    h9.s();
                                                }
                                            }
                                            i31 = 1;
                                            i34++;
                                            c8 = c3;
                                            i15 = 4;
                                            i32 = 16;
                                        } else {
                                            if (h9.h()) {
                                                int i38 = 4;
                                                int iK6 = U2.a.K(h9, 2, 4, 8) + 1;
                                                int i39 = 0;
                                                bArr = null;
                                                while (i39 < iK6) {
                                                    int iK7 = U2.a.K(h9, i38, 8, 16);
                                                    int iK8 = U2.a.K(h9, i38, 8, 16);
                                                    if (iK7 == 7) {
                                                        int i40 = h9.i(i38) + 1;
                                                        h9.t(i38);
                                                        byte[] bArr4 = new byte[i40];
                                                        for (int i41 = 0; i41 < i40; i41++) {
                                                            bArr4[i41] = (byte) h9.i(8);
                                                        }
                                                        bArr = bArr4;
                                                    } else {
                                                        h9.t(iK8 * 8);
                                                    }
                                                    i39++;
                                                    i38 = 4;
                                                }
                                            } else {
                                                bArr = null;
                                            }
                                            switch (i9) {
                                                case 14700:
                                                case 16000:
                                                    d8 = 3.0d;
                                                    this.f348q = (int) (((double) i9) * d8);
                                                    this.f349r = (int) (((double) i28) * d8);
                                                    j8 = this.f351t;
                                                    j9 = wVar2.f354b;
                                                    if (j8 != j9) {
                                                        this.f351t = j9;
                                                        String strConcat = i25 != -1 ? "mhm1".concat(String.format(".%02X", Integer.valueOf(i25))) : "mhm1";
                                                        W wS = (bArr == null || bArr.length <= 0) ? null : C3.G.s(x0.v.f18555c, bArr);
                                                        C1578n c1578n = new C1578n();
                                                        c1578n.f17309a = this.f337e;
                                                        c1578n.f17319l = u0.E.m("video/mp2t");
                                                        c1578n.f17320m = u0.E.m("audio/mhm1");
                                                        c1578n.D = this.f348q;
                                                        c1578n.f17317j = strConcat;
                                                        c1578n.f17323p = wS;
                                                        this.f338f.e(new C1579o(c1578n));
                                                    }
                                                    this.f352u = true;
                                                    break;
                                                case 22050:
                                                case 24000:
                                                    this.f348q = (int) (((double) i9) * d8);
                                                    this.f349r = (int) (((double) i28) * d8);
                                                    j8 = this.f351t;
                                                    j9 = wVar2.f354b;
                                                    if (j8 != j9) {
                                                    }
                                                    this.f352u = true;
                                                    break;
                                                case 29400:
                                                case 32000:
                                                case 58800:
                                                case 64000:
                                                    d8 = 1.5d;
                                                    this.f348q = (int) (((double) i9) * d8);
                                                    this.f349r = (int) (((double) i28) * d8);
                                                    j8 = this.f351t;
                                                    j9 = wVar2.f354b;
                                                    if (j8 != j9) {
                                                    }
                                                    this.f352u = true;
                                                    break;
                                                case 44100:
                                                case 48000:
                                                case 88200:
                                                case 96000:
                                                    d8 = 1.0d;
                                                    this.f348q = (int) (((double) i9) * d8);
                                                    this.f349r = (int) (((double) i28) * d8);
                                                    j8 = this.f351t;
                                                    j9 = wVar2.f354b;
                                                    if (j8 != j9) {
                                                    }
                                                    this.f352u = true;
                                                    break;
                                                default:
                                                    throw u0.F.c("Unsupported sampling rate " + i9);
                                            }
                                        }
                                    }
                                }
                            }
                        } else if (i24 == 17) {
                            byte[] bArr5 = oVar2.f18539a;
                            T0.H h10 = new T0.H(bArr5.length, bArr5);
                            if (h10.h()) {
                                h10.t(2);
                                i5 = h10.i(13);
                            } else {
                                i5 = 0;
                            }
                            this.f350s = i5;
                        } else if (i24 == 2) {
                            if (this.f352u) {
                                this.f341j = false;
                                i = 1;
                            } else {
                                i = 0;
                            }
                            double d9 = (((double) (this.f349r - this.f350s)) * 1000000.0d) / ((double) this.f348q);
                            long jRound = Math.round(this.f339g);
                            if (this.i) {
                                this.i = false;
                                this.f339g = this.f340h;
                            } else {
                                this.f339g += d9;
                            }
                            this.f338f.a(jRound, i, this.f346o, 0, null);
                            this.f352u = false;
                            this.f350s = 0;
                            this.f346o = 0;
                        }
                        i8 = 1;
                        this.f336d = 1;
                    }
                }
                i16 = i8;
                i15 = 4;
            } else {
                int i42 = this.f342k;
                if ((i42 & 2) == 0) {
                    oVar.F(oVar.f18541c);
                    i14 = 4;
                } else {
                    i14 = 4;
                    if ((i42 & 4) == 0) {
                        while (oVar.a() > 0) {
                            int i43 = this.f343l << 8;
                            this.f343l = i43;
                            int iT = i43 | oVar.t();
                            this.f343l = iT;
                            if ((iT & 16777215) == 12583333) {
                                oVar.F(oVar.f18540b - 3);
                                this.f343l = 0;
                            }
                        }
                    }
                    this.f336d = 1;
                    i16 = 1;
                    i15 = 4;
                }
                i15 = i14;
                i16 = 1;
            }
        }
    }

    @Override // A1.InterfaceC0008i
    public final void g(T0.o oVar, M m8) {
        m8.a();
        m8.b();
        this.f337e = m8.f103e;
        m8.b();
        this.f338f = oVar.j(m8.f102d, 1);
    }

    @Override // A1.InterfaceC0008i
    public final void h(long j8, int i) {
        this.f342k = i;
        if (!this.f341j && (this.f346o != 0 || !this.f344m)) {
            this.i = true;
        }
        if (j8 != -9223372036854775807L) {
            if (this.i) {
                this.f340h = j8;
            } else {
                this.f339g = j8;
            }
        }
    }

    @Override // A1.InterfaceC0008i
    public final void f(boolean z8) {
    }
}
