From a0cce7f775e97aa364d166c278c49df1325e6cc7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 17 May 2018 21:45:17 +0200 Subject: stream_file: use a separate mp_cancel thing The intention is to avoid that the parent mp_cancel retains the internally allocated wakeup pipe. File FDs are a relatively scarce resource, so try to avoid having too many. This might matter for subtitle files, for which it is relatively likely that they are loaded in large quantities. demux_lavf.c will close the underlying stream for most subtitle files, and now it will free the wakeup pipe too. Actually, there are currently only 1 or 2 mp_cancel objects per mpv core, but this could change if every external subtitle track gets its own mp_cancel in later commits. --- stream/stream_file.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'stream/stream_file.c') diff --git a/stream/stream_file.c b/stream/stream_file.c index 73048baefb..785e96b12c 100644 --- a/stream/stream_file.c +++ b/stream/stream_file.c @@ -65,6 +65,7 @@ struct priv { bool regular_file; bool appending; int64_t orig_size; + struct mp_cancel *cancel; }; // Total timeout = RETRY_TIMEOUT * MAX_RETRIES @@ -85,7 +86,7 @@ static int fill_buffer(stream_t *s, char *buffer, int max_len) #ifndef __MINGW32__ if (p->use_poll) { - int c = s->cancel ? mp_cancel_get_fd(s->cancel) : -1; + int c = mp_cancel_get_fd(p->cancel); struct pollfd fds[2] = { {.fd = p->fd, .events = POLLIN}, {.fd = c, .events = POLLIN}, @@ -112,7 +113,7 @@ static int fill_buffer(stream_t *s, char *buffer, int max_len) if (!p->appending || p->use_poll) break; - if (mp_cancel_wait(s->cancel, RETRY_TIMEOUT)) + if (mp_cancel_wait(p->cancel, RETRY_TIMEOUT)) break; } @@ -160,6 +161,7 @@ static void s_close(stream_t *s) struct priv *p = s->priv; if (p->close) close(p->fd); + talloc_free(p->cancel); } // If url is a file:// URL, return the local filename, otherwise return NULL. @@ -361,6 +363,10 @@ static int open_f(stream_t *stream) p->orig_size = get_size(stream); + p->cancel = mp_cancel_new(p); + if (stream->cancel) + mp_cancel_add_slave(stream->cancel, p->cancel); + return STREAM_OK; } -- cgit v1.2.3