diff options
author | wm4 <wm4@nowhere> | 2014-04-25 19:11:58 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-04-25 19:11:58 +0200 |
commit | 3d51ef3dc83ea59a47c0eccf4ae93ae2a441ceb7 (patch) | |
tree | 89f44daa62ea10f38cf4d9da3dbeeb114550d668 | |
parent | cbeb558c6c635259e6fc98fe595b7011a3e09b92 (diff) | |
download | mpv-3d51ef3dc83ea59a47c0eccf4ae93ae2a441ceb7.tar.bz2 mpv-3d51ef3dc83ea59a47c0eccf4ae93ae2a441ceb7.tar.xz |
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.
-rw-r--r-- | stream/stream.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/stream/stream.c b/stream/stream.c index 99e871d5a0..5eee953bf6 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -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; |