]> git.sesse.net Git - vlc/blobdiff - modules/codec/ffmpeg/mux.c
More Id and permission fixes.
[vlc] / modules / codec / ffmpeg / mux.c
index 2d616846b842e1426f3a1ac836fa48ace07665fe..8caab6b6751d1da5269b046d60103a369e1c17f2 100644 (file)
@@ -2,7 +2,7 @@
  * mux.c: muxer using ffmpeg (libavformat).
  *****************************************************************************
  * Copyright (C) 2006 the VideoLAN team
- * $Id: demux.c 8444 2004-08-17 08:21:07Z gbazin $
+ * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
  *
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
 #include <vlc_block.h>
 #include <vlc_sout.h>
 
 /* ffmpeg header */
-#ifdef HAVE_FFMPEG_AVFORMAT_H
+#ifdef HAVE_LIBAVFORMAT_AVFORMAT_H
+#   include <libavformat/avformat.h>
+#elif defined(HAVE_FFMPEG_AVFORMAT_H)
 #   include <ffmpeg/avformat.h>
 #elif defined(HAVE_LIBAVFORMAT_TREE)
 #   include <avformat.h>
@@ -42,7 +47,7 @@
 //#define AVFORMAT_DEBUG 1
 
 /* Version checking */
-#if defined(HAVE_FFMPEG_AVFORMAT_H) || defined(HAVE_LIBAVFORMAT_TREE)
+#if defined(HAVE_LIBAVFORMAT_AVFORMAT_H) || defined(HAVE_FFMPEG_AVFORMAT_H) || defined(HAVE_LIBAVFORMAT_TREE)
 
 static const char *ppsz_mux_options[] = {
     "mux", NULL
@@ -149,7 +154,11 @@ int E_(OpenMux)( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
+#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(0<<8)+0)
+    p_sys->oc->pb = &p_sys->io;
+#else
     p_sys->oc->pb = p_sys->io;
+#endif
     p_sys->oc->nb_streams = 0;
 
     p_sys->b_write_header = VLC_TRUE;
@@ -166,7 +175,7 @@ void E_(CloseMux)( vlc_object_t *p_this )
 {
     sout_mux_t *p_mux = (sout_mux_t*)p_this;
     sout_mux_sys_t *p_sys = p_mux->p_sys;
-    int i;
+    unsigned int i;
 
     if( av_write_trailer( p_sys->oc ) < 0 )
     {
@@ -249,6 +258,9 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
         codec->time_base.den = p_input->p_fmt->video.i_frame_rate;
         codec->time_base.num = p_input->p_fmt->video.i_frame_rate_base;
         break;
+
+    default:
+        msg_Warn( p_mux, "Unhandled ES category" );
     }
 
     codec->bit_rate = p_input->p_fmt->i_bitrate;
@@ -261,7 +273,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
     }
 #else
 #   warning "WARNING!!!!!!!"
-#   warning "Using libavformat muxing with versions older than 51.8.0 (r7593) might produce broken files.
+#   warning "Using libavformat muxing with versions older than 51.8.0 (r7593) might produce broken files."
     /* This is a hack */
     if( i_codec_id == CODEC_ID_MP2 )
         i_codec_id = CODEC_ID_MP3;
@@ -306,9 +318,9 @@ static int MuxGetStream( sout_mux_t *p_mux, int *pi_stream, mtime_t *pi_dts )
 
         /* We don't really need to have anything in the SPU fifo */
         if( p_mux->pp_inputs[i]->p_fmt->i_cat == SPU_ES &&
-            p_fifo->i_depth == 0 ) continue;
+            block_FifoCount( p_fifo ) == 0 ) continue;
 
-        if( p_fifo->i_depth )
+        if( block_FifoCount( p_fifo ) )
         {
             block_t *p_buf;
 
@@ -357,7 +369,8 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
             I64C(1000000) / p_stream->time_base.num;
 
     /* this is another hack to prevent libavformat from triggering the "non monotone timestamps" check in avformat/utils.c */
-    p_stream->cur_dts = AV_NOPTS_VALUE;
+    p_stream->cur_dts = ( p_data->i_dts * p_stream->time_base.den /
+            I64C(1000000) / p_stream->time_base.num ) - 1;
 
     if( av_write_frame( p_sys->oc, &pkt ) < 0 )
     {
@@ -386,16 +399,19 @@ static int Mux( sout_mux_t *p_mux )
     {
         msg_Dbg( p_mux, "writing header" );
 
-
         if( av_write_header( p_sys->oc ) < 0 )
         {
             msg_Err( p_mux, "could not write header" );
-        p_sys->b_write_header = VLC_FALSE;
+            p_sys->b_write_header = VLC_FALSE;
             p_sys->b_error = VLC_TRUE;
             return VLC_EGENERIC;
         }
 
+#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(0<<8)+0)
+        put_flush_packet( p_sys->oc->pb );
+#else
         put_flush_packet( &p_sys->oc->pb );
+#endif
         p_sys->b_write_header = VLC_FALSE;
     }
 
@@ -491,15 +507,4 @@ static offset_t IOSeek( void *opaque, offset_t offset, int whence )
     return 0;
 }
 
-#else /* HAVE_FFMPEG_AVFORMAT_H */
-
-int E_(OpenMux)( vlc_object_t *p_this )
-{
-    return VLC_EGENERIC;
-}
-
-void E_(CloseMux)( vlc_object_t *p_this )
-{
-}
-
 #endif /* HAVE_FFMPEG_AVFORMAT_H */