diff options
-rw-r--r-- | core/mplayer.c | 25 | ||||
-rw-r--r-- | stream/asf_mmst_streaming.c | 2 | ||||
-rw-r--r-- | stream/asf_streaming.c | 11 | ||||
-rw-r--r-- | stream/cache2.c | 20 | ||||
-rw-r--r-- | stream/cache2.h | 1 | ||||
-rw-r--r-- | stream/http.c | 6 | ||||
-rw-r--r-- | stream/stream.c | 10 | ||||
-rw-r--r-- | stream/stream.h | 9 | ||||
-rw-r--r-- | stream/stream_udp.c | 3 |
9 files changed, 45 insertions, 42 deletions
diff --git a/core/mplayer.c b/core/mplayer.c index cc1749fb6b..e60c7e173c 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -1038,6 +1038,19 @@ void init_vo_spudec(struct MPContext *mpctx) } } +static int get_cache_percent(struct MPContext *mpctx) +{ + if (mpctx->stream) { + int64_t size = -1; + int64_t fill = -1; + stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_SIZE, &size); + stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_FILL, &fill); + if (size > 0 && fill >= 0) + return fill / (size / 100); + } + return -1; +} + /** * \brief append a formatted string * \param buf buffer to print into @@ -1181,11 +1194,9 @@ static void print_status(struct MPContext *mpctx) saddf(line, width, " D: %d", drop_frame_cnt); } -#ifdef CONFIG_STREAM_CACHE - // cache stats - if (mpctx->stream->cached) - saddf(line, width, " C: %d%%", cache_fill_status(mpctx->stream)); -#endif + int cache = get_cache_percent(mpctx); + if (cache >= 0) + saddf(line, width, " C: %d%%", cache); // end write_status_line(mpctx, line); @@ -3299,11 +3310,9 @@ static void run_playloop(struct MPContext *mpctx) update_osd_msg(mpctx); -#ifdef CONFIG_STREAM_CACHE // The cache status is part of the status line. Possibly update it. - if (mpctx->paused && mpctx->stream && mpctx->stream->cached) + if (mpctx->paused && get_cache_percent(mpctx) >= 0) print_status(mpctx); -#endif if (!video_left && (!mpctx->paused || was_restart)) { double a_pos = 0; diff --git a/stream/asf_mmst_streaming.c b/stream/asf_mmst_streaming.c index 371e256da5..98c386d11d 100644 --- a/stream/asf_mmst_streaming.c +++ b/stream/asf_mmst_streaming.c @@ -671,8 +671,8 @@ int asf_mmst_streaming_start(stream_t *stream) stream->fd = s; stream->streaming_ctrl->streaming_read = asf_mmst_streaming_read; stream->streaming_ctrl->streaming_seek = asf_mmst_streaming_seek; - stream->streaming_ctrl->buffering = 1; stream->streaming_ctrl->status = streaming_playing_e; + stream->streaming = true; packet_length1 = packet_length; mp_msg(MSGT_NETWORK,MSGL_INFO,"mmst packet_length = %d\n", packet_length); diff --git a/stream/asf_streaming.c b/stream/asf_streaming.c index 31e0d71b89..9b6e2e3a64 100644 --- a/stream/asf_streaming.c +++ b/stream/asf_streaming.c @@ -166,7 +166,8 @@ static int max_idx(int s_count, int *s_rates, int bound) { return best; } -static int asf_streaming_parse_header(int fd, streaming_ctrl_t* streaming_ctrl) { +static int asf_streaming_parse_header(stream_t *s, int fd) { + streaming_ctrl_t* streaming_ctrl = s->streaming_ctrl; ASF_stream_chunck_t chunk; asf_http_streaming_ctrl_t* asf_ctrl = streaming_ctrl->data; char* buffer=NULL, *chunk_buffer=NULL; @@ -246,7 +247,9 @@ static int asf_streaming_parse_header(int fd, streaming_ctrl_t* streaming_ctrl) asf_ctrl->packet_size = AV_RL32(&fileh->max_packet_size); // before playing. // preroll: time in ms to bufferize before playing - streaming_ctrl->prebuffer_size = (unsigned int)(((double)fileh->preroll/1000.0)*((double)fileh->max_bitrate/8.0)); + unsigned int preroll = (unsigned int)(((double)fileh->preroll/1000.0)*((double)fileh->max_bitrate/8.0)); + // buffer in KBytes, *5 assuming the prefill is 20% of the buffer. + s->cache_size = preroll / 1024 * 5; } pos = start; @@ -754,7 +757,7 @@ static int asf_http_streaming_start( stream_t *stream, int *demuxer_type ) { if( asf_http_ctrl->request==1 ) { if( asf_http_ctrl->streaming_type!=ASF_PlainText_e ) { // First request, we only got the ASF header. - ret = asf_streaming_parse_header(fd,stream->streaming_ctrl); + ret = asf_streaming_parse_header(stream,fd); if(ret < 0) goto err_out; if(asf_http_ctrl->n_audio == 0 && asf_http_ctrl->n_video == 0) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"No stream found.\n"); @@ -796,7 +799,7 @@ static int asf_http_streaming_start( stream_t *stream, int *demuxer_type ) { } else { stream->streaming_ctrl->streaming_read = asf_http_streaming_read; stream->streaming_ctrl->streaming_seek = asf_http_streaming_seek; - stream->streaming_ctrl->buffering = 1; + stream->streaming = true; } stream->streaming_ctrl->status = streaming_playing_e; stream->close = close_s; diff --git a/stream/cache2.c b/stream/cache2.c index 27147d00fb..8b35150321 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -360,9 +360,9 @@ static cache_vars_t* cache_init(int64_t size,int sector){ memset(s,0,sizeof(cache_vars_t)); num=size/sector; - if(num < 16){ - num = 16; - }//32kb min_size + if(num < 32){ + num = 32; + }//64kb min_size s->buffer_size=num*sector; s->sector_size=sector; s->buffer=shared_alloc(s->buffer_size); @@ -583,14 +583,6 @@ int cache_stream_fill_buffer(stream_t *s){ } -int cache_fill_status(stream_t *s) { - cache_vars_t *cv; - if (!s || !s->cache_data) - return -1; - cv = s->cache_data; - return (cv->max_filepos-cv->read_filepos)/(cv->buffer_size / 100); -} - int cache_stream_seek_long(stream_t *stream,int64_t pos){ cache_vars_t* s; int64_t newpos; @@ -626,6 +618,12 @@ int cache_do_control(stream_t *stream, int cmd, void *arg) { int pos_change = 0; cache_vars_t* s = stream->cache_data; switch (cmd) { + case STREAM_CTRL_GET_CACHE_SIZE: + *(int64_t *)arg = s->buffer_size; + return STREAM_OK; + case STREAM_CTRL_GET_CACHE_FILL: + *(int64_t *)arg = s->max_filepos - s->read_filepos; + return STREAM_OK; case STREAM_CTRL_SEEK_TO_TIME: s->control_double_arg = *(double *)arg; s->control = cmd; diff --git a/stream/cache2.h b/stream/cache2.h index 9c98193f0c..330558333e 100644 --- a/stream/cache2.h +++ b/stream/cache2.h @@ -23,6 +23,5 @@ void cache_uninit(stream_t *s); int cache_do_control(stream_t *stream, int cmd, void *arg); -int cache_fill_status(stream_t *s); #endif /* MPLAYER_CACHE2_H */ diff --git a/stream/http.c b/stream/http.c index c77e7e05c5..8b71435d2f 100644 --- a/stream/http.c +++ b/stream/http.c @@ -214,9 +214,8 @@ static int scast_streaming_start(stream_t *stream) { stream->streaming_ctrl->data = scast_data; stream->streaming_ctrl->streaming_read = scast_streaming_read; stream->streaming_ctrl->streaming_seek = NULL; - stream->streaming_ctrl->prebuffer_size = 64 * 1024; // 64 KBytes - stream->streaming_ctrl->buffering = 1; stream->streaming_ctrl->status = streaming_playing_e; + stream->streaming = true; return 0; } @@ -293,9 +292,8 @@ static int nop_streaming_start( stream_t *stream ) { stream->streaming_ctrl->streaming_read = nop_streaming_read; stream->streaming_ctrl->streaming_seek = nop_streaming_seek; - stream->streaming_ctrl->prebuffer_size = 64*1024; // 64 KBytes - stream->streaming_ctrl->buffering = 1; stream->streaming_ctrl->status = streaming_playing_e; + stream->streaming = true; return 0; } diff --git a/stream/stream.c b/stream/stream.c index bd87448fac..6e0644e59c 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -183,13 +183,9 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo, return NULL; } - s->cache_size = 0; - if (s->streaming_ctrl && s->streaming_ctrl->buffering) { + if (s->streaming && !s->cache_size) { // 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; + s->cache_size = 320; } if(s->type <= -2) @@ -480,11 +476,11 @@ void stream_reset(stream_t *s){ } int stream_control(stream_t *s, int cmd, void *arg){ - if(!s->control) return STREAM_UNSUPPORTED; #ifdef CONFIG_STREAM_CACHE if (s->cache_pid) return cache_do_control(s, cmd, arg); #endif + if(!s->control) return STREAM_UNSUPPORTED; return s->control(s, cmd, arg); } diff --git a/stream/stream.h b/stream/stream.h index dd092ddaec..a112b0f3f6 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -98,6 +98,8 @@ #define STREAM_CTRL_GET_NUM_TITLES 12 #define STREAM_CTRL_GET_LANG 13 #define STREAM_CTRL_GET_CURRENT_TITLE 14 +#define STREAM_CTRL_GET_CACHE_SIZE 15 +#define STREAM_CTRL_GET_CACHE_FILL 16 struct stream_lang_req { int type; // STREAM_AUDIO, STREAM_SUB @@ -113,8 +115,6 @@ typedef enum { typedef struct streaming_control { URL_t *url; streaming_status status; - int buffering; // boolean - unsigned int prebuffer_size; char *buffer; unsigned int buffer_size; unsigned int buffer_pos; @@ -167,8 +167,9 @@ 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; + bool streaming; // known to be a network stream if true + int cache_size; // cache size in KB to use if enabled + bool cached; // cache active unsigned int cache_pid; void* cache_data; void* priv; // used for DVD, TV, RTSP etc diff --git a/stream/stream_udp.c b/stream/stream_udp.c index 22b9cefc57..fc7da19aa0 100644 --- a/stream/stream_udp.c +++ b/stream/stream_udp.c @@ -51,9 +51,8 @@ udp_streaming_start (stream_t *stream) streaming_ctrl->streaming_read = nop_streaming_read; streaming_ctrl->streaming_seek = nop_streaming_seek; - streaming_ctrl->prebuffer_size = 64 * 1024; /* 64 KBytes */ - streaming_ctrl->buffering = 0; streaming_ctrl->status = streaming_playing_e; + stream->streaming = false; return 0; } |