From patchwork Thu Jan 13 02:06:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33517 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp44792iog; Wed, 12 Jan 2022 18:47:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJywgTIlof2OC/HmfllMN9z8qdGIFLEqQsbUcXSkgwsfsOykno+lo5Q/1sKtrI5cek+BrKOV X-Received: by 2002:a17:907:8a26:: with SMTP id sc38mr1972514ejc.362.1642042069770; Wed, 12 Jan 2022 18:47:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642042069; cv=none; d=google.com; s=arc-20160816; b=0m+V/FBUT0sMxEHySYDId3/UIDZGdqBIaSeQjBQtNeUx+WlfqvKcZq242RSlmCXozp KBWHPo+p+rNt1DLOZJUr1+7lLG2em42VkYM9JXQ947cWviKnqtx8sfYSRSx7l9tNUIrz Uo3orEQ88Lqz0Ud8GTpDXvaf3ol75AOR2+v2i79xC3dGyOM+VURtRhjMK+SSQDI3eIdT 6H23UqsnK0/zW7Ds+LA2utN4IVQH3I8ZiuXBSPyUCFkgsvEVRgGccr3QUdmPtwtpKdTO wkildv89ZuTZMS6qLPJHcFjxYAqAK2hZd/EyjzJf+mlXPyZ0Wn1dM0r1ZtJJe14sA29d YIlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=A0botD3Mwx0aEERI2IknWO5F/kgehXbDA8lE7JoGbAQ=; b=SRjGskYnIfO1FmHjRuRF2IYRL5tC2ALjwgp4kr4BzdWkv/EShQSZjYWiXHWwtf5w08 gsiL+ZgmiWcq9C9znsOHvBrXYcmuJqxcVLziiy/n/yPnrXwyxCPWGuD9gWJsJ5IKXFfo Kfp+hp2nsxtnedPdJXkNGYyeC5vQcsJpJO0JR1Jr8NyuUdCJ7ivGieJNHn2yN4WqzpPq h3mHZGu2O61enfPnSRSrEUzcQX/rg1yYgRXThp9ZB/4CFhwtgbfY7AaEllvT2uIqno77 b8RTFfeYq9zjZvoFciJ+Oqk1ir+D1D2OereuuKKsEpSFMj+1hxpLqwIT6CW+KLnVPYxu RUMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=YpSGwLbt; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c17si833292edy.408.2022.01.12.18.47.49; Wed, 12 Jan 2022 18:47:49 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=YpSGwLbt; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4B93B68B9CC; Thu, 13 Jan 2022 04:07:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4769A68B9B7 for ; Thu, 13 Jan 2022 04:07:46 +0200 (EET) Received: by mail-qk1-f178.google.com with SMTP id e25so5562030qkl.12 for ; Wed, 12 Jan 2022 18:07:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=R4nHs1L/jnzh6gB+KjLly/YWMVIUkOyWvy9WYiZsGto=; b=YpSGwLbtVsvueSxtmKt/1haiRjm5U58VPetkT+wj19kIGC/uGbeuGQcIXaHJhMOKGO VV0Ff/cu8lOgfxkULqMqoPa6p5NDStOEz1nHScGwX0z+5XxvJh6ht8QeB7Ut6ebs6fnE tNXVTNThMveBJ5b1B4hslgqkM6YplblCoguvhVeuJnDzP+4SyXszy6as/pq8+5xd30Tn Rvy8n15v66ZAa6xi76R8tmbjlFOfvJetv67hnSHS1RWOcFrA0Tkgk7E0ToycjkZJJczA Dx28Qkl2WEOGZph1Npn5jzYzLC9B2gkPi0e31G8dNfcTI5ITY5ChzjfvLhRNsrHgFDjP i+Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R4nHs1L/jnzh6gB+KjLly/YWMVIUkOyWvy9WYiZsGto=; b=keIjyepvxj3aMWiwaqdib5quzi7M5AJKohJ4SGJKFiuEfeJNnd9guy/poAIfqw2zj9 EYWnjW6BnK7bdU9xXIL1E7fdVvCDWW3jh7sz3SalJKCOOMpjWrCBv2FBr/A0K1dWsdav DKjwzd95JUQAXihC7QV5l3CCZg9IzngotMf2PcYeuntFKLW1qVtsywoxPWbNjZ3OvqM6 7/Uup+ZMbf5rpW+YLsCw1qdU/CeUFWhVrdrYdkHZ8PVgac8aybtxDvEfEhD+PUgtRvSd Mgr3u2Sqzk0hEy6gkYcVwFi1jtCq+7ELtad067yZaLjz9FSO+2zBIOv1tKMRyuXX4lJh 2ylg== X-Gm-Message-State: AOAM531LnpWnVxxZbz83UzYgonYzoakDJqZxqMR21QhrKC6A34iYZt29 xge2XNcvXONQFE/X5VwVWAfa24cjSkU= X-Received: by 2002:a05:620a:372c:: with SMTP id de44mr1927826qkb.338.1642039664637; Wed, 12 Jan 2022 18:07:44 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id a16sm1085946qta.13.2022.01.12.18.07.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:07:44 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:06:57 -0300 Message-Id: <20220113020713.801-14-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113015101.4-1-jamrial@gmail.com> References: <20220113015101.4-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 253/281] roqaudioenc: convert to new channel layout API 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: CoECdMVody6s From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- libavcodec/roqaudioenc.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libavcodec/roqaudioenc.c b/libavcodec/roqaudioenc.c index 530e6b68d8..d482fd213a 100644 --- a/libavcodec/roqaudioenc.c +++ b/libavcodec/roqaudioenc.c @@ -54,8 +54,9 @@ static av_cold int roq_dpcm_encode_close(AVCodecContext *avctx) static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx) { ROQDPCMContext *context = avctx->priv_data; + int channels = avctx->ch_layout.nb_channels; - if (avctx->channels > 2) { + if (channels > 2) { av_log(avctx, AV_LOG_ERROR, "Audio must be mono or stereo\n"); return AVERROR(EINVAL); } @@ -65,10 +66,10 @@ static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx) } avctx->frame_size = ROQ_FRAME_SIZE; - avctx->bit_rate = (ROQ_HEADER_SIZE + ROQ_FRAME_SIZE * avctx->channels) * + avctx->bit_rate = (ROQ_HEADER_SIZE + ROQ_FRAME_SIZE * channels) * (22050 / ROQ_FRAME_SIZE) * 8; - context->frame_buffer = av_malloc(8 * ROQ_FRAME_SIZE * avctx->channels * + context->frame_buffer = av_malloc(8 * ROQ_FRAME_SIZE * channels * sizeof(*context->frame_buffer)); if (!context->frame_buffer) return AVERROR(ENOMEM); @@ -123,17 +124,18 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, { int i, stereo, data_size, ret; const int16_t *in = frame ? (const int16_t *)frame->data[0] : NULL; + int channels = avctx->ch_layout.nb_channels; uint8_t *out; ROQDPCMContext *context = avctx->priv_data; - stereo = (avctx->channels == 2); + stereo = (channels == 2); if (!in && context->input_frames >= 8) return 0; if (in && context->input_frames < 8) { - memcpy(&context->frame_buffer[context->buffered_samples * avctx->channels], - in, avctx->frame_size * avctx->channels * sizeof(*in)); + memcpy(&context->frame_buffer[context->buffered_samples * channels], + in, avctx->frame_size * channels * sizeof(*in)); context->buffered_samples += avctx->frame_size; if (context->input_frames == 0) context->first_pts = frame->pts; @@ -151,9 +153,9 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } if (context->input_frames == 7) - data_size = avctx->channels * context->buffered_samples; + data_size = channels * context->buffered_samples; else - data_size = avctx->channels * avctx->frame_size; + data_size = channels * avctx->frame_size; ret = ff_get_encode_buffer(avctx, avpkt, ROQ_HEADER_SIZE + data_size, 0); if (ret < 0) @@ -175,7 +177,7 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, *out++ = dpcm_predict(&context->lastSample[i & 1], *in++); avpkt->pts = context->input_frames <= 7 ? context->first_pts : frame->pts; - avpkt->duration = data_size / avctx->channels; + avpkt->duration = data_size / channels; context->input_frames++; if (!in)