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_lavf.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_lavf.c')
-rw-r--r-- | stream/stream_lavf.c | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/stream/stream_lavf.c b/stream/stream_lavf.c index 2230247f28..82d9b3a392 100644 --- a/stream/stream_lavf.c +++ b/stream/stream_lavf.c @@ -77,8 +77,6 @@ static struct mp_tags *read_icy(stream_t *stream); static int fill_buffer(stream_t *s, char *buffer, int max_len) { AVIOContext *avio = s->priv; - if (!avio) - return -1; #if LIBAVFORMAT_VERSION_MICRO >= 100 && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 81, 100) int r = avio_read_partial(avio, buffer, max_len); #else @@ -90,8 +88,6 @@ static int fill_buffer(stream_t *s, char *buffer, int max_len) static int write_buffer(stream_t *s, char *buffer, int len) { AVIOContext *avio = s->priv; - if (!avio) - return -1; avio_write(avio, buffer, len); avio_flush(avio); if (avio->error) @@ -102,8 +98,6 @@ static int write_buffer(stream_t *s, char *buffer, int len) static int seek(stream_t *s, int64_t newpos) { AVIOContext *avio = s->priv; - if (!avio) - return -1; if (avio_seek(avio, newpos, SEEK_SET) < 0) { return 0; } @@ -125,8 +119,6 @@ static void close_f(stream_t *stream) static int control(stream_t *s, int cmd, void *arg) { AVIOContext *avio = s->priv; - if (!avio && cmd != STREAM_CTRL_RECONNECT) - return -1; int64_t size; switch(cmd) { case STREAM_CTRL_GET_SIZE: @@ -175,25 +167,6 @@ static int control(stream_t *s, int cmd, void *arg) break; return 1; } - case STREAM_CTRL_RECONNECT: { - if (avio && avio->write_flag) - break; // don't bother with this - // avio supports reconneting for http (as private avio option), but it - // seems somewhat broken and drops part of the stream if the first - // reconnect does not work. emulate it. - close_f(s); - s->priv = NULL; - int res = open_f(s); - if (res == STREAM_OK) { - if (!seek(s, s->pos)) { - MP_WARN(s, "Reconnecting failed.\n"); - close_f(s); - s->priv = NULL; - return STREAM_UNSUPPORTED; - } - } - return res; - } } return STREAM_UNSUPPORTED; } @@ -313,6 +286,9 @@ static int open_f(stream_t *stream) filename = talloc_asprintf(temp, "mmsh://%.*s", BSTR_P(b_filename)); } + av_dict_set(&dict, "reconnect", "1", 0); + av_dict_set(&dict, "reconnect_delay_max", "7", 0); + mp_setup_av_network_options(&dict, stream->global, stream->log); AVIOInterruptCB cb = { |