[x264-devel] commit: Add API function to fix x264_picture_t initialization ( Jason Garrett-Glaser )
git at videolan.org
git at videolan.org
Wed Jun 2 22:00:58 CEST 2010
x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Wed Jun 2 01:07:44 2010 -0700| [b794258670e914c34c8b644d3fdd7d5250029817] | committer: Jason Garrett-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.
> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=b794258670e914c34c8b644d3fdd7d5250029817
---
common/common.c | 14 +++++++++++---
input/avs.c | 3 +--
x264.h | 7 ++++++-
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/common/common.c b/common/common.c
index 48e1bbc..1ba420c 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 9bf486b..4c91a70 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 a4b3400..9cd4600 100644
--- 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. */
More information about the x264-devel
mailing list