File tree Expand file tree Collapse file tree 3 files changed +15
-11
lines changed
androidTest/java/io/github/thibaultbee/streampack/core/pipelines/outputs
main/java/io/github/thibaultbee/streampack/core/pipelines/outputs Expand file tree Collapse file tree 3 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,8 @@ open class StubAudioAsyncPipelineOutput :
4343 private val _audioFrameFlow = MutableStateFlow <RawFrame ?>(null )
4444 val audioFrameFlow = _audioFrameFlow .asStateFlow()
4545
46- override fun queueAudioFrame (frame : RawFrame ) {
47- _audioFrameFlow .value = frame
46+ override suspend fun queueAudioFrame (frame : RawFrame ) {
47+ _audioFrameFlow .emit( frame)
4848 }
4949}
5050
@@ -84,8 +84,8 @@ class StubAudioSyncVideoSurfacePipelineOutput(resolution: Size) :
8484 private val _audioFrameFlow = MutableStateFlow <RawFrame ?>(null )
8585 val audioFrameFlow = _audioFrameFlow .asStateFlow()
8686
87- override fun queueAudioFrame (frame : RawFrame ) {
88- _audioFrameFlow .value = frame
87+ override suspend fun queueAudioFrame (frame : RawFrame ) {
88+ _audioFrameFlow .emit( frame)
8989 }
9090}
9191
@@ -150,8 +150,8 @@ class StubAudioSyncVideoSurfacePipelineOutputInternal(resolution: Size) :
150150 private val _audioFrameFlow = MutableStateFlow <RawFrame ?>(null )
151151 val audioFrameFlow = _audioFrameFlow .asStateFlow()
152152
153- override fun queueAudioFrame (frame : RawFrame ) {
154- _audioFrameFlow .value = frame
153+ override suspend fun queueAudioFrame (frame : RawFrame ) {
154+ _audioFrameFlow .emit( frame)
155155 }
156156}
157157
Original file line number Diff line number Diff line change @@ -244,7 +244,7 @@ interface IAudioSyncPipelineOutputInternal : IAudioPipelineOutputInternal {
244244 *
245245 * @param frame The audio [RawFrame] to queue.
246246 */
247- fun queueAudioFrame (frame : RawFrame )
247+ suspend fun queueAudioFrame (frame : RawFrame )
248248}
249249
250250/* *
Original file line number Diff line number Diff line change @@ -52,7 +52,6 @@ import kotlinx.coroutines.CoroutineDispatcher
5252import kotlinx.coroutines.CoroutineScope
5353import kotlinx.coroutines.Dispatchers
5454import kotlinx.coroutines.cancel
55- import kotlinx.coroutines.cancelChildren
5655import kotlinx.coroutines.channels.Channel
5756import kotlinx.coroutines.channels.consumeEach
5857import kotlinx.coroutines.flow.MutableStateFlow
@@ -114,7 +113,13 @@ internal class EncodingPipelineOutput(
114113 override val surfaceFlow = _surfaceFlow .asStateFlow()
115114
116115 // ENCODERS
116+ private var audioInput: IEncoderInternal .ISyncByteBufferInput ? = null
117+
117118 private var audioEncoderInternal: IEncoderInternal ? = null
119+ set(value) {
120+ audioInput = value?.input as ? IEncoderInternal .ISyncByteBufferInput
121+ field = value
122+ }
118123 override val audioEncoder: IEncoder ?
119124 get() = audioEncoderInternal
120125
@@ -281,9 +286,8 @@ internal class EncodingPipelineOutput(
281286 }
282287 }
283288
284- override fun queueAudioFrame (frame : RawFrame ) {
285- val encoder = requireNotNull(audioEncoderInternal) { " Audio is not configured" }
286- val input = encoder.input as IEncoderInternal .ISyncByteBufferInput
289+ override suspend fun queueAudioFrame (frame : RawFrame ) = mutex.withLock {
290+ val input = requireNotNull(audioInput) { " Audio input is null" }
287291 input.queueInputFrame(
288292 frame
289293 )
You can’t perform that action at this time.
0 commit comments