Changeset e4c110a0805532b60defd19ea23d0c2a47e626cd

Show
Ignore:
Timestamp:
28/06/04 23:36:17 (4 years ago)
Author:
Laurent Aimar <fenrir@videolan.org>
git-committer:
Laurent Aimar <fenrir@videolan.org> 1088458577 +0000
git-parent:

[d755649277131dd111667db2fb46bf41a375b6df]

git-author:
Laurent Aimar <fenrir@videolan.org> 1088458577 +0000
Message:
  • demuxdump: ported to demux2.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/demux/demuxdump.c

    rffdca9a re4c110a  
    22 * demuxdump.c : Pseudo demux module for vlc (dump raw stream) 
    33 ***************************************************************************** 
    4  * Copyright (C) 2001-2003 VideoLAN 
    5  * $Id: demuxdump.c,v 1.12 2004/01/25 20:05:28 hartman Exp
     4 * Copyright (C) 2001-2004 VideoLAN 
     5 * $Id
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    1111 * the Free Software Foundation; either version 2 of the License, or 
    1212 * (at your option) any later version. 
    13  *  
     13 * 
    1414 * This program is distributed in the hope that it will be useful, 
    1515 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     
    3232#include <vlc/input.h> 
    3333 
    34 #include <sys/types.h> 
    35  
    36 /***************************************************************************** 
    37  * Local prototypes 
    38  *****************************************************************************/ 
    39 static int  Activate ( vlc_object_t * ); 
    40 static int  Demux ( input_thread_t * ); 
    41 static void Deactivate ( vlc_object_t * ); 
    42  
    43 #define DUMP_BLOCKSIZE  16384 
    44  
    4534/***************************************************************************** 
    4635 * Module descriptor 
     
    5039    "Specify a file name to which the raw stream will be dumped." ) 
    5140 
     41static int  Open( vlc_object_t * ); 
     42static void Close ( vlc_object_t * ); 
     43 
    5244vlc_module_begin(); 
    5345    set_description( _("Filedump demuxer") ); 
    54     set_capability( "demux", 0 ); 
    55     add_file( "demuxdump-file", "stream-demux.dump", NULL, FILE_TEXT,  
     46    set_capability( "demux2", 0 ); 
     47    add_file( "demuxdump-file", "stream-demux.dump", NULL, FILE_TEXT, 
    5648              FILE_LONGTEXT, VLC_FALSE ); 
    57     set_callbacks( Activate, Deactivate ); 
     49    set_callbacks( Open, Close ); 
    5850    add_shortcut( "dump" ); 
    5951vlc_module_end(); 
    6052 
     53 
     54/***************************************************************************** 
     55 * Local prototypes 
     56 *****************************************************************************/ 
     57static int Demux( demux_t * ); 
     58static int Control( demux_t *, int,va_list ); 
     59 
     60#define DUMP_BLOCKSIZE  16384 
     61 
    6162struct demux_sys_t 
    6263{ 
    63     char        *psz_name; 
     64    char        *psz_file; 
    6465    FILE        *p_file; 
    6566    uint64_t    i_write; 
    6667 
    67     void        *p_demux_data_sav
     68    uint8_t     buffer[DUMP_BLOCKSIZE]
    6869}; 
    6970 
     
    7374 
    7475/***************************************************************************** 
    75  * Activate: initializes dump structures 
     76 * Open: initializes dump structures 
    7677 *****************************************************************************/ 
    77 static int Activate( vlc_object_t * p_this ) 
     78static int Open( vlc_object_t * p_this ) 
    7879{ 
    79     input_thread_t      *p_input = (input_thread_t *)p_this; 
    80     demux_sys_t         *p_demux; 
    81     vlc_value_t         val; 
    82     char                *psz_name; 
     80    demux_t     *p_demux = (demux_t*)p_this; 
     81    demux_sys_t *p_sys; 
    8382 
    84     /* Set the demux function */ 
    85     p_input->pf_demux = Demux; 
    86     p_input->pf_demux_control = demux_vaControlDefault
     83    /* Accept only if forced */ 
     84    if( strcasecmp( p_demux->psz_demux, "dump" ) ) 
     85        return VLC_EGENERIC
    8786 
    88     /* Initialize access plug-in structures. */ 
    89     if( p_input->i_mtu == 0 ) 
     87    p_demux->pf_demux = Demux; 
     88    p_demux->pf_control = Control; 
     89    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); 
     90    p_sys->i_write = 0; 
     91    p_sys->p_file = NULL; 
     92    p_sys->psz_file = var_CreateGetString( p_demux, "demuxdump-file" ); 
     93    if( *p_sys->psz_file == '\0' ) 
    9094    { 
    91         /* Improve speed. */ 
    92         p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE; 
    93     } 
    94      
    95     var_Create( p_input, "demuxdump-file", VLC_VAR_FILE|VLC_VAR_DOINHERIT ); 
    96     var_Get( p_input, "demuxdump-file", &val ); 
    97     psz_name = val.psz_string; 
    98     if( !psz_name || !*psz_name ) 
    99     { 
    100         msg_Warn( p_input, "no dump file name given" ); 
     95        msg_Warn( p_demux, "no dump file name given" ); 
    10196        return VLC_EGENERIC; 
    10297    } 
    10398 
    104     p_demux = malloc( sizeof( demux_sys_t ) ); 
    105     memset( p_demux, 0, sizeof( demux_sys_t ) ); 
     99    if( !strcmp( p_sys->psz_file, "-" ) ) 
     100    { 
     101        msg_Info( p_demux, "dumping raw stream to standard output" ); 
     102        p_sys->p_file = stdout; 
     103    } 
     104    else if( ( p_sys->p_file = fopen( p_sys->psz_file, "wb" ) ) == NULL ) 
     105    { 
     106        msg_Err( p_demux,"cannot create `%s' for writing", p_sys->psz_file ); 
    106107 
    107     if( !strcmp( psz_name, "-" ) ) 
    108     { 
    109         msg_Info( p_input, 
    110                   "dumping raw stream to standard output" ); 
    111         p_demux->p_file = stdout; 
    112         p_demux->psz_name = psz_name; 
    113     } 
    114     else if( !( p_demux->p_file = fopen( psz_name, "wb" ) ) ) 
    115     { 
    116         msg_Err( p_input, 
    117                  "cannot create `%s' for writing",  
    118                  psz_name ); 
    119         free( p_demux ); 
     108        free( p_sys ); 
    120109        return VLC_EGENERIC; 
    121110    } 
    122     else 
    123     { 
    124         msg_Info( p_input, 
    125                   "dumping raw stream to file `%s'",  
    126                   psz_name ); 
    127         p_demux->psz_name = psz_name; 
    128     } 
     111    msg_Info( p_demux, "dumping raw stream to file `%s'", p_sys->psz_file ); 
    129112 
    130     p_demux->i_write = 0; 
    131     p_demux->p_demux_data_sav = p_input->p_demux_data; 
    132  
    133     if( p_input->stream.p_selected_program != NULL ) 
    134     { 
    135         /* workaround for dvd access */ 
    136         msg_Warn( p_input, "demux data already initializated (by access?)" ); 
    137     } 
    138     else 
    139     { 
    140  
    141         if( input_InitStream( p_input, 0 ) == -1 ) 
    142         { 
    143             if( p_demux->p_file != stdout ) 
    144                 fclose( p_demux->p_file ); 
    145             free( p_demux ); 
    146             return VLC_EGENERIC; 
    147         } 
    148         input_AddProgram( p_input, 0, 0 ); 
    149         p_input->stream.p_selected_program = p_input->stream.pp_programs[0]; 
    150  
    151         vlc_mutex_lock( &p_input->stream.stream_lock ); 
    152         p_input->stream.p_selected_area->i_tell = 0; 
    153         vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    154     } 
    155  
    156     p_input->p_demux_data = p_demux; 
    157  
    158     vlc_mutex_lock( &p_input->stream.stream_lock ); 
    159     p_input->stream.p_selected_program->b_is_ok = 1; 
    160     vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    161      
    162113    return VLC_SUCCESS; 
    163114} 
    164115 
    165116/***************************************************************************** 
    166  * Deactivate: initializes dump structures 
     117 * Close: 
    167118 *****************************************************************************/ 
    168 static void Deactivate ( vlc_object_t *p_this ) 
     119static void Close( vlc_object_t *p_this ) 
    169120{ 
    170     input_thread_t      *p_input = (input_thread_t *)p_this; 
    171     demux_sys_t         *p_demux = (demux_sys_t*)p_input->p_demux_data; 
    172121 
    173     msg_Info( p_input, 
    174               "closing %s ("I64Fd" Kbytes dumped)", 
    175               p_demux->psz_name, 
    176               p_demux->i_write / 1024 ); 
     122    demux_t     *p_demux = (demux_t*)p_this; 
     123    demux_sys_t *p_sys = p_demux->p_sys; 
    177124 
    178     if( p_demux->p_file ) 
     125    msg_Info( p_demux ,"closing %s ("I64Fd" Kbytes dumped)", p_sys->psz_file, 
     126              p_sys->i_write / 1024 ); 
     127 
     128    if( p_sys->p_file != stdout ) 
    179129    { 
    180         if( p_demux->p_file != stdout ) 
    181             fclose( p_demux->p_file ); 
    182         p_demux->p_file = NULL; 
     130        fclose( p_sys->p_file ); 
    183131    } 
    184     if( p_demux->psz_name ) 
    185     { 
    186         free( p_demux->psz_name ); 
    187     } 
    188     p_input->p_demux_data = p_demux->p_demux_data_sav; 
    189     free( p_demux ); 
     132    free( p_sys->psz_file ); 
     133 
     134    free( p_sys ); 
    190135} 
    191136 
     
    195140 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise 
    196141 *****************************************************************************/ 
    197 static int Demux( input_thread_t * p_input
     142static int Demux( demux_t *p_demux
    198143{ 
    199     demux_sys_t         *p_demux = (demux_sys_t*)p_input->p_demux_data
     144    demux_sys_t *p_sys = p_demux->p_sys
    200145 
    201     ssize_t         i_read; 
    202     data_packet_t * p_data; 
    203     int             i_write; 
     146    int i_data; 
    204147 
    205     p_input->p_demux_data = p_demux->p_demux_data_sav; 
    206     i_read = input_SplitBuffer( p_input, &p_data, DUMP_BLOCKSIZE ); 
    207     p_input->p_demux_data = p_demux; 
    208      
    209     if ( i_read <= 0 ) 
     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 ); 
     150    if ( i_data <= 0 ) 
     151        return i_data; 
     152 
     153    i_data = fwrite( p_sys->buffer, 1, i_data, p_sys->p_file ); 
     154 
     155    if( i_data < 0 ) 
    210156    { 
    211         return i_read; 
     157        msg_Err( p_demux, "failed to write data" ); 
     158        return -1; 
    212159    } 
     160    msg_Dbg( p_demux, "dumped %d bytes", i_data ); 
    213161 
    214     i_write = fwrite( p_data->p_payload_start, 
    215                        1, 
    216                        i_read, 
    217                        p_demux->p_file ); 
    218      
    219     input_DeletePacket( p_input->p_method_data, p_data ); 
     162    p_sys->i_write += i_data; 
    220163 
    221     if( i_write < 0 ) 
    222     { 
    223         msg_Err( p_input,  
    224                  "failed to write %d bytes", 
    225                  i_write ); 
    226         return( -1 ); 
    227     } 
    228     else 
    229     { 
    230         msg_Dbg( p_input, 
    231                  "dumped %d bytes", 
    232                  i_write ); 
    233         p_demux->i_write += i_write; 
    234     } 
     164    return 1; 
     165
    235166 
     167/***************************************************************************** 
     168 * Demux: reads and demuxes data packets 
     169 *****************************************************************************/ 
     170static int Control( demux_t *p_demux, int i_query, va_list args ) 
     171{ 
     172    return demux2_vaControlHelper( p_demux->s, 0, -1, 0, 1, i_query, args ); 
     173} 
    236174 
    237     if( (p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT) 
    238          | (input_ClockManageControl( p_input,  
    239                       p_input->stream.p_selected_program, 
    240                          (mtime_t)0 ) == PAUSE_S) ) 
    241     { 
    242         msg_Warn( p_input, "synchro reinit" ); 
    243         p_input->stream.p_selected_program->i_synchro_state = SYNCHRO_OK; 
    244     } 
    245  
    246     return( 1 ); 
    247 }