glmemory: use the plane offsets to compute the size of the data pointer
authorMatthew Waters <ystreet00@gmail.com>
Thu, 31 Jul 2014 05:18:04 +0000 (15:18 +1000)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:31:45 +0000 (19:31 +0000)
Certain elements expect that there be a certain number of lines
that they can write into.  e.g. for odd heights, I420, YV12, NV12,
NV21 (and others) Y lines are expected to have exactly twice the
number of U/UV lines.

https://bugzilla.gnome.org/show_bug.cgi?id=733717

gst-libs/gst/gl/gstglmemory.c

index ad7da14..3d1d4fc 100644 (file)
@@ -345,6 +345,15 @@ _get_plane_height (GstVideoInfo * info, guint plane)
     return GST_VIDEO_INFO_HEIGHT (info);
 }
 
+static inline gsize
+_get_plane_data_size (GstVideoInfo * info, guint plane)
+{
+  if (GST_VIDEO_INFO_N_PLANES (info) == plane + 1)
+    return info->offset[0] + info->size - info->offset[plane];
+
+  return info->offset[plane + 1] - info->offset[plane];
+}
+
 typedef struct _GenTexture
 {
   guint width, height;
@@ -566,9 +575,9 @@ _gl_mem_init (GstGLMemory * mem, GstAllocator * allocator, GstMemory * parent,
 {
   gsize maxsize;
 
-  maxsize =
-      GST_VIDEO_INFO_PLANE_STRIDE (info, plane) * _get_plane_height (info,
-      plane);
+  g_return_if_fail (plane < GST_VIDEO_INFO_N_PLANES (info));
+
+  maxsize = _get_plane_data_size (info, plane);
 
   gst_memory_init (GST_MEMORY_CAST (mem), GST_MEMORY_FLAG_NO_SHARE,
       allocator, parent, maxsize, 0, 0, maxsize);
@@ -587,8 +596,8 @@ _gl_mem_init (GstGLMemory * mem, GstAllocator * allocator, GstMemory * parent,
   _calculate_unpack_length (mem);
 
   GST_CAT_DEBUG (GST_CAT_GL_MEMORY, "new GL texture memory:%p format:%u "
-      "dimensions:%ux%u", mem, mem->tex_type, mem->tex_width,
-      GL_MEM_HEIGHT (mem));
+      "dimensions:%ux%u size:%" G_GSIZE_FORMAT, mem, mem->tex_type,
+      mem->tex_width, GL_MEM_HEIGHT (mem), maxsize);
 }
 
 static GstGLMemory *