diff options
author | wm4 <wm4@nowhere> | 2018-01-04 15:20:19 +0100 |
---|---|---|
committer | Kevin Mitchell <kevmitch@gmail.com> | 2018-01-04 18:33:18 -0800 |
commit | 185e63a3e2a84fe4d006054960481460072a8243 (patch) | |
tree | a320b4df574926e0254749a445006e9d9b798e65 /stream/stream.c | |
parent | cf411a9489b825f5b5587414431a694dc743da82 (diff) | |
download | mpv-185e63a3e2a84fe4d006054960481460072a8243.tar.bz2 mpv-185e63a3e2a84fe4d006054960481460072a8243.tar.xz |
stream: use native libavformat reconnection feature
Remove our own hacky reconnection code, and use libavformat's feature for
that. It's disabled by default, and until recently it did not work too
well. This has been fixed in recent ffmpeg git master[1], so there's no reason
to keep our own code.
[1] FFmpeg/FFmpeg@8a108bdea06fac43af9f44b6d2538f357451167a
We set "reconnect_delay_max" to 7, which limits the maximum time it
waits. Since libavformat doubles the wait time on each reconnect attempt
(starting with 1), and stops trying to reconnect once the wait time is
over the reconnect_delay_max value, this allows for 4 reconnection
attempts which should add to 11 seconds maximum wait time. The default
is 120, which seems too high for normal playback use.
(The user can still override these parameters with --stream-lavf-o.)
Diffstat (limited to 'stream/stream.c')
-rw-r--r-- | stream/stream.c | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/stream/stream.c b/stream/stream.c index dba30d5df2..255e583de2 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -336,32 +336,6 @@ stream_t *open_output_stream(const char *filename, struct mpv_global *global) return stream_create(filename, STREAM_WRITE, NULL, global); } -static bool stream_reconnect(stream_t *s) -{ - if (!s->streaming || s->caching || !s->seekable || !s->cancel) - return false; - - double sleep_secs = 0; - for (int retry = 0; retry < 6; retry++) { - if (mp_cancel_wait(s->cancel, sleep_secs)) - break; - - int r = stream_control(s, STREAM_CTRL_RECONNECT, NULL); - if (r == STREAM_UNSUPPORTED) - break; - if (r == STREAM_OK) { - MP_WARN(s, "Reconnected successfully.\n"); - return true; - } - - MP_WARN(s, "Connection lost! Attempting to reconnect (%d)...\n", retry + 1); - - sleep_secs = MPMAX(sleep_secs, 0.1); - sleep_secs = MPMIN(sleep_secs * 4, 10.0); - } - return false; -} - // Read function bypassing the local stream buffer. This will not write into // s->buffer, but into buf[0..len] instead. // Returns 0 on error or EOF, and length of bytes read on success. @@ -374,15 +348,6 @@ static int stream_read_unbuffered(stream_t *s, void *buf, int len) if (s->fill_buffer && !mp_cancel_test(s->cancel)) res = s->fill_buffer(s, buf, len); if (res <= 0) { - // just in case this is an error e.g. due to network - // timeout reset and retry - // do not retry if this looks like proper eof - int64_t size = stream_get_size(s); - if (!s->eof && s->pos != size && stream_reconnect(s)) { - s->eof = 1; // make sure EOF is set to ensure no endless recursion - return stream_read_unbuffered(s, buf, len); - } - s->eof = 1; return 0; } |