From 4448190ef0c0c8029a3b3a41aab5b913ca0caa2b Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 16:57:16 +0000 Subject: Fix cache process accidentally being killed by SIGUSR1. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31250 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'stream') diff --git a/stream/cache2.c b/stream/cache2.c index e534f381c7..e13f3e75f3 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -351,6 +351,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 @@ -401,6 +404,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())){ -- cgit v1.2.3 From 6f7c1ea40922a7093e07958dc12d5519505c5a63 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 17:26:31 +0000 Subject: Improve handling of cache process/thread hanging/being killed. In particular allow a single STRG+C to quit MPlayer. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31251 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'stream') diff --git a/stream/cache2.c b/stream/cache2.c index e13f3e75f3..dd9f4414a7 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -116,6 +116,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; @@ -124,10 +126,21 @@ static int cache_read(cache_vars_t *s, unsigned char *buf, int size) 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 @@ 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 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: -- cgit v1.2.3 From 16e3978e1e1b2f8a302b7e45d4b09e602e6b8733 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 18:45:25 +0000 Subject: Document time scale for stream_check_interrupt argument. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31253 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/stream.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'stream') diff --git a/stream/stream.h b/stream/stream.h index b21e1a7a90..1ff94a331c 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -327,7 +327,8 @@ stream_t* open_output_stream(const char* filename,char** options); /// Set the callback to be used by libstream to check for user /// interruption during long blocking operations (cache filling, etc). void stream_set_interrupt_callback(int (*cb)(int)); -/// 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; -- cgit v1.2.3 From 27d41fa5b353be63e8578b49b33359ed11a82276 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 18:47:03 +0000 Subject: 100l, stream_check_for_interrupt argument is not in usec, so we would end up sleeping for 10s instead of 10ms. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31254 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'stream') diff --git a/stream/cache2.c b/stream/cache2.c index dd9f4414a7..1e0bea9c7b 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 @@ -127,14 +127,14 @@ static int cache_read(cache_vars_t *s, unsigned char *buf, int size) // eof? if(s->eof) break; if (s->max_filepos == last_max) { - if (sleep_count++ == 5) + 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... - if (stream_check_interrupt(READ_USLEEP_TIME)) { + if (stream_check_interrupt(READ_SLEEP_TIME)) { s->eof = 1; break; } -- cgit v1.2.3 From 6b255e5083d11a1026c94ad07b45f1fc3288b3e0 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 18:49:02 +0000 Subject: stream_check_interrupt should sleep even if no callback is set. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31255 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/stream.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'stream') diff --git a/stream/stream.c b/stream/stream.c index cdd9713a20..64c97cf0dc 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -486,7 +486,10 @@ void stream_set_interrupt_callback(int (*cb)(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(time); } -- cgit v1.2.3 From a564c5a6cc3eeeaa5b271aead5d05b90e6fdb041 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 28 May 2010 20:59:53 +0000 Subject: Fix typo in message. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31256 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stream') diff --git a/stream/cache2.c b/stream/cache2.c index 1e0bea9c7b..3748e6f2f4 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -578,7 +578,7 @@ int cache_do_control(stream_t *stream, int cmd, void *arg) { cache_wakeup(stream); while (s->control != -1) { if (sleep_count++ == 1000) - mp_msg(MSGT_CACHE, MSGL_WARN, "Cache no responding!\n"); + mp_msg(MSGT_CACHE, MSGL_WARN, "Cache not responding!\n"); if (stream_check_interrupt(CONTROL_SLEEP_TIME)) { s->eof = 1; return STREAM_UNSUPPORTED; -- cgit v1.2.3