Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决Android使用AudioTrack播放时,因为多线程同步问题导致的AudioTrack没有调用play的问题 #4879

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

xiaoxia1992
Copy link

多线程问题分析:

  1. if (!opaque->abort_request && !opaque->pause_on) 执行到这里时,opaque->pause_on为true,此时不会调用AudioTrack.play方法
  2. 接着进入循环while (!opaque->abort_request) ,此时,外部调用了aout_pause_audio方法,opaque->pause_on变成了false,下面的代码不成立,因此不会调用AudioTrack.play方法
if (!opaque->abort_request && opaque->pause_on) {
            SDL_Android_AudioTrack_pause(env, atrack);
            while (!opaque->abort_request && opaque->pause_on) {
                SDL_CondWaitTimeout(opaque->wakeup_cond, opaque->wakeup_mutex, 1000);
            }
            if (!opaque->abort_request && !opaque->pause_on) {
                if (opaque->need_flush) {
                    opaque->need_flush = 0;
                    SDL_Android_AudioTrack_flush(env, atrack);
                }
                SDL_Android_AudioTrack_play(env, atrack);
            }
        }

后面就一直不会调用AudioTrack.play方法,除非再次调用aout_pause_audio方法。

这个多线程问题,在比较低端的机型上容易出现,我们这边实在TV上出现的

@xiaoxia1992 xiaoxia1992 changed the title 解决Android使用AudioTrack播放时,因为多线程不同步导致的AudioTrack没有调用play的问题 解决Android使用AudioTrack播放时,因为多线程同步问题导致的AudioTrack没有调用play的问题 Oct 21, 2019
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