From patchwork Fri Nov 20 07:33:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23890 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 55CF344A412 for ; Fri, 20 Nov 2020 09:51:42 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C317168BD68; Fri, 20 Nov 2020 09:34:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6F93368BD40 for ; Fri, 20 Nov 2020 09:34:45 +0200 (EET) Received: by mail-ej1-f46.google.com with SMTP id o21so11523075ejb.3 for ; Thu, 19 Nov 2020 23:34:45 -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:reply-to :mime-version:content-transfer-encoding; bh=gtQnnBG3z0Rc7P6tfl+mKBUlsaMsBQFmHJSUXHg0yqA=; b=EOEdjCkmipoLA9U1VP2rBn2VKbKVVoiCRCmSkRlZzvTnQd7Im69+dnTT5Hd+yejmvM UgUg55D3M/fPoV2XCzjqieVkT0rGGmG7Fk60HDMxR95Syfk5MsRwjF166kBHqaKa0aXf yAEj3qI2bNgFHGRbInjuYxe/5TlNFRrK4ttfFWY8Gc8qWNAn5/x7xRDVxQX+VRMfXxQS 5MuLTUH0t9wwDh9nEB3VCkn/0XU/7FR3r/pbspVKDLj5w7ppQqOZXBMdIfRyxNLADCNn vLJzjlh1oXIiG849KJuQYNwIZ2LKbR5eIkoGCNI4iI4+Mrw17Cy0VS2dPkfIn/qKCdyz 0Viw== 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:reply-to:mime-version:content-transfer-encoding; bh=gtQnnBG3z0Rc7P6tfl+mKBUlsaMsBQFmHJSUXHg0yqA=; b=O6QVhwuuBcrN6yAK3UhQMs5gcqtuZhJ49k8MJjpZwIgcAbDCX4DRCr1gPKdndR531m DRdGTqiYMeGvF2Ihfarwi8AsAEuueUuSUBEyHEqK4LsxdJ+TdMzsa7i1Iv5cUls3zM+j OwpaUsVHGvgu3nhSJOGACybZayE7OMMiUdaVyGdz+/caG2hUKCjTKKTAUGjqkDdOYdC2 LDnnHolLxk73NnknjSHirqNGPVr4fSt6yV+4jeIcfZUxZBf1XdWUjjKCzCgv1SEpDThA dDbtRmlqY9YN5v8yYyJu4Ipy3unKbeqly3fOd5j26RtK45CEqJKCKxFJdL0I0Bkn7miQ No7w== X-Gm-Message-State: AOAM533KHP5L4ypH6r7XYd9KsJ5QaGFFAmH1vbIbFAXe3mXvolB5iTyA k9nkqQ+tJQ2suRGDezaXY3dkV3ifZUrzeQ== X-Google-Smtp-Source: ABdhPJxCaVsqJFcGwoJnSrPOQAFvUqAA0qu4pmLn/xPOqiiBKisG4RPrP+PmzOfZZRObb3vMhVwwFg== X-Received: by 2002:a17:906:1542:: with SMTP id c2mr21234849ejd.382.1605857684546; Thu, 19 Nov 2020 23:34:44 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id i13sm769110ejv.84.2020.11.19.23.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:34:43 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:33:04 +0100 Message-Id: <20201120073327.820745-40-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> References: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 139/162] avcodec/qdmc: Avoid code duplication when initializing VLC 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/qdmc.c | 60 ++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/libavcodec/qdmc.c b/libavcodec/qdmc.c index 2c870fcc1b..eca64b056e 100644 --- a/libavcodec/qdmc.c +++ b/libavcodec/qdmc.c @@ -119,28 +119,23 @@ static const uint8_t noise_bands_selector[] = { 4, 3, 2, 1, 0, 0, 0, }; -static const uint8_t noise_value[][2] = { +static const uint8_t qdmc_hufftab[][2] = { + /* Noise value - 27 entries */ { 1, 2 }, { 10, 7 }, { 26, 9 }, { 22, 9 }, { 24, 9 }, { 14, 9 }, { 8, 6 }, { 6, 5 }, { 7, 5 }, { 9, 7 }, { 30, 9 }, { 32, 10 }, { 13, 10 }, { 20, 9 }, { 28, 9 }, { 12, 7 }, { 15, 11 }, { 36, 12 }, { 0, 12 }, { 34, 10 }, { 18, 9 }, { 11, 9 }, { 16, 9 }, { 5, 3 }, { 2, 3 }, { 4, 3 }, { 3, 2 }, -}; - -static const uint8_t noise_segment_length[][2] = { + /* Noise segment length - 12 entries */ { 1, 1 }, { 2, 2 }, { 3, 4 }, { 8, 9 }, { 9, 10 }, { 0, 10 }, { 13, 8 }, { 7, 7 }, { 6, 6 }, { 17, 5 }, { 4, 4 }, { 5, 4 }, -}; - -static const uint8_t amplitude[][2] = { + /* Amplitude - 28 entries */ { 18, 3 }, { 16, 3 }, { 22, 7 }, { 8, 10 }, { 4, 10 }, { 3, 9 }, { 2, 8 }, { 23, 8 }, { 10, 8 }, { 11, 7 }, { 21, 5 }, { 20, 4 }, { 1, 7 }, { 7, 10 }, { 5, 10 }, { 9, 9 }, { 6, 10 }, { 25, 11 }, { 26, 12 }, { 27, 13 }, { 0, 13 }, { 24, 9 }, { 12, 6 }, { 13, 5 }, { 14, 4 }, { 19, 3 }, { 15, 3 }, { 17, 2 }, -}; - -static const uint8_t freq_diff[][2] = { + /* Frequency differences - 47 entries */ { 2, 4 }, { 14, 6 }, { 26, 7 }, { 31, 8 }, { 32, 9 }, { 35, 9 }, { 7, 5 }, { 10, 5 }, { 22, 7 }, { 27, 7 }, { 19, 7 }, { 20, 7 }, { 4, 5 }, { 13, 5 }, { 17, 6 }, { 15, 6 }, { 8, 5 }, { 5, 4 }, @@ -149,40 +144,37 @@ static const uint8_t freq_diff[][2] = { { 39, 12 }, { 41, 12 }, { 34, 8 }, { 16, 6 }, { 11, 5 }, { 9, 4 }, { 1, 2 }, { 3, 4 }, { 30, 7 }, { 29, 7 }, { 23, 6 }, { 24, 6 }, { 18, 6 }, { 6, 4 }, { 12, 5 }, { 21, 6 }, { 25, 6 }, -}; - -static const uint8_t amplitude_diff[][2] = { + /* Amplitude differences - 9 entries */ { 1, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 }, { 8, 8 }, { 0, 8 }, { 2, 1 }, -}; - -static const uint8_t phase_diff[][2] = { + /* Phase differences - 9 entries */ { 2, 2 }, { 1, 2 }, { 3, 4 }, { 7, 4 }, { 6, 5 }, { 5, 6 }, { 0, 6 }, { 4, 4 }, { 8, 2 }, }; +static const uint8_t huff_sizes[] = { + 27, 12, 28, 47, 9, 9 +}; + +static const uint8_t huff_bits[] = { + 12, 10, 12, 12, 8, 6 +}; + static av_cold void qdmc_init_static_data(void) { + const uint8_t (*hufftab)[2] = qdmc_hufftab; int i; - INIT_VLC_STATIC_FROM_LENGTHS(&vtable[0], 12, FF_ARRAY_ELEMS(noise_value), - &noise_value[0][1], 2, - &noise_value[0][0], 2, 1, -1, INIT_VLC_LE, 4096); - INIT_VLC_STATIC_FROM_LENGTHS(&vtable[1], 10, FF_ARRAY_ELEMS(noise_segment_length), - &noise_segment_length[0][1], 2, - &noise_segment_length[0][0], 2, 1, -1, INIT_VLC_LE, 1024); - INIT_VLC_STATIC_FROM_LENGTHS(&vtable[2], 12, FF_ARRAY_ELEMS(amplitude), - &litude[0][1], 2, - &litude[0][0], 2, 1, -1, INIT_VLC_LE, 4098); - INIT_VLC_STATIC_FROM_LENGTHS(&vtable[3], 12, FF_ARRAY_ELEMS(freq_diff), - &freq_diff[0][1], 2, - &freq_diff[0][0], 2, 1, -1, INIT_VLC_LE, 4160); - INIT_VLC_STATIC_FROM_LENGTHS(&vtable[4], 8, FF_ARRAY_ELEMS(amplitude_diff), - &litude_diff[0][1], 2, - &litude_diff[0][0], 2, 1, -1, INIT_VLC_LE, 256); - INIT_VLC_STATIC_FROM_LENGTHS(&vtable[5], 6, FF_ARRAY_ELEMS(phase_diff), - &phase_diff[0][1], 2, - &phase_diff[0][0], 2, 1, -1, INIT_VLC_LE, 64); + for (unsigned i = 0, offset = 0; i < FF_ARRAY_ELEMS(vtable); i++) { + static VLC_TYPE vlc_buffer[13698][2]; + vtable[i].table = &vlc_buffer[offset]; + vtable[i].table_allocated = FF_ARRAY_ELEMS(vlc_buffer) - offset; + ff_init_vlc_from_lengths(&vtable[i], huff_bits[i], huff_sizes[i], + &hufftab[0][1], 2, &hufftab[0][0], 2, 1, -1, + INIT_VLC_LE | INIT_VLC_STATIC_OVERLONG, NULL); + hufftab += huff_sizes[i]; + offset += vtable[i].table_size; + } for (i = 0; i < 512; i++) sin_table[i] = sin(2.0f * i * M_PI * 0.001953125f);