[11/14] cbs_h2645: Simplify representation of fixed values

Message ID 20190504121427.9638-12-lu_zero@gentoo.org
State New
Headers show
Series
  • [01/14] maint: Ignore dot dirs
Related show

Commit Message

Luca Barbato May 4, 2019, 12:14 p.m.
From: Mark Thompson <sw@jkqxz.net>

---
 libavcodec/cbs_h2645.c                |  5 +++++
 libavcodec/cbs_h264_syntax_template.c | 30 ++++++++++++---------------
 libavcodec/cbs_h265_syntax_template.c | 38 +++++++++++++++--------------------
 3 files changed, 34 insertions(+), 39 deletions(-)

Comments

Alexandra Hájková May 13, 2019, 8:55 a.m. | #1
On Sat, May 4, 2019 at 2:15 PM Luca Barbato <lu_zero@gentoo.org> wrote:
>
> From: Mark Thompson <sw@jkqxz.net>
>
> ---
>  libavcodec/cbs_h2645.c                |  5 +++++
>  libavcodec/cbs_h264_syntax_template.c | 30 ++++++++++++---------------
>  libavcodec/cbs_h265_syntax_template.c | 38 +++++++++++++++--------------------
>  3 files changed, 34 insertions(+), 39 deletions(-)
>
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 8cd6db3fb4..0509d6d836 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -239,6 +239,11 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
>  #define FUNC_H264(rw, name) FUNC_NAME(rw, h264, name)
>  #define FUNC_H265(rw, name) FUNC_NAME(rw, h265, name)
>
> +#define fixed(width, name, value) do { \
> +        av_unused uint32_t fixed_value = value; \
> +        xu(width, name, fixed_value, value, value); \
> +    } while (0)
> +
>
>  #define READ
>  #define READWRITE read
> diff --git a/libavcodec/cbs_h264_syntax_template.c b/libavcodec/cbs_h264_syntax_template.c
> index 92c1b67862..82d9d23200 100644
> --- a/libavcodec/cbs_h264_syntax_template.c
> +++ b/libavcodec/cbs_h264_syntax_template.c
> @@ -19,10 +19,10 @@
>  static int FUNC(rbsp_trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
>  {
>      int err;
> -    av_unused int one = 1, zero = 0;
> -    xu(1, rbsp_stop_one_bit, one, 1, 1);
> +
> +    fixed(1, rbsp_stop_one_bit, 1);
>      while (byte_alignment(rw) != 0)
> -        xu(1, rbsp_alignment_zero_bit, zero, 0, 0);
> +        fixed(1, rbsp_alignment_zero_bit, 0);
>
>      return 0;
>  }
> @@ -740,9 +740,8 @@ static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
>          break;
>      case H264_SEI_TYPE_FILLER_PAYLOAD:
>          {
> -            av_unused int ff_byte = 0xff;
>              for (i = 0; i  < current->payload_size; i++)
> -                xu(8, ff_byte, ff_byte, 0xff, 0xff);
> +                fixed(8, ff_byte, 0xff);
>          }
>          break;
>      case H264_SEI_TYPE_USER_DATA_REGISTERED:
> @@ -770,10 +769,9 @@ static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
>      }
>
>      if (byte_alignment(rw)) {
> -        av_unused int one = 1, zero = 0;
> -        xu(1, bit_equal_to_one, one, 1, 1);
> +        fixed(1, bit_equal_to_one, 1);
>          while (byte_alignment(rw))
> -            xu(1, bit_equal_to_zero, zero, 0, 0);
> +            fixed(1, bit_equal_to_zero, 0);
>      }
>
>  #ifdef READ
> @@ -810,14 +808,14 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw,
>          uint32_t tmp;
>
>          while (bitstream_peek(rw, 8) == 0xff) {
> -            xu(8, ff_byte, tmp, 0xff, 0xff);
> +            fixed(8, ff_byte, 0xff);
>              payload_type += 255;
>          }
>          xu(8, last_payload_type_byte, tmp, 0, 254);
>          payload_type += tmp;
>
>          while (bitstream_peek(rw, 8) == 0xff) {
> -            xu(8, ff_byte, tmp, 0xff, 0xff);
> +            fixed(8, ff_byte, 0xff);
>              payload_size += 255;
>          }
>          xu(8, last_payload_size_byte, tmp, 0, 254);
> @@ -853,14 +851,14 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw,
>
>              tmp = current->payload[k].payload_type;
>              while (tmp >= 255) {
> -                xu(8, ff_byte, 0xff, 0xff, 0xff);
> +                fixed(8, ff_byte, 0xff);
>                  tmp -= 255;
>              }
>              xu(8, last_payload_type_byte, tmp, 0, 254);
>
>              tmp = current->payload[k].payload_size;
>              while (tmp >= 255) {
> -                xu(8, ff_byte, 0xff, 0xff, 0xff);
> +                fixed(8, ff_byte, 0xff);
>                  tmp -= 255;
>              }
>              xu(8, last_payload_size_byte, tmp, 0, 254);
> @@ -1240,9 +1238,8 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw,
>      }
>
>      if (pps->entropy_coding_mode_flag) {
> -        av_unused int one = 1;
>          while (byte_alignment(rw))
> -            xu(1, cabac_alignment_one_bit, one, 1, 1);
> +            fixed(1, cabac_alignment_one_bit, 1);
>      }
>
>      return 0;
> @@ -1251,7 +1248,6 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw,
>  static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw,
>                          H264RawFiller *current)
>  {
> -    av_unused int ff_byte = 0xff;
>      int err;
>
>      HEADER("Filler Data");
> @@ -1261,14 +1257,14 @@ static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw,
>
>  #ifdef READ
>      while (bitstream_peek(rw, 8) == 0xff) {
> -        xu(8, ff_byte, ff_byte, 0xff, 0xff);
> +        fixed(8, ff_byte, 0xff);
>          ++current->filler_size;
>      }
>  #else
>      {
>          uint32_t i;
>          for (i = 0; i < current->filler_size; i++)
> -            xu(8, ff_byte, ff_byte, 0xff, 0xff);
> +            fixed(8, ff_byte, 0xff);
>      }
>  #endif
>
> diff --git a/libavcodec/cbs_h265_syntax_template.c b/libavcodec/cbs_h265_syntax_template.c
> index 20b0479891..0779589712 100644
> --- a/libavcodec/cbs_h265_syntax_template.c
> +++ b/libavcodec/cbs_h265_syntax_template.c
> @@ -19,10 +19,10 @@
>  static int FUNC(rbsp_trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
>  {
>      int err;
> -    av_unused int one = 1, zero = 0;
> -    xu(1, rbsp_stop_one_bit, one, 1, 1);
> +
> +    fixed(1, rbsp_stop_one_bit, 1);
>      while (byte_alignment(rw) != 0)
> -        xu(1, rbsp_alignment_zero_bit, zero, 0, 0);
> +        fixed(1, rbsp_alignment_zero_bit, 0);
>
>      return 0;
>  }
> @@ -50,10 +50,10 @@ static int FUNC(nal_unit_header)(CodedBitstreamContext *ctx, RWContext *rw,
>  static int FUNC(byte_alignment)(CodedBitstreamContext *ctx, RWContext *rw)
>  {
>      int err;
> -    av_unused int one = 1, zero = 0;
> -    xu(1, alignment_bit_equal_to_one, one, 1, 1);
> +
> +    fixed(1, alignment_bit_equal_to_one, 1);
>      while (byte_alignment(rw) != 0)
> -        xu(1, alignment_bit_equal_to_zero, zero, 0, 0);
> +        fixed(1, alignment_bit_equal_to_zero, 0);
>
>      return 0;
>  }
> @@ -90,7 +90,6 @@ static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
>                                      int profile_present_flag,
>                                      int max_num_sub_layers_minus1)
>  {
> -    av_unused unsigned int zero = 0;
>      int err, i, j;
>
>      if (profile_present_flag) {
> @@ -125,15 +124,15 @@ static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
>              if (profile_compatible(5) || profile_compatible(9) ||
>                  profile_compatible(10)) {
>                  flag(general_max_14bit_constraint_flag);
> -                xu(24, general_reserved_zero_33bits, zero, 0, 0);
> -                xu(9, general_reserved_zero_33bits, zero, 0, 0);
> +                fixed(24, general_reserved_zero_33bits, 0);
> +                fixed( 9, general_reserved_zero_33bits, 0);
>              } else {
> -                xu(24, general_reserved_zero_34bits, zero, 0, 0);
> -                xu(10, general_reserved_zero_34bits, zero, 0, 0);
> +                fixed(24, general_reserved_zero_34bits, 0);
> +                fixed(10, general_reserved_zero_34bits, 0);
>              }
>          } else {
> -            xu(24, general_reserved_zero_43bits, zero, 0, 0);
> -            xu(19, general_reserved_zero_43bits, zero, 0, 0);
> +            fixed(24, general_reserved_zero_43bits, 0);
> +            fixed(19, general_reserved_zero_43bits, 0);
>          }
>
>          if (profile_compatible(1) || profile_compatible(2) ||
> @@ -141,7 +140,7 @@ static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
>              profile_compatible(5) || profile_compatible(9)) {
>              flag(general_inbld_flag);
>          } else {
> -            xu(1, general_reserved_zero_bit, zero, 0, 0);
> +            fixed(1, general_reserved_zero_bit, 0);
>          }
>  #undef profile_compatible
>      }
> @@ -154,10 +153,8 @@ static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
>      }
>
>      if (max_num_sub_layers_minus1 > 0) {
> -        for (i = max_num_sub_layers_minus1; i < 8; i++) {
> -            av_unused int zero = 0;
> -            xu(2, reserved_zero_2bits, zero, 0, 0);
> -        }
> +        for (i = max_num_sub_layers_minus1; i < 8; i++)
> +            fixed(2, reserved_zero_2bits, 0);
>      }
>
>      for (i = 0; i < max_num_sub_layers_minus1; i++) {
> @@ -386,10 +383,7 @@ static int FUNC(vps)(CodedBitstreamContext *ctx, RWContext *rw,
>          return AVERROR_INVALIDDATA;
>      }
>
> -    {
> -        av_unused uint16_t ffff = 0xffff;
> -        xu(16, vps_reserved_0xffff_16bits, ffff, 0xffff, 0xffff);
> -    }
> +    fixed(16, vps_reserved_0xffff_16bits, 0xffff);
>
>      CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
>                                     1, current->vps_max_sub_layers_minus1));
> --
> 2.12.2
>
> _______________________________________________
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel

OK

Patch

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 8cd6db3fb4..0509d6d836 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -239,6 +239,11 @@  static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
 #define FUNC_H264(rw, name) FUNC_NAME(rw, h264, name)
 #define FUNC_H265(rw, name) FUNC_NAME(rw, h265, name)
 
+#define fixed(width, name, value) do { \
+        av_unused uint32_t fixed_value = value; \
+        xu(width, name, fixed_value, value, value); \
+    } while (0)
+
 
 #define READ
 #define READWRITE read
diff --git a/libavcodec/cbs_h264_syntax_template.c b/libavcodec/cbs_h264_syntax_template.c
index 92c1b67862..82d9d23200 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -19,10 +19,10 @@ 
 static int FUNC(rbsp_trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
 {
     int err;
-    av_unused int one = 1, zero = 0;
-    xu(1, rbsp_stop_one_bit, one, 1, 1);
+
+    fixed(1, rbsp_stop_one_bit, 1);
     while (byte_alignment(rw) != 0)
-        xu(1, rbsp_alignment_zero_bit, zero, 0, 0);
+        fixed(1, rbsp_alignment_zero_bit, 0);
 
     return 0;
 }
@@ -740,9 +740,8 @@  static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
         break;
     case H264_SEI_TYPE_FILLER_PAYLOAD:
         {
-            av_unused int ff_byte = 0xff;
             for (i = 0; i  < current->payload_size; i++)
-                xu(8, ff_byte, ff_byte, 0xff, 0xff);
+                fixed(8, ff_byte, 0xff);
         }
         break;
     case H264_SEI_TYPE_USER_DATA_REGISTERED:
@@ -770,10 +769,9 @@  static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
     }
 
     if (byte_alignment(rw)) {
-        av_unused int one = 1, zero = 0;
-        xu(1, bit_equal_to_one, one, 1, 1);
+        fixed(1, bit_equal_to_one, 1);
         while (byte_alignment(rw))
-            xu(1, bit_equal_to_zero, zero, 0, 0);
+            fixed(1, bit_equal_to_zero, 0);
     }
 
 #ifdef READ
@@ -810,14 +808,14 @@  static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw,
         uint32_t tmp;
 
         while (bitstream_peek(rw, 8) == 0xff) {
-            xu(8, ff_byte, tmp, 0xff, 0xff);
+            fixed(8, ff_byte, 0xff);
             payload_type += 255;
         }
         xu(8, last_payload_type_byte, tmp, 0, 254);
         payload_type += tmp;
 
         while (bitstream_peek(rw, 8) == 0xff) {
-            xu(8, ff_byte, tmp, 0xff, 0xff);
+            fixed(8, ff_byte, 0xff);
             payload_size += 255;
         }
         xu(8, last_payload_size_byte, tmp, 0, 254);
@@ -853,14 +851,14 @@  static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw,
 
             tmp = current->payload[k].payload_type;
             while (tmp >= 255) {
-                xu(8, ff_byte, 0xff, 0xff, 0xff);
+                fixed(8, ff_byte, 0xff);
                 tmp -= 255;
             }
             xu(8, last_payload_type_byte, tmp, 0, 254);
 
             tmp = current->payload[k].payload_size;
             while (tmp >= 255) {
-                xu(8, ff_byte, 0xff, 0xff, 0xff);
+                fixed(8, ff_byte, 0xff);
                 tmp -= 255;
             }
             xu(8, last_payload_size_byte, tmp, 0, 254);
@@ -1240,9 +1238,8 @@  static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw,
     }
 
     if (pps->entropy_coding_mode_flag) {
-        av_unused int one = 1;
         while (byte_alignment(rw))
-            xu(1, cabac_alignment_one_bit, one, 1, 1);
+            fixed(1, cabac_alignment_one_bit, 1);
     }
 
     return 0;
@@ -1251,7 +1248,6 @@  static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw,
 static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw,
                         H264RawFiller *current)
 {
-    av_unused int ff_byte = 0xff;
     int err;
 
     HEADER("Filler Data");
@@ -1261,14 +1257,14 @@  static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw,
 
 #ifdef READ
     while (bitstream_peek(rw, 8) == 0xff) {
-        xu(8, ff_byte, ff_byte, 0xff, 0xff);
+        fixed(8, ff_byte, 0xff);
         ++current->filler_size;
     }
 #else
     {
         uint32_t i;
         for (i = 0; i < current->filler_size; i++)
-            xu(8, ff_byte, ff_byte, 0xff, 0xff);
+            fixed(8, ff_byte, 0xff);
     }
 #endif
 
diff --git a/libavcodec/cbs_h265_syntax_template.c b/libavcodec/cbs_h265_syntax_template.c
index 20b0479891..0779589712 100644
--- a/libavcodec/cbs_h265_syntax_template.c
+++ b/libavcodec/cbs_h265_syntax_template.c
@@ -19,10 +19,10 @@ 
 static int FUNC(rbsp_trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
 {
     int err;
-    av_unused int one = 1, zero = 0;
-    xu(1, rbsp_stop_one_bit, one, 1, 1);
+
+    fixed(1, rbsp_stop_one_bit, 1);
     while (byte_alignment(rw) != 0)
-        xu(1, rbsp_alignment_zero_bit, zero, 0, 0);
+        fixed(1, rbsp_alignment_zero_bit, 0);
 
     return 0;
 }
@@ -50,10 +50,10 @@  static int FUNC(nal_unit_header)(CodedBitstreamContext *ctx, RWContext *rw,
 static int FUNC(byte_alignment)(CodedBitstreamContext *ctx, RWContext *rw)
 {
     int err;
-    av_unused int one = 1, zero = 0;
-    xu(1, alignment_bit_equal_to_one, one, 1, 1);
+
+    fixed(1, alignment_bit_equal_to_one, 1);
     while (byte_alignment(rw) != 0)
-        xu(1, alignment_bit_equal_to_zero, zero, 0, 0);
+        fixed(1, alignment_bit_equal_to_zero, 0);
 
     return 0;
 }
@@ -90,7 +90,6 @@  static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
                                     int profile_present_flag,
                                     int max_num_sub_layers_minus1)
 {
-    av_unused unsigned int zero = 0;
     int err, i, j;
 
     if (profile_present_flag) {
@@ -125,15 +124,15 @@  static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
             if (profile_compatible(5) || profile_compatible(9) ||
                 profile_compatible(10)) {
                 flag(general_max_14bit_constraint_flag);
-                xu(24, general_reserved_zero_33bits, zero, 0, 0);
-                xu(9, general_reserved_zero_33bits, zero, 0, 0);
+                fixed(24, general_reserved_zero_33bits, 0);
+                fixed( 9, general_reserved_zero_33bits, 0);
             } else {
-                xu(24, general_reserved_zero_34bits, zero, 0, 0);
-                xu(10, general_reserved_zero_34bits, zero, 0, 0);
+                fixed(24, general_reserved_zero_34bits, 0);
+                fixed(10, general_reserved_zero_34bits, 0);
             }
         } else {
-            xu(24, general_reserved_zero_43bits, zero, 0, 0);
-            xu(19, general_reserved_zero_43bits, zero, 0, 0);
+            fixed(24, general_reserved_zero_43bits, 0);
+            fixed(19, general_reserved_zero_43bits, 0);
         }
 
         if (profile_compatible(1) || profile_compatible(2) ||
@@ -141,7 +140,7 @@  static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
             profile_compatible(5) || profile_compatible(9)) {
             flag(general_inbld_flag);
         } else {
-            xu(1, general_reserved_zero_bit, zero, 0, 0);
+            fixed(1, general_reserved_zero_bit, 0);
         }
 #undef profile_compatible
     }
@@ -154,10 +153,8 @@  static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
     }
 
     if (max_num_sub_layers_minus1 > 0) {
-        for (i = max_num_sub_layers_minus1; i < 8; i++) {
-            av_unused int zero = 0;
-            xu(2, reserved_zero_2bits, zero, 0, 0);
-        }
+        for (i = max_num_sub_layers_minus1; i < 8; i++)
+            fixed(2, reserved_zero_2bits, 0);
     }
 
     for (i = 0; i < max_num_sub_layers_minus1; i++) {
@@ -386,10 +383,7 @@  static int FUNC(vps)(CodedBitstreamContext *ctx, RWContext *rw,
         return AVERROR_INVALIDDATA;
     }
 
-    {
-        av_unused uint16_t ffff = 0xffff;
-        xu(16, vps_reserved_0xffff_16bits, ffff, 0xffff, 0xffff);
-    }
+    fixed(16, vps_reserved_0xffff_16bits, 0xffff);
 
     CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
                                    1, current->vps_max_sub_layers_minus1));