package defpackage;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import androidx.media3.extractor.text.SubtitleDecoderException;
import j$.util.Objects;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;

/* JADX INFO: renamed from: ᵖᵵ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C2457 extends AbstractC0799 implements Handler.Callback {

    /* JADX INFO: renamed from: ʽᵡᵢᵾ, reason: contains not printable characters */
    public InterfaceC3876 f9543;

    /* JADX INFO: renamed from: ʿᵿʽᵞ, reason: contains not printable characters */
    public final Handler f9544;

    /* JADX INFO: renamed from: ˀᵗ, reason: contains not printable characters */
    public AbstractC3334 f9545;

    /* JADX INFO: renamed from: ˁʢᵛ, reason: contains not printable characters */
    public C1561 f9546;

    /* JADX INFO: renamed from: ˁᵺˈ, reason: contains not printable characters */
    public C5286 f9547;

    /* JADX INFO: renamed from: ˈⁱᵡ, reason: contains not printable characters */
    public final InterfaceC5061 f9548;

    /* JADX INFO: renamed from: ˉˆᵗ, reason: contains not printable characters */
    public boolean f9549;

    /* JADX INFO: renamed from: ˊˌˊ, reason: contains not printable characters */
    public InterfaceC1641 f9550;

    /* JADX INFO: renamed from: ˋʿᐧ, reason: contains not printable characters */
    public boolean f9551;

    /* JADX INFO: renamed from: ˋᵯᵩ, reason: contains not printable characters */
    public long f9552;

    /* JADX INFO: renamed from: ˏᵩʨ, reason: contains not printable characters */
    public AbstractC3334 f9553;

    /* JADX INFO: renamed from: ːᵝٴᵶ, reason: contains not printable characters */
    public boolean f9554;

    /* JADX INFO: renamed from: ˑʢ, reason: contains not printable characters */
    public final C3008 f9555;

    /* JADX INFO: renamed from: ᵛˀˊ, reason: contains not printable characters */
    public int f9556;

    /* JADX INFO: renamed from: ᵜᵤ, reason: contains not printable characters */
    public long f9557;

    /* JADX INFO: renamed from: ᵞᵛᵘ, reason: contains not printable characters */
    public int f9558;

    /* JADX INFO: renamed from: ᵡᵶ, reason: contains not printable characters */
    public final SurfaceHolderCallbackC2683 f9559;

    /* JADX INFO: renamed from: ᵡᵶᵬʤ, reason: contains not printable characters */
    public final ˊˊᵞᵽ f9560;

    /* JADX INFO: renamed from: ᵨˈʼﹶ, reason: contains not printable characters */
    public boolean f9561;

    /* JADX INFO: renamed from: ᵵᵬᵽ, reason: contains not printable characters */
    public final ˉᵠﹳᵘ f9562;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C2457(SurfaceHolderCallbackC2683 surfaceHolderCallbackC2683, Looper looper) {
        super(3);
        ʽˎˇˌ r0 = InterfaceC5061.f19111;
        this.f9559 = surfaceHolderCallbackC2683;
        this.f9544 = new Handler(looper, this);
        this.f9548 = r0;
        this.f9562 = new ˉᵠﹳᵘ(16);
        this.f9555 = new C3008(1, 0);
        this.f9560 = new ˊˊᵞᵽ(27, false);
        this.f9557 = -9223372036854775807L;
        this.f9552 = -9223372036854775807L;
        this.f9554 = false;
    }

    @Override // android.os.Handler.Callback
    public final boolean handleMessage(Message message) {
        if (message.what == 1) {
            m6207((C4284) message.obj);
            return true;
        }
        ᵷᵝˎ.ᵱʡˏ();
        return false;
    }

    /* JADX INFO: renamed from: ʿٴˇ, reason: contains not printable characters */
    public final long m6205() {
        if (this.f9556 == -1) {
            return Long.MAX_VALUE;
        }
        this.f9545.getClass();
        if (this.f9556 >= this.f9545.mo3131()) {
            return Long.MAX_VALUE;
        }
        return this.f9545.mo3133(this.f9556);
    }

    /* JADX INFO: renamed from: ˀᵭ, reason: contains not printable characters */
    public final void m6206() {
        this.f9546 = null;
        this.f9556 = -1;
        AbstractC3334 abstractC3334 = this.f9545;
        if (abstractC3334 != null) {
            abstractC3334.mo359();
            this.f9545 = null;
        }
        AbstractC3334 abstractC33342 = this.f9553;
        if (abstractC33342 != null) {
            abstractC33342.mo359();
            this.f9553 = null;
        }
    }

    /* JADX INFO: renamed from: ˁˌᵩ, reason: contains not printable characters */
    public final void m6207(C4284 c4284) {
        C2598 c2598 = c4284.f16346;
        SurfaceHolderCallbackC2683 surfaceHolderCallbackC2683 = this.f9559;
        surfaceHolderCallbackC2683.f10352.f12452.m7412(27, new ᵳᵢᵺ(25, c2598));
        C3262 c3262 = surfaceHolderCallbackC2683.f10352;
        c3262.f12446 = c4284;
        c3262.f12452.m7412(27, new ᵳᵢᵺ(22, c4284));
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ˈᵲᵢ */
    public final int mo376(C5286 c5286) {
        boolean zEquals = Objects.equals(c5286.f19987, "application/x-media3-cues");
        String str = c5286.f19987;
        if (!zEquals) {
            ʽˎˇˌ r3 = this.f9548;
            r3.getClass();
            if (!((ᵱᵻᵧᵷ) r3.ᵜᵪʾ).ᵷᵺʾᵖ(c5286) && !Objects.equals(str, "application/cea-608") && !Objects.equals(str, "application/x-mp4-cea-608") && !Objects.equals(str, "application/cea-708")) {
                return AbstractC4208.m9129(str) ? AbstractC2704.m6526(1, 0, 0, 0) : AbstractC2704.m6526(0, 0, 0, 0);
            }
        }
        return AbstractC2704.m6526(c5286.f19959 == 0 ? 4 : 2, 0, 0, 0);
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x0050  */
    /* JADX INFO: renamed from: ˉᵵᵜ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m6208() {
        InterfaceC1641 c5121;
        this.f9561 = true;
        C5286 c5286 = this.f9547;
        c5286.getClass();
        ᵱᵻᵧᵷ r2 = (ᵱᵻᵧᵷ) this.f9548.ᵜᵪʾ;
        String str = c5286.f19987;
        int i = c5286.f19968;
        if (str != null) {
            switch (str) {
                case "application/x-mp4-cea-608":
                case "application/cea-608":
                    c5121 = new C5411(i, str);
                    break;
                case "application/cea-708":
                    c5121 = new C0605(i, c5286.f19967);
                    break;
                default:
                    if (!r2.ᵷᵺʾᵖ(c5286)) {
                        ᵕᵩʽᵲ.ᵮᵣᵗˈ(AbstractC3589.m8102("Attempted to create decoder for unsupported MIME type: ", str));
                        return;
                    } else {
                        InterfaceC3971 interfaceC3971 = r2.ᵱʡˏ(c5286);
                        c5121 = new C5121(interfaceC3971.getClass().getSimpleName().concat("Decoder"), interfaceC3971);
                        break;
                    }
                    break;
            }
        }
        this.f9550 = c5121;
        c5121.mo2935(this.f3593);
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ˊᵨᵧ */
    public final void mo380(C5286[] c5286Arr, long j, long j2, C4100 c4100) {
        C5286 c5286 = c5286Arr[0];
        this.f9547 = c5286;
        if (Objects.equals(c5286.f19987, "application/x-media3-cues")) {
            this.f9543 = this.f9547.f19980 == 1 ? new C0390() : new C0738(1);
            return;
        }
        m6209();
        if (this.f9550 != null) {
            this.f9558 = 1;
        } else {
            m6208();
        }
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ˋˈ */
    public final void mo383() {
        this.f9547 = null;
        this.f9557 = -9223372036854775807L;
        C2598 c2598 = C2598.f10048;
        m6210(this.f9552);
        C4284 c4284 = new C4284(c2598);
        Handler handler = this.f9544;
        if (handler != null) {
            handler.obtainMessage(1, c4284).sendToTarget();
        } else {
            m6207(c4284);
        }
        this.f9552 = -9223372036854775807L;
        if (this.f9550 != null) {
            m6206();
            InterfaceC1641 interfaceC1641 = this.f9550;
            interfaceC1641.getClass();
            interfaceC1641.mo364();
            this.f9550 = null;
            this.f9558 = 0;
        }
    }

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public final void m6209() {
        boolean z = this.f9554 || Objects.equals(this.f9547.f19987, "application/cea-608") || Objects.equals(this.f9547.f19987, "application/x-mp4-cea-608") || Objects.equals(this.f9547.f19987, "application/cea-708");
        String str = this.f9547.f19987;
        if (z) {
            return;
        }
        ᵕᵩʽᵲ.ᵪᵹᵥᵻ(ᵱˉˈ.ᵸˆˁ("Legacy decoding is disabled, can't handle %s samples (expected %s).", new Object[]{str, "application/x-media3-cues"}));
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵔᵖᵹᵫ */
    public final void mo388(long j, long j2) {
        boolean z;
        long jMo3133;
        if (this.f3582) {
            long j3 = this.f9557;
            if (j3 != -9223372036854775807L && j >= j3) {
                m6206();
                this.f9549 = true;
            }
        }
        if (this.f9549) {
            return;
        }
        C5286 c5286 = this.f9547;
        c5286.getClass();
        boolean zEquals = Objects.equals(c5286.f19987, "application/x-media3-cues");
        Handler handler = this.f9544;
        ˊˊᵞᵽ r8 = this.f9560;
        boolean zMo1713 = false;
        zMo1713 = false;
        zMo1713 = false;
        if (zEquals) {
            this.f9543.getClass();
            if (!this.f9551) {
                C3008 c3008 = this.f9555;
                if (m2893(r8, c3008, 0) == -4) {
                    if (c3008.m6278(4)) {
                        this.f9551 = true;
                    } else {
                        c3008.m7092();
                        ByteBuffer byteBuffer = c3008.f11582;
                        byteBuffer.getClass();
                        long j4 = c3008.f11577;
                        byte[] bArrArray = byteBuffer.array();
                        int iArrayOffset = byteBuffer.arrayOffset();
                        int iLimit = byteBuffer.limit();
                        this.f9562.getClass();
                        Parcel parcelObtain = Parcel.obtain();
                        parcelObtain.unmarshall(bArrArray, iArrayOffset, iLimit);
                        parcelObtain.setDataPosition(0);
                        Bundle bundle = parcelObtain.readBundle(Bundle.class.getClassLoader());
                        parcelObtain.recycle();
                        ArrayList parcelableArrayList = bundle.getParcelableArrayList("c");
                        parcelableArrayList.getClass();
                        C3821 c3821 = new C3821(1);
                        C3975 c3975M9561 = AbstractC4509.m9561();
                        for (int i = 0; i < parcelableArrayList.size(); i++) {
                            Bundle bundle2 = (Bundle) parcelableArrayList.get(i);
                            bundle2.getClass();
                            c3975M9561.m7406(c3821.apply(bundle2));
                        }
                        C5508 c5508 = new C5508(j4, bundle.getLong("d"), c3975M9561.m8718());
                        c3008.mo7091();
                        zMo1713 = this.f9543.mo1713(c5508, j);
                    }
                }
            }
            long jMo1716 = this.f9543.mo1716(this.f9552);
            if (jMo1716 == Long.MIN_VALUE && this.f9551 && !zMo1713) {
                this.f9549 = true;
            }
            if (jMo1716 != Long.MIN_VALUE && jMo1716 <= j) {
                zMo1713 = true;
            }
            if (zMo1713) {
                AbstractC4509 abstractC4509Mo1714 = this.f9543.mo1714(j);
                long jMo1717 = this.f9543.mo1717(j);
                m6210(jMo1717);
                C4284 c4284 = new C4284(abstractC4509Mo1714);
                if (handler != null) {
                    handler.obtainMessage(1, c4284).sendToTarget();
                } else {
                    m6207(c4284);
                }
                this.f9543.mo1715(jMo1717);
            }
            this.f9552 = j;
            return;
        }
        m6209();
        this.f9552 = j;
        if (this.f9553 == null) {
            InterfaceC1641 interfaceC1641 = this.f9550;
            interfaceC1641.getClass();
            interfaceC1641.mo4536(j);
            try {
                InterfaceC1641 interfaceC16412 = this.f9550;
                interfaceC16412.getClass();
                this.f9553 = (AbstractC3334) interfaceC16412.mo2937();
            } catch (SubtitleDecoderException e) {
                ˋˀᵧ.ˋˈ("Subtitle decoding failed. streamFormat=" + this.f9547, e);
                C2598 c2598 = C2598.f10048;
                m6210(this.f9552);
                C4284 c42842 = new C4284(c2598);
                if (handler != null) {
                    handler.obtainMessage(1, c42842).sendToTarget();
                } else {
                    m6207(c42842);
                }
                m6206();
                InterfaceC1641 interfaceC16413 = this.f9550;
                interfaceC16413.getClass();
                interfaceC16413.mo364();
                this.f9550 = null;
                this.f9558 = 0;
                m6208();
                return;
            }
        }
        if (this.f3588 != 2) {
            return;
        }
        if (this.f9545 != null) {
            long jM6205 = m6205();
            z = false;
            while (jM6205 <= j) {
                this.f9556++;
                jM6205 = m6205();
                z = true;
            }
        } else {
            z = false;
        }
        AbstractC3334 abstractC3334 = this.f9553;
        boolean z2 = z;
        if (abstractC3334 != null) {
            z2 = z;
            if (!abstractC3334.m6278(4)) {
                z2 = z;
                if (abstractC3334.f15983 <= j) {
                    AbstractC3334 abstractC33342 = this.f9545;
                    if (abstractC33342 != null) {
                        abstractC33342.mo359();
                    }
                    this.f9556 = abstractC3334.mo3132(j);
                    this.f9545 = abstractC3334;
                    this.f9553 = null;
                    z2 = true;
                }
            } else if (!z) {
                z2 = z;
                if (m6205() == Long.MAX_VALUE) {
                    if (this.f9558 == 2) {
                        m6206();
                        InterfaceC1641 interfaceC16414 = this.f9550;
                        interfaceC16414.getClass();
                        interfaceC16414.mo364();
                        this.f9550 = null;
                        this.f9558 = 0;
                        m6208();
                        z2 = z;
                    } else {
                        m6206();
                        this.f9549 = true;
                        z2 = z;
                    }
                }
            }
        }
        if (z2) {
            this.f9545.getClass();
            int iMo3132 = this.f9545.mo3132(j);
            if (iMo3132 == 0 || this.f9545.mo3131() == 0) {
                jMo3133 = this.f9545.f15983;
            } else {
                AbstractC3334 abstractC33343 = this.f9545;
                jMo3133 = iMo3132 == -1 ? abstractC33343.mo3133(abstractC33343.mo3131() - 1) : abstractC33343.mo3133(iMo3132 - 1);
            }
            m6210(jMo3133);
            C4284 c42843 = new C4284(this.f9545.mo3134(j));
            if (handler != null) {
                handler.obtainMessage(1, c42843).sendToTarget();
            } else {
                m6207(c42843);
            }
        }
        if (this.f9558 == 2) {
            return;
        }
        while (!this.f9551) {
            try {
                C1561 c1561 = this.f9546;
                if (c1561 == null) {
                    InterfaceC1641 interfaceC16415 = this.f9550;
                    interfaceC16415.getClass();
                    c1561 = (C1561) interfaceC16415.mo2936();
                    if (c1561 == null) {
                        return;
                    } else {
                        this.f9546 = c1561;
                    }
                }
                if (this.f9558 == 1) {
                    c1561.f9866 = 4;
                    InterfaceC1641 interfaceC16416 = this.f9550;
                    interfaceC16416.getClass();
                    interfaceC16416.mo2938(c1561);
                    this.f9546 = null;
                    this.f9558 = 2;
                    return;
                }
                int iM2893 = m2893(r8, c1561, 0);
                if (iM2893 == -4) {
                    if (c1561.m6278(4)) {
                        this.f9551 = true;
                        this.f9561 = false;
                    } else {
                        C5286 c52862 = (C5286) r8.ᵔᵖᵹᵫ;
                        if (c52862 == null) {
                            return;
                        }
                        c1561.f6256 = c52862.f19975;
                        c1561.m7092();
                        this.f9561 &= !c1561.m6278(1);
                    }
                    if (!this.f9561) {
                        InterfaceC1641 interfaceC16417 = this.f9550;
                        interfaceC16417.getClass();
                        interfaceC16417.mo2938(c1561);
                        this.f9546 = null;
                    }
                } else if (iM2893 == -3) {
                    return;
                }
            } catch (SubtitleDecoderException e2) {
                ˋˀᵧ.ˋˈ("Subtitle decoding failed. streamFormat=" + this.f9547, e2);
                C2598 c25982 = C2598.f10048;
                m6210(this.f9552);
                C4284 c42844 = new C4284(c25982);
                if (handler != null) {
                    handler.obtainMessage(1, c42844).sendToTarget();
                } else {
                    m6207(c42844);
                }
                m6206();
                InterfaceC1641 interfaceC16418 = this.f9550;
                interfaceC16418.getClass();
                interfaceC16418.mo364();
                this.f9550 = null;
                this.f9558 = 0;
                m6208();
                return;
            }
        }
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵝᵶ */
    public final boolean mo389() {
        C5286 c5286 = this.f9547;
        if (c5286 != null) {
            if (Objects.equals(c5286.f19987, "application/x-media3-cues")) {
                InterfaceC3876 interfaceC3876 = this.f9543;
                interfaceC3876.getClass();
                if (interfaceC3876.mo1716(this.f9552) == Long.MIN_VALUE) {
                    try {
                        InterfaceC4833 interfaceC4833 = this.f3597;
                        interfaceC4833.getClass();
                        interfaceC4833.mo1983();
                        return true;
                    } catch (IOException unused) {
                        return false;
                    }
                }
            } else {
                if (this.f9549) {
                    return false;
                }
                if (this.f9551) {
                    AbstractC3334 abstractC3334 = this.f9545;
                    long j = this.f9552;
                    if (abstractC3334 == null || abstractC3334.mo3131() <= 0 || abstractC3334.mo3133(abstractC3334.mo3131() - 1) <= j) {
                        AbstractC3334 abstractC33342 = this.f9553;
                        long j2 = this.f9552;
                        if ((abstractC33342 == null || abstractC33342.mo3131() <= 0 || abstractC33342.mo3133(abstractC33342.mo3131() - 1) <= j2) && this.f9546 != null) {
                            return false;
                        }
                    }
                }
            }
        }
        return true;
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵟᵹᵙ */
    public final void mo390(long j, boolean z, boolean z2) {
        this.f9552 = j;
        InterfaceC3876 interfaceC3876 = this.f9543;
        if (interfaceC3876 != null) {
            interfaceC3876.clear();
        }
        C2598 c2598 = C2598.f10048;
        m6210(this.f9552);
        C4284 c4284 = new C4284(c2598);
        Handler handler = this.f9544;
        if (handler != null) {
            handler.obtainMessage(1, c4284).sendToTarget();
        } else {
            m6207(c4284);
        }
        this.f9551 = false;
        this.f9549 = false;
        this.f9557 = -9223372036854775807L;
        C5286 c5286 = this.f9547;
        if (c5286 == null || Objects.equals(c5286.f19987, "application/x-media3-cues")) {
            return;
        }
        if (this.f9558 == 0) {
            m6206();
            InterfaceC1641 interfaceC1641 = this.f9550;
            interfaceC1641.getClass();
            interfaceC1641.flush();
            interfaceC1641.mo2935(this.f3593);
            return;
        }
        m6206();
        InterfaceC1641 interfaceC16412 = this.f9550;
        interfaceC16412.getClass();
        interfaceC16412.mo364();
        this.f9550 = null;
        this.f9558 = 0;
        m6208();
    }

    /* JADX INFO: renamed from: ᵠˏˏ, reason: contains not printable characters */
    public final long m6210(long j) {
        ᵻᵪ.ˌᴵ(j != -9223372036854775807L);
        return j - this.f3580;
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵮᵣᵗˈ */
    public final boolean mo393() {
        return this.f9549;
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵱᵽʡᵚ */
    public final String mo394() {
        return "TextRenderer";
    }
}
