3 * Copyright (C) <2019> Seungha Yang <seungha.yang@navercorp.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.
25 #include "gstcudadownload.h"
27 GST_DEBUG_CATEGORY_STATIC (gst_cuda_download_debug);
28 #define GST_CAT_DEFAULT gst_cuda_download_debug
30 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
33 GST_STATIC_CAPS ("video/x-raw(" GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY
36 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
39 GST_STATIC_CAPS ("video/x-raw"));
41 G_DEFINE_TYPE (GstCudaDownload, gst_cuda_download,
42 GST_TYPE_CUDA_BASE_TRANSFORM);
44 static GstCaps *gst_cuda_download_transform_caps (GstBaseTransform * trans,
45 GstPadDirection direction, GstCaps * caps, GstCaps * filter);
48 gst_cuda_download_class_init (GstCudaDownloadClass * klass)
50 GstElementClass *element_class;
51 GstBaseTransformClass *trans_class;
53 element_class = GST_ELEMENT_CLASS (klass);
54 trans_class = GST_BASE_TRANSFORM_CLASS (klass);
56 gst_element_class_add_static_pad_template (element_class, &sink_template);
57 gst_element_class_add_static_pad_template (element_class, &src_template);
59 gst_element_class_set_static_metadata (element_class,
60 "CUDA downloader", "Filter/Video",
61 "Uploads data into NVIDA GPU via CUDA APIs",
62 "Seungha Yang <seungha.yang@navercorp.com>");
64 trans_class->passthrough_on_same_caps = TRUE;
66 trans_class->transform_caps =
67 GST_DEBUG_FUNCPTR (gst_cuda_download_transform_caps);
69 GST_DEBUG_CATEGORY_INIT (gst_cuda_download_debug,
70 "cudadownload", 0, "cudadownload Element");
74 gst_cuda_download_init (GstCudaDownload * download)
79 _set_caps_features (const GstCaps * caps, const gchar * feature_name)
81 GstCaps *tmp = gst_caps_copy (caps);
82 guint n = gst_caps_get_size (tmp);
85 for (i = 0; i < n; i++)
86 gst_caps_set_features (tmp, i,
87 gst_caps_features_from_string (feature_name));
93 gst_cuda_download_transform_caps (GstBaseTransform * trans,
94 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
96 GstCaps *result, *tmp;
98 GST_DEBUG_OBJECT (trans,
99 "Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
100 (direction == GST_PAD_SINK) ? "sink" : "src");
102 if (direction == GST_PAD_SINK) {
103 tmp = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
104 tmp = gst_caps_merge (gst_caps_ref (caps), tmp);
107 tmp = gst_caps_ref (caps);
109 newcaps = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY);
110 tmp = gst_caps_merge (tmp, newcaps);
114 result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
115 gst_caps_unref (tmp);
120 GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, result);