diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-05-30 16:39:41 +0300 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-05-30 16:39:41 +0300 |
commit | 0e0d88ede9c7e9decf4079adcffc7713d4ded210 (patch) | |
tree | 819165655b2b2bc72f4ffa12f4bfec93e6f8bb36 /stream | |
parent | c61e57bdd035ba2e151df9cdc7f3186ddf5fcb97 (diff) | |
parent | a564c5a6cc3eeeaa5b271aead5d05b90e6fdb041 (diff) | |
download | mpv-0e0d88ede9c7e9decf4079adcffc7713d4ded210.tar.bz2 mpv-0e0d88ede9c7e9decf4079adcffc7713d4ded210.tar.xz |
Merge svn changes up to r31256
Diffstat (limited to 'stream')
-rw-r--r-- | stream/cache2.c | 35 | ||||
-rw-r--r-- | stream/stream.c | 6 | ||||
-rw-r--r-- | stream/stream.h | 3 |
3 files changed, 38 insertions, 6 deletions
diff --git a/stream/cache2.c b/stream/cache2.c index b9a1f15faa..05905a6ded 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -22,7 +22,7 @@ // Note it runs in 2 processes (using fork()), but doesn't require locking!! // TODO: seeking, data consistency checking -#define READ_USLEEP_TIME 10000 +#define READ_SLEEP_TIME 10 // These defines are used to reduce the cost of many successive // seeks (e.g. when a file has no index) by spinning quickly at first. #define INITIAL_FILL_USLEEP_TIME 1000 @@ -114,6 +114,8 @@ static void cache_stats(cache_vars_t *s) static int cache_read(cache_vars_t *s, unsigned char *buf, int size) { int total=0; + int sleep_count = 0; + int last_max = s->max_filepos; while(size>0){ int pos,newb,len; @@ -122,10 +124,21 @@ static int cache_read(cache_vars_t *s, unsigned char *buf, int size) if(s->read_filepos>=s->max_filepos || s->read_filepos<s->min_filepos){ // eof? if(s->eof) break; + if (s->max_filepos == last_max) { + if (sleep_count++ == 10) + mp_msg(MSGT_CACHE, MSGL_WARN, "Cache not filling!\n"); + } else { + last_max = s->max_filepos; + sleep_count = 0; + } // waiting for buffer fill... - usec_sleep(READ_USLEEP_TIME); // 10ms + if (stream_check_interrupt(READ_SLEEP_TIME)) { + s->eof = 1; + break; + } continue; // try again... } + sleep_count = 0; newb=s->max_filepos-s->read_filepos; // new bytes in the buffer if(newb<min_fill) min_fill=newb; // statistics... @@ -349,6 +362,9 @@ static void dummy_sighandler(int x) { */ static void cache_mainloop(cache_vars_t *s) { int sleep_count = 0; +#if FORKED_CACHE + signal(SIGUSR1, SIG_IGN); +#endif do { if (!cache_fill(s)) { #if FORKED_CACHE @@ -399,6 +415,10 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){ if (min > s->buffer_size - s->fill_limit) { min = s->buffer_size - s->fill_limit; } + // to make sure we wait for the cache process/thread to be active + // before continuing + if (min <= 0) + min = 1; #if FORKED_CACHE if((stream->cache_pid=fork())){ @@ -522,6 +542,7 @@ int cache_stream_seek_long(stream_t *stream,off_t pos){ } int cache_do_control(stream_t *stream, int cmd, void *arg) { + int sleep_count = 0; cache_vars_t* s = stream->cache_data; switch (cmd) { case STREAM_CTRL_SEEK_TO_TIME: @@ -550,8 +571,14 @@ int cache_do_control(stream_t *stream, int cmd, void *arg) { return STREAM_UNSUPPORTED; } cache_wakeup(stream); - while (s->control != -1) - usec_sleep(CONTROL_SLEEP_TIME); + while (s->control != -1) { + if (sleep_count++ == 1000) + mp_msg(MSGT_CACHE, MSGL_WARN, "Cache not responding!\n"); + if (stream_check_interrupt(CONTROL_SLEEP_TIME)) { + s->eof = 1; + return STREAM_UNSUPPORTED; + } + } switch (cmd) { case STREAM_CTRL_GET_TIME_LENGTH: case STREAM_CTRL_GET_CURRENT_TIME: diff --git a/stream/stream.c b/stream/stream.c index 165166245d..01245b757a 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -37,6 +37,7 @@ #include "mp_msg.h" #include "osdep/shmem.h" +#include "osdep/timer.h" #include "network.h" #include "stream.h" #include "libmpdemux/demuxer.h" @@ -490,7 +491,10 @@ void stream_set_interrupt_callback(int (*cb)(struct input_ctx *, int), } int stream_check_interrupt(int time) { - if(!stream_check_interrupt_cb) return 0; + if(!stream_check_interrupt_cb) { + usec_sleep(time * 1000); + return 0; + } return stream_check_interrupt_cb(stream_check_interrupt_ctx, time); } diff --git a/stream/stream.h b/stream/stream.h index 5cbc304e81..40ea321bc4 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -336,7 +336,8 @@ stream_t *open_output_stream(const char *filename, struct MPOpts *options); struct input_ctx; void stream_set_interrupt_callback(int (*cb)(struct input_ctx*, int), struct input_ctx *ctx); -/// Call the interrupt checking callback if there is one. +/// Call the interrupt checking callback if there is one and +/// wait for time milliseconds int stream_check_interrupt(int time); extern int dvd_title; |