Skip to content

Fix: Mali GPU Deadlock ANR on Stream Stop - #2185

Open
krishnasen2401 wants to merge 1 commit into
pedroSG94:masterfrom
krishnasen2401:fix-anr-deadlock
Open

Fix: Mali GPU Deadlock ANR on Stream Stop#2185
krishnasen2401 wants to merge 1 commit into
pedroSG94:masterfrom
krishnasen2401:fix-anr-deadlock

Conversation

@krishnasen2401

@krishnasen2401 krishnasen2401 commented Aug 24, 2026

Copy link
Copy Markdown

Although #2058 was closed previously, the deadlock still occurs on Mali GPUs because the video source is stopped before the GL interface is unbound in StreamBase.kt.

  • StreamBase.kt: Stop GlStreamInterface before stopping video and audio sources to release buffers.
  • GlStreamInterface.kt: Render preview surface first to prevent hardware encoder back-pressure from freezing the preview.
  • GlStreamInterface.kt / OpenGlView.kt: Implement synchronous teardown using a CountDownLatch to ensure all EGL surfaces are fully released before proceeding with stream stop.

@krishnasen2401
krishnasen2401 marked this pull request as draft August 24, 2026 16:19
@krishnasen2401
krishnasen2401 deleted the fix-anr-deadlock branch August 24, 2026 16:20
@krishnasen2401
krishnasen2401 restored the fix-anr-deadlock branch August 24, 2026 16:20
Although pedroSG94#2058 was closed previously, the deadlock still occurs on Mali GPUs because the video source is stopped before the GL interface is unbound in StreamBase.kt.

- StreamBase.kt: Stop GlStreamInterface before stopping video and audio sources to release buffers.
- GlStreamInterface.kt: Render preview surface first to prevent hardware encoder back-pressure from freezing the preview.
- GlStreamInterface.kt / OpenGlView.kt: Implement synchronous teardown using a CountDownLatch to ensure all EGL surfaces are fully released before proceeding with stream stop.
@krishnasen2401
krishnasen2401 marked this pull request as ready for review August 24, 2026 16:32
@pedroSG94

pedroSG94 commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Hello,

The PR was no developed on master branch removing multiple recent commits and it is not compiling. Also, the way to stop/start is really weird (do sleeps and wait that the fix works with random timers is not the correct way to fix a race conditions produced by async code).

Can you test that the ANR still happens using this commit? I added the code of the PR that could be useful for the case here (stop encoders before the gl thread):

  implementation "com.github.pedroSG94.RootEncoder:library:0c3e1ee1db"

This basically is master with a bit of code added.

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.

2 participants