[vlc-commits] packetizer: packetizer_helper: add drain

Francois Cartegnie git at videolan.org
Tue Sep 24 20:57:14 CEST 2019


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

packetizer: packetizer_helper: add drain

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

 modules/packetizer/h264.c              |  3 ++-
 modules/packetizer/hevc.c              |  3 ++-
 modules/packetizer/mjpeg.c             |  3 ++-
 modules/packetizer/mpeg4video.c        |  3 ++-
 modules/packetizer/mpegvideo.c         |  3 ++-
 modules/packetizer/packetizer_helper.h | 28 +++++++++++++++++++++++++---
 modules/packetizer/vc1.c               |  3 ++-
 7 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/modules/packetizer/h264.c b/modules/packetizer/h264.c
index 23cccb0252..dc1567292d 100644
--- a/modules/packetizer/h264.c
+++ b/modules/packetizer/h264.c
@@ -335,7 +335,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 f9b38fa8c6..900c8647ee 100644
--- a/modules/packetizer/hevc.c
+++ b/modules/packetizer/hevc.c
@@ -213,7 +213,8 @@ static int Open(vlc_object_t *p_this)
     packetizer_Init(&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/mjpeg.c b/modules/packetizer/mjpeg.c
index 223f7e9c7c..fa015f3828 100644
--- a/modules/packetizer/mjpeg.c
+++ b/modules/packetizer/mjpeg.c
@@ -202,7 +202,8 @@ static int Open( vlc_object_t *p_this )
     packetizer_Init( &p_sys->packetizer,
                      p_mjpg_startcode, sizeof(p_mjpg_startcode), startcode_Find,
                      NULL, 0, 295,
-                     PacketizeReset, PacketizeParse, PacketizeValidate, p_dec );
+                     PacketizeReset, PacketizeParse, PacketizeValidate, NULL,
+                     p_dec );
 
     p_dec->pf_packetize = Packetize;
     p_dec->pf_flush = PacketizeFlush;
diff --git a/modules/packetizer/mpeg4video.c b/modules/packetizer/mpeg4video.c
index 927f71e828..f2709f1206 100644
--- a/modules/packetizer/mpeg4video.c
+++ b/modules/packetizer/mpeg4video.c
@@ -145,7 +145,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 ac8040f0d0..d449e4204b 100644
--- a/modules/packetizer/mpegvideo.c
+++ b/modules/packetizer/mpegvideo.c
@@ -211,7 +211,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 c65c4e5911..c2ef611e44 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_flush );
 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;
 
@@ -233,6 +237,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 e08ab034e8..08c5ffed60 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