From 3486f59fe28efa81ce6951208b94cec91ad6cdb8 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 2 Dec 2012 00:22:54 +0100 Subject: core: automatically pause on low cache When the cache fill status goes below a certain threshold, automatically pause the player. When the cache is filled again, unpause again. This is intended to help with streaming from http. It's better to pause a while, rather than exposing extremely crappy behavior when packet reads during decoding block the entire player. In theory, we should try to increase the cache if underruns happen too often. Unfortunately, changing the cache implementation would be very hard, because it's insane code (forks, uses shared memory and "volatile" etc.). So for now, this just reduces the frequency of the stuttering if the network is absolutely too slow to play the stream in realtime. --- stream/cache2.c | 9 ++++++++- stream/stream.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'stream') diff --git a/stream/cache2.c b/stream/cache2.c index 8b35150321..7744f2cba9 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -93,6 +93,7 @@ typedef struct { volatile int control_res; volatile double stream_time_length; volatile double stream_time_pos; + volatile int idle; } cache_vars_t; static void cache_wakeup(stream_t *s) @@ -420,6 +421,7 @@ static void cache_mainloop(cache_vars_t *s) { #endif do { if (!cache_fill(s)) { + s->idle = 1; #if FORKED_CACHE // Let signal wake us up, we cannot leave this // enabled since we do not handle EINTR in most places. @@ -436,8 +438,10 @@ static void cache_mainloop(cache_vars_t *s) { sa.sa_handler = SIG_IGN; sigaction(SIGUSR1, &sa, NULL); #endif - } else + } else { sleep_count = 0; + s->idle = 0; + } } while (cache_execute_control(s)); } @@ -624,6 +628,9 @@ int cache_do_control(stream_t *stream, int cmd, void *arg) { case STREAM_CTRL_GET_CACHE_FILL: *(int64_t *)arg = s->max_filepos - s->read_filepos; return STREAM_OK; + case STREAM_CTRL_GET_CACHE_IDLE: + *(int *)arg = s->idle; + return STREAM_OK; case STREAM_CTRL_SEEK_TO_TIME: s->control_double_arg = *(double *)arg; s->control = cmd; diff --git a/stream/stream.h b/stream/stream.h index a112b0f3f6..9f2be2f817 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -100,6 +100,7 @@ #define STREAM_CTRL_GET_CURRENT_TITLE 14 #define STREAM_CTRL_GET_CACHE_SIZE 15 #define STREAM_CTRL_GET_CACHE_FILL 16 +#define STREAM_CTRL_GET_CACHE_IDLE 17 struct stream_lang_req { int type; // STREAM_AUDIO, STREAM_SUB -- cgit v1.2.3