Commit 28f7772e authored by Antoine Cellerier's avatar Antoine Cellerier Committed by Jean-Paul Saman

Start fixing audio decoder. Not done yet.

Signed-off-by: Jean-Paul Saman's avatarJean-Paul Saman <jean-paul.saman@m2x.nl>
parent f1d6cbe3
......@@ -27,6 +27,7 @@
#include "davinci.h"
#include <ti/sdo/ce/audio/auddec.h>
#include <assert.h>
/*****************************************************************************
* Local prototypes
......@@ -43,6 +44,8 @@ struct decoder_sys_t
XDM_BufDesc in;
XDM_BufDesc out;
audio_date_t date;
};
/*****************************************************************************
......@@ -118,9 +121,9 @@ int OpenAudioDecoder( vlc_object_t *p_this )
/* Create audio decoder */
params.size = sizeof( params );
params.maxSampleRate = 48000; /* in Hz */
params.maxBitrate = 256000; /* in kbps */
params.maxNoOfCh = IAUDIO_SEVEN_ONE; /* 7.1 */
params.maxSampleRate = 0; /* Use default. in Hz */
params.maxBitrate = 0; /* Use default. in kbps */
params.maxNoOfCh = 0; /* Use default */
params.dataEndianness = XDM_BYTE; /* FIXME? */
p_sys->d = AUDDEC_create( p_sys->e, (String)psz_codec, &params );
......@@ -135,6 +138,16 @@ int OpenAudioDecoder( vlc_object_t *p_this )
/* Set callbacks */
p_dec->pf_decode_audio = DecodeAudioBlock;
if( p_dec->fmt_in.audio.i_rate )
{
aout_DateInit( &p_sys->date, p_dec->fmt_in.audio.i_rate );
aout_DateSet( &p_sys->date, 0 );
}
p_dec->fmt_out.i_cat = AUDIO_ES;
p_dec->fmt_out.i_codec =
p_dec->fmt_out.audio.i_format = AOUT_FMT_S16_NE;
p_dec->fmt_out.audio.i_bitspersample = 16;
#ifdef DEBUG_DAVINCI
msg_Info( p_dec, "Wooooohooo!" );
#endif
......@@ -180,7 +193,6 @@ void CloseAudioDecoder( vlc_object_t *p_this )
*****************************************************************************/
static aout_buffer_t *DecodeAudioBlock( decoder_t *p_dec, block_t **pp_block )
{
#if 0
decoder_sys_t *p_sys = p_dec->p_sys;
block_t *p_block;
aout_buffer_t *p_out = NULL;
......@@ -197,18 +209,33 @@ static aout_buffer_t *DecodeAudioBlock( decoder_t *p_dec, block_t **pp_block )
msg_Err( p_dec, "DecodeAudioBlock starts now!" );
#endif
if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
block_Release( p_block );
return NULL;
}
memset( &in_args, 0, sizeof( in_args ) );
memset( &out_args, 0, sizeof( out_args ) );
/* Configure audio decoder */
dparams.size = sizeof( dparams );
memset( &status, 0, sizeof( status ) );
status.size = sizeof( status );
if( p_sys->in.numBufs == 0 || p_sys->out.numBufs == 0 )
{
/* Configure audio decoder */
dparams.outputFormat = IAUDIO_INTERLEAVED;
if( AUDDEC_control( p_sys->d, XDM_SETPARAMS, &dparams, &status )
!= AUDDEC_EOK )
{
msg_Err( p_dec, "Failed to set dynamic decoder parameters" );
goto error;
}
if( AUDDEC_control( p_sys->d, XDM_GETBUFINFO, &dparams, &status )
!= VIDDEC_EOK )
!= AUDDEC_EOK )
{
msg_Err( p_dec, "Failed to get buffer info" );
goto error;
......@@ -235,21 +262,32 @@ static aout_buffer_t *DecodeAudioBlock( decoder_t *p_dec, block_t **pp_block )
/* Setup input arguments */
in_args.size = sizeof( in_args );
in_args.numBytes = __MIN( p_block->i_buffer, p_sys->in.bufSizes[0] );
in_args.numBytes = __MIN( p_dec->fmt_in.i_extra + p_block->i_buffer,
p_sys->in.bufSizes[0] );
/* Setup input buffer */
#ifdef DEBUG_DAVINCI
if( p_block->i_buffer > p_sys->in.bufSizes[0] )
msg_Dbg( p_dec, "Woah! Not enough room to store the whole block" );
#endif
memcpy( p_sys->in.bufs[0], p_block->p_buffer, in_args.numBytes );
if( p_dec->fmt_in.i_extra > 0 )
{
memcpy( p_sys->in.bufs[0], p_dec->fmt_in.p_extra,
p_dec->fmt_in.i_extra );
}
memcpy( p_sys->in.bufs[0] + p_dec->fmt_in.i_extra, p_block->p_buffer,
in_args.numBytes - p_dec->fmt_in.i_extra );
#ifdef DEBUG_DAVINCI
msg_Dbg( p_dec, "Sending %d + %d bytes", p_dec->fmt_in.i_extra,
(int)in_args.numBytes - p_dec->fmt_in.i_extra );
#endif
/* Setup output arguments */
out_args.size = sizeof( out_args );
/* Decode the audio */
i = AUDDEC_process( p_sys->d, &p_sys->in, &p_sys->out, &in_args, &out_args );
if( i != VIDDEC_EOK )
if( i != AUDDEC_EOK )
{
msg_Err( p_dec, "Audio decoding failed (Error code: %d, "
"Extended error: %x)", i, (int)out_args.extendedError );
......@@ -257,54 +295,88 @@ static aout_buffer_t *DecodeAudioBlock( decoder_t *p_dec, block_t **pp_block )
goto error;
}
if( VIDDEC_control( p_sys->d, XDM_GETSTATUS, &dparams, &status ) != AUDDEC_EOK )
if( AUDDEC_control( p_sys->d, XDM_GETSTATUS, &dparams, &status ) != AUDDEC_EOK )
{
msg_Err( p_dec, "Failed to get decoder status" );
goto error;
}
p_block->p_buffer += out_args.bytesConsumed;
p_block->i_buffer -= out_args.bytesConsumed;
#ifdef DEBUG_DAVINCI
msg_Dbg( p_dec, "Bytes consumed: %d", (int)out_args.bytesConsumed );
#endif
p_block->p_buffer += out_args.bytesConsumed - p_dec->fmt_in.i_extra;
p_block->i_buffer -= out_args.bytesConsumed - p_dec->fmt_in.i_extra;
if( p_dec->fmt_out.audio.i_rate != (unsigned int)status.sampleRate )
{
msg_Dbg( p_dec, "Setting audio output format info" );
p_dec->fmt_out.audio.i_rate = status.sampleRate;
msg_Dbg( p_dec, "Rate: %d", p_dec->fmt_out.audio.i_rate );
aout_DateInit( &p_sys->date, p_dec->fmt_out.audio.i_rate );
aout_DateSet( &p_sys->date, p_block->i_pts );
p_dec->fmt_out.audio.i_channels = status.numChannels;
switch( status.numChannels )
{
case IAUDIO_MONO:
i = AOUT_VAR_MONO;
i = AOUT_CHAN_CENTER;
break;
case IAUDIO_STEREO:
i = AOUT_VAR_STEREO;
i = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
break;
case IAUDIO_THREE_ZERO:
i = 3; /* FIXME? */
i = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_LFE;
break;
case IAUDIO_FIVE_ZERO:
i = AOUT_VAR_3F2R;
i = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_CENTER ;
break;
case IAUDIO_FIVE_ONE:
i = AOUT_VAR_5_1;
i = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_LFE;
break;
case IAUDIO_SEVEN_ONE:
i = AOUT_VAR_7_1;
i = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_LFE;
break;
default:
msg_Warn( p_dec, "Unknown numChannels (%d)", status.numChannels );
msg_Warn( p_dec, "Unknown numChannels (%d)", (int)status.numChannels );
i = status.numChannels;
break;
}
p_dec->fmt_out.audio.i_physical_channels =
p_dec->fmt_out.audio.i_original_channels =
p_dec->fmt_out.audio.i_channels = i;
p_dec->fmt_out.audio.i_original_channels = i;
msg_Dbg( p_dec, "Channels: %d", p_dec->fmt_out.audio.i_original_channels );
p_dec->fmt_out.audio.i_bitspersample = status.outputBitsPerSample;
msg_Dbg( p_dec, "Bits per sample: %d", p_dec->fmt_out.audio.i_bitspersample );
p_out = p_dec->pf_aout_buffer_new( p_dec, status.frameLen /
assert( p_dec->fmt_out.audio.i_bitspersample == 16 );
}
if( p_block->i_pts != 0 && p_block->i_pts != aout_DateGet( &p_sys->date ) )
{
aout_DateSet( &p_sys->date, p_block->i_pts );
}
else if( !aout_DateGet( &p_sys->date ) )
{
/* We're still waiting for a pts */
goto error;
}
p_out = p_dec->pf_aout_buffer_new( p_dec, status.frameLen / 2 /
p_dec->fmt_out.audio.i_channels );
p_out->start_date =
p_out->end_date =
p_out->p_buffer =
p_out->start_date = aout_DateGet( &p_sys->date );
p_out->end_date = aout_DateIncrement( &p_sys->date, status.frameLen / 2 / p_dec->fmt_out.audio.i_channels );
memcpy( p_out->p_buffer, p_sys->out.bufs[0], p_out->i_nb_bytes );
if( p_block->i_buffer == 0 )
{
block_Release( p_block );
*pp_block = NULL;
}
msg_Info( p_dec, "Audio samples incoming ... get ready!" );
return p_out;
......@@ -312,6 +384,5 @@ static aout_buffer_t *DecodeAudioBlock( decoder_t *p_dec, block_t **pp_block )
if( p_out && p_out->pf_release )
p_out->pf_release( p_out );
block_Release( p_block );
#endif
return NULL;
}
......@@ -34,7 +34,7 @@
#include <ti/sdo/ce/CERuntime.h>
#include <ti/sdo/ce/Engine.h>
/* #define DEBUG_DAVINCI */
#define DEBUG_DAVINCI
int OpenVideoDecoder( vlc_object_t * );
void CloseVideoDecoder( vlc_object_t * );
......@@ -171,6 +171,7 @@ extern const char *ppsz_engine_error[];
case VLC_FOURCC('w','v','c','1'):
#define CASE_MP3 \
case VLC_FOURCC('m','p','g','a'): \
case VLC_FOURCC('m','p','3',' '): \
case VLC_FOURCC('.','m','p','3'): \
case VLC_FOURCC('M','P','3',' '): \
......
......@@ -244,6 +244,12 @@ static picture_t *DecodeVideoBlock( decoder_t *p_dec, block_t **pp_block )
msg_Err( p_dec, "DecodeVideoBlock starts now!" );
#endif
if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
block_Release( p_block );
return NULL;
}
memset( &in_args, 0, sizeof( in_args ) );
memset( &out_args, 0, sizeof( out_args ) );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment