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 <[email protected]> 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 <[email protected]> --- 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 <[email protected]> Date: Sun, 23 Nov 2025 00:26:07 +0100 Subject: [PATCH 2/2] avcodec/liblc3dec: Simplify sample fmt selection Signed-off-by: Andreas Rheinhardt <[email protected]> --- 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 -- [email protected] To unsubscribe send an email to [email protected]
