diff mbox series

[FFmpeg-devel,v3,4/5] avcodec/cavsdec, h264*, hevc_parser: Use get_ue_golomb_31 where possible

Message ID 20200727090810.23794-4-andreas.rheinhardt@gmail.com
State Accepted
Commit cbb6ba2e86923349ff9c5602976bb02ffa9d3fff
Headers show
Series [FFmpeg-devel,v3,1/5] avcodec/golomb: Don't emit error message in get_ue_golomb | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt July 27, 2020, 9:08 a.m. UTC
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,
leading to more code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/cavsdec.c     |  2 +-
 libavcodec/h264_parse.c  |  4 ++--
 libavcodec/h264_ps.c     | 24 ++++++++++++------------
 libavcodec/hevc_parser.c |  2 +-
 4 files changed, 16 insertions(+), 16 deletions(-)

Comments

Michael Niedermayer July 28, 2020, 7:39 p.m. UTC | #1
On Mon, Jul 27, 2020 at 11:08:09AM +0200, Andreas Rheinhardt wrote:
> 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,
> leading to more code.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/cavsdec.c     |  2 +-
>  libavcodec/h264_parse.c  |  4 ++--
>  libavcodec/h264_ps.c     | 24 ++++++++++++------------
>  libavcodec/hevc_parser.c |  2 +-
>  4 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
> index aaed807196..9c3825df38 100644
> --- a/libavcodec/cavsdec.c
> +++ b/libavcodec/cavsdec.c
> @@ -676,7 +676,7 @@ static int decode_mb_i(AVSContext *h, int cbp_code)
>          }
>          h->pred_mode_Y[pos] = predpred;
>      }
> -    pred_mode_uv = get_ue_golomb(gb);
> +    pred_mode_uv = get_ue_golomb_31(gb);
>      if (pred_mode_uv > 6) {
>          av_log(h->avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
>          return AVERROR_INVALIDDATA;

LGTM
i dont think the others are speed relevant so they could be changed or left
as they are

thx
[...]
diff mbox series

Patch

diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index aaed807196..9c3825df38 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -676,7 +676,7 @@  static int decode_mb_i(AVSContext *h, int cbp_code)
         }
         h->pred_mode_Y[pos] = predpred;
     }
-    pred_mode_uv = get_ue_golomb(gb);
+    pred_mode_uv = get_ue_golomb_31(gb);
     if (pred_mode_uv > 6) {
         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..1c1d1c04b0 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_31(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_31(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 e774929e21..e21c2b56ac 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_31(gb) + 1;
+        get_ue_golomb_31(gb);  /* chroma_sample_location_type_bottom_field */
     } else
         sps->chroma_location = AVCHROMA_LOC_LEFT;
 
@@ -224,12 +224,12 @@  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(gb); /*max_dec_frame_buffering*/
+        get_ue_golomb_31(gb); /* max_bytes_per_pic_denom */
+        get_ue_golomb_31(gb); /* max_bits_per_mb_denom */
+        get_ue_golomb_31(gb); /* log2_max_mv_length_horizontal */
+        get_ue_golomb_31(gb); /* log2_max_mv_length_vertical */
+        sps->num_reorder_frames = get_ue_golomb_31(gb);
+        get_ue_golomb_31(gb); /*max_dec_frame_buffering*/
 
         if (get_bits_left(gb) < 0) {
             sps->num_reorder_frames         = 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_31(gb) + 8;
+        sps->bit_depth_chroma = get_ue_golomb_31(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_31(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_31(gb);
 
     if (sps->poc_type == 0) { // FIXME #define
-        unsigned t = get_ue_golomb(gb);
+        unsigned t = get_ue_golomb_31(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..463d352055 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_31(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",