Skip to content

ANR when stopping stream on some devices due to blocking codec/camera/GL teardown #2058

@anilateapp

Description

@anilateapp

Describe the bug
On some devices, stopping an active stream can block long enough to freeze the UI and trigger ANR.

This does not appear to be related to stream connection or encoder selection. The issue seems to happen during the stop/release path, when the library is tearing down codec, camera, and GL resources.

In practice:

  • stream starts and runs normally
  • user presses Stop
  • UI may freeze for several seconds
  • in some cases this results in ANR

This looks like a lifecycle / teardown problem rather than a connection problem.

To Reproduce

  1. Start an RTMP stream on the affected device (Tecno spark 30c - HiOS v14.5.0)
  2. Wait until the stream is running normally
  3. Stop the stream
  4. Observe that the app may freeze during stop
  5. In some cases Android reports ANR

Expected behavior
Stopping a stream should return control to the UI quickly and should not block long enough to trigger ANR.

Screenshots
N/A

Smartphone (please complete the following information):

  • Library version: 2.7.1
  • Device: [your device model here]
  • OS: [your Android version here]
  • Media server: [your RTMP server here]
  • Class used: GenericStream

Additional context
From local investigation, the freeze seems to be caused by blocking operations during teardown, including one or more of:

  • MediaCodec.start()/flush()/stop()/release()
  • camera open/close callbacks
  • encoder EGL surface add/remove
  • stream stop being executed from the UI path

What helped locally:

  • moving stream operations off the main thread
  • adding timeout protection around blocking MediaCodec operations
  • running encoder EGL surface add/remove on the GL executor thread
  • guarding Camera2 open/close flow against stale or delayed callbacks

So far I am reporting this separately from the secure AVC encoder issue, because this seems to be a broader stop/lifecycle robustness problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions