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

import android.net.Uri;
import android.os.Handler;
import android.os.SystemClock;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker;
import com.google.android.exoplayer2.upstream.Loader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import p000.p001.p002.p003.p004.C0567;
import p138.p176.p177.p190.C3414;
import p138.p176.p177.p190.p217.C3826;
import p138.p176.p177.p190.p217.InterfaceC3803;
import p138.p176.p177.p190.p217.p222.C3907;
import p138.p176.p177.p190.p217.p222.InterfaceC3904;
import p138.p176.p177.p190.p217.p222.p223.C3926;
import p138.p176.p177.p190.p217.p222.p223.C3929;
import p138.p176.p177.p190.p238.C4098;
import p138.p176.p177.p190.p238.C4112;
import p138.p176.p177.p190.p238.C4114;
import p138.p176.p177.p190.p238.InterfaceC4109;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ໞ.ޟ.ސ.ހ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C3923 implements HlsPlaylistTracker, Loader.InterfaceC0319<C4112<AbstractC3931>> {

    /* JADX INFO: renamed from: ޓ, reason: contains not printable characters */
    public static final HlsPlaylistTracker.InterfaceC0301 f12201 = new HlsPlaylistTracker.InterfaceC0301() { // from class: ދ.ހ.֏.ؠ.ໞ.ޟ.ސ.֏
        @Override // com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker.InterfaceC0301
        /* JADX INFO: renamed from: ֏ */
        public final HlsPlaylistTracker mo1236(InterfaceC3904 interfaceC3904, InterfaceC4109 interfaceC4109, InterfaceC3934 interfaceC3934) {
            return new C3923(interfaceC3904, interfaceC4109, interfaceC3934);
        }
    };

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

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

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

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public C4112.InterfaceC4113<AbstractC3931> f12208;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public InterfaceC3803.C3804 f12209;

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

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

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public HlsPlaylistTracker.InterfaceC0303 f12212;

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public C3926 f12213;

    /* JADX INFO: renamed from: ޏ, reason: contains not printable characters */
    public Uri f12214;

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public C3929 f12215;

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

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public final double f12207 = 3.5d;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final List<HlsPlaylistTracker.InterfaceC0302> f12206 = new ArrayList();

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final HashMap<Uri, RunnableC3924> f12205 = new HashMap<>();

    /* JADX INFO: renamed from: ޒ, reason: contains not printable characters */
    public long f12217 = -9223372036854775807L;

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ໞ.ޟ.ސ.ހ$֏, reason: contains not printable characters */
    public final class RunnableC3924 implements Loader.InterfaceC0319<C4112<AbstractC3931>>, Runnable {

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

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public final Loader f12219 = new Loader("DefaultHlsPlaylistTracker:MediaPlaylist");

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public final C4112<AbstractC3931> f12220;

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

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

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

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

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

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

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

        public RunnableC3924(Uri uri) {
            this.f12218 = uri;
            this.f12220 = new C4112<>(C3923.this.f12202.mo6300(4), uri, 4, C3923.this.f12208);
        }

        @Override // java.lang.Runnable
        public void run() {
            this.f12226 = false;
            m6347();
        }

        @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) {
            Loader.C0320 c0320M1289;
            C4112 c4112 = (C4112) interfaceC0322;
            long jMo6615 = C3923.this.f12204.mo6615(c4112.f13154, j2, iOException, i);
            boolean z = jMo6615 != -9223372036854775807L;
            boolean zM6346 = C3923.m6340(C3923.this, this.f12218, jMo6615) || !z;
            if (z) {
                zM6346 |= m6346(jMo6615);
            }
            if (zM6346) {
                long jMo6616 = C3923.this.f12204.mo6616(c4112.f13154, j2, iOException, i);
                c0320M1289 = jMo6616 != -9223372036854775807L ? Loader.m1289(false, jMo6616) : Loader.f1981;
            } else {
                c0320M1289 = Loader.f1980;
            }
            InterfaceC3803.C3804 c3804 = C3923.this.f12209;
            C4098 c4098 = c4112.f13153;
            C4114 c4114 = c4112.f13155;
            c3804.m6137(c4098, c4114.f13160, c4114.f13161, 4, j, j2, c4114.f13159, iOException, !c0320M1289.m1296());
            return c0320M1289;
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public void m6344() {
            this.f12225 = 0L;
            if (this.f12226 || this.f12219.m1295() || this.f12219.m1294()) {
                return;
            }
            long jElapsedRealtime = SystemClock.elapsedRealtime();
            long j = this.f12224;
            if (jElapsedRealtime >= j) {
                m6347();
            } else {
                this.f12226 = true;
                C3923.this.f12211.postDelayed(this, j - jElapsedRealtime);
            }
        }

        /* 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;
            AbstractC3931 abstractC3931 = (AbstractC3931) c4112.f13157;
            if (!(abstractC3931 instanceof C3929)) {
                this.f12227 = new ParserException("Loaded playlist has unexpected type.");
                return;
            }
            m6345((C3929) abstractC3931, j2);
            InterfaceC3803.C3804 c3804 = C3923.this.f12209;
            C4098 c4098 = c4112.f13153;
            C4114 c4114 = c4112.f13155;
            c3804.m6142(c4098, c4114.f13160, c4114.f13161, 4, j, j2, c4114.f13159);
        }

        @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 = C3923.this.f12209;
            C4098 c4098 = c4112.f13153;
            C4114 c4114 = c4112.f13155;
            c3804.m6136(c4098, c4114.f13160, c4114.f13161, 4, j, j2, c4114.f13159);
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final void m6345(C3929 c3929, long j) {
            C3929 c39292;
            long j2;
            C3826 c3826;
            long j3;
            C3929 c39293 = this.f12221;
            long jElapsedRealtime = SystemClock.elapsedRealtime();
            this.f12222 = jElapsedRealtime;
            C3929 c3929M6339 = C3923.m6339(C3923.this, c39293, c3929);
            this.f12221 = c3929M6339;
            if (c3929M6339 != c39293) {
                this.f12227 = null;
                this.f12223 = jElapsedRealtime;
                C3923 c3923 = C3923.this;
                if (this.f12218.equals(c3923.f12214)) {
                    if (c3923.f12215 == null) {
                        c3923.f12216 = !c3929M6339.f12257;
                        c3923.f12217 = c3929M6339.f12251;
                    }
                    c3923.f12215 = c3929M6339;
                    HlsMediaSource hlsMediaSource = (HlsMediaSource) c3923.f12212;
                    if (hlsMediaSource == null) {
                        throw null;
                    }
                    long jM5459 = c3929M6339.f12258 ? C3414.m5459(c3929M6339.f12251) : -9223372036854775807L;
                    int i = c3929M6339.f12249;
                    long j4 = (i == 2 || i == 1) ? jM5459 : -9223372036854775807L;
                    long j5 = c3929M6339.f12250;
                    C3926 c3926 = ((C3923) hlsMediaSource.f1816).f12213;
                    C0567.m1856(c3926);
                    C3907 c3907 = new C3907(c3926, c3929M6339);
                    C3923 c39232 = (C3923) hlsMediaSource.f1816;
                    if (c39232.f12216) {
                        long j6 = c3929M6339.f12251 - c39232.f12217;
                        long j7 = c3929M6339.f12257 ? c3929M6339.f12261 + j6 : -9223372036854775807L;
                        List<C3929.C3930> list = c3929M6339.f12260;
                        if (j5 != -9223372036854775807L) {
                            c39292 = c39293;
                            j2 = jElapsedRealtime;
                            j3 = j5;
                        } else if (list.isEmpty()) {
                            c39292 = c39293;
                            j2 = jElapsedRealtime;
                            j3 = 0;
                        } else {
                            int iMax = Math.max(0, list.size() - 3);
                            long j8 = c3929M6339.f12261 - (c3929M6339.f12256 * 2);
                            int i2 = iMax;
                            while (true) {
                                if (i2 <= 0) {
                                    c39292 = c39293;
                                    j2 = jElapsedRealtime;
                                    break;
                                }
                                c39292 = c39293;
                                j2 = jElapsedRealtime;
                                if (list.get(i2).f12266 <= j8) {
                                    break;
                                }
                                i2--;
                                c39293 = c39292;
                                jElapsedRealtime = j2;
                            }
                            j3 = list.get(i2).f12266;
                        }
                        c3826 = new C3826(j4, jM5459, j7, c3929M6339.f12261, j6, j3, true, !c3929M6339.f12257, true, c3907, hlsMediaSource.f1817);
                    } else {
                        c39292 = c39293;
                        j2 = jElapsedRealtime;
                        long j9 = j5 == -9223372036854775807L ? 0L : j5;
                        long j10 = c3929M6339.f12261;
                        c3826 = new C3826(j4, jM5459, j10, j10, 0L, j9, true, false, false, c3907, hlsMediaSource.f1817);
                    }
                    hlsMediaSource.m6098(c3826);
                } else {
                    c39292 = c39293;
                    j2 = jElapsedRealtime;
                }
                int size = c3923.f12206.size();
                for (int i3 = 0; i3 < size; i3++) {
                    c3923.f12206.get(i3).mo1237();
                }
            } else {
                c39292 = c39293;
                j2 = jElapsedRealtime;
                if (!c3929M6339.f12257) {
                    if (c3929.f12254 + ((long) c3929.f12260.size()) < this.f12221.f12254) {
                        this.f12227 = new HlsPlaylistTracker.PlaylistResetException(this.f12218);
                        C3923.m6340(C3923.this, this.f12218, -9223372036854775807L);
                    } else if (j2 - this.f12223 > C3414.m5459(r1.f12256) * C3923.this.f12207) {
                        HlsPlaylistTracker.PlaylistStuckException playlistStuckException = new HlsPlaylistTracker.PlaylistStuckException(this.f12218);
                        this.f12227 = playlistStuckException;
                        long jMo6615 = C3923.this.f12204.mo6615(4, j, playlistStuckException, 1);
                        C3923.m6340(C3923.this, this.f12218, jMo6615);
                        if (jMo6615 != -9223372036854775807L) {
                            m6346(jMo6615);
                        }
                    }
                }
            }
            C3929 c39294 = this.f12221;
            this.f12224 = C3414.m5459(c39294 != c39292 ? c39294.f12256 : c39294.f12256 / 2) + j2;
            if (!this.f12218.equals(C3923.this.f12214) || this.f12221.f12257) {
                return;
            }
            m6344();
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final boolean m6346(long j) {
            boolean z;
            this.f12225 = SystemClock.elapsedRealtime() + j;
            if (!this.f12218.equals(C3923.this.f12214)) {
                return false;
            }
            C3923 c3923 = C3923.this;
            List<C3926.C3928> list = c3923.f12213.f12233;
            int size = list.size();
            long jElapsedRealtime = SystemClock.elapsedRealtime();
            int i = 0;
            while (true) {
                if (i >= size) {
                    z = false;
                    break;
                }
                RunnableC3924 runnableC3924 = c3923.f12205.get(list.get(i).f12243);
                if (jElapsedRealtime > runnableC3924.f12225) {
                    c3923.f12214 = runnableC3924.f12218;
                    runnableC3924.m6344();
                    z = true;
                    break;
                }
                i++;
            }
            return !z;
        }

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final void m6347() {
            Loader loader = this.f12219;
            C4112<AbstractC3931> c4112 = this.f12220;
            long jM1290 = loader.m1290(c4112, this, C3923.this.f12204.mo6614(c4112.f13154));
            InterfaceC3803.C3804 c3804 = C3923.this.f12209;
            C4112<AbstractC3931> c41122 = this.f12220;
            c3804.m6133(c41122.f13153, c41122.f13154, jM1290);
        }
    }

    public C3923(InterfaceC3904 interfaceC3904, InterfaceC4109 interfaceC4109, InterfaceC3934 interfaceC3934) {
        this.f12202 = interfaceC3904;
        this.f12203 = interfaceC3934;
        this.f12204 = interfaceC4109;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static C3929.C3930 m6338(C3929 c3929, C3929 c39292) {
        int i = (int) (c39292.f12254 - c3929.f12254);
        List<C3929.C3930> list = c3929.f12260;
        if (i < list.size()) {
            return list.get(i);
        }
        return null;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static /* synthetic */ C3929 m6339(C3923 c3923, C3929 c3929, C3929 c39292) {
        long j;
        long j2;
        long j3;
        int i;
        C3929.C3930 c3930M6338;
        int size;
        int size2;
        if (c3923 == null || c39292 == null) {
            throw null;
        }
        boolean z = true;
        if (c3929 != null) {
            long j4 = c39292.f12254;
            long j5 = c3929.f12254;
            if (j4 <= j5 && (j4 < j5 || ((size = c39292.f12260.size()) <= (size2 = c3929.f12260.size()) && (size != size2 || !c39292.f12257 || c3929.f12257)))) {
                z = false;
            }
        }
        if (!z) {
            return (!c39292.f12257 || c3929.f12257) ? c3929 : new C3929(c3929.f12249, c3929.f12273, c3929.f12274, c3929.f12250, c3929.f12251, c3929.f12252, c3929.f12253, c3929.f12254, c3929.f12255, c3929.f12256, c3929.f12275, true, c3929.f12258, c3929.f12259, c3929.f12260);
        }
        if (c39292.f12258) {
            j = c39292.f12251;
        } else {
            C3929 c39293 = c3923.f12215;
            j = c39293 != null ? c39293.f12251 : 0L;
            if (c3929 != null) {
                int size3 = c3929.f12260.size();
                C3929.C3930 c3930M63382 = m6338(c3929, c39292);
                if (c3930M63382 != null) {
                    j2 = c3929.f12251;
                    j3 = c3930M63382.f12266;
                } else if (size3 == c39292.f12254 - c3929.f12254) {
                    j2 = c3929.f12251;
                    j3 = c3929.f12261;
                }
                j = j2 + j3;
            }
        }
        long j6 = j;
        if (c39292.f12252) {
            i = c39292.f12253;
        } else {
            C3929 c39294 = c3923.f12215;
            i = c39294 != null ? c39294.f12253 : 0;
            if (c3929 != null && (c3930M6338 = m6338(c3929, c39292)) != null) {
                i = (c3929.f12253 + c3930M6338.f12265) - c39292.f12260.get(0).f12265;
            }
        }
        return new C3929(c39292.f12249, c39292.f12273, c39292.f12274, c39292.f12250, j6, true, i, c39292.f12254, c39292.f12255, c39292.f12256, c39292.f12275, c39292.f12257, c39292.f12258, c39292.f12259, c39292.f12260);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static /* synthetic */ boolean m6340(C3923 c3923, Uri uri, long j) {
        int size = c3923.f12206.size();
        boolean z = false;
        for (int i = 0; i < size; i++) {
            z |= !c3923.f12206.get(i).mo1238(uri, j);
        }
        return z;
    }

    @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.f12204.mo6616(c4112.f13154, j2, iOException, i);
        boolean z = jMo6616 == -9223372036854775807L;
        InterfaceC3803.C3804 c3804 = this.f12209;
        C4098 c4098 = c4112.f13153;
        C4114 c4114 = c4112.f13155;
        c3804.m6137(c4098, c4114.f13160, c4114.f13161, 4, j, j2, c4114.f13159, iOException, z);
        return z ? Loader.f1981 : Loader.m1289(false, jMo6616);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public C3929 m6341(Uri uri, boolean z) {
        C3929 c3929;
        C3929 c39292 = this.f12205.get(uri).f12221;
        if (c39292 != null && z && !uri.equals(this.f12214)) {
            List<C3926.C3928> list = this.f12213.f12233;
            boolean z2 = false;
            int i = 0;
            while (true) {
                if (i >= list.size()) {
                    break;
                }
                if (uri.equals(list.get(i).f12243)) {
                    z2 = true;
                    break;
                }
                i++;
            }
            if (z2 && ((c3929 = this.f12215) == null || !c3929.f12257)) {
                this.f12214 = uri;
                this.f12205.get(uri).m6344();
            }
        }
        return c39292;
    }

    /* 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;
        AbstractC3931 abstractC3931 = (AbstractC3931) c4112.f13157;
        boolean z = abstractC3931 instanceof C3929;
        C3926 c3926M6349 = z ? C3926.m6349(abstractC3931.f12273) : (C3926) abstractC3931;
        this.f12213 = c3926M6349;
        this.f12208 = this.f12203.mo6337(c3926M6349);
        this.f12214 = c3926M6349.f12233.get(0).f12243;
        List<Uri> list = c3926M6349.f12232;
        int size = list.size();
        for (int i = 0; i < size; i++) {
            Uri uri = list.get(i);
            this.f12205.put(uri, new RunnableC3924(uri));
        }
        RunnableC3924 runnableC3924 = this.f12205.get(this.f12214);
        if (z) {
            runnableC3924.m6345((C3929) abstractC3931, j2);
        } else {
            runnableC3924.m6344();
        }
        InterfaceC3803.C3804 c3804 = this.f12209;
        C4098 c4098 = c4112.f13153;
        C4114 c4114 = c4112.f13155;
        c3804.m6142(c4098, c4114.f13160, c4114.f13161, 4, j, j2, c4114.f13159);
    }

    @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.f12209;
        C4098 c4098 = c4112.f13153;
        C4114 c4114 = c4112.f13155;
        c3804.m6136(c4098, c4114.f13160, c4114.f13161, 4, j, j2, c4114.f13159);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public boolean m6342(Uri uri) {
        int i;
        RunnableC3924 runnableC3924 = this.f12205.get(uri);
        if (runnableC3924.f12221 == null) {
            return false;
        }
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        long jMax = Math.max(30000L, C3414.m5459(runnableC3924.f12221.f12261));
        C3929 c3929 = runnableC3924.f12221;
        return c3929.f12257 || (i = c3929.f12249) == 2 || i == 1 || runnableC3924.f12222 + jMax > jElapsedRealtime;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public void m6343(Uri uri) throws IOException {
        RunnableC3924 runnableC3924 = this.f12205.get(uri);
        runnableC3924.f12219.m1291(Integer.MIN_VALUE);
        IOException iOException = runnableC3924.f12227;
        if (iOException != null) {
            throw iOException;
        }
    }
}
