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 DBA844A3A0 for ; Wed, 27 Mar 2024 11:49:42 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D4E8868CDE3; Wed, 27 Mar 2024 13:49:38 +0200 (EET) Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CD7C568AFCE for ; Wed, 27 Mar 2024 13:49:31 +0200 (EET) Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-56c2b4850d2so2078294a12.2 for ; Wed, 27 Mar 2024 04:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711540171; x=1712144971; darn=ffmpeg.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=lQ6guYRlZvbWSSJrkGnwalF1efJBjt0cg2H8j+sVQiY=; b=ZzzFmpU8gSLc7Wmz5SoZRJoE87Tm/rqvg56MNJvg6I9odIuwEhTEBj4O/pdnPTBzND LUWKHRfK9hhEdibVrJ9stficn9D69PFsMfFUTo9abFWpyNQ/JYsR/OvwguOQTRc4560r VTADGdVWZL7VR8DPKiSqe0NsUUHrZlHD3wx98pEr29NvqWQWT0zOifKtDHc7iNQJTKHC T6Hy5dgaMl7AvQK0Bj81ggKmU8WDmHUVsjuLopMAE1KwIKLzQjOfg8iuFwNdn34EUnN1 POchbp9MSGSLYWFgzB+tWwgQq/mJLRL7EzTk3tE3vONphtiaZlhF4fDONkqE2z1Mfomv 5A4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711540171; x=1712144971; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lQ6guYRlZvbWSSJrkGnwalF1efJBjt0cg2H8j+sVQiY=; b=JopRZ8LgMklTV+ndGBsSxqm5xV6JUvXUGR8gLHDJ3XlWmvTmS80+6OncqaUBrkqIoI GVdZ0iwLB5+eBlttqE//ObRUN7cQ8M4AuQph7QiUfSisS3V0rLAWWSpoNVK7c51YVbJL /Ur+UnvHluv4F7deroGUtz7rqFkVv3yOhq2jUxJKqEWEKN2s6QcYzO+nDFQTM9m+NAjb FvCCwEWb3AhU4R/5wWTzy1QDY0YL5jsdMBv7Mpi04BMnOx17fxK2gFhaVAaOTNYsbEwf I40ikg64WUWTqjVhtGfoXjPiS5JPgzvkjOAFvnMqji6jv6h4xzCYLAwgEp6iaWBw/yZS e2JA== X-Gm-Message-State: AOJu0Yw4zi3wW4mU8N7H+1KeYC+7bz7TUDDcbpkmNGrlzh6v5QQ0CxT6 Mb13JaxA5cHmA3lMVvOI9B+BDiw2sonqwmvA8jB/34jHdVV0xEDNqCAswIH4 X-Google-Smtp-Source: AGHT+IFeJVz02LnHRPDJZp163j4+XJP62hzdnZ9GWbaxpaPmK9v8w1nxcACScv67bOSQYWwAOcnOSA== X-Received: by 2002:a50:8706:0:b0:565:e646:5c15 with SMTP id i6-20020a508706000000b00565e6465c15mr4193431edb.31.1711540170492; Wed, 27 Mar 2024 04:49:30 -0700 (PDT) Received: from mariano (net-93-70-84-101.cust.vodafonedsl.it. [93.70.84.101]) by smtp.gmail.com with ESMTPSA id b8-20020aa7dc08000000b0056c06d5dce1sm4210814edu.81.2024.03.27.04.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 04:49:30 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id 95423BFCE0; Wed, 27 Mar 2024 12:49:29 +0100 (CET) Date: Wed, 27 Mar 2024 12:49:29 +0100 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches , Antoine Soulier References: <20240326230757.282319-1-asoulier@google.com> <20240326230757.282319-2-asoulier@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240326230757.282319-2-asoulier@google.com> User-Agent: Mutt/2.1.4 (2021-12-11) Subject: Re: [FFmpeg-devel] [PATCH 2/5] avcodec/liblc3: Add encoding/decoding support of LC3 audio codec 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 Cc: Antoine Soulier 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: On date Tuesday 2024-03-26 23:07:54 +0000, ffmpeg-devel Mailing List wrote: > The LC3 audio codec is the default codec of Bluetooth LE audio. > This is a wrapper over the liblc3 library (https://github.com/google/liblc3). > > Signed-off-by: Antoine Soulier > --- > libavcodec/Makefile | 2 + > libavcodec/allcodecs.c | 2 + > libavcodec/codec_desc.c | 7 ++ > libavcodec/codec_id.h | 1 + > libavcodec/liblc3dec.c | 138 +++++++++++++++++++++++++++++ > libavcodec/liblc3enc.c | 192 ++++++++++++++++++++++++++++++++++++++++ > 6 files changed, 342 insertions(+) > create mode 100644 libavcodec/liblc3dec.c > create mode 100644 libavcodec/liblc3enc.c [...] > +static av_cold int liblc3_encode_init(AVCodecContext *avctx) > +{ > + LibLC3EncContext *liblc3 = avctx->priv_data; > + bool hr_mode = liblc3->opts.hr_mode; > + int frame_us = liblc3->opts.frame_duration * 1000; > + int srate_hz = avctx->sample_rate; > + int channels = avctx->ch_layout.nb_channels; > + int effective_bit_rate; > + unsigned encoder_size; > + > + if (frame_us != 2500 && frame_us != 5000 && > + frame_us != 7500 && frame_us != 10000 ) { > + av_log(avctx, AV_LOG_ERROR, > + "Unsupported frame duration %.1f ms\n", frame_us / 1e3f); > + return AVERROR(EINVAL); > + } > + > + hr_mode |= srate_hz > 48000; > + hr_mode &= srate_hz >= 48000; > + > + if (frame_us == 7500 && hr_mode) { > + av_log(avctx, AV_LOG_ERROR, > + "High-resolution mode not supported with 7.5 ms frames\n"); > + return AVERROR(EINVAL); > + } > + > + av_log(avctx, AV_LOG_INFO, "Encoding %.1f ms frames\n", frame_us / 1e3f); readability: use 1000f since it's more explicit > + if (hr_mode) > + av_log(avctx, AV_LOG_INFO, "High-resolution mode enabled\n"); > + > + liblc3->block_bytes = lc3_hr_frame_block_bytes( > + hr_mode, frame_us, srate_hz, channels, avctx->bit_rate); > + > + effective_bit_rate = lc3_hr_resolve_bitrate( > + hr_mode, frame_us, srate_hz, liblc3->block_bytes); > + > + if (avctx->bit_rate != effective_bit_rate) > + av_log(avctx, AV_LOG_WARNING, > + "Bitrate changed to %d bps\n", effective_bit_rate); > + avctx->bit_rate = effective_bit_rate; > + > + encoder_size = lc3_hr_encoder_size(hr_mode, frame_us, srate_hz); > + if (!encoder_size) > + return AVERROR(EINVAL); > + > + liblc3->encoder_mem = av_malloc_array(channels, encoder_size); > + if (!liblc3->encoder_mem) > + return AVERROR(ENOMEM); > + > + for (int ch = 0; ch < channels; ch++) { > + liblc3->encoder[ch] = lc3_hr_setup_encoder( > + hr_mode, frame_us, srate_hz, 0, > + (char *)liblc3->encoder_mem + ch * encoder_size); > + if (!liblc3->encoder[ch]) > + return AVERROR(EINVAL); do you need to reset/free the encoder in case of failure? If this is the case you need to unset/free here or in the close function [...] > +static int liblc3_encode(AVCodecContext *avctx, AVPacket *avpkt, > + const AVFrame *av_frame, int *got_packet_ptr) > +{ > + LibLC3EncContext *liblc3 = avctx->priv_data; > + int block_bytes = liblc3->block_bytes; > + int channels = avctx->ch_layout.nb_channels; > + uint8_t *data_ptr; > + int ret; > + > + if ((ret = ff_alloc_packet(avctx, avpkt, block_bytes)) < 0) > + return ret; > + > + data_ptr = avpkt->data; > + for (int ch = 0; ch < channels; ch++) { > + int frame_bytes = block_bytes / channels > + + (ch < block_bytes % channels); > + > + lc3_encode(liblc3->encoder[ch], > + LC3_PCM_FORMAT_FLOAT, av_frame->data[ch], 1, > + frame_bytes, data_ptr); can this fail? [...] _______________________________________________ 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".