vulkan: don't require every element to have a display

Only sink elements really care about a valid display
This commit is contained in:
Matthew Waters 2019-04-04 19:27:55 +11:00
parent eb0f7f3279
commit 7ee28e2e4b
3 changed files with 26 additions and 22 deletions

View file

@ -564,7 +564,7 @@ gst_vulkan_upload_query (GstBaseTransform * bt, GstPadDirection direction,
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_CONTEXT:{
res = gst_vulkan_handle_context_query (GST_ELEMENT (vk_upload), query,
&vk_upload->display, &vk_upload->instance, &vk_upload->device);
NULL, &vk_upload->instance, &vk_upload->device);
if (res)
return res;
@ -582,8 +582,7 @@ gst_vulkan_upload_set_context (GstElement * element, GstContext * context)
{
GstVulkanUpload *vk_upload = GST_VULKAN_UPLOAD (element);
gst_vulkan_handle_set_context (element, context, &vk_upload->display,
&vk_upload->instance);
gst_vulkan_handle_set_context (element, context, NULL, &vk_upload->instance);
GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
}
@ -602,18 +601,24 @@ gst_vulkan_upload_change_state (GstElement * element, GstStateChange transition)
case GST_STATE_CHANGE_NULL_TO_READY:
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
if (!gst_vulkan_ensure_element_data (element, &vk_upload->display,
&vk_upload->instance)) {
if (!gst_vulkan_ensure_element_data (element, NULL, &vk_upload->instance)) {
GST_ELEMENT_ERROR (vk_upload, RESOURCE, NOT_FOUND,
("Failed to retreive vulkan instance/display"), (NULL));
("Failed to retreive vulkan instance"), (NULL));
return GST_STATE_CHANGE_FAILURE;
}
if (!gst_vulkan_device_run_context_query (GST_ELEMENT (vk_upload),
&vk_upload->device)) {
GError *error = NULL;
GST_DEBUG_OBJECT (vk_upload, "No device retrieved from peer elements");
if (!(vk_upload->device =
gst_vulkan_instance_create_device (vk_upload->instance,
&error))) {
GST_ELEMENT_ERROR (vk_upload, RESOURCE, NOT_FOUND,
("Failed to retreive vulkan device"), (NULL));
("Failed to create vulkan device"), ("%s", error->message));
g_clear_error (&error);
return GST_STATE_CHANGE_FAILURE;
}
}
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
break;
@ -629,9 +634,6 @@ gst_vulkan_upload_change_state (GstElement * element, GstStateChange transition)
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
if (vk_upload->display)
gst_object_unref (vk_upload->display);
vk_upload->display = NULL;
if (vk_upload->device)
gst_object_unref (vk_upload->device);
vk_upload->device = NULL;

View file

@ -66,8 +66,6 @@ struct _GstVulkanUpload
GstVulkanInstance *instance;
GstVulkanDevice *device;
GstVulkanDisplay *display;
GstCaps *in_caps;
GstCaps *out_caps;

View file

@ -184,7 +184,6 @@ gst_vulkan_ensure_element_data (gpointer element,
GstVulkanDisplay ** display_ptr, GstVulkanInstance ** instance_ptr)
{
g_return_val_if_fail (element != NULL, FALSE);
g_return_val_if_fail (display_ptr != NULL, FALSE);
g_return_val_if_fail (instance_ptr != NULL, FALSE);
/* 1) Check if the element already has a context of the specific
@ -192,21 +191,18 @@ gst_vulkan_ensure_element_data (gpointer element,
*/
if (!*instance_ptr) {
GError *error = NULL;
GstContext *context = NULL;
gst_vulkan_global_context_query (element,
GST_VULKAN_INSTANCE_CONTEXT_TYPE_STR);
/* Neighbour found and it updated the display */
if (!*instance_ptr) {
GstContext *context;
/* If no neighboor, or application not interested, use system default */
*instance_ptr = gst_vulkan_instance_new ();
context = gst_context_new (GST_VULKAN_INSTANCE_CONTEXT_TYPE_STR, TRUE);
gst_context_set_vulkan_instance (context, *instance_ptr);
_vk_context_propagate (element, context);
}
if (!gst_vulkan_instance_open (*instance_ptr, &error)) {
@ -217,8 +213,15 @@ gst_vulkan_ensure_element_data (gpointer element,
g_clear_error (&error);
return FALSE;
}
if (context)
_vk_context_propagate (element, context);
}
/* we don't care about a display */
if (!display_ptr)
return *instance_ptr != NULL;
if (!*display_ptr) {
_vk_display_context_query (element, display_ptr);
@ -250,7 +253,6 @@ gst_vulkan_handle_set_context (GstElement * element, GstContext * context,
GstVulkanInstance *instance_replacement = NULL;
const gchar *context_type;
g_return_val_if_fail (display != NULL, FALSE);
g_return_val_if_fail (instance != NULL, FALSE);
if (!context)
@ -258,7 +260,8 @@ gst_vulkan_handle_set_context (GstElement * element, GstContext * context,
context_type = gst_context_get_context_type (context);
if (g_strcmp0 (context_type, GST_VULKAN_DISPLAY_CONTEXT_TYPE_STR) == 0) {
if (display
&& g_strcmp0 (context_type, GST_VULKAN_DISPLAY_CONTEXT_TYPE_STR) == 0) {
if (!gst_context_get_vulkan_display (context, &display_replacement)) {
GST_WARNING_OBJECT (element, "Failed to get display from context");
return FALSE;
@ -295,7 +298,8 @@ gst_vulkan_handle_context_query (GstElement * element, GstQuery * query,
GstVulkanDisplay ** display, GstVulkanInstance ** instance,
GstVulkanDevice ** device)
{
if (gst_vulkan_display_handle_context_query (element, query, display))
if (display
&& gst_vulkan_display_handle_context_query (element, query, display))
return TRUE;
if (gst_vulkan_instance_handle_context_query (element, query, instance))
return TRUE;