package n;

import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.os.Bundle;
import android.os.ConditionVariable;
import android.os.Handler;
import android.os.Process;
import android.os.SystemClock;
import android.util.Log;
import android.view.Surface;
import androidx.core.location.LocationRequestCompat;
import androidx.core.view.PointerIconCompat;
import b0.AbstractC0396a;
import b0.AbstractC0399d;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import n.u;
import okhttp3.HttpUrl;
import u.InterfaceC0722a;

/* JADX INFO: loaded from: classes.dex */
public abstract class t extends C {

    /* JADX INFO: renamed from: U0, reason: collision with root package name */
    private static final byte[] f5654U0 = b0.D.o("0000016742C00BDA259000000168CE0F13200000016588840DCE7118A0002FBF1C31C3275D78");

    /* JADX INFO: renamed from: V0, reason: collision with root package name */
    private static boolean f5655V0 = false;

    /* JADX INFO: renamed from: W0, reason: collision with root package name */
    public static final boolean f5656W0 = "1".equals(b0.D.y("vendor.mtk.exoplayer.aosp_cn_support", HttpUrl.FRAGMENT_ENCODE_SET));

    /* JADX INFO: renamed from: X0, reason: collision with root package name */
    private static int f5657X0 = 7;

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    private final g f5658A;

    /* JADX INFO: renamed from: A0, reason: collision with root package name */
    protected boolean f5659A0;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    private final boolean f5660B;

    /* JADX INFO: renamed from: B0, reason: collision with root package name */
    private long f5661B0;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    protected final Handler f5662C;

    /* JADX INFO: renamed from: C0, reason: collision with root package name */
    protected boolean f5663C0;

    /* JADX INFO: renamed from: D, reason: collision with root package name */
    private final C0635a f5664D;

    /* JADX INFO: renamed from: D0, reason: collision with root package name */
    protected boolean f5665D0;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    private boolean f5666E;

    /* JADX INFO: renamed from: E0, reason: collision with root package name */
    public int f5667E0;

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    private boolean f5668F;

    /* JADX INFO: renamed from: F0, reason: collision with root package name */
    private int f5669F0;

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    private boolean f5670G;

    /* JADX INFO: renamed from: G0, reason: collision with root package name */
    private boolean f5671G0;

    /* JADX INFO: renamed from: H, reason: collision with root package name */
    protected x f5672H;

    /* JADX INFO: renamed from: H0, reason: collision with root package name */
    private boolean f5673H0;

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    private InterfaceC0722a f5674I;

    /* JADX INFO: renamed from: I0, reason: collision with root package name */
    private boolean[] f5675I0;

    /* JADX INFO: renamed from: J, reason: collision with root package name */
    private MediaCodec f5676J;

    /* JADX INFO: renamed from: J0, reason: collision with root package name */
    private int f5677J0;

    /* JADX INFO: renamed from: K, reason: collision with root package name */
    private boolean f5678K;

    /* JADX INFO: renamed from: K0, reason: collision with root package name */
    private r f5679K0;

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    private boolean f5680L;

    /* JADX INFO: renamed from: L0, reason: collision with root package name */
    private LinkedBlockingQueue f5681L0;

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    private boolean f5682M;

    /* JADX INFO: renamed from: M0, reason: collision with root package name */
    private LinkedBlockingQueue f5683M0;

    /* JADX INFO: renamed from: N, reason: collision with root package name */
    private boolean f5684N;

    /* JADX INFO: renamed from: N0, reason: collision with root package name */
    private l f5685N0;

    /* JADX INFO: renamed from: O, reason: collision with root package name */
    private boolean f5686O;

    /* JADX INFO: renamed from: O0, reason: collision with root package name */
    private ByteBuffer f5687O0;

    /* JADX INFO: renamed from: P, reason: collision with root package name */
    private boolean f5688P;

    /* JADX INFO: renamed from: P0, reason: collision with root package name */
    private boolean f5689P0;

    /* JADX INFO: renamed from: Q, reason: collision with root package name */
    private boolean f5690Q;

    /* JADX INFO: renamed from: Q0, reason: collision with root package name */
    private int f5691Q0;

    /* JADX INFO: renamed from: R, reason: collision with root package name */
    private boolean f5692R;

    /* JADX INFO: renamed from: R0, reason: collision with root package name */
    protected ByteBuffer f5693R0;

    /* JADX INFO: renamed from: S, reason: collision with root package name */
    private boolean f5694S;

    /* JADX INFO: renamed from: S0, reason: collision with root package name */
    protected ByteBuffer f5695S0;

    /* JADX INFO: renamed from: T, reason: collision with root package name */
    private boolean f5696T;

    /* JADX INFO: renamed from: T0, reason: collision with root package name */
    private int f5697T0;

    /* JADX INFO: renamed from: U, reason: collision with root package name */
    private ByteBuffer[] f5698U;

    /* JADX INFO: renamed from: V, reason: collision with root package name */
    private ByteBuffer[] f5699V;

    /* JADX INFO: renamed from: W, reason: collision with root package name */
    private long f5700W;

    /* JADX INFO: renamed from: X, reason: collision with root package name */
    private int f5701X;

    /* JADX INFO: renamed from: Y, reason: collision with root package name */
    private int f5702Y;

    /* JADX INFO: renamed from: Z, reason: collision with root package name */
    private boolean f5703Z;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    private boolean f5704a0;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    private int f5705b0;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    protected int f5706c0;

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    protected boolean f5707d0;

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    private boolean f5708e0;

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    private int f5709f0;

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    private volatile boolean f5710g0;

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    private boolean f5711h0;

    /* JADX INFO: renamed from: i0, reason: collision with root package name */
    private boolean f5712i0;

    /* JADX INFO: renamed from: j0, reason: collision with root package name */
    private boolean f5713j0;

    /* JADX INFO: renamed from: k0, reason: collision with root package name */
    private boolean f5714k0;

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    private boolean f5715l0;

    /* JADX INFO: renamed from: m0, reason: collision with root package name */
    private boolean f5716m0;

    /* JADX INFO: renamed from: n0, reason: collision with root package name */
    protected volatile boolean f5717n0;

    /* JADX INFO: renamed from: o0, reason: collision with root package name */
    protected volatile boolean f5718o0;

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    protected long f5719p0;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private final String f5720q;

    /* JADX INFO: renamed from: q0, reason: collision with root package name */
    protected boolean f5721q0;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private boolean f5722r;

    /* JADX INFO: renamed from: r0, reason: collision with root package name */
    private volatile int f5723r0;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final C0638d f5724s;

    /* JADX INFO: renamed from: s0, reason: collision with root package name */
    private final ConditionVariable f5725s0;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    private final s f5726t;

    /* JADX INFO: renamed from: t0, reason: collision with root package name */
    protected boolean f5727t0;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    private u.b f5728u;

    /* JADX INFO: renamed from: u0, reason: collision with root package name */
    protected int f5729u0;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    private final boolean f5730v;

    /* JADX INFO: renamed from: v0, reason: collision with root package name */
    private volatile boolean f5731v0;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    private final C0633A f5732w;

    /* JADX INFO: renamed from: w0, reason: collision with root package name */
    protected boolean f5733w0;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    private final y f5734x;

    /* JADX INFO: renamed from: x0, reason: collision with root package name */
    private int f5735x0;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    private final List f5736y;

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    private boolean f5737y0;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    private MediaCodec.BufferInfo f5738z;

    /* JADX INFO: renamed from: z0, reason: collision with root package name */
    protected long f5739z0;

    class a extends Thread {
        a() {
        }

        @Override // java.lang.Thread, java.lang.Runnable
        public void run() {
            Process.setThreadPriority(-16);
            try {
                try {
                    t.this.H0();
                    t.this.f5723r0 = 3;
                } catch (C0643i e2) {
                    t.this.f5731v0 = true;
                    Log.e(t.this.f5720q, "Internal track renderer error.", e2);
                    if (t.this.f5685N0 != null) {
                        t.this.f5685N0.e0(e2);
                    }
                }
            } finally {
                t.this.f5725s0.open();
            }
        }
    }

    class b implements Runnable {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ f f5741b;

        b(f fVar) {
            this.f5741b = fVar;
        }

        @Override // java.lang.Runnable
        public void run() {
            t.this.f5658A.l(this.f5741b);
        }
    }

    class c implements Runnable {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ MediaCodec.CryptoException f5743b;

        c(MediaCodec.CryptoException cryptoException) {
            this.f5743b = cryptoException;
        }

        @Override // java.lang.Runnable
        public void run() {
            t.this.f5658A.q(this.f5743b);
        }
    }

    class d implements Runnable {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ String f5745b;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        final /* synthetic */ long f5746g;

        /* JADX INFO: renamed from: r, reason: collision with root package name */
        final /* synthetic */ long f5747r;

        d(String str, long j2, long j3) {
            this.f5745b = str;
            this.f5746g = j2;
            this.f5747r = j3;
        }

        @Override // java.lang.Runnable
        public void run() {
            t.this.f5658A.onDecoderInitialized(this.f5745b, this.f5746g, this.f5747r);
        }
    }

    class e implements Runnable {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ String f5749b;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        final /* synthetic */ long f5750g;

        e(String str, long j2) {
            this.f5749b = str;
            this.f5750g = j2;
        }

        @Override // java.lang.Runnable
        public void run() {
            t.this.f5658A.n(this.f5749b, this.f5750g);
        }
    }

    public interface g {
        void l(f fVar);

        void n(String str, long j2);

        void onDecoderInitialized(String str, long j2, long j3);

        void q(MediaCodec.CryptoException cryptoException);
    }

    public t(String str, InterfaceC0634B interfaceC0634B, s sVar, u.b bVar, boolean z2, Handler handler, g gVar) {
        this(str, new InterfaceC0634B[]{interfaceC0634B}, sVar, bVar, z2, handler, gVar);
    }

    private void B0() {
        String str;
        j0();
        this.f5664D.x(1);
        this.f5666E = true;
        x xVar = this.f5672H;
        if (xVar == null || (str = xVar.f5842g) == null) {
            str = this instanceof q ? "audio" : "video";
        }
        Log.i(this.f5720q, "[" + str + "] Enabled bypass mode.");
        MediaFormat mediaFormatR = this.f5672H.r();
        if (mediaFormatR.containsKey("csd-0")) {
            Log.i(this.f5720q, "Restore csd-0 for bypass mode");
            this.f5695S0 = mediaFormatR.getByteBuffer("csd-0");
        }
    }

    private boolean D0() {
        if (this.f5685N0.m() != 0) {
            return true;
        }
        return (b0.D.f2965a >= 21 && this.f5669F0 != -1) || b0.n.d();
    }

    private boolean F0() {
        return SystemClock.elapsedRealtime() < this.f5700W + 1000;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void H0() throws C0643i {
        MediaCrypto mediaCryptoB;
        boolean zA;
        String str;
        C0640f c0640fQ0;
        String strB;
        String str2 = this.f5672H.f5842g;
        if (this.f5674I != null || (this.f5728u != null && b0.n.e())) {
            u.b bVar = this.f5728u;
            if (bVar == null) {
                throw new C0643i("Media requires a DrmSessionManager");
            }
            if (!this.f5703Z) {
                InterfaceC0722a interfaceC0722a = this.f5674I;
                if (interfaceC0722a != null) {
                    bVar.c(interfaceC0722a);
                } else if (b0.n.e()) {
                    this.f5728u.c(new InterfaceC0722a.C0098a());
                }
                this.f5703Z = true;
            }
            int iB = this.f5728u.b();
            if (iB == 0) {
                throw new C0643i(this.f5728u.e());
            }
            if (iB != 3 && iB != 4) {
                return;
            }
            mediaCryptoB = ((u.e) this.f5728u.d()).b();
            zA = this.f5728u.a(str2);
        } else {
            mediaCryptoB = null;
            zA = false;
        }
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        try {
            if ((this instanceof q) && "audio/mp4a-latm".equals(str2)) {
                if (this.f5672H.r().containsKey("is-adts")) {
                    this.f5672H.r().getInteger("is-adts");
                }
                c0640fQ0 = r0(this.f5726t, str2, zA, true);
            } else {
                if ("video/dolby-vision".equals(str2)) {
                    if (b0.D.f2965a < 24 || (strB = u.b(this.f5672H.r(), zA)) == null) {
                        J0(new f(this.f5672H, (Throwable) null, zA, -49999));
                    } else {
                        str2 = str2 + "#" + strB;
                    }
                }
                c0640fQ0 = q0(this.f5726t, str2, zA);
            }
            str = str2;
        } catch (u.b e2) {
            J0(new f(this.f5672H, e2, zA, -49998));
            str = str2;
            c0640fQ0 = null;
        }
        long jElapsedRealtime2 = SystemClock.elapsedRealtime();
        Log.d(this.f5720q, "[Performance]getDecoderInfo() costTimeMs=" + (jElapsedRealtime2 - jElapsedRealtime));
        if (c0640fQ0 == null) {
            J0(new f(this.f5672H, (Throwable) null, zA, -49999));
        }
        if (this instanceof w) {
            if ("video/avc".equals(this.f5672H.f5842g) || "video/hevc".equals(this.f5672H.f5842g) || "video/x-vnd.on2.vp9".equals(this.f5672H.f5842g) || "video/av01".equals(this.f5672H.f5842g) || "video/vvc".equals(this.f5672H.f5842g) || "video/dolby-vision".equals(this.f5672H.f5842g)) {
                MediaCodecInfo.VideoCapabilities videoCapabilities = c0640fQ0.f5520b.getVideoCapabilities();
                int iIntValue = ((Integer) videoCapabilities.getSupportedWidths().getUpper()).intValue();
                int iIntValue2 = ((Integer) videoCapabilities.getSupportedHeights().getUpper()).intValue();
                x xVar = this.f5672H;
                int i2 = xVar.f5831L;
                int i3 = xVar.f5832M;
                if (i2 * i3 > iIntValue * iIntValue2 || i2 < 64 || i3 < 64) {
                    Log.w(this.f5720q, "Mainstream video resolution (" + this.f5672H.f5831L + "x" + this.f5672H.f5832M + ") is beyond the capbilities[" + c0640fQ0.f5519a + "]: capawidth x capaheight: " + iIntValue + "x" + iIntValue2);
                    throw new C0643i(new Exception("vdec beyond capabilities").getCause(), 0);
                }
            } else {
                x xVar2 = this.f5672H;
                int i4 = xVar2.f5831L;
                int i5 = xVar2.f5832M;
                if (i4 * i5 > 9437184 || i4 < 64 || i5 < 64) {
                    Log.w(this.f5720q, "Niche video resolution (" + this.f5672H.f5831L + "x" + this.f5672H.f5832M + ") is beyond the capbilities[" + c0640fQ0.f5519a + "]: w[64, 4096], h[64, 2304]");
                    throw new C0643i(new Exception("vdec beyond capabilities").getCause(), 0);
                }
            }
            int i6 = this.f5672H.f5852p0;
            if (i6 > 0) {
                this.f5667E0 = i6;
            }
        }
        String str3 = c0640fQ0.f5519a;
        this.f5737y0 = str3 != null && (str3.startsWith("OMX.google") || str3.startsWith("c2.android"));
        this.f5678K = c0640fQ0.f5521c;
        this.f5680L = b0(str3, this.f5672H);
        this.f5682M = f0(str3);
        this.f5684N = a0(str3);
        this.f5686O = e0(str3);
        this.f5688P = c0(str3);
        this.f5690Q = d0(str3);
        this.f5692R = g0(str3, this.f5672H);
        try {
            long jElapsedRealtime3 = SystemClock.elapsedRealtime();
            b0.B.a("createByCodecName(" + str3 + ")");
            this.f5676J = MediaCodec.createByCodecName(str3);
            boolean zD0 = D0();
            this.f5689P0 = zD0;
            if (zD0) {
                r rVar = new r(this, this.f5461c);
                this.f5679K0 = rVar;
                this.f5676J.setCallback(rVar, rVar.c());
            }
            b0.B.c();
            b0.B.a("configureCodec");
            h0(this.f5676J, c0640fQ0.f5521c, u0(this.f5672H), mediaCryptoB);
            b0.B.c();
            b0.B.a("codec.start()");
            this.f5713j0 = true;
            this.f5714k0 = false;
            this.f5676J.start();
            if (this instanceof w) {
                Bundle bundle = new Bundle();
                if (b0.n.e()) {
                    Log.i(this.f5720q, "disable vpeek for hbbtv");
                    bundle.putInt("tunnel-peek", 0);
                } else {
                    Log.i(this.f5720q, "enable vpeek for mmp");
                    bundle.putInt("tunnel-peek", 1);
                }
                this.f5676J.setParameters(bundle);
            }
            b0.B.c();
            if (!this.f5689P0) {
                this.f5698U = this.f5676J.getInputBuffers();
                this.f5699V = this.f5676J.getOutputBuffers();
            }
            long jElapsedRealtime4 = SystemClock.elapsedRealtime();
            long j2 = jElapsedRealtime4 - jElapsedRealtime3;
            M0(str3, jElapsedRealtime4, j2);
            Log.i(this.f5720q, "[Performance]InitCodec, mimeType[" + str + "], codecName[" + str3 + "] costTimeMs=" + j2);
            if (this instanceof w) {
                w wVar = (w) this;
                Bundle bundle2 = new Bundle();
                if (wVar.v0().m() == 1) {
                    bundle2.putInt("vendor.mtk-iview.apply-system-clock", 0);
                } else if (wVar.v0().m() == 2) {
                    bundle2.putInt("vendor.mtk-iview.apply-system-clock", 1);
                }
                Log.d(this.f5720q, "+set vendor cmd: apply system clock ");
                this.f5676J.setParameters(bundle2);
                Log.d(this.f5720q, "-set vendor cmd: apply system clock ");
            }
        } catch (Exception e3) {
            J0(new f(this.f5672H, e3, zA, str3));
        }
        this.f5700W = l() == 3 ? SystemClock.elapsedRealtime() : -1L;
        if (!this.f5689P0) {
            this.f5701X = -1;
            this.f5702Y = -1;
        }
        this.f5717n0 = false;
        this.f5718o0 = false;
        this.f5724s.f5501a++;
    }

    private void J0(f fVar) throws C0643i {
        L0(fVar);
        throw new C0643i(fVar, this instanceof q ? 1 : 0);
    }

    private void K0(MediaCodec.CryptoException cryptoException) {
        Handler handler = this.f5662C;
        if (handler == null || this.f5658A == null) {
            return;
        }
        handler.post(new c(cryptoException));
    }

    private void L0(f fVar) {
        Handler handler = this.f5662C;
        if (handler == null || this.f5658A == null) {
            return;
        }
        handler.post(new b(fVar));
    }

    private void M0(String str, long j2, long j3) {
        Handler handler = this.f5662C;
        if (handler == null || this.f5658A == null) {
            return;
        }
        handler.post(new d(str, j2, j3));
    }

    private boolean W(long j2, long j3) {
        String str;
        long j4;
        MediaCodec mediaCodec;
        String str2;
        C0635a c0635a = this.f5664D;
        boolean z2 = this.f5460b == 1;
        boolean z3 = this.f5422l <= 3 && z2 && o0() < this.f5423m;
        boolean zS = c0635a.s();
        boolean zT = c0635a.t();
        x xVar = this.f5672H;
        if (xVar == null || (str = xVar.f5842g) == null) {
            str = this instanceof q ? "audio" : "video";
            j4 = -1;
        } else {
            j4 = xVar.f5856y;
        }
        String str3 = str;
        b0.o.c(this.f5720q, 1, "bypassRender[", str3, "], positionUs[", Long.valueOf(j2), "], batchBufferPts[", Long.valueOf(o0()), "/", Long.valueOf(j4), "/", Long.valueOf(this.f5423m), "], batchBufferEmpty[", Boolean.valueOf(zS), "], batchBufferEOS[", Boolean.valueOf(zT), "], speed[", Integer.valueOf(this.f5422l), "], PrecisionSeekMode[", Boolean.valueOf(z2), "]");
        if (zS) {
            mediaCodec = null;
            str2 = str3;
        } else {
            mediaCodec = null;
            str2 = str3;
            if (!Z0(j2, j3, null, c0635a.f5409b, null, -1, z3)) {
                return false;
            }
            W0(c0635a.q());
            this.f5693R0 = null;
            this.f5691Q0 = 0;
        }
        if (zT) {
            if (b0.n.e() && (this instanceof q) && !this.f5722r) {
                ((q) this).F1(c0635a.o());
                this.f5722r = true;
            }
            if (this.f5711h0 || (this.f5685N0 != null && c0635a.o() - j2 > 1500000 && this.f5707d0)) {
                return false;
            }
            Log.d(this.f5720q, "bypassRender: End Of " + str2 + " Output Stream.");
            this.f5711h0 = true;
            V0();
            return false;
        }
        c0635a.i();
        if (this.f5668F) {
            if (!c0635a.s()) {
                return true;
            }
            j0();
            this.f5668F = false;
            G0();
            if (!this.f5666E) {
                return false;
            }
        }
        AbstractC0399d.e(!this.f5710g0);
        int iC1 = c1(j2, c0635a);
        if (iC1 == -4) {
            R0(this.f5734x);
        } else if (iC1 == -2) {
            return false;
        }
        if (!c0635a.s() && this.f5670G) {
            AbstractC0399d.d(this.f5672H);
            T0(mediaCodec, u0(this.f5672H));
            this.f5670G = false;
        }
        if (c0635a.s()) {
            return false;
        }
        c0635a.d();
        c0635a.f5409b.order(ByteOrder.nativeOrder());
        return true;
    }

    private void Y0() {
        if (this.f5706c0 == 2) {
            e1();
            G0();
            return;
        }
        if (this.f5685N0 != null && (this instanceof q) && !Y()) {
            if (this.f5732w.f5412e - (this.f5685N0.j() * 1000) > 1500000 && this.f5707d0) {
                return;
            }
        }
        this.f5711h0 = true;
        V0();
    }

    private static boolean a0(String str) {
        if (b0.D.f2965a < 24 && ("OMX.Nvidia.h264.decode".equals(str) || "OMX.Nvidia.h264.decode.secure".equals(str))) {
            String str2 = b0.D.f2966b;
            if (str2.equals("flounder") || str2.equals("flounder_lte") || str2.equals("grouper") || str2.equals("tilapia")) {
                return true;
            }
        }
        return false;
    }

    private void a1() throws C0643i {
        b1(this.f5676J.getOutputFormat());
    }

    private static boolean b0(String str, x xVar) {
        return b0.D.f2965a < 21 && xVar.f5829H.isEmpty() && "OMX.MTK.VIDEO.DECODER.AVC".equals(str);
    }

    private void b1(MediaFormat mediaFormat) throws C0643i {
        if (this.f5684N && mediaFormat.getInteger("width") == 32 && mediaFormat.getInteger("height") == 32) {
            this.f5696T = true;
            return;
        }
        if (this.f5692R) {
            mediaFormat.setInteger("channel-count", 1);
        }
        if (mediaFormat.containsKey("vendor.mtk-codec2.error-code")) {
            mediaFormat.getInteger("vendor.mtk-codec2.error-code");
        }
        try {
            T0(this.f5676J, mediaFormat);
            this.f5724s.f5504d++;
            this.f5717n0 = true;
            if (((b0.n.d() && f5656W0) || b0.n.c()) && this.f5671G0) {
                Log.d(this.f5720q, "processOutputFormat: TunnelingVideo setupVideoMediaTunnelingOutput");
                ((w) this).R1();
            }
        } catch (Exception e2) {
            throw new C0643i(e2, this instanceof q ? 1 : 0);
        }
    }

    private static boolean c0(String str) {
        int i2 = b0.D.f2965a;
        return (i2 <= 23 && "OMX.google.vorbis.decoder".equals(str)) || (i2 <= 19 && "hb2000".equals(b0.D.f2966b) && ("OMX.amlogic.avc.decoder.awesome".equals(str) || "OMX.amlogic.avc.decoder.awesome.secure".equals(str)));
    }

    /* JADX WARN: Removed duplicated region for block: B:28:0x00e4  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private int c1(long r23, n.C0635a r25) {
        /*
            Method dump skipped, instruction units count: 243
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: n.t.c1(long, n.a):int");
    }

    private static boolean d0(String str) {
        return b0.D.f2965a == 21 && "OMX.google.aac.decoder".equals(str);
    }

    private void d1(long j2) {
        if (K(j2, this.f5734x, null) == -4) {
            Log.d(this.f5720q, "[Performance]FORMAT_READ:" + this.f5734x.f5857a.f5842g);
            R0(this.f5734x);
        }
    }

    private static boolean e0(String str) {
        return b0.D.f2965a <= 17 && ("OMX.rk.video_decoder.avc".equals(str) || "OMX.allwinner.video.decoder.avc".equals(str));
    }

    private static boolean f0(String str) {
        int i2 = b0.D.f2965a;
        return i2 < 18 || (i2 == 18 && ("OMX.SEC.avc.dec".equals(str) || "OMX.SEC.avc.dec.secure".equals(str))) || (i2 == 19 && b0.D.f2968d.startsWith("SM-G800") && ("OMX.Exynos.avc.dec".equals(str) || "OMX.Exynos.avc.dec.secure".equals(str)));
    }

    private static boolean g0(String str, x xVar) {
        return b0.D.f2965a <= 18 && xVar.f5840e0 == 1 && "OMX.MTK.AUDIO.DECODER.MP3".equals(str);
    }

    private void h1() {
        int i2;
        if (b0.n.c()) {
            try {
                i2 = Integer.parseInt(b0.D.y("ro.vendor.iview.force_non_realtime", "0"));
            } catch (NumberFormatException e2) {
                Log.e(this.f5720q, "Invalid iview.force_non_realtime string. " + e2.toString());
                i2 = 0;
            }
            if (i2 == 1) {
                this.f5733w0 = false;
            } else {
                this.f5733w0 = true;
            }
            Log.d(this.f5720q, "setForceRealtime: " + this.f5733w0);
        }
    }

    private static boolean i0() {
        return b0.D.f2965a <= 22 && "foster".equals(b0.D.f2966b) && "NVIDIA".equals(b0.D.f2967c);
    }

    private void j0() {
        this.f5668F = false;
        this.f5664D.k();
        this.f5666E = false;
        this.f5707d0 = false;
    }

    private boolean k0(long j2, long j3) throws C0643i {
        ByteBuffer outputBuffer;
        boolean zZ0;
        x xVar;
        if (this.f5731v0) {
            return false;
        }
        if (b0.n.d() && this.f5671G0) {
            if (f5656W0) {
                w wVar = (w) this;
                if (this.f5710g0 && wVar.a() == LocationRequestCompat.PASSIVE_INTERVAL) {
                    Log.d(this.f5720q, "drainOutputBuffer: End Of " + this.f5672H.f5842g + " Output Stream.");
                    this.f5711h0 = true;
                }
            } else {
                try {
                    MediaCodec mediaCodec = this.f5676J;
                    T0(mediaCodec, mediaCodec.getOutputFormat());
                    w wVar2 = (w) this;
                    if (!this.f5663C0) {
                        wVar2.R1();
                        this.f5663C0 = true;
                    }
                    if (this.f5710g0 && wVar2.a() == LocationRequestCompat.PASSIVE_INTERVAL) {
                        Log.d(this.f5720q, "drainOutputBuffer: End Of " + this.f5672H.f5842g + " Output Stream.");
                        this.f5711h0 = true;
                    }
                } catch (IllegalStateException e2) {
                    if (this.f5689P0) {
                        return false;
                    }
                    throw new C0643i(e2.getCause(), 0);
                }
            }
            return false;
        }
        if (b0.n.c() && this.f5671G0) {
            w wVar3 = (w) this;
            if (!this.f5681L0.isEmpty()) {
                Integer num = (Integer) this.f5681L0.peek();
                this.f5676J.releaseOutputBuffer(num.intValue(), false);
                this.f5681L0.remove();
                b0.o.c(this.f5720q, 1, "releaseOutputBuffer for tunneling video, index:", num, ", available size:", Integer.valueOf(this.f5681L0.size()));
            }
            if (wVar3.a() == LocationRequestCompat.PASSIVE_INTERVAL) {
                if (this.f5706c0 == 2) {
                    if (b0.n.e()) {
                        wVar3.L1(this.f5676J);
                    }
                    this.f5706c0 = 0;
                    long jElapsedRealtime = SystemClock.elapsedRealtime();
                    e1();
                    G0();
                    long jElapsedRealtime2 = SystemClock.elapsedRealtime();
                    Log.i(this.f5720q, "codecReinitialization need ms:" + (jElapsedRealtime2 - jElapsedRealtime));
                    return true;
                }
                if (this.f5710g0) {
                    this.f5711h0 = true;
                }
                Log.i(this.f5720q, "codecReinitialization, input end and output end.");
            }
            return false;
        }
        if (this.f5711h0) {
            return this.f5689P0 && this.f5685N0.m() != 0;
        }
        if (this.f5689P0) {
            if (this.f5681L0.isEmpty() || this.f5683M0.isEmpty()) {
                return false;
            }
            this.f5702Y = ((Integer) this.f5681L0.peek()).intValue();
            this.f5738z = (MediaCodec.BufferInfo) this.f5683M0.peek();
        } else if (this.f5702Y < 0) {
            if (this.f5690Q && this.f5708e0) {
                try {
                    this.f5702Y = this.f5676J.dequeueOutputBuffer(this.f5738z, s0());
                } catch (IllegalStateException unused) {
                    Log.d(this.f5720q, "processEndOfOutputStream...");
                    Y0();
                    if (this.f5711h0) {
                        e1();
                    }
                    return false;
                }
            } else {
                try {
                    this.f5702Y = this.f5676J.dequeueOutputBuffer(this.f5738z, s0());
                } catch (IllegalStateException e3) {
                    Log.w(this.f5720q, "Catch codec.dequeueOutputBuffer IllegalStateException!");
                    if (this instanceof w) {
                        throw new C0643i(e3, 0);
                    }
                    throw new C0643i(e3, 1);
                }
            }
        }
        int i2 = this.f5702Y;
        if (i2 == -2) {
            a1();
            return true;
        }
        if (i2 == -3) {
            this.f5699V = this.f5676J.getOutputBuffers();
            this.f5724s.f5505e++;
            return true;
        }
        if (i2 < 0) {
            if (!this.f5686O || (!this.f5710g0 && this.f5706c0 != 2)) {
                return false;
            }
            Log.d(this.f5720q, "REINITIALIZATION_STATE_WAIT_END_OF_STREAM. processEndOfOutputStream...");
            Y0();
            return true;
        }
        if (this.f5696T) {
            this.f5696T = false;
            this.f5676J.releaseOutputBuffer(i2, false);
            if (this.f5689P0) {
                this.f5681L0.remove();
                this.f5683M0.remove();
            }
            this.f5702Y = -1;
            return true;
        }
        if ((this.f5738z.flags & 4) != 0) {
            Log.d(this.f5720q, "drainOutputBuffer: End Of " + this.f5672H.f5842g + " Output Stream.");
            Y0();
            return false;
        }
        boolean z2 = this instanceof q;
        if (z2 && !((q) this).f5629t1.tryLock()) {
            return false;
        }
        try {
            if (this.f5689P0) {
                outputBuffer = this.f5687O0;
                if (outputBuffer == null) {
                    outputBuffer = this.f5676J.getOutputBuffer(this.f5702Y);
                }
            } else {
                outputBuffer = this.f5699V[this.f5702Y];
            }
            this.f5687O0 = outputBuffer;
            if (z2 && (xVar = this.f5672H) != null && ((xVar.f5842g.equals("audio/mp4a-latm") || this.f5672H.f5842g.equals("audio/mp4a-latm-hw")) && I0(this.f5687O0))) {
                ByteBuffer byteBuffer = this.f5693R0;
                if (byteBuffer == null) {
                    ByteBuffer byteBufferW0 = w0(this.f5687O0, this.f5738z.size);
                    this.f5687O0 = byteBufferW0;
                    MediaCodec.BufferInfo bufferInfo = this.f5738z;
                    bufferInfo.size += this.f5691Q0;
                    bufferInfo.offset = byteBufferW0.position();
                } else {
                    this.f5687O0 = byteBuffer;
                }
            }
            boolean z3 = this.f5460b == 1;
            if (this.f5716m0) {
                b0.o.c(this.f5720q, 1, "drainOutputBuffer[", this.f5672H.f5842g, "] speed ", Integer.valueOf(this.f5422l), ", isPrecisionSeekMode ", Boolean.valueOf(z3), ", presentationTimeUs ", Long.valueOf(this.f5738z.presentationTimeUs), ", lastSeekPositionUs ", Long.valueOf(this.f5423m));
            } else {
                Log.d(this.f5720q, "[Performance]speed " + this.f5422l + ", isPrecisionSeekMode " + z3 + ", presentationTimeUs " + this.f5738z.presentationTimeUs + ", lastSeekPositionUs " + this.f5423m);
                this.f5716m0 = true;
            }
            boolean z4 = this.f5422l <= 3 && z3 && this.f5738z.presentationTimeUs < this.f5423m;
            if (this.f5690Q && this.f5708e0) {
                try {
                    zZ0 = Z0(j2, j3, this.f5676J, this.f5687O0, this.f5738z, this.f5702Y, z4);
                } catch (IllegalStateException unused2) {
                    Y0();
                    if (this.f5711h0) {
                        e1();
                    }
                    if (z2) {
                        ((q) this).f5629t1.unlock();
                    }
                    return false;
                }
            } else {
                zZ0 = Z0(j2, j3, this.f5676J, this.f5687O0, this.f5738z, this.f5702Y, z4);
            }
            if (z2) {
                ((q) this).f5629t1.unlock();
            }
            if (!zZ0) {
                return false;
            }
            W0(this.f5738z.presentationTimeUs);
            if (this.f5689P0) {
                this.f5681L0.remove();
                this.f5683M0.remove();
            }
            this.f5702Y = -1;
            this.f5687O0 = null;
            this.f5693R0 = null;
            this.f5691Q0 = 0;
            return true;
        } catch (IllegalStateException unused3) {
            Log.w(this.f5720q, "Catch codec.getOutputBuffer IllegalStateException!");
            this.f5681L0.clear();
            this.f5683M0.clear();
            return false;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    private boolean l0(long j2, boolean z2) throws C0643i {
        String str;
        long j3;
        int iK;
        String str2;
        String str3;
        int i2;
        Object[] objArr;
        x xVar;
        List list;
        int i3;
        Object[] objArr2;
        if (this.f5731v0) {
            return false;
        }
        if (this.f5710g0 || this.f5706c0 == 2) {
            return this.f5689P0;
        }
        if (this.f5689P0) {
            ByteBuffer byteBuffer = this.f5732w.f5409b;
            if (byteBuffer == null || byteBuffer.position() == 0) {
                try {
                    ByteBuffer inputBuffer = this.f5676J.getInputBuffer(this.f5701X);
                    C0633A c0633a = this.f5732w;
                    c0633a.f5409b = inputBuffer;
                    c0633a.a();
                } catch (IllegalStateException unused) {
                    Log.w(this.f5720q, "Catch codec.getInputBuffer IllegalStateException!");
                    return false;
                }
            }
        } else if (this.f5701X < 0) {
            try {
                int iDequeueInputBuffer = this.f5676J.dequeueInputBuffer(0L);
                this.f5701X = iDequeueInputBuffer;
                if (iDequeueInputBuffer < 0) {
                    return false;
                }
                C0633A c0633a2 = this.f5732w;
                c0633a2.f5409b = this.f5698U[iDequeueInputBuffer];
                c0633a2.a();
            } catch (IllegalStateException e2) {
                Log.w(this.f5720q, "Catch codec.dequeueInputBuffer IllegalStateException!");
                if (this instanceof w) {
                    throw new C0643i(e2, 0);
                }
                throw new C0643i(e2, 1);
            }
        }
        if (this.f5706c0 == 1) {
            if (this.f5686O) {
                objArr2 = false;
            } else {
                this.f5708e0 = true;
                this.f5676J.queueInputBuffer(this.f5701X, 0, 0, 0L, 4);
                this.f5701X = -1;
                objArr2 = true;
            }
            this.f5706c0 = 2;
            return this.f5689P0 && objArr2 == true;
        }
        if (this.f5694S) {
            this.f5694S = false;
            ByteBuffer byteBuffer2 = this.f5732w.f5409b;
            byte[] bArr = f5654U0;
            byteBuffer2.put(bArr);
            this.f5676J.queueInputBuffer(this.f5701X, 0, bArr.length, 0L, 0);
            this.f5701X = -1;
            this.f5707d0 = true;
            return true;
        }
        boolean z3 = this instanceof q;
        if (this.f5718o0 && (xVar = this.f5672H) != null && (list = xVar.f5829H) != null && list.size() > 0) {
            if (z3 && this.f5737y0) {
                if (this.f5735x0 >= this.f5672H.f5829H.size()) {
                    this.f5718o0 = false;
                    this.f5735x0 = 0;
                    return true;
                }
                this.f5732w.f5409b.put((byte[]) this.f5672H.f5829H.get(this.f5735x0));
                int length = ((byte[]) this.f5672H.f5829H.get(this.f5735x0)).length;
                this.f5735x0++;
                i3 = length;
            } else {
                int length2 = 0;
                for (byte[] bArr2 : this.f5672H.f5829H) {
                    this.f5732w.f5409b.put(bArr2);
                    length2 += bArr2.length;
                }
                this.f5718o0 = false;
                i3 = length2;
            }
            this.f5676J.queueInputBuffer(this.f5701X, 0, i3, 0L, 2);
            b0.o.d(this.f5720q, "Resubmit the csd data as flush before outputFormatChanged isAudio[" + z3 + "] csd-" + this.f5735x0, 1);
            if (this.f5689P0) {
                this.f5732w.f5409b.clear();
            }
            this.f5701X = -1;
            this.f5705b0 = 0;
            this.f5724s.f5503c++;
            return true;
        }
        x xVar2 = this.f5672H;
        if (xVar2 == null || (str = xVar2.f5842g) == null) {
            str = z3 ? "audio" : "video";
            j3 = -1;
        } else {
            j3 = xVar2.f5856y;
        }
        if (this.f5712i0) {
            iK = -3;
            str2 = str;
            str3 = "vendor.mtk-codec2.trick";
            i2 = -2;
        } else {
            if (this.f5705b0 == 1) {
                if (xVar2 != null) {
                    for (int i4 = 0; i4 < this.f5672H.f5829H.size(); i4++) {
                        this.f5732w.f5409b.put((byte[]) this.f5672H.f5829H.get(i4));
                    }
                } else {
                    Log.e(this.f5720q, "format is null!");
                }
                this.f5705b0 = 2;
            }
            b0.o.c(this.f5720q, 1, "+readData[", str, "] positionMs[", Long.valueOf(j2), "]");
            long jCurrentTimeMillis = System.currentTimeMillis();
            try {
                if (this.f5731v0) {
                    return false;
                }
                iK = K(j2, this.f5734x, this.f5732w);
                if (this.f5715l0) {
                    str2 = str;
                    str3 = "vendor.mtk-codec2.trick";
                    i2 = -2;
                    b0.o.c(this.f5720q, 1, "-readData[", str2, "], result[", Integer.valueOf(iK), "], timeUs[", Long.valueOf(this.f5732w.f5412e), "/", Long.valueOf(j3), "], size[", Integer.valueOf(this.f5732w.f5410c), "], speedTimeMs[", Long.valueOf(System.currentTimeMillis() - jCurrentTimeMillis), "], flags[", Integer.valueOf(this.f5732w.f5411d), "], speed[", Integer.valueOf(this.f5422l), "], trickMode[", Integer.valueOf(this.f5729u0), "]");
                } else {
                    String str4 = this.f5720q;
                    StringBuilder sb = new StringBuilder();
                    sb.append("[Performance]-readData[");
                    sb.append(str);
                    sb.append("], result[");
                    sb.append(iK);
                    sb.append("], timeUs[");
                    str2 = str;
                    sb.append(this.f5732w.f5412e);
                    sb.append("], size[");
                    sb.append(this.f5732w.f5410c);
                    sb.append("], speedTimeMs[");
                    sb.append(System.currentTimeMillis() - jCurrentTimeMillis);
                    sb.append("], flags[");
                    sb.append(this.f5732w.f5411d);
                    sb.append("]");
                    Log.d(str4, sb.toString());
                    this.f5715l0 = true;
                    if (this.f5671G0 && b0.n.c() && this.f5732w.f5412e < 0) {
                        Bundle bundle = new Bundle();
                        bundle.putString("vendor.mtk-codec2.trick", "start-from-video");
                        this.f5676J.setParameters(bundle);
                        Log.i(this.f5720q, "Set start-from-video for viodeo with negative pts");
                    }
                    str3 = "vendor.mtk-codec2.trick";
                    i2 = -2;
                }
                if (z2 && this.f5709f0 == 1 && iK == i2 && this.f5425o != 3) {
                    this.f5709f0 = 2;
                }
            } catch (IllegalStateException e3) {
                Log.w(this.f5720q, "Readdata illegalStateException");
                if (this.f5689P0 && e3.getMessage() != null && e3.getMessage().contains("buffer is inaccessible")) {
                    return true;
                }
                throw new C0643i(e3, z3 ? 1 : 0);
            }
        }
        if (iK == i2) {
            return false;
        }
        C0633A c0633a3 = this.f5732w;
        if ((c0633a3.f5411d & 67108864) != 0 && this.f5671G0 && this.f5673H0) {
            long j4 = c0633a3.f5412e;
            this.f5423m = j4;
            this.f5719p0 = j4;
            if (this.f5422l > 4 && !z3) {
                this.f5677J0 = 1;
            }
        }
        int i5 = this.f5422l;
        if (i5 > 4 && !z3) {
            long j5 = this.f5719p0;
            long j6 = c0633a3.f5412e;
            if (j5 > j6) {
                this.f5719p0 = j6;
            }
        }
        if (!z3 && this.f5671G0 && this.f5673H0 && q1(i5) && this.f5671G0 && this.f5677J0 == 1 && this.f5729u0 == 0) {
            b0.o.d(this.f5720q, "lzl setvendorparam FF seek trick step", 1);
            Bundle bundle2 = new Bundle();
            if (b0.n.d()) {
                bundle2.putString("vendor.vdecomx.trick", "step");
            } else if (b0.n.c() && b0.n.e()) {
                Log.d(this.f5720q, "[C2Param] set Step before feedInputBuffer for Hbbtv");
                bundle2.putString(str3, "step");
            }
            this.f5676J.setParameters(bundle2);
            this.f5677J0 = 0;
            boolean[] zArr = this.f5675I0;
            zArr[1] = true;
            zArr[0] = false;
        }
        if (iK == -4) {
            if (this.f5705b0 == 2) {
                this.f5732w.a();
                this.f5705b0 = 1;
            }
            R0(this.f5734x);
            return !this.f5689P0;
        }
        if (iK == -1) {
            if (this.f5705b0 == 2) {
                this.f5732w.a();
                this.f5705b0 = 1;
            }
            Log.d(this.f5720q, "feedInputBuffer: End of " + str2 + " Input Stream.");
            this.f5710g0 = true;
            if (z3) {
                f5655V0 = true;
            }
            if (!this.f5707d0) {
                Log.d(this.f5720q, "Not received codec buffer anymore. processEndOfOutputStream...");
                Y0();
                return false;
            }
            try {
                if (this.f5686O) {
                    objArr = false;
                } else {
                    if ((this instanceof w) && this.f5669F0 != -1) {
                        ((w) this).I1(this.f5676J);
                    }
                    if (this.f5659A0) {
                        long j7 = this.f5739z0;
                        if (j7 == -1 || this.f5661B0 < j7) {
                            Bundle bundle3 = new Bundle();
                            bundle3.putLong("vendor.mtk-codec2.play-to", LocationRequestCompat.PASSIVE_INTERVAL);
                            m1(bundle3);
                            Log.i(this.f5720q, "hbbtv set ta mm playto 0x7fff....");
                            if (this.f5661B0 != -1 && (this instanceof w)) {
                                v0().I(this.f5661B0 + 40000);
                            }
                        }
                    }
                    this.f5708e0 = true;
                    this.f5676J.queueInputBuffer(this.f5701X, 0, 0, 0L, 4);
                    this.f5701X = -1;
                    objArr = true;
                }
                return this.f5689P0 && objArr == true;
            } catch (MediaCodec.CryptoException e4) {
                K0(e4);
                throw new C0643i(e4);
            }
        }
        String str5 = str2;
        if (this.f5713j0) {
            if (!this.f5732w.h()) {
                this.f5732w.a();
                if (this.f5705b0 == 2) {
                    this.f5705b0 = 1;
                }
                return !this.f5689P0;
            }
            if (!this.f5714k0) {
                this.f5713j0 = false;
            }
        }
        boolean z4 = this.f5732w.f() || this.f5732w.g();
        boolean zP1 = p1(z4);
        this.f5712i0 = zP1;
        if (zP1) {
            return false;
        }
        if (this.f5680L && !z4) {
            b0.r.b(this.f5732w.f5409b);
            if (this.f5732w.f5409b.position() == 0) {
                return !this.f5689P0;
            }
            this.f5680L = false;
        }
        try {
            int iPosition = this.f5732w.f5409b.position();
            C0633A c0633a4 = this.f5732w;
            int i6 = iPosition - c0633a4.f5410c;
            long j8 = c0633a4.f5412e;
            X0(j8, c0633a4.f5409b, iPosition, z4);
            this.f5661B0 = j8;
            if (z4) {
                MediaCodec.CryptoInfo cryptoInfoT0 = t0(this.f5732w, i6);
                b0.o.c(this.f5720q, 1, "queueSecureInputBuffer[", str5, "] timeStampUs[", Long.valueOf(j8), "/", Long.valueOf(j3), "]");
                this.f5676J.queueSecureInputBuffer(this.f5701X, 0, cryptoInfoT0, j8, 0);
            } else {
                try {
                    b0.o.c(this.f5720q, 1, "queueInputBuffer[", str5, "] timeStampUs[", Long.valueOf(j8), "/", Long.valueOf(j3), "]");
                    this.f5676J.queueInputBuffer(this.f5701X, 0, iPosition, j8, 0);
                } catch (IllegalStateException e5) {
                    Log.w(this.f5720q, "Catch codec.queueInputBuffer IllegalStateException!");
                    if (this.f5689P0) {
                        return false;
                    }
                    if (this instanceof w) {
                        throw new C0643i(e5, 0);
                    }
                    if (((q) this).v1()) {
                        throw new C0643i(e5);
                    }
                    throw new C0643i(e5, 1);
                }
            }
            if (this.f5689P0) {
                this.f5732w.f5409b.clear();
            }
            this.f5701X = -1;
            this.f5707d0 = true;
            this.f5705b0 = 0;
            this.f5724s.f5503c++;
            return true;
        } catch (MediaCodec.CryptoException e6) {
            K0(e6);
            throw new C0643i(e6);
        }
    }

    private boolean p1(boolean z2) throws C0643i {
        if (!this.f5703Z) {
            return false;
        }
        int iB = this.f5728u.b();
        if (iB != 0) {
            return iB != 4 && (z2 || !this.f5730v);
        }
        throw new C0643i(this.f5728u.e());
    }

    private boolean q1(int i2) {
        switch (i2) {
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
                return true;
            default:
                switch (i2) {
                    case 20:
                    case 21:
                    case 22:
                    case 23:
                    case 24:
                        return true;
                    default:
                        return false;
                }
        }
    }

    private static MediaCodec.CryptoInfo t0(C0633A c0633a, int i2) {
        MediaCodec.CryptoInfo cryptoInfoA = c0633a.f5408a.a();
        if (i2 == 0) {
            return cryptoInfoA;
        }
        if (cryptoInfoA.numBytesOfClearData == null) {
            cryptoInfoA.numBytesOfClearData = new int[1];
        }
        int[] iArr = cryptoInfoA.numBytesOfClearData;
        iArr[0] = iArr[0] + i2;
        return cryptoInfoA;
    }

    protected void A0(MediaFormat mediaFormat) {
    }

    protected boolean C0() {
        return this.f5710g0;
    }

    @Override // n.C
    protected void D(long j2, long j3, boolean z2) {
        int i2;
        if (z2) {
            i2 = this.f5709f0;
            if (i2 == 0) {
                i2 = 1;
            }
        } else {
            i2 = 0;
        }
        this.f5709f0 = i2;
        if (this.f5672H == null) {
            d1(j2);
        }
        G0();
        if (this.f5666E) {
            b0.B.a("bypassRender");
            while (W(j2, j3)) {
            }
            b0.B.c();
        } else if (this.f5676J != null && this.f5723r0 == 3) {
            b0.B.a("drainAndFeed");
            if (this.f5685N0.m() == 0 || (this.f5669F0 != -1 && (this instanceof w))) {
                while (k0(j2, j3)) {
                }
                if (!this.f5689P0 && l0(j2, true)) {
                    while (l0(j2, false)) {
                    }
                }
            }
            b0.B.c();
        }
        this.f5724s.a();
    }

    protected abstract boolean E0(x xVar);

    @Override // n.C
    protected final boolean F(x xVar) {
        return z0(this.f5726t, xVar);
    }

    protected final void G0() {
        x xVar;
        if (this.f5676J != null || this.f5666E || (xVar = this.f5672H) == null) {
            return;
        }
        if (this.f5674I == null && V(xVar.f5842g)) {
            if (this.f5728u == null || !b0.n.e()) {
                B0();
                A0(u0(this.f5672H));
                return;
            }
            Log.d(this.f5720q, "not bypass because drmSessionManager not null for hbbtv ");
        }
        if (!o1()) {
            if ((this instanceof w) && f5655V0) {
                if (!((w) this).C1()) {
                    this.f5711h0 = true;
                    Log.d(this.f5720q, "surface is not valid. set video outputStreamEnded");
                }
                f5655V0 = false;
                return;
            }
            return;
        }
        Log.i(this.f5720q, "maybeInitCodec entry mime:" + this.f5672H.f5842g);
        this.f5723r0 = 2;
        this.f5725s0.close();
        new a().start();
    }

    protected boolean I0(ByteBuffer byteBuffer) {
        if ((!this.f5666E && !this.f5721q0) || byteBuffer.limit() < 2) {
            return false;
        }
        if (this.f5697T0 == -1 && this.f5672H.r().containsKey("aac-profile")) {
            this.f5697T0 = this.f5672H.r().getInteger("aac-profile");
        }
        if (this.f5697T0 == 42) {
            return true;
        }
        byte b2 = byteBuffer.get(0);
        byte b3 = byteBuffer.get(1);
        int i2 = b2 & 255;
        return ((i2 == 255 && (b3 & 240) == 240) || (i2 == 86 && (b3 & 224) == 224)) ? false : true;
    }

    @Override // n.C
    protected void J(long j2) {
        l lVar;
        this.f5709f0 = 0;
        this.f5710g0 = false;
        this.f5711h0 = false;
        this.f5693R0 = null;
        this.f5691Q0 = 0;
        this.f5697T0 = -1;
        MediaCodec mediaCodec = this.f5676J;
        if (mediaCodec != null) {
            if (!this.f5689P0) {
                m0();
                return;
            }
            boolean z2 = this instanceof q;
            if (!z2 && this.f5669F0 != -1) {
                ((w) this).I1(mediaCodec);
            }
            Log.d(this.f5720q, "+codec.start(), isAudio[" + z2 + "]");
            if (!this.f5731v0) {
                try {
                    this.f5676J.start();
                    if (this instanceof w) {
                        Bundle bundle = new Bundle();
                        if (b0.n.e()) {
                            Log.i(this.f5720q, "disable vpeek for hbbtv");
                            bundle.putInt("tunnel-peek", 0);
                        } else {
                            Log.i(this.f5720q, "enable vpeek for mmp");
                            bundle.putInt("tunnel-peek", 1);
                        }
                        this.f5676J.setParameters(bundle);
                    }
                } catch (IllegalStateException e2) {
                    Log.e(this.f5720q, "Start codec error.", e2);
                    if (!this.f5731v0 && (lVar = this.f5685N0) != null) {
                        lVar.e0(new C0643i(e2, z2 ? 1 : 0));
                    }
                }
            }
            Log.d(this.f5720q, "-codec.start(), isAudio[" + z2 + "]");
        }
    }

    public boolean N0() {
        l lVar = this.f5685N0;
        if (lVar == null) {
            return false;
        }
        try {
            return k0(lVar.k(), this.f5685N0.i());
        } catch (C0643i e2) {
            this.f5685N0.e0(e2);
            return true;
        }
    }

    public void O0(MediaCodec.CodecException codecException, boolean z2) {
        this.f5731v0 = true;
        this.f5685N0.e0(new C0643i(codecException, z2 ? 1 : 0));
    }

    protected void P0(boolean z2) {
        Bundle bundle = new Bundle();
        Bundle bundle2 = new Bundle();
        if (this.f5676J != null) {
            if (z2 && this.f5733w0) {
                bundle.putInt("vendor.mtk-iview.force-real-time", 1);
            } else {
                bundle.putInt("vendor.mtk-iview.force-real-time", 2);
            }
            Log.d(this.f5720q, "+set vendor cmd: realtime = " + this.f5733w0 + ", focused = " + z2);
            this.f5676J.setParameters(bundle);
            Log.d(this.f5720q, "+set vendor cmd: realtime = " + this.f5733w0 + ", focused = " + z2);
            if (z2) {
                bundle2.putInt("vendor.mtk-iview.apply-system-clock", 0);
            } else {
                bundle2.putInt("vendor.mtk-iview.apply-system-clock", 1);
            }
            Log.d(this.f5720q, "+set vendor cmd: apply system clock " + z2);
            this.f5676J.setParameters(bundle2);
            Log.d(this.f5720q, "-set vendor cmd: apply system clock " + z2);
        }
    }

    public boolean Q0(int i2) {
        this.f5701X = i2;
        l lVar = this.f5685N0;
        long j2 = lVar != null ? lVar.j() : 0L;
        try {
            if (this.f5709f0 != 0) {
                return l0(j2, true);
            }
            return false;
        } catch (C0643i e2) {
            l lVar2 = this.f5685N0;
            if (lVar2 != null) {
                lVar2.e0(e2);
            }
            return true;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:31:0x005b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    protected void R0(n.y r6) {
        /*
            r5 = this;
            n.x r0 = r5.f5672H
            n.x r1 = r6.f5857a
            r5.f5672H = r1
            u.a r6 = r6.f5858b
            r5.f5674I = r6
            r6 = 1
            r5.f5670G = r6
            b0.AbstractC0399d.d(r1)
            u.a r1 = r5.f5674I
            r2 = 0
            if (r1 == 0) goto L1b
            boolean r1 = r5.f5703Z
            if (r1 != 0) goto L1b
            r1 = r6
            goto L1c
        L1b:
            r1 = r2
        L1c:
            n.x r3 = r5.f5672H
            boolean r3 = b0.D.a(r3, r0)
            if (r3 == 0) goto L27
            if (r1 != 0) goto L27
            return
        L27:
            boolean r3 = r5.f5666E
            if (r3 == 0) goto L2e
            r5.f5668F = r6
            return
        L2e:
            android.media.MediaCodec r3 = r5.f5676J
            if (r3 != 0) goto L36
            r5.G0()
            return
        L36:
            if (r3 == 0) goto L5f
            if (r1 != 0) goto L5f
            boolean r1 = r5.f5678K
            n.x r4 = r5.f5672H
            boolean r1 = r5.X(r3, r1, r0, r4)
            if (r1 == 0) goto L5f
            r5.f5704a0 = r6
            r5.f5705b0 = r6
            boolean r1 = r5.f5684N
            if (r1 == 0) goto L5b
            n.x r1 = r5.f5672H
            int r3 = r1.f5831L
            int r4 = r0.f5831L
            if (r3 != r4) goto L5b
            int r1 = r1.f5832M
            int r0 = r0.f5832M
            if (r1 != r0) goto L5b
            goto L5c
        L5b:
            r6 = r2
        L5c:
            r5.f5694S = r6
            goto L6c
        L5f:
            boolean r0 = r5.f5707d0
            if (r0 == 0) goto L66
            r5.f5706c0 = r6
            goto L6c
        L66:
            r5.e1()
            r5.G0()
        L6c:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: n.t.R0(n.y):void");
    }

    public void S0(int i2, MediaCodec.BufferInfo bufferInfo) {
        if (this.f5671G0 && (this instanceof w)) {
            try {
                this.f5681L0.put(Integer.valueOf(i2));
            } catch (InterruptedException unused) {
                Log.e(this.f5720q, "onOutputBufferAvailable, catch InterruptedException 1");
            }
        } else {
            try {
                this.f5681L0.put(Integer.valueOf(i2));
                this.f5683M0.put(bufferInfo);
            } catch (InterruptedException unused2) {
                Log.e(this.f5720q, "onOutputBufferAvailable, catch InterruptedException 2");
            }
        }
    }

    protected abstract void T0(MediaCodec mediaCodec, MediaFormat mediaFormat);

    protected void U(String str, long j2) {
        Handler handler = this.f5662C;
        if (handler == null || this.f5658A == null) {
            return;
        }
        handler.post(new e(str, j2));
    }

    public void U0(MediaFormat mediaFormat) {
        try {
            b1(mediaFormat);
        } catch (C0643i e2) {
            this.f5685N0.e0(e2);
        }
    }

    protected boolean V(String str) {
        return false;
    }

    protected void V0() {
    }

    protected void W0(long j2) {
    }

    protected boolean X(MediaCodec mediaCodec, boolean z2, x xVar, x xVar2) {
        return false;
    }

    protected void X0(long j2, ByteBuffer byteBuffer, int i2, boolean z2) {
    }

    protected boolean Y() {
        return false;
    }

    protected final boolean Z() {
        return this.f5676J != null && this.f5723r0 == 3;
    }

    protected abstract boolean Z0(long j2, long j3, MediaCodec mediaCodec, ByteBuffer byteBuffer, MediaCodec.BufferInfo bufferInfo, int i2, boolean z2);

    @Override // n.C, n.G, n.j.a
    public void b(int i2, Object obj) {
        Bundle bundle = new Bundle();
        if (i2 == 1010) {
            if (this.f5676J == null || !b0.n.d()) {
                return;
            }
            bundle.putString("vendor.vdecomx.trick", "step");
            this.f5676J.setParameters(bundle);
        }
        if (i2 == 1011) {
            if (this.f5676J != null) {
                Long l2 = (Long) obj;
                bundle.putInt("vendor.vdecomx.seek-to", l2.intValue());
                this.f5676J.setParameters(bundle);
                Log.d(this.f5720q, "set vendor cmd seek-to, pos:" + l2);
                return;
            }
            return;
        }
        switch (i2) {
            case PointerIconCompat.TYPE_ZOOM_OUT /* 1019 */:
                if (this.f5676J != null) {
                    Log.i(this.f5720q, "Set new videoPqParams");
                    Bundle bundle2 = new Bundle();
                    bundle2.putString("pq-applier", (String) obj);
                    this.f5676J.setParameters(bundle2);
                }
                break;
            case PointerIconCompat.TYPE_GRAB /* 1020 */:
                if (this.f5676J != null) {
                    String str = this.f5720q;
                    StringBuilder sb = new StringBuilder();
                    sb.append("Set video game mode:");
                    Integer num = (Integer) obj;
                    sb.append(num.intValue());
                    Log.i(str, sb.toString());
                    Bundle bundle3 = new Bundle();
                    bundle3.putInt("vendor.mtk-codec2.game-mode", num.intValue());
                    this.f5676J.setParameters(bundle3);
                }
                break;
            case PointerIconCompat.TYPE_GRABBING /* 1021 */:
                if (this.f5676J != null) {
                    Log.d(this.f5720q, "hbbtv set release vdec resource");
                    bundle.putInt("vendor.mtk-codec2.release-vdec-resource", 1);
                    bundle.putInt("vendor.mtk-codec2.acquire-vdec-resource", 0);
                    this.f5676J.setParameters(bundle);
                }
                break;
            case 1022:
                if (this.f5676J != null) {
                    Log.d(this.f5720q, "hbbtv set acquire vdec resource");
                    bundle.putInt("vendor.mtk-codec2.acquire-vdec-resource", 1);
                    bundle.putInt("vendor.mtk-codec2.release-vdec-resource", 0);
                    this.f5676J.setParameters(bundle);
                }
                break;
            case 1023:
                boolean zBooleanValue = ((Boolean) obj).booleanValue();
                if (this.f5676J == null) {
                    this.f5727t0 = true;
                    Log.d(this.f5720q, "hbbtv save setting pause-at-first-sequence-changed=" + zBooleanValue);
                } else {
                    this.f5727t0 = false;
                    Log.d(this.f5720q, "hbbtv set c2 pause-at-first-sequence-changed=" + zBooleanValue);
                    bundle.putInt("vendor.mtk-codec2.pause-at-first-sequence-change", zBooleanValue ? 1 : 0);
                    this.f5676J.setParameters(bundle);
                }
                break;
            default:
                super.b(i2, obj);
                break;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    protected void e1() {
        this.f5725s0.block();
        if (p0()) {
            j0();
        }
        if (this.f5676J != null) {
            this.f5700W = -1L;
            this.f5712i0 = false;
            this.f5735x0 = 0;
            this.f5737y0 = false;
            this.f5736y.clear();
            this.f5698U = null;
            this.f5699V = null;
            this.f5704a0 = false;
            this.f5707d0 = false;
            this.f5678K = false;
            this.f5680L = false;
            this.f5682M = false;
            this.f5684N = false;
            this.f5686O = false;
            this.f5688P = false;
            this.f5692R = false;
            this.f5694S = false;
            this.f5696T = false;
            this.f5708e0 = false;
            f5655V0 = false;
            this.f5705b0 = 0;
            this.f5706c0 = 0;
            this.f5724s.f5502b++;
            this.f5723r0 = 1;
            this.f5739z0 = -1L;
            this.f5663C0 = false;
            this.f5661B0 = -1L;
            try {
                r rVar = this.f5679K0;
                if (rVar != null) {
                    rVar.d();
                    this.f5681L0.clear();
                    this.f5683M0.clear();
                }
                this.f5687O0 = null;
                this.f5701X = -1;
                this.f5702Y = -1;
                Log.i(this.f5720q, "+++codec stop");
                this.f5676J.stop();
                Log.i(this.f5720q, "---codec stop");
                try {
                    Log.i(this.f5720q, "+++codec release");
                    this.f5676J.release();
                    Log.i(this.f5720q, "---codec release");
                } finally {
                }
            } catch (Throwable th) {
                try {
                    Log.i(this.f5720q, "+++codec release");
                    this.f5676J.release();
                    Log.i(this.f5720q, "---codec release");
                    throw th;
                } finally {
                }
            }
        }
    }

    public void f1(int i2, Bundle bundle) {
        boolean z2 = this instanceof q;
        if (this.f5676J == null || z2) {
            return;
        }
        if (b0.n.e() && bundle.containsKey("vendor.mtk-codec2.trick") && bundle.getString("vendor.mtk-codec2.trick").equals("decode-i")) {
            Log.d(this.f5720q, "decodeI need flush codec");
            n0();
        }
        Log.d(this.f5720q, "[C2Param]Set C2 vendor params speed[" + i2 + "]");
        bundle.remove("rendererSpeed");
        this.f5676J.setParameters(bundle);
        if (b0.n.e()) {
            return;
        }
        if (i2 == 3 || i2 == 1) {
            ((w) this).L1(this.f5676J);
        } else {
            Log.d(this.f5720q, "set C2 maybeSetOnFrameRenderedListener on");
            ((w) this).I1(this.f5676J);
        }
    }

    public void g1(u.b bVar) {
        this.f5728u = bVar;
    }

    protected abstract void h0(MediaCodec mediaCodec, boolean z2, MediaFormat mediaFormat, MediaCrypto mediaCrypto);

    public void i1(l lVar) {
        this.f5685N0 = lVar;
    }

    protected void j1(boolean z2) {
        this.f5671G0 = z2;
    }

    public void k1(Surface surface) {
        if (this instanceof q) {
            return;
        }
        if (this.f5676J == null) {
            Log.e(this.f5720q, "set output surface fail, codec null.");
        } else {
            Log.e(this.f5720q, "update hbbtv output surface");
            this.f5676J.setOutputSurface(surface);
        }
    }

    public void l1(int i2) {
        this.f5669F0 = i2;
    }

    protected void m0() {
        this.f5700W = -1L;
        this.f5701X = -1;
        this.f5702Y = -1;
        this.f5713j0 = true;
        this.f5714k0 = false;
        this.f5712i0 = false;
        this.f5735x0 = 0;
        this.f5736y.clear();
        this.f5694S = false;
        this.f5696T = false;
        this.f5718o0 = !this.f5717n0;
        if (this.f5682M || ((this.f5688P && this.f5708e0) || this.f5706c0 != 0)) {
            e1();
            G0();
        } else {
            this.f5676J.flush();
            this.f5707d0 = false;
        }
        if (!this.f5704a0 || this.f5672H == null) {
            return;
        }
        this.f5705b0 = 1;
    }

    public void m1(Bundle bundle) {
        MediaCodec mediaCodec = this.f5676J;
        if (mediaCodec == null || bundle == null) {
            return;
        }
        mediaCodec.setParameters(bundle);
    }

    @Override // n.G
    protected boolean n() {
        return this.f5711h0;
    }

    protected void n0() {
        l lVar;
        l lVar2;
        this.f5679K0.a();
        this.f5681L0.clear();
        this.f5683M0.clear();
        this.f5732w.f5409b = null;
        this.f5687O0 = null;
        if (!this.f5731v0) {
            Log.d(this.f5720q, "+codec.flush() for decodeI");
            try {
                m0();
            } catch (Exception e2) {
                Log.e(this.f5720q, "decodeI Flush codec error.", e2);
                if (!this.f5731v0 && (lVar2 = this.f5685N0) != null) {
                    lVar2.e0(new C0643i(e2, 0));
                }
            }
            this.f5714k0 = true;
            this.f5679K0.b();
            Log.d(this.f5720q, "-codec.flush() for decodeI");
        }
        if (this.f5731v0 || !this.f5689P0) {
            return;
        }
        Log.d(this.f5720q, "+codec.start() for decodeI");
        try {
            this.f5676J.start();
        } catch (Exception e3) {
            Log.e(this.f5720q, "Start codec error.", e3);
            if (!this.f5731v0 && (lVar = this.f5685N0) != null) {
                lVar.e0(new C0643i(e3, 0));
            }
        }
        Log.d(this.f5720q, "-codec.start() for decodeI");
    }

    public void n1(int i2, boolean z2) {
        boolean z3 = this instanceof q;
        if (this.f5676J == null || z3) {
            return;
        }
        if (this.f5723r0 != 3) {
            b0.o.d("MediaCodecVideoTrackRenderer", "codec is not init done, return", 1);
            return;
        }
        Bundle bundle = new Bundle();
        if (z2) {
            if (i2 == 3) {
                bundle.putString("vendor.vdecomx.trick", "resume");
                this.f5676J.setParameters(bundle);
                b0.o.d(this.f5720q, "lzl setvendorparam VIDEO_ONLY_RESUME", 1);
            } else if (i2 == 1) {
                bundle.putString("vendor.vdecomx.trick", "pause");
                this.f5676J.setParameters(bundle);
                b0.o.d(this.f5720q, "lzl setvendorparam VIDEO_ONLY_PAUSE", 1);
            }
        } else if (i2 == 4) {
            if (!this.f5675I0[0]) {
                bundle.putString("vendor.vdecomx.trick", "resume");
                this.f5676J.setParameters(bundle);
                bundle.putString("vendor.vdecomx.trick", "dropframe");
                this.f5676J.setParameters(bundle);
                boolean[] zArr = this.f5675I0;
                zArr[0] = true;
                zArr[1] = false;
                b0.o.d(this.f5720q, "lzl setvendorparam FF 2x trick dropframe", 1);
            }
        } else if (i2 == 3 || i2 == 1 || i2 == 2) {
            if (i2 == 3) {
                bundle.putString("vendor.vdecomx.trick", "tricktonormal");
                this.f5676J.setParameters(bundle);
                bundle.putString("vendor.vdecomx.trick", "resume");
            } else if (i2 == 1) {
                bundle.putString("vendor.vdecomx.trick", "pause");
            } else {
                bundle.putString("vendor.vdecomx.trick", "step");
            }
            this.f5676J.setParameters(bundle);
            boolean[] zArr2 = this.f5675I0;
            zArr2[0] = false;
            zArr2[1] = false;
            b0.o.d(this.f5720q, "lzl setvendorparam trick to normal", 1);
        }
        if (b0.n.e()) {
            return;
        }
        if (i2 == 3 || i2 == 1) {
            ((w) this).L1(this.f5676J);
        } else {
            Log.d(this.f5720q, "set maybeSetOnFrameRenderedListener on");
            ((w) this).I1(this.f5676J);
        }
    }

    @Override // n.G
    protected boolean o() {
        return (this.f5672H == null || this.f5712i0 || (this.f5709f0 == 0 && this.f5702Y < 0 && !F0())) ? false : true;
    }

    protected long o0() {
        C0635a c0635a = this.f5664D;
        if (c0635a != null) {
            return c0635a.p();
        }
        return -1L;
    }

    protected boolean o1() {
        return this.f5676J == null && this.f5672H != null && this.f5723r0 == 1;
    }

    @Override // n.C, n.G
    protected void p() {
        super.p();
    }

    protected boolean p0() {
        return this.f5666E;
    }

    @Override // n.C, n.G
    protected void q(long j2) {
        this.f5725s0.block();
        this.f5672H = null;
        this.f5674I = null;
        this.f5693R0 = null;
        this.f5691Q0 = 0;
        this.f5697T0 = -1;
        this.f5663C0 = false;
        if (this instanceof q) {
            this.f5423m = -1L;
        }
        try {
            e1();
            try {
                if (this.f5703Z) {
                    this.f5728u.close();
                    this.f5703Z = false;
                }
            } finally {
            }
        } catch (Throwable th) {
            try {
                if (this.f5703Z) {
                    this.f5728u.close();
                    this.f5703Z = false;
                }
                throw th;
            } finally {
            }
        }
    }

    protected C0640f q0(s sVar, String str, boolean z2) {
        return sVar.c(str, z2);
    }

    protected C0640f r0(s sVar, String str, boolean z2, boolean z3) {
        return sVar.a(str, z2, z3);
    }

    protected long s0() {
        return 0L;
    }

    @Override // n.G
    protected void t() {
    }

    @Override // n.G
    protected void u() {
        this.f5725s0.block();
        this.f5663C0 = false;
        if (this.f5422l <= 4 || !this.f5689P0) {
            return;
        }
        Log.i(this.f5720q, "onStopped speed:" + this.f5422l);
        this.f5679K0.a();
        this.f5681L0.clear();
        this.f5683M0.clear();
        this.f5732w.f5409b = null;
        this.f5687O0 = null;
        if (p0()) {
            j0();
        }
        this.f5679K0.b();
    }

    protected MediaFormat u0(x xVar) {
        MediaFormat mediaFormatR = xVar.r();
        if (this.f5660B) {
            mediaFormatR.setInteger("auto-frc", 0);
        }
        return mediaFormatR;
    }

    public l v0() {
        return this.f5685N0;
    }

    protected ByteBuffer w0(ByteBuffer byteBuffer, int i2) {
        if (this.f5697T0 == 42) {
            ByteBuffer byteBuffer2 = this.f5695S0;
            if (byteBuffer2 != null) {
                this.f5691Q0 = AbstractC0396a.d(byteBuffer2, i2);
            }
        } else {
            this.f5691Q0 = f5657X0;
        }
        ByteBuffer byteBuffer3 = this.f5693R0;
        if (byteBuffer3 == null || byteBuffer3.limit() < this.f5691Q0 + i2) {
            this.f5693R0 = ByteBuffer.allocate(this.f5691Q0 + i2);
        }
        this.f5693R0.clear();
        int iPosition = byteBuffer.position();
        if (this.f5697T0 != 42) {
            ByteBuffer byteBuffer4 = this.f5693R0;
            x xVar = this.f5672H;
            byteBuffer4.put(AbstractC0396a.a(xVar.f5841f0, xVar.f5840e0, i2));
            this.f5693R0.put(byteBuffer);
            this.f5693R0.position(0);
        } else if (this.f5695S0 != null) {
            b0.E e2 = new b0.E(this.f5693R0);
            AbstractC0396a.b(this.f5695S0, i2, e2);
            e2.f(byteBuffer);
            this.f5693R0 = e2.d();
        } else {
            Log.e(this.f5720q, "No avaiable ascbuffer");
        }
        byteBuffer.position(iPosition);
        return this.f5693R0;
    }

    @Override // n.C, n.G
    protected void x(long j2) {
        l lVar;
        this.f5725s0.block();
        if (this.f5729u0 == -1) {
            this.f5665D0 = true;
        }
        this.f5663C0 = false;
        boolean z2 = this instanceof q;
        if (this.f5676J != null && this.f5689P0) {
            this.f5679K0.a();
            this.f5681L0.clear();
            this.f5683M0.clear();
            this.f5732w.f5409b = null;
            this.f5687O0 = null;
            if (!this.f5731v0) {
                try {
                    m0();
                } catch (IllegalStateException e2) {
                    Log.e(this.f5720q, "Flush codec error.", e2);
                    if (!this.f5731v0 && (lVar = this.f5685N0) != null) {
                        lVar.e0(new C0643i(e2, z2 ? 1 : 0));
                    }
                }
            }
            this.f5679K0.b();
        }
        if (p0()) {
            j0();
            G0();
        }
        super.x(j2);
        Bundle bundle = new Bundle();
        if (!b0.n.c() || this.f5676J == null || z2 || this.f5460b != 1) {
            return;
        }
        long j3 = 1000 * j2;
        bundle.putString("vendor.mtk-codec2.trick", "start-from-video");
        bundle.putLong("vendor.mtk-codec2.seek-to", j3);
        this.f5676J.setParameters(bundle);
        Log.i(this.f5720q, "Render seek to " + j2 + " Us, Ns=" + j3);
    }

    protected final int x0() {
        return this.f5709f0;
    }

    protected int y0() {
        return this.f5669F0;
    }

    protected abstract boolean z0(s sVar, x xVar);

    public t(String str, InterfaceC0634B[] interfaceC0634BArr, s sVar, u.b bVar, boolean z2, Handler handler, g gVar) {
        super(str, interfaceC0634BArr);
        this.f5722r = false;
        this.f5717n0 = false;
        this.f5718o0 = false;
        this.f5719p0 = 0L;
        this.f5721q0 = false;
        this.f5723r0 = 1;
        this.f5727t0 = false;
        this.f5729u0 = -1;
        this.f5731v0 = false;
        this.f5733w0 = true;
        this.f5735x0 = 0;
        this.f5737y0 = false;
        this.f5739z0 = -1L;
        this.f5659A0 = false;
        this.f5661B0 = -1L;
        this.f5663C0 = false;
        this.f5665D0 = false;
        this.f5667E0 = -1;
        this.f5675I0 = new boolean[]{false, false};
        this.f5697T0 = -1;
        this.f5720q = "MediaCodecTrackRenderer" + str;
        AbstractC0399d.e(b0.D.f2965a >= 16);
        this.f5726t = (s) AbstractC0399d.d(sVar);
        this.f5728u = bVar;
        this.f5730v = z2;
        this.f5662C = handler;
        this.f5658A = gVar;
        this.f5660B = i0();
        this.f5724s = new C0638d();
        this.f5732w = new C0633A(0);
        this.f5664D = new C0635a();
        this.f5734x = new y();
        this.f5736y = new ArrayList();
        this.f5738z = new MediaCodec.BufferInfo();
        this.f5705b0 = 0;
        this.f5706c0 = 0;
        this.f5669F0 = -1;
        this.f5677J0 = 0;
        this.f5673H0 = true;
        this.f5681L0 = new LinkedBlockingQueue();
        this.f5683M0 = new LinkedBlockingQueue();
        this.f5687O0 = null;
        this.f5693R0 = ByteBuffer.allocate(0);
        this.f5691Q0 = 0;
        this.f5695S0 = null;
        this.f5715l0 = false;
        this.f5716m0 = false;
        this.f5725s0 = new ConditionVariable(true);
        h1();
    }

    public static class f extends Exception {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final String f5752b;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public final boolean f5753g;

        /* JADX INFO: renamed from: r, reason: collision with root package name */
        public final String f5754r;

        /* JADX INFO: renamed from: x, reason: collision with root package name */
        public final String f5755x;

        public f(x xVar, Throwable th, boolean z2, int i2) {
            super("Decoder init failed: [" + i2 + "], " + xVar, th);
            this.f5752b = xVar.f5842g;
            this.f5753g = z2;
            this.f5754r = null;
            this.f5755x = a(i2);
        }

        private static String a(int i2) {
            return "com.google.android.exoplayer.MediaCodecTrackRenderer_" + (i2 < 0 ? "neg_" : HttpUrl.FRAGMENT_ENCODE_SET) + Math.abs(i2);
        }

        private static String b(Throwable th) {
            if (th instanceof MediaCodec.CodecException) {
                return ((MediaCodec.CodecException) th).getDiagnosticInfo();
            }
            return null;
        }

        public f(x xVar, Throwable th, boolean z2, String str) {
            super("Decoder init failed: " + str + ", " + xVar, th);
            this.f5752b = xVar.f5842g;
            this.f5753g = z2;
            this.f5754r = str;
            this.f5755x = b0.D.f2965a >= 21 ? b(th) : null;
        }
    }
}
