summaryrefslogtreecommitdiffstats
path: root/stream/cache2.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@symbol.nonexistent.invalid>2008-06-04 08:10:48 +0300
committerUoti Urpala <uau@symbol.nonexistent.invalid>2008-06-04 08:10:48 +0300
commitd5c868325cefcd5fad53361d1dfdc9757674eb70 (patch)
treea838e509fdc2468220466e6337097b3ef590b00c /stream/cache2.c
parent0cb5123c8f65b3d7715deb22ce8430eccc21996e (diff)
parent5b3834c5d1033f05d798278c33782c5563247062 (diff)
downloadmpv-d5c868325cefcd5fad53361d1dfdc9757674eb70.tar.bz2
mpv-d5c868325cefcd5fad53361d1dfdc9757674eb70.tar.xz
Merge svn changes up to r26979
Most of the conflicts are trivial. Conflicts: Makefile cfg-mplayer.h input/input.c libmenu/vf_menu.c libmpcodecs/dec_video.c libmpcodecs/vf_expand.c libmpcodecs/vf_vo.c libmpdemux/demux_mkv.c libmpdemux/demuxer.c libmpdemux/demuxer.h libvo/vo_directfb2.c libvo/vo_gl.c libvo/vo_winvidix.c libvo/vo_xv.c libvo/vo_xvidix.c libvo/vo_xvmc.c libvo/x11_common.c mplayer.c osdep/timer-linux.c stream/cache2.c
Diffstat (limited to 'stream/cache2.c')
-rw-r--r--stream/cache2.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/stream/cache2.c b/stream/cache2.c
index 7d67bfb034..0696526f32 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 <stdio.h>
#include <stdlib.h>
@@ -57,6 +58,12 @@ 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;
+ volatile double stream_time_length;
} cache_vars_t;
static int min_fill=0;
@@ -191,6 +198,46 @@ static 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)
+ 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_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;
+}
+
static cache_vars_t* cache_init(int size,int sector){
int num;
#if !defined(WIN32) && !defined(__OS2__)
@@ -331,6 +378,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 +432,53 @@ 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;
+// 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_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:
+ 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;
+}