aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/alffplay.cpp28
1 files changed, 13 insertions, 15 deletions
diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp
index 1f2c7d6c..063ea157 100644
--- a/examples/alffplay.cpp
+++ b/examples/alffplay.cpp
@@ -748,19 +748,10 @@ void AL_APIENTRY AudioState::EventCallback(ALenum eventType, ALuint object, ALui
int AudioState::handler()
{
- std::unique_lock<std::mutex> srclock{mSrcMutex};
+ std::unique_lock<std::mutex> srclock{mSrcMutex, std::defer_lock};
milliseconds sleep_time{AudioBufferTime / 3};
ALenum fmt;
- if(alcGetInteger64vSOFT)
- {
- int64_t devtime{};
- alcGetInteger64vSOFT(alcGetContextsDevice(alcGetCurrentContext()), ALC_DEVICE_CLOCK_SOFT,
- 1, &devtime);
- mDeviceStartTime = nanoseconds{devtime} - mCurrentPts;
- }
- srclock.unlock();
-
#ifdef AL_SOFT_events
const std::array<ALenum,6> evt_types{{
AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT, AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT,
@@ -1012,6 +1003,13 @@ int AudioState::handler()
mPackets.sendTo(mCodecCtx.get());
srclock.lock();
+ if(alcGetInteger64vSOFT)
+ {
+ int64_t devtime{};
+ alcGetInteger64vSOFT(alcGetContextsDevice(alcGetCurrentContext()), ALC_DEVICE_CLOCK_SOFT,
+ 1, &devtime);
+ mDeviceStartTime = nanoseconds{devtime} - mCurrentPts;
+ }
while(alGetError() == AL_NO_ERROR && !mMovie.mQuit.load(std::memory_order_relaxed) &&
mConnected.test_and_set(std::memory_order_relaxed))
{
@@ -1301,11 +1299,6 @@ void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer)
int VideoState::handler()
{
- {
- std::lock_guard<std::mutex> _{mDispPtsMutex};
- mDisplayPtsTime = get_avtime();
- }
-
std::for_each(mPictQ.begin(), mPictQ.end(),
[](Picture &pict) -> void
{ pict.mFrame = AVFramePtr{av_frame_alloc()}; });
@@ -1313,6 +1306,11 @@ int VideoState::handler()
/* Prefill the codec buffer. */
mPackets.sendTo(mCodecCtx.get());
+ {
+ std::lock_guard<std::mutex> _{mDispPtsMutex};
+ mDisplayPtsTime = get_avtime();
+ }
+
while(!mMovie.mQuit.load(std::memory_order_relaxed))
{
size_t write_idx{mPictQWrite.load(std::memory_order_relaxed)};