video: Add gst_video_info_set_interlaced_format()
authorZeeshan Ali <zeenix@collabora.co.uk>
Mon, 2 Jul 2018 14:48:30 +0000 (16:48 +0200)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 29 Aug 2018 16:14:38 +0000 (12:14 -0400)
Add a helper to set the interlacing mode while creating the GstVideoInfo
in addition to format and resolution. Using this helper will ensure that
size is correctly calculated for split-field interlacing mode.

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

gst-libs/gst/video/video-info.c
gst-libs/gst/video/video-info.h
tests/check/libs/video.c

index 0e764a7..7a8f4ad 100644 (file)
@@ -195,6 +195,28 @@ validate_colorimetry (GstVideoInfo * info)
   return TRUE;
 }
 
+static gboolean
+gst_video_info_set_format_common (GstVideoInfo * info, GstVideoFormat format,
+    guint width, guint height)
+{
+  g_return_val_if_fail (info != NULL, FALSE);
+  g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, FALSE);
+
+  if (width > G_MAXINT || height > G_MAXINT)
+    return FALSE;
+
+  gst_video_info_init (info);
+
+  info->finfo = gst_video_format_get_info (format);
+  info->width = width;
+  info->height = height;
+  info->views = 1;
+
+  set_default_colorimetry (info);
+
+  return TRUE;
+}
+
 /**
  * gst_video_info_set_format:
  * @info: a #GstVideoInfo
@@ -215,21 +237,37 @@ gboolean
 gst_video_info_set_format (GstVideoInfo * info, GstVideoFormat format,
     guint width, guint height)
 {
-  g_return_val_if_fail (info != NULL, FALSE);
-  g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, FALSE);
-
-  if (width > G_MAXINT || height > G_MAXINT)
+  if (!gst_video_info_set_format_common (info, format, width, height))
     return FALSE;
 
-  gst_video_info_init (info);
-
-  info->finfo = gst_video_format_get_info (format);
-  info->width = width;
-  info->height = height;
-  info->views = 1;
+  return fill_planes (info);
+}
 
-  set_default_colorimetry (info);
+/**
+ * gst_video_info_set_interlaced_format:
+ * @info: a #GstVideoInfo
+ * @format: the format
+ * @mode: a #GstVideoInterlaceMode
+ * @width: a width
+ * @height: a height
+ *
+ * Same as #gst_video_info_set_format but also allowing to set the interlaced
+ * mode.
+ *
+ * Returns: %FALSE if the returned video info is invalid, e.g. because the
+ *   size of a frame can't be represented as a 32 bit integer.
+ *
+ * Since: 1.16
+ */
+gboolean
+gst_video_info_set_interlaced_format (GstVideoInfo * info,
+    GstVideoFormat format, GstVideoInterlaceMode mode, guint width,
+    guint height)
+{
+  if (!gst_video_info_set_format_common (info, format, width, height))
+    return FALSE;
 
+  GST_VIDEO_INFO_INTERLACE_MODE (info) = mode;
   return fill_planes (info);
 }
 
index f9de938..36268a9 100644 (file)
@@ -403,6 +403,14 @@ gboolean       gst_video_info_set_format  (GstVideoInfo *info, GstVideoFormat fo
                                            guint width, guint height);
 
 GST_VIDEO_API
+gboolean       gst_video_info_set_interlaced_format
+                                          (GstVideoInfo         *info,
+                                           GstVideoFormat        format,
+                                           GstVideoInterlaceMode mode,
+                                           guint                 width,
+                                           guint                 height);
+
+GST_VIDEO_API
 gboolean       gst_video_info_from_caps   (GstVideoInfo *info, const GstCaps  * caps);
 
 GST_VIDEO_API
index ade6276..3d94ff4 100644 (file)
@@ -1206,8 +1206,10 @@ GST_START_TEST (test_interlace_mode)
   gst_video_info_init (&vinfo);
 
   /* Progressive */
-  gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_YV12, 320, 240);
-  GST_VIDEO_INFO_INTERLACE_MODE (&vinfo) = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
+  fail_unless (gst_video_info_set_interlaced_format (&vinfo,
+          GST_VIDEO_FORMAT_YV12, GST_VIDEO_INTERLACE_MODE_PROGRESSIVE, 320,
+          240));
+  fail_unless (GST_VIDEO_INFO_SIZE (&vinfo) == 115200);
 
   caps = gst_video_info_to_caps (&vinfo);
   fail_unless (caps != NULL);
@@ -1225,8 +1227,9 @@ GST_START_TEST (test_interlace_mode)
   gst_caps_unref (caps);
 
   /* Interlaced with alternate frame on buffers */
-  gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_YV12, 320, 240);
-  GST_VIDEO_INFO_INTERLACE_MODE (&vinfo) = GST_VIDEO_INTERLACE_MODE_ALTERNATE;
+  fail_unless (gst_video_info_set_interlaced_format (&vinfo,
+          GST_VIDEO_FORMAT_YV12, GST_VIDEO_INTERLACE_MODE_ALTERNATE, 320, 240));
+  fail_unless (GST_VIDEO_INFO_SIZE (&vinfo) == 57600);
 
   caps = gst_video_info_to_caps (&vinfo);
   fail_unless (caps != NULL);