package p138.p176.p177.p190.p217.p222;

import android.net.Uri;
import java.io.EOFException;
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import p000.p001.p002.p003.p004.C0567;
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.p210.C3710;
import p138.p176.p177.p190.p210.p214.C3746;
import p138.p176.p177.p190.p210.p214.C3754;
import p138.p176.p177.p190.p217.p219.AbstractC3848;
import p138.p176.p177.p190.p217.p222.C3911;
import p138.p176.p177.p190.p217.p222.InterfaceC3905;
import p138.p176.p177.p190.p217.p222.p223.C3929;
import p138.p176.p177.p190.p238.C4098;
import p138.p176.p177.p190.p238.InterfaceC4095;
import p138.p176.p177.p190.p239.C4140;
import p138.p176.p177.p190.p239.C4149;
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 C3908 extends AbstractC3848 {

    /* JADX INFO: renamed from: ޟ, reason: contains not printable characters */
    public static final C3570 f12075 = new C3570();

    /* JADX INFO: renamed from: ޠ, reason: contains not printable characters */
    public static final AtomicInteger f12076 = new AtomicInteger();

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

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

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public final Uri f12079;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public final InterfaceC4095 f12080;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public final C4098 f12081;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public final InterfaceC3561 f12082;

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public final boolean f12083;

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public final boolean f12084;

    /* JADX INFO: renamed from: ޏ, reason: contains not printable characters */
    public final C4149 f12085;

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public final boolean f12086;

    /* JADX INFO: renamed from: ޑ, reason: contains not printable characters */
    public final InterfaceC3905 f12087;

    /* JADX INFO: renamed from: ޒ, reason: contains not printable characters */
    public final List<C3431> f12088;

    /* JADX INFO: renamed from: ޓ, reason: contains not printable characters */
    public final C3526 f12089;

    /* JADX INFO: renamed from: ޔ, reason: contains not printable characters */
    public final C3746 f12090;

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

    /* JADX INFO: renamed from: ޖ, reason: contains not printable characters */
    public final boolean f12092;

    /* JADX INFO: renamed from: ޗ, reason: contains not printable characters */
    public final boolean f12093;

    /* JADX INFO: renamed from: ޘ, reason: contains not printable characters */
    public InterfaceC3561 f12094;

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

    /* JADX INFO: renamed from: ޚ, reason: contains not printable characters */
    public C3911 f12096;

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

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

    /* JADX INFO: renamed from: ޝ, reason: contains not printable characters */
    public volatile boolean f12099;

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

    public C3908(InterfaceC3905 interfaceC3905, InterfaceC4095 interfaceC4095, C4098 c4098, C3431 c3431, boolean z, InterfaceC4095 interfaceC40952, C4098 c40982, boolean z2, Uri uri, List<C3431> list, int i, Object obj, long j, long j2, long j3, int i2, boolean z3, boolean z4, C4149 c4149, C3526 c3526, InterfaceC3561 interfaceC3561, C3746 c3746, C4140 c4140, boolean z5) {
        super(interfaceC4095, c4098, c3431, i, obj, j, j2, j3);
        this.f12092 = z;
        this.f12078 = i2;
        this.f12081 = c40982;
        this.f12080 = interfaceC40952;
        this.f12098 = c40982 != null;
        this.f12093 = z2;
        this.f12079 = uri;
        this.f12083 = z4;
        this.f12085 = c4149;
        this.f12084 = z3;
        this.f12087 = interfaceC3905;
        this.f12088 = list;
        this.f12089 = c3526;
        this.f12082 = interfaceC3561;
        this.f12090 = c3746;
        this.f12091 = c4140;
        this.f12086 = z5;
        this.f12077 = f12076.getAndIncrement();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static C3908 m6313(InterfaceC3905 interfaceC3905, InterfaceC4095 interfaceC4095, C3431 c3431, long j, C3929 c3929, int i, Uri uri, List<C3431> list, int i2, Object obj, boolean z, C3919 c3919, C3908 c3908, byte[] bArr, byte[] bArr2) {
        byte[] bArrM6314;
        InterfaceC4095 c3894;
        C4098 c4098;
        InterfaceC4095 interfaceC40952;
        boolean z2;
        C3746 c3746;
        C4140 c4140;
        InterfaceC3561 interfaceC3561;
        boolean z3;
        byte[] bArrM63142;
        InterfaceC4095 c38942 = interfaceC4095;
        C3929.C3930 c3930 = c3929.f12260.get(i);
        C4098 c40982 = new C4098(C0567.m1934(c3929.f12273, c3930.f12262), c3930.f12270, c3930.f12271, null);
        boolean z4 = bArr != null;
        if (z4) {
            String str = c3930.f12269;
            C0567.m1856(str);
            bArrM6314 = m6314(str);
        } else {
            bArrM6314 = null;
        }
        if (bArr == null) {
            c3894 = c38942;
        } else {
            if (bArrM6314 == null) {
                throw null;
            }
            c3894 = new C3894(c38942, bArr, bArrM6314);
        }
        C3929.C3930 c39302 = c3930.f12263;
        if (c39302 != null) {
            boolean z5 = bArr2 != null;
            if (z5) {
                String str2 = c39302.f12269;
                C0567.m1856(str2);
                bArrM63142 = m6314(str2);
            } else {
                bArrM63142 = null;
            }
            boolean z6 = z5;
            C4098 c40983 = new C4098(C0567.m1934(c3929.f12273, c39302.f12262), c39302.f12270, c39302.f12271, null);
            if (bArr2 != null) {
                if (bArrM63142 == null) {
                    throw null;
                }
                c38942 = new C3894(c38942, bArr2, bArrM63142);
            }
            z2 = z6;
            interfaceC40952 = c38942;
            c4098 = c40983;
        } else {
            c4098 = null;
            interfaceC40952 = null;
            z2 = false;
        }
        long j2 = j + c3930.f12266;
        long j3 = j2 + c3930.f12264;
        int i3 = c3929.f12253 + c3930.f12265;
        if (c3908 != null) {
            C3746 c37462 = c3908.f12090;
            C4140 c41402 = c3908.f12091;
            boolean z7 = (uri.equals(c3908.f12079) && c3908.f12100) ? false : true;
            c3746 = c37462;
            c4140 = c41402;
            interfaceC3561 = (c3908.f12095 && c3908.f12078 == i3 && !z7) ? c3908.f12094 : null;
            z3 = z7;
        } else {
            c3746 = new C3746();
            c4140 = new C4140(10);
            interfaceC3561 = null;
            z3 = false;
        }
        long j4 = c3929.f12254 + ((long) i);
        boolean z8 = c3930.f12272;
        C4149 c4149 = c3919.f12191.get(i3);
        if (c4149 == null) {
            c4149 = new C4149(Long.MAX_VALUE);
            c3919.f12191.put(i3, c4149);
        }
        return new C3908(interfaceC3905, c3894, c40982, c3431, z4, interfaceC40952, c4098, z2, uri, list, i2, obj, j2, j3, j4, i3, z8, z, c4149, c3930.f12267, interfaceC3561, c3746, c4140, z3);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static byte[] m6314(String str) {
        if (C4150.m6809(str).startsWith("0x")) {
            str = str.substring(2);
        }
        byte[] byteArray = new BigInteger(str, 16).toByteArray();
        byte[] bArr = new byte[16];
        int length = byteArray.length > 16 ? byteArray.length - 16 : 0;
        System.arraycopy(byteArray, length, bArr, (16 - byteArray.length) + length, byteArray.length - length);
        return bArr;
    }

    /* JADX WARN: Removed duplicated region for block: B:23:0x00a5  */
    /* JADX WARN: Removed duplicated region for block: B:26:0x00c9  */
    /* JADX WARN: Removed duplicated region for block: B:31:0x00dc  */
    @EnsuresNonNull({"extractor"})
    @RequiresNonNull({"output"})
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C3558 m6315(InterfaceC4095 interfaceC4095, C4098 c4098) {
        C3558 c3558;
        long jM6699;
        InterfaceC3905.C3906 c3906Mo6305;
        C3558 c35582 = new C3558(interfaceC4095, c4098.f13080, interfaceC4095.mo1283(c4098));
        int i = 0;
        if (this.f12094 == null) {
            c35582.f10565 = 0;
            try {
                c35582.m5875(this.f12091.f13227, 0, 10, false);
                this.f12091.m6689(10);
            } catch (EOFException unused) {
            }
            if (this.f12091.m6704() != 4801587) {
                jM6699 = -9223372036854775807L;
                c35582.f10565 = 0;
                c3558 = c35582;
                c3906Mo6305 = this.f12087.mo6305(this.f12082, c4098.f13076, this.f11807, this.f12088, this.f12085, interfaceC4095.mo6120(), c35582);
                this.f12094 = c3906Mo6305.f12072;
                this.f12095 = c3906Mo6305.f12074;
                if (c3906Mo6305.f12073) {
                    this.f12096.m6327(0L);
                } else {
                    this.f12096.m6327(jM6699 != -9223372036854775807L ? this.f12085.m6737(jM6699) : this.f11810);
                }
                this.f12096.f12146.clear();
                this.f12094.mo5889(this.f12096);
            } else {
                this.f12091.m6695(3);
                int iM6701 = this.f12091.m6701();
                int i2 = iM6701 + 10;
                C4140 c4140 = this.f12091;
                byte[] bArr = c4140.f13227;
                if (i2 > bArr.length) {
                    c4140.m6689(i2);
                    System.arraycopy(bArr, 0, this.f12091.f13227, 0, 10);
                }
                c35582.m5875(this.f12091.f13227, 10, iM6701, false);
                C3710 c3710M6090 = this.f12090.m6090(this.f12091.f13227, iM6701);
                if (c3710M6090 != null) {
                    int length = c3710M6090.f11440.length;
                    for (int i3 = 0; i3 < length; i3++) {
                        C3710.InterfaceC3712 interfaceC3712 = c3710M6090.f11440[i3];
                        if (interfaceC3712 instanceof C3754) {
                            C3754 c3754 = (C3754) interfaceC3712;
                            if ("com.apple.streaming.transportStreamTimestamp".equals(c3754.f11524)) {
                                System.arraycopy(c3754.f11525, 0, this.f12091.f13227, 0, 8);
                                this.f12091.m6689(8);
                                jM6699 = this.f12091.m6699() & 8589934591L;
                                break;
                            }
                        }
                    }
                    jM6699 = -9223372036854775807L;
                    c35582.f10565 = 0;
                    c3558 = c35582;
                    c3906Mo6305 = this.f12087.mo6305(this.f12082, c4098.f13076, this.f11807, this.f12088, this.f12085, interfaceC4095.mo6120(), c35582);
                    this.f12094 = c3906Mo6305.f12072;
                    this.f12095 = c3906Mo6305.f12074;
                    if (c3906Mo6305.f12073) {
                    }
                    this.f12096.f12146.clear();
                    this.f12094.mo5889(this.f12096);
                }
            }
        } else {
            c3558 = c35582;
        }
        C3911 c3911 = this.f12096;
        C3526 c3526 = this.f12089;
        if (!C4150.m6769(c3911.f12171, c3526)) {
            c3911.f12171 = c3526;
            while (true) {
                C3911.C3914[] c3914Arr = c3911.f12144;
                if (i >= c3914Arr.length) {
                    break;
                }
                if (c3911.f12163[i]) {
                    C3911.C3914 c3914 = c3914Arr[i];
                    c3914.f12182 = c3526;
                    c3914.f11762 = true;
                }
                i++;
            }
        }
        return c3558;
    }

    @Override // com.google.android.exoplayer2.upstream.Loader.InterfaceC0322
    /* JADX INFO: renamed from: ֏ */
    public void mo1299() {
        InterfaceC3561 interfaceC3561;
        C0567.m1856(this.f12096);
        if (this.f12094 == null && (interfaceC3561 = this.f12082) != null) {
            this.f12094 = interfaceC3561;
            this.f12095 = true;
            this.f12098 = false;
        }
        if (this.f12098) {
            C0567.m1856(this.f12080);
            C0567.m1856(this.f12081);
            m6316(this.f12080, this.f12081, this.f12093);
            this.f12097 = 0;
            this.f12098 = false;
        }
        if (this.f12099) {
            return;
        }
        if (!this.f12084) {
            if (this.f12083) {
                C4149 c4149 = this.f12085;
                if (c4149.f13256 == Long.MAX_VALUE) {
                    c4149.m6739(this.f11810);
                }
            } else {
                this.f12085.m6738();
            }
            m6316(this.f11812, this.f11805, this.f12092);
        }
        this.f12100 = true;
    }

    @RequiresNonNull({"output"})
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m6316(InterfaceC4095 interfaceC4095, C4098 c4098, boolean z) {
        C4098 c4098M6585;
        boolean z2;
        int iMo5886 = 0;
        if (z) {
            z2 = this.f12097 != 0;
            c4098M6585 = c4098;
        } else {
            c4098M6585 = c4098.m6585(this.f12097);
            z2 = false;
        }
        try {
            C3558 c3558M6315 = m6315(interfaceC4095, c4098M6585);
            if (z2) {
                c3558M6315.m5878(this.f12097);
            }
            while (iMo5886 == 0) {
                try {
                    if (this.f12099) {
                        break;
                    } else {
                        iMo5886 = this.f12094.mo5886(c3558M6315, f12075);
                    }
                } finally {
                    this.f12097 = (int) (c3558M6315.f10563 - c4098.f13080);
                }
            }
            try {
                interfaceC4095.close();
            } catch (IOException unused) {
            }
        } catch (Throwable th) {
            if (interfaceC4095 != null) {
                try {
                    interfaceC4095.close();
                } catch (IOException unused2) {
                }
            }
            throw th;
        }
    }

    @Override // com.google.android.exoplayer2.upstream.Loader.InterfaceC0322
    /* JADX INFO: renamed from: ؠ */
    public void mo1300() {
        this.f12099 = true;
    }

    @Override // p138.p176.p177.p190.p217.p219.AbstractC3848
    /* JADX INFO: renamed from: ށ */
    public boolean mo6234() {
        return this.f12100;
    }
}
