package com.google.android.gms.internal.ads;

import android.net.Uri;
import androidx.annotation.Nullable;
import java.io.InterruptedIOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/* JADX INFO: loaded from: classes2.dex */
public final class sp2 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Uri f16536a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final f92 f16537b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final pp2 f16538c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final q2 f16539d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final nn0 f16540e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final androidx.media3.extractor.f0 f16541f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public volatile boolean f16542g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f16543h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public long f16544i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public dy1 f16545j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public boolean f16546k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final /* synthetic */ yp2 f16547l;

    @Nullable
    private u3 zzm;

    public sp2(yp2 yp2Var, Uri uri, sv1 sv1Var, pp2 pp2Var, q2 q2Var, nn0 nn0Var) {
        Objects.requireNonNull(yp2Var);
        this.f16547l = yp2Var;
        this.f16536a = uri;
        this.f16537b = new f92(sv1Var);
        this.f16538c = pp2Var;
        this.f16539d = q2Var;
        this.f16540e = nn0Var;
        this.f16541f = new androidx.media3.extractor.f0();
        this.f16543h = true;
        to2.f16973a.getAndIncrement();
        this.f16545j = zzi(0L, null);
    }

    private final dy1 zzi(long j10, @Nullable String str) {
        Map mapD = yp2.f18929p0;
        if (str != null && !str.startsWith("W/")) {
            ds1 ds1Var = new ds1(4);
            ds1Var.b(mapD.entrySet());
            ds1Var.a("If-Range", str);
            mapD = ds1Var.d(false);
        }
        ox1 ox1Var = new ox1();
        ox1Var.a(this.f16536a);
        ox1Var.f15195b = j10;
        ox1Var.f15197d = 6;
        ox1Var.f15194a = mapD;
        return ox1Var.b();
    }

    public final void a(p01 p01Var) {
        long jMax = !this.f16546k ? this.f16544i : Math.max(this.f16547l.y(true), this.f16544i);
        int iY = p01Var.y();
        u3 u3Var = this.zzm;
        u3Var.getClass();
        u3Var.a(p01Var, iY);
        u3Var.zze(jMax, 1, iY, 0, null);
        this.f16546k = true;
    }

    /* JADX WARN: Removed duplicated region for block: B:112:0x0226  */
    /* JADX WARN: Removed duplicated region for block: B:113:0x0228  */
    /* JADX WARN: Removed duplicated region for block: B:130:0x01e1 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:149:0x0223 A[EDGE_INSN: B:149:0x0223->B:110:0x0223 BREAK  A[LOOP:1: B:79:0x01df->B:152:0x01df], SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00d7 A[Catch: all -> 0x0059, TryCatch #6 {all -> 0x0059, blocks: (B:7:0x000e, B:14:0x003c, B:16:0x004c, B:18:0x0052, B:24:0x0061, B:25:0x0071, B:27:0x008c, B:28:0x0092, B:36:0x00cd, B:38:0x00d7, B:40:0x00e3, B:42:0x00ed, B:44:0x00f9, B:46:0x0103, B:48:0x010f, B:50:0x0119, B:52:0x012b, B:54:0x0135, B:55:0x013b, B:64:0x0173, B:66:0x017c, B:68:0x0189, B:70:0x0191, B:72:0x01af, B:74:0x01cf, B:75:0x01d2, B:77:0x01d6, B:59:0x0145, B:62:0x0165, B:32:0x009e, B:35:0x00bf), top: B:137:0x000e }] */
    /* JADX WARN: Removed duplicated region for block: B:39:0x00e1  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00ed A[Catch: all -> 0x0059, TryCatch #6 {all -> 0x0059, blocks: (B:7:0x000e, B:14:0x003c, B:16:0x004c, B:18:0x0052, B:24:0x0061, B:25:0x0071, B:27:0x008c, B:28:0x0092, B:36:0x00cd, B:38:0x00d7, B:40:0x00e3, B:42:0x00ed, B:44:0x00f9, B:46:0x0103, B:48:0x010f, B:50:0x0119, B:52:0x012b, B:54:0x0135, B:55:0x013b, B:64:0x0173, B:66:0x017c, B:68:0x0189, B:70:0x0191, B:72:0x01af, B:74:0x01cf, B:75:0x01d2, B:77:0x01d6, B:59:0x0145, B:62:0x0165, B:32:0x009e, B:35:0x00bf), top: B:137:0x000e }] */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00f7  */
    /* JADX WARN: Removed duplicated region for block: B:46:0x0103 A[Catch: all -> 0x0059, TryCatch #6 {all -> 0x0059, blocks: (B:7:0x000e, B:14:0x003c, B:16:0x004c, B:18:0x0052, B:24:0x0061, B:25:0x0071, B:27:0x008c, B:28:0x0092, B:36:0x00cd, B:38:0x00d7, B:40:0x00e3, B:42:0x00ed, B:44:0x00f9, B:46:0x0103, B:48:0x010f, B:50:0x0119, B:52:0x012b, B:54:0x0135, B:55:0x013b, B:64:0x0173, B:66:0x017c, B:68:0x0189, B:70:0x0191, B:72:0x01af, B:74:0x01cf, B:75:0x01d2, B:77:0x01d6, B:59:0x0145, B:62:0x0165, B:32:0x009e, B:35:0x00bf), top: B:137:0x000e }] */
    /* JADX WARN: Removed duplicated region for block: B:47:0x010d  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x0119 A[Catch: all -> 0x0059, TryCatch #6 {all -> 0x0059, blocks: (B:7:0x000e, B:14:0x003c, B:16:0x004c, B:18:0x0052, B:24:0x0061, B:25:0x0071, B:27:0x008c, B:28:0x0092, B:36:0x00cd, B:38:0x00d7, B:40:0x00e3, B:42:0x00ed, B:44:0x00f9, B:46:0x0103, B:48:0x010f, B:50:0x0119, B:52:0x012b, B:54:0x0135, B:55:0x013b, B:64:0x0173, B:66:0x017c, B:68:0x0189, B:70:0x0191, B:72:0x01af, B:74:0x01cf, B:75:0x01d2, B:77:0x01d6, B:59:0x0145, B:62:0x0165, B:32:0x009e, B:35:0x00bf), top: B:137:0x000e }] */
    /* JADX WARN: Removed duplicated region for block: B:51:0x0129  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x0135 A[Catch: all -> 0x0059, TRY_LEAVE, TryCatch #6 {all -> 0x0059, blocks: (B:7:0x000e, B:14:0x003c, B:16:0x004c, B:18:0x0052, B:24:0x0061, B:25:0x0071, B:27:0x008c, B:28:0x0092, B:36:0x00cd, B:38:0x00d7, B:40:0x00e3, B:42:0x00ed, B:44:0x00f9, B:46:0x0103, B:48:0x010f, B:50:0x0119, B:52:0x012b, B:54:0x0135, B:55:0x013b, B:64:0x0173, B:66:0x017c, B:68:0x0189, B:70:0x0191, B:72:0x01af, B:74:0x01cf, B:75:0x01d2, B:77:0x01d6, B:59:0x0145, B:62:0x0165, B:32:0x009e, B:35:0x00bf), top: B:137:0x000e }] */
    /* JADX WARN: Removed duplicated region for block: B:60:0x0161  */
    /* JADX WARN: Removed duplicated region for block: B:64:0x0173 A[Catch: all -> 0x0059, TryCatch #6 {all -> 0x0059, blocks: (B:7:0x000e, B:14:0x003c, B:16:0x004c, B:18:0x0052, B:24:0x0061, B:25:0x0071, B:27:0x008c, B:28:0x0092, B:36:0x00cd, B:38:0x00d7, B:40:0x00e3, B:42:0x00ed, B:44:0x00f9, B:46:0x0103, B:48:0x010f, B:50:0x0119, B:52:0x012b, B:54:0x0135, B:55:0x013b, B:64:0x0173, B:66:0x017c, B:68:0x0189, B:70:0x0191, B:72:0x01af, B:74:0x01cf, B:75:0x01d2, B:77:0x01d6, B:59:0x0145, B:62:0x0165, B:32:0x009e, B:35:0x00bf), top: B:137:0x000e }] */
    /* JADX WARN: Removed duplicated region for block: B:65:0x017b  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0189 A[Catch: all -> 0x0059, TryCatch #6 {all -> 0x0059, blocks: (B:7:0x000e, B:14:0x003c, B:16:0x004c, B:18:0x0052, B:24:0x0061, B:25:0x0071, B:27:0x008c, B:28:0x0092, B:36:0x00cd, B:38:0x00d7, B:40:0x00e3, B:42:0x00ed, B:44:0x00f9, B:46:0x0103, B:48:0x010f, B:50:0x0119, B:52:0x012b, B:54:0x0135, B:55:0x013b, B:64:0x0173, B:66:0x017c, B:68:0x0189, B:70:0x0191, B:72:0x01af, B:74:0x01cf, B:75:0x01d2, B:77:0x01d6, B:59:0x0145, B:62:0x0165, B:32:0x009e, B:35:0x00bf), top: B:137:0x000e }] */
    /* JADX WARN: Removed duplicated region for block: B:71:0x01ae  */
    /* JADX WARN: Removed duplicated region for block: B:74:0x01cf A[Catch: all -> 0x0059, TryCatch #6 {all -> 0x0059, blocks: (B:7:0x000e, B:14:0x003c, B:16:0x004c, B:18:0x0052, B:24:0x0061, B:25:0x0071, B:27:0x008c, B:28:0x0092, B:36:0x00cd, B:38:0x00d7, B:40:0x00e3, B:42:0x00ed, B:44:0x00f9, B:46:0x0103, B:48:0x010f, B:50:0x0119, B:52:0x012b, B:54:0x0135, B:55:0x013b, B:64:0x0173, B:66:0x017c, B:68:0x0189, B:70:0x0191, B:72:0x01af, B:74:0x01cf, B:75:0x01d2, B:77:0x01d6, B:59:0x0145, B:62:0x0165, B:32:0x009e, B:35:0x00bf), top: B:137:0x000e }] */
    /* JADX WARN: Removed duplicated region for block: B:77:0x01d6 A[Catch: all -> 0x0059, TRY_LEAVE, TryCatch #6 {all -> 0x0059, blocks: (B:7:0x000e, B:14:0x003c, B:16:0x004c, B:18:0x0052, B:24:0x0061, B:25:0x0071, B:27:0x008c, B:28:0x0092, B:36:0x00cd, B:38:0x00d7, B:40:0x00e3, B:42:0x00ed, B:44:0x00f9, B:46:0x0103, B:48:0x010f, B:50:0x0119, B:52:0x012b, B:54:0x0135, B:55:0x013b, B:64:0x0173, B:66:0x017c, B:68:0x0189, B:70:0x0191, B:72:0x01af, B:74:0x01cf, B:75:0x01d2, B:77:0x01d6, B:59:0x0145, B:62:0x0165, B:32:0x009e, B:35:0x00bf), top: B:137:0x000e }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void b() throws Throwable {
        long j10;
        f92 f92Var;
        long jB;
        boolean z10;
        int i10;
        List list;
        String str;
        List list2;
        String str2;
        List list3;
        String str3;
        List list4;
        boolean zEquals;
        List list5;
        int i11;
        f92 f92Var2;
        yp2 yp2Var;
        sv1 sv1Var;
        int i12;
        int i13;
        int i14 = 0;
        int iF = 0;
        String str4 = null;
        while (iF == 0 && !this.f16542g) {
            try {
                j10 = this.f16541f.f3366a;
                dy1 dy1VarZzi = zzi(j10, str4);
                this.f16545j = dy1VarZzi;
                f92Var = this.f16537b;
                jB = f92Var.b(dy1VarZzi);
            } catch (Throwable th) {
                th = th;
            }
            if (this.f16542g) {
                ho2 ho2Var = (ho2) this.f16538c;
                if (ho2Var.d() != -1) {
                    this.f16541f.f3366a = ho2Var.d();
                }
                xw1.zza(this.f16537b);
                return;
            }
            List list6 = (List) f92Var.f11123a.zzj().get("ETag");
            String str5 = (list6 == null || list6.isEmpty()) ? null : (String) list6.get(0);
            if (jB != -1) {
                jB += j10;
                yp2 yp2Var2 = this.f16547l;
                yp2Var2.getClass();
                yp2Var2.R.post(new up2(yp2Var2, 1));
            }
            long j11 = jB;
            yp2 yp2Var3 = this.f16547l;
            Map mapZzj = f92Var.f11123a.zzj();
            List list7 = (List) mapZzj.get("icy-br");
            if (list7 != null) {
                String str6 = (String) list7.get(0);
                try {
                    i13 = Integer.parseInt(str6) * 1000;
                } catch (NumberFormatException unused) {
                    i13 = -1;
                }
                if (i13 > 0) {
                    i10 = i13;
                    z10 = true;
                    list = (List) mapZzj.get("icy-genre");
                    if (list != null) {
                        str = (String) list.get(0);
                        z10 = true;
                    } else {
                        str = null;
                    }
                    list2 = (List) mapZzj.get("icy-name");
                    if (list2 != null) {
                        str2 = (String) list2.get(0);
                        z10 = true;
                    } else {
                        str2 = null;
                    }
                    list3 = (List) mapZzj.get("icy-url");
                    if (list3 != null) {
                        str3 = (String) list3.get(0);
                        z10 = true;
                    } else {
                        str3 = null;
                    }
                    list4 = (List) mapZzj.get("icy-pub");
                    if (list4 != null) {
                        zEquals = ((String) list4.get(0)).equals("1");
                        z10 = true;
                    } else {
                        zEquals = false;
                    }
                    list5 = (List) mapZzj.get("icy-metaint");
                    if (list5 != null) {
                        String str7 = (String) list5.get(0);
                        try {
                            i12 = Integer.parseInt(str7);
                        } catch (NumberFormatException unused2) {
                            i12 = -1;
                        }
                        if (i12 > 0) {
                            z10 = true;
                            i11 = i12;
                            yp2Var3.q(z10 ? new e5(i10, str, str2, str3, zEquals, i11) : null);
                            f92Var2 = this.f16537b;
                            yp2Var = this.f16547l;
                            if (yp2Var.p() == null || yp2Var.p().f10636c == -1) {
                                sv1Var = f92Var2;
                            } else {
                                so2 so2Var = new so2(f92Var2, yp2Var.p().f10636c, this);
                                u3 u3VarU = yp2Var.u(new wp2(0, true));
                                this.zzm = u3VarU;
                                u3VarU.d(yp2.f18930q0);
                                sv1Var = so2Var;
                            }
                            ho2 ho2Var2 = (ho2) this.f16538c;
                            String str8 = str5;
                            ho2Var2.a(sv1Var, this.f16536a, f92Var2.f11123a.zzj(), j10, j11, this.f16539d);
                            if (yp2Var.p() != null) {
                                ho2Var2.c();
                            }
                            if (this.f16543h) {
                                ho2Var2.e(j10, this.f16544i);
                                this.f16543h = false;
                            }
                            long j12 = j10;
                            iF = 0;
                            while (true) {
                                if (iF == 0) {
                                    break;
                                }
                                try {
                                    if (this.f16542g) {
                                        iF = 0;
                                        break;
                                    }
                                    try {
                                        nn0 nn0Var = this.f16540e;
                                        synchronized (nn0Var) {
                                            while (!nn0Var.f14669a) {
                                                nn0Var.wait();
                                            }
                                        }
                                        iF = ho2Var2.f(this.f16541f);
                                        long jD = ho2Var2.d();
                                        if (jD > yp2Var.f18945h + j12) {
                                            synchronized (nn0Var) {
                                                nn0Var.f14669a = false;
                                            }
                                            yp2Var.R.post(yp2Var.Q);
                                            j12 = jD;
                                        }
                                    } catch (InterruptedException unused3) {
                                        throw new InterruptedIOException();
                                    }
                                } catch (Throwable th2) {
                                    th = th2;
                                    i14 = iF;
                                }
                            }
                            if (iF != 1) {
                                iF = 0;
                            } else if (ho2Var2.d() != -1) {
                                this.f16541f.f3366a = ho2Var2.d();
                            }
                            xw1.zza(f92Var2);
                            str4 = str8;
                        } else {
                            try {
                                StringBuilder sb = new StringBuilder(String.valueOf(str7).length() + 27);
                                sb.append("Invalid metadata interval: ");
                                sb.append(str7);
                                vt0.c(sb.toString());
                                i11 = -1;
                            } catch (NumberFormatException unused4) {
                                vt0.c("Invalid metadata interval: ".concat(String.valueOf(str7)));
                                i11 = i12;
                            }
                            yp2Var3.q(z10 ? new e5(i10, str, str2, str3, zEquals, i11) : null);
                            f92Var2 = this.f16537b;
                            yp2Var = this.f16547l;
                            if (yp2Var.p() == null) {
                                sv1Var = f92Var2;
                                ho2 ho2Var22 = (ho2) this.f16538c;
                                String str82 = str5;
                                ho2Var22.a(sv1Var, this.f16536a, f92Var2.f11123a.zzj(), j10, j11, this.f16539d);
                                if (yp2Var.p() != null) {
                                }
                                if (this.f16543h) {
                                }
                                long j122 = j10;
                                iF = 0;
                                while (true) {
                                    if (iF == 0) {
                                    }
                                }
                                if (iF != 1) {
                                }
                                xw1.zza(f92Var2);
                                str4 = str82;
                            }
                        }
                    } else {
                        i11 = -1;
                        yp2Var3.q(z10 ? new e5(i10, str, str2, str3, zEquals, i11) : null);
                        f92Var2 = this.f16537b;
                        yp2Var = this.f16547l;
                        if (yp2Var.p() == null) {
                        }
                    }
                } else {
                    try {
                        StringBuilder sb2 = new StringBuilder(String.valueOf(str6).length() + 17);
                        sb2.append("Invalid bitrate: ");
                        sb2.append(str6);
                        vt0.c(sb2.toString());
                        z10 = false;
                        i10 = -1;
                    } catch (NumberFormatException unused5) {
                        vt0.c("Invalid bitrate header: ".concat(String.valueOf(str6)));
                        i10 = i13;
                        z10 = false;
                    }
                    list = (List) mapZzj.get("icy-genre");
                    if (list != null) {
                    }
                    list2 = (List) mapZzj.get("icy-name");
                    if (list2 != null) {
                    }
                    list3 = (List) mapZzj.get("icy-url");
                    if (list3 != null) {
                    }
                    list4 = (List) mapZzj.get("icy-pub");
                    if (list4 != null) {
                    }
                    list5 = (List) mapZzj.get("icy-metaint");
                    if (list5 != null) {
                    }
                }
            } else {
                z10 = false;
                i10 = -1;
                list = (List) mapZzj.get("icy-genre");
                if (list != null) {
                }
                list2 = (List) mapZzj.get("icy-name");
                if (list2 != null) {
                }
                list3 = (List) mapZzj.get("icy-url");
                if (list3 != null) {
                }
                list4 = (List) mapZzj.get("icy-pub");
                if (list4 != null) {
                }
                list5 = (List) mapZzj.get("icy-metaint");
                if (list5 != null) {
                }
            }
            if (i14 != 1) {
                ho2 ho2Var3 = (ho2) this.f16538c;
                if (ho2Var3.d() != -1) {
                    this.f16541f.f3366a = ho2Var3.d();
                }
            }
            xw1.zza(this.f16537b);
            throw th;
        }
    }
}
