package androidx.media3.extractor;

import androidx.annotation.Nullable;
import androidx.media3.common.util.Assertions;

/* JADX INFO: loaded from: classes.dex */
public final class a1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final byte[] f3309a = new byte[10];

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

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

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

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

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

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

    public final void a(z zVar) {
        if (this.f3310b) {
            return;
        }
        byte[] bArr = this.f3309a;
        zVar.a(0, 10, bArr);
        zVar.j();
        if (bArr[4] == -8 && bArr[5] == 114 && bArr[6] == 111) {
            byte b10 = bArr[7];
            if ((b10 & 254) != 186) {
                return;
            }
            if ((40 << ((bArr[(b10 & 255) == 187 ? '\t' : '\b'] >> 4) & 7)) == 0) {
                return;
            }
            this.f3310b = true;
        }
    }

    public void outputPendingSampleMetadata(z0 z0Var, @Nullable y0 y0Var) {
        if (this.f3311c > 0) {
            z0Var.sampleMetadata(this.f3312d, this.f3313e, this.f3314f, this.f3315g, y0Var);
            this.f3311c = 0;
        }
    }

    public void sampleMetadata(z0 z0Var, long j10, int i10, int i11, int i12, @Nullable y0 y0Var) {
        Assertions.checkState(this.f3315g <= i11 + i12, "TrueHD chunk samples must be contiguous in the sample queue.");
        if (this.f3310b) {
            int i13 = this.f3311c;
            int i14 = i13 + 1;
            this.f3311c = i14;
            if (i13 == 0) {
                this.f3312d = j10;
                this.f3313e = i10;
                this.f3314f = 0;
            }
            this.f3314f += i11;
            this.f3315g = i12;
            if (i14 >= 16) {
                outputPendingSampleMetadata(z0Var, y0Var);
            }
        }
    }
}
