From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 90D6D48AB4 for ; Thu, 28 Mar 2024 21:49:55 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DE6EC68D70B; Thu, 28 Mar 2024 23:49:52 +0200 (EET) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03olkn2035.outbound.protection.outlook.com [40.92.59.35]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A8BCC68D4D6 for ; Thu, 28 Mar 2024 23:49:46 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lzLk0E35Dlv5Y51KR6LTWpEcDYywz/iIsE/gDuNxk4oI46h4OFP+Q4tvEW6+65rBLiXRL42OuKYRjdMG5Z9sPdltVFXnfiqy6uK8lHhHsntqLs1S/yRbKnOdkHLGu+bVchBlOBDcDDFy9umHt6tx0h77+r8RXgH226xv/dL/B1nPFgl+1wxtFX4KtW7odko1qgboJsXvKD4mphF0O2QAb9ae6KWZR0d8qV4KIjxgioTvRmpwf+H0wr7aQRvg9a4Sr//wP/SA73jbbQ+8ySg2gD4NftGqDMNV3D3sTdaGIsIvxYvVEPuTE223O+Ps1VstykZD5zQLoO9bqIVmFeAQYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YUyzM8kmrfT6cQB6Okd58UyOwii4oPD3Dh9D11lLxLg=; b=L4idLiZqIALVtQG1jl+I0Lb19++byZv1+jc7q84gY2vKZ+n5wksA4ycpKcAWUQzRHHrI75zXM+DVcIGWoD9Sb96CVcZ7KMIVMApa1OtOy6d8RBp1iF+Teh7+4C/kX9XsqK4yhzrt2Ps0+OTSYuOnWVkNv0MW6a1nprpkcsiQ/yYHLg4j/veDbsujxwTfbkUNosErEZVzNHrabgwaf9XU/aM3l6JcNziEXQJE2w4YpD3UxQsSHMYxucHGtXK0m/qh03L16smVa5qKsyz5M83OJfeaEt3I7v4YrfHptd/8fal7VEpUNMf0r7XUwDMxEhzndmnnVf6T4o4b/Q1Ij20DoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YUyzM8kmrfT6cQB6Okd58UyOwii4oPD3Dh9D11lLxLg=; b=CuFUcIquTWU50BnkYkJFs6Rxf+QKGBc7HC7ZfTRWq/F0crxQbetSTgGOTAM3lv+iukeItW9KyOn9w/5njKjrpxd1/5Spa7jM6rEhm09BoqVaut1GoLbhs8K/GteW7xFJJZlMFki9O8YG1qhAy2HmatJF+TJ/K1w1r+ecDltXqBNaFI56z10k7hhHjNwvjDDBggI3CVuVXwewh1q65B7C4ZoTJLyQDkz3mT8rYgXZ1VhZMhXGi5s5RQlMQCvZo2XHtSr9tcP6f9A6y5oH5WJ/jXm8ju8AsluqOF7+vUoxgYfE7wlsFh6+WbWTTVQJ9GMLrQP6BP/HbJbxhieyiFNgnQ== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by PAXP250MB0495.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:28e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.39; Thu, 28 Mar 2024 21:49:44 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d%4]) with mapi id 15.20.7409.028; Thu, 28 Mar 2024 21:49:44 +0000 Message-ID: Date: Thu, 28 Mar 2024 22:49:42 +0100 User-Agent: Mozilla Thunderbird Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20240328213600.864070-1-asoulier@google.com> <20240328213600.864070-2-asoulier@google.com> From: Andreas Rheinhardt In-Reply-To: <20240328213600.864070-2-asoulier@google.com> X-TMN: [A3bGLkyaNjhaCibXSicp76derYG5KaAu] X-ClientProxiedBy: FR0P281CA0012.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::17) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|PAXP250MB0495:EE_ X-MS-Office365-Filtering-Correlation-Id: 3879853e-e924-4120-b902-08dc4f70fa8a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7PAn1po+FRo/BD6hV7nUt8RbtKtvyGBGvsAw53c5AjoDYgP8HOLybGvykDBnRVzt/Nmyhqnks/fAuNxCbSgNTcpN3NZgmD3B6+ksxdkCX8dihUzJxPbjbRM2kWPYl13WSfYXiEcog3mFotz0aCJFEdz5SeiNZhs4YCc4SlDq4EMa/jmx00Dtc2QQnwhveVOyHxtGL8WV31anO2wN+vC1rOJpRlFdiA2fjkwXRhRlpsW2DESIsClzms87pmBSq58x3pOqwfqNI3V97VyQWMxBH5YIMLGy9/9BSXe+ss0l94L7doPSY7m8WWJ8KvD941HYAkG3H20dd1jwjjvpnc/6gN9MSaPA46QXWq0+lmqvJ5W1fu0eaWqr8ryXRh0gTnvAHxtVVrhtxQcr4v7TqftR28yujg/kWibiAyCjp7vBpjw9GPF8SPy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0FLdWJRZy9IaWlrRndXWXFmczhpb0R2M2VQd1lLbzljL1pSenVr?= =?utf-8?B?cUlwNFljTWZwQVNtd3llL2F3VVFIVU80RXNLNFMvdUxvUFArV1I4RDhpaWlu?= =?utf-8?B?VlRVNzhKTmlZMFpkd1ovRGJlVWFleGN2TStWSE9iMFI4R213ekpKeW8wSFZO?= =?utf-8?B?VWtNaEVqZXJkSzhYaExldjhUQ3p1Zmg5TVdKRCt1RG1tWkxLMm5EOE5RPT0=?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3879853e-e924-4120-b902-08dc4f70fa8a X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2024 21:49:44.0154 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXP250MB0495 Subject: Re: [FFmpeg-devel] [PATCH 2/2] avformat/lc3: Add file format for LC3/LC3plus transport X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Antoine Soulier via ffmpeg-devel: > A file format is described in Bluetooth SIG LC3 and ETSI TS 103 634, for > test purpose. This is the format implemented here. > > Signed-off-by: Antoine Soulier > --- > Changelog | 1 + > doc/muxers.texi | 6 ++ > libavformat/Makefile | 2 + > libavformat/allformats.c | 2 + > libavformat/lc3dec.c | 135 +++++++++++++++++++++++++++++++++++++++ > libavformat/lc3enc.c | 102 +++++++++++++++++++++++++++++ > 6 files changed, 248 insertions(+) > create mode 100644 libavformat/lc3dec.c > create mode 100644 libavformat/lc3enc.c > > diff --git a/Changelog b/Changelog > index 83a4cf7888..08c200a41d 100644 > --- a/Changelog > +++ b/Changelog > @@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest within each release, > releases are sorted from youngest to oldest. > > version : > +- LC3/LC3plus demuxer and muxer > - LC3/LC3plus decoding/encoding using external library liblc3 > > > diff --git a/doc/muxers.texi b/doc/muxers.texi > index a10a8e216f..9687746c30 100644 > --- a/doc/muxers.texi > +++ b/doc/muxers.texi > @@ -2612,6 +2612,12 @@ WebDAV server every second: > ffmpeg -f x11grab -framerate 1 -i :0.0 -q:v 6 -update 1 -protocol_opts method=PUT http://example.com/desktop.jpg > @end example > > +@section lc3 > +Bluetooth SIG Low Complexity Communication Codec audio (LC3), or > +ETSI TS 103 634 Low Complexity Communication Codec plus (LC3plus). > + > +This muxer accepts a single @code{lc3} audio stream. > + > @section matroska > > Matroska container muxer. > diff --git a/libavformat/Makefile b/libavformat/Makefile > index 44aa485029..4961c42852 100644 > --- a/libavformat/Makefile > +++ b/libavformat/Makefile > @@ -332,6 +332,8 @@ OBJS-$(CONFIG_KVAG_DEMUXER) += kvag.o > OBJS-$(CONFIG_KVAG_MUXER) += kvag.o rawenc.o > OBJS-$(CONFIG_LAF_DEMUXER) += lafdec.o > OBJS-$(CONFIG_LATM_MUXER) += latmenc.o rawenc.o > +OBJS-$(CONFIG_LC3_DEMUXER) += lc3dec.o > +OBJS-$(CONFIG_LC3_MUXER) += lc3enc.o > OBJS-$(CONFIG_LMLM4_DEMUXER) += lmlm4.o > OBJS-$(CONFIG_LOAS_DEMUXER) += loasdec.o rawdec.o > OBJS-$(CONFIG_LUODAT_DEMUXER) += luodatdec.o > diff --git a/libavformat/allformats.c b/libavformat/allformats.c > index 9df42bb87a..0b36a7c3eb 100644 > --- a/libavformat/allformats.c > +++ b/libavformat/allformats.c > @@ -252,6 +252,8 @@ extern const FFInputFormat ff_kvag_demuxer; > extern const FFOutputFormat ff_kvag_muxer; > extern const FFInputFormat ff_laf_demuxer; > extern const FFOutputFormat ff_latm_muxer; > +extern const FFInputFormat ff_lc3_demuxer; > +extern const FFOutputFormat ff_lc3_muxer; > extern const FFInputFormat ff_lmlm4_demuxer; > extern const FFInputFormat ff_loas_demuxer; > extern const FFInputFormat ff_luodat_demuxer; > diff --git a/libavformat/lc3dec.c b/libavformat/lc3dec.c > new file mode 100644 > index 0000000000..9ca9825f1b > --- /dev/null > +++ b/libavformat/lc3dec.c > @@ -0,0 +1,135 @@ > +/* > + * LC3 demuxer > + * Copyright (C) 2024 Antoine Soulier > + * > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * FFmpeg is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA > + */ > + > +/** > + * @file > + * Based on the file format specified by : > + * > + * - Bluetooth SIG - Low Complexity Communication Codec Test Suite > + * https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=502301 > + * 3.2.8.2 Reference LC3 Codec Bitstream Format > + * > + * - ETSI TI 103 634 V1.4.1 - Low Complexity Communication Codec plus > + * https://www.etsi.org/deliver/etsi_ts/103600_103699/103634/01.04.01_60/ts_103634v010401p.pdf > + * LC3plus conformance script package > + */ > + > +#include "libavcodec/packet.h" > +#include "libavutil/intreadwrite.h" > + > +#include "avformat.h" > +#include "avio.h" > +#include "demux.h" > +#include "internal.h" > + > +typedef struct LC3DemuxContext { > + int frame_samples; > + int64_t position; > + int64_t length; > +} LC3DemuxContext; > + > +static int lc3_read_header(AVFormatContext *s) > +{ > + LC3DemuxContext *lc3 = s->priv_data; > + AVStream *st = NULL; > + uint16_t tag, hdr_size; > + uint16_t frame_us; > + uint32_t length; > + int ep_mode, hr_mode; > + int srate_hz, channels, bit_rate; > + int num_extra_params, ret; > + > + tag = avio_rb16(s->pb); > + hdr_size = avio_rl16(s->pb); > + > + if (tag != 0x1ccc || hdr_size < 9 * sizeof(uint16_t)) > + return AVERROR_INVALIDDATA; > + > + num_extra_params = hdr_size / sizeof(uint16_t) - 9; > + > + srate_hz = avio_rl16(s->pb) * 100; > + bit_rate = avio_rl16(s->pb) * 100; > + channels = avio_rl16(s->pb); > + frame_us = avio_rl16(s->pb) * 10; There is nothing that guarantees that the RHS will fit into an uint16_t. Is there a reason why you are using a more precise timebase for the extradata than the container format? > + ep_mode = avio_rl16(s->pb) != 0; > + length = avio_rl32(s->pb); > + hr_mode = num_extra_params >= 1 && avio_rl16(s->pb); > + > + st = avformat_new_stream(s, NULL); > + if (!st) > + return AVERROR(ENOMEM); > + > + avpriv_set_pts_info(st, 32, 1, srate_hz); Why 32? This format provides no timestamps, so it makes no sense for them to be wrapped. > + st->duration = length; > + > + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; > + st->codecpar->codec_id = AV_CODEC_ID_LC3; > + st->codecpar->sample_rate = srate_hz; > + st->codecpar->bit_rate = bit_rate; > + st->codecpar->ch_layout.nb_channels = channels; > + > + if ((ret = ff_alloc_extradata(st->codecpar, 6)) < 0) { > + av_log(s, AV_LOG_ERROR, "Could not allocate extradata\n"); Pointless logmessage > + return ret; > + } > + > + AV_WL16(st->codecpar->extradata + 0, frame_us); > + AV_WL16(st->codecpar->extradata + 2, ep_mode); > + AV_WL16(st->codecpar->extradata + 4, hr_mode); > + > + lc3->frame_samples = av_rescale(frame_us, srate_hz, 1000*1000); > + > + lc3->position = 0; > + lc3->length = st->duration + > + av_rescale(frame_us == 7500 ? 4000 : 2500, srate_hz, 1000*1000); > + > + return 0; > +} > + > +static int lc3_read_packet(AVFormatContext *s, AVPacket *pkt) > +{ > + LC3DemuxContext *lc3 = s->priv_data; > + AVIOContext *pb = s->pb; > + int ret; > + > + ret = av_get_packet(s->pb, pkt, avio_rl16(pb)); > + if (ret < 0) > + return ret; > + > + pkt->duration = lc3->frame_samples; > + lc3->position += lc3->frame_samples; > + if (lc3->position > lc3->length) { > + pkt->duration -= lc3->position - lc3->length; > + lc3->position = lc3->length; > + } > + > + return 0; > +} > + > +const FFInputFormat ff_lc3_demuxer = { > + .p.name = "lc3", > + .p.long_name = NULL_IF_CONFIG_SMALL("LC3 (Low Complexity Communication Codec)"), > + .p.extensions = "lc3", > + .p.flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK | AVFMT_NOTIMESTAMPS, > + .priv_data_size = sizeof(LC3DemuxContext), > + .read_header = lc3_read_header, > + .read_packet = lc3_read_packet, > +}; > diff --git a/libavformat/lc3enc.c b/libavformat/lc3enc.c > new file mode 100644 > index 0000000000..a7e3e3f4f7 > --- /dev/null > +++ b/libavformat/lc3enc.c > @@ -0,0 +1,102 @@ > +/* > + * LC3 muxer > + * Copyright (C) 2024 Antoine Soulier > + * > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * FFmpeg is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA > + */ > + > +/** > + * @file > + * Based on the file format specified by : > + * > + * - Bluetooth SIG - Low Complexity Communication Codec Test Suite > + * https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=502301 > + * 3.2.8.2 Reference LC3 Codec Bitstream Format > + * > + * - ETSI TI 103 634 V1.4.1 - Low Complexity Communication Codec plus > + * https://www.etsi.org/deliver/etsi_ts/103600_103699/103634/01.04.01_60/ts_103634v010401p.pdf > + * LC3plus conformance script package > + */ > + > +#include "libavutil/intreadwrite.h" > + > +#include "avformat.h" > +#include "avio.h" > +#include "mux.h" > +#include "internal.h" > + > +static av_cold int lc3_init(AVFormatContext *s) > +{ > + if (s->nb_streams != 1) { > + av_log(s, AV_LOG_ERROR, "This muxer only supports a single stream.\n"); > + return AVERROR(EINVAL); > + } > + > + return 0; > +} > + > +static int lc3_write_header(AVFormatContext *s) > +{ > + AVStream *st = s->streams[0]; > + int channels = st->codecpar->ch_layout.nb_channels; > + int srate_hz = st->codecpar->sample_rate; > + int bit_rate = st->codecpar->bit_rate; > + uint16_t frame_us = 10000; > + int ep_mode = 0, hr_mode = 0; > + uint32_t nb_samples = av_rescale_q( > + st->duration, st->time_base, (AVRational){ 1, srate_hz }); > + > + if (st->codecpar->extradata_size >= 2) > + frame_us = AV_RL16(st->codecpar->extradata + 0); > + > + if (st->codecpar->extradata_size >= 6) { > + ep_mode = AV_RL16(st->codecpar->extradata + 2); > + hr_mode = AV_RL16(st->codecpar->extradata + 4); > + } Given that this is not an established format, we can simply demand that extradata_size has to be >= 6. > + > + avio_wb16(s->pb, 0x1ccc); > + avio_wl16(s->pb, (9 + hr_mode) * sizeof(uint16_t)); > + avio_wl16(s->pb, srate_hz / 100); > + avio_wl16(s->pb, bit_rate / 100); > + avio_wl16(s->pb, channels); > + avio_wl16(s->pb, frame_us / 10); > + avio_wl16(s->pb, ep_mode); > + avio_wl32(s->pb, nb_samples); > + if (hr_mode) > + avio_wl16(s->pb, hr_mode); > + > + return 0; > +} > + > +static int lc3_write_packet(AVFormatContext *s, AVPacket *pkt) > +{ > + avio_wl16(s->pb, pkt->size); > + avio_write(s->pb, pkt->data, pkt->size); > + return 0; > +} > + > +const FFOutputFormat ff_lc3_muxer = { > + .p.name = "lc3", > + .p.long_name = NULL_IF_CONFIG_SMALL("LC3 (Low Complexity Communication Codec)"), > + .p.extensions = "lc3", > + .p.audio_codec = AV_CODEC_ID_LC3, > + .p.video_codec = AV_CODEC_ID_NONE, > + .p.flags = AVFMT_NOTIMESTAMPS, > + .init = lc3_init, > + .write_header = lc3_write_header, > + .write_packet = lc3_write_packet, > +}; _______________________________________________ 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".