Debian Codegraph @

tools/gst-element-maker

raw symbols SCIP
1 #!/bin/sh
2
3
4 prefix=gst
5 basedir=`dirname $0`
6 templatedir=$basedir/element-templates
7
8 while [ "$1" ] ; do
9 case $1 in
10 --help)
11 cat <<-EOF
12 Usage: element-maker [OPTIONS] ELEMENT_NAME BASE_CLASS
13 Create a GStreamer element that subclasses BASE_CLASS.
14 Options:
15 --help Print this information
16 --prefix PREFIX Use PREFIX instead of "gst"
17 Example: 'element-maker my_element basetransform' will create the files
18 gstmyelement.c and gstmyelement.h that implement GstMyElement, a
19 subclass of GstBaseTransform, as an element named myelement.
20 EOF
21 exit 0
22 ;;
23 --prefix)
24 shift
25 prefix=$1
26 ;;
27 -*)
28 echo Unknown option: $1
29 exit 1
30 ;;
31 *)
32 if [ "$name" = "" ]; then
33 name=$1
34 elif [ "$class" = "" ]; then
35 class=$1
36 else
37 echo Ignored: $1
38 fi
39 esac
40 shift
41 done
42
43 if [ "$name" = "" -o "$class" = "" ] ; then
44 echo "Usage: element-maker [OPTIONS] ELEMENT_NAME BASE_CLASS"
45 exit 1
46 fi
47
48 if [ ! -f "$templatedir/$class" ] ; then
49 echo "Template file for $class not found."
50 exit 1
51 fi
52
53
54 PREFIX=$(echo $prefix | sed -e 's/\(.*\)/\U\1/')
55 NAME=$(echo $name | sed -e 's/\(.*\)/\U\1/')
56 Prefix=$(echo $prefix | sed -e 's/_\(.\)/\U\1/g' -e 's/^\(.\)/\U\1/')
57 Name=$(echo $name | sed -e 's/_\(.\)/\U\1/g' -e 's/^\(.\)/\U\1/')
58 name=$(echo $name | sed -e 's/\(.*\)/\L\1/')
59
60 GST_IS_REPLACE=${PREFIX}_IS_${NAME}
61 GST_REPLACE=${PREFIX}_${NAME}
62 GST_TYPE_REPLACE=${PREFIX}_TYPE_${NAME}
63 GstReplace=${Prefix}${Name}
64 gst_replace=${prefix}_${name}
65 gstreplace=${prefix}$(echo $name | sed -e 's/_//g')
66 replace=$(echo $name | sed -e 's/_//g')
67 if [ "${prefix}" = gst ] ; then
68 prefixreplace=$replace
69 else
70 prefixreplace=$gstreplace
71 fi
72
73 if [ "$REAL_NAME" = "" ] ; then
74 REAL_NAME=FIXME
75 fi
76 if [ "$EMAIL_ADDRESS" = "" ] ; then
77 EMAIL_ADDRESS[email protected]
78 fi
79
80
81 pkg=`grep -A 10000 '^% pkg-config' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
82 GST_TYPE_BASE_REPLACE=`grep -A 10000 '^% TYPE_CLASS_NAME' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
83 GstBaseReplace=`grep -A 10000 '^% ClassName' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
84 pads=`grep -A 10000 '^% pads' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1`
85
86 generate ()
87 {
88
89 cat <<-EOF
90 /* GStreamer
91 * Copyright (C) $(date +%Y) $REAL_NAME <$EMAIL_ADDRESS>
92 *
93 * This library is free software; you can redistribute it and/or
94 * modify it under the terms of the GNU Library General Public
95 * License as published by the Free Software Foundation; either
96 * version 2 of the License, or (at your option) any later version.
97 *
98 * This library is distributed in the hope that it will be useful,
99 * but WITHOUT ANY WARRANTY; without even the implied warranty of
100 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
101 * Library General Public License for more details.
102 *
103 * You should have received a copy of the GNU Library General Public
104 * License along with this library; if not, write to the
105 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
106 * Boston, MA 02110-1335, USA.
107 */
108 EOF
109
110 cat <<-EOF
111 /**
112 * SECTION:element-$gstreplace
113 *
114 * The $replace element does FIXME stuff.
115 *
116 * <refsect2>
117 * <title>Example launch line</title>
118 * |[
119 * gst-launch-1.0 -v fakesrc ! $replace ! FIXME ! fakesink
120 * ]|
121 * FIXME Describe what the pipeline does.
122 * </refsect2>
123 */
124 EOF
125
126
127 cat <<EOF
128
129 #ifdef HAVE_CONFIG_H
130 #include "config.h"
131 #endif
132
133 #include <gst/gst.h>
134 EOF
135
136 grep -A 10000 '^% includes' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
137 grep -A 10000 '^% includes' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
138
139 cat <<EOF
140 #include "gstreplace.h"
141
142 GST_DEBUG_CATEGORY_STATIC (gst_replace_debug_category);
143 #define GST_CAT_DEFAULT gst_replace_debug_category
144
145 /* prototypes */
146
147 EOF
148
149 grep -A 10000 '^% prototypes' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
150 grep -A 10000 '^% prototypes' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
151 for each in $pads
152 do
153 grep -A 10000 '^% prototypes' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
154 done
155
156 cat <<EOF
157
158 enum
159 {
160 PROP_0
161 };
162
163 /* pad templates */
164
165 EOF
166
167 for each in $pads
168 do
169 grep -A 10000 '^% pad-template' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
170 done
171
172 cat <<EOF
173
174 /* class initialization */
175
176 G_DEFINE_TYPE_WITH_CODE (GstReplace, gst_replace, GST_TYPE_BASE_REPLACE,
177 GST_DEBUG_CATEGORY_INIT (gst_replace_debug_category, "prefixreplace", 0,
178 "debug category for replace element"));
179
180 static void
181 gst_replace_class_init (GstReplaceClass * klass)
182 {
183 EOF
184 grep -A 10000 '^% declare-class' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
185 grep -A 10000 '^% declare-class' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
186
187 cat <<EOF
188
189 /* Setting up pads and setting metadata should be moved to
190 base_class_init if you intend to subclass this class. */
191 EOF
192 for each in $pads
193 do
194 grep -A 10000 '^% base-init' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
195 done
196 cat <<EOF
197
198 gst_element_class_set_static_metadata (GST_ELEMENT_CLASS(klass),
199 "FIXME Long name", "Generic", "FIXME Description",
200 "$REAL_NAME <$EMAIL_ADDRESS>");
201
202 EOF
203
204 grep -A 10000 '^% set-methods' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
205 grep -A 10000 '^% set-methods' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
206
207 cat <<EOF
208
209 }
210
211 static void
212 gst_replace_init (GstReplace *replace)
213 {
214 EOF
215
216 for each in $pads
217 do
218 grep -A 10000 '^% instance-init' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
219 done
220
221
222 cat <<EOF
223 }
224 EOF
225
226
227 grep -A 10000 '^% methods' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
228 grep -A 10000 '^% methods' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
229 for each in $pads
230 do
231 grep -A 10000 '^% methods' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
232 done
233
234
235 cat <<EOF
236
237 static gboolean
238 plugin_init (GstPlugin * plugin)
239 {
240
241 /* FIXME Remember to set the rank if it's an element that is meant
242 to be autoplugged by decodebin. */
243 return gst_element_register (plugin, "prefixreplace", GST_RANK_NONE,
244 GST_TYPE_REPLACE);
245 }
246
247 /* FIXME: these are normally defined by the GStreamer build system.
248 If you are creating an element to be included in gst-plugins-*,
249 remove these, as they're always defined. Otherwise, edit as
250 appropriate for your external plugin package. */
251 #ifndef VERSION
252 #define VERSION "0.0.FIXME"
253 #endif
254 #ifndef PACKAGE
255 #define PACKAGE "FIXME_package"
256 #endif
257 #ifndef PACKAGE_NAME
258 #define PACKAGE_NAME "FIXME_package_name"
259 #endif
260 #ifndef GST_PACKAGE_ORIGIN
261 #define GST_PACKAGE_ORIGIN "http://FIXME.org/"
262 #endif
263
264 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
265 GST_VERSION_MINOR,
266 replace,
267 "FIXME plugin description",
268 plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)
269
270 EOF
271
272
273 }
274
275 generate_header ()
276 {
277
278 cat <<-EOF
279 /* GStreamer
280 * Copyright (C) $(date +%Y) $REAL_NAME <$EMAIL_ADDRESS>
281 *
282 * This library is free software; you can redistribute it and/or
283 * modify it under the terms of the GNU Library General Public
284 * License as published by the Free Software Foundation; either
285 * version 2 of the License, or (at your option) any later version.
286 *
287 * This library is distributed in the hope that it will be useful,
288 * but WITHOUT ANY WARRANTY; without even the implied warranty of
289 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
290 * Library General Public License for more details.
291 *
292 * You should have received a copy of the GNU Library General Public
293 * License along with this library; if not, write to the
294 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
295 * Boston, MA 02110-1301, USA.
296 */
297
298 EOF
299
300 cat <<EOF
301 #ifndef _GST_REPLACE_H_
302 #define _GST_REPLACE_H_
303
304 EOF
305
306 grep -A 10000 '^% includes' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
307 grep -A 10000 '^% includes' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
308
309 cat <<EOF
310
311 G_BEGIN_DECLS
312
313 #define GST_TYPE_REPLACE \
314 (gst_replace_get_type())
315 #define GST_REPLACE(obj) \
316 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_REPLACE,GstReplace))
317 #define GST_REPLACE_CLASS(klass) \
318 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_REPLACE,GstReplaceClass))
319 #define GST_IS_REPLACE(obj) \
320 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_REPLACE))
321 #define GST_IS_REPLACE_CLASS(obj) \
322 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_REPLACE))
323
324 typedef struct _GstReplace GstReplace;
325 typedef struct _GstReplaceClass GstReplaceClass;
326
327 struct _GstReplace
328 {
329 GstBaseReplace base_replace;
330
331 EOF
332
333 for each in $pads
334 do
335 grep -A 10000 '^% instance-members' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1
336 done
337
338 cat <<EOF
339 };
340
341 struct _GstReplaceClass
342 {
343 GstBaseReplaceClass base_replace_class;
344 };
345
346 GType gst_replace_get_type (void);
347
348 G_END_DECLS
349
350 #endif
351 EOF
352
353
354 }
355
356
357 generate | sed \
358 -e "s/GST_BASE_REPLACE/$GST_BASE_REPLACE/g" \
359 -e "s/GST_TYPE_BASE_REPLACE/$GST_TYPE_BASE_REPLACE/g" \
360 -e "s/GstBaseReplace/$GstBaseReplace/g" \
361 -e "s/GST_IS_REPLACE/$GST_IS_REPLACE/g" \
362 -e "s/GST_REPLACE/$GST_REPLACE/g" \
363 -e "s/GST_TYPE_REPLACE/$GST_TYPE_REPLACE/g" \
364 -e "s/GstReplace/$GstReplace/g" \
365 -e "s/gst_replace/$gst_replace/g" \
366 -e "s/gstreplace/$gstreplace/g" \
367 -e "s/prefixreplace/$prefixreplace/g" \
368 -e "s/replace/$replace/g" >$gstreplace.c
369
370 generate_header | sed \
371 -e "s/GST_BASE_REPLACE/$GST_BASE_REPLACE/g" \
372 -e "s/GST_TYPE_BASE_REPLACE/$GST_TYPE_BASE_REPLACE/g" \
373 -e "s/GstBaseReplace/$GstBaseReplace/g" \
374 -e "s/GST_IS_REPLACE/$GST_IS_REPLACE/g" \
375 -e "s/GST_REPLACE/$GST_REPLACE/g" \
376 -e "s/GST_TYPE_REPLACE/$GST_TYPE_REPLACE/g" \
377 -e "s/GstReplace/$GstReplace/g" \
378 -e "s/gst_replace/$gst_replace/g" \
379 -e "s/gstreplace/$gstreplace/g" \
380 -e "s/prefixreplace/$prefixreplace/g" \
381 -e "s/replace/$replace/g" >$gstreplace.h
382
383 gst-indent-1.0 $gstreplace.c
384
385 echo pkg is $pkg
386
387 gcc -Wall -Werror -fPIC $CPPFLAGS $(pkg-config --cflags gstreamer-1.0 $pkg) -c -o $gstreplace.o $gstreplace.c
388 if test $? -ne 0; then
389 exit 1
390 fi
391
392 gcc -shared -o $gstreplace.so $gstreplace.o $(pkg-config --libs gstreamer-1.0 $pkg)
393 if test $? -ne 0; then
394 exit 1
395 fi
396
397 gst-inspect-1.0 ./$gstreplace.so