diff options
author | eddyg <[email protected]> | 2007-12-12 01:05:02 +0000 |
---|---|---|
committer | eddyg <[email protected]> | 2007-12-12 01:05:02 +0000 |
commit | 292e07d1b5a84c3502363dab56bdaddb805b68f1 (patch) | |
tree | 1752f3b8896241eb5baee1549ab8510cf0aafc22 | |
parent | 51be4f891f243d6ef757cbfd9fc272f63b72c35a (diff) |
Don't copy the frame before passing it to x264, let x264 look directly into our HB buffer instead. x264 will copy the data from it as required.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1116 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/encx264.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/libhb/encx264.c b/libhb/encx264.c index fa41a5f78..b7e08b8cc 100644 --- a/libhb/encx264.c +++ b/libhb/encx264.c @@ -30,6 +30,7 @@ struct hb_work_private_s hb_job_t * job; x264_t * x264; x264_picture_t pic_in; + uint8_t *x264_allocated_pic; // Internal queue of DTS start/stop values. int64_t dts_start[DTS_BUFFER_SIZE]; @@ -241,7 +242,9 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job ) memcpy( &w->config->h264.pps[1], nal[2].p_payload, nal[2].i_payload ); x264_picture_alloc( &pv->pic_in, X264_CSP_I420, - job->width, job->height ); + job->width, job->height ); + + pv->x264_allocated_pic = pv->pic_in.img.plane[0]; pv->dts_write_index = 0; pv->dts_read_index = 0; @@ -253,6 +256,11 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job ) void encx264Close( hb_work_object_t * w ) { hb_work_private_t * pv = w->private_data; + /* + * Patch the x264 allocated data back in so that x264 can free it + * we have been using our own buffers during the encode to avoid copying. + */ + pv->pic_in.img.plane[0] = pv->x264_allocated_pic; x264_picture_clean( &pv->pic_in ); x264_encoder_close( pv->x264 ); free( pv ); @@ -274,8 +282,11 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in, if( in->data ) { - /* XXX avoid this memcpy ? */ - memcpy( pv->pic_in.img.plane[0], in->data, job->width * job->height ); + /* + * Point x264 at our current buffers Y(UV) data. + */ + pv->pic_in.img.plane[0] = in->data; + if( job->grayscale ) { /* XXX x264 has currently no option for grayscale encoding */ @@ -284,10 +295,12 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in, } else { - memcpy( pv->pic_in.img.plane[1], in->data + job->width * job->height, - job->width * job->height / 4 ); - memcpy( pv->pic_in.img.plane[2], in->data + 5 * job->width * - job->height / 4, job->width * job->height / 4 ); + /* + * Point x264 at our buffers (Y)UV data + */ + pv->pic_in.img.plane[1] = in->data + job->width * job->height; + pv->pic_in.img.plane[2] = in->data + 5 * job->width * + job->height / 4; } if( in->new_chap && job->chapter_markers ) |