video-format: add alignment checks
authorWim Taymans <wtaymans@redhat.com>
Fri, 31 Oct 2014 09:34:46 +0000 (10:34 +0100)
committerWim Taymans <wtaymans@redhat.com>
Fri, 31 Oct 2014 10:23:21 +0000 (11:23 +0100)
Some of the ORC functions need specific alignment

gst-libs/gst/video/video-format.c

index 4985809..c23c08f 100644 (file)
@@ -65,6 +65,8 @@
    ((line & ~7) >> 2) + (line & 1) :            \
    line >> 2)
 
+#define IS_ALIGNED(x,n) ((((guintptr)(x)&((n)-1))) == 0)
+
 #define PACK_420 GST_VIDEO_FORMAT_AYUV, unpack_planar_420, 1, pack_planar_420
 static void
 unpack_planar_420 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
@@ -99,6 +101,8 @@ pack_planar_420 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *v_line = GET_V_LINE (uv);
   const guint8 *ayuv = src;
 
+  g_return_if_fail (IS_ALIGNED (src, 8));
+
   video_orc_pack_I420 (y_line, u_line, v_line, src, width / 2);
 
   if (width & 1) {
@@ -119,6 +123,8 @@ unpack_YUY2 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *line = GET_LINE (y);
   guint8 *d = dest;
 
+  g_return_if_fail (IS_ALIGNED (dest, 8));
+
   video_orc_unpack_YUY2 (dest, line, width / 2);
 
   if (width & 1) {
@@ -140,6 +146,8 @@ pack_YUY2 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *line = GET_LINE (y);
   const guint8 *ayuv = src;
 
+  g_return_if_fail (IS_ALIGNED (src, 8));
+
   video_orc_pack_YUY2 (line, src, width / 2);
 
   if (width & 1) {
@@ -160,6 +168,8 @@ unpack_UYVY (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *line = GET_LINE (y);
   guint8 *d = dest;
 
+  g_return_if_fail (IS_ALIGNED (dest, 8));
+
   video_orc_unpack_UYVY (dest, line, width / 2);
 
   if (width & 1) {
@@ -181,6 +191,8 @@ pack_UYVY (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *line = GET_LINE (y);
   const guint8 *ayuv = src;
 
+  g_return_if_fail (IS_ALIGNED (src, 8));
+
   video_orc_pack_UYVY (line, src, width / 2);
 
   if (width & 1) {
@@ -201,6 +213,8 @@ unpack_YVYU (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *line = GET_LINE (y);
   guint8 *d = dest;
 
+  g_return_if_fail (IS_ALIGNED (dest, 8));
+
   video_orc_unpack_YVYU (dest, line, width / 2);
 
   if (width & 1) {
@@ -222,6 +236,8 @@ pack_YVYU (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *line = GET_LINE (y);
   const guint8 *ayuv = src;
 
+  g_return_if_fail (IS_ALIGNED (src, 8));
+
   video_orc_pack_YVYU (line, src, width / 2);
 
   if (width & 1) {
@@ -514,6 +530,8 @@ unpack_Y41B (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *v_line = GET_V_LINE (y);
   guint8 *d = dest;
 
+  g_return_if_fail (IS_ALIGNED (dest, 8));
+
   video_orc_unpack_YUV9 (dest, y_line, u_line, v_line, width / 2);
 
   if (width & 1) {
@@ -569,6 +587,8 @@ unpack_Y42B (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *v_line = GET_V_LINE (y);
   guint8 *d = dest;
 
+  g_return_if_fail (IS_ALIGNED (dest, 8));
+
   video_orc_unpack_Y42B (dest, y_line, u_line, v_line, width / 2);
 
   if (width & 1) {
@@ -592,6 +612,8 @@ pack_Y42B (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *v_line = GET_V_LINE (y);
   const guint8 *ayuv = src;
 
+  g_return_if_fail (IS_ALIGNED (src, 8));
+
   video_orc_pack_Y42B (y_line, u_line, v_line, src, width / 2);
 
   if (width & 1) {
@@ -1038,6 +1060,8 @@ unpack_NV12 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *uv_line = GET_PLANE_LINE (1, uv);
   guint8 *d = dest;
 
+  g_return_if_fail (IS_ALIGNED (dest, 8));
+
   video_orc_unpack_NV12 (dest, y_line, uv_line, width / 2);
 
   if (width & 1) {
@@ -1061,6 +1085,8 @@ pack_NV12 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *uv_line = GET_PLANE_LINE (1, uv);
   const guint8 *ayuv = src;
 
+  g_return_if_fail (IS_ALIGNED (src, 8));
+
   video_orc_pack_NV12 (y_line, uv_line, src, width / 2);
 
   if (width & 1) {
@@ -1083,6 +1109,8 @@ unpack_NV21 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *uv_line = GET_PLANE_LINE (1, uv);
   guint8 *d = dest;
 
+  g_return_if_fail (IS_ALIGNED (dest, 8));
+
   video_orc_unpack_NV21 (dest, y_line, uv_line, width / 2);
 
   if (width & 1) {
@@ -1106,6 +1134,8 @@ pack_NV21 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *uv_line = GET_PLANE_LINE (1, uv);
   const guint8 *ayuv = src;
 
+  g_return_if_fail (IS_ALIGNED (src, 8));
+
   video_orc_pack_NV21 (y_line, uv_line, src, width / 2);
 
   if (width & 1) {
@@ -1127,6 +1157,8 @@ unpack_NV16 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *uv_line = GET_PLANE_LINE (1, y);
   guint8 *d = dest;
 
+  g_return_if_fail (IS_ALIGNED (dest, 8));
+
   video_orc_unpack_NV12 (dest, y_line, uv_line, width / 2);
 
   if (width & 1) {
@@ -1149,6 +1181,8 @@ pack_NV16 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *uv_line = GET_PLANE_LINE (1, y);
   const guint8 *ayuv = src;
 
+  g_return_if_fail (IS_ALIGNED (src, 8));
+
   video_orc_pack_NV12 (y_line, uv_line, src, width / 2);
 
   if (width & 1) {
@@ -1278,6 +1312,8 @@ pack_A420 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *a_line = GET_A_LINE (y);
   const guint8 *ayuv = src;
 
+  g_return_if_fail (IS_ALIGNED (src, 8));
+
   video_orc_pack_A420 (y_line, u_line, v_line, a_line, src, width / 2);
 
   if (width & 1) {
@@ -1390,6 +1426,8 @@ unpack_410 (const GstVideoFormatInfo * info, GstVideoPackFlags flags,
   guint8 *v_line = GET_V_LINE (uv);
   guint8 *d = dest;
 
+  g_return_if_fail (IS_ALIGNED (dest, 8));
+
   video_orc_unpack_YUV9 (dest, y_line, u_line, v_line, width / 2);
 
   if (width & 1) {