From patchwork Sat Aug 22 20:39:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 21820 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 96687449CF8 for ; Sat, 22 Aug 2020 23:40:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7731368B5F6; Sat, 22 Aug 2020 23:40:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E28C168A5B5 for ; Sat, 22 Aug 2020 23:39:56 +0300 (EEST) Received: by mail-lf1-f68.google.com with SMTP id v15so2552867lfg.6 for ; Sat, 22 Aug 2020 13:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=gMuqhuwpde99zcTd5g2O2WfVzGpDX7PbT2tJqjcpemc=; b=cd0bXuzRClwn8gEC8AwEuF/YGTy9Esfj9K4ha9hIvkqYGC62Fb2OgcCh9Cl8KQjRc3 ogDiBDx+RFPlMDBJ0PpyL5UuHMhLfHaEBybpGHgQQv7pIx5OPKtB0ZOFD3iFyJ93L/Rl g/xqDbbP0pV9MULJeflE+SCbWwticisaP2fGHdiVk1BD+LJnUhJd4nMHAnjVLJOsQQzl U5OboYXp7JYylVeWR6/9x8HHIRkkYIvJNEvdnRtuo2Y0a13R9WezyaBxyTG8JIkk95jP i0CgS/JhyDcxULAE9Ahc2Zyo86yFqIz0e11r5TsKGD+/6P3gm4iFULPMEFvTSytZMrTS xd4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gMuqhuwpde99zcTd5g2O2WfVzGpDX7PbT2tJqjcpemc=; b=cOE8cBMyMdZmcbpVhCxhl4pp42fdd2lVDwaEwwFqoXzwIDqsyRDsyflnnelEdQKTtW mNd09gBTtrYvSZ80Guvmcl3UbqO0aTXKo2f7oLjktFodnKGyy/yXWJZidylWjDczzSwt VVyDVMWOBu3JcoEtvo7gGxE6JMNS4LOdfwh88AAEd5WpSd2X/zoLpCaCaQBJBQF+llIo SmtxWPBgWsMeGz/GMCk6Tux0Vteya4BEvG4BnBXOwjZbT+sdtY9qBaa2KjyRs9F5fo9i ka+99OlyYTGn5N5gkGRHFwySJBhR60CaPxlkBqGDIsIi654n78Hw0sbR8cRxho3hpW2B 3mHQ== X-Gm-Message-State: AOAM532Fe/CT9mETgAMHxqIfhHPLGfVePEC3bpfv4E6e2WaO+snaROLq cw8GTy1f+BYn+h/x+H4kSzo3+o9erSw= X-Google-Smtp-Source: ABdhPJw9q+Fu0jm99OlycJhhWGZFyZTBXGfMXvVI4fwacXafdMJRtxSjBe4yCuyzQ6f5jI2r3nGZHw== X-Received: by 2002:a19:3d4:: with SMTP id 203mr3978520lfd.183.1598128795853; Sat, 22 Aug 2020 13:39:55 -0700 (PDT) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id 1sm1192839ljr.6.2020.08.22.13.39.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Aug 2020 13:39:55 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 22 Aug 2020 23:39:54 +0300 Message-Id: <20200822203954.4940-1-jeebjp@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200821215800.27162-3-jeebjp@gmail.com> References: <20200821215800.27162-3-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3 v3] avcodec/aacdec_template: add more checks to make sure only 22.2 gets to 22.2 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" Validates the set channel layout as well as verifies that the received layout to the function matches the reference layout, so that it matches the implemented re-ordering logic. Fixes #8845 --- libavcodec/aacdec_template.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 9f7016790e..6473de4ee9 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -266,6 +266,7 @@ static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos, return num_pos_channels; } +#define PREFIX_FOR_22POINT2 (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_LOW_FREQUENCY_2) static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) { int i, n, total_non_cc_elements; @@ -402,46 +403,60 @@ static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) } // The previous checks would end up at 8 at this point for 22.2 - if (tags == 16 && i == 8) { + if (layout == PREFIX_FOR_22POINT2 && tags == 16 && i == 8) { + const uint8_t (*reference_layout_map)[3] = aac_channel_layout_map[12]; + for (int j = 0; j < tags; j++) { + if (layout_map[j][0] != reference_layout_map[j][0] || + layout_map[j][2] != reference_layout_map[j][2]) + goto end_of_layout_definition; + } + e2c_vec[i] = (struct elem_to_channel) { .av_position = AV_CH_TOP_FRONT_CENTER, .syn_ele = layout_map[i][0], .elem_id = layout_map[i][1], .aac_position = layout_map[i][2] }; layout |= e2c_vec[i].av_position; i++; + i += assign_pair(e2c_vec, layout_map, i, AV_CH_TOP_FRONT_LEFT, AV_CH_TOP_FRONT_RIGHT, AAC_CHANNEL_FRONT, &layout); + i += assign_pair(e2c_vec, layout_map, i, AV_CH_TOP_SIDE_LEFT, AV_CH_TOP_SIDE_RIGHT, AAC_CHANNEL_SIDE, &layout); + e2c_vec[i] = (struct elem_to_channel) { .av_position = AV_CH_TOP_CENTER, .syn_ele = layout_map[i][0], .elem_id = layout_map[i][1], .aac_position = layout_map[i][2] }; layout |= e2c_vec[i].av_position; i++; + i += assign_pair(e2c_vec, layout_map, i, AV_CH_TOP_BACK_LEFT, AV_CH_TOP_BACK_RIGHT, AAC_CHANNEL_BACK, &layout); + e2c_vec[i] = (struct elem_to_channel) { .av_position = AV_CH_TOP_BACK_CENTER, .syn_ele = layout_map[i][0], .elem_id = layout_map[i][1], .aac_position = layout_map[i][2] }; layout |= e2c_vec[i].av_position; i++; + e2c_vec[i] = (struct elem_to_channel) { .av_position = AV_CH_BOTTOM_FRONT_CENTER, .syn_ele = layout_map[i][0], .elem_id = layout_map[i][1], .aac_position = layout_map[i][2] }; layout |= e2c_vec[i].av_position; i++; + i += assign_pair(e2c_vec, layout_map, i, AV_CH_BOTTOM_FRONT_LEFT, AV_CH_BOTTOM_FRONT_RIGHT, @@ -449,9 +464,11 @@ static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) &layout); } +end_of_layout_definition: + total_non_cc_elements = n = i; - if (tags == 16 && total_non_cc_elements == 16) { + if (layout == AV_CH_LAYOUT_22POINT2) { // For 22.2 reorder the result as needed FFSWAP(struct elem_to_channel, e2c_vec[2], e2c_vec[0]); // FL & FR first (final), FC third FFSWAP(struct elem_to_channel, e2c_vec[2], e2c_vec[1]); // FC second (final), FLc & FRc third