Commit 36bbd4d2 authored by Fiona Glaser's avatar Fiona Glaser

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.
parent f857c08d
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -35,7 +35,7 @@
#include <stdarg.h>
#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. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment