summaryrefslogtreecommitdiff
path: root/ffplay.c
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2012-08-28 00:00:15 +0200
committerMarton Balint <cus@passwd.hu>2012-08-31 21:00:20 +0200
commit0e5042be284182823223a8c3d0006298ba16c921 (patch)
treededadc04d0cddb4293150d204dc8ee061e96662d /ffplay.c
parent4a45e722e373c85cae7b5d57fb6bb7e295e664e0 (diff)
ffplay: replace SDL_delay in read thread with SDL_CondWait
When the audio queue was empty, it was not filled until the 10ms delay expired in the read thread. This patch changes the delay method with a condition wait, which reacts to an empty queue a lot faster, therefore the audio buffer underruns become less common especially after seeking. Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'ffplay.c')
-rw-r--r--ffplay.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/ffplay.c b/ffplay.c
index 2157131f21..861080c2b9 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -237,6 +237,8 @@ typedef struct VideoState {
int refresh;
int last_video_stream, last_audio_stream, last_subtitle_stream;
+
+ SDL_cond *continue_read_thread;
} VideoState;
typedef struct AllocEventProps {
@@ -919,6 +921,7 @@ static void stream_close(VideoState *is)
SDL_DestroyCond(is->pictq_cond);
SDL_DestroyMutex(is->subpq_mutex);
SDL_DestroyCond(is->subpq_cond);
+ SDL_DestroyCond(is->continue_read_thread);
#if !CONFIG_AVFILTER
if (is->img_convert_ctx)
sws_freeContext(is->img_convert_ctx);
@@ -2055,6 +2058,9 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
return -1;
}
+ if (is->audioq.nb_packets == 0)
+ SDL_CondSignal(is->continue_read_thread);
+
/* read next packet */
if ((new_packet = packet_queue_get(&is->audioq, pkt, 1)) < 0)
return -1;
@@ -2371,6 +2377,7 @@ static int read_thread(void *arg)
AVDictionaryEntry *t;
AVDictionary **opts;
int orig_nb_streams;
+ SDL_mutex *wait_mutex = SDL_CreateMutex();
memset(st_index, -1, sizeof(st_index));
is->last_video_stream = is->video_stream = -1;
@@ -2538,7 +2545,9 @@ static int read_thread(void *arg)
&& (is->videoq .nb_packets > MIN_FRAMES || is->video_stream < 0 || is->videoq.abort_request)
&& (is->subtitleq.nb_packets > MIN_FRAMES || is->subtitle_stream < 0 || is->subtitleq.abort_request)))) {
/* wait 10 ms */
- SDL_Delay(10);
+ SDL_LockMutex(wait_mutex);
+ SDL_CondWaitTimeout(is->continue_read_thread, wait_mutex, 10);
+ SDL_UnlockMutex(wait_mutex);
continue;
}
if (eof) {
@@ -2619,6 +2628,7 @@ static int read_thread(void *arg)
event.user.data1 = is;
SDL_PushEvent(&event);
}
+ SDL_DestroyMutex(wait_mutex);
return 0;
}
@@ -2645,6 +2655,8 @@ static VideoState *stream_open(const char *filename, AVInputFormat *iformat)
packet_queue_init(&is->audioq);
packet_queue_init(&is->subtitleq);
+ is->continue_read_thread = SDL_CreateCond();
+
is->av_sync_type = av_sync_type;
is->read_tid = SDL_CreateThread(read_thread, is);
if (!is->read_tid) {