[vlc-commits] packetizer: h264: store original slice type

Francois Cartegnie git at videolan.org
Mon Mar 20 14:17:07 CET 2017


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Mar 20 13:52:49 2017 +0100| [659b84e88b971977967178abf5bda989088f51ff] | committer: Francois Cartegnie

packetizer: h264: store original slice type

And do not tag blocks with switching slices

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

 modules/packetizer/h264.c       | 31 ++++++++++++++++++++++---------
 modules/packetizer/h264_slice.c | 24 ++----------------------
 modules/packetizer/h264_slice.h | 14 ++++++++++++--
 3 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/modules/packetizer/h264.c b/modules/packetizer/h264.c
index 5c5d397..aa5b17a 100644
--- a/modules/packetizer/h264.c
+++ b/modules/packetizer/h264.c
@@ -501,7 +501,7 @@ static void PacketizeReset( void *p_private, bool b_broken )
         p_sys->i_frame_pts = VLC_TS_INVALID;
         p_sys->i_frame_dts = VLC_TS_INVALID;
         p_sys->b_even_frame = false;
-        p_sys->slice.i_frame_type = 0;
+        p_sys->slice.type = H264_SLICE_TYPE_UNKNOWN;
         p_sys->b_slice = false;
         /* POC */
         h264_poc_context_init( &p_sys->pocctx );
@@ -551,7 +551,7 @@ static block_t *ParseNALBlock( decoder_t *p_dec, bool *pb_ts_used, block_t *p_fr
         msg_Warn( p_dec, "waiting for SPS/PPS" );
 
         /* Reset context */
-        p_sys->slice.i_frame_type = 0;
+        p_sys->slice.type = H264_SLICE_TYPE_UNKNOWN;
         p_sys->p_frame = NULL;
         p_sys->pp_frame_last = &p_sys->p_frame;
         p_sys->p_sei = NULL;
@@ -687,7 +687,7 @@ static block_t *OutputPicture( decoder_t *p_dec )
     }
 
     if( !p_sys->b_header && p_sys->i_recovery_frames == -1 &&
-         p_sys->slice.i_frame_type != BLOCK_FLAG_TYPE_I)
+         p_sys->slice.type != H264_SLICE_TYPE_I)
         return NULL;
 
     /* Bind matched/referred PPS and SPS */
@@ -699,7 +699,7 @@ static block_t *OutputPicture( decoder_t *p_dec )
     /* Gather PPS/SPS if required */
     block_t *p_xpsnal = NULL;
     block_t **pp_xpsnal_tail = &p_xpsnal;
-    const bool b_sps_pps_i = p_sys->slice.i_frame_type == BLOCK_FLAG_TYPE_I &&
+    const bool b_sps_pps_i = p_sys->slice.type != H264_SLICE_TYPE_I &&
                              p_sys->p_active_pps &&
                              p_sys->p_active_sps;
     if( b_sps_pps_i || p_sys->b_new_sps || p_sys->b_new_pps )
@@ -816,7 +816,7 @@ static block_t *OutputPicture( decoder_t *p_dec )
     int tFOC = 0, bFOC = 0, PictureOrderCount = 0;
     h264_compute_poc( p_sps, &p_sys->slice, &p_sys->pocctx, &PictureOrderCount, &tFOC, &bFOC );
 
-    if( p_sys->slice.i_frame_type & BLOCK_FLAG_TYPE_I )
+    if( p_sys->slice.type == H264_SLICE_TYPE_I )
         p_sys->prevdatedpoc.pts = VLC_TS_INVALID;
 
     if( p_pic->i_pts == VLC_TS_INVALID )
@@ -836,11 +836,11 @@ static block_t *OutputPicture( decoder_t *p_dec )
         }
         /* In case there's no PTS at all */
         else if( p_sys->slice.i_nal_ref_idc == 0 &&
-                 p_sys->slice.i_frame_type == BLOCK_FLAG_TYPE_B )
+                 p_sys->slice.type == H264_SLICE_TYPE_B )
         {
             p_pic->i_pts = p_pic->i_dts;
         }
-        else if( p_sys->slice.i_frame_type == BLOCK_FLAG_TYPE_I )
+        else if( p_sys->slice.type == H264_SLICE_TYPE_I )
         {
             /* Hell no PTS on IDR. We're totally blind */
             date_t pts = p_sys->dts;
@@ -876,7 +876,20 @@ static block_t *OutputPicture( decoder_t *p_dec )
             p_pic->i_flags |= BLOCK_FLAG_DISCONTINUITY;
     }
 
-    p_pic->i_flags |= p_sys->slice.i_frame_type;
+    switch( p_sys->slice.type )
+    {
+        case H264_SLICE_TYPE_P:
+            p_pic->i_flags |= BLOCK_FLAG_TYPE_P;
+            break;
+        case H264_SLICE_TYPE_B:
+            p_pic->i_flags |= BLOCK_FLAG_TYPE_B;
+            break;
+        case H264_SLICE_TYPE_I:
+            p_pic->i_flags |= BLOCK_FLAG_TYPE_I;
+        default:
+            break;
+    }
+
     p_pic->i_flags &= ~BLOCK_FLAG_PRIVATE_AUD;
     if( !p_sys->b_header )
         p_pic->i_flags |= BLOCK_FLAG_PREROLL;
@@ -886,7 +899,7 @@ static block_t *OutputPicture( decoder_t *p_dec )
     p_sys->i_frame_pts = VLC_TS_INVALID;
     p_sys->i_dpb_output_delay = 0;
     p_sys->i_pic_struct = 0;
-    p_sys->slice.i_frame_type = 0;
+    p_sys->slice.type = H264_SLICE_TYPE_UNKNOWN;
     p_sys->p_sei = NULL;
     p_sys->pp_sei_last = &p_sys->p_sei;
     p_sys->b_new_sps = false;
diff --git a/modules/packetizer/h264_slice.c b/modules/packetizer/h264_slice.c
index 1b14382..98f487e 100644
--- a/modules/packetizer/h264_slice.c
+++ b/modules/packetizer/h264_slice.c
@@ -23,7 +23,6 @@
 
 #include <vlc_common.h>
 #include <vlc_bits.h>
-#include <vlc_block.h>
 
 #include "h264_nal.h"
 #include "h264_slice.h"
@@ -52,27 +51,8 @@ bool h264_decode_slice( const uint8_t *p_buffer, size_t i_buffer,
     /* int i_first_mb = */ bs_read_ue( &s );
 
     /* slice_type */
-    switch( (i_slice_type = bs_read_ue( &s )) )
-    {
-    case 0: case 5:
-        p_slice->i_frame_type = BLOCK_FLAG_TYPE_P;
-        break;
-    case 1: case 6:
-        p_slice->i_frame_type = BLOCK_FLAG_TYPE_B;
-        break;
-    case 2: case 7:
-        p_slice->i_frame_type = BLOCK_FLAG_TYPE_I;
-        break;
-    case 3: case 8: /* SP */
-        p_slice->i_frame_type = BLOCK_FLAG_TYPE_P;
-        break;
-    case 4: case 9:
-        p_slice->i_frame_type = BLOCK_FLAG_TYPE_I;
-        break;
-    default:
-        p_slice->i_frame_type = 0;
-        break;
-    }
+    i_slice_type = bs_read_ue( &s );
+    p_slice->type = i_slice_type % 5;
 
     /* */
     p_slice->i_nal_type = i_nal_type;
diff --git a/modules/packetizer/h264_slice.h b/modules/packetizer/h264_slice.h
index 1ac399d..5729bdc 100644
--- a/modules/packetizer/h264_slice.h
+++ b/modules/packetizer/h264_slice.h
@@ -20,12 +20,22 @@
 #ifndef VLC_H264_SLICE_H
 #define VLC_H264_SLICE_H
 
+enum h264_slice_type_e
+{
+    H264_SLICE_TYPE_P = 0,
+    H264_SLICE_TYPE_B,
+    H264_SLICE_TYPE_I,
+    H264_SLICE_TYPE_SP,
+    H264_SLICE_TYPE_SI,
+    H264_SLICE_TYPE_UNKNOWN,
+};
+
 typedef struct
 {
     int i_nal_type;
     int i_nal_ref_idc;
 
-    int i_frame_type;
+    enum h264_slice_type_e type;
     int i_pic_parameter_set_id;
     int i_frame_num;
 
@@ -50,7 +60,7 @@ static inline void h264_slice_init( h264_slice_t *p_slice )
     p_slice->i_nal_ref_idc = -1;
     p_slice->i_idr_pic_id = -1;
     p_slice->i_frame_num = -1;
-    p_slice->i_frame_type = 0;
+    p_slice->type = H264_SLICE_TYPE_UNKNOWN;
     p_slice->i_pic_parameter_set_id = -1;
     p_slice->i_field_pic_flag = 0;
     p_slice->i_bottom_field_flag = -1;



More information about the vlc-commits mailing list