diff options
author | wm4 <wm4@nowhere> | 2018-05-17 21:45:17 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2018-05-24 19:56:35 +0200 |
commit | a0cce7f775e97aa364d166c278c49df1325e6cc7 (patch) | |
tree | 615873f40b29753c5bb13b884f9a7762e2356806 /stream/stream_file.c | |
parent | a253c72dbb0fedf3b83f2f20f1f311c40551a6b1 (diff) | |
download | mpv-a0cce7f775e97aa364d166c278c49df1325e6cc7.tar.bz2 mpv-a0cce7f775e97aa364d166c278c49df1325e6cc7.tar.xz |
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.
Diffstat (limited to 'stream/stream_file.c')
-rw-r--r-- | stream/stream_file.c | 10 |
1 files changed, 8 insertions, 2 deletions
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; } |