[vlc-commits] TS: insert/flag PAT/PMT before keyframes if use-keyframes is set

Ilkka Ollakka git at videolan.org
Tue Jan 22 19:48:05 CET 2013


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Tue Jan 22 16:11:43 2013 +0200| [578e4483bc06c947db6e5017724297a6a74caa42] | committer: Ilkka Ollakka

TS: insert/flag PAT/PMT before keyframes if use-keyframes is set

Flagging those PAT/PMT blocks enables us to segment ts-files so that
each segment starts with PAT,PMT,Keyframes. Usable in livehttp-module.

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

 modules/mux/mpeg/ts.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/modules/mux/mpeg/ts.c b/modules/mux/mpeg/ts.c
index b916730..578ada3 100644
--- a/modules/mux/mpeg/ts.c
+++ b/modules/mux/mpeg/ts.c
@@ -1173,6 +1173,18 @@ static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
     return VLC_SUCCESS;
 }
 
+static void SetHeader( sout_buffer_chain_t *c,
+                        int depth )
+{
+    block_t *p_ts = BufferChainPeek( c );
+    while( depth > 0 )
+    {
+        p_ts = p_ts->p_next;
+        depth--;
+    }
+    p_ts->i_flags |= BLOCK_FLAG_HEADER;
+}
+
 /* returns true if needs more data */
 static bool MuxStreams(sout_mux_t *p_mux )
 {
@@ -1430,6 +1442,7 @@ static bool MuxStreams(sout_mux_t *p_mux )
     /* 3: mux PES into TS */
     BufferChainInit( &chain_ts );
     /* append PAT/PMT  -> FIXME with big pcr delay it won't have enough pat/pmt */
+    bool pat_was_previous = true; //This is to prevent unnecessary double PAT/PMT insertions
     GetPAT( p_mux, &chain_ts );
     GetPMT( p_mux, &chain_ts );
     int i_packet_pos = 0;
@@ -1487,6 +1500,24 @@ static bool MuxStreams(sout_mux_t *p_mux )
         }
         i_packet_pos++;
 
+        /* Write PAT/PMT before every keyframe if use-key-frames is enabled,
+         * this helps to do segmenting with livehttp-output so it can cut segment
+         * and start new one with pat,pmt,keyframe*/
+        if( ( p_sys->b_use_key_frames ) && ( p_ts->i_flags & BLOCK_FLAG_TYPE_I ) )
+        {
+            if( likely( !pat_was_previous ) )
+            {
+                int startcount = chain_ts.i_depth;
+                GetPAT( p_mux, &chain_ts );
+                GetPMT( p_mux, &chain_ts );
+                SetHeader( &chain_ts, startcount );
+                i_packet_count += (chain_ts.i_depth - startcount );
+            } else {
+                SetHeader( &chain_ts, 0); //We just inserted pat/pmt,so just flag it instead of adding new one
+            }
+        }
+        pat_was_previous = false;
+
         /* */
         BufferChainAppend( &chain_ts, p_ts );
     }



More information about the vlc-commits mailing list