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

import androidx.annotation.Nullable;
import androidx.media3.common.MimeTypes;
import java.io.EOFException;
import java.util.List;
import java.util.Objects;

/* JADX INFO: loaded from: classes2.dex */
public final class l8 implements u3 {

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

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

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

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

    @Nullable
    private j8 zzg;

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public byte[] f13529f = bb1.f9475b;

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

    public l8(u3 u3Var, i8 i8Var) {
        this.f13524a = u3Var;
        this.f13525b = i8Var;
    }

    @Override // com.google.android.gms.internal.ads.u3
    public final void b(p01 p01Var, int i10, int i11) {
        if (this.zzg == null) {
            this.f13524a.b(p01Var, i10, i11);
            return;
        }
        f(i10);
        p01Var.F(this.f13528e, i10, this.f13529f);
        this.f13528e += i10;
    }

    @Override // com.google.android.gms.internal.ads.u3
    public final int c(eh2 eh2Var, int i10, boolean z10) throws EOFException {
        if (this.zzg == null) {
            return this.f13524a.c(eh2Var, i10, z10);
        }
        f(i10);
        int iD = eh2Var.d(this.f13529f, this.f13528e, i10);
        if (iD != -1) {
            this.f13528e += iD;
            return iD;
        }
        if (z10) {
            return -1;
        }
        throw new EOFException();
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Removed duplicated region for block: B:67:0x00ff  */
    @Override // com.google.android.gms.internal.ads.u3
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void d(zn2 zn2Var) {
        Object obj;
        char c6;
        byte b10;
        int i10;
        boolean z10;
        j8 y8Var;
        byte b11;
        String str = zn2Var.zzo;
        str.getClass();
        ih1.x(hc.zzf(str) == 3);
        boolean zEquals = zn2Var.equals(this.f13530g);
        i8 i8Var = this.f13525b;
        if (zEquals) {
            obj = MimeTypes.APPLICATION_DVBSUBS;
            c6 = 4;
        } else {
            this.f13530g = zn2Var;
            va2 va2Var = (va2) i8Var;
            switch (va2Var.f17586a) {
                case 5:
                    String str2 = zn2Var.zzo;
                    if (Objects.equals(str2, MimeTypes.TEXT_SSA) || Objects.equals(str2, MimeTypes.TEXT_VTT) || Objects.equals(str2, MimeTypes.APPLICATION_MP4VTT) || Objects.equals(str2, MimeTypes.APPLICATION_SUBRIP) || Objects.equals(str2, MimeTypes.APPLICATION_TX3G) || Objects.equals(str2, MimeTypes.APPLICATION_PGS) || Objects.equals(str2, MimeTypes.APPLICATION_VOBSUB) || Objects.equals(str2, MimeTypes.APPLICATION_DVBSUBS) || Objects.equals(str2, MimeTypes.APPLICATION_TTML)) {
                        z10 = true;
                        break;
                    }
                default:
                    z10 = false;
                    break;
            }
            if (z10) {
                switch (va2Var.f17586a) {
                    case 5:
                        String str3 = zn2Var.zzo;
                        if (str3 != null) {
                            switch (str3.hashCode()) {
                                case -1351681404:
                                    if (!str3.equals(MimeTypes.APPLICATION_DVBSUBS)) {
                                        obj = MimeTypes.APPLICATION_DVBSUBS;
                                        b11 = -1;
                                    } else {
                                        obj = MimeTypes.APPLICATION_DVBSUBS;
                                        b11 = 7;
                                    }
                                    break;
                                case -1248334819:
                                    if (str3.equals(MimeTypes.APPLICATION_PGS)) {
                                        obj = MimeTypes.APPLICATION_DVBSUBS;
                                        b11 = 5;
                                        break;
                                    }
                                    break;
                                case -1026075066:
                                    if (str3.equals(MimeTypes.APPLICATION_MP4VTT)) {
                                        obj = MimeTypes.APPLICATION_DVBSUBS;
                                        b11 = 2;
                                        break;
                                    }
                                    break;
                                case -1004728940:
                                    if (str3.equals(MimeTypes.TEXT_VTT)) {
                                        obj = MimeTypes.APPLICATION_DVBSUBS;
                                        b11 = 1;
                                        break;
                                    }
                                    break;
                                case 691401887:
                                    if (str3.equals(MimeTypes.APPLICATION_TX3G)) {
                                        obj = MimeTypes.APPLICATION_DVBSUBS;
                                        b11 = 4;
                                        break;
                                    }
                                    break;
                                case 822864842:
                                    if (str3.equals(MimeTypes.TEXT_SSA)) {
                                        obj = MimeTypes.APPLICATION_DVBSUBS;
                                        b11 = 0;
                                        break;
                                    }
                                    break;
                                case 1157994102:
                                    if (str3.equals(MimeTypes.APPLICATION_VOBSUB)) {
                                        obj = MimeTypes.APPLICATION_DVBSUBS;
                                        b11 = 6;
                                        break;
                                    }
                                    break;
                                case 1668750253:
                                    if (str3.equals(MimeTypes.APPLICATION_SUBRIP)) {
                                        obj = MimeTypes.APPLICATION_DVBSUBS;
                                        b11 = 3;
                                        break;
                                    }
                                    break;
                                case 1693976202:
                                    if (str3.equals(MimeTypes.APPLICATION_TTML)) {
                                        obj = MimeTypes.APPLICATION_DVBSUBS;
                                        b11 = 8;
                                        break;
                                    }
                                    break;
                            }
                            List list = zn2Var.f19336i;
                            switch (b11) {
                                case 0:
                                    c6 = 4;
                                    y8Var = new y8(list);
                                    break;
                                case 1:
                                    y8Var = new zv1(4);
                                    c6 = 4;
                                    break;
                                case 2:
                                    y8Var = new ru(8);
                                    c6 = 4;
                                    break;
                                case 3:
                                    y8Var = new c9();
                                    c6 = 4;
                                    break;
                                case 4:
                                    y8Var = new m9(list);
                                    c6 = 4;
                                    break;
                                case 5:
                                    y8Var = new w8();
                                    c6 = 4;
                                    break;
                                case 6:
                                    y8Var = new o9(list);
                                    c6 = 4;
                                    break;
                                case 7:
                                    y8Var = new u8(list);
                                    c6 = 4;
                                    break;
                                case 8:
                                    y8Var = new h9();
                                    c6 = 4;
                                    break;
                            }
                        }
                        throw new IllegalArgumentException("Unsupported MIME type: ".concat(String.valueOf(str3)));
                    default:
                        throw new IllegalStateException("This SubtitleParser.Factory doesn't support any formats.");
                }
            }
            obj = MimeTypes.APPLICATION_DVBSUBS;
            c6 = 4;
            y8Var = null;
            this.zzg = y8Var;
        }
        j8 j8Var = this.zzg;
        u3 u3Var = this.f13524a;
        if (j8Var == null) {
            u3Var.d(zn2Var);
            return;
        }
        sm2 sm2Var = new sm2(zn2Var);
        sm2Var.zzm(MimeTypes.APPLICATION_MEDIA3_CUES);
        sm2Var.zzj(str);
        sm2Var.f16485h = Long.MAX_VALUE;
        switch (((va2) i8Var).f17586a) {
            case 5:
                String str4 = zn2Var.zzo;
                if (str4 != null) {
                    switch (str4.hashCode()) {
                        case -1351681404:
                            b10 = !str4.equals(obj) ? (byte) -1 : (byte) 0;
                            break;
                        case -1248334819:
                            b10 = !str4.equals(MimeTypes.APPLICATION_PGS) ? (byte) -1 : (byte) 1;
                            break;
                        case -1026075066:
                            b10 = !str4.equals(MimeTypes.APPLICATION_MP4VTT) ? (byte) -1 : (byte) 2;
                            break;
                        case -1004728940:
                            b10 = !str4.equals(MimeTypes.TEXT_VTT) ? (byte) -1 : (byte) 3;
                            break;
                        case 691401887:
                            b10 = !str4.equals(MimeTypes.APPLICATION_TX3G) ? (byte) -1 : c6;
                            break;
                        case 822864842:
                            b10 = !str4.equals(MimeTypes.TEXT_SSA) ? (byte) -1 : (byte) 5;
                            break;
                        case 1157994102:
                            b10 = !str4.equals(MimeTypes.APPLICATION_VOBSUB) ? (byte) -1 : (byte) 6;
                            break;
                        case 1668750253:
                            b10 = !str4.equals(MimeTypes.APPLICATION_SUBRIP) ? (byte) -1 : (byte) 7;
                            break;
                        case 1693976202:
                            b10 = !str4.equals(MimeTypes.APPLICATION_TTML) ? (byte) -1 : (byte) 8;
                            break;
                        default:
                            b10 = -1;
                            break;
                    }
                    switch (b10) {
                        case 0:
                        case 1:
                        case 2:
                        case 4:
                        case 6:
                            i10 = 2;
                            break;
                    }
                    sm2Var.f16502y = i10;
                    u3Var.d(new zn2(sm2Var));
                    return;
                }
                throw new IllegalArgumentException("Unsupported MIME type: ".concat(String.valueOf(str4)));
            default:
                i10 = 1;
                sm2Var.f16502y = i10;
                u3Var.d(new zn2(sm2Var));
                return;
        }
    }

    public final void f(int i10) {
        int length = this.f13529f.length;
        int i11 = this.f13528e;
        if (length - i11 >= i10) {
            return;
        }
        int i12 = i11 - this.f13527d;
        int iMax = Math.max(i12 + i12, i10 + i12);
        byte[] bArr = this.f13529f;
        byte[] bArr2 = iMax <= bArr.length ? bArr : new byte[iMax];
        System.arraycopy(bArr, this.f13527d, bArr2, 0, i12);
        this.f13527d = 0;
        this.f13528e = i12;
        this.f13529f = bArr2;
    }

    @Override // com.google.android.gms.internal.ads.u3
    public final void zze(long j10, int i10, int i11, int i12, @Nullable t3 t3Var) {
        if (this.zzg == null) {
            this.f13524a.zze(j10, i10, i11, i12, t3Var);
            return;
        }
        ih1.e0("DRM on subtitles is not supported", t3Var == null);
        int i13 = (this.f13528e - i12) - i11;
        try {
            this.zzg.b(this.f13529f, i13, i11, new g7.h(this, j10, i10));
        } catch (RuntimeException e10) {
            if (!this.f13531h) {
                throw e10;
            }
            vt0.zzd("SubtitleTranscodingTO", "Parsing subtitles failed, ignoring sample.", e10);
        }
        int i14 = i13 + i11;
        this.f13527d = i14;
        if (i14 == this.f13528e) {
            this.f13527d = 0;
            this.f13528e = 0;
        }
    }
}
