Repository navigation
media: Fix crash in Decode-to-Texture pipeline - #13114
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a reference-counted GlesClosureRun structure to safely manage RunSbDecodeTargetFunctionOnGpu requests, preventing memory access issues when a caller times out and abandons a task. It also updates StarboardRendererWrapper to handle timeouts and retries, and adds initialization checks to DecodeTarget and MediaCodecVideoDecoder to prevent crashes. The review feedback correctly identifies a memory leak in MediaCodecVideoDecoder::InitializeCodec where calling AddRef() followed by Release() fails to free the acquired decode_target reference, and suggests using SbDecodeTargetRelease instead.
Contributor
🤖 Gemini Suggested Commit Message💡 Pro Tips for a Better Commit Message:
|
Contributor
|
kjyoun
reviewed
Oct 5, 2026
kjyoun
approved these changes
Oct 6, 2026
added 3 commits
October 6, 2026 19:25
On Android, SbPlayerCreate() in decode-to-texture mode constructs a
DecodeTarget whose GL texture / SurfaceTexture / Surface are created inside
a closure run through SbDecodeTargetRunInGlesContext(). That call is routed
to StarboardRendererWrapper::GraphicsContextRunner, which posts the closure
to the gpu thread via StarboardGpuFactoryImpl::RunSbDecodeTargetFunctionOnGpu.
If the gpu thread cannot make the command buffer's GL context current (the
stub was destroyed, or the context is not restorable yet after the app sat
idle), the closure is silently skipped. DecodeTarget's constructor then
returns with a null surface_texture_, and MediaCodecVideoDecoder::
InitializeCodec() passes it to VideoSurfaceTextureBridge::
SetOnFrameAvailableListener(), which aborts the process.
This change:
1. Makes RunSbDecodeTargetFunctionOnGpu() report the outcome of the request
through a shared, lock-protected GlesClosureRun (ran / no command buffer
stub / context could not be made current), and re-acquire the stub if it
was cleared by OnWillDestroyStub(), using the channel token / route id
cached in Initialize().
2. Makes the cross-thread path of GraphicsContextRunner() bounded and
honest about whether the closure ran. The gpu-thread path is unchanged.
- "context could not be made current" is transient (the context comes
back within a few hundred ms after idle), so it is retried every
100 ms for up to 1 s of wall-clock time.
- "no command buffer stub" is not retried: this is what a player sees
when it is torn down after its renderer lost the stub, and waiting
cannot help (an earlier draft retried here and stalled
SbPlayerDestroy() for ~5 s on every such teardown).
- Each request waits at most 2 s for the gpu thread. If the gpu thread
does not respond, the request is abandoned: the gpu task takes the
same lock before touching the context argument and sees |abandoned|,
so the caller's stack-owned context is never used after the caller
returns. Worst-case blocking of the caller is therefore ~2 s (wedged
gpu thread) or ~1 s plus one gpu round trip (persistent context loss);
the normal case is unchanged (one round trip).
3. Default-initializes DecodeTarget's native_window_/info_ and guards its
destructor so a target whose creation closure never ran can be freed, and
adds DecodeTarget::is_initialized().
4. Makes InitializeCodec() fail with a decode error (instead of a JNI abort)
if the decode target is still uninitialized after the retries. The output
mode is fixed at SbPlayerCreate() and cannot be renegotiated from inside
the decoder, so a decoder-side punch-out fallback would leave the renderer
polling an empty decode target; a decode error reaches the web app as a
normal player error, which can retry.
Bug: 490474392, 565889635
at-ninja
enabled auto-merge (squash)
October 6, 2026 19:30
briantting
pushed a commit
that referenced
this pull request
Oct 8, 2026
… pipeline Refer to original PR: #13114 On Android, SbPlayerCreate() in decode-to-texture mode constructs a DecodeTarget whose GL texture / SurfaceTexture / Surface are created inside a closure run through SbDecodeTargetRunInGlesContext(). That call is routed to StarboardRendererWrapper::GraphicsContextRunner, which posts the closure to the gpu thread via StarboardGpuFactoryImpl::RunSbDecodeTargetFunctionOnGpu. If the gpu thread cannot make the command buffer's GL context current (the stub was destroyed, or the context is not restorable yet after the app sat idle), the closure is silently skipped. DecodeTarget's constructor then returns with a null surface_texture_, and MediaCodecVideoDecoder:: InitializeCodec() passes it to VideoSurfaceTextureBridge:: SetOnFrameAvailableListener(), which aborts the process. This change: 1. Makes RunSbDecodeTargetFunctionOnGpu() report the outcome of the request through a shared, lock-protected GlesClosureRun (ran / no command buffer stub / context could not be made current), and re-acquire the stub if it was cleared by OnWillDestroyStub(), using the channel token / route id cached in Initialize(). 2. Makes the cross-thread path of GraphicsContextRunner() bounded and honest about whether the closure ran. The gpu-thread path is unchanged. - "context could not be made current" is transient (the context comes back within a few hundred ms after idle), so it is retried every 100 ms for up to 1 s of wall-clock time. - "no command buffer stub" is not retried: this is what a player sees when it is torn down after its renderer lost the stub, and waiting cannot help (an earlier draft retried here and stalled SbPlayerDestroy() for ~5 s on every such teardown). - Each request waits at most 2 s for the gpu thread. If the gpu thread does not respond, the request is abandoned: the gpu task takes the same lock before touching the context argument and sees |abandoned|, so the caller's stack-owned context is never used after the caller returns. Worst-case blocking of the caller is therefore ~2 s (wedged gpu thread) or ~1 s plus one gpu round trip (persistent context loss); the normal case is unchanged (one round trip). 3. Default-initializes DecodeTarget's native_window_/info_ and guards its destructor so a target whose creation closure never ran can be freed, and adds DecodeTarget::is_initialized(). 4. Makes InitializeCodec() fail with a decode error (instead of a JNI abort) if the decode target is still uninitialized after the retries. The output mode is fixed at SbPlayerCreate() and cannot be renegotiated from inside the decoder, so a decoder-side punch-out fallback would leave the renderer polling an empty decode target; a decode error reaches the web app as a normal player error, which can retry. Bug: 490474392 Bug: 565889635 --------- Co-authored-by: Drew Thomas <acthomas@google.com> (cherry picked from commit 1166e26)
briantting
pushed a commit
that referenced
this pull request
Oct 8, 2026
…re pipeline (#13205) Automated cherry-pick roll to staging. Original pull requests: - #13114 CONFLICTED files: ``` media/mojo/services/starboard/starboard_renderer_wrapper.cc ``` To merge these changes, run the autoroll script: ```bash GITHUB_REPOSITORY=youtube/cobalt python3 cobalt/devinfra/github/autoroll/merge_autoroll.py \ --source-branch main \ --target-branch staging ```⚠️ This PR has conflicts that must be resolved manually (don't forget to update the `.github/AUTOROLL` file). Use the following commands to checkout the branch locally and resolve the conflicts in a separate commit: ```bash gh pr checkout <pull_request_number> -R youtube/cobalt # Resolve conflicts and update .github/AUTOROLL then git add <resolved_files> # Copy CONFLICTED commit's message and metadata # Replace CONFLICTED in title with RESOLVED git commit -c <conflicted_sha> git push origin autoroll-main-to-staging ``` --------- Co-authored-by: Drew Thomas <async@google.com>
briantting
pushed a commit
that referenced
this pull request
Oct 16, 2026
Refer to original PR: #13114 On Android, SbPlayerCreate() in decode-to-texture mode constructs a DecodeTarget whose GL texture / SurfaceTexture / Surface are created inside a closure run through SbDecodeTargetRunInGlesContext(). That call is routed to StarboardRendererWrapper::GraphicsContextRunner, which posts the closure to the gpu thread via StarboardGpuFactoryImpl::RunSbDecodeTargetFunctionOnGpu. If the gpu thread cannot make the command buffer's GL context current (the stub was destroyed, or the context is not restorable yet after the app sat idle), the closure is silently skipped. DecodeTarget's constructor then returns with a null surface_texture_, and MediaCodecVideoDecoder:: InitializeCodec() passes it to VideoSurfaceTextureBridge:: SetOnFrameAvailableListener(), which aborts the process. This change: 1. Makes RunSbDecodeTargetFunctionOnGpu() report the outcome of the request through a shared, lock-protected GlesClosureRun (ran / no command buffer stub / context could not be made current), and re-acquire the stub if it was cleared by OnWillDestroyStub(), using the channel token / route id cached in Initialize(). 2. Makes the cross-thread path of GraphicsContextRunner() bounded and honest about whether the closure ran. The gpu-thread path is unchanged. - "context could not be made current" is transient (the context comes back within a few hundred ms after idle), so it is retried every 100 ms for up to 1 s of wall-clock time. - "no command buffer stub" is not retried: this is what a player sees when it is torn down after its renderer lost the stub, and waiting cannot help (an earlier draft retried here and stalled SbPlayerDestroy() for ~5 s on every such teardown). - Each request waits at most 2 s for the gpu thread. If the gpu thread does not respond, the request is abandoned: the gpu task takes the same lock before touching the context argument and sees |abandoned|, so the caller's stack-owned context is never used after the caller returns. Worst-case blocking of the caller is therefore ~2 s (wedged gpu thread) or ~1 s plus one gpu round trip (persistent context loss); the normal case is unchanged (one round trip). 3. Default-initializes DecodeTarget's native_window_/info_ and guards its destructor so a target whose creation closure never ran can be freed, and adds DecodeTarget::is_initialized(). 4. Makes InitializeCodec() fail with a decode error (instead of a JNI abort) if the decode target is still uninitialized after the retries. The output mode is fixed at SbPlayerCreate() and cannot be renegotiated from inside the decoder, so a decoder-side punch-out fallback would leave the renderer polling an empty decode target; a decode error reaches the web app as a normal player error, which can retry. Bug: 490474392 Bug: 565889635 --------- Co-authored-by: Drew Thomas <acthomas@google.com> (cherry picked from commit 1166e26)
briantting
pushed a commit
that referenced
this pull request
Oct 16, 2026
Refer to original PR: #13114 On Android, SbPlayerCreate() in decode-to-texture mode constructs a DecodeTarget whose GL texture / SurfaceTexture / Surface are created inside a closure run through SbDecodeTargetRunInGlesContext(). That call is routed to StarboardRendererWrapper::GraphicsContextRunner, which posts the closure to the gpu thread via StarboardGpuFactoryImpl::RunSbDecodeTargetFunctionOnGpu. If the gpu thread cannot make the command buffer's GL context current (the stub was destroyed, or the context is not restorable yet after the app sat idle), the closure is silently skipped. DecodeTarget's constructor then returns with a null surface_texture_, and MediaCodecVideoDecoder:: InitializeCodec() passes it to VideoSurfaceTextureBridge:: SetOnFrameAvailableListener(), which aborts the process. This change: 1. Makes RunSbDecodeTargetFunctionOnGpu() report the outcome of the request through a shared, lock-protected GlesClosureRun (ran / no command buffer stub / context could not be made current), and re-acquire the stub if it was cleared by OnWillDestroyStub(), using the channel token / route id cached in Initialize(). 2. Makes the cross-thread path of GraphicsContextRunner() bounded and honest about whether the closure ran. The gpu-thread path is unchanged. - "context could not be made current" is transient (the context comes back within a few hundred ms after idle), so it is retried every 100 ms for up to 1 s of wall-clock time. - "no command buffer stub" is not retried: this is what a player sees when it is torn down after its renderer lost the stub, and waiting cannot help (an earlier draft retried here and stalled SbPlayerDestroy() for ~5 s on every such teardown). - Each request waits at most 2 s for the gpu thread. If the gpu thread does not respond, the request is abandoned: the gpu task takes the same lock before touching the context argument and sees |abandoned|, so the caller's stack-owned context is never used after the caller returns. Worst-case blocking of the caller is therefore ~2 s (wedged gpu thread) or ~1 s plus one gpu round trip (persistent context loss); the normal case is unchanged (one round trip). 3. Default-initializes DecodeTarget's native_window_/info_ and guards its destructor so a target whose creation closure never ran can be freed, and adds DecodeTarget::is_initialized(). 4. Makes InitializeCodec() fail with a decode error (instead of a JNI abort) if the decode target is still uninitialized after the retries. The output mode is fixed at SbPlayerCreate() and cannot be renegotiated from inside the decoder, so a decoder-side punch-out fallback would leave the renderer polling an empty decode target; a decode error reaches the web app as a normal player error, which can retry. Bug: 490474392 Bug: 565889635 --------- Co-authored-by: Drew Thomas <acthomas@google.com> (cherry picked from commit 1166e26)
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.
On Android, SbPlayerCreate() in decode-to-texture mode constructs a DecodeTarget whose GL texture / SurfaceTexture / Surface are created inside a closure run through SbDecodeTargetRunInGlesContext(). That call is routed to StarboardRendererWrapper::GraphicsContextRunner, which posts the closure to the gpu thread via StarboardGpuFactoryImpl::RunSbDecodeTargetFunctionOnGpu. If the gpu thread cannot make the command buffer's GL context current (the stub was destroyed, or the context is not restorable yet after the app sat idle), the closure is silently skipped. DecodeTarget's constructor then returns with a null surface_texture_, and MediaCodecVideoDecoder:: InitializeCodec() passes it to VideoSurfaceTextureBridge:: SetOnFrameAvailableListener(), which aborts the process.
This change:
Bug: 490474392
Bug: 565889635