[vlc-commits] h264: refactor Exp-Golomb reading functions with existing mpeg demuxing code

Felix Abecassis git at videolan.org
Fri Aug 1 11:24:14 CEST 2014


vlc | branch: master | Felix Abecassis <felix.abecassis at gmail.com> | Fri Aug  1 11:18:35 2014 +0200| [999867028cb6f3dcfb0bdbdb8289d8c392eac9a1] | committer: Felix Abecassis

h264: refactor Exp-Golomb reading functions with existing mpeg demuxing code

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=999867028cb6f3dcfb0bdbdb8289d8c392eac9a1
---

 modules/demux/mpeg/hevc.c                |    8 ++++----
 modules/demux/mpeg/mpeg_parser_helpers.h |   10 +++++++++-
 modules/mux/mp4.c                        |   20 ++++++++++----------
 modules/packetizer/h264.c                |   19 +------------------
 4 files changed, 24 insertions(+), 33 deletions(-)

diff --git a/modules/demux/mpeg/hevc.c b/modules/demux/mpeg/hevc.c
index 9add76b..b564ea5 100644
--- a/modules/demux/mpeg/hevc.c
+++ b/modules/demux/mpeg/hevc.c
@@ -263,12 +263,12 @@ static int32_t getFPS( demux_t *p_demux, block_t * p_block )
     int32_t i = vps_sub_layer_ordering_info_present_flag? 0 : max_sub_layer_minus1;
     for( ; i <= max_sub_layer_minus1; i++ )
     {
-        read_ue( &bs );
-        read_ue( &bs );
-        read_ue( &bs );
+        bs_read_ue( &bs );
+        bs_read_ue( &bs );
+        bs_read_ue( &bs );
     }
     uint32_t vps_max_layer_id = bs_read( &bs, 6);
-    uint32_t vps_num_layer_sets_minus1 = read_ue( &bs );
+    uint32_t vps_num_layer_sets_minus1 = bs_read_ue( &bs );
     bs_skip( &bs, vps_max_layer_id * vps_num_layer_sets_minus1 );
 
     if( bs_read1( &bs ))
diff --git a/modules/demux/mpeg/mpeg_parser_helpers.h b/modules/demux/mpeg/mpeg_parser_helpers.h
index f8522e8..362ae6b 100644
--- a/modules/demux/mpeg/mpeg_parser_helpers.h
+++ b/modules/demux/mpeg/mpeg_parser_helpers.h
@@ -51,7 +51,8 @@ static inline void hevc_skip_profile_tiers_level( bs_t * bs, int32_t max_sub_lay
     }
 }
 
-static inline uint32_t read_ue( bs_t * bs )
+/* Read unsigned Exp-Golomb code */
+static inline uint32_t bs_read_ue( bs_t * bs )
 {
     int32_t i = 0;
 
@@ -61,6 +62,13 @@ static inline uint32_t read_ue( bs_t * bs )
     return (1 << i) - 1 + bs_read( bs, i );
 }
 
+/* Read signed Exp-Golomb code */
+static inline int32_t bs_read_se( bs_t *s )
+{
+    int val = bs_read_ue( s );
+
+    return val&0x01 ? (val+1)/2 : -(val/2);
+}
 
 static inline size_t nal_decode(uint8_t * p_src, uint8_t * p_dst, size_t i_size)
 {
diff --git a/modules/mux/mp4.c b/modules/mux/mp4.c
index 92fe09a..68b9ecb 100644
--- a/modules/mux/mp4.c
+++ b/modules/mux/mp4.c
@@ -856,26 +856,26 @@ static void hevcParseSPS(uint8_t * p_buffer, size_t i_buffer, uint8_t * chroma_i
     hevc_skip_profile_tiers_level(&bs, sps_max_sublayer_minus1);
 
     /* skip sps id */
-    (void) read_ue( &bs );
+    (void) bs_read_ue( &bs );
 
-    *chroma_idc = read_ue(&bs);
+    *chroma_idc = bs_read_ue(&bs);
     if (*chroma_idc == 3)
         bs_skip(&bs, 1);
 
     /* skip width and heigh */
-    (void) read_ue( &bs );
-    (void) read_ue( &bs );
+    (void) bs_read_ue( &bs );
+    (void) bs_read_ue( &bs );
 
     uint32_t conformance_window_flag = bs_read1(&bs);
     if (conformance_window_flag) {
         /* skip offsets*/
-        (void) read_ue(&bs);
-        (void) read_ue(&bs);
-        (void) read_ue(&bs);
-        (void) read_ue(&bs);
+        (void) bs_read_ue(&bs);
+        (void) bs_read_ue(&bs);
+        (void) bs_read_ue(&bs);
+        (void) bs_read_ue(&bs);
     }
-    *bit_depth_luma_minus8 = read_ue(&bs);
-    *bit_depth_chroma_minus8 = read_ue(&bs);
+    *bit_depth_luma_minus8 = bs_read_ue(&bs);
+    *bit_depth_chroma_minus8 = bs_read_ue(&bs);
 }
 
 static bo_t *GetHvcCTag(mp4_stream_t *p_stream)
diff --git a/modules/packetizer/h264.c b/modules/packetizer/h264.c
index e671f6e..202ae6b 100644
--- a/modules/packetizer/h264.c
+++ b/modules/packetizer/h264.c
@@ -42,6 +42,7 @@
 #include <vlc_bits.h>
 #include "../codec/cc.h"
 #include "packetizer_helper.h"
+#include "../demux/mpeg/mpeg_parser_helpers.h"
 
 /*****************************************************************************
  * Module descriptor
@@ -572,24 +573,6 @@ static void CreateDecodedNAL( uint8_t **pp_ret, int *pi_ret,
     *pi_ret = dst - *pp_ret;
 }
 
-static inline int bs_read_ue( bs_t *s )
-{
-    int i = 0;
-
-    while( bs_read1( s ) == 0 && s->p < s->p_end && i < 32 )
-    {
-        i++;
-    }
-    return( ( 1 << i) - 1 + bs_read( s, i ) );
-}
-
-static inline int bs_read_se( bs_t *s )
-{
-    int val = bs_read_ue( s );
-
-    return val&0x01 ? (val+1)/2 : -(val/2);
-}
-
 /*****************************************************************************
  * ParseNALBlock: parses annexB type NALs
  * All p_frag blocks are required to start with 0 0 0 1 4-byte startcode



More information about the vlc-commits mailing list