From: mkver via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: mkver <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avcodec/liblc3{dec,enc}: Simplify sample_size, is_planar check, sample fmt selection (PR #20998)
Date: Sat, 22 Nov 2025 23:29:11 -0000
Message-ID: <176385415248.59.13150557062275567884@2cb04c0e5124> (raw)
PR #20998 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20998
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20998.patch
>From e528d76b28240e5502fdea12ad9bf0a583420043 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Sat, 22 Nov 2025 23:56:14 +0100
Subject: [PATCH 1/2] avcodec/liblc3{dec,enc}: Simplify sample_size, is_planar
check
Sample size is always sizeof(float), is planar is a simple if
given that these codecs only support float and planar float.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/liblc3dec.c | 9 +++------
libavcodec/liblc3enc.c | 15 ++++++---------
2 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/libavcodec/liblc3dec.c b/libavcodec/liblc3dec.c
index 293325ba2b..a0989c88b0 100644
--- a/libavcodec/liblc3dec.c
+++ b/libavcodec/liblc3dec.c
@@ -123,8 +123,6 @@ static int liblc3_decode(AVCodecContext *avctx, AVFrame *frame,
int channels = avctx->ch_layout.nb_channels;
uint8_t *in = avpkt->data;
int block_bytes, ret;
- size_t sample_size;
- int is_planar;
frame->nb_samples = av_rescale(
liblc3->frame_us, liblc3->srate_hz, 1000*1000);
@@ -132,13 +130,12 @@ static int liblc3_decode(AVCodecContext *avctx, AVFrame *frame,
return ret;
block_bytes = avpkt->size;
- is_planar = av_sample_fmt_is_planar(avctx->sample_fmt);
- sample_size = av_get_bytes_per_sample(avctx->sample_fmt);
+ int is_planar = avctx->sample_fmt == AV_SAMPLE_FMT_FLTP;
for (int ch = 0; ch < channels; ch++) {
int nbytes = block_bytes / channels + (ch < block_bytes % channels);
- void *pcm_data = is_planar ? frame->extended_data[ch] :
- frame->extended_data[0] + ch * sample_size;
+ float *pcm_data = is_planar ? (float*)frame->extended_data[ch] :
+ (float*)frame->extended_data[0] + ch;
int stride = is_planar ? 1 : channels;
ret = lc3_decode(liblc3->decoder[ch], in, nbytes,
diff --git a/libavcodec/liblc3enc.c b/libavcodec/liblc3enc.c
index 8bdf6bd5d8..e64963b457 100644
--- a/libavcodec/liblc3enc.c
+++ b/libavcodec/liblc3enc.c
@@ -138,13 +138,8 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt,
int block_bytes = liblc3->block_bytes;
int channels = avctx->ch_layout.nb_channels;
uint8_t *data_ptr;
- size_t sample_size;
- int is_planar;
int ret;
- is_planar = av_sample_fmt_is_planar(avctx->sample_fmt);
- sample_size = av_get_bytes_per_sample(avctx->sample_fmt);
-
if ((ret = ff_get_encode_buffer(avctx, pkt, block_bytes, 0)) < 0)
return ret;
@@ -158,14 +153,16 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt,
liblc3->remaining_samples = 0;
}
+ int is_planar = avctx->sample_fmt == AV_SAMPLE_FMT_FLTP;
+
data_ptr = pkt->data;
for (int ch = 0; ch < channels; ch++) {
int nbytes = block_bytes / channels + (ch < block_bytes % channels);
- const void *pcm = frame ?
- (is_planar ? frame->data[ch] :
- frame->data[0] + ch * sample_size) :
- (const void *)(const float[]){ 0 };
+ const float *pcm = frame ?
+ (is_planar ? (const float*)frame->data[ch] :
+ (const float*)frame->data[0] + ch) :
+ (const float[]){ 0 };
int stride = frame ? (is_planar ? 1 : channels) : 0;
--
2.49.1
>From b667579ab0cc96c679277f404d83ba682b59c180 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Sun, 23 Nov 2025 00:26:07 +0100
Subject: [PATCH 2/2] avcodec/liblc3dec: Simplify sample fmt selection
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/liblc3dec.c | 19 ++-----------------
1 file changed, 2 insertions(+), 17 deletions(-)
diff --git a/libavcodec/liblc3dec.c b/libavcodec/liblc3dec.c
index a0989c88b0..953445ecfa 100644
--- a/libavcodec/liblc3dec.c
+++ b/libavcodec/liblc3dec.c
@@ -43,14 +43,6 @@ static av_cold int liblc3_decode_init(AVCodecContext *avctx)
int ep_mode;
unsigned decoder_size;
- static const struct {
- enum AVSampleFormat av_format;
- enum lc3_pcm_format lc3_format;
- } format_map[] = {
- { AV_SAMPLE_FMT_FLT, LC3_PCM_FORMAT_FLOAT },
- { AV_SAMPLE_FMT_FLTP, LC3_PCM_FORMAT_FLOAT },
- };
-
if (avctx->extradata_size < 6)
return AVERROR_INVALIDDATA;
if (channels < 0 || channels > DECODER_MAX_CHANNELS) {
@@ -90,15 +82,8 @@ static av_cold int liblc3_decode_init(AVCodecContext *avctx)
(char *)liblc3->decoder_mem + ch * decoder_size);
}
- avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
- if (avctx->request_sample_fmt != AV_SAMPLE_FMT_NONE) {
- for (int i = 0; i < FF_ARRAY_ELEMS(format_map); i++) {
- if (format_map[i].av_format == avctx->request_sample_fmt) {
- avctx->sample_fmt = avctx->request_sample_fmt;
- break;
- }
- }
- }
+ avctx->sample_fmt = avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
+ AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_FLTP;
avctx->delay = lc3_hr_delay_samples(
liblc3->hr_mode, liblc3->frame_us, liblc3->srate_hz);
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-11-22 23:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=176385415248.59.13150557062275567884@2cb04c0e5124 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@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