From: Jason Garrett-Glaser Date: Wed, 2 Jun 2010 08:07:44 +0000 (-0700) Subject: Add API function to fix x264_picture_t initialization X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=b794258670e914c34c8b644d3fdd7d5250029817;p=x264.git Add API function to fix x264_picture_t initialization Calling applications that do not use x264_picture_alloc need to use x264_picture_init to initialize x264_picture_t structures. Previously, if the calling application didn't zero x264_picture_t, Bad Things could happen. --- diff --git a/common/common.c b/common/common.c index 48e1bbc5..1ba420cb 100644 --- a/common/common.c +++ b/common/common.c @@ -994,13 +994,22 @@ static void x264_log_default( void *p_unused, int i_level, const char *psz_fmt, } /**************************************************************************** - * x264_picture_alloc: + * x264_picture_init: ****************************************************************************/ -int x264_picture_alloc( x264_picture_t *pic, int i_csp, int i_width, int i_height ) +void x264_picture_init( x264_picture_t *pic ) { memset( pic, 0, sizeof( x264_picture_t ) ); pic->i_type = X264_TYPE_AUTO; pic->i_qpplus1 = 0; + pic->i_pic_struct = PIC_STRUCT_AUTO; +} + +/**************************************************************************** + * x264_picture_alloc: + ****************************************************************************/ +int x264_picture_alloc( x264_picture_t *pic, int i_csp, int i_width, int i_height ) +{ + x264_picture_init( pic ); pic->img.i_csp = i_csp; pic->img.i_plane = 3; pic->img.plane[0] = x264_malloc( 3 * i_width * i_height / 2 ); @@ -1011,7 +1020,6 @@ int x264_picture_alloc( x264_picture_t *pic, int i_csp, int i_width, int i_heigh pic->img.i_stride[0] = i_width; pic->img.i_stride[1] = i_width / 2; pic->img.i_stride[2] = i_width / 2; - pic->i_pic_struct = PIC_STRUCT_AUTO; return 0; } diff --git a/input/avs.c b/input/avs.c index 9bf486bd..4c91a708 100644 --- a/input/avs.c +++ b/input/avs.c @@ -280,10 +280,9 @@ static int get_frame_total( hnd_t handle ) static int picture_alloc( x264_picture_t *pic, int i_csp, int i_width, int i_height ) { - memset( pic, 0, sizeof( x264_picture_t ) ); + x264_picture_init( pic ); pic->img.i_csp = i_csp; pic->img.i_plane = 3; - pic->i_pic_struct = PIC_STRUCT_AUTO; return 0; } diff --git a/x264.h b/x264.h index a4b34001..9cd4600d 100644 --- a/x264.h +++ b/x264.h @@ -35,7 +35,7 @@ #include -#define X264_BUILD 97 +#define X264_BUILD 98 /* x264_t: * opaque handler for encoder */ @@ -562,6 +562,11 @@ typedef struct void *opaque; } x264_picture_t; +/* x264_picture_init: + * initialize an x264_picture_t. Needs to be done if the calling application + * allocates its own x264_picture_t as opposed to using x264_picture_alloc. */ +void x264_picture_init( x264_picture_t *pic ); + /* x264_picture_alloc: * alloc data for a picture. You must call x264_picture_clean on it. * returns 0 on success, or -1 on malloc failure. */