aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2024-02-26 01:12:23 +0100
committerMarton Balint <cus@passwd.hu>2024-03-02 19:13:03 +0100
commit3a09c2122d1f77c3e14c43855b21ef1da9f7fa27 (patch)
tree49b9ae5fd6d5006f3724d9185604cd590f737f1e /libavformat
parent315be8b27926fb46338a8fc10cf39cbb9f99dcc8 (diff)
downloadffmpeg-3a09c2122d1f77c3e14c43855b21ef1da9f7fa27.tar.gz
avformat/wavdec: dynamically set max_size by default
The wav demuxer by default tried to demux 4096-byte packets which caused packets with very few number of samples for files with high channel count. This caused a significant overhead especially since the latest ffmpeg.c threading changes. So let's use a similar approach for selecting audio frame size which is already used in the PCM demuxer, which is to read 25 times per second but at most 1024 samples. Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/wavdec.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 0c6629b157..5ceb8bef23 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -73,10 +73,25 @@ static const AVOption demux_options[] = {
#if CONFIG_WAV_DEMUXER
{ "ignore_length", "Ignore length", OFFSET(ignore_length), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, DEC },
#endif
- { "max_size", "max size of single packet", OFFSET(max_size), AV_OPT_TYPE_INT, { .i64 = 4096 }, 1024, 1 << 22, DEC },
+ { "max_size", "max size of single packet", OFFSET(max_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1 << 22, DEC },
{ NULL },
};
+static void set_max_size(AVStream *st, WAVDemuxContext *wav)
+{
+ if (wav->max_size <= 0) {
+ int64_t nb_samples = av_clip(st->codecpar->sample_rate / 25, 1, 1024);
+ if (st->codecpar->block_align > 0 &&
+ st->codecpar->block_align * nb_samples < INT_MAX &&
+ st->codecpar->ch_layout.nb_channels > 0 &&
+ st->codecpar->block_align <= 8LL * st->codecpar->ch_layout.nb_channels) {
+ wav->max_size = st->codecpar->block_align * nb_samples;
+ } else {
+ wav->max_size = 4096;
+ }
+ }
+}
+
static void set_spdif(AVFormatContext *s, WAVDemuxContext *wav)
{
if (CONFIG_SPDIF_DEMUXER && s->streams[0]->codecpar->codec_tag == 1) {
@@ -669,6 +684,7 @@ break_loop:
ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv);
set_spdif(s, wav);
+ set_max_size(st, wav);
return 0;
}
@@ -981,6 +997,7 @@ static int w64_read_header(AVFormatContext *s)
avio_seek(pb, data_ofs, SEEK_SET);
set_spdif(s, wav);
+ set_max_size(st, wav);
return 0;
}