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;

/* renamed from: ˏᵮᵲ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1899 implements InterfaceC5524, InterfaceC4442 {

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public static final C1899 f7665;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public static final C1899 f7666;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public boolean f7667;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final /* synthetic */ int f7668;

    static {
        int i = 0;
        f7666 = new C1899(i, true);
        f7665 = new C1899(i, false);
    }

    public C1899(int i) {
        this.f7668 = i;
        switch (i) {
            case C1339.STRING_SET_FIELD_NUMBER /* 6 */:
                break;
            default:
                this.f7667 = false;
                break;
        }
    }

    public /* synthetic */ C1899(int i, boolean z) {
        this.f7668 = i;
        this.f7667 = z;
    }

    public C1899(Context context, Looper looper, C1875 c1875) {
        this.f7668 = 4;
        new ˊᵿʗ(context.getApplicationContext());
        c1875.m5287(looper, null);
        c1875.m5287(Looper.getMainLooper(), null);
    }

    public C1899(C4134 c4134, C2184 c2184) throws C4001 {
        this.f7668 = 2;
        int i = c2184.f8595;
        ByteBuffer byteBuffer = c2184.f8596;
        ᵛᵾˏ.ᵯٴᵦ(i == 6 || i == 3);
        int iMin = Math.min(4, byteBuffer.remaining());
        byte[] bArr = new byte[iMin];
        byteBuffer.asReadOnlyBuffer().get(bArr);
        C4089 c4089 = new C4089(iMin, bArr);
        if (c4134.f15453) {
            throw new C4001();
        }
        if (c4089.m8964()) {
            this.f7667 = false;
            return;
        }
        int iM8966 = c4089.m8966(2);
        boolean zM8964 = c4089.m8964();
        if (c4134.f15457) {
            throw new C4001();
        }
        if (!zM8964) {
            this.f7667 = true;
            return;
        }
        boolean zM89642 = (iM8966 == 3 || iM8966 == 0) ? true : c4089.m8964();
        c4089.m8965();
        if (!c4134.f15461) {
            throw new C4001();
        }
        if (c4089.m8964()) {
            if (!c4134.f15447) {
                throw new C4001();
            }
            c4089.m8965();
        }
        if (c4134.f15451) {
            throw new C4001();
        }
        if (iM8966 != 3) {
            c4089.m8965();
        }
        c4089.m8956(c4134.f15450);
        if (iM8966 != 2 && iM8966 != 0 && !zM89642) {
            c4089.m8956(3);
        }
        this.f7667 = ((iM8966 == 3 || iM8966 == 0) ? 255 : c4089.m8966(8)) != 0;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public static C3160 m5317(C3103 c3103, C2124 c2124) {
        IOException iOException = (IOException) c2124.f8376;
        if (!(iOException instanceof HttpDataSource$InvalidResponseCodeException)) {
            return null;
        }
        int i = ((HttpDataSource$InvalidResponseCodeException) iOException).f561;
        if (i != 403 && i != 404 && i != 410 && i != 416 && i != 500 && i != 503) {
            return null;
        }
        if (c3103.m7434(1)) {
            return new C3160(300000L, 1);
        }
        if (c3103.m7434(2)) {
            return new C3160(60000L, 2);
        }
        return null;
    }

    public String toString() {
        switch (this.f7668) {
            case 0:
                return AbstractC1327.m4090(new StringBuilder("IncorrectFragmentation{expected="), !this.f7667, "}");
            default:
                return super.toString();
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // defpackage.InterfaceC4442
    /* renamed from: ˇʼʤˎ */
    public /* bridge */ /* synthetic */ Object mo2355(C1770 c1770) {
        C2511 c2511M6366;
        InputStream inputStream = ᵸᵡˋʧ.ˑᵥˁ(c1770);
        try {
            int i = 4096;
            if (this.f7667) {
                if (inputStream instanceof InterfaceC4660) {
                    long length = ((InterfaceC4660) inputStream).mo8845().length();
                    if (length == 0) {
                        i = 512;
                    } else if (length < 4096) {
                        i = (int) length;
                    }
                }
                c2511M6366 = C2511.m6366(AbstractC3415.m7775(inputStream, i), true);
            } else {
                c2511M6366 = C2511.m6366(AbstractC3415.m7775(inputStream, 4096), false);
            }
            ˋᵮᵯᵔ.ˎˏʜʾ(inputStream, (Throwable) null);
            return c2511M6366;
        } catch (Throwable th) {
            try {
                throw th;
            } catch (Throwable th2) {
                ˋᵮᵯᵔ.ˎˏʜʾ(inputStream, th);
                throw th2;
            }
        }
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public long m5318(C2124 c2124) {
        Throwable cause = (IOException) c2124.f8376;
        if ((cause instanceof HttpDataSource$InvalidResponseCodeException) && (this.f7667 || ((HttpDataSource$InvalidResponseCodeException) cause).f561 == 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((c2124.f8374 - 1) * 1000, 5000);
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public int m5319(int i) {
        return i == 7 ? 6 : 3;
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public void m5320(boolean z) {
        if (this.f7667 == z) {
            return;
        }
        this.f7667 = z;
    }
}
