Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: cenzhanquan1 via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: cenzhanquan1 <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avcodec/liblc3enc: support packed float (AV_SAMPLE_FMT_FLT) input. (PR #20721)
Date: Mon, 20 Oct 2025 04:07:19 -0000
Message-ID: <176093323993.62.14909432623612667434@bf907ddaa564> (raw)

PR #20721 opened by cenzhanquan1
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20721
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20721.patch

Previously, the LC3 encoder only accepted planar float (AV_SAMPLE_FMT_FLTP).
This change extends support to packed float (AV_SAMPLE_FMT_FLT) by properly
handling channel layout and sample stride.

The pcm data pointer and stride are now calculated based on the sample
format: for planar, use frame->data[ch]; for packed, use frame->data[0]
with channel offset. The stride is set to 1 for planar and number of
channels for packed layout.

This enables encoding from common packed audio sources without requiring
a prior planar conversion, improving usability and efficiency.

Signed-off-by: cenzhanquan1 <cenzhanquan1@xiaomi.com>


>From cbf757c112f67b8835ee56718954a697a7c06330 Mon Sep 17 00:00:00 2001
From: cenzhanquan1 <cenzhanquan1@xiaomi.com>
Date: Mon, 20 Oct 2025 12:04:01 +0800
Subject: [PATCH] avcodec/liblc3enc: support packed float (AV_SAMPLE_FMT_FLT)
 input.

Previously, the LC3 encoder only accepted planar float (AV_SAMPLE_FMT_FLTP).
This change extends support to packed float (AV_SAMPLE_FMT_FLT) by properly
handling channel layout and sample stride.

The pcm data pointer and stride are now calculated based on the sample
format: for planar, use frame->data[ch]; for packed, use frame->data[0]
with channel offset. The stride is set to 1 for planar and number of
channels for packed layout.

This enables encoding from common packed audio sources without requiring
a prior planar conversion, improving usability and efficiency.

Signed-off-by: cenzhanquan1 <cenzhanquan1@xiaomi.com>
---
 libavcodec/liblc3enc.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/libavcodec/liblc3enc.c b/libavcodec/liblc3enc.c
index 72c117b993..2c4dff7761 100644
--- a/libavcodec/liblc3enc.c
+++ b/libavcodec/liblc3enc.c
@@ -138,8 +138,13 @@ 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;
 
@@ -155,10 +160,15 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt,
 
     data_ptr = pkt->data;
     for (int ch = 0; ch < channels; ch++) {
-        const float *pcm = frame ? (const float*)frame->data[ch] : (const float[]){ 0 };
-        int stride = !!frame; // use a stride of zero to send a zero frame
         int nbytes = block_bytes / channels + (ch < block_bytes % channels);
 
+        const void *pcm = frame ?
+                    (is_planar ? frame->data[ch] :
+                    (uint8_t *)frame->data[0] + ch * sample_size) :
+                    (const void *)(const float[]){ 0 };
+
+        int stride = frame ? (is_planar ? 1 : channels) : 0;
+
         lc3_encode(liblc3->encoder[ch],
                    LC3_PCM_FORMAT_FLOAT, pcm, stride, nbytes, data_ptr);
 
@@ -198,7 +208,7 @@ const FFCodec ff_liblc3_encoder = {
     .p.priv_class   = &class,
     .p.wrapper_name = "liblc3",
     CODEC_SAMPLERATES(96000, 48000, 32000, 24000, 16000, 8000),
-    CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_FLTP),
+    CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT),
     .priv_data_size = sizeof(LibLC3EncContext),
     .init           = liblc3_encode_init,
     .close          = liblc3_encode_close,
-- 
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-10-20  4:08 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=176093323993.62.14909432623612667434@bf907ddaa564 \
    --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