diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2012-08-19 15:31:38 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2012-09-18 21:07:30 +0200 |
commit | 70e7d63ba011a326f5e03137b8fb45df222c43af (patch) | |
tree | 7537f596d739f09837f43cf7078cd46bda265527 /timeline/tl_matroska.c | |
parent | 1959ba006ce1a4591f3dcd5093901993e3fdda5f (diff) | |
download | mpv-70e7d63ba011a326f5e03137b8fb45df222c43af.tar.bz2 mpv-70e7d63ba011a326f5e03137b8fb45df222c43af.tar.xz |
core, timeline: cache external ordered chapter files too
Previously, Matroska source files other than the initially opened one
were always accessed without caching. Enable cache for extra files
too. A separate cache process/thread is started for each file, which
is less than optimal but probably better than no caching if the user
explicitly enabled cache. This commit only implements caching for
Matroska ordered chapters (not for EDL timeline).
To build the timeline we need to demux the files in the current
directory to look for segments with matching uuid. This first demux is
done with no cache since we don't need to read a lot of the stream. If
the file is recognized as one of the needed sources it's reopened with
cache enabled.
Also move the stream_cache_size global variable to the options struct.
Conflicts:
cfg-mplayer.h
mplayer.c
stream/stream.h
timeline/tl_matroska.c
Diffstat (limited to 'timeline/tl_matroska.c')
-rw-r--r-- | timeline/tl_matroska.c | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/timeline/tl_matroska.c b/timeline/tl_matroska.c index 4edc8d494e..30694fff24 100644 --- a/timeline/tl_matroska.c +++ b/timeline/tl_matroska.c @@ -112,6 +112,50 @@ static char **find_files(const char *original_file, const char *suffix) return results; } +static struct demuxer *open_demuxer(struct stream *stream, + struct MPContext *mpctx, char *filename, unsigned char uid_map[][16]) +{ + return demux_open_withparams(&mpctx->opts, stream, + DEMUXER_TYPE_MATROSKA, NULL, mpctx->opts.audio_id, + mpctx->opts.video_id, mpctx->opts.sub_id, filename, + &(struct demuxer_params){.matroska_wanted_uids = uid_map}); +} + +static int enable_cache(struct MPContext *mpctx, struct stream **stream, + struct demuxer **demuxer, unsigned char uid_map[][16]) +{ + struct MPOpts *opts = &mpctx->opts; + + if (opts->stream_cache_size <= 0) + return 0; + + char *filename = talloc_strdup(NULL, (*demuxer)->filename); + free_demuxer(*demuxer); + free_stream(*stream); + + int format = 0; + *stream = open_stream(filename, &mpctx->opts, &format); + if (!*stream) { + talloc_free(filename); + return -1; + } + + stream_enable_cache_percent(*stream, + opts->stream_cache_size, + opts->stream_cache_min_percent, + opts->stream_cache_seek_min_percent); + + *demuxer = open_demuxer(*stream, mpctx, filename, uid_map); + if (!*demuxer) { + talloc_free(filename); + free_stream(*stream); + return -1; + } + + talloc_free(filename); + return 1; +} + static int find_ordered_chapter_sources(struct MPContext *mpctx, struct demuxer **sources, int num_sources, @@ -140,11 +184,7 @@ static int find_ordered_chapter_sources(struct MPContext *mpctx, struct stream *s = open_stream(filenames[i], &mpctx->opts, &format); if (!s) continue; - struct demuxer *d = demux_open_withparams(&mpctx->opts, s, - DEMUXER_TYPE_MATROSKA, NULL, mpctx->opts.audio_id, - mpctx->opts.video_id, mpctx->opts.sub_id, filenames[i], - &(struct demuxer_params){.matroska_wanted_uids = uid_map}); - + struct demuxer *d = open_demuxer(s, mpctx, filenames[i], uid_map); if (!d) { free_stream(s); @@ -157,6 +197,10 @@ static int find_ordered_chapter_sources(struct MPContext *mpctx, if (!memcmp(uid_map[i], d->matroska_data.segment_uid, 16)) { mp_msg(MSGT_CPLAYER, MSGL_INFO,"Match for source %d: %s\n", i, d->filename); + + if (enable_cache(mpctx, &s, &d, uid_map) < 0) + continue; + sources[i] = d; num_left--; goto match; |