[vlc-commits] avformat: mux: use the more accurate AVIODataMarkerType type to write headers

Steve Lhomme git at videolan.org
Mon Aug 8 19:35:52 CEST 2016


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Thu Aug  4 18:43:47 2016 +0200| [00fa9b1a5c4a2af66868346226f6cb86f731ff60] | committer: Jean-Baptiste Kempf

avformat: mux: use the more accurate AVIODataMarkerType type to write headers

In FFmpeg a call to avformat_write_header() then avio_flush() doesn't
necessarily write the data to the IO so our b_write_header detection never sees
anything.
We can rely on the new write system that tells what kind of data that is being
written.

This fixes multiple connections on the HTTP server when using the FFmpeg muxer.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/demux/avformat/mux.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/modules/demux/avformat/mux.c b/modules/demux/avformat/mux.c
index efe9b9d..e2df0f1 100644
--- a/modules/demux/avformat/mux.c
+++ b/modules/demux/avformat/mux.c
@@ -61,6 +61,9 @@ struct sout_mux_sys_t
     bool     b_write_header;
     bool     b_write_keyframe;
     bool     b_error;
+#if LIBAVCODEC_VERSION_CHECK( 57, 7, 0, 40, 100 )
+    bool     b_header_done;
+#endif
 };
 
 /*****************************************************************************
@@ -73,6 +76,10 @@ static int Mux      ( sout_mux_t * );
 
 static int IOWrite( void *opaque, uint8_t *buf, int buf_size );
 static int64_t IOSeek( void *opaque, int64_t offset, int whence );
+#if LIBAVCODEC_VERSION_CHECK( 57, 7, 0, 40, 100 )
+static int IOWriteTyped(void *opaque, uint8_t *buf, int buf_size,
+                              enum AVIODataMarkerType type, int64_t time);
+#endif
 
 /*****************************************************************************
  * Open
@@ -137,6 +144,10 @@ int OpenMux( vlc_object_t *p_this )
     p_sys->b_write_header = true;
     p_sys->b_write_keyframe = false;
     p_sys->b_error = false;
+#if LIBAVCODEC_VERSION_CHECK( 57, 7, 0, 40, 100 )
+    p_sys->io->write_data_type = IOWriteTyped;
+    p_sys->b_header_done = false;
+#endif
 
     /* Fill p_mux fields */
     p_mux->pf_control   = Control;
@@ -362,6 +373,20 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
     return VLC_SUCCESS;
 }
 
+#if LIBAVCODEC_VERSION_CHECK( 57, 7, 0, 40, 100 )
+int IOWriteTyped(void *opaque, uint8_t *buf, int buf_size,
+                              enum AVIODataMarkerType type, int64_t time)
+{
+    VLC_UNUSED(time);
+
+    sout_mux_t *p_mux = opaque;
+    sout_mux_sys_t *p_sys = p_mux->p_sys;
+    if ( !p_sys->b_header_done && type != AVIO_DATA_MARKER_HEADER )
+        p_sys->b_header_done = true;
+    return IOWrite(opaque, buf, buf_size);
+}
+#endif
+
 /*****************************************************************************
  * Mux: multiplex available data in input fifos
  *****************************************************************************/
@@ -465,6 +490,10 @@ static int IOWrite( void *opaque, uint8_t *buf, int buf_size )
 
     if( p_sys->b_write_header )
         p_buf->i_flags |= BLOCK_FLAG_HEADER;
+#if LIBAVCODEC_VERSION_CHECK( 57, 7, 0, 40, 100 )
+    if( !p_sys->b_header_done )
+        p_buf->i_flags |= BLOCK_FLAG_HEADER;
+#endif
 
     if( p_sys->b_write_keyframe )
     {



More information about the vlc-commits mailing list