opencvvideofilter: Don't parse the caps twice
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 30 Nov 2016 02:09:14 +0000 (21:09 -0500)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 30 Nov 2016 02:21:49 +0000 (21:21 -0500)
The GstVideoFilter already provide caps parsed into GstVideoInfo. Avoid
doing that twice by splitting the helper.

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

gst-libs/gst/opencv/gstopencvutils.cpp
gst-libs/gst/opencv/gstopencvutils.h
gst-libs/gst/opencv/gstopencvvideofilter.cpp

index 640486b..e070c70 100644 (file)
@@ -32,9 +32,6 @@ gst_opencv_parse_iplimage_params_from_caps (GstCaps * caps, gint * width,
     gint * height, gint * ipldepth, gint * channels, GError ** err)
 {
   GstVideoInfo info;
-  gint depth = 0;
-  guint i;
-  gchar *caps_str;
 
   if (!gst_video_info_from_caps (&info, caps)) {
     GST_ERROR ("Failed to get the videoinfo from caps");
@@ -43,22 +40,32 @@ gst_opencv_parse_iplimage_params_from_caps (GstCaps * caps, gint * width,
     return FALSE;
   }
 
-  *width = GST_VIDEO_INFO_WIDTH (&info);
-  *height = GST_VIDEO_INFO_HEIGHT (&info);
-  if (GST_VIDEO_INFO_IS_RGB (&info))
+  return gst_opencv_iplimage_params_from_video_info (&info, width, height,
+          ipldepth, channels, err);
+}
+
+gboolean
+gst_opencv_iplimage_params_from_video_info (GstVideoInfo * info, gint * width,
+    gint * height, gint * ipldepth, gint * channels, GError ** err)
+{
+  gint depth = 0;
+  guint i;
+
+  *width = GST_VIDEO_INFO_WIDTH (info);
+  *height = GST_VIDEO_INFO_HEIGHT (info);
+  if (GST_VIDEO_INFO_IS_RGB (info))
     *channels = 3;
-  else if (GST_VIDEO_INFO_IS_GRAY (&info))
+  else if (GST_VIDEO_INFO_IS_GRAY (info))
     *channels = 1;
   else {
-    caps_str = gst_caps_to_string (caps);
     g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
-        "Unsupported caps %s", caps_str);
-    g_free (caps_str);
+        "Unsupported video format %s",
+        gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (info)));
     return FALSE;
   }
 
-  for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (&info); i++)
-    depth += GST_VIDEO_INFO_COMP_DEPTH (&info, i);
+  for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
+    depth += GST_VIDEO_INFO_COMP_DEPTH (info, i);
 
   if (depth / *channels == 8) {
     /* TODO signdness? */
index 13dfd9e..4cd32d8 100644 (file)
@@ -36,6 +36,10 @@ gboolean gst_opencv_parse_iplimage_params_from_caps
     (GstCaps * caps, gint * width, gint * height, gint * depth,
     gint * channels, GError ** err);
 
+gboolean gst_opencv_iplimage_params_from_video_info
+    (GstVideoInfo * info, gint * width, gint * height, gint * depth,
+    gint * channels, GError ** err);
+
 GstCaps * gst_opencv_caps_from_cv_image_type (int cv_type);
 G_END_DECLS
 
index 7d02742..7f520b1 100644 (file)
@@ -192,7 +192,7 @@ gst_opencv_video_filter_set_info (GstVideoFilter * trans, GstCaps * incaps,
   GError *in_err = NULL;
   GError *out_err = NULL;
 
-  if (!gst_opencv_parse_iplimage_params_from_caps (incaps, &in_width,
+  if (!gst_opencv_iplimage_params_from_video_info (in_info, &in_width,
           &in_height, &in_depth, &in_channels, &in_err)) {
     GST_WARNING_OBJECT (transform, "Failed to parse input caps: %s",
         in_err->message);
@@ -200,7 +200,7 @@ gst_opencv_video_filter_set_info (GstVideoFilter * trans, GstCaps * incaps,
     return FALSE;
   }
 
-  if (!gst_opencv_parse_iplimage_params_from_caps (outcaps, &out_width,
+  if (!gst_opencv_iplimage_params_from_video_info (out_info, &out_width,
           &out_height, &out_depth, &out_channels, &out_err)) {
     GST_WARNING_OBJECT (transform, "Failed to parse output caps: %s",
         out_err->message);