diff options
-rw-r--r-- | core/cfg-mplayer.h | 3 | ||||
-rw-r--r-- | core/mplayer.c | 39 | ||||
-rw-r--r-- | core/timeline/tl_matroska.c | 3 | ||||
-rw-r--r-- | stream/asf_streaming.c | 1 | ||||
-rw-r--r-- | stream/cache2.c | 10 | ||||
-rw-r--r-- | stream/http.c | 1 | ||||
-rw-r--r-- | stream/network.c | 16 | ||||
-rw-r--r-- | stream/network.h | 1 | ||||
-rw-r--r-- | stream/stream.c | 14 | ||||
-rw-r--r-- | stream/stream.h | 7 | ||||
-rw-r--r-- | stream/stream_udp.c | 1 |
11 files changed, 41 insertions, 55 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); diff --git a/stream/asf_streaming.c b/stream/asf_streaming.c index e3bfbe9019..31e0d71b89 100644 --- a/stream/asf_streaming.c +++ b/stream/asf_streaming.c @@ -839,7 +839,6 @@ static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { if (*file_format != DEMUXER_TYPE_PLAYLIST) *file_format = DEMUXER_TYPE_ASF; stream->type = STREAMTYPE_STREAM; - fixup_network_stream_cache(stream); return STREAM_OK; } diff --git a/stream/cache2.c b/stream/cache2.c index d547f9e5ea..27147d00fb 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -452,7 +452,14 @@ int stream_enable_cache_percent(stream_t *stream, int64_t stream_cache_size, /** * \return 1 on success, 0 if the function was interrupted and -1 on error */ -int stream_enable_cache(stream_t *stream,int64_t size,int64_t min,int64_t seek_limit){ +int stream_enable_cache(stream_t *stream,int64_t size,int64_t min,int64_t seek_limit) +{ + if (size < 0) + size = stream->cache_size * 1024; + if (!size) + return 1; + mp_tmsg(MSGT_NETWORK,MSGL_INFO,"Cache size set to %"PRId64" KiB\n", size / 1024); + int ss = stream->sector_size ? stream->sector_size : STREAM_BUFFER_SIZE; int res = -1; cache_vars_t* s; @@ -521,6 +528,7 @@ int stream_enable_cache(stream_t *stream,int64_t size,int64_t min,int64_t seek_l } } mp_msg(MSGT_CACHE,MSGL_STATUS,"\n"); + stream->cached = true; return 1; // parent exits err_out: diff --git a/stream/http.c b/stream/http.c index 1638d80790..c77e7e05c5 100644 --- a/stream/http.c +++ b/stream/http.c @@ -880,7 +880,6 @@ static int fixup_open(stream_t *stream,int seekable) { return STREAM_UNSUPPORTED; } - fixup_network_stream_cache(stream); return STREAM_OK; } diff --git a/stream/network.c b/stream/network.c index fb432d47c0..56e5a1b5e1 100644 --- a/stream/network.c +++ b/stream/network.c @@ -461,19 +461,3 @@ int nop_streaming_seek( int fd, int64_t pos, streaming_ctrl_t *stream_ctrl ) { return -1; } - - -void fixup_network_stream_cache(stream_t *stream) { - struct MPOpts *opts = stream->opts; - if(!opts) - return; - if(stream->streaming_ctrl->buffering) { - 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. - 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", opts->stream_cache_size); - } -} diff --git a/stream/network.h b/stream/network.h index ee6a940c99..6e21453b16 100644 --- a/stream/network.h +++ b/stream/network.h @@ -77,7 +77,6 @@ int http_authenticate(HTTP_header_t *http_hdr, URL_t *url, int *auth_retry); URL_t* check4proxies(const URL_t *url); URL_t *url_new_with_proxy(const char *urlstr); -void fixup_network_stream_cache(stream_t *stream); int http_seek(stream_t *stream, int64_t pos); #endif /* MPLAYER_NETWORK_H */ diff --git a/stream/stream.c b/stream/stream.c index 94a7c4cf6d..bd87448fac 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -182,6 +182,16 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo, free(s); return NULL; } + + s->cache_size = 0; + if (s->streaming_ctrl && s->streaming_ctrl->buffering) { + // Set default cache size to use if user does not specify it. + // buffer in KBytes, *5 assuming the prefill is 20% of the buffer. + s->cache_size = s->streaming_ctrl->prebuffer_size / 1024 * 5; + if (s->cache_size < 64) + s->cache_size = 64; + } + if(s->type <= -2) mp_msg(MSGT_OPEN,MSGL_WARN, "Warning streams need a type !!!!\n"); if(s->flags & MP_STREAM_SEEK && !s->seek) @@ -200,8 +210,8 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo, } -stream_t *open_stream_full(const char *filename, int mode, - struct MPOpts *options, int *file_format) +static stream_t *open_stream_full(const char *filename, int mode, + struct MPOpts *options, int *file_format) { int i,j,l,r; const stream_info_t* sinfo; diff --git a/stream/stream.h b/stream/stream.h index 28557e8c6e..dd092ddaec 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -22,6 +22,7 @@ #include "config.h" #include "core/mp_msg.h" #include "url.h" +#include <stdbool.h> #include <stdio.h> #include <string.h> #include <inttypes.h> @@ -166,15 +167,15 @@ typedef struct stream { int64_t pos,start_pos,end_pos; int eof; int mode; //STREAM_READ or STREAM_WRITE + int cache_size; // cache size to use if enabled + bool cached; unsigned int cache_pid; void* cache_data; void* priv; // used for DVD, TV, RTSP etc char* url; // strdup() of filename/url char *lavf_type; // name of expected demuxer type for lavf struct MPOpts *opts; -#ifdef CONFIG_NETWORKING streaming_ctrl_t *streaming_ctrl; -#endif unsigned char buffer[STREAM_BUFFER_SIZE>STREAM_MAX_SECTOR_SIZE?STREAM_BUFFER_SIZE:STREAM_MAX_SECTOR_SIZE]; } stream_t; @@ -356,8 +357,6 @@ void free_stream(stream_t *s); stream_t* new_memory_stream(unsigned char* data,int len); stream_t *open_stream(const char *filename, struct MPOpts *options, int *file_format); -stream_t *open_stream_full(const char *filename,int mode, - struct MPOpts *options, int *file_format); stream_t *open_output_stream(const char *filename, struct MPOpts *options); struct demux_stream; struct stream *new_ds_stream(struct demux_stream *ds); diff --git a/stream/stream_udp.c b/stream/stream_udp.c index 2654a01577..22b9cefc57 100644 --- a/stream/stream_udp.c +++ b/stream/stream_udp.c @@ -91,7 +91,6 @@ udp_stream_open (stream_t *stream, int mode, void *opts, int *file_format) } stream->type = STREAMTYPE_STREAM; - fixup_network_stream_cache (stream); return STREAM_OK; } |