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

Steve Lhomme robux4 at videolabs.io
Thu Aug 4 18:43:47 CEST 2016


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.
---
 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 75e38f9..462d092 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
  *****************************************************************************/
@@ -463,6 +488,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 )
     {
-- 
2.8.2



More information about the vlc-devel mailing list