From: Loren Merritt Date: Sun, 9 Oct 2005 00:14:30 +0000 (+0000) Subject: don't allocate lowres planes if they won't be used (i.e. in the 2nd pass). X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=acee2d5168a39f301b7cda1d4effe943e321e1f8;p=x264.git don't allocate lowres planes if they won't be used (i.e. in the 2nd pass). git-svn-id: svn://svn.videolan.org/x264/trunk@320 df754926-b1dd-0310-bc7b-ec298dee348c --- diff --git a/common/common.h b/common/common.h index 403fb367..4149fbf6 100644 --- a/common/common.h +++ b/common/common.h @@ -279,6 +279,7 @@ struct x264_t int i_max_ref0; int i_max_ref1; int i_delay; /* Number of frames buffered for B reordering */ + int b_have_lowres; /* Whether 1/2 resolution luma planes are being used */ } frames; /* current frame being encoded */ diff --git a/common/frame.c b/common/frame.c index 69a42b8a..b23e38c4 100644 --- a/common/frame.c +++ b/common/frame.c @@ -37,6 +37,8 @@ x264_frame_t *x264_frame_new( x264_t *h ) int i_stride; int i_lines; + memset( frame, 0, sizeof(x264_frame_t) ); + /* allocate frame data (+64 for extra data for me) */ i_stride = ( ( h->param.i_width + 15 )&0xfffff0 )+ 64; i_lines = ( ( h->param.i_height + 15 )&0xfffff0 ); @@ -76,14 +78,17 @@ x264_frame_t *x264_frame_new( x264_t *h ) frame->i_stride[0] * 32 + 32; } - frame->i_stride_lowres = frame->i_stride[0]/2 + 32; - frame->i_lines_lowres = frame->i_lines[0]/2; - for( i = 0; i < 4; i++ ) + if( h->frames.b_have_lowres ) { - frame->buffer[7+i] = x264_malloc( frame->i_stride_lowres * - ( frame->i_lines[0]/2 + 64 ) ); - frame->lowres[i] = ((uint8_t*)frame->buffer[7+i]) + - frame->i_stride_lowres * 32 + 32; + frame->i_stride_lowres = frame->i_stride[0]/2 + 32; + frame->i_lines_lowres = frame->i_lines[0]/2; + for( i = 0; i < 4; i++ ) + { + frame->buffer[7+i] = x264_malloc( frame->i_stride_lowres * + ( frame->i_lines[0]/2 + 64 ) ); + frame->lowres[i] = ((uint8_t*)frame->buffer[7+i]) + + frame->i_stride_lowres * 32 + 32; + } } frame->i_poc = -1; diff --git a/encoder/encoder.c b/encoder/encoder.c index 3ca83ea7..a34dfa8b 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -544,6 +544,8 @@ x264_t *x264_encoder_open ( x264_param_t *param ) h->frames.i_max_ref0 = h->param.i_frame_reference; h->frames.i_max_ref1 = h->sps->vui.i_num_reorder_frames; h->frames.i_max_dpb = h->sps->vui.i_max_dec_frame_buffering + 1; + h->frames.b_have_lowres = !h->param.rc.b_stat_read + && ( h->param.rc.b_cbr || h->param.b_bframe_adaptive ); for( i = 0; i < X264_BFRAME_MAX + 3; i++ ) { @@ -1201,7 +1203,8 @@ int x264_encoder_encode( x264_t *h, x264_frame_put( h->frames.next, fenc ); - x264_frame_init_lowres( h->param.cpu, fenc ); + if( h->frames.b_have_lowres ) + x264_frame_init_lowres( h->param.cpu, fenc ); if( h->frames.i_input <= h->frames.i_delay ) {