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

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

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

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

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

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

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

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

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

    @Nullable
    private j7 zzf;

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

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

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

    /* JADX WARN: Code restructure failed: missing block: B:29:0x006b, code lost:
    
        return false;
     */
    @Override // com.google.android.gms.internal.ads.o2
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean a(p2 p2Var) throws EOFException, InterruptedIOException {
        int i10;
        p01 p01Var = new p01(16);
        boolean z10 = true;
        while (true) {
            p01Var.v(8);
            if (!p2Var.j(p01Var.f15225a, 0, 8, true)) {
                break;
            }
            long jN = p01Var.N();
            int iB = p01Var.b();
            if (jN != 1) {
                i10 = 8;
            } else {
                if (!p2Var.j(p01Var.f15225a, 8, 8, true)) {
                    break;
                }
                jN = p01Var.j();
                i10 = 16;
            }
            long j10 = i10;
            if (jN < j10) {
                break;
            }
            int i11 = (int) (jN - j10);
            if (z10) {
                if (iB != 1718909296 || i11 < 8) {
                    break;
                }
                p01Var.v(4);
                h2 h2Var = (h2) p2Var;
                h2Var.j(p01Var.f15225a, 0, 4, false);
                if (p01Var.b() != 1751476579) {
                    break;
                }
                h2Var.l(i11 - 4, false);
            } else {
                if (iB == 1836086884) {
                    return true;
                }
                if (i11 != 0) {
                    ((h2) p2Var).l(i11, false);
                }
            }
            z10 = false;
        }
    }

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

    @Override // com.google.android.gms.internal.ads.o2
    public final int c(p2 p2Var, androidx.media3.extractor.f0 f0Var) throws zzat {
        while (true) {
            int i10 = this.f15981e;
            if (i10 == 0) {
                int i11 = this.f15984h;
                p01 p01Var = this.f15977a;
                if (i11 == 0) {
                    if (!p2Var.i(p01Var.f15225a, 0, 8, true)) {
                        q2 q2Var = this.f15978b;
                        q2Var.getClass();
                        q2Var.d();
                        this.f15978b.k(new w2(-9223372036854775807L, 0L));
                        this.f15981e = 4;
                        return -1;
                    }
                    this.f15984h = 8;
                    p01Var.C(0);
                    this.f15983g = p01Var.N();
                    this.f15982f = p01Var.b();
                }
                long j10 = this.f15983g;
                if (j10 == 1) {
                    p2Var.c(p01Var.f15225a, 8, 8);
                    this.f15984h += 8;
                    j10 = p01Var.j();
                    this.f15983g = j10;
                }
                if (this.f15982f == 1836086884) {
                    long jZzn = p2Var.zzn();
                    this.f15985i = jZzn;
                    long j11 = this.f15984h;
                    x4 x4Var = new x4(0L, jZzn - j11, -9223372036854775807L, jZzn, j10 - j11);
                    q2 q2Var2 = this.f15978b;
                    q2Var2.getClass();
                    u3 u3VarE = q2Var2.e(1024, 4);
                    sm2 sm2Var = new sm2();
                    sm2Var.zzl(MimeTypes.IMAGE_HEIC);
                    sm2Var.zzk(new ta(x4Var));
                    u3VarE.d(new zn2(sm2Var));
                    this.f15981e = 2;
                } else {
                    this.f15981e = 1;
                }
            } else if (i10 == 1) {
                p2Var.e((int) (this.f15983g - ((long) this.f15984h)));
                this.f15984h = 0;
                this.f15981e = 0;
            } else {
                if (i10 != 2) {
                    if (i10 != 3) {
                        return -1;
                    }
                    if (this.f15980d == null || p2Var != this.f15979c) {
                        this.f15979c = p2Var;
                        this.f15980d = new q3(p2Var, this.f15985i);
                    }
                    j7 j7Var = this.zzf;
                    j7Var.getClass();
                    int iC = j7Var.c(this.f15980d, f0Var);
                    if (iC == 1) {
                        f0Var.f3366a += this.f15985i;
                    }
                    return iC;
                }
                if (this.zzf == null) {
                    this.zzf = new j7(8, i8.f12406t);
                }
                q3 q3Var = new q3(p2Var, this.f15985i);
                this.f15980d = q3Var;
                if (this.zzf.a(q3Var)) {
                    j7 j7Var2 = this.zzf;
                    long j12 = this.f15985i;
                    q2 q2Var3 = this.f15978b;
                    q2Var3.getClass();
                    j7Var2.b(new s3(j12, q2Var3));
                    this.f15981e = 3;
                } else {
                    q2 q2Var4 = this.f15978b;
                    q2Var4.getClass();
                    q2Var4.d();
                    this.f15978b.k(new w2(-9223372036854775807L, 0L));
                    this.f15981e = 4;
                }
            }
        }
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void d(long j10, long j11) {
        if (j10 != 0) {
            if (this.f15981e == 3) {
                j7 j7Var = this.zzf;
                j7Var.getClass();
                j7Var.d(j10, j11);
                return;
            }
            return;
        }
        this.f15981e = 0;
        this.f15984h = 0;
        this.f15985i = -1L;
        if (this.zzf != null) {
            this.zzf = null;
        }
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void zzf() {
        if (this.zzf != null) {
            this.zzf = null;
        }
    }
}
