summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authormplayer-svn <svn@mplayerhq.hu>2012-04-22 12:10:49 +0000
committerwm4 <wm4@nowhere>2012-08-03 03:34:38 +0200
commit7e87c0e76a69918296161f77c0cf337650d249c1 (patch)
tree35d7a790a89ae59ff59d7f0163ebc8dbe3e4dffa /stream
parent2d513fac330d7b8b02f053fce5d68a4c422b75f6 (diff)
downloadmpv-7e87c0e76a69918296161f77c0cf337650d249c1.tar.bz2
mpv-7e87c0e76a69918296161f77c0cf337650d249c1.tar.xz
stream: retry reconnecting several times
Retry reconnecting several times. Also add a delay, otherwise a server closing any incoming connection immediately would make MPlayer stop even if it happens only for 1 second or so. With this change, no server/network outage of any kind shorter than 5 seconds should cause MPlayer to give up anymore. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34871 b3059339-0415-0410-9bf9-f77b7e298cf2 Author: reimar
Diffstat (limited to 'stream')
-rw-r--r--stream/stream.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 5a0aa7d7dd..7af8fa52fa 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -262,6 +262,26 @@ stream_t *open_output_stream(const char *filename, struct MPOpts *options)
//=================== STREAMER =========================
+static int stream_reconnect(stream_t *s)
+{
+#define MAX_RECONNECT_RETRIES 5
+#define RECONNECT_SLEEP_MS 1000
+ int retry = 0;
+ off_t pos = s->pos;
+ // 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
+ do {
+ if (retry >= MAX_RECONNECT_RETRIES)
+ return 0;
+ if (retry) usec_sleep(RECONNECT_SLEEP_MS * 1000);
+ retry++;
+ s->eof=1;
+ stream_reset(s);
+ } while (stream_seek_internal(s, pos) >= 0 || s->pos != pos); // seek failed
+ return 1;
+}
+
int stream_read_internal(stream_t *s, void *buf, int len)
{
int orig_len = len;
@@ -289,9 +309,8 @@ int stream_read_internal(stream_t *s, void *buf, int len)
len= s->fill_buffer ? s->fill_buffer(s, buf, len) : 0;
}
if(len<=0){
- off_t pos = s->pos;
// do not retry if this looks like proper eof
- if (s->eof || (s->end_pos && pos == s->end_pos))
+ if (s->eof || (s->end_pos && s->pos == s->end_pos))
goto eof_out;
// dvdnav has some horrible hacks to "suspend" reads,
// we need to skip this code or seeks will hang.
@@ -300,12 +319,7 @@ int stream_read_internal(stream_t *s, void *buf, int len)
// 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
- s->eof=1;
- stream_reset(s);
- if (stream_seek_internal(s, pos) >= 0 || s->pos != pos) // seek failed
+ if (!stream_reconnect(s))
goto eof_out;
// make sure EOF is set to ensure no endless loops
s->eof=1;