On 03.01.2016 02:03, Michael Niedermayer wrote:
> On Sun, Jan 03, 2016 at 01:35:39AM +0100, Andreas Cadhalpun wrote:
>> --- a/libavcodec/get_bits.h
>> +++ b/libavcodec/get_bits.h
>> @@ -269,6 +269,14 @@ static inline unsigned int get_bits(GetBitContext *s, 
>> int n)
>>      return tmp;
>>  }
>>  
>> +/**
>> + * Read 0-25 bits.
>> + */
> 
>> +static inline int get_bitsz(GetBitContext *s, int n)
> 
> just realized when looking at the code this replaces, this should be
> always_inline possibly

OK, changed inline to av_always_inline.

On 03.01.2016 02:26, Luca Barbato wrote:
> On 03/01/16 01:36, Andreas Cadhalpun wrote:
>> -/* handle n = 0 too */
>> -static inline int get_bitsz(GetBitContext *s, int n)
>> -{
>> -    return n ? get_bits(s, n) : 0;
>> -}
>> -
>> -
> 
> If you want to go the extra mile you might move this hunk in the first patch, 
> beside that seems fine.

Done.

Updated patches attached.

Best regards,
Andreas
>From 50cc356a559e55657e9d90ed4c7fc2ba3e50551a Mon Sep 17 00:00:00 2001
From: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
Date: Sun, 3 Jan 2016 00:28:42 +0100
Subject: [PATCH 1/2] get_bits: add get_bitsz for reading 0-25 bits

This can be used to simplify code in a couple of places.

Signed-off-by: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
---
 libavcodec/get_bits.h              | 8 ++++++++
 libavcodec/mpegaudiodec_template.c | 7 -------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index 0a61c80..4cf61d6 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -269,6 +269,14 @@ static inline unsigned int get_bits(GetBitContext *s, int n)
     return tmp;
 }
 
+/**
+ * Read 0-25 bits.
+ */
+static av_always_inline int get_bitsz(GetBitContext *s, int n)
+{
+    return n ? get_bits(s, n) : 0;
+}
+
 static inline unsigned int get_bits_le(GetBitContext *s, int n)
 {
     register int tmp;
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index d2420c1..5e3fe7e 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -816,13 +816,6 @@ static void exponents_from_scale_factors(MPADecodeContext *s, GranuleDef *g,
     }
 }
 
-/* handle n = 0 too */
-static inline int get_bitsz(GetBitContext *s, int n)
-{
-    return n ? get_bits(s, n) : 0;
-}
-
-
 static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos,
                           int *end_pos2)
 {
-- 
2.6.4

>From b3d5a2383264b98582a3f96132e72cd085a3f187 Mon Sep 17 00:00:00 2001
From: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
Date: Sun, 3 Jan 2016 01:19:23 +0100
Subject: [PATCH 2/2] lavc: use get_bitsz to simplify the code

Signed-off-by: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
---
 libavcodec/atrac3plus.c     | 13 +++++--------
 libavcodec/escape124.c      |  2 +-
 libavcodec/hevc.c           |  2 +-
 libavcodec/hevc_parser.c    |  2 +-
 libavcodec/wavpack.c        |  2 +-
 libavcodec/wmalosslessdec.c |  7 +++----
 libavcodec/wmaprodec.c      |  2 +-
 7 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c
index b16a139..46e0bea 100644
--- a/libavcodec/atrac3plus.c
+++ b/libavcodec/atrac3plus.c
@@ -39,9 +39,6 @@ static VLC spec_vlc_tabs[112];
 static VLC gain_vlc_tabs[11];
 static VLC tone_vlc_tabs[7];
 
-#define GET_DELTA(gb, delta_bits) \
-    ((delta_bits) ? get_bits((gb), (delta_bits)) : 0)
-
 /**
  * Generate canonical VLC table from given descriptor.
  *
@@ -384,7 +381,7 @@ static int decode_channel_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
                     chan->qu_wordlen[i] = get_bits(gb, 3);
 
                 for (i = pos; i < chan->num_coded_vals; i++)
-                    chan->qu_wordlen[i] = (min_val + GET_DELTA(gb, delta_bits)) & 7;
+                    chan->qu_wordlen[i] = (min_val + get_bitsz(gb, delta_bits)) & 7;
             }
         }
         break;
@@ -516,7 +513,7 @@ static int decode_channel_sf_idx(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
                 /* all others are: min_val + delta */
                 for (i = num_long_vals; i < ctx->used_quant_units; i++)
                     chan->qu_sf_idx[i] = (chan->qu_sf_idx[i] + min_val +
-                                          GET_DELTA(gb, delta_bits)) & 0x3F;
+                                          get_bitsz(gb, delta_bits)) & 0x3F;
             } else {
                 num_long_vals = get_bits(gb, 5);
                 delta_bits    = get_bits(gb, 3);
@@ -534,7 +531,7 @@ static int decode_channel_sf_idx(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
                 /* all others are: min_val + delta */
                 for (i = num_long_vals; i < ctx->used_quant_units; i++)
                     chan->qu_sf_idx[i] = (min_val +
-                                          GET_DELTA(gb, delta_bits)) & 0x3F;
+                                          get_bitsz(gb, delta_bits)) & 0x3F;
             }
         }
         break;
@@ -1014,7 +1011,7 @@ static int decode_gainc_npoints(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
             min_val    = get_bits(gb, 3);
 
             for (i = 0; i < coded_subbands; i++) {
-                chan->gain_data[i].num_points = min_val + GET_DELTA(gb, delta_bits);
+                chan->gain_data[i].num_points = min_val + get_bitsz(gb, delta_bits);
                 if (chan->gain_data[i].num_points > 7)
                     return AVERROR_INVALIDDATA;
             }
@@ -1134,7 +1131,7 @@ static int decode_gainc_levels(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
 
             for (sb = 0; sb < coded_subbands; sb++)
                 for (i = 0; i < chan->gain_data[sb].num_points; i++) {
-                    chan->gain_data[sb].lev_code[i] = min_val + GET_DELTA(gb, delta_bits);
+                    chan->gain_data[sb].lev_code[i] = min_val + get_bitsz(gb, delta_bits);
                     if (chan->gain_data[sb].lev_code[i] > 15)
                         return AVERROR_INVALIDDATA;
                 }
diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c
index efcac64..50a86c8 100644
--- a/libavcodec/escape124.c
+++ b/libavcodec/escape124.c
@@ -155,7 +155,7 @@ static MacroBlock decode_macroblock(Escape124Context* s, GetBitContext* gb,
     // depth = 0 means that this shouldn't read any bits;
     // in theory, this is the same as get_bits(gb, 0), but
     // that doesn't actually work.
-    block_index = depth ? get_bits(gb, depth) : 0;
+    block_index = get_bitsz(gb, depth);
 
     if (*codebook_index == 1) {
         block_index += superblock_index << s->codebooks[1].depth;
diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index 33c6ee2..c245d3b 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -469,7 +469,7 @@ static int hls_slice_header(HEVCContext *s)
 
         slice_address_length = av_ceil_log2(s->ps.sps->ctb_width *
                                             s->ps.sps->ctb_height);
-        sh->slice_segment_addr = slice_address_length ? get_bits(gb, slice_address_length) : 0;
+        sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
         if (sh->slice_segment_addr >= s->ps.sps->ctb_width * s->ps.sps->ctb_height) {
             av_log(s->avctx, AV_LOG_ERROR,
                    "Invalid slice segment address: %u.\n",
diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c
index fc10797..4625e61 100644
--- a/libavcodec/hevc_parser.c
+++ b/libavcodec/hevc_parser.c
@@ -318,7 +318,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
 
                 slice_address_length = av_ceil_log2_c(ps->sps->ctb_width *
                                                       ps->sps->ctb_height);
-                sh->slice_segment_addr = slice_address_length ? get_bits(gb, slice_address_length) : 0;
+                sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
                 if (sh->slice_segment_addr >= ps->sps->ctb_width * ps->sps->ctb_height) {
                     av_log(avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n",
                            sh->slice_segment_addr);
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index d20556d..b6022f0 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -93,7 +93,7 @@ static av_always_inline int get_tail(GetBitContext *gb, int k)
         return 0;
     p   = av_log2(k);
     e   = (1 << (p + 1)) - k - 1;
-    res = p ? get_bits(gb, p) : 0;
+    res = get_bitsz(gb, p);
     if (res >= e)
         res = (res << 1) - e + get_bits1(gb);
     return res;
diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c
index e9d0bca..8a5ffb8 100644
--- a/libavcodec/wmalosslessdec.c
+++ b/libavcodec/wmalosslessdec.c
@@ -422,8 +422,7 @@ static void decode_ac_filter(WmallDecodeCtx *s)
     s->acfilter_scaling = get_bits(&s->gb, 4);
 
     for (i = 0; i < s->acfilter_order; i++)
-        s->acfilter_coeffs[i] = (s->acfilter_scaling ?
-                                 get_bits(&s->gb, s->acfilter_scaling) : 0) + 1;
+        s->acfilter_coeffs[i] = get_bitsz(&s->gb, s->acfilter_scaling) + 1;
 }
 
 static void decode_mclms(WmallDecodeCtx *s)
@@ -436,7 +435,7 @@ static void decode_mclms(WmallDecodeCtx *s)
         if (1 << cbits < s->mclms_scaling + 1)
             cbits++;
 
-        send_coef_bits = (cbits ? get_bits(&s->gb, cbits) : 0) + 2;
+        send_coef_bits = get_bitsz(&s->gb, cbits) + 2;
 
         for (i = 0; i < s->mclms_order * s->num_channels * s->num_channels; i++)
             s->mclms_coeffs[i] = get_bits(&s->gb, send_coef_bits);
@@ -489,7 +488,7 @@ static int decode_cdlms(WmallDecodeCtx *s)
                 if ((1 << cbits) < s->cdlms[c][i].scaling + 1)
                     cbits++;
 
-                s->cdlms[c][i].bitsend = (cbits ? get_bits(&s->gb, cbits) : 0) + 2;
+                s->cdlms[c][i].bitsend = get_bitsz(&s->gb, cbits) + 2;
                 shift_l = 32 - s->cdlms[c][i].bitsend;
                 shift_r = 32 - s->cdlms[c][i].scaling - 2;
                 for (j = 0; j < s->cdlms[c][i].coefsend; j++)
diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
index c150eaf..2ea59e9 100644
--- a/libavcodec/wmaprodec.c
+++ b/libavcodec/wmaprodec.c
@@ -1222,7 +1222,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
         int num_fill_bits;
         if (!(num_fill_bits = get_bits(&s->gb, 2))) {
             int len = get_bits(&s->gb, 4);
-            num_fill_bits = (len ? get_bits(&s->gb, len) : 0) + 1;
+            num_fill_bits = get_bitsz(&s->gb, len) + 1;
         }
 
         if (num_fill_bits >= 0) {
-- 
2.6.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to