From 5560a0b358e7cda887f4b7aac96a84e3270b5c6e Mon Sep 17 00:00:00 2001 From: reimar Date: Sat, 24 May 2008 07:48:35 +0000 Subject: Add basic support for stream controls with cache enabled. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@26865 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'stream/cache2.c') diff --git a/stream/cache2.c b/stream/cache2.c index 84a58272df..584af1faf4 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -7,6 +7,7 @@ #define READ_USLEEP_TIME 10000 #define FILL_USLEEP_TIME 50000 #define PREFILL_SLEEP_TIME 200 +#define CONTROL_SLEEP_TIME 0 #include #include @@ -57,6 +58,11 @@ typedef struct { // int fifo_flag; // 1 if we should use FIFO to notice cache about buffer reads. // callback stream_t* stream; + volatile int control; + volatile unsigned control_uint_arg; + volatile double control_double_arg; + volatile int control_res; + volatile off_t control_new_pos; } cache_vars_t; static int min_fill=0; @@ -191,6 +197,31 @@ int cache_fill(cache_vars_t* s){ } +static void cache_execute_control(cache_vars_t *s) { + if (s->control == -1) return; + switch (s->control) { + case STREAM_CTRL_GET_TIME_LENGTH: + case STREAM_CTRL_GET_CURRENT_TIME: + case STREAM_CTRL_SEEK_TO_TIME: + case STREAM_CTRL_GET_ASPECT_RATIO: + s->control_res = s->stream->control(s->stream, s->control, &s->control_double_arg); + break; + case STREAM_CTRL_SEEK_TO_CHAPTER: + case STREAM_CTRL_GET_NUM_CHAPTERS: + case STREAM_CTRL_GET_CURRENT_CHAPTER: + case STREAM_CTRL_GET_NUM_ANGLES: + case STREAM_CTRL_GET_ANGLE: + case STREAM_CTRL_SET_ANGLE: + s->control_res = s->stream->control(s->stream, s->control, &s->control_uint_arg); + break; + default: + s->control_res = STREAM_UNSUPPORTED; + break; + } + s->control_new_pos = s->stream->pos; + s->control = -1; +} + cache_vars_t* cache_init(int size,int sector){ int num; #if !defined(WIN32) && !defined(__OS2__) @@ -331,6 +362,7 @@ static void ThreadProc( void *s ){ if(!cache_fill((cache_vars_t*)s)){ usec_sleep(FILL_USLEEP_TIME); // idle } + cache_execute_control((cache_vars_t*)s); // cache_stats(s->cache_data); } } @@ -384,3 +416,51 @@ int cache_stream_seek_long(stream_t *stream,off_t pos){ mp_msg(MSGT_CACHE,MSGL_V,"cache_stream_seek: WARNING! Can't seek to 0x%"PRIX64" !\n",(int64_t)(pos+newpos)); return 0; } + +int cache_do_control(stream_t *stream, int cmd, void *arg) { + cache_vars_t* s = stream->cache_data; + switch (cmd) { + case STREAM_CTRL_SEEK_TO_TIME: + s->control_double_arg = *(double *)arg; + s->control = cmd; + break; + case STREAM_CTRL_SEEK_TO_CHAPTER: + case STREAM_CTRL_SET_ANGLE: + s->control_uint_arg = *(unsigned *)arg; + s->control = cmd; + break; + case STREAM_CTRL_GET_NUM_CHAPTERS: + case STREAM_CTRL_GET_CURRENT_CHAPTER: +// the core might call these every frame, they are too slow for this... +// case STREAM_CTRL_GET_TIME_LENGTH: +// case STREAM_CTRL_GET_CURRENT_TIME: + case STREAM_CTRL_GET_ASPECT_RATIO: + case STREAM_CTRL_GET_NUM_ANGLES: + case STREAM_CTRL_GET_ANGLE: + s->control = cmd; + break; + default: + return STREAM_UNSUPPORTED; + } + while (s->control != -1) + usec_sleep(CONTROL_SLEEP_TIME); + switch (cmd) { + case STREAM_CTRL_GET_TIME_LENGTH: + case STREAM_CTRL_GET_CURRENT_TIME: + case STREAM_CTRL_GET_ASPECT_RATIO: + *(double *)arg = s->control_double_arg; + break; + case STREAM_CTRL_GET_NUM_CHAPTERS: + case STREAM_CTRL_GET_CURRENT_CHAPTER: + case STREAM_CTRL_GET_NUM_ANGLES: + case STREAM_CTRL_GET_ANGLE: + *(unsigned *)arg = s->control_uint_arg; + break; + case STREAM_CTRL_SEEK_TO_CHAPTER: + case STREAM_CTRL_SEEK_TO_TIME: + case STREAM_CTRL_SET_ANGLE: + stream->pos = s->read_filepos = s->control_new_pos; + break; + } + return s->control_res; +} -- cgit v1.2.3 From 8e218ff32956e6279d909814bc7e7c7f82921729 Mon Sep 17 00:00:00 2001 From: reimar Date: Mon, 26 May 2008 18:46:13 +0000 Subject: Emulate STREAM_CTRL_GET_TIME_LENGTH if cache is used. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@26879 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'stream/cache2.c') diff --git a/stream/cache2.c b/stream/cache2.c index 584af1faf4..11d6574cf2 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -63,6 +63,7 @@ typedef struct { volatile double control_double_arg; volatile int control_res; volatile off_t control_new_pos; + volatile double stream_time_length; } cache_vars_t; static int min_fill=0; @@ -198,9 +199,17 @@ int cache_fill(cache_vars_t* s){ } static void cache_execute_control(cache_vars_t *s) { + static unsigned last; + if (GetTimerMS() - last > 99) { + double len; + 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; + last = GetTimerMS(); + } if (s->control == -1) return; switch (s->control) { - case STREAM_CTRL_GET_TIME_LENGTH: case STREAM_CTRL_GET_CURRENT_TIME: case STREAM_CTRL_SEEK_TO_TIME: case STREAM_CTRL_GET_ASPECT_RATIO: @@ -432,7 +441,9 @@ int cache_do_control(stream_t *stream, int cmd, void *arg) { case STREAM_CTRL_GET_NUM_CHAPTERS: case STREAM_CTRL_GET_CURRENT_CHAPTER: // the core might call these every frame, they are too slow for this... -// case STREAM_CTRL_GET_TIME_LENGTH: + case STREAM_CTRL_GET_TIME_LENGTH: + *(double *)arg = s->stream_time_length; + return s->stream_time_length ? STREAM_OK : STREAM_UNSUPPORTED; // case STREAM_CTRL_GET_CURRENT_TIME: case STREAM_CTRL_GET_ASPECT_RATIO: case STREAM_CTRL_GET_NUM_ANGLES: -- cgit v1.2.3 From 09b97f48268ce10e22fb18082cfdbf35e93e7b2c Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 30 May 2008 15:20:42 +0000 Subject: Handle NULL control function in cache_execute_control, fixes crash with http urls. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@26929 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'stream/cache2.c') diff --git a/stream/cache2.c b/stream/cache2.c index 11d6574cf2..e0dba9936c 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -200,6 +200,13 @@ int cache_fill(cache_vars_t* s){ static void cache_execute_control(cache_vars_t *s) { static unsigned last; + if (!s->stream->control) { + s->stream_time_length = 0; + s->control_new_pos = 0; + s->control_res = STREAM_UNSUPPORTED; + s->control = -1; + return; + } if (GetTimerMS() - last > 99) { double len; if (s->stream->control(s->stream, STREAM_CTRL_GET_TIME_LENGTH, &len) == STREAM_OK) -- cgit v1.2.3 From 9c6a2cb7401cca3c1f9a7b5857f81f5703b2df5a Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 1 Jun 2008 18:14:56 +0000 Subject: 100l, fix wrong order of cases in cache_do_control git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@26956 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'stream/cache2.c') diff --git a/stream/cache2.c b/stream/cache2.c index e0dba9936c..a5be3903fa 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -445,13 +445,13 @@ int cache_do_control(stream_t *stream, int cmd, void *arg) { s->control_uint_arg = *(unsigned *)arg; s->control = cmd; break; - case STREAM_CTRL_GET_NUM_CHAPTERS: - case STREAM_CTRL_GET_CURRENT_CHAPTER: // the core might call these every frame, they are too slow for this... case STREAM_CTRL_GET_TIME_LENGTH: +// case STREAM_CTRL_GET_CURRENT_TIME: *(double *)arg = s->stream_time_length; return s->stream_time_length ? STREAM_OK : STREAM_UNSUPPORTED; -// case STREAM_CTRL_GET_CURRENT_TIME: + case STREAM_CTRL_GET_NUM_CHAPTERS: + case STREAM_CTRL_GET_CURRENT_CHAPTER: case STREAM_CTRL_GET_ASPECT_RATIO: case STREAM_CTRL_GET_NUM_ANGLES: case STREAM_CTRL_GET_ANGLE: -- cgit v1.2.3