summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2012-11-17 19:12:13 +0200
committerwm4 <wm4@nowhere>2012-12-03 21:08:51 +0100
commit2d58234c86e59298de52fec12d1eb59086d68763 (patch)
treed11ec050f30e1fa47cbf30475e6d84adf8080468 /core
parentc082240c62cb8855e55c0dbe88b8591458599ce9 (diff)
downloadmpv-2d58234c86e59298de52fec12d1eb59086d68763.tar.bz2
mpv-2d58234c86e59298de52fec12d1eb59086d68763.tar.xz
cache: refactor how cache enabling is done
Code enabling the cache by default for network streams did that by modifying the value of the "cache" option. This wasn't sane, as multiple streams may be created and all share the same options. Change the code to not modify options but store data in the stream instance instead. Conflicts: core/mplayer.c demux/demux.c stream/cache2.c stream/network.c stream/network.h stream/pnm.c stream/stream.c stream/stream_rtp.c Merged from mplayer2 commit e26070. Note that this doesn't solve any actual bug, as the playlist crashing bug has been fixed before. Since the global cache size option value is not overwritten anymore, the option doesn't need to be restored on end of playback (M_OPT_LOCAL).
Diffstat (limited to 'core')
-rw-r--r--core/cfg-mplayer.h3
-rw-r--r--core/mplayer.c39
-rw-r--r--core/timeline/tl_matroska.c3
3 files changed, 17 insertions, 28 deletions
diff --git a/core/cfg-mplayer.h b/core/cfg-mplayer.h
index 23b937f91a..b1c693a5a9 100644
--- a/core/cfg-mplayer.h
+++ b/core/cfg-mplayer.h
@@ -324,8 +324,7 @@ const m_option_t common_opts[] = {
// ------------------------- stream options --------------------
#ifdef CONFIG_STREAM_CACHE
- OPT_INTRANGE("cache", stream_cache_size, M_OPT_LOCAL, 32, 0x7fffffff,
- OPTDEF_INT(-1)),
+ OPT_INTRANGE("cache", stream_cache_size, 0, 32, 0x7fffffff, OPTDEF_INT(-1)),
OPT_FLAG_CONSTANTS("no-cache", stream_cache_size, 0, -1, 0),
OPT_FLOATRANGE("cache-min", stream_cache_min_percent, 0, 0, 99),
diff --git a/core/mplayer.c b/core/mplayer.c
index c636c0012c..cc1749fb6b 100644
--- a/core/mplayer.c
+++ b/core/mplayer.c
@@ -1183,7 +1183,7 @@ static void print_status(struct MPContext *mpctx)
#ifdef CONFIG_STREAM_CACHE
// cache stats
- if (opts->stream_cache_size > 0)
+ if (mpctx->stream->cached)
saddf(line, width, " C: %d%%", cache_fill_status(mpctx->stream));
#endif
@@ -3301,7 +3301,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 && opts->stream_cache_size > 0)
+ if (mpctx->paused && mpctx->stream && mpctx->stream->cached)
print_status(mpctx);
#endif
@@ -3633,25 +3633,16 @@ static void open_external_file(struct MPContext *mpctx, char *filename,
char *demuxer_name, int stream_cache,
enum stream_type filter)
{
+ struct MPOpts *opts = &mpctx->opts;
if (!filename)
return;
int format = 0;
struct stream *stream = open_stream(filename, &mpctx->opts, &format);
if (!stream)
goto err_out;
- if (stream_cache) {
- if (!stream_enable_cache(stream, stream_cache * 1024,
- stream_cache * 1024 *
- (mpctx->opts.stream_cache_min_percent / 100.0),
- stream_cache * 1024 *
- (mpctx->opts.stream_cache_seek_min_percent / 100.0)))
- {
- free_stream(stream);
- mp_msg(MSGT_CPLAYER, MSGL_ERR,
- "Can't enable external file stream cache\n");
- return;
- }
- }
+ stream_enable_cache_percent(stream, stream_cache,
+ opts->stream_cache_min_percent,
+ opts->stream_cache_seek_min_percent);
// deal with broken demuxers: preselect streams
int vs = -2, as = -2, ss = -2;
switch (filter) {
@@ -3893,17 +3884,15 @@ static void play_current_file(struct MPContext *mpctx)
// CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
#ifdef CONFIG_DVBIN
-goto_enable_cache:
+goto_enable_cache: ;
#endif
- 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 (demux_was_interrupted(mpctx))
- goto terminate_playback;
- }
+ 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 (demux_was_interrupted(mpctx))
+ goto terminate_playback;
//============ Open DEMUXERS --- DETECT file type =======================
diff --git a/core/timeline/tl_matroska.c b/core/timeline/tl_matroska.c
index a87889edd8..75530116aa 100644
--- a/core/timeline/tl_matroska.c
+++ b/core/timeline/tl_matroska.c
@@ -127,7 +127,8 @@ static int enable_cache(struct MPContext *mpctx, struct stream **stream,
{
struct MPOpts *opts = &mpctx->opts;
- if (opts->stream_cache_size <= 0)
+ if (!(opts->stream_cache_size > 0 ||
+ opts->stream_cache_size < 0 && (*stream)->cache_size))
return 0;
char *filename = talloc_strdup(NULL, (*demuxer)->filename);