package com.ss.android.ttve.nativePort;

import X.8XX;
import X.C0147I5q;
import X.C0148I5r;
import X.C0153I5w;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.vesdk.VEAudioCaptureSettings;
import com.ss.android.vesdk.VEInfo;
import com.ss.android.vesdk.audio.VEAudioSample;
import java.nio.ByteBuffer;

public class TEAudioDataInterface implements C0153I5w {
    public long handle = nativeCreate();
    public VEAudioCaptureSettings mAudioCaptureSettings;

    private native long nativeCreate();

    private native int nativeInit(long j, int i, int i2, int i3);

    private native void nativeRelease(long j);

    private native int nativeSendArrayData(long j, byte[] bArr, int i, long j2, long j3);

    private native int nativeSendBufferData(long j, ByteBuffer byteBuffer, int i, long j2, long j3);

    public void onError(int i, int i2, String str) {
    }

    public long getHandle() {
        return this.handle;
    }

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

    public TEAudioDataInterface() {
        MethodCollector.i(1882);
        MethodCollector.o(1882);
    }

    public synchronized void release() {
        MethodCollector.i(1884);
        long j = this.handle;
        if (j != 0) {
            nativeRelease(j);
            this.handle = 0;
        }
        MethodCollector.o(1884);
    }

    public synchronized void onReceive(VEAudioSample vEAudioSample) {
        VEAudioCaptureSettings vEAudioCaptureSettings;
        MethodCollector.i(1793);
        if (!(this.handle == 0 || (vEAudioCaptureSettings = this.mAudioCaptureSettings) == null)) {
            if (vEAudioCaptureSettings.getDataStore() == 0) {
                nativeSendArrayData(this.handle, ((C0147I5q) vEAudioSample.getSampleBuffer()).LIZ, vEAudioSample.getByteSize(), vEAudioSample.getTimeStamp(), (System.nanoTime() / 1000) - vEAudioSample.getTimeStamp());
                MethodCollector.o(1793);
                return;
            }
            nativeSendBufferData(this.handle, ((C0148I5r) vEAudioSample.getSampleBuffer()).LIZ, vEAudioSample.getByteSize(), vEAudioSample.getTimeStamp(), (System.nanoTime() / 1000) - vEAudioSample.getTimeStamp());
        }
        MethodCollector.o(1793);
    }

    public void onInfo(int i, int i2, double d, Object obj) {
        MethodCollector.i(1879);
        if (i == VEInfo.TE_INFO_RECORD_AUDIO_CAPTURE_INIT) {
            VEAudioCaptureSettings vEAudioCaptureSettings = (VEAudioCaptureSettings) obj;
            this.mAudioCaptureSettings = vEAudioCaptureSettings;
            long j = this.handle;
            if (j != 0) {
                nativeInit(j, vEAudioCaptureSettings.getSampleRate(), this.mAudioCaptureSettings.getChannel(), this.mAudioCaptureSettings.getBitSamples());
            }
        }
        MethodCollector.o(1879);
    }
}
