1 /*****************************************************************************
2 * demuxdump.c : Pseudo demux module for vlc (dump raw stream)
3 *****************************************************************************
4 * Copyright (C) 2001-2004 VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <string.h> /* strdup() */
32 #include <vlc/input.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 #define FILE_TEXT N_("Filename of dump")
38 #define FILE_LONGTEXT N_( \
39 "Specify a file name to which the raw stream will be dumped." )
41 static int Open( vlc_object_t * );
42 static void Close ( vlc_object_t * );
45 set_description( _("Filedump demuxer") );
46 set_capability( "demux2", 0 );
47 add_file( "demuxdump-file", "stream-demux.dump", NULL, FILE_TEXT,
48 FILE_LONGTEXT, VLC_FALSE );
49 set_callbacks( Open, Close );
50 add_shortcut( "dump" );
54 /*****************************************************************************
56 *****************************************************************************/
57 static int Demux( demux_t * );
58 static int Control( demux_t *, int,va_list );
60 #define DUMP_BLOCKSIZE 16384
68 uint8_t buffer[DUMP_BLOCKSIZE];
72 * Data reading functions
75 /*****************************************************************************
76 * Open: initializes dump structures
77 *****************************************************************************/
78 static int Open( vlc_object_t * p_this )
80 demux_t *p_demux = (demux_t*)p_this;
83 /* Accept only if forced */
84 if( strcasecmp( p_demux->psz_demux, "dump" ) )
87 p_demux->pf_demux = Demux;
88 p_demux->pf_control = Control;
89 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
92 p_sys->psz_file = var_CreateGetString( p_demux, "demuxdump-file" );
93 if( *p_sys->psz_file == '\0' )
95 msg_Warn( p_demux, "no dump file name given" );
99 if( !strcmp( p_sys->psz_file, "-" ) )
101 msg_Info( p_demux, "dumping raw stream to standard output" );
102 p_sys->p_file = stdout;
104 else if( ( p_sys->p_file = fopen( p_sys->psz_file, "wb" ) ) == NULL )
106 msg_Err( p_demux,"cannot create `%s' for writing", p_sys->psz_file );
111 msg_Info( p_demux, "dumping raw stream to file `%s'", p_sys->psz_file );
116 /*****************************************************************************
118 *****************************************************************************/
119 static void Close( vlc_object_t *p_this )
122 demux_t *p_demux = (demux_t*)p_this;
123 demux_sys_t *p_sys = p_demux->p_sys;
125 msg_Info( p_demux ,"closing %s ("I64Fd" Kbytes dumped)", p_sys->psz_file,
126 p_sys->i_write / 1024 );
128 if( p_sys->p_file != stdout )
130 fclose( p_sys->p_file );
132 free( p_sys->psz_file );
137 /*****************************************************************************
138 * Demux: reads and demuxes data packets
139 *****************************************************************************
140 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
141 *****************************************************************************/
142 static int Demux( demux_t *p_demux )
144 demux_sys_t *p_sys = p_demux->p_sys;
148 /* I'm pretty sure that stream_Peek,stream_Read( , NULL ) would be faster*/
149 i_data = stream_Read( p_demux->s, p_sys->buffer, DUMP_BLOCKSIZE );
153 i_data = fwrite( p_sys->buffer, 1, i_data, p_sys->p_file );
157 msg_Err( p_demux, "failed to write data" );
160 msg_Dbg( p_demux, "dumped %d bytes", i_data );
162 p_sys->i_write += i_data;
167 /*****************************************************************************
168 * Demux: reads and demuxes data packets
169 *****************************************************************************/
170 static int Control( demux_t *p_demux, int i_query, va_list args )
172 return demux2_vaControlHelper( p_demux->s, 0, -1, 0, 1, i_query, args );