X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Fdemuxdump.c;h=2a642929978885abb6d00e8544a6c0d011d968ed;hb=e2eccee759772d903d7fb1fed398fb354d45b676;hp=c759a8698a71f9050b1359a91d92417a320d550d;hpb=091aff73545a19bdb1c1706acecfc86e326e2734;p=vlc diff --git a/modules/demux/demuxdump.c b/modules/demux/demuxdump.c index c759a8698a..2a64292997 100644 --- a/modules/demux/demuxdump.c +++ b/modules/demux/demuxdump.c @@ -1,8 +1,8 @@ /***************************************************************************** * demuxdump.c : Pseudo demux module for vlc (dump raw stream) ***************************************************************************** - * Copyright (C) 2001 VideoLAN - * $Id: demuxdump.c,v 1.10 2003/09/07 22:48:29 fenrir Exp $ + * Copyright (C) 2001-2004 the VideoLAN team + * $Id$ * * Authors: Laurent Aimar * @@ -10,7 +10,7 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -18,54 +18,65 @@ * * 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 +#include /***************************************************************************** - * Local prototypes + * Module descriptor *****************************************************************************/ -static int Activate ( vlc_object_t * ); -static int Demux ( input_thread_t * ); -static void Desactivate ( vlc_object_t * ); +#define FILE_TEXT N_("Dump filename") +#define FILE_LONGTEXT N_( \ + "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_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, false ) + add_bool( "demuxdump-append", false, NULL, APPEND_TEXT, APPEND_LONGTEXT, + false ) + set_callbacks( Open, Close ) + add_shortcut( "dump" ) +vlc_module_end () -#define DUMP_BLOCKSIZE 16384 /***************************************************************************** - * Module descriptor + * Local prototypes *****************************************************************************/ -#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( _("file dump demuxer") ); - set_capability( "demux", 0 ); - 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(); +static int Demux( demux_t * ); +static int Control( demux_t *, int,va_list ); + +#define DUMP_BLOCKSIZE 16384 struct demux_sys_t { - char *psz_name; + char *psz_file; FILE *p_file; uint64_t i_write; - void *p_demux_data_sav; + uint8_t buffer[DUMP_BLOCKSIZE]; }; /* @@ -73,119 +84,79 @@ struct demux_sys_t */ /***************************************************************************** - * Activate: initializes dump structures + * Open: initializes dump structures *****************************************************************************/ -static int Activate( vlc_object_t * p_this ) +static int Open( vlc_object_t * p_this ) { - input_thread_t *p_input = (input_thread_t *)p_this; - demux_sys_t *p_demux; + demux_t *p_demux = (demux_t*)p_this; + demux_sys_t *p_sys; + const char *psz_mode; + bool b_append; - char *psz_name; + /* Accept only if forced */ + if( !p_demux->b_force ) + return VLC_EGENERIC; - /* Set the demux function */ - p_input->pf_demux = Demux; - p_input->pf_demux_control = demux_vaControlDefault; + p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); + if( !p_sys ) + return VLC_ENOMEM; - /* Initialize access plug-in structures. */ - if( p_input->i_mtu == 0 ) - { - /* Improve speed. */ - p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE; - } - - psz_name = config_GetPsz( p_input, "demuxdump-file" ); - if( !psz_name || !*psz_name ) - { - msg_Warn( p_input, "no dump file name given" ); - return VLC_EGENERIC; - } + b_append = var_CreateGetBool( p_demux, "demuxdump-append" ); + if ( b_append ) + psz_mode = "ab"; + else + psz_mode = "wb"; - p_demux = malloc( sizeof( demux_sys_t ) ); - memset( p_demux, 0, sizeof( demux_sys_t ) ); + p_demux->pf_demux = Demux; + p_demux->pf_control = Control; - if( !strcmp( psz_name, "-" ) ) + 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_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 ); + msg_Warn( p_demux, "no dump file name given" ); + free( p_sys->psz_file ); + free( p_sys ); return VLC_EGENERIC; } - else - { - msg_Info( p_input, - "dumping raw stream to file `%s'", - psz_name ); - p_demux->psz_name = psz_name; - } - p_demux->i_write = 0; - p_demux->p_demux_data_sav = p_input->p_demux_data; - - if( p_input->stream.p_selected_program != NULL ) + if( !strcmp( p_sys->psz_file, "-" ) ) { - /* workaround for dvd access */ - msg_Warn( p_input, "demux data already initializated (by access?)" ); + msg_Info( p_demux, "dumping raw stream to standard output" ); + p_sys->p_file = stdout; } - else + else if( ( p_sys->p_file = vlc_fopen( p_sys->psz_file, psz_mode ) ) == NULL ) { - - if( input_InitStream( p_input, 0 ) == -1 ) - { - if( p_demux->p_file != stdout ) - fclose( p_demux->p_file ); - free( p_demux ); - return VLC_EGENERIC; - } - input_AddProgram( p_input, 0, 0 ); - p_input->stream.p_selected_program = p_input->stream.pp_programs[0]; - - vlc_mutex_lock( &p_input->stream.stream_lock ); - p_input->stream.p_selected_area->i_tell = 0; - vlc_mutex_unlock( &p_input->stream.stream_lock ); + msg_Err( p_demux, "cannot create `%s' for writing", p_sys->psz_file ); + free( p_sys->psz_file ); + free( p_sys ); + return VLC_EGENERIC; } + msg_Info( p_demux, "%s raw stream to file `%s'", + b_append ? "appending" : "dumping", p_sys->psz_file ); - p_input->p_demux_data = p_demux; - - vlc_mutex_lock( &p_input->stream.stream_lock ); - p_input->stream.p_selected_program->b_is_ok = 1; - vlc_mutex_unlock( &p_input->stream.stream_lock ); - return VLC_SUCCESS; } /***************************************************************************** - * Desctivate: initializes dump structures + * Close: *****************************************************************************/ -static void Desactivate ( vlc_object_t *p_this ) +static void Close( vlc_object_t *p_this ) { - input_thread_t *p_input = (input_thread_t *)p_this; - demux_sys_t *p_demux = (demux_sys_t*)p_input->p_demux_data; - msg_Info( p_input, - "closing %s ("I64Fd" Kbytes dumped)", - p_demux->psz_name, - p_demux->i_write / 1024 ); + demux_t *p_demux = (demux_t*)p_this; + demux_sys_t *p_sys = p_demux->p_sys; - if( 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 ) + msg_Info( p_demux ,"closing %s (%"PRId64" KiB dumped)", p_sys->psz_file, + p_sys->i_write / 1024 ); + + if( p_sys->p_file != stdout ) { - free( p_demux->psz_name ); + fclose( p_sys->p_file ); } - p_input->p_demux_data = p_demux->p_demux_data_sav; - free( p_demux ); + free( p_sys->psz_file ); + free( p_sys ); } /***************************************************************************** @@ -193,54 +164,37 @@ static void Desactivate ( vlc_object_t *p_this ) ***************************************************************************** * Returns -1 in case of error, 0 in case of EOF, 1 otherwise *****************************************************************************/ -static int Demux( input_thread_t * p_input ) +static int Demux( demux_t *p_demux ) { - demux_sys_t *p_demux = (demux_sys_t*)p_input->p_demux_data; + demux_sys_t *p_sys = p_demux->p_sys; - ssize_t i_read; - data_packet_t * p_data; - int i_write; + int i_data; - p_input->p_demux_data = p_demux->p_demux_data_sav; - i_read = input_SplitBuffer( p_input, &p_data, DUMP_BLOCKSIZE ); - p_input->p_demux_data = p_demux; - - if ( i_read <= 0 ) - { - return i_read; - } + i_data = stream_Read( p_demux->s, p_sys->buffer, DUMP_BLOCKSIZE ); + if ( i_data <= 0 ) + return i_data; - i_write = fwrite( p_data->p_payload_start, - 1, - i_read, - p_demux->p_file ); - - input_DeletePacket( p_input->p_method_data, p_data ); + i_data = fwrite( p_sys->buffer, 1, i_data, p_sys->p_file ); - if( i_write < 0 ) + if( i_data == 0 ) { - msg_Err( p_input, - "failed to write %d bytes", - i_write ); - return( -1 ); - } - else - { - msg_Dbg( p_input, - "dumped %d bytes", - i_write ); - p_demux->i_write += i_write; + 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; - if( (p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT) - | (input_ClockManageControl( p_input, - p_input->stream.p_selected_program, - (mtime_t)0 ) == PAUSE_S) ) - { - msg_Warn( p_input, "synchro reinit" ); - p_input->stream.p_selected_program->i_synchro_state = SYNCHRO_OK; - } + return 1; +} - return( 1 ); +/***************************************************************************** + * Demux: reads and demuxes data packets + *****************************************************************************/ +static int Control( demux_t *p_demux, int i_query, va_list args ) +{ + return demux_vaControlHelper( p_demux->s, 0, -1, 0, 1, i_query, args ); } +