summaryrefslogtreecommitdiffstats
path: root/libhb/encvorbis.c
diff options
context:
space:
mode:
Diffstat (limited to 'libhb/encvorbis.c')
-rw-r--r--libhb/encvorbis.c112
1 files changed, 52 insertions, 60 deletions
diff --git a/libhb/encvorbis.c b/libhb/encvorbis.c
index 86b824372..4bdb6efeb 100644
--- a/libhb/encvorbis.c
+++ b/libhb/encvorbis.c
@@ -10,12 +10,22 @@
#define OGGVORBIS_FRAME_SIZE 1024
-struct hb_work_object_s
+int encvorbisInit( hb_work_object_t *, hb_job_t * );
+int encvorbisWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** );
+void encvorbisClose( hb_work_object_t * );
+
+hb_work_object_t hb_encvorbis =
{
- HB_WORK_COMMON;
+ WORK_ENCVORBIS,
+ "Vorbis encoder (libvorbis)",
+ encvorbisInit,
+ encvorbisWork,
+ encvorbisClose
+};
+struct hb_work_private_s
+{
hb_job_t * job;
- hb_audio_t * audio;
vorbis_info vi;
vorbis_comment vc;
@@ -29,70 +39,53 @@ struct hb_work_object_s
hb_list_t * list;
};
-/***********************************************************************
- * 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 );
-
-/***********************************************************************
- * hb_work_encvorbis_init
- ***********************************************************************
- *
- **********************************************************************/
-hb_work_object_t * hb_work_encvorbis_init( hb_job_t * job, hb_audio_t * audio )
+int encvorbisInit( hb_work_object_t * w, hb_job_t * job )
{
int i;
ogg_packet header[3];
- hb_work_object_t * w = calloc( sizeof( hb_work_object_t ), 1 );
- w->name = strdup( "Vorbis encoder (libvorbis)" );
- w->work = Work;
- w->close = Close;
+ hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
+ w->private_data = pv;
- w->job = job;
- w->audio = audio;
+ pv->job = job;
hb_log( "encvorbis: opening libvorbis" );
/* init */
- vorbis_info_init( &w->vi );
- if( vorbis_encode_setup_managed( &w->vi, 2,
+ vorbis_info_init( &pv->vi );
+ if( vorbis_encode_setup_managed( &pv->vi, 2,
job->arate, -1, 1000 * job->abitrate, -1 ) ||
- vorbis_encode_ctl( &w->vi, OV_ECTL_RATEMANAGE_AVG, NULL ) ||
- vorbis_encode_setup_init( &w->vi ) )
+ vorbis_encode_ctl( &pv->vi, OV_ECTL_RATEMANAGE_AVG, NULL ) ||
+ vorbis_encode_setup_init( &pv->vi ) )
{
hb_log( "encvorbis: vorbis_encode_setup_managed failed" );
}
/* add a comment */
- vorbis_comment_init( &w->vc );
- vorbis_comment_add_tag( &w->vc, "Encoder", "HandBrake");
+ vorbis_comment_init( &pv->vc );
+ vorbis_comment_add_tag( &pv->vc, "Encoder", "HandBrake");
/* set up the analysis state and auxiliary encoding storage */
- vorbis_analysis_init( &w->vd, &w->vi);
- vorbis_block_init( &w->vd, &w->vb);
+ vorbis_analysis_init( &pv->vd, &pv->vi);
+ vorbis_block_init( &pv->vd, &pv->vb);
/* get the 3 headers */
- vorbis_analysis_headerout( &w->vd, &w->vc,
+ vorbis_analysis_headerout( &pv->vd, &pv->vc,
&header[0], &header[1], &header[2] );
for( i = 0; i < 3; i++ )
{
- audio->config.vorbis.headers[i] =
- malloc( sizeof( ogg_packet ) + header[i].bytes );
- memcpy( audio->config.vorbis.headers[i], &header[i],
+ memcpy( w->config->vorbis.headers[i], &header[i],
sizeof( ogg_packet ) );
- memcpy( audio->config.vorbis.headers[i] + sizeof( ogg_packet ),
+ memcpy( w->config->vorbis.headers[i] + sizeof( ogg_packet ),
header[i].packet, header[i].bytes );
}
- w->input_samples = 2 * OGGVORBIS_FRAME_SIZE;
- w->buf = malloc( w->input_samples * sizeof( float ) );
+ pv->input_samples = 2 * OGGVORBIS_FRAME_SIZE;
+ pv->buf = malloc( pv->input_samples * sizeof( float ) );
- w->list = hb_list_init();
+ pv->list = hb_list_init();
- return w;
+ return 0;
}
/***********************************************************************
@@ -100,12 +93,8 @@ hb_work_object_t * hb_work_encvorbis_init( hb_job_t * job, hb_audio_t * audio )
***********************************************************************
*
**********************************************************************/
-static void Close( hb_work_object_t ** _w )
+void encvorbisClose( hb_work_object_t * w )
{
- hb_work_object_t * w = *_w;
- free( w->name );
- free( w );
- *_w = NULL;
}
/***********************************************************************
@@ -115,26 +104,27 @@ static void Close( hb_work_object_t ** _w )
**********************************************************************/
static hb_buffer_t * Flush( hb_work_object_t * w )
{
+ hb_work_private_t * pv = w->private_data;
hb_buffer_t * buf;
- if( vorbis_analysis_blockout( &w->vd, &w->vb ) == 1 )
+ if( vorbis_analysis_blockout( &pv->vd, &pv->vb ) == 1 )
{
ogg_packet op;
- vorbis_analysis( &w->vb, NULL );
- vorbis_bitrate_addblock( &w->vb );
+ vorbis_analysis( &pv->vb, NULL );
+ vorbis_bitrate_addblock( &pv->vb );
- if( vorbis_bitrate_flushpacket( &w->vd, &op ) )
+ if( vorbis_bitrate_flushpacket( &pv->vd, &op ) )
{
buf = hb_buffer_init( sizeof( ogg_packet ) + op.bytes );
memcpy( buf->data, &op, sizeof( ogg_packet ) );
memcpy( buf->data + sizeof( ogg_packet ), op.packet,
op.bytes );
buf->key = 1;
- buf->start = w->pts; /* No exact, but who cares - the OGM
+ buf->start = pv->pts; /* No exact, but who cares - the OGM
muxer doesn't use it */
buf->stop = buf->start +
- 90000 * OGGVORBIS_FRAME_SIZE + w->job->arate;
+ 90000 * OGGVORBIS_FRAME_SIZE + pv->job->arate;
return buf;
}
@@ -150,6 +140,7 @@ static hb_buffer_t * Flush( 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;
float ** buffer;
int i;
@@ -160,21 +151,21 @@ static hb_buffer_t * Encode( hb_work_object_t * w )
return buf;
}
- if( hb_list_bytes( w->list ) < w->input_samples * sizeof( float ) )
+ if( hb_list_bytes( pv->list ) < pv->input_samples * sizeof( float ) )
{
return NULL;
}
/* Process more samples */
- hb_list_getbytes( w->list, w->buf, w->input_samples * sizeof( float ),
- &w->pts, NULL );
- buffer = vorbis_analysis_buffer( &w->vd, OGGVORBIS_FRAME_SIZE );
+ hb_list_getbytes( pv->list, pv->buf, pv->input_samples * sizeof( float ),
+ &pv->pts, NULL );
+ buffer = vorbis_analysis_buffer( &pv->vd, OGGVORBIS_FRAME_SIZE );
for( i = 0; i < OGGVORBIS_FRAME_SIZE; i++ )
{
- buffer[0][i] = ((float *) w->buf)[2*i] / 32768.f;
- buffer[1][i] = ((float *) w->buf)[2*i+1] / 32768.f;
+ buffer[0][i] = ((float *) pv->buf)[2*i] / 32768.f;
+ buffer[1][i] = ((float *) pv->buf)[2*i+1] / 32768.f;
}
- vorbis_analysis_wrote( &w->vd, OGGVORBIS_FRAME_SIZE );
+ vorbis_analysis_wrote( &pv->vd, OGGVORBIS_FRAME_SIZE );
/* Try to extract again */
return Flush( w );
@@ -185,12 +176,13 @@ static hb_buffer_t * Encode( hb_work_object_t * w )
***********************************************************************
*
**********************************************************************/
-static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
- hb_buffer_t ** buf_out )
+int encvorbisWork( 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 );