]> git.sesse.net Git - vlc/blobdiff - modules/demux/demuxdump.c
A bit of headers cleanup
[vlc] / modules / demux / demuxdump.c
index b4baa440e0dd1659a87607ab6f2de63db7a121c9..bd46e9511471677567830320a9d3c15eae5a76d1 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * demuxdump.c : Pseudo demux module for vlc (dump raw stream)
  *****************************************************************************
- * Copyright (C) 2001-2004 VideoLAN
+ * Copyright (C) 2001-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
@@ -18,7 +18,7 @@
  *
  * 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.
  *****************************************************************************/
 
 /*****************************************************************************
 #include <errno.h>
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
+#include <vlc_demux.h>
+#include <vlc_charset.h>
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-#define FILE_TEXT N_("Filename of dump")
+#define FILE_TEXT N_("Dump filename")
 #define FILE_LONGTEXT N_( \
-    "Specify a file name to which the raw stream will be dumped." )
+    "Name of the file to which the raw stream will be dumped." )
+#define APPEND_TEXT N_("Append to existing file")
+#define APPEND_LONGTEXT N_( \
+    "If the file already exists, it will not be overwritten." )
 
 static int  Open( vlc_object_t * );
 static void Close ( vlc_object_t * );
 
 vlc_module_begin();
-    set_description( _("Filedump demuxer") );
+    set_shortname("Dump");
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_DEMUX );
+    set_description( _("File dumpper") );
     set_capability( "demux2", 0 );
     add_file( "demuxdump-file", "stream-demux.dump", NULL, FILE_TEXT,
               FILE_LONGTEXT, VLC_FALSE );
+    add_bool( "demuxdump-append", 0, NULL, APPEND_TEXT, APPEND_LONGTEXT,
+              VLC_FALSE );
     set_callbacks( Open, Close );
     add_shortcut( "dump" );
 vlc_module_end();
@@ -79,11 +88,22 @@ static int Open( vlc_object_t * p_this )
 {
     demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys;
+    const char  *psz_mode;
+    vlc_value_t val;
+    vlc_bool_t  b_append;
 
     /* Accept only if forced */
     if( strcasecmp( p_demux->psz_demux, "dump" ) )
         return VLC_EGENERIC;
 
+    var_Create( p_demux, "demuxdump-append", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "demuxdump-append", &val );
+    b_append = val.b_bool;
+    if ( b_append )
+        psz_mode = "ab";
+    else
+        psz_mode = "wb";
+
     p_demux->pf_demux = Demux;
     p_demux->pf_control = Control;
     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
@@ -101,14 +121,15 @@ static int Open( vlc_object_t * p_this )
         msg_Info( p_demux, "dumping raw stream to standard output" );
         p_sys->p_file = stdout;
     }
-    else if( ( p_sys->p_file = fopen( p_sys->psz_file, "wb" ) ) == NULL )
+    else if( ( p_sys->p_file = utf8_fopen( p_sys->psz_file, psz_mode ) ) == NULL )
     {
-        msg_Err( p_demux,"cannot create `%s' for writing", p_sys->psz_file );
+        msg_Err( p_demux, "cannot create `%s' for writing", p_sys->psz_file );
 
         free( p_sys );
         return VLC_EGENERIC;
     }
-    msg_Info( p_demux, "dumping raw stream to file `%s'", p_sys->psz_file );
+    msg_Info( p_demux, "%s raw stream to file `%s'",
+              b_append ? "appending" : "dumping", p_sys->psz_file );
 
     return VLC_SUCCESS;
 }
@@ -152,12 +173,14 @@ static int Demux( demux_t *p_demux )
 
     i_data = fwrite( p_sys->buffer, 1, i_data, p_sys->p_file );
 
-    if( i_data < 0 )
+    if( i_data == 0 )
     {
         msg_Err( p_demux, "failed to write data" );
         return -1;
     }
+#if 0
     msg_Dbg( p_demux, "dumped %d bytes", i_data );
+#endif
 
     p_sys->i_write += i_data;