package androidx.media3.common;

import android.os.Bundle;
import android.os.RemoteException;
import android.os.SystemClock;
import android.text.TextUtils;
import androidx.annotation.CallSuper;
import androidx.annotation.Nullable;
import androidx.media3.common.util.Clock;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public class PlaybackException extends Exception {
    public static final int CUSTOM_ERROR_CODE_BASE = 1000000;
    public static final int ERROR_CODE_AUDIO_TRACK_INIT_FAILED = 5001;
    public static final int ERROR_CODE_AUDIO_TRACK_OFFLOAD_INIT_FAILED = 5004;
    public static final int ERROR_CODE_AUDIO_TRACK_OFFLOAD_WRITE_FAILED = 5003;
    public static final int ERROR_CODE_AUDIO_TRACK_WRITE_FAILED = 5002;
    public static final int ERROR_CODE_AUTHENTICATION_EXPIRED = -102;
    public static final int ERROR_CODE_BAD_VALUE = -3;
    public static final int ERROR_CODE_BEHIND_LIVE_WINDOW = 1002;
    public static final int ERROR_CODE_CONCURRENT_STREAM_LIMIT = -104;
    public static final int ERROR_CODE_CONTENT_ALREADY_PLAYING = -110;
    public static final int ERROR_CODE_DECODER_INIT_FAILED = 4001;
    public static final int ERROR_CODE_DECODER_QUERY_FAILED = 4002;
    public static final int ERROR_CODE_DECODING_FAILED = 4003;
    public static final int ERROR_CODE_DECODING_FORMAT_EXCEEDS_CAPABILITIES = 4004;
    public static final int ERROR_CODE_DECODING_FORMAT_UNSUPPORTED = 4005;
    public static final int ERROR_CODE_DECODING_RESOURCES_RECLAIMED = 4006;
    public static final int ERROR_CODE_DISCONNECTED = -100;
    public static final int ERROR_CODE_DRM_CONTENT_ERROR = 6003;
    public static final int ERROR_CODE_DRM_DEVICE_REVOKED = 6007;
    public static final int ERROR_CODE_DRM_DISALLOWED_OPERATION = 6005;
    public static final int ERROR_CODE_DRM_LICENSE_ACQUISITION_FAILED = 6004;
    public static final int ERROR_CODE_DRM_LICENSE_EXPIRED = 6008;
    public static final int ERROR_CODE_DRM_PROVISIONING_FAILED = 6002;
    public static final int ERROR_CODE_DRM_SCHEME_UNSUPPORTED = 6001;
    public static final int ERROR_CODE_DRM_SYSTEM_ERROR = 6006;
    public static final int ERROR_CODE_DRM_UNSPECIFIED = 6000;
    public static final int ERROR_CODE_END_OF_PLAYLIST = -109;
    public static final int ERROR_CODE_FAILED_RUNTIME_CHECK = 1004;
    public static final int ERROR_CODE_INVALID_STATE = -2;
    public static final int ERROR_CODE_IO_BAD_HTTP_STATUS = 2004;
    public static final int ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED = 2007;
    public static final int ERROR_CODE_IO_FILE_NOT_FOUND = 2005;
    public static final int ERROR_CODE_IO_INVALID_HTTP_CONTENT_TYPE = 2003;
    public static final int ERROR_CODE_IO_NETWORK_CONNECTION_FAILED = 2001;
    public static final int ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT = 2002;
    public static final int ERROR_CODE_IO_NO_PERMISSION = 2006;
    public static final int ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE = 2008;
    public static final int ERROR_CODE_IO_UNSPECIFIED = 2000;
    public static final int ERROR_CODE_NOT_AVAILABLE_IN_REGION = -106;
    public static final int ERROR_CODE_NOT_SUPPORTED = -6;
    public static final int ERROR_CODE_PARENTAL_CONTROL_RESTRICTED = -105;
    public static final int ERROR_CODE_PARSING_CONTAINER_MALFORMED = 3001;
    public static final int ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED = 3003;
    public static final int ERROR_CODE_PARSING_MANIFEST_MALFORMED = 3002;
    public static final int ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED = 3004;
    public static final int ERROR_CODE_PERMISSION_DENIED = -4;
    public static final int ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED = -103;
    public static final int ERROR_CODE_REMOTE_ERROR = 1001;
    public static final int ERROR_CODE_SETUP_REQUIRED = -108;
    public static final int ERROR_CODE_SKIP_LIMIT_REACHED = -107;
    public static final int ERROR_CODE_TIMEOUT = 1003;
    public static final int ERROR_CODE_UNSPECIFIED = 1000;

    @UnstableApi
    public static final int ERROR_CODE_VIDEO_FRAME_PROCESSING_FAILED = 7001;

    @UnstableApi
    public static final int ERROR_CODE_VIDEO_FRAME_PROCESSOR_INIT_FAILED = 7000;

    @UnstableApi
    protected static final int FIELD_CUSTOM_ID_BASE = 1000;
    public final int errorCode;

    @UnstableApi
    public final Bundle extras;
    public final long timestampMs;
    private static final String FIELD_INT_ERROR_CODE = Util.intToStringMaxRadix(0);
    private static final String FIELD_LONG_TIMESTAMP_MS = Util.intToStringMaxRadix(1);
    private static final String FIELD_STRING_MESSAGE = Util.intToStringMaxRadix(2);
    private static final String FIELD_STRING_CAUSE_CLASS_NAME = Util.intToStringMaxRadix(3);
    private static final String FIELD_STRING_CAUSE_MESSAGE = Util.intToStringMaxRadix(4);
    private static final String FIELD_BUNDLE_EXTRAS = Util.intToStringMaxRadix(5);

    @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE})
    @Documented
    @Retention(RetentionPolicy.SOURCE)
    public @interface ErrorCode {
    }

    @UnstableApi
    public PlaybackException(@Nullable String str, @Nullable Throwable th, int i10) {
        this(str, th, i10, Bundle.EMPTY, Clock.DEFAULT.elapsedRealtime());
    }

    @UnstableApi
    public static boolean areErrorInfosEqual(@Nullable PlaybackException playbackException, @Nullable PlaybackException playbackException2) {
        return playbackException != null ? playbackException.errorInfoEquals(playbackException2) : playbackException2 == null;
    }

    private static RemoteException createRemoteException(@Nullable String str) {
        return new RemoteException(str);
    }

    private static Throwable createThrowable(Class<?> cls, @Nullable String str) throws Exception {
        return (Throwable) cls.getConstructor(String.class).newInstance(str);
    }

    @UnstableApi
    public static PlaybackException fromBundle(Bundle bundle) {
        return new PlaybackException(bundle);
    }

    @Nullable
    private static Throwable getCauseFromBundle(Bundle bundle) {
        String string = bundle.getString(FIELD_STRING_CAUSE_CLASS_NAME);
        String string2 = bundle.getString(FIELD_STRING_CAUSE_MESSAGE);
        if (TextUtils.isEmpty(string)) {
            return null;
        }
        try {
            Class<?> cls = Class.forName(string, true, PlaybackException.class.getClassLoader());
            Throwable thCreateThrowable = Throwable.class.isAssignableFrom(cls) ? createThrowable(cls, string2) : null;
            if (thCreateThrowable != null) {
                return thCreateThrowable;
            }
        } catch (Throwable unused) {
        }
        return createRemoteException(string2);
    }

    public static String getErrorCodeName(int i10) {
        if (i10 == -100) {
            return "ERROR_CODE_DISCONNECTED";
        }
        if (i10 == -6) {
            return "ERROR_CODE_NOT_SUPPORTED";
        }
        if (i10 == -4) {
            return "ERROR_CODE_PERMISSION_DENIED";
        }
        if (i10 == -3) {
            return "ERROR_CODE_BAD_VALUE";
        }
        if (i10 == -2) {
            return "ERROR_CODE_INVALID_STATE";
        }
        if (i10 == 7000) {
            return "ERROR_CODE_VIDEO_FRAME_PROCESSOR_INIT_FAILED";
        }
        if (i10 == 7001) {
            return "ERROR_CODE_VIDEO_FRAME_PROCESSING_FAILED";
        }
        switch (i10) {
            case -110:
                return "ERROR_CODE_CONTENT_ALREADY_PLAYING";
            case ERROR_CODE_END_OF_PLAYLIST /* -109 */:
                return "ERROR_CODE_END_OF_PLAYLIST";
            case ERROR_CODE_SETUP_REQUIRED /* -108 */:
                return "ERROR_CODE_SETUP_REQUIRED";
            case ERROR_CODE_SKIP_LIMIT_REACHED /* -107 */:
                return "ERROR_CODE_SKIP_LIMIT_REACHED";
            case ERROR_CODE_NOT_AVAILABLE_IN_REGION /* -106 */:
                return "ERROR_CODE_NOT_AVAILABLE_IN_REGION";
            case ERROR_CODE_PARENTAL_CONTROL_RESTRICTED /* -105 */:
                return "ERROR_CODE_PARENTAL_CONTROL_RESTRICTED";
            case ERROR_CODE_CONCURRENT_STREAM_LIMIT /* -104 */:
                return "ERROR_CODE_CONCURRENT_STREAM_LIMIT";
            case ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED /* -103 */:
                return "ERROR_CODE_PREMIUM_ACCOUNT_REQUIRED";
            case ERROR_CODE_AUTHENTICATION_EXPIRED /* -102 */:
                return "ERROR_CODE_AUTHENTICATION_EXPIRED";
            default:
                switch (i10) {
                    case 1000:
                        return "ERROR_CODE_UNSPECIFIED";
                    case 1001:
                        return "ERROR_CODE_REMOTE_ERROR";
                    case 1002:
                        return "ERROR_CODE_BEHIND_LIVE_WINDOW";
                    case 1003:
                        return "ERROR_CODE_TIMEOUT";
                    case 1004:
                        return "ERROR_CODE_FAILED_RUNTIME_CHECK";
                    default:
                        switch (i10) {
                            case 2000:
                                return "ERROR_CODE_IO_UNSPECIFIED";
                            case ERROR_CODE_IO_NETWORK_CONNECTION_FAILED /* 2001 */:
                                return "ERROR_CODE_IO_NETWORK_CONNECTION_FAILED";
                            case ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT /* 2002 */:
                                return "ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT";
                            case ERROR_CODE_IO_INVALID_HTTP_CONTENT_TYPE /* 2003 */:
                                return "ERROR_CODE_IO_INVALID_HTTP_CONTENT_TYPE";
                            case ERROR_CODE_IO_BAD_HTTP_STATUS /* 2004 */:
                                return "ERROR_CODE_IO_BAD_HTTP_STATUS";
                            case ERROR_CODE_IO_FILE_NOT_FOUND /* 2005 */:
                                return "ERROR_CODE_IO_FILE_NOT_FOUND";
                            case ERROR_CODE_IO_NO_PERMISSION /* 2006 */:
                                return "ERROR_CODE_IO_NO_PERMISSION";
                            case ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED /* 2007 */:
                                return "ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED";
                            case 2008:
                                return "ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE";
                            default:
                                switch (i10) {
                                    case ERROR_CODE_PARSING_CONTAINER_MALFORMED /* 3001 */:
                                        return "ERROR_CODE_PARSING_CONTAINER_MALFORMED";
                                    case ERROR_CODE_PARSING_MANIFEST_MALFORMED /* 3002 */:
                                        return "ERROR_CODE_PARSING_MANIFEST_MALFORMED";
                                    case ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED /* 3003 */:
                                        return "ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED";
                                    case ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED /* 3004 */:
                                        return "ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED";
                                    default:
                                        switch (i10) {
                                            case ERROR_CODE_DECODER_INIT_FAILED /* 4001 */:
                                                return "ERROR_CODE_DECODER_INIT_FAILED";
                                            case ERROR_CODE_DECODER_QUERY_FAILED /* 4002 */:
                                                return "ERROR_CODE_DECODER_QUERY_FAILED";
                                            case ERROR_CODE_DECODING_FAILED /* 4003 */:
                                                return "ERROR_CODE_DECODING_FAILED";
                                            case ERROR_CODE_DECODING_FORMAT_EXCEEDS_CAPABILITIES /* 4004 */:
                                                return "ERROR_CODE_DECODING_FORMAT_EXCEEDS_CAPABILITIES";
                                            case ERROR_CODE_DECODING_FORMAT_UNSUPPORTED /* 4005 */:
                                                return "ERROR_CODE_DECODING_FORMAT_UNSUPPORTED";
                                            case ERROR_CODE_DECODING_RESOURCES_RECLAIMED /* 4006 */:
                                                return "ERROR_CODE_DECODING_RESOURCES_RECLAIMED";
                                            default:
                                                switch (i10) {
                                                    case ERROR_CODE_AUDIO_TRACK_INIT_FAILED /* 5001 */:
                                                        return "ERROR_CODE_AUDIO_TRACK_INIT_FAILED";
                                                    case ERROR_CODE_AUDIO_TRACK_WRITE_FAILED /* 5002 */:
                                                        return "ERROR_CODE_AUDIO_TRACK_WRITE_FAILED";
                                                    case ERROR_CODE_AUDIO_TRACK_OFFLOAD_WRITE_FAILED /* 5003 */:
                                                        return "ERROR_CODE_AUDIO_TRACK_OFFLOAD_WRITE_FAILED";
                                                    case ERROR_CODE_AUDIO_TRACK_OFFLOAD_INIT_FAILED /* 5004 */:
                                                        return "ERROR_CODE_AUDIO_TRACK_OFFLOAD_INIT_FAILED";
                                                    default:
                                                        switch (i10) {
                                                            case ERROR_CODE_DRM_UNSPECIFIED /* 6000 */:
                                                                return "ERROR_CODE_DRM_UNSPECIFIED";
                                                            case ERROR_CODE_DRM_SCHEME_UNSUPPORTED /* 6001 */:
                                                                return "ERROR_CODE_DRM_SCHEME_UNSUPPORTED";
                                                            case ERROR_CODE_DRM_PROVISIONING_FAILED /* 6002 */:
                                                                return "ERROR_CODE_DRM_PROVISIONING_FAILED";
                                                            case ERROR_CODE_DRM_CONTENT_ERROR /* 6003 */:
                                                                return "ERROR_CODE_DRM_CONTENT_ERROR";
                                                            case ERROR_CODE_DRM_LICENSE_ACQUISITION_FAILED /* 6004 */:
                                                                return "ERROR_CODE_DRM_LICENSE_ACQUISITION_FAILED";
                                                            case ERROR_CODE_DRM_DISALLOWED_OPERATION /* 6005 */:
                                                                return "ERROR_CODE_DRM_DISALLOWED_OPERATION";
                                                            case ERROR_CODE_DRM_SYSTEM_ERROR /* 6006 */:
                                                                return "ERROR_CODE_DRM_SYSTEM_ERROR";
                                                            case ERROR_CODE_DRM_DEVICE_REVOKED /* 6007 */:
                                                                return "ERROR_CODE_DRM_DEVICE_REVOKED";
                                                            case ERROR_CODE_DRM_LICENSE_EXPIRED /* 6008 */:
                                                                return "ERROR_CODE_DRM_LICENSE_EXPIRED";
                                                            default:
                                                                return i10 >= 1000000 ? "custom error code" : "invalid error code";
                                                        }
                                                }
                                        }
                                }
                        }
                }
        }
    }

    private static Bundle getExtrasFromBundle(Bundle bundle) {
        Bundle bundle2 = bundle.getBundle(FIELD_BUNDLE_EXTRAS);
        return bundle2 != null ? bundle2 : Bundle.EMPTY;
    }

    /* JADX WARN: Code restructure failed: missing block: B:20:0x003e, code lost:
    
        if (r3 == null) goto L22;
     */
    @CallSuper
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean errorInfoEquals(@Nullable PlaybackException playbackException) {
        if (this == playbackException) {
            return true;
        }
        if (playbackException != null && getClass() == playbackException.getClass()) {
            Throwable cause = getCause();
            Throwable cause2 = playbackException.getCause();
            if (cause == null || cause2 == null) {
                if (cause == null) {
                }
            } else if (!Objects.equals(cause.getMessage(), cause2.getMessage()) || !cause.getClass().equals(cause2.getClass())) {
                return false;
            }
            return this.errorCode == playbackException.errorCode && Objects.equals(getMessage(), playbackException.getMessage()) && this.timestampMs == playbackException.timestampMs;
        }
        return false;
    }

    @CallSuper
    @UnstableApi
    public Bundle toBundle() {
        Bundle bundle = new Bundle();
        bundle.putInt(FIELD_INT_ERROR_CODE, this.errorCode);
        bundle.putLong(FIELD_LONG_TIMESTAMP_MS, this.timestampMs);
        bundle.putString(FIELD_STRING_MESSAGE, getMessage());
        bundle.putBundle(FIELD_BUNDLE_EXTRAS, this.extras);
        Throwable cause = getCause();
        if (cause != null) {
            bundle.putString(FIELD_STRING_CAUSE_CLASS_NAME, cause.getClass().getName());
            bundle.putString(FIELD_STRING_CAUSE_MESSAGE, cause.getMessage());
        }
        return bundle;
    }

    @UnstableApi
    public PlaybackException(@Nullable String str, @Nullable Throwable th, int i10, Bundle bundle) {
        this(str, th, i10, bundle, Clock.DEFAULT.elapsedRealtime());
    }

    public final String getErrorCodeName() {
        return getErrorCodeName(this.errorCode);
    }

    @UnstableApi
    public PlaybackException(Bundle bundle) {
        this(bundle.getString(FIELD_STRING_MESSAGE), getCauseFromBundle(bundle), bundle.getInt(FIELD_INT_ERROR_CODE, 1000), getExtrasFromBundle(bundle), bundle.getLong(FIELD_LONG_TIMESTAMP_MS, SystemClock.elapsedRealtime()));
    }

    @UnstableApi
    public PlaybackException(@Nullable String str, @Nullable Throwable th, int i10, Bundle bundle, long j10) {
        super(str, th);
        this.errorCode = i10;
        this.extras = bundle;
        this.timestampMs = j10;
    }
}
