From patchwork Tue Jan 26 16:43:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 25199 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 7837F44BDF6 for ; Tue, 26 Jan 2021 18:44:03 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 63223689C60; Tue, 26 Jan 2021 18:44:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DC307680987 for ; Tue, 26 Jan 2021 18:43:56 +0200 (EET) Received: by mail-wm1-f52.google.com with SMTP id 190so3041957wmz.0 for ; Tue, 26 Jan 2021 08:43:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=29pxPvtEzbJ8FI4elyMGMN6CW952ojXPXRO2s7tU2y8=; b=QYaPQp4BkaVbDXQAxoiOQzuSQDAn/HW0bYvEGvgBa4i8Co05gxjnBh29cOTcYJoUIc Bbn5LhPow2HYdtfCZMjKiF5hadzr12i2QSVH+DyxDMN2BJKzj+E90Vn44YrIq4ljrtyd goweMASh5hEY8Nhbl14nfOuRFyWVoSM1BiM6jnAAfDE9Twt3P0ZETVA4vcCnJwev2+f6 lgBedtitooI/JEyDNuQ6NSVp9TW64Npn8MgbwTYNRULoBBwvqTATeyAka6RzfH5H/Bx8 rmPiltiuQyzp58D373bA3SI1dpVPZQVd0XTQxHi7eWE7zrPyQRydWEvR5Cp7/G9h2mnQ gOkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=29pxPvtEzbJ8FI4elyMGMN6CW952ojXPXRO2s7tU2y8=; b=fS4CpxN8g5Wr0FLbQzxtD2cv5NC+fI95hmT7ZLGvTkJdGWVieNJc6cacZaZ0uPY4RE eqex8Dpd1zES7kwwsJJFlW76f6h8sxhq2WGt+rnNqVk95yTRdc/hwAnI7d1t87IRLBgp AYMbQ5/34YL3o2JtjyvfSwbNvsjoSf71YBDwx5btGaNPImMzQXLcmq2I9A+MQvI3mMYJ GvMBVGYmGSxmXqHXibz+xPHQo3glxUtIK8vyhNo2JbO6wOvN6gD3qfgCNHqAyVQ1LEMH j3Kb0OnWS+DP5+fDDth50cx9oXIukkPRqDYmsehmuXrunZWp6zcsSWXbFNU9UGLnuETK qUHQ== X-Gm-Message-State: AOAM532V/1uQu0JvbYo3yOt/6MkjApt8h0ffxieolsvTwGfNy8x5ps3p n8j6u9KypbFJSzwa4mDcIx4nQlVFNy4= X-Google-Smtp-Source: ABdhPJxn/58r+sO7xiy5cW5+Zjp1haDdSTxpK2RCJ46XGEGUguuMyhOMzHRHuahV9ZmnDerVc+nf7g== X-Received: by 2002:a1c:6208:: with SMTP id w8mr589504wmb.24.1611679436122; Tue, 26 Jan 2021 08:43:56 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id h23sm4156798wmi.26.2021.01.26.08.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 08:43:55 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 26 Jan 2021 17:43:27 +0100 Message-Id: <20210126164328.1889908-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126164328.1889908-1-andreas.rheinhardt@gmail.com> References: <20210126164328.1889908-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/dolby_e: Avoid code duplication when converting input 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" convert_input, a nontrivial auxiliary function used by both the general parsing code as well as the decoder itself, has been duplicated in c7016e35a624a75bb5b82bee932ddfe28d013b3f; this commit removes said duplication. Signed-off-by: Andreas Rheinhardt --- libavcodec/dolby_e.c | 40 ++------------------------------------ libavcodec/dolby_e.h | 7 +++++++ libavcodec/dolby_e_parse.c | 8 +++++--- 3 files changed, 14 insertions(+), 41 deletions(-) diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c index f828de2f88..9031c18210 100644 --- a/libavcodec/dolby_e.c +++ b/libavcodec/dolby_e.c @@ -25,7 +25,6 @@ #include "internal.h" #include "get_bits.h" -#include "put_bits.h" #include "dolby_e.h" #include "kbdwin.h" #include "fft.h" @@ -626,42 +625,6 @@ static int parse_key(DBEContext *s) return 0; } -static int convert_input(DBEContext *s, int nb_words, int key) -{ - const uint8_t *src = s->input; - uint8_t *dst = s->buffer; - PutBitContext pb; - int i; - - av_assert0(nb_words <= 1024u); - - if (nb_words > s->input_size) { - av_log(s->avctx, AV_LOG_ERROR, "Packet too short\n"); - return AVERROR_INVALIDDATA; - } - - switch (s->word_bits) { - case 16: - for (i = 0; i < nb_words; i++, src += 2, dst += 2) - AV_WB16(dst, AV_RB16(src) ^ key); - break; - case 20: - init_put_bits(&pb, s->buffer, sizeof(s->buffer)); - for (i = 0; i < nb_words; i++, src += 3) - put_bits(&pb, 20, AV_RB24(src) >> 4 ^ key); - flush_put_bits(&pb); - break; - case 24: - for (i = 0; i < nb_words; i++, src += 3, dst += 3) - AV_WB24(dst, AV_RB24(src) ^ key); - break; - default: - av_assert0(0); - } - - return init_get_bits(&s->gb, s->buffer, nb_words * s->word_bits); -} - static int parse_metadata_ext(DBEDecodeContext *s1) { DBEContext *s = &s1->dectx; @@ -992,7 +955,8 @@ static int parse_audio(DBEDecodeContext *s1, int start, int end, int seg_id) s1->channels[seg_id][ch].nb_groups = 0; continue; } - if ((ret = convert_input(s, s->metadata.ch_size[ch], key)) < 0) + ret = ff_dolby_e_convert_input(s, s->metadata.ch_size[ch], key); + if (ret < 0) return ret; if ((ret = parse_channel(s1, ch, seg_id)) < 0) { if (s1->avctx->err_recognition & AV_EF_EXPLODE) diff --git a/libavcodec/dolby_e.h b/libavcodec/dolby_e.h index 0838a1d3ea..32471bce80 100644 --- a/libavcodec/dolby_e.h +++ b/libavcodec/dolby_e.h @@ -84,6 +84,13 @@ typedef struct DBEContext { static const uint16_t sample_rate_tab[16] = { 0, 42965, 43008, 44800, 53706, 53760 }; + +/** + * Use the provided key to transform the input into data (put into s->buffer) + * suitable for further processing and initialize s->gb to read said data. + */ +int ff_dolby_e_convert_input(DBEContext *s, int nb_words, int key); + /** * Initialize DBEContext and parse Dolby E metadata. * Set word_bits/word_bytes, input, input_size, key_present diff --git a/libavcodec/dolby_e_parse.c b/libavcodec/dolby_e_parse.c index 33ec3d7f09..00b5536020 100644 --- a/libavcodec/dolby_e_parse.c +++ b/libavcodec/dolby_e_parse.c @@ -53,7 +53,7 @@ static int parse_key(DBEContext *s) return 0; } -static int convert_input(DBEContext *s, int nb_words, int key) +int ff_dolby_e_convert_input(DBEContext *s, int nb_words, int key) { const uint8_t *src = s->input; uint8_t *dst = s->buffer; @@ -63,6 +63,8 @@ static int convert_input(DBEContext *s, int nb_words, int key) av_assert0(nb_words <= 1024u); if (nb_words > s->input_size) { + if (s->avctx) + av_log(s->avctx, AV_LOG_ERROR, "Packet too short\n"); return AVERROR_INVALIDDATA; } @@ -116,7 +118,7 @@ int ff_dolby_e_parse_header(DBEContext *s, const uint8_t *buf, int buf_size) if ((key = parse_key(s)) < 0) return key; - if ((ret = convert_input(s, 1, key)) < 0) + if ((ret = ff_dolby_e_convert_input(s, 1, key)) < 0) return ret; skip_bits(&s->gb, 4); @@ -127,7 +129,7 @@ int ff_dolby_e_parse_header(DBEContext *s, const uint8_t *buf, int buf_size) return AVERROR_INVALIDDATA; } - if ((ret = convert_input(s, mtd_size, key)) < 0) + if ((ret = ff_dolby_e_convert_input(s, mtd_size, key)) < 0) return ret; skip_bits(&s->gb, 14);