X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Fau.c;h=1efd2d0a3647454b88090c74e9be13302c3608fa;hb=371b0ddd9c66218094043699b44e4fdd59433a42;hp=254332a679d0ff0a4490b4af8f10783344ffa2f4;hpb=0e1fdf57e63692674558265ffdb6a7cb3fd87425;p=vlc diff --git a/modules/demux/au.c b/modules/demux/au.c index 254332a679..1efd2d0a36 100644 --- a/modules/demux/au.c +++ b/modules/demux/au.c @@ -1,8 +1,9 @@ /***************************************************************************** * au.c : au file input module for vlc ***************************************************************************** - * Copyright (C) 2001 VideoLAN - * $Id: au.c,v 1.1 2003/03/11 07:03:16 fenrir Exp $ + * Copyright (C) 2001-2007 the VideoLAN team + * $Id$ + * * Authors: Laurent Aimar * * This program is free software; you can redistribute it and/or modify @@ -17,557 +18,319 @@ * * 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 -/***************************************************************************** - * Local prototypes - *****************************************************************************/ -static int AUInit ( vlc_object_t * ); -static void AUEnd ( vlc_object_t * ); -static int AUDemux ( input_thread_t * ); +#include +#include +#include -static int AUDemuxPCM ( input_thread_t * ); +/* TODO: + * - all adpcm things (I _NEED_ samples) + * - ... + */ /***************************************************************************** * Module descriptor *****************************************************************************/ -vlc_module_begin(); - set_description( _("AU demuxer") ); - set_capability( "demux", 142 ); - set_callbacks( AUInit, AUEnd ); -vlc_module_end(); - - -#define AUDIO_FILE_ENCODING_MULAW_8 1 /* 8-bit ISDN u-law */ -#define AUDIO_FILE_ENCODING_LINEAR_8 2 /* 8-bit linear PCM */ -#define AUDIO_FILE_ENCODING_LINEAR_16 3 /* 16-bit linear PCM */ -#define AUDIO_FILE_ENCODING_LINEAR_24 4 /* 24-bit linear PCM */ -#define AUDIO_FILE_ENCODING_LINEAR_32 5 /* 32-bit linear PCM */ -#define AUDIO_FILE_ENCODING_FLOAT 6 /* 32-bit IEEE floating point */ -#define AUDIO_FILE_ENCODING_DOUBLE 7 /* 64-bit IEEE floating point */ -#define AUDIO_FILE_ENCODING_ADPCM_G721 23 /* 4-bit CCITT g.721 ADPCM */ -#define AUDIO_FILE_ENCODING_ADPCM_G722 24 /* CCITT g.722 ADPCM */ -#define AUDIO_FILE_ENCODING_ADPCM_G723_3 25 /* CCITT g.723 3-bit ADPCM */ -#define AUDIO_FILE_ENCODING_ADPCM_G723_5 26 /* CCITT g.723 5-bit ADPCM */ -#define AUDIO_FILE_ENCODING_ALAW_8 27 /* 8-bit ISDN A-law */ - -typedef struct -{ - uint32_t i_header_size; - uint32_t i_data_size; - uint32_t i_encoding; - uint32_t i_sample_rate; - uint32_t i_channels; -} au_t; - -#define AU_DEMUX_PCM 0x01 -#define AU_DEMUX_ADPCM 0x02 -struct demux_sys_t -{ - au_t au; - WAVEFORMATEX wf; - - mtime_t i_time; - - es_descriptor_t *p_es; - - int i_demux; -}; +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( N_("AU demuxer") ) + set_capability( "demux", 10 ) + set_callbacks( Open, Close ) + add_shortcut( "au" ) +vlc_module_end () /***************************************************************************** - * Declaration of local function + * Local prototypes *****************************************************************************/ - -#define FREE( p ) if( p ) { free( p ); (p) = NULL; } - -static uint32_t GetDWBE( uint8_t *p_buff ) +enum AuType_e { - return( ( p_buff[0] << 24 ) + ( p_buff[1] << 16 ) + - ( p_buff[2] << 8 ) + p_buff[3] ); -} - - -static off_t TellAbsolute( input_thread_t *p_input ) -{ - off_t i_pos; - - vlc_mutex_lock( &p_input->stream.stream_lock ); - - i_pos= p_input->stream.p_selected_area->i_tell; - - vlc_mutex_unlock( &p_input->stream.stream_lock ); - - return( i_pos ); -} - -/* return 1 if success, 0 if fail */ -static int ReadData( input_thread_t *p_input, uint8_t *p_buff, int i_size ) -{ - data_packet_t *p_data; - - int i_count = 0; - - if( !i_size ) - { - return( 0 ); - } - - do - { - int i_read; - - i_read = input_SplitBuffer(p_input, &p_data, __MIN( i_size, 1024 ) ); - if( i_read <= 0 ) - { - return( i_count ); - } - memcpy( p_buff, p_data->p_payload_start, i_read ); - input_DeletePacket( p_input->p_method_data, p_data ); - - p_buff += i_read; - i_size -= i_read; - i_count += i_read; - - } while( i_size ); - - return( i_count ); -} + AU_UNKNOWN = 0, + AU_MULAW_8 = 1, /* 8-bit ISDN u-law */ + AU_LINEAR_8 = 2, /* 8-bit linear PCM */ + AU_LINEAR_16 = 3, /* 16-bit linear PCM */ + AU_LINEAR_24 = 4, /* 24-bit linear PCM */ + AU_LINEAR_32 = 5, /* 32-bit linear PCM */ + AU_FLOAT = 6, /* 32-bit IEEE floating point */ + AU_DOUBLE = 7, /* 64-bit IEEE floating point */ + AU_ADPCM_G721 = 23, /* 4-bit CCITT g.721 ADPCM */ + AU_ADPCM_G722 = 24, /* CCITT g.722 ADPCM */ + AU_ADPCM_G723_3 = 25, /* CCITT g.723 3-bit ADPCM */ + AU_ADPCM_G723_5 = 26, /* CCITT g.723 5-bit ADPCM */ + AU_ALAW_8 = 27 /* 8-bit ISDN A-law */ +}; -static int SeekAbsolute( input_thread_t *p_input, - off_t i_pos) +enum AuCat_e { - int i_skip; - - i_skip = i_pos - TellAbsolute( p_input ); - if( i_skip == 0 ) - { - return( VLC_SUCCESS ); - } - if( i_skip < 0 && !p_input->stream.b_seekable ) - { - return( VLC_EGENERIC ); - } - else if( !p_input->stream.b_seekable || - ( i_skip > 0 && i_skip < 1024 && p_input->stream.i_method != INPUT_METHOD_FILE ) ) - { - while( i_skip > 0 ) - { - uint8_t dummy[1024]; - int i_read; - - i_read = ReadData( p_input, dummy, __MIN( i_skip, 1024 ) ); - if( i_read <= 0 ) - { - return( VLC_EGENERIC ); - } - i_skip -= i_read; - } - return( VLC_SUCCESS ); - } - else - { - input_AccessReinit( p_input ); - p_input->pf_seek( p_input, i_pos ); - return( VLC_SUCCESS ); - } -} + AU_CAT_UNKNOWN = 0, + AU_CAT_PCM = 1, + AU_CAT_ADPCM = 2 +}; -static int SkipBytes( input_thread_t *p_input, int i_skip ) +struct demux_sys_t { - return( SeekAbsolute( p_input, TellAbsolute( p_input ) + i_skip ) ); -} + es_format_t fmt; + es_out_id_t *es; -static int ReadPES( input_thread_t *p_input, - pes_packet_t **pp_pes, - int i_size ) -{ - pes_packet_t *p_pes; + mtime_t i_time; - *pp_pes = NULL; + int i_frame_size; + mtime_t i_frame_length; - if( !(p_pes = input_NewPES( p_input->p_method_data )) ) - { - msg_Err( p_input, "cannot allocate new PES" ); - return( VLC_EGENERIC ); - } + int i_header_size; +}; - while( i_size > 0 ) - { - data_packet_t *p_data; - int i_read; - - if( (i_read = input_SplitBuffer( p_input, - &p_data, - __MIN( i_size, 1024 ) ) ) <= 0 ) - { - input_DeletePES( p_input->p_method_data, p_pes ); - return( VLC_EGENERIC ); - } - if( !p_pes->p_first ) - { - p_pes->p_first = p_data; - p_pes->i_nb_data = 1; - p_pes->i_pes_size = i_read; - } - else - { - p_pes->p_last->p_next = p_data; - p_pes->i_nb_data++; - p_pes->i_pes_size += i_read; - } - p_pes->p_last = p_data; - i_size -= i_read; - } - *pp_pes = p_pes; - return( VLC_SUCCESS ); -} +static int Demux( demux_t * ); +static int Control ( demux_t *, int i_query, va_list args ); /***************************************************************************** - * AUInit: check file and initializes structures + * Open: check file and initializes structures *****************************************************************************/ -static int AUInit( vlc_object_t * p_this ) +static int Open( vlc_object_t *p_this ) { - input_thread_t *p_input = (input_thread_t *)p_this; - uint8_t *p_peek; + demux_t *p_demux = (demux_t*)p_this; + demux_sys_t *p_sys; - au_t au; - WAVEFORMATEX wf; - vlc_fourcc_t i_codec; + uint8_t hdr[20]; + const uint8_t *p_peek; + int i_cat; + int i_samples, i_modulo; - demux_sys_t *p_demux; - es_descriptor_t *p_es; + if( stream_Peek( p_demux->s , &p_peek, 4 ) < 4 ) + return VLC_EGENERIC; + if( memcmp( p_peek, ".snd", 4 ) ) + return VLC_EGENERIC; - /* Initialize access plug-in structures. */ - if( p_input->i_mtu == 0 ) - { - /* Improve speed. */ - p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE ; - } + /* skip signature */ + stream_Read( p_demux->s, NULL, 4 ); /* cannot fail */ - /* a little test to see if it's a wav file */ - if( input_Peek( p_input, &p_peek, 24 ) < 24 ) + /* read header */ + if( stream_Read( p_demux->s, hdr, 20 ) < 20 ) { - msg_Warn( p_input, "AU plugin discarded (cannot peek)" ); - return( -1 ); + msg_Err( p_demux, "cannot read" ); + return VLC_EGENERIC; } - /* read header */ - if( strcmp( p_peek, ".snd" ) ) + if( GetDWBE( &hdr[0] ) < 24 ) { - msg_Warn( p_input, "AU plugin discarded (not a valid file)" ); - return( VLC_EGENERIC ); + msg_Err( p_demux, "invalid file" ); + return VLC_EGENERIC; } - au.i_header_size = GetDWBE( &p_peek[0x04] ); - au.i_data_size = GetDWBE( &p_peek[0x08] ); - au.i_encoding = GetDWBE( &p_peek[0x0c] ); - au.i_sample_rate = GetDWBE( &p_peek[0x10] ); - au.i_channels = GetDWBE( &p_peek[0x14] ); - msg_Dbg( p_input, - "au file: header_size=%d data_size=%d encoding=0x%x sample_rate=%d channels=%d", - au.i_header_size, - au.i_data_size, - au.i_encoding, - au.i_sample_rate, - au.i_channels ); - if( au.i_header_size < 24 ) + + DEMUX_INIT_COMMON(); p_sys = p_demux->p_sys; + p_sys->i_time = 0; + p_sys->i_header_size = GetDWBE( &hdr[0] ); + + /* skip extra header data */ + if( p_sys->i_header_size > 24 ) { - msg_Warn( p_input, "AU plugin discarded (not a valid file)" ); - return( VLC_EGENERIC ); + stream_Read( p_demux->s, NULL, p_sys->i_header_size - 24 ); } - /* Create WAVEFORMATEX structure */ - wf.nChannels = au.i_channels; - wf.nSamplesPerSec= au.i_sample_rate; - wf.cbSize = 0; - - switch( au.i_encoding ) + /* init fmt */ + es_format_Init( &p_sys->fmt, AUDIO_ES, 0 ); + p_sys->fmt.audio.i_rate = GetDWBE( &hdr[12] ); + p_sys->fmt.audio.i_channels = GetDWBE( &hdr[16] ); + +#if 0 + p_sys->au.i_header_size = GetDWBE( &p_sys->au.i_header_size ); + p_sys->au.i_data_size = GetDWBE( &p_sys->au.i_data_size ); + p_sys->au.i_encoding = GetDWBE( &p_sys->au.i_encoding ); + p_sys->au.i_sample_rate = GetDWBE( &p_sys->au.i_sample_rate ); + p_sys->au.i_channels = GetDWBE( &p_sys->au.i_channels ); +#endif + switch( GetDWBE( &hdr[8] ) ) { - case AUDIO_FILE_ENCODING_MULAW_8: /* 8-bit ISDN u-law */ - wf.wFormatTag = WAVE_FORMAT_MULAW; // FIXME ?? - wf.wBitsPerSample = 8; - wf.nBlockAlign = 1 * wf.nChannels; - i_codec = VLC_FOURCC( 'u','l','a','w' ); + case AU_ALAW_8: /* 8-bit ISDN A-law */ + p_sys->fmt.i_codec = VLC_CODEC_ALAW; + p_sys->fmt.audio.i_bitspersample = 8; + p_sys->fmt.audio.i_blockalign = 1 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_PCM; break; - case AUDIO_FILE_ENCODING_LINEAR_8: /* 8-bit linear PCM */ - wf.wFormatTag = WAVE_FORMAT_PCM; - wf.wBitsPerSample = 8; - wf.nBlockAlign = 1 * wf.nChannels; - i_codec = VLC_FOURCC( 't','w','o','s' ); + + case AU_MULAW_8: /* 8-bit ISDN u-law */ + p_sys->fmt.i_codec = VLC_CODEC_MULAW; + p_sys->fmt.audio.i_bitspersample = 8; + p_sys->fmt.audio.i_blockalign = 1 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_PCM; break; - case AUDIO_FILE_ENCODING_LINEAR_16: /* 16-bit linear PCM */ - wf.wFormatTag = WAVE_FORMAT_PCM; - wf.wBitsPerSample = 16; - wf.nBlockAlign = 2 * wf.nChannels; - i_codec = VLC_FOURCC( 't','w','o','s' ); + case AU_LINEAR_8: /* 8-bit linear PCM */ + p_sys->fmt.i_codec = VLC_FOURCC( 't','w','o','s' ); + p_sys->fmt.audio.i_bitspersample = 8; + p_sys->fmt.audio.i_blockalign = 1 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_PCM; break; - case AUDIO_FILE_ENCODING_LINEAR_24: /* 24-bit linear PCM */ - wf.wFormatTag = WAVE_FORMAT_PCM; - wf.wBitsPerSample = 24; - wf.nBlockAlign = 3 * wf.nChannels; - i_codec = VLC_FOURCC( 't','w','o','s' ); + case AU_LINEAR_16: /* 16-bit linear PCM */ + p_sys->fmt.i_codec = VLC_FOURCC( 't','w','o','s' ); + p_sys->fmt.audio.i_bitspersample = 16; + p_sys->fmt.audio.i_blockalign = 2 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_PCM; break; - case AUDIO_FILE_ENCODING_LINEAR_32: /* 32-bit linear PCM */ - wf.wFormatTag = WAVE_FORMAT_PCM; - wf.wBitsPerSample = 32; - wf.nBlockAlign = 4 * wf.nChannels; - i_codec = VLC_FOURCC( 't','w','o','s' ); + case AU_LINEAR_24: /* 24-bit linear PCM */ + p_sys->fmt.i_codec = VLC_FOURCC( 't','w','o','s' ); + p_sys->fmt.audio.i_bitspersample = 24; + p_sys->fmt.audio.i_blockalign = 3 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_PCM; break; - case AUDIO_FILE_ENCODING_FLOAT: /* 32-bit IEEE floating point */ - wf.wFormatTag = WAVE_FORMAT_UNKNOWN; - wf.wBitsPerSample = 32; - wf.nBlockAlign = 4 * wf.nChannels; - i_codec = VLC_FOURCC( 'a', 'u', 0, AUDIO_FILE_ENCODING_FLOAT ); + case AU_LINEAR_32: /* 32-bit linear PCM */ + p_sys->fmt.i_codec = VLC_FOURCC( 't','w','o','s' ); + p_sys->fmt.audio.i_bitspersample = 32; + p_sys->fmt.audio.i_blockalign = 4 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_PCM; break; - case AUDIO_FILE_ENCODING_DOUBLE: /* 64-bit IEEE floating point */ - wf.wFormatTag = WAVE_FORMAT_UNKNOWN; - wf.wBitsPerSample = 64; - wf.nBlockAlign = 8 * wf.nChannels; - i_codec = VLC_FOURCC( 'a', 'u', 0, AUDIO_FILE_ENCODING_DOUBLE ); + case AU_FLOAT: /* 32-bit IEEE floating point */ + p_sys->fmt.i_codec = VLC_FOURCC( 'a', 'u', 0, AU_FLOAT ); + p_sys->fmt.audio.i_bitspersample = 32; + p_sys->fmt.audio.i_blockalign = 4 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_PCM; break; - case AUDIO_FILE_ENCODING_ADPCM_G721: /* 4-bit CCITT g.721 ADPCM */ - wf.wFormatTag = WAVE_FORMAT_UNKNOWN; - wf.wBitsPerSample = 0; - wf.nBlockAlign = 0 * wf.nChannels; - i_codec = VLC_FOURCC( 'a', 'u', 0, AUDIO_FILE_ENCODING_ADPCM_G721 ); + case AU_DOUBLE: /* 64-bit IEEE floating point */ + p_sys->fmt.i_codec = VLC_FOURCC( 'a', 'u', 0, AU_DOUBLE ); + p_sys->fmt.audio.i_bitspersample = 64; + p_sys->fmt.audio.i_blockalign = 8 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_PCM; break; - case AUDIO_FILE_ENCODING_ADPCM_G722: /* CCITT g.722 ADPCM */ - wf.wFormatTag = WAVE_FORMAT_UNKNOWN; - wf.wBitsPerSample = 0; - wf.nBlockAlign = 0 * wf.nChannels; - i_codec = VLC_FOURCC( 'a', 'u', 0, AUDIO_FILE_ENCODING_ADPCM_G722 ); + case AU_ADPCM_G721: /* 4-bit CCITT g.721 ADPCM */ + p_sys->fmt.i_codec = VLC_FOURCC( 'a', 'u', 0, AU_ADPCM_G721 ); + p_sys->fmt.audio.i_bitspersample = 0; + p_sys->fmt.audio.i_blockalign = 0 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_ADPCM; break; - case AUDIO_FILE_ENCODING_ADPCM_G723_3: /* CCITT g.723 3-bit ADPCM */ - wf.wFormatTag = WAVE_FORMAT_UNKNOWN; - wf.wBitsPerSample = 0; - wf.nBlockAlign = 0 * wf.nChannels; - i_codec = VLC_FOURCC( 'a', 'u', 0, AUDIO_FILE_ENCODING_ADPCM_G723_3 ); + case AU_ADPCM_G722: /* CCITT g.722 ADPCM */ + p_sys->fmt.i_codec = VLC_FOURCC( 'a', 'u', 0, AU_ADPCM_G722 ); + p_sys->fmt.audio.i_bitspersample = 0; + p_sys->fmt.audio.i_blockalign = 0 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_ADPCM; break; - case AUDIO_FILE_ENCODING_ADPCM_G723_5: /* CCITT g.723 5-bit ADPCM */ - wf.wFormatTag = WAVE_FORMAT_UNKNOWN; - wf.wBitsPerSample = 0; - wf.nBlockAlign = 0 * wf.nChannels; - i_codec = VLC_FOURCC( 'a', 'u', 0, AUDIO_FILE_ENCODING_ADPCM_G723_5 ); + case AU_ADPCM_G723_3: /* CCITT g.723 3-bit ADPCM */ + p_sys->fmt.i_codec = VLC_FOURCC( 'a', 'u', 0, AU_ADPCM_G723_3 ); + p_sys->fmt.audio.i_bitspersample = 0; + p_sys->fmt.audio.i_blockalign = 0 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_ADPCM; break; - case AUDIO_FILE_ENCODING_ALAW_8: /* 8-bit ISDN A-law */ - wf.wFormatTag = WAVE_FORMAT_ALAW; // FIXME ?? - wf.wBitsPerSample = 8; - wf.nBlockAlign = 1 * wf.nChannels; - i_codec = VLC_FOURCC( 'a','l','a','w' ); + case AU_ADPCM_G723_5: /* CCITT g.723 5-bit ADPCM */ + p_sys->fmt.i_codec = VLC_FOURCC( 'a', 'u', 0, AU_ADPCM_G723_5 ); + p_sys->fmt.audio.i_bitspersample = 0; + p_sys->fmt.audio.i_blockalign = 0 * p_sys->fmt.audio.i_channels; + i_cat = AU_CAT_ADPCM; break; default: - msg_Warn( p_input, "unknow encoding=0x%x", au.i_encoding ); - wf.wFormatTag = WAVE_FORMAT_UNKNOWN; - wf.wBitsPerSample = 0; - wf.nBlockAlign = 0 * wf.nChannels; - i_codec = VLC_FOURCC( 'a','u', 0, au.i_encoding ); + msg_Warn( p_demux, "unknow encoding=0x%x", GetDWBE( &hdr[8] ) ); + p_sys->fmt.audio.i_bitspersample = 0; + p_sys->fmt.audio.i_blockalign = 0; + i_cat = AU_CAT_UNKNOWN; break; } - wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nChannels * wf.wBitsPerSample / 8; - - /* create one program */ - vlc_mutex_lock( &p_input->stream.stream_lock ); - if( input_InitStream( p_input, 0 ) == -1) - { - vlc_mutex_unlock( &p_input->stream.stream_lock ); - msg_Err( p_input, "cannot init stream" ); - return( VLC_EGENERIC ); - } - if( input_AddProgram( p_input, 0, 0) == NULL ) - { - vlc_mutex_unlock( &p_input->stream.stream_lock ); - msg_Err( p_input, "cannot add program" ); - return( VLC_EGENERIC ); - } - - p_input->stream.p_selected_program = p_input->stream.pp_programs[0]; - p_input->stream.i_mux_rate = wf.nAvgBytesPerSec / 50; - p_es = input_AddES( p_input, - p_input->stream.p_selected_program, - 0x01, - 0 ); + p_sys->fmt.i_bitrate = p_sys->fmt.audio.i_rate * + p_sys->fmt.audio.i_channels * + p_sys->fmt.audio.i_bitspersample; - p_es->i_stream_id = 0x01; - p_es->i_cat = AUDIO_ES; - p_es->i_fourcc = i_codec; - p_es->p_waveformatex= malloc( sizeof( WAVEFORMATEX ) ); - memcpy( p_es->p_waveformatex, - &wf, - sizeof( WAVEFORMATEX ) ); - - input_SelectES( p_input, p_es ); - p_input->stream.p_selected_program->b_is_ok = 1; - vlc_mutex_unlock( &p_input->stream.stream_lock ); - - /* create our structure that will contains all data */ - if( ( p_demux = malloc( sizeof( demux_sys_t ) ) ) == NULL ) - { - msg_Err( p_input, "out of memory" ); - return( VLC_EGENERIC ); - } - p_demux->p_es = p_es; - p_demux->i_time = 0; - memcpy( &p_demux->au, &au, sizeof( au_t ) ); - memcpy( &p_demux->wf, &wf, sizeof( WAVEFORMATEX ) ); - switch( au.i_encoding ) + if( i_cat == AU_CAT_UNKNOWN || i_cat == AU_CAT_ADPCM ) { - case AUDIO_FILE_ENCODING_MULAW_8: - case AUDIO_FILE_ENCODING_LINEAR_8: - case AUDIO_FILE_ENCODING_LINEAR_16: - case AUDIO_FILE_ENCODING_LINEAR_24: - case AUDIO_FILE_ENCODING_LINEAR_32: - case AUDIO_FILE_ENCODING_FLOAT: - case AUDIO_FILE_ENCODING_DOUBLE: - case AUDIO_FILE_ENCODING_ALAW_8: - p_demux->i_demux = AU_DEMUX_PCM; - break; - - case AUDIO_FILE_ENCODING_ADPCM_G721: - case AUDIO_FILE_ENCODING_ADPCM_G722: - case AUDIO_FILE_ENCODING_ADPCM_G723_3: - case AUDIO_FILE_ENCODING_ADPCM_G723_5: - p_demux->i_demux = AU_DEMUX_ADPCM; - break; + p_sys->i_frame_size = 0; + p_sys->i_frame_length = 0; - default: - p_demux->i_demux = 0; - break; + msg_Err( p_demux, "unsupported codec/type (Please report it)" ); + free( p_sys ); + return VLC_EGENERIC; } - p_input->p_demux_data = p_demux; - p_input->pf_demux = AUDemux; + /* add the es */ + p_sys->es = es_out_Add( p_demux->out, &p_sys->fmt ); - /* skip header*/ - SkipBytes( p_input, au.i_header_size ); + /* calculate 50ms frame size/time */ + i_samples = __MAX( p_sys->fmt.audio.i_rate / 20, 1 ); + p_sys->i_frame_size = i_samples * p_sys->fmt.audio.i_channels * + ( (p_sys->fmt.audio.i_bitspersample + 7) / 8 ); + if( p_sys->fmt.audio.i_blockalign > 0 ) + { + if( ( i_modulo = p_sys->i_frame_size % p_sys->fmt.audio.i_blockalign ) != 0 ) + { + p_sys->i_frame_size += p_sys->fmt.audio.i_blockalign - i_modulo; + } + } + p_sys->i_frame_length = (mtime_t)1000000 * + (mtime_t)i_samples / + (mtime_t)p_sys->fmt.audio.i_rate; - return( VLC_SUCCESS ); + return VLC_SUCCESS; } /***************************************************************************** - * AUDemux: read packet and send them to decoders + * Demux: read packet and send them to decoders ***************************************************************************** * Returns -1 in case of error, 0 in case of EOF, 1 otherwise *****************************************************************************/ -static int AUDemux( input_thread_t *p_input ) +static int Demux( demux_t *p_demux ) { - demux_sys_t *p_demux = p_input->p_demux_data; - - if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT ) - { - off_t i_offset; - - i_offset = TellAbsolute( p_input ) - p_demux->au.i_header_size; - if( i_offset < 0 ) - { - i_offset = 0; - } - if( p_demux->wf.nBlockAlign != 0 ) - { - i_offset += p_demux->wf.nBlockAlign - - i_offset % p_demux->wf.nBlockAlign; - } - SeekAbsolute( p_input, p_demux->au.i_header_size + i_offset ); - } + demux_sys_t *p_sys = p_demux->p_sys; + block_t *p_block; - input_ClockManageRef( p_input, - p_input->stream.p_selected_program, - p_demux->i_time * 9 / 100 ); + /* set PCR */ + es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_time ); - switch( p_demux->i_demux ) + if( ( p_block = stream_Block( p_demux->s, p_sys->i_frame_size ) ) == NULL ) { - case AU_DEMUX_PCM: - return( AUDemuxPCM( p_input ) ); - case AU_DEMUX_ADPCM: - default: - msg_Err( p_input, "Internal error (p_demux->i_demux invalid/unsported)" ); - return( 0 ); + msg_Warn( p_demux, "cannot read data" ); + return 0; } -} -static int AUDemuxPCM( input_thread_t *p_input ) -{ - demux_sys_t *p_demux = p_input->p_demux_data; - pes_packet_t *p_pes; - - int i_samples; - - int i_bytes; - int i_modulo; - - /* read samples for 50ms of */ - i_samples = __MAX( p_demux->wf.nSamplesPerSec / 20, 1 ); - + p_block->i_dts = + p_block->i_pts = VLC_TS_0 + p_sys->i_time; - i_bytes = i_samples * p_demux->wf.nChannels * ( (p_demux->wf.wBitsPerSample + 7) / 8 ); + es_out_Send( p_demux->out, p_sys->es, p_block ); - if( p_demux->wf.nBlockAlign > 0 ) - { - if( ( i_modulo = i_bytes % p_demux->wf.nBlockAlign ) != 0 ) - { - i_bytes += p_demux->wf.nBlockAlign - i_modulo; - } - } - - if( ReadPES( p_input, &p_pes, i_bytes ) ) - { - msg_Warn( p_input, "failed to get one frame" ); - return( 0 ); - } - - p_pes->i_dts = - p_pes->i_pts = input_ClockGetTS( p_input, - p_input->stream.p_selected_program, - p_demux->i_time * 9 / 100 ); + p_sys->i_time += p_sys->i_frame_length; - if( !p_demux->p_es->p_decoder_fifo ) - { - msg_Err( p_input, "no audio decoder" ); - input_DeletePES( p_input->p_method_data, p_pes ); - return( -1 ); - } - else - { - input_DecodePES( p_demux->p_es->p_decoder_fifo, p_pes ); - } + return 1; +} - p_demux->i_time += (mtime_t)1000000 * - (mtime_t)i_samples / - (mtime_t)p_demux->wf.nSamplesPerSec; +/***************************************************************************** + * Close: frees unused data + *****************************************************************************/ +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; - return( 1 ); + free( p_sys ); } /***************************************************************************** - * AUEnd: frees unused data + * Control: *****************************************************************************/ -static void AUEnd ( vlc_object_t * p_this ) +static int Control( demux_t *p_demux, int i_query, va_list args ) { - input_thread_t * p_input = (input_thread_t *)p_this; + demux_sys_t *p_sys = p_demux->p_sys; - FREE( p_input->p_demux_data ); + return demux_vaControlHelper( p_demux->s, p_sys->i_header_size, -1, + p_sys->fmt.i_bitrate, p_sys->fmt.audio.i_blockalign, + i_query, args ); }