• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include "vkqueue.h"
26 
27 #define GST_CAT_DEFAULT gst_vulkan_queue_debug
28 GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
29 GST_DEBUG_CATEGORY_STATIC (GST_CAT_CONTEXT);
30 
31 G_DEFINE_TYPE_WITH_CODE (GstVulkanQueue, gst_vulkan_queue, GST_TYPE_OBJECT,
32     GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "vulkanqueue", 0,
33         "Vulkan Queue");
34     GST_DEBUG_CATEGORY_GET (GST_CAT_CONTEXT, "GST_CONTEXT"));
35 
36 static void gst_vulkan_queue_dispose (GObject * object);
37 
38 static void
gst_vulkan_queue_init(GstVulkanQueue * device)39 gst_vulkan_queue_init (GstVulkanQueue * device)
40 {
41 }
42 
43 static void
gst_vulkan_queue_class_init(GstVulkanQueueClass * device_class)44 gst_vulkan_queue_class_init (GstVulkanQueueClass * device_class)
45 {
46   GObjectClass *gobject_class = (GObjectClass *) device_class;
47 
48   gobject_class->dispose = gst_vulkan_queue_dispose;
49 }
50 
51 static void
gst_vulkan_queue_dispose(GObject * object)52 gst_vulkan_queue_dispose (GObject * object)
53 {
54   GstVulkanQueue *queue = GST_VULKAN_QUEUE (object);
55 
56   if (queue->device)
57     gst_object_unref (queue->device);
58   queue->device = NULL;
59 }
60 
61 GstVulkanDevice *
gst_vulkan_queue_get_device(GstVulkanQueue * queue)62 gst_vulkan_queue_get_device (GstVulkanQueue * queue)
63 {
64   g_return_val_if_fail (GST_IS_VULKAN_QUEUE (queue), NULL);
65 
66   return queue->device ? gst_object_ref (queue->device) : NULL;
67 }
68 
69 /**
70  * gst_context_set_vulkan_queue:
71  * @context: a #GstContext
72  * @queue: a #GstVulkanQueue
73  *
74  * Sets @queue on @context
75  *
76  * Since: 1.10
77  */
78 void
gst_context_set_vulkan_queue(GstContext * context,GstVulkanQueue * queue)79 gst_context_set_vulkan_queue (GstContext * context, GstVulkanQueue * queue)
80 {
81   GstStructure *s;
82 
83   g_return_if_fail (context != NULL);
84   g_return_if_fail (gst_context_is_writable (context));
85 
86   if (queue)
87     GST_CAT_LOG (GST_CAT_CONTEXT,
88         "setting GstVulkanQueue(%" GST_PTR_FORMAT ") on context(%"
89         GST_PTR_FORMAT ")", queue, context);
90 
91   s = gst_context_writable_structure (context);
92   gst_structure_set (s, GST_VULKAN_QUEUE_CONTEXT_TYPE_STR,
93       GST_TYPE_VULKAN_QUEUE, queue, NULL);
94 }
95 
96 /**
97  * gst_context_get_vulkan_queue:
98  * @context: a #GstContext
99  * @queue: resulting #GstVulkanQueue
100  *
101  * Returns: Whether @queue was in @context
102  *
103  * Since: 1.10
104  */
105 gboolean
gst_context_get_vulkan_queue(GstContext * context,GstVulkanQueue ** queue)106 gst_context_get_vulkan_queue (GstContext * context, GstVulkanQueue ** queue)
107 {
108   const GstStructure *s;
109   gboolean ret;
110 
111   g_return_val_if_fail (queue != NULL, FALSE);
112   g_return_val_if_fail (context != NULL, FALSE);
113 
114   s = gst_context_get_structure (context);
115   ret = gst_structure_get (s, GST_VULKAN_QUEUE_CONTEXT_TYPE_STR,
116       GST_TYPE_VULKAN_QUEUE, queue, NULL);
117 
118   GST_CAT_LOG (GST_CAT_CONTEXT, "got GstVulkanQueue(%" GST_PTR_FORMAT
119       ") from context(%" GST_PTR_FORMAT ")", *queue, context);
120 
121   return ret;
122 }
123 
124 gboolean
gst_vulkan_queue_handle_context_query(GstElement * element,GstQuery * query,GstVulkanQueue ** queue)125 gst_vulkan_queue_handle_context_query (GstElement * element, GstQuery * query,
126     GstVulkanQueue ** queue)
127 {
128   gboolean res = FALSE;
129   const gchar *context_type;
130   GstContext *context, *old_context;
131 
132   g_return_val_if_fail (element != NULL, FALSE);
133   g_return_val_if_fail (query != NULL, FALSE);
134   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
135   g_return_val_if_fail (queue != NULL, FALSE);
136 
137   gst_query_parse_context_type (query, &context_type);
138 
139   if (g_strcmp0 (context_type, GST_VULKAN_QUEUE_CONTEXT_TYPE_STR) == 0) {
140     gst_query_parse_context (query, &old_context);
141 
142     if (old_context)
143       context = gst_context_copy (old_context);
144     else
145       context = gst_context_new (GST_VULKAN_QUEUE_CONTEXT_TYPE_STR, TRUE);
146 
147     gst_context_set_vulkan_queue (context, *queue);
148     gst_query_set_context (query, context);
149     gst_context_unref (context);
150 
151     res = *queue != NULL;
152   }
153 
154   return res;
155 }
156 
157 gboolean
gst_vulkan_queue_run_context_query(GstElement * element,GstVulkanQueue ** queue)158 gst_vulkan_queue_run_context_query (GstElement * element,
159     GstVulkanQueue ** queue)
160 {
161   GstQuery *query;
162 
163   g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
164   g_return_val_if_fail (queue != NULL, FALSE);
165 
166   if (*queue && GST_IS_VULKAN_QUEUE (*queue))
167     return TRUE;
168 
169   if ((query =
170           gst_vulkan_local_context_query (element,
171               GST_VULKAN_QUEUE_CONTEXT_TYPE_STR, FALSE))) {
172     GstContext *context;
173 
174     gst_query_parse_context (query, &context);
175     if (context)
176       gst_context_get_vulkan_queue (context, queue);
177   }
178 
179   GST_DEBUG_OBJECT (element, "found queue %p", *queue);
180 
181   gst_query_unref (query);
182 
183   if (*queue)
184     return TRUE;
185 
186   return FALSE;
187 }
188