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

import android.net.Uri;
import java.io.IOException;
import java.nio.ByteBuffer;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/* JADX INFO: loaded from: classes2.dex */
public final class d50 extends w40 implements u30 {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public n50 f10202d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public String f10203e;

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

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

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

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

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

    public static String s(String str, Exception exc) {
        String canonicalName = exc.getClass().getCanonicalName();
        String message = exc.getMessage();
        int length = String.valueOf(canonicalName).length();
        StringBuilder sb = new StringBuilder(str.length() + 1 + length + 1 + String.valueOf(message).length());
        u.a.h(sb, str, "/", canonicalName, ":");
        sb.append(message);
        return sb.toString();
    }

    @Override // com.google.android.gms.internal.ads.w40
    public final void b() {
        n50 n50Var = this.f10202d;
        if (n50Var != null) {
            n50Var.f14448k = null;
            n50Var.x();
        }
    }

    @Override // com.google.android.gms.internal.ads.u30
    public final void c() {
        q7.j.d("Precache onRenderedFirstFrame");
    }

    @Override // com.google.android.gms.internal.ads.u30
    public final void d(long j10, boolean z10) {
        c40 c40Var = (c40) this.f17863c.get();
        if (c40Var != null) {
            b30.f9364f.execute(new i40(c40Var, z10, j10, 1));
        }
    }

    @Override // com.google.android.gms.internal.ads.u30
    public final void e(int i10, int i11) {
    }

    @Override // com.google.android.gms.internal.ads.u30
    public final void f(String str, Exception exc) {
        m7.n.C.f30469h.e("VideoStreamExoPlayerCache.onError", exc);
    }

    @Override // com.google.android.gms.internal.ads.u30
    public final void h(Exception exc) {
        m7.n.C.f30469h.e("VideoStreamExoPlayerCache.onException", exc);
    }

    @Override // com.google.android.gms.internal.ads.w40
    public final boolean i(String str) {
        return j(str, new String[]{str});
    }

    /* JADX WARN: Code restructure failed: missing block: B:50:0x0163, code lost:
    
        q7.e.f32222b.post(new com.google.android.gms.internal.ads.u40(r47, r48, r30, r24));
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v7, types: [com.google.android.gms.internal.ads.c40] */
    /* JADX WARN: Type inference failed for: r15v0, types: [com.google.android.gms.internal.ads.d50, com.google.android.gms.internal.ads.w40] */
    /* JADX WARN: Type inference failed for: r15v1 */
    /* JADX WARN: Type inference failed for: r15v2, types: [com.google.android.gms.internal.ads.d50] */
    /* JADX WARN: Type inference failed for: r15v3 */
    /* JADX WARN: Type inference failed for: r15v5 */
    /* JADX WARN: Type inference failed for: r3v0 */
    /* JADX WARN: Type inference failed for: r3v1, types: [com.google.android.gms.internal.ads.w40] */
    /* JADX WARN: Type inference failed for: r3v10 */
    /* JADX WARN: Type inference failed for: r3v11 */
    /* JADX WARN: Type inference failed for: r3v12 */
    /* JADX WARN: Type inference failed for: r3v13, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r3v15 */
    /* JADX WARN: Type inference failed for: r3v16 */
    /* JADX WARN: Type inference failed for: r3v24 */
    /* JADX WARN: Type inference failed for: r3v25 */
    /* JADX WARN: Type inference failed for: r3v26 */
    /* JADX WARN: Type inference failed for: r3v5 */
    /* JADX WARN: Type inference failed for: r3v6 */
    /* JADX WARN: Type inference failed for: r3v7 */
    /* JADX WARN: Type inference failed for: r3v8 */
    /* JADX WARN: Type inference failed for: r3v9 */
    @Override // com.google.android.gms.internal.ads.w40
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean j(String str, String[] strArr) throws Throwable {
        boolean z10;
        String str2;
        ?? r32;
        boolean z11;
        long j10;
        long j11;
        String str3;
        String str4;
        long j12;
        long j13;
        long j14;
        String str5;
        ?? r15 = this;
        r15.f10203e = str;
        String strConcat = "cache:".concat(String.valueOf(q7.e.zzf(str)));
        String str6 = " ms";
        String str7 = "Timeout reached. Limit: ";
        boolean z12 = false;
        try {
            Uri[] uriArr = new Uri[strArr.length];
            for (int i10 = 0; i10 < strArr.length; i10++) {
                uriArr[i10] = Uri.parse(strArr[i10]);
            }
            n50 n50Var = r15.f10202d;
            n50Var.getClass();
            n50Var.w(uriArr, ByteBuffer.allocate(0), false);
            ?? r02 = (c40) r15.f17863c.get();
            if (r02 != 0) {
                r02.r(strConcat, r15);
            }
            m7.n.C.f30472k.getClass();
            long jCurrentTimeMillis = System.currentTimeMillis();
            tn tnVar = ao.Z;
            n7.y yVar = n7.y.f31093e;
            long jLongValue = ((Long) yVar.f31096c.b(tnVar)).longValue();
            long jLongValue2 = ((Long) yVar.f31096c.b(ao.Y)).longValue() * 1000;
            long jIntValue = ((Integer) yVar.f31096c.b(ao.f9126w)).intValue();
            boolean zBooleanValue = ((Boolean) yVar.f31096c.b(ao.f8979n2)).booleanValue();
            long j15 = -1;
            long j16 = jIntValue;
            r15 = r15;
            while (true) {
                synchronized (this) {
                    try {
                        if (System.currentTimeMillis() - jCurrentTimeMillis > jLongValue2) {
                            long j17 = jLongValue2;
                            StringBuilder sb = new StringBuilder(String.valueOf(j17).length() + 27);
                            sb.append(str7);
                            sb.append(j17);
                            sb.append(str6);
                            throw new IOException(sb.toString());
                        }
                        if (r15.f10204f) {
                            throw new IOException("Abort requested before buffering finished. ");
                        }
                        if (r15.f10205g) {
                            break;
                        }
                        if (!r15.f10202d.n()) {
                            throw new IOException("ExoPlayer was released during preloading.");
                        }
                        long jR = r15.f10202d.r();
                        if (jR > 0) {
                            long jC = r15.f10202d.C();
                            if (jC != j15) {
                                boolean z13 = jC > 0 ? true : z12;
                                try {
                                    z11 = zBooleanValue;
                                    j13 = j16;
                                    str5 = str;
                                    j11 = jLongValue2;
                                    j14 = jLongValue;
                                    z10 = z12;
                                    str3 = str6;
                                    str4 = str7;
                                    str2 = strConcat;
                                } catch (Throwable th) {
                                    th = th;
                                    z10 = z12;
                                    str2 = strConcat;
                                    r32 = this;
                                    try {
                                        throw th;
                                    } catch (Exception e10) {
                                        e = e10;
                                        String message = e.getMessage();
                                        StringBuilder sb2 = new StringBuilder(String.valueOf(str).length() + 34 + String.valueOf(message).length());
                                        sb2.append("Failed to preload url ");
                                        sb2.append(str);
                                        sb2.append(" Exception: ");
                                        sb2.append(message);
                                        q7.j.d(sb2.toString());
                                        m7.n.C.f30469h.e("VideoStreamExoPlayerCache.preload", e);
                                        b();
                                        r32.zzq(str, str2, IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, s(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, e));
                                        return z10;
                                    }
                                }
                                try {
                                    q7.e.f32222b.post(new s40(this, str5, strConcat, jC, jR, zBooleanValue ? r15.f10202d.s() : -1L, zBooleanValue ? r15.f10202d.t() : -1L, zBooleanValue ? r15.f10202d.u() : -1L, z13, v30.f17495a.get(), v30.f17496b.get()));
                                    j15 = jC;
                                    r32 = str5;
                                } catch (Throwable th2) {
                                    th = th2;
                                    r32 = this;
                                    throw th;
                                }
                            } else {
                                z11 = zBooleanValue;
                                j13 = j16;
                                j11 = jLongValue2;
                                j14 = jLongValue;
                                z10 = z12;
                                str3 = str6;
                                str4 = str7;
                                str2 = strConcat;
                                r32 = j16;
                            }
                            if (jC >= jR) {
                                break;
                            }
                            try {
                                d50 d50Var = this;
                                if (d50Var.f10202d.f14449l < j13 || jC <= 0) {
                                    j12 = j14;
                                    r32 = d50Var;
                                    j10 = j13;
                                }
                            } catch (Throwable th3) {
                                th = th3;
                                throw th;
                            }
                        } else {
                            z11 = zBooleanValue;
                            j10 = j16;
                            j11 = jLongValue2;
                            z10 = z12;
                            str3 = str6;
                            str4 = str7;
                            str2 = strConcat;
                            r32 = r15;
                            j12 = jLongValue;
                        }
                        try {
                            r32.wait(j12);
                        } catch (InterruptedException unused) {
                            throw new IOException("Wait interrupted.");
                        }
                    } catch (Throwable th4) {
                        th = th4;
                        z10 = z12;
                        str2 = strConcat;
                        r32 = r15;
                    }
                }
                zBooleanValue = z11;
                r15 = r32;
                jLongValue = j12;
                strConcat = str2;
                j16 = j10;
                jLongValue2 = j11;
                z12 = z10;
                str6 = str3;
                str7 = str4;
            }
            return true;
        } catch (Exception e11) {
            e = e11;
            z10 = z12;
            str2 = strConcat;
            r32 = r15;
        }
    }

    @Override // com.google.android.gms.internal.ads.w40
    public final boolean l(String str, String[] strArr, p40 p40Var) {
        this.f10203e = str;
        this.f10206h = p40Var;
        String strConcat = "cache:".concat(String.valueOf(q7.e.zzf(str)));
        try {
            Uri[] uriArr = new Uri[strArr.length];
            for (int i10 = 0; i10 < strArr.length; i10++) {
                uriArr[i10] = Uri.parse(strArr[i10]);
            }
            n50 n50Var = this.f10202d;
            n50Var.getClass();
            n50Var.w(uriArr, ByteBuffer.allocate(0), false);
            c40 c40Var = (c40) this.f17863c.get();
            if (c40Var != null) {
                c40Var.r(strConcat, this);
            }
            m7.n.C.f30472k.getClass();
            this.f10207i = System.currentTimeMillis();
            this.f10208j = -1L;
            p7.r0.f31763l.postDelayed(new mv1(this, 23), 0L);
            return true;
        } catch (Exception e10) {
            String message = e10.getMessage();
            StringBuilder sb = new StringBuilder(String.valueOf(str).length() + 34 + String.valueOf(message).length());
            sb.append("Failed to preload url ");
            sb.append(str);
            sb.append(" Exception: ");
            sb.append(message);
            q7.j.d(sb.toString());
            m7.n.C.f30469h.e("VideoStreamExoPlayerCache.preload", e10);
            b();
            zzq(str, strConcat, IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, s(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, e10));
            return false;
        }
    }

    @Override // com.google.android.gms.internal.ads.w40
    public final void m(int i10) {
        g50 g50Var = this.f10202d.f14441d;
        synchronized (g50Var) {
            g50Var.f11487c = ((long) i10) * 1000;
        }
    }

    @Override // com.google.android.gms.internal.ads.w40
    public final void n(int i10) {
        g50 g50Var = this.f10202d.f14441d;
        synchronized (g50Var) {
            g50Var.f11486b = ((long) i10) * 1000;
        }
    }

    @Override // com.google.android.gms.internal.ads.w40
    public final void o(int i10) {
        g50 g50Var = this.f10202d.f14441d;
        synchronized (g50Var) {
            g50Var.f11488d = ((long) i10) * 1000;
        }
    }

    @Override // com.google.android.gms.internal.ads.w40
    public final void p(int i10) {
        g50 g50Var = this.f10202d.f14441d;
        synchronized (g50Var) {
            g50Var.f11489e = ((long) i10) * 1000;
        }
    }

    @Override // com.google.android.gms.internal.ads.w40
    public final void q() {
        synchronized (this) {
            this.f10204f = true;
            notify();
            b();
        }
        String str = this.f10203e;
        if (str != null) {
            zzq(this.f10203e, "cache:".concat(String.valueOf(q7.e.zzf(str))), "externalAbort", "Programmatic precache abort.");
        }
    }

    @Override // com.google.android.gms.internal.ads.u30
    public final void v(int i10) {
    }
}
