From patchwork Tue Jul 14 15:34:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21007 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 F0C0A44AA50 for ; Tue, 14 Jul 2020 18:35:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D6FA468B302; Tue, 14 Jul 2020 18:35:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7CE7968B22A for ; Tue, 14 Jul 2020 18:35:12 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id s10so22476821wrw.12 for ; Tue, 14 Jul 2020 08:35:12 -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=EgeSE0xAQLWCnknElAJ19CL+3e+kUA/j/JSnIQDG8h0=; b=ZTo3m1jPCbKkC5rk0uAIuTc/IXaIuh3YGOrKgutkx/GzrGYVdnVNmQ5kRIdKMh15KA qrTu5dW8f8z82l/22EnM0wYMSS60wbaYg0EYIaCv9fUCYZjY2PkzqG6PUTR1ecyrRkSl wypDbX03i9tCNuvj+xsKZ+hn/e6nPB8qEfoJQlC0isZ69DBrsz9YuUOcCWcjVWN9WsZM X4XPcK9NRG7+Puhs1Kx+w03mNnQa2t01hfWidIc6fTymllJn4Kd5rqaXRaCilY9lUV4w JumKyb1RE5xCsAz/ALwwesdl4jgaxh1SDbsPSqlIPN/QPZddwP68fZQ5cvKx/aWmWJzw y9hQ== 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=EgeSE0xAQLWCnknElAJ19CL+3e+kUA/j/JSnIQDG8h0=; b=kP4Jb6dHCJzAGiATdl+WoqeSd9Yrd4MAlguTmlUtSacxBrEVmP+/dBeVAq5Mecj22+ t1xuKSI44HCGXnJAXZONZRrks2UurcYDcsZY8/n1TJGstMd1LC3V+iF91/hrM7JEzWlQ Y2kHEzhv4LeWXk47BW0YFvNg3bSvaiUUcrTKu7Pw61nDTPa8ZhV8M9UBhva9WRFiuKw7 l423wD2nwnIpoMmvFYV3AwhBK1a/T5m52piVMd3n1IuEtowHn3V7rHxfutWNLiiclumi tlYIGtGtx1hW9PuTkoJj7LQxDJGSeBAWbflliCAPxIpSJZZVSUI6bbDR+tHHX6XzAL4A Geyg== X-Gm-Message-State: AOAM5323mdYwqqUUARm7ixSiHDb0nJxUkv4YrfOh38x5R6tkIiTOnRH1 3OOgkewoOwO/AJWkRWomajnr57Lu X-Google-Smtp-Source: ABdhPJzsgCwLi16B4hP1xZ+pW+Y2VANMQmT0jMsbAiyD2PNGzXZVplNDau7pXUj4M00uD/yNxoyC6Q== X-Received: by 2002:adf:9307:: with SMTP id 7mr6375742wro.414.1594740911632; Tue, 14 Jul 2020 08:35:11 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id w14sm29545452wrt.55.2020.07.14.08.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 08:35:10 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 Jul 2020 17:34:52 +0200 Message-Id: <20200714153454.9354-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200710134803.4347-1-andreas.rheinhardt@gmail.com> References: <20200710134803.4347-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/7] avcodec/cavsdec, h264*, hevc_parser: Use get_ue_golomb_30 where possible 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" instead of get_ue_golomb(). The difference between the two is that the latter also has to take into account the case in which the read code is more than 9 bits (four preceding zeroes + at most five value bits) long. Signed-off-by: Andreas Rheinhardt --- libavcodec/cavsdec.c | 4 ++-- libavcodec/h264_parse.c | 4 ++-- libavcodec/h264_ps.c | 22 +++++++++++----------- libavcodec/hevc_parser.c | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index aaed807196..1c8585f5af 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -676,8 +676,8 @@ static int decode_mb_i(AVSContext *h, int cbp_code) } h->pred_mode_Y[pos] = predpred; } - pred_mode_uv = get_ue_golomb(gb); - if (pred_mode_uv > 6) { + pred_mode_uv = get_ue_golomb_30(gb); + if (pred_mode_uv > 6U) { av_log(h->avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n"); return AVERROR_INVALIDDATA; } diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c index 352ffea948..53e644da66 100644 --- a/libavcodec/h264_parse.c +++ b/libavcodec/h264_parse.c @@ -35,7 +35,7 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps, pwt->use_weight = 0; pwt->use_weight_chroma = 0; - pwt->luma_log2_weight_denom = get_ue_golomb(gb); + pwt->luma_log2_weight_denom = get_ue_golomb_30(gb); if (pwt->luma_log2_weight_denom > 7U) { av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of range\n", pwt->luma_log2_weight_denom); pwt->luma_log2_weight_denom = 0; @@ -43,7 +43,7 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps, luma_def = 1 << pwt->luma_log2_weight_denom; if (sps->chroma_format_idc) { - pwt->chroma_log2_weight_denom = get_ue_golomb(gb); + pwt->chroma_log2_weight_denom = get_ue_golomb_30(gb); if (pwt->chroma_log2_weight_denom > 7U) { av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out of range\n", pwt->chroma_log2_weight_denom); pwt->chroma_log2_weight_denom = 0; diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c index 13823b8dc0..5ad311e52e 100644 --- a/libavcodec/h264_ps.c +++ b/libavcodec/h264_ps.c @@ -181,8 +181,8 @@ static inline int decode_vui_parameters(GetBitContext *gb, void *logctx, /* chroma_location_info_present_flag */ if (get_bits1(gb)) { /* chroma_sample_location_type_top_field */ - sps->chroma_location = get_ue_golomb(gb) + 1; - get_ue_golomb(gb); /* chroma_sample_location_type_bottom_field */ + sps->chroma_location = get_ue_golomb_30(gb) + 1; + get_ue_golomb_30(gb); /* chroma_sample_location_type_bottom_field */ } else sps->chroma_location = AVCHROMA_LOC_LEFT; @@ -224,11 +224,11 @@ static inline int decode_vui_parameters(GetBitContext *gb, void *logctx, sps->bitstream_restriction_flag = get_bits1(gb); if (sps->bitstream_restriction_flag) { get_bits1(gb); /* motion_vectors_over_pic_boundaries_flag */ - get_ue_golomb(gb); /* max_bytes_per_pic_denom */ - get_ue_golomb(gb); /* max_bits_per_mb_denom */ - get_ue_golomb(gb); /* log2_max_mv_length_horizontal */ - get_ue_golomb(gb); /* log2_max_mv_length_vertical */ - sps->num_reorder_frames = get_ue_golomb(gb); + get_ue_golomb_30(gb); /* max_bytes_per_pic_denom */ + get_ue_golomb_30(gb); /* max_bits_per_mb_denom */ + get_ue_golomb_30(gb); /* log2_max_mv_length_horizontal */ + get_ue_golomb_30(gb); /* log2_max_mv_length_vertical */ + sps->num_reorder_frames = get_ue_golomb_30(gb); get_ue_golomb(gb); /*max_dec_frame_buffering*/ if (get_bits_left(gb) < 0) { @@ -403,8 +403,8 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, goto fail; } } - sps->bit_depth_luma = get_ue_golomb(gb) + 8; - sps->bit_depth_chroma = get_ue_golomb(gb) + 8; + sps->bit_depth_luma = get_ue_golomb_30(gb) + 8; + sps->bit_depth_chroma = get_ue_golomb_30(gb) + 8; if (sps->bit_depth_chroma != sps->bit_depth_luma) { avpriv_request_sample(avctx, "Different chroma and luma bit depth"); @@ -428,7 +428,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, sps->bit_depth_chroma = 8; } - log2_max_frame_num_minus4 = get_ue_golomb(gb); + log2_max_frame_num_minus4 = get_ue_golomb_30(gb); if (log2_max_frame_num_minus4 < MIN_LOG2_MAX_FRAME_NUM - 4 || log2_max_frame_num_minus4 > MAX_LOG2_MAX_FRAME_NUM - 4) { av_log(avctx, AV_LOG_ERROR, @@ -441,7 +441,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, sps->poc_type = get_ue_golomb_30(gb); if (sps->poc_type == 0) { // FIXME #define - unsigned t = get_ue_golomb(gb); + unsigned t = get_ue_golomb_30(gb); if (t>12) { av_log(avctx, AV_LOG_ERROR, "log2_max_poc_lsb (%d) is out of range\n", t); goto fail; diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c index 5af4b788d5..3ec490bd34 100644 --- a/libavcodec/hevc_parser.c +++ b/libavcodec/hevc_parser.c @@ -136,7 +136,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal, for (i = 0; i < ps->pps->num_extra_slice_header_bits; i++) skip_bits(gb, 1); // slice_reserved_undetermined_flag[] - slice_type = get_ue_golomb(gb); + slice_type = get_ue_golomb_30(gb); if (!(slice_type == HEVC_SLICE_I || slice_type == HEVC_SLICE_P || slice_type == HEVC_SLICE_B)) { av_log(avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n",