]> git.sesse.net Git - x264/commitdiff
Add API function to fix x264_picture_t initialization
authorFiona Glaser <fiona@x264.com>
Wed, 2 Jun 2010 08:07:44 +0000 (01:07 -0700)
committerFiona Glaser <fiona@x264.com>
Wed, 2 Jun 2010 09:26:43 +0000 (02:26 -0700)
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.

common/common.c
input/avs.c
x264.h

index 48e1bbc5c3469dd7276dcff1def9d1d0cb2afaef..1ba420cbfdd911dbf54e90d26038c441f8605bd3 100644 (file)
@@ -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;
 }
 
index 9bf486bd1c08f11eb5a16b4a817b71f9d4ac459b..4c91a708b760d6f34a888e53529e4e2c0650dc5d 100644 (file)
@@ -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 a4b3400152ba63723bfa65a55810ea375cf3cc52..9cd4600d39096fcfe8d3a60bfbfdd2c8c91f124e 100644 (file)
--- a/x264.h
+++ b/x264.h
@@ -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. */