package defpackage;

import android.net.Uri;
import android.os.SystemClock;
import androidx.media3.common.ParserException;
import androidx.media3.datasource.HttpDataSource$InvalidResponseCodeException;
import androidx.media3.exoplayer.hls.playlist.HlsPlaylistParser$DeltaUpdateException;
import androidx.media3.exoplayer.hls.playlist.HlsPlaylistTracker$PlaylistResetException;
import androidx.media3.exoplayer.hls.playlist.HlsPlaylistTracker$PlaylistStuckException;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

/* JADX INFO: renamed from: יˈ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C2163 implements InterfaceC4051 {

    /* JADX INFO: renamed from: ʿٴˇ, reason: contains not printable characters */
    public IOException f8603;

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public long f8604;

    /* JADX INFO: renamed from: ˉᵵᵜ, reason: contains not printable characters */
    public final /* synthetic */ C1952 f8605;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final Uri f8606;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public long f8607;

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public boolean f8608;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final ᵣˊˈᵪ f8609 = new ᵣˊˈᵪ(2, "DefaultHlsPlaylistTracker:MediaPlaylist");

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final String f8610;

    /* JADX INFO: renamed from: ᵠˏˏ, reason: contains not printable characters */
    public boolean f8611;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public final InterfaceC1070 f8612;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public C3096 f8613;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public long f8614;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public long f8615;

    public C2163(C1952 c1952, Uri uri, String str) {
        this.f8605 = c1952;
        this.f8606 = uri;
        this.f8610 = str;
        this.f8612 = ((InterfaceC1479) c1952.f7768.ˌᴵ).mo4241();
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final void m5676(Uri uri) {
        C1952 c1952 = this.f8605;
        InterfaceC2793 interfaceC2793Mo2762 = c1952.f7773.mo2762(c1952.f7770, this.f8613);
        Map map = Collections.EMPTY_MAP;
        ᵻᵪ.ᵱʡˏ(uri, "The uri must be set.");
        C3026 c3026 = new C3026(this.f8612, new C0084(uri, 1, null, map, 0L, -1L, null, 1), 4, interfaceC2793Mo2762);
        this.f8609.ᵵᵬᵽ(c3026, this, c1952.f7771.m3345(c3026.f11645));
    }

    @Override // defpackage.InterfaceC4051
    /* JADX INFO: renamed from: ˊᵫᵗ */
    public final void mo5223(InterfaceC1933 interfaceC1933, long j, long j2, boolean z) {
        C3026 c3026 = (C3026) interfaceC1933;
        long j3 = c3026.f11644;
        C0084 c0084 = c3026.f11646;
        C0165 c0165 = c3026.f11647;
        C3622 c3622 = new C3622(c0084, c0165.f1575, c0165.f1577, j, j2, c0165.f1576);
        C1952 c1952 = this.f8605;
        c1952.f7771.getClass();
        c1952.f7778.m4045(c3622, 4, -1, null, 0, null, -9223372036854775807L, -9223372036854775807L);
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final void m5677(Uri uri) {
        this.f8615 = 0L;
        if (this.f8608) {
            return;
        }
        ᵣˊˈᵪ r0 = this.f8609;
        if (r0.ᵠˏˏ() || r0.ˑˊᵲ()) {
            return;
        }
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        long j = this.f8607;
        if (jElapsedRealtime >= j) {
            m5676(uri);
        } else {
            this.f8608 = true;
            this.f8605.f7769.postDelayed(new RunnableC4076(this, 19, uri), j - jElapsedRealtime);
        }
    }

    @Override // defpackage.InterfaceC4051
    /* JADX INFO: renamed from: ᵱʡˏ */
    public final void mo5226(InterfaceC1933 interfaceC1933, long j, long j2) {
        C3026 c3026 = (C3026) interfaceC1933;
        AbstractC0617 abstractC0617 = (AbstractC0617) c3026.f11649;
        C0084 c0084 = c3026.f11646;
        C0165 c0165 = c3026.f11647;
        C3622 c3622 = new C3622(c0084, c0165.f1575, c0165.f1577, j, j2, c0165.f1576);
        if (abstractC0617 instanceof C3096) {
            m5679((C3096) abstractC0617, c3622);
            this.f8605.f7778.m4029(c3622, 4);
        } else {
            ParserException parserExceptionM355 = ParserException.m355("Loaded playlist has unexpected type.", null);
            this.f8603 = parserExceptionM355;
            this.f8605.f7778.m4030(c3622, 4, parserExceptionM355, true);
        }
        this.f8605.f7771.getClass();
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final Uri m5678() {
        C3096 c3096 = this.f8613;
        Uri uri = this.f8606;
        if (c3096 != null) {
            C2462 c2462 = c3096.f11819;
            if (c2462.f9575 != -9223372036854775807L || c2462.f9574) {
                Uri.Builder builderBuildUpon = uri.buildUpon();
                C3096 c30962 = this.f8613;
                if (c30962.f11819.f9574) {
                    builderBuildUpon.appendQueryParameter("_HLS_msn", String.valueOf(c30962.f11831 + ((long) c30962.f11815.size())));
                    C3096 c30963 = this.f8613;
                    if (c30963.f11818 != -9223372036854775807L) {
                        AbstractC4509 abstractC4509 = c30963.f11814;
                        int size = abstractC4509.size();
                        if (!abstractC4509.isEmpty() && ((C5274) ᵸᵺᵜ.ˊᵙᵾᵲ(abstractC4509)).f19922) {
                            size--;
                        }
                        builderBuildUpon.appendQueryParameter("_HLS_part", String.valueOf(size));
                    }
                }
                C2462 c24622 = this.f8613.f11819;
                if (c24622.f9575 != -9223372036854775807L) {
                    builderBuildUpon.appendQueryParameter("_HLS_skip", c24622.f9572 ? "v2" : "YES");
                }
                return builderBuildUpon.build();
            }
        }
        return uri;
    }

    @Override // defpackage.InterfaceC4051
    /* JADX INFO: renamed from: ᵵᵬᵽ */
    public final C0655 mo5228(InterfaceC1933 interfaceC1933, long j, long j2, IOException iOException, int i) {
        C0655 c0655 = ᵣˊˈᵪ.ˌᵨʠᵫ;
        C3026 c3026 = (C3026) interfaceC1933;
        long j3 = c3026.f11644;
        int i2 = c3026.f11645;
        C0084 c0084 = c3026.f11646;
        C0165 c0165 = c3026.f11647;
        Uri uri = c0165.f1575;
        C3622 c3622 = new C3622(c0084, uri, c0165.f1577, j, j2, c0165.f1576);
        boolean z = uri.getQueryParameter("_HLS_msn") != null;
        boolean z2 = iOException instanceof HlsPlaylistParser$DeltaUpdateException;
        Uri uri2 = this.f8606;
        C1952 c1952 = this.f8605;
        if (z || z2) {
            int i3 = iOException instanceof HttpDataSource$InvalidResponseCodeException ? ((HttpDataSource$InvalidResponseCodeException) iOException).f560 : Integer.MAX_VALUE;
            if (z2 || i3 == 400 || i3 == 503) {
                this.f8607 = SystemClock.elapsedRealtime();
                m5677(uri2);
                C1404 c1404 = c1952.f7778;
                String str = AbstractC0956.f4222;
                c1404.m4030(c3622, i2, iOException, true);
                return c0655;
            }
        }
        C1785 c1785 = new C1785(i, 5, iOException);
        Iterator it = c1952.f7776.iterator();
        boolean z3 = false;
        while (it.hasNext()) {
            z3 |= !((InterfaceC0759) it.next()).mo2706(uri2, c1785, false);
        }
        C1013 c1013 = c1952.f7771;
        if (z3) {
            long jM3346 = c1013.m3346(c1785);
            c0655 = jM3346 != -9223372036854775807L ? new C0655(0, jM3346, false) : ᵣˊˈᵪ.ᵸˆˁ;
        }
        boolean zM2396 = c0655.m2396();
        c1952.f7778.m4030(c3622, i2, iOException, !zM2396);
        if (!zM2396) {
            c1013.getClass();
        }
        return c0655;
    }

    @Override // defpackage.InterfaceC4051
    /* JADX INFO: renamed from: ᵶˇᵱ */
    public final void mo5230(InterfaceC1933 interfaceC1933, long j, long j2, int i) {
        C3622 c3622;
        C3026 c3026 = (C3026) interfaceC1933;
        if (i == 0) {
            long j3 = c3026.f11644;
            c3622 = new C3622(c3026.f11646, j);
        } else {
            long j4 = c3026.f11644;
            C0084 c0084 = c3026.f11646;
            C0165 c0165 = c3026.f11647;
            c3622 = new C3622(c0084, c0165.f1575, c0165.f1577, j, j2, c0165.f1576);
        }
        this.f8605.f7778.m4037(c3622, c3026.f11645, -1, null, 0, null, -9223372036854775807L, -9223372036854775807L, i);
    }

    /* JADX WARN: Removed duplicated region for block: B:102:0x0251  */
    /* JADX WARN: Removed duplicated region for block: B:109:0x0276  */
    /* JADX WARN: Removed duplicated region for block: B:117:? A[RETURN, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0057  */
    /* JADX WARN: Removed duplicated region for block: B:32:0x00d1  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x0122  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x012a  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0134  */
    /* JADX WARN: Removed duplicated region for block: B:72:0x01af  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x01e4  */
    /* JADX WARN: Removed duplicated region for block: B:99:0x024a  */
    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m5679(C3096 c3096, C3622 c3622) {
        boolean z;
        CopyOnWriteArrayList copyOnWriteArrayList;
        boolean z2;
        long j;
        long j2;
        long j3;
        long j4;
        int i;
        AbstractC4509 abstractC4509;
        C3096 c30962;
        IOException iOException;
        IOException hlsPlaylistTracker$PlaylistStuckException;
        boolean z3;
        C2462 c2462;
        int size;
        int size2;
        int size3;
        C3096 c30963 = this.f8613;
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        this.f8614 = jElapsedRealtime;
        C1952 c1952 = this.f8605;
        CopyOnWriteArrayList copyOnWriteArrayList2 = c1952.f7776;
        if (c30963 != null) {
            long j5 = c3096.f11831;
            long j6 = c30963.f11831;
            z = j5 > j6 || (j5 >= j6 && ((size = c3096.f11815.size() - c30963.f11815.size()) == 0 ? (size2 = c3096.f11814.size()) > (size3 = c30963.f11814.size()) || (size2 == size3 && c3096.f11826 && !c30963.f11826) : size > 0));
            long j7 = c3096.f11831;
            AbstractC4509 abstractC45092 = c3096.f11815;
            long j8 = 0;
            if (z) {
                if (!c3096.f11826) {
                    copyOnWriteArrayList = copyOnWriteArrayList2;
                    z2 = true;
                    c30962 = c30963;
                } else if (c30963.f11826) {
                    c30962 = c30963;
                    copyOnWriteArrayList = copyOnWriteArrayList2;
                    iOException = null;
                    z2 = true;
                } else {
                    z2 = true;
                    copyOnWriteArrayList = copyOnWriteArrayList2;
                    c30962 = new C3096(c30963.f11832, c30963.f2956, c30963.f2954, c30963.f11825, c30963.f11830, c30963.f11817, c30963.f11833, c30963.f11829, c30963.f11831, c30963.f11827, c30963.f11823, c30963.f11818, c30963.f2955, true, c30963.f11824, c30963.f11828, c30963.f11815, c30963.f11814, c30963.f11819, c30963.f11820, c30963.f11822, c30963.f11821);
                }
                iOException = null;
            } else {
                copyOnWriteArrayList = copyOnWriteArrayList2;
                z2 = true;
                if (c3096.f11824) {
                    j3 = c3096.f11817;
                } else {
                    C3096 c30964 = c1952.f7766;
                    long j9 = c30964 != null ? c30964.f11817 : 0L;
                    if (c30963 == null) {
                        j = j9;
                    } else {
                        long j10 = c30963.f11817;
                        long j11 = c30963.f11831;
                        AbstractC4509 abstractC45093 = c30963.f11815;
                        j = j9;
                        int size4 = abstractC45093.size();
                        int i2 = (int) (j7 - j11);
                        C2799 c2799 = i2 < abstractC45093.size() ? (C2799) abstractC45093.get(i2) : null;
                        if (c2799 != null) {
                            j2 = c2799.f1916;
                        } else if (size4 == j7 - j11) {
                            j2 = c30963.f11816;
                        }
                        j3 = j10 + j2;
                    }
                    j4 = j;
                    if (c3096.f11833) {
                        C3096 c30965 = c1952.f7766;
                        int i3 = c30965 != null ? c30965.f11829 : 0;
                        if (c30963 == null) {
                            i = i3;
                            abstractC4509 = abstractC45092;
                        } else {
                            int i4 = (int) (j7 - c30963.f11831);
                            AbstractC4509 abstractC45094 = c30963.f11815;
                            C2799 c27992 = i4 < abstractC45094.size() ? (C2799) abstractC45094.get(i4) : null;
                            if (c27992 != null) {
                                i3 = (c30963.f11829 + c27992.f1915) - ((C2799) abstractC45092.get(0)).f1915;
                            }
                            i = i3;
                            abstractC4509 = abstractC45092;
                        }
                    } else {
                        i = c3096.f11829;
                        abstractC4509 = abstractC45092;
                    }
                    iOException = null;
                    c30962 = new C3096(c3096.f11832, c3096.f2956, c3096.f2954, c3096.f11825, c3096.f11830, j4, true, i, c3096.f11831, c3096.f11827, c3096.f11823, c3096.f11818, c3096.f2955, c3096.f11826, c3096.f11824, c3096.f11828, abstractC4509, c3096.f11814, c3096.f11819, c3096.f11820, c3096.f11822, c3096.f11821);
                }
                j4 = j3;
                if (c3096.f11833) {
                }
                iOException = null;
                c30962 = new C3096(c3096.f11832, c3096.f2956, c3096.f2954, c3096.f11825, c3096.f11830, j4, true, i, c3096.f11831, c3096.f11827, c3096.f11823, c3096.f11818, c3096.f2955, c3096.f11826, c3096.f11824, c3096.f11828, abstractC4509, c3096.f11814, c3096.f11819, c3096.f11820, c3096.f11822, c3096.f11821);
            }
            this.f8613 = c30962;
            Uri uri = this.f8606;
            if (c30962 == c30963) {
                this.f8603 = iOException;
                this.f8604 = jElapsedRealtime;
                if (uri.equals(c1952.f7767)) {
                    if (c1952.f7766 == null) {
                        c1952.f7772 = !c30962.f11826;
                        c1952.f7777 = c30962.f11817;
                    }
                    c1952.f7766 = c30962;
                    c1952.f7779.m9446(c30962);
                }
                Iterator it = copyOnWriteArrayList.iterator();
                while (it.hasNext()) {
                    ((InterfaceC0759) it.next()).mo2707();
                }
            } else if (!c30962.f11826) {
                long size5 = c3096.f11831 + ((long) c3096.f11815.size());
                C3096 c30966 = this.f8613;
                if (size5 < c30966.f11831) {
                    hlsPlaylistTracker$PlaylistStuckException = new HlsPlaylistTracker$PlaylistResetException();
                    z3 = z2;
                } else {
                    hlsPlaylistTracker$PlaylistStuckException = ((double) (jElapsedRealtime - this.f8604)) > ((double) AbstractC0956.m3264(c30966.f11823)) * 3.5d ? new HlsPlaylistTracker$PlaylistStuckException() : iOException;
                    z3 = false;
                }
                if (hlsPlaylistTracker$PlaylistStuckException != null) {
                    this.f8603 = hlsPlaylistTracker$PlaylistStuckException;
                    C1785 c1785 = new C1785(z2 ? 1 : 0, 5, hlsPlaylistTracker$PlaylistStuckException);
                    Iterator it2 = copyOnWriteArrayList.iterator();
                    while (it2.hasNext()) {
                        ((InterfaceC0759) it2.next()).mo2706(uri, c1785, z3);
                    }
                }
            }
            C3096 c30967 = this.f8613;
            c2462 = c30967.f11819;
            long j12 = c30967.f11823;
            if (!c2462.f9574) {
                if (c30967 == c30963) {
                    long j13 = c30967.f11818;
                    if (j13 != -9223372036854775807L) {
                        j8 = j13 / 2;
                    } else {
                        j12 /= 2;
                    }
                }
                this.f8607 = (AbstractC0956.m3264(j8) + jElapsedRealtime) - c3622.f13745;
                if (this.f8613.f11826) {
                    return;
                }
                if (uri.equals(c1952.f7767) || this.f8611) {
                    m5677(m5678());
                    return;
                }
                return;
            }
            if (c30967 == c30963) {
                j12 /= 2;
            }
            j8 = j12;
            this.f8607 = (AbstractC0956.m3264(j8) + jElapsedRealtime) - c3622.f13745;
            if (this.f8613.f11826) {
            }
        } else {
            c3096.getClass();
        }
        long j72 = c3096.f11831;
        AbstractC4509 abstractC450922 = c3096.f11815;
        long j82 = 0;
        if (z) {
        }
        this.f8613 = c30962;
        Uri uri2 = this.f8606;
        if (c30962 == c30963) {
        }
        C3096 c309672 = this.f8613;
        c2462 = c309672.f11819;
        long j122 = c309672.f11823;
        if (!c2462.f9574) {
        }
        j82 = j122;
        this.f8607 = (AbstractC0956.m3264(j82) + jElapsedRealtime) - c3622.f13745;
        if (this.f8613.f11826) {
        }
    }
}
