From f37f4de8496556afaa024e39e2efb433eb1680d4 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 6 Nov 2019 21:36:02 +0100 Subject: stream: turn into a ring buffer, make size configurable In some corner cases (see #6802), it can be beneficial to use a larger stream buffer size. Use this as argument to rewrite everything for no reason. Turn stream.c itself into a ring buffer, with configurable size. The latter would have been easily achievable with minimal changes, and the ring buffer is the hard part. There is no reason to have a ring buffer at all, except possibly if ffmpeg don't fix their awful mp4 demuxer, and some subtle issues with demux_mkv.c wanting to seek back by small offsets (the latter was handled with small stream_peek() calls, which are unneeded now). In addition, this turns small forward seeks into reads (where data is simply skipped). Before this commit, only stream_skip() did this (which also mean that stream_skip() simply calls stream_seek() now). Replace all stream_peek() calls with something else (usually stream_read_peek()). The function was a problem, because it returned a pointer to the internal buffer, which is now a ring buffer with wrapping. The new function just copies the data into a buffer, and in some cases requires callers to dynamically allocate memory. (The most common case, demux_lavf.c, required a separate buffer allocation anyway due to FFmpeg "idiosyncrasies".) This is the bulk of the demuxer_* changes. I'm not happy with this. There still isn't a good reason why there should be a ring buffer, that is complex, and most of the time just wastes half of the available memory. Maybe another rewrite soon. It also contains bugs; you're an alpha tester now. --- options/options.c | 1 + options/options.h | 2 ++ 2 files changed, 3 insertions(+) (limited to 'options') diff --git a/options/options.c b/options/options.c index 4fbf9d6401..79ae3ca5ab 100644 --- a/options/options.c +++ b/options/options.c @@ -711,6 +711,7 @@ const m_option_t mp_opts[] = { OPT_SUBSTRUCT("", vo, vo_sub_opts, 0), OPT_SUBSTRUCT("", demux_opts, demux_conf, 0), OPT_SUBSTRUCT("", demux_cache_opts, demux_cache_conf, 0), + OPT_SUBSTRUCT("", stream_opts, stream_conf, 0), OPT_SUBSTRUCT("", gl_video_opts, gl_video_conf, 0), OPT_SUBSTRUCT("", spirv_opts, spirv_conf, 0), diff --git a/options/options.h b/options/options.h index 441d06b285..7af86ab9fb 100644 --- a/options/options.h +++ b/options/options.h @@ -307,6 +307,7 @@ typedef struct MPOpts { struct demux_opts *demux_opts; struct demux_cache_opts *demux_cache_opts; + struct stream_opts *stream_opts; struct vd_lavc_params *vd_lavc_params; struct ad_lavc_params *ad_lavc_params; @@ -360,5 +361,6 @@ extern const struct m_sub_options mp_subtitle_sub_opts; extern const struct m_sub_options mp_osd_render_sub_opts; extern const struct m_sub_options filter_conf; extern const struct m_sub_options resample_conf; +extern const struct m_sub_options stream_conf; #endif -- cgit v1.2.3