X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Faraw.c;h=30c7d15d561b86bf0c8763d73f78c276f3a978e8;hb=8b69f37b61ff8a729ace73b2ee16fe29d877f7a6;hp=de370d2c3f4da163b65c59db4ca03eda244f5f52;hpb=2cb472dba008f7d877ffe6bae9c5575253365282;p=vlc diff --git a/modules/codec/araw.c b/modules/codec/araw.c index de370d2c3f..30c7d15d56 100644 --- a/modules/codec/araw.c +++ b/modules/codec/araw.c @@ -24,8 +24,14 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include /***************************************************************************** * Module descriptor @@ -38,22 +44,22 @@ static int EncoderOpen ( vlc_object_t * ); static void EncoderClose( vlc_object_t * ); #endif -vlc_module_begin(); +vlc_module_begin () /* audio decoder module */ - set_description( _("Raw/Log Audio decoder") ); - set_capability( "decoder", 100 ); - set_category( CAT_INPUT ); - set_subcategory( SUBCAT_INPUT_ACODEC ); - set_callbacks( DecoderOpen, DecoderClose ); + set_description( N_("Raw/Log Audio decoder") ) + set_capability( "decoder", 100 ) + set_category( CAT_INPUT ) + set_subcategory( SUBCAT_INPUT_ACODEC ) + set_callbacks( DecoderOpen, DecoderClose ) #ifdef ENABLE_SOUT /* audio encoder submodule */ - add_submodule(); - set_description( _("Raw audio encoder") ); - set_capability( "encoder", 150 ); - set_callbacks( EncoderOpen, EncoderClose ); + add_submodule () + set_description( N_("Raw audio encoder") ) + set_capability( "encoder", 150 ) + set_callbacks( EncoderOpen, EncoderClose ) #endif -vlc_module_end(); +vlc_module_end () /***************************************************************************** * Local prototypes @@ -65,12 +71,11 @@ static block_t *EncoderEncode( encoder_t *, aout_buffer_t * ); struct decoder_sys_t { - int16_t *p_logtos16; /* used with m/alaw to int16_t */ - - audio_date_t end_date; + void (*decode) (void *, const uint8_t *, unsigned); + date_t end_date; }; -static int pi_channels_maps[] = +static const int pi_channels_maps[] = { 0, AOUT_CHAN_CENTER, @@ -90,7 +95,7 @@ static int pi_channels_maps[] = | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE }; -static int16_t ulawtos16[256] = +static const int16_t ulawtos16[256] = { -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956, -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764, @@ -126,7 +131,7 @@ static int16_t ulawtos16[256] = 56, 48, 40, 32, 24, 16, 8, 0 }; -static int16_t alawtos16[256] = +static const int16_t alawtos16[256] = { -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736, -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784, @@ -162,6 +167,11 @@ static int16_t alawtos16[256] = 944, 912, 1008, 976, 816, 784, 880, 848 }; +static void DecodeAlaw( void *, const uint8_t *, unsigned ); +static void DecodeUlaw( void *, const uint8_t *, unsigned ); +static void DecodeS20B( void *, const uint8_t *, unsigned ); +static void DecodeDAT12( void *, const uint8_t *, unsigned ); + /***************************************************************************** * DecoderOpen: probe the decoder and return score *****************************************************************************/ @@ -181,20 +191,23 @@ static int DecoderOpen( vlc_object_t *p_this ) /* _signed_ little endian samples (mov)*/ case VLC_FOURCC('s','o','w','t'): - case VLC_FOURCC('a','l','a','w'): - case VLC_FOURCC('u','l','a','w'): - case VLC_FOURCC('m','l','a','w'): - - case VLC_FOURCC('f','l','6','4'): - case VLC_FOURCC('f','l','3','2'): - case VLC_FOURCC('s','3','2','l'): - case VLC_FOURCC('s','3','2','b'): - case VLC_FOURCC('s','2','4','l'): - case VLC_FOURCC('s','2','4','b'): - case VLC_FOURCC('s','1','6','l'): - case VLC_FOURCC('s','1','6','b'): - case VLC_FOURCC('s','8',' ',' '): - case VLC_FOURCC('u','8',' ',' '): + case VLC_CODEC_ALAW: + case VLC_CODEC_MULAW: + case VLC_CODEC_DAT12: + + case VLC_CODEC_F64L: + case VLC_CODEC_F64B: + case VLC_CODEC_F32L: + case VLC_CODEC_F32B: + case VLC_CODEC_S32L: + case VLC_CODEC_S32B: + case VLC_CODEC_S24L: + case VLC_CODEC_S24B: + case VLC_CODEC_S20B: + case VLC_CODEC_S16L: + case VLC_CODEC_S16B: + case VLC_CODEC_S8: + case VLC_CODEC_U8: break; default: @@ -204,7 +217,8 @@ static int DecoderOpen( vlc_object_t *p_this ) if( p_dec->fmt_in.audio.i_channels <= 0 || p_dec->fmt_in.audio.i_channels > 8 ) { - msg_Err( p_dec, "bad channels count (1-8)" ); + msg_Err( p_dec, "bad channels count (1-8): %i", + p_dec->fmt_in.audio.i_channels ); return VLC_EGENERIC; } @@ -217,144 +231,89 @@ static int DecoderOpen( vlc_object_t *p_this ) /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) - { - msg_Err( p_dec, "out of memory" ); - return VLC_EGENERIC; - } + return VLC_ENOMEM; - p_sys->p_logtos16 = NULL; + p_sys->decode = NULL; msg_Dbg( p_dec, "samplerate:%dHz channels:%d bits/sample:%d", p_dec->fmt_in.audio.i_rate, p_dec->fmt_in.audio.i_channels, p_dec->fmt_in.audio.i_bitspersample ); - if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'f', 'l', '6', '4' ) ) + if( p_dec->fmt_in.i_codec == VLC_CODEC_F64L || + p_dec->fmt_in.i_codec == VLC_CODEC_F64B ) { p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec; p_dec->fmt_in.audio.i_bitspersample = 64; } - else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'f', 'l', '3', '2' ) ) + else if( p_dec->fmt_in.i_codec == VLC_CODEC_F32L || + p_dec->fmt_in.i_codec == VLC_CODEC_F32B ) { p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec; p_dec->fmt_in.audio.i_bitspersample = 32; } - else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 's', '3', '2', 'l' ) || - p_dec->fmt_in.i_codec == VLC_FOURCC( 's', '3', '2', 'b' ) ) + else if( p_dec->fmt_in.i_codec == VLC_CODEC_S32L || + p_dec->fmt_in.i_codec == VLC_CODEC_S32B ) { p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec; p_dec->fmt_in.audio.i_bitspersample = 32; } - else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 's', '2', '4', 'l' ) || - p_dec->fmt_in.i_codec == VLC_FOURCC( 's', '2', '4', 'b' ) ) + else if( p_dec->fmt_in.i_codec == VLC_CODEC_S24L || + p_dec->fmt_in.i_codec == VLC_CODEC_S24B ) { p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec; p_dec->fmt_in.audio.i_bitspersample = 24; } - else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 's', '1', '6', 'l' ) || - p_dec->fmt_in.i_codec == VLC_FOURCC( 's', '1', '6', 'b' ) ) + else if( p_dec->fmt_in.i_codec == VLC_CODEC_S20B ) + { + p_dec->fmt_out.i_codec = VLC_CODEC_S32N; + p_dec->fmt_out.audio.i_bitspersample = 32; + p_sys->decode = DecodeS20B; + p_dec->fmt_in.audio.i_bitspersample = 20; + } + else if( p_dec->fmt_in.i_codec == VLC_CODEC_S16L || + p_dec->fmt_in.i_codec == VLC_CODEC_S16B ) { p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec; p_dec->fmt_in.audio.i_bitspersample = 16; } - else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 's', '8', ' ', ' ' ) || - p_dec->fmt_in.i_codec == VLC_FOURCC( 'u', '8', ' ', ' ' ) ) + else if( p_dec->fmt_in.i_codec == VLC_CODEC_DAT12 ) { - p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec; - p_dec->fmt_in.audio.i_bitspersample = 8; + p_dec->fmt_out.i_codec = VLC_CODEC_S16N; + p_dec->fmt_out.audio.i_bitspersample = 16; + p_sys->decode = DecodeDAT12; + p_dec->fmt_in.audio.i_bitspersample = 12; } - else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'f', 'l', 't' ) ) + else if( p_dec->fmt_in.i_codec == VLC_CODEC_S8 || + p_dec->fmt_in.i_codec == VLC_CODEC_U8 ) { - switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 ) - { - case 4: - p_dec->fmt_out.i_codec = VLC_FOURCC('f','l','3','2'); - break; - case 8: - p_dec->fmt_out.i_codec = VLC_FOURCC('f','l','6','4'); - break; - default: - msg_Err( p_dec, "bad parameters(bits/sample)" ); - return VLC_EGENERIC; - } + p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec; + p_dec->fmt_in.audio.i_bitspersample = 8; } - else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'r', 'a', 'w' ) || - p_dec->fmt_in.i_codec == VLC_FOURCC( 'p', 'c', 'm', ' ' ) ) + else if( p_dec->fmt_in.i_codec == VLC_CODEC_ALAW ) { - switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 ) - { - case 1: - p_dec->fmt_out.i_codec = VLC_FOURCC('u','8',' ',' '); - break; - case 2: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l'); - break; - case 3: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l'); - break; - case 4: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l'); - break; - default: - msg_Err( p_dec, "bad parameters(bits/sample)" ); - return VLC_EGENERIC; - } + p_dec->fmt_out.i_codec = VLC_CODEC_S16N; + p_dec->fmt_out.audio.i_bitspersample = 16; + p_sys->decode = DecodeAlaw; + p_dec->fmt_in.audio.i_bitspersample = 8; } - else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 't', 'w', 'o', 's' ) ) + else if( p_dec->fmt_in.i_codec == VLC_CODEC_MULAW ) { - switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 ) - { - case 1: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' '); - break; - case 2: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','b'); - break; - case 3: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','b'); - break; - case 4: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','b'); - break; - default: - msg_Err( p_dec, "bad parameters(bits/sample)" ); - return VLC_EGENERIC; - } + p_dec->fmt_out.i_codec = VLC_CODEC_S16N; + p_dec->fmt_out.audio.i_bitspersample = 16; + p_sys->decode = DecodeUlaw; + p_dec->fmt_in.audio.i_bitspersample = 8; } - else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 's', 'o', 'w', 't' ) ) + else { - switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 ) + p_dec->fmt_out.i_codec = + vlc_fourcc_GetCodecAudio( p_dec->fmt_in.i_codec, + p_dec->fmt_in.audio.i_bitspersample ); + if( !p_dec->fmt_out.i_codec ) { - case 1: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' '); - break; - case 2: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l'); - break; - case 3: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l'); - break; - case 4: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l'); - break; - default: msg_Err( p_dec, "bad parameters(bits/sample)" ); return VLC_EGENERIC; } } - else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'l', 'a', 'w' ) ) - { - p_dec->fmt_out.i_codec = AOUT_FMT_S16_NE; - p_sys->p_logtos16 = alawtos16; - p_dec->fmt_in.audio.i_bitspersample = 8; - } - else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'u', 'l', 'a', 'w' ) || - p_dec->fmt_in.i_codec == VLC_FOURCC( 'm', 'l', 'a', 'w' ) ) - { - p_dec->fmt_out.i_codec = AOUT_FMT_S16_NE; - p_sys->p_logtos16 = ulawtos16; - p_dec->fmt_in.audio.i_bitspersample = 8; - } - else return VLC_EGENERIC; /* Set output properties */ p_dec->fmt_out.i_cat = AUDIO_ES; @@ -371,15 +330,8 @@ static int DecoderOpen( vlc_object_t *p_this ) p_dec->fmt_out.audio.i_original_channels = p_dec->fmt_in.audio.i_original_channels; - if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'l', 'a', 'w' ) || - p_dec->fmt_in.i_codec == VLC_FOURCC( 'u', 'l', 'a', 'w' ) || - p_dec->fmt_in.i_codec == VLC_FOURCC( 'm', 'l', 'a', 'w' ) ) - { - p_dec->fmt_out.audio.i_bitspersample = 16; - } - - aout_DateInit( &p_sys->end_date, p_dec->fmt_out.audio.i_rate ); - aout_DateSet( &p_sys->end_date, 0 ); + date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 ); + date_Set( &p_sys->end_date, 0 ); p_dec->pf_decode_audio = DecodeBlock; @@ -394,20 +346,17 @@ static int DecoderOpen( vlc_object_t *p_this ) static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) { decoder_sys_t *p_sys = p_dec->p_sys; - block_t *p_block; - aout_buffer_t *p_out; - int i_samples; if( !pp_block || !*pp_block ) return NULL; - p_block = *pp_block; + block_t *p_block = *pp_block; - if( p_block->i_pts != 0 && - p_block->i_pts != aout_DateGet( &p_sys->end_date ) ) + if( p_block->i_pts > VLC_TS_INVALID && + p_block->i_pts != date_Get( &p_sys->end_date ) ) { - aout_DateSet( &p_sys->end_date, p_block->i_pts ); + date_Set( &p_sys->end_date, p_block->i_pts ); } - else if( !aout_DateGet( &p_sys->end_date ) ) + else if( !date_Get( &p_sys->end_date ) ) { /* We've just started the stream, wait for the first PTS. */ block_Release( p_block ); @@ -415,49 +364,105 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) } /* Don't re-use the same pts twice */ - p_block->i_pts = 0; + p_block->i_pts = VLC_TS_INVALID; - i_samples = p_block->i_buffer * 8 / p_dec->fmt_in.audio.i_bitspersample / - p_dec->fmt_in.audio.i_channels; - - if( i_samples <= 0 ) + const unsigned framebits = + p_dec->fmt_in.audio.i_bitspersample * p_dec->fmt_in.audio.i_channels; + unsigned samples = (8 * p_block->i_buffer) / framebits; + if( samples == 0 ) { block_Release( p_block ); return NULL; } /* Create chunks of max 1024 samples */ - i_samples = __MIN( i_samples, 1024 ); + if( samples > 1024 ) samples = 1024; - p_out = p_dec->pf_aout_buffer_new( p_dec, i_samples ); + block_t *p_out = decoder_NewAudioBuffer( p_dec, samples ); if( p_out == NULL ) { block_Release( p_block ); return NULL; } - p_out->start_date = aout_DateGet( &p_sys->end_date ); - p_out->end_date = aout_DateIncrement( &p_sys->end_date, i_samples ); + p_out->i_pts = date_Get( &p_sys->end_date ); + p_out->i_length = date_Increment( &p_sys->end_date, samples ) + - p_out->i_pts; - if( p_sys->p_logtos16 ) - { - int16_t *s = (int16_t*)p_out->p_buffer; - unsigned int i; + if( p_sys->decode != NULL ) + p_sys->decode( p_out->p_buffer, p_block->p_buffer, + samples * p_dec->fmt_in.audio.i_channels ); + else + memcpy( p_out->p_buffer, p_block->p_buffer, p_out->i_buffer ); - for( i = 0; i < p_out->i_nb_bytes / 2; i++ ) - { - *s++ = p_sys->p_logtos16[*p_block->p_buffer++]; - p_block->i_buffer--; - } + samples = (samples * framebits) / 8; + p_block->p_buffer += samples; + p_block->i_buffer -= samples; + + return p_out; +} + +static void DecodeAlaw( void *outp, const uint8_t *in, unsigned samples ) +{ + int16_t *out = outp; + + for( unsigned i = 0; i < samples; i++ ) + *(out++) = alawtos16[*(in++)]; +} + +static void DecodeUlaw( void *outp, const uint8_t *in, unsigned samples ) +{ + int16_t *out = outp; + + for( unsigned i = 0; i < samples; i++ ) + *(out++) = ulawtos16[*(in++)]; +} + +static void DecodeS20B( void *outp, const uint8_t *in, unsigned samples ) +{ + int32_t *out = outp; + + while( samples >= 2 ) + { + uint32_t dw = U32_AT(in); + in += 4; + *(out++) = dw & ~0xFFF; + *(out++) = (dw << 20) | (*in << 12); + in++; + samples -= 2; } - else + + /* No U32_AT() for the last odd sample: avoid off-by-one overflow! */ + if( samples ) + *(out++) = (U16_AT(in) << 16) | ((in[2] & 0xF0) << 8); +} + +static int16_t dat12tos16( uint16_t y ) +{ + static const uint16_t diff[16] = { + 0x0000, 0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, + 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0x1000, 0x1000 }; + static const uint8_t shift[16] = { + 0, 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0, 0 }; + + int d = y >> 8; + return (y - diff[d]) << shift[d]; +} + +static void DecodeDAT12( void *outp, const uint8_t *in, unsigned samples ) +{ + int32_t *out = outp; + + while( samples >= 2 ) { - memcpy( p_out->p_buffer, p_block->p_buffer, p_out->i_nb_bytes ); - p_block->p_buffer += p_out->i_nb_bytes; - p_block->i_buffer -= p_out->i_nb_bytes; + *(out++) = dat12tos16(U16_AT(in) >> 4); + *(out++) = dat12tos16(U16_AT(in + 1) & ~0xF000); + in += 3; + samples -= 2; } - return p_out; + if( samples ) + *(out++) = dat12tos16(U16_AT(in) >> 4); } /***************************************************************************** @@ -482,7 +487,7 @@ struct encoder_sys_t int i_s16tolog; /* used with int16_t to m/alaw */ }; -static int8_t alaw_encode[2049] = +static const int8_t alaw_encode[2049] = { 0xD5, 0xD4, 0xD7, 0xD6, 0xD1, 0xD0, 0xD3, 0xD2, 0xDD, 0xDC, 0xDF, 0xDE, 0xD9, 0xD8, 0xDB, 0xDA, 0xC5, 0xC4, 0xC7, 0xC6, 0xC1, 0xC0, 0xC3, 0xC2, @@ -657,7 +662,7 @@ static int8_t alaw_encode[2049] = 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x2A }; /* alaw_encode */ -static int8_t ulaw_encode[8193] = +static const int8_t ulaw_encode[8193] = { 0xFF, 0xFE, 0xFE, 0xFD, 0xFD, 0xFC, 0xFC, 0xFB, 0xFB, 0xFA, 0xFA, 0xF9, 0xF9, 0xF8, 0xF8, 0xF7, 0xF7, 0xF6, 0xF6, 0xF5, 0xF5, 0xF4, 0xF4, 0xF3, @@ -1352,38 +1357,37 @@ static int EncoderOpen( vlc_object_t *p_this ) encoder_t *p_enc = (encoder_t *)p_this; encoder_sys_t *p_sys; - if( p_enc->fmt_out.i_codec == VLC_FOURCC('u','8',' ',' ') || - p_enc->fmt_out.i_codec == VLC_FOURCC('s','8',' ',' ') || - p_enc->fmt_out.i_codec == VLC_FOURCC('a','l','a','w') || - p_enc->fmt_out.i_codec == VLC_FOURCC('u','l','a','w') || - p_enc->fmt_out.i_codec == VLC_FOURCC('m','l','a','w')) + if( p_enc->fmt_out.i_codec == VLC_CODEC_U8 || + p_enc->fmt_out.i_codec == VLC_CODEC_S8 || + p_enc->fmt_out.i_codec == VLC_CODEC_ALAW || + p_enc->fmt_out.i_codec == VLC_CODEC_MULAW) { p_enc->fmt_out.audio.i_bitspersample = 8; } - else if( p_enc->fmt_out.i_codec == VLC_FOURCC('u','1','6','l') || - p_enc->fmt_out.i_codec == VLC_FOURCC('u','1','6','b') || - p_enc->fmt_out.i_codec == VLC_FOURCC('s','1','6','l') || - p_enc->fmt_out.i_codec == VLC_FOURCC('s','1','6','b') ) + else if( p_enc->fmt_out.i_codec == VLC_CODEC_U16L || + p_enc->fmt_out.i_codec == VLC_CODEC_U16B || + p_enc->fmt_out.i_codec == VLC_CODEC_S16L || + p_enc->fmt_out.i_codec == VLC_CODEC_S16B ) { p_enc->fmt_out.audio.i_bitspersample = 16; } - else if( p_enc->fmt_out.i_codec == VLC_FOURCC('u','2','4','l') || - p_enc->fmt_out.i_codec == VLC_FOURCC('u','2','4','b') || - p_enc->fmt_out.i_codec == VLC_FOURCC('s','2','4','l') || - p_enc->fmt_out.i_codec == VLC_FOURCC('s','2','4','b') ) + else if( p_enc->fmt_out.i_codec == VLC_CODEC_U24L || + p_enc->fmt_out.i_codec == VLC_CODEC_U24B || + p_enc->fmt_out.i_codec == VLC_CODEC_S24L || + p_enc->fmt_out.i_codec == VLC_CODEC_S24B ) { p_enc->fmt_out.audio.i_bitspersample = 24; } - else if( p_enc->fmt_out.i_codec == VLC_FOURCC('u','3','2','l') || - p_enc->fmt_out.i_codec == VLC_FOURCC('u','3','2','b') || - p_enc->fmt_out.i_codec == VLC_FOURCC('s','3','2','l') || - p_enc->fmt_out.i_codec == VLC_FOURCC('s','3','2','b') || - p_enc->fmt_out.i_codec == VLC_FOURCC('f','i','3','2') || - p_enc->fmt_out.i_codec == VLC_FOURCC('f','l','3','2') ) + else if( p_enc->fmt_out.i_codec == VLC_CODEC_U32L || + p_enc->fmt_out.i_codec == VLC_CODEC_U32B || + p_enc->fmt_out.i_codec == VLC_CODEC_S32L || + p_enc->fmt_out.i_codec == VLC_CODEC_S32B || + p_enc->fmt_out.i_codec == VLC_CODEC_FI32 || + p_enc->fmt_out.i_codec == VLC_CODEC_FL32 ) { p_enc->fmt_out.audio.i_bitspersample = 32; } - else if( p_enc->fmt_out.i_codec == VLC_FOURCC('f','l','6','4') ) + else if( p_enc->fmt_out.i_codec == VLC_CODEC_FL64 ) { p_enc->fmt_out.audio.i_bitspersample = 64; } @@ -1395,29 +1399,30 @@ static int EncoderOpen( vlc_object_t *p_this ) /* Allocate the memory needed to store the encoder's structure */ if( ( p_enc->p_sys = p_sys = (encoder_sys_t *)malloc(sizeof(encoder_sys_t)) ) == NULL ) - { - msg_Err( p_enc, "out of memory" ); - return VLC_EGENERIC; - } + return VLC_ENOMEM; p_enc->pf_encode_audio = EncoderEncode; p_enc->fmt_in.i_codec = p_enc->fmt_out.i_codec; p_sys->i_s16tolog = 0; - if( p_enc->fmt_out.i_codec == VLC_FOURCC( 'a', 'l', 'a', 'w' )) + if( p_enc->fmt_out.i_codec == VLC_CODEC_ALAW) { p_enc->fmt_in.audio.i_bitspersample = 16; - p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE; + p_enc->fmt_in.i_codec = VLC_CODEC_S16N; p_sys->i_s16tolog = ALAW; } - else if( p_enc->fmt_out.i_codec == VLC_FOURCC( 'u', 'l', 'a', 'w' ) || - p_enc->fmt_out.i_codec == VLC_FOURCC( 'm', 'l', 'a', 'w' ) ) + else if( p_enc->fmt_out.i_codec == VLC_CODEC_MULAW ) { p_enc->fmt_in.audio.i_bitspersample = 16; - p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE; + p_enc->fmt_in.i_codec = VLC_CODEC_S16N; p_sys->i_s16tolog = ULAW; } + p_enc->fmt_out.i_bitrate = + p_enc->fmt_in.audio.i_channels * + p_enc->fmt_in.audio.i_rate * + p_enc->fmt_in.audio.i_bitspersample; + msg_Dbg( p_enc, "samplerate:%dHz channels:%d bits/sample:%d", p_enc->fmt_out.audio.i_rate, p_enc->fmt_out.audio.i_channels, p_enc->fmt_out.audio.i_bitspersample ); @@ -1430,7 +1435,7 @@ static int EncoderOpen( vlc_object_t *p_this ) *****************************************************************************/ static void EncoderClose ( vlc_object_t *p_this ) { - return; + VLC_UNUSED(p_this); } /***************************************************************************** @@ -1441,11 +1446,11 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) encoder_sys_t *p_sys = p_enc->p_sys; block_t *p_block = NULL; - if( !p_aout_buf || !p_aout_buf->i_nb_bytes ) return NULL; + if( !p_aout_buf || !p_aout_buf->i_buffer ) return NULL; if( p_sys->i_s16tolog ) { - if( ( p_block = block_New( p_enc, p_aout_buf->i_nb_bytes / 2 ) ) ) + if( ( p_block = block_New( p_enc, p_aout_buf->i_buffer / 2 ) ) ) { int8_t *s = (int8_t*)p_block->p_buffer; // sink int16_t *aout = (int16_t*)p_aout_buf->p_buffer; // source @@ -1453,7 +1458,7 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) if( p_sys->i_s16tolog == ALAW ) { - for( i = 0; i < p_aout_buf->i_nb_bytes / 2; i++ ) + for( i = 0; i < p_aout_buf->i_buffer / 2; i++ ) { if( *aout >= 0) *s++ = alaw_encode[*aout / 16]; @@ -1465,7 +1470,7 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) } else /* ULAW */ { - for( i = 0; i < p_aout_buf->i_nb_bytes / 2; i++ ) + for( i = 0; i < p_aout_buf->i_buffer / 2; i++ ) { if( *aout >= 0) *s++ = ulaw_encode[*aout / 4]; @@ -1477,15 +1482,15 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf ) } } } - else if( ( p_block = block_New( p_enc, p_aout_buf->i_nb_bytes ) ) ) + else if( ( p_block = block_New( p_enc, p_aout_buf->i_buffer ) ) ) { memcpy( p_block->p_buffer, p_aout_buf->p_buffer, - p_aout_buf->i_nb_bytes ); + p_aout_buf->i_buffer ); } if( p_block ) { - p_block->i_dts = p_block->i_pts = p_aout_buf->start_date; + p_block->i_dts = p_block->i_pts = p_aout_buf->i_pts; p_block->i_length = (int64_t)p_aout_buf->i_nb_samples * (int64_t)1000000 / p_enc->fmt_in.audio.i_rate; }