diff options
author | handbrake <[email protected]> | 2006-01-14 13:34:42 +0000 |
---|---|---|
committer | handbrake <[email protected]> | 2006-01-14 13:34:42 +0000 |
commit | d35a2a23fe450c88925128b9db7c63a5f1ed395d (patch) | |
tree | ed7f6b0e4b1f118b0209c606448b693b822020fb /core/X264Enc.c | |
parent | 60925e41e540e9c79b522f4864296bc425fcc9e4 (diff) |
HandBrake 0.6.2
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@15 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'core/X264Enc.c')
-rw-r--r-- | core/X264Enc.c | 126 |
1 files changed, 57 insertions, 69 deletions
diff --git a/core/X264Enc.c b/core/X264Enc.c index 50b9ab8bf..be8d76709 100644 --- a/core/X264Enc.c +++ b/core/X264Enc.c @@ -1,4 +1,4 @@ -/* $Id: X264Enc.c,v 1.3 2003/12/26 20:03:27 titer Exp $ +/* $Id: X264Enc.c,v 1.8 2004/05/02 16:25:00 titer Exp $ This file is part of the HandBrake source code. Homepage: <http://handbrake.m0k.org/>. @@ -9,79 +9,69 @@ /* x264 */ #include "x264.h" -typedef struct HBX264Enc +struct HBWork { HB_WORK_COMMON_MEMBERS HBHandle *handle; HBTitle *title; - HBBuffer *buffer; - x264_t *h; x264_picture_t picture; -} HBX264Enc; +}; /* Local prototypes */ static int HBX264EncWork( HBWork * ); -HBWork *HBX264EncInit( HBHandle * handle, HBTitle * title ) +HBWork * HBX264EncInit( HBHandle * handle, HBTitle * title ) { - HBX264Enc *f = malloc( sizeof( HBX264Enc ) ); + HBWork * w = malloc( sizeof( HBWork ) ); - if( f ) + if( w ) { x264_param_t param; - f->name = strdup( "X264Enc" ); - f->work = HBX264EncWork; - - f->handle = handle; - f->title = title; + w->name = strdup( "X264Enc" ); + w->work = HBX264EncWork; - f->buffer = NULL; + w->handle = handle; + w->title = title; x264_param_default( ¶m ); param.i_width = title->outWidth; param.i_height= title->outHeight; - param.i_iframe = 5 * title->rate / title->rateBase; - /* FIXME */ - param.b_deblocking_filter = 0; - param.i_me = 1; - - if( ( f->h = x264_encoder_open( ¶m ) ) == NULL ) + param.i_iframe = 20 * title->rate / title->rateBase; + param.i_idrframe = 1; + param.b_cabac = 0; + param.analyse.inter = + X264_ANALYSE_I16x16|X264_ANALYSE_I4x4|X264_ANALYSE_P16x16| + X264_ANALYSE_P16x8|X264_ANALYSE_P8x16|X264_ANALYSE_P8x8| + X264_ANALYSE_SMART_PSUB; + + if( ( w->h = x264_encoder_open( ¶m ) ) == NULL ) { HBLog( "x264: x264_encoder_new failed" ); return NULL; } - memset( &f->picture, 0, sizeof( x264_picture_t ) ); - f->picture.i_width = param.i_width; - f->picture.i_height = param.i_height; - f->picture.i_plane = 3; + memset( &w->picture, 0, sizeof( x264_picture_t ) ); + w->picture.i_width = param.i_width; + w->picture.i_height = param.i_height; + w->picture.i_plane = 3; HBLog( "x264: opening with %dx%d iframes=%d", param.i_width, param.i_height, param.i_iframe ); } - return (HBWork*) f; + return w; } -void HBX264EncClose( HBWork **_f ) +void HBX264EncClose( HBWork ** _w ) { - HBX264Enc *f = (HBX264Enc*) *_f; - - x264_encoder_close( f->h ); - - if( f->buffer ) - { - HBBufferClose( &f->buffer ); - } - - free( f->name ); - - free( f ); - - *_f = NULL; + HBWork * w = *_w; + x264_encoder_close( w->h ); + free( w->name ); + free( w ); + *_w = NULL; } /* TODO trash buffer->pass == 1 @@ -90,29 +80,22 @@ void HBX264EncClose( HBWork **_f ) */ static int HBX264EncWork( HBWork * w ) { - HBX264Enc * f = (HBX264Enc*) w; - HBTitle * title = f->title; + HBTitle * title = w->title; - HBBuffer * frame; - int didSomething = 0; + HBBuffer * frame, * buffer; x264_nal_t *nal; int i_nal; int i; - if( f->buffer ) + if( HBFifoIsHalfFull( title->outFifo ) ) { - if( !HBFifoPush( title->outFifo, &f->buffer ) ) - { - /* nothing done */ - return 0; - } - didSomething = 1; + return 0; } - if( ( frame = HBFifoPop( title->scaledFifo ) ) == NULL ) + if( !( frame = HBFifoPop( title->scaledFifo ) ) ) { - return didSomething; + return 0; } if( frame->pass == 1 ) @@ -122,46 +105,51 @@ static int HBX264EncWork( HBWork * w ) return 1; } - f->picture.i_stride[0] = title->outWidth; - f->picture.i_stride[1] = title->outWidth/2; - f->picture.i_stride[2] = title->outWidth/2; + w->picture.i_stride[0] = title->outWidth; + w->picture.i_stride[1] = title->outWidth/2; + w->picture.i_stride[2] = title->outWidth/2; - f->picture.plane[0] = frame->data; - f->picture.plane[1] = &f->picture.plane[0][title->outWidth*title->outHeight]; - f->picture.plane[2] = &f->picture.plane[1][title->outWidth*title->outHeight/4]; + w->picture.plane[0] = frame->data; + w->picture.plane[1] = &w->picture.plane[0][title->outWidth*title->outHeight]; + w->picture.plane[2] = &w->picture.plane[1][title->outWidth*title->outHeight/4]; - x264_encoder_encode( f->h, &nal, &i_nal, &f->picture ); + x264_encoder_encode( w->h, &nal, &i_nal, &w->picture ); - f->buffer = HBBufferInit( 3 * title->outWidth * title->outHeight / 2 ); /* FIXME */ - f->buffer->keyFrame = 0; - f->buffer->position = frame->position; - f->buffer->size = 0; + buffer = HBBufferInit( 3 * title->outWidth * title->outHeight / 2 ); /* FIXME */ + buffer->keyFrame = 0; + buffer->position = frame->position; + buffer->size = 0; for( i = 0; i < i_nal; i++ ) { - int i_data = f->buffer->alloc - f->buffer->size; + int i_data = buffer->alloc - buffer->size; int i_size; - i_size = x264_nal_encode( &f->buffer->data[f->buffer->size], + i_size = x264_nal_encode( &buffer->data[buffer->size], &i_data, 1, &nal[i] ); if( i_size <= 0 ) { fprintf( stderr, "#################### error" ); } - f->buffer->size += i_size; + buffer->size += i_size; if( nal[i].i_ref_idc == NAL_PRIORITY_HIGH || nal[i].i_ref_idc == NAL_PRIORITY_HIGHEST ) { - f->buffer->keyFrame = 1; + buffer->keyFrame = 1; } } /* Inform the GUI about the current position */ - HBPosition( f->handle, frame->position ); + HBPosition( w->handle, frame->position ); HBBufferClose( &frame ); + if( !HBFifoPush( title->outFifo, &buffer ) ) + { + HBLog( "HBX264Enc: HBFifoPush failed" ); + } + return 1; } |