documentation: fixed a heap o' typos
[platform/upstream/gstreamer.git] / ext / directfb / dfbvideosink.c
index 5723e6d..ae042e6 100644 (file)
 
 /**
  * SECTION:element-dfbvideosink
+ * @title: dfbvideosink
  *
  * DfbVideoSink renders video frames using the
- * <ulink url="http://www.directfb.org/">DirectFB</ulink> library.
+ * [DirectFB](http://www.directfb.org/) library.
  * Rendering can happen in two different modes :
- * <itemizedlist>
- * <listitem>
- *   <para>
- *   Standalone: this mode will take complete control of the monitor forcing
- *   <ulink url="http://www.directfb.org/">DirectFB</ulink> to fullscreen layout.
+ *
+ * * Standalone: this mode will take complete control of the monitor forcing
+ *   DirectFB to fullscreen layout.
+ *
  *   This is convenient to test using the  gst-launch-1.0 command line tool or
  *   other simple applications. It is possible to interrupt playback while
  *   being in this mode by pressing the Escape key.
- *   </para>
- *   <para>
  *   This mode handles navigation events for every input device supported by
- *   the <ulink url="http://www.directfb.org/">DirectFB</ulink> library, it will
- *   look for available video modes in the fb.modes file and try to switch
- *   the framebuffer video mode to the most suitable one. Depending on 
- *   hardware acceleration capabilities the element will handle scaling or not.
+ *   the DirectFB library, it will look for available video modes in the fb.modes
+ *   file and try to switch the framebuffer video mode to the most suitable one.
+ *   Depending on hardware acceleration capabilities the element will handle
+ *   scaling or not.
+ *
  *   If no acceleration is available it will do clipping or centering of the
  *   video frames respecting the original aspect ratio.
- *   </para>
- * </listitem>
- * <listitem>
- *   <para>
- *   Embedded: this mode will render video frames in a 
+ *
+ * * Embedded: this mode will render video frames in a
  *   #GstDfbVideoSink:surface provided by the
  *   application developer. This is a more advanced usage of the element and
- *   it is required to integrate video playback in existing 
- *   <ulink url="http://www.directfb.org/">DirectFB</ulink> applications.
- *   </para>
- *   <para>
+ *   it is required to integrate video playback in existing
+ *   DirectFB applications.
+ *
  *   When using this mode the element just renders to the
- *   #GstDfbVideoSink:surface provided by the 
+ *   #GstDfbVideoSink:surface provided by the
  *   application, that means it won't handle navigation events and won't resize
  *   the #GstDfbVideoSink:surface to fit video
  *   frames geometry. Application has to implement the necessary code to grab
- *   informations about the negotiated geometry and resize there
+ *   information about the negotiated geometry and resize there
  *   #GstDfbVideoSink:surface accordingly.
- *   </para>
- * </listitem>
- * </itemizedlist>
- * For both modes the element implements a buffer pool allocation system to 
- * optimize memory allocation time and handle reverse negotiation. Indeed if 
+ *
+ * For both modes the element implements a buffer pool allocation system to
+ * optimize memory allocation time and handle reverse negotiation. Indeed if
  * you insert an element like videoscale in the pipeline the video sink will
  * negotiate with it to try get a scaled video for either the fullscreen layout
  * or the application provided external #GstDfbVideoSink:surface.
  *
- * <refsect2>
- * <title>Example application</title>
- * <para>
+ * ## Example application
+ *
  * <include xmlns="http://www.w3.org/2003/XInclude" href="element-dfb-example.xml" />
- * </para>
- * </refsect2>
- * <refsect2>
- * <title>Example pipelines</title>
+ *
+ * ## Example pipelines
  * |[
  * gst-launch-1.0 -v videotestsrc ! dfbvideosink hue=20000 saturation=40000 brightness=25000
  * ]| test the colorbalance interface implementation in dfbvideosink
- * </refsect2>
  */
 
 #ifdef HAVE_CONFIG_H
@@ -168,6 +157,19 @@ gst_meta_dfbsurface_api_get_type (void)
   return type;
 }
 
+static gboolean
+gst_meta_dfbsurface_init (GstMetaDfbSurface * meta, gpointer params,
+    GstBuffer * buf)
+{
+  meta->surface = NULL;
+  meta->width = meta->height = 0;
+  meta->locked = FALSE;
+  meta->pixel_format = 0;
+  meta->dfbvideosink = NULL;
+
+  return TRUE;
+}
+
 /* our metadata */
 const GstMetaInfo *
 gst_meta_dfbsurface_get_info (void)
@@ -178,7 +180,8 @@ gst_meta_dfbsurface_get_info (void)
     const GstMetaInfo *meta =
         gst_meta_register (gst_meta_dfbsurface_api_get_type (),
         "GstMetaDfbSurface", sizeof (GstMetaDfbSurface),
-        (GstMetaInitFunction) NULL, (GstMetaFreeFunction) NULL,
+        (GstMetaInitFunction) gst_meta_dfbsurface_init,
+        (GstMetaFreeFunction) NULL,
         (GstMetaTransformFunction) NULL);
     g_once_init_leave (&meta_info, meta);
   }
@@ -466,6 +469,7 @@ gst_dfb_buffer_pool_new (GstDfbVideoSink * dfbvideosink)
   g_return_val_if_fail (GST_IS_DFBVIDEOSINK (dfbvideosink), NULL);
 
   pool = g_object_new (GST_TYPE_DFB_BUFFER_POOL, NULL);
+  g_object_ref_sink (pool);
   pool->dfbvideosink = gst_object_ref (dfbvideosink);
 
   GST_LOG_OBJECT (pool, "new dfb buffer pool %p", pool);
@@ -796,7 +800,7 @@ gst_dfbvideosink_setup (GstDfbVideoSink * dfbvideosink)
   dfbvideosink->backbuffer = FALSE;
   dfbvideosink->pixel_format = DSPF_UNKNOWN;
 
-  /* If we do it all by ourself we create the DirectFB context, get the 
+  /* If we do it all by ourself we create the DirectFB context, get the
      primary layer and use a fullscreen configuration */
   if (!dfbvideosink->ext_surface) {
     GST_DEBUG_OBJECT (dfbvideosink, "no external surface, taking over "
@@ -1848,6 +1852,7 @@ gst_dfbvideosink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
     caps = gst_pad_get_current_caps (GST_BASE_SINK_PAD (bsink));
     if (!gst_video_info_from_caps (&src_info, caps)) {
       GST_WARNING_OBJECT (dfbvideosink, "failed getting video info");
+      gst_caps_unref (caps);
       ret = GST_FLOW_ERROR;
       goto beach;
     }
@@ -1855,6 +1860,7 @@ gst_dfbvideosink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
     str = gst_structure_get_string (structure, "format");
     if (str == NULL) {
       GST_WARNING ("failed grabbing fourcc from caps %" GST_PTR_FORMAT, caps);
+      gst_caps_unref (caps);
       ret = GST_FLOW_ERROR;
       goto beach;
     }
@@ -2026,8 +2032,14 @@ gst_dfbvideosink_navigation_send_event (GstNavigation * navigation,
   pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (dfbvideosink));
 
   if (GST_IS_PAD (pad) && GST_IS_EVENT (event)) {
-    gst_pad_send_event (pad, event);
-
+    if (!gst_pad_send_event (pad, gst_event_ref (event))) {
+      /* If upstream didn't handle the event we'll post a message with it
+       * for the application in case it wants to do something with it */
+      gst_element_post_message (GST_ELEMENT_CAST (dfbvideosink),
+          gst_navigation_message_new_event (GST_OBJECT_CAST (dfbvideosink),
+              event));
+    }
+    gst_event_unref (event);
     gst_object_unref (pad);
   }
 }
@@ -2264,6 +2276,12 @@ gst_dfbvideosink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
 
   gst_query_parse_allocation (query, &caps, &need_pool);
 
+  if (!caps) {
+    GST_WARNING_OBJECT (dfbvideosink, "Missing caps in allocation query.");
+    return FALSE;
+  }
+
+  /* FIXME re-using buffer pool breaks renegotiation */
   if ((pool = dfbvideosink->pool))
     gst_object_ref (pool);
 
@@ -2284,6 +2302,16 @@ gst_dfbvideosink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
       return FALSE;
     }
     gst_structure_free (config);
+  } else {
+    GstVideoInfo info;
+
+    if (!gst_video_info_from_caps (&info, caps)) {
+      GST_WARNING_OBJECT (dfbvideosink,
+          "Invalid video caps in allocation query");
+      return FALSE;
+    }
+
+    size = info.size;
   }
 
   gst_query_add_allocation_pool (query, pool, size, 1, 0);
@@ -2442,6 +2470,6 @@ plugin_init (GstPlugin * plugin)
 
 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
     GST_VERSION_MINOR,
-    dfbvideosink,
+    directfb,
     "DirectFB video output plugin",
     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)