From f8c32fc953320b93c5975c03d3d2f8a5febce498 Mon Sep 17 00:00:00 2001 From: ranma Date: Thu, 10 Feb 2011 21:25:38 +0000 Subject: stream: Make stream_write_buffer() check for short writes None of the calling sites to stream_write_buffer were checking the return value to see if all bytes got written (nothing in current code actually calls it any more after MEncoder was removed). This was causing (very occasionally) problems with mencoder when using output pipes AND running under a sandbox or when being straced (ptrace is the culprit). Theoretically this problem can happen without pipes or ptrace. Only stream_file, stream_smb and stream_ffmpeg implement write_buffer and ffmpeg already handles this internally. Original patch by Sang-Uok Kum. Signed-off-by: Tobias Diedrich git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32881 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/stream.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'stream/stream.c') diff --git a/stream/stream.c b/stream/stream.c index 6f35252e3d..34b6bc81f9 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -28,6 +28,7 @@ #endif #include #include +#include #include "config.h" @@ -326,6 +327,7 @@ int stream_write_buffer(stream_t *s, unsigned char *buf, int len) { if(rd < 0) return -1; s->pos += rd; + assert(rd == len && "stream_write_buffer(): unexpected short write"); return rd; } -- cgit v1.2.3 From 67f5ef670c97a68c96351d96a8f1631d796c3bc9 Mon Sep 17 00:00:00 2001 From: reimar Date: Tue, 22 Feb 2011 22:27:01 +0000 Subject: stream: try to reset stream once if read fails When reading from a stream fails, try one more time after a reset. This should re-establish for example timed-out network connections. Fixes bug #1841. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32954 b3059339-0415-0410-9bf9-f77b7e298cf2 100l, fix incorrect len when retrying read. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32957 b3059339-0415-0410-9bf9-f77b7e298cf2 Improve stream reset on read error, should now fix bug #1841 in more cases, e.g. also with -cache. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32977 b3059339-0415-0410-9bf9-f77b7e298cf2 Add ugly hack to compensate DVDNAV's ugly hacks and fix seeking. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33122 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/stream.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'stream/stream.c') diff --git a/stream/stream.c b/stream/stream.c index 34b6bc81f9..62f6a1f171 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -278,6 +278,7 @@ void stream_capture_do(stream_t *s) int stream_read_internal(stream_t *s, void *buf, int len) { + int orig_len = len; // we will retry even if we already reached EOF previously. switch(s->type){ case STREAMTYPE_STREAM: @@ -299,7 +300,26 @@ int stream_read_internal(stream_t *s, void *buf, int len) default: len= s->fill_buffer ? s->fill_buffer(s, buf, len) : 0; } - if(len<=0){ s->eof=1; return 0; } + if(len<=0){ + // dvdnav has some horrible hacks to "suspend" reads, + // we need to skip this code or seeks will hang. + if (!s->eof && s->type != STREAMTYPE_DVDNAV) { + // just in case this is an error e.g. due to network + // timeout reset and retry + // Seeking is used as a hack to make network streams + // reopen the connection, ideally they would implement + // e.g. a STREAM_CTRL_RECONNECT to do this + off_t pos = s->pos; + s->eof=1; + stream_reset(s); + stream_seek_internal(s, pos); + // make sure EOF is set to ensure no endless loops + s->eof=1; + return stream_read_internal(s, buf, orig_len); + } + s->eof=1; + return 0; + } // When reading succeeded we are obviously not at eof. // This e.g. avoids issues with eof getting stuck when lavf seeks in MPEG-TS s->eof=0; -- cgit v1.2.3