summaryrefslogtreecommitdiffstats
path: root/libhb/decavcodec.c
diff options
context:
space:
mode:
authortiter <[email protected]>2006-03-16 06:58:39 +0000
committertiter <[email protected]>2006-03-16 06:58:39 +0000
commit47765593ae5f554e3e6e0e41d32c3d300bf537d3 (patch)
tree94ac3874dde28294fbab23ba101daa8f2892fe5a /libhb/decavcodec.c
parenta024a7dcf406dbc621c0765469a61dbc1983e0ed (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/decavcodec.c')
-rw-r--r--libhb/decavcodec.c71
1 files changed, 34 insertions, 37 deletions
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c
index f18579f36..4d74fc68f 100644
--- a/libhb/decavcodec.c
+++ b/libhb/decavcodec.c
@@ -8,12 +8,22 @@
#include "ffmpeg/avcodec.h"
-struct hb_work_object_s
+int decavcodecInit( hb_work_object_t *, hb_job_t * );
+int decavcodecWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** );
+void decavcodecClose( hb_work_object_t * );
+
+hb_work_object_t hb_decavcodec =
{
- HB_WORK_COMMON;
+ WORK_DECAVCODEC,
+ "MPGA decoder (libavcodec)",
+ decavcodecInit,
+ decavcodecWork,
+ decavcodecClose
+};
+struct hb_work_private_s
+{
hb_job_t * job;
- hb_audio_t * audio;
AVCodecContext * context;
int64_t pts_last;
@@ -21,35 +31,24 @@ struct hb_work_object_s
/***********************************************************************
- * Local prototypes
- **********************************************************************/
-static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
- hb_buffer_t ** buf_out );
-static void Close( hb_work_object_t ** _w );
-
-/***********************************************************************
* hb_work_decavcodec_init
***********************************************************************
*
**********************************************************************/
-hb_work_object_t * hb_work_decavcodec_init( hb_job_t * job,
- hb_audio_t * audio )
+int decavcodecInit( hb_work_object_t * w, hb_job_t * job )
{
- hb_work_object_t * w = calloc( sizeof( hb_work_object_t ), 1 );
AVCodec * codec;
- w->name = strdup( "MPGA decoder (libavcodec)" );
- 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;
codec = avcodec_find_decoder( CODEC_ID_MP2 );
- w->context = avcodec_alloc_context();
- avcodec_open( w->context, codec );
- w->pts_last = -1;
+ pv->context = avcodec_alloc_context();
+ avcodec_open( pv->context, codec );
+ pv->pts_last = -1;
- return w;
+ return 0;
}
/***********************************************************************
@@ -57,13 +56,10 @@ hb_work_object_t * hb_work_decavcodec_init( hb_job_t * job,
***********************************************************************
*
**********************************************************************/
-static void Close( hb_work_object_t ** _w )
+void decavcodecClose( hb_work_object_t * w )
{
- hb_work_object_t * w = *_w;
- avcodec_close( w->context );
- free( w->name );
- free( w );
- *_w = NULL;
+ hb_work_private_t * pv = w->private_data;
+ avcodec_close( pv->context );
}
/***********************************************************************
@@ -71,9 +67,10 @@ 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 decavcodecWork( 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 * in = *buf_in, * buf, * last = NULL;
int pos, len, out_size, i;
short buffer[AVCODEC_MAX_AUDIO_FRAME_SIZE];
@@ -82,11 +79,11 @@ static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
*buf_out = NULL;
if( in->start < 0 ||
- ( w->pts_last > 0 &&
- in->start > w->pts_last &&
- in->start - w->pts_last < 5000 ) ) /* Hacky */
+ ( pv->pts_last > 0 &&
+ in->start > pv->pts_last &&
+ in->start - pv->pts_last < 5000 ) ) /* Hacky */
{
- cur = w->pts_last;
+ cur = pv->pts_last;
}
else
{
@@ -96,7 +93,7 @@ static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
pos = 0;
while( pos < in->size )
{
- len = avcodec_decode_audio( w->context, buffer, &out_size,
+ len = avcodec_decode_audio( pv->context, buffer, &out_size,
in->data + pos, in->size - pos );
if( out_size )
{
@@ -107,7 +104,7 @@ static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
buf->start = cur;
buf->stop = cur + 90000 * ( out_size / 4 ) /
- w->context->sample_rate;
+ pv->context->sample_rate;
cur = buf->stop;
s16 = buffer;
@@ -130,7 +127,7 @@ static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
pos += len;
}
- w->pts_last = cur;
+ pv->pts_last = cur;
return HB_WORK_OK;
}