package com.ss.android.medialib.NativePort;

import X.C0014I0n;
import X.C0444IHb;
import android.view.Surface;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.nio.ByteBuffer;

public class HWAvcNativeBridge implements C0014I0n {
    public C0444IHb mAVCEncoder;
    public long mNativePtr;

    static {
        Covode.recordClassIndex(48480);
    }

    public int getProfile() {
        return 0;
    }

    public native int nativeSetCodecConfig(long j, ByteBuffer byteBuffer, int i);

    public native int nativeSetColorFormat(long j, int i);

    public native int nativeSetHardEncoderStatus(long j, boolean z);

    public native void nativeSwapGlBuffer(long j);

    public native int nativeWriteFile(long j, ByteBuffer byteBuffer, int i, int i2, int i3, int i4);

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

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

    public Surface onInitHardEncoder(int i, int i2, int i3, int i4, int i5, int i6, boolean z, int i7) {
        return null;
    }

    public void onWriteFile(ByteBuffer byteBuffer, long j, long j2, int i, boolean z) {
    }

    public void onSwapGlBuffers() {
        MethodCollector.i(14840);
        nativeSwapGlBuffer(this.mNativePtr);
        MethodCollector.o(14840);
    }

    public void onUninitHardEncoder() {
        C0444IHb iHb = this.mAVCEncoder;
        if (iHb != null) {
            iHb.LIZJ();
            this.mAVCEncoder = null;
        }
    }

    public HWAvcNativeBridge(long j) {
        this.mNativePtr = j;
    }

    public void setColorFormat(int i) {
        MethodCollector.i(13424);
        nativeSetColorFormat(this.mNativePtr, i);
        MethodCollector.o(13424);
    }

    public void onSetCodecConfig(ByteBuffer byteBuffer) {
        MethodCollector.i(13986);
        nativeSetCodecConfig(this.mNativePtr, byteBuffer, byteBuffer.remaining());
        MethodCollector.o(13986);
    }

    public int onEncoderData(int i, int i2, int i3, boolean z) {
        C0444IHb iHb = this.mAVCEncoder;
        if (iHb == null) {
            return 0;
        }
        iHb.LIZ(i, i2, i3, z);
        return 0;
    }

    public void onWriteFile(ByteBuffer byteBuffer, int i, int i2, int i3) {
        MethodCollector.i(14614);
        ByteBuffer byteBuffer2 = byteBuffer;
        nativeWriteFile(this.mNativePtr, byteBuffer2, byteBuffer2.remaining(), i, i2, i3);
        MethodCollector.o(14614);
    }

    public Surface onInitHardEncoder(int i, int i2, int i3, int i4, boolean z) {
        MethodCollector.i(13757);
        int i5 = i4;
        if (this.mAVCEncoder == null) {
            this.mAVCEncoder = new C0444IHb();
            C0444IHb.LIZLLL = i5;
        }
        C0444IHb.LIZ = this;
        Surface LIZ = this.mAVCEncoder.LIZ(i, i2, i3, 1, 1, i5, z);
        if (LIZ == null) {
            this.mAVCEncoder = null;
            nativeSetHardEncoderStatus(this.mNativePtr, false);
            MethodCollector.o(13757);
            return null;
        }
        nativeSetHardEncoderStatus(this.mNativePtr, true);
        MethodCollector.o(13757);
        return LIZ;
    }
}
