diff options
author | titer <[email protected]> | 2006-03-16 06:58:39 +0000 |
---|---|---|
committer | titer <[email protected]> | 2006-03-16 06:58:39 +0000 |
commit | 47765593ae5f554e3e6e0e41d32c3d300bf537d3 (patch) | |
tree | 94ac3874dde28294fbab23ba101daa8f2892fe5a /libhb/encfaac.c | |
parent | a024a7dcf406dbc621c0765469a61dbc1983e0ed (diff) |
Structural changes, in order to eventually be able to compile HB
without certain encoders
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@34 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/encfaac.c')
-rw-r--r-- | libhb/encfaac.c | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/libhb/encfaac.c b/libhb/encfaac.c index a5b704f4c..4c0d19e72 100644 --- a/libhb/encfaac.c +++ b/libhb/encfaac.c @@ -8,12 +8,9 @@ #include "faac.h" -struct hb_work_object_s +struct hb_work_private_s { - HB_WORK_COMMON; - hb_job_t * job; - hb_audio_t * audio; faacEncHandle * faac; unsigned long input_samples; @@ -24,34 +21,38 @@ struct hb_work_object_s int64_t pts; }; -/*********************************************************************** - * Local prototypes - **********************************************************************/ -static void Close( hb_work_object_t ** _w ); -static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in, - hb_buffer_t ** buf_out ); +int encfaacInit( hb_work_object_t *, hb_job_t * ); +int encfaacWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** ); +void encfaacClose( hb_work_object_t * ); + +hb_work_object_t hb_encfaac = +{ + WORK_ENCFAAC, + "AAC encoder (libfaac)", + encfaacInit, + encfaacWork, + encfaacClose +}; /*********************************************************************** * hb_work_encfaac_init *********************************************************************** * **********************************************************************/ -hb_work_object_t * hb_work_encfaac_init( hb_job_t * job, hb_audio_t * audio ) +int encfaacInit( hb_work_object_t * w, hb_job_t * job ) { - hb_work_object_t * w = calloc( sizeof( hb_work_object_t ), 1 ); + hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) ); + w->private_data = pv; + faacEncConfigurationPtr cfg; - w->name = strdup( "AAC encoder (libfaac)" ); - w->work = Work; - w->close = Close; - w->job = job; - w->audio = audio; + pv->job = job; - w->faac = faacEncOpen( job->arate, 2, &w->input_samples, - &w->output_bytes ); - w->buf = malloc( w->input_samples * sizeof( float ) ); + pv->faac = faacEncOpen( job->arate, 2, &pv->input_samples, + &pv->output_bytes ); + pv->buf = malloc( pv->input_samples * sizeof( float ) ); - cfg = faacEncGetCurrentConfiguration( w->faac ); + cfg = faacEncGetCurrentConfiguration( pv->faac ); cfg->mpegVersion = MPEG4; cfg->aacObjectType = LOW; cfg->allowMidside = 1; @@ -61,20 +62,25 @@ hb_work_object_t * hb_work_encfaac_init( hb_job_t * job, hb_audio_t * audio ) cfg->bandWidth = 0; cfg->outputFormat = 0; cfg->inputFormat = FAAC_INPUT_FLOAT; - if( !faacEncSetConfiguration( w->faac, cfg ) ) + if( !faacEncSetConfiguration( pv->faac, cfg ) ) { hb_log( "faacEncSetConfiguration failed" ); } - if( faacEncGetDecoderSpecificInfo( w->faac, &audio->config.faac.decinfo, - &audio->config.faac.size ) < 0 ) + + uint8_t * bytes; + unsigned long length; + if( faacEncGetDecoderSpecificInfo( pv->faac, &bytes, &length ) < 0 ) { hb_log( "faacEncGetDecoderSpecificInfo failed" ); } + memcpy( w->config->aac.bytes, bytes, length ); + w->config->aac.length = length; + free( bytes ); - w->list = hb_list_init(); - w->pts = -1; + pv->list = hb_list_init(); + pv->pts = -1; - return w; + return 0; } /*********************************************************************** @@ -82,18 +88,12 @@ hb_work_object_t * hb_work_encfaac_init( hb_job_t * job, hb_audio_t * audio ) *********************************************************************** * **********************************************************************/ -static void Close( hb_work_object_t ** _w ) +void encfaacClose( hb_work_object_t * w ) { - hb_work_object_t * w = *_w; - - faacEncClose( w->faac ); - free( w->buf ); - hb_list_empty( &w->list ); - free( w->audio->config.faac.decinfo ); - - free( w->name ); - free( w ); - *_w = NULL; + hb_work_private_t * pv = w->private_data; + faacEncClose( pv->faac ); + free( pv->buf ); + hb_list_empty( &pv->list ); } /*********************************************************************** @@ -103,24 +103,25 @@ static void Close( hb_work_object_t ** _w ) **********************************************************************/ static hb_buffer_t * Encode( hb_work_object_t * w ) { + hb_work_private_t * pv = w->private_data; hb_buffer_t * buf; uint64_t pts; int pos; - if( hb_list_bytes( w->list ) < w->input_samples * sizeof( float ) ) + if( hb_list_bytes( pv->list ) < pv->input_samples * sizeof( float ) ) { /* Need more data */ return NULL; } - hb_list_getbytes( w->list, w->buf, w->input_samples * sizeof( float ), + hb_list_getbytes( pv->list, pv->buf, pv->input_samples * sizeof( float ), &pts, &pos ); - buf = hb_buffer_init( w->output_bytes ); - buf->start = pts + 90000 * pos / 2 / sizeof( float ) / w->job->arate; - buf->stop = buf->start + 90000 * w->input_samples / w->job->arate / 2; - buf->size = faacEncEncode( w->faac, (int32_t *) w->buf, - w->input_samples, buf->data, w->output_bytes ); + buf = hb_buffer_init( pv->output_bytes ); + buf->start = pts + 90000 * pos / 2 / sizeof( float ) / pv->job->arate; + buf->stop = buf->start + 90000 * pv->input_samples / pv->job->arate / 2; + buf->size = faacEncEncode( pv->faac, (int32_t *) pv->buf, + pv->input_samples, buf->data, pv->output_bytes ); buf->key = 1; if( !buf->size ) @@ -145,12 +146,13 @@ static hb_buffer_t * Encode( hb_work_object_t * w ) *********************************************************************** * **********************************************************************/ -static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in, +int encfaacWork( hb_work_object_t * w, hb_buffer_t ** buf_in, hb_buffer_t ** buf_out ) { + hb_work_private_t * pv = w->private_data; hb_buffer_t * buf; - hb_list_add( w->list, *buf_in ); + hb_list_add( pv->list, *buf_in ); *buf_in = NULL; *buf_out = buf = Encode( w ); |