package y2;

import androidx.media3.common.DataReader;
import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.ParserException;
import androidx.media3.common.util.Util;
import androidx.media3.extractor.b0;
import androidx.media3.extractor.z;
import androidx.media3.extractor.z0;
import x.i;

/* JADX INFO: loaded from: classes.dex */
public final class c implements b {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final i f36746c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Format f36747d;

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

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

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

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

    public c(b0 b0Var, z0 z0Var, i iVar, String str, int i10) throws ParserException {
        this.f36744a = b0Var;
        this.f36745b = z0Var;
        this.f36746c = iVar;
        int i11 = (iVar.f34308b * iVar.f34312f) / 8;
        int i12 = iVar.f34311e;
        if (i12 != i11) {
            throw ParserException.createForMalformedContainer("Expected block size: " + i11 + "; got: " + i12, null);
        }
        int i13 = iVar.f34309c;
        int i14 = i13 * i11;
        int i15 = i14 * 8;
        int iMax = Math.max(i11, i14 / 10);
        this.f36748e = iMax;
        this.f36747d = new Format.Builder().setContainerMimeType(MimeTypes.AUDIO_WAV).setSampleMimeType(str).setAverageBitrate(i15).setPeakBitrate(i15).setMaxInputSize(iMax).setChannelCount(iVar.f34308b).setSampleRate(i13).setPcmEncoding(i10).build();
    }

    @Override // y2.b
    public final void a(long j10) {
        this.f36749f = j10;
        this.f36750g = 0;
        this.f36751h = 0L;
    }

    @Override // y2.b
    public final boolean b(z zVar, long j10) {
        int i10;
        int i11;
        long j11 = j10;
        while (j11 > 0 && (i10 = this.f36750g) < (i11 = this.f36748e)) {
            int iSampleData = this.f36745b.sampleData((DataReader) zVar, (int) Math.min(i11 - i10, j11), true);
            if (iSampleData == -1) {
                j11 = 0;
            } else {
                this.f36750g += iSampleData;
                j11 -= (long) iSampleData;
            }
        }
        int i12 = this.f36746c.f34311e;
        int i13 = this.f36750g / i12;
        if (i13 > 0) {
            long jScaleLargeTimestamp = this.f36749f + Util.scaleLargeTimestamp(this.f36751h, 1000000L, r1.f34309c);
            int i14 = i13 * i12;
            int i15 = this.f36750g - i14;
            this.f36745b.sampleMetadata(jScaleLargeTimestamp, 1, i14, i15, null);
            this.f36751h += (long) i13;
            this.f36750g = i15;
        }
        return j11 <= 0;
    }

    @Override // y2.b
    public final void c(int i10, long j10) {
        f fVar = new f(this.f36746c, 1, i10, j10);
        this.f36744a.seekMap(fVar);
        z0 z0Var = this.f36745b;
        z0Var.format(this.f36747d);
        z0Var.durationUs(fVar.f36765e);
    }
}
