From 7676c8c2bbd06937d9a6f6ab65c25802a524fc53 Mon Sep 17 00:00:00 2001 From: ThibaultBee <37510686+ThibaultBee@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:56:26 +0100 Subject: [PATCH] fix(core): streamer: recreate a SurfaceTexture on stopStream if the encoder has not been changed --- .../streampack/core/streamers/DefaultStreamer.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/java/io/github/thibaultbee/streampack/core/streamers/DefaultStreamer.kt b/core/src/main/java/io/github/thibaultbee/streampack/core/streamers/DefaultStreamer.kt index ef3f66865..8d2931b0a 100644 --- a/core/src/main/java/io/github/thibaultbee/streampack/core/streamers/DefaultStreamer.kt +++ b/core/src/main/java/io/github/thibaultbee/streampack/core/streamers/DefaultStreamer.kt @@ -602,6 +602,20 @@ open class DefaultStreamer( // Only reset if the encoder is the same. Otherwise, it is already configured. if (previousVideoEncoder == videoEncoderInternal) { + /** + * Workaround to avoid spurious frame from the SurfaceTexture on the new stream when + * SurfaceTexture is not changed. + */ + surfaceProcessor?.let { processor -> + videoSourceInternal?.let { source -> + source.outputSurface?.let { surface -> processor.removeInputSurface(surface) } + source.outputSurface = processor.createInputSurface( + source.infoProvider.getSurfaceSize( + videoConfig!!.resolution, targetRotation + ) + ) + } + } videoEncoderInternal?.reset() } }