package defpackage;

import androidx.media3.common.ParserException;
import java.io.EOFException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

/* JADX INFO: renamed from: ᵥᵭᵡ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C3528 implements InterfaceC4291 {

    /* JADX INFO: renamed from: ˉᵲ, reason: contains not printable characters */
    public static final byte[] f13541;

    /* JADX INFO: renamed from: ˏːˆ, reason: contains not printable characters */
    public static final byte[] f13543;

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final C0406 f13545;

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public int f13546;

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public boolean f13547;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public boolean f13548;

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public InterfaceC5517 f13549;

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public boolean f13550;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public int f13551;

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public long f13552;

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public InterfaceC5226 f13553;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public InterfaceC4550 f13554;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final byte[] f13555 = new byte[1];

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public int f13556 = -1;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public InterfaceC5226 f13557;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public long f13558;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public long f13559;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public int f13560;

    /* JADX INFO: renamed from: ᵱʡˏ, reason: contains not printable characters */
    public static final int[] f13544 = {13, 14, 16, 18, 20, 21, 27, 32, 6, 7, 6, 6, 1, 1, 1, 1};

    /* JADX INFO: renamed from: ˊᵙᵾᵲ, reason: contains not printable characters */
    public static final int[] f13542 = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 1, 1, 1, 1, 1, 1};

    static {
        String str = AbstractC0956.f4222;
        Charset charset = StandardCharsets.UTF_8;
        f13541 = "#!AMR\n".getBytes(charset);
        f13543 = "#!AMR-WB\n".getBytes(charset);
    }

    public C3528() {
        C0406 c0406 = new C0406();
        this.f13545 = c0406;
        this.f13553 = c0406;
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ʽˈˋ */
    public final void mo1252(long j, long j2) {
        this.f13558 = 0L;
        this.f13551 = 0;
        this.f13560 = 0;
        this.f13552 = j2;
        InterfaceC5517 interfaceC5517 = this.f13549;
        if (!(interfaceC5517 instanceof C2665)) {
            if (j == 0 || !(interfaceC5517 instanceof C5417)) {
                this.f13559 = 0L;
                return;
            } else {
                C5417 c5417 = (C5417) interfaceC5517;
                this.f13559 = (Math.max(0L, j - c5417.f20552) * 8000000) / ((long) c5417.f20556);
                return;
            }
        }
        C2665 c2665 = (C2665) interfaceC5517;
        C1785 c1785 = c2665.f10310;
        long jM4933 = c1785.f7163 == 0 ? -9223372036854775807L : c1785.m4933(AbstractC0956.m3268(c2665.f10312, j));
        this.f13559 = jM4933;
        if (Math.abs(this.f13552 - jM4933) < 20000) {
            return;
        }
        this.f13547 = true;
        this.f13553 = this.f13545;
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final int m8038(InterfaceC5206 interfaceC5206) throws ParserException {
        boolean z;
        interfaceC5206.mo4698();
        byte[] bArr = this.f13555;
        interfaceC5206.mo4701(bArr, 0, 1);
        byte b = bArr[0];
        if ((b & 131) > 0) {
            throw ParserException.m357("Invalid padding bits for frame header " + ((int) b), null);
        }
        int i = (b >> 3) & 15;
        if (i >= 0 && i <= 15 && (((z = this.f13548) && (i < 10 || i > 13)) || (!z && (i < 12 || i > 14)))) {
            return z ? f13542[i] : f13544[i];
        }
        StringBuilder sb = new StringBuilder("Illegal AMR ");
        sb.append(this.f13548 ? "WB" : "NB");
        sb.append(" frame type ");
        sb.append(i);
        throw ParserException.m357(sb.toString(), null);
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ːˏᵟᵯ */
    public final InterfaceC4291 mo1254() {
        return this;
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵨᵣ */
    public final boolean mo1255(InterfaceC5206 interfaceC5206) {
        return m8039(interfaceC5206);
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final void mo1256() {
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵵᵽ */
    public final void mo1257(InterfaceC4550 interfaceC4550) {
        this.f13554 = interfaceC4550;
        InterfaceC5226 interfaceC5226Mo2743 = interfaceC4550.mo2743(0, 1);
        this.f13557 = interfaceC5226Mo2743;
        this.f13553 = interfaceC5226Mo2743;
        interfaceC4550.mo2740();
    }

    /* JADX WARN: Removed duplicated region for block: B:54:0x00eb A[PHI: r4
      0x00eb: PHI (r4v1 ᵻᵗᵻ) = (r4v0 ᵻᵗᵻ), (r4v6 ᵻᵗᵻ) binds: [B:53:0x00e9, B:56:0x00f7] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:58:0x00fa  */
    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵷᵺʾᵖ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int mo1258(InterfaceC5206 interfaceC5206, C2669 c2669) throws ParserException {
        InterfaceC5206 interfaceC52062;
        int iMo1744;
        this.f13557.getClass();
        String str = AbstractC0956.f4222;
        if (interfaceC5206.getPosition() == 0 && !m8039(interfaceC5206)) {
            throw ParserException.m357("Could not find AMR header.", null);
        }
        if (!this.f13550) {
            this.f13550 = true;
            boolean z = this.f13548;
            String str2 = z ? "audio/amr-wb" : "audio/amr";
            String str3 = z ? "audio/amr-wb" : "audio/3gpp";
            int i = z ? 16000 : 8000;
            int i2 = z ? f13542[8] : f13544[7];
            InterfaceC5226 interfaceC5226 = this.f13557;
            C4753 c4753 = new C4753();
            c4753.f18111 = AbstractC4208.m9132(str2);
            c4753.f18101 = AbstractC4208.m9132(str3);
            c4753.f18116 = i2;
            c4753.f18090 = 1;
            c4753.f18113 = i;
            AbstractC0659.m2415(c4753, interfaceC5226);
        }
        int i3 = 0;
        if (this.f13560 == 0) {
            try {
                int iM8038 = m8038(interfaceC5206);
                this.f13551 = iM8038;
                this.f13560 = iM8038;
                if (this.f13556 == -1) {
                    interfaceC5206.getPosition();
                    this.f13556 = this.f13551;
                }
                if (this.f13556 == this.f13551) {
                    this.f13546++;
                }
                InterfaceC5517 interfaceC5517 = this.f13549;
                if (interfaceC5517 instanceof C2665) {
                    C2665 c2665 = (C2665) interfaceC5517;
                    long j = this.f13559 + this.f13558 + 20000;
                    long position = interfaceC5206.getPosition() + ((long) this.f13551);
                    C1785 c1785 = c2665.f10310;
                    int i4 = c1785.f7163;
                    if (i4 == 0 || j - c1785.m4933(i4 - 1) >= 100000) {
                        C1785 c17852 = c2665.f10312;
                        C1785 c17853 = c2665.f10310;
                        if (c17853.f7163 == 0 && j > 0) {
                            c17852.m4932(0L);
                            c17853.m4932(0L);
                        }
                        c17852.m4932(position);
                        c17853.m4932(j);
                    }
                    if (this.f13547 && Math.abs(this.f13552 - j) < 20000) {
                        this.f13547 = false;
                        this.f13553 = this.f13557;
                    }
                }
                interfaceC52062 = interfaceC5206;
                iMo1744 = this.f13553.mo1744(interfaceC52062, this.f13560, true);
            } catch (EOFException unused) {
                interfaceC52062 = interfaceC5206;
            }
            if (iMo1744 != -1) {
                i3 = -1;
            } else {
                int i5 = this.f13560 - iMo1744;
                this.f13560 = i5;
                if (i5 <= 0) {
                    this.f13553.mo1741(this.f13558 + this.f13559, 1, this.f13551, 0, null);
                    this.f13558 += 20000;
                }
            }
        } else {
            interfaceC52062 = interfaceC5206;
            iMo1744 = this.f13553.mo1744(interfaceC52062, this.f13560, true);
            if (iMo1744 != -1) {
            }
        }
        interfaceC52062.getLength();
        if (this.f13549 == null) {
            C3782 c3782 = new C3782(-9223372036854775807L);
            this.f13549 = c3782;
            this.f13554.mo2739(c3782);
        }
        if (i3 == -1) {
            InterfaceC5517 interfaceC55172 = this.f13549;
            if (interfaceC55172 instanceof C2665) {
                long j2 = this.f13559 + this.f13558;
                ((C2665) interfaceC55172).f10311 = j2;
                this.f13554.mo2739(interfaceC55172);
                this.f13557.mo1743(j2);
            }
        }
        return i3;
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final boolean m8039(InterfaceC5206 interfaceC5206) {
        interfaceC5206.mo4698();
        byte[] bArr = f13541;
        byte[] bArr2 = new byte[bArr.length];
        interfaceC5206.mo4701(bArr2, 0, bArr.length);
        if (Arrays.equals(bArr2, bArr)) {
            this.f13548 = false;
            interfaceC5206.mo4700(bArr.length);
            return true;
        }
        interfaceC5206.mo4698();
        byte[] bArr3 = f13543;
        byte[] bArr4 = new byte[bArr3.length];
        interfaceC5206.mo4701(bArr4, 0, bArr3.length);
        if (!Arrays.equals(bArr4, bArr3)) {
            return false;
        }
        this.f13548 = true;
        interfaceC5206.mo4700(bArr3.length);
        return true;
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵻˈᵦʼ */
    public final List mo1259() {
        C2822 c2822 = AbstractC4509.f17159;
        return C2598.f10048;
    }
}
