package defpackage;

import android.content.Context;
import android.os.Looper;
import androidx.media3.common.ParserException;
import androidx.media3.datasource.DataSourceException;
import androidx.media3.datasource.HttpDataSource$CleartextNotPermittedException;
import androidx.media3.datasource.HttpDataSource$InvalidResponseCodeException;
import androidx.media3.exoplayer.upstream.Loader$UnexpectedLoaderException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;

/* JADX INFO: renamed from: ˈʚ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1013 implements InterfaceC5444, InterfaceC2437 {

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public static final C1013 f4395;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public static final C1013 f4396;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final /* synthetic */ int f4397;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public boolean f4398;

    static {
        int i = 0;
        f4395 = new C1013(i, true);
        f4396 = new C1013(i, false);
    }

    public C1013() {
        this.f4397 = 2;
        this.f4398 = false;
    }

    public /* synthetic */ C1013(int i) {
        this.f4397 = i;
    }

    public /* synthetic */ C1013(int i, boolean z) {
        this.f4397 = i;
        this.f4398 = z;
    }

    public C1013(Context context, Looper looper, C2353 c2353) {
        this.f4397 = 5;
        new ᵨᵡᵱ(context.getApplicationContext());
        c2353.m6030(looper, null);
        c2353.m6030(Looper.getMainLooper(), null);
    }

    public C1013(C1985 c1985, C3506 c3506) throws C3470 {
        this.f4397 = 3;
        int i = c3506.f13469;
        ByteBuffer byteBuffer = c3506.f13468;
        ᵻᵪ.ᵱᵽʡᵚ(i == 6 || i == 3);
        int iMin = Math.min(4, byteBuffer.remaining());
        byte[] bArr = new byte[iMin];
        byteBuffer.asReadOnlyBuffer().get(bArr);
        C3180 c3180 = new C3180(iMin, bArr);
        if (c1985.f7867) {
            throw new C3470();
        }
        if (c3180.m7299()) {
            this.f4398 = false;
            return;
        }
        int iM7302 = c3180.m7302(2);
        boolean zM7299 = c3180.m7299();
        if (c1985.f7858) {
            throw new C3470();
        }
        if (!zM7299) {
            this.f4398 = true;
            return;
        }
        boolean zM72992 = (iM7302 == 3 || iM7302 == 0) ? true : c3180.m7299();
        c3180.m7288();
        if (!c1985.f7870) {
            throw new C3470();
        }
        if (c3180.m7299()) {
            if (!c1985.f7863) {
                throw new C3470();
            }
            c3180.m7288();
        }
        if (c1985.f7861) {
            throw new C3470();
        }
        if (iM7302 != 3) {
            c3180.m7288();
        }
        c3180.m7287(c1985.f7872);
        if (iM7302 != 2 && iM7302 != 0 && !zM72992) {
            c3180.m7287(3);
        }
        this.f4398 = ((iM7302 == 3 || iM7302 == 0) ? 255 : c3180.m7302(8)) != 0;
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static C0655 m3344(C4973 c4973, C1785 c1785) {
        IOException iOException = (IOException) c1785.f7162;
        if (!(iOException instanceof HttpDataSource$InvalidResponseCodeException)) {
            return null;
        }
        int i = ((HttpDataSource$InvalidResponseCodeException) iOException).f560;
        if (i != 403 && i != 404 && i != 410 && i != 416 && i != 500 && i != 503) {
            return null;
        }
        if (c4973.m10283(1)) {
            return new C0655(300000L, 1);
        }
        if (c4973.m10283(2)) {
            return new C0655(60000L, 2);
        }
        return null;
    }

    public String toString() {
        switch (this.f4397) {
            case 0:
                StringBuilder sb = new StringBuilder("IncorrectFragmentation{expected=");
                sb.append(!this.f4398);
                sb.append("}");
                return sb.toString();
            default:
                return super.toString();
        }
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public int m3345(int i) {
        return i == 7 ? 6 : 3;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public long m3346(C1785 c1785) {
        Throwable cause = (IOException) c1785.f7162;
        if ((cause instanceof HttpDataSource$InvalidResponseCodeException) && (this.f4398 || ((HttpDataSource$InvalidResponseCodeException) cause).f560 == 401)) {
            return -9223372036854775807L;
        }
        while (cause != null) {
            if ((cause instanceof ParserException) || (cause instanceof FileNotFoundException) || (cause instanceof HttpDataSource$CleartextNotPermittedException) || (cause instanceof Loader$UnexpectedLoaderException)) {
                return -9223372036854775807L;
            }
            if ((cause instanceof DataSourceException) && ((DataSourceException) cause).f558 == 2008) {
                return -9223372036854775807L;
            }
            cause = cause.getCause();
        }
        return Math.min((c1785.f7163 - 1) * 1000, 5000);
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // defpackage.InterfaceC2437
    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public /* bridge */ /* synthetic */ Object mo3347(C5339 c5339) {
        C2831 c2831M6814;
        InputStream inputStream = ᵻᵪ.ᵵᵬᵽ(c5339);
        try {
            int i = 4096;
            if (this.f4398) {
                if (inputStream instanceof InterfaceC4388) {
                    long length = ((InterfaceC4388) inputStream).mo5962().length();
                    if (length == 0) {
                        i = 512;
                    } else if (length < 4096) {
                        i = (int) length;
                    }
                }
                c2831M6814 = C2831.m6814(AbstractC5456.m11073(inputStream, i), true);
            } else {
                c2831M6814 = C2831.m6814(AbstractC5456.m11073(inputStream, 4096), false);
            }
            ᵱˉˈ.ᵮᵣᵗˈ(inputStream, (Throwable) null);
            return c2831M6814;
        } catch (Throwable th) {
            try {
                throw th;
            } catch (Throwable th2) {
                ᵱˉˈ.ᵮᵣᵗˈ(inputStream, th);
                throw th2;
            }
        }
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public void m3348(boolean z) {
        if (this.f4398 == z) {
            return;
        }
        this.f4398 = z;
    }
}
