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

import com.google.android.exoplayer2.ParserException;
import java.io.EOFException;
import p000.p001.p002.p003.p004.C0567;
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.p207.InterfaceC3690;
import p138.p176.p177.p190.p239.C4139;
import p138.p176.p177.p190.p239.C4140;

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final C3656 f11093 = new C3656(true, null);

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final C4140 f11094 = new C4140(2048);

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

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

    public C3655(int i) {
        this.f11092 = i;
        C4140 c4140 = new C4140(10);
        this.f11095 = c4140;
        this.f11096 = new C4139(c4140.f13227);
    }

    /* JADX WARN: Removed duplicated region for block: B:64:0x00ee  */
    @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 {
        long j = c3558.f10562;
        boolean z = ((this.f11092 & 1) == 0 || j == -1) ? false : true;
        if (z && !this.f11101) {
            this.f11100 = -1;
            c3558.f10565 = 0;
            if (c3558.f10563 == 0) {
                m6002(c3558);
            }
            long j2 = 0;
            int i = 0;
            while (true) {
                try {
                    if (!c3558.m5875(this.f11095.f13227, 0, 2, true)) {
                        break;
                    }
                    this.f11095.m6693(0);
                    if (!C3656.m6003(this.f11095.m6707())) {
                        i = 0;
                        break;
                    }
                    if (!c3558.m5875(this.f11095.f13227, 0, 4, true)) {
                        break;
                    }
                    this.f11096.m6672(14);
                    int iM6667 = this.f11096.m6667(13);
                    if (iM6667 <= 6) {
                        this.f11101 = true;
                        throw new ParserException("Malformed ADTS stream");
                    }
                    j2 += (long) iM6667;
                    i++;
                    if (i != 1000 && c3558.m5874(iM6667 - 6, true)) {
                    }
                } catch (EOFException unused) {
                }
            }
            c3558.f10565 = 0;
            if (i > 0) {
                this.f11100 = (int) (j2 / ((long) i));
            } else {
                this.f11100 = -1;
            }
            this.f11101 = true;
        }
        int iM5870 = c3558.m5870(this.f11094.f13227, 0, 2048);
        boolean z2 = iM5870 == -1;
        if (!this.f11103) {
            boolean z3 = z && this.f11100 > 0;
            if (!z3 || this.f11093.f11121 != -9223372036854775807L || z2) {
                InterfaceC3562 interfaceC3562 = this.f11097;
                C0567.m1856(interfaceC3562);
                if (z3) {
                    long j3 = this.f11093.f11121;
                    if (j3 != -9223372036854775807L) {
                        int i2 = this.f11100;
                        interfaceC3562.mo5893(new C3557(j, this.f11099, (int) ((((long) (i2 * 8)) * 1000000) / j3), i2));
                    } else {
                        interfaceC3562.mo5893(new InterfaceC3571.C3573(-9223372036854775807L, 0L));
                    }
                    this.f11103 = true;
                }
            }
        }
        if (z2) {
            return -1;
        }
        this.f11094.m6693(0);
        this.f11094.m6691(iM5870);
        if (!this.f11102) {
            this.f11093.f11123 = this.f11098;
            this.f11102 = true;
        }
        this.f11093.mo6000(this.f11094);
        return 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) {
        this.f11102 = false;
        this.f11093.mo5997();
        this.f11098 = j2;
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public void mo5889(InterfaceC3562 interfaceC3562) {
        this.f11097 = interfaceC3562;
        this.f11093.mo5999(interfaceC3562, new InterfaceC3690.C3694(Integer.MIN_VALUE, 0, 1));
        interfaceC3562.mo5892();
    }

    /* JADX WARN: Code restructure failed: missing block: B:6:0x0021, code lost:
    
        r9.f10565 = 0;
        r3 = r3 + 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:7:0x0029, code lost:
    
        if ((r3 - r0) < 8192) goto L9;
     */
    /* JADX WARN: Code restructure failed: missing block: B:8:0x002b, code lost:
    
        return false;
     */
    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean mo5890(C3558 c3558) throws InterruptedException, EOFException {
        int iM6002 = m6002(c3558);
        int i = iM6002;
        while (true) {
            int i2 = 0;
            int i3 = 0;
            while (true) {
                c3558.m5875(this.f11095.f13227, 0, 2, false);
                this.f11095.m6693(0);
                if (!C3656.m6003(this.f11095.m6707())) {
                    break;
                }
                i2++;
                if (i2 >= 4 && i3 > 188) {
                    return true;
                }
                c3558.m5875(this.f11095.f13227, 0, 4, false);
                this.f11096.m6672(14);
                int iM6667 = this.f11096.m6667(13);
                if (iM6667 <= 6) {
                    return false;
                }
                c3558.m5874(iM6667 - 6, false);
                i3 += iM6667;
            }
            c3558.m5874(i, false);
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final int m6002(C3558 c3558) throws InterruptedException, EOFException {
        int i = 0;
        while (true) {
            c3558.m5875(this.f11095.f13227, 0, 10, false);
            this.f11095.m6693(0);
            if (this.f11095.m6704() != 4801587) {
                break;
            }
            this.f11095.m6695(3);
            int iM6701 = this.f11095.m6701();
            i += iM6701 + 10;
            c3558.m5874(iM6701, false);
        }
        c3558.f10565 = 0;
        c3558.m5874(i, false);
        if (this.f11099 == -1) {
            this.f11099 = i;
        }
        return i;
    }
}
