package y1;

import androidx.media3.common.ParserException;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.extractor.b0;
import androidx.media3.extractor.i0;
import androidx.media3.extractor.p0;
import androidx.media3.extractor.r0;
import androidx.media3.extractor.v;
import androidx.media3.extractor.y;
import androidx.media3.extractor.z;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ParsableByteArray f36705a = new ParsableByteArray(4);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ParsableByteArray f36706b = new ParsableByteArray(9);

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final ParsableByteArray f36708d = new ParsableByteArray();

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

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public a f36719o;

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

    public b() {
        c cVar = new c(new v());
        cVar.f36721b = -9223372036854775807L;
        cVar.f36722c = new long[0];
        cVar.f36723d = new long[0];
        this.f36709e = cVar;
        this.f36711g = 1;
    }

    public final ParsableByteArray a(z zVar) {
        int i10 = this.f36716l;
        ParsableByteArray parsableByteArray = this.f36708d;
        if (i10 > parsableByteArray.capacity()) {
            parsableByteArray.reset(new byte[Math.max(parsableByteArray.capacity() * 2, this.f36716l)], 0);
        } else {
            parsableByteArray.setPosition(0);
        }
        parsableByteArray.setLimit(this.f36716l);
        zVar.readFully(parsableByteArray.getData(), 0, this.f36716l);
        return parsableByteArray;
    }

    @Override // androidx.media3.extractor.y
    public final void init(b0 b0Var) {
        this.f36710f = b0Var;
    }

    /* JADX WARN: Removed duplicated region for block: B:50:0x00c9  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x00cd  */
    /* JADX WARN: Removed duplicated region for block: B:86:0x00d7 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:96:0x0009 A[SYNTHETIC] */
    @Override // androidx.media3.extractor.y
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int read(z zVar, r0 r0Var) throws ParserException {
        boolean zY;
        boolean z10;
        Assertions.checkStateNotNull(this.f36710f);
        while (true) {
            int i10 = this.f36711g;
            if (i10 == 1) {
                ParsableByteArray parsableByteArray = this.f36706b;
                if (!zVar.b(parsableByteArray.getData(), 0, 9, true)) {
                    return -1;
                }
                parsableByteArray.setPosition(0);
                parsableByteArray.skipBytes(4);
                int unsignedByte = parsableByteArray.readUnsignedByte();
                boolean z11 = (unsignedByte & 4) != 0;
                boolean z12 = (unsignedByte & 1) != 0;
                if (z11 && this.f36719o == null) {
                    this.f36719o = new a(this.f36710f.track(8, 1));
                }
                if (z12 && this.f36720p == null) {
                    this.f36720p = new d(this.f36710f.track(9, 2));
                }
                this.f36710f.endTracks();
                this.f36714j = parsableByteArray.readInt() - 5;
                this.f36711g = 2;
            } else if (i10 == 2) {
                zVar.k(this.f36714j);
                this.f36714j = 0;
                this.f36711g = 3;
            } else if (i10 == 3) {
                ParsableByteArray parsableByteArray2 = this.f36707c;
                if (!zVar.b(parsableByteArray2.getData(), 0, 11, true)) {
                    return -1;
                }
                parsableByteArray2.setPosition(0);
                this.f36715k = parsableByteArray2.readUnsignedByte();
                this.f36716l = parsableByteArray2.readUnsignedInt24();
                this.f36717m = parsableByteArray2.readUnsignedInt24();
                this.f36717m = (((long) (parsableByteArray2.readUnsignedByte() << 24)) | this.f36717m) * 1000;
                parsableByteArray2.skipBytes(3);
                this.f36711g = 4;
            } else {
                if (i10 != 4) {
                    throw new IllegalStateException();
                }
                boolean z13 = this.f36712h;
                c cVar = this.f36709e;
                long j10 = z13 ? this.f36713i + this.f36717m : cVar.f36721b == -9223372036854775807L ? 0L : this.f36717m;
                int i11 = this.f36715k;
                if (i11 != 8 || this.f36719o == null) {
                    if (i11 == 9 && this.f36720p != null) {
                        if (!this.f36718n) {
                            this.f36710f.seekMap(new i0(-9223372036854775807L));
                            this.f36718n = true;
                        }
                        d dVar = this.f36720p;
                        ParsableByteArray parsableByteArrayA = a(zVar);
                        if (dVar.x(parsableByteArrayA) && dVar.y(parsableByteArrayA, j10)) {
                            zY = true;
                        }
                    } else if (i11 != 18 || this.f36718n) {
                        zVar.k(this.f36716l);
                        zY = false;
                        z10 = false;
                        if (!this.f36712h && zY) {
                            this.f36712h = true;
                            this.f36713i = cVar.f36721b != -9223372036854775807L ? -this.f36717m : 0L;
                        }
                        this.f36714j = 4;
                        this.f36711g = 2;
                        if (!z10) {
                            return 0;
                        }
                    } else {
                        ParsableByteArray parsableByteArrayA2 = a(zVar);
                        cVar.getClass();
                        cVar.x(parsableByteArrayA2, j10);
                        long j11 = cVar.f36721b;
                        if (j11 != -9223372036854775807L) {
                            this.f36710f.seekMap(new p0(j11, cVar.f36723d, cVar.f36722c));
                            this.f36718n = true;
                        }
                    }
                    zY = false;
                } else {
                    if (!this.f36718n) {
                        this.f36710f.seekMap(new i0(-9223372036854775807L));
                        this.f36718n = true;
                    }
                    a aVar = this.f36719o;
                    ParsableByteArray parsableByteArrayA3 = a(zVar);
                    aVar.x(parsableByteArrayA3);
                    zY = aVar.y(parsableByteArrayA3, j10);
                }
                z10 = true;
                if (!this.f36712h) {
                    this.f36712h = true;
                    this.f36713i = cVar.f36721b != -9223372036854775807L ? -this.f36717m : 0L;
                }
                this.f36714j = 4;
                this.f36711g = 2;
                if (!z10) {
                }
            }
        }
    }

    @Override // androidx.media3.extractor.y
    public final void release() {
    }

    @Override // androidx.media3.extractor.y
    public final void seek(long j10, long j11) {
        if (j10 == 0) {
            this.f36711g = 1;
            this.f36712h = false;
        } else {
            this.f36711g = 3;
        }
        this.f36714j = 0;
    }

    @Override // androidx.media3.extractor.y
    public final boolean sniff(z zVar) {
        ParsableByteArray parsableByteArray = this.f36705a;
        zVar.a(0, 3, parsableByteArray.getData());
        parsableByteArray.setPosition(0);
        if (parsableByteArray.readUnsignedInt24() != 4607062) {
            return false;
        }
        zVar.a(0, 2, parsableByteArray.getData());
        parsableByteArray.setPosition(0);
        if ((parsableByteArray.readUnsignedShort() & 250) != 0) {
            return false;
        }
        zVar.a(0, 4, parsableByteArray.getData());
        parsableByteArray.setPosition(0);
        int i10 = parsableByteArray.readInt();
        zVar.j();
        zVar.h(i10);
        zVar.a(0, 4, parsableByteArray.getData());
        parsableByteArray.setPosition(0);
        return parsableByteArray.readInt() == 0;
    }
}
