1 /* $Id: decavcodec.c,v 1.6 2005/03/06 04:08:54 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
9 #include "ffmpeg/avcodec.h"
11 int decavcodecInit( hb_work_object_t *, hb_job_t * );
12 int decavcodecWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** );
13 void decavcodecClose( hb_work_object_t * );
15 hb_work_object_t hb_decavcodec =
18 "MPGA decoder (libavcodec)",
24 struct hb_work_private_s
28 AVCodecContext * context;
33 /***********************************************************************
34 * hb_work_decavcodec_init
35 ***********************************************************************
37 **********************************************************************/
38 int decavcodecInit( hb_work_object_t * w, hb_job_t * job )
41 hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
46 codec = avcodec_find_decoder( CODEC_ID_MP2 );
47 pv->context = avcodec_alloc_context();
48 avcodec_open( pv->context, codec );
54 /***********************************************************************
56 ***********************************************************************
58 **********************************************************************/
59 void decavcodecClose( hb_work_object_t * w )
61 hb_work_private_t * pv = w->private_data;
62 avcodec_close( pv->context );
65 /***********************************************************************
67 ***********************************************************************
69 **********************************************************************/
70 int decavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
71 hb_buffer_t ** buf_out )
73 hb_work_private_t * pv = w->private_data;
74 hb_buffer_t * in = *buf_in, * buf, * last = NULL;
75 int pos, len, out_size, i;
76 short buffer[AVCODEC_MAX_AUDIO_FRAME_SIZE];
83 in->start > pv->pts_last &&
84 in->start - pv->pts_last < 5000 ) ) /* Hacky */
94 while( pos < in->size )
96 len = avcodec_decode_audio( pv->context, buffer, &out_size,
97 in->data + pos, in->size - pos );
103 buf = hb_buffer_init( 2 * out_size );
106 buf->stop = cur + 90000 * ( out_size / 4 ) /
107 pv->context->sample_rate;
111 fl32 = (float *) buf->data;
112 for( i = 0; i < out_size / 2; i++ )
119 last = last->next = buf;
123 *buf_out = last = buf;