@@ -23,7 +23,6 @@ import io.github.thibaultbee.streampack.core.elements.processing.video.ISurfaceP
2323import io.github.thibaultbee.streampack.core.elements.processing.video.outputs.ISurfaceOutput
2424import io.github.thibaultbee.streampack.core.elements.processing.video.outputs.SurfaceOutput
2525import io.github.thibaultbee.streampack.core.elements.processing.video.source.DefaultSourceInfoProvider
26- import io.github.thibaultbee.streampack.core.elements.processing.video.source.ISourceInfoProvider
2726import io.github.thibaultbee.streampack.core.elements.sources.video.IPreviewableSource
2827import io.github.thibaultbee.streampack.core.elements.sources.video.ISurfaceSourceInternal
2928import io.github.thibaultbee.streampack.core.elements.sources.video.IVideoSource
@@ -184,8 +183,8 @@ internal class VideoInput(
184183 private val source: IVideoSourceInternal ?
185184 get() = sourceInternalFlow.value
186185
187- private val _infoProviderFlow = MutableStateFlow < ISourceInfoProvider ?>( null )
188- val infoProviderFlow = _infoProviderFlow .asStateFlow()
186+ private val _inputConfigChanged = MutableStateFlow ( Unit )
187+ val inputConfigChanged : StateFlow < Unit > = _inputConfigChanged .asStateFlow()
189188
190189 // CONFIG
191190 private val _sourceConfigFlow = MutableStateFlow <VideoSourceConfig ?>(null )
@@ -208,10 +207,6 @@ internal class VideoInput(
208207 private val _isStreamingFlow = MutableStateFlow (false )
209208 override val isStreamingFlow = _isStreamingFlow .asStateFlow()
210209
211- // OUTPUT
212- private val outputMutex = Mutex ()
213- private val surfaceOutput = mutableListOf<ISurfaceOutput >()
214-
215210 override suspend fun setSource (videoSourceFactory : IVideoSourceInternal .Factory ) {
216211 if (isReleaseRequested.get()) {
217212 throw IllegalStateException (" Input is released" )
@@ -261,7 +256,7 @@ internal class VideoInput(
261256
262257 infoProviderJob + = coroutineScope.launch {
263258 newVideoSource.infoProviderFlow.collect {
264- _infoProviderFlow .emit(it )
259+ _inputConfigChanged .emit(Unit )
265260 }
266261 }
267262
@@ -375,6 +370,7 @@ internal class VideoInput(
375370 videoSourceInternal.resetOutput()
376371 }
377372 currentSurfaceProcessor.removeInputSurface(it)
373+ _inputConfigChanged .emit(Unit )
378374 addSourceSurface(
379375 videoConfig,
380376 currentSurfaceProcessor,
@@ -403,19 +399,16 @@ internal class VideoInput(
403399 }
404400 }
405401
406- private suspend fun buildSurfaceProcessor (
407- videoSourceConfig : VideoSourceConfig
408- ): ISurfaceProcessorInternal {
402+ private suspend fun buildSurfaceProcessor (videoSourceConfig : VideoSourceConfig ): ISurfaceProcessorInternal {
409403 val newSurfaceProcessor =
410404 surfaceProcessorFactory.create(
411405 videoSourceConfig.dynamicRangeProfile,
412406 dispatcherProvider
413407 )
414408 addSourceSurface(videoSourceConfig, newSurfaceProcessor)
415409
416- outputMutex.withLock {
417- surfaceOutput.forEach { newSurfaceProcessor.addOutputSurface(it) }
418- }
410+ // Re-adds output surfaces
411+ _inputConfigChanged .emit(Unit )
419412
420413 return newSurfaceProcessor
421414 }
@@ -451,7 +444,7 @@ internal class VideoInput(
451444 isMirroringRequired : Boolean ,
452445 isStreaming : () -> Boolean
453446 ): ISurfaceOutput {
454- val infoProvider = infoProviderFlow.value ? : DefaultSourceInfoProvider ()
447+ val infoProvider = source?. infoProviderFlow? .value ? : DefaultSourceInfoProvider ()
455448 val sourceResolution = infoProvider.getSurfaceSize(
456449 sourceConfig!! .resolution // build surface output is only called after config is set
457450 )
@@ -482,24 +475,16 @@ internal class VideoInput(
482475 )
483476 }
484477
485- internal suspend fun addOutputSurface (output : ISurfaceOutput ) {
478+ internal fun addOutputSurface (output : ISurfaceOutput ) {
486479 if (isReleaseRequested.get()) {
487480 throw IllegalStateException (" Input is released" )
488481 }
489482
490- outputMutex.withLock {
491- surfaceOutput.add(output)
492- processor.addOutputSurface(output)
493- }
483+ processor.addOutputSurface(output)
494484 }
495485
496- internal suspend fun removeOutputSurface (output : Surface ) {
497- outputMutex.withLock {
498- surfaceOutput.firstOrNull { it.targetSurface == output }?.let {
499- surfaceOutput.remove(it)
500- }
501- processor.removeOutputSurface(output)
502- }
486+ internal fun removeOutputSurface (output : Surface ) {
487+ processor.removeOutputSurface(output)
503488 }
504489
505490 private suspend fun startStreamUnsafe () {
@@ -580,11 +565,7 @@ internal class VideoInput(
580565 processor.removeInputSurface(it)
581566 }
582567 }
583- outputMutex.withLock {
584- surfaceOutput.clear()
585- processor.removeAllOutputSurfaces()
586- }
587-
568+ processor.removeAllOutputSurfaces()
588569 processor.release()
589570 }
590571
0 commit comments