ximageutil: shouldn't implement transform if don't support it
[platform/upstream/gst-plugins-good.git] / sys / ximage / ximageutil.c
index 4e599b3..57c9392 100644 (file)
@@ -13,8 +13,8 @@
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
 
 #include "ximageutil.h"
 
+GType
+gst_meta_ximage_api_get_type (void)
+{
+  static volatile GType type;
+  static const gchar *tags[] = { "memory", NULL };
+
+  if (g_once_init_enter (&type)) {
+    GType _type = gst_meta_api_type_register ("GstMetaXImageSrcAPI", tags);
+    g_once_init_leave (&type, _type);
+  }
+  return type;
+}
+
+static gboolean
+gst_meta_ximage_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
+{
+  GstMetaXImage *emeta = (GstMetaXImage *) meta;
+
+  emeta->parent = NULL;
+  emeta->ximage = NULL;
+#ifdef HAVE_XSHM
+  emeta->SHMInfo.shmaddr = ((void *) -1);
+  emeta->SHMInfo.shmid = -1;
+  emeta->SHMInfo.readOnly = TRUE;
+#endif
+  emeta->width = emeta->height = emeta->size = 0;
+  emeta->return_func = NULL;
+
+  return TRUE;
+}
+
 const GstMetaInfo *
 gst_meta_ximage_get_info (void)
 {
   static const GstMetaInfo *meta_ximage_info = NULL;
 
-  if (meta_ximage_info == NULL) {
-    meta_ximage_info =
-        gst_meta_register ("GstMetaXImageSrc", "GstMetaXImageSrc",
-        sizeof (GstMetaXImage), (GstMetaInitFunction) NULL,
-        (GstMetaFreeFunction) NULL, (GstMetaTransformFunction) NULL,
-        (GstMetaSerializeFunction) NULL, (GstMetaDeserializeFunction) NULL);
+  if (g_once_init_enter (&meta_ximage_info)) {
+    const GstMetaInfo *meta =
+        gst_meta_register (gst_meta_ximage_api_get_type (), "GstMetaXImageSrc",
+        sizeof (GstMetaXImage), (GstMetaInitFunction) gst_meta_ximage_init,
+        (GstMetaFreeFunction) NULL, (GstMetaTransformFunction) NULL);
+    g_once_init_leave (&meta_ximage_info, meta);
   }
   return meta_ximage_info;
 }
@@ -162,18 +193,17 @@ ximageutil_xcontext_get (GstElement * parent, const gchar * display_name)
     return NULL;
   }
   xcontext->screen = DefaultScreenOfDisplay (xcontext->disp);
-  xcontext->screen_num = DefaultScreen (xcontext->disp);
-  xcontext->visual = DefaultVisual (xcontext->disp, xcontext->screen_num);
-  xcontext->root = DefaultRootWindow (xcontext->disp);
-  xcontext->white = XWhitePixel (xcontext->disp, xcontext->screen_num);
-  xcontext->black = XBlackPixel (xcontext->disp, xcontext->screen_num);
+  xcontext->visual = DefaultVisualOfScreen (xcontext->screen);
+  xcontext->root = RootWindowOfScreen (xcontext->screen);
+  xcontext->white = WhitePixelOfScreen (xcontext->screen);
+  xcontext->black = BlackPixelOfScreen (xcontext->screen);
   xcontext->depth = DefaultDepthOfScreen (xcontext->screen);
 
-  xcontext->width = DisplayWidth (xcontext->disp, xcontext->screen_num);
-  xcontext->height = DisplayHeight (xcontext->disp, xcontext->screen_num);
+  xcontext->width = WidthOfScreen (xcontext->screen);
+  xcontext->height = HeightOfScreen (xcontext->screen);
 
-  xcontext->widthmm = DisplayWidthMM (xcontext->disp, xcontext->screen_num);
-  xcontext->heightmm = DisplayHeightMM (xcontext->disp, xcontext->screen_num);
+  xcontext->widthmm = WidthMMOfScreen (xcontext->screen);
+  xcontext->heightmm = HeightMMOfScreen (xcontext->screen);
 
   xcontext->caps = NULL;
 
@@ -245,11 +275,6 @@ ximageutil_xcontext_clear (GstXContext * xcontext)
   if (xcontext->caps != NULL)
     gst_caps_unref (xcontext->caps);
 
-  if (xcontext->par) {
-    g_value_unset (xcontext->par);
-    g_free (xcontext->par);
-  }
-
   XCloseDisplay (xcontext->disp);
 
   g_free (xcontext);
@@ -301,23 +326,17 @@ ximageutil_calculate_pixel_aspect_ratio (GstXContext * xcontext)
   GST_DEBUG ("Decided on index %d (%d/%d)", index,
       par[index][0], par[index][1]);
 
-  if (xcontext->par)
-    g_free (xcontext->par);
-  xcontext->par = g_new0 (GValue, 1);
-  g_value_init (xcontext->par, GST_TYPE_FRACTION);
-  gst_value_set_fraction (xcontext->par, par[index][0], par[index][1]);
-  GST_DEBUG ("set xcontext PAR to %d/%d\n",
-      gst_value_get_fraction_numerator (xcontext->par),
-      gst_value_get_fraction_denominator (xcontext->par));
+  xcontext->par_n = par[index][0];
+  xcontext->par_d = par[index][1];
+  GST_DEBUG ("set xcontext PAR to %d/%d\n", xcontext->par_n, xcontext->par_d);
 }
 
-static void
+static gboolean
 gst_ximagesrc_buffer_dispose (GstBuffer * ximage)
 {
   GstElement *parent;
   GstMetaXImage *meta;
-
-  g_return_if_fail (ximage != NULL);
+  gboolean ret = TRUE;
 
   meta = GST_META_XIMAGE_GET (ximage);
 
@@ -328,10 +347,10 @@ gst_ximagesrc_buffer_dispose (GstBuffer * ximage)
   }
 
   if (meta->return_func)
-    meta->return_func (parent, ximage);
+    ret = meta->return_func (parent, ximage);
 
 beach:
-  return;
+  return ret;
 }
 
 void
@@ -421,8 +440,9 @@ gst_ximageutil_ximage_new (GstXContext * xcontext,
   }
   succeeded = TRUE;
 
-  GST_BUFFER_DATA (ximage) = (guchar *) meta->ximage->data;
-  GST_BUFFER_SIZE (ximage) = meta->size;
+  gst_buffer_append_memory (ximage,
+      gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, meta->ximage->data,
+          meta->size, 0, meta->size, NULL, NULL));
 
   /* Keep a ref to our src */
   meta->parent = gst_object_ref (parent);