]> git.sesse.net Git - vlc/commitdiff
h264: refactor Exp-Golomb reading functions with existing mpeg demuxing code
authorFelix Abecassis <felix.abecassis@gmail.com>
Fri, 1 Aug 2014 09:18:35 +0000 (11:18 +0200)
committerFelix Abecassis <felix.abecassis@gmail.com>
Fri, 1 Aug 2014 09:18:35 +0000 (11:18 +0200)
modules/demux/mpeg/hevc.c
modules/demux/mpeg/mpeg_parser_helpers.h
modules/mux/mp4.c
modules/packetizer/h264.c

index 9add76bd7b5bb787ec4a996328bfa217fc5e0c5d..b564ea5e8785ad0f0ff770ba65c4646df5a70d5f 100644 (file)
@@ -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 ))
index f8522e8a3da9a93a4132297a7997056590ebe78f..362ae6b79c0e23d4def9ce4b80238a5bdf086c7c 100644 (file)
@@ -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)
 {
index 92fe09a4d26480ca5a707324cea167bf01d538fb..68b9ecb0014f812bd84ec839672d23a18bab5d40 100644 (file)
@@ -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)
index e671f6e92bc97347bd50355db4ddc5664974f547..202ae6b95e52a1828d5f7a29c43deafa10ba2264 100644 (file)
@@ -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