aboutsummaryrefslogtreecommitdiffstats
path: root/examples/alffplay.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-07-20 01:10:14 -0700
committerChris Robinson <[email protected]>2019-07-20 01:10:14 -0700
commitf0ed35d3d0fb35a9ff0dbcecc90d5c75a7618ca1 (patch)
tree6372569f3ed5eae90d6ed237bcebf203a47bf567 /examples/alffplay.cpp
parent9959d661a02b8d140dfc43b2aa1c6bfa40a5af18 (diff)
Set the initial clock time closer to starting playback
Diffstat (limited to 'examples/alffplay.cpp')
-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)};