summaryrefslogtreecommitdiffstats
path: root/demux/demux.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-11-12 21:47:41 +0100
committerwm4 <wm4@nowhere>2014-11-12 21:47:41 +0100
commit09e08bfe2e1502c4772c94080b49ddf30a27fd69 (patch)
tree2b0d31b8732298366f94604e7647f10b9ffeb317 /demux/demux.c
parentbe9eb083894f207cd390bf7de77f762d754f9a7c (diff)
downloadmpv-09e08bfe2e1502c4772c94080b49ddf30a27fd69.tar.bz2
mpv-09e08bfe2e1502c4772c94080b49ddf30a27fd69.tar.xz
demux: update cache state when paused
This was removed in commit 480f82fa. This caused the cache display not to update while paused, because the update_cache() function is never called in the thread (now I remember why the extra call was "needed"). The old implementation intentionally run update_cache() only before waiting on a mutex, with no further checks for the condition variable. In theory, this is strictly not sane, but since it was just for the retrieval of the very fuzzy cache status, it was ok. Now we want to call update_cache() outside of the mutex though - which means that in order to avoid missed wakeups, a proper condition has to be used.
Diffstat (limited to 'demux/demux.c')
-rw-r--r--demux/demux.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/demux/demux.c b/demux/demux.c
index d3e9b43903..95d35034eb 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -123,6 +123,7 @@ struct demux_internal {
double seek_pts;
// Cached state.
+ bool force_cache_update;
double time_length;
struct mp_tags *stream_metadata;
int64_t stream_size;
@@ -481,6 +482,13 @@ static void *demux_thread(void *pctx)
if (read_packet(in))
continue; // read_packet unlocked, so recheck conditions
}
+ if (in->force_cache_update) {
+ pthread_mutex_unlock(&in->lock);
+ update_cache(in);
+ pthread_mutex_lock(&in->lock);
+ in->force_cache_update = false;
+ continue;
+ }
pthread_cond_signal(&in->wakeup);
pthread_cond_wait(&in->wakeup, &in->lock);
}
@@ -1157,8 +1165,10 @@ static void update_cache(struct demux_internal *in)
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)
+ if (in->stream_cache_size >= 0) {
+ in->force_cache_update = true;
pthread_cond_signal(&in->wakeup);
+ }
switch (cmd) {
case STREAM_CTRL_GET_CACHE_SIZE: