summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-04-25 19:11:58 +0200
committerwm4 <wm4@nowhere>2014-04-30 11:45:31 +0200
commit491f633a208ab1b16ad39653b4ccdf180fd7505d (patch)
treedabf45c0f700e65c3085b13c618422e4536f584c
parenteb5e45855a017da2f0199a8ecd0d1245db48d5ab (diff)
downloadmpv-491f633a208ab1b16ad39653b4ccdf180fd7505d.tar.bz2
mpv-491f633a208ab1b16ad39653b4ccdf180fd7505d.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.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/stream/stream.c b/stream/stream.c
index b48de575ea..cd809503d2 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -396,16 +396,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;