Changeset 08ece243befadb2eaf51ce28067829733eaab3ab

Show
Ignore:
Timestamp:
03/03/04 12:40:19 (5 years ago)
Author:
Laurent Aimar <fenrir@videolan.org>
git-committer:
Laurent Aimar <fenrir@videolan.org> 1078314019 +0000
git-parent:

[ae60413f308ab0d09bb3a1fd8bb63661ec1bb569]

git-author:
Laurent Aimar <fenrir@videolan.org> 1078314019 +0000
Message:
  • a52.c aac.c au.c dts.c flac.c wav.c: Converted all audio only demuxers
    to demux2.
Files:

Legend:

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

    rde81c25 r08ece24  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001 VideoLAN 
    5  * $Id: a52.c,v 1.6 2004/02/25 17:48:52 fenrir Exp $ 
     5 * $Id: a52.c,v 1.7 2004/03/03 11:40:19 fenrir Exp $ 
    66 * 
    77 * Authors: Gildas Bazin <gbazin@netcourrier.com> 
     
    3333#endif 
    3434 
     35/***************************************************************************** 
     36 * Module descriptor 
     37 *****************************************************************************/ 
     38static int  Open  ( vlc_object_t * ); 
     39static void Close ( vlc_object_t * ); 
     40 
     41vlc_module_begin(); 
     42    set_description( _("Raw A/52 demuxer") ); 
     43    set_capability( "demux2", 145 ); 
     44    set_callbacks( Open, Close ); 
     45    add_shortcut( "a52" ); 
     46vlc_module_end(); 
     47 
     48/***************************************************************************** 
     49 * Local prototypes 
     50 *****************************************************************************/ 
     51static int Demux  ( demux_t * ); 
     52static int Control( demux_t *, int, va_list ); 
     53 
     54struct demux_sys_t 
     55{ 
     56    vlc_bool_t  b_start; 
     57    es_out_id_t *p_es; 
     58 
     59    /* Packetizer */ 
     60    decoder_t *p_packetizer; 
     61 
     62    int i_mux_rate; 
     63    vlc_bool_t b_big_endian; 
     64}; 
     65 
     66static int CheckSync( uint8_t *p_peek, vlc_bool_t *p_big_endian ); 
     67 
    3568#define PCM_FRAME_SIZE (1536 * 4) 
    3669#define A52_PACKET_SIZE (4 * PCM_FRAME_SIZE) 
    3770#define A52_MAX_HEADER_SIZE 10 
    3871 
    39 /***************************************************************************** 
    40  * Local prototypes 
    41  *****************************************************************************/ 
    42 static int  Open  ( vlc_object_t * ); 
    43 static void Close ( vlc_object_t * ); 
    44 static int  Demux ( input_thread_t * ); 
    45  
    46 static int Control( input_thread_t *, int, va_list ); 
    47  
    48 struct demux_sys_t 
    49 { 
    50     vlc_bool_t  b_start; 
    51     es_out_id_t *p_es; 
    52  
    53     /* Packetizer */ 
    54     decoder_t *p_packetizer; 
    55  
    56     int i_mux_rate; 
    57     vlc_bool_t b_big_endian; 
    58 }; 
    59  
    60 /***************************************************************************** 
    61  * Module descriptor 
    62  *****************************************************************************/ 
    63 vlc_module_begin(); 
    64     set_description( _("Raw A/52 demuxer") ); 
    65     set_capability( "demux", 145 ); 
    66     set_callbacks( Open, Close ); 
    67     add_shortcut( "a52" ); 
    68 vlc_module_end(); 
    69  
    70 /***************************************************************************** 
    71  * CheckSync: Check if buffer starts with an A52 sync code 
    72  *****************************************************************************/ 
    73 static int CheckSync( uint8_t *p_peek, vlc_bool_t *p_big_endian ) 
    74 { 
    75     /* Little endian version of the bitstream */ 
    76     if( p_peek[0] == 0x77 && p_peek[1] == 0x0b && 
    77         p_peek[4] < 0x60 /* bsid < 12 */ ) 
    78     { 
    79         *p_big_endian = VLC_FALSE; 
    80         return VLC_SUCCESS; 
    81     } 
    82     /* Big endian version of the bitstream */ 
    83     else if( p_peek[0] == 0x0b && p_peek[1] == 0x77 && 
    84              p_peek[5] < 0x60 /* bsid < 12 */ ) 
    85     { 
    86         *p_big_endian = VLC_TRUE; 
    87         return VLC_SUCCESS; 
    88     } 
    89  
    90     return VLC_EGENERIC; 
    91 } 
    9272 
    9373/***************************************************************************** 
     
    9676static int Open( vlc_object_t * p_this ) 
    9777{ 
    98     input_thread_t *p_input = (input_thread_t *)p_this; 
    99     demux_sys_t    *p_sys; 
    100     byte_t *       p_peek; 
    101     int            i_peek = 0; 
    102     vlc_bool_t     b_big_endian; 
    103  
    104     p_input->pf_demux = Demux; 
    105     p_input->pf_demux_control = Control; 
    106     p_input->pf_rewind = NULL; 
     78    demux_t     *p_demux = (demux_t*)p_this; 
     79    demux_sys_t *p_sys; 
     80    byte_t      *p_peek; 
     81    int         i_peek = 0; 
     82    vlc_bool_t  b_big_endian; 
    10783 
    10884    /* Check if we are dealing with a WAV file */ 
    109     if( input_Peek( p_input, &p_peek, 12 ) == 12 && 
     85    if( stream_Peek( p_demux->s, &p_peek, 12 ) == 12 && 
    11086        !strncmp( p_peek, "RIFF", 4 ) && !strncmp( &p_peek[8], "WAVE", 4 ) ) 
    11187    { 
     
    11490        /* Skip the wave header */ 
    11591        i_peek = 12 + 8; 
    116         while( input_Peek( p_input, &p_peek, i_peek ) == i_peek && 
     92        while( stream_Peek( p_demux->s, &p_peek, i_peek ) == i_peek && 
    11793               strncmp( p_peek + i_peek - 8, "data", 4 ) ) 
    11894        { 
     
    124100        /* Some A52 wav files don't begin with a sync code so we do a more 
    125101         * extensive search */ 
    126         i_size = input_Peek( p_input, &p_peek, i_peek + A52_PACKET_SIZE * 2); 
     102        i_size = stream_Peek( p_demux->s, &p_peek, i_peek + A52_PACKET_SIZE * 2); 
    127103        i_size -= (PCM_FRAME_SIZE + A52_MAX_HEADER_SIZE); 
    128104 
     
    148124 
    149125    /* Have a peep at the show. */ 
    150     if( input_Peek( p_input, &p_peek, i_peek + A52_MAX_HEADER_SIZE * 2 ) < 
     126    if( stream_Peek( p_demux->s, &p_peek, i_peek + A52_MAX_HEADER_SIZE * 2 ) < 
    151127        i_peek + A52_MAX_HEADER_SIZE * 2 ) 
    152128    { 
    153129        /* Stream too short */ 
    154         msg_Warn( p_input, "cannot peek()" ); 
     130        msg_Warn( p_demux, "cannot peek()" ); 
    155131        return VLC_EGENERIC; 
    156132    } 
     
    158134    if( CheckSync( p_peek + i_peek, &b_big_endian ) != VLC_SUCCESS ) 
    159135    { 
    160         if( p_input->psz_demux && !strncmp( p_input->psz_demux, "a52", 3 ) ) 
    161         { 
    162             /* User forced */ 
    163             msg_Err( p_input, "this doesn't look like a A52 audio stream, " 
    164                      "continuing anyway" ); 
    165         } 
    166         else 
     136        if( strncmp( p_demux->psz_demux, "a52", 3 ) ) 
    167137        { 
    168138            return VLC_EGENERIC; 
    169139        } 
    170     } 
    171  
    172     p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) ); 
     140 
     141        /* User forced */ 
     142        msg_Err( p_demux, "this doesn't look like a A52 audio stream, " 
     143                 "continuing anyway" ); 
     144    } 
     145 
     146    /* Fill p_demux fields */ 
     147    p_demux->pf_demux = Demux; 
     148    p_demux->pf_control = Control; 
     149    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); 
    173150    p_sys->b_start = VLC_TRUE; 
    174151    p_sys->i_mux_rate = 0; 
     
    178155     * Load the A52 packetizer 
    179156     */ 
    180     p_sys->p_packetizer = vlc_object_create( p_input, VLC_OBJECT_DECODER ); 
     157    p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_DECODER ); 
    181158    p_sys->p_packetizer->pf_decode_audio = 0; 
    182159    p_sys->p_packetizer->pf_decode_video = 0; 
     
    192169    if( !p_sys->p_packetizer->p_module ) 
    193170    { 
    194         msg_Err( p_input, "cannot find A52 packetizer" ); 
     171        msg_Err( p_demux, "cannot find A52 packetizer" ); 
    195172        return VLC_EGENERIC; 
    196173    } 
    197174 
    198175    /* Create one program */ 
    199     vlc_mutex_lock( &p_input->stream.stream_lock ); 
    200     if( input_InitStream( p_input, 0 ) == -1 ) 
    201     { 
    202         vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    203         msg_Err( p_input, "cannot init stream" ); 
    204         return VLC_EGENERIC; 
    205     } 
    206     p_input->stream.i_mux_rate = 0; 
    207     vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    208  
    209     p_sys->p_es = 
    210         es_out_Add( p_input->p_es_out, &p_sys->p_packetizer->fmt_in ); 
     176    p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_in ); 
    211177 
    212178    return VLC_SUCCESS; 
     
    218184static void Close( vlc_object_t * p_this ) 
    219185{ 
    220     input_thread_t *p_input = (input_thread_t*)p_this; 
    221     demux_sys_t    *p_sys = p_input->p_demux_data
     186    demux_t        *p_demux = (demux_t*)p_this; 
     187    demux_sys_t    *p_sys = p_demux->p_sys
    222188 
    223189    /* Unneed module */ 
     
    235201 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise 
    236202 *****************************************************************************/ 
    237 static int Demux( input_thread_t * p_input
    238 { 
    239     demux_sys_t *p_sys = p_input->p_demux_data
    240     block_t *p_block_in, *p_block_out; 
     203static int Demux( demux_t *p_demux
     204{ 
     205    demux_sys_t *p_sys = p_demux->p_sys
     206    block_t     *p_block_in, *p_block_out; 
    241207 
    242208     /* Align stream */ 
    243     int64_t i_pos = stream_Tell( p_input->s ); 
    244     if( i_pos % 2 ) stream_Read( p_input->s, NULL, 1 ); 
    245  
    246     if( !( p_block_in = stream_Block( p_input->s, A52_PACKET_SIZE ) ) ) 
     209    int64_t i_pos = stream_Tell( p_demux->s ); 
     210    if( i_pos % 2 ) stream_Read( p_demux->s, NULL, 1 ); 
     211 
     212    if( !( p_block_in = stream_Block( p_demux->s, A52_PACKET_SIZE ) ) ) 
    247213    { 
    248214        return 0; 
     
    286252            /* We assume a constant bitrate */ 
    287253            if( p_block_out->i_length ) 
    288             p_sys->i_mux_rate = 
    289                 p_block_out->i_buffer * I64C(1000000) / p_block_out->i_length; 
    290             p_input->stream.i_mux_rate = p_sys->i_mux_rate / 50; 
    291  
    292             input_ClockManageRef( p_input, 
    293                                   p_input->stream.p_selected_program, 
    294                                   p_block_out->i_pts * 9 / 100 ); 
    295  
    296             p_block_out->i_dts = p_block_out->i_pts = 
    297                 input_ClockGetTS( p_input, p_input->stream.p_selected_program, 
    298                                   p_block_out->i_pts * 9 / 100 ); 
    299  
    300             es_out_Send( p_input->p_es_out, p_sys->p_es, p_block_out ); 
     254            { 
     255                p_sys->i_mux_rate = 
     256                    p_block_out->i_buffer * I64C(1000000)/p_block_out->i_length; 
     257            } 
     258 
     259            /* set PCR */ 
     260            es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts ); 
     261 
     262            es_out_Send( p_demux->out, p_sys->p_es, p_block_out ); 
    301263 
    302264            p_block_out = p_next; 
     
    310272 * Control: 
    311273 *****************************************************************************/ 
    312 static int Control( input_thread_t *p_input, int i_query, va_list args ) 
    313 
    314     demux_sys_t *p_sys  = (demux_sys_t *)p_input->p_demux_data; 
    315     int64_t *pi64; 
    316  
    317     switch( i_query ) 
    318     { 
    319         case DEMUX_GET_TIME: 
    320             pi64 = (int64_t*)va_arg( args, int64_t * ); 
    321             if( p_sys->i_mux_rate > 0 ) 
    322             { 
    323                 *pi64 = I64C(1000000) * stream_Tell( p_input->s ) / 
    324                         p_sys->i_mux_rate; 
    325                 return VLC_SUCCESS; 
    326             } 
    327             *pi64 = 0; 
    328             return VLC_EGENERIC; 
    329  
    330         case DEMUX_GET_LENGTH: 
    331             pi64 = (int64_t*)va_arg( args, int64_t * ); 
    332             if( p_sys->i_mux_rate > 0 ) 
    333             { 
    334                 *pi64 = I64C(1000000) * stream_Size( p_input->s ) / 
    335                         p_sys->i_mux_rate; 
    336                 return VLC_SUCCESS; 
    337             } 
    338             *pi64 = 0; 
    339             return VLC_EGENERIC; 
    340  
    341         default: 
    342             return demux_vaControlDefault( p_input, i_query, args ); 
    343     } 
    344 
     274static int Control( demux_t *p_demux, int i_query, va_list args ) 
     275
     276    demux_sys_t *p_sys  = p_demux->p_sys; 
     277    return demux2_vaControlHelper( p_demux->s, 
     278                                   0, -1, 
     279                                   8*p_sys->i_mux_rate, 1, i_query, args ); 
     280
     281 
     282/***************************************************************************** 
     283 * CheckSync: Check if buffer starts with an A52 sync code 
     284 *****************************************************************************/ 
     285static int CheckSync( uint8_t *p_peek, vlc_bool_t *p_big_endian ) 
     286
     287    /* Little endian version of the bitstream */ 
     288    if( p_peek[0] == 0x77 && p_peek[1] == 0x0b && 
     289        p_peek[4] < 0x60 /* bsid < 12 */ ) 
     290    { 
     291        *p_big_endian = VLC_FALSE; 
     292        return VLC_SUCCESS; 
     293    } 
     294    /* Big endian version of the bitstream */ 
     295    else if( p_peek[0] == 0x0b && p_peek[1] == 0x77 && 
     296             p_peek[5] < 0x60 /* bsid < 12 */ ) 
     297    { 
     298        *p_big_endian = VLC_TRUE; 
     299        return VLC_SUCCESS; 
     300    } 
     301 
     302    return VLC_EGENERIC; 
     303
     304 
     305 
  • modules/demux/aac.c

    rffdca9a r08ece24  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001-2003 VideoLAN 
    5  * $Id: aac.c,v 1.9 2004/01/25 20:05:28 hartman Exp $ 
     5 * $Id: aac.c,v 1.10 2004/03/03 11:40:19 fenrir Exp $ 
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    3838vlc_module_begin(); 
    3939    set_description( _("AAC demuxer" ) ); 
    40     set_capability( "demux", 10 ); 
     40    set_capability( "demux2", 100 ); 
    4141    set_callbacks( Open, Close ); 
    4242    add_shortcut( "aac" ); 
     
    5151 * Local prototypes 
    5252 *****************************************************************************/ 
    53 static int  Demux       ( input_thread_t * ); 
    54  
    5553struct demux_sys_t 
    5654{ 
     
    6058}; 
    6159 
     60static int Demux  ( demux_t * ); 
     61static int Control( demux_t *, int, va_list ); 
     62 
    6263static int i_aac_samplerate[16] = 
    6364{ 
    64     96000, 88200, 64000, 48000, 44100, 32000,  
     65    96000, 88200, 64000, 48000, 44100, 32000, 
    6566    24000, 22050, 16000, 12000, 11025, 8000, 
    6667    7350,  0,     0,     0 
     
    7172#define AAC_CHANNELS( p )    ( (((p)[2]&0x01)<<2) | (((p)[3]>>6)&0x03) ) 
    7273#define AAC_FRAME_SIZE( p )  ( (((p)[3]&0x03) << 11)|( (p)[4] << 3 )|( (((p)[5]) >>5)&0x7 ) ) 
     74 
    7375/* FIXME it's plain wrong */ 
    7476#define AAC_FRAME_SAMPLES( p )  1024 
     
    8789} 
    8890 
    89  
    9091/***************************************************************************** 
    9192 * Open: initializes AAC demux structures 
     
    9394static int Open( vlc_object_t * p_this ) 
    9495{ 
    95     input_thread_t *p_input = (input_thread_t *)p_this; 
    96     demux_sys_t    *p_sys; 
    97     int            b_forced = VLC_FALSE; 
    98  
    99     uint8_t        *p_peek; 
    100  
    101     module_t       *p_id3; 
    102  
    103     es_format_t    fmt; 
    104  
    105  
    106     if( p_input->psz_demux && !strncmp( p_input->psz_demux, "aac", 3 ) ) 
     96    demux_t     *p_demux = (demux_t*)p_this; 
     97    demux_sys_t *p_sys; 
     98    int         b_forced = VLC_FALSE; 
     99 
     100    uint8_t     *p_peek; 
     101    module_t    *p_id3; 
     102    es_format_t fmt; 
     103 
     104    if( !strncmp( p_demux->psz_demux, "aac", 3 ) ) 
    107105    { 
    108106        b_forced = VLC_TRUE; 
    109107    } 
    110108 
    111     if( p_input->psz_name
    112     { 
    113         int  i_len = strlen( p_input->psz_name ); 
    114  
    115         if( i_len > 4 && !strcasecmp( &p_input->psz_name[i_len - 4], ".aac" ) ) 
     109    if( p_demux->psz_path
     110    { 
     111        int  i_len = strlen( p_demux->psz_path ); 
     112 
     113        if( i_len > 4 && !strcasecmp( &p_demux->psz_path[i_len - 4], ".aac" ) ) 
    116114        { 
    117115            b_forced = VLC_TRUE; 
     
    124122         * extention check 
    125123         */ 
    126         msg_Warn( p_input, "AAC module discarded" ); 
     124        msg_Warn( p_demux, "AAC module discarded" ); 
    127125        return VLC_EGENERIC; 
    128126    } 
    129127 
    130128    /* skip possible id3 header */ 
    131     p_id3 = module_Need( p_input, "id3", NULL ); 
    132     if ( p_id3 ) 
    133     { 
    134         module_Unneed( p_input, p_id3 ); 
    135     } 
    136  
    137     p_input->pf_demux = Demux; 
    138     p_input->pf_demux_control = demux_vaControlDefault; 
    139  
    140     p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) ); 
     129    if( ( p_id3 = module_Need( p_demux, "id3", NULL ) ) ) 
     130    { 
     131        module_Unneed( p_demux, p_id3 ); 
     132    } 
     133 
     134    p_demux->pf_demux   = Demux; 
     135    p_demux->pf_control = Control; 
     136    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); 
     137 
    141138    p_sys->i_time = 0; 
    142139 
    143140    /* peek the begining (10 is for adts header) */ 
    144     if( stream_Peek( p_input->s, &p_peek, 10 ) < 10 ) 
    145     { 
    146         msg_Err( p_input, "cannot peek" ); 
     141    if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) 
     142    { 
     143        msg_Err( p_demux, "cannot peek" ); 
    147144        goto error; 
    148145    } 
    149  
    150146    if( !strncmp( p_peek, "ADIF", 4 ) ) 
    151147    { 
    152         msg_Err( p_input, "ADIF file. Not yet supported. (Please report)" ); 
     148        msg_Err( p_demux, "ADIF file. Not yet supported. (Please report)" ); 
    153149        goto error; 
    154150    } 
     
    158154    { 
    159155        fmt.audio.i_channels = AAC_CHANNELS( p_peek ); 
    160         fmt.audio.i_rate = AAC_SAMPLE_RATE( p_peek ); 
    161  
    162         msg_Dbg( p_input
     156        fmt.audio.i_rate     = AAC_SAMPLE_RATE( p_peek ); 
     157 
     158        msg_Dbg( p_demux
    163159                 "adts header: id=%d channels=%d sample_rate=%d", 
    164160                 AAC_ID( p_peek ), 
     
    167163    } 
    168164 
    169     vlc_mutex_lock( &p_input->stream.stream_lock ); 
    170     if( input_InitStream( p_input, 0 ) == -1) 
    171     { 
    172         vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    173         msg_Err( p_input, "cannot init stream" ); 
    174         goto error; 
    175     } 
    176     p_input->stream.i_mux_rate = 0 / 50; 
    177     vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    178  
    179     p_sys->p_es = es_out_Add( p_input->p_es_out, &fmt ); 
    180  
     165    p_sys->p_es = es_out_Add( p_demux->out, &fmt ); 
    181166    return VLC_SUCCESS; 
    182167 
     
    192177 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise 
    193178 *****************************************************************************/ 
    194 static int Demux( input_thread_t * p_input
    195 { 
    196     demux_sys_t *p_sys = p_input->p_demux_data
    197     block_t *p_block; 
    198  
    199     uint8_t      h[8]; 
    200     uint8_t      *p_peek; 
    201  
    202     if( stream_Peek( p_input->s, &p_peek, 8 ) < 8 ) 
    203     { 
    204         msg_Warn( p_input, "cannot peek" ); 
     179static int Demux( demux_t *p_demux
     180{ 
     181    demux_sys_t *p_sys = p_demux->p_sys
     182    block_t     *p_block; 
     183 
     184    uint8_t     h[8]; 
     185    uint8_t     *p_peek; 
     186 
     187    if( stream_Peek( p_demux->s, &p_peek, 8 ) < 8 ) 
     188    { 
     189        msg_Warn( p_demux, "cannot peek" ); 
    205190        return 0; 
    206191    } 
     
    213198        int         i_peek; 
    214199 
    215         i_peek = stream_Peek( p_input->s, &p_peek, 8096 ); 
     200        i_peek = stream_Peek( p_demux->s, &p_peek, 8096 ); 
    216201        if( i_peek < 8 ) 
    217202        { 
    218             msg_Warn( p_input, "cannot peek" ); 
     203            msg_Warn( p_demux, "cannot peek" ); 
    219204            return 0; 
    220205        } 
     
    233218        } 
    234219 
    235         msg_Warn( p_input, "garbage=%d bytes", i_skip ); 
    236         stream_Read( p_input->s, NULL, i_skip ); 
     220        msg_Warn( p_demux, "garbage=%d bytes", i_skip ); 
     221        stream_Read( p_demux->s, NULL, i_skip ); 
    237222        return 1; 
    238223    } 
     
    240225    memcpy( h, p_peek, 8 );    /* can't use p_peek after stream_*  */ 
    241226 
    242     input_ClockManageRef( p_input, 
    243                           p_input->stream.p_selected_program, 
    244                           p_sys->i_time * 9 / 100 ); 
    245  
    246     if( ( p_block = stream_Block( p_input->s, AAC_FRAME_SIZE( h ) ) ) == NULL ) 
    247     { 
    248         msg_Warn( p_input, "cannot read data" ); 
     227 
     228 
     229    /* set PCR */ 
     230    es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_time ); 
     231 
     232    if( ( p_block = stream_Block( p_demux->s, AAC_FRAME_SIZE( h ) ) ) == NULL ) 
     233    { 
     234        msg_Warn( p_demux, "cannot read data" ); 
    249235        return 0; 
    250236    } 
    251237 
    252     p_block->i_dts = 
    253     p_block->i_pts = input_ClockGetTS( p_input, 
    254                                      p_input->stream.p_selected_program, 
    255                                      p_sys->i_time * 9 / 100 ); 
    256  
    257     es_out_Send( p_input->p_es_out, p_sys->p_es, p_block ); 
     238    p_block->i_dts = p_block->i_pts = p_sys->i_time; 
     239 
     240    es_out_Send( p_demux->out, p_sys->p_es, p_block ); 
    258241 
    259242    p_sys->i_time += (mtime_t)1000000 * 
     
    268251static void Close( vlc_object_t * p_this ) 
    269252{ 
    270     input_thread_t *p_input = (input_thread_t*)p_this; 
    271     demux_sys_t    *p_sys = p_input->p_demux_data
     253    demux_t     *p_demux = (demux_t*)p_this; 
     254    demux_sys_t *p_sys = p_demux->p_sys
    272255 
    273256    free( p_sys ); 
    274257} 
    275258 
     259/***************************************************************************** 
     260 * Control: 
     261 *****************************************************************************/ 
     262static int Control( demux_t *p_demux, int i_query, va_list args ) 
     263{ 
     264    /* demux_sys_t *p_sys  = p_demux->p_sys; */ 
     265    /* FIXME calculate the bitrate */ 
     266    return demux2_vaControlHelper( p_demux->s, 
     267                                   0, -1, 
     268                                   8*0, 1, i_query, args ); 
     269} 
     270 
  • modules/demux/au.c

    r0b1ccd3 r08ece24  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001-2003 VideoLAN 
    5  * $Id: au.c,v 1.13 2004/01/29 15:11:17 fenrir Exp $ 
     5 * $Id: au.c,v 1.14 2004/03/03 11:40:19 fenrir Exp $ 
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    332332{ 
    333333    demux_sys_t *p_sys = p_demux->p_sys; 
    334     double f, *pf; 
    335     int64_t *pi64; 
    336  
    337     switch( i_query ) 
    338     { 
    339         case DEMUX_GET_POSITION: 
    340         { 
    341             int64_t i_tell = stream_Tell( p_demux->s ); 
    342             int64_t i_end  = stream_Size( p_demux->s ); 
    343  
    344             pf = (double*) va_arg( args, double* ); 
    345  
    346             if( p_sys->i_header_size < i_end ) 
    347             { 
    348                 *pf = (double)( i_tell - p_sys->i_header_size ) / 
    349                       (double)(i_end - p_sys->i_header_size); 
    350                 return VLC_SUCCESS; 
    351             } 
    352             return VLC_EGENERIC; 
    353         } 
    354         case DEMUX_SET_POSITION: 
    355         { 
    356             int64_t i_end  = stream_Size( p_demux->s ); 
    357  
    358             f = (double) va_arg( args, double ); 
    359  
    360             if( p_sys->i_header_size < i_end ) 
    361             { 
    362                 int64_t i_frame = (f * ( i_end - p_sys->i_header_size )) / 
    363                                   p_sys->fmt.audio.i_blockalign; 
    364  
    365                 if( stream_Seek( p_demux->s, p_sys->i_header_size + 
    366                                              i_frame * p_sys->fmt.audio.i_blockalign ) ) 
    367                 { 
    368                     return VLC_EGENERIC; 
    369                 } 
    370                 p_sys->i_time = 1 + ( i_frame * p_sys->fmt.audio.i_blockalign / p_sys->i_frame_size ) * p_sys->i_frame_length; 
    371                 return VLC_SUCCESS; 
    372             } 
    373             return VLC_EGENERIC; 
    374         } 
    375  
    376         case DEMUX_GET_TIME: 
    377             pi64 = (int64_t*)va_arg( args, int64_t * ); 
    378             *pi64 = p_sys->i_time; 
    379             return VLC_SUCCESS; 
    380  
    381         case DEMUX_GET_LENGTH: 
    382         { 
    383             int64_t i_size  = stream_Size( p_demux->s ) - p_sys->i_header_size; 
    384             if( i_size > 0 ) 
    385             { 
    386                 pi64 = (int64_t*)va_arg( args, int64_t * ); 
    387                 *pi64 = i_size / p_sys->i_frame_size * p_sys->i_frame_length; 
    388                 return VLC_SUCCESS; 
    389             } 
    390             return VLC_EGENERIC; 
    391         } 
    392         case DEMUX_SET_TIME: 
    393         case DEMUX_GET_FPS: 
    394         default: 
    395             return VLC_EGENERIC; 
    396     } 
     334 
     335    return demux2_vaControlHelper( p_demux->s, p_sys->i_header_size, -1, 
     336                                   p_sys->fmt.i_bitrate, p_sys->fmt.audio.i_blockalign, 
     337                                   i_query, args ); 
    397338} 
    398339 
    399  
    400  
    401  
    402  
    403  
    404  
    405  
  • modules/demux/dts.c

    rde81c25 r08ece24  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001 VideoLAN 
    5  * $Id: dts.c,v 1.10 2004/02/25 17:48:52 fenrir Exp $ 
     5 * $Id: dts.c,v 1.11 2004/03/03 11:40:19 fenrir Exp $ 
    66 * 
    77 * Authors: Gildas Bazin <gbazin@netcourrier.com> 
     
    2929#include <vlc_codec.h> 
    3030 
     31/***************************************************************************** 
     32 * Module descriptor 
     33 *****************************************************************************/ 
     34static int  Open  ( vlc_object_t * ); 
     35static void Close ( vlc_object_t * ); 
     36 
     37vlc_module_begin(); 
     38    set_description( _("Raw DTS demuxer") ); 
     39    set_capability( "demux2", 155 ); 
     40    set_callbacks( Open, Close ); 
     41    add_shortcut( "dts" ); 
     42vlc_module_end(); 
     43 
     44/***************************************************************************** 
     45 * Local prototypes 
     46 *****************************************************************************/ 
     47static int Demux  ( demux_t * ); 
     48static int Control( demux_t *, int, va_list ); 
     49 
     50struct demux_sys_t 
     51{ 
     52    vlc_bool_t  b_start; 
     53    es_out_id_t *p_es; 
     54 
     55    /* Packetizer */ 
     56    decoder_t *p_packetizer; 
     57 
     58    int i_mux_rate; 
     59}; 
     60 
     61static int CheckSync( uint8_t *p_peek ); 
     62 
    3163#define DTS_PACKET_SIZE 16384 
    3264#define DTS_PROBE_SIZE (DTS_PACKET_SIZE * 4) 
     
    3466 
    3567/***************************************************************************** 
    36  * Local prototypes 
    37  *****************************************************************************/ 
    38 static int  Open  ( vlc_object_t * ); 
    39 static void Close ( vlc_object_t * ); 
    40 static int  Demux ( input_thread_t * ); 
    41  
    42 static int Control( input_thread_t *, int, va_list ); 
    43  
    44 struct demux_sys_t 
    45 { 
    46     vlc_bool_t  b_start; 
    47     es_out_id_t *p_es; 
    48  
    49     /* Packetizer */ 
    50     decoder_t *p_packetizer; 
    51  
    52     int i_mux_rate; 
    53 }; 
    54  
    55 /***************************************************************************** 
    56  * Module descriptor 
    57  *****************************************************************************/ 
    58 vlc_module_begin(); 
    59     set_description( _("Raw DTS demuxer") ); 
    60     set_capability( "demux", 155 ); 
    61     set_callbacks( Open, Close ); 
    62     add_shortcut( "dts" ); 
    63 vlc_module_end(); 
    64  
    65 /***************************************************************************** 
    66  * CheckSync: Check if buffer starts with a DTS sync code 
    67  *****************************************************************************/ 
    68 static int CheckSync( uint8_t *p_peek ) 
    69 { 
    70     /* 14 bits, little endian version of the bitstream */ 
    71     if( p_peek[0] == 0xff && p_peek[1] == 0x1f && 
    72         p_peek[2] == 0x00 && p_peek[3] == 0xe8 && 
    73         (p_peek[4] & 0xf0) == 0xf0 && p_peek[5] == 0x07 ) 
    74     { 
    75         return VLC_SUCCESS; 
    76     } 
    77     /* 14 bits, big endian version of the bitstream */ 
    78     else if( p_peek[0] == 0x1f && p_peek[1] == 0xff && 
    79              p_peek[2] == 0xe8 && p_peek[3] == 0x00 && 
    80              p_peek[4] == 0x07 && (p_peek[5] & 0xf0) == 0xf0) 
    81     { 
    82         return VLC_SUCCESS; 
    83     } 
    84     /* 16 bits, big endian version of the bitstream */ 
    85     else if( p_peek[0] == 0x7f && p_peek[1] == 0xfe && 
    86              p_peek[2] == 0x80 && p_peek[3] == 0x01 ) 
    87     { 
    88         return VLC_SUCCESS; 
    89     } 
    90     /* 16 bits, little endian version of the bitstream */ 
    91     else if( p_peek[0] == 0xfe && p_peek[1] == 0x7f && 
    92              p_peek[2] == 0x01 && p_peek[3] == 0x80 ) 
    93     { 
    94         return VLC_SUCCESS; 
    95     } 
    96  
    97     return VLC_EGENERIC; 
    98 } 
    99  
    100 /***************************************************************************** 
    10168 * Open: initializes ES structures 
    10269 *****************************************************************************/ 
    10370static int Open( vlc_object_t * p_this ) 
    10471{ 
    105     input_thread_t *p_input = (input_thread_t *)p_this; 
    106     demux_sys_t    *p_sys; 
    107     byte_t *       p_peek; 
    108     int            i_peek = 0; 
    109  
    110     p_input->pf_demux = Demux; 
    111     p_input->pf_demux_control = Control; 
    112     p_input->pf_rewind = NULL; 
     72    demux_t     *p_demux = (demux_t*)p_this; 
     73    demux_sys_t *p_sys; 
     74    byte_t *     p_peek; 
     75    int          i_peek = 0; 
    11376 
    11477    /* Check if we are dealing with a WAV file */ 
    115     if( input_Peek( p_input, &p_peek, 20 ) == 20 && 
     78    if( stream_Peek( p_demux->s, &p_peek, 20 ) == 20 && 
    11679        !strncmp( p_peek, "RIFF", 4 ) && !strncmp( &p_peek[8], "WAVE", 4 ) ) 
    11780    { 
     
    12689            i_peek += i_size + 8; 
    12790 
    128             if( input_Peek( p_input, &p_peek, i_peek ) != i_peek ) 
     91            if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek ) 
    12992                return VLC_EGENERIC; 
    13093        } 
     
    13497        if( i_size + i_peek > DTS_PROBE_SIZE ) return VLC_EGENERIC; 
    13598        i_peek += i_size + 8; 
    136         if( input_Peek( p_input, &p_peek, i_peek ) != i_peek ) 
     99        if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek ) 
    137100            return VLC_EGENERIC; 
    138101        if( GetWLE( p_peek + i_peek - i_size - 8 /* wFormatTag */ ) != 
     
    152115            i_peek += i_size + 8; 
    153116 
    154             if( input_Peek( p_input, &p_peek, i_peek ) != i_peek ) 
     117            if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek ) 
    155118                return VLC_EGENERIC; 
    156119        } 
     
    158121        /* Some DTS wav files don't begin with a sync code so we do a more 
    159122         * extensive search */ 
    160         i_size = input_Peek( p_input, &p_peek, DTS_PROBE_SIZE ); 
     123        i_size = stream_Peek( p_demux->s, &p_peek, DTS_PROBE_SIZE ); 
    161124        i_size -= DTS_MAX_HEADER_SIZE; 
    162125 
     
    172135 
    173136    /* Have a peep at the show. */ 
    174     if( input_Peek( p_input, &p_peek, i_peek + DTS_MAX_HEADER_SIZE * 2 ) < 
     137    if( stream_Peek( p_demux->s, &p_peek, i_peek + DTS_MAX_HEADER_SIZE * 2 ) < 
    175138        i_peek + DTS_MAX_HEADER_SIZE * 2 ) 
    176139    { 
    177140        /* Stream too short */ 
    178         msg_Warn( p_input, "cannot peek()" ); 
     141        msg_Warn( p_demux, "cannot peek()" ); 
    179142        return VLC_EGENERIC; 
    180143    } 
     
    182145    if( CheckSync( p_peek + i_peek ) != VLC_SUCCESS ) 
    183146    { 
    184         if( p_input->psz_demux && !strncmp( p_input->psz_demux, "dts", 3 ) ) 
    185         { 
    186             /* User forced */ 
    187             msg_Err( p_input, "this doesn't look like a DTS audio stream, " 
    188                      "continuing anyway" ); 
    189         } 
    190         else 
    191         { 
    192             return VLC_EGENERIC; 
    193         } 
    194     } 
    195  
    196     p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) ); 
     147        if( strncmp( p_demux->psz_demux, "dts", 3 ) ) 
     148        { 
     149            return VLC_EGENERIC; 
     150        } 
     151        /* User forced */ 
     152        msg_Err( p_demux, "this doesn't look like a DTS audio stream, " 
     153                 "continuing anyway" ); 
     154    } 
     155 
     156    p_demux->pf_demux = Demux; 
     157    p_demux->pf_control = Control; 
     158    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); 
    197159    p_sys->b_start = VLC_TRUE; 
    198160    p_sys->i_mux_rate = 0; 
     
    201163     * Load the DTS packetizer 
    202164     */ 
    203     p_sys->p_packetizer = vlc_object_create( p_input, VLC_OBJECT_DECODER ); 
     165    p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_DECODER ); 
    204166    p_sys->p_packetizer->pf_decode_audio = 0; 
    205167    p_sys->p_packetizer->pf_decode_video = 0; 
     
    215177    if( !p_sys->p_packetizer->p_module ) 
    216178    { 
    217         msg_Err( p_input, "cannot find DTS packetizer" ); 
     179        msg_Err( p_demux, "cannot find DTS packetizer" ); 
    218180        return VLC_EGENERIC; 
    219181    } 
    220182 
    221     /* Create one program */ 
    222     vlc_mutex_lock( &p_input->stream.stream_lock ); 
    223     if( input_InitStream( p_input, 0 ) == -1 ) 
    224     { 
    225         vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    226         msg_Err( p_input, "cannot init stream" ); 
    227         return VLC_EGENERIC; 
    228     } 
    229     p_input->stream.i_mux_rate = 0; 
    230     vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    231  
    232     p_sys->p_es = 
    233         es_out_Add( p_input->p_es_out, &p_sys->p_packetizer->fmt_in ); 
     183    p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_in ); 
    234184 
    235185    return VLC_SUCCESS; 
     
    239189 * Close: frees unused data 
    240190 *****************************************************************************/ 
    241 static void Close( vlc_object_t * p_this ) 
    242 { 
    243     input_thread_t *p_input = (input_thread_t*)p_this; 
    244     demux_sys_t    *p_sys = p_input->p_demux_data
     191static void Close( vlc_object_t *p_this ) 
     192{ 
     193    demux_t     *p_demux = (demux_t*)p_this; 
     194    demux_sys_t *p_sys = p_demux->p_sys
    245195 
    246196    /* Unneed module */ 
     
    258208 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise 
    259209 *****************************************************************************/ 
    260 static int Demux( input_thread_t * p_input
    261 { 
    262     demux_sys_t *p_sys = p_input->p_demux_data
     210static int Demux( demux_t *p_demux
     211{ 
     212    demux_sys_t *p_sys = p_demux->p_sys
    263213    block_t *p_block_in, *p_block_out; 
    264214 
    265     if( !( p_block_in = stream_Block( p_input->s, DTS_PACKET_SIZE ) ) ) 
     215    if( !( p_block_in = stream_Block( p_demux->s, DTS_PACKET_SIZE ) ) ) 
    266216    { 
    267217        return 0; 
     
    284234            /* We assume a constant bitrate */ 
    285235            if( p_block_out->i_length ) 
    286             p_sys->i_mux_rate = 
    287                 p_block_out->i_buffer * I64C(1000000) / p_block_out->i_length; 
    288             p_input->stream.i_mux_rate = p_sys->i_mux_rate / 50; 
    289  
    290             input_ClockManageRef( p_input, 
    291                                   p_input->stream.p_selected_program, 
    292                                   p_block_out->i_pts * 9 / 100 ); 
    293  
    294             p_block_out->i_dts = p_block_out->i_pts = 
    295                 input_ClockGetTS( p_input, p_input->stream.p_selected_program, 
    296                                   p_block_out->i_pts * 9 / 100 ); 
    297  
    298             es_out_Send( p_input->p_es_out, p_sys->p_es, p_block_out ); 
     236            { 
     237                p_sys->i_mux_rate = 
     238                    p_block_out->i_buffer * I64C(1000000) / p_block_out->i_length; 
     239            } 
     240 
     241            /* set PCR */ 
     242            es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts ); 
     243 
     244            es_out_Send( p_demux->out, p_sys->p_es, p_block_out ); 
    299245 
    300246            p_block_out = p_next; 
     
    308254 * Control: 
    309255 *****************************************************************************/ 
    310 static int Control( input_thread_t *p_input, int i_query, va_list args ) 
    311 
    312     demux_sys_t *p_sys  = (demux_sys_t *)p_input->p_demux_data; 
    313     int64_t *pi64; 
    314  
    315     switch( i_query ) 
    316     { 
    317