davidliu
Committed by GitHub

Add EglBase to LiveKitOverrides (#310)

... ... @@ -22,7 +22,9 @@ import io.livekit.android.audio.AudioFocusHandler
import io.livekit.android.audio.AudioHandler
import io.livekit.android.audio.AudioSwitchHandler
import io.livekit.android.audio.NoAudioHandler
import io.livekit.android.room.Room
import okhttp3.OkHttpClient
import org.webrtc.EglBase
import org.webrtc.VideoDecoderFactory
import org.webrtc.VideoEncoderFactory
import org.webrtc.audio.AudioDeviceModule
... ... @@ -47,7 +49,20 @@ data class LiveKitOverrides(
*/
val videoDecoderFactory: VideoDecoderFactory? = null,
/**
* Override various audio options used by the library.
*/
val audioOptions: AudioOptions? = null,
/**
* Override the [EglBase] used by the library.
*
* If a non-null value is passed, the library does not
* take ownership of the object and will not release it upon [Room.release].
* It is the responsibility of the owner to call [EglBase.release] when finished
* with it to prevent memory leaks.
*/
val eglBase: EglBase? = null,
)
class AudioOptions(
... ... @@ -72,6 +87,11 @@ class AudioOptions(
/**
* Override the default [AudioDeviceModule].
*
* If a non-null value is passed, the library does not
* take ownership of the object and will not release it upon [Room.release].
* It is the responsibility of the owner to call [AudioDeviceModule.release] when finished
* with it to prevent memory leaks.
*/
val audioDeviceModule: AudioDeviceModule? = null,
... ...
... ... @@ -55,4 +55,5 @@ object InjectionNames {
internal const val OVERRIDE_VIDEO_DECODER_FACTORY = "override_video_decoder_factory"
internal const val OVERRIDE_AUDIO_HANDLER = "override_audio_handler"
internal const val OVERRIDE_AUDIO_OUTPUT_TYPE = "override_audio_output_type"
internal const val OVERRIDE_EGL_BASE = "override_egl_base"
}
... ...
... ... @@ -63,4 +63,9 @@ class OverridesModule(private val overrides: LiveKitOverrides) {
@Provides
@Named(InjectionNames.OVERRIDE_AUDIO_OUTPUT_TYPE)
fun audioOutputType() = overrides.audioOptions?.audioOutputType
@Provides
@Named(InjectionNames.OVERRIDE_EGL_BASE)
@Nullable
fun eglBase() = overrides.eglBase
}
... ...
... ... @@ -175,12 +175,14 @@ object RTCModule {
@Provides
@Singleton
fun eglBase(
@Named(InjectionNames.OVERRIDE_EGL_BASE)
@Nullable
eglBaseOverride: EglBase?,
memoryManager: CloseableManager,
): EglBase {
val eglBase = EglBase.create()
memoryManager.registerResource(eglBase) { eglBase.release() }
return eglBase
return eglBaseOverride ?: EglBase
.create()
.apply { memoryManager.registerClosable { release() } }
}
@Provides
... ...