aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-12-27 15:26:11 -0800
committerChris Robinson <[email protected]>2021-12-27 15:26:11 -0800
commitf3aa08aad9af64ceeababa9a937a5d6175865ee4 (patch)
treec66cb184b7d7ad7a6e46e7b92b0037d7a26c160a
parentf1a970e6804ad1d95b70dd44662ef2aa180438f0 (diff)
Make sure alffplay properly stops when quiting
The parser thread could be waiting on the threads to join after queueing all packets, so it wouldn't see mQuit to flush the queue. So make a stop method that forces a flush when setting mQuit.
-rw-r--r--examples/alffplay.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp
index 7f068e0d..b9739e7b 100644
--- a/examples/alffplay.cpp
+++ b/examples/alffplay.cpp
@@ -293,7 +293,7 @@ public:
{
{
std::unique_lock<std::mutex> lock{mPacketMutex};
- if(mTotalSize >= SizeLimit)
+ if(mTotalSize >= SizeLimit || mFinished)
return false;
mPackets.push_back(AVPacketPtr{av_packet_alloc()});
@@ -478,7 +478,7 @@ struct MovieState {
{ }
~MovieState()
{
- mQuit = true;
+ stop();
if(mParseThread.joinable())
mParseThread.join();
}
@@ -486,6 +486,7 @@ struct MovieState {
static int decode_interrupt_cb(void *ctx);
bool prepare();
void setTitle(SDL_Window *window);
+ void stop();
nanoseconds getClock();
@@ -1890,11 +1891,6 @@ int MovieState::parse_handler()
av_packet_unref(packet.get());
}
- if(mQuit.load(std::memory_order_relaxed))
- {
- video_queue.flush();
- audio_queue.flush();
- }
/* Finish the queues so the receivers know nothing more is coming. */
video_queue.setFinished();
audio_queue.setFinished();
@@ -1918,6 +1914,13 @@ int MovieState::parse_handler()
return 0;
}
+void MovieState::stop()
+{
+ mQuit = true;
+ mAudio.mQueue.flush();
+ mVideo.mQueue.flush();
+}
+
// Helper class+method to print the time with human-readable formatting.
struct PrettyTime {
@@ -2161,12 +2164,12 @@ int main(int argc, char *argv[])
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
- movState->mQuit = true;
+ movState->stop();
eom_action = EomAction::Quit;
break;
case SDLK_n:
- movState->mQuit = true;
+ movState->stop();
eom_action = EomAction::Next;
break;
@@ -2194,7 +2197,7 @@ int main(int argc, char *argv[])
break;
case SDL_QUIT:
- movState->mQuit = true;
+ movState->stop();
eom_action = EomAction::Quit;
break;