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.
This commit is contained in:
wm4 2014-11-12 21:47:41 +01:00
parent be9eb08389
commit 09e08bfe2e
1 changed files with 11 additions and 1 deletions

View File

@ -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: