/* $Id: encfaac.c,v 1.13 2005/03/03 17:21:57 titer Exp $
This file is part of the HandBrake source code.
- Homepage: <http://handbrake.m0k.org/>.
+ Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */
#include "hb.h"
hb_list_t * list;
int64_t pts;
-
- int channelsused;
+
+ int out_discrete_channels;
};
int encfaacInit( hb_work_object_t * w, hb_job_t * job )
{
hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
+ hb_audio_t * audio = w->audio;
faacEncConfigurationPtr cfg;
uint8_t * bytes;
unsigned long length;
pv->job = job;
/* pass the number of channels used into the private work data */
- pv->channelsused = w->config->aac.channelsused;
+ pv->out_discrete_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown);
- pv->faac = faacEncOpen( job->arate, pv->channelsused, &pv->input_samples,
+ pv->faac = faacEncOpen( audio->config.out.samplerate, pv->out_discrete_channels, &pv->input_samples,
&pv->output_bytes );
pv->buf = malloc( pv->input_samples * sizeof( float ) );
-
+
cfg = faacEncGetCurrentConfiguration( pv->faac );
cfg->mpegVersion = MPEG4;
cfg->aacObjectType = LOW;
cfg->allowMidside = 1;
-
- if (pv->channelsused == 6) {
+
+ if (pv->out_discrete_channels == 6) {
/* we are preserving 5.1 audio into 6-channel AAC,
so indicate that we have an lfe channel */
cfg->useLfe = 1;
}
cfg->useTns = 0;
- cfg->bitRate = job->abitrate * 1000 / pv->channelsused; /* Per channel */
+ cfg->bitRate = audio->config.out.bitrate * 1000 / pv->out_discrete_channels; /* Per channel */
cfg->bandWidth = 0;
cfg->outputFormat = 0;
cfg->inputFormat = FAAC_INPUT_FLOAT;
-
- if (pv->channelsused == 6) {
- /* we are preserving 5.1 audio into 6-channel AAC, and need to
- re-map the output of deca52 into our own mapping - the mapping
- below is the default mapping expected by QuickTime */
- /* This doesn't seem to be correct for VLC on Linux */
- cfg->channel_map[0] = 2;
- cfg->channel_map[1] = 1;
- cfg->channel_map[2] = 3;
- cfg->channel_map[3] = 4;
- cfg->channel_map[4] = 5;
- cfg->channel_map[5] = 0;
+
+ if (audio->config.out.mixdown == HB_AMIXDOWN_6CH && audio->config.in.codec == HB_ACODEC_AC3)
+ {
+ /* we are preserving 5.1 AC-3 audio into 6-channel AAC, and need to
+ re-map the output of deca52 into our own mapping - the mapping
+ below is the default mapping expected by QuickTime */
+ /* DTS output from libdca is already in the right mapping for QuickTime */
+ /* This doesn't seem to be correct for VLC on Linux */
+ cfg->channel_map[0] = 2;
+ cfg->channel_map[1] = 1;
+ cfg->channel_map[2] = 3;
+ cfg->channel_map[3] = 4;
+ cfg->channel_map[4] = 5;
+ cfg->channel_map[5] = 0;
}
-
+
if( !faacEncSetConfiguration( pv->faac, cfg ) )
{
hb_log( "faacEncSetConfiguration failed" );
+ *job->die = 1;
+ return 0;
}
if( faacEncGetDecoderSpecificInfo( pv->faac, &bytes, &length ) < 0 )
{
hb_log( "faacEncGetDecoderSpecificInfo failed" );
+ *job->die = 1;
+ return 0;
}
memcpy( w->config->aac.bytes, bytes, length );
w->config->aac.length = length;
faacEncClose( pv->faac );
free( pv->buf );
hb_list_empty( &pv->list );
+ free( pv );
+ w->private_data = NULL;
}
/***********************************************************************
static hb_buffer_t * Encode( hb_work_object_t * w )
{
hb_work_private_t * pv = w->private_data;
+ hb_audio_t * audio = w->audio;
hb_buffer_t * buf;
uint64_t pts, pos;
&pts, &pos );
buf = hb_buffer_init( pv->output_bytes );
- buf->start = pts + 90000 * pos / pv->channelsused / sizeof( float ) / pv->job->arate;
- buf->stop = buf->start + 90000 * pv->input_samples / pv->job->arate / pv->channelsused;
+ buf->start = pts + 90000 * pos / pv->out_discrete_channels / sizeof( float ) / audio->config.out.samplerate;
+ buf->stop = buf->start + 90000 * pv->input_samples / audio->config.out.samplerate / pv->out_discrete_channels;
buf->size = faacEncEncode( pv->faac, (int32_t *) pv->buf,
pv->input_samples, buf->data, pv->output_bytes );
- buf->key = 1;
+ buf->frametype = HB_FRAME_AUDIO;
if( !buf->size )
{
buf->next = Encode( w );
buf = buf->next;
}
-
+
return HB_WORK_OK;
}