From patchwork Fri Sep 7 23:50:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dale Curtis X-Patchwork-Id: 10274 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp62998jap; Fri, 7 Sep 2018 16:57:16 -0700 (PDT) X-Google-Smtp-Source: ANB0VdayxNN8D/7XwkqbwslmLnZNVKVg2fBbGion1BVvMf7q7wbMiX63Rkg96yQGI+jfWldGcZt+ X-Received: by 2002:adf:d20a:: with SMTP id g10-v6mr8370677wri.66.1536364636843; Fri, 07 Sep 2018 16:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536364636; cv=none; d=google.com; s=arc-20160816; b=jNXsDtMXFeiEVG7LXYVUwZ9EN7yJ8coYqXmi7HUG2/kTQHplJBg9pIREJCN/jbWtmN 4VsNz/0Vd9xNHHFb5lyxydihZXEizsqYoakwiaIsj946sX1gfXlD62wikk8WKlARZEVV vQz6OjkyyegRtnjdJlxIyAZ60wcub2j9beebAnblJk9IZXDQg3XO5Bvy+90UQ2atBz3t YbFwH6fiEa6jN+4bn/uV5I7TYawgNj23VDLRD1IzYupUyTtSnKvrjKtXuypyEct8Xtg3 o2UDdlaAgqTA8JCDiubomYJzDWAdMLvxfCaV5NeQy2Z/DqY+9vtWanIMgl9JYrGSbX3E p/7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=vid2hMuRWYAlMLfSW3FkGlOFKik/jx8z/z7rAVW27/M=; b=YDkvbo2yfkdEeU3/jsm3ztnUSDZwaTxyjrxrRN+DBUI0DEOUX36Q/5hMcbJqPbahMy 6D3T+PwpOrVXDhujDWhogdS8QicrLQMEfObVtJA+AE0HL6oKXWOACpcK8N7DeQdMvnHz 99l+xW1Q4pE5bOgVfCufN6N2fPpg/Lx3ywt4bclfXssY8VViM0bjre/h+JWBNfzjs1wW WtkGGFN0zdJReYSIqR4pm0MiOHfiNV5QdYxjvyjP5uFO2yVWwd25oX8t+6x4N6CV3S7r zONues9l0onFjqwy1CpkQT5fkLYvy7dh/VXNBgUDiFFEV5hI7EwmxLz2gooSjnYd0mBq 50OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@chromium.org header.s=google header.b=JltuMhuI; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r10-v6si8972061wrg.126.2018.09.07.16.57.16; Fri, 07 Sep 2018 16:57:16 -0700 (PDT) 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=@chromium.org header.s=google header.b=JltuMhuI; 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=NONE dis=NONE) header.from=chromium.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E0DC4689FD7; Sat, 8 Sep 2018 02:57:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw1-f54.google.com (mail-yw1-f54.google.com [209.85.161.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3DB5E689C87 for ; Sat, 8 Sep 2018 02:57:00 +0300 (EEST) Received: by mail-yw1-f54.google.com with SMTP id i144-v6so230813ywc.3 for ; Fri, 07 Sep 2018 16:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:from:date:message-id:subject:to; bh=pyKEjSwVL+EZMsBHSmkMpAE9E55c0cMUc5YbSO0CIWU=; b=JltuMhuI6shP+vkfd8DanUBmlknEFltf6xoqyFnc97ZbjCpMlbFkr6oxjz/qmNcHzc xr8pcOserqHSOWMyyNncszsUWLaXOTNSVtJjGuxFlmjULvxm9O0m125lfHNwOkBwtYRp 4LRR0ONgixY43BSoH7q9+3hbm5vVgQJVNp13w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=pyKEjSwVL+EZMsBHSmkMpAE9E55c0cMUc5YbSO0CIWU=; b=Qw285qPegSN/Z3O0nDF9/ifzE/RE9VT3gCxUx5bas8eI1vlVTs4JAxhRHS+xCewsuX /ExOiLnV0Ov3GagbsbbNTZy6bI9AsMjE7JsA0a+yFXojgvlGRVVDsvFH7hWldKzh6MTW Z3Z1Md2GQWP7zayS3Jdx19HqrIJlZXHsP/CbJXsVeXHEp/S9Z+b5nD1ZQaRYT203KD/c uCDyDcoRzHaSVtq4Zlj1y1FopSd8J88zIENv3Df+ps2+BuoXKnTMkA6eedDLcvPXfRfO /VbQDTAYqUxXR65SjfNhg1DUoIM0eOMUdp1CuBees/5KgtL2ozPXrJrunierI6xhiKii poLA== X-Gm-Message-State: APzg51DFB8U+Q1Yo632E24RH5Dh5eAyy5M51fxZaDr0OlQbo7T+bgEup Z+c3RqypO4YvNWDPSDeW6kZgxiAOnrvq2swmPmiaWUxVPGU= X-Received: by 2002:a81:10d5:: with SMTP id 204-v6mr5510794ywq.450.1536364269229; Fri, 07 Sep 2018 16:51:09 -0700 (PDT) MIME-Version: 1.0 From: Dale Curtis Date: Fri, 7 Sep 2018 16:50:57 -0700 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] Reduce static table size for VLC tables in h264_cavlc.c 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" These tables represent ~70k so moving the allocation to when they're actually used reduces memory usage in cases where the h264 decoder isn't used. From e1cbe52a1f41a39698136efb4695d8d019117853 Mon Sep 17 00:00:00 2001 From: Dale Curtis Date: Fri, 31 Aug 2018 16:50:23 -0700 Subject: [PATCH] Reduce static table size for VLC tables in h264_cavlc.c These tables represent ~70k so moving the allocation to when they're actually used reduces memory usage in cases where the h264 decoder isn't used. Signed-off-by: Dale Curtis --- libavcodec/h264_cavlc.c | 43 +++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index a7e60676a0..7769202401 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -236,35 +236,35 @@ static const uint8_t run_bits[7][16]={ }; static VLC coeff_token_vlc[4]; -static VLC_TYPE coeff_token_vlc_tables[520+332+280+256][2]; +static VLC_TYPE (*coeff_token_vlc_tables)[520+332+280+256][2]; static const int coeff_token_vlc_tables_size[4]={520,332,280,256}; static VLC chroma_dc_coeff_token_vlc; -static VLC_TYPE chroma_dc_coeff_token_vlc_table[256][2]; +static VLC_TYPE (*chroma_dc_coeff_token_vlc_table)[256][2]; static const int chroma_dc_coeff_token_vlc_table_size = 256; static VLC chroma422_dc_coeff_token_vlc; -static VLC_TYPE chroma422_dc_coeff_token_vlc_table[8192][2]; +static VLC_TYPE (*chroma422_dc_coeff_token_vlc_table)[8192][2]; static const int chroma422_dc_coeff_token_vlc_table_size = 8192; static VLC total_zeros_vlc[15+1]; -static VLC_TYPE total_zeros_vlc_tables[15][512][2]; +static VLC_TYPE (*total_zeros_vlc_tables)[15][512][2]; static const int total_zeros_vlc_tables_size = 512; static VLC chroma_dc_total_zeros_vlc[3+1]; -static VLC_TYPE chroma_dc_total_zeros_vlc_tables[3][8][2]; +static VLC_TYPE (*chroma_dc_total_zeros_vlc_tables)[3][8][2]; static const int chroma_dc_total_zeros_vlc_tables_size = 8; static VLC chroma422_dc_total_zeros_vlc[7+1]; -static VLC_TYPE chroma422_dc_total_zeros_vlc_tables[7][32][2]; +static VLC_TYPE (*chroma422_dc_total_zeros_vlc_tables)[7][32][2]; static const int chroma422_dc_total_zeros_vlc_tables_size = 32; static VLC run_vlc[6+1]; -static VLC_TYPE run_vlc_tables[6][8][2]; +static VLC_TYPE (*run_vlc_tables)[6][8][2]; static const int run_vlc_tables_size = 8; static VLC run7_vlc; -static VLC_TYPE run7_vlc_table[96][2]; +static VLC_TYPE (*run7_vlc_table)[96][2]; static const int run7_vlc_table_size = 96; #define LEVEL_TAB_BITS 8 @@ -331,14 +331,23 @@ av_cold void ff_h264_decode_init_vlc(void){ int offset; done = 1; - chroma_dc_coeff_token_vlc.table = chroma_dc_coeff_token_vlc_table; + coeff_token_vlc_tables = av_mallocz(sizeof(*coeff_token_vlc_tables)); + chroma_dc_coeff_token_vlc_table = av_mallocz(sizeof(*chroma_dc_coeff_token_vlc_table)); + chroma422_dc_coeff_token_vlc_table = av_mallocz(sizeof(*chroma422_dc_coeff_token_vlc_table)); + total_zeros_vlc_tables = av_mallocz(sizeof(*total_zeros_vlc_tables)); + chroma_dc_total_zeros_vlc_tables = av_mallocz(sizeof(*chroma_dc_total_zeros_vlc_tables)); + chroma422_dc_total_zeros_vlc_tables = av_mallocz(sizeof(*chroma422_dc_total_zeros_vlc_tables)); + run_vlc_tables = av_mallocz(sizeof(*run_vlc_tables)); + run7_vlc_table = av_mallocz(sizeof(*run7_vlc_table)); + + chroma_dc_coeff_token_vlc.table = *chroma_dc_coeff_token_vlc_table; chroma_dc_coeff_token_vlc.table_allocated = chroma_dc_coeff_token_vlc_table_size; init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5, &chroma_dc_coeff_token_len [0], 1, 1, &chroma_dc_coeff_token_bits[0], 1, 1, INIT_VLC_USE_NEW_STATIC); - chroma422_dc_coeff_token_vlc.table = chroma422_dc_coeff_token_vlc_table; + chroma422_dc_coeff_token_vlc.table = *chroma422_dc_coeff_token_vlc_table; chroma422_dc_coeff_token_vlc.table_allocated = chroma422_dc_coeff_token_vlc_table_size; init_vlc(&chroma422_dc_coeff_token_vlc, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 4*9, &chroma422_dc_coeff_token_len [0], 1, 1, @@ -347,7 +356,7 @@ av_cold void ff_h264_decode_init_vlc(void){ offset = 0; for(i=0; i<4; i++){ - coeff_token_vlc[i].table = coeff_token_vlc_tables+offset; + coeff_token_vlc[i].table = (*coeff_token_vlc_tables)+offset; coeff_token_vlc[i].table_allocated = coeff_token_vlc_tables_size[i]; init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17, &coeff_token_len [i][0], 1, 1, @@ -360,10 +369,10 @@ av_cold void ff_h264_decode_init_vlc(void){ * the packed static coeff_token_vlc table sizes * were initialized correctly. */ - av_assert0(offset == FF_ARRAY_ELEMS(coeff_token_vlc_tables)); + av_assert0(offset == FF_ARRAY_ELEMS(*coeff_token_vlc_tables)); for(i=0; i<3; i++){ - chroma_dc_total_zeros_vlc[i+1].table = chroma_dc_total_zeros_vlc_tables[i]; + chroma_dc_total_zeros_vlc[i+1].table = (*chroma_dc_total_zeros_vlc_tables)[i]; chroma_dc_total_zeros_vlc[i+1].table_allocated = chroma_dc_total_zeros_vlc_tables_size; init_vlc(&chroma_dc_total_zeros_vlc[i+1], CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4, @@ -373,7 +382,7 @@ av_cold void ff_h264_decode_init_vlc(void){ } for(i=0; i<7; i++){ - chroma422_dc_total_zeros_vlc[i+1].table = chroma422_dc_total_zeros_vlc_tables[i]; + chroma422_dc_total_zeros_vlc[i+1].table = (*chroma422_dc_total_zeros_vlc_tables)[i]; chroma422_dc_total_zeros_vlc[i+1].table_allocated = chroma422_dc_total_zeros_vlc_tables_size; init_vlc(&chroma422_dc_total_zeros_vlc[i+1], CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 8, @@ -383,7 +392,7 @@ av_cold void ff_h264_decode_init_vlc(void){ } for(i=0; i<15; i++){ - total_zeros_vlc[i+1].table = total_zeros_vlc_tables[i]; + total_zeros_vlc[i+1].table = (*total_zeros_vlc_tables)[i]; total_zeros_vlc[i+1].table_allocated = total_zeros_vlc_tables_size; init_vlc(&total_zeros_vlc[i+1], TOTAL_ZEROS_VLC_BITS, 16, @@ -393,7 +402,7 @@ av_cold void ff_h264_decode_init_vlc(void){ } for(i=0; i<6; i++){ - run_vlc[i+1].table = run_vlc_tables[i]; + run_vlc[i+1].table = (*run_vlc_tables)[i]; run_vlc[i+1].table_allocated = run_vlc_tables_size; init_vlc(&run_vlc[i+1], RUN_VLC_BITS, 7, @@ -401,7 +410,7 @@ av_cold void ff_h264_decode_init_vlc(void){ &run_bits[i][0], 1, 1, INIT_VLC_USE_NEW_STATIC); } - run7_vlc.table = run7_vlc_table, + run7_vlc.table = *run7_vlc_table, run7_vlc.table_allocated = run7_vlc_table_size; init_vlc(&run7_vlc, RUN7_VLC_BITS, 16, &run_len [6][0], 1, 1, -- 2.19.0.rc2.392.g5ba43deb5a-goog