Skip to content

Audio decode thread and InitDecoder can exit without DetachCurrentThread #15

Description

@QiuYucheng2003

In app/src/main/cpp/player/HWCodecPlayer.cpp, AudioDecodeThreadProc and InitDecoder both run on a std::thread. GetJNIEnv attaches that thread and sets isAttach = true. Two early exits skip the matching DetachCurrentThread, so the thread can exit while still attached to the JVM.

· AudioDecodeThreadProc: stop and an empty packet queue use break and still reach the detach at line 364. If avcodec_send_packet fails, line 308 returns and skips it.

· InitDecoder is a do ... while (false). break before GetJNIEnv (line 546) is fine, because the thread is not attached yet. After that, the breaks at line 559 (AMediaExtractor_setDataSourceFd failure) and line 588 (m_MediaCodec == nullptr) skip the detach at line 591. The break at line 573 only leaves the for loop. PostMessage later sees the thread already attached and does not detach it either.

Fix both exits so every path that set isAttach calls DetachCurrentThread before the thread returns.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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