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

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

/* JADX INFO: loaded from: classes2.dex */
public final class t4 implements o2 {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public q2 f16704b;

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

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

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

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

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

    @Nullable
    private x4 zzg;

    @Nullable
    private j7 zzj;

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

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

    @Override // com.google.android.gms.internal.ads.o2
    public final boolean a(p2 p2Var) throws EOFException, InterruptedIOException {
        p01 p01Var = this.f16703a;
        p01Var.v(2);
        h2 h2Var = (h2) p2Var;
        h2Var.j(p01Var.f15225a, 0, 2, false);
        if (p01Var.J() == 65496) {
            while (true) {
                p01Var.v(2);
                h2Var.j(p01Var.f15225a, 0, 2, false);
                int iJ = p01Var.J();
                this.f16706d = iJ;
                if (iJ != 65498) {
                    p01Var.v(2);
                    p2Var.h(0, 2, p01Var.f15225a);
                    int iJ2 = p01Var.J() - 2;
                    if (iJ2 < 0) {
                        break;
                    }
                    if (this.f16706d != 65505) {
                        ((h2) p2Var).l(iJ2, false);
                    } else {
                        p01Var.v(iJ2);
                        ((h2) p2Var).j(p01Var.f15225a, 0, iJ2, false);
                        if (Objects.equals(p01Var.zzM((char) 0), "http://ns.adobe.com/xap/1.0/") && w4.zzb(p01Var.zzM((char) 0))) {
                            return true;
                        }
                    }
                } else {
                    break;
                }
            }
        }
        return false;
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void b(q2 q2Var) {
        this.f16704b = q2Var;
    }

    /* JADX WARN: Removed duplicated region for block: B:49:0x0103  */
    /* JADX WARN: Removed duplicated region for block: B:89:0x0183  */
    @Override // com.google.android.gms.internal.ads.o2
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int c(p2 p2Var, androidx.media3.extractor.f0 f0Var) throws zzat {
        String strZzM;
        v4 v4VarZza;
        x4 x4Var;
        long j10;
        int i10 = this.f16705c;
        p01 p01Var = this.f16703a;
        if (i10 == 0) {
            p01Var.v(2);
            p2Var.c(p01Var.f15225a, 0, 2);
            int iJ = p01Var.J();
            this.f16706d = iJ;
            if (iJ == 65498) {
                if (this.f16708f != -1) {
                    this.f16705c = 4;
                } else {
                    e();
                }
            } else if ((iJ < 65488 || iJ > 65497) && iJ != 65281) {
                this.f16705c = 1;
            }
            return 0;
        }
        if (i10 == 1) {
            p01Var.v(2);
            p2Var.h(0, 2, p01Var.f15225a);
            this.f16707e = p01Var.J() - 2;
            p2Var.e(2);
            this.f16705c = 2;
            return 0;
        }
        if (i10 != 2) {
            if (i10 != 4) {
                if (i10 != 5) {
                    if (i10 == 6) {
                        return -1;
                    }
                    throw new IllegalStateException();
                }
                if (this.f16710h == null || p2Var != this.f16709g) {
                    this.f16709g = p2Var;
                    this.f16710h = new q3(p2Var, this.f16708f);
                }
                j7 j7Var = this.zzj;
                j7Var.getClass();
                int iC = j7Var.c(this.f16710h, f0Var);
                if (iC == 1) {
                    f0Var.f3366a += this.f16708f;
                }
                return iC;
            }
            long jZzn = p2Var.zzn();
            long j11 = this.f16708f;
            if (jZzn != j11) {
                f0Var.f3366a = j11;
                return 1;
            }
            if (p2Var.j(p01Var.f15225a, 0, 1, true)) {
                p2Var.zzl();
                if (this.zzj == null) {
                    this.zzj = new j7(8, i8.f12406t);
                }
                q3 q3Var = new q3(p2Var, this.f16708f);
                this.f16710h = q3Var;
                if (this.zzj.a(q3Var)) {
                    j7 j7Var2 = this.zzj;
                    long j12 = this.f16708f;
                    q2 q2Var = this.f16704b;
                    q2Var.getClass();
                    j7Var2.b(new s3(j12, q2Var));
                    x4 x4Var2 = this.zzg;
                    x4Var2.getClass();
                    q2 q2Var2 = this.f16704b;
                    q2Var2.getClass();
                    u3 u3VarE = q2Var2.e(1024, 4);
                    sm2 sm2Var = new sm2();
                    sm2Var.zzl(MimeTypes.IMAGE_JPEG);
                    sm2Var.zzk(new ta(x4Var2));
                    u3VarE.d(new zn2(sm2Var));
                    this.f16705c = 5;
                } else {
                    e();
                }
            } else {
                e();
            }
            return 0;
        }
        if (this.f16706d == 65505) {
            p01 p01Var2 = new p01(this.f16707e);
            p2Var.c(p01Var2.f15225a, 0, this.f16707e);
            if (this.zzg == null && "http://ns.adobe.com/xap/1.0/".equals(p01Var2.zzM((char) 0)) && (strZzM = p01Var2.zzM((char) 0)) != null) {
                long jZzo = p2Var.zzo();
                if (jZzo != -1 && (v4VarZza = w4.zza(strZzM)) != null) {
                    List list = v4VarZza.f17505b;
                    if (list.size() < 2) {
                        x4Var = null;
                        this.zzg = x4Var;
                        if (x4Var != null) {
                            this.f16708f = x4Var.f17515d;
                        }
                    } else {
                        long j13 = -1;
                        long j14 = -1;
                        long j15 = -1;
                        long j16 = -1;
                        for (int size = list.size() - 1; size >= 0; size--) {
                            u4 u4Var = (u4) list.get(size);
                            String str = u4Var.f17070a;
                            boolean z10 = str.equals(MimeTypes.VIDEO_MP4) || str.equals("video/quicktime");
                            if (size == 0) {
                                jZzo -= u4Var.f17072c;
                                j10 = 0;
                            } else {
                                j10 = jZzo - u4Var.f17071b;
                            }
                            long j17 = jZzo;
                            jZzo = j10;
                            if (z10 && jZzo != j17) {
                                j16 = j17 - jZzo;
                                j15 = jZzo;
                            }
                            if (size == 0) {
                                j14 = j17;
                            }
                            if (size == 0) {
                                j13 = jZzo;
                            }
                        }
                        if (j15 != -1 && j16 != -1 && j13 != -1 && j14 != -1) {
                            x4Var = new x4(j13, j14, v4VarZza.f17504a, j15, j16);
                        }
                        this.zzg = x4Var;
                        if (x4Var != null) {
                        }
                    }
                }
            }
        } else {
            p2Var.e(this.f16707e);
        }
        this.f16705c = 0;
        return 0;
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void d(long j10, long j11) {
        if (j10 == 0) {
            this.f16705c = 0;
            this.zzj = null;
        } else if (this.f16705c == 5) {
            j7 j7Var = this.zzj;
            j7Var.getClass();
            j7Var.d(j10, j11);
        }
    }

    public final void e() {
        q2 q2Var = this.f16704b;
        q2Var.getClass();
        q2Var.d();
        this.f16704b.k(new w2(-9223372036854775807L, 0L));
        this.f16705c = 6;
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void zzf() {
    }
}
