Skip to content

Add shortcut to reset video capture/encoding#5432

Merged
rom1v merged 3 commits intodevfrom
reset_video
Nov 3, 2024
Merged

Add shortcut to reset video capture/encoding#5432
rom1v merged 3 commits intodevfrom
reset_video

Conversation

@rom1v
Copy link
Collaborator

@rom1v rom1v commented Oct 31, 2024

First, make reset requests interrupt the encoder blocking call dequeueOutputBuffer() immediately, to avoid waiting until the next frame to consider the reset request.

Then, reset video capture/encoding on MOD+Shift+r. Like on device rotation, this starts a new encoding session which produces a video stream starting by a key frame.

@rom1v rom1v marked this pull request as draft November 3, 2024 09:48
rom1v added 2 commits November 3, 2024 19:26
When the capture source becomes "invalid" (because the display size
changes for example), a reset request is performed to restart the
encoder.

The reset state was stored in SurfaceCapture. The capture implementation
set the flag, and the encoder consumed it.

However, this mechanism did not allow a reset request to _interrupt_ the
encoder, which may be waiting on a blocking call (until a new frame is
produced).

To be able to interrupt the encoder, a reset request must not only set a
flag, but run a callback provided by the encoder. For that purpose,
introduce the CaptureListener interface, which is notified by the
SurfaceCapture implementation whenever the capture is invalidated.

For now, the listener implementation just set a flag as before, so the
behavior is unchanged. It lays the groundwork for the next commits.

PR #5432 <#5432>
When the MediaCodec input is a Surface, no EOS (end-of-stream) will
never occur automatically: it may only be triggered manually by
MediaCodec.signalEndOfInputStream().

Use this signal to interrupt the blocking call to dequeueOutputBuffer()
immediately on reset, without waiting for the next frame to be dequeued.

PR #5432 <#5432>
rom1v added a commit that referenced this pull request Nov 3, 2024
Reset video capture/encoding on MOD+Shift+r.

Like on device rotation, this starts a new encoding session which
produces a video stream starting by a key frame.

PR #5432 <#5432>
@rom1v rom1v marked this pull request as ready for review November 3, 2024 18:28
rom1v added a commit that referenced this pull request Nov 3, 2024
Reset video capture/encoding on MOD+Shift+r.

Like on device rotation, this starts a new encoding session which
produces a video stream starting by a key frame.

PR #5432 <#5432>
Reset video capture/encoding on MOD+Shift+r.

Like on device rotation, this starts a new encoding session which
produces a video stream starting by a key frame.

PR #5432 <#5432>
@rom1v rom1v merged commit 104195f into dev Nov 3, 2024
bartsaintgermain pushed a commit to bartsaintgermain/scrcpy that referenced this pull request Apr 11, 2025
When the capture source becomes "invalid" (because the display size
changes for example), a reset request is performed to restart the
encoder.

The reset state was stored in SurfaceCapture. The capture implementation
set the flag, and the encoder consumed it.

However, this mechanism did not allow a reset request to _interrupt_ the
encoder, which may be waiting on a blocking call (until a new frame is
produced).

To be able to interrupt the encoder, a reset request must not only set a
flag, but run a callback provided by the encoder. For that purpose,
introduce the CaptureListener interface, which is notified by the
SurfaceCapture implementation whenever the capture is invalidated.

For now, the listener implementation just set a flag as before, so the
behavior is unchanged. It lays the groundwork for the next commits.

PR Genymobile#5432 <Genymobile#5432>
bartsaintgermain pushed a commit to bartsaintgermain/scrcpy that referenced this pull request Apr 11, 2025
When the MediaCodec input is a Surface, no EOS (end-of-stream) will
never occur automatically: it may only be triggered manually by
MediaCodec.signalEndOfInputStream().

Use this signal to interrupt the blocking call to dequeueOutputBuffer()
immediately on reset, without waiting for the next frame to be dequeued.

PR Genymobile#5432 <Genymobile#5432>
bartsaintgermain pushed a commit to bartsaintgermain/scrcpy that referenced this pull request Apr 11, 2025
Reset video capture/encoding on MOD+Shift+r.

Like on device rotation, this starts a new encoding session which
produces a video stream starting by a key frame.

PR Genymobile#5432 <Genymobile#5432>
@yume-chan yume-chan mentioned this pull request Jun 5, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant