[vlc-commits] packetizer: packetizer_helper: add drain

Francois Cartegnie git at videolan.org
Fri Oct 11 17:28:30 CEST 2019


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Sep 23 20:35:23 2019 +0200| [ec09038c51bec24aaaedac50e6ceccd120273a95] | committer: Francois Cartegnie

packetizer: packetizer_helper: add drain

(cherry picked from commit b279fc8f635b52431f56ed5aadb5ff99d73dab1f)

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

 modules/packetizer/h264.c              |  3 ++-
 modules/packetizer/hevc.c              |  3 ++-
 modules/packetizer/mpeg4video.c        |  3 ++-
 modules/packetizer/mpegvideo.c         |  3 ++-
 modules/packetizer/packetizer_helper.h | 28 +++++++++++++++++++++++++---
 modules/packetizer/vc1.c               |  3 ++-
 6 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/modules/packetizer/h264.c b/modules/packetizer/h264.c
index c625005c8e..b9a4597b7f 100644
--- a/modules/packetizer/h264.c
+++ b/modules/packetizer/h264.c
@@ -334,7 +334,8 @@ static int Open( vlc_object_t *p_this )
     packetizer_Init( &p_sys->packetizer,
                      p_h264_startcode, sizeof(p_h264_startcode), startcode_FindAnnexB,
                      p_h264_startcode, 1, 5,
-                     PacketizeReset, PacketizeParse, PacketizeValidate, p_dec );
+                     PacketizeReset, PacketizeParse, PacketizeValidate, NULL,
+                     p_dec );
 
     p_sys->b_slice = false;
     p_sys->frame.p_head = NULL;
diff --git a/modules/packetizer/hevc.c b/modules/packetizer/hevc.c
index 0feeb659fe..7c007b1eb2 100644
--- a/modules/packetizer/hevc.c
+++ b/modules/packetizer/hevc.c
@@ -190,7 +190,8 @@ static int Open(vlc_object_t *p_this)
     packetizer_Init(&p_dec->p_sys->packetizer,
                     p_hevc_startcode, sizeof(p_hevc_startcode), startcode_FindAnnexB,
                     p_hevc_startcode, 1, 5,
-                    PacketizeReset, PacketizeParse, PacketizeValidate, p_dec);
+                    PacketizeReset, PacketizeParse, PacketizeValidate, NULL,
+                    p_dec);
 
     /* Copy properties */
     es_format_Copy(&p_dec->fmt_out, &p_dec->fmt_in);
diff --git a/modules/packetizer/mpeg4video.c b/modules/packetizer/mpeg4video.c
index 8b26ed557d..979f9bc6a7 100644
--- a/modules/packetizer/mpeg4video.c
+++ b/modules/packetizer/mpeg4video.c
@@ -148,7 +148,8 @@ static int Open( vlc_object_t *p_this )
     packetizer_Init( &p_sys->packetizer,
                      p_mp4v_startcode, sizeof(p_mp4v_startcode), startcode_FindAnnexB,
                      NULL, 0, 4,
-                     PacketizeReset, PacketizeParse, PacketizeValidate, p_dec );
+                     PacketizeReset, PacketizeParse, PacketizeValidate, NULL,
+                     p_dec );
 
     p_sys->p_frame = NULL;
     p_sys->pp_last = &p_sys->p_frame;
diff --git a/modules/packetizer/mpegvideo.c b/modules/packetizer/mpegvideo.c
index 3214922761..8fda80050c 100644
--- a/modules/packetizer/mpegvideo.c
+++ b/modules/packetizer/mpegvideo.c
@@ -210,7 +210,8 @@ static int Open( vlc_object_t *p_this )
     packetizer_Init( &p_sys->packetizer,
                      p_mp2v_startcode, sizeof(p_mp2v_startcode), startcode_FindAnnexB,
                      NULL, 0, 4,
-                     PacketizeReset, PacketizeParse, PacketizeValidate, p_dec );
+                     PacketizeReset, PacketizeParse, PacketizeValidate, NULL,
+                     p_dec );
 
     p_sys->p_seq = NULL;
     p_sys->p_ext = NULL;
diff --git a/modules/packetizer/packetizer_helper.h b/modules/packetizer/packetizer_helper.h
index f771189570..3edd61c66e 100644
--- a/modules/packetizer/packetizer_helper.h
+++ b/modules/packetizer/packetizer_helper.h
@@ -38,6 +38,7 @@ enum
 
 typedef void (*packetizer_reset_t)( void *p_private, bool b_broken );
 typedef block_t *(*packetizer_parse_t)( void *p_private, bool *pb_ts_used, block_t * );
+typedef block_t *(*packetizer_drain_t)( void *p_private );
 typedef int (*packetizer_validate_t)( void *p_private, block_t * );
 
 typedef struct
@@ -59,6 +60,7 @@ typedef struct
     packetizer_reset_t    pf_reset;
     packetizer_parse_t    pf_parse;
     packetizer_validate_t pf_validate;
+    packetizer_drain_t    pf_drain;
 
 } packetizer_t;
 
@@ -70,6 +72,7 @@ static inline void packetizer_Init( packetizer_t *p_pack,
                                     packetizer_reset_t pf_reset,
                                     packetizer_parse_t pf_parse,
                                     packetizer_validate_t pf_validate,
+                                    packetizer_drain_t pf_drain,
                                     void *p_private )
 {
     p_pack->i_state = STATE_NOSYNC;
@@ -86,6 +89,7 @@ static inline void packetizer_Init( packetizer_t *p_pack,
     p_pack->pf_reset = pf_reset;
     p_pack->pf_parse = pf_parse;
     p_pack->pf_validate = pf_validate;
+    p_pack->pf_drain = pf_drain;
     p_pack->p_private = p_private;
 }
 
@@ -102,16 +106,16 @@ static inline void packetizer_Flush( packetizer_t *p_pack )
     p_pack->pf_reset( p_pack->p_private, true );
 }
 
-static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_block )
+static block_t *packetizer_PacketizeBlock( packetizer_t *p_pack, block_t **pp_block )
 {
     block_t *p_block = ( pp_block ) ? *pp_block : NULL;
 
     if( p_block == NULL && p_pack->bytestream.p_block == NULL )
-        return NULL; /* nothing to do */
+        return NULL;
 
     if( p_block && unlikely( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
     {
-        block_t *p_drained = packetizer_Packetize( p_pack, NULL );
+        block_t *p_drained = packetizer_PacketizeBlock( p_pack, NULL );
         if( p_drained )
             return p_drained;
 
@@ -231,6 +235,24 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_
     }
 }
 
+static block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_block )
+{
+    block_t *p_out = packetizer_PacketizeBlock( p_pack, pp_block );
+    if( p_out )
+        return p_out;
+    /* handle caller drain */
+    if( pp_block == NULL && p_pack->pf_drain )
+    {
+        p_out = p_pack->pf_drain( p_pack->p_private );
+        if( p_out && p_pack->pf_validate( p_pack->p_private, p_out ) )
+        {
+            block_Release( p_out );
+            p_out = NULL;
+        }
+    }
+    return p_out;
+}
+
 static inline void packetizer_Header( packetizer_t *p_pack,
                                       const uint8_t *p_header, int i_header )
 {
diff --git a/modules/packetizer/vc1.c b/modules/packetizer/vc1.c
index 0780dbdb6a..e639a766ed 100644
--- a/modules/packetizer/vc1.c
+++ b/modules/packetizer/vc1.c
@@ -159,7 +159,8 @@ static int Open( vlc_object_t *p_this )
     packetizer_Init( &p_sys->packetizer,
                      p_vc1_startcode, sizeof(p_vc1_startcode), startcode_FindAnnexB,
                      NULL, 0, 4,
-                     PacketizeReset, PacketizeParse, PacketizeValidate, p_dec );
+                     PacketizeReset, PacketizeParse, PacketizeValidate, NULL,
+                     p_dec );
 
     p_sys->b_sequence_header = false;
     p_sys->sh.p_sh = NULL;



More information about the vlc-commits mailing list