]> git.sesse.net Git - vlc/blobdiff - modules/demux/demuxdump.c
PDA Interface:
[vlc] / modules / demux / demuxdump.c
index 7dae59cae2155724eb6ea3771bf598d0f5d5b820..ccf25bd85d65e80693dfad2dcee2829f2709f5b2 100644 (file)
@@ -2,7 +2,7 @@
  * demuxdump.c : Pseudo demux module for vlc (dump raw stream)
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: demuxdump.c,v 1.3 2003/01/25 16:58:34 fenrir Exp $
+ * $Id: demuxdump.c,v 1.11 2003/11/05 17:57:29 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -45,13 +45,16 @@ static void Desactivate ( vlc_object_t * );
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
+#define FILE_TEXT N_("Dump file name")
+#define FILE_LONGTEXT N_( \
+    "Specify a file name to which the raw stream will be dumped." )
+
 vlc_module_begin();
-    set_description( _("Dump Demux input") );
+    set_description( _("file dump demuxer") );
     set_capability( "demux", 0 );
-    add_category_hint( "File", NULL );
-        add_string( "demuxdump-file", NULL, NULL, 
-                    "dump file name", 
-                    "file name for dumping raw stream read by demux" );
+    add_category_hint( "File", NULL, VLC_FALSE );
+        add_file( "demuxdump-file", "stream-demux.dump", NULL, FILE_TEXT, 
+                  FILE_LONGTEXT, VLC_FALSE );
     set_callbacks( Activate, Desactivate );
     add_shortcut( "dump" );
 vlc_module_end();
@@ -76,11 +79,12 @@ static int Activate( vlc_object_t * p_this )
 {
     input_thread_t      *p_input = (input_thread_t *)p_this;
     demux_sys_t         *p_demux;
-
+    vlc_value_t         val;
     char                *psz_name;
 
     /* Set the demux function */
     p_input->pf_demux = Demux;
+    p_input->pf_demux_control = demux_vaControlDefault;
 
     /* Initialize access plug-in structures. */
     if( p_input->i_mtu == 0 )
@@ -89,22 +93,32 @@ static int Activate( vlc_object_t * p_this )
         p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
     }
     
-    psz_name = config_GetPsz( p_input, "demuxdump-file" );
+    var_Create( p_input, "demuxdump-file", VLC_VAR_FILE|VLC_VAR_DOINHERIT );
+    var_Get( p_input, "demuxdump-file", &val );
+    psz_name = val.psz_string;
     if( !psz_name || !*psz_name )
     {
-        psz_name = strdup( "stream-demux.dump" );
+        msg_Warn( p_input, "no dump file name given" );
+        return VLC_EGENERIC;
     }
 
     p_demux = malloc( sizeof( demux_sys_t ) );
     memset( p_demux, 0, sizeof( demux_sys_t ) );
 
-    if( !( p_demux->p_file = fopen( psz_name, "wb" ) ) )
+    if( !strcmp( psz_name, "-" ) )
+    {
+        msg_Info( p_input,
+                  "dumping raw stream to standard output" );
+        p_demux->p_file = stdout;
+        p_demux->psz_name = psz_name;
+    }
+    else if( !( p_demux->p_file = fopen( psz_name, "wb" ) ) )
     {
         msg_Err( p_input,
                  "cannot create `%s' for writing", 
                  psz_name );
         free( p_demux );
-        return( -1 );
+        return VLC_EGENERIC;
     }
     else
     {
@@ -127,9 +141,10 @@ static int Activate( vlc_object_t * p_this )
 
         if( input_InitStream( p_input, 0 ) == -1 )
         {
-            fclose( p_demux->p_file );
+            if( p_demux->p_file != stdout )
+                fclose( p_demux->p_file );
             free( p_demux );
-            return( -1 );
+            return VLC_EGENERIC;
         }
         input_AddProgram( p_input, 0, 0 );
         p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
@@ -145,7 +160,7 @@ static int Activate( vlc_object_t * p_this )
     p_input->stream.p_selected_program->b_is_ok = 1;
     vlc_mutex_unlock( &p_input->stream.stream_lock );
     
-    return( 0 );
+    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -163,7 +178,8 @@ static void Desactivate ( vlc_object_t *p_this )
 
     if( p_demux->p_file )
     {
-        fclose( p_demux->p_file );
+        if( p_demux->p_file != stdout )
+            fclose( p_demux->p_file );
         p_demux->p_file = NULL;
     }
     if( p_demux->psz_name )
@@ -230,4 +246,3 @@ static int Demux( input_thread_t * p_input )
 
     return( 1 );
 }
-