package com.ss.android.medialib.jni;

import X.8XX;
import X.C45106pI;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.medialib.model.CoverInfo;
import com.ss.android.medialib.player.EffectConfig;
import java.util.ArrayList;
import java.util.List;

public class EffectThumb {
    public long handle = nativeCreate();
    public List<CoverInfo> mCovers = new ArrayList();
    public int mMaxSize;
    public float mSpeed;
    public long mTrimIn;
    public long mTrimOut;
    public boolean stopped;
    public C45106pI thumbListener;

    private native long nativeCreate();

    private native long nativeGetDuration(long j);

    private native int nativeInit(long j, String str);

    private native int nativeRenderVideo(long j, long[] jArr, EffectConfig effectConfig, int i, int i2);

    private native void nativeStop(long j);

    public CoverInfo getThumb() {
        return null;
    }

    public void finalize() {
        stopRender();
        super.finalize();
    }

    static {
        Covode.recordClassIndex(48539);
        8XX.LJ();
    }

    public long getDuration() {
        return (long) (((float) (this.mTrimOut - this.mTrimIn)) / this.mSpeed);
    }

    public EffectThumb() {
        MethodCollector.i(16197);
        MethodCollector.o(16197);
    }

    public long getSourceVideoDuration() {
        MethodCollector.i(16346);
        long j = this.handle;
        if (j == 0) {
            MethodCollector.o(16346);
            return -1;
        }
        long nativeGetDuration = nativeGetDuration(j);
        MethodCollector.o(16346);
        return nativeGetDuration;
    }

    public synchronized void stopRender() {
        MethodCollector.i(17521);
        long j = this.handle;
        if (j == 0) {
            MethodCollector.o(17521);
            return;
        }
        this.stopped = true;
        nativeStop(j);
        this.handle = 0;
        MethodCollector.o(17521);
    }

    public void setThumbListener(C45106pI r1) {
        this.thumbListener = r1;
    }

    public int init(String str) {
        MethodCollector.i(16198);
        long j = this.handle;
        if (j == 0) {
            MethodCollector.o(16198);
            return -1;
        }
        int nativeInit = nativeInit(j, str);
        if (nativeInit >= 0) {
            this.mTrimIn = 0;
            this.mTrimOut = getSourceVideoDuration();
            this.mSpeed = 1.0f;
        }
        MethodCollector.o(16198);
        return nativeInit;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:31:0x004a, code lost:
        r2 = r1;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public com.ss.android.medialib.model.CoverInfo getThumb(int r5) {
        /*
            r4 = this;
            r3 = 17523(0x4473, float:2.4555E-41)
            com.bytedance.frameworks.apm.trace.MethodCollector.i(r3)
            r2 = 0
            if (r5 < 0) goto L_0x0010
            int r0 = r4.mMaxSize
            if (r5 >= r0) goto L_0x0010
            java.util.List<com.ss.android.medialib.model.CoverInfo> r0 = r4.mCovers
            if (r0 != 0) goto L_0x0014
        L_0x0010:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r3)
            return r2
        L_0x0014:
            boolean r0 = r4.stopped
            if (r0 != 0) goto L_0x004b
            monitor-enter(r4)
            java.util.List<com.ss.android.medialib.model.CoverInfo> r0 = r4.mCovers     // Catch:{ all -> 0x0044 }
            int r0 = r0.size()     // Catch:{ all -> 0x0044 }
            if (r0 > r5) goto L_0x002b
            r0 = 10
            r4.wait(r0)     // Catch:{ InterruptedException -> 0x0027 }
            goto L_0x002b
        L_0x0027:
            r0 = move-exception
            X.0HH.LIZ(r0)     // Catch:{ all -> 0x0044 }
        L_0x002b:
            java.util.List<com.ss.android.medialib.model.CoverInfo> r0 = r4.mCovers     // Catch:{ all -> 0x0044 }
            int r0 = r0.size()     // Catch:{ all -> 0x0044 }
            if (r0 > r5) goto L_0x0035
            monitor-exit(r4)     // Catch:{ all -> 0x0044 }
            goto L_0x0014
        L_0x0035:
            java.util.List<com.ss.android.medialib.model.CoverInfo> r0 = r4.mCovers     // Catch:{ all -> 0x0044 }
            java.lang.Object r1 = r0.get(r5)     // Catch:{ all -> 0x0044 }
            com.ss.android.medialib.model.CoverInfo r1 = (com.ss.android.medialib.model.CoverInfo) r1     // Catch:{ all -> 0x0044 }
            java.util.List<com.ss.android.medialib.model.CoverInfo> r0 = r4.mCovers     // Catch:{ all -> 0x0044 }
            r0.set(r5, r2)     // Catch:{ all -> 0x0044 }
            monitor-exit(r4)     // Catch:{ all -> 0x0044 }
            goto L_0x004a
        L_0x0044:
            r0 = move-exception
            monitor-exit(r4)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r3)
            throw r0
        L_0x004a:
            r2 = r1
        L_0x004b:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r3)
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.medialib.jni.EffectThumb.getThumb(int):com.ss.android.medialib.model.CoverInfo");
    }

    public void onThumb(int[] iArr, int i, int i2) {
        MethodCollector.i(17898);
        CoverInfo coverInfo = new CoverInfo(i, i2, iArr);
        synchronized (this) {
            try {
                if (!this.stopped) {
                    this.mCovers.add(coverInfo);
                    notify();
                }
            } finally {
                MethodCollector.o(17898);
            }
        }
    }

    public int renderVideo(long j, EffectConfig effectConfig, int i, int i2) {
        MethodCollector.i(17311);
        long j2 = this.handle;
        if (j2 == 0) {
            MethodCollector.o(17311);
            return -1;
        }
        this.mMaxSize = 1;
        int nativeRenderVideo = nativeRenderVideo(j2, new long[]{((long) (((float) j) * this.mSpeed)) + this.mTrimIn}, effectConfig, i, i2);
        MethodCollector.o(17311);
        return nativeRenderVideo;
    }

    public int init(String str, long j, long j2, float f) {
        MethodCollector.i(16199);
        long j3 = this.handle;
        if (j3 == 0) {
            MethodCollector.o(16199);
            return -1;
        }
        int nativeInit = nativeInit(j3, str);
        if (nativeInit >= 0) {
            this.mTrimIn = j;
            this.mTrimOut = j2;
            this.mSpeed = f;
        }
        MethodCollector.o(16199);
        return nativeInit;
    }

    public int renderVideo(long[] jArr, EffectConfig effectConfig, int i, int i2) {
        MethodCollector.i(17310);
        if (this.handle == 0) {
            MethodCollector.o(17310);
            return -1;
        }
        long[] jArr2 = jArr;
        this.mMaxSize = jArr2.length;
        for (int i3 = 0; i3 < jArr2.length; i3++) {
            jArr2[i3] = ((long) (((float) jArr2[i3]) * this.mSpeed)) + this.mTrimIn;
        }
        int nativeRenderVideo = nativeRenderVideo(this.handle, jArr2, effectConfig, i, i2);
        MethodCollector.o(17310);
        return nativeRenderVideo;
    }
}
