package com.bytedance.bae;

import X.4Sh;
import android.content.Context;
import android.os.SystemClock;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.librarian.Librarian;
import java.util.ArrayList;
import java.util.List;

public class ByteAudioEngine extends IByteAudioEngine {
    public static Boolean sIsLibraryLoaded = false;
    public List<ByteAudioEventHandlerProxy> eventHandlerList = new ArrayList();
    public long nativeEnginePtr;

    static {
        Covode.recordClassIndex(24169);
    }

    public int addEnableAudioRouteReference() {
        MethodCollector.i(18582);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            int nativeAddEnableAudioRouteReference = ByteAudioNativeFunctions.nativeAddEnableAudioRouteReference(j);
            MethodCollector.o(18582);
            return nativeAddEnableAudioRouteReference;
        }
        MethodCollector.o(18582);
        return -1;
    }

    public void release() {
        MethodCollector.i(18337);
        if (this.nativeEnginePtr != 0) {
            ByteAudioNativeFunctions.nativeReleaseInstance();
        }
        MethodCollector.o(18337);
    }

    public int removeEnableAudioRouteReference() {
        MethodCollector.i(18584);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            int nativeRemoveEnableAudioRouteReference = ByteAudioNativeFunctions.nativeRemoveEnableAudioRouteReference(j);
            MethodCollector.o(18584);
            return nativeRemoveEnableAudioRouteReference;
        }
        MethodCollector.o(18584);
        return -1;
    }

    public ByteAudioEngine() {
        MethodCollector.i(17860);
        if (!sIsLibraryLoaded.booleanValue()) {
            try {
                INVOKESTATIC_com_bytedance_bae_ByteAudioEngine_com_ss_android_ugc_aweme_lancet_LoadSoLancet_loadLibrary("byteaudio");
                sIsLibraryLoaded = true;
            } catch (UnsatisfiedLinkError unused) {
            }
        }
        this.nativeEnginePtr = ByteAudioNativeFunctions.nativeGetInstance();
        MethodCollector.o(17860);
    }

    public static void setLibraryLoaded(boolean z) {
        sIsLibraryLoaded = Boolean.valueOf(z);
    }

    public int releaseAuxStream(ByteAudioAuxStream byteAudioAuxStream) {
        byteAudioAuxStream.releaseStream();
        return -1;
    }

    public int releaseInputStream(ByteAudioInputStream byteAudioInputStream) {
        byteAudioInputStream.releaseStream();
        return -1;
    }

    public int releaseOutputStream(ByteAudioOutputStream byteAudioOutputStream) {
        byteAudioOutputStream.releaseStream();
        return -1;
    }

    public static void INVOKESTATIC_com_bytedance_bae_ByteAudioEngine_com_ss_android_ugc_aweme_lancet_LoadSoLancet_loadLibrary(String str) {
        long uptimeMillis = SystemClock.uptimeMillis();
        Librarian.LIZ(str, false, (Context) null);
        4Sh.LIZ(uptimeMillis, str);
    }

    public int adjustHeadsetMonitorVolume(int i) {
        MethodCollector.i(19253);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            int nativeAdjustHeadsetMonitorVolume = ByteAudioNativeFunctions.nativeAdjustHeadsetMonitorVolume(j, i);
            MethodCollector.o(19253);
            return nativeAdjustHeadsetMonitorVolume;
        }
        MethodCollector.o(19253);
        return -1;
    }

    public int adjustPlaybackVolume(int i) {
        MethodCollector.i(19316);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            int nativeAdjustPlaybackVolume = ByteAudioNativeFunctions.nativeAdjustPlaybackVolume(j, i);
            MethodCollector.o(19316);
            return nativeAdjustPlaybackVolume;
        }
        MethodCollector.o(19316);
        return -1;
    }

    public int adjustRecordVolume(int i) {
        MethodCollector.i(19291);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            int nativeAdjustRecordVolume = ByteAudioNativeFunctions.nativeAdjustRecordVolume(j, i);
            MethodCollector.o(19291);
            return nativeAdjustRecordVolume;
        }
        MethodCollector.o(19291);
        return -1;
    }

    public ByteAudioAuxStream createAuxStream(String str) {
        if (this.nativeEnginePtr != 0) {
            return new ByteAudioAuxStream(this.nativeEnginePtr, str);
        }
        return null;
    }

    public ByteAudioInputStream createInputStream(String str) {
        if (this.nativeEnginePtr != 0) {
            return new ByteAudioInputStream(this.nativeEnginePtr, str);
        }
        return null;
    }

    public ByteAudioOutputStream createOutputStream(String str) {
        if (this.nativeEnginePtr != 0) {
            return new ByteAudioOutputStream(this.nativeEnginePtr, str);
        }
        return null;
    }

    public int enableEarMonitor(boolean z) {
        MethodCollector.i(18585);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            ByteAudioNativeFunctions.nativeEnableEarMonitor(j, z);
        }
        MethodCollector.o(18585);
        return 0;
    }

    public void enableLocalAudio(boolean z) {
        MethodCollector.i(19222);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            ByteAudioNativeFunctions.nativeEnableLocalAudio(j, z);
        }
        MethodCollector.o(19222);
    }

    public ByteAudioStreamOption getValue(int i) {
        MethodCollector.i(19318);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            ByteAudioStreamOption nativeGetValue = ByteAudioNativeFunctions.nativeGetValue(j, i);
            MethodCollector.o(19318);
            return nativeGetValue;
        }
        MethodCollector.o(19318);
        return null;
    }

    public int setAudioScenario(int i) {
        MethodCollector.i(19290);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            int nativeSetAudioScenario = ByteAudioNativeFunctions.nativeSetAudioScenario(j, i);
            MethodCollector.o(19290);
            return nativeSetAudioScenario;
        }
        MethodCollector.o(19290);
        return -1;
    }

    public void setEnableSpeakerphone(boolean z) {
        MethodCollector.i(18580);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            ByteAudioNativeFunctions.nativeSetEnableSpeakerphone(j, z);
        }
        MethodCollector.o(18580);
    }

    public int setServerConfigure(String str) {
        int i;
        MethodCollector.i(18384);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            i = ByteAudioNativeFunctions.nativeSetServerConfigure(j, str);
        } else {
            i = -1;
        }
        MethodCollector.o(18384);
        return i;
    }

    public void addEventHandler(ByteAudioEventHandler byteAudioEventHandler) {
        MethodCollector.i(18484);
        for (ByteAudioEventHandlerProxy equals : this.eventHandlerList) {
            if (byteAudioEventHandler.equals(equals)) {
                MethodCollector.o(18484);
                return;
            }
        }
        ByteAudioEventHandlerProxy byteAudioEventHandlerProxy = new ByteAudioEventHandlerProxy(byteAudioEventHandler);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            long nativeAddEventHandler = ByteAudioNativeFunctions.nativeAddEventHandler(j, byteAudioEventHandlerProxy);
            if (nativeAddEventHandler != 0) {
                byteAudioEventHandlerProxy.setNativeHandler(nativeAddEventHandler);
                this.eventHandlerList.add(byteAudioEventHandlerProxy);
            }
        }
        MethodCollector.o(18484);
    }

    public void removeEventHandler(ByteAudioEventHandler byteAudioEventHandler) {
        MethodCollector.i(18529);
        if (this.nativeEnginePtr != 0) {
            for (int i = 0; i < this.eventHandlerList.size(); i++) {
                ByteAudioEventHandlerProxy byteAudioEventHandlerProxy = this.eventHandlerList.get(i);
                if (byteAudioEventHandlerProxy.handler == byteAudioEventHandler) {
                    ByteAudioNativeFunctions.nativeRemoveEventHandler(this.nativeEnginePtr, byteAudioEventHandlerProxy.nativeHandlerPtr);
                    this.eventHandlerList.remove(byteAudioEventHandlerProxy);
                    byteAudioEventHandlerProxy.handler = null;
                    byteAudioEventHandlerProxy.nativeHandlerPtr = 0;
                    MethodCollector.o(18529);
                    return;
                }
            }
        }
        MethodCollector.o(18529);
    }

    public int setValue(int i, ByteAudioStreamOption byteAudioStreamOption) {
        MethodCollector.i(19317);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            int nativeSetValue = ByteAudioNativeFunctions.nativeSetValue(j, i, byteAudioStreamOption);
            MethodCollector.o(19317);
            return nativeSetValue;
        }
        MethodCollector.o(19317);
        return -1;
    }

    public void setFrontInputFilter(ByteAudioFilterProxy byteAudioFilterProxy, int i, int i2) {
        MethodCollector.i(18587);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            ByteAudioNativeFunctions.nativeSetFrontInputFilter(j, byteAudioFilterProxy, i, i2);
        }
        MethodCollector.o(18587);
    }

    public void setInputFilter(ByteAudioFilterProxy byteAudioFilterProxy, int i, int i2) {
        MethodCollector.i(18586);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            ByteAudioNativeFunctions.nativeSetInputFilter(j, byteAudioFilterProxy, i, i2);
        }
        MethodCollector.o(18586);
    }

    public void setOutputFilter(ByteAudioFilterProxy byteAudioFilterProxy, int i, int i2) {
        MethodCollector.i(18588);
        long j = this.nativeEnginePtr;
        if (j != 0) {
            ByteAudioNativeFunctions.nativeSetOutputFilter(j, byteAudioFilterProxy, i, i2);
        }
        MethodCollector.o(18588);
    }
}
