From patchwork Thu Jan 13 02:02:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33473 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp39009iog; Wed, 12 Jan 2022 18:36:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvwxF6/rBmBHSTpJQ4OL9XhuJsQgnNj4Rr0ho3tH76a7b1GezRVvNZQwrhXQkO9uRn8paT X-Received: by 2002:a17:906:b044:: with SMTP id bj4mr1883716ejb.467.1642041401086; Wed, 12 Jan 2022 18:36:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642041401; cv=none; d=google.com; s=arc-20160816; b=KFqb35XngRibUZ4A5sfwkw/2dIUof85WxVLF07cbMY11Uf0wH8DTsmCDqY2W5m2BXZ wTK8tqX5hvJPg4Wy8C9PosC297nxGvjXcV1DNAxDCIx4/LpcvjlV8DqL6uXO0pEqkSUA A6izLceRGdiOd8mVl48dA4TCmoD3/YhaaEi+OHKpcGuunrJ4W5RZWRRm/luwAJn8eYJZ wB59FqiffNGDkxdi+v+k4vrNzgJESq/A8R7Jqb3ErDciYK4ja7cvfm0lHY4Uq+zzg50R 7dQIzMq4qTQz0sURJ6Lomv9LOhVcRnhUJ9o3P+KPlUg9hkVVACHuiKot1ABxEyq/tgTB o8Qg== 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=ocg4LHJlk8whqESlZbUlxAbDnO9L6BWC7YcI/DI879U=; b=EGvIem8cXG6z+ainsraXoihQ/yUPPNRNVX7fViplVYSV8xZT0P+3dF4tU1+i3wamWt tyepgX8Qf7DNykXgDoCkcbSvIqVuqxWxjzGgzp3rvmt+q3MizKb1km81wRW4QS0GrZo6 vnGi7KGgvb2cFrlnSg9lXvtrJflByJAvhIqNXiGTekYEbstHR0taScKZ8TbrKRySOdEm pT+6ItJAg2ZEufOk/Iloh8LoPRZt+k35cDT9MbHipCsyHEvX/VrEDIFTTbEla/q666Gb jAr867ucgtSloOaAlXRQ2SXyRkqo4AJzPMhVtMcGK5ypPiQGWWehicRidV0dDUBjrcvs YYAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=qujmILH7; 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 et3si686434ejc.301.2022.01.12.18.36.40; Wed, 12 Jan 2022 18:36:41 -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=qujmILH7; 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 8412A68B755; Thu, 13 Jan 2022 04:03:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C986D68B65D for ; Thu, 13 Jan 2022 04:03:21 +0200 (EET) Received: by mail-qv1-f50.google.com with SMTP id kc16so5153098qvb.3 for ; Wed, 12 Jan 2022 18:03:21 -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=ttlJXthsb4ELOyWO4AVgM7mpydFRIvGM45LmHQxocMg=; b=qujmILH78XtCtGKR2LgFyd2ttBcg1oNjo4EtblFboXS9GfZ6e+ISR4qiyaAUgRdAUQ 7qauaKDP5dQNJs6xfQUtgFkqIP8C0sZo4yzf4BDcNpSDuXc/LOumEkedJyF+dEWzIyGs o/bMCG56Nxn0o/80ye4w3oaXBxwXIDaLysnaBVn/YjPZLD54jCbxbPzFVN+qlrZgdwhS Tjy7nxWBAPgZX2LcGnjkyzrPSQgN0Wayg1oqYp66E+Jy1Eh87P8jBcxsLHp+StladEno 1Q7dzRcLsgvvQ7J5KoWkFkUzsadnRuFvTOPHMhqNABIswu2VQC2ExxRY631Ra5dry2UX wZzQ== 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=ttlJXthsb4ELOyWO4AVgM7mpydFRIvGM45LmHQxocMg=; b=JoYesaDSxWUbiIWFzVOZg46ibQnxUdQWhheoD+8enYpG5wZ0l2PBwh/J0reNmS4urs 3bHTXmjvd1V6rShqPZibpKPMThgn+QMtf6wfbOg5FlOrdhGVUwYBfHafX3R06I5cH45l lm4XAaPc85C/pRuLto8akidnOqCtGfu+6lRnqe8apjxljWLaue+yydLnGgNnqctnvAvZ /ACOYARI7dwE73PjEyInSI/ePaKYq/2vUm9fxGbS62jeQxKYnPQRZ1khblHBmRN9Ff1s Y5edyTH05F7p2siBXZxx4cOXVy3qhCe4MOusymhzPxfodjiql5kmY49OSmnSW002EwLn c4wA== X-Gm-Message-State: AOAM532S4ZSQSh7qpU7q5jgXYM1B7gQOKOeFGn925HoktNS04LW8uX+A Dzkld/7uO2YYNEP3mRhX4eMZ7fvthpU= X-Received: by 2002:a05:6214:23c6:: with SMTP id hr6mr2146178qvb.126.1642039400356; Wed, 12 Jan 2022 18:03:20 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id v1sm1045961qtc.95.2022.01.12.18.03.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:03:20 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:02:32 -0300 Message-Id: <20220113020242.661-20-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 199/281] cook: 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: GD7paqcH/Hju From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/cook.c | 25 ++++++++++++++----------- libavcodec/cook_parser.c | 4 ++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/libavcodec/cook.c b/libavcodec/cook.c index 3720772102..6f9bdb55e0 100644 --- a/libavcodec/cook.c +++ b/libavcodec/cook.c @@ -1054,7 +1054,7 @@ static void dump_cook_context(COOKContext *q) PRINT("js_vlc_bits", q->subpacket[0].js_vlc_bits); } ff_dlog(q->avctx, "COOKContext\n"); - PRINT("nb_channels", q->avctx->channels); + PRINT("nb_channels", q->avctx->ch_layout.nb_channels); PRINT("bit_rate", (int)q->avctx->bit_rate); PRINT("sample_rate", q->avctx->sample_rate); PRINT("samples_per_channel", q->subpacket[0].samples_per_channel); @@ -1079,6 +1079,8 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) unsigned int channel_mask = 0; int samples_per_frame = 0; int ret; + int channels = avctx->ch_layout.nb_channels; + q->avctx = avctx; /* Take care of the codec specific extradata. */ @@ -1091,7 +1093,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) bytestream2_init(&gb, avctx->extradata, avctx->extradata_size); /* Take data from the AVCodecContext (RM container). */ - if (!avctx->channels) { + if (!channels) { av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n"); return AVERROR_INVALIDDATA; } @@ -1123,7 +1125,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) q->subpacket[s].js_vlc_bits = bytestream2_get_be16(&gb); /* Initialize extradata related variables. */ - q->subpacket[s].samples_per_channel = samples_per_frame / avctx->channels; + q->subpacket[s].samples_per_channel = samples_per_frame / channels; q->subpacket[s].bits_per_subpacket = avctx->block_align * 8; /* Initialize default data states. */ @@ -1138,21 +1140,21 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) q->subpacket[s].joint_stereo = 0; switch (q->subpacket[s].cookversion) { case MONO: - if (avctx->channels != 1) { + if (channels != 1) { avpriv_request_sample(avctx, "Container channels != 1"); return AVERROR_PATCHWELCOME; } av_log(avctx, AV_LOG_DEBUG, "MONO\n"); break; case STEREO: - if (avctx->channels != 1) { + if (channels != 1) { q->subpacket[s].bits_per_subpdiv = 1; q->subpacket[s].num_channels = 2; } av_log(avctx, AV_LOG_DEBUG, "STEREO\n"); break; case JOINT_STEREO: - if (avctx->channels != 2) { + if (channels != 2) { avpriv_request_sample(avctx, "Container channels != 2"); return AVERROR_PATCHWELCOME; } @@ -1174,7 +1176,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_DEBUG, "MULTI_CHANNEL\n"); channel_mask |= q->subpacket[s].channel_mask = bytestream2_get_be32(&gb); - if (av_get_channel_layout_nb_channels(q->subpacket[s].channel_mask) > 1) { + if (channels > 1) { q->subpacket[s].total_subbands = q->subpacket[s].subbands + q->subpacket[s].js_subband_start; q->subpacket[s].joint_stereo = 1; @@ -1233,8 +1235,8 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) q->subpacket[s].gains2.now = q->subpacket[s].gain_3; q->subpacket[s].gains2.previous = q->subpacket[s].gain_4; - if (q->num_subpackets + q->subpacket[s].num_channels > q->avctx->channels) { - av_log(avctx, AV_LOG_ERROR, "Too many subpackets %d for channels %d\n", q->num_subpackets, q->avctx->channels); + if (q->num_subpackets + q->subpacket[s].num_channels > channels) { + av_log(avctx, AV_LOG_ERROR, "Too many subpackets %d for channels %d\n", q->num_subpackets, channels); return AVERROR_INVALIDDATA; } @@ -1282,10 +1284,11 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) } avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; + av_channel_layout_uninit(&avctx->ch_layout); if (channel_mask) - avctx->channel_layout = channel_mask; + av_channel_layout_from_mask(&avctx->ch_layout, channel_mask); else - avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; + av_channel_layout_default(&avctx->ch_layout, channels); dump_cook_context(q); diff --git a/libavcodec/cook_parser.c b/libavcodec/cook_parser.c index a05ebf94b8..0d9473845e 100644 --- a/libavcodec/cook_parser.c +++ b/libavcodec/cook_parser.c @@ -41,8 +41,8 @@ static int cook_parse(AVCodecParserContext *s1, AVCodecContext *avctx, CookParseContext *s = s1->priv_data; if (!s->duration && - avctx->extradata && avctx->extradata_size >= 8 && avctx->channels) - s->duration = AV_RB16(avctx->extradata + 4) / avctx->channels; + avctx->extradata && avctx->extradata_size >= 8 && avctx->ch_layout.nb_channels) + s->duration = AV_RB16(avctx->extradata + 4) / avctx->ch_layout.nb_channels; s1->duration = s->duration;