Commit 352e95ad authored by Jean-Paul Saman's avatar Jean-Paul Saman

davinci: XDM 1.0 HEAAC DSP encoder

parent a8c5af18
This diff is collapsed.
......@@ -63,6 +63,11 @@ struct xdm_sys_t
XDM_BufDesc in;
XDM_BufDesc out;
/* remainder buffer management */
uint8_t p_buffer[4096]; /* FIXME: assume buffer is 4096 */
mtime_t i_pts;
size_t i_size;
};
/*****************************************************************************
......@@ -80,6 +85,8 @@ int OpenEncoderAudio( encoder_t *p_enc )
xdm = p_sys->xdm;
xdm->params.size = sizeof( xdm->params );
xdm->dparams.size = sizeof( xdm->dparams );
switch( var_CreateGetInteger( p_enc, ENC_CFG_PREFIX "quality" ) )
{
case 1: xdm->params.encodingPreset = XDM_HIGH_QUALITY; break;
......@@ -118,6 +125,8 @@ void CloseEncoderAudio( encoder_t *p_enc )
encoder_sys_t *p_sys = p_enc->p_sys;
xdm_sys_t *xdm = p_sys->xdm;
if( !xdm ) return;
/* Delete audio encoder */
if( p_enc->fmt_out.i_cat == AUDIO_ES )
AUDENC_delete( xdm->handle );
......@@ -133,15 +142,12 @@ void CloseEncoderAudio( encoder_t *p_enc )
/*****************************************************************************
* Audio Encoder: XDM 0.9
*****************************************************************************/
static inline int davinci_InitAudioBuffers( encoder_t *p_enc )
static inline int davinci_SetDynamicParams( encoder_t *p_enc )
{
encoder_sys_t *p_sys = p_enc->p_sys;
xdm_sys_t *xdm = p_sys->xdm;
int i_ret = VLC_SUCCESS;
AUDENC_Status status;
xdm->dparams.size = sizeof( xdm->dparams );
memset( &status, 0, sizeof( status ) );
status.size = sizeof( status );
......@@ -172,14 +178,6 @@ static inline int davinci_InitAudioBuffers( encoder_t *p_enc )
xdm->dparams.numLFEChannels = 0; /* FIXME: What to fill in here?
* Number of LFE (Low Frequency Effects) channels in the stream. */
xdm->dparams.inputBitsPerSample = p_enc->fmt_out.audio.i_bitspersample;
//p_enc->fmt_in.i_codec == AOUT_FMT_S16_NE) ? 16: 32;
msg_Info( p_enc, "using %d channels at %d Hz samplerate (bitrate %d kBps, "
"%d bits per sample)\n",
p_enc->fmt_out.audio.i_channels,
(int)xdm->dparams.sampleRate,
((int)xdm->dparams.bitRate) >> 13 /* / (8*1024)*/,
(int)xdm->dparams.inputBitsPerSample );
if( AUDENC_control( xdm->handle, XDM_SETPARAMS, &xdm->dparams, &status )
!= AUDENC_EOK )
......@@ -188,6 +186,20 @@ static inline int davinci_InitAudioBuffers( encoder_t *p_enc )
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
static inline int davinci_InitAudioBuffers( encoder_t *p_enc )
{
encoder_sys_t *p_sys = p_enc->p_sys;
xdm_sys_t *xdm = p_sys->xdm;
int i_ret = VLC_SUCCESS;
AUDENC_Status status;
memset( &status, 0, sizeof( status ) );
status.size = sizeof( status );
/* Configure buffers */
if( AUDENC_control( xdm->handle, XDM_GETBUFINFO, &xdm->dparams, &status )
!= AUDENC_EOK )
......@@ -226,19 +238,58 @@ static block_t *EncodeAudio( encoder_t *p_enc, aout_buffer_t *p_buffer )
block_t *p_block;
int i_ret;
if( davinci_SetDynamicParams( p_enc ) != VLC_SUCCESS )
{
msg_Warn( p_enc, "Failed setting dynamic params." );
}
if( xdm->in.numBufs == 0 || xdm->out.numBufs == 0 )
{
msg_Info( p_enc, "using %d channels at %d Hz samplerate (bitrate %d kBps, "
"%d bits per sample)\n",
p_enc->fmt_out.audio.i_channels,
(int)xdm->dparams.sampleRate,
((int)xdm->dparams.bitRate) >> 13 /* / (8*1024)*/,
(int)xdm->dparams.inputBitsPerSample );
if( davinci_InitAudioBuffers( p_enc ) != VLC_SUCCESS )
return NULL;
}
/* NOTE: assume interleaved channels */
if( xdm->i_size == 0 )
{ /* buffer is filled in one go */
memcpy( xdm->in.bufs[0], p_buffer->p_buffer, p_buffer->i_nb_bytes );
if( p_buffer->i_nb_bytes < (uint32_t)xdm->in.bufSizes[0] )
{
xdm->i_size = p_buffer->i_nb_bytes;
xdm->i_pts = p_buffer->start_date;
return NULL; /* wait till buffer is filled */
}
xdm->i_pts = 0;
}
else
{
/* there is a remainder */
size_t i_remainder = (uint32_t)xdm->in.bufSizes[0] - xdm->i_size;
if( i_remainder > p_buffer->i_nb_bytes )
i_remainder = p_buffer->i_nb_bytes;
if( xdm->i_size > 0 )
memcpy( xdm->in.bufs[0], xdm->p_buffer, xdm->i_size );
memcpy( xdm->in.bufs[0] + xdm->i_size, p_buffer->p_buffer, i_remainder );
/* keep remainder part of buffer */
if( i_remainder < (size_t)xdm->in.bufSizes[0] )
{
memcpy( xdm->p_buffer, p_buffer->p_buffer + i_remainder, p_buffer->i_nb_bytes - i_remainder );
xdm->i_size = (p_buffer->i_nb_bytes - i_remainder);
}
}
/* Configure input */
memset( &in_args, 0, sizeof( in_args ) );
in_args.size = sizeof( in_args );
/* NOTE: assume interleaved channels */
memcpy( xdm->in.bufs[0], p_buffer->p_buffer, p_buffer->i_nb_bytes );
/* Configure output */
memset( &out_args, 0, sizeof( out_args ) );
out_args.size = sizeof( out_args );
......
......@@ -62,6 +62,7 @@
* Encoder
*/
/* video settings */
#define ENC_KEYINT_TEXT N_( "Ratio of key frames" )
#define ENC_KEYINT_LONGTEXT N_( "Number of frames " \
"that will be coded for one key frame." )
......@@ -85,6 +86,19 @@
#define ENC_CBR_LONGTEXT N_( "Use constant bitrate encoding. If disabled, " \
"then variable bitrate encoding is used resulting in higher bandwidth savings." )
/* audio settings */
#define ENC_PROFILE_TEXT N_( "Specify AAC audio profile to use" )
#define ENC_PROFILE_LONGTEXT N_( "Specify the AAC audio profile to use " \
"for encoding the audio bitstream. It takes the following options: " \
"low (LC), sbr (HE) and ps (HEv2) (default: low)" )
/* */
#ifdef ENABLE_SOUT
static const char *const enc_aac_profile_list[] = { "low", "sbr", "ps" };
static const char *const enc_aac_profile_list_text[] = {
N_("low"), N_("sbr"), N_("ps") };
#endif
/* */
#define MODULE_DESCRIPTION N_( "Various audio and video decoders/encoders" \
"delivered by TI Davinci library. This includes MPEG4, H264, VC-1, "\
......@@ -125,25 +139,28 @@ vlc_module_begin()
/* encoder settings - XDM 0.9 only */
add_integer( ENC_CFG_PREFIX "quality", 0, NULL, ENC_QUALITY_TEXT,
ENC_QUALITY_LONGTEXT, true )
ENC_QUALITY_LONGTEXT, false )
change_integer_range( 0, 3 )
/* encoder settings - XDM 1.0 only */
add_bool( ENC_CFG_PREFIX "cbr", true, NULL, ENC_CBR_TEXT,
ENC_CBR_LONGTEXT, true )
ENC_CBR_LONGTEXT, false )
/* video encoder settings - XDM all versions */
add_integer( ENC_CFG_PREFIX "keyint", 0, NULL, ENC_KEYINT_TEXT,
ENC_KEYINT_LONGTEXT, false )
add_bool( ENC_CFG_PREFIX "interlace", false, NULL, ENC_INTERLACE_TEXT,
ENC_INTERLACE_LONGTEXT, true )
ENC_INTERLACE_LONGTEXT, false )
add_integer( ENC_CFG_PREFIX "rc", 1, NULL, ENC_RC_TEXT,
ENC_RC_LONGTEXT, true )
ENC_RC_LONGTEXT, false )
change_integer_range( 0, 5 )
add_integer( ENC_CFG_PREFIX "tolerance", 0, NULL, ENC_VT_TEXT,
ENC_VT_LONGTEXT, true )
ENC_VT_LONGTEXT, false )
/* audio encoder settings */
add_string( ENC_CFG_PREFIX "aac-profile", "low", NULL,
ENC_PROFILE_TEXT, ENC_PROFILE_LONGTEXT, false )
change_string_list( enc_aac_profile_list, enc_aac_profile_list_text, 0 )
#endif
#if 0
......
......@@ -44,7 +44,11 @@
/*****************************************************************************
* Encoder
*****************************************************************************/
static const char *const ppsz_enc_options[] = {
"aac-profile", "cbr", "engine", "fourcc", "keyint", "interlace", "quality",
"rc", "tolerance",
NULL
};
/*****************************************************************************
*
......@@ -97,6 +101,8 @@ int OpenEncoder( vlc_object_t *p_this )
davinci_PrintAvailableAlgorithms( p_this, p_sys->psz_ti_engine );
config_ChainParse( p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg );
/* Initialize random stuff */
switch( i_cat )
{
......@@ -134,9 +140,7 @@ error:
(i_cat == AUDIO_ES) ? "audio" : "other",
p_sys->psz_codec, psz_namecodec );
if( p_sys->engine ) Engine_close( p_sys->engine );
free( p_sys->psz_ti_engine );
free( p_sys );
CloseEncoder( p_this );
return VLC_EGENERIC;
}
......@@ -179,7 +183,8 @@ void CloseEncoder( vlc_object_t *p_this )
Engine_close( p_sys->engine );
/* Exit the codec engine */
CERuntime_exit(); /* FIXME: Should this be done only once (if we have encoder + decoder runing) */
/* FIXME: Should this be done only once (if we have encoder + decoder runing) */
CERuntime_exit();
free( p_sys->psz_ti_engine );
free( p_sys );
......
......@@ -65,7 +65,7 @@
#define DAVINCI_ENC_H264 "h264enc"
#define DAVINCI_ENC_VC1 "vc1enc"
#define DAVINCI_ENC_AAC "aaclcenc"
#define DAVINCI_ENC_AAC "aacheenc"
#define DAVINCI_ENC_G711 "g711enc"
#define DAVINCI_NONE ""
......
......@@ -93,6 +93,8 @@ void CloseEncoderVideo( encoder_t *p_enc )
encoder_sys_t *p_sys = p_enc->p_sys;
xdm_sys_t *xdm = p_sys->xdm;
if( !xdm ) return;
/* Delete video encoder */
if( p_enc->fmt_out.i_cat == VIDEO_ES )
VIDENC_delete( xdm->handle );
......
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