1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 17:12:36 +00:00

stream: use uninterruptible sleep on reconnecting

This is the only function which actually used the time argument of
stream_check_interrupt(). Considering that the whole player freezes
anyway, this is not worth the complication.

Also generally reduce the maximum wait time due to timeout. Introduce
exponential backoff, which makes the first reconnect retries faster, but
still waits up to 500ms in the later retries.
This commit is contained in:
wm4 2014-04-25 19:11:58 +02:00
parent cbeb558c6c
commit 3d51ef3dc8

View File

@ -394,16 +394,22 @@ stream_t *open_output_stream(const char *filename, struct mpv_global *global)
static int stream_reconnect(stream_t *s)
{
#define MAX_RECONNECT_RETRIES 5
#define RECONNECT_SLEEP_MS 1000
#define RECONNECT_SLEEP_MAX_MS 500
if (!s->streaming)
return 0;
if (!(s->flags & MP_STREAM_SEEK_FW))
return 0;
int64_t pos = s->pos;
int sleep_ms = 5;
for (int retry = 0; retry < MAX_RECONNECT_RETRIES; retry++) {
MP_WARN(s, "Connection lost! Attempting to reconnect (%d)...\n", retry + 1);
if (stream_check_interrupt(retry ? RECONNECT_SLEEP_MS : 0))
if (retry) {
mp_sleep_us(sleep_ms * 1000);
sleep_ms = MPMIN(sleep_ms * 2, RECONNECT_SLEEP_MAX_MS);
}
if (stream_check_interrupt(0))
return 0;
s->eof = 1;