package p138.p176.p177.p190.p198.p199;

import com.google.android.exoplayer2.ParserException;
import java.io.EOFException;
import java.util.Arrays;
import java.util.List;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p190.C3431;
import p138.p176.p177.p190.p194.C3526;
import p138.p176.p177.p190.p198.C3557;
import p138.p176.p177.p190.p198.C3558;
import p138.p176.p177.p190.p198.C3570;
import p138.p176.p177.p190.p198.InterfaceC3561;
import p138.p176.p177.p190.p198.InterfaceC3562;
import p138.p176.p177.p190.p198.InterfaceC3571;
import p138.p176.p177.p190.p198.InterfaceC3575;
import p138.p176.p177.p190.p239.C4150;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ೲ.ޕ.֏, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C3581 implements InterfaceC3561 {

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public static final int[] f10615 = {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[] f10616 = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 1, 1, 1, 1, 1, 1};

    /* JADX INFO: renamed from: ޏ, reason: contains not printable characters */
    public static final byte[] f10617 = C4150.m6799("#!AMR\n");

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public static final byte[] f10618 = C4150.m6799("#!AMR-WB\n");

    /* JADX INFO: renamed from: ޑ, reason: contains not printable characters */
    public static final int f10619 = f10616[8];

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final int f10621;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public boolean f10622;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public long f10623;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public int f10624;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public int f10625;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public boolean f10626;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public long f10627;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public int f10629;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public long f10630;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public InterfaceC3562 f10631;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public InterfaceC3575 f10632;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public InterfaceC3571 f10633;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public boolean f10634;

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final byte[] f10620 = new byte[1];

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public int f10628 = -1;

    public C3581(int i) {
        this.f10621 = i;
    }

    /* JADX WARN: Removed duplicated region for block: B:31:0x007d  */
    /* JADX WARN: Removed duplicated region for block: B:32:0x007f  */
    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public int mo5886(C3558 c3558, C3570 c3570) throws ParserException {
        int i;
        int i2;
        int iMo5882;
        if (c3558.f10563 == 0 && !m5909(c3558)) {
            throw new ParserException("Could not find AMR header.");
        }
        if (!this.f10634) {
            this.f10634 = true;
            this.f10632.mo5884(C3431.m5584((String) null, this.f10622 ? "audio/amr-wb" : "audio/3gpp", (String) null, -1, f10619, 1, this.f10622 ? 16000 : 8000, -1, (List<byte[]>) null, (C3526) null, 0, (String) null));
        }
        if (this.f10625 == 0) {
            try {
                int iM5908 = m5908(c3558);
                this.f10624 = iM5908;
                this.f10625 = iM5908;
                if (this.f10628 == -1) {
                    this.f10627 = c3558.f10563;
                    this.f10628 = iM5908;
                }
                if (this.f10628 == this.f10624) {
                    this.f10629++;
                }
                iMo5882 = this.f10632.mo5882(c3558, this.f10625, true);
            } catch (EOFException unused) {
            }
            if (iMo5882 != -1) {
                i = -1;
            } else {
                int i3 = this.f10625 - iMo5882;
                this.f10625 = i3;
                i = 0;
                if (i3 <= 0) {
                    this.f10632.mo5883(this.f10630 + this.f10623, 1, this.f10624, 0, null);
                    this.f10623 += 20000;
                }
            }
        } else {
            iMo5882 = this.f10632.mo5882(c3558, this.f10625, true);
            if (iMo5882 != -1) {
            }
        }
        long j = c3558.f10562;
        if (!this.f10626) {
            if ((this.f10621 & 1) == 0 || j == -1 || !((i2 = this.f10628) == -1 || i2 == this.f10624)) {
                InterfaceC3571.C3573 c3573 = new InterfaceC3571.C3573(-9223372036854775807L, 0L);
                this.f10633 = c3573;
                this.f10631.mo5893(c3573);
                this.f10626 = true;
            } else if (this.f10629 >= 20 || i == -1) {
                int i4 = this.f10628;
                C3557 c3557 = new C3557(j, this.f10627, (int) ((((long) (i4 * 8)) * 1000000) / 20000), i4);
                this.f10633 = c3557;
                this.f10631.mo5893(c3557);
                this.f10626 = true;
            }
        }
        return i;
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public void mo5887() {
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public void mo5888(long j, long j2) {
        this.f10623 = 0L;
        this.f10624 = 0;
        this.f10625 = 0;
        if (j != 0) {
            InterfaceC3571 interfaceC3571 = this.f10633;
            if (interfaceC3571 instanceof C3557) {
                C3557 c3557 = (C3557) interfaceC3571;
                this.f10630 = C3557.m5868(j, c3557.f10555, c3557.f10558);
                return;
            }
        }
        this.f10630 = 0L;
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public void mo5889(InterfaceC3562 interfaceC3562) {
        this.f10631 = interfaceC3562;
        this.f10632 = interfaceC3562.mo5891(0, 1);
        interfaceC3562.mo5892();
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public boolean mo5890(C3558 c3558) {
        return m5909(c3558);
    }

    /* JADX WARN: Removed duplicated region for block: B:25:0x003c  */
    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int m5908(C3558 c3558) throws ParserException {
        boolean z = false;
        c3558.f10565 = 0;
        c3558.m5875(this.f10620, 0, 1, false);
        byte b = this.f10620[0];
        if ((b & 131) > 0) {
            throw new ParserException(C2803.m4871("Invalid padding bits for frame header ", (int) b));
        }
        int i = (b >> 3) & 15;
        if (i >= 0 && i <= 15) {
            if (this.f10622 && (i < 10 || i > 13)) {
                z = true;
            } else {
                if (!this.f10622 && (i < 12 || i > 14)) {
                }
            }
        }
        if (z) {
            return this.f10622 ? f10616[i] : f10615[i];
        }
        StringBuilder sbM4889 = C2803.m4889("Illegal AMR ");
        sbM4889.append(this.f10622 ? "WB" : "NB");
        sbM4889.append(" frame type ");
        sbM4889.append(i);
        throw new ParserException(sbM4889.toString());
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final boolean m5909(C3558 c3558) throws InterruptedException, EOFException {
        byte[] bArr = f10617;
        c3558.f10565 = 0;
        byte[] bArr2 = new byte[bArr.length];
        c3558.m5875(bArr2, 0, bArr.length, false);
        if (Arrays.equals(bArr2, bArr)) {
            this.f10622 = false;
            c3558.m5878(f10617.length);
            return true;
        }
        byte[] bArr3 = f10618;
        c3558.f10565 = 0;
        byte[] bArr4 = new byte[bArr3.length];
        c3558.m5875(bArr4, 0, bArr3.length, false);
        if (!Arrays.equals(bArr4, bArr3)) {
            return false;
        }
        this.f10622 = true;
        c3558.m5878(f10618.length);
        return true;
    }
}
