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 struct hb_work_object_s
18 AVCodecContext * context;
23 /***********************************************************************
25 **********************************************************************/
26 static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
27 hb_buffer_t ** buf_out );
28 static void Close( hb_work_object_t ** _w );
30 /***********************************************************************
31 * hb_work_decavcodec_init
32 ***********************************************************************
34 **********************************************************************/
35 hb_work_object_t * hb_work_decavcodec_init( hb_job_t * job,
38 hb_work_object_t * w = calloc( sizeof( hb_work_object_t ), 1 );
40 w->name = strdup( "MPGA decoder (libavcodec)" );
47 codec = avcodec_find_decoder( CODEC_ID_MP2 );
48 w->context = avcodec_alloc_context();
49 avcodec_open( w->context, codec );
55 /***********************************************************************
57 ***********************************************************************
59 **********************************************************************/
60 static void Close( hb_work_object_t ** _w )
62 hb_work_object_t * w = *_w;
63 avcodec_close( w->context );
69 /***********************************************************************
71 ***********************************************************************
73 **********************************************************************/
74 static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
75 hb_buffer_t ** buf_out )
77 hb_buffer_t * in = *buf_in, * buf, * last = NULL;
78 int pos, len, out_size, i;
79 short buffer[AVCODEC_MAX_AUDIO_FRAME_SIZE];
86 in->start > w->pts_last &&
87 in->start - w->pts_last < 5000 ) ) /* Hacky */
97 while( pos < in->size )
99 len = avcodec_decode_audio( w->context, buffer, &out_size,
100 in->data + pos, in->size - pos );
106 buf = hb_buffer_init( 2 * out_size );
109 buf->stop = cur + 90000 * ( out_size / 4 ) /
110 w->context->sample_rate;
114 fl32 = (float *) buf->data;
115 for( i = 0; i < out_size / 2; i++ )
122 last = last->next = buf;
126 *buf_out = last = buf;