1#!/bin/sh 2 3 4prefix=gst 5basedir=`dirname $0` 6templatedir=$basedir/element-templates 7 8while [ "$1" ] ; do 9 case $1 in 10 --help) 11 cat <<-EOF 12Usage: element-maker [OPTIONS] ELEMENT_NAME BASE_CLASS 13Create a GStreamer element that subclasses BASE_CLASS. 14Options: 15 --help Print this information 16 --prefix PREFIX Use PREFIX instead of "gst" 17Example: '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. 20EOF 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 41done 42 43if [ "$name" = "" -o "$class" = "" ] ; then 44 echo "Usage: element-maker [OPTIONS] ELEMENT_NAME BASE_CLASS" 45 exit 1 46fi 47 48if [ ! -f "$templatedir/$class" ] ; then 49 echo "Template file for $class not found." 50 exit 1 51fi 52 53 54PREFIX=$(echo $prefix | sed -e 's/\(.*\)/\U\1/') 55NAME=$(echo $name | sed -e 's/\(.*\)/\U\1/') 56Prefix=$(echo $prefix | sed -e 's/_\(.\)/\U\1/g' -e 's/^\(.\)/\U\1/') 57Name=$(echo $name | sed -e 's/_\(.\)/\U\1/g' -e 's/^\(.\)/\U\1/') 58name=$(echo $name | sed -e 's/\(.*\)/\L\1/') 59 60GST_IS_REPLACE=${PREFIX}_IS_${NAME} 61GST_REPLACE=${PREFIX}_${NAME} 62GST_TYPE_REPLACE=${PREFIX}_TYPE_${NAME} 63GstReplace=${Prefix}${Name} 64gst_replace=${prefix}_${name} 65gstreplace=${prefix}$(echo $name | sed -e 's/_//g') 66replace=$(echo $name | sed -e 's/_//g') 67if [ "${prefix}" = gst ] ; then 68 prefixreplace=$replace 69else 70 prefixreplace=$gstreplace 71fi 72 73if [ "$REAL_NAME" = "" ] ; then 74 REAL_NAME=FIXME 75fi 76if [ "$EMAIL_ADDRESS" = "" ] ; then 77 EMAIL_ADDRESS=fixme@example.com 78fi 79 80 81pkg=`grep -A 10000 '^% pkg-config' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1` 82GST_TYPE_BASE_REPLACE=`grep -A 10000 '^% TYPE_CLASS_NAME' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1` 83GstBaseReplace=`grep -A 10000 '^% ClassName' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1` 84pads=`grep -A 10000 '^% pads' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1` 85 86generate () 87{ 88 89cat <<-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 */ 108EOF 109 110cat <<-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 */ 124EOF 125 126 127cat <<EOF 128 129#ifdef HAVE_CONFIG_H 130#include "config.h" 131#endif 132 133#include <gst/gst.h> 134EOF 135 136grep -A 10000 '^% includes' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 137grep -A 10000 '^% includes' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 138 139cat <<EOF 140#include "gstreplace.h" 141 142GST_DEBUG_CATEGORY_STATIC (gst_replace_debug_category); 143#define GST_CAT_DEFAULT gst_replace_debug_category 144 145/* prototypes */ 146 147EOF 148 149grep -A 10000 '^% prototypes' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 150grep -A 10000 '^% prototypes' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 151for each in $pads 152do 153 grep -A 10000 '^% prototypes' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 154done 155 156cat <<EOF 157 158enum 159{ 160 PROP_0 161}; 162 163/* pad templates */ 164 165EOF 166 167for each in $pads 168do 169 grep -A 10000 '^% pad-template' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 170done 171 172cat <<EOF 173 174/* class initialization */ 175 176G_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 180static void 181gst_replace_class_init (GstReplaceClass * klass) 182{ 183EOF 184grep -A 10000 '^% declare-class' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 185grep -A 10000 '^% declare-class' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 186 187cat <<EOF 188 189 /* Setting up pads and setting metadata should be moved to 190 base_class_init if you intend to subclass this class. */ 191EOF 192for each in $pads 193do 194 grep -A 10000 '^% base-init' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 195done 196cat <<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 202EOF 203 204grep -A 10000 '^% set-methods' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 205grep -A 10000 '^% set-methods' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 206 207cat <<EOF 208 209} 210 211static void 212gst_replace_init (GstReplace *replace) 213{ 214EOF 215 216for each in $pads 217do 218 grep -A 10000 '^% instance-init' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 219done 220 221 222cat <<EOF 223} 224EOF 225 226 227grep -A 10000 '^% methods' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 228grep -A 10000 '^% methods' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 229for each in $pads 230do 231 grep -A 10000 '^% methods' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 232done 233 234 235cat <<EOF 236 237static gboolean 238plugin_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 264GST_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 270EOF 271 272 273} 274 275generate_header () 276{ 277 278cat <<-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 298EOF 299 300cat <<EOF 301#ifndef _GST_REPLACE_H_ 302#define _GST_REPLACE_H_ 303 304EOF 305 306grep -A 10000 '^% includes' $templatedir/gobject | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 307grep -A 10000 '^% includes' $templatedir/$class | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 308 309cat <<EOF 310 311G_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 324typedef struct _GstReplace GstReplace; 325typedef struct _GstReplaceClass GstReplaceClass; 326 327struct _GstReplace 328{ 329 GstBaseReplace base_replace; 330 331EOF 332 333for each in $pads 334do 335 grep -A 10000 '^% instance-members' $templatedir/$each | tail -n +2|grep -m 1 -B 10000 '^%'|head -n -1 336done 337 338cat <<EOF 339}; 340 341struct _GstReplaceClass 342{ 343 GstBaseReplaceClass base_replace_class; 344}; 345 346GType gst_replace_get_type (void); 347 348G_END_DECLS 349 350#endif 351EOF 352 353 354} 355 356 357generate | 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 370generate_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 383gst-indent $gstreplace.c 384 385echo pkg is $pkg 386 387gcc -Wall -Werror -fPIC $CPPFLAGS $(pkg-config --cflags gstreamer-1.0 $pkg) -c -o $gstreplace.o $gstreplace.c 388if test $? -ne 0; then 389 exit 1 390fi 391 392gcc -shared -o $gstreplace.so $gstreplace.o $(pkg-config --libs gstreamer-1.0 $pkg) 393if test $? -ne 0; then 394 exit 1 395fi 396 397gst-inspect-1.0 ./$gstreplace.so 398