summaryrefslogtreecommitdiffstats
path: root/demux/demux_mkv.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-11-06 21:36:02 +0100
committerwm4 <wm4@nowhere>2019-11-06 21:36:02 +0100
commitf37f4de8496556afaa024e39e2efb433eb1680d4 (patch)
tree1ade8205598a3142d1fcbe5f32f461266ce81b76 /demux/demux_mkv.c
parentabb089431d0467c3609207d0b27359ef08a6c16d (diff)
downloadmpv-f37f4de8496556afaa024e39e2efb433eb1680d4.tar.bz2
mpv-f37f4de8496556afaa024e39e2efb433eb1680d4.tar.xz
stream: turn into a ring buffer, make size configurable
In some corner cases (see #6802), it can be beneficial to use a larger stream buffer size. Use this as argument to rewrite everything for no reason. Turn stream.c itself into a ring buffer, with configurable size. The latter would have been easily achievable with minimal changes, and the ring buffer is the hard part. There is no reason to have a ring buffer at all, except possibly if ffmpeg don't fix their awful mp4 demuxer, and some subtle issues with demux_mkv.c wanting to seek back by small offsets (the latter was handled with small stream_peek() calls, which are unneeded now). In addition, this turns small forward seeks into reads (where data is simply skipped). Before this commit, only stream_skip() did this (which also mean that stream_skip() simply calls stream_seek() now). Replace all stream_peek() calls with something else (usually stream_read_peek()). The function was a problem, because it returned a pointer to the internal buffer, which is now a ring buffer with wrapping. The new function just copies the data into a buffer, and in some cases requires callers to dynamically allocate memory. (The most common case, demux_lavf.c, required a separate buffer allocation anyway due to FFmpeg "idiosyncrasies".) This is the bulk of the demuxer_* changes. I'm not happy with this. There still isn't a good reason why there should be a ring buffer, that is complex, and most of the time just wastes half of the available memory. Maybe another rewrite soon. It also contains bugs; you're an alpha tester now.
Diffstat (limited to 'demux/demux_mkv.c')
-rw-r--r--demux/demux_mkv.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 5eaa7bbb07..db1ccff13a 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -1999,13 +1999,9 @@ static int demux_mkv_open(demuxer_t *demuxer, enum demux_check check)
if (demuxer->params)
mkv_d->probably_webm_dash_init = demuxer->params->init_fragment.len > 0;
- bstr start = stream_peek(s, 4);
- uint32_t start_id = 0;
- for (int n = 0; n < start.len; n++)
- start_id = (start_id << 8) | start.start[n];
- if (start_id != EBML_ID_EBML)
+ // Make sure you can seek back after read_ebml_header() if no EBML ID.
+ if (stream_read_peek(s, &(char[4]){0}, 4) != 4)
return -1;
-
if (!read_ebml_header(demuxer))
return -1;
MP_DBG(demuxer, "Found the head...\n");
@@ -2027,7 +2023,6 @@ static int demux_mkv_open(demuxer_t *demuxer, enum demux_check check)
while (1) {
start_pos = stream_tell(s);
- stream_peek(s, 4); // make sure we can always seek back
uint32_t id = ebml_read_id(s);
if (s->eof) {
if (!mkv_d->probably_webm_dash_init)
@@ -2836,7 +2831,6 @@ static int read_next_block_into_queue(demuxer_t *demuxer)
find_next_cluster:
mkv_d->cluster_end = 0;
for (;;) {
- stream_peek(s, 4); // guarantee we can undo ebml_read_id() below
mkv_d->cluster_start = stream_tell(s);
uint32_t id = ebml_read_id(s);
if (id == MATROSKA_ID_CLUSTER)