From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 5EC254B910 for ; Wed, 24 Sep 2025 14:50:20 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'Dl1Fowh+3oCIYfb3tETHGpeuPohukL58Wdq0gJxHw0s=', expected b'9QKqYGo1OcfUuXFtZMgCjSGmLRt4VT6iAuxuHjnsYWM=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1758725406; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=Dl1Fowh+3oCIYfb3tETHGpeuPohukL58Wdq0gJxHw0s=; b=1rQARS3UiXq69OZiMhWz5K+myUaCnymeU5FljDDINtQFEL5/ev6mIHGr/BH+uuvpGQMOu RQdjmvq6N7RdR8AvKQLib5S7TUg14Jp4g5cLDijVo96+Hy92iHWVfwmC55KpWhObajxBMhy AG30yw78q8do8QAcJNGm6dXu7WrXMtPWDMd7TWSJ2648cG7+Y5z45yMl5RTXYzoES3qrfdc cfVFZUyQ+zWZpJcVkm097sXXIN67zbcWQ90k/k3ABH8LZowajZzjKkNxYY6xnjfuZtpSuax tpvfWFqQXhEJP5SBN8LCUogwWetwMqWEh+9UF8QUte5smEhIIkaXhDgnYIQA== Received: from [172.19.0.4] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id D877A68ECFE; Wed, 24 Sep 2025 17:50:06 +0300 (EEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1758725402; b=YCBg4Uf1L4mb2T1iA0whPQNOc96kGqiln1Werz/TICLXJHGDfg31lR+VZjbL8/5w2yCqQ Y7eMUAPu7ZeQk4ZwCWj/znocGtf320f9aedIgvhfcXtCbrZdx2Li1Rd8+yTP0a8UAemk58C nNxferaWCp8cBcHOMmJQHaIYL8FrK8Dzj5T5naUEzTsAF/bg2oAGk+DD0NrK7TVFrFWIL6y Fzxhcjj/c0ua9KQeXwJgK+knQ1MArjD9wsMItFHvk7G4CWGQpzvOaL0tDNnj9d3spUWPjXe 5NG7wjJyih5nd6Cyx14w6r4tVv4yTtTTAM+kNx6GlPCwemK2Tz4+i9ggtq6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1758725402; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=LegP1df3kqi/kOEJMp88mg0g9X82NVFjzX+6czR//V0=; b=WANcaYKTdscOceTUuccZmCMVqytR7Mnjsyslu/6T6a7mo/6vPBQIKpT2kVoPHl71T9fSS +BUp4SutF9+GvC+/UVyUbIxlO3GXqxINNsUblLXgYbY8Dvhh+S29FI5Z8x8o6QGrGiKXp8z zTvM4sUBUFXjg0eOzDGLx0f3gY9q2Dy00ol2ZM0hA8Icn/W8DaeeEl3/MGmMVM09OgVmgZQ lNKuyaU98tbPmGea3LeOcIcdZf40+nN7CrtJeW/65ka2Kdc8ik0s9oxL7IPQmaGewFi6wTS b4hyHCfGF5j5D8aTHYm4gmR8El7DLnh+9v286nV57BpvJRf/13VpRh8D1UQA== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1758725394; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=9QKqYGo1OcfUuXFtZMgCjSGmLRt4VT6iAuxuHjnsYWM=; b=vrxE8oAz0/iJmbXNHrpoq/yhYaI4XqtJL/9Z+V8LjS5ScZlEblkXS4Zcc5ytvfKSi19Ty /yR3zUPB6osK+ZGS40dGwYDEJNAzmYPXnqfhWNFL7GldIuktw2sSd7oSBmRD1cW2aDfWeOc MExOF7h2//0lGehH1PgNfBLc3LBIJVjYDkYnNdBWAZGYt6KVBaoep7rKtHfbVSSR2+HKVS1 v8CwYMlAZUchzXTPoEn+6330ZsL0ydDoAKZvueEG8Eo1rziM13LxeYxVCF5iBtX0cjKqw/q 6oc154MO3+ZNs1NBmH21+WkQ3gsNIDhNfz7HhPv3bTMumDU20VAvRmMeaYeQ== Received: from ed19c606a818 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 9CADA6800AC for ; Wed, 24 Sep 2025 17:49:54 +0300 (EEST) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Sep 2025 14:49:54 -0000 Message-ID: <175872539476.25.3289690234759195646@bf249f23a2c8> Message-ID-Hash: SQUFI5EVTJNID5DHBSB3KVIOOVEZ7GD7 X-Message-ID-Hash: SQUFI5EVTJNID5DHBSB3KVIOOVEZ7GD7 X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] avcodec/liblc3: add support for multiple sample formats. (PR #20601) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: cenzhanquan1 via ffmpeg-devel Cc: cenzhanquan1 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20601 opened by cenzhanquan1 URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20601 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20601.patch - Decoder: - Respect request_sample_fmt if set, default to S16 instead of FLTP - Add support for S16, S16P, FLT and FLTP sample formats - Properly handle both planar and interleaved layouts - Calculate correct data pointers and stride for liblc3 - Encoder: - Add support for S16, S16P, FLT and FLTP sample formats - Remove hardcoded use of LC3_PCM_FORMAT_FLOAT - Handle both planar and interleaved input data - Update zero frame allocation to account for sample size - Update codec capabilities to include all supported sample formats - Enhance error handling for unsupported formats Signed-off-by: cenzhanquan1 >>From 0e560e67ae62ba568b0bcf2dc10fb322cd8fff3f Mon Sep 17 00:00:00 2001 From: cenzhanquan1 Date: Wed, 24 Sep 2025 22:43:18 +0800 Subject: [PATCH] avcodec/liblc3: add support for multiple sample formats. - Decoder: - Respect request_sample_fmt if set, default to S16 instead of FLTP - Add support for S16, S16P, FLT and FLTP sample formats - Properly handle both planar and interleaved layouts - Calculate correct data pointers and stride for liblc3 - Encoder: - Add support for S16, S16P, FLT and FLTP sample formats - Remove hardcoded use of LC3_PCM_FORMAT_FLOAT - Handle both planar and interleaved input data - Update zero frame allocation to account for sample size - Update codec capabilities to include all supported sample formats - Enhance error handling for unsupported formats Signed-off-by: cenzhanquan1 --- libavcodec/liblc3dec.c | 47 ++++++++++++++++++++++++++++++++++++------ libavcodec/liblc3enc.c | 46 ++++++++++++++++++++++++++++++++++------- 2 files changed, 79 insertions(+), 14 deletions(-) diff --git a/libavcodec/liblc3dec.c b/libavcodec/liblc3dec.c index d250ace38a..50154b911b 100644 --- a/libavcodec/liblc3dec.c +++ b/libavcodec/liblc3dec.c @@ -82,7 +82,12 @@ 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) { + avctx->sample_fmt = avctx->request_sample_fmt; + } else { + avctx->sample_fmt = AV_SAMPLE_FMT_S16; + } + avctx->delay = lc3_hr_delay_samples( liblc3->hr_mode, liblc3->frame_us, liblc3->srate_hz); avctx->internal->skip_samples = avctx->delay; @@ -104,8 +109,10 @@ static int liblc3_decode(AVCodecContext *avctx, AVFrame *frame, { LibLC3DecContext *liblc3 = avctx->priv_data; int channels = avctx->ch_layout.nb_channels; - uint8_t *in = avpkt->data; + enum lc3_pcm_format liblc3_format; int block_bytes, ret; + size_t sample_size; + int is_planar; frame->nb_samples = av_rescale( liblc3->frame_us, liblc3->srate_hz, 1000*1000); @@ -113,15 +120,43 @@ static int liblc3_decode(AVCodecContext *avctx, AVFrame *frame, return ret; block_bytes = avpkt->size; + + switch (avctx->sample_fmt) { + case AV_SAMPLE_FMT_S16: + case AV_SAMPLE_FMT_S16P: + liblc3_format = LC3_PCM_FORMAT_S16; + break; + case AV_SAMPLE_FMT_FLT: + case AV_SAMPLE_FMT_FLTP: + liblc3_format = LC3_PCM_FORMAT_FLOAT; + break; + default: + av_log(NULL, AV_LOG_ERROR, + "Unsupported sample format %s\n", + av_get_sample_fmt_name(avctx->sample_fmt)); + return AVERROR(EINVAL); + } + + is_planar = av_sample_fmt_is_planar(avctx->sample_fmt); + sample_size = av_get_bytes_per_sample(avctx->sample_fmt); + for (int ch = 0; ch < channels; ch++) { int nbytes = block_bytes / channels + (ch < block_bytes % channels); + void *pcm_data; + int stride; - ret = lc3_decode(liblc3->decoder[ch], in, nbytes, - LC3_PCM_FORMAT_FLOAT, frame->data[ch], 1); + if (is_planar) { + pcm_data = frame->extended_data[ch]; + stride = 1; + } else { + pcm_data = (uint8_t *)frame->extended_data[0] + ch * sample_size; + stride = channels; + } + + ret = lc3_decode(liblc3->decoder[ch], avpkt->data + ch * nbytes, nbytes, + liblc3_format, pcm_data, stride); if (ret < 0) return AVERROR_INVALIDDATA; - - in += nbytes; } frame->nb_samples = FFMIN(frame->nb_samples, avpkt->duration); diff --git a/libavcodec/liblc3enc.c b/libavcodec/liblc3enc.c index 66007a90f3..8aee9304b9 100644 --- a/libavcodec/liblc3enc.c +++ b/libavcodec/liblc3enc.c @@ -137,10 +137,30 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt, LibLC3EncContext *liblc3 = avctx->priv_data; int block_bytes = liblc3->block_bytes; int channels = avctx->ch_layout.nb_channels; + enum lc3_pcm_format lc3_format; void *zero_frame = NULL; - 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); + + switch (avctx->sample_fmt) { + case AV_SAMPLE_FMT_S16P: + case AV_SAMPLE_FMT_S16: + lc3_format = LC3_PCM_FORMAT_S16; + break; + case AV_SAMPLE_FMT_FLT: + case AV_SAMPLE_FMT_FLTP: + lc3_format = LC3_PCM_FORMAT_FLOAT; + break; + default: + av_log(avctx, AV_LOG_ERROR, "Unsupported sample format: %s\n", + av_get_sample_fmt_name(avctx->sample_fmt)); + return AVERROR(EINVAL); + } + if ((ret = ff_get_encode_buffer(avctx, pkt, block_bytes, 0)) < 0) return ret; @@ -152,20 +172,30 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt, return 0; liblc3->remaining_samples = 0; - zero_frame = av_mallocz(avctx->frame_size * sizeof(float)); + zero_frame = av_mallocz(avctx->frame_size * channels * sample_size); if (!zero_frame) return AVERROR(ENOMEM); } - data_ptr = pkt->data; for (int ch = 0; ch < channels; ch++) { - const float *pcm = zero_frame ? zero_frame : frame->data[ch]; int nbytes = block_bytes / channels + (ch < block_bytes % channels); + const void *pcm; + int stride; + + if (zero_frame) { + pcm = (uint8_t *)zero_frame + ch * (is_planar ? avctx->frame_size * sample_size : sample_size); + } else { + if (is_planar) { + pcm = frame->data[ch]; + stride = 1; + } else { + pcm = frame->data[0] + ch * sample_size; + stride = channels; + } + } lc3_encode(liblc3->encoder[ch], - LC3_PCM_FORMAT_FLOAT, pcm, 1, nbytes, data_ptr); - - data_ptr += nbytes; + lc3_format, pcm, stride, nbytes, pkt->data + ch * nbytes); } if (zero_frame) @@ -204,7 +234,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_FLT, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P), .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