vaapisink: fix initialization with "drm" display type. upstream/0.2.6+1235+g5e5d62c
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Fri, 7 Mar 2014 16:40:34 +0000 (17:40 +0100)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Fri, 13 Jun 2014 15:42:35 +0000 (17:42 +0200)
Force early initializatin of the GstVaapiDisplay so that to make sure
that the sink element display object is presented first to upstream
elements, as it will be correctly featuring the requested display type
by the user.

Otherwise, we might end up in situations where a VA/X11 display is
initialized in vaapidecode, then we try VA/DRM display in vaapisink
(as requested by the "display" property), but this would cause a failure
because we cannot acquire a DRM display that was previously acquired
through another backend (e.g. VA/X11).

gst/vaapi/gstvaapisink.c

index d9fd703..ad4d8d7 100644 (file)
@@ -898,10 +898,14 @@ gst_vaapisink_show_frame_glx(
     guint                       flags
 )
 {
-    GstVaapiWindowGLX * const window = GST_VAAPI_WINDOW_GLX(sink->window);
+    GstVaapiWindowGLX *window;
     GLenum target;
     GLuint texture;
 
+    if (!sink->window)
+        return FALSE;
+    window = GST_VAAPI_WINDOW_GLX(sink->window);
+
     gst_vaapi_window_glx_make_current(window);
     if (!gst_vaapisink_ensure_texture(sink, surface))
         goto error_create_texture;
@@ -960,6 +964,9 @@ gst_vaapisink_put_surface(
     guint                       flags
 )
 {
+    if (!sink->window)
+        return FALSE;
+
     if (!gst_vaapi_window_put_surface(sink->window, surface,
                 surface_rect, &sink->display_rect, flags)) {
         GST_DEBUG("could not render VA surface");
@@ -1004,9 +1011,6 @@ gst_vaapisink_show_frame(GstBaseSink *base_sink, GstBuffer *src_buffer)
     GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE(sink,
         gst_vaapi_video_meta_get_display(meta));
 
-    if (!sink->window)
-        goto error;
-
     gst_vaapisink_ensure_rotation(sink, TRUE);
 
     surface = gst_vaapi_video_meta_get_surface(meta);
@@ -1207,6 +1211,19 @@ gst_vaapisink_get_property(
 }
 
 static void
+gst_vaapisink_set_bus(GstElement *element, GstBus *bus)
+{
+    /* Make sure to allocate a VA display in the sink element first,
+       so that upstream elements could query a display that was
+       allocated here, and that exactly matches what the user
+       requested through the "display" property */
+    if (!GST_ELEMENT_BUS(element) && bus)
+        gst_vaapisink_ensure_display(GST_VAAPISINK(element));
+
+    GST_ELEMENT_CLASS(gst_vaapisink_parent_class)->set_bus(element, bus);
+}
+
+static void
 gst_vaapisink_class_init(GstVaapiSinkClass *klass)
 {
     GObjectClass * const     object_class   = G_OBJECT_CLASS(klass);
@@ -1240,6 +1257,7 @@ gst_vaapisink_class_init(GstVaapiSinkClass *klass)
     basesink_class->buffer_alloc = gst_vaapisink_buffer_alloc;
 #endif
 
+    element_class->set_bus = gst_vaapisink_set_bus;
     gst_element_class_set_static_metadata(element_class,
         "VA-API sink",
         "Sink/Video",