package b0;

import android.media.MediaCodec;
import android.media.PlaybackParams;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.SystemClock;
import android.util.Log;
import android.view.Surface;
import androidx.core.view.PointerIconCompat;
import com.cvte.vman.instance.InvokeCmd;
import java.lang.Thread;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArraySet;
import n.C0642h;
import n.C0643i;
import n.G;
import n.j;
import n.t;
import n.w;
import okhttp3.HttpUrl;

/* JADX INFO: loaded from: classes.dex */
public class p extends v implements j.c, I.l, Handler.Callback, w.f {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    private PlaybackParams f3035A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    private Bundle f3036B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    private float f3037C;

    /* JADX INFO: renamed from: D, reason: collision with root package name */
    private String f3038D;

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final n.j f3041c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final CopyOnWriteArraySet f3042d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private G[] f3043e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private int[] f3044f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private c f3045g;

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private a f3047i;

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private final Handler f3049k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private final HandlerThread f3050l;

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

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

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

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private List f3054p;

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

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

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

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

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

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

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

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

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

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

    public interface a {
        void onCues(List list);
    }

    public interface b {
        void onPrepared();

        void onSeekReadyInTrick();

        void onTrackStateChanged(int i2, int i3, boolean z2);

        void onTrickEnded(int i2, int i3);
    }

    public final class c {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final a0.n f3065a;

        public c(a0.n nVar) {
            this.f3065a = nVar;
        }

        protected void a() {
            a0.n nVar = this.f3065a;
            if (nVar != null) {
                nVar.g();
            }
        }

        protected void b(long j2) {
            a0.n nVar = this.f3065a;
            if (nVar != null) {
                nVar.h(j2);
            }
        }
    }

    public p(String str, n.j jVar) {
        super(jVar);
        this.f3055q = -1;
        this.f3056r = Integer.MIN_VALUE;
        this.f3062x = 0L;
        this.f3063y = -1;
        this.f3064z = -1;
        this.f3035A = null;
        this.f3036B = null;
        this.f3037C = 1.0f;
        this.f3038D = "resume";
        this.f3040b = "MtkPlayerControl" + str;
        this.f3041c = jVar;
        jVar.h(this);
        this.f3042d = new CopyOnWriteArraySet();
        int[] iArr = new int[6];
        this.f3044f = iArr;
        iArr[2] = -1;
        x xVar = new x(getClass().getSimpleName() + ":Handler", -4);
        this.f3050l = xVar;
        xVar.start();
        this.f3049k = new Handler(xVar.getLooper(), this);
        this.f3048j = false;
        this.f3046h = 3;
        this.f3051m = -1;
        this.f3052n = -1;
        this.f3053o = 1;
        this.f3054p = null;
        this.f3039E = false;
        this.f3057s = false;
        this.f3058t = false;
        this.f3059u = false;
        this.f3060v = false;
        this.f3061w = false;
        PlaybackParams playbackParams = new PlaybackParams();
        this.f3035A = playbackParams;
        playbackParams.setSpeed(1.0f);
    }

    private boolean A(float f2) {
        return Math.abs(f2 - this.f3035A.getSpeed()) < 1.0E-4f;
    }

    private void C(G[] gArr) {
        G[] gArr2;
        G g2;
        String str = this.f3040b;
        StringBuilder sb = new StringBuilder();
        sb.append("update newest TrackRenderers, is null(");
        sb.append(gArr == null);
        sb.append(")");
        Log.i(str, sb.toString());
        this.f3043e = gArr;
        if (gArr != null && (g2 = gArr[0]) != null && (g2 instanceof n.w)) {
            ((n.w) g2).t1(this);
            int i2 = this.f3063y;
            if (i2 != -1) {
                this.f3041c.q(gArr[0], InvokeCmd.CMD_PROJECT_ID_GET_INDEX, Integer.valueOf(i2));
            }
            int i3 = this.f3064z;
            if (i3 != -1) {
                this.f3041c.q(gArr[0], 1009, Integer.valueOf(i3));
            }
            Bundle bundle = this.f3036B;
            if (bundle != null) {
                this.f3041c.q(gArr[0], InvokeCmd.CMD_PROJECT_ID_IS_SUPPORT, bundle);
            }
        }
        if (A(0.0f) || A(1.0f) || (gArr2 = this.f3043e) == null || gArr2[1] == null) {
            return;
        }
        this.f3041c.q(gArr[1], 2, this.f3035A);
    }

    private void E(int i2) {
        boolean z2;
        Iterator it = this.f3042d.iterator();
        while (it.hasNext()) {
            ((b) it.next()).onSeekReadyInTrick();
        }
        if (b()) {
            if (this.f3059u) {
                start();
                this.f3059u = false;
                this.f3061w = false;
                return;
            } else if (this.f3061w) {
                pause();
                this.f3061w = false;
                return;
            }
        }
        long jG = 0;
        if (i2 < 5 || i2 > 14) {
            z2 = false;
        } else {
            try {
                long jElapsedRealtime = SystemClock.elapsedRealtime() - this.f3062x;
                if (jElapsedRealtime < 980) {
                    String str = this.f3040b;
                    StringBuilder sb = new StringBuilder();
                    sb.append("sleep time = ");
                    long j2 = 980 - jElapsedRealtime;
                    sb.append(j2);
                    Log.i(str, sb.toString());
                    Thread.sleep(j2);
                } else if (jElapsedRealtime > 1000) {
                    jG = ((long) g(i2)) * (jElapsedRealtime - 1200) * ((long) ((int) s(i2)));
                    Log.i(this.f3040b, "forwardDiffTime = " + jG);
                } else {
                    Log.i(this.f3040b, "trickInSeekDelayTime = " + jElapsedRealtime);
                }
                this.f3062x = SystemClock.elapsedRealtime();
                z2 = false;
            } catch (InterruptedException e2) {
                Log.i(this.f3040b, "Thread interrupted, ignore next seek.\n" + e2.toString());
                z2 = true;
            }
        }
        if (i2 == 4 && !b()) {
            if (!this.f3041c.getPlayWhenReady()) {
                this.f3041c.setPlayWhenReady(true);
            }
            I(1, false);
            if (!n.c()) {
                if (n.d()) {
                    M(i2, this.f3051m);
                    return;
                }
                return;
            }
            this.f3041c.f(i2, 0, this.f3051m);
            Bundle bundle = new Bundle();
            Log.d(this.f3040b, "[C2Param]seekInTrick --> 2x resume C2");
            bundle.putString("vendor.mtk-codec2.trick", "resume");
            Log.d(this.f3040b, "[C2Param]setSpeed 2.0 to C2");
            bundle.putFloat("vendor.mtk-codec2.set-speed", 2.0f);
            O(i2, PointerIconCompat.TYPE_NO_DROP, bundle);
            return;
        }
        if (this.f3059u && !b()) {
            start();
            this.f3059u = false;
            this.f3061w = false;
            return;
        }
        if (this.f3061w && !b()) {
            pause();
            this.f3061w = false;
            return;
        }
        if (z2) {
            Log.i(this.f3040b, "seekInterrupted, return direclty");
            return;
        }
        long duration = this.f3041c.getDuration();
        if (this.f3056r == 0) {
            this.f3060v = true;
            Iterator it2 = this.f3042d.iterator();
            while (it2.hasNext()) {
                ((b) it2.next()).onTrickEnded(i2, 0);
            }
            this.f3056r = Integer.MIN_VALUE;
            return;
        }
        int i3 = i(i2);
        this.f3056r = i3;
        if (i3 == 0) {
            I(1, true);
        }
        int i4 = this.f3056r;
        if (i4 == Integer.MIN_VALUE) {
            this.f3060v = true;
            Iterator it3 = this.f3042d.iterator();
            while (it3.hasNext()) {
                ((b) it3.next()).onTrickEnded(i2, 0);
            }
            return;
        }
        if (i4 < 0 || i4 > duration) {
            Log.e(this.f3040b, "unexpected next trick position, " + this.f3056r + "ms");
            return;
        }
        if (i2 >= 20 && i2 <= 24 && i4 < this.f3041c.getCurrentPosition()) {
            try {
                Thread.sleep((long) ((this.f3041c.getCurrentPosition() - ((long) this.f3056r)) / s(i2)));
            } catch (InterruptedException e3) {
                e3.printStackTrace();
            }
        }
        this.f3056r = (int) (((long) this.f3056r) + jG);
        if (this.f3046h != 3) {
            seekTo(this.f3056r);
        }
        if (this.f3056r == duration) {
            this.f3049k.removeMessages(1);
            for (b bVar : this.f3042d) {
                Log.i(this.f3040b, "seek for trick, notify TRICK_TO_END!");
                bVar.onTrickEnded(i2, 1);
            }
        }
    }

    private void M(int i2, int i3) {
        if (b()) {
            return;
        }
        this.f3041c.f(i2, 0, i3);
        Bundle bundle = new Bundle();
        bundle.putInt("rendererSpeed", i2);
        this.f3041c.q(this.f3043e[0], 1002, bundle);
    }

    private void O(int i2, int i3, Bundle bundle) {
        if (i2 == 3) {
            this.f3037C = 1.0f;
        } else if (i2 == 4) {
            this.f3037C = 2.0f;
        }
        if (bundle.containsKey("vendor.mtk-codec2.trick")) {
            String string = bundle.getString("vendor.mtk-codec2.trick");
            if (string.equals("pause") || string.equals("resume")) {
                this.f3038D = string;
                Log.i(this.f3040b, "update C2 status:" + string);
            }
        }
        bundle.putInt("rendererSpeed", i2);
        this.f3041c.q(this.f3043e[0], i3, bundle);
    }

    private void c(G[] gArr) {
        G g2;
        String str = this.f3040b;
        StringBuilder sb = new StringBuilder();
        sb.append("update newest TrackRenderers, is null(");
        sb.append(gArr == null);
        sb.append(")");
        Log.i(str, sb.toString());
        this.f3043e = gArr;
        if (gArr == null || (g2 = gArr[0]) == null || !(g2 instanceof n.w)) {
            return;
        }
        ((n.w) g2).t1(this);
    }

    private int g(int i2) {
        if ((i2 >= 4 && i2 <= 8) || (i2 >= 15 && i2 <= 19)) {
            return 1;
        }
        if (i2 >= 9 && i2 <= 14) {
            return -1;
        }
        if (i2 >= 20 && i2 <= 24) {
            return -1;
        }
        Log.e(this.f3040b, "currentSpeed " + this.f3046h + " is not a trick speed!");
        return 1;
    }

    private int i(int i2) {
        int currentPosition = getCurrentPosition();
        int iG = ((int) (((double) g(i2)) * s(i2) * 1000.0d)) + currentPosition;
        if (iG < 0) {
            return currentPosition > 0 ? 0 : Integer.MIN_VALUE;
        }
        long duration = this.f3041c.getDuration();
        return ((long) iG) > duration ? (int) duration : iG;
    }

    private double s(int i2) {
        switch (i2) {
            case 4:
            case 10:
                return 2.0d;
            case 5:
            case 11:
                return 4.0d;
            case 6:
            case 12:
                return 8.0d;
            case 7:
            case 13:
                return 16.0d;
            case 8:
            case 14:
                return 32.0d;
            case 9:
            default:
                return 1.0d;
            case 15:
            case 20:
                return 0.5d;
            case 16:
            case 21:
                return 0.25d;
            case 17:
            case 22:
                return 0.125d;
            case 18:
            case 23:
                return 0.0625d;
            case 19:
            case 24:
                return 0.03125d;
        }
    }

    public void B(int i2, int i3) {
        G[] gArr;
        int i4;
        this.f3054p = new ArrayList();
        if (n.e() || (gArr = this.f3043e) == null) {
            return;
        }
        G g2 = gArr[0];
        int i5 = -1;
        if (g2 == null || (g2 instanceof C0642h)) {
            i4 = -1;
        } else {
            int iE = this.f3041c.e(0);
            i4 = -1;
            for (int i6 = 0; i6 < iE; i6++) {
                n.x xVarB = this.f3041c.b(0, i6);
                if (xVarB != null) {
                    int i7 = xVarB.f5850n0;
                    if (i7 == -1) {
                        if (!"1".equals(D.y("vendor.mtk.auto_test", HttpUrl.FRAGMENT_ENCODE_SET)) || w(2) <= 0) {
                            return;
                        }
                        K(2, 0);
                        return;
                    }
                    if (!this.f3054p.contains(Integer.valueOf(i7))) {
                        this.f3054p.add(Integer.valueOf(xVarB.f5850n0));
                    }
                    if (i4 == -1 && i2 < this.f3054p.size() && xVarB.f5850n0 == ((Integer) this.f3054p.get(i2)).intValue()) {
                        i4 = i6;
                    }
                }
            }
        }
        G g3 = this.f3043e[1];
        if (g3 != null && !(g3 instanceof C0642h)) {
            int iE2 = this.f3041c.e(1);
            int i8 = 0;
            while (true) {
                if (i8 >= iE2) {
                    break;
                }
                n.x xVarB2 = this.f3041c.b(1, i8);
                if (xVarB2 != null) {
                    int i9 = xVarB2.f5850n0;
                    if (i9 == -1) {
                        if (!"1".equals(D.y("vendor.mtk.auto_test", HttpUrl.FRAGMENT_ENCODE_SET)) || w(2) <= 0) {
                            return;
                        }
                        K(2, 0);
                        return;
                    }
                    if (!this.f3054p.contains(Integer.valueOf(i9))) {
                        this.f3054p.add(Integer.valueOf(xVarB2.f5850n0));
                    }
                    if (i2 < this.f3054p.size() && xVarB2.f5850n0 == ((Integer) this.f3054p.get(i2)).intValue()) {
                        i5 = i8;
                        break;
                    }
                }
                i8++;
            }
        }
        if (i2 >= this.f3054p.size()) {
            Log.w(this.f3040b, "[NativeTS] select program index(" + i2 + ") is invalid!");
            return;
        }
        Log.i(this.f3040b, "[NativeTS] program(" + this.f3054p.get(i2) + "), videoTrackIndex(" + i4 + "), audioTrackIndex(" + i5 + ")");
        if ("1".equals(D.y("vendor.mtk.auto_test", HttpUrl.FRAGMENT_ENCODE_SET)) && w(2) > 0) {
            K(2, 0);
        }
        if (this.f3055q >= 0) {
            seekTo(0);
        }
        this.f3055q = i2;
    }

    public void D() {
        this.f3049k.removeCallbacksAndMessages(null);
        this.f3050l.quit();
        this.f3042d.clear();
        this.f3047i = null;
    }

    public void F(a aVar) {
        this.f3047i = aVar;
    }

    public void G(String str) {
        n.x xVarB;
        if (this.f3044f[2] == -1 || !u(2) || (xVarB = this.f3041c.b(2, this.f3044f[2])) == null) {
            return;
        }
        if (xVarB.f5842g.startsWith("text/ext/srt") || xVarB.f5842g.equals("text/ext/ssa") || xVarB.f5842g.startsWith("text/ext/ass") || xVarB.f5842g.equals("text/ext/sub") || xVarB.f5842g.equals("text/sub") || xVarB.f5842g.startsWith("application/x-subrip") || xVarB.f5842g.equals("text/ext/txt") || xVarB.f5842g.equals("text/txt") || xVarB.f5842g.startsWith("text/vtt") || xVarB.f5842g.equals("text/ext/smi") || xVarB.f5842g.equals("text/smi")) {
            this.f3041c.i(2, -1);
            this.f3041c.q(this.f3043e[2], 1003, str);
            this.f3041c.i(2, this.f3044f[2]);
        }
    }

    public void H(PlaybackParams playbackParams) {
        G[] gArr;
        G g2;
        Log.i(this.f3040b, "setPlaybackRate " + playbackParams.getSpeed());
        int i2 = this.f3052n;
        if (i2 != -1 && i2 != 5) {
            throw new UnsupportedOperationException("In trick Mode,not be allowed to set playbackRate !");
        }
        this.f3035A = playbackParams;
        if (A(1.0f) && this.f3052n == -1) {
            return;
        }
        this.f3051m = A(1.0f) ? -1 : 5;
        if (!A(0.0f) && (gArr = this.f3043e) != null && (g2 = gArr[1]) != null && (g2 instanceof n.q)) {
            this.f3041c.q(g2, 2, this.f3035A);
        }
        this.f3052n = this.f3051m;
    }

    public void I(int i2, boolean z2) {
        if (z2) {
            this.f3041c.i(i2, this.f3044f[i2]);
        } else {
            this.f3041c.i(i2, -1);
        }
        Iterator it = this.f3042d.iterator();
        while (it.hasNext()) {
            ((b) it.next()).onTrackStateChanged(i2, this.f3044f[i2], z2);
        }
    }

    public void J(int i2) {
        G g2;
        this.f3063y = i2;
        Log.d(this.f3040b, "setSeamlessMode " + this.f3063y);
        G[] gArr = this.f3043e;
        if (gArr == null || (g2 = gArr[0]) == null || !(g2 instanceof n.w)) {
            return;
        }
        this.f3041c.q(g2, InvokeCmd.CMD_PROJECT_ID_GET_INDEX, Integer.valueOf(this.f3063y));
    }

    public void K(int i2, int i3) {
        o.d(this.f3040b, "setSelectedTrack called, rendererType: " + i2 + ", trackIndex: " + i3, 1);
        int i4 = this.f3051m;
        if (i4 == -1 || i4 == 5) {
            this.f3041c.i(i2, i3);
            this.f3044f[i2] = i3;
            Iterator it = this.f3042d.iterator();
            while (it.hasNext()) {
                ((b) it.next()).onTrackStateChanged(i2, i3, i3 != -1);
            }
            return;
        }
        o.d(this.f3040b, "tricking, just remember the selected track index:" + i3, 1);
        this.f3044f[i2] = i3;
    }

    public void L(c cVar) {
        this.f3045g = cVar;
    }

    public void N(Bundle bundle) {
        G g2;
        this.f3036B = new Bundle(bundle);
        Log.d(this.f3040b, "setVendCmd");
        G[] gArr = this.f3043e;
        if (gArr == null || (g2 = gArr[0]) == null || !(g2 instanceof n.w)) {
            return;
        }
        this.f3041c.q(g2, InvokeCmd.CMD_PROJECT_ID_IS_SUPPORT, bundle);
    }

    public void P(String str) {
        G[] gArr = this.f3043e;
        if (gArr == null || gArr[0] == null || str == null) {
            Log.i(this.f3040b, "Video renderer is null, output selection is invalid!");
            return;
        }
        if (!"OUTPUT_VIDEO_MAIN".equals(str) && !"OUTPUT_VIDEO_SUB".equals(str) && !"OUTPUT_GRAPHIC".equals(str)) {
            throw new UnsupportedOperationException("Unsupported output selection: " + str);
        }
        Log.i(this.f3040b, "setVideoOutput device is " + str);
        Bundle bundle = new Bundle();
        bundle.putString("X-tv-output-path", str);
        this.f3041c.q(this.f3043e[0], 1001, bundle);
    }

    public void Q(float f2) {
        this.f3041c.q(this.f3043e[1], 1, Float.valueOf(f2));
    }

    public void R(int i2) {
        int iH;
        o.d(this.f3040b, "trick called, speed: " + i2, 1);
        if (this.f3052n == 5) {
            throw new UnsupportedOperationException("In playbackRate Mode,not be allowed to set trick mode !");
        }
        if (b()) {
            switch (i2) {
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                case 12:
                case 13:
                case 14:
                    if (this.f3051m != 0) {
                        this.f3051m = 0;
                        this.f3046h = i2;
                        this.f3062x = SystemClock.elapsedRealtime();
                        seekTo(i(i2));
                        return;
                    }
                    this.f3046h = i2;
                    break;
                    break;
                default:
                    return;
            }
        } else {
            G g2 = this.f3043e[0];
            if (g2 != null && (((iH = g2.h()) != 16 || this.f3039E) && iH == 0)) {
                return;
            }
        }
        Log.i(this.f3040b, "set trick, speed is " + i2 + "  trick is " + this.f3051m);
        switch (i2) {
            case 2:
                this.f3051m = 1;
                if (this.f3041c.getPlayWhenReady()) {
                    this.f3041c.setPlayWhenReady(false);
                }
                I(1, false);
                I(2, false);
                if (n.c()) {
                    this.f3041c.f(i2, 0, this.f3051m);
                    Log.d(this.f3040b, "[C2Param] Set Step");
                    Bundle bundle = new Bundle();
                    bundle.putString("vendor.mtk-codec2.trick", "step");
                    O(i2, PointerIconCompat.TYPE_NO_DROP, bundle);
                } else if (n.d()) {
                    M(i2, this.f3051m);
                }
                if (this.f3052n == 2) {
                    E(i2);
                }
                this.f3046h = i2;
                break;
            case 3:
            default:
                Log.i(this.f3040b, "speed is not handled in here !");
                break;
            case 4:
                this.f3051m = 3;
                if (this.f3052n != 0) {
                    if (!this.f3041c.getPlayWhenReady()) {
                        this.f3041c.setPlayWhenReady(true);
                    }
                    I(1, false);
                    I(2, false);
                    if (n.c()) {
                        this.f3041c.f(i2, 0, this.f3051m);
                        Bundle bundle2 = new Bundle();
                        if (this.f3038D == "pause") {
                            Log.i(this.f3040b, "[C2Param] lastC2Status[pause] -> 2X resume C2");
                            bundle2.putString("vendor.mtk-codec2.trick", "resume");
                        }
                        bundle2.putFloat("vendor.mtk-codec2.set-speed", 2.0f);
                        O(i2, PointerIconCompat.TYPE_NO_DROP, bundle2);
                        Log.d(this.f3040b, "[C2Param] 1X -> 2X set speed[" + i2 + "]");
                    } else if (n.d()) {
                        M(i2, this.f3051m);
                    }
                }
                this.f3046h = i2;
                if (this.f3059u) {
                    this.f3059u = false;
                    Log.i(this.f3040b, "set trick trickInSeekToPlay false");
                }
                if (this.f3061w) {
                    this.f3061w = false;
                    Log.i(this.f3040b, "set trick trickInSeekToPause false");
                }
                break;
            case 5:
            case 6:
            case 7:
            case 8:
                if (this.f3059u) {
                    this.f3059u = false;
                    Log.i(this.f3040b, "set trick trickInSeekToPlay false");
                }
                if (this.f3061w) {
                    this.f3061w = false;
                    Log.i(this.f3040b, "set trick trickInSeekToPause false");
                }
                this.f3051m = 0;
                if (this.f3046h < 5 || this.f3046h > 7) {
                    if (this.f3041c.getPlayWhenReady()) {
                        this.f3041c.setPlayWhenReady(false);
                    }
                    if (n.c()) {
                        Log.d(this.f3040b, "[C2Param] prevSpeed[" + this.f3046h + "] --> Speed[" + i2 + "] Pause C2, reset Speed");
                        Bundle bundle3 = new Bundle();
                        bundle3.putString("vendor.mtk-codec2.trick", "pause");
                        bundle3.putFloat("vendor.mtk-codec2.set-speed", 1.0f);
                        O(i2, PointerIconCompat.TYPE_NO_DROP, bundle3);
                    }
                    this.f3046h = i2;
                    I(1, false);
                    I(2, false);
                    M(i2, this.f3051m);
                    this.f3062x = SystemClock.elapsedRealtime();
                    seekTo(i(i2));
                } else {
                    this.f3046h = i2;
                    M(i2, this.f3051m);
                }
                break;
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
                if (this.f3059u) {
                    this.f3059u = false;
                    Log.i(this.f3040b, "set trick trickInSeekToPlay false");
                }
                if (this.f3061w) {
                    this.f3061w = false;
                    Log.i(this.f3040b, "set trick trickInSeekToPause false");
                }
                int i3 = i(i2);
                if (i3 == getCurrentPosition() || i3 == Integer.MIN_VALUE) {
                    Log.i(this.f3040b, "because of same position or invalid next position!!!");
                    if (i3 == 0 || i3 == Integer.MIN_VALUE) {
                        for (b bVar : this.f3042d) {
                            Log.i(this.f3040b, "notify TRICK_TO_START!");
                            bVar.onTrickEnded(i2, 0);
                        }
                    }
                } else if (this.f3046h < 9 || this.f3046h > 13) {
                    if (this.f3050l.getState() == Thread.State.TIMED_WAITING && this.f3046h >= 5 && this.f3046h <= 8) {
                        this.f3050l.interrupt();
                    }
                    Log.i(this.f3040b, "nextPosition=" + i3);
                    if (this.f3041c.getPlayWhenReady() && i3 != 0) {
                        this.f3041c.setPlayWhenReady(false);
                    }
                    if (n.c()) {
                        Log.d(this.f3040b, "[C2Param] prevSpeed[" + this.f3046h + "] --> Speed[" + i2 + "] Pause C2, reset C2 speed");
                        Bundle bundle4 = new Bundle();
                        bundle4.putString("vendor.mtk-codec2.trick", "pause");
                        bundle4.putFloat("vendor.mtk-codec2.set-speed", 1.0f);
                        O(i2, PointerIconCompat.TYPE_NO_DROP, bundle4);
                    }
                    this.f3046h = i2;
                    this.f3051m = 0;
                    if (i3 != 0) {
                        I(1, false);
                        I(2, false);
                    }
                    M(i2, this.f3051m);
                    this.f3062x = SystemClock.elapsedRealtime();
                    seekTo(i3);
                    if (i3 == 0) {
                        this.f3060v = true;
                        for (b bVar2 : this.f3042d) {
                            Log.i(this.f3040b, "seek for zero, notify TRICK_TO_START!");
                            bVar2.onTrickEnded(i2, 0);
                        }
                    }
                } else {
                    this.f3046h = i2;
                    this.f3051m = 0;
                    M(i2, 0);
                }
                break;
            case 15:
            case 16:
            case 17:
            case 18:
            case 19:
                if (!this.f3041c.getPlayWhenReady()) {
                    this.f3041c.setPlayWhenReady(true);
                }
                float f2 = i2 == 15 ? 0.5f : 1.0f;
                this.f3041c.i(1, -1);
                this.f3041c.i(2, -1);
                if (this.f3052n == 2) {
                    M(2, this.f3051m);
                    E(2);
                }
                this.f3051m = 4;
                if (n.c()) {
                    Bundle bundle5 = new Bundle();
                    bundle5.putFloat("vendor.mtk-codec2.set-speed", f2);
                    O(i2, PointerIconCompat.TYPE_NO_DROP, bundle5);
                    Log.d(this.f3040b, "[C2Param] SF set speed[" + i2 + "], codec2Speed=" + f2);
                } else if (n.d()) {
                    M(i2, this.f3051m);
                }
                this.f3046h = i2;
                break;
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
                if (this.f3041c.getPlayWhenReady()) {
                    this.f3041c.setPlayWhenReady(false);
                }
                this.f3046h = i2;
                this.f3051m = 0;
                I(1, false);
                I(2, false);
                M(i2, this.f3051m);
                if (n.c()) {
                    Log.d(this.f3040b, "[C2Param] prevSpeed[" + this.f3046h + "] --> Speed[" + i2 + "] Pause C2");
                    Bundle bundle6 = new Bundle();
                    bundle6.putString("vendor.mtk-codec2.trick", "pause");
                    O(i2, PointerIconCompat.TYPE_NO_DROP, bundle6);
                }
                seekTo(i(i2));
                break;
        }
        this.f3052n = this.f3051m;
    }

    public void S(int i2) {
        G g2;
        this.f3064z = i2;
        Log.d(this.f3040b, "mSetVideoDegree " + this.f3064z);
        G[] gArr = this.f3043e;
        if (gArr == null || (g2 = gArr[0]) == null || !(g2 instanceof n.w)) {
            return;
        }
        this.f3041c.q(g2, 1009, Integer.valueOf(this.f3064z));
    }

    public void T(G[] gArr) {
        if (n.c()) {
            c(gArr);
        } else if (n.d()) {
            C(gArr);
        }
    }

    public boolean U() {
        G g2 = this.f3043e[1];
        return g2 == null || (g2 instanceof C0642h) || this.f3041c.e(1) == 0;
    }

    public void a(b bVar) {
        this.f3042d.add(bVar);
    }

    public boolean b() {
        G g2 = this.f3043e[0];
        return g2 == null || (g2 instanceof C0642h) || this.f3041c.e(0) == 0 || (!u(0) && u(1));
    }

    @Override // n.w.f
    public void d() {
        this.f3048j = true;
        o.d(this.f3040b, "onRenderFirstFrame trickMode is " + this.f3051m + "State is " + this.f3041c.getPlaybackState(), 1);
        if (this.f3046h != 1) {
            int i2 = this.f3051m;
            if (i2 == 0 || i2 == 3) {
                this.f3049k.sendEmptyMessage(1);
            }
        }
    }

    public int f() {
        return this.f3046h;
    }

    public int h() {
        G g2;
        G[] gArr = this.f3043e;
        if (gArr != null && (g2 = gArr[0]) != null && !(g2 instanceof C0642h)) {
            return ((n.w) g2).y1();
        }
        Log.i(this.f3040b, "Video renderer is null, IsFilmmaker is invalid!");
        return -1;
    }

    @Override // android.os.Handler.Callback
    public boolean handleMessage(Message message) {
        if (message.what != 1) {
            return false;
        }
        E(this.f3046h);
        return true;
    }

    @Override // n.j.c
    public void j(boolean z2, int i2) {
        int i3;
        o.d(this.f3040b, "onPlayerStateChanged trickMode is " + this.f3051m + "State is " + i2, 1);
        if (this.f3043e == null) {
            Log.e(this.f3040b, "renders has not built, onPlayerStateChanged do nothing");
            return;
        }
        if (i2 == 4 && this.f3046h != 1 && this.f3053o != 4 && ((this.f3048j || (b() && this.f3057s)) && (((i3 = this.f3051m) == 0 || i3 == 3) && this.f3048j))) {
            this.f3048j = false;
        }
        int i4 = this.f3053o;
        if ((i4 == 1 || i4 == 2) && (i2 == 3 || i2 == 4 || i2 == 5)) {
            Iterator it = this.f3042d.iterator();
            while (it.hasNext()) {
                ((b) it.next()).onPrepared();
            }
        }
        if (i2 == 4) {
            o.d(this.f3040b, "EXO_PLAY_PASS", 32);
            if ("1".equals(D.y("vendor.mtk.auto_test", HttpUrl.FRAGMENT_ENCODE_SET))) {
                Log.d(this.f3040b, "EXO_PLAY_PASS");
            }
            if (this.f3057s) {
                this.f3057s = false;
                o.d(this.f3040b, "EXO_SEEK_PASS", 32);
            }
            if (b()) {
                o.d(this.f3040b, "EXO_AUDIO_ONLY_PASS", 32);
            }
        }
        this.f3053o = i2;
    }

    @Override // n.w.f
    public void k(Surface surface) {
    }

    @Override // n.t.g
    public void l(t.f fVar) {
    }

    @Override // n.j.c
    public void m(C0643i c0643i) {
    }

    @Override // n.t.g
    public void n(String str, long j2) {
    }

    public List o() {
        return this.f3054p;
    }

    @Override // I.l
    public void onCues(List list) {
        if (this.f3047i != null) {
            if ((this.f3044f[2] == -1 || !u(2)) && (this.f3044f[5] == -1 || !u(5))) {
                this.f3047i.onCues(Collections.emptyList());
                return;
            }
            this.f3047i.onCues(list);
            if (this.f3058t) {
                return;
            }
            this.f3058t = true;
            o.d(this.f3040b, "EXO_SUBTITLE_PASS", 32);
        }
    }

    @Override // n.t.g
    public void onDecoderInitialized(String str, long j2, long j3) {
    }

    @Override // n.w.f
    public void onDroppedFrames(int i2, long j2) {
    }

    @Override // n.w.f
    public void onRenderFrameJiffies(long j2, long j3) {
    }

    @Override // n.w.f
    public void onVideoSizeChanged(int i2, int i3, int i4, float f2, q qVar) {
    }

    @Override // n.j.c
    public void p() {
    }

    @Override // b0.v, android.widget.MediaController.MediaPlayerControl
    public void pause() {
        o.d(this.f3040b, "pause called", 1);
        if (n.e() && this.f3046h != 1) {
            this.f3046h = 1;
            Log.d(this.f3040b, "hbbtv pause c2.");
            Bundle bundle = new Bundle();
            bundle.putString("vendor.mtk-codec2.trick", "pause");
            O(this.f3046h, PointerIconCompat.TYPE_NO_DROP, bundle);
            return;
        }
        if (this.f3051m == 0 && !this.f3061w) {
            this.f3061w = true;
            if (this.f3059u) {
                this.f3059u = false;
                return;
            }
            return;
        }
        super.pause();
        int i2 = this.f3046h;
        if (this.f3046h != 1) {
            this.f3046h = 1;
            M(this.f3046h, -1);
        }
        c cVar = this.f3045g;
        if (cVar != null) {
            cVar.a();
        }
        if (this.f3051m == 0 && !U()) {
            Log.d(this.f3040b, "pause and setRendererEnabled true");
            I(1, true);
        }
        if (n.c() && this.f3041c.o() && (U() || i2 == 4 || this.f3041c.l())) {
            Log.d(this.f3040b, "[C2Param]video Only or lastSpeed[" + i2 + "] == FF_2X, pause C2");
            Bundle bundle2 = new Bundle();
            bundle2.putString("vendor.mtk-codec2.trick", "pause");
            O(this.f3046h, PointerIconCompat.TYPE_NO_DROP, bundle2);
        }
        if (n.d() && U() && this.f3041c.o() && this.f3051m == -1) {
            this.f3041c.q(this.f3043e[0], 1008, 1);
        }
        this.f3051m = -1;
        this.f3052n = -1;
    }

    @Override // n.t.g
    public void q(MediaCodec.CryptoException cryptoException) {
    }

    @Override // android.widget.MediaController.MediaPlayerControl
    public void seekTo(int i2) {
        long jMin = this.f3041c.getDuration() == -1 ? 0L : Math.min(Math.max(0, i2), getDuration());
        o.d(this.f3040b, "seekTo called, seekPosition(Ms): " + jMin, 1);
        o.d(this.f3040b, "[Performance]seekTo:" + i2 + "(ms)", 32);
        this.f3048j = false;
        if (this.f3046h == 2 || this.f3046h == 1) {
            this.f3046h = 1;
            if (n.c()) {
                this.f3041c.f(this.f3046h, 0, -1);
                Log.d(this.f3040b, "[C2Param]: speed[" + this.f3046h + "] --> seekTo, Pause C2");
                Bundle bundle = new Bundle();
                bundle.putString("vendor.mtk-codec2.trick", "pause");
                O(this.f3046h, PointerIconCompat.TYPE_NO_DROP, bundle);
            } else if (n.d()) {
                M(this.f3046h, -1);
            }
        }
        this.f3041c.seekTo(jMin);
        this.f3057s = true;
    }

    @Override // b0.v, android.widget.MediaController.MediaPlayerControl
    public void start() {
        c cVar;
        o.d(this.f3040b, "start called", 1);
        if (n.e()) {
            if (this.f3051m == 0) {
                this.f3051m = -1;
                this.f3041c.f(3, 0, -1);
                if (!this.f3041c.getPlayWhenReady()) {
                    this.f3041c.setPlayWhenReady(true);
                }
            }
            Bundle bundle = new Bundle();
            if (this.f3046h != 3) {
                if (this.f3043e[1] != null && (!u(1) || t(1))) {
                    I(1, true);
                }
                if (this.f3043e[2] != null && (!u(2) || t(2))) {
                    I(2, true);
                }
                bundle.putFloat("vendor.mtk-codec2.set-speed", 1.0f);
            }
            this.f3046h = 3;
            Log.d(this.f3040b, "hbbtv resume c2 start.");
            bundle.putString("vendor.mtk-codec2.trick", "resume");
            O(this.f3046h, PointerIconCompat.TYPE_NO_DROP, bundle);
            return;
        }
        if (this.f3046h == 1 && (cVar = this.f3045g) != null) {
            cVar.b(this.f3041c.getCurrentPosition());
        }
        o.d(this.f3040b, "trickMode=" + this.f3051m + ",trickInSeekToPlay=" + this.f3059u + ",speed=" + this.f3046h, 1);
        if (this.f3051m == 0 && !this.f3059u && !this.f3060v) {
            this.f3059u = true;
            if (this.f3061w) {
                this.f3061w = false;
            }
            if (this.f3050l.getState() == Thread.State.TIMED_WAITING) {
                this.f3050l.interrupt();
                return;
            }
            return;
        }
        if (this.f3060v) {
            this.f3060v = false;
        }
        if (this.f3043e == null) {
            Log.e(this.f3040b, "There is no valid renders!");
            return;
        }
        if (this.f3046h != 3) {
            int i2 = this.f3046h;
            this.f3046h = 3;
            if (n.c()) {
                this.f3041c.f(this.f3046h, 0, -1);
                if (i2 != 1 || this.f3037C == 2.0f) {
                    Bundle bundle2 = new Bundle();
                    if (i2 != 1) {
                        bundle2.putString("vendor.mtk-codec2.trick", "start-from-video");
                        Log.d(this.f3040b, "[C2Param] prevSpeed[" + i2 + "] --> 1X set start-from-video");
                    }
                    if (this.f3037C == 2.0f) {
                        Log.d(this.f3040b, "[C2Param] lastC2Speed[2X] --> 1X set speed 1.0");
                        bundle2.putFloat("vendor.mtk-codec2.set-speed", 1.0f);
                    }
                    O(this.f3046h, PointerIconCompat.TYPE_NO_DROP, bundle2);
                }
            } else if (n.d()) {
                M(this.f3046h, -1);
            }
            int i3 = this.f3051m;
            if (i3 == 2 || i3 == 4) {
                E(3);
            }
            if (this.f3043e[1] != null && (!u(1) || t(1))) {
                I(1, true);
            }
            if (this.f3043e[2] != null && (!u(2) || t(2))) {
                I(2, true);
            }
            if (n.c() && this.f3038D == "pause") {
                Log.d(this.f3040b, "[C2Param] prevSpeed[" + i2 + "] --> 1X set resume to C2");
                Bundle bundle3 = new Bundle();
                bundle3.putString("vendor.mtk-codec2.trick", "resume");
                O(this.f3046h, PointerIconCompat.TYPE_NO_DROP, bundle3);
            }
            this.f3051m = -1;
            this.f3052n = -1;
        }
        if (U() && this.f3041c.o() && this.f3051m == -1 && n.d()) {
            this.f3041c.q(this.f3043e[0], 1008, 3);
        }
        super.start();
    }

    public boolean t(int i2) {
        return this.f3044f[i2] != this.f3041c.m(i2);
    }

    public boolean u(int i2) {
        return this.f3041c.m(i2) >= 0;
    }

    public int v(int i2) {
        if (this.f3051m == -1) {
            if (w(i2) == 0) {
                return -1;
            }
            return this.f3041c.m(i2);
        }
        int i3 = this.f3044f[i2];
        o.d(this.f3040b, "tricking, return the remembered selected track index:" + i3, 1);
        return i3;
    }

    public int w(int i2) {
        return this.f3041c.e(i2);
    }

    public n.x x(int i2, int i3) {
        return this.f3041c.b(i2, i3);
    }

    public int y() {
        return this.f3041c.a();
    }

    public int z() {
        G g2;
        G[] gArr = this.f3043e;
        if (gArr != null && (g2 = gArr[0]) != null) {
            return ((n.w) g2).A1();
        }
        Log.i(this.f3040b, "Video renderer is null, unique stream id is invalid!");
        return -1;
    }
}
