]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
parsers: h265 parser - tiny optimizations
authorJaroslav Kysela <perex@perex.cz>
Tue, 27 Oct 2015 20:43:23 +0000 (21:43 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 27 Oct 2015 20:43:23 +0000 (21:43 +0100)
src/parsers/bitstream.c
src/parsers/parser_h264.c

index 9e9fefdb94feec4d4fb8d406aca409ebedab07c5..13ce82546101f775b4f140c5d215ce7d1b381283 100644 (file)
@@ -105,7 +105,7 @@ read_golomb_ue(bitstream_t *bs)
   uint32_t b;
   int lzb = -1;
 
-  for(b = 0; !b && !bs_eof(bs); lzb++)
+  for(b = 0; !b && !bs_eof(bs) && lzb < 32; lzb++)
     b = read_bits1(bs);
 
   if (lzb < 0)
@@ -117,14 +117,12 @@ read_golomb_ue(bitstream_t *bs)
 int32_t
 read_golomb_se(bitstream_t *bs)
 {
-  uint32_t v, pos;
+  uint32_t v;
   v = read_golomb_ue(bs);
   if(v == 0)
     return 0;
 
-  pos = v & 1;
-  v = (v + 1) >> 1;
-  return pos ? v : -v;
+  return (v & 1) ? ((v + 1) >> 1) : -(v >> 1);
 }
 
 
index 3c87a709abcb7ea9f46f0ef8e87ec0339c97cd3a..7f3f9cd49319c6fa10c7ee30ce26dd23906d224f 100644 (file)
@@ -189,6 +189,9 @@ decode_vui(h264_sps_t *sps, bitstream_t *bs)
   if (!read_bits1(bs))   /* We need timing info */
     return 0;
 
+  if (remaining_bits(bs) < 65)
+    return 0;
+
   sps->units_in_tick = read_bits(bs, 32);
   sps->time_scale    = read_bits(bs, 32);
   sps->fixed_rate    = read_bits1(bs);
@@ -254,11 +257,12 @@ h264_decode_seq_parameter_set(elementary_stream_t *st, bitstream_t *bs)
     return -1;
 
   if (profile_idc >= 100){ //high profile
-    if(read_golomb_ue(bs) == 3) //chroma_format_idc
-      read_bits1(bs);  //residual_color_transform_flag
-    read_golomb_ue(bs);  //bit_depth_luma_minus8
-    read_golomb_ue(bs);  //bit_depth_chroma_minus8
-    read_bits1(bs);
+    tmp = read_golomb_ue(bs);
+    if (tmp == 3)          //chroma_format_idc
+      read_bits1(bs);      //residual_color_transform_flag
+    read_golomb_ue(bs);    //bit_depth_luma_minus8
+    read_golomb_ue(bs);    //bit_depth_chroma_minus8
+    read_bits1(bs);        //transform_bypass
 
     if(read_bits1(bs)) {
       /* Scaling matrices */
@@ -276,11 +280,11 @@ h264_decode_seq_parameter_set(elementary_stream_t *st, bitstream_t *bs)
   }
 
   max_frame_num_bits = read_golomb_ue(bs) + 4;
-  poc_type = read_golomb_ue(bs);
-  if(poc_type == 0){ //FIXME #define
+  poc_type = read_golomb_ue(bs); // pic_order_cnt_type
+
+  if(poc_type == 0){
     read_golomb_ue(bs);
-  } else if(poc_type == 1){//FIXME #define
+  } else if(poc_type == 1){
     skip_bits1(bs);
     read_golomb_se(bs);
     read_golomb_se(bs);