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 | |
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
-rw-r--r-- | cfg-mplayer.h | 5 | ||||
-rw-r--r-- | mplayer.c | 19 | ||||
-rw-r--r-- | mplayer.h | 2 | ||||
-rw-r--r-- | options.h | 1 | ||||
-rw-r--r-- | stream/cache2.c | 8 | ||||
-rw-r--r-- | stream/http.c | 1 | ||||
-rw-r--r-- | stream/network.c | 12 | ||||
-rw-r--r-- | stream/stream.h | 3 | ||||
-rw-r--r-- | timeline/tl_matroska.c | 54 |
9 files changed, 77 insertions, 28 deletions
diff --git a/cfg-mplayer.h b/cfg-mplayer.h index fa5f35af6c..529df35caf 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -336,8 +336,9 @@ const m_option_t common_opts[] = { // ------------------------- stream options -------------------- #ifdef CONFIG_STREAM_CACHE - {"cache", &stream_cache_size, CONF_TYPE_INT, CONF_RANGE, 32, 0x7fffffff, NULL}, - {"no-cache", &stream_cache_size, CONF_TYPE_FLAG, 0, 1, 0, NULL}, + OPT_INTRANGE("cache", stream_cache_size, 0, 32, 0x7fffffff, OPTDEF_INT(-1)), + OPT_FLAG_CONSTANTS("nocache", stream_cache_size, 0, -1, 0), + OPT_FLOATRANGE("cache-min", stream_cache_min_percent, 0, 0, 99), OPT_FLOATRANGE("cache-seek-min", stream_cache_seek_min_percent, 0, 0, 99), #endif /* CONFIG_STREAM_CACHE */ @@ -221,9 +221,6 @@ int vobsub_id = -1; static char *spudec_ifo = NULL; int forced_subs_only = 0; -// cache2: -int stream_cache_size = -1; - // A-V sync: static float default_max_pts_correction = -1; float audio_delay = 0; @@ -1252,7 +1249,7 @@ static void print_status(struct MPContext *mpctx, double a_pos, bool at_frame) #ifdef CONFIG_STREAM_CACHE // cache stats - if (stream_cache_size > 0) + if (opts->stream_cache_size > 0) saddf(line, width, " C: %d%%", cache_fill_status(mpctx->stream)); #endif @@ -3286,7 +3283,7 @@ static void run_playloop(struct MPContext *mpctx) #ifdef CONFIG_STREAM_CACHE // The cache status is part of the status line. Possibly update it. - if (mpctx->paused && stream_cache_size > 0) + if (mpctx->paused && opts->stream_cache_size > 0) print_status(mpctx, MP_NOPTS_VALUE, false); #endif @@ -3804,13 +3801,11 @@ static void play_current_file(struct MPContext *mpctx) // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts) goto_enable_cache: - if (stream_cache_size > 0) { - int res; - float stream_cache_min_percent = opts->stream_cache_min_percent; - float stream_cache_seek_min_percent = opts->stream_cache_seek_min_percent; - res = stream_enable_cache(mpctx->stream, stream_cache_size * 1024ull, - stream_cache_size * 1024ull * (stream_cache_min_percent / 100.0), - stream_cache_size * 1024ull * (stream_cache_seek_min_percent / 100.0)); + if (opts->stream_cache_size > 0) { + int res = stream_enable_cache_percent(mpctx->stream, + opts->stream_cache_size, + opts->stream_cache_min_percent, + opts->stream_cache_seek_min_percent); if (res == 0) if (libmpdemux_was_interrupted(mpctx)) goto terminate_playback; @@ -31,8 +31,6 @@ extern float audio_delay; extern double force_fps; -extern int stream_cache_size; - extern int frame_dropping; extern int auto_quality; @@ -48,6 +48,7 @@ typedef struct MPOpts { int chapter_merge_threshold; int quiet; int noconfig; + int stream_cache_size; float stream_cache_min_percent; float stream_cache_seek_min_percent; int chapterrange[2]; diff --git a/stream/cache2.c b/stream/cache2.c index 77c74d3b19..9161027ee3 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -434,6 +434,14 @@ static void cache_mainloop(cache_vars_t *s) { } while (cache_execute_control(s)); } +int stream_enable_cache_percent(stream_t *stream, int64_t stream_cache_size, + float stream_cache_min_percent, float stream_cache_seek_min_percent) +{ + return stream_enable_cache(stream, stream_cache_size * 1024, + stream_cache_size * 1024 * (stream_cache_min_percent / 100.0), + stream_cache_size * 1024 * (stream_cache_seek_min_percent / 100.0)); +} + /** * \return 1 on success, 0 if the function was interrupted and -1 on error */ diff --git a/stream/http.c b/stream/http.c index cd68029025..8d930c6460 100644 --- a/stream/http.c +++ b/stream/http.c @@ -45,7 +45,6 @@ #include <libavutil/avutil.h> -extern int stream_cache_size; extern int network_bandwidth; typedef struct { diff --git a/stream/network.c b/stream/network.c index 87b295e7e6..7d45ca71d9 100644 --- a/stream/network.c +++ b/stream/network.c @@ -29,6 +29,7 @@ #include <ctype.h> #include "config.h" +#include "options.h" #include "mp_msg.h" @@ -47,8 +48,6 @@ #include "cookies.h" #include "url.h" -extern int stream_cache_size; - /* Variables for the command line option -user, -passwd, -bandwidth, -user-agent and -nocookies */ @@ -461,13 +460,14 @@ nop_streaming_seek( int fd, off_t pos, streaming_ctrl_t *stream_ctrl ) { void fixup_network_stream_cache(stream_t *stream) { + struct MPOpts *opts = stream->opts; if(stream->streaming_ctrl->buffering) { - if(stream_cache_size<0) { + if(opts->stream_cache_size<0) { // cache option not set, will use our computed value. // buffer in KBytes, *5 because the prefill is 20% of the buffer. - stream_cache_size = (stream->streaming_ctrl->prebuffer_size/1024)*5; - if( stream_cache_size<64 ) stream_cache_size = 64; // 16KBytes min buffer + opts->stream_cache_size = (stream->streaming_ctrl->prebuffer_size/1024)*5; + if( opts->stream_cache_size<64 ) opts->stream_cache_size = 64; // 16KBytes min buffer } - mp_tmsg(MSGT_NETWORK,MSGL_INFO,"Cache size set to %d KBytes\n", stream_cache_size); + mp_tmsg(MSGT_NETWORK,MSGL_INFO,"Cache size set to %d KBytes\n", opts->stream_cache_size); } } diff --git a/stream/stream.h b/stream/stream.h index eeb2f769bd..0cee8498eb 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -184,6 +184,8 @@ int stream_fill_buffer(stream_t *s); int stream_seek_long(stream_t *s, off_t pos); #ifdef CONFIG_STREAM_CACHE +int stream_enable_cache_percent(stream_t *stream, int64_t stream_cache_size, + float stream_cache_min_percent, float stream_cache_seek_min_percent); int stream_enable_cache(stream_t *stream,int64_t size,int64_t min,int64_t prefill); int cache_stream_fill_buffer(stream_t *s); int cache_stream_seek_long(stream_t *s,int64_t pos); @@ -192,6 +194,7 @@ int cache_stream_seek_long(stream_t *s,int64_t pos); #define cache_stream_fill_buffer(x) stream_fill_buffer(x) #define cache_stream_seek_long(x,y) stream_seek_long(x,y) #define stream_enable_cache(x,y,z,w) 1 +#define stream_enable_cache_percent(x,y,z,w) 1 #endif int stream_write_buffer(stream_t *s, unsigned char *buf, int len); 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; |