@@ -80,6 +80,7 @@ public SchedulerAsyncCommand(SchedulerAsyncCommandEnum command, TimeSpan? target
8080
8181 //Variables used for managing the synchornization and the main extraction loop
8282 private bool inputExtractionDone ;
83+ private bool inputQueuedSinceFlush ;
8384 private volatile bool isEOF ;
8485
8586 protected MediaSynchronizer Scheduler { get ; }
@@ -209,7 +210,13 @@ protected void SeekMediaAt(TimeSpan expectedTime)
209210 {
210211 isSeekRequestCompleted = false ;
211212 SeekTargetTime = expectedTime ;
212- MediaDecoder . Flush ( ) ;
213+ // With no input queued the flush is a no-op, and flushing a just-started codec
214+ // wedges the emulator's C2 decoder before its surface handshake completes.
215+ if ( inputQueuedSinceFlush )
216+ {
217+ MediaDecoder . Flush ( ) ;
218+ inputQueuedSinceFlush = false ;
219+ }
213220 mediaExtractor . SeekTo ( expectedTime . TotalMicroSeconds ( ) , MediaExtractorSeekTo . PreviousSync ) ;
214221 inputExtractionDone = false ;
215222 isEOF = false ;
@@ -299,7 +306,9 @@ private void ExtractMedia()
299306
300307 //=================================================================================================
301308 //Extract video inputs
302- if ( ! inputExtractionDone )
309+ // While stopped with no seek pending, outputs are not dequeued either, so feeding
310+ // the decoder would only build up buffers that the next seek has to flush away.
311+ if ( ! inputExtractionDone && ( ! isSeekRequestCompleted || currentState != SchedulerAsyncCommandEnum . Stop ) )
303312 {
304313 int inputBufIndex = MediaDecoder . DequeueInputBuffer ( 0 ) ;
305314 if ( inputBufIndex >= 0 )
@@ -315,11 +324,13 @@ private void ExtractMedia()
315324 throw new Exception ( $ "Got media sample from track { mediaExtractor . SampleTrackIndex } , track expected { mediaTrackIndex } ") ;
316325
317326 MediaDecoder . QueueInputBuffer ( inputBufIndex , 0 , chunkSize , mediaExtractor . SampleTime , 0 ) ;
327+ inputQueuedSinceFlush = true ;
318328 mediaExtractor . Advance ( ) ;
319329 }
320330 else // End of stream -- send empty frame with EOS flag set.
321331 {
322332 MediaDecoder . QueueInputBuffer ( inputBufIndex , 0 , 0 , 0L , MediaCodecBufferFlags . EndOfStream ) ;
333+ inputQueuedSinceFlush = true ;
323334 inputExtractionDone = true ;
324335 }
325336 }
0 commit comments