X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Fdemuxdump.c;h=2a642929978885abb6d00e8544a6c0d011d968ed;hb=33778d4d8c5d4b53793bdfe699315dac4e5baf68;hp=9a108c80067d826cf93c18d3bc58210193ed8b95;hpb=a90a19a6b0468ea9fedadc27cfc1118d70295263;p=vlc diff --git a/modules/demux/demuxdump.c b/modules/demux/demuxdump.c index 9a108c8006..2a64292997 100644 --- a/modules/demux/demuxdump.c +++ b/modules/demux/demuxdump.c @@ -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 @@ -18,45 +18,48 @@ * * 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 /* malloc(), free() */ -#include /* strdup() */ -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include /***************************************************************************** * 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." ) -#define APPEND_TEXT N_("Append") + "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 exists and this option is selected, the existing file " \ - "will not be overwritten." ) + "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_category( CAT_INPUT ); - set_subcategory( SUBCAT_INPUT_DEMUX ); - set_description( _("Filedump demuxer") ); - set_capability( "demux2", 0 ); +vlc_module_begin () + set_shortname("Dump") + set_category( CAT_INPUT ) + set_subcategory( SUBCAT_INPUT_DEMUX ) + set_description( N_("File dumper") ) + set_capability( "demux", 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(); + FILE_LONGTEXT, false ) + add_bool( "demuxdump-append", false, NULL, APPEND_TEXT, APPEND_LONGTEXT, + false ) + set_callbacks( Open, Close ) + add_shortcut( "dump" ) +vlc_module_end () /***************************************************************************** @@ -87,17 +90,18 @@ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; - char *psz_mode; - vlc_value_t val; - vlc_bool_t b_append; + const char *psz_mode; + bool b_append; /* Accept only if forced */ - if( strcasecmp( p_demux->psz_demux, "dump" ) ) + if( !p_demux->b_force ) 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; + p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); + if( !p_sys ) + return VLC_ENOMEM; + + b_append = var_CreateGetBool( p_demux, "demuxdump-append" ); if ( b_append ) psz_mode = "ab"; else @@ -105,13 +109,15 @@ static int Open( vlc_object_t * p_this ) p_demux->pf_demux = Demux; p_demux->pf_control = Control; - p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); + p_sys->i_write = 0; p_sys->p_file = NULL; p_sys->psz_file = var_CreateGetString( p_demux, "demuxdump-file" ); if( *p_sys->psz_file == '\0' ) { msg_Warn( p_demux, "no dump file name given" ); + free( p_sys->psz_file ); + free( p_sys ); return VLC_EGENERIC; } @@ -120,10 +126,10 @@ 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, psz_mode ) ) == NULL ) + else if( ( p_sys->p_file = vlc_fopen( p_sys->psz_file, psz_mode ) ) == NULL ) { msg_Err( p_demux, "cannot create `%s' for writing", p_sys->psz_file ); - + free( p_sys->psz_file ); free( p_sys ); return VLC_EGENERIC; } @@ -142,7 +148,7 @@ static void Close( vlc_object_t *p_this ) demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys = p_demux->p_sys; - msg_Info( p_demux ,"closing %s ("I64Fd" Kbytes dumped)", p_sys->psz_file, + msg_Info( p_demux ,"closing %s (%"PRId64" KiB dumped)", p_sys->psz_file, p_sys->i_write / 1024 ); if( p_sys->p_file != stdout ) @@ -150,7 +156,6 @@ static void Close( vlc_object_t *p_this ) fclose( p_sys->p_file ); } free( p_sys->psz_file ); - free( p_sys ); } @@ -165,14 +170,13 @@ static int Demux( demux_t *p_demux ) int i_data; - /* I'm pretty sure that stream_Peek,stream_Read( , NULL ) would be faster*/ i_data = stream_Read( p_demux->s, p_sys->buffer, DUMP_BLOCKSIZE ); if ( i_data <= 0 ) return i_data; 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; @@ -191,6 +195,6 @@ static int Demux( demux_t *p_demux ) *****************************************************************************/ static int Control( demux_t *p_demux, int i_query, va_list args ) { - return demux2_vaControlHelper( p_demux->s, 0, -1, 0, 1, i_query, args ); + return demux_vaControlHelper( p_demux->s, 0, -1, 0, 1, i_query, args ); }