3 * Copyright (C) 2019 Matthew Waters <matthew@centricular.com>
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.
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.
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.
22 * SECTION:element-vulkandownload
23 * @title: vulkandownload
25 * vulkandownload downloads data into Vulkan memory objects.
34 #include "vkdownload.h"
36 GST_DEBUG_CATEGORY (gst_debug_vulkan_download);
37 #define GST_CAT_DEFAULT gst_debug_vulkan_download
40 _set_caps_features_with_passthrough (const GstCaps * caps,
41 const gchar * feature_name, GstCapsFeatures * passthrough)
46 tmp = gst_caps_copy (caps);
48 n = gst_caps_get_size (caps);
49 for (i = 0; i < n; i++) {
50 GstCapsFeatures *features, *orig_features;
52 orig_features = gst_caps_get_features (caps, i);
53 features = gst_caps_features_new (feature_name, NULL);
55 m = gst_caps_features_get_size (orig_features);
56 for (j = 0; j < m; j++) {
57 const gchar *feature = gst_caps_features_get_nth (orig_features, j);
59 /* if we already have the features */
60 if (gst_caps_features_contains (features, feature))
63 if (g_strcmp0 (feature, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY) == 0)
66 if (passthrough && gst_caps_features_contains (passthrough, feature)) {
67 gst_caps_features_add (features, feature);
71 gst_caps_set_features (tmp, i, features);
77 struct ImageToRawDownload
79 GstVulkanDownload *download;
82 GstVideoInfo out_info;
87 GstVulkanCommandPool *cmd_pool;
88 GstVulkanTrashList *trash_list;
92 _image_to_raw_new_impl (GstVulkanDownload * download)
94 struct ImageToRawDownload *raw = g_new0 (struct ImageToRawDownload, 1);
96 raw->download = download;
97 raw->trash_list = gst_vulkan_trash_fence_list_new ();
103 _image_to_raw_transform_caps (gpointer impl, GstPadDirection direction,
108 if (direction == GST_PAD_SINK) {
110 _set_caps_features_with_passthrough (caps,
111 GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY, NULL);
114 _set_caps_features_with_passthrough (caps,
115 GST_CAPS_FEATURE_MEMORY_VULKAN_IMAGE, NULL);
122 _image_to_raw_set_caps (gpointer impl, GstCaps * in_caps, GstCaps * out_caps)
124 struct ImageToRawDownload *raw = impl;
126 if (!gst_video_info_from_caps (&raw->in_info, in_caps))
129 if (!gst_video_info_from_caps (&raw->out_info, out_caps))
136 _image_to_raw_propose_allocation (gpointer impl, GstQuery * decide_query,
139 /* FIXME: implement */
143 _image_to_raw_perform (gpointer impl, GstBuffer * inbuf, GstBuffer ** outbuf)
145 struct ImageToRawDownload *raw = impl;
146 GstVulkanCommandBuffer *cmd_buf;
147 GError *error = NULL;
152 if (!raw->cmd_pool) {
153 if (!(raw->cmd_pool =
154 gst_vulkan_queue_create_command_pool (raw->download->queue,
160 if (!(cmd_buf = gst_vulkan_command_pool_create (raw->cmd_pool, &error)))
164 GstStructure *config;
165 guint min = 0, max = 0;
168 raw->pool = gst_vulkan_buffer_pool_new (raw->download->device);
169 config = gst_buffer_pool_get_config (raw->pool);
170 gst_buffer_pool_config_set_params (config, raw->download->out_caps, size,
172 gst_buffer_pool_set_config (raw->pool, config);
174 if (!raw->pool_active) {
175 gst_buffer_pool_set_active (raw->pool, TRUE);
176 raw->pool_active = TRUE;
180 gst_buffer_pool_acquire_buffer (raw->pool, outbuf,
181 NULL)) != GST_FLOW_OK)
186 VkCommandBufferBeginInfo cmd_buf_info = {
187 .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
189 .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
190 .pInheritanceInfo = NULL
194 gst_vulkan_command_buffer_lock (cmd_buf);
195 err = vkBeginCommandBuffer (cmd_buf->cmd, &cmd_buf_info);
196 if (gst_vulkan_error_to_g_error (err, &error, "vkBeginCommandBuffer") < 0)
200 for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&raw->out_info); i++) {
201 VkBufferImageCopy region;
202 GstMemory *in_mem, *out_mem;
203 GstVulkanBufferMemory *buf_mem;
204 GstVulkanImageMemory *img_mem;
205 VkImageMemoryBarrier image_memory_barrier;
206 VkBufferMemoryBarrier buffer_memory_barrier;
208 in_mem = gst_buffer_peek_memory (inbuf, i);
209 if (!gst_is_vulkan_image_memory (in_mem)) {
210 GST_WARNING_OBJECT (raw->download, "Input is not a GstVulkanImageMemory");
213 img_mem = (GstVulkanImageMemory *) in_mem;
215 out_mem = gst_buffer_peek_memory (*outbuf, i);
216 if (!gst_is_vulkan_buffer_memory (out_mem)) {
217 GST_WARNING_OBJECT (raw->download,
218 "Output is not a GstVulkanBufferMemory");
221 buf_mem = (GstVulkanBufferMemory *) out_mem;
224 region = (VkBufferImageCopy) {
226 .bufferRowLength = GST_VIDEO_INFO_COMP_WIDTH (&raw->in_info, i),
227 .bufferImageHeight = GST_VIDEO_INFO_COMP_HEIGHT (&raw->in_info, i),
228 .imageSubresource = {
229 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
234 .imageOffset = { .x = 0, .y = 0, .z = 0, },
236 .width = GST_VIDEO_INFO_COMP_WIDTH (&raw->out_info, i),
237 .height = GST_VIDEO_INFO_COMP_HEIGHT (&raw->out_info, i),
242 image_memory_barrier = (VkImageMemoryBarrier) {
243 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
245 .srcAccessMask = img_mem->barrier.parent.access_flags,
246 .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
247 .oldLayout = img_mem->barrier.image_layout,
248 .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
249 /* FIXME: implement exclusive transfers */
250 .srcQueueFamilyIndex = 0,
251 .dstQueueFamilyIndex = 0,
252 .image = img_mem->image,
253 .subresourceRange = img_mem->barrier.subresource_range
256 buffer_memory_barrier = (VkBufferMemoryBarrier) {
257 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
259 .srcAccessMask = buf_mem->barrier.parent.access_flags,
260 .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
261 /* FIXME: implement exclusive transfers */
262 .srcQueueFamilyIndex = 0,
263 .dstQueueFamilyIndex = 0,
264 .buffer = buf_mem->buffer,
265 .offset = region.bufferOffset,
266 .size = region.bufferRowLength * region.bufferImageHeight
270 vkCmdPipelineBarrier (cmd_buf->cmd,
271 buf_mem->barrier.parent.pipeline_stages | img_mem->barrier.
272 parent.pipeline_stages, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 1,
273 &buffer_memory_barrier, 1, &image_memory_barrier);
275 buf_mem->barrier.parent.pipeline_stages = VK_PIPELINE_STAGE_TRANSFER_BIT;
276 buf_mem->barrier.parent.access_flags = buffer_memory_barrier.dstAccessMask;
278 img_mem->barrier.parent.pipeline_stages = VK_PIPELINE_STAGE_TRANSFER_BIT;
279 img_mem->barrier.parent.access_flags = image_memory_barrier.dstAccessMask;
280 img_mem->barrier.image_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
282 vkCmdCopyImageToBuffer (cmd_buf->cmd, img_mem->image,
283 img_mem->barrier.image_layout, buf_mem->buffer, 1, ®ion);
286 err = vkEndCommandBuffer (cmd_buf->cmd);
287 gst_vulkan_command_buffer_unlock (cmd_buf);
288 if (gst_vulkan_error_to_g_error (err, &error, "vkEndCommandBuffer") < 0)
292 VkSubmitInfo submit_info = { 0, };
293 VkPipelineStageFlags stages = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
294 GstVulkanFence *fence;
297 submit_info = (VkSubmitInfo) {
298 .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
300 .waitSemaphoreCount = 0,
301 .pWaitSemaphores = NULL,
302 .pWaitDstStageMask = &stages,
303 .commandBufferCount = 1,
304 .pCommandBuffers = &cmd_buf->cmd,
305 .signalSemaphoreCount = 0,
306 .pSignalSemaphores = NULL
310 fence = gst_vulkan_fence_new (raw->download->device, 0, &error);
315 vkQueueSubmit (raw->download->queue->queue, 1, &submit_info,
316 GST_VULKAN_FENCE_FENCE (fence));
317 if (gst_vulkan_error_to_g_error (err, &error, "vkQueueSubmit") < 0)
320 gst_vulkan_trash_list_add (raw->trash_list,
321 gst_vulkan_trash_new_mini_object_unref (fence,
322 GST_MINI_OBJECT_CAST (cmd_buf)));
326 * Need to have the buffer gst_memory_map() wait for this fence before
328 gst_vulkan_trash_list_wait (raw->trash_list, -1);
329 gst_vulkan_trash_list_gc (raw->trash_list);
338 gst_vulkan_command_buffer_unlock (cmd_buf);
339 gst_vulkan_command_buffer_unref (cmd_buf);
343 GST_WARNING_OBJECT (raw->download, "Error: %s", error->message);
344 g_clear_error (&error);
346 gst_clear_buffer (outbuf);
347 ret = GST_FLOW_ERROR;
352 _image_to_raw_free (gpointer impl)
354 struct ImageToRawDownload *raw = impl;
357 if (raw->pool_active) {
358 gst_buffer_pool_set_active (raw->pool, FALSE);
360 raw->pool_active = FALSE;
361 gst_object_unref (raw->pool);
366 gst_object_unref (raw->cmd_pool);
367 raw->cmd_pool = NULL;
370 gst_object_unref (raw->trash_list);
371 raw->trash_list = NULL;
376 static GstStaticCaps _image_to_raw_in_templ =
377 GST_STATIC_CAPS ("video/x-raw(" GST_CAPS_FEATURE_MEMORY_VULKAN_IMAGE ")");
378 static GstStaticCaps _image_to_raw_out_templ = GST_STATIC_CAPS ("video/x-raw");
380 static const struct DownloadMethod image_to_raw_download = {
382 &_image_to_raw_in_templ,
383 &_image_to_raw_out_templ,
384 _image_to_raw_new_impl,
385 _image_to_raw_transform_caps,
386 _image_to_raw_set_caps,
387 _image_to_raw_propose_allocation,
388 _image_to_raw_perform,
392 static const struct DownloadMethod *download_methods[] = {
393 &image_to_raw_download,
397 _get_input_template_caps (void)
402 /* FIXME: cache this and invalidate on changes to download_methods */
403 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
404 GstCaps *template = gst_static_caps_get (download_methods[i]->in_template);
405 ret = ret == NULL ? template : gst_caps_merge (ret, template);
408 ret = gst_caps_simplify (ret);
414 _get_output_template_caps (void)
419 /* FIXME: cache this and invalidate on changes to download_methods */
420 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
421 GstCaps *template = gst_static_caps_get (download_methods[i]->out_template);
422 ret = ret == NULL ? template : gst_caps_merge (ret, template);
425 ret = gst_caps_simplify (ret);
430 static void gst_vulkan_download_finalize (GObject * object);
432 static gboolean gst_vulkan_download_query (GstBaseTransform * bt,
433 GstPadDirection direction, GstQuery * query);
434 static void gst_vulkan_download_set_context (GstElement * element,
435 GstContext * context);
436 static GstStateChangeReturn gst_vulkan_download_change_state (GstElement *
437 element, GstStateChange transition);
439 static gboolean gst_vulkan_download_set_caps (GstBaseTransform * bt,
440 GstCaps * in_caps, GstCaps * out_caps);
441 static GstCaps *gst_vulkan_download_transform_caps (GstBaseTransform * bt,
442 GstPadDirection direction, GstCaps * caps, GstCaps * filter);
443 static gboolean gst_vulkan_download_propose_allocation (GstBaseTransform * bt,
444 GstQuery * decide_query, GstQuery * query);
445 static gboolean gst_vulkan_download_decide_allocation (GstBaseTransform * bt,
447 static GstFlowReturn gst_vulkan_download_transform (GstBaseTransform * bt,
448 GstBuffer * inbuf, GstBuffer * outbuf);
449 static GstFlowReturn gst_vulkan_download_prepare_output_buffer (GstBaseTransform
450 * bt, GstBuffer * inbuf, GstBuffer ** outbuf);
463 /* static guint gst_vulkan_download_signals[LAST_SIGNAL] = { 0 }; */
465 #define gst_vulkan_download_parent_class parent_class
466 G_DEFINE_TYPE_WITH_CODE (GstVulkanDownload, gst_vulkan_download,
467 GST_TYPE_BASE_TRANSFORM, GST_DEBUG_CATEGORY_INIT (gst_debug_vulkan_download,
468 "vulkandownload", 0, "Vulkan Downloader"));
471 gst_vulkan_download_class_init (GstVulkanDownloadClass * klass)
473 GObjectClass *gobject_class;
474 GstElementClass *gstelement_class;
475 GstBaseTransformClass *gstbasetransform_class;
477 gobject_class = (GObjectClass *) klass;
478 gstelement_class = (GstElementClass *) klass;
479 gstbasetransform_class = (GstBaseTransformClass *) klass;
481 gst_element_class_set_metadata (gstelement_class, "Vulkan Downloader",
482 "Filter/Video", "A Vulkan data downloader",
483 "Matthew Waters <matthew@centricular.com>");
488 caps = _get_input_template_caps ();
489 gst_element_class_add_pad_template (gstelement_class,
490 gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps));
491 gst_caps_unref (caps);
493 caps = _get_output_template_caps ();
494 gst_element_class_add_pad_template (gstelement_class,
495 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps));
496 gst_caps_unref (caps);
499 gobject_class->finalize = gst_vulkan_download_finalize;
501 gstelement_class->change_state = gst_vulkan_download_change_state;
502 gstelement_class->set_context = gst_vulkan_download_set_context;
503 gstbasetransform_class->query = GST_DEBUG_FUNCPTR (gst_vulkan_download_query);
504 gstbasetransform_class->set_caps = gst_vulkan_download_set_caps;
505 gstbasetransform_class->transform_caps = gst_vulkan_download_transform_caps;
506 gstbasetransform_class->propose_allocation =
507 gst_vulkan_download_propose_allocation;
508 gstbasetransform_class->decide_allocation =
509 gst_vulkan_download_decide_allocation;
510 gstbasetransform_class->transform = gst_vulkan_download_transform;
511 gstbasetransform_class->prepare_output_buffer =
512 gst_vulkan_download_prepare_output_buffer;
516 gst_vulkan_download_init (GstVulkanDownload * vk_download)
520 n = G_N_ELEMENTS (download_methods);
521 vk_download->download_impls = g_malloc (sizeof (gpointer) * n);
522 for (i = 0; i < n; i++) {
523 vk_download->download_impls[i] =
524 download_methods[i]->new_impl (vk_download);
529 gst_vulkan_download_finalize (GObject * object)
531 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (object);
534 gst_caps_replace (&vk_download->in_caps, NULL);
535 gst_caps_replace (&vk_download->out_caps, NULL);
537 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
538 download_methods[i]->free (vk_download->download_impls[i]);
540 g_free (vk_download->download_impls);
541 vk_download->download_impls = NULL;
543 G_OBJECT_CLASS (parent_class)->finalize (object);
547 gst_vulkan_download_query (GstBaseTransform * bt, GstPadDirection direction,
550 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (bt);
552 switch (GST_QUERY_TYPE (query)) {
553 case GST_QUERY_CONTEXT:{
554 if (gst_vulkan_handle_context_query (GST_ELEMENT (vk_download), query,
555 NULL, vk_download->instance, vk_download->device))
558 if (gst_vulkan_queue_handle_context_query (GST_ELEMENT (vk_download),
559 query, vk_download->queue))
568 return GST_BASE_TRANSFORM_CLASS (parent_class)->query (bt, direction, query);
572 gst_vulkan_download_set_context (GstElement * element, GstContext * context)
574 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (element);
576 gst_vulkan_handle_set_context (element, context, NULL,
577 &vk_download->instance);
579 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
584 GstVulkanDownload *download;
585 GstVulkanQueue *queue;
589 _choose_queue (GstVulkanDevice * device, GstVulkanQueue * queue,
590 struct choose_data *data)
593 device->physical_device->queue_family_props[queue->family].queueFlags;
595 if ((flags & VK_QUEUE_GRAPHICS_BIT) != 0) {
597 gst_object_unref (data->queue);
598 data->queue = gst_object_ref (queue);
605 static GstVulkanQueue *
606 _find_graphics_queue (GstVulkanDownload * download)
608 struct choose_data data;
610 data.download = download;
613 gst_vulkan_device_foreach_queue (download->device,
614 (GstVulkanDeviceForEachQueueFunc) _choose_queue, &data);
619 static GstStateChangeReturn
620 gst_vulkan_download_change_state (GstElement * element,
621 GstStateChange transition)
623 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (element);
624 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
626 GST_DEBUG ("changing state: %s => %s",
627 gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)),
628 gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition)));
630 switch (transition) {
631 case GST_STATE_CHANGE_NULL_TO_READY:
633 case GST_STATE_CHANGE_READY_TO_PAUSED:
634 if (!gst_vulkan_ensure_element_data (element, NULL,
635 &vk_download->instance)) {
636 GST_ELEMENT_ERROR (vk_download, RESOURCE, NOT_FOUND,
637 ("Failed to retrieve vulkan instance"), (NULL));
638 return GST_STATE_CHANGE_FAILURE;
640 if (!gst_vulkan_device_run_context_query (GST_ELEMENT (vk_download),
641 &vk_download->device)) {
642 GError *error = NULL;
643 GST_DEBUG_OBJECT (vk_download,
644 "No device retrieved from peer elements");
645 if (!(vk_download->device =
646 gst_vulkan_instance_create_device (vk_download->instance,
648 GST_ELEMENT_ERROR (vk_download, RESOURCE, NOT_FOUND,
649 ("Failed to create vulkan device"), ("%s",
650 error ? error->message : ""));
651 g_clear_error (&error);
652 return GST_STATE_CHANGE_FAILURE;
656 if (!gst_vulkan_queue_run_context_query (GST_ELEMENT (vk_download),
657 &vk_download->queue)) {
658 GST_DEBUG_OBJECT (vk_download, "No queue retrieved from peer elements");
659 vk_download->queue = _find_graphics_queue (vk_download);
661 if (!vk_download->queue) {
662 GST_ELEMENT_ERROR (vk_download, RESOURCE, NOT_FOUND,
663 ("Failed to create/retrieve vulkan queue"), (NULL));
664 return GST_STATE_CHANGE_FAILURE;
667 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
673 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
674 if (ret == GST_STATE_CHANGE_FAILURE)
677 switch (transition) {
678 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
680 case GST_STATE_CHANGE_PAUSED_TO_READY:
681 if (vk_download->queue)
682 gst_object_unref (vk_download->queue);
683 vk_download->queue = NULL;
684 if (vk_download->device)
685 gst_object_unref (vk_download->device);
686 vk_download->device = NULL;
687 if (vk_download->instance)
688 gst_object_unref (vk_download->instance);
689 vk_download->instance = NULL;
691 case GST_STATE_CHANGE_READY_TO_NULL:
701 gst_vulkan_download_transform_caps (GstBaseTransform * bt,
702 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
704 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (bt);
705 GstCaps *result, *tmp;
708 tmp = gst_caps_new_empty ();
710 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
714 if (direction == GST_PAD_SINK) {
715 templ = gst_static_caps_get (download_methods[i]->in_template);
717 templ = gst_static_caps_get (download_methods[i]->out_template);
719 if (!gst_caps_can_intersect (caps, templ)) {
720 gst_caps_unref (templ);
723 gst_caps_unref (templ);
725 tmp2 = download_methods[i]->transform_caps (vk_download->download_impls[i],
729 tmp = gst_caps_merge (tmp, tmp2);
733 result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
734 gst_caps_unref (tmp);
743 gst_vulkan_download_set_caps (GstBaseTransform * bt, GstCaps * in_caps,
746 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (bt);
747 gboolean found_method = FALSE;
750 gst_caps_replace (&vk_download->in_caps, in_caps);
751 gst_caps_replace (&vk_download->out_caps, out_caps);
753 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
756 templ = gst_static_caps_get (download_methods[i]->in_template);
757 if (!gst_caps_can_intersect (in_caps, templ)) {
758 gst_caps_unref (templ);
761 gst_caps_unref (templ);
763 templ = gst_static_caps_get (download_methods[i]->out_template);
764 if (!gst_caps_can_intersect (out_caps, templ)) {
765 gst_caps_unref (templ);
768 gst_caps_unref (templ);
770 if (!download_methods[i]->set_caps (vk_download->download_impls[i], in_caps,
774 GST_LOG_OBJECT (bt, "downloader %s accepted caps in: %" GST_PTR_FORMAT
775 " out: %" GST_PTR_FORMAT, download_methods[i]->name, in_caps, out_caps);
777 vk_download->current_impl = i;
782 GST_DEBUG_OBJECT (bt,
783 "set caps in: %" GST_PTR_FORMAT " out: %" GST_PTR_FORMAT, in_caps,
790 gst_vulkan_download_propose_allocation (GstBaseTransform * bt,
791 GstQuery * decide_query, GstQuery * query)
793 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (bt);
796 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
799 templ = gst_static_caps_get (download_methods[i]->in_template);
800 if (!gst_caps_can_intersect (vk_download->in_caps, templ)) {
801 gst_caps_unref (templ);
804 gst_caps_unref (templ);
806 templ = gst_static_caps_get (download_methods[i]->out_template);
807 if (!gst_caps_can_intersect (vk_download->out_caps, templ)) {
808 gst_caps_unref (templ);
811 gst_caps_unref (templ);
813 download_methods[i]->propose_allocation (vk_download->download_impls[i],
814 decide_query, query);
821 gst_vulkan_download_decide_allocation (GstBaseTransform * bt, GstQuery * query)
827 _download_find_method (GstVulkanDownload * vk_download)
829 vk_download->current_impl++;
831 if (vk_download->current_impl >= G_N_ELEMENTS (download_methods))
834 GST_DEBUG_OBJECT (vk_download, "attempting download with downloader %s",
835 download_methods[vk_download->current_impl]->name);
841 gst_vulkan_download_prepare_output_buffer (GstBaseTransform * bt,
842 GstBuffer * inbuf, GstBuffer ** outbuf)
844 GstBaseTransformClass *bclass = GST_BASE_TRANSFORM_GET_CLASS (bt);
845 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (bt);
850 gpointer method_impl;
851 const struct DownloadMethod *method;
853 method = download_methods[vk_download->current_impl];
854 method_impl = vk_download->download_impls[vk_download->current_impl];
856 ret = method->perform (method_impl, inbuf, outbuf);
857 if (ret != GST_FLOW_OK) {
859 if (!_download_find_method (vk_download)) {
860 GST_ELEMENT_ERROR (bt, RESOURCE, NOT_FOUND,
861 ("Could not find suitable downloader"), (NULL));
862 return GST_FLOW_ERROR;
865 method = download_methods[vk_download->current_impl];
866 method_impl = vk_download->download_impls[vk_download->current_impl];
867 if (!method->set_caps (method_impl, vk_download->in_caps,
868 vk_download->out_caps))
869 /* try the next method */
872 /* try the downloading with the next method */
877 if (ret == GST_FLOW_OK) {
878 /* basetransform doesn't unref if they're the same */
879 if (inbuf != *outbuf)
880 bclass->copy_metadata (bt, inbuf, *outbuf);
887 gst_vulkan_download_transform (GstBaseTransform * bt, GstBuffer * inbuf,