From: Marton Balint <cus@passwd.hu>
To: ffmpeg-devel@ffmpeg.org
Cc: Marton Balint <cus@passwd.hu>
Subject: [FFmpeg-devel] [PATCH 7/9] avformat/pcm: use a common default packet size function for both wav and pcm
Date: Tue, 5 Mar 2024 23:51:45 +0100
Message-ID: <20240305225147.6849-7-cus@passwd.hu> (raw)
In-Reply-To: <20240305225147.6849-1-cus@passwd.hu>
Signed-off-by: Marton Balint <cus@passwd.hu>
---
libavformat/pcm.c | 38 ++++++++++++++++++++++++++------------
libavformat/pcm.h | 1 +
libavformat/wavdec.c | 11 ++---------
3 files changed, 29 insertions(+), 21 deletions(-)
diff --git a/libavformat/pcm.c b/libavformat/pcm.c
index 9741f73667..b3d23110ab 100644
--- a/libavformat/pcm.c
+++ b/libavformat/pcm.c
@@ -24,26 +24,40 @@
#include "internal.h"
#include "pcm.h"
-#define RAW_SAMPLES 1024
+#define PCM_DEMUX_TARGET_FPS 25
+#define PCM_DEMUX_MAX_SAMPLES 1024
-int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
+int ff_pcm_default_packet_size(AVCodecParameters *par)
{
- AVCodecParameters *par = s->streams[0]->codecpar;
- int ret, size;
+ int nb_samples, max_samples;
if (par->block_align <= 0)
return AVERROR(EINVAL);
+ if (par->ch_layout.nb_channels <= 0)
+ return AVERROR(EINVAL);
+
+ /* Unusually large block_align means a non-pcm codec */
+ if (par->block_align > 8LL * par->ch_layout.nb_channels)
+ return AVERROR(EINVAL);
+
/*
- * Compute read size to complete a read every 62ms.
- * Clamp to RAW_SAMPLES if larger.
+ * Compute read size based on PCM_DEMUX_TARGET_FPS
+ * Clamp to PCM_DEMUX_MAX_SAMPLES if larger.
*/
- size = FFMAX(par->sample_rate/25, 1);
- if (par->block_align <= INT_MAX / RAW_SAMPLES) {
- size = FFMIN(size, RAW_SAMPLES) * par->block_align;
- } else {
- size = par->block_align;
- }
+ max_samples = FFMIN(PCM_DEMUX_MAX_SAMPLES, INT_MAX / par->block_align);
+ nb_samples = av_clip(par->sample_rate / PCM_DEMUX_TARGET_FPS, 1, max_samples);
+
+ return par->block_align * nb_samples;
+}
+
+int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ int ret, size;
+
+ size = ff_pcm_default_packet_size(s->streams[0]->codecpar);
+ if (size < 0)
+ return size;
ret = av_get_packet(s->pb, pkt, size);
diff --git a/libavformat/pcm.h b/libavformat/pcm.h
index 9af36d5a2e..1928497eed 100644
--- a/libavformat/pcm.h
+++ b/libavformat/pcm.h
@@ -24,6 +24,7 @@
#include "avformat.h"
+int ff_pcm_default_packet_size(AVCodecParameters *par);
int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt);
int ff_pcm_read_seek(AVFormatContext *s,
int stream_index, int64_t timestamp, int flags);
diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 5ceb8bef23..61b4b12dc5 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -80,15 +80,8 @@ static const AVOption demux_options[] = {
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;
- }
+ int max_size = ff_pcm_default_packet_size(st->codecpar);
+ wav->max_size = max_size < 0 ? 4096 : max_size;
}
}
--
2.35.3
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-03-05 22:52 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-05 22:51 [FFmpeg-devel] [PATCH 1/9] avcodec/bsf/pcm_rechunk: reorder supported codec list Marton Balint
2024-03-05 22:51 ` [FFmpeg-devel] [PATCH 2/9] avcodec/bsf/pcm_rechunk: add some more supported PCM formats Marton Balint
2024-03-06 14:18 ` Stefano Sabatini
2024-03-05 22:51 ` [FFmpeg-devel] [PATCH 3/9] avformat/daudenc: force 2000 sample packet size with a bsf Marton Balint
2024-03-06 14:24 ` Stefano Sabatini
2024-03-05 22:51 ` [FFmpeg-devel] [PATCH 4/9] fate: make filter-channelsplit test use a fixed frame size Marton Balint
2024-03-05 22:51 ` [FFmpeg-devel] [PATCH 5/9] fate: use a fixed wav demux packet size for amix tests Marton Balint
2024-03-05 22:51 ` [FFmpeg-devel] [PATCH 6/9] fate: use atrim filter instead of -frames:a 20 for fate-filter-tremolo Marton Balint
2024-03-05 22:51 ` Marton Balint [this message]
2024-03-06 20:37 ` [FFmpeg-devel] [PATCH 7/9] avformat/pcm: use a common default packet size function for both wav and pcm Michael Niedermayer
2024-03-05 22:51 ` [FFmpeg-devel] [PATCH 8/9] avformat/pcm: remove max samples cap when calculating the default packet size Marton Balint
2024-03-05 22:51 ` [FFmpeg-devel] [PATCH 9/9] avformat/pcm: decrease target audio frame per sec to 10 Marton Balint
2024-03-06 13:47 ` [FFmpeg-devel] [PATCH 1/9] avcodec/bsf/pcm_rechunk: reorder supported codec list Stefano Sabatini
2024-03-08 0:53 ` [FFmpeg-devel] [PATCH v2 " Marton Balint
2024-03-08 0:53 ` [FFmpeg-devel] [PATCH v2 2/9] avcodec/bsf/pcm_rechunk: add some more supported PCM formats Marton Balint
2024-03-09 16:21 ` Stefano Sabatini
2024-03-08 0:53 ` [FFmpeg-devel] [PATCH v2 3/9] avformat/daudenc: force 2000 sample packet size with a bsf Marton Balint
2024-03-09 16:23 ` Stefano Sabatini
2024-03-08 0:53 ` [FFmpeg-devel] [PATCH v2 4/9] fate: make filter-channelsplit test use a fixed frame size Marton Balint
2024-03-08 0:53 ` [FFmpeg-devel] [PATCH v2 5/9] fate: use a fixed wav demux packet size for amix tests Marton Balint
2024-03-08 0:53 ` [FFmpeg-devel] [PATCH v2 6/9] fate: use atrim filter instead of -frames:a 20 for fate-filter-tremolo Marton Balint
2024-03-08 0:53 ` [FFmpeg-devel] [PATCH v2 7/9] avformat/pcm: factorize and improve determining the default packet size Marton Balint
2024-03-12 21:31 ` Marton Balint
2024-03-14 23:18 ` [FFmpeg-devel] [PATCH v3 " Marton Balint
2024-03-16 8:45 ` Marton Balint
2024-03-08 0:53 ` [FFmpeg-devel] [PATCH v2 8/9] avformat/wavdec: use ff_pcm_default_packet_size for " Marton Balint
2024-03-08 0:53 ` [FFmpeg-devel] [PATCH v2 9/9] avformat/pcm: decrease target audio frame per sec to 10 Marton Balint
2024-03-14 8:10 ` Tobias Rapp
2024-03-14 11:12 ` Paul B Mahol
2024-03-14 22:30 ` Marton Balint
2024-03-17 12:44 ` Paul B Mahol
2024-03-14 22:04 ` Marton Balint
2024-03-15 7:54 ` Tobias Rapp
2024-03-09 16:20 ` [FFmpeg-devel] [PATCH v2 1/9] avcodec/bsf/pcm_rechunk: reorder supported codec list Stefano Sabatini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240305225147.6849-7-cus@passwd.hu \
--to=cus@passwd.hu \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git