From cfe1af72af0ca2a92257ef542209be61709ac34f Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 12 Jun 2011 11:26:22 +0000 Subject: cache: allow STREAM_CTRL_GET_CURRENT_TIME with cache Change code to allow STREAM_CTRL_GET_CURRENT_TIME with cache enabled. Due to that time being from what is currently read into the cache it is unfortunately somewhat inaccurate and unsmooth, however for streams that do have stream timestamps it is till a lot better than going by the demuxer alone. In particular it fixes bug #1081, when starting a DVD with -chapter following seeks would be relative to the start of the DVD instead of the current position. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33605 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/stream/cache2.c b/stream/cache2.c index 6a8b7c7a70..b643ed8897 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -64,6 +64,7 @@ static void *ThreadProc(void *s); #include "stream.h" #include "cache2.h" +#include "mpcommon.h" typedef struct { // constats: @@ -91,6 +92,7 @@ typedef struct { volatile int control_res; volatile off_t control_new_pos; volatile double stream_time_length; + volatile double stream_time_pos; } cache_vars_t; static int min_fill=0; @@ -260,17 +262,22 @@ static int cache_execute_control(cache_vars_t *s) { int quit = s->control == -2; if (quit || !s->stream->control) { s->stream_time_length = 0; + s->stream_time_pos = MP_NOPTS_VALUE; s->control_new_pos = 0; s->control_res = STREAM_UNSUPPORTED; s->control = -1; return !quit; } if (GetTimerMS() - last > 99) { - double len; + double len, pos; if (s->stream->control(s->stream, STREAM_CTRL_GET_TIME_LENGTH, &len) == STREAM_OK) s->stream_time_length = len; else s->stream_time_length = 0; + if (s->stream->control(s->stream, STREAM_CTRL_GET_CURRENT_TIME, &pos) == STREAM_OK) + s->stream_time_pos = pos; + else + s->stream_time_pos = MP_NOPTS_VALUE; last = GetTimerMS(); } if (s->control == -1) return 1; @@ -581,11 +588,13 @@ int cache_do_control(stream_t *stream, int cmd, void *arg) { s->control_uint_arg = *(unsigned *)arg; s->control = cmd; break; + // the core might call these every frame, so cache them... case STREAM_CTRL_GET_TIME_LENGTH: *(double *)arg = s->stream_time_length; return s->stream_time_length ? STREAM_OK : STREAM_UNSUPPORTED; -// the core might call this every frame, but it is too slow for this... -// case STREAM_CTRL_GET_CURRENT_TIME: + case STREAM_CTRL_GET_CURRENT_TIME: + *(double *)arg = s->stream_time_pos; + return s->stream_time_pos != MP_NOPTS_VALUE ? STREAM_OK : STREAM_UNSUPPORTED; case STREAM_CTRL_GET_NUM_CHAPTERS: case STREAM_CTRL_GET_CURRENT_CHAPTER: case STREAM_CTRL_GET_ASPECT_RATIO: -- cgit v1.2.3