package com.ss.android.ugc.aweme.shortvideo.cover;

import X.0CB;
import X.0CH;
import X.0CN;
import X.0Gp;
import X.AnonymousClass6J4;
import X.C030758v;
import X.C13165es;
import X.C13175et;
import X.C23265vA;
import X.C31126Is;
import X.Lea;
import X.M12;
import X.Nsg;
import X.OnU;
import com.bytedance.covode.number.Covode;
import com.ss.android.vesdk.VEEditor;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class VEVideoCoverGeneratorImpl implements C31126Is, OnU {
    public int[] LIZ;
    public int LIZIZ;
    public int LIZJ;
    public C030758v LIZLLL;
    public List<Long> LJ = new ArrayList();
    public VEEditor.GET_FRAMES_FLAGS LJFF;
    public String LJI;
    public final String LJII = "VEVideoCoverGeneratorImpl";

    static {
        Covode.recordClassIndex(108456);
    }

    public void onStateChanged(0CH r2, 0CB r3) {
        if (r3 == 0CB.ON_DESTROY) {
            onDestroy();
        }
    }

    public final int LIZ() {
        return this.LIZIZ;
    }

    public final void LIZIZ() {
        this.LIZJ = -1;
        this.LIZ = null;
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public void onDestroy() {
        this.LIZLLL.LJJIIZI();
        List<Long> list = this.LJ;
        String str = this.LJI;
        M12.LIZ(list, str);
        if (!list.isEmpty()) {
            C13175et LIZLLL2 = Nsg.LJIIIZ.LIZLLL();
            AnonymousClass6J4 r3 = new AnonymousClass6J4();
            r3.LIZ("duration", Lea.LJJ(list));
            r3.LIZ("count", list.size());
            r3.LIZ("scene", str);
            LIZLLL2.LIZ("tool_performance_fetch_frames", r3.LIZ);
        }
    }

    public int[] LIZ(int i, int i2) {
        int[] iArr = new int[i2];
        int i3 = i / i2;
        for (int i4 = 0; i4 < i2; i4++) {
            iArr[i4] = i3 * i4;
        }
        return iArr;
    }

    public final void LIZ(int i, int i2, C23265vA r13) {
        boolean z;
        int i3 = i2;
        int i4 = i;
        int LJI2 = this.LIZLLL.LJI();
        int i5 = this.LIZJ;
        if (i5 <= 0 || i5 != LJI2) {
            z = true;
            this.LIZJ = LJI2;
        } else {
            z = false;
        }
        if (this.LIZ == null || z) {
            this.LIZ = LIZ(this.LIZJ, this.LIZIZ);
        }
        int[] iArr = this.LIZ;
        AtomicInteger atomicInteger = new AtomicInteger(0);
        if (i3 > i4 && i4 != -1) {
            i3 = -1;
        } else if (i3 != -1) {
            i4 = -1;
        } else {
            i3 = -1;
        }
        0Gp.LIZ(new C13165es(this, iArr, i4, i3, r13, atomicInteger, System.currentTimeMillis()));
    }

    public VEVideoCoverGeneratorImpl(C030758v r2, 0CH r3, int i, VEEditor.GET_FRAMES_FLAGS get_frames_flags, String str) {
        r3.getLifecycle().LIZ(this);
        this.LIZLLL = r2;
        this.LIZIZ = i;
        this.LJFF = get_frames_flags;
        this.LJI = str;
    }
}
