1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 15:22:09 +00:00

stream_lavf: minor fixes to HTTP reconnection support

Don't drop the stream buffers, because the read call (that must have
been failing) might try to extend an existing read buffer in the first
place. Just move the messy seek logic to stream_lavf.c. (In theory,
stream_lavf should probably make libavformat connect at the correct
offset instead of using a seek to reconnect it again. This patch doesn't
fix it, but at least it's a good argument to have the messing with the
position not in the generic code.)

Also update the comment about avio not supporting reconnecting. It has
that feature now. Maybe we should use it, but only after it gets fixed.
This commit is contained in:
wm4 2017-12-30 17:39:08 +01:00 committed by Kevin Mitchell
parent 6aad532aa3
commit 722f9b63c2
2 changed files with 14 additions and 6 deletions

View File

@ -341,7 +341,6 @@ static bool stream_reconnect(stream_t *s)
if (!s->streaming || s->caching || !s->seekable || !s->cancel) if (!s->streaming || s->caching || !s->seekable || !s->cancel)
return false; return false;
int64_t pos = s->pos;
double sleep_secs = 0; double sleep_secs = 0;
for (int retry = 0; retry < 6; retry++) { for (int retry = 0; retry < 6; retry++) {
if (mp_cancel_wait(s->cancel, sleep_secs)) if (mp_cancel_wait(s->cancel, sleep_secs))
@ -350,7 +349,7 @@ static bool stream_reconnect(stream_t *s)
int r = stream_control(s, STREAM_CTRL_RECONNECT, NULL); int r = stream_control(s, STREAM_CTRL_RECONNECT, NULL);
if (r == STREAM_UNSUPPORTED) if (r == STREAM_UNSUPPORTED)
break; break;
if (r == STREAM_OK && stream_seek_unbuffered(s, pos) && s->pos == pos) { if (r == STREAM_OK) {
MP_WARN(s, "Reconnected successfully.\n"); MP_WARN(s, "Reconnected successfully.\n");
return true; return true;
} }

View File

@ -178,12 +178,21 @@ static int control(stream_t *s, int cmd, void *arg)
case STREAM_CTRL_RECONNECT: { case STREAM_CTRL_RECONNECT: {
if (avio && avio->write_flag) if (avio && avio->write_flag)
break; // don't bother with this break; // don't bother with this
// avio doesn't seem to support this - emulate it by reopening // 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); close_f(s);
s->priv = NULL; s->priv = NULL;
stream_drop_buffers(s); int res = open_f(s);
s->pos = 0; if (res == STREAM_OK) {
return open_f(s); 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; return STREAM_UNSUPPORTED;