[MPlayer-cvslog] r34461 - trunk/stream/cache2.c
reimar
subversion at mplayerhq.hu
Fri Dec 23 22:50:33 CET 2011
Author: reimar
Date: Fri Dec 23 22:50:32 2011
New Revision: 34461
Log:
Flush cache and sync stream position/eof after seeking STREAM_CTRLs.
This avoid some strange differences in behaviour between -cache and -nocache.
Modified:
trunk/stream/cache2.c
Modified: trunk/stream/cache2.c
==============================================================================
--- trunk/stream/cache2.c Fri Dec 23 20:00:31 2011 (r34460)
+++ trunk/stream/cache2.c Fri Dec 23 22:50:32 2011 (r34461)
@@ -94,7 +94,6 @@ typedef struct {
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;
volatile double stream_time_pos;
} cache_vars_t;
@@ -109,6 +108,12 @@ static void cache_wakeup(stream_t *s)
#endif
}
+static void cache_flush(cache_vars_t *s)
+{
+ s->offset= // FIXME!?
+ s->min_filepos=s->max_filepos=s->read_filepos; // drop cache content :(
+}
+
static int cache_read(cache_vars_t *s, unsigned char *buf, int size)
{
int total=0;
@@ -184,8 +189,7 @@ static int cache_fill(cache_vars_t *s)
// issues with e.g. mov or badly interleaved files
if(read<s->min_filepos || read>=s->max_filepos+s->seek_limit)
{
- s->offset= // FIXME!?
- s->min_filepos=s->max_filepos=read; // drop cache content :(
+ cache_flush(s);
if(s->stream->eof) stream_reset(s->stream);
stream_seek_internal(s->stream,read);
mp_msg(MSGT_CACHE,MSGL_DBG2,"Seek done. new pos: 0x%"PRIX64" \n",(int64_t)stream_tell(s->stream));
@@ -262,12 +266,12 @@ static int cache_fill(cache_vars_t *s)
static int cache_execute_control(cache_vars_t *s) {
double double_res;
unsigned uint_res;
+ int needs_flush = 0;
static unsigned last;
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;
@@ -294,6 +298,7 @@ static int cache_execute_control(cache_v
if (s->control == -1) return 1;
switch (s->control) {
case STREAM_CTRL_SEEK_TO_TIME:
+ needs_flush = 1;
double_res = s->control_double_arg;
case STREAM_CTRL_GET_CURRENT_TIME:
case STREAM_CTRL_GET_ASPECT_RATIO:
@@ -302,6 +307,7 @@ static int cache_execute_control(cache_v
break;
case STREAM_CTRL_SEEK_TO_CHAPTER:
case STREAM_CTRL_SET_ANGLE:
+ needs_flush = 1;
uint_res = s->control_uint_arg;
case STREAM_CTRL_GET_NUM_CHAPTERS:
case STREAM_CTRL_GET_CURRENT_CHAPTER:
@@ -314,7 +320,11 @@ static int cache_execute_control(cache_v
s->control_res = STREAM_UNSUPPORTED;
break;
}
- s->control_new_pos = s->stream->pos;
+ if (needs_flush) {
+ s->read_filepos = s->stream->pos;
+ s->eof = s->stream->eof;
+ cache_flush(s);
+ }
s->control = -1;
return 1;
}
@@ -593,16 +603,19 @@ int cache_stream_seek_long(stream_t *str
int cache_do_control(stream_t *stream, int cmd, void *arg) {
int sleep_count = 0;
+ int pos_change = 0;
cache_vars_t* s = stream->cache_data;
switch (cmd) {
case STREAM_CTRL_SEEK_TO_TIME:
s->control_double_arg = *(double *)arg;
s->control = cmd;
+ pos_change = 1;
break;
case STREAM_CTRL_SEEK_TO_CHAPTER:
case STREAM_CTRL_SET_ANGLE:
s->control_uint_arg = *(unsigned *)arg;
s->control = cmd;
+ pos_change = 1;
break;
// the core might call these every frame, so cache them...
case STREAM_CTRL_GET_TIME_LENGTH:
@@ -631,6 +644,12 @@ int cache_do_control(stream_t *stream, i
return STREAM_UNSUPPORTED;
}
}
+ // to avoid unnecessary differences with non-cache behaviour,
+ // do this also on failure.
+ if (pos_change) {
+ stream->pos = s->read_filepos;
+ stream->eof = s->eof;
+ }
if (s->control_res != STREAM_OK)
return s->control_res;
switch (cmd) {
@@ -645,11 +664,6 @@ int cache_do_control(stream_t *stream, i
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;
}
More information about the MPlayer-cvslog
mailing list