demux: really disable cache for sub-demuxers

It seems the so called demuxer cache wasn't really disabled for
sub-demuxers (timeline stuff). This was relatively harmless, since the
actual packet data was shared anyway via refcounting. But with the
addition of a mmap cache backend, this may change a lot.

So strictly disable any caching for sub-demuxers. This assumes that
users of sub-demuxers (only demux_timeline.c by now?) strictly use
demux_read_any_packet(), since demux_read_packet_async() will require
some minor read-ahead if a low level packet read returned a packet for a
different stream.

This requires some awkward messing with this fucking heap of trash. The
thing that is really wrong here is that the demuxer API mixes different
concepts, and sub-demuxers get the same API as decoders, and use the
cache code.
This commit is contained in:
wm4 2019-06-07 17:09:22 +02:00
parent 5d6b7c39ab
commit e8147843fc
3 changed files with 15 additions and 6 deletions

View File

@ -2923,21 +2923,26 @@ static struct demuxer *open_given_type(struct mpv_global *global,
seekable = 1;
}
in->seekable_cache = seekable == 1;
struct demuxer *sub = NULL;
if (!(params && params->disable_timeline)) {
struct timeline *tl = timeline_load(global, log, demuxer);
if (tl) {
struct demuxer_params params2 = {0};
params2.timeline = tl;
struct demuxer *sub =
params2.is_top_level = params && params->is_top_level;
sub =
open_given_type(global, log, &demuxer_desc_timeline,
demuxer->stream, &params2, DEMUX_CHECK_FORCE);
if (sub) {
demuxer = sub;
} else {
if (!sub)
timeline_destroy(tl);
}
}
}
if (!(params && params->is_top_level) || sub) {
in->seekable_cache = false;
in->min_secs = 0;
in->max_bytes = 1;
}
demuxer = sub ? sub : demuxer;
// Let this demuxer free demuxer->stream. Timeline sub-demuxers can
// share a stream, and in these cases the demux_timeline instance
// should own the stream, as it frees the sub demuxers first.

View File

@ -158,6 +158,7 @@ typedef struct demux_attachment
} demux_attachment_t;
struct demuxer_params {
bool is_top_level; // if true, it's not a sub-demuxer (enables cache etc.)
char *force_format;
int matroska_num_wanted_uids;
struct matroska_segment_uid *matroska_wanted_uids;

View File

@ -724,7 +724,9 @@ int mp_add_external_file(struct MPContext *mpctx, char *filename,
if (strncmp(disp_filename, "memory://", 9) == 0)
disp_filename = "memory://"; // avoid noise
struct demuxer_params params = {0};
struct demuxer_params params = {
.is_top_level = true,
};
switch (filter) {
case STREAM_SUB:
@ -968,6 +970,7 @@ static void *open_demux_thread(void *ctx)
.force_format = mpctx->open_format,
.stream_flags = mpctx->open_url_flags,
.stream_record = true,
.is_top_level = true,
};
mpctx->open_res_demuxer =
demux_open_url(mpctx->open_url, &p, mpctx->open_cancel, mpctx->global);