Browse code

h264: fix HRD parameters parsing

The bit_rate_value_minus1 and cpb_size_value_minus1 elements
allow a wider range than get_ue_golomb() supports. This
adds a get_ue_golomb_long() function supporting up to 31
leading zeros, which is the maximum for these syntax
elements, and uses it in decode_hrd_parameters().

Signed-off-by: Mans Rullgard <mans@mansr.com>

Mans Rullgard authored on 2011/10/12 00:00:21
Showing 2 changed files
... ...
@@ -75,6 +75,20 @@ static inline int get_ue_golomb(GetBitContext *gb){
75 75
     }
76 76
 }
77 77
 
78
+/**
79
+ * Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
80
+ */
81
+static inline unsigned get_ue_golomb_long(GetBitContext *gb)
82
+{
83
+    unsigned buf, log;
84
+
85
+    buf = show_bits_long(gb, 32);
86
+    log = 31 - av_log2(buf);
87
+    skip_bits_long(gb, log);
88
+
89
+    return get_bits_long(gb, log + 1) - 1;
90
+}
91
+
78 92
  /**
79 93
  * read unsigned exp golomb code, constraint to a max of 31.
80 94
  * the return value is undefined if the stored value exceeds 31.
... ...
@@ -130,8 +130,8 @@ static inline int decode_hrd_parameters(H264Context *h, SPS *sps){
130 130
     get_bits(&s->gb, 4); /* bit_rate_scale */
131 131
     get_bits(&s->gb, 4); /* cpb_size_scale */
132 132
     for(i=0; i<cpb_count; i++){
133
-        get_ue_golomb(&s->gb); /* bit_rate_value_minus1 */
134
-        get_ue_golomb(&s->gb); /* cpb_size_value_minus1 */
133
+        get_ue_golomb_long(&s->gb); /* bit_rate_value_minus1 */
134
+        get_ue_golomb_long(&s->gb); /* cpb_size_value_minus1 */
135 135
         get_bits1(&s->gb);     /* cbr_flag */
136 136
     }
137 137
     sps->initial_cpb_removal_delay_length = get_bits(&s->gb, 5) + 1;