aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-07-13 22:50:14 -0700
committerChris Robinson <[email protected]>2019-07-14 03:59:57 -0700
commitac7eeeae7997b6e75ec82dce610b524df33d6f8b (patch)
tree7f38b35149007ce0f0e7417bb8a1ab37ba3d457e /examples
parent93c53e33f040851489db6f3704e3350a650f84f4 (diff)
Don't use the same mutex for the video clock
Diffstat (limited to 'examples')
-rw-r--r--examples/alffplay.cpp30
1 files changed, 14 insertions, 16 deletions
diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp
index 1a509c92..625c63a6 100644
--- a/examples/alffplay.cpp
+++ b/examples/alffplay.cpp
@@ -338,6 +338,7 @@ struct VideoState {
*/
nanoseconds mDisplayPts{0};
microseconds mDisplayPtsTime{microseconds::min()};
+ std::mutex mDispPtsMutex;
/* Swscale context for format conversion */
SwsContextPtr mSwscaleCtx;
@@ -1104,7 +1105,7 @@ finish:
nanoseconds VideoState::getClock()
{
/* NOTE: This returns incorrect times while not playing. */
- std::lock_guard<std::mutex> _{mPictQMutex};
+ std::lock_guard<std::mutex> _{mDispPtsMutex};
if(mDisplayPtsTime == microseconds::min())
return nanoseconds::zero();
auto delta = get_avtime() - mDisplayPtsTime;
@@ -1154,19 +1155,20 @@ void VideoState::display(SDL_Window *screen, SDL_Renderer *renderer)
*/
void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer)
{
- std::unique_lock<std::mutex> lock{mPictQMutex};
Picture *vp{&mPictQ[mPictQRead]};
+
+ std::unique_lock<std::mutex> lock{mPictQMutex};
auto clocktime = mMovie.getMasterClock();
bool updated{false};
while(mPictQSize > 0)
{
size_t nextIdx{(mPictQRead+1)%mPictQ.size()};
- Picture *newvp{&mPictQ[nextIdx]};
- if(clocktime < newvp->mPts)
+ Picture *nextvp{&mPictQ[nextIdx]};
+ if(clocktime < nextvp->mPts)
break;
- vp = newvp;
+ vp = nextvp;
updated = true;
mPictQRead = nextIdx;
@@ -1181,6 +1183,7 @@ void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer)
return;
}
lock.unlock();
+
if(updated)
{
mPictQCond.notify_all();
@@ -1264,7 +1267,6 @@ void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer)
SDL_UnlockTexture(mImage);
}
}
- av_frame_unref(vp->mFrame.get());
}
/* Show the picture! */
@@ -1272,17 +1274,13 @@ void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer)
if(updated)
{
- lock.lock();
+ auto disp_time = get_avtime();
+
+ std::lock_guard<std::mutex> _{mDispPtsMutex};
mDisplayPts = vp->mPts;
- mDisplayPtsTime = get_avtime();
- if(mEOS.load(std::memory_order_acquire) && mPictQSize == 0)
- {
- mFinalUpdate = true;
- mPictQCond.notify_all();
- }
- lock.unlock();
+ mDisplayPtsTime = disp_time;
}
- else if(mEOS.load(std::memory_order_acquire))
+ if(mEOS.load(std::memory_order_acquire))
{
lock.lock();
if(mPictQSize == 0)
@@ -1297,7 +1295,7 @@ void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer)
int VideoState::handler()
{
{
- std::lock_guard<std::mutex> _{mPictQMutex};
+ std::lock_guard<std::mutex> _{mDispPtsMutex};
mDisplayPtsTime = get_avtime();
}