From patchwork Thu Oct 8 19:53:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22767 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 2EFC844B58C for ; Thu, 8 Oct 2020 22:53:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0EA2B68B935; Thu, 8 Oct 2020 22:53:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CDD1268B7D0 for ; Thu, 8 Oct 2020 22:53:20 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id f21so7642284wml.3 for ; Thu, 08 Oct 2020 12:53:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=coDOVE3cV5o4Vpt0ZNgIQPflbehradhkXOXLtLT5pUg=; b=b0XyLEEOX5aqoCV+dI5V3UvMKxeKH1+VyZcciwAgsSHEoLu9/Lgj2IN22Z1wgI95xz CONHJ7N34UCYjxcOko1sInh8ghgYnwxfOATfRmsOTsJBXG7LQJ7XPnAJ0bTadmCJd8nq P0kYJ/IYOJecB3SglpEolswafxnuKelW+1QYX8W/2YlbzQ2qQ/N7QQiA660882Y4UMC1 GCdFzQqBAR9kOZ7gQw0/K54CWtsdWWAP5dXmSxYGWwI1QrLEkTLOT78D0FrLJfuMooh8 Pu2wwcUPEa46J2wKj26xbqan97Id3peF2mh+hTnoYLauCMStBLRvtIZhU3dvbOG1Y+3m dYBw== 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:mime-version :content-transfer-encoding; bh=coDOVE3cV5o4Vpt0ZNgIQPflbehradhkXOXLtLT5pUg=; b=Hz30GqTCgQMGoItwp1yH04CcxlfE0+U1xCF4xQz2YTdpR4aFB3IvAcDS4yvk/fefKb VNFkesrhfvOJapH2oF8O4hVAgAXcZPwqdyioP4KMNuP5McGXhqXRhDX7iYQuWek52WPD ETfrpfHMIcFsc6/zQ/EDTRJTwr3WmeCs4NUurszXs7qPXzu0YmLhsTRSRsJ0ajlbs9li jfT+AIUuFQeAawa6kk8ynqGqCPfoP5NaL+QemD4U8jBeDz4hwCoJWUkEo3rKu+7i/lNP qZVj+0aEER6cPRGGUQoB+09pQaBT5GA1ns2xZ0srKDCWyM6sPJCBVWngHCwX1MIEz2zb IFlw== X-Gm-Message-State: AOAM531gKIi38+aIX+E5POonmY/2F1auRLXTBiG5+2F5nfEpKnBM1rFm utYUeABoPadSf3eQF/pxNyDcSwPwO9g= X-Google-Smtp-Source: ABdhPJxAQ2GHyt3qzAi5sxMZQuiSYrRDXs1Vb3RLuYoosq/sRS5BSlr570QuzENg8YanN5WGwqzw7A== X-Received: by 2002:a1c:7c12:: with SMTP id x18mr10749501wmc.107.1602186799798; Thu, 08 Oct 2020 12:53:19 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id g14sm8776203wrx.22.2020.10.08.12.53.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 12:53:19 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Oct 2020 21:53:11 +0200 Message-Id: <20201008195313.471755-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/mpeg12: Reduce size of motion-vector 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" It currently uses 9 bits per table, but there are no codes with nine bits at all, while there are codes with eight, ten and eleven bits. So reducing the table size to eight bits will not reduce the amount of codes that can be parsed in the first step, but it allows to reduce the size of the motion-vector VLC. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg12.c | 2 +- libavcodec/mpeg12vlc.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index ab6c19c615..e4f007aec5 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -149,7 +149,7 @@ av_cold void ff_mpeg12_init_vlcs(void) ff_mpeg12_vlc_dc_chroma_code, 2, 2, 514); INIT_VLC_STATIC(&ff_mv_vlc, MV_VLC_BITS, 17, &ff_mpeg12_mbMotionVectorTable[0][1], 2, 1, - &ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 518); + &ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 266); INIT_VLC_STATIC(&ff_mbincr_vlc, MBINCR_VLC_BITS, 36, &ff_mpeg12_mbAddrIncrTable[0][1], 2, 1, &ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 538); diff --git a/libavcodec/mpeg12vlc.h b/libavcodec/mpeg12vlc.h index c5abae96b6..70aca645cb 100644 --- a/libavcodec/mpeg12vlc.h +++ b/libavcodec/mpeg12vlc.h @@ -31,7 +31,7 @@ #include "vlc.h" #define DC_VLC_BITS 9 -#define MV_VLC_BITS 9 +#define MV_VLC_BITS 8 #define TEX_VLC_BITS 9 #define MBINCR_VLC_BITS 9 From patchwork Thu Oct 8 19:53:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22768 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 10C0944B58C for ; Thu, 8 Oct 2020 22:53:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ECB8D68B951; Thu, 8 Oct 2020 22:53:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 79D4468B7F0 for ; Thu, 8 Oct 2020 22:53:40 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id e18so7893993wrw.9 for ; Thu, 08 Oct 2020 12:53:40 -0700 (PDT) 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=CNjqtk8CNdwGOb+Mnlm7Vjb9JAuD8A/+amCX5Qk3/xw=; b=cS5ggfaKFY/u+Tu//es0F9FPjz1XsK91tP0iIWqa88mTiwPnt+P+AB5JrpuTSoo6FY 98ZwsV0RWWuChdC7uznPbRWEe/NrWV9OqSpZYYqkzJoWRmcKAyLtQiPRyRtHd6TYOTur MGM102FbCUUD8Lb9+ZK/sk3LvZJuO+FhOIn1K9uP19k4COPGEhvPg/w6mK6TTJbM9MDB RPgybOIXZ//XONJmw1FeSZHKOgvAQsiogklvWsxFavLK1Ne4AC7z6gvbI0cIPotC84+R 1AB9TiMO11VJR3pOHaQq1QUVXT7DVWEVut8tHmuPDxCL5X6Cj0x6RZq8YiHjGcKX4GY9 MzKA== 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=CNjqtk8CNdwGOb+Mnlm7Vjb9JAuD8A/+amCX5Qk3/xw=; b=k56wQISF3srj/DL0VdBwDJ4hHS48NOwobc4wBJ62ATYH8P7Jo6CkUJuzLDxg5K/3/J uajgeLVstvNnsfMNat/Rpg7i+OZ43gjxxnZV3HiwcdbMMP1lVt5UR6T+OenyuR7MlrfJ l9BDzZAen3cf4kYHTKFFAiHoAoQDQeJJskaP0iPTqKknw+irlhiOiCTyJrgOI4aAnZq4 4LMigfJaX2GCX39J4sMYGe02jnRqD+i6/4lCuU98bCnujrAznh1cBKPxgFqLHCH28IOe Ibrvq93OLhGsKdwQiordjQxMVBBXRAFNZOUVobkwJ7AnVmz+gbHbzGeZyhqrNoOms/f5 vSEg== X-Gm-Message-State: AOAM5300KvuqWM4Og5PSCxhdAhXQb4X3MyI4q4BfAWVrzUywxQhYtnSA pkkloHLLzYZACAzxcQ//xVFPV+M7q+w= X-Google-Smtp-Source: ABdhPJxlh/0USDRSWpFPGNUYJAECkawDILR+Yhh8/Xtn4zCpWQf3kTltrGuKO6G57VIYi8ubPUP5fQ== X-Received: by 2002:a05:6000:12c3:: with SMTP id l3mr11677010wrx.164.1602186819402; Thu, 08 Oct 2020 12:53:39 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id g14sm8776203wrx.22.2020.10.08.12.53.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 12:53:38 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Oct 2020 21:53:12 +0200 Message-Id: <20201008195313.471755-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201008195313.471755-1-andreas.rheinhardt@gmail.com> References: <20201008195313.471755-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/mpeg12: Don't pretend reading dct_dc_size_* VLCs can fail 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" It can't because the corresponding trees don't have any loose ends. Removing the checks also removed an instance of av_log(NULL (with a nonsense message) from the codebase. Signed-off-by: Andreas Rheinhardt --- libavcodec/mdec.c | 2 -- libavcodec/mpeg12.h | 4 ---- libavcodec/mpeg12dec.c | 4 ---- 3 files changed, 10 deletions(-) diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c index 7e34ec568e..b16cbb6a79 100644 --- a/libavcodec/mdec.c +++ b/libavcodec/mdec.c @@ -71,8 +71,6 @@ static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n) } else { component = (n <= 3 ? 0 : n - 4 + 1); diff = decode_dc(&a->gb, component); - if (diff >= 0xffff) - return AVERROR_INVALIDDATA; a->last_dc[component] += diff; block[0] = a->last_dc[component] * (1 << 3); } diff --git a/libavcodec/mpeg12.h b/libavcodec/mpeg12.h index 1ec99f17e1..345d473d3a 100644 --- a/libavcodec/mpeg12.h +++ b/libavcodec/mpeg12.h @@ -47,10 +47,6 @@ static inline int decode_dc(GetBitContext *gb, int component) } else { code = get_vlc2(gb, ff_dc_chroma_vlc.table, DC_VLC_BITS, 2); } - if (code < 0){ - av_log(NULL, AV_LOG_ERROR, "invalid dc code at\n"); - return 0xffff; - } if (code == 0) { diff = 0; } else { diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 2494226aa3..7b448d3648 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -490,8 +490,6 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, component = (n & 1) + 1; } diff = decode_dc(&s->gb, component); - if (diff >= 0xffff) - return AVERROR_INVALIDDATA; dc = s->last_dc[component]; dc += diff; s->last_dc[component] = dc; @@ -578,8 +576,6 @@ static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, component = (n & 1) + 1; } diff = decode_dc(&s->gb, component); - if (diff >= 0xffff) - return AVERROR_INVALIDDATA; dc = s->last_dc[component]; dc += diff; s->last_dc[component] = dc; From patchwork Thu Oct 8 19:53:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22769 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 EA35844B58C for ; Thu, 8 Oct 2020 22:53:48 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D3C5D68B955; Thu, 8 Oct 2020 22:53:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7865068B7F0 for ; Thu, 8 Oct 2020 22:53:41 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id d3so7702344wma.4 for ; Thu, 08 Oct 2020 12:53:41 -0700 (PDT) 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=ETYKIs9UMCQw1WMOFqyd4J23vxBZ8fs4SWMylweZF3M=; b=u32zFoLfBWrdXsyeouP/MccuygcJ0mNp1DPK94MR2B4dgRFFL2FLZ4zFE6bWR8igFI /Q5XORbdW81l0gKoWdTjzbFJH7madlBah/zE40DHFEcNzlOBPpUi7Azr6qSUfbP4geJt fYGQnKpgy4Nmfe6TnaBoSIxSRIvBNEZT/ZGFKovRKpzRtvbbVtFpm/KS0FR6+SvCsFKV 2WwI6Yf9xxhymEJi7HS4nRqmcU29Epc06VpynWWsdpLcj63TVbH8V/qGu7+7UgOw2eFq 5bCJAMYCMJVXvINUaFPykRr1Ulac4IBxGRFgstn2lbce4y4VdEXeaTjwvsElBrVcADCW heBQ== 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=ETYKIs9UMCQw1WMOFqyd4J23vxBZ8fs4SWMylweZF3M=; b=dQVBmddEV9NNldSrYKmfO3Lf9q2KpFNgAkxCIap3mb0N1Sh3lg7Lw9S5qdNUQH7Enj F3prnnGXIv3Yu+NejGD/BkaDU+3LC3iFxSj2RswmQPZjD1CSahVzPWzjgEmG4gQiACTU zw9lRlKT2xI3CLwdn2r/DYB0pJlPxChvB8nEhWhpZ3qjDGwdulX9qRhgR57p16icblv0 xITRo9UgkU+ZFBhwYVthfzSLysJiGmlLb1+Tl0YsCAi6OHXtwH1wXcz0b0Ij7+ouQShU Js083RV/kZhol7QQl0aK28+Ce0kxw+scUbyLi7O/gEA8QNXpqEDZPoh+9dzYCsgMagt0 IAOQ== X-Gm-Message-State: AOAM530mnQIC0ZRPS03OA0W8m6mqxgL1JffMgaEhVfGe3qZbZZKa1RAa x4r6RHF22YNQbwbWYVAlvgBj4HfqnMU= X-Google-Smtp-Source: ABdhPJwtXV2BfQjxRtFyni8luhuqQg4oeo1ua3RScEX0FEVeIGdMj+YYkq6sojSi/yvYfgQEYwAvbQ== X-Received: by 2002:a7b:cb46:: with SMTP id v6mr7588991wmj.146.1602186820637; Thu, 08 Oct 2020 12:53:40 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id g14sm8776203wrx.22.2020.10.08.12.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 12:53:39 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Oct 2020 21:53:13 +0200 Message-Id: <20201008195313.471755-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201008195313.471755-1-andreas.rheinhardt@gmail.com> References: <20201008195313.471755-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/mpeg12dec: Optimize reading mpeg2 intra escape codes 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" Said escape code is only six bits long, so that one has at least 25 - 6 bits in the bitstream reader's cache after reading it; therefore the whole following 18 bits (containing the actual code) are already in the bitstream reader's cache, making it unnecessary to reload the cache. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg12dec.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 7b448d3648..3be90d7f25 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -524,10 +524,9 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, } else { /* escape */ run = SHOW_UBITS(re, &s->gb, 6) + 1; - LAST_SKIP_BITS(re, &s->gb, 6); - UPDATE_CACHE(re, &s->gb); + SKIP_BITS(re, &s->gb, 6); level = SHOW_SBITS(re, &s->gb, 12); - SKIP_BITS(re, &s->gb, 12); + LAST_SKIP_BITS(re, &s->gb, 12); i += run; if (i > MAX_INDEX) break; @@ -606,10 +605,9 @@ static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, } else { /* escape */ run = SHOW_UBITS(re, &s->gb, 6) + 1; - LAST_SKIP_BITS(re, &s->gb, 6); - UPDATE_CACHE(re, &s->gb); + SKIP_BITS(re, &s->gb, 6); level = SHOW_SBITS(re, &s->gb, 12); - SKIP_BITS(re, &s->gb, 12); + LAST_SKIP_BITS(re, &s->gb, 12); i += run; j = scantable[i]; if (level < 0) {