@@ -22,7 +22,6 @@ import androidx.annotation.IntRange
2222import io.github.thibaultbee.streampack.core.elements.processing.video.ISurfaceProcessorInternal
2323import io.github.thibaultbee.streampack.core.elements.processing.video.outputs.ISurfaceOutput
2424import io.github.thibaultbee.streampack.core.elements.processing.video.outputs.SurfaceOutput
25- import io.github.thibaultbee.streampack.core.elements.processing.video.source.DefaultSourceInfoProvider
2625import 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
@@ -393,7 +392,7 @@ internal class VideoInput(
393392 videoSourceInternal.resetOutput()
394393 }
395394 currentSurfaceProcessor.removeInputSurface(it)
396- updateOutputSurfacesUnsafe()
395+ updateOutputSurfacesUnsafe(videoSourceConfig = videoConfig )
397396 addSourceSurface(
398397 videoConfig,
399398 currentSurfaceProcessor,
@@ -432,7 +431,7 @@ internal class VideoInput(
432431 addSourceSurface(videoSourceConfig, newSurfaceProcessor)
433432
434433 // Re-adds output surfaces
435- addOutputSurfacesUnsafe()
434+ addOutputSurfacesUnsafe(videoSourceConfig = videoSourceConfig )
436435
437436 return newSurfaceProcessor
438437 }
@@ -465,19 +464,21 @@ internal class VideoInput(
465464 * Use it for additional processing.
466465 *
467466 * @param infoProvider the source info provider
467+ * @param videoSourceConfig the source configuration
468468 * @param surfaceDescriptor the encoder surface
469469 * @param isMirroringRequired whether mirroring is required
470470 * @param isStreaming a lambda to check if the surface is streaming
471471 */
472472 private fun buildSurfaceOutput (
473- infoProvider : ISourceInfoProvider ? ,
473+ infoProvider : ISourceInfoProvider ,
474+ videoSourceConfig : VideoSourceConfig ,
474475 surfaceDescriptor : SurfaceDescriptor ,
475476 isMirroringRequired : Boolean ,
476477 isStreaming : () -> Boolean
477478 ): ISurfaceOutput {
478- val infoProvider = infoProvider ? : DefaultSourceInfoProvider ()
479+ val infoProvider = infoProvider
479480 val sourceResolution = infoProvider.getSurfaceSize(
480- sourceConfig !! .resolution // build surface output is only called after config is set
481+ videoSourceConfig .resolution // build surface output is only called after config is set
481482 )
482483 return SurfaceOutput (
483484 surfaceDescriptor,
@@ -498,12 +499,22 @@ internal class VideoInput(
498499 }
499500
500501 sourceMutex.withLock {
502+ val sourceConfig = sourceConfig
503+ val infoProvider = source?.infoProviderFlow?.value
504+ if ((sourceConfig == null ) || (infoProvider == null )) {
505+ Logger .w(
506+ TAG ,
507+ " Video source configuration or info provider is not set, can't add output surface"
508+ )
509+ return
510+ }
501511 addOutputSurfaceUnsafe(
502512 buildSurfaceOutput(
503- source?.infoProviderFlow?.value,
504- surfaceDescriptor,
505- isMirroringRequired,
506- isStreaming
513+ infoProvider,
514+ sourceConfig,
515+ surfaceDescriptor = surfaceDescriptor,
516+ isMirroringRequired = isMirroringRequired,
517+ isStreaming = isStreaming
507518 )
508519 )
509520 }
@@ -517,27 +528,28 @@ internal class VideoInput(
517528 processor.addOutputSurface(output)
518529 }
519530
520-
521- private suspend fun addOutputSurfaces (infoProvider : ISourceInfoProvider ? = source?.infoProviderFlow?.value) {
531+ private suspend fun addOutputSurfacesUnsafe (
532+ infoProvider : ISourceInfoProvider ? = source?.infoProviderFlow?.value,
533+ videoSourceConfig : VideoSourceConfig ? = sourceConfig
534+ ) {
522535 if (isReleaseRequested.get()) {
523536 throw IllegalStateException (" Input is released" )
524537 }
525538
526- sourceMutex.withLock {
527- addOutputSurfacesUnsafe(infoProvider)
528- }
529- }
530-
531- private suspend fun addOutputSurfacesUnsafe (infoProvider : ISourceInfoProvider ? = source?.infoProviderFlow?.value) {
532- if (isReleaseRequested.get()) {
533- throw IllegalStateException (" Input is released" )
539+ if ((videoSourceConfig == null ) || (infoProvider == null )) {
540+ Logger .w(
541+ TAG ,
542+ " Video source configuration or info provider is not set, can't add output surface"
543+ )
544+ return
534545 }
535546
536547 val surfaces = onUpdateOutputSurface()
537548 surfaces.forEach { (surfaceDescriptor, isMirroringRequired, isStreaming) ->
538549 addOutputSurfaceUnsafe(
539550 buildSurfaceOutput(
540551 infoProvider,
552+ videoSourceConfig,
541553 surfaceDescriptor,
542554 isMirroringRequired,
543555 isStreaming
@@ -546,22 +558,28 @@ internal class VideoInput(
546558 }
547559 }
548560
549- private suspend fun updateOutputSurfacesUnsafe (infoProvider : ISourceInfoProvider ? = source?.infoProviderFlow?.value) {
561+ private suspend fun updateOutputSurfacesUnsafe (
562+ infoProvider : ISourceInfoProvider ? = source?.infoProviderFlow?.value,
563+ videoSourceConfig : VideoSourceConfig ? = sourceConfig
564+ ) {
550565 if (isReleaseRequested.get()) {
551566 throw IllegalStateException (" Input is released" )
552567 }
553568
554569 processor.removeAllOutputSurfaces()
555- addOutputSurfacesUnsafe(infoProvider)
570+ addOutputSurfacesUnsafe(infoProvider, videoSourceConfig )
556571 }
557572
558- private suspend fun updateOutputSurfaces (infoProvider : ISourceInfoProvider ? = source?.infoProviderFlow?.value) {
573+ private suspend fun updateOutputSurfaces (
574+ infoProvider : ISourceInfoProvider ? = source?.infoProviderFlow?.value,
575+ videoSourceConfig : VideoSourceConfig ? = sourceConfig
576+ ) {
559577 if (isReleaseRequested.get()) {
560578 throw IllegalStateException (" Input is released" )
561579 }
562580
563581 sourceMutex.withLock {
564- updateOutputSurfacesUnsafe(infoProvider)
582+ updateOutputSurfacesUnsafe(infoProvider, videoSourceConfig )
565583 }
566584 }
567585
0 commit comments