# HG changeset patch # User reimar # Date 1275067591 0 # Node ID 8432358f2d32a57db54fb1af80a926d5348a22a9 # Parent edfa98275e045b5e2a29e470ef29d3b9219457ab Improve handling of cache process/thread hanging/being killed. In particular allow a single STRG+C to quite MPlayer. diff -r edfa98275e04 -r 8432358f2d32 stream/cache2.c --- a/stream/cache2.c Fri May 28 16:57:16 2010 +0000 +++ b/stream/cache2.c Fri May 28 17:26:31 2010 +0000 @@ -116,6 +116,8 @@ 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; @@ -124,10 +126,21 @@ if(s->read_filepos>=s->max_filepos || s->read_fileposmin_filepos){ // eof? if(s->eof) break; + if (s->max_filepos == last_max) { + if (sleep_count++ == 5) + 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_USLEEP_TIME)) { + s->eof = 1; + break; + } continue; // try again... } + sleep_count = 0; newb=s->max_filepos-s->read_filepos; // new bytes in the buffer if(newbcache_data; switch (cmd) { case STREAM_CTRL_SEEK_TO_TIME: @@ -562,8 +576,14 @@ 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 no 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: