From a8513f8b37343c27a4abea380ae0aa6bbae3894c Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 27 Aug 2014 00:20:38 +0200 Subject: demux: reduce wakeups if no cache is active The purpose of the unconditional pthread_cond_signal() when reading cached DEMUXER_CTRLs and STREAM_CTRLs was apparently to update the stream cache state. Otherwise, the cached fields would never be updated when the stream is e.g. paused. The same could be said about other CTRLs, but these aren't as important, since they are normally updated while reading packet data. In order to reduce wakeups, make this logic explicit. --- demux/demux.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/demux/demux.c b/demux/demux.c index f27b8d1855..e54027cc9d 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -1112,6 +1112,10 @@ static void update_cache(struct demux_internal *in) // must be called locked static int cached_stream_control(struct demux_internal *in, int cmd, void *arg) { + // If the cache is active, wake up the thread to possibly update cache state. + if (in->stream_cache_size >= 0) + pthread_cond_signal(&in->wakeup); + switch (cmd) { case STREAM_CTRL_GET_CACHE_SIZE: if (in->stream_cache_size < 0) @@ -1156,6 +1160,7 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg) } case DEMUXER_CTRL_SWITCHED_TRACKS: in->tracks_switched = true; + pthread_cond_signal(&in->wakeup); return DEMUXER_CTRL_OK; } return DEMUXER_CTRL_DONTKNOW; @@ -1167,7 +1172,6 @@ int demux_control(demuxer_t *demuxer, int cmd, void *arg) if (in->threading) { pthread_mutex_lock(&in->lock); - pthread_cond_signal(&in->wakeup); int cr = cached_demux_control(in, cmd, arg); pthread_mutex_unlock(&in->lock); if (cr != DEMUXER_CTRL_DONTKNOW) -- cgit v1.2.3