Commit 711528c4 authored by Seungha Yang's avatar Seungha Yang 🐑
Browse files

nvcodec: Add simple cuda{upload,download} elements

... to transfer memory between system and GPU
parent 02af830e
Pipeline #26867 failed with stages
in 4 minutes and 14 seconds
plugin_LTLIBRARIES = libgstnvcodec.la
libgstnvcodec_la_SOURCES = \
plugin.c
plugin.c \
gstcudadownload.c \
gstcudaupload.c
if USE_NVDEC
libgstnvcodec_la_SOURCES += \
......@@ -23,7 +25,9 @@ noinst_HEADERS = \
gstnvbaseenc.h \
gstnvh264enc.h \
gstnvh265enc.h \
gstcuvidloader.h
gstcuvidloader.h \
gstcudadownload.h \
gstcudaupload.h
libgstnvcodec_la_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) \
......
/* GStreamer
* Copyright (C) <2019> Seungha Yang <seungha.yang@navercorp.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "gstcudadownload.h"
GST_DEBUG_CATEGORY_STATIC (gst_cuda_download_debug);
#define GST_CAT_DEFAULT gst_cuda_download_debug
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw(" GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY
"); video/x-raw"));
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw; video/x-raw("
GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY ")"));
G_DEFINE_TYPE (GstCudaDownload, gst_cuda_download, GST_TYPE_CUDA_BASE_FILTER);
static GstCaps *gst_cuda_download_transform_caps (GstBaseTransform * trans,
GstPadDirection direction, GstCaps * caps, GstCaps * filter);
static void
gst_cuda_download_class_init (GstCudaDownloadClass * klass)
{
GstElementClass *element_class;
GstBaseTransformClass *trans_class;
element_class = GST_ELEMENT_CLASS (klass);
trans_class = GST_BASE_TRANSFORM_CLASS (klass);
gst_element_class_add_static_pad_template (element_class, &sink_template);
gst_element_class_add_static_pad_template (element_class, &src_template);
gst_element_class_set_static_metadata (element_class,
"CUDA downloader", "Filter/Video",
"Uploads data into NVIDA GPU via CUDA APIs",
"Seungha Yang <seungha.yang@navercorp.com>");
trans_class->passthrough_on_same_caps = TRUE;
trans_class->transform_caps =
GST_DEBUG_FUNCPTR (gst_cuda_download_transform_caps);
GST_DEBUG_CATEGORY_INIT (gst_cuda_download_debug,
"cudadownload", 0, "cudadownload Element");
}
static void
gst_cuda_download_init (GstCudaDownload * download)
{
}
static GstCaps *
_set_caps_features (const GstCaps * caps, const gchar * feature_name)
{
GstCaps *tmp = gst_caps_copy (caps);
guint n = gst_caps_get_size (tmp);
guint i = 0;
for (i = 0; i < n; i++)
gst_caps_set_features (tmp, i,
gst_caps_features_from_string (feature_name));
return tmp;
}
static GstCaps *
gst_cuda_download_transform_caps (GstBaseTransform * trans,
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
{
GstCaps *result, *tmp;
GST_DEBUG_OBJECT (trans,
"Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
(direction == GST_PAD_SINK) ? "sink" : "src");
if (direction == GST_PAD_SINK) {
tmp = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
tmp = gst_caps_merge (gst_caps_ref (caps), tmp);
} else {
GstCaps *newcaps;
tmp = gst_caps_ref (caps);
newcaps = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY);
tmp = gst_caps_merge (tmp, newcaps);
}
if (filter) {
result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (tmp);
} else {
result = tmp;
}
GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, result);
return result;
}
/* GStreamer
* Copyright (C) <2019> Seungha Yang <seungha.yang@navercorp.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_CUDA_DOWNLOAD_H__
#define __GST_CUDA_DOWNLOAD_H__
#include <gst/cuda/gstcudabasefilter.h>
G_BEGIN_DECLS
#define GST_TYPE_CUDA_DOWNLOAD (gst_cuda_download_get_type())
#define GST_CUDA_DOWNLOAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CUDA_DOWNLOAD,GstCudaDownload))
#define GST_CUDA_DOWNLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_CUDA_DOWNLOAD,GstCudaDownloadClass))
#define GST_CUDA_DOWNLOAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_CUDA_DOWNLOAD,GstCudaDownloadClass))
#define GST_IS_CUDA_DOWNLOAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CUDA_DOWNLOAD))
#define GST_IS_CUDA_DOWNLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_CUDA_DOWNLOAD))
typedef struct _GstCudaDownload GstCudaDownload;
typedef struct _GstCudaDownloadClass GstCudaDownloadClass;
struct _GstCudaDownload
{
GstCudaBaseFilter parent;
};
struct _GstCudaDownloadClass
{
GstCudaBaseFilterClass parent_class;
};
GType gst_cuda_download_get_type (void);
G_END_DECLS
#endif /* __GST_CUDA_DOWNLOAD_H__ */
/* GStreamer
* Copyright (C) <2019> Seungha Yang <seungha.yang@navercorp.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "gstcudaupload.h"
GST_DEBUG_CATEGORY_STATIC (gst_cuda_upload_debug);
#define GST_CAT_DEFAULT gst_cuda_upload_debug
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw; video/x-raw("
GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY ")"));
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw(" GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY
"); video/x-raw"));
G_DEFINE_TYPE (GstCudaUpload, gst_cuda_upload, GST_TYPE_CUDA_BASE_FILTER);
static GstCaps *gst_cuda_upload_transform_caps (GstBaseTransform * trans,
GstPadDirection direction, GstCaps * caps, GstCaps * filter);
static void
gst_cuda_upload_class_init (GstCudaUploadClass * klass)
{
GstElementClass *element_class;
GstBaseTransformClass *trans_class;
element_class = GST_ELEMENT_CLASS (klass);
trans_class = GST_BASE_TRANSFORM_CLASS (klass);
gst_element_class_add_static_pad_template (element_class, &sink_template);
gst_element_class_add_static_pad_template (element_class, &src_template);
gst_element_class_set_static_metadata (element_class,
"CUDA uploader", "Filter/Video",
"Uploads data into NVIDA GPU via CUDA APIs",
"Seungha Yang <seungha.yang@navercorp.com>");
trans_class->passthrough_on_same_caps = TRUE;
trans_class->transform_caps =
GST_DEBUG_FUNCPTR (gst_cuda_upload_transform_caps);
GST_DEBUG_CATEGORY_INIT (gst_cuda_upload_debug,
"cudaupload", 0, "cudaupload Element");
}
static void
gst_cuda_upload_init (GstCudaUpload * upload)
{
}
static GstCaps *
_set_caps_features (const GstCaps * caps, const gchar * feature_name)
{
GstCaps *tmp = gst_caps_copy (caps);
guint n = gst_caps_get_size (tmp);
guint i = 0;
for (i = 0; i < n; i++)
gst_caps_set_features (tmp, i,
gst_caps_features_from_string (feature_name));
return tmp;
}
static GstCaps *
gst_cuda_upload_transform_caps (GstBaseTransform * trans,
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
{
GstCaps *result, *tmp;
GST_DEBUG_OBJECT (trans,
"Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
(direction == GST_PAD_SINK) ? "sink" : "src");
if (direction == GST_PAD_SINK) {
tmp = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY);
tmp = gst_caps_merge (gst_caps_ref (caps), tmp);
} else {
GstCaps *newcaps;
tmp = gst_caps_ref (caps);
newcaps = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
tmp = gst_caps_merge (tmp, newcaps);
}
if (filter) {
result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (tmp);
} else {
result = tmp;
}
GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, result);
return result;
}
/* GStreamer
* Copyright (C) <2019> Seungha Yang <seungha.yang@navercorp.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_CUDA_UPLOAD_H__
#define __GST_CUDA_UPLOAD_H__
#include <gst/cuda/gstcudabasefilter.h>
G_BEGIN_DECLS
#define GST_TYPE_CUDA_UPLOAD (gst_cuda_upload_get_type())
#define GST_CUDA_UPLOAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CUDA_UPLOAD,GstCudaUpload))
#define GST_CUDA_UPLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_CUDA_UPLOAD,GstCudaUploadClass))
#define GST_CUDA_UPLOAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_CUDA_UPLOAD,GstCudaUploadClass))
#define GST_IS_CUDA_UPLOAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CUDA_UPLOAD))
#define GST_IS_CUDA_UPLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_CUDA_UPLOAD))
typedef struct _GstCudaUpload GstCudaUpload;
typedef struct _GstCudaUploadClass GstCudaUploadClass;
struct _GstCudaUpload
{
GstCudaBaseFilter parent;
};
struct _GstCudaUploadClass
{
GstCudaBaseFilterClass parent_class;
};
GType gst_cuda_upload_get_type (void);
G_END_DECLS
#endif /* __GST_CUDA_UPLOAD_H__ */
......@@ -12,6 +12,8 @@ nvenc_sources = [
nvcodec_sources = [
'plugin.c',
'gstcudadownload.c',
'gstcudaupload.c',
]
nvdec_option = get_option('nvdec')
......
......@@ -41,6 +41,9 @@
#include "gstnvenc.h"
#endif
#include "gstcudaupload.h"
#include "gstcudadownload.h"
static gboolean
plugin_init (GstPlugin * plugin)
{
......@@ -60,6 +63,11 @@ plugin_init (GstPlugin * plugin)
ret &= gst_nvenc_plugin_init (plugin);
#endif
ret &= gst_element_register (plugin, "cudadownload", GST_RANK_NONE,
GST_TYPE_CUDA_DOWNLOAD);
ret &= gst_element_register (plugin, "cudaupload", GST_RANK_NONE,
GST_TYPE_CUDA_UPLOAD);
return ret;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment