]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/es.c
Don't include config.h from the headers - refs #297.
[vlc] / modules / stream_out / es.c
index 0ddac410af98308f3430de69799200befffbcb83..222bfa33a73848ad235933c5187ab3c83ea3052b 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * es.c
+ * es.c: Elementary stream output module
  *****************************************************************************
- * Copyright (C) 2001, 2002 VideoLAN
- * $Id: es.c,v 1.1 2003/04/13 20:00:21 fenrir Exp $
+ * Copyright (C) 2003-2004 the VideoLAN team
+ * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
-#include <string.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
-#include <vlc/sout.h>
+#include <vlc_input.h>
+#include <vlc_sout.h>
+#include <vlc_interface.h>
 
-#define FREE( p ) if( p ) { free( p ); (p) = NULL; }
 /*****************************************************************************
- * Exported prototypes
+ * Module descriptor
  *****************************************************************************/
+#define ACCESS_TEXT N_("Output access method")
+#define ACCESS_LONGTEXT N_( \
+    "This is the default output access method that will be used." )
+
+#define ACCESSA_TEXT N_("Audio output access method")
+#define ACCESSA_LONGTEXT N_( \
+    "This is the output access method that will be used for audio." )
+#define ACCESSV_TEXT N_("Video output access method")
+#define ACCESSV_LONGTEXT N_( \
+    "This is the output access method that will be used for video." )
+
+#define MUX_TEXT N_("Output muxer")
+#define MUX_LONGTEXT N_( \
+    "This is the default muxer method that will be used." )
+#define MUXA_TEXT N_("Audio output muxer")
+#define MUXA_LONGTEXT N_( \
+    "This is the muxer that will be used for audio." )
+#define MUXV_TEXT N_("Video output muxer")
+#define MUXV_LONGTEXT N_( \
+    "This is the muxer that will be used for video." )
+
+#define DEST_TEXT N_("Output URL")
+#define DEST_LONGTEXT N_( \
+    "This is the default output URI." )
+#define DESTA_TEXT N_("Audio output URL")
+#define DESTA_LONGTEXT N_( \
+    "This is the output URI that will be used for audio." )
+#define DESTV_TEXT N_("Video output URL")
+#define DESTV_LONGTEXT N_( \
+    "This is the output URI that will be used for video." )
+
 static int      Open    ( vlc_object_t * );
 static void     Close   ( vlc_object_t * );
 
-static sout_stream_id_t *Add ( sout_stream_t *, sout_format_t * );
-static int               Del ( sout_stream_t *, sout_stream_id_t * );
-static int               Send( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
+#define SOUT_CFG_PREFIX "sout-es-"
 
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
 vlc_module_begin();
-    set_description( _("ES stream") );
+    set_shortname( "ES" );
+    set_description( _("Elementary stream output") );
     set_capability( "sout stream", 50 );
     add_shortcut( "es" );
-    add_shortcut( "es" );
+    set_category( CAT_SOUT );
+    set_subcategory( SUBCAT_SOUT_STREAM );
+
+    add_string( SOUT_CFG_PREFIX "access", "", NULL, ACCESS_TEXT,
+                ACCESS_LONGTEXT, VLC_TRUE );
+    add_string( SOUT_CFG_PREFIX "access-audio", "", NULL, ACCESSA_TEXT,
+                ACCESSA_LONGTEXT, VLC_TRUE );
+    add_string( SOUT_CFG_PREFIX "access-video", "", NULL, ACCESSV_TEXT,
+                ACCESSV_LONGTEXT, VLC_TRUE );
+
+    add_string( SOUT_CFG_PREFIX "mux", "", NULL, MUX_TEXT,
+                MUX_LONGTEXT, VLC_TRUE );
+    add_string( SOUT_CFG_PREFIX "mux-audio", "", NULL, MUXA_TEXT,
+                MUXA_LONGTEXT, VLC_TRUE );
+    add_string( SOUT_CFG_PREFIX "mux-video", "", NULL, MUXV_TEXT,
+                MUXV_LONGTEXT, VLC_TRUE );
+
+    add_string( SOUT_CFG_PREFIX "dst", "", NULL, DEST_TEXT,
+                DEST_LONGTEXT, VLC_TRUE );
+        change_unsafe();
+    add_string( SOUT_CFG_PREFIX "dst-audio", "", NULL, DESTA_TEXT,
+                DESTA_LONGTEXT, VLC_TRUE );
+        change_unsafe();
+    add_string( SOUT_CFG_PREFIX "dst-video", "", NULL, DESTV_TEXT,
+                DESTV_LONGTEXT, VLC_TRUE );
+        change_unsafe();
+
     set_callbacks( Open, Close );
 vlc_module_end();
 
+/*****************************************************************************
+ * Exported prototypes
+ *****************************************************************************/
+static const char *ppsz_sout_options[] = {
+    "access", "access-audio", "access-video",
+    "mux", "mux-audio", "mux-video",
+    "dst", "dst-audio", "dst-video",
+    NULL
+};
+
+static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
+static int               Del ( sout_stream_t *, sout_stream_id_t * );
+static int               Send( sout_stream_t *, sout_stream_id_t *, block_t* );
+
 struct sout_stream_sys_t
 {
     int  i_count_audio;
@@ -67,9 +136,9 @@ struct sout_stream_sys_t
     char *psz_access_audio;
     char *psz_access_video;
 
-    char *psz_url;
-    char *psz_url_audio;
-    char *psz_url_video;
+    char *psz_dst;
+    char *psz_dst_audio;
+    char *psz_dst_video;
 };
 
 /*****************************************************************************
@@ -79,27 +148,35 @@ static int Open( vlc_object_t *p_this )
 {
     sout_stream_t       *p_stream = (sout_stream_t*)p_this;
     sout_stream_sys_t   *p_sys;
+    vlc_value_t         val;
 
-    //p_sout->i_preheader = __MAX( p_sout->i_preheader, p_mux->i_preheader );
-
+    config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options, p_stream->p_cfg );
     p_sys                   = malloc( sizeof( sout_stream_sys_t ) );
 
     p_sys->i_count          = 0;
     p_sys->i_count_audio    = 0;
     p_sys->i_count_video    = 0;
 
-    p_sys->psz_access       = sout_cfg_find_value( p_stream->p_cfg, "access" );
-    p_sys->psz_access_audio = sout_cfg_find_value( p_stream->p_cfg, "acesss_audio" );
-    p_sys->psz_access_video = sout_cfg_find_value( p_stream->p_cfg, "access_video" );
-
-
-    p_sys->psz_mux          = sout_cfg_find_value( p_stream->p_cfg, "mux" );
-    p_sys->psz_mux_audio    = sout_cfg_find_value( p_stream->p_cfg, "mux_audio" );
-    p_sys->psz_mux_video    = sout_cfg_find_value( p_stream->p_cfg, "mux_video" );
-
-    p_sys->psz_url         = sout_cfg_find_value( p_stream->p_cfg, "url" );
-    p_sys->psz_url_audio   = sout_cfg_find_value( p_stream->p_cfg, "url_audio" );
-    p_sys->psz_url_video   = sout_cfg_find_value( p_stream->p_cfg, "url_video" );
+    var_Get( p_stream, SOUT_CFG_PREFIX "access", &val );
+    p_sys->psz_access       = val.psz_string;
+    var_Get( p_stream, SOUT_CFG_PREFIX "access-audio", &val );
+    p_sys->psz_access_audio = val.psz_string;
+    var_Get( p_stream, SOUT_CFG_PREFIX "access-video", &val );
+    p_sys->psz_access_video = val.psz_string;
+
+    var_Get( p_stream, SOUT_CFG_PREFIX "mux", &val );
+    p_sys->psz_mux       = val.psz_string;
+    var_Get( p_stream, SOUT_CFG_PREFIX "mux-audio", &val );
+    p_sys->psz_mux_audio = val.psz_string;
+    var_Get( p_stream, SOUT_CFG_PREFIX "mux-video", &val );
+    p_sys->psz_mux_video = val.psz_string;
+
+    var_Get( p_stream, SOUT_CFG_PREFIX "dst", &val );
+    p_sys->psz_dst       = val.psz_string;
+    var_Get( p_stream, SOUT_CFG_PREFIX "dst-audio", &val );
+    p_sys->psz_dst_audio = val.psz_string;
+    var_Get( p_stream, SOUT_CFG_PREFIX "dst-video", &val );
+    p_sys->psz_dst_video = val.psz_string;
 
     p_stream->pf_add    = Add;
     p_stream->pf_del    = Del;
@@ -119,6 +196,18 @@ static void Close( vlc_object_t * p_this )
     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
     sout_stream_sys_t *p_sys = p_stream->p_sys;
 
+    free( p_sys->psz_access );
+    free( p_sys->psz_access_audio );
+    free( p_sys->psz_access_video );
+
+    free( p_sys->psz_mux );
+    free( p_sys->psz_mux_audio );
+    free( p_sys->psz_mux_video );
+
+    free( p_sys->psz_dst );
+    free( p_sys->psz_dst_audio );
+    free( p_sys->psz_dst_video );
+
     free( p_sys );
 }
 
@@ -128,16 +217,17 @@ struct sout_stream_id_t
     sout_mux_t   *p_mux;
 };
 
-static char * es_print_url( char *psz_fmt, vlc_fourcc_t i_fourcc, int i_count, char *psz_access, char *psz_mux )
+static char * es_print_url( char *psz_fmt, vlc_fourcc_t i_fourcc, int i_count,
+                            char *psz_access, char *psz_mux )
 {
-    char *psz_url, *p;
+    char *psz_dst, *p;
 
     if( psz_fmt == NULL || !*psz_fmt )
     {
         psz_fmt = "stream-%n-%c.%m";
     }
 
-    p = psz_url = malloc( 4096 );
+    p = psz_dst = malloc( 4096 );
     memset( p, 0, 4096 );
     for( ;; )
     {
@@ -183,10 +273,10 @@ static char * es_print_url( char *psz_fmt, vlc_fourcc_t i_fourcc, int i_count, c
         }
     }
 
-    return( psz_url );
+    return( psz_dst );
 }
 
-static sout_stream_id_t * Add      ( sout_stream_t *p_stream, sout_format_t *p_fmt )
+static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
     sout_instance_t   *p_sout = p_stream->p_sout;
@@ -194,17 +284,17 @@ static sout_stream_id_t * Add      ( sout_stream_t *p_stream, sout_format_t *p_f
 
     char              *psz_access;
     char              *psz_mux;
-    char              *psz_url;
+    char              *psz_dst;
 
     sout_access_out_t *p_access;
     sout_mux_t        *p_mux;
 
     /* *** get access name *** */
-    if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_access_audio )
+    if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_access_audio && *p_sys->psz_access_audio )
     {
         psz_access = p_sys->psz_access_audio;
     }
-    else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_access_video )
+    else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_access_video && *p_sys->psz_access_video )
     {
         psz_access = p_sys->psz_access_video;
     }
@@ -214,11 +304,11 @@ static sout_stream_id_t * Add      ( sout_stream_t *p_stream, sout_format_t *p_f
     }
 
     /* *** get mux name *** */
-    if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_mux_audio )
+    if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_mux_audio && *p_sys->psz_mux_audio )
     {
         psz_mux = p_sys->psz_mux_audio;
     }
-    else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_mux_video )
+    else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_mux_video && *p_sys->psz_mux_video )
     {
         psz_mux = p_sys->psz_mux_video;
     }
@@ -227,14 +317,16 @@ static sout_stream_id_t * Add      ( sout_stream_t *p_stream, sout_format_t *p_f
         psz_mux = p_sys->psz_mux;
     }
 
-    /* *** get url (%d expanded as a codec count, %c expanded as codec fcc ) *** */
-    if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_url_audio )
+    /* Get url (%d expanded as a codec count, %c expanded as codec fcc ) */
+    if( p_fmt->i_cat == AUDIO_ES && p_sys->psz_dst_audio && *p_sys->psz_dst_audio )
     {
-        psz_url = es_print_url( p_sys->psz_url_audio, p_fmt->i_fourcc, p_sys->i_count_audio, psz_access, psz_mux );
+        psz_dst = es_print_url( p_sys->psz_dst_audio, p_fmt->i_codec,
+                                p_sys->i_count_audio, psz_access, psz_mux );
     }
-    else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_url_video )
+    else if( p_fmt->i_cat == VIDEO_ES && p_sys->psz_dst_video && *p_sys->psz_dst_video )
     {
-        psz_url = es_print_url( p_sys->psz_url_video, p_fmt->i_fourcc, p_sys->i_count_video, psz_access, psz_mux );
+        psz_dst = es_print_url( p_sys->psz_dst_video, p_fmt->i_codec,
+                                p_sys->i_count_video, psz_access, psz_mux );
     }
     else
     {
@@ -252,7 +344,8 @@ static sout_stream_id_t * Add      ( sout_stream_t *p_stream, sout_format_t *p_f
             i_count = p_sys->i_count;
         }
 
-        psz_url = es_print_url( p_sys->psz_url, p_fmt->i_fourcc, i_count, psz_access, psz_mux );
+        psz_dst = es_print_url( p_sys->psz_dst, p_fmt->i_codec,
+                                i_count, psz_access, psz_mux );
     }
 
     p_sys->i_count++;
@@ -265,14 +358,19 @@ static sout_stream_id_t * Add      ( sout_stream_t *p_stream, sout_format_t *p_f
         p_sys->i_count_audio++;
     }
     msg_Dbg( p_stream, "creating `%s/%s://%s'",
-             psz_access, psz_mux, psz_url );
+             psz_access, psz_mux, psz_dst );
 
     /* *** find and open appropriate access module *** */
-    p_access = sout_AccessOutNew( p_sout, psz_access, psz_url );
+    p_access = sout_AccessOutNew( p_sout, psz_access, psz_dst );
     if( p_access == NULL )
     {
         msg_Err( p_stream, "no suitable sout access module for `%s/%s://%s'",
-                 psz_access, psz_mux, psz_url );
+                 psz_access, psz_mux, psz_dst );
+        intf_UserFatal( p_stream, VLC_FALSE,
+                    _("Streaming / Transcoding failed"),
+                    _("There is no suitable stream-output access module for \"%s/%s://%s\"."),
+                          psz_access,
+                          psz_mux, psz_dst );
         return( NULL );
     }
 
@@ -281,14 +379,16 @@ static sout_stream_id_t * Add      ( sout_stream_t *p_stream, sout_format_t *p_f
     if( p_mux == NULL )
     {
         msg_Err( p_stream, "no suitable sout mux module for `%s/%s://%s'",
-                 psz_access, psz_mux, psz_url );
+                 psz_access, psz_mux, psz_dst );
+        intf_UserFatal( p_stream, VLC_FALSE,
+                        _("Streaming / Transcoding failed"),
+                        _("There is no suitable stream-output access module "\
+                          "for \"%s/%s://%s\"."),
+                          psz_access, psz_mux, psz_dst );
         sout_AccessOutDelete( p_access );
         return( NULL );
     }
 
-    /* XXX beurk */
-    p_sout->i_preheader = __MAX( p_sout->i_preheader, p_mux->i_preheader );
-
     id = malloc( sizeof( sout_stream_id_t ) );
     id->p_mux = p_mux;
     id->p_input = sout_MuxAddStream( p_mux, p_fmt );
@@ -306,10 +406,10 @@ static sout_stream_id_t * Add      ( sout_stream_t *p_stream, sout_format_t *p_f
     return id;
 }
 
-static int     Del      ( sout_stream_t *p_stream, sout_stream_id_t *id )
+static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
 {
     sout_access_out_t *p_access = id->p_mux->p_access;
-
+    sout_MuxDelete( id->p_mux );
     sout_MuxDeleteStream( id->p_mux, id->p_input );
     sout_AccessOutDelete( p_access );
 
@@ -317,7 +417,8 @@ static int     Del      ( sout_stream_t *p_stream, sout_stream_id_t *id )
     return VLC_SUCCESS;
 }
 
-static int     Send     ( sout_stream_t *p_stream, sout_stream_id_t *id, sout_buffer_t *p_buffer )
+static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
+                 block_t *p_buffer )
 {
     sout_MuxSendBuffer( id->p_mux, id->p_input, p_buffer );