package B1;

import C3.E;
import C3.G;
import C3.W;
import L4.h;
import T0.F;
import T0.j;
import T0.m;
import T0.n;
import T0.o;
import android.util.Pair;
import java.io.EOFException;
import java.io.InterruptedIOException;
import java.util.List;
import n4.u0;
import x0.AbstractC1709a;
import x0.v;

/* JADX INFO: loaded from: classes.dex */
public final class d implements m {

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

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

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

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

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

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

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

    @Override // T0.m
    public final m c() {
        return this;
    }

    /* JADX WARN: Code restructure failed: missing block: B:53:0x018b, code lost:
    
        if (r12 != 65534) goto L54;
     */
    /* JADX WARN: Removed duplicated region for block: B:60:0x019e  */
    /* JADX WARN: Removed duplicated region for block: B:63:0x01b4  */
    @Override // T0.m
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int e(n nVar, h hVar) throws u0.F, EOFException, InterruptedIOException {
        byte[] bArr;
        int i;
        AbstractC1709a.k(this.f950b);
        int i5 = v.f18553a;
        int i8 = this.f951c;
        int iY = 4;
        if (i8 == 0) {
            AbstractC1709a.j(((j) nVar).f6428t == 0);
            int i9 = this.f954f;
            if (i9 != -1) {
                ((j) nVar).b(i9);
                this.f951c = 4;
                return 0;
            }
            j jVar = (j) nVar;
            if (!u0.f(jVar)) {
                throw u0.F.a(null, "Unsupported or unrecognized wav file type.");
            }
            jVar.b((int) (jVar.i() - jVar.f6428t));
            this.f951c = 1;
            return 0;
        }
        long j8 = -1;
        if (i8 == 1) {
            x0.o oVar = new x0.o(8);
            j jVar2 = (j) nVar;
            f fVarA = f.a(jVar2, oVar);
            if (fVarA.f961a != 1685272116) {
                jVar2.f6430v = 0;
            } else {
                jVar2.h(8, false);
                oVar.F(0);
                j jVar3 = (j) nVar;
                jVar3.f(oVar.f18539a, 0, 8, false);
                j8 = oVar.j();
                jVar3.b(((int) fVarA.f962b) + 8);
            }
            this.f952d = j8;
            this.f951c = 2;
            return 0;
        }
        if (i8 != 2) {
            if (i8 != 3) {
                if (i8 != 4) {
                    throw new IllegalStateException();
                }
                AbstractC1709a.j(this.f955g != -1);
                long j9 = this.f955g - ((j) nVar).f6428t;
                b bVar = this.f953e;
                bVar.getClass();
                return bVar.c((j) nVar, j9) ? -1 : 0;
            }
            ((j) nVar).f6430v = 0;
            j jVar4 = (j) nVar;
            f fVarA2 = u0.A(1684108385, jVar4, new x0.o(8));
            jVar4.b(8);
            Pair pairCreate = Pair.create(Long.valueOf(jVar4.f6428t), Long.valueOf(fVarA2.f962b));
            this.f954f = ((Long) pairCreate.first).intValue();
            long jLongValue = ((Long) pairCreate.second).longValue();
            long j10 = this.f952d;
            if (j10 != -1 && jLongValue == 4294967295L) {
                jLongValue = j10;
            }
            long j11 = ((long) this.f954f) + jLongValue;
            this.f955g = j11;
            long j12 = jVar4.f6427s;
            if (j12 != -1 && j11 > j12) {
                AbstractC1709a.B("WavExtractor", "Data exceeds input length: " + this.f955g + ", " + j12);
                this.f955g = j12;
            }
            b bVar2 = this.f953e;
            bVar2.getClass();
            bVar2.b(this.f955g, this.f954f);
            this.f951c = 4;
            return 0;
        }
        x0.o oVar2 = new x0.o(16);
        j jVar5 = (j) nVar;
        long j13 = u0.A(1718449184, jVar5, oVar2).f962b;
        AbstractC1709a.j(j13 >= 16);
        jVar5.f(oVar2.f18539a, 0, 16, false);
        oVar2.F(0);
        int iM = oVar2.m();
        int iM2 = oVar2.m();
        int iL = oVar2.l();
        oVar2.l();
        int iM3 = oVar2.m();
        int iM4 = oVar2.m();
        int i10 = ((int) j13) - 16;
        if (i10 > 0) {
            bArr = new byte[i10];
            ((j) nVar).f(bArr, 0, i10, false);
        } else {
            bArr = v.f18555c;
        }
        byte[] bArr2 = bArr;
        j jVar6 = (j) nVar;
        jVar6.b((int) (jVar6.i() - jVar6.f6428t));
        e eVar = new e(iM, iM2, iL, iM3, iM4, bArr2);
        if (iM == 17) {
            this.f953e = new a(this.f949a, this.f950b, eVar);
        } else if (iM == 6) {
            this.f953e = new c(this.f949a, this.f950b, eVar, "audio/g711-alaw", -1);
        } else if (iM == 7) {
            this.f953e = new c(this.f949a, this.f950b, eVar, "audio/g711-mlaw", -1);
        } else if (iM == 1) {
            iY = v.y(iM4);
            i = iY;
            if (i == 0) {
                throw u0.F.c("Unsupported WAV format type: " + iM);
            }
            this.f953e = new c(this.f949a, this.f950b, eVar, "audio/raw", i);
        } else {
            if (iM == 3) {
                if (iM4 == 32) {
                    i = iY;
                }
                if (i == 0) {
                }
            }
            i = 0;
            if (i == 0) {
            }
        }
        this.f951c = 3;
        return 0;
    }

    @Override // T0.m
    public final boolean f(n nVar) {
        return u0.f((j) nVar);
    }

    @Override // T0.m
    public final void i(long j8, long j9) {
        this.f951c = j8 == 0 ? 0 : 4;
        b bVar = this.f953e;
        if (bVar != null) {
            bVar.a(j9);
        }
    }

    @Override // T0.m
    public final void l(o oVar) {
        this.f949a = oVar;
        this.f950b = oVar.j(0, 1);
        oVar.h();
    }

    @Override // T0.m
    public final List m() {
        E e8 = G.f1197r;
        return W.f1225u;
    }

    @Override // T0.m
    public final void a() {
    }
}
