├── .gitignore
├── README
├── autogen.sh
├── configure.ac
├── configure.py
├── curves.cu
├── .cproject.in
├── .project
├── curve.txt
├── install
├── src
│ └── gstvideofilter.cu
├── test
└── webcam
├── desaturate.cu
├── .cproject.in
├── .project
├── install
├── src
│ └── gstvideofilter.cu
├── test
└── webcam
├── gpu2host.cu
├── .cproject.in
├── .project
├── install
├── src
│ └── gstvideofilter.cu
└── test
├── gradient.cu
├── .cproject.in
├── .project
├── install
├── src
│ └── gstvideofilter.cu
├── test
└── webcam
├── host2gpu.cu
├── .cproject.in
├── .project
├── install
├── src
│ └── gstvideofilter.cu
└── test
├── lens.cu
├── .cproject.in
├── .project
├── install
├── src
│ └── gstvideofilter.cu
├── test
└── webcam
├── retina.cu
├── .cproject.in
├── .project
├── install
├── src
│ └── gstvideofilter.cu
├── test
└── webcam
└── temporal.cu
├── .cproject.in
├── .project
├── install
├── src
└── gstvideofilter.cu
├── test
└── webcam
/.gitignore:
--------------------------------------------------------------------------------
1 | config.h
2 | config.log
3 | .cproject
4 | .metadata
5 | RemoteSystemsTempFiles
6 | Debug
7 | Release
8 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | GSTREAMER PLUGIN BUNDLE FOR NVIDIA GPUS
2 | ---------------------------------------
3 |
4 | This is a bundle of gstreamer plugins which use NVIDIA CUDA technology to run on NVIDIA GPUs.
5 | To build those plugins you have to install gstreamer 0.10 and NVIDIA CUDA SDK 5.5.22 for Linux.
6 | To use the plugins you need an NVIDIA GPU with compute capability 2.0 or higher.
7 |
8 |
9 |
10 | BUILD INSTRUCTIONS
11 | ------------------
12 |
13 | 1. 'git clone' or copy the sources into your Nsight Eclipse Edition workspace
14 |
15 | 2. Execute configure.py
16 |
17 | 3. From Nsight IDE import all projects into your workspace (File -> Import... -> General -> Exsting Projects into Workspace)
18 |
19 | 4. Build plugins you need
20 |
21 | 5. Copy libgstcuda*.so files to /usr/lib/gstreamer-0.10/
22 |
23 |
24 |
25 | GSTREAMER PIPELINE EXAMPLES
26 | ---------------------------
27 |
28 | There are two special plugins: cudahost2gpu opens a CUDA pipeline and cudagpu2host closes the CUDA pipeline. All other CUDA plugins
29 | must be in between.
30 |
31 | gst-launch v4l2src ! ffmpegcolorspace ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudalens ! cudagpu2host ! ximagesink
32 |
--------------------------------------------------------------------------------
/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # you can either set the environment variables AUTOCONF, AUTOHEADER, AUTOMAKE,
3 | # ACLOCAL, AUTOPOINT and/or LIBTOOLIZE to the right versions, or leave them
4 | # unset and get the defaults
5 |
6 | mkdir -p common
7 | touch common/Makefile.am
8 |
9 | autoreconf --verbose --force --install --make || {
10 | echo 'autogen.sh failed';
11 | exit 1;
12 | }
13 |
14 | ./configure || {
15 | echo 'configure failed';
16 | exit 1;
17 | }
18 |
19 | rm -r aclocal.m4 autom4te.cache config.guess config.status config.sub configure install-sh libtool ltmain.sh missing
20 | rm common/config.h.in* common/Makefile* common/stamp-h1
21 |
22 |
--------------------------------------------------------------------------------
/configure.ac:
--------------------------------------------------------------------------------
1 | dnl required version of autoconf
2 | AC_PREREQ([2.53])
3 |
4 | dnl TODO: fill in your package name and package version here
5 | AC_INIT([cuda-plugins],[0.10.0])
6 |
7 | dnl required versions of gstreamer and plugins-base
8 | GST_REQUIRED=0.10.16
9 | GSTPB_REQUIRED=0.10.16
10 |
11 | AC_CONFIG_HEADERS([common/config.h])
12 |
13 | dnl required version of automake
14 | AM_INIT_AUTOMAKE([1.10])
15 |
16 | dnl enable mainainer mode by default
17 | AM_MAINTAINER_MODE([enable])
18 |
19 | dnl check for tools (compiler etc.)
20 | AC_PROG_CC
21 |
22 | dnl required version of libtool
23 | LT_PREREQ([2.2.6])
24 | LT_INIT
25 |
26 | dnl give error and exit if we don't have pkgconfig
27 | AC_CHECK_PROG(HAVE_PKGCONFIG, pkg-config, [ ], [
28 | AC_MSG_ERROR([You need to have pkg-config installed!])
29 | ])
30 |
31 | dnl Check for the required version of GStreamer core (and gst-plugins-base)
32 | dnl This will export GST_CFLAGS and GST_LIBS variables for use in Makefile.am
33 | dnl
34 | dnl If you need libraries from gst-plugins-base here, also add:
35 | dnl for libgstaudio-0.10: gstreamer-audio-0.10 >= $GST_REQUIRED
36 | dnl for libgstvideo-0.10: gstreamer-video-0.10 >= $GST_REQUIRED
37 | dnl for libgsttag-0.10: gstreamer-tag-0.10 >= $GST_REQUIRED
38 | dnl for libgstpbutils-0.10: gstreamer-pbutils-0.10 >= $GST_REQUIRED
39 | dnl for libgstfft-0.10: gstreamer-fft-0.10 >= $GST_REQUIRED
40 | dnl for libgstinterfaces-0.10: gstreamer-interfaces-0.10 >= $GST_REQUIRED
41 | dnl for libgstrtp-0.10: gstreamer-rtp-0.10 >= $GST_REQUIRED
42 | dnl for libgstrtsp-0.10: gstreamer-rtsp-0.10 >= $GST_REQUIRED
43 | dnl etc.
44 | PKG_CHECK_MODULES(GST, [
45 | gstreamer-0.10 >= $GST_REQUIRED
46 | gstreamer-base-0.10 >= $GST_REQUIRED
47 | gstreamer-controller-0.10 >= $GST_REQUIRED
48 | gstreamer-video-0.10 >= $GST_REQUIRED
49 | ], [
50 | AC_SUBST(GST_CFLAGS)
51 | AC_SUBST(GST_LIBS)
52 | ], [
53 | AC_MSG_ERROR([
54 | You need to install or upgrade the GStreamer development
55 | packages on your system. On debian-based systems these are
56 | libgstreamer0.10-dev and libgstreamer-plugins-base0.10-dev.
57 | on RPM-based systems gstreamer0.10-devel, libgstreamer0.10-devel
58 | or similar. The minimum version required is $GST_REQUIRED.
59 | ])
60 | ])
61 |
62 | dnl check if compiler understands -Wall (if yes, add -Wall to GST_CFLAGS)
63 | AC_MSG_CHECKING([to see if compiler understands -Wall])
64 | save_CFLAGS="$CFLAGS"
65 | CFLAGS="$CFLAGS -Wall"
66 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ ], [ ])], [
67 | GST_CFLAGS="$GST_CFLAGS -Wall"
68 | AC_MSG_RESULT([yes])
69 | ], [
70 | AC_MSG_RESULT([no])
71 | ])
72 |
73 | dnl set the plugindir where plugins should be installed (for src/Makefile.am)
74 | if test "x${prefix}" = "x$HOME"; then
75 | plugindir="$HOME/.gstreamer-0.10/plugins"
76 | else
77 | plugindir="\$(libdir)/gstreamer-0.10"
78 | fi
79 | AC_SUBST(plugindir)
80 |
81 | dnl set proper LDFLAGS for plugins
82 | GST_PLUGIN_LDFLAGS='-module -avoid-version -export-symbols-regex [_]*\(gst_\|Gst\|GST_\).*'
83 | AC_SUBST(GST_PLUGIN_LDFLAGS)
84 |
85 | AC_CONFIG_FILES([common/Makefile])
86 | AC_OUTPUT
87 |
88 |
--------------------------------------------------------------------------------
/configure.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2
2 |
3 | import os
4 | import sys
5 | import re
6 |
7 | if __name__ == "__main__":
8 |
9 | #----------------
10 | # run autogen.sh
11 | #----------------
12 | if os.system("./autogen.sh") != 0:
13 | print("Error: autogen.sh failed")
14 | sys.exit(2)
15 |
16 | #------------------
17 | # parse config.log
18 | #------------------
19 | try:
20 | f = open("config.log", "r")
21 | except IOError as err:
22 | print(str(err))
23 | sys.exit(2)
24 |
25 | q_cflags = re.compile(r"^GST_CFLAGS=[\"\'](.*)[\"\']")
26 | q_libs = re.compile(r"^GST_LIBS=[\"\'](.*)[\"\']")
27 |
28 | cflags = []
29 | lflags = []
30 |
31 | for l in f.readlines():
32 | m = q_cflags.match(l)
33 | if m:
34 | cflags = m.group(1).split()
35 | else:
36 | m = q_libs.match(l)
37 | if m:
38 | lflags = m.group(1).split()
39 | if cflags != [] and lflags != []:
40 | break
41 |
42 | f.close()
43 |
44 | include_dirs = []
45 | libs = []
46 |
47 | for flag in cflags:
48 | if len(flag) > 2 and flag[0:2] == "-I":
49 | include_dirs.append(flag[2:])
50 |
51 | if len(include_dirs) <= 0:
52 | print("Warning: No include dirs")
53 |
54 | for flag in lflags:
55 | if len(flag) > 2 and flag[0:2] == "-l":
56 | libs.append(flag[2:])
57 |
58 | if len(libs) <= 0:
59 | print("Warning: No libs")
60 |
61 | del cflags
62 | del lflags
63 |
64 | #----------------------
65 | # Create project files
66 | #----------------------
67 | q_tbd_includes = re.compile(r"^(.*)TBD_INCLUDES(.*)$")
68 | q_tbd_libs = re.compile(r"^(.*)TBD_LIBS(.*)$")
69 |
70 | dir_list = os.listdir(".")
71 | for i in dir_list:
72 | if i[-3:] == ".cu":
73 | f_in = open("%s/.cproject.in" % i, "r")
74 | if not f_in:
75 | print("Warning: %s/.cproject.in does not exist" %i)
76 | break
77 |
78 | f_out = open("%s/.cproject" % i, "w")
79 |
80 | for j in f_in.readlines():
81 | m = q_tbd_includes.match(j)
82 | if m:
83 | prefix = m.group(1)
84 | postfix = m.group(2)
85 | for k in include_dirs:
86 | f_out.write("%s%s%s\n" % (prefix, k, postfix))
87 | else:
88 | m = q_tbd_libs.match(j)
89 | if m:
90 | prefix = m.group(1)
91 | postfix = m.group(2)
92 | for k in libs:
93 | f_out.write("%s%s%s\n" % (prefix, k, postfix))
94 | else:
95 | f_out.write(j)
96 |
97 | f_out.close()
98 | f_in.close()
99 |
100 |
--------------------------------------------------------------------------------
/curves.cu/.cproject.in:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
39 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
113 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
--------------------------------------------------------------------------------
/curves.cu/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | curves.cu
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/curves.cu/curve.txt:
--------------------------------------------------------------------------------
1 | 0 255
2 | 63 191
3 | 127 127
4 | 191 63
5 | 255 0
6 |
--------------------------------------------------------------------------------
/curves.cu/install:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cp Release/libgstcudacurves.so /usr/lib/gstreamer-0.10/
3 |
--------------------------------------------------------------------------------
/curves.cu/test:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch --gst-debug="cudacurves:5" videotestsrc ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudacurves red="curve.txt" green="curve.txt" blue="curve.txt" ! cudagpu2host ! ximagesink
3 |
--------------------------------------------------------------------------------
/curves.cu/webcam:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch v4l2src ! ffmpegcolorspace ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudacurves red="curve.txt" green="curve.txt" blue="curve.txt" ! cudagpu2host ! ximagesink
3 |
4 |
--------------------------------------------------------------------------------
/desaturate.cu/.cproject.in:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
39 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
113 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
--------------------------------------------------------------------------------
/desaturate.cu/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | desaturate.cu
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/desaturate.cu/install:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cp Release/libgstcudadesaturate.so /usr/lib/gstreamer-0.10/
3 |
--------------------------------------------------------------------------------
/desaturate.cu/src/gstvideofilter.cu:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) <1999> Erik Walthinsen
4 | * Copyright (C) <2003> David Schleef
5 | * Copyright (C) <2012> Mikhail Durnev
6 | * Copyright (C) <2014> Mikhail Durnev
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a
9 | * copy of this software and associated documentation files (the "Software"),
10 | * to deal in the Software without restriction, including without limitation
11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 | * and/or sell copies of the Software, and to permit persons to whom the
13 | * Software is furnished to do so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 | * DEALINGS IN THE SOFTWARE.
25 | *
26 | * Alternatively, the contents of this file may be used under the
27 | * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
28 | * which case the following provisions apply instead of the ones
29 | * mentioned above:
30 | *
31 | * This library is free software; you can redistribute it and/or
32 | * modify it under the terms of the GNU Library General Public
33 | * License as published by the Free Software Foundation; either
34 | * version 2 of the License, or (at your option) any later version.
35 | *
36 | * This library is distributed in the hope that it will be useful,
37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 | * Library General Public License for more details.
40 | *
41 | * You should have received a copy of the GNU Library General Public
42 | * License along with this library; if not, write to the
43 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
44 | * Boston, MA 02111-1307, USA.
45 | */
46 |
47 | /**
48 | * SECTION:element-plugin
49 | *
50 | * FIXME:Describe plugin here.
51 | *
52 | *
53 | * Example launch line
54 | * |[
55 | * gst-launch -v -m videotestsrc ! plugin ! autovideosink
56 | * ]|
57 | *
58 | */
59 |
60 | #ifdef HAVE_CONFIG_H
61 | #include "../../common/config.h"
62 | #endif
63 |
64 | #include
65 | #include
66 | #include
67 | #include
68 |
69 | #define CUDA_CHECK_RETURN(value) { \
70 | cudaError_t stat = value; \
71 | if (stat != cudaSuccess) { \
72 | GST_DEBUG("Error %s at line %d in file %s\n", \
73 | cudaGetErrorString(stat), __LINE__, __FILE__); \
74 | } }
75 |
76 | typedef unsigned int uint32_t;
77 |
78 | #define PLAGIN_NAME "cudadesaturate"
79 | #define PLAGIN_SHORT_DESCRIPTION "CUDA desaturate Filter"
80 |
81 | GST_DEBUG_CATEGORY_STATIC (gst_plugin_template_debug);
82 | #define GST_CAT_DEFAULT gst_plugin_template_debug
83 |
84 | typedef struct _GstPlugincudadesaturate GstPlugincudadesaturate;
85 | typedef struct _GstPlugincudadesaturateClass GstPlugincudadesaturateClass;
86 |
87 | #define GST_TYPE_PLUGIN_TEMPLATE \
88 | (gst_plugin_template_get_type())
89 | #define GST_PLUGIN_TEMPLATE(obj) \
90 | (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLUGIN_TEMPLATE,GstPlugincudadesaturate))
91 | #define GST_PLUGIN_TEMPLATE_CLASS(klass) \
92 | (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLUGIN_TEMPLATE,GstPlugincudadesaturateClass))
93 | #define GST_IS_PLUGIN_TEMPLATE(obj) \
94 | (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLUGIN_TEMPLATE))
95 | #define GST_IS_PLUGIN_TEMPLATE_CLASS(klass) \
96 | (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLUGIN_TEMPLATE))
97 |
98 | struct _GstPlugincudadesaturate
99 | {
100 | GstVideoFilter videofilter;
101 |
102 | gint width;
103 | gint height;
104 |
105 | gint saturation;
106 | };
107 |
108 | struct _GstPlugincudadesaturateClass
109 | {
110 | GstVideoFilterClass parent_class;
111 | };
112 |
113 |
114 | enum
115 | {
116 | /* FILL ME */
117 | LAST_SIGNAL
118 | };
119 |
120 | enum
121 | {
122 | PROP_0,
123 | PROP_SATURATION
124 | };
125 |
126 | /* debug category for fltering log messages
127 | */
128 | #define DEBUG_INIT(bla) \
129 | GST_DEBUG_CATEGORY_INIT (gst_plugin_template_debug, PLAGIN_NAME, 0, PLAGIN_SHORT_DESCRIPTION);
130 |
131 | GST_BOILERPLATE_FULL (GstPlugincudadesaturate, gst_plugin_template,
132 | GstVideoFilter, GST_TYPE_VIDEO_FILTER, DEBUG_INIT);
133 |
134 | static void gst_plugin_template_set_property (GObject * object,
135 | guint prop_id, const GValue * value, GParamSpec * pspec);
136 | static void gst_plugin_template_get_property (GObject * object,
137 | guint prop_id, GValue * value, GParamSpec * pspec);
138 | static void gst_plugin_template_finalize (GObject * object);
139 |
140 | static gboolean gst_plugin_template_set_caps (GstBaseTransform * bt,
141 | GstCaps * incaps, GstCaps * outcaps);
142 | //static GstFlowReturn gst_plugin_template_filter (GstBaseTransform * bt,
143 | // GstBuffer * outbuf, GstBuffer * inbuf);
144 | static GstFlowReturn
145 | gst_plugin_template_filter_inplace (GstBaseTransform * base_transform,
146 | GstBuffer * buf);
147 |
148 | #define ALLOWED_CAPS_STRING \
149 | GST_VIDEO_CAPS_BGRx
150 |
151 | static GstStaticPadTemplate gst_video_filter_src_template =
152 | GST_STATIC_PAD_TEMPLATE ("src",
153 | GST_PAD_SRC,
154 | GST_PAD_ALWAYS,
155 | GST_STATIC_CAPS (ALLOWED_CAPS_STRING)
156 | );
157 |
158 | static GstStaticPadTemplate gst_video_filter_sink_template =
159 | GST_STATIC_PAD_TEMPLATE ("sink",
160 | GST_PAD_SINK,
161 | GST_PAD_ALWAYS,
162 | GST_STATIC_CAPS (ALLOWED_CAPS_STRING)
163 | );
164 |
165 | /* GObject method implementations */
166 |
167 | static void
168 | gst_plugin_template_base_init (gpointer klass)
169 | {
170 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
171 | GstVideoFilterClass *videofilter_class = GST_VIDEO_FILTER_CLASS (klass);
172 | GstCaps *caps;
173 |
174 | gst_element_class_set_details_simple (element_class,
175 | PLAGIN_NAME,
176 | "Filter/Effect/Video",
177 | "Desaturate",
178 | "Mikhail Durnev ");
179 |
180 | gst_element_class_add_pad_template (element_class,
181 | gst_static_pad_template_get (&gst_video_filter_sink_template));
182 | gst_element_class_add_pad_template (element_class,
183 | gst_static_pad_template_get (&gst_video_filter_src_template));
184 | }
185 |
186 | static void
187 | gst_plugin_template_class_init (GstPlugincudadesaturateClass * klass)
188 | {
189 | GObjectClass *gobject_class;
190 | GstBaseTransformClass *btrans_class;
191 | GstVideoFilterClass *video_filter_class;
192 |
193 | gobject_class = (GObjectClass *) klass;
194 | btrans_class = (GstBaseTransformClass *) klass;
195 | video_filter_class = (GstVideoFilterClass *) klass;
196 |
197 | gobject_class->set_property = gst_plugin_template_set_property;
198 | gobject_class->get_property = gst_plugin_template_get_property;
199 | gobject_class->finalize = gst_plugin_template_finalize;
200 |
201 | g_object_class_install_property (gobject_class, PROP_SATURATION,
202 | g_param_spec_int ("saturation", "Saturation", "Saturation = ",
203 | 0, 100, 10, (GParamFlags)G_PARAM_READWRITE));
204 |
205 | btrans_class->set_caps = gst_plugin_template_set_caps;
206 | btrans_class->transform = NULL;
207 | btrans_class->transform_ip = gst_plugin_template_filter_inplace;
208 | }
209 |
210 | static void
211 | gst_plugin_template_init (GstPlugincudadesaturate * plugin_template,
212 | GstPlugincudadesaturateClass * g_class)
213 | {
214 | GST_DEBUG ("init");
215 |
216 | plugin_template->saturation = 10;
217 | }
218 |
219 | static void
220 | gst_plugin_template_set_property (GObject * object, guint prop_id,
221 | const GValue * value, GParamSpec * pspec)
222 | {
223 | GstPlugincudadesaturate *filter = GST_PLUGIN_TEMPLATE (object);
224 |
225 | GST_OBJECT_LOCK (filter);
226 | switch (prop_id) {
227 | case PROP_SATURATION:
228 | filter->saturation = g_value_get_int (value);
229 | GST_DEBUG("saturation = %d\n", filter->saturation);
230 | break;
231 | default:
232 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
233 | break;
234 | }
235 | GST_OBJECT_UNLOCK (filter);
236 | }
237 |
238 | static void
239 | gst_plugin_template_get_property (GObject * object, guint prop_id,
240 | GValue * value, GParamSpec * pspec)
241 | {
242 | GstPlugincudadesaturate *filter = GST_PLUGIN_TEMPLATE (object);
243 |
244 | GST_OBJECT_LOCK (filter);
245 | switch (prop_id) {
246 | case PROP_SATURATION:
247 | g_value_set_int (value, filter->saturation);
248 | break;
249 | default:
250 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
251 | break;
252 | }
253 | GST_OBJECT_UNLOCK (filter);
254 | }
255 |
256 | static void
257 | gst_plugin_template_finalize (GObject * object)
258 | {
259 | GstPlugincudadesaturate *filter = GST_PLUGIN_TEMPLATE (object);
260 |
261 | //G_OBJECT_CLASS (object)->finalize (object);
262 |
263 | GST_DEBUG("finalize");
264 | }
265 |
266 |
267 | static gboolean
268 | gst_plugin_template_set_caps (GstBaseTransform * bt,
269 | GstCaps * incaps, GstCaps * outcaps)
270 | {
271 | GstPlugincudadesaturate *plugin_template;
272 | GstStructure *structure = NULL;
273 | gboolean ret = FALSE;
274 |
275 | plugin_template = GST_PLUGIN_TEMPLATE (bt);
276 |
277 | structure = gst_caps_get_structure (incaps, 0);
278 |
279 | GST_OBJECT_LOCK (plugin_template);
280 | if (gst_structure_get_int (structure, "width", &plugin_template->width) &&
281 | gst_structure_get_int (structure, "height", &plugin_template->height))
282 | {
283 | /* Check width and height and modify other plugin_template members accordingly */
284 | ret = TRUE;
285 |
286 | }
287 | GST_OBJECT_UNLOCK (plugin_template);
288 |
289 | return ret;
290 | }
291 |
292 | __global__ void video_filter(cudaTextureObject_t in, uchar4* out, size_t pitch, int width, int height,
293 | float saturation)
294 | {
295 | unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
296 | unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
297 |
298 | uchar4 v = tex2D(in, x, y);
299 |
300 | int m = (v.x + v.y + v.z) / 3;
301 |
302 | v.x = (v.x - m) * saturation + m;
303 | v.y = (v.y - m) * saturation + m;
304 | v.z = (v.z - m) * saturation + m;
305 |
306 | *(uchar4*)((char*)out + (pitch * y + x * sizeof(uchar4))) = v;
307 | }
308 |
309 | static GstFlowReturn
310 | gst_plugin_template_filter_inplace (GstBaseTransform * base_transform,
311 | GstBuffer * buf)
312 | {
313 | GstPlugincudadesaturate *plugin_template = GST_PLUGIN_TEMPLATE (base_transform);
314 | GstVideoFilter *videofilter = GST_VIDEO_FILTER (base_transform);
315 |
316 | gint width = plugin_template->width;
317 | gint height = plugin_template->height;
318 |
319 | unsigned long long *in = (unsigned long long *) GST_BUFFER_DATA (buf);
320 | /*
321 | * in[0] - device pointer to the allocated memory
322 | * in[1] - pitch in bytes
323 | * in[2] - texture object
324 | * in[3] - device memory allocated for image processing
325 | * in[4] - pitch in bytes
326 | * in[5] - texture object
327 | */
328 |
329 | dim3 dimBlock(16, 16);
330 | dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x,
331 | (height + dimBlock.y - 1) / dimBlock.y);
332 |
333 | video_filter<<>>((cudaTextureObject_t)in[2], (uchar4*)in[3], (size_t)in[4], width, height,
334 | (float)(plugin_template->saturation) / 100.0);
335 |
336 | CUDA_CHECK_RETURN(cudaThreadSynchronize());
337 | CUDA_CHECK_RETURN(cudaGetLastError());
338 |
339 | // Swap buffers
340 | int i;
341 | for (i = 0; i < 3; i++)
342 | {
343 | unsigned long long x = in[i];
344 | in[i] = in[i + 3];
345 | in[i + 3] = x;
346 | }
347 |
348 | return GST_FLOW_OK;
349 | }
350 |
351 | static gboolean
352 | plugin_init (GstPlugin * plugin)
353 | {
354 | return gst_element_register (plugin, PLAGIN_NAME, GST_RANK_NONE,
355 | GST_TYPE_PLUGIN_TEMPLATE);
356 | }
357 |
358 | /* gstreamer looks for this structure to register plugins
359 | */
360 | GST_PLUGIN_DEFINE (
361 | GST_VERSION_MAJOR,
362 | GST_VERSION_MINOR,
363 | PLAGIN_NAME,
364 | PLAGIN_SHORT_DESCRIPTION,
365 | plugin_init,
366 | VERSION, "LGPL",
367 | "GStreamer",
368 | "http://gstreamer.net/"
369 | );
370 |
--------------------------------------------------------------------------------
/desaturate.cu/test:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch --gst-debug="cudadesaturate:5" videotestsrc ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudadesaturate saturation=5 ! cudagpu2host ! ximagesink
3 |
--------------------------------------------------------------------------------
/desaturate.cu/webcam:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch v4l2src ! ffmpegcolorspace ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudadesaturate saturation=30 ! cudagpu2host ! ximagesink
3 |
4 |
--------------------------------------------------------------------------------
/gpu2host.cu/.cproject.in:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
39 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
120 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
--------------------------------------------------------------------------------
/gpu2host.cu/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | gpu2host.cu
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/gpu2host.cu/install:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cp Release/libgstcudagpu2host.so /usr/lib/gstreamer-0.10/
3 |
--------------------------------------------------------------------------------
/gpu2host.cu/src/gstvideofilter.cu:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) <1999> Erik Walthinsen
4 | * Copyright (C) <2003> David Schleef
5 | * Copyright (C) <2012> Mikhail Durnev
6 | * Copyright (C) <2014> Mikhail Durnev
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a
9 | * copy of this software and associated documentation files (the "Software"),
10 | * to deal in the Software without restriction, including without limitation
11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 | * and/or sell copies of the Software, and to permit persons to whom the
13 | * Software is furnished to do so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 | * DEALINGS IN THE SOFTWARE.
25 | *
26 | * Alternatively, the contents of this file may be used under the
27 | * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
28 | * which case the following provisions apply instead of the ones
29 | * mentioned above:
30 | *
31 | * This library is free software; you can redistribute it and/or
32 | * modify it under the terms of the GNU Library General Public
33 | * License as published by the Free Software Foundation; either
34 | * version 2 of the License, or (at your option) any later version.
35 | *
36 | * This library is distributed in the hope that it will be useful,
37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 | * Library General Public License for more details.
40 | *
41 | * You should have received a copy of the GNU Library General Public
42 | * License along with this library; if not, write to the
43 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
44 | * Boston, MA 02111-1307, USA.
45 | */
46 |
47 | /**
48 | * SECTION:element-plugin
49 | *
50 | * FIXME:Describe plugin here.
51 | *
52 | *
53 | * Example launch line
54 | * |[
55 | * gst-launch -v -m videotestsrc ! plugin ! autovideosink
56 | * ]|
57 | *
58 | */
59 |
60 | #ifdef HAVE_CONFIG_H
61 | #include "../../common/config.h"
62 | #endif
63 |
64 | #include
65 | #include
66 | #include
67 | #include
68 |
69 | typedef unsigned int uint32_t;
70 |
71 | #define PLAGIN_NAME "cudagpu2host"
72 | #define PLAGIN_SHORT_DESCRIPTION "cudagpu2host Filter"
73 |
74 | GST_DEBUG_CATEGORY_STATIC (gst_plugin_template_debug);
75 | #define GST_CAT_DEFAULT gst_plugin_template_debug
76 |
77 | typedef struct _GstCudagpu2host GstCudagpu2host;
78 | typedef struct _GstCudagpu2hostClass GstCudagpu2hostClass;
79 |
80 | #define GST_TYPE_PLUGIN_TEMPLATE \
81 | (gst_plugin_template_get_type())
82 | #define GST_PLUGIN_TEMPLATE(obj) \
83 | (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLUGIN_TEMPLATE,GstCudagpu2host))
84 | #define GST_PLUGIN_TEMPLATE_CLASS(klass) \
85 | (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLUGIN_TEMPLATE,GstCudagpu2hostClass))
86 | #define GST_IS_PLUGIN_TEMPLATE(obj) \
87 | (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLUGIN_TEMPLATE))
88 | #define GST_IS_PLUGIN_TEMPLATE_CLASS(klass) \
89 | (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLUGIN_TEMPLATE))
90 |
91 | struct _GstCudagpu2host
92 | {
93 | GstVideoFilter videofilter;
94 |
95 | gint width;
96 | gint height;
97 | };
98 |
99 | struct _GstCudagpu2hostClass
100 | {
101 | GstVideoFilterClass parent_class;
102 | };
103 |
104 |
105 | enum
106 | {
107 | /* FILL ME */
108 | LAST_SIGNAL
109 | };
110 |
111 | enum
112 | {
113 | PROP_0,
114 | };
115 |
116 | #define DEBUG_INIT(bla) \
117 | GST_DEBUG_CATEGORY_INIT (gst_plugin_template_debug, PLAGIN_NAME, 0, PLAGIN_SHORT_DESCRIPTION);
118 |
119 | GST_BOILERPLATE_FULL (GstCudagpu2host, gst_plugin_template,
120 | GstVideoFilter, GST_TYPE_VIDEO_FILTER, DEBUG_INIT);
121 |
122 | static void gst_plugin_template_set_property (GObject * object,
123 | guint prop_id, const GValue * value, GParamSpec * pspec);
124 | static void gst_plugin_template_get_property (GObject * object,
125 | guint prop_id, GValue * value, GParamSpec * pspec);
126 |
127 | static gboolean gst_plugin_template_set_caps (GstBaseTransform * bt,
128 | GstCaps * incaps, GstCaps * outcaps);
129 | //static GstFlowReturn gst_plugin_template_filter (GstBaseTransform * bt,
130 | // GstBuffer * outbuf, GstBuffer * inbuf);
131 | static GstFlowReturn
132 | gst_plugin_template_filter_inplace (GstBaseTransform * base_transform,
133 | GstBuffer * buf);
134 |
135 | #define ALLOWED_CAPS_STRING \
136 | GST_VIDEO_CAPS_BGRx
137 |
138 | static GstStaticPadTemplate gst_video_filter_src_template =
139 | GST_STATIC_PAD_TEMPLATE ("src",
140 | GST_PAD_SRC,
141 | GST_PAD_ALWAYS,
142 | GST_STATIC_CAPS (ALLOWED_CAPS_STRING)
143 | );
144 |
145 | static GstStaticPadTemplate gst_video_filter_sink_template =
146 | GST_STATIC_PAD_TEMPLATE ("sink",
147 | GST_PAD_SINK,
148 | GST_PAD_ALWAYS,
149 | GST_STATIC_CAPS (ALLOWED_CAPS_STRING)
150 | );
151 |
152 | /* GObject vmethod implementations */
153 |
154 | static void
155 | gst_plugin_template_base_init (gpointer klass)
156 | {
157 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
158 | GstVideoFilterClass *videofilter_class = GST_VIDEO_FILTER_CLASS (klass);
159 | GstCaps *caps;
160 |
161 | gst_element_class_set_details_simple (element_class,
162 | PLAGIN_NAME,
163 | "Filter/Effect/Video",
164 | "Copies video frames from device memory",
165 | "Mikhail Durnev ");
166 |
167 | gst_element_class_add_pad_template (element_class,
168 | gst_static_pad_template_get (&gst_video_filter_sink_template));
169 | gst_element_class_add_pad_template (element_class,
170 | gst_static_pad_template_get (&gst_video_filter_src_template));
171 | }
172 |
173 | static void
174 | gst_plugin_template_class_init (GstCudagpu2hostClass * klass)
175 | {
176 | GObjectClass *gobject_class;
177 | GstBaseTransformClass *btrans_class;
178 | GstVideoFilterClass *video_filter_class;
179 |
180 | gobject_class = (GObjectClass *) klass;
181 | btrans_class = (GstBaseTransformClass *) klass;
182 | video_filter_class = (GstVideoFilterClass *) klass;
183 |
184 | gobject_class->set_property = gst_plugin_template_set_property;
185 | gobject_class->get_property = gst_plugin_template_get_property;
186 |
187 | btrans_class->set_caps = gst_plugin_template_set_caps;
188 | btrans_class->transform = NULL;
189 | btrans_class->transform_ip = gst_plugin_template_filter_inplace;
190 | }
191 |
192 | static void
193 | gst_plugin_template_init (GstCudagpu2host * plugin_template,
194 | GstCudagpu2hostClass * g_class)
195 | {
196 | GST_DEBUG ("init");
197 | }
198 |
199 | static void
200 | gst_plugin_template_set_property (GObject * object, guint prop_id,
201 | const GValue * value, GParamSpec * pspec)
202 | {
203 | GstCudagpu2host *filter = GST_PLUGIN_TEMPLATE (object);
204 |
205 | GST_OBJECT_LOCK (filter);
206 | switch (prop_id) {
207 | default:
208 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
209 | break;
210 | }
211 | GST_OBJECT_UNLOCK (filter);
212 | }
213 |
214 | static void
215 | gst_plugin_template_get_property (GObject * object, guint prop_id,
216 | GValue * value, GParamSpec * pspec)
217 | {
218 | GstCudagpu2host *filter = GST_PLUGIN_TEMPLATE (object);
219 |
220 | GST_OBJECT_LOCK (filter);
221 | switch (prop_id) {
222 | default:
223 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
224 | break;
225 | }
226 | GST_OBJECT_UNLOCK (filter);
227 | }
228 |
229 | static gboolean
230 | gst_plugin_template_set_caps (GstBaseTransform * bt,
231 | GstCaps * incaps, GstCaps * outcaps)
232 | {
233 | GstCudagpu2host *plugin_template;
234 | GstStructure *structure = NULL;
235 | gboolean ret = FALSE;
236 |
237 | plugin_template = GST_PLUGIN_TEMPLATE (bt);
238 |
239 | structure = gst_caps_get_structure (incaps, 0);
240 |
241 | GST_OBJECT_LOCK (plugin_template);
242 | if (gst_structure_get_int (structure, "width", &plugin_template->width) &&
243 | gst_structure_get_int (structure, "height", &plugin_template->height)) {
244 |
245 | /* Check width and height and modify other plugin_template members accordingly */
246 | ret = TRUE;
247 | }
248 | GST_OBJECT_UNLOCK (plugin_template);
249 |
250 | return ret;
251 | }
252 |
253 | static GstFlowReturn
254 | gst_plugin_template_filter_inplace (GstBaseTransform * base_transform, GstBuffer * buf)
255 | {
256 | GstCudagpu2host *plugin_template = GST_PLUGIN_TEMPLATE (base_transform);
257 | GstVideoFilter *videofilter = GST_VIDEO_FILTER (base_transform);
258 |
259 | gint width = plugin_template->width;
260 | gint height = plugin_template->height;
261 | gint stride = width * 4;
262 |
263 | unsigned long long *in = (unsigned long long *) GST_BUFFER_DATA (buf);
264 | uint32_t *out = (uint32_t *) GST_BUFFER_DATA (buf);
265 |
266 | /*
267 | * in[0] - device pointer to the allocated memory
268 | * in[1] - pitch in bytes
269 | * in[2] - texture object
270 | * in[3] - device memory allocated for image processing
271 | * in[4] - pitch in bytes
272 | * in[5] - texture object
273 | */
274 |
275 | void* dframe = (void*)in[0];
276 | size_t pitch = (size_t)in[1];
277 | cudaTextureObject_t tex = (cudaTextureObject_t)in[2];
278 | void* dbuf = (void*)in[3];
279 | //size_t pitch2 = (size_t)in[4];
280 | cudaTextureObject_t tex2 = (cudaTextureObject_t)in[5];
281 |
282 | GstFlowReturn result = GST_FLOW_OK;
283 | cudaError_t stat;
284 |
285 | /* Copy video buffer from device */
286 | if (dframe != NULL)
287 | {
288 | stat = cudaMemcpy2D((void*)out, stride, dframe, pitch, stride, height, cudaMemcpyDeviceToHost);
289 | if (stat != cudaSuccess)
290 | {
291 | result = GST_FLOW_ERROR;
292 | }
293 | }
294 | else
295 | {
296 | result = GST_FLOW_ERROR;
297 | }
298 |
299 | /* Destroy texture objects */
300 | if (tex != 0)
301 | {
302 | stat = cudaDestroyTextureObject(tex);
303 | if (stat != cudaSuccess)
304 | {
305 | result = GST_FLOW_ERROR;
306 | }
307 | }
308 |
309 | if (tex2 != 0)
310 | {
311 | stat = cudaDestroyTextureObject(tex2);
312 | if (stat != cudaSuccess)
313 | {
314 | result = GST_FLOW_ERROR;
315 | }
316 | }
317 |
318 | /* Free device memory*/
319 | stat = cudaFree(dframe);
320 | if (stat != cudaSuccess)
321 | {
322 | result = GST_FLOW_ERROR;
323 | }
324 |
325 | stat = cudaFree(dbuf);
326 | if (stat != cudaSuccess)
327 | {
328 | result = GST_FLOW_ERROR;
329 | }
330 |
331 | return result;
332 | }
333 |
334 | static gboolean
335 | plugin_init (GstPlugin * plugin)
336 | {
337 | return gst_element_register (plugin, PLAGIN_NAME, GST_RANK_NONE,
338 | GST_TYPE_PLUGIN_TEMPLATE);
339 | }
340 |
341 | /* gstreamer looks for this structure to register plugins
342 | */
343 | GST_PLUGIN_DEFINE (
344 | GST_VERSION_MAJOR,
345 | GST_VERSION_MINOR,
346 | PLAGIN_NAME,
347 | PLAGIN_SHORT_DESCRIPTION,
348 | plugin_init,
349 | VERSION, "LGPL",
350 | "GStreamer",
351 | "http://gstreamer.net/"
352 | );
353 |
--------------------------------------------------------------------------------
/gpu2host.cu/test:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch --gst-debug="cudahost2gpu:5,cudagpu2host:5" videotestsrc ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudagpu2host ! ximagesink
3 |
--------------------------------------------------------------------------------
/gradient.cu/.cproject.in:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
39 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
113 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
--------------------------------------------------------------------------------
/gradient.cu/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | gradient.cu
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/gradient.cu/install:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cp Release/libgstcudagradient.so /usr/lib/gstreamer-0.10/
3 |
--------------------------------------------------------------------------------
/gradient.cu/src/gstvideofilter.cu:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) <1999> Erik Walthinsen
4 | * Copyright (C) <2003> David Schleef
5 | * Copyright (C) <2012> Mikhail Durnev
6 | * Copyright (C) <2014> Mikhail Durnev
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a
9 | * copy of this software and associated documentation files (the "Software"),
10 | * to deal in the Software without restriction, including without limitation
11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 | * and/or sell copies of the Software, and to permit persons to whom the
13 | * Software is furnished to do so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 | * DEALINGS IN THE SOFTWARE.
25 | *
26 | * Alternatively, the contents of this file may be used under the
27 | * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
28 | * which case the following provisions apply instead of the ones
29 | * mentioned above:
30 | *
31 | * This library is free software; you can redistribute it and/or
32 | * modify it under the terms of the GNU Library General Public
33 | * License as published by the Free Software Foundation; either
34 | * version 2 of the License, or (at your option) any later version.
35 | *
36 | * This library is distributed in the hope that it will be useful,
37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 | * Library General Public License for more details.
40 | *
41 | * You should have received a copy of the GNU Library General Public
42 | * License along with this library; if not, write to the
43 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
44 | * Boston, MA 02111-1307, USA.
45 | */
46 |
47 | /**
48 | * SECTION:element-plugin
49 | *
50 | * FIXME:Describe plugin here.
51 | *
52 | *
53 | * Example launch line
54 | * |[
55 | * gst-launch -v -m videotestsrc ! plugin ! autovideosink
56 | * ]|
57 | *
58 | */
59 |
60 | #ifdef HAVE_CONFIG_H
61 | #include "../../common/config.h"
62 | #endif
63 |
64 | #include
65 | #include
66 | #include
67 | #include
68 |
69 | #define CUDA_CHECK_RETURN(value) { \
70 | cudaError_t stat = value; \
71 | if (stat != cudaSuccess) { \
72 | GST_DEBUG("Error %s at line %d in file %s\n", \
73 | cudaGetErrorString(stat), __LINE__, __FILE__); \
74 | } }
75 |
76 | typedef unsigned int uint32_t;
77 |
78 | #define PLAGIN_NAME "cudagradient"
79 | #define PLAGIN_SHORT_DESCRIPTION "CUDA gradient Filter"
80 |
81 | GST_DEBUG_CATEGORY_STATIC (gst_plugin_template_debug);
82 | #define GST_CAT_DEFAULT gst_plugin_template_debug
83 |
84 | typedef struct _GstPlugincudagradient GstPlugincudagradient;
85 | typedef struct _GstPlugincudagradientClass GstPlugincudagradientClass;
86 |
87 | #define GST_TYPE_PLUGIN_TEMPLATE \
88 | (gst_plugin_template_get_type())
89 | #define GST_PLUGIN_TEMPLATE(obj) \
90 | (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLUGIN_TEMPLATE,GstPlugincudagradient))
91 | #define GST_PLUGIN_TEMPLATE_CLASS(klass) \
92 | (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLUGIN_TEMPLATE,GstPlugincudagradientClass))
93 | #define GST_IS_PLUGIN_TEMPLATE(obj) \
94 | (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLUGIN_TEMPLATE))
95 | #define GST_IS_PLUGIN_TEMPLATE_CLASS(klass) \
96 | (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLUGIN_TEMPLATE))
97 |
98 | #define RECEPTIVE_FIELD_SIZE 8
99 | #define RECEPTIVE_FIELD_MAX_VALUE 46
100 |
101 | const int receptive_field_mask[RECEPTIVE_FIELD_SIZE * RECEPTIVE_FIELD_SIZE] =
102 | { 0, 0, 1, 1, 1, 1, 0, 0,
103 | 0, 1, 1, 2, 2, 1, 1, 0,
104 | 1, 1, 2, 3, 3, 2, 1, 1,
105 | 1, 2, 3, 4, 4, 3, 2, 1,
106 | -1, -2, -3, -4, -4, -3, -2, -1,
107 | -1, -1, -2, -3, -3, -2, -1, -1,
108 | 0, -1, -1, -2, -2, -1, -1, 0,
109 | 0, 0, -1, -1, -1, -1, 0, 0
110 | };
111 |
112 | __device__ __constant__ int c_receptive_field_mask[RECEPTIVE_FIELD_SIZE][RECEPTIVE_FIELD_SIZE];
113 |
114 | struct _GstPlugincudagradient
115 | {
116 | GstVideoFilter videofilter;
117 |
118 | gint width;
119 | gint height;
120 | };
121 |
122 | struct _GstPlugincudagradientClass
123 | {
124 | GstVideoFilterClass parent_class;
125 | };
126 |
127 |
128 | enum
129 | {
130 | /* FILL ME */
131 | LAST_SIGNAL
132 | };
133 |
134 | enum
135 | {
136 | PROP_0
137 | };
138 |
139 | /* debug category for fltering log messages
140 | */
141 | #define DEBUG_INIT(bla) \
142 | GST_DEBUG_CATEGORY_INIT (gst_plugin_template_debug, PLAGIN_NAME, 0, PLAGIN_SHORT_DESCRIPTION);
143 |
144 | GST_BOILERPLATE_FULL (GstPlugincudagradient, gst_plugin_template,
145 | GstVideoFilter, GST_TYPE_VIDEO_FILTER, DEBUG_INIT);
146 |
147 | static void gst_plugin_template_set_property (GObject * object,
148 | guint prop_id, const GValue * value, GParamSpec * pspec);
149 | static void gst_plugin_template_get_property (GObject * object,
150 | guint prop_id, GValue * value, GParamSpec * pspec);
151 | static void gst_plugin_template_finalize (GObject * object);
152 |
153 | static gboolean gst_plugin_template_set_caps (GstBaseTransform * bt,
154 | GstCaps * incaps, GstCaps * outcaps);
155 | //static GstFlowReturn gst_plugin_template_filter (GstBaseTransform * bt,
156 | // GstBuffer * outbuf, GstBuffer * inbuf);
157 | static GstFlowReturn
158 | gst_plugin_template_filter_inplace (GstBaseTransform * base_transform,
159 | GstBuffer * buf);
160 |
161 | #define ALLOWED_CAPS_STRING \
162 | GST_VIDEO_CAPS_BGRx
163 |
164 | static GstStaticPadTemplate gst_video_filter_src_template =
165 | GST_STATIC_PAD_TEMPLATE ("src",
166 | GST_PAD_SRC,
167 | GST_PAD_ALWAYS,
168 | GST_STATIC_CAPS (ALLOWED_CAPS_STRING)
169 | );
170 |
171 | static GstStaticPadTemplate gst_video_filter_sink_template =
172 | GST_STATIC_PAD_TEMPLATE ("sink",
173 | GST_PAD_SINK,
174 | GST_PAD_ALWAYS,
175 | GST_STATIC_CAPS (ALLOWED_CAPS_STRING)
176 | );
177 |
178 | /* GObject method implementations */
179 |
180 | static void
181 | gst_plugin_template_base_init (gpointer klass)
182 | {
183 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
184 | GstVideoFilterClass *videofilter_class = GST_VIDEO_FILTER_CLASS (klass);
185 | GstCaps *caps;
186 |
187 | gst_element_class_set_details_simple (element_class,
188 | PLAGIN_NAME,
189 | "Filter/Effect/Video",
190 | "gradient",
191 | "Mikhail Durnev ");
192 |
193 | gst_element_class_add_pad_template (element_class,
194 | gst_static_pad_template_get (&gst_video_filter_sink_template));
195 | gst_element_class_add_pad_template (element_class,
196 | gst_static_pad_template_get (&gst_video_filter_src_template));
197 | }
198 |
199 | static void
200 | gst_plugin_template_class_init (GstPlugincudagradientClass * klass)
201 | {
202 | GObjectClass *gobject_class;
203 | GstBaseTransformClass *btrans_class;
204 | GstVideoFilterClass *video_filter_class;
205 |
206 | gobject_class = (GObjectClass *) klass;
207 | btrans_class = (GstBaseTransformClass *) klass;
208 | video_filter_class = (GstVideoFilterClass *) klass;
209 |
210 | gobject_class->set_property = gst_plugin_template_set_property;
211 | gobject_class->get_property = gst_plugin_template_get_property;
212 | gobject_class->finalize = gst_plugin_template_finalize;
213 |
214 | btrans_class->set_caps = gst_plugin_template_set_caps;
215 | btrans_class->transform = NULL;
216 | btrans_class->transform_ip = gst_plugin_template_filter_inplace;
217 | }
218 |
219 | static void
220 | gst_plugin_template_init (GstPlugincudagradient * plugin_template,
221 | GstPlugincudagradientClass * g_class)
222 | {
223 | CUDA_CHECK_RETURN(cudaMemcpyToSymbol(c_receptive_field_mask, receptive_field_mask, RECEPTIVE_FIELD_SIZE * RECEPTIVE_FIELD_SIZE * sizeof(int)));
224 | GST_DEBUG ("init");
225 | }
226 |
227 | static void
228 | gst_plugin_template_set_property (GObject * object, guint prop_id,
229 | const GValue * value, GParamSpec * pspec)
230 | {
231 | GstPlugincudagradient *filter = GST_PLUGIN_TEMPLATE (object);
232 |
233 | GST_OBJECT_LOCK (filter);
234 | switch (prop_id) {
235 | default:
236 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
237 | break;
238 | }
239 | GST_OBJECT_UNLOCK (filter);
240 | }
241 |
242 | static void
243 | gst_plugin_template_get_property (GObject * object, guint prop_id,
244 | GValue * value, GParamSpec * pspec)
245 | {
246 | GstPlugincudagradient *filter = GST_PLUGIN_TEMPLATE (object);
247 |
248 | GST_OBJECT_LOCK (filter);
249 | switch (prop_id) {
250 | default:
251 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
252 | break;
253 | }
254 | GST_OBJECT_UNLOCK (filter);
255 | }
256 |
257 | static void
258 | gst_plugin_template_finalize (GObject * object)
259 | {
260 | GstPlugincudagradient *filter = GST_PLUGIN_TEMPLATE (object);
261 |
262 | //G_OBJECT_CLASS (object)->finalize (object);
263 |
264 | GST_DEBUG("finalize");
265 | }
266 |
267 |
268 | static gboolean
269 | gst_plugin_template_set_caps (GstBaseTransform * bt,
270 | GstCaps * incaps, GstCaps * outcaps)
271 | {
272 | GstPlugincudagradient *plugin_template;
273 | GstStructure *structure = NULL;
274 | gboolean ret = FALSE;
275 |
276 | plugin_template = GST_PLUGIN_TEMPLATE (bt);
277 |
278 | structure = gst_caps_get_structure (incaps, 0);
279 |
280 | GST_OBJECT_LOCK (plugin_template);
281 | if (gst_structure_get_int (structure, "width", &plugin_template->width) &&
282 | gst_structure_get_int (structure, "height", &plugin_template->height))
283 | {
284 | /* Check width and height and modify other plugin_template members accordingly */
285 | ret = TRUE;
286 | }
287 | GST_OBJECT_UNLOCK (plugin_template);
288 |
289 | return ret;
290 | }
291 |
292 | __global__ void video_filter(cudaTextureObject_t in, uchar4* out, size_t pitch, int width, int height)
293 | {
294 | unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
295 | unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
296 |
297 | __shared__ int s_receptive_field_mask[RECEPTIVE_FIELD_SIZE][RECEPTIVE_FIELD_SIZE];
298 | if (threadIdx.x < RECEPTIVE_FIELD_SIZE && threadIdx.y < RECEPTIVE_FIELD_SIZE)
299 | {
300 | s_receptive_field_mask[threadIdx.x][threadIdx.y] = c_receptive_field_mask[threadIdx.x][threadIdx.y];
301 | }
302 | __syncthreads();
303 |
304 | int vert = 0;
305 | int horz = 0;
306 | int i, j;
307 | for (i = 0; i < RECEPTIVE_FIELD_SIZE; i++)
308 | {
309 | for (j = 0; j < RECEPTIVE_FIELD_SIZE; j++)
310 | {
311 | uchar4 p = tex2D(in, x + j, y + i);
312 | int lum = p.x + 6 * p.y + 3 * p.z;
313 | vert += lum * s_receptive_field_mask[j][i];
314 | horz += lum * s_receptive_field_mask[i][j];
315 |
316 | }
317 | }
318 | vert = vert / (RECEPTIVE_FIELD_MAX_VALUE * 20) + 128;
319 | horz = horz / (RECEPTIVE_FIELD_MAX_VALUE * 20) + 128;
320 |
321 | uchar4 v = {128, vert, horz, 0};
322 |
323 | *(uchar4*)((char*)out + (pitch * y + x * sizeof(uchar4))) = v;
324 | }
325 |
326 | static GstFlowReturn
327 | gst_plugin_template_filter_inplace (GstBaseTransform * base_transform,
328 | GstBuffer * buf)
329 | {
330 | GstPlugincudagradient *plugin_template = GST_PLUGIN_TEMPLATE (base_transform);
331 | GstVideoFilter *videofilter = GST_VIDEO_FILTER (base_transform);
332 |
333 | gint width = plugin_template->width;
334 | gint height = plugin_template->height;
335 |
336 | unsigned long long *in = (unsigned long long *) GST_BUFFER_DATA (buf);
337 | /*
338 | * in[0] - device pointer to the allocated memory
339 | * in[1] - pitch in bytes
340 | * in[2] - texture object
341 | * in[3] - device memory allocated for image processing
342 | * in[4] - pitch in bytes
343 | * in[5] - texture object
344 | */
345 |
346 | dim3 dimBlock(16, 16);
347 | dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x,
348 | (height + dimBlock.y - 1) / dimBlock.y);
349 |
350 | video_filter<<>>((cudaTextureObject_t)in[2], (uchar4*)in[3], (size_t)in[4], width, height);
351 |
352 | CUDA_CHECK_RETURN(cudaThreadSynchronize());
353 | CUDA_CHECK_RETURN(cudaGetLastError());
354 |
355 | // Swap buffers
356 | int i;
357 | for (i = 0; i < 3; i++)
358 | {
359 | unsigned long long x = in[i];
360 | in[i] = in[i + 3];
361 | in[i + 3] = x;
362 | }
363 |
364 | return GST_FLOW_OK;
365 | }
366 |
367 | static gboolean
368 | plugin_init (GstPlugin * plugin)
369 | {
370 | return gst_element_register (plugin, PLAGIN_NAME, GST_RANK_NONE,
371 | GST_TYPE_PLUGIN_TEMPLATE);
372 | }
373 |
374 | /* gstreamer looks for this structure to register plugins
375 | */
376 | GST_PLUGIN_DEFINE (
377 | GST_VERSION_MAJOR,
378 | GST_VERSION_MINOR,
379 | PLAGIN_NAME,
380 | PLAGIN_SHORT_DESCRIPTION,
381 | plugin_init,
382 | VERSION, "LGPL",
383 | "GStreamer",
384 | "http://gstreamer.net/"
385 | );
386 |
--------------------------------------------------------------------------------
/gradient.cu/test:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #gst-launch --gst-debug="cudadesaturate:5" videotestsrc ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudagradient ! cudagpu2host ! ximagesink
3 | gst-launch filesrc location="${HOME}/Видео/свои/MVI_0732.MOV" ! decodebin2 ! ffmpegcolorspace ! cudahost2gpu ! cudagradient ! cudagpu2host ! ximagesink
4 |
--------------------------------------------------------------------------------
/gradient.cu/webcam:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch v4l2src ! ffmpegcolorspace ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudagradient ! cudagpu2host ! ximagesink
3 |
4 | #gst-launch v4l2src ! ffmpegcolorspace ! 'video/x-raw-rgb,width=640,height=480' ! videoscale ! 'video/x-raw-rgb,width=160,height=120' \
5 | # ! cudahost2gpu ! cudagradient ! cudagpu2host \
6 | # ! videoscale ! 'video/x-raw-rgb,width=640,height=480' \
7 | # ! ximagesink
8 |
9 |
--------------------------------------------------------------------------------
/host2gpu.cu/.cproject.in:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
39 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
121 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
--------------------------------------------------------------------------------
/host2gpu.cu/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | host2gpu.cu
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/host2gpu.cu/install:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cp Release/libgstcudahost2gpu.so /usr/lib/gstreamer-0.10/
3 |
--------------------------------------------------------------------------------
/host2gpu.cu/src/gstvideofilter.cu:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) <1999> Erik Walthinsen
4 | * Copyright (C) <2003> David Schleef
5 | * Copyright (C) <2012> Mikhail Durnev
6 | * Copyright (C) <2014> Mikhail Durnev
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a
9 | * copy of this software and associated documentation files (the "Software"),
10 | * to deal in the Software without restriction, including without limitation
11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 | * and/or sell copies of the Software, and to permit persons to whom the
13 | * Software is furnished to do so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 | * DEALINGS IN THE SOFTWARE.
25 | *
26 | * Alternatively, the contents of this file may be used under the
27 | * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
28 | * which case the following provisions apply instead of the ones
29 | * mentioned above:
30 | *
31 | * This library is free software; you can redistribute it and/or
32 | * modify it under the terms of the GNU Library General Public
33 | * License as published by the Free Software Foundation; either
34 | * version 2 of the License, or (at your option) any later version.
35 | *
36 | * This library is distributed in the hope that it will be useful,
37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 | * Library General Public License for more details.
40 | *
41 | * You should have received a copy of the GNU Library General Public
42 | * License along with this library; if not, write to the
43 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
44 | * Boston, MA 02111-1307, USA.
45 | */
46 |
47 | /**
48 | * SECTION:element-plugin
49 | *
50 | * FIXME:Describe plugin here.
51 | *
52 | *
53 | * Example launch line
54 | * |[
55 | * gst-launch -v -m videotestsrc ! plugin ! autovideosink
56 | * ]|
57 | *
58 | */
59 |
60 | #ifdef HAVE_CONFIG_H
61 | #include "../../common/config.h"
62 | #endif
63 |
64 | #include
65 | #include
66 | #include
67 | #include
68 |
69 | typedef unsigned int uint32_t;
70 |
71 | #define PLAGIN_NAME "cudahost2gpu"
72 | #define PLAGIN_SHORT_DESCRIPTION "cudahost2gpu Filter"
73 |
74 | GST_DEBUG_CATEGORY_STATIC (gst_plugin_template_debug);
75 | #define GST_CAT_DEFAULT gst_plugin_template_debug
76 |
77 | typedef struct _GstCudahost2gpu GstCudahost2gpu;
78 | typedef struct _GstCudahost2gpuClass GstCudahost2gpuClass;
79 |
80 | #define GST_TYPE_PLUGIN_TEMPLATE \
81 | (gst_plugin_template_get_type())
82 | #define GST_PLUGIN_TEMPLATE(obj) \
83 | (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLUGIN_TEMPLATE,GstCudahost2gpu))
84 | #define GST_PLUGIN_TEMPLATE_CLASS(klass) \
85 | (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLUGIN_TEMPLATE,GstCudahost2gpuClass))
86 | #define GST_IS_PLUGIN_TEMPLATE(obj) \
87 | (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLUGIN_TEMPLATE))
88 | #define GST_IS_PLUGIN_TEMPLATE_CLASS(klass) \
89 | (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLUGIN_TEMPLATE))
90 |
91 | struct _GstCudahost2gpu
92 | {
93 | GstVideoFilter videofilter;
94 |
95 | gint width;
96 | gint height;
97 | };
98 |
99 | struct _GstCudahost2gpuClass
100 | {
101 | GstVideoFilterClass parent_class;
102 | };
103 |
104 |
105 | enum
106 | {
107 | /* FILL ME */
108 | LAST_SIGNAL
109 | };
110 |
111 | enum
112 | {
113 | PROP_0,
114 | };
115 |
116 | /* debug category for fltering log messages
117 | */
118 | #define DEBUG_INIT(bla) \
119 | GST_DEBUG_CATEGORY_INIT (gst_plugin_template_debug, PLAGIN_NAME, 0, PLAGIN_SHORT_DESCRIPTION);
120 |
121 | GST_BOILERPLATE_FULL (GstCudahost2gpu, gst_plugin_template,
122 | GstVideoFilter, GST_TYPE_VIDEO_FILTER, DEBUG_INIT);
123 |
124 |
125 | static void gst_plugin_template_set_property (GObject * object,
126 | guint prop_id, const GValue * value, GParamSpec * pspec);
127 | static void gst_plugin_template_get_property (GObject * object,
128 | guint prop_id, GValue * value, GParamSpec * pspec);
129 |
130 | static gboolean gst_plugin_template_set_caps (GstBaseTransform * bt,
131 | GstCaps * incaps, GstCaps * outcaps);
132 | //static GstFlowReturn gst_plugin_template_filter (GstBaseTransform * bt,
133 | // GstBuffer * outbuf, GstBuffer * inbuf);
134 | static GstFlowReturn
135 | gst_plugin_template_filter_inplace (GstBaseTransform * base_transform,
136 | GstBuffer * buf);
137 |
138 | #define ALLOWED_CAPS_STRING \
139 | GST_VIDEO_CAPS_BGRx
140 |
141 | static GstStaticPadTemplate gst_video_filter_src_template =
142 | GST_STATIC_PAD_TEMPLATE ("src",
143 | GST_PAD_SRC,
144 | GST_PAD_ALWAYS,
145 | GST_STATIC_CAPS (ALLOWED_CAPS_STRING)
146 | );
147 |
148 | static GstStaticPadTemplate gst_video_filter_sink_template =
149 | GST_STATIC_PAD_TEMPLATE ("sink",
150 | GST_PAD_SINK,
151 | GST_PAD_ALWAYS,
152 | GST_STATIC_CAPS (ALLOWED_CAPS_STRING)
153 | );
154 |
155 | /* GObject vmethod implementations */
156 |
157 | static void
158 | gst_plugin_template_base_init (gpointer klass)
159 | {
160 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
161 | GstVideoFilterClass *videofilter_class = GST_VIDEO_FILTER_CLASS (klass);
162 | GstCaps *caps;
163 |
164 | gst_element_class_set_details_simple (element_class,
165 | PLAGIN_NAME,
166 | "Filter/Effect/Video",
167 | "Moves video frame to device memory",
168 | "Mikhail Durnev ");
169 |
170 | gst_element_class_add_pad_template (element_class,
171 | gst_static_pad_template_get (&gst_video_filter_sink_template));
172 | gst_element_class_add_pad_template (element_class,
173 | gst_static_pad_template_get (&gst_video_filter_src_template));
174 | }
175 |
176 | static void
177 | gst_plugin_template_class_init (GstCudahost2gpuClass * klass)
178 | {
179 | GObjectClass *gobject_class;
180 | GstBaseTransformClass *btrans_class;
181 | GstVideoFilterClass *video_filter_class;
182 |
183 | gobject_class = (GObjectClass *) klass;
184 | btrans_class = (GstBaseTransformClass *) klass;
185 | video_filter_class = (GstVideoFilterClass *) klass;
186 |
187 | gobject_class->set_property = gst_plugin_template_set_property;
188 | gobject_class->get_property = gst_plugin_template_get_property;
189 |
190 | btrans_class->set_caps = gst_plugin_template_set_caps;
191 | btrans_class->transform = NULL;
192 | btrans_class->transform_ip = gst_plugin_template_filter_inplace;
193 | }
194 |
195 | static void
196 | gst_plugin_template_init (GstCudahost2gpu * plugin_template,
197 | GstCudahost2gpuClass * g_class)
198 | {
199 | GST_DEBUG ("init");
200 | }
201 |
202 | static void
203 | gst_plugin_template_set_property (GObject * object, guint prop_id,
204 | const GValue * value, GParamSpec * pspec)
205 | {
206 | GstCudahost2gpu *filter = GST_PLUGIN_TEMPLATE (object);
207 |
208 | GST_OBJECT_LOCK (filter);
209 | switch (prop_id) {
210 | default:
211 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
212 | break;
213 | }
214 | GST_OBJECT_UNLOCK (filter);
215 | }
216 |
217 | static void
218 | gst_plugin_template_get_property (GObject * object, guint prop_id,
219 | GValue * value, GParamSpec * pspec)
220 | {
221 | GstCudahost2gpu *filter = GST_PLUGIN_TEMPLATE (object);
222 |
223 | GST_OBJECT_LOCK (filter);
224 | switch (prop_id) {
225 | default:
226 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
227 | break;
228 | }
229 | GST_OBJECT_UNLOCK (filter);
230 | }
231 |
232 | static gboolean
233 | gst_plugin_template_set_caps (GstBaseTransform * bt,
234 | GstCaps * incaps, GstCaps * outcaps)
235 | {
236 | GstCudahost2gpu *plugin_template;
237 | GstStructure *structure = NULL;
238 | gboolean ret = FALSE;
239 |
240 | plugin_template = GST_PLUGIN_TEMPLATE (bt);
241 |
242 | structure = gst_caps_get_structure (incaps, 0);
243 |
244 | GST_OBJECT_LOCK (plugin_template);
245 | if (gst_structure_get_int (structure, "width", &plugin_template->width) &&
246 | gst_structure_get_int (structure, "height", &plugin_template->height)) {
247 |
248 | /* Check width and height and modify other plugin_template members accordingly */
249 | ret = TRUE;
250 | }
251 | GST_OBJECT_UNLOCK (plugin_template);
252 |
253 | return ret;
254 | }
255 |
256 | static GstFlowReturn
257 | gst_plugin_template_filter_inplace (GstBaseTransform * base_transform,
258 | GstBuffer * buf)
259 | {
260 | GstCudahost2gpu *plugin_template = GST_PLUGIN_TEMPLATE (base_transform);
261 | GstVideoFilter *videofilter = GST_VIDEO_FILTER (base_transform);
262 |
263 | gint width = plugin_template->width;
264 | gint height = plugin_template->height;
265 | gint stride = width * 4;
266 |
267 | uint32_t *in = (uint32_t *) GST_BUFFER_DATA (buf);
268 | unsigned long long *out = (unsigned long long *) GST_BUFFER_DATA (buf);
269 |
270 | /* Allocate device memory */
271 | void *dframe = NULL;
272 | void *dbuf = NULL;
273 | size_t pitch, pitch2;
274 | cudaError_t stat = cudaMallocPitch(&dframe, &pitch, stride, height);
275 | if (stat != cudaSuccess)
276 | {
277 | return GST_FLOW_ERROR;
278 | }
279 | stat = cudaMallocPitch(&dbuf, &pitch2, stride, height);
280 | if (stat != cudaSuccess)
281 | {
282 | cudaFree(dframe);
283 | return GST_FLOW_ERROR;
284 | }
285 |
286 | /* Copy video buffer to the device */
287 | stat = cudaMemcpy2D(dframe, pitch, (const void*)in, stride, stride, height, cudaMemcpyHostToDevice);
288 | if (stat != cudaSuccess)
289 | {
290 | cudaFree(dframe);
291 | cudaFree(dbuf);
292 | return GST_FLOW_ERROR;
293 | }
294 |
295 | /* Create texture object */
296 | cudaResourceDesc resDesc;
297 | memset(&resDesc, 0, sizeof(resDesc));
298 | resDesc.resType = cudaResourceTypePitch2D;
299 | resDesc.res.pitch2D.devPtr = dframe;
300 | resDesc.res.pitch2D.desc = cudaCreateChannelDesc();
301 | resDesc.res.pitch2D.pitchInBytes = pitch;
302 | resDesc.res.pitch2D.width = stride;
303 | resDesc.res.pitch2D.height = height;
304 |
305 | cudaTextureDesc texDesc;
306 | memset(&texDesc, 0, sizeof(texDesc));
307 | texDesc.addressMode[0] = cudaAddressModeWrap;
308 | texDesc.addressMode[1] = cudaAddressModeWrap;
309 | texDesc.filterMode = cudaFilterModePoint;
310 | texDesc.readMode = cudaReadModeElementType;
311 | texDesc.normalizedCoords = 0;
312 |
313 | cudaTextureObject_t tex = 0;
314 | stat = cudaCreateTextureObject(&tex, &resDesc, &texDesc, NULL);
315 | if (stat != cudaSuccess)
316 | {
317 | GST_DEBUG("%s\n", cudaGetErrorString(stat));
318 | cudaFree(dframe);
319 | cudaFree(dbuf);
320 | return GST_FLOW_ERROR;
321 | }
322 |
323 | resDesc.res.pitch2D.devPtr = dbuf;
324 | resDesc.res.pitch2D.pitchInBytes = pitch2;
325 |
326 | cudaTextureObject_t tex2 = 0;
327 | stat = cudaCreateTextureObject(&tex2, &resDesc, &texDesc, NULL);
328 | if (stat != cudaSuccess)
329 | {
330 | GST_DEBUG("%s\n", cudaGetErrorString(stat));
331 | cudaDestroyTextureObject(tex);
332 | cudaFree(dframe);
333 | cudaFree(dbuf);
334 | return GST_FLOW_ERROR;
335 | }
336 |
337 | /*
338 | * out[0] - device pointer to the allocated memory
339 | * out[1] - pitch in bytes
340 | * out[2] - texture object
341 | * out[3] - device memory allocated for image processing
342 | * out[4] - pitch in bytes
343 | * out[5] - texture object
344 | */
345 |
346 | out[0] = (unsigned long long)dframe;
347 | out[1] = (unsigned long long)pitch;
348 | out[2] = (unsigned long long)tex;
349 | out[3] = (unsigned long long)dbuf;
350 | out[4] = (unsigned long long)pitch2;
351 | out[5] = (unsigned long long)tex2;
352 |
353 | //GST_DEBUG("0x%x %d %d 0x%x %d %d", (int)out[0], (int)out[1], (int)out[2], (int)out[3], (int)out[4], (int)out[5]);
354 |
355 | return GST_FLOW_OK;
356 | }
357 |
358 | static gboolean
359 | plugin_init (GstPlugin * plugin)
360 | {
361 | return gst_element_register (plugin, PLAGIN_NAME, GST_RANK_NONE,
362 | GST_TYPE_PLUGIN_TEMPLATE);
363 | }
364 |
365 | /* gstreamer looks for this structure to register plugins
366 | */
367 | GST_PLUGIN_DEFINE (
368 | GST_VERSION_MAJOR,
369 | GST_VERSION_MINOR,
370 | PLAGIN_NAME,
371 | PLAGIN_SHORT_DESCRIPTION,
372 | plugin_init,
373 | VERSION, "LGPL",
374 | "GStreamer",
375 | "http://gstreamer.net/"
376 | );
377 |
--------------------------------------------------------------------------------
/host2gpu.cu/test:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch --gst-debug="cudahost2gpu:5,cudagpu2host:5" videotestsrc ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudagpu2host ! ximagesink
3 |
--------------------------------------------------------------------------------
/lens.cu/.cproject.in:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
39 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
113 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
--------------------------------------------------------------------------------
/lens.cu/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | lens.cu
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/lens.cu/install:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cp Release/libgstcudalens.so /usr/lib/gstreamer-0.10/
3 |
--------------------------------------------------------------------------------
/lens.cu/test:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch --gst-debug="cudalens:5" videotestsrc num-buffers=50 ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudalens ! cudagpu2host ! ximagesink
3 |
--------------------------------------------------------------------------------
/lens.cu/webcam:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch v4l2src ! ffmpegcolorspace ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudalens ! cudagpu2host ! ximagesink
3 |
4 |
--------------------------------------------------------------------------------
/retina.cu/.cproject.in:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
39 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
113 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
--------------------------------------------------------------------------------
/retina.cu/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | retina.cu
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/retina.cu/install:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cp Release/libgstcudaretina.so /usr/lib/gstreamer-0.10/
3 |
--------------------------------------------------------------------------------
/retina.cu/src/gstvideofilter.cu:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) <1999> Erik Walthinsen
4 | * Copyright (C) <2003> David Schleef
5 | * Copyright (C) <2012> Mikhail Durnev
6 | * Copyright (C) <2014> Mikhail Durnev
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a
9 | * copy of this software and associated documentation files (the "Software"),
10 | * to deal in the Software without restriction, including without limitation
11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 | * and/or sell copies of the Software, and to permit persons to whom the
13 | * Software is furnished to do so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 | * DEALINGS IN THE SOFTWARE.
25 | *
26 | * Alternatively, the contents of this file may be used under the
27 | * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
28 | * which case the following provisions apply instead of the ones
29 | * mentioned above:
30 | *
31 | * This library is free software; you can redistribute it and/or
32 | * modify it under the terms of the GNU Library General Public
33 | * License as published by the Free Software Foundation; either
34 | * version 2 of the License, or (at your option) any later version.
35 | *
36 | * This library is distributed in the hope that it will be useful,
37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 | * Library General Public License for more details.
40 | *
41 | * You should have received a copy of the GNU Library General Public
42 | * License along with this library; if not, write to the
43 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
44 | * Boston, MA 02111-1307, USA.
45 | */
46 |
47 | /**
48 | * SECTION:element-plugin
49 | *
50 | * FIXME:Describe plugin here.
51 | *
52 | *
53 | * Example launch line
54 | * |[
55 | * gst-launch -v -m videotestsrc ! plugin ! autovideosink
56 | * ]|
57 | *
58 | */
59 |
60 | #ifdef HAVE_CONFIG_H
61 | #include "../../common/config.h"
62 | #endif
63 |
64 | #include
65 | #include
66 | #include
67 | #include
68 |
69 | #define CUDA_CHECK_RETURN(value) { \
70 | cudaError_t stat = value; \
71 | if (stat != cudaSuccess) { \
72 | GST_DEBUG("Error %s at line %d in file %s\n", \
73 | cudaGetErrorString(stat), __LINE__, __FILE__); \
74 | } }
75 |
76 | typedef unsigned int uint32_t;
77 |
78 | #define PLAGIN_NAME "cudaretina"
79 | #define PLAGIN_SHORT_DESCRIPTION "CUDA retina Filter"
80 |
81 | GST_DEBUG_CATEGORY_STATIC (gst_plugin_template_debug);
82 | #define GST_CAT_DEFAULT gst_plugin_template_debug
83 |
84 | typedef struct _GstPlugincudaretina GstPlugincudaretina;
85 | typedef struct _GstPlugincudaretinaClass GstPlugincudaretinaClass;
86 |
87 | #define GST_TYPE_PLUGIN_TEMPLATE \
88 | (gst_plugin_template_get_type())
89 | #define GST_PLUGIN_TEMPLATE(obj) \
90 | (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLUGIN_TEMPLATE,GstPlugincudaretina))
91 | #define GST_PLUGIN_TEMPLATE_CLASS(klass) \
92 | (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLUGIN_TEMPLATE,GstPlugincudaretinaClass))
93 | #define GST_IS_PLUGIN_TEMPLATE(obj) \
94 | (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLUGIN_TEMPLATE))
95 | #define GST_IS_PLUGIN_TEMPLATE_CLASS(klass) \
96 | (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLUGIN_TEMPLATE))
97 |
98 | #define RECEPTIVE_FIELD_SIZE 8
99 | #define RECEPTIVE_FIELD_MAX_VALUE 40
100 |
101 | const int receptive_field_mask[RECEPTIVE_FIELD_SIZE * RECEPTIVE_FIELD_SIZE] =
102 | { 0, 0, -1, -1, -1, -1, 0, 0,
103 | 0, -1, -1, -1, -1, -1, -1, 0,
104 | -1, -1, -1, 3, 3, -1, -1, -1,
105 | -1, -1, 3, 4, 4, 3, -1, -1,
106 | -1, -1, 3, 4, 4, 3, -1, -1,
107 | -1, -1, -1, 3, 3, -1, -1, -1,
108 | 0, -1, -1, -1, -1, -1, -1, 0,
109 | 0, 0, -1, -1, -1, -1, 0, 0
110 | };
111 |
112 | __device__ __constant__ int c_receptive_field_mask[RECEPTIVE_FIELD_SIZE][RECEPTIVE_FIELD_SIZE];
113 |
114 | struct _GstPlugincudaretina
115 | {
116 | GstVideoFilter videofilter;
117 |
118 | gint width;
119 | gint height;
120 | };
121 |
122 | struct _GstPlugincudaretinaClass
123 | {
124 | GstVideoFilterClass parent_class;
125 | };
126 |
127 |
128 | enum
129 | {
130 | /* FILL ME */
131 | LAST_SIGNAL
132 | };
133 |
134 | enum
135 | {
136 | PROP_0
137 | };
138 |
139 | /* debug category for fltering log messages
140 | */
141 | #define DEBUG_INIT(bla) \
142 | GST_DEBUG_CATEGORY_INIT (gst_plugin_template_debug, PLAGIN_NAME, 0, PLAGIN_SHORT_DESCRIPTION);
143 |
144 | GST_BOILERPLATE_FULL (GstPlugincudaretina, gst_plugin_template,
145 | GstVideoFilter, GST_TYPE_VIDEO_FILTER, DEBUG_INIT);
146 |
147 | static void gst_plugin_template_set_property (GObject * object,
148 | guint prop_id, const GValue * value, GParamSpec * pspec);
149 | static void gst_plugin_template_get_property (GObject * object,
150 | guint prop_id, GValue * value, GParamSpec * pspec);
151 | static void gst_plugin_template_finalize (GObject * object);
152 |
153 | static gboolean gst_plugin_template_set_caps (GstBaseTransform * bt,
154 | GstCaps * incaps, GstCaps * outcaps);
155 | //static GstFlowReturn gst_plugin_template_filter (GstBaseTransform * bt,
156 | // GstBuffer * outbuf, GstBuffer * inbuf);
157 | static GstFlowReturn
158 | gst_plugin_template_filter_inplace (GstBaseTransform * base_transform,
159 | GstBuffer * buf);
160 |
161 | #define ALLOWED_CAPS_STRING \
162 | GST_VIDEO_CAPS_BGRx
163 |
164 | static GstStaticPadTemplate gst_video_filter_src_template =
165 | GST_STATIC_PAD_TEMPLATE ("src",
166 | GST_PAD_SRC,
167 | GST_PAD_ALWAYS,
168 | GST_STATIC_CAPS (ALLOWED_CAPS_STRING)
169 | );
170 |
171 | static GstStaticPadTemplate gst_video_filter_sink_template =
172 | GST_STATIC_PAD_TEMPLATE ("sink",
173 | GST_PAD_SINK,
174 | GST_PAD_ALWAYS,
175 | GST_STATIC_CAPS (ALLOWED_CAPS_STRING)
176 | );
177 |
178 | /* GObject method implementations */
179 |
180 | static void
181 | gst_plugin_template_base_init (gpointer klass)
182 | {
183 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
184 | GstVideoFilterClass *videofilter_class = GST_VIDEO_FILTER_CLASS (klass);
185 | GstCaps *caps;
186 |
187 | gst_element_class_set_details_simple (element_class,
188 | PLAGIN_NAME,
189 | "Filter/Effect/Video",
190 | "Retina",
191 | "Mikhail Durnev ");
192 |
193 | gst_element_class_add_pad_template (element_class,
194 | gst_static_pad_template_get (&gst_video_filter_sink_template));
195 | gst_element_class_add_pad_template (element_class,
196 | gst_static_pad_template_get (&gst_video_filter_src_template));
197 | }
198 |
199 | static void
200 | gst_plugin_template_class_init (GstPlugincudaretinaClass * klass)
201 | {
202 | GObjectClass *gobject_class;
203 | GstBaseTransformClass *btrans_class;
204 | GstVideoFilterClass *video_filter_class;
205 |
206 | gobject_class = (GObjectClass *) klass;
207 | btrans_class = (GstBaseTransformClass *) klass;
208 | video_filter_class = (GstVideoFilterClass *) klass;
209 |
210 | gobject_class->set_property = gst_plugin_template_set_property;
211 | gobject_class->get_property = gst_plugin_template_get_property;
212 | gobject_class->finalize = gst_plugin_template_finalize;
213 |
214 | btrans_class->set_caps = gst_plugin_template_set_caps;
215 | btrans_class->transform = NULL;
216 | btrans_class->transform_ip = gst_plugin_template_filter_inplace;
217 | }
218 |
219 | static void
220 | gst_plugin_template_init (GstPlugincudaretina * plugin_template,
221 | GstPlugincudaretinaClass * g_class)
222 | {
223 | CUDA_CHECK_RETURN(cudaMemcpyToSymbol(c_receptive_field_mask, receptive_field_mask, RECEPTIVE_FIELD_SIZE * RECEPTIVE_FIELD_SIZE * sizeof(int)));
224 | GST_DEBUG ("init");
225 | }
226 |
227 | static void
228 | gst_plugin_template_set_property (GObject * object, guint prop_id,
229 | const GValue * value, GParamSpec * pspec)
230 | {
231 | GstPlugincudaretina *filter = GST_PLUGIN_TEMPLATE (object);
232 |
233 | GST_OBJECT_LOCK (filter);
234 | switch (prop_id) {
235 | default:
236 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
237 | break;
238 | }
239 | GST_OBJECT_UNLOCK (filter);
240 | }
241 |
242 | static void
243 | gst_plugin_template_get_property (GObject * object, guint prop_id,
244 | GValue * value, GParamSpec * pspec)
245 | {
246 | GstPlugincudaretina *filter = GST_PLUGIN_TEMPLATE (object);
247 |
248 | GST_OBJECT_LOCK (filter);
249 | switch (prop_id) {
250 | default:
251 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
252 | break;
253 | }
254 | GST_OBJECT_UNLOCK (filter);
255 | }
256 |
257 | static void
258 | gst_plugin_template_finalize (GObject * object)
259 | {
260 | GstPlugincudaretina *filter = GST_PLUGIN_TEMPLATE (object);
261 |
262 | //G_OBJECT_CLASS (object)->finalize (object);
263 |
264 | GST_DEBUG("finalize");
265 | }
266 |
267 |
268 | static gboolean
269 | gst_plugin_template_set_caps (GstBaseTransform * bt,
270 | GstCaps * incaps, GstCaps * outcaps)
271 | {
272 | GstPlugincudaretina *plugin_template;
273 | GstStructure *structure = NULL;
274 | gboolean ret = FALSE;
275 |
276 | plugin_template = GST_PLUGIN_TEMPLATE (bt);
277 |
278 | structure = gst_caps_get_structure (incaps, 0);
279 |
280 | GST_OBJECT_LOCK (plugin_template);
281 | if (gst_structure_get_int (structure, "width", &plugin_template->width) &&
282 | gst_structure_get_int (structure, "height", &plugin_template->height))
283 | {
284 | /* Check width and height and modify other plugin_template members accordingly */
285 | ret = TRUE;
286 | }
287 | GST_OBJECT_UNLOCK (plugin_template);
288 |
289 | return ret;
290 | }
291 |
292 | __global__ void video_filter(cudaTextureObject_t in, uchar4* out, size_t pitch, int width, int height)
293 | {
294 | unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
295 | unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
296 |
297 | __shared__ int s_receptive_field_mask[RECEPTIVE_FIELD_SIZE][RECEPTIVE_FIELD_SIZE];
298 | if (threadIdx.x < RECEPTIVE_FIELD_SIZE && threadIdx.y < RECEPTIVE_FIELD_SIZE)
299 | {
300 | s_receptive_field_mask[threadIdx.x][threadIdx.y] = c_receptive_field_mask[threadIdx.x][threadIdx.y];
301 | }
302 | __syncthreads();
303 |
304 | int lum = 0;
305 | int i, j;
306 | for (i = 0; i < RECEPTIVE_FIELD_SIZE; i++)
307 | {
308 | for (j = 0; j < RECEPTIVE_FIELD_SIZE; j++)
309 | {
310 | uchar4 p = tex2D(in, x + j, y + i);
311 | lum += (p.x + 6 * p.y + 3 * p.z) * s_receptive_field_mask[j][i];
312 |
313 | }
314 | }
315 | lum = lum / (RECEPTIVE_FIELD_MAX_VALUE * 20) + 128;
316 |
317 | uchar4 v = {0, 0, 0, 0};
318 | v.x = v.y = v.z = lum;
319 |
320 | *(uchar4*)((char*)out + (pitch * y + x * sizeof(uchar4))) = v;
321 | }
322 |
323 | static GstFlowReturn
324 | gst_plugin_template_filter_inplace (GstBaseTransform * base_transform,
325 | GstBuffer * buf)
326 | {
327 | GstPlugincudaretina *plugin_template = GST_PLUGIN_TEMPLATE (base_transform);
328 | GstVideoFilter *videofilter = GST_VIDEO_FILTER (base_transform);
329 |
330 | gint width = plugin_template->width;
331 | gint height = plugin_template->height;
332 |
333 | unsigned long long *in = (unsigned long long *) GST_BUFFER_DATA (buf);
334 | /*
335 | * in[0] - device pointer to the allocated memory
336 | * in[1] - pitch in bytes
337 | * in[2] - texture object
338 | * in[3] - device memory allocated for image processing
339 | * in[4] - pitch in bytes
340 | * in[5] - texture object
341 | */
342 |
343 | dim3 dimBlock(16, 16);
344 | dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x,
345 | (height + dimBlock.y - 1) / dimBlock.y);
346 |
347 | video_filter<<>>((cudaTextureObject_t)in[2], (uchar4*)in[3], (size_t)in[4], width, height);
348 |
349 | CUDA_CHECK_RETURN(cudaThreadSynchronize());
350 | CUDA_CHECK_RETURN(cudaGetLastError());
351 |
352 | // Swap buffers
353 | int i;
354 | for (i = 0; i < 3; i++)
355 | {
356 | unsigned long long x = in[i];
357 | in[i] = in[i + 3];
358 | in[i + 3] = x;
359 | }
360 |
361 | return GST_FLOW_OK;
362 | }
363 |
364 | static gboolean
365 | plugin_init (GstPlugin * plugin)
366 | {
367 | return gst_element_register (plugin, PLAGIN_NAME, GST_RANK_NONE,
368 | GST_TYPE_PLUGIN_TEMPLATE);
369 | }
370 |
371 | /* gstreamer looks for this structure to register plugins
372 | */
373 | GST_PLUGIN_DEFINE (
374 | GST_VERSION_MAJOR,
375 | GST_VERSION_MINOR,
376 | PLAGIN_NAME,
377 | PLAGIN_SHORT_DESCRIPTION,
378 | plugin_init,
379 | VERSION, "LGPL",
380 | "GStreamer",
381 | "http://gstreamer.net/"
382 | );
383 |
--------------------------------------------------------------------------------
/retina.cu/test:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #gst-launch --gst-debug="cudadesaturate:5" videotestsrc ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudaretina ! cudagpu2host ! ximagesink
3 | gst-launch filesrc location="${HOME}/Видео/свои/MVI_0732.MOV" ! decodebin2 ! ffmpegcolorspace ! cudahost2gpu ! cudaretina ! cudagpu2host ! ximagesink
4 |
--------------------------------------------------------------------------------
/retina.cu/webcam:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch v4l2src ! ffmpegcolorspace ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudaretina ! cudagpu2host ! ximagesink
3 |
4 | #gst-launch v4l2src ! ffmpegcolorspace ! 'video/x-raw-rgb,width=640,height=480' ! videoscale ! 'video/x-raw-rgb,width=160,height=120' \
5 | # ! cudahost2gpu ! cudaretina ! cudagpu2host \
6 | # ! videoscale ! 'video/x-raw-rgb,width=640,height=480' \
7 | # ! ximagesink
8 |
9 |
--------------------------------------------------------------------------------
/temporal.cu/.cproject.in:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
39 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
113 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
--------------------------------------------------------------------------------
/temporal.cu/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | temporal.cu
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/temporal.cu/install:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cp Release/libgstcudatemporal.so /usr/lib/gstreamer-0.10/
3 |
--------------------------------------------------------------------------------
/temporal.cu/test:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch --gst-debug="cudatemporal:5" videotestsrc num-buffers=50 ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudatemporal window=4 ! cudagpu2host ! ximagesink
3 |
--------------------------------------------------------------------------------
/temporal.cu/webcam:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | gst-launch v4l2src ! ffmpegcolorspace ! 'video/x-raw-rgb,width=640,height=480' ! cudahost2gpu ! cudatemporal window=3 ! cudagpu2host ! ximagesink
3 |
4 |
--------------------------------------------------------------------------------