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.
This commit is contained in:
parent
f1a970e680
commit
f3aa08aad9
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user