Use a proper flag to indicate audio is prepared in alffplay
This commit is contained in:
parent
e4b76d2627
commit
0aa0f24dd7
@ -264,6 +264,7 @@ struct AudioState {
|
|||||||
std::mutex mSrcMutex;
|
std::mutex mSrcMutex;
|
||||||
std::condition_variable mSrcCond;
|
std::condition_variable mSrcCond;
|
||||||
std::atomic_flag mConnected;
|
std::atomic_flag mConnected;
|
||||||
|
std::atomic<bool> mPrepared{false};
|
||||||
ALuint mSource{0};
|
ALuint mSource{0};
|
||||||
std::vector<ALuint> mBuffers;
|
std::vector<ALuint> mBuffers;
|
||||||
ALsizei mBufferIdx{0};
|
ALsizei mBufferIdx{0};
|
||||||
@ -293,7 +294,7 @@ struct AudioState {
|
|||||||
return getClockNoLock();
|
return getClockNoLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isBufferFilled();
|
bool isBufferFilled() const { return mPrepared.load(); }
|
||||||
void startPlayback();
|
void startPlayback();
|
||||||
|
|
||||||
int getSync();
|
int getSync();
|
||||||
@ -485,16 +486,6 @@ nanoseconds AudioState::getClockNoLock()
|
|||||||
return std::max(pts, nanoseconds::zero());
|
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()
|
void AudioState::startPlayback()
|
||||||
{
|
{
|
||||||
alSourcePlay(mSource);
|
alSourcePlay(mSource);
|
||||||
@ -1070,9 +1061,13 @@ int AudioState::handler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* (re)start the source if needed, and wait for a buffer to finish */
|
/* (re)start the source if needed, and wait for a buffer to finish */
|
||||||
if(state != AL_PLAYING && state != AL_PAUSED &&
|
if(state != AL_PLAYING && state != AL_PAUSED)
|
||||||
mMovie.mPlaying.load(std::memory_order_relaxed))
|
{
|
||||||
startPlayback();
|
if(mMovie.mPlaying.load(std::memory_order_relaxed))
|
||||||
|
startPlayback();
|
||||||
|
else
|
||||||
|
mPrepared.store(true);
|
||||||
|
}
|
||||||
|
|
||||||
mSrcCond.wait_for(srclock, sleep_time);
|
mSrcCond.wait_for(srclock, sleep_time);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user