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;

/* renamed from: ˆـ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C0835 extends AbstractC4483 implements Handler.Callback {

    /* renamed from: ʾᵻᵭٴ, reason: contains not printable characters */
    public long f3838;

    /* renamed from: ˀˁᵨ, reason: contains not printable characters */
    public final C2720 f3839;

    /* renamed from: ˀᵗᵩ, reason: contains not printable characters */
    public final InterfaceC4059 f3840;

    /* renamed from: ˆᵼᵷˊ, reason: contains not printable characters */
    public boolean f3841;

    /* renamed from: ˊʽˎ, reason: contains not printable characters */
    public AbstractC2880 f3842;

    /* renamed from: ˊʾˊ, reason: contains not printable characters */
    public boolean f3843;

    /* renamed from: ˊᵸˊ, reason: contains not printable characters */
    public InterfaceC3983 f3844;

    /* renamed from: ˌᵪ, reason: contains not printable characters */
    public InterfaceC5100 f3845;

    /* renamed from: ˌᵹᵨˑ, reason: contains not printable characters */
    public C3446 f3846;

    /* renamed from: ˎᵬˀ, reason: contains not printable characters */
    public int f3847;

    /* renamed from: ˑᵝﹳᵜ, reason: contains not printable characters */
    public final C2441 f3848;

    /* renamed from: ᵛˈᵤ, reason: contains not printable characters */
    public int f3849;

    /* renamed from: ᵠᵿː, reason: contains not printable characters */
    public long f3850;

    /* renamed from: ᵡᵘˎʽ, reason: contains not printable characters */
    public final ʾᵚᵱ f3851;

    /* renamed from: ᵡᵶᵡ, reason: contains not printable characters */
    public AbstractC2880 f3852;

    /* renamed from: ᵫᵮʾ, reason: contains not printable characters */
    public final Handler f3853;

    /* renamed from: ᵳᵹᵺˋ, reason: contains not printable characters */
    public C3481 f3854;

    /* renamed from: ᵷᵱ, reason: contains not printable characters */
    public boolean f3855;

    /* renamed from: ᵺᵠ, reason: contains not printable characters */
    public boolean f3856;

    /* renamed from: ᵽʛ, reason: contains not printable characters */
    public final SurfaceHolderCallbackC4282 f3857;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C0835(SurfaceHolderCallbackC4282 surfaceHolderCallbackC4282, Looper looper) {
        super(3);
        ᵿʤˑᵦ r0 = InterfaceC4059.f15219;
        this.f3857 = surfaceHolderCallbackC4282;
        this.f3853 = new Handler(looper, this);
        this.f3840 = r0;
        this.f3851 = new ʾᵚᵱ(16);
        this.f3848 = new C2441(1, 0);
        this.f3839 = new C2720(25, false);
        this.f3838 = -9223372036854775807L;
        this.f3850 = -9223372036854775807L;
        this.f3856 = false;
    }

    @Override // android.os.Handler.Callback
    public final boolean handleMessage(Message message) {
        if (message.what == 1) {
            m2955((C1510) message.obj);
            return true;
        }
        ᵨᴵᵺ.ˌʾˀ();
        return false;
    }

    @Override // defpackage.AbstractC4483
    /* renamed from: ˀᵗᵝᵭ */
    public final int mo372(C3446 c3446) {
        boolean zEquals = Objects.equals(c3446.f12929, "application/x-media3-cues");
        String str = c3446.f12929;
        if (!zEquals) {
            ᵿʤˑᵦ r3 = this.f3840;
            r3.getClass();
            if (!((ᵼᵫᵧˀ) r3.ᵢˇᵭ).ᵻᵢﹳᵰ(c3446) && !Objects.equals(str, "application/cea-608") && !Objects.equals(str, "application/x-mp4-cea-608") && !Objects.equals(str, "application/cea-708")) {
                return AbstractC2924.m7108(str) ? AbstractC2990.m7325(1, 0, 0, 0) : AbstractC2990.m7325(0, 0, 0, 0);
            }
        }
        return AbstractC2990.m7325(c3446.f12902 == 0 ? 4 : 2, 0, 0, 0);
    }

    @Override // defpackage.AbstractC4483
    /* renamed from: ˌʾˀ */
    public final void mo374(long j, boolean z, boolean z2) {
        this.f3850 = j;
        InterfaceC3983 interfaceC3983 = this.f3844;
        if (interfaceC3983 != null) {
            interfaceC3983.clear();
        }
        C4471 c4471 = C4471.f16684;
        m2956(this.f3850);
        C1510 c1510 = new C1510(c4471);
        Handler handler = this.f3853;
        if (handler != null) {
            handler.obtainMessage(1, c1510).sendToTarget();
        } else {
            m2955(c1510);
        }
        this.f3843 = false;
        this.f3855 = false;
        this.f3838 = -9223372036854775807L;
        C3446 c3446 = this.f3846;
        if (c3446 == null || Objects.equals(c3446.f12929, "application/x-media3-cues")) {
            return;
        }
        if (this.f3849 == 0) {
            m2958();
            InterfaceC5100 interfaceC5100 = this.f3845;
            interfaceC5100.getClass();
            interfaceC5100.flush();
            interfaceC5100.mo1219(this.f16726);
            return;
        }
        m2958();
        InterfaceC5100 interfaceC51002 = this.f3845;
        interfaceC51002.getClass();
        interfaceC51002.mo364();
        this.f3845 = null;
        this.f3849 = 0;
        m2959();
    }

    @Override // defpackage.AbstractC4483
    /* renamed from: ˌᵜᵹᵩ */
    public final boolean mo375() {
        return this.f3855;
    }

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public final void m2954() {
        boolean z = this.f3856 || Objects.equals(this.f3846.f12929, "application/cea-608") || Objects.equals(this.f3846.f12929, "application/x-mp4-cea-608") || Objects.equals(this.f3846.f12929, "application/cea-708");
        String str = this.f3846.f12929;
        if (z) {
            return;
        }
        ᵹˉᵞ.ᵳٴᵶ(ˊˉʤﹳ.ˁˑᵰ("Legacy decoding is disabled, can't handle %s samples (expected %s).", new Object[]{str, "application/x-media3-cues"}));
    }

    @Override // defpackage.AbstractC4483
    /* renamed from: ˑᵱ */
    public final void mo380(C3446[] c3446Arr, long j, long j2, C2477 c2477) {
        C3446 c3446 = c3446Arr[0];
        this.f3846 = c3446;
        if (Objects.equals(c3446.f12929, "application/x-media3-cues")) {
            this.f3844 = this.f3846.f12913 == 1 ? new C4233() : new C4356(1);
            return;
        }
        m2954();
        if (this.f3845 != null) {
            this.f3849 = 1;
        } else {
            m2959();
        }
    }

    /* renamed from: ᐧﾞ, reason: contains not printable characters */
    public final void m2955(C1510 c1510) {
        C4471 c4471 = c1510.f6071;
        SurfaceHolderCallbackC4282 surfaceHolderCallbackC4282 = this.f3857;
        surfaceHolderCallbackC4282.f16066.f14768.m10590(27, new ʾᵛ(25, c4471));
        C3916 c3916 = surfaceHolderCallbackC4282.f16066;
        c3916.f14758 = c1510;
        c3916.f14768.m10590(27, new ʾᵛ(22, c1510));
    }

    /* renamed from: ᵧـˌᵎ, reason: contains not printable characters */
    public final long m2956(long j) {
        ᵛᵾˏ.ᵿʗᵝʽ(j != -9223372036854775807L);
        return j - this.f16728;
    }

    @Override // defpackage.AbstractC4483
    /* renamed from: ᵪʩ */
    public final void mo388() {
        this.f3846 = null;
        this.f3838 = -9223372036854775807L;
        C4471 c4471 = C4471.f16684;
        m2956(this.f3850);
        C1510 c1510 = new C1510(c4471);
        Handler handler = this.f3853;
        if (handler != null) {
            handler.obtainMessage(1, c1510).sendToTarget();
        } else {
            m2955(c1510);
        }
        this.f3850 = -9223372036854775807L;
        if (this.f3845 != null) {
            m2958();
            InterfaceC5100 interfaceC5100 = this.f3845;
            interfaceC5100.getClass();
            interfaceC5100.mo364();
            this.f3845 = null;
            this.f3849 = 0;
        }
    }

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public final long m2957() {
        if (this.f3847 == -1) {
            return Long.MAX_VALUE;
        }
        this.f3852.getClass();
        if (this.f3847 >= this.f3852.mo1889()) {
            return Long.MAX_VALUE;
        }
        return this.f3852.mo1886(this.f3847);
    }

    @Override // defpackage.AbstractC4483
    /* renamed from: ᵯٴᵦ */
    public final boolean mo390() {
        C3446 c3446 = this.f3846;
        if (c3446 != null) {
            if (Objects.equals(c3446.f12929, "application/x-media3-cues")) {
                InterfaceC3983 interfaceC3983 = this.f3844;
                interfaceC3983.getClass();
                if (interfaceC3983.mo8811(this.f3850) == Long.MIN_VALUE) {
                    try {
                        InterfaceC0772 interfaceC0772 = this.f16719;
                        interfaceC0772.getClass();
                        interfaceC0772.mo1129();
                        return true;
                    } catch (IOException unused) {
                        return false;
                    }
                }
            } else {
                if (this.f3855) {
                    return false;
                }
                if (this.f3843) {
                    AbstractC2880 abstractC2880 = this.f3852;
                    long j = this.f3850;
                    if (abstractC2880 == null || abstractC2880.mo1889() <= 0 || abstractC2880.mo1886(abstractC2880.mo1889() - 1) <= j) {
                        AbstractC2880 abstractC28802 = this.f3842;
                        long j2 = this.f3850;
                        if ((abstractC28802 == null || abstractC28802.mo1889() <= 0 || abstractC28802.mo1886(abstractC28802.mo1889() - 1) <= j2) && this.f3854 != null) {
                            return false;
                        }
                    }
                }
            }
        }
        return true;
    }

    /* renamed from: ᵶʔᵢˊ, reason: contains not printable characters */
    public final void m2958() {
        this.f3854 = null;
        this.f3847 = -1;
        AbstractC2880 abstractC2880 = this.f3852;
        if (abstractC2880 != null) {
            abstractC2880.mo359();
            this.f3852 = null;
        }
        AbstractC2880 abstractC28802 = this.f3842;
        if (abstractC28802 != null) {
            abstractC28802.mo359();
            this.f3842 = null;
        }
    }

    @Override // defpackage.AbstractC4483
    /* renamed from: ᵶᵷᵕ */
    public final String mo394() {
        return "TextRenderer";
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Removed duplicated region for block: B:22:0x0050  */
    /* JADX WARN: Removed duplicated region for block: B:6:0x001e  */
    /* renamed from: ᵺʙ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void m2959() {
        /*
            r7 = this;
            r0 = 1
            r7.f3841 = r0
            ᵤᵛᵖ r1 = r7.f3846
            r1.getClass()
            ᵬᵩᵞ r2 = r7.f3840
            ᵿʤˑᵦ r2 = (ᵿʤˑᵦ) r2
            java.lang.Object r2 = r2.ᵢˇᵭ
            ᵼᵫᵧˀ r2 = (ᵼᵫᵧˀ) r2
            java.lang.String r3 = r1.f12929
            int r4 = r1.f12940
            if (r3 == 0) goto L50
            int r5 = r3.hashCode()
            r6 = -1
            switch(r5) {
                case 930165504: goto L34;
                case 1566015601: goto L2b;
                case 1566016562: goto L20;
                default: goto L1e;
            }
        L1e:
            r0 = r6
            goto L3e
        L20:
            java.lang.String r0 = "application/cea-708"
            boolean r0 = r3.equals(r0)
            if (r0 != 0) goto L29
            goto L1e
        L29:
            r0 = 2
            goto L3e
        L2b:
            java.lang.String r5 = "application/cea-608"
            boolean r5 = r3.equals(r5)
            if (r5 != 0) goto L3e
            goto L1e
        L34:
            java.lang.String r0 = "application/x-mp4-cea-608"
            boolean r0 = r3.equals(r0)
            if (r0 != 0) goto L3d
            goto L1e
        L3d:
            r0 = 0
        L3e:
            switch(r0) {
                case 0: goto L4a;
                case 1: goto L4a;
                case 2: goto L42;
                default: goto L41;
            }
        L41:
            goto L50
        L42:
            ᵾᵙ r0 = new ᵾᵙ
            java.util.List r1 = r1.f12933
            r0.<init>(r4, r1)
            goto L6e
        L4a:
            ᵤˑᵗ r0 = new ᵤˑᵗ
            r0.<init>(r4, r3)
            goto L6e
        L50:
            boolean r0 = r2.ᵻᵢﹳᵰ(r1)
            if (r0 == 0) goto L76
            ˁᵤᵖᵢ r0 = r2.ᵪʩ(r1)
            ᵢᵶˋ r1 = new ᵢᵶˋ
            java.lang.Class r2 = r0.getClass()
            java.lang.String r2 = r2.getSimpleName()
            java.lang.String r3 = "Decoder"
            java.lang.String r2 = r2.concat(r3)
            r1.<init>(r2, r0)
            r0 = r1
        L6e:
            r7.f3845 = r0
            long r1 = r7.f16726
            r0.mo1219(r1)
            return
        L76:
            java.lang.String r7 = "Attempted to create decoder for unsupported MIME type: "
            java.lang.String r7 = defpackage.AbstractC4486.m9562(r7, r3)
            ᵹˉᵞ.ˌᵜᵹᵩ(r7)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C0835.m2959():void");
    }

    @Override // defpackage.AbstractC4483
    /* renamed from: ᵿʗᵝʽ */
    public final void mo397(long j, long j2) {
        boolean z;
        long jMo1886;
        if (this.f16720) {
            long j3 = this.f3838;
            if (j3 != -9223372036854775807L && j >= j3) {
                m2958();
                this.f3855 = true;
            }
        }
        if (this.f3855) {
            return;
        }
        C3446 c3446 = this.f3846;
        c3446.getClass();
        boolean zEquals = Objects.equals(c3446.f12929, "application/x-media3-cues");
        Handler handler = this.f3853;
        C2720 c2720 = this.f3839;
        boolean zMo8812 = false;
        zMo8812 = false;
        zMo8812 = false;
        if (zEquals) {
            this.f3844.getClass();
            if (!this.f3843) {
                C2441 c2441 = this.f3848;
                if (m9535(c2720, c2441, 0) == -4) {
                    if (c2441.m9873(4)) {
                        this.f3843 = true;
                    } else {
                        c2441.m6219();
                        ByteBuffer byteBuffer = c2441.f9517;
                        byteBuffer.getClass();
                        long j4 = c2441.f9512;
                        byte[] bArrArray = byteBuffer.array();
                        int iArrayOffset = byteBuffer.arrayOffset();
                        int iLimit = byteBuffer.limit();
                        this.f3851.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();
                        C2834 c2834 = new C2834(1);
                        C4704 c4704M6701 = AbstractC2692.m6701();
                        for (int i = 0; i < parcelableArrayList.size(); i++) {
                            Bundle bundle2 = (Bundle) parcelableArrayList.get(i);
                            bundle2.getClass();
                            c4704M6701.m3197(c2834.apply(bundle2));
                        }
                        C1808 c1808 = new C1808(j4, bundle.getLong("d"), c4704M6701.m9892());
                        c2441.mo6221();
                        zMo8812 = this.f3844.mo8812(c1808, j);
                    }
                }
            }
            long jMo8811 = this.f3844.mo8811(this.f3850);
            if (jMo8811 == Long.MIN_VALUE && this.f3843 && !zMo8812) {
                this.f3855 = true;
            }
            if (jMo8811 != Long.MIN_VALUE && jMo8811 <= j) {
                zMo8812 = true;
            }
            if (zMo8812) {
                AbstractC2692 abstractC2692Mo8810 = this.f3844.mo8810(j);
                long jMo8813 = this.f3844.mo8813(j);
                m2956(jMo8813);
                C1510 c1510 = new C1510(abstractC2692Mo8810);
                if (handler != null) {
                    handler.obtainMessage(1, c1510).sendToTarget();
                } else {
                    m2955(c1510);
                }
                this.f3844.mo8809(jMo8813);
            }
            this.f3850 = j;
            return;
        }
        m2954();
        this.f3850 = j;
        if (this.f3842 == null) {
            InterfaceC5100 interfaceC5100 = this.f3845;
            interfaceC5100.getClass();
            interfaceC5100.mo1217(j);
            try {
                InterfaceC5100 interfaceC51002 = this.f3845;
                interfaceC51002.getClass();
                this.f3842 = (AbstractC2880) interfaceC51002.mo1222();
            } catch (SubtitleDecoderException e) {
                ᵳʿˉ.ᵸˑ("Subtitle decoding failed. streamFormat=" + this.f3846, e);
                C4471 c4471 = C4471.f16684;
                m2956(this.f3850);
                C1510 c15102 = new C1510(c4471);
                if (handler != null) {
                    handler.obtainMessage(1, c15102).sendToTarget();
                } else {
                    m2955(c15102);
                }
                m2958();
                InterfaceC5100 interfaceC51003 = this.f3845;
                interfaceC51003.getClass();
                interfaceC51003.mo364();
                this.f3845 = null;
                this.f3849 = 0;
                m2959();
                return;
            }
        }
        if (this.f16722 != 2) {
            return;
        }
        if (this.f3852 != null) {
            long jM2957 = m2957();
            z = false;
            while (jM2957 <= j) {
                this.f3847++;
                jM2957 = m2957();
                z = true;
            }
        } else {
            z = false;
        }
        AbstractC2880 abstractC2880 = this.f3842;
        boolean z2 = z;
        if (abstractC2880 != null) {
            z2 = z;
            if (!abstractC2880.m9873(4)) {
                z2 = z;
                if (abstractC2880.f2897 <= j) {
                    AbstractC2880 abstractC28802 = this.f3852;
                    if (abstractC28802 != null) {
                        abstractC28802.mo359();
                    }
                    this.f3847 = abstractC2880.mo1890(j);
                    this.f3852 = abstractC2880;
                    this.f3842 = null;
                    z2 = true;
                }
            } else if (!z) {
                z2 = z;
                if (m2957() == Long.MAX_VALUE) {
                    if (this.f3849 == 2) {
                        m2958();
                        InterfaceC5100 interfaceC51004 = this.f3845;
                        interfaceC51004.getClass();
                        interfaceC51004.mo364();
                        this.f3845 = null;
                        this.f3849 = 0;
                        m2959();
                        z2 = z;
                    } else {
                        m2958();
                        this.f3855 = true;
                        z2 = z;
                    }
                }
            }
        }
        if (z2) {
            this.f3852.getClass();
            int iMo1890 = this.f3852.mo1890(j);
            if (iMo1890 == 0 || this.f3852.mo1889() == 0) {
                jMo1886 = this.f3852.f2897;
            } else {
                AbstractC2880 abstractC28803 = this.f3852;
                jMo1886 = iMo1890 == -1 ? abstractC28803.mo1886(abstractC28803.mo1889() - 1) : abstractC28803.mo1886(iMo1890 - 1);
            }
            m2956(jMo1886);
            C1510 c15103 = new C1510(this.f3852.mo1887(j));
            if (handler != null) {
                handler.obtainMessage(1, c15103).sendToTarget();
            } else {
                m2955(c15103);
            }
        }
        if (this.f3849 == 2) {
            return;
        }
        while (!this.f3843) {
            try {
                C3481 c3481 = this.f3854;
                if (c3481 == null) {
                    InterfaceC5100 interfaceC51005 = this.f3845;
                    interfaceC51005.getClass();
                    c3481 = (C3481) interfaceC51005.mo1214();
                    if (c3481 == null) {
                        return;
                    } else {
                        this.f3854 = c3481;
                    }
                }
                if (this.f3849 == 1) {
                    c3481.f17323 = 4;
                    InterfaceC5100 interfaceC51006 = this.f3845;
                    interfaceC51006.getClass();
                    interfaceC51006.mo1216(c3481);
                    this.f3854 = null;
                    this.f3849 = 2;
                    return;
                }
                int iM9535 = m9535(c2720, c3481, 0);
                if (iM9535 == -4) {
                    if (c3481.m9873(4)) {
                        this.f3843 = true;
                        this.f3841 = false;
                    } else {
                        C3446 c34462 = (C3446) c2720.f10550;
                        if (c34462 == null) {
                            return;
                        }
                        c3481.f13035 = c34462.f12925;
                        c3481.m6219();
                        this.f3841 &= !c3481.m9873(1);
                    }
                    if (!this.f3841) {
                        InterfaceC5100 interfaceC51007 = this.f3845;
                        interfaceC51007.getClass();
                        interfaceC51007.mo1216(c3481);
                        this.f3854 = null;
                    }
                } else if (iM9535 == -3) {
                    return;
                }
            } catch (SubtitleDecoderException e2) {
                ᵳʿˉ.ᵸˑ("Subtitle decoding failed. streamFormat=" + this.f3846, e2);
                C4471 c44712 = C4471.f16684;
                m2956(this.f3850);
                C1510 c15104 = new C1510(c44712);
                if (handler != null) {
                    handler.obtainMessage(1, c15104).sendToTarget();
                } else {
                    m2955(c15104);
                }
                m2958();
                InterfaceC5100 interfaceC51008 = this.f3845;
                interfaceC51008.getClass();
                interfaceC51008.mo364();
                this.f3845 = null;
                this.f3849 = 0;
                m2959();
                return;
            }
        }
    }
}
