davidliu
Committed by GitHub

Add EglBase to LiveKitOverrides (#310)

@@ -22,7 +22,9 @@ import io.livekit.android.audio.AudioFocusHandler @@ -22,7 +22,9 @@ import io.livekit.android.audio.AudioFocusHandler
22 import io.livekit.android.audio.AudioHandler 22 import io.livekit.android.audio.AudioHandler
23 import io.livekit.android.audio.AudioSwitchHandler 23 import io.livekit.android.audio.AudioSwitchHandler
24 import io.livekit.android.audio.NoAudioHandler 24 import io.livekit.android.audio.NoAudioHandler
  25 +import io.livekit.android.room.Room
25 import okhttp3.OkHttpClient 26 import okhttp3.OkHttpClient
  27 +import org.webrtc.EglBase
26 import org.webrtc.VideoDecoderFactory 28 import org.webrtc.VideoDecoderFactory
27 import org.webrtc.VideoEncoderFactory 29 import org.webrtc.VideoEncoderFactory
28 import org.webrtc.audio.AudioDeviceModule 30 import org.webrtc.audio.AudioDeviceModule
@@ -47,7 +49,20 @@ data class LiveKitOverrides( @@ -47,7 +49,20 @@ data class LiveKitOverrides(
47 */ 49 */
48 val videoDecoderFactory: VideoDecoderFactory? = null, 50 val videoDecoderFactory: VideoDecoderFactory? = null,
49 51
  52 + /**
  53 + * Override various audio options used by the library.
  54 + */
50 val audioOptions: AudioOptions? = null, 55 val audioOptions: AudioOptions? = null,
  56 +
  57 + /**
  58 + * Override the [EglBase] used by the library.
  59 + *
  60 + * If a non-null value is passed, the library does not
  61 + * take ownership of the object and will not release it upon [Room.release].
  62 + * It is the responsibility of the owner to call [EglBase.release] when finished
  63 + * with it to prevent memory leaks.
  64 + */
  65 + val eglBase: EglBase? = null,
51 ) 66 )
52 67
53 class AudioOptions( 68 class AudioOptions(
@@ -72,6 +87,11 @@ class AudioOptions( @@ -72,6 +87,11 @@ class AudioOptions(
72 87
73 /** 88 /**
74 * Override the default [AudioDeviceModule]. 89 * Override the default [AudioDeviceModule].
  90 + *
  91 + * If a non-null value is passed, the library does not
  92 + * take ownership of the object and will not release it upon [Room.release].
  93 + * It is the responsibility of the owner to call [AudioDeviceModule.release] when finished
  94 + * with it to prevent memory leaks.
75 */ 95 */
76 val audioDeviceModule: AudioDeviceModule? = null, 96 val audioDeviceModule: AudioDeviceModule? = null,
77 97
@@ -55,4 +55,5 @@ object InjectionNames { @@ -55,4 +55,5 @@ object InjectionNames {
55 internal const val OVERRIDE_VIDEO_DECODER_FACTORY = "override_video_decoder_factory" 55 internal const val OVERRIDE_VIDEO_DECODER_FACTORY = "override_video_decoder_factory"
56 internal const val OVERRIDE_AUDIO_HANDLER = "override_audio_handler" 56 internal const val OVERRIDE_AUDIO_HANDLER = "override_audio_handler"
57 internal const val OVERRIDE_AUDIO_OUTPUT_TYPE = "override_audio_output_type" 57 internal const val OVERRIDE_AUDIO_OUTPUT_TYPE = "override_audio_output_type"
  58 + internal const val OVERRIDE_EGL_BASE = "override_egl_base"
58 } 59 }
@@ -63,4 +63,9 @@ class OverridesModule(private val overrides: LiveKitOverrides) { @@ -63,4 +63,9 @@ class OverridesModule(private val overrides: LiveKitOverrides) {
63 @Provides 63 @Provides
64 @Named(InjectionNames.OVERRIDE_AUDIO_OUTPUT_TYPE) 64 @Named(InjectionNames.OVERRIDE_AUDIO_OUTPUT_TYPE)
65 fun audioOutputType() = overrides.audioOptions?.audioOutputType 65 fun audioOutputType() = overrides.audioOptions?.audioOutputType
  66 +
  67 + @Provides
  68 + @Named(InjectionNames.OVERRIDE_EGL_BASE)
  69 + @Nullable
  70 + fun eglBase() = overrides.eglBase
66 } 71 }
@@ -175,12 +175,14 @@ object RTCModule { @@ -175,12 +175,14 @@ object RTCModule {
175 @Provides 175 @Provides
176 @Singleton 176 @Singleton
177 fun eglBase( 177 fun eglBase(
  178 + @Named(InjectionNames.OVERRIDE_EGL_BASE)
  179 + @Nullable
  180 + eglBaseOverride: EglBase?,
178 memoryManager: CloseableManager, 181 memoryManager: CloseableManager,
179 ): EglBase { 182 ): EglBase {
180 - val eglBase = EglBase.create()  
181 - memoryManager.registerResource(eglBase) { eglBase.release() }  
182 -  
183 - return eglBase 183 + return eglBaseOverride ?: EglBase
  184 + .create()
  185 + .apply { memoryManager.registerClosable { release() } }
184 } 186 }
185 187
186 @Provides 188 @Provides