diff options
author | Chris Robinson <[email protected]> | 2019-03-01 22:46:56 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-03-01 22:46:56 -0800 |
commit | 0aa0f24dd749fecadade906ce58f56b6726c0f20 (patch) | |
tree | a4b9d49c1875df35a897117bffa3102da920cae5 /examples/alffplay.cpp | |
parent | e4b76d26271931d1207538cbfbfb92facad0e9c7 (diff) |
Use a proper flag to indicate audio is prepared in alffplay
Diffstat (limited to 'examples/alffplay.cpp')
-rw-r--r-- | examples/alffplay.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index 31099c75..6298cb43 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -264,6 +264,7 @@ struct AudioState { std::mutex mSrcMutex; std::condition_variable mSrcCond; std::atomic_flag mConnected; + std::atomic<bool> mPrepared{false}; ALuint mSource{0}; std::vector<ALuint> mBuffers; ALsizei mBufferIdx{0}; @@ -293,7 +294,7 @@ struct AudioState { return getClockNoLock(); } - bool isBufferFilled(); + bool isBufferFilled() const { return mPrepared.load(); } void startPlayback(); int getSync(); @@ -485,16 +486,6 @@ nanoseconds AudioState::getClockNoLock() return std::max(pts, nanoseconds::zero()); } -bool AudioState::isBufferFilled() -{ - /* All of OpenAL's buffer queueing happens under the mSrcMutex lock, as - * does the source gen. So when we're able to grab the lock and the source - * is valid, the queue must be full. - */ - std::lock_guard<std::mutex> lock(mSrcMutex); - return mSource != 0; -} - void AudioState::startPlayback() { alSourcePlay(mSource); @@ -1070,9 +1061,13 @@ int AudioState::handler() } /* (re)start the source if needed, and wait for a buffer to finish */ - if(state != AL_PLAYING && state != AL_PAUSED && - mMovie.mPlaying.load(std::memory_order_relaxed)) - startPlayback(); + if(state != AL_PLAYING && state != AL_PAUSED) + { + if(mMovie.mPlaying.load(std::memory_order_relaxed)) + startPlayback(); + else + mPrepared.store(true); + } mSrcCond.wait_for(srclock, sleep_time); } |