keep encoders running in stopStream while a recording is starting or paused - #2196
Merged
pedroSG94 merged 1 commit intoSep 11, 2026
Conversation
…g or paused Co-authored-by: Cursor <cursoragent@cursor.com>
Owner
|
Hello, Thank you for the fix. Merged |
RomanHerbstmann
deleted the
fix/stopstream-keep-encoders-while-record-starting
branch
September 13, 2026 19:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Keep encoders running in stopStream() while a recording is starting or paused
Problem
startStream()andstopStream()check different record states:startStream()starts the encoders only if!recordController.isRunning(). Otherwise it just requests a keyframe.stopStream()stops encoders, microphone, GL surfaces and camera if!recordController.isRecording().isRecording()is only true inRECORDING.isRunning()is also true inSTARTED,PAUSEDandRESUMED. AfterstartRecord()the controller stays inSTARTEDuntil the first keyframe arrives, usually 35–150 ms and up to one keyframe interval.If
stopStream()is called in that window (for example because the connection failed right after a new recording segment was started):isRecording()is false, so the encoders, mic and camera are stopped and the formats are reset.STARTEDand never receives a frame.startStream()seesisRunning() == trueand skipsstartEncoders().requestKeyFrame()is a no-op because the encoder is not running.startRecord()while streaming also gets no frames, becausestartRecord()only starts the encoders when not streaming.The same applies to
PAUSED:stopStream()during a paused recording stops the encoders, althoughresumeRecord()waits for the next keyframe.StreamBase.ktalready does this consistently: itsisRecordingproperty maps torecordController.isRunning(), andstopStream()uses it.Camera2Base.isRecording()also returnsisRunning().Fix
stopStream()now checks!recordController.isRunning(), symmetric tostartStream(), in all Java bases:Camera1BaseCamera2BaseDisplayBaseFromFileBaseOnlyAudioBaseWith this change, stopping the stream while a recording is starting or paused keeps the encoders alive, which is the same behaviour as today while
RECORDING.stopRecord()still cleans up correctly.recordController.stopRecord()sets the status toSTOPPEDbeforeif (!streaming) stopStream()runs, so the full teardown happens as before.Test
Android emulator,
SrtCamera2streaming to MediaMTX, with a local recording rotated every 60 s while streaming (stopRecord()+startRecord(newFile)). A debug hook calledstopStream()directly afterstartRecord()of a new segment, while the status was stillSTARTED.stopStream()Normal reconnects (library
reTryand a full stop/start) behave as before.