package com.google.android.exoplayer2.source.smoothstreaming;

import android.net.Uri;
import android.os.Handler;
import android.os.SystemClock;
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifestParser;
import com.google.android.exoplayer2.upstream.Loader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import p000.p001.p002.p003.p004.C0567;
import p138.p176.p177.p190.C3414;
import p138.p176.p177.p190.C3430;
import p138.p176.p177.p190.p194.C3531;
import p138.p176.p177.p190.p194.InterfaceC3532;
import p138.p176.p177.p190.p216.C3776;
import p138.p176.p177.p190.p216.C3777;
import p138.p176.p177.p190.p217.AbstractC3790;
import p138.p176.p177.p190.p217.C3794;
import p138.p176.p177.p190.p217.C3826;
import p138.p176.p177.p190.p217.InterfaceC3798;
import p138.p176.p177.p190.p217.InterfaceC3800;
import p138.p176.p177.p190.p217.InterfaceC3803;
import p138.p176.p177.p190.p217.InterfaceC3808;
import p138.p176.p177.p190.p217.p219.C3841;
import p138.p176.p177.p190.p217.p224.C3936;
import p138.p176.p177.p190.p217.p224.C3941;
import p138.p176.p177.p190.p217.p224.InterfaceC3939;
import p138.p176.p177.p190.p217.p224.p225.C3942;
import p138.p176.p177.p190.p238.C4098;
import p138.p176.p177.p190.p238.C4108;
import p138.p176.p177.p190.p238.C4112;
import p138.p176.p177.p190.p238.C4114;
import p138.p176.p177.p190.p238.InterfaceC4089;
import p138.p176.p177.p190.p238.InterfaceC4095;
import p138.p176.p177.p190.p238.InterfaceC4109;
import p138.p176.p177.p190.p238.InterfaceC4110;
import p138.p176.p177.p190.p238.InterfaceC4115;
import p138.p176.p177.p190.p239.C4150;

/* JADX INFO: loaded from: classes.dex */
public final class SsMediaSource extends AbstractC3790 implements Loader.InterfaceC0319<C4112<C3942>> {

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

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

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

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public final InterfaceC3939.InterfaceC3940 f1832;

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

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public final InterfaceC3532<?> f1834;

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

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

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public final InterfaceC3803.C3804 f1837;

    /* JADX INFO: renamed from: ޑ, reason: contains not printable characters */
    public final C4112.InterfaceC4113<? extends C3942> f1838;

    /* JADX INFO: renamed from: ޒ, reason: contains not printable characters */
    public final ArrayList<C3941> f1839;

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

    /* JADX INFO: renamed from: ޔ, reason: contains not printable characters */
    public InterfaceC4095 f1841;

    /* JADX INFO: renamed from: ޕ, reason: contains not printable characters */
    public Loader f1842;

    /* JADX INFO: renamed from: ޖ, reason: contains not printable characters */
    public InterfaceC4110 f1843;

    /* JADX INFO: renamed from: ޗ, reason: contains not printable characters */
    public InterfaceC4115 f1844;

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

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

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

    public static final class Factory implements InterfaceC3808 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final InterfaceC3939.InterfaceC3940 f1848;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final InterfaceC4095.InterfaceC4096 f1849;

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public C4112.InterfaceC4113<? extends C3942> f1850;

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public List<C3777> f1851;

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

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public InterfaceC3532<?> f1853;

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

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

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

        public Factory(InterfaceC3939.InterfaceC3940 interfaceC3940, InterfaceC4095.InterfaceC4096 interfaceC4096) {
            if (interfaceC3940 == null) {
                throw null;
            }
            this.f1848 = interfaceC3940;
            this.f1849 = interfaceC4096;
            this.f1853 = C3531.m5830();
            this.f1854 = new C4108();
            this.f1855 = 30000L;
            this.f1852 = new C3794();
        }

        public Factory(InterfaceC4095.InterfaceC4096 interfaceC4096) {
            this(new C3936.C3937(interfaceC4096), interfaceC4096);
        }

        public SsMediaSource createMediaSource(Uri uri) {
            this.f1856 = true;
            if (this.f1850 == null) {
                this.f1850 = new SsManifestParser();
            }
            List<C3777> list = this.f1851;
            if (list != null) {
                this.f1850 = new C3776(this.f1850, list);
            }
            C3942 c3942 = null;
            if (uri != null) {
                return new SsMediaSource(c3942, uri, this.f1849, this.f1850, this.f1848, this.f1852, this.f1853, this.f1854, this.f1855, null, null);
            }
            throw null;
        }

        public Factory setStreamKeys(List<C3777> list) {
            C0567.m1932(!this.f1856);
            this.f1851 = list;
            return this;
        }

        /* JADX INFO: renamed from: setStreamKeys, reason: collision with other method in class */
        public /* bridge */ /* synthetic */ InterfaceC3808 m1241setStreamKeys(List list) {
            return setStreamKeys((List<C3777>) list);
        }
    }

    static {
        C3430.m5578("goog.exo.smoothstreaming");
    }

    public /* synthetic */ SsMediaSource(C3942 c3942, Uri uri, InterfaceC4095.InterfaceC4096 interfaceC4096, C4112.InterfaceC4113 interfaceC4113, InterfaceC3939.InterfaceC3940 interfaceC3940, C3794 c3794, InterfaceC3532 interfaceC3532, InterfaceC4109 interfaceC4109, long j, Object obj, C0304 c0304) {
        Uri uriWithAppendedPath = uri;
        C0567.m1932(c3942 == null || !c3942.f12343);
        this.f1846 = c3942;
        if (uriWithAppendedPath == null) {
            uriWithAppendedPath = null;
        } else {
            String lastPathSegment = uri.getLastPathSegment();
            if (lastPathSegment == null || !C4150.m6809(lastPathSegment).matches("manifest(\\(.+\\))?")) {
                uriWithAppendedPath = Uri.withAppendedPath(uri, "Manifest");
            }
        }
        this.f1830 = uriWithAppendedPath;
        this.f1831 = interfaceC4096;
        this.f1838 = interfaceC4113;
        this.f1832 = interfaceC3940;
        this.f1833 = c3794;
        this.f1834 = interfaceC3532;
        this.f1835 = interfaceC4109;
        this.f1836 = j;
        this.f1837 = m6096((InterfaceC3800.C3801) null);
        this.f1840 = obj;
        this.f1829 = c3942 != null;
        this.f1839 = new ArrayList<>();
    }

    @Override // com.google.android.exoplayer2.upstream.Loader.InterfaceC0319
    /* JADX INFO: renamed from: ֏ */
    public Loader.C0320 mo1230(Loader.InterfaceC0322 interfaceC0322, long j, long j2, IOException iOException, int i) {
        C4112 c4112 = (C4112) interfaceC0322;
        long jMo6616 = this.f1835.mo6616(4, j2, iOException, i);
        Loader.C0320 c0320M1289 = jMo6616 == -9223372036854775807L ? Loader.f1981 : Loader.m1289(false, jMo6616);
        InterfaceC3803.C3804 c3804 = this.f1837;
        C4098 c4098 = c4112.f13153;
        C4114 c4114 = c4112.f13155;
        c3804.m6137(c4098, c4114.f13160, c4114.f13161, c4112.f13154, j, j2, c4114.f13159, iOException, !c0320M1289.m1296());
        return c0320M1289;
    }

    @Override // p138.p176.p177.p190.p217.InterfaceC3800
    /* JADX INFO: renamed from: ֏ */
    public InterfaceC3798 mo1209(InterfaceC3800.C3801 c3801, InterfaceC4089 interfaceC4089, long j) {
        C3941 c3941 = new C3941(this.f1846, this.f1832, this.f1844, this.f1833, this.f1834, this.f1835, m6096(c3801), this.f1843, interfaceC4089);
        this.f1839.add(c3941);
        return c3941;
    }

    @Override // p138.p176.p177.p190.p217.InterfaceC3800
    /* JADX INFO: renamed from: ֏ */
    public void mo1210() {
        this.f1843.mo1233();
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // com.google.android.exoplayer2.upstream.Loader.InterfaceC0319
    /* JADX INFO: renamed from: ֏ */
    public void mo1231(Loader.InterfaceC0322 interfaceC0322, long j, long j2) {
        C4112 c4112 = (C4112) interfaceC0322;
        InterfaceC3803.C3804 c3804 = this.f1837;
        C4098 c4098 = c4112.f13153;
        C4114 c4114 = c4112.f13155;
        c3804.m6142(c4098, c4114.f13160, c4114.f13161, c4112.f13154, j, j2, c4114.f13159);
        this.f1846 = (C3942) c4112.f13157;
        this.f1845 = j - j2;
        m1239();
        if (this.f1846.f12343) {
            this.f1847.postDelayed(new Runnable() { // from class: ދ.ހ.֏.ؠ.ໞ.ޠ.֏
                @Override // java.lang.Runnable
                public final void run() {
                    this.f12316.m1240();
                }
            }, Math.max(0L, (this.f1845 + 5000) - SystemClock.elapsedRealtime()));
        }
    }

    @Override // com.google.android.exoplayer2.upstream.Loader.InterfaceC0319
    /* JADX INFO: renamed from: ֏ */
    public void mo1232(Loader.InterfaceC0322 interfaceC0322, long j, long j2, boolean z) {
        C4112 c4112 = (C4112) interfaceC0322;
        InterfaceC3803.C3804 c3804 = this.f1837;
        C4098 c4098 = c4112.f13153;
        C4114 c4114 = c4112.f13155;
        c3804.m6136(c4098, c4114.f13160, c4114.f13161, c4112.f13154, j, j2, c4114.f13159);
    }

    @Override // p138.p176.p177.p190.p217.InterfaceC3800
    /* JADX INFO: renamed from: ֏ */
    public void mo1212(InterfaceC3798 interfaceC3798) {
        C3941 c3941 = (C3941) interfaceC3798;
        for (C3841<InterfaceC3939> c3841 : c3941.f12337) {
            c3841.m6219((C3841.InterfaceC3843) null);
        }
        c3941.f12335 = null;
        c3941.f12331.m6138();
        this.f1839.remove(interfaceC3798);
    }

    @Override // p138.p176.p177.p190.p217.AbstractC3790
    /* JADX INFO: renamed from: ֏ */
    public void mo1215(InterfaceC4115 interfaceC4115) {
        this.f1844 = interfaceC4115;
        this.f1834.mo1129();
        if (this.f1829) {
            this.f1843 = new InterfaceC4110.C4111();
            m1239();
            return;
        }
        this.f1841 = this.f1831.mo1286();
        Loader loader = new Loader("Loader:Manifest");
        this.f1842 = loader;
        this.f1843 = loader;
        this.f1847 = new Handler();
        if (this.f1842.m1294()) {
            return;
        }
        C4112 c4112 = new C4112(this.f1841, this.f1830, 4, this.f1838);
        this.f1837.m6133(c4112.f13153, c4112.f13154, this.f1842.m1290(c4112, this, this.f1835.mo6614(c4112.f13154)));
    }

    @Override // p138.p176.p177.p190.p217.AbstractC3790
    /* JADX INFO: renamed from: ؠ */
    public void mo1217() {
        this.f1846 = this.f1829 ? this.f1846 : null;
        this.f1841 = null;
        this.f1845 = 0L;
        Loader loader = this.f1842;
        if (loader != null) {
            loader.m1292((Loader.InterfaceC0323) null);
            this.f1842 = null;
        }
        Handler handler = this.f1847;
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
            this.f1847 = null;
        }
        this.f1834.mo1126();
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final void m1239() {
        C3826 c3826;
        for (int i = 0; i < this.f1839.size(); i++) {
            C3941 c3941 = this.f1839.get(i);
            C3942 c3942 = this.f1846;
            c3941.f12336 = c3942;
            for (C3841<InterfaceC3939> c3841 : c3941.f12337) {
                ((InterfaceC3939) c3841.f11835).mo6365(c3942);
            }
            c3941.f12335.mo5541(c3941);
        }
        long jMax = Long.MIN_VALUE;
        long jMax2 = Long.MAX_VALUE;
        for (C3942.C3944 c3944 : this.f1846.f12345) {
            if (c3944.f12361 > 0) {
                jMax2 = Math.min(jMax2, c3944.f12365[0]);
                int i2 = c3944.f12361;
                jMax = Math.max(jMax, c3944.m6369(i2 - 1) + c3944.f12365[i2 - 1]);
            }
        }
        if (jMax2 == Long.MAX_VALUE) {
            long j = this.f1846.f12343 ? -9223372036854775807L : 0L;
            C3942 c39422 = this.f1846;
            boolean z = c39422.f12343;
            c3826 = new C3826(j, 0L, 0L, 0L, true, z, z, c39422, this.f1840);
        } else {
            C3942 c39423 = this.f1846;
            if (c39423.f12343) {
                long j2 = c39423.f12347;
                if (j2 != -9223372036854775807L && j2 > 0) {
                    jMax2 = Math.max(jMax2, jMax - j2);
                }
                long j3 = jMax2;
                long j4 = jMax - j3;
                long jM5458 = j4 - C3414.m5458(this.f1836);
                if (jM5458 < 5000000) {
                    jM5458 = Math.min(5000000L, j4 / 2);
                }
                c3826 = new C3826(-9223372036854775807L, j4, j3, jM5458, true, true, true, this.f1846, this.f1840);
            } else {
                long j5 = c39423.f12346;
                long j6 = j5 != -9223372036854775807L ? j5 : jMax - jMax2;
                c3826 = new C3826(jMax2 + j6, j6, jMax2, 0L, true, false, false, this.f1846, this.f1840);
            }
        }
        m6098(c3826);
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final void m1240() {
        if (this.f1842.m1294()) {
            return;
        }
        C4112 c4112 = new C4112(this.f1841, this.f1830, 4, this.f1838);
        this.f1837.m6133(c4112.f13153, c4112.f13154, this.f1842.m1290(c4112, this, this.f1835.mo6614(c4112.f13154)));
    }
}
