package com.ss.android.medialib.photomovie;

import X.8XX;
import X.C0347IDi;
import X.C0445IHc;
import X.C0446IHd;
import X.C0449IHg;
import X.C0450IHh;
import android.content.Context;
import android.os.Looper;
import android.view.Surface;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.nio.ByteBuffer;

public final class PhotoMovie implements C0449IHg {
    public static final String TAG = PhotoMovie.class.getSimpleName();
    public static C0450IHh mPhotoMovieListener;
    public static volatile PhotoMovie mSingleton = null;
    public C0445IHc mAVCEncoderMark;

    public interface ProgressCallback {
        static {
            Covode.recordClassIndex(48575);
        }

        void onProgress(int i);
    }

    public static native int nativeSynthetise(String[] strArr, String str, String str2, String[] strArr2, String[] strArr3, int[] iArr, int i, String str3, String str4, float f, int i2, int i3, int i4, ProgressCallback progressCallback);

    private native void onWriteFile(byte[] bArr, int i, int i2, int i3, int i4);

    private native int setCodecConfig(byte[] bArr, int i);

    private native int setColorFormat(int i);

    private native int setHardEncoderMarkStatus(boolean z);

    public static native void setMarkParams(String[] strArr, String str, boolean z, int i, int i2, int i3, int i4, int i5, int i6);

    private native void swapGlBuffer();

    public final void onInitMarkHardEncoderRet(int i) {
    }

    public final void onMarkEncoderData(ByteBuffer byteBuffer, int i, boolean z) {
    }

    public final void onMarkEncoderData(byte[] bArr, int i, boolean z) {
    }

    public PhotoMovie() {
        mSingleton = this;
    }

    public static void onNativeCallback_UninitMarkHardEncoder() {
        if (mSingleton != null) {
            mSingleton.onUninitMarkHardEncoder();
        }
    }

    public final void onMarkSwapGlBuffers() {
        MethodCollector.i(18527);
        swapGlBuffer();
        MethodCollector.o(18527);
    }

    static {
        Covode.recordClassIndex(48574);
        8XX.LIZLLL();
    }

    /*  JADX ERROR: IndexOutOfBoundsException in pass: RegionMakerVisitor
        java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        	at java.util.ArrayList.rangeCheck(ArrayList.java:659)
        	at java.util.ArrayList.get(ArrayList.java:435)
        	at jadx.core.dex.nodes.InsnNode.getArg(InsnNode.java:101)
        	at jadx.core.dex.visitors.regions.RegionMaker.traverseMonitorExits(RegionMaker.java:611)
        	at jadx.core.dex.visitors.regions.RegionMaker.traverseMonitorExits(RegionMaker.java:619)
        	at jadx.core.dex.visitors.regions.RegionMaker.traverseMonitorExits(RegionMaker.java:619)
        	at jadx.core.dex.visitors.regions.RegionMaker.traverseMonitorExits(RegionMaker.java:619)
        	at jadx.core.dex.visitors.regions.RegionMaker.traverseMonitorExits(RegionMaker.java:619)
        	at jadx.core.dex.visitors.regions.RegionMaker.traverseMonitorExits(RegionMaker.java:619)
        	at jadx.core.dex.visitors.regions.RegionMaker.processMonitorEnter(RegionMaker.java:561)
        	at jadx.core.dex.visitors.regions.RegionMaker.traverse(RegionMaker.java:133)
        	at jadx.core.dex.visitors.regions.RegionMaker.makeRegion(RegionMaker.java:86)
        	at jadx.core.dex.visitors.regions.RegionMaker.processIf(RegionMaker.java:693)
        	at jadx.core.dex.visitors.regions.RegionMaker.traverse(RegionMaker.java:123)
        	at jadx.core.dex.visitors.regions.RegionMaker.makeRegion(RegionMaker.java:86)
        	at jadx.core.dex.visitors.regions.RegionMaker.processMonitorEnter(RegionMaker.java:598)
        	at jadx.core.dex.visitors.regions.RegionMaker.traverse(RegionMaker.java:133)
        	at jadx.core.dex.visitors.regions.RegionMaker.makeRegion(RegionMaker.java:86)
        	at jadx.core.dex.visitors.regions.RegionMakerVisitor.visit(RegionMakerVisitor.java:49)
        */
    public static com.ss.android.medialib.photomovie.PhotoMovie getInstance() {
        /*
            java.lang.Class<com.ss.android.medialib.photomovie.PhotoMovie> r2 = com.ss.android.medialib.photomovie.PhotoMovie.class
            r1 = 16626(0x40f2, float:2.3298E-41)
            com.bytedance.frameworks.apm.trace.MethodCollector.i(r1)
            monitor-enter(r2)
            com.ss.android.medialib.photomovie.PhotoMovie r0 = mSingleton     // Catch:{ all -> 0x0027 }
            if (r0 != 0) goto L_0x0020
            monitor-enter(r2)     // Catch:{ all -> 0x0027 }
            com.ss.android.medialib.photomovie.PhotoMovie r0 = mSingleton     // Catch:{ all -> 0x001a }
            if (r0 != 0) goto L_0x0018
            com.ss.android.medialib.photomovie.PhotoMovie r0 = new com.ss.android.medialib.photomovie.PhotoMovie     // Catch:{ all -> 0x001a }
            r0.<init>()     // Catch:{ all -> 0x001a }
            mSingleton = r0     // Catch:{ all -> 0x001a }
        L_0x0018:
            monitor-exit(r2)     // Catch:{ all -> 0x001a }
            goto L_0x0020
        L_0x001a:
            r0 = move-exception
            monitor-exit(r2)     // Catch:{ all -> 0x0027 }
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r1)     // Catch:{ all -> 0x0027 }
            throw r0     // Catch:{ all -> 0x0027 }
        L_0x0020:
            monitor-exit(r2)     // Catch:{ all -> 0x0027 }
            com.ss.android.medialib.photomovie.PhotoMovie r0 = mSingleton
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r1)
            return r0
        L_0x0027:
            r0 = move-exception
            monitor-exit(r2)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r1)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.medialib.photomovie.PhotoMovie.getInstance():com.ss.android.medialib.photomovie.PhotoMovie");
    }

    /* JADX WARNING: Can't wrap try/catch for region: R(4:12|13|14|15) */
    /* JADX WARNING: Code restructure failed: missing block: B:24:0x0040, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:26:0x0042, code lost:
        com.bytedance.frameworks.apm.trace.MethodCollector.o(18525);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:27:0x0045, code lost:
        throw r0;
     */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:14:0x0027 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:18:0x0033 */
    /* JADX WARNING: Removed duplicated region for block: B:21:0x0039 A[Catch:{ all -> 0x0040 }] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void onUninitMarkHardEncoder() {
        /*
            r5 = this;
            r4 = 18525(0x485d, float:2.5959E-41)
            com.bytedance.frameworks.apm.trace.MethodCollector.i(r4)
            java.lang.String r1 = TAG
            java.lang.String r0 = "onUninitMarkHardEncoder == enter"
            X.C0347IDi.LIZ(r1, r0)
            X.IHc r3 = r5.mAVCEncoderMark
            if (r3 == 0) goto L_0x004f
            monitor-enter(r3)
            int r0 = r3.LJII     // Catch:{ all -> 0x0040 }
            r2 = 0
            if (r0 == 0) goto L_0x001a
            android.media.MediaCodec r0 = r3.LJ     // Catch:{ all -> 0x0040 }
            if (r0 != 0) goto L_0x001c
        L_0x001a:
            monitor-exit(r3)     // Catch:{ all -> 0x0040 }
            goto L_0x0046
        L_0x001c:
            int r1 = r3.LJII     // Catch:{ all -> 0x0040 }
            r0 = 2
            if (r1 != r0) goto L_0x002e
            android.media.MediaCodec r0 = r3.LJ     // Catch:{ Exception -> 0x0027 }
            r0.stop()     // Catch:{ Exception -> 0x0027 }
            goto L_0x002e
        L_0x0027:
            java.lang.String r1 = X.C0445IHc.LIZ     // Catch:{ all -> 0x0040 }
            java.lang.String r0 = "MediaCodec Exception"
            X.C0347IDi.LIZLLL(r1, r0)     // Catch:{ all -> 0x0040 }
        L_0x002e:
            android.media.MediaCodec r0 = r3.LJ     // Catch:{ Exception -> 0x0033 }
            r0.release()     // Catch:{ Exception -> 0x0033 }
        L_0x0033:
            r3.LJ = r2     // Catch:{ all -> 0x0040 }
            android.view.Surface r0 = r3.LJFF     // Catch:{ all -> 0x0040 }
            if (r0 == 0) goto L_0x003e
            android.view.Surface r0 = r3.LJFF     // Catch:{ all -> 0x0040 }
            r0.release()     // Catch:{ all -> 0x0040 }
        L_0x003e:
            monitor-exit(r3)     // Catch:{ all -> 0x0040 }
            goto L_0x0046
        L_0x0040:
            r0 = move-exception
            monitor-exit(r3)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r4)
            throw r0
        L_0x0046:
            r5.mAVCEncoderMark = r2
            java.lang.String r1 = TAG
            java.lang.String r0 = "====== uninitAVCEncoder ======"
            X.C0347IDi.LIZ(r1, r0)
        L_0x004f:
            java.lang.String r1 = TAG
            java.lang.String r0 = "onUninitMarkHardEncoder == exit"
            X.C0347IDi.LIZ(r1, r0)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r4)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.medialib.photomovie.PhotoMovie.onUninitMarkHardEncoder():void");
    }

    public static void setPhotoMovieListener(C0450IHh iHh) {
        mPhotoMovieListener = iHh;
    }

    public static PhotoMoviePlayer createPlayer(Context context) {
        return new PhotoMoviePlayer(context);
    }

    public static int calulateDuration(C0446IHd iHd) {
        if (iHd.LIZ.length == 0) {
            return 0;
        }
        return (iHd.LIZ.length * 2500) - 500;
    }

    public static void onNativeCallback_InitMarkHardEncoderRet(int i) {
        if (mSingleton != null) {
            mSingleton.onInitMarkHardEncoderRet(i);
        }
    }

    public final void onMarkSetCodecConfig(byte[] bArr) {
        MethodCollector.i(18528);
        setCodecConfig(bArr, bArr.length);
        MethodCollector.o(18528);
    }

    public final void setColorFormatMark(int i) {
        MethodCollector.i(18482);
        setColorFormat(i);
        MethodCollector.o(18482);
    }

    public final int synthetise(C0446IHd iHd) {
        MethodCollector.i(16780);
        if (Looper.myLooper() != Looper.getMainLooper()) {
            C0446IHd iHd2 = iHd;
            int nativeSynthetise = nativeSynthetise(iHd2.LIZ, iHd2.LIZIZ, iHd2.LIZJ, iHd2.LIZLLL, iHd2.LJ, iHd2.LJFF, iHd2.LJI, iHd2.LJII, iHd2.LJIIIIZZ, iHd2.LJIIIZ, iHd2.LJIIJ.LIZ, iHd2.LJIIJ.LIZIZ, iHd2.LJIIJ.LIZJ, iHd2.LJIIJJI);
            MethodCollector.o(16780);
            return nativeSynthetise;
        }
        IllegalStateException illegalStateException = new IllegalStateException("Don't synthetise photomovie in main thread");
        MethodCollector.o(16780);
        throw illegalStateException;
    }

    public final void onMarkWriteFile(byte[] bArr, int i, int i2, int i3) {
        MethodCollector.i(18526);
        byte[] bArr2 = bArr;
        onWriteFile(bArr2, bArr2.length, i, i2, i3);
        C0347IDi.LIZIZ(TAG, "onEncoderData: ...");
        MethodCollector.o(18526);
    }

    public static int onNativeCallback_MarkencodeTexture(int i, int i2, int i3, int i4, boolean z) {
        if (mSingleton != null) {
            return mSingleton.onMarkEncodeData(i, i2, i3, i4, z);
        }
        return 0;
    }

    public final Surface onInitMarkHardEncoder(int i, int i2, int i3, int i4, boolean z) {
        return onInitMarkHardEncoder(i, i2, i3, 1, 1, i4, z);
    }

    public final int onMarkEncodeData(int i, int i2, int i3, int i4, boolean z) {
        C0445IHc iHc = this.mAVCEncoderMark;
        if (iHc == null) {
            return 0;
        }
        return iHc.LIZ(i, i2, i3, i4, z);
    }

    public final int onMarkEncoderData(int i, int i2, int i3, int i4, boolean z) {
        C0445IHc iHc = this.mAVCEncoderMark;
        if (iHc == null) {
            return 0;
        }
        return iHc.LIZ(i, i2, i3, i4, z);
    }

    public static Surface onNativeCallback_InitMarkHardEncoder(int i, int i2, int i3, int i4, int i5, boolean z) {
        if (mSingleton != null) {
            return mSingleton.onInitMarkHardEncoder(i, i2, i3, i4, i5, z);
        }
        return null;
    }

    public final Surface onInitMarkHardEncoder(int i, int i2, int i3, int i4, int i5, boolean z) {
        MethodCollector.i(17016);
        if (this.mAVCEncoderMark == null) {
            this.mAVCEncoderMark = new C0445IHc();
        }
        C0445IHc.LIZIZ = this;
        Surface LIZ = this.mAVCEncoderMark.LIZ(i, i2, i3, z);
        if (LIZ == null) {
            this.mAVCEncoderMark = null;
            setHardEncoderMarkStatus(false);
            MethodCollector.o(17016);
            return null;
        }
        C0347IDi.LIZ(TAG, "====== initAVCEncoder succeed ======");
        setHardEncoderMarkStatus(true);
        MethodCollector.o(17016);
        return LIZ;
    }

    public final Surface onInitMarkHardEncoder(int i, int i2, int i3, int i4, int i5, int i6, boolean z) {
        MethodCollector.i(18523);
        String str = TAG;
        C0347IDi.LIZ(str, "onInitMarkHardEncoder == enter");
        C0347IDi.LIZ(str, "width = " + i + "\theight = " + i2);
        if (this.mAVCEncoderMark == null) {
            this.mAVCEncoderMark = new C0445IHc();
        }
        C0445IHc.LIZIZ = this;
        Surface LIZ = this.mAVCEncoderMark.LIZ(i, i2, i3, z);
        if (LIZ == null) {
            this.mAVCEncoderMark = null;
            setHardEncoderMarkStatus(false);
            MethodCollector.o(18523);
            return null;
        }
        C0347IDi.LIZ(str, "====== initAVCEncoder succeed ======");
        setHardEncoderMarkStatus(true);
        C0347IDi.LIZ(str, "onInitMarkHardEncoder == exit");
        MethodCollector.o(18523);
        return LIZ;
    }

    public static void onNativeCallback_MarkParam(float f, int i, float f2, float f3, float f4, float f5, float f6, float f7) {
        if (mSingleton != null) {
            mSingleton.onMarkParam(f, i, f2, f3, f4, f5, f6, f7);
        }
    }

    public final void onMarkParam(float f, int i, float f2, float f3, float f4, float f5, float f6, float f7) {
        C0445IHc iHc = this.mAVCEncoderMark;
        if (iHc != null) {
            iHc.LJIIIZ = f;
            iHc.LJIIJ = i;
            iHc.LJIIJJI = f2;
            iHc.LJIIL = f3;
            iHc.LJIILIIL = f4;
            iHc.LJIILJJIL = f5;
            iHc.LJIILL = f6;
            iHc.LJIILLIIL = f7;
            if (iHc.LJI != null) {
                iHc.LJI.LIZIZ(iHc.LJIIIZ);
                iHc.LJI.LIZ(iHc.LJIIJJI, iHc.LJIIL, iHc.LJIILIIL, iHc.LJIILJJIL);
            }
        }
    }

    public final void setMarkParam(String[] strArr, String str, boolean z, int i, int i2, int i3, int i4, int i5, int i6) {
        MethodCollector.i(16781);
        int i7 = i;
        String[] strArr2 = strArr;
        String str2 = str;
        boolean z2 = z;
        setMarkParams(strArr2, str2, z2, i7, i2, i3, i4, i5, i6);
        MethodCollector.o(16781);
    }
}
