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 "gstvulkanelements.h"
35 #include "vkdownload.h"
37 GST_DEBUG_CATEGORY (gst_debug_vulkan_download);
38 #define GST_CAT_DEFAULT gst_debug_vulkan_download
41 _set_caps_features_with_passthrough (const GstCaps * caps,
42 const gchar * feature_name, GstCapsFeatures * passthrough)
47 tmp = gst_caps_copy (caps);
49 n = gst_caps_get_size (caps);
50 for (i = 0; i < n; i++) {
51 GstCapsFeatures *features, *orig_features;
53 orig_features = gst_caps_get_features (caps, i);
54 features = gst_caps_features_new (feature_name, NULL);
56 m = gst_caps_features_get_size (orig_features);
57 for (j = 0; j < m; j++) {
58 const gchar *feature = gst_caps_features_get_nth (orig_features, j);
60 /* if we already have the features */
61 if (gst_caps_features_contains (features, feature))
64 if (g_strcmp0 (feature, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY) == 0)
67 if (passthrough && gst_caps_features_contains (passthrough, feature)) {
68 gst_caps_features_add (features, feature);
72 gst_caps_set_features (tmp, i, features);
78 struct ImageToRawDownload
80 GstVulkanDownload *download;
83 GstVideoInfo out_info;
88 GstVulkanCommandPool *cmd_pool;
89 GstVulkanTrashList *trash_list;
93 _image_to_raw_new_impl (GstVulkanDownload * download)
95 struct ImageToRawDownload *raw = g_new0 (struct ImageToRawDownload, 1);
97 raw->download = download;
98 raw->trash_list = gst_vulkan_trash_fence_list_new ();
104 _image_to_raw_transform_caps (gpointer impl, GstPadDirection direction,
109 if (direction == GST_PAD_SINK) {
111 _set_caps_features_with_passthrough (caps,
112 GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY, NULL);
115 _set_caps_features_with_passthrough (caps,
116 GST_CAPS_FEATURE_MEMORY_VULKAN_IMAGE, NULL);
123 _image_to_raw_set_caps (gpointer impl, GstCaps * in_caps, GstCaps * out_caps)
125 struct ImageToRawDownload *raw = impl;
127 if (!gst_video_info_from_caps (&raw->in_info, in_caps))
130 if (!gst_video_info_from_caps (&raw->out_info, out_caps))
137 _image_to_raw_propose_allocation (gpointer impl, GstQuery * decide_query,
140 /* FIXME: implement */
144 _image_to_raw_perform (gpointer impl, GstBuffer * inbuf, GstBuffer ** outbuf)
146 struct ImageToRawDownload *raw = impl;
147 GstVulkanCommandBuffer *cmd_buf;
148 GError *error = NULL;
153 if (!raw->cmd_pool) {
154 if (!(raw->cmd_pool =
155 gst_vulkan_queue_create_command_pool (raw->download->queue,
161 if (!(cmd_buf = gst_vulkan_command_pool_create (raw->cmd_pool, &error)))
165 GstStructure *config;
166 guint min = 0, max = 0;
169 raw->pool = gst_vulkan_buffer_pool_new (raw->download->device);
170 config = gst_buffer_pool_get_config (raw->pool);
171 gst_buffer_pool_config_set_params (config, raw->download->out_caps, size,
173 gst_buffer_pool_set_config (raw->pool, config);
175 if (!raw->pool_active) {
176 gst_buffer_pool_set_active (raw->pool, TRUE);
177 raw->pool_active = TRUE;
181 gst_buffer_pool_acquire_buffer (raw->pool, outbuf,
182 NULL)) != GST_FLOW_OK)
187 VkCommandBufferBeginInfo cmd_buf_info = {
188 .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
190 .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
191 .pInheritanceInfo = NULL
195 gst_vulkan_command_buffer_lock (cmd_buf);
196 err = vkBeginCommandBuffer (cmd_buf->cmd, &cmd_buf_info);
197 if (gst_vulkan_error_to_g_error (err, &error, "vkBeginCommandBuffer") < 0)
201 for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&raw->out_info); i++) {
202 VkBufferImageCopy region;
203 GstMemory *in_mem, *out_mem;
204 GstVulkanBufferMemory *buf_mem;
205 GstVulkanImageMemory *img_mem;
206 VkImageMemoryBarrier image_memory_barrier;
207 VkBufferMemoryBarrier buffer_memory_barrier;
209 in_mem = gst_buffer_peek_memory (inbuf, i);
210 if (!gst_is_vulkan_image_memory (in_mem)) {
211 GST_WARNING_OBJECT (raw->download, "Input is not a GstVulkanImageMemory");
214 img_mem = (GstVulkanImageMemory *) in_mem;
216 out_mem = gst_buffer_peek_memory (*outbuf, i);
217 if (!gst_is_vulkan_buffer_memory (out_mem)) {
218 GST_WARNING_OBJECT (raw->download,
219 "Output is not a GstVulkanBufferMemory");
222 buf_mem = (GstVulkanBufferMemory *) out_mem;
225 region = (VkBufferImageCopy) {
227 .bufferRowLength = GST_VIDEO_INFO_COMP_WIDTH (&raw->in_info, i),
228 .bufferImageHeight = GST_VIDEO_INFO_COMP_HEIGHT (&raw->in_info, i),
229 .imageSubresource = {
230 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
235 .imageOffset = { .x = 0, .y = 0, .z = 0, },
237 .width = GST_VIDEO_INFO_COMP_WIDTH (&raw->out_info, i),
238 .height = GST_VIDEO_INFO_COMP_HEIGHT (&raw->out_info, i),
243 image_memory_barrier = (VkImageMemoryBarrier) {
244 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
246 .srcAccessMask = img_mem->barrier.parent.access_flags,
247 .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
248 .oldLayout = img_mem->barrier.image_layout,
249 .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
250 /* FIXME: implement exclusive transfers */
251 .srcQueueFamilyIndex = 0,
252 .dstQueueFamilyIndex = 0,
253 .image = img_mem->image,
254 .subresourceRange = img_mem->barrier.subresource_range
257 buffer_memory_barrier = (VkBufferMemoryBarrier) {
258 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
260 .srcAccessMask = buf_mem->barrier.parent.access_flags,
261 .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
262 /* FIXME: implement exclusive transfers */
263 .srcQueueFamilyIndex = 0,
264 .dstQueueFamilyIndex = 0,
265 .buffer = buf_mem->buffer,
266 .offset = region.bufferOffset,
267 .size = region.bufferRowLength * region.bufferImageHeight
271 vkCmdPipelineBarrier (cmd_buf->cmd,
272 buf_mem->barrier.parent.pipeline_stages | img_mem->barrier.
273 parent.pipeline_stages, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 1,
274 &buffer_memory_barrier, 1, &image_memory_barrier);
276 buf_mem->barrier.parent.pipeline_stages = VK_PIPELINE_STAGE_TRANSFER_BIT;
277 buf_mem->barrier.parent.access_flags = buffer_memory_barrier.dstAccessMask;
279 img_mem->barrier.parent.pipeline_stages = VK_PIPELINE_STAGE_TRANSFER_BIT;
280 img_mem->barrier.parent.access_flags = image_memory_barrier.dstAccessMask;
281 img_mem->barrier.image_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
283 vkCmdCopyImageToBuffer (cmd_buf->cmd, img_mem->image,
284 img_mem->barrier.image_layout, buf_mem->buffer, 1, ®ion);
287 err = vkEndCommandBuffer (cmd_buf->cmd);
288 gst_vulkan_command_buffer_unlock (cmd_buf);
289 if (gst_vulkan_error_to_g_error (err, &error, "vkEndCommandBuffer") < 0)
293 VkSubmitInfo submit_info = { 0, };
294 VkPipelineStageFlags stages = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
295 GstVulkanFence *fence;
298 submit_info = (VkSubmitInfo) {
299 .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
301 .waitSemaphoreCount = 0,
302 .pWaitSemaphores = NULL,
303 .pWaitDstStageMask = &stages,
304 .commandBufferCount = 1,
305 .pCommandBuffers = &cmd_buf->cmd,
306 .signalSemaphoreCount = 0,
307 .pSignalSemaphores = NULL
311 fence = gst_vulkan_device_create_fence (raw->download->device, &error);
315 gst_vulkan_queue_submit_lock (raw->download->queue);
317 vkQueueSubmit (raw->download->queue->queue, 1, &submit_info,
318 GST_VULKAN_FENCE_FENCE (fence));
319 gst_vulkan_queue_submit_unlock (raw->download->queue);
320 if (gst_vulkan_error_to_g_error (err, &error, "vkQueueSubmit") < 0)
323 gst_vulkan_trash_list_add (raw->trash_list,
324 gst_vulkan_trash_list_acquire (raw->trash_list, fence,
325 gst_vulkan_trash_mini_object_unref,
326 GST_MINI_OBJECT_CAST (cmd_buf)));
327 gst_vulkan_fence_unref (fence);
331 * Need to have the buffer gst_memory_map() wait for this fence before
333 gst_vulkan_trash_list_wait (raw->trash_list, -1);
334 gst_vulkan_trash_list_gc (raw->trash_list);
343 gst_vulkan_command_buffer_unlock (cmd_buf);
344 gst_vulkan_command_buffer_unref (cmd_buf);
348 GST_WARNING_OBJECT (raw->download, "Error: %s", error->message);
349 g_clear_error (&error);
351 gst_clear_buffer (outbuf);
352 ret = GST_FLOW_ERROR;
357 _image_to_raw_free (gpointer impl)
359 struct ImageToRawDownload *raw = impl;
362 if (raw->pool_active) {
363 gst_buffer_pool_set_active (raw->pool, FALSE);
365 raw->pool_active = FALSE;
366 gst_object_unref (raw->pool);
371 gst_object_unref (raw->cmd_pool);
372 raw->cmd_pool = NULL;
375 gst_object_unref (raw->trash_list);
376 raw->trash_list = NULL;
381 static GstStaticCaps _image_to_raw_in_templ =
382 GST_STATIC_CAPS ("video/x-raw(" GST_CAPS_FEATURE_MEMORY_VULKAN_IMAGE ")");
383 static GstStaticCaps _image_to_raw_out_templ = GST_STATIC_CAPS ("video/x-raw");
385 static const struct DownloadMethod image_to_raw_download = {
387 &_image_to_raw_in_templ,
388 &_image_to_raw_out_templ,
389 _image_to_raw_new_impl,
390 _image_to_raw_transform_caps,
391 _image_to_raw_set_caps,
392 _image_to_raw_propose_allocation,
393 _image_to_raw_perform,
397 static const struct DownloadMethod *download_methods[] = {
398 &image_to_raw_download,
402 _get_input_template_caps (void)
407 /* FIXME: cache this and invalidate on changes to download_methods */
408 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
409 GstCaps *template = gst_static_caps_get (download_methods[i]->in_template);
410 ret = ret == NULL ? template : gst_caps_merge (ret, template);
413 ret = gst_caps_simplify (ret);
419 _get_output_template_caps (void)
424 /* FIXME: cache this and invalidate on changes to download_methods */
425 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
426 GstCaps *template = gst_static_caps_get (download_methods[i]->out_template);
427 ret = ret == NULL ? template : gst_caps_merge (ret, template);
430 ret = gst_caps_simplify (ret);
435 static void gst_vulkan_download_finalize (GObject * object);
437 static gboolean gst_vulkan_download_query (GstBaseTransform * bt,
438 GstPadDirection direction, GstQuery * query);
439 static void gst_vulkan_download_set_context (GstElement * element,
440 GstContext * context);
441 static GstStateChangeReturn gst_vulkan_download_change_state (GstElement *
442 element, GstStateChange transition);
444 static gboolean gst_vulkan_download_set_caps (GstBaseTransform * bt,
445 GstCaps * in_caps, GstCaps * out_caps);
446 static GstCaps *gst_vulkan_download_transform_caps (GstBaseTransform * bt,
447 GstPadDirection direction, GstCaps * caps, GstCaps * filter);
448 static gboolean gst_vulkan_download_propose_allocation (GstBaseTransform * bt,
449 GstQuery * decide_query, GstQuery * query);
450 static gboolean gst_vulkan_download_decide_allocation (GstBaseTransform * bt,
452 static GstFlowReturn gst_vulkan_download_transform (GstBaseTransform * bt,
453 GstBuffer * inbuf, GstBuffer * outbuf);
454 static GstFlowReturn gst_vulkan_download_prepare_output_buffer (GstBaseTransform
455 * bt, GstBuffer * inbuf, GstBuffer ** outbuf);
468 /* static guint gst_vulkan_download_signals[LAST_SIGNAL] = { 0 }; */
470 #define gst_vulkan_download_parent_class parent_class
471 G_DEFINE_TYPE_WITH_CODE (GstVulkanDownload, gst_vulkan_download,
472 GST_TYPE_BASE_TRANSFORM, GST_DEBUG_CATEGORY_INIT (gst_debug_vulkan_download,
473 "vulkandownload", 0, "Vulkan Downloader"));
474 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (vulkandownload, "vulkandownload",
475 GST_RANK_NONE, GST_TYPE_VULKAN_DOWNLOAD, vulkan_element_init (plugin));
478 gst_vulkan_download_class_init (GstVulkanDownloadClass * klass)
480 GObjectClass *gobject_class;
481 GstElementClass *gstelement_class;
482 GstBaseTransformClass *gstbasetransform_class;
484 gobject_class = (GObjectClass *) klass;
485 gstelement_class = (GstElementClass *) klass;
486 gstbasetransform_class = (GstBaseTransformClass *) klass;
488 gst_element_class_set_metadata (gstelement_class, "Vulkan Downloader",
489 "Filter/Video", "A Vulkan data downloader",
490 "Matthew Waters <matthew@centricular.com>");
495 caps = _get_input_template_caps ();
496 gst_element_class_add_pad_template (gstelement_class,
497 gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps));
498 gst_caps_unref (caps);
500 caps = _get_output_template_caps ();
501 gst_element_class_add_pad_template (gstelement_class,
502 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps));
503 gst_caps_unref (caps);
506 gobject_class->finalize = gst_vulkan_download_finalize;
508 gstelement_class->change_state = gst_vulkan_download_change_state;
509 gstelement_class->set_context = gst_vulkan_download_set_context;
510 gstbasetransform_class->query = GST_DEBUG_FUNCPTR (gst_vulkan_download_query);
511 gstbasetransform_class->set_caps = gst_vulkan_download_set_caps;
512 gstbasetransform_class->transform_caps = gst_vulkan_download_transform_caps;
513 gstbasetransform_class->propose_allocation =
514 gst_vulkan_download_propose_allocation;
515 gstbasetransform_class->decide_allocation =
516 gst_vulkan_download_decide_allocation;
517 gstbasetransform_class->transform = gst_vulkan_download_transform;
518 gstbasetransform_class->prepare_output_buffer =
519 gst_vulkan_download_prepare_output_buffer;
523 gst_vulkan_download_init (GstVulkanDownload * vk_download)
527 n = G_N_ELEMENTS (download_methods);
528 vk_download->download_impls = g_malloc (sizeof (gpointer) * n);
529 for (i = 0; i < n; i++) {
530 vk_download->download_impls[i] =
531 download_methods[i]->new_impl (vk_download);
536 gst_vulkan_download_finalize (GObject * object)
538 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (object);
541 gst_caps_replace (&vk_download->in_caps, NULL);
542 gst_caps_replace (&vk_download->out_caps, NULL);
544 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
545 download_methods[i]->free (vk_download->download_impls[i]);
547 g_free (vk_download->download_impls);
548 vk_download->download_impls = NULL;
550 G_OBJECT_CLASS (parent_class)->finalize (object);
554 gst_vulkan_download_query (GstBaseTransform * bt, GstPadDirection direction,
557 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (bt);
559 switch (GST_QUERY_TYPE (query)) {
560 case GST_QUERY_CONTEXT:{
561 if (gst_vulkan_handle_context_query (GST_ELEMENT (vk_download), query,
562 NULL, vk_download->instance, vk_download->device))
565 if (gst_vulkan_queue_handle_context_query (GST_ELEMENT (vk_download),
566 query, vk_download->queue))
575 return GST_BASE_TRANSFORM_CLASS (parent_class)->query (bt, direction, query);
579 gst_vulkan_download_set_context (GstElement * element, GstContext * context)
581 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (element);
583 gst_vulkan_handle_set_context (element, context, NULL,
584 &vk_download->instance);
586 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
591 GstVulkanDownload *download;
592 GstVulkanQueue *queue;
596 _choose_queue (GstVulkanDevice * device, GstVulkanQueue * queue,
597 struct choose_data *data)
600 device->physical_device->queue_family_props[queue->family].queueFlags;
602 if ((flags & VK_QUEUE_GRAPHICS_BIT) != 0) {
604 gst_object_unref (data->queue);
605 data->queue = gst_object_ref (queue);
612 static GstVulkanQueue *
613 _find_graphics_queue (GstVulkanDownload * download)
615 struct choose_data data;
617 data.download = download;
620 gst_vulkan_device_foreach_queue (download->device,
621 (GstVulkanDeviceForEachQueueFunc) _choose_queue, &data);
626 static GstStateChangeReturn
627 gst_vulkan_download_change_state (GstElement * element,
628 GstStateChange transition)
630 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (element);
631 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
633 GST_DEBUG ("changing state: %s => %s",
634 gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)),
635 gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition)));
637 switch (transition) {
638 case GST_STATE_CHANGE_NULL_TO_READY:
640 case GST_STATE_CHANGE_READY_TO_PAUSED:
641 if (!gst_vulkan_ensure_element_data (element, NULL,
642 &vk_download->instance)) {
643 GST_ELEMENT_ERROR (vk_download, RESOURCE, NOT_FOUND,
644 ("Failed to retrieve vulkan instance"), (NULL));
645 return GST_STATE_CHANGE_FAILURE;
647 if (!gst_vulkan_device_run_context_query (GST_ELEMENT (vk_download),
648 &vk_download->device)) {
649 GError *error = NULL;
650 GST_DEBUG_OBJECT (vk_download,
651 "No device retrieved from peer elements");
652 if (!(vk_download->device =
653 gst_vulkan_instance_create_device (vk_download->instance,
655 GST_ELEMENT_ERROR (vk_download, RESOURCE, NOT_FOUND,
656 ("Failed to create vulkan device"), ("%s",
657 error ? error->message : ""));
658 g_clear_error (&error);
659 return GST_STATE_CHANGE_FAILURE;
663 if (!gst_vulkan_queue_run_context_query (GST_ELEMENT (vk_download),
664 &vk_download->queue)) {
665 GST_DEBUG_OBJECT (vk_download, "No queue retrieved from peer elements");
666 vk_download->queue = _find_graphics_queue (vk_download);
668 if (!vk_download->queue) {
669 GST_ELEMENT_ERROR (vk_download, RESOURCE, NOT_FOUND,
670 ("Failed to create/retrieve vulkan queue"), (NULL));
671 return GST_STATE_CHANGE_FAILURE;
674 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
680 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
681 if (ret == GST_STATE_CHANGE_FAILURE)
684 switch (transition) {
685 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
687 case GST_STATE_CHANGE_PAUSED_TO_READY:
688 if (vk_download->queue)
689 gst_object_unref (vk_download->queue);
690 vk_download->queue = NULL;
691 if (vk_download->device)
692 gst_object_unref (vk_download->device);
693 vk_download->device = NULL;
694 if (vk_download->instance)
695 gst_object_unref (vk_download->instance);
696 vk_download->instance = NULL;
698 case GST_STATE_CHANGE_READY_TO_NULL:
708 gst_vulkan_download_transform_caps (GstBaseTransform * bt,
709 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
711 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (bt);
712 GstCaps *result, *tmp;
715 tmp = gst_caps_new_empty ();
717 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
721 if (direction == GST_PAD_SINK) {
722 templ = gst_static_caps_get (download_methods[i]->in_template);
724 templ = gst_static_caps_get (download_methods[i]->out_template);
726 if (!gst_caps_can_intersect (caps, templ)) {
727 gst_caps_unref (templ);
730 gst_caps_unref (templ);
732 tmp2 = download_methods[i]->transform_caps (vk_download->download_impls[i],
736 tmp = gst_caps_merge (tmp, tmp2);
740 result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
741 gst_caps_unref (tmp);
750 gst_vulkan_download_set_caps (GstBaseTransform * bt, GstCaps * in_caps,
753 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (bt);
754 gboolean found_method = FALSE;
757 gst_caps_replace (&vk_download->in_caps, in_caps);
758 gst_caps_replace (&vk_download->out_caps, out_caps);
760 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
763 templ = gst_static_caps_get (download_methods[i]->in_template);
764 if (!gst_caps_can_intersect (in_caps, templ)) {
765 gst_caps_unref (templ);
768 gst_caps_unref (templ);
770 templ = gst_static_caps_get (download_methods[i]->out_template);
771 if (!gst_caps_can_intersect (out_caps, templ)) {
772 gst_caps_unref (templ);
775 gst_caps_unref (templ);
777 if (!download_methods[i]->set_caps (vk_download->download_impls[i], in_caps,
781 GST_LOG_OBJECT (bt, "downloader %s accepted caps in: %" GST_PTR_FORMAT
782 " out: %" GST_PTR_FORMAT, download_methods[i]->name, in_caps, out_caps);
784 vk_download->current_impl = i;
789 GST_DEBUG_OBJECT (bt,
790 "set caps in: %" GST_PTR_FORMAT " out: %" GST_PTR_FORMAT, in_caps,
797 gst_vulkan_download_propose_allocation (GstBaseTransform * bt,
798 GstQuery * decide_query, GstQuery * query)
800 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (bt);
803 for (i = 0; i < G_N_ELEMENTS (download_methods); i++) {
806 templ = gst_static_caps_get (download_methods[i]->in_template);
807 if (!gst_caps_can_intersect (vk_download->in_caps, templ)) {
808 gst_caps_unref (templ);
811 gst_caps_unref (templ);
813 templ = gst_static_caps_get (download_methods[i]->out_template);
814 if (!gst_caps_can_intersect (vk_download->out_caps, templ)) {
815 gst_caps_unref (templ);
818 gst_caps_unref (templ);
820 download_methods[i]->propose_allocation (vk_download->download_impls[i],
821 decide_query, query);
828 gst_vulkan_download_decide_allocation (GstBaseTransform * bt, GstQuery * query)
834 _download_find_method (GstVulkanDownload * vk_download)
836 vk_download->current_impl++;
838 if (vk_download->current_impl >= G_N_ELEMENTS (download_methods))
841 GST_DEBUG_OBJECT (vk_download, "attempting download with downloader %s",
842 download_methods[vk_download->current_impl]->name);
848 gst_vulkan_download_prepare_output_buffer (GstBaseTransform * bt,
849 GstBuffer * inbuf, GstBuffer ** outbuf)
851 GstBaseTransformClass *bclass = GST_BASE_TRANSFORM_GET_CLASS (bt);
852 GstVulkanDownload *vk_download = GST_VULKAN_DOWNLOAD (bt);
857 gpointer method_impl;
858 const struct DownloadMethod *method;
860 method = download_methods[vk_download->current_impl];
861 method_impl = vk_download->download_impls[vk_download->current_impl];
863 ret = method->perform (method_impl, inbuf, outbuf);
864 if (ret != GST_FLOW_OK) {
866 if (!_download_find_method (vk_download)) {
867 GST_ELEMENT_ERROR (bt, RESOURCE, NOT_FOUND,
868 ("Could not find suitable downloader"), (NULL));
869 return GST_FLOW_ERROR;
872 method = download_methods[vk_download->current_impl];
873 method_impl = vk_download->download_impls[vk_download->current_impl];
874 if (!method->set_caps (method_impl, vk_download->in_caps,
875 vk_download->out_caps))
876 /* try the next method */
879 /* try the downloading with the next method */
884 if (ret == GST_FLOW_OK) {
885 /* basetransform doesn't unref if they're the same */
886 if (inbuf != *outbuf)
887 bclass->copy_metadata (bt, inbuf, *outbuf);
894 gst_vulkan_download_transform (GstBaseTransform * bt, GstBuffer * inbuf,