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-vulkanimageidentity
23 * @title: vulkanimgeidentity
25 * vulkanimageidentity produces a vulkan image that is a copy of the input image.
34 #include "vkimageidentity.h"
36 #include "vkelementutils.h"
38 #include "shaders/identity.vert.h"
39 #include "shaders/identity.frag.h"
41 GST_DEBUG_CATEGORY (gst_debug_vulkan_image_identity);
42 #define GST_CAT_DEFAULT gst_debug_vulkan_image_identity
44 static gboolean gst_vulkan_image_identity_start (GstBaseTransform * bt);
45 static gboolean gst_vulkan_image_identity_stop (GstBaseTransform * bt);
47 static GstFlowReturn gst_vulkan_image_identity_transform (GstBaseTransform * bt,
48 GstBuffer * inbuf, GstBuffer * outbuf);
49 static gboolean gst_vulkan_image_identity_set_caps (GstBaseTransform * bt,
50 GstCaps * in_caps, GstCaps * out_caps);
52 #define IMAGE_FORMATS " { BGRA }"
54 static GstStaticPadTemplate gst_vulkan_sink_template =
55 GST_STATIC_PAD_TEMPLATE ("sink",
58 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
59 (GST_CAPS_FEATURE_MEMORY_VULKAN_IMAGE,
62 static GstStaticPadTemplate gst_vulkan_src_template =
63 GST_STATIC_PAD_TEMPLATE ("src",
66 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
67 (GST_CAPS_FEATURE_MEMORY_VULKAN_IMAGE,
81 /* static guint gst_vulkan_image_identity_signals[LAST_SIGNAL] = { 0 }; */
83 #define gst_vulkan_image_identity_parent_class parent_class
84 G_DEFINE_TYPE_WITH_CODE (GstVulkanImageIdentity, gst_vulkan_image_identity,
85 GST_TYPE_VULKAN_VIDEO_FILTER,
86 GST_DEBUG_CATEGORY_INIT (gst_debug_vulkan_image_identity,
87 "vulkanimageidentity", 0, "Vulkan Image identity"));
90 gst_vulkan_image_identity_class_init (GstVulkanImageIdentityClass * klass)
92 GstElementClass *gstelement_class;
93 GstBaseTransformClass *gstbasetransform_class;
95 gstelement_class = (GstElementClass *) klass;
96 gstbasetransform_class = (GstBaseTransformClass *) klass;
98 gst_element_class_set_metadata (gstelement_class, "Vulkan Image Identity",
99 "Filter/Video", "A Vulkan image copier",
100 "Matthew Waters <matthew@centricular.com>");
102 gst_element_class_add_static_pad_template (gstelement_class,
103 &gst_vulkan_sink_template);
104 gst_element_class_add_static_pad_template (gstelement_class,
105 &gst_vulkan_src_template);
107 gstbasetransform_class->start =
108 GST_DEBUG_FUNCPTR (gst_vulkan_image_identity_start);
109 gstbasetransform_class->stop =
110 GST_DEBUG_FUNCPTR (gst_vulkan_image_identity_stop);
111 gstbasetransform_class->set_caps = gst_vulkan_image_identity_set_caps;
112 gstbasetransform_class->transform = gst_vulkan_image_identity_transform;
116 gst_vulkan_image_identity_init (GstVulkanImageIdentity * vk_identity)
121 gst_vulkan_image_identity_set_caps (GstBaseTransform * bt, GstCaps * in_caps,
124 GstVulkanVideoFilter *vfilter = GST_VULKAN_VIDEO_FILTER (bt);
125 GstVulkanImageIdentity *vk_identity = GST_VULKAN_IMAGE_IDENTITY (bt);
127 if (!GST_BASE_TRANSFORM_CLASS (parent_class)->set_caps (bt, in_caps,
131 if (!gst_vulkan_full_screen_quad_set_info (vk_identity->quad,
132 &vfilter->in_info, &vfilter->out_info))
139 gst_vulkan_image_identity_start (GstBaseTransform * bt)
141 GstVulkanImageIdentity *vk_identity = GST_VULKAN_IMAGE_IDENTITY (bt);
142 GstVulkanVideoFilter *vfilter = GST_VULKAN_VIDEO_FILTER (vk_identity);
143 GstVulkanHandle *vert, *frag;
144 GError *error = NULL;
146 if (!GST_BASE_TRANSFORM_CLASS (parent_class)->start (bt))
149 vk_identity->quad = gst_vulkan_full_screen_quad_new (vfilter->queue);
151 if (!(vert = _vk_create_shader (vfilter->device, identity_vert,
152 identity_vert_size, &error)))
154 if (!(frag = _vk_create_shader (vfilter->device, identity_frag,
155 identity_frag_size, &error))) {
156 gst_vulkan_handle_unref (vert);
159 gst_vulkan_full_screen_quad_set_shaders (vk_identity->quad, vert, frag);
161 gst_vulkan_handle_unref (vert);
162 gst_vulkan_handle_unref (frag);
167 GST_ELEMENT_ERROR (bt, RESOURCE, NOT_FOUND, ("%s", error->message), (NULL));
172 gst_vulkan_image_identity_stop (GstBaseTransform * bt)
174 GstVulkanImageIdentity *vk_identity = GST_VULKAN_IMAGE_IDENTITY (bt);
176 gst_clear_object (&vk_identity->quad);
178 return GST_BASE_TRANSFORM_CLASS (parent_class)->stop (bt);
182 gst_vulkan_image_identity_transform (GstBaseTransform * bt, GstBuffer * inbuf,
185 GstVulkanImageIdentity *vk_identity = GST_VULKAN_IMAGE_IDENTITY (bt);
186 GError *error = NULL;
188 if (!gst_vulkan_full_screen_quad_set_input_buffer (vk_identity->quad, inbuf,
191 if (!gst_vulkan_full_screen_quad_set_output_buffer (vk_identity->quad, outbuf,
195 if (!gst_vulkan_full_screen_quad_draw (vk_identity->quad, &error))
201 GST_ELEMENT_ERROR (bt, LIBRARY, FAILED, ("%s", error->message), (NULL));
202 g_clear_error (&error);
203 return GST_FLOW_ERROR;