package com.google.android.gms.internal.ads;

import androidx.media3.common.C;
import androidx.media3.common.MimeTypes;
import tv.danmaku.ijk.media.player.IjkMediaMeta;

/* JADX INFO: loaded from: classes2.dex */
public final class ua implements ja {

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public u3 f17175f;

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final androidx.media3.extractor.b1 f17171b = new androidx.media3.extractor.b1();

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

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final l2.a f17185p = new l2.a(3);

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public int f17186q = C.RATE_UNSET_INT;

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

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

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

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

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

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

    @Override // com.google.android.gms.internal.ads.ja
    public final void a(q2 q2Var, x2.o0 o0Var) {
        o0Var.d();
        o0Var.e();
        this.f17174e = o0Var.f34561e;
        o0Var.e();
        this.f17175f = q2Var.e(o0Var.f34560d, 1);
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void b(boolean z10) {
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void c(int i10, long j10) {
        this.f17180k = i10;
        if (!this.f17179j && (this.f17184o != 0 || !this.f17182m)) {
            this.f17178i = true;
        }
        if (j10 != -9223372036854775807L) {
            double d10 = j10;
            if (this.f17178i) {
                this.f17177h = d10;
            } else {
                this.f17176g = d10;
            }
        }
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Removed duplicated region for block: B:152:0x02e1  */
    /* JADX WARN: Removed duplicated region for block: B:192:0x040e  */
    /* JADX WARN: Removed duplicated region for block: B:208:0x0442  */
    /* JADX WARN: Removed duplicated region for block: B:254:0x04c3 A[SYNTHETIC] */
    @Override // com.google.android.gms.internal.ads.ja
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void d(p01 p01Var) throws zzat {
        int i10;
        int i11;
        int iP;
        int iP2;
        int i12;
        char c6;
        byte[] bArr;
        long j10;
        long j11;
        int iP3;
        char c10;
        long jQ;
        this.f17175f.getClass();
        while (p01Var.y() > 0) {
            int i13 = this.f17173d;
            int i14 = 8;
            int i15 = 1;
            if (i13 != 0) {
                l2.a aVar = this.f17185p;
                p01 p01Var2 = this.f17172c;
                if (i13 != 1) {
                    int i16 = aVar.f29936b;
                    if (i16 == 1 || i16 == 17) {
                        int i17 = p01Var.f15226b;
                        int iMin = Math.min(p01Var.y(), p01Var2.y());
                        p01Var.F(p01Var2.f15226b, iMin, p01Var2.f15225a);
                        p01Var2.E(iMin);
                        p01Var.C(i17);
                    }
                    int iMin2 = Math.min(p01Var.y(), aVar.f29938d - this.f17183n);
                    this.f17175f.a(p01Var, iMin2);
                    int i18 = this.f17183n + iMin2;
                    this.f17183n = i18;
                    if (i18 != aVar.f29938d) {
                        continue;
                    } else {
                        int i19 = aVar.f29936b;
                        if (i19 == 1) {
                            byte[] bArr2 = p01Var2.f15225a;
                            androidx.media3.extractor.b1 b1Var = new androidx.media3.extractor.b1(bArr2, bArr2.length);
                            int iP4 = b1Var.p(8);
                            int iP5 = b1Var.p(5);
                            if (iP5 != 31) {
                                switch (iP5) {
                                    case 0:
                                        iP2 = 96000;
                                        break;
                                    case 1:
                                        iP2 = 88200;
                                        break;
                                    case 2:
                                        iP2 = 64000;
                                        break;
                                    case 3:
                                        iP2 = 48000;
                                        break;
                                    case 4:
                                        iP2 = 44100;
                                        break;
                                    case 5:
                                        iP2 = 32000;
                                        break;
                                    case 6:
                                        iP2 = 24000;
                                        break;
                                    case 7:
                                        iP2 = 22050;
                                        break;
                                    case 8:
                                        iP2 = 16000;
                                        break;
                                    case 9:
                                        iP2 = 12000;
                                        break;
                                    case 10:
                                        iP2 = 11025;
                                        break;
                                    case 11:
                                        iP2 = 8000;
                                        break;
                                    case 12:
                                        iP2 = 7350;
                                        break;
                                    case 13:
                                    case 14:
                                    default:
                                        StringBuilder sb = new StringBuilder(String.valueOf(iP5).length() + 32);
                                        sb.append("Unsupported sampling rate index ");
                                        sb.append(iP5);
                                        throw zzat.zzc(sb.toString());
                                    case 15:
                                        iP2 = 57600;
                                        break;
                                    case 16:
                                        iP2 = 51200;
                                        break;
                                    case 17:
                                        iP2 = 40000;
                                        break;
                                    case 18:
                                        iP2 = 38400;
                                        break;
                                    case 19:
                                        iP2 = 34150;
                                        break;
                                    case 20:
                                        iP2 = 28800;
                                        break;
                                    case 21:
                                        iP2 = 25600;
                                        break;
                                    case 22:
                                        iP2 = 20000;
                                        break;
                                    case 23:
                                        iP2 = 19200;
                                        break;
                                    case 24:
                                        iP2 = 17075;
                                        break;
                                    case 25:
                                        iP2 = 14400;
                                        break;
                                    case 26:
                                        iP2 = 12800;
                                        break;
                                    case 27:
                                        iP2 = 9600;
                                        break;
                                }
                            } else {
                                iP2 = b1Var.p(24);
                            }
                            int iP6 = b1Var.p(3);
                            if (iP6 == 0) {
                                i12 = 768;
                            } else if (iP6 == 1) {
                                i12 = 1024;
                            } else if (iP6 == 2 || iP6 == 3) {
                                i12 = 2048;
                            } else {
                                if (iP6 != 4) {
                                    StringBuilder sb2 = new StringBuilder(com.google.android.gms.measurement.internal.u1.b(iP6, 36));
                                    sb2.append("Unsupported coreSbrFrameLengthIndex ");
                                    sb2.append(iP6);
                                    throw zzat.zzc(sb2.toString());
                                }
                                i12 = 4096;
                            }
                            int i20 = i12;
                            if (iP6 == 0 || iP6 == 1) {
                                c6 = 0;
                            } else if (iP6 == 2) {
                                c6 = 2;
                            } else if (iP6 == 3) {
                                c6 = 3;
                            } else {
                                if (iP6 != 4) {
                                    StringBuilder sb3 = new StringBuilder(com.google.android.gms.measurement.internal.u1.b(iP6, 36));
                                    sb3.append("Unsupported coreSbrFrameLengthIndex ");
                                    sb3.append(iP6);
                                    throw zzat.zzc(sb3.toString());
                                }
                                c6 = 1;
                            }
                            b1Var.n(2);
                            za2.A(b1Var);
                            int iP7 = b1Var.p(5);
                            int i21 = 0;
                            int iM = 0;
                            while (true) {
                                int i22 = 16;
                                if (i21 < iP7 + 1) {
                                    int iP8 = b1Var.p(3);
                                    iM = za2.M(b1Var, 5, 8, 16) + 1 + iM;
                                    if ((iP8 == 0 || iP8 == 2) && b1Var.o()) {
                                        za2.A(b1Var);
                                    }
                                    i21++;
                                } else {
                                    int iM2 = za2.M(b1Var, 4, 8, 16) + 1;
                                    b1Var.m();
                                    int i23 = 0;
                                    while (true) {
                                        double d10 = 2.0d;
                                        if (i23 < iM2) {
                                            int iP9 = b1Var.p(2);
                                            if (iP9 == 0) {
                                                b1Var.n(3);
                                                if (b1Var.o()) {
                                                    b1Var.n(13);
                                                }
                                                if (c6 > 0) {
                                                    za2.I(b1Var);
                                                }
                                            } else if (iP9 == i15) {
                                                b1Var.n(3);
                                                boolean zO = b1Var.o();
                                                if (zO) {
                                                    b1Var.n(13);
                                                }
                                                if (zO) {
                                                    b1Var.m();
                                                }
                                                if (c6 > 0) {
                                                    za2.I(b1Var);
                                                    iP3 = b1Var.p(2);
                                                    c10 = c6;
                                                } else {
                                                    iP3 = 0;
                                                    c10 = 0;
                                                }
                                                if (iP3 > 0) {
                                                    b1Var.n(6);
                                                    int iP10 = b1Var.p(2);
                                                    b1Var.n(4);
                                                    if (b1Var.o()) {
                                                        b1Var.n(5);
                                                    }
                                                    if (iP3 == 2 || iP3 == 3) {
                                                        b1Var.n(6);
                                                    }
                                                    if (iP10 == 2) {
                                                        b1Var.m();
                                                    }
                                                }
                                                int iFloor = ((int) Math.floor(Math.log(iM - 1) / Math.log(2.0d))) + 1;
                                                int iP11 = b1Var.p(2);
                                                if (iP11 > 0 && b1Var.o()) {
                                                    b1Var.n(iFloor);
                                                }
                                                if (b1Var.o()) {
                                                    b1Var.n(iFloor);
                                                }
                                                if (c10 == 0 && iP11 == 0) {
                                                    b1Var.m();
                                                }
                                            } else if (iP9 == 3) {
                                                za2.M(b1Var, 4, i14, i22);
                                                int iM3 = za2.M(b1Var, 4, i14, i22);
                                                if (b1Var.o()) {
                                                    za2.M(b1Var, i14, i22, 0);
                                                }
                                                b1Var.m();
                                                if (iM3 > 0) {
                                                    b1Var.n(iM3 * 8);
                                                }
                                            }
                                            i23++;
                                            i14 = 8;
                                            i15 = 1;
                                            i22 = 16;
                                        } else {
                                            if (b1Var.o()) {
                                                int i24 = 8;
                                                int i25 = 1;
                                                int iM4 = za2.M(b1Var, 2, 4, 8) + 1;
                                                int i26 = 0;
                                                bArr = null;
                                                while (i26 < iM4) {
                                                    int iM5 = za2.M(b1Var, 4, i24, 16);
                                                    int iM6 = za2.M(b1Var, 4, i24, 16);
                                                    if (iM5 == 7) {
                                                        int iP12 = b1Var.p(4) + i25;
                                                        b1Var.n(4);
                                                        byte[] bArr3 = new byte[iP12];
                                                        for (int i27 = 0; i27 < iP12; i27++) {
                                                            bArr3[i27] = (byte) b1Var.p(i24);
                                                        }
                                                        bArr = bArr3;
                                                    } else {
                                                        b1Var.n(iM6 * i24);
                                                    }
                                                    i26++;
                                                    i24 = 8;
                                                    i25 = 1;
                                                }
                                            } else {
                                                bArr = null;
                                            }
                                            switch (iP2) {
                                                case 14700:
                                                case 16000:
                                                    d10 = 3.0d;
                                                    int i28 = (int) (((double) iP2) * d10);
                                                    int i29 = (int) (((double) i20) * d10);
                                                    va vaVar = new va(bArr, iP4, i28, i29);
                                                    this.f17186q = i28;
                                                    this.f17187r = i29;
                                                    j10 = this.f17189t;
                                                    j11 = aVar.f29937c;
                                                    if (j10 != j11) {
                                                        this.f17189t = j11;
                                                        String strConcat = iP4 != -1 ? "mhm1".concat(String.valueOf(String.format(".%02X", Integer.valueOf(iP4)))) : "mhm1";
                                                        byte[] bArr4 = vaVar.zzd;
                                                        zzguf zzgufVarP = (bArr4 == null || bArr4.length <= 0) ? null : zzguf.p(bb1.f9475b, bArr4);
                                                        sm2 sm2Var = new sm2();
                                                        sm2Var.zza(this.f17174e);
                                                        sm2Var.zzl(MimeTypes.VIDEO_MP2T);
                                                        sm2Var.zzm(MimeTypes.AUDIO_MPEGH_MHM1);
                                                        sm2Var.f16497t = this.f17186q;
                                                        sm2Var.zzj(strConcat);
                                                        sm2Var.zzp(zzgufVarP);
                                                        this.f17175f.d(new zn2(sm2Var));
                                                    }
                                                    i11 = 1;
                                                    this.f17190u = true;
                                                    break;
                                                case 22050:
                                                case 24000:
                                                    int i282 = (int) (((double) iP2) * d10);
                                                    int i292 = (int) (((double) i20) * d10);
                                                    va vaVar2 = new va(bArr, iP4, i282, i292);
                                                    this.f17186q = i282;
                                                    this.f17187r = i292;
                                                    j10 = this.f17189t;
                                                    j11 = aVar.f29937c;
                                                    if (j10 != j11) {
                                                    }
                                                    i11 = 1;
                                                    this.f17190u = true;
                                                    break;
                                                case 29400:
                                                case 32000:
                                                case 58800:
                                                case 64000:
                                                    d10 = 1.5d;
                                                    int i2822 = (int) (((double) iP2) * d10);
                                                    int i2922 = (int) (((double) i20) * d10);
                                                    va vaVar22 = new va(bArr, iP4, i2822, i2922);
                                                    this.f17186q = i2822;
                                                    this.f17187r = i2922;
                                                    j10 = this.f17189t;
                                                    j11 = aVar.f29937c;
                                                    if (j10 != j11) {
                                                    }
                                                    i11 = 1;
                                                    this.f17190u = true;
                                                    break;
                                                case 44100:
                                                case 48000:
                                                case 88200:
                                                case 96000:
                                                    d10 = 1.0d;
                                                    int i28222 = (int) (((double) iP2) * d10);
                                                    int i29222 = (int) (((double) i20) * d10);
                                                    va vaVar222 = new va(bArr, iP4, i28222, i29222);
                                                    this.f17186q = i28222;
                                                    this.f17187r = i29222;
                                                    j10 = this.f17189t;
                                                    j11 = aVar.f29937c;
                                                    if (j10 != j11) {
                                                    }
                                                    i11 = 1;
                                                    this.f17190u = true;
                                                    break;
                                                default:
                                                    StringBuilder sb4 = new StringBuilder(String.valueOf(iP2).length() + 26);
                                                    sb4.append("Unsupported sampling rate ");
                                                    sb4.append(iP2);
                                                    throw zzat.zzc(sb4.toString());
                                            }
                                        }
                                    }
                                }
                            }
                        } else {
                            if (i19 == 17) {
                                byte[] bArr5 = p01Var2.f15225a;
                                androidx.media3.extractor.b1 b1Var2 = new androidx.media3.extractor.b1(bArr5, bArr5.length);
                                if (b1Var2.o()) {
                                    b1Var2.n(2);
                                    iP = b1Var2.p(13);
                                } else {
                                    iP = 0;
                                }
                                this.f17188s = iP;
                            } else if (i19 == 2) {
                                if (this.f17190u) {
                                    this.f17179j = false;
                                    i10 = 1;
                                } else {
                                    i10 = 0;
                                }
                                int i30 = this.f17187r - this.f17188s;
                                double d11 = this.f17186q;
                                long jRound = Math.round(this.f17176g);
                                if (this.f17178i) {
                                    this.f17178i = false;
                                    this.f17176g = this.f17177h;
                                } else {
                                    this.f17176g += (((double) i30) * 1000000.0d) / d11;
                                }
                                this.f17175f.zze(jRound, i10, this.f17184o, 0, null);
                                this.f17190u = false;
                                this.f17188s = 0;
                                this.f17184o = 0;
                            }
                            i11 = 1;
                        }
                        this.f17173d = i11;
                    }
                } else {
                    int iY = p01Var.y();
                    p01 p01Var3 = this.f17170a;
                    int iMin3 = Math.min(iY, p01Var3.y());
                    p01Var.F(p01Var3.f15226b, iMin3, p01Var3.f15225a);
                    p01Var3.E(iMin3);
                    if (p01Var3.y() == 0) {
                        int i31 = p01Var3.f15227c;
                        byte[] bArr6 = p01Var3.f15225a;
                        androidx.media3.extractor.b1 b1Var3 = this.f17171b;
                        b1Var3.f3327b = bArr6;
                        b1Var3.f3328c = 0;
                        b1Var3.f3329d = 0;
                        b1Var3.f3330e = i31;
                        b1Var3.k();
                        int iM7 = za2.M(b1Var3, 3, 8, 8);
                        aVar.f29936b = iM7;
                        if (iM7 != -1) {
                            ih1.x(Math.max(Math.max(2, 8), 32) <= 63);
                            Math.addExact(Math.addExact(3L, 255L), IjkMediaMeta.AV_CH_WIDE_RIGHT);
                            if (b1Var3.h() < 2) {
                                jQ = -1;
                                aVar.f29937c = jQ;
                                if (jQ != -1) {
                                    if (jQ > 16) {
                                        StringBuilder sb5 = new StringBuilder(String.valueOf(jQ).length() + 49);
                                        sb5.append("Contains sub-stream with an invalid packet label ");
                                        sb5.append(jQ);
                                        throw zzat.zzc(sb5.toString());
                                    }
                                    if (jQ == 0) {
                                        int i32 = aVar.f29936b;
                                        if (i32 == 1) {
                                            throw zzat.zzb("Mpegh3daConfig packet with invalid packet label 0", null);
                                        }
                                        if (i32 == 2) {
                                            throw zzat.zzb("Mpegh3daFrame packet with invalid packet label 0", null);
                                        }
                                        if (i32 == 17) {
                                            throw zzat.zzb("AudioTruncation packet with invalid packet label 0", null);
                                        }
                                    }
                                    int iM8 = za2.M(b1Var3, 11, 24, 24);
                                    aVar.f29938d = iM8;
                                    if (iM8 != -1) {
                                        this.f17183n = 0;
                                        this.f17184o = iM8 + i31 + this.f17184o;
                                        p01Var3.C(0);
                                        this.f17175f.a(p01Var3, p01Var3.f15227c);
                                        p01Var3.v(2);
                                        p01Var2.v(aVar.f29938d);
                                        this.f17182m = true;
                                        this.f17173d = 2;
                                    }
                                }
                            } else {
                                jQ = b1Var3.q(2);
                                if (jQ == 3) {
                                    if (b1Var3.h() >= 8) {
                                        long jQ2 = b1Var3.q(8);
                                        long j12 = 3 + jQ2;
                                        if (jQ2 != 255) {
                                            jQ = j12;
                                        } else if (b1Var3.h() >= 32) {
                                            jQ = b1Var3.q(32) + j12;
                                        }
                                    }
                                }
                                aVar.f29937c = jQ;
                                if (jQ != -1) {
                                }
                            }
                        }
                        int i33 = p01Var3.f15227c;
                        if (i33 < 15) {
                            p01Var3.A(i33 + 1);
                        }
                    }
                    this.f17182m = false;
                }
            } else {
                int i34 = this.f17180k;
                if ((i34 & 2) == 0) {
                    p01Var.C(p01Var.f15227c);
                } else {
                    if ((i34 & 4) == 0) {
                        while (p01Var.y() > 0) {
                            int i35 = this.f17181l << 8;
                            this.f17181l = i35;
                            int I = i35 | p01Var.I();
                            this.f17181l = I;
                            if ((I & 16777215) == 12583333) {
                                p01Var.C(p01Var.f15226b - 3);
                                this.f17181l = 0;
                            }
                        }
                    }
                    this.f17173d = 1;
                }
            }
        }
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void zza() {
        this.f17173d = 0;
        this.f17181l = 0;
        this.f17170a.v(2);
        this.f17183n = 0;
        this.f17184o = 0;
        this.f17186q = C.RATE_UNSET_INT;
        this.f17187r = -1;
        this.f17188s = 0;
        this.f17189t = -1L;
        this.f17190u = false;
        this.f17178i = false;
        this.f17182m = true;
        this.f17179j = true;
        this.f17176g = -9.223372036854776E18d;
        this.f17177h = -9.223372036854776E18d;
    }
}
