]> git.sesse.net Git - vlc/commitdiff
TS: insert/flag PAT/PMT before keyframes if use-keyframes is set
authorIlkka Ollakka <ileoo@videolan.org>
Tue, 22 Jan 2013 14:11:43 +0000 (16:11 +0200)
committerIlkka Ollakka <ileoo@videolan.org>
Tue, 22 Jan 2013 18:46:22 +0000 (20:46 +0200)
Flagging those PAT/PMT blocks enables us to segment ts-files so that
each segment starts with PAT,PMT,Keyframes. Usable in livehttp-module.

modules/mux/mpeg/ts.c

index b916730ebcc2d7f73958458887d9a34fae7c0f01..578ada361d57a65d6d857dd92830741fb4cc35f3 100644 (file)
@@ -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 );
     }