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

import android.util.Log;
import android.util.Pair;
import com.google.android.exoplayer2.ParserException;
import java.io.EOFException;
import java.util.List;
import p000.p001.p002.p003.p004.C0567;
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.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.InterfaceC3575;
import p138.p176.p177.p190.p239.C4140;
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 C3696 implements InterfaceC3561 {

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

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

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

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

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public long f11391 = -1;

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ೲ.ޞ.֏$֏, reason: contains not printable characters */
    public static final class C3697 implements InterfaceC3698 {

        /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
        public static final int[] f11392 = {-1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8};

        /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
        public static final int[] f11393 = {7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767};

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final InterfaceC3562 f11394;

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

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public final C3700 f11396;

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

        /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
        public final byte[] f11398;

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final C4140 f11399;

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

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public final C3431 f11401;

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

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

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

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

        public C3697(InterfaceC3562 interfaceC3562, InterfaceC3575 interfaceC3575, C3700 c3700) throws ParserException {
            this.f11394 = interfaceC3562;
            this.f11395 = interfaceC3575;
            this.f11396 = c3700;
            this.f11400 = Math.max(1, c3700.f11416 / 10);
            byte[] bArr = c3700.f11419;
            int length = bArr.length;
            int i = 0 + 1;
            byte b = bArr[0];
            int i2 = i + 1;
            byte b2 = bArr[i];
            int i3 = i2 + 1;
            int i4 = ((bArr[i3] & 255) << 8) | (bArr[i2] & 255);
            this.f11397 = i4;
            int i5 = c3700.f11415;
            int i6 = (((c3700.f11417 - (i5 * 4)) * 8) / (c3700.f11418 * i5)) + 1;
            if (i4 != i6) {
                StringBuilder sbM4896 = C2803.m4896("Expected frames per block: ", i6, "; got: ");
                sbM4896.append(this.f11397);
                throw new ParserException(sbM4896.toString());
            }
            int iM6742 = C4150.m6742(this.f11400, i4);
            this.f11398 = new byte[c3700.f11417 * iM6742];
            this.f11399 = new C4140(this.f11397 * 2 * i5 * iM6742);
            int i7 = c3700.f11416;
            this.f11401 = C3431.m5584((String) null, "audio/raw", (String) null, ((c3700.f11417 * i7) * 8) / this.f11397, this.f11400 * 2 * i5, c3700.f11415, i7, 2, (List<byte[]>) null, (C3526) null, 0, (String) null);
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final int m6038(int i) {
            return i / (this.f11396.f11415 * 2);
        }

        @Override // p138.p176.p177.p190.p198.p208.C3696.InterfaceC3698
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public void mo6039(int i, long j) {
            this.f11394.mo5893(new C3702(this.f11396, this.f11397, i, j));
            this.f11395.mo5884(this.f11401);
        }

        @Override // p138.p176.p177.p190.p198.p208.C3696.InterfaceC3698
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public void mo6040(long j) {
            this.f11402 = 0;
            this.f11403 = j;
            this.f11404 = 0;
            this.f11405 = 0L;
        }

        /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:11:0x003b -> B:4:0x001f). Please report as a decompilation issue!!! */
        /*  JADX ERROR: JadxRuntimeException in pass: RegionMakerVisitor
            jadx.core.utils.exceptions.JadxRuntimeException: Not found exit edge by exit block: B:7:0x0023
            	at jadx.core.dex.visitors.regions.maker.LoopRegionMaker.checkLoopExits(LoopRegionMaker.java:226)
            	at jadx.core.dex.visitors.regions.maker.LoopRegionMaker.makeLoopRegion(LoopRegionMaker.java:196)
            	at jadx.core.dex.visitors.regions.maker.LoopRegionMaker.process(LoopRegionMaker.java:63)
            	at jadx.core.dex.visitors.regions.maker.RegionMaker.traverse(RegionMaker.java:89)
            	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeRegion(RegionMaker.java:66)
            	at jadx.core.dex.visitors.regions.maker.IfRegionMaker.process(IfRegionMaker.java:96)
            	at jadx.core.dex.visitors.regions.maker.RegionMaker.traverse(RegionMaker.java:106)
            	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeRegion(RegionMaker.java:66)
            	at jadx.core.dex.visitors.regions.maker.LoopRegionMaker.process(LoopRegionMaker.java:125)
            	at jadx.core.dex.visitors.regions.maker.RegionMaker.traverse(RegionMaker.java:89)
            	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeRegion(RegionMaker.java:66)
            	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeMthRegion(RegionMaker.java:48)
            	at jadx.core.dex.visitors.regions.RegionMakerVisitor.visit(RegionMakerVisitor.java:25)
            */
        @Override // p138.p176.p177.p190.p198.p208.C3696.InterfaceC3698
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public boolean mo6041(p138.p176.p177.p190.p198.C3558 r20, long r21) {
            /*
                Method dump skipped, instruction units count: 360
                To view this dump add '--comments-level debug' option
            */
            throw new UnsupportedOperationException("Method not decompiled: p138.p176.p177.p190.p198.p208.C3696.C3697.mo6041(ދ.ހ.֏.ؠ.ೲ.ނ, long):boolean");
        }

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final void m6042(int i) {
            long jM6797 = this.f11403 + C4150.m6797(this.f11405, 1000000L, this.f11396.f11416);
            int i2 = i * 2 * this.f11396.f11415;
            this.f11395.mo5883(jM6797, 1, i2, this.f11404 - i2, null);
            this.f11405 += (long) i;
            this.f11404 -= i2;
        }
    }

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ೲ.ޞ.֏$ؠ, reason: contains not printable characters */
    public interface InterfaceC3698 {
        /* JADX INFO: renamed from: ֏ */
        void mo6039(int i, long j);

        /* JADX INFO: renamed from: ֏ */
        void mo6040(long j);

        /* JADX INFO: renamed from: ֏ */
        boolean mo6041(C3558 c3558, long j);
    }

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ೲ.ޞ.֏$ހ, reason: contains not printable characters */
    public static final class C3699 implements InterfaceC3698 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final InterfaceC3562 f11406;

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

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public final C3700 f11408;

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public final C3431 f11409;

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

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

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

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

        public C3699(InterfaceC3562 interfaceC3562, InterfaceC3575 interfaceC3575, C3700 c3700, String str, int i) throws ParserException {
            this.f11406 = interfaceC3562;
            this.f11407 = interfaceC3575;
            this.f11408 = c3700;
            int i2 = (c3700.f11415 * c3700.f11418) / 8;
            if (c3700.f11417 != i2) {
                StringBuilder sbM4896 = C2803.m4896("Expected block size: ", i2, "; got: ");
                sbM4896.append(c3700.f11417);
                throw new ParserException(sbM4896.toString());
            }
            int iMax = Math.max(i2, (c3700.f11416 * i2) / 10);
            this.f11410 = iMax;
            int i3 = c3700.f11416;
            this.f11409 = C3431.m5584((String) null, str, (String) null, i2 * i3 * 8, iMax, c3700.f11415, i3, i, (List<byte[]>) null, (C3526) null, 0, (String) null);
        }

        @Override // p138.p176.p177.p190.p198.p208.C3696.InterfaceC3698
        /* JADX INFO: renamed from: ֏ */
        public void mo6039(int i, long j) {
            this.f11406.mo5893(new C3702(this.f11408, 1, i, j));
            this.f11407.mo5884(this.f11409);
        }

        @Override // p138.p176.p177.p190.p198.p208.C3696.InterfaceC3698
        /* JADX INFO: renamed from: ֏ */
        public void mo6040(long j) {
            this.f11411 = j;
            this.f11412 = 0;
            this.f11413 = 0L;
        }

        @Override // p138.p176.p177.p190.p198.p208.C3696.InterfaceC3698
        /* JADX INFO: renamed from: ֏ */
        public boolean mo6041(C3558 c3558, long j) {
            int i;
            int i2;
            long j2 = j;
            while (j2 > 0 && (i = this.f11412) < (i2 = this.f11410)) {
                int iMo5882 = this.f11407.mo5882(c3558, (int) Math.min(i2 - i, j2), true);
                if (iMo5882 == -1) {
                    j2 = 0;
                } else {
                    this.f11412 += iMo5882;
                    j2 -= (long) iMo5882;
                }
            }
            int i3 = this.f11408.f11417;
            int i4 = this.f11412 / i3;
            if (i4 > 0) {
                long jM6797 = this.f11411 + C4150.m6797(this.f11413, 1000000L, r1.f11416);
                int i5 = i4 * i3;
                int i6 = this.f11412 - i5;
                this.f11407.mo5883(jM6797, 1, i5, i6, null);
                this.f11413 += (long) i4;
                this.f11412 = i6;
            }
            return j2 <= 0;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:29:0x006d  */
    /* JADX WARN: Removed duplicated region for block: B:30:0x007c  */
    @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 InterruptedException, ParserException, EOFException {
        int iM6741;
        int i;
        C0567.m1925(this.f11388);
        C4150.m6755(this.f11387);
        if (this.f11389 == null) {
            C3700 c3700M1871 = C0567.m1871(c3558);
            if (c3700M1871 == null) {
                throw new ParserException("Unsupported or unrecognized wav header.");
            }
            int i2 = c3700M1871.f11414;
            if (i2 == 17) {
                this.f11389 = new C3697(this.f11387, this.f11388, c3700M1871);
            } else if (i2 == 6) {
                this.f11389 = new C3699(this.f11387, this.f11388, c3700M1871, "audio/g711-alaw", -1);
            } else if (i2 == 7) {
                this.f11389 = new C3699(this.f11387, this.f11388, c3700M1871, "audio/g711-mlaw", -1);
            } else {
                int i3 = c3700M1871.f11418;
                if (i2 == 1) {
                    iM6741 = C4150.m6741(i3);
                    i = iM6741;
                    if (i != 0) {
                        StringBuilder sbM4889 = C2803.m4889("Unsupported WAV format type: ");
                        sbM4889.append(c3700M1871.f11414);
                        throw new ParserException(sbM4889.toString());
                    }
                    this.f11389 = new C3699(this.f11387, this.f11388, c3700M1871, "audio/raw", i);
                } else if (i2 != 3) {
                    if (i2 != 65534) {
                        i = 0;
                        if (i != 0) {
                        }
                    }
                    iM6741 = C4150.m6741(i3);
                    i = iM6741;
                    if (i != 0) {
                    }
                } else {
                    iM6741 = i3 == 32 ? 4 : 0;
                    i = iM6741;
                    if (i != 0) {
                    }
                }
            }
        }
        int i4 = this.f11390;
        if (i4 == -1) {
            if (c3558 == null) {
                throw null;
            }
            c3558.f10565 = 0;
            C4140 c4140 = new C4140(8);
            C3701 c3701M6043 = C3701.m6043(c3558, c4140);
            while (true) {
                int i5 = c3701M6043.f11420;
                if (i5 != 1684108385) {
                    if (i5 != 1380533830 && i5 != 1718449184) {
                        StringBuilder sbM48892 = C2803.m4889("Ignoring unknown WAV chunk: ");
                        sbM48892.append(c3701M6043.f11420);
                        Log.w("WavHeaderReader", sbM48892.toString());
                    }
                    long j = c3701M6043.f11421 + 8;
                    if (c3701M6043.f11420 == 1380533830) {
                        j = 12;
                    }
                    if (j > 2147483647L) {
                        StringBuilder sbM48893 = C2803.m4889("Chunk is too large (~2GB+) to skip; id: ");
                        sbM48893.append(c3701M6043.f11420);
                        throw new ParserException(sbM48893.toString());
                    }
                    c3558.m5878((int) j);
                    c3701M6043 = C3701.m6043(c3558, c4140);
                } else {
                    c3558.m5878(8);
                    long j2 = c3558.f10563;
                    long j3 = c3701M6043.f11421 + j2;
                    long j4 = c3558.f10562;
                    if (j4 != -1 && j3 > j4) {
                        Log.w("WavHeaderReader", "Data exceeds input length: " + j3 + ", " + j4);
                        j3 = j4;
                    }
                    Pair pairCreate = Pair.create(Long.valueOf(j2), Long.valueOf(j3));
                    this.f11390 = ((Long) pairCreate.first).intValue();
                    long jLongValue = ((Long) pairCreate.second).longValue();
                    this.f11391 = jLongValue;
                    this.f11389.mo6039(this.f11390, jLongValue);
                }
            }
        } else if (c3558.f10563 == 0) {
            c3558.m5878(i4);
        }
        C0567.m1932(this.f11391 != -1);
        return this.f11389.mo6041(c3558, this.f11391 - c3558.f10563) ? -1 : 0;
    }

    @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) {
        InterfaceC3698 interfaceC3698 = this.f11389;
        if (interfaceC3698 != null) {
            interfaceC3698.mo6040(j2);
        }
    }

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

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