[Gstreamer-openmax] [PATCH 2/2] template caps from config file

Rob Clark rob at ti.com
Wed Nov 3 18:58:48 PDT 2010


---
 omx/gstomx.c               |   30 +++++++++++++++
 omx/gstomx.conf.in         |   89 ++++++++++++++++++++++++++++++++++++++++++++
 omx/gstomx.h               |    1 +
 omx/gstomx_aacdec.c        |   77 +++-----------------------------------
 omx/gstomx_aacenc.c        |   78 +++-----------------------------------
 omx/gstomx_adpcmdec.c      |   49 +++---------------------
 omx/gstomx_adpcmenc.c      |   49 +++---------------------
 omx/gstomx_amrnbdec.c      |   48 +++---------------------
 omx/gstomx_amrnbenc.c      |   48 +++---------------------
 omx/gstomx_amrwbdec.c      |   48 +++---------------------
 omx/gstomx_amrwbenc.c      |   48 +++---------------------
 omx/gstomx_audiosink.c     |   27 +------------
 omx/gstomx_base_videodec.c |   54 --------------------------
 omx/gstomx_base_videoenc.c |   54 --------------------------
 omx/gstomx_filereadersrc.c |   21 +---------
 omx/gstomx_g711dec.c       |   58 +++-------------------------
 omx/gstomx_g711enc.c       |   58 +++-------------------------
 omx/gstomx_g729dec.c       |   53 +++-----------------------
 omx/gstomx_g729enc.c       |   55 +++-----------------------
 omx/gstomx_h263dec.c       |   32 +++-------------
 omx/gstomx_h263enc.c       |   27 +++----------
 omx/gstomx_h264dec.c       |   31 +++------------
 omx/gstomx_h264enc.c       |   26 +++----------
 omx/gstomx_ilbcdec.c       |   73 +++---------------------------------
 omx/gstomx_ilbcenc.c       |   73 +++---------------------------------
 omx/gstomx_jpegenc.c       |   71 +++--------------------------------
 omx/gstomx_mp2dec.c        |   53 +++-----------------------
 omx/gstomx_mp3dec.c        |   53 +++-----------------------
 omx/gstomx_mpeg4dec.c      |   55 +++------------------------
 omx/gstomx_mpeg4enc.c      |   28 +++-----------
 omx/gstomx_videosink.c     |   53 +------------------------
 omx/gstomx_volume.c        |   54 +++-----------------------
 omx/gstomx_vorbisdec.c     |   47 +++--------------------
 omx/gstomx_wmvdec.c        |   31 +++------------
 34 files changed, 286 insertions(+), 1366 deletions(-)

diff --git a/omx/gstomx.c b/omx/gstomx.c
index 8b375c0..c444de5 100644
--- a/omx/gstomx.c
+++ b/omx/gstomx.c
@@ -327,6 +327,36 @@ gstomx_core_new (void *object, GType type)
   return core;
 }
 
+GstCaps *
+gstomx_template_caps (GType type, const gchar * pad_name)
+{
+  const gchar *element_name;
+  GstStructure *element;
+  const gchar *caps_str;
+
+  element_name = g_type_get_qdata (type, element_name_quark);
+  element = get_element_entry (element_name);
+
+
+  /* this shouldn't really happen.. */
+  if (!element)
+    return GST_CAPS_ANY;
+
+  caps_str = gst_structure_get_string (element, pad_name);
+
+  GST_DEBUG ("%s: %s", element_name, caps_str);
+
+  /* default to ANY.. at least for now.. maybe when everything is converted
+   * over, we should treat missing caps as a more serious condition?
+   */
+  if (!caps_str) {
+    g_warning ("%s is missing required field: %s", element_name, pad_name);
+    return GST_CAPS_ANY;
+  }
+
+  return gst_caps_from_string (caps_str);
+}
+
 void
 gstomx_install_property_helper (GObjectClass * gobject_class)
 {
diff --git a/omx/gstomx.conf.in b/omx/gstomx.conf.in
index c22c6d6..2a7f5bd 100644
--- a/omx/gstomx.conf.in
+++ b/omx/gstomx.conf.in
@@ -20,58 +20,108 @@ omx_dummy_2,
   component-name=OMX.st.dummy2,
   rank=256;
 
+/* standard width/height/framerate that applies to video decoders and encoders
+ * on both src and sink pad:
+ */
+#define VIDEO_SIZE_RATE \
+	"width=(int)[16,4096], " \
+	"height=(int)[16,4096], " \
+	"framerate=(fraction)[0,max]"
+
+/* standard raw video caps that applies to all video decoder src pads and
+ * video encoder sink pads:
+ */
+#define RAW_VIDEO_CAPS \
+	"video/x-raw-yuv, " \
+	VIDEO_SIZE_RATE ", " \
+	"format=(fourcc){I420, YUY2, UYVY, NV12}; "
+
+
+/* standard raw audio caps that applies to all audio decoder src pads and
+ * audio encoder sink pads:
+ */
+#define RAW_AUDIO_CAPS(rate,channels) \
+	"audio/x-raw-int, " \
+	"endianess=(int)1234, " \
+	"width=(int)16, " \
+	"depth=(int)16, " \
+	"rate=(int)" rate ", " \
+	"signed=(boolean)true, " \
+	"channels=(int)" channels ";"
+
 omx_mpeg4dec,
   type=GstOmxMpeg4Dec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.video_decoder.mpeg4,
+  sink="video/mpeg, mpegversion=(int)4, systemstream=false, " VIDEO_SIZE_RATE ";" \
+      "video/x-divx, divxversion=(int)[4,5], " VIDEO_SIZE_RATE ";" \
+      "video/x-xvid, " VIDEO_SIZE_RATE ";" \
+      "video/x-3ivx, " VIDEO_SIZE_RATE ";",
+  src=RAW_VIDEO_CAPS,
   rank=256;
 
 omx_h264dec,
   type=GstOmxH264Dec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.video_decoder.avc,
+  sink="video/x-h264, " VIDEO_SIZE_RATE ";",
+  src=RAW_VIDEO_CAPS,
   rank=256;
 
 omx_h263dec,
   type=GstOmxH263Dec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.video_decoder.h263,
+  sink="video/x-h263, variant=(string)itu, " VIDEO_SIZE_RATE ";",
+  src=RAW_VIDEO_CAPS,
   rank=256;
 
 omx_wmvdec,
   type=GstOmxWmvDec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.video_decoder.wmv,
+  sink="video/x-wmv, " VIDEO_SIZE_RATE ";",
+  src=RAW_VIDEO_CAPS,
   rank=256;
 
 omx_mpeg4enc,
   type=GstOmxMpeg4Enc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.video_encoder.mpeg4,
+  sink=RAW_VIDEO_CAPS,
+  src="video/mpeg, mpegversion=(int)4, systemstream=false, " VIDEO_SIZE_RATE ";",
   rank=256;
 
 omx_h264enc,
   type=GstOmxH264Enc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.video_encoder.avc,
+  sink=RAW_VIDEO_CAPS,
+  src="video/x-h264, " VIDEO_SIZE_RATE ";",
   rank=256;
 
 omx_h263enc,
   type=GstOmxH263Enc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.video_encoder.h263,
+  sink=RAW_VIDEO_CAPS,
+  src="video/x-h263, variant=(string)itu, " VIDEO_SIZE_RATE ";",
   rank=256;
 
 omx_vorbisdec,
   type=GstOmxVorbisDec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_decoder.ogg.single,
+  sink="application/ogg;",
+  src=RAW_AUDIO_CAPS("[8000, 96000]", "[1, 256]"),
   rank=128;
 
 omx_mp3dec,
   type=GstOmxMp3Dec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_decoder.mp3.mad,
+  sink="audio/mpeg, mpegversion=(int)1, layer=(int)3, rate=(int)[8000, 48000], channels=(int)[1, 8], parsed=true;",
+  src=RAW_AUDIO_CAPS("[8000, 96000]", "[1, 2]"),
   rank=256;
 
 #ifdef EXPERIMENTAL
@@ -80,96 +130,130 @@ omx_mp2dec,
   type=GstOmxMp2Dec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_decoder.mp3.mad,
+  sink="audio/mpeg, mpegversion=(int)1, layer=(int)2, rate=(int)[8000, 96000], channels=(int)[1, 2], parsed=true;",
+  src=RAW_AUDIO_CAPS("[8000, 96000]", "[1, 2]"),
   rank=256;
 
 omx_amrnbdec,
   type=GstOmxAmrNbDec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_decoder.amrnb,
+  sink="audio/AMR, rate=(int)8000, channels=(int)1;",
+  src=RAW_AUDIO_CAPS("8000", "1"),
   rank=256;
 
 omx_amrnbenc,
   type=GstOmxAmrNbEnc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_encoder.amrnb,
+  sink=RAW_AUDIO_CAPS("8000", "1"),
+  src="audio/AMR, rate=(int)8000, channels=(int)1;",
   rank=256;
 
 omx_amrwbdec,
   type=GstOmxAmrWbDec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_decoder.amrwb,
+  sink="audio/AMR-WB, rate=(int)16000, channels=(int)1;",
+  src=RAW_AUDIO_CAPS("16000", "1"),
   rank=256;
 
 omx_amrwbenc,
   type=GstOmxAmrWbEnc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_encoder.amrwb,
+  sink=RAW_AUDIO_CAPS("16000", "1"),
+  src="audio/AMR-WB, rate=(int)16000, channels=(int)1;",
   rank=256;
 
 omx_aacdec,
   type=GstOmxAacDec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_decoder.aac,
+  sink="audio/mpeg, mpegversion=(int){2,4}, rate=(int)[8000, 96000], channels=(int)[1, 6];",
+  src=RAW_AUDIO_CAPS("[8000, 96000]", "[1, 6]"),
   rank=256;
 
 omx_aacenc,
   type=GstOmxAacEnc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_encoder.aac,
+  sink=RAW_AUDIO_CAPS("[8000, 96000]", "[1, 6]"),
+  src="audio/mpeg, mpegversion=(int){2,4}, rate=(int)[8000, 96000], channels=(int)[1, 6];",
   rank=256;
 
 omx_adpcmdec,
   type=GstOmxAdpcmDec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_decoder.adpcm,
+  sink="audio/x-adpcm, layout=dvi, rate=(int)[8000, 96000], channels=(int)1;",
+  src=RAW_AUDIO_CAPS("[8000, 96000]", "1"),
   rank=256;
 
 omx_adpcmenc,
   type=GstOmxAdpcmEnc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_encoder.adpcm,
+  sink=RAW_AUDIO_CAPS("[8000, 96000]", "1"),
+  src="audio/x-adpcm, layout=dvi, rate=(int)[8000, 96000], channels=(int)1;",
   rank=256;
 
 omx_g711dec,
   type=GstOmxG711Dec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_decoder.g711,
+  sink="audio/x-alaw, rate=(int)8000, channels=(int)1;" \
+      "audio/x-mulaw, rate=(int)8000, channels=(int)1;",
+  src=RAW_AUDIO_CAPS("8000", "1"),
   rank=256;
 
 omx_g711enc,
   type=GstOmxG711Enc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_encoder.g711,
+  sink=RAW_AUDIO_CAPS("8000", "1"),
+  src="audio/x-alaw, rate=(int)8000, channels=(int)1;" \
+      "audio/x-mulaw, rate=(int)8000, channels=(int)1;",
   rank=256;
 
 omx_g729dec,
   type=GstOmxG729Dec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_decoder.g729,
+  sink="audio/G729, rate=(int)8000, channels=(int)1;",
+  src=RAW_AUDIO_CAPS("8000", "1"),
   rank=256;
 
 omx_g729enc,
   type=GstOmxG729Enc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_encoder.g729,
+  sink=RAW_AUDIO_CAPS("8000", "1"),
+  src="audio/G729, rate=(int)8000, channels=(int)1;",
   rank=256;
 
 omx_ilbcdec,
   type=GstOmxIlbcDec,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_decoder.ilbc,
+  sink="audio/x-iLBC, mode=(int){20, 30};",
+  src=RAW_AUDIO_CAPS("8000", "1"),
   rank=256;
 
 omx_ilbcenc,
   type=GstOmxIlbcEnc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_encoder.ilbc,
+  sink=RAW_AUDIO_CAPS("8000", "1"),
+  src="audio/x-iLBC, mode=(int){20, 30};",
   rank=256;
 
 omx_jpegenc,
   type=GstOmxJpegEnc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.image_encoder.jpeg,
+  sink=RAW_VIDEO_CAPS,
+  src="image/jpeg, " VIDEO_SIZE_RATE ";",
   rank=256;
 
 #endif /* EXPERIMENTAL */
@@ -178,6 +262,7 @@ omx_audiosink,
   type=GstOmxAudioSink,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.alsa.alsasink,
+  sink=RAW_AUDIO_CAPS("[8000, 48000]", "[1, 8]"),
   rank=0;
 
 #ifdef EXPERIMENTAL
@@ -186,12 +271,14 @@ omx_videosink,
   type=GstOmxVideoSink,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.videosink,
+  sink=RAW_VIDEO_CAPS,
   rank=0;
 
 omx_filereadersrc,
   type=GstOmxFilereaderSrc,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.audio_filereader,
+  src="ANY",
   rank=0;
 
 #endif /* EXPERIMENTAL */
@@ -200,4 +287,6 @@ omx_volume,
   type=GstOmxVolume,
   library-name=libomxil-bellagio.so.0,
   component-name=OMX.st.volume.component,
+  sink=RAW_AUDIO_CAPS("[8000, 48000]", "[1, 8]"),
+  src=RAW_AUDIO_CAPS("[8000, 48000]", "[1, 8]"),
   rank=0;
diff --git a/omx/gstomx.h b/omx/gstomx.h
index f638a8c..7076870 100644
--- a/omx/gstomx.h
+++ b/omx/gstomx.h
@@ -43,6 +43,7 @@ enum
 gboolean gstomx_get_component_info (void *core, GType type);
 
 void *gstomx_core_new (void *object, GType type);
+GstCaps *gstomx_template_caps (GType type, const gchar * pad_name);
 void gstomx_install_property_helper (GObjectClass * gobject_class);
 gboolean gstomx_get_property_helper (void *core, guint prop_id, GValue * value);
 
diff --git a/omx/gstomx_aacdec.c b/omx/gstomx_aacdec.c
index ec06de3..70ba3c7 100644
--- a/omx/gstomx_aacdec.c
+++ b/omx/gstomx_aacdec.c
@@ -25,61 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxAacDec, gst_omx_aacdec, GstOmxBaseAudioDec,
     GST_OMX_BASE_AUDIODEC_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000,
-      "signed", G_TYPE_BOOLEAN, TRUE,
-      "channels", GST_TYPE_INT_RANGE, 1, 6, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("audio/mpeg",
-      "mpegversion", G_TYPE_INT, 4,
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000,
-      "channels", GST_TYPE_INT_RANGE, 1, 6, NULL);
-
-  {
-    GValue list;
-    GValue val;
-
-    list.g_type = val.g_type = 0;
-
-    g_value_init (&list, GST_TYPE_LIST);
-    g_value_init (&val, G_TYPE_INT);
-
-    g_value_set_int (&val, 2);
-    gst_value_list_append_value (&list, &val);
-
-    g_value_set_int (&val, 4);
-    gst_value_list_append_value (&list, &val);
-
-    gst_structure_set_value (struc, "mpegversion", &list);
-
-    g_value_unset (&val);
-    g_value_unset (&list);
-  }
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -92,23 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Audio",
       "Decodes audio in AAC format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_aacenc.c b/omx/gstomx_aacenc.c
index da741a7..c3118a0 100644
--- a/omx/gstomx_aacenc.c
+++ b/omx/gstomx_aacenc.c
@@ -99,62 +99,6 @@ gst_omx_aacenc_output_format_get_type (void)
   return gst_omx_aacenc_output_format_type;
 }
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("audio/mpeg",
-      "mpegversion", G_TYPE_INT, 4,
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000,
-      "channels", GST_TYPE_INT_RANGE, 1, 6, NULL);
-
-  {
-    GValue list;
-    GValue val;
-
-    list.g_type = val.g_type = 0;
-
-    g_value_init (&list, GST_TYPE_LIST);
-    g_value_init (&val, G_TYPE_INT);
-
-    g_value_set_int (&val, 2);
-    gst_value_list_append_value (&list, &val);
-
-    g_value_set_int (&val, 4);
-    gst_value_list_append_value (&list, &val);
-
-    gst_structure_set_value (struc, "mpegversion", &list);
-
-    g_value_unset (&val);
-    g_value_unset (&list);
-  }
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000,
-      "signed", G_TYPE_BOOLEAN, TRUE,
-      "channels", GST_TYPE_INT_RANGE, 1, 6, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -167,23 +111,13 @@ type_base_init (gpointer g_class)
       "Codec/Encoder/Audio",
       "Encodes audio in AAC format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
-
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_adpcmdec.c b/omx/gstomx_adpcmdec.c
index 6b39881..f97717a 100644
--- a/omx/gstomx_adpcmdec.c
+++ b/omx/gstomx_adpcmdec.c
@@ -27,33 +27,6 @@
 GSTOMX_BOILERPLATE (GstOmxAdpcmDec, gst_omx_adpcmdec, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-adpcm",
-      "layout", G_TYPE_STRING, "dvi",
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -66,23 +39,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Audio",
       "Decodes audio in ADPCM format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_adpcmenc.c b/omx/gstomx_adpcmenc.c
index 55d6c93..3085f7a 100644
--- a/omx/gstomx_adpcmenc.c
+++ b/omx/gstomx_adpcmenc.c
@@ -26,33 +26,6 @@
 GSTOMX_BOILERPLATE (GstOmxAdpcmEnc, gst_omx_adpcmenc, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-adpcm",
-      "layout", G_TYPE_STRING, "dvi",
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -65,23 +38,13 @@ type_base_init (gpointer g_class)
       "Codec/Encoder/Audio",
       "Encodes audio in ADPCM format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_amrnbdec.c b/omx/gstomx_amrnbdec.c
index 99fa45a..c38da05 100644
--- a/omx/gstomx_amrnbdec.c
+++ b/omx/gstomx_amrnbdec.c
@@ -25,32 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxAmrNbDec, gst_omx_amrnbdec, GstOmxBaseAudioDec,
     GST_OMX_BASE_AUDIODEC_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", G_TYPE_INT, 8000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/AMR",
-      "rate", G_TYPE_INT, 8000, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -63,23 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Audio",
       "Decodes audio in AMR-NB format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
-
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_amrnbenc.c b/omx/gstomx_amrnbenc.c
index 491165d..80c8cd0 100644
--- a/omx/gstomx_amrnbenc.c
+++ b/omx/gstomx_amrnbenc.c
@@ -34,32 +34,6 @@ enum
 GSTOMX_BOILERPLATE (GstOmxAmrNbEnc, gst_omx_amrnbenc, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/AMR",
-      "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", G_TYPE_INT, 8000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -72,23 +46,13 @@ type_base_init (gpointer g_class)
       "Codec/Encoder/Audio",
       "Encodes audio in AMR-NB format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_amrwbdec.c b/omx/gstomx_amrwbdec.c
index e94827d..222ea23 100644
--- a/omx/gstomx_amrwbdec.c
+++ b/omx/gstomx_amrwbdec.c
@@ -25,32 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxAmrWbDec, gst_omx_amrwbdec, GstOmxBaseAudioDec,
     GST_OMX_BASE_AUDIODEC_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", G_TYPE_INT, 16000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/AMR-WB",
-      "rate", G_TYPE_INT, 16000, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -63,23 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Audio",
       "Decodes audio in AMR-WB format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
-
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_amrwbenc.c b/omx/gstomx_amrwbenc.c
index 2aad99f..fd5ca61 100644
--- a/omx/gstomx_amrwbenc.c
+++ b/omx/gstomx_amrwbenc.c
@@ -34,32 +34,6 @@ enum
 GSTOMX_BOILERPLATE (GstOmxAmrWbEnc, gst_omx_amrwbenc, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/AMR-WB",
-      "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 16000, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", G_TYPE_INT, 16000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -72,23 +46,13 @@ type_base_init (gpointer g_class)
       "Codec/Encoder/Audio",
       "Encodes audio in AMR-WB format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_audiosink.c b/omx/gstomx_audiosink.c
index bc6d6ef..5bee433 100644
--- a/omx/gstomx_audiosink.c
+++ b/omx/gstomx_audiosink.c
@@ -25,22 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxAudioSink, gst_omx_audiosink, GstOmxBaseSink,
     GST_OMX_BASE_SINK_TYPE);
 
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", GST_TYPE_INT_RANGE, 8, 32,
-      "depth", GST_TYPE_INT_RANGE, 8, 32,
-      "rate", GST_TYPE_INT_RANGE, 8000, 48000,
-      "signed", G_TYPE_BOOLEAN, TRUE,
-      "channels", GST_TYPE_INT_RANGE, 1, 8, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -52,14 +36,9 @@ type_base_init (gpointer g_class)
       "OpenMAX IL audiosink element",
       "Sink/Audio", "Renders audio", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 }
 
 static gboolean
diff --git a/omx/gstomx_base_videodec.c b/omx/gstomx_base_videodec.c
index de36899..9148dec 100644
--- a/omx/gstomx_base_videodec.c
+++ b/omx/gstomx_base_videodec.c
@@ -25,63 +25,9 @@
 GSTOMX_BOILERPLATE (GstOmxBaseVideoDec, gst_omx_base_videodec, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("video/x-raw-yuv",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  {
-    GValue list;
-    GValue val;
-
-    list.g_type = val.g_type = 0;
-
-    g_value_init (&list, GST_TYPE_LIST);
-    g_value_init (&val, GST_TYPE_FOURCC);
-
-    gst_value_set_fourcc (&val, GST_MAKE_FOURCC ('I', '4', '2', '0'));
-    gst_value_list_append_value (&list, &val);
-
-    gst_value_set_fourcc (&val, GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'));
-    gst_value_list_append_value (&list, &val);
-
-    gst_value_set_fourcc (&val, GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'));
-    gst_value_list_append_value (&list, &val);
-
-    gst_structure_set_value (struc, "format", &list);
-
-    g_value_unset (&val);
-    g_value_unset (&list);
-  }
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
-  GstElementClass *element_class;
-
-  element_class = GST_ELEMENT_CLASS (g_class);
-
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
 }
 
 static void
diff --git a/omx/gstomx_base_videoenc.c b/omx/gstomx_base_videoenc.c
index 87a4f1b..0599a25 100644
--- a/omx/gstomx_base_videoenc.c
+++ b/omx/gstomx_base_videoenc.c
@@ -35,63 +35,9 @@ enum
 GSTOMX_BOILERPLATE (GstOmxBaseVideoEnc, gst_omx_base_videoenc, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("video/x-raw-yuv",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  {
-    GValue list;
-    GValue val;
-
-    list.g_type = val.g_type = 0;
-
-    g_value_init (&list, GST_TYPE_LIST);
-    g_value_init (&val, GST_TYPE_FOURCC);
-
-    gst_value_set_fourcc (&val, GST_MAKE_FOURCC ('I', '4', '2', '0'));
-    gst_value_list_append_value (&list, &val);
-
-    gst_value_set_fourcc (&val, GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'));
-    gst_value_list_append_value (&list, &val);
-
-    gst_value_set_fourcc (&val, GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'));
-    gst_value_list_append_value (&list, &val);
-
-    gst_structure_set_value (struc, "format", &list);
-
-    g_value_unset (&val);
-    g_value_unset (&list);
-  }
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
-  GstElementClass *element_class;
-
-  element_class = GST_ELEMENT_CLASS (g_class);
-
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
 }
 
 static void
diff --git a/omx/gstomx_filereadersrc.c b/omx/gstomx_filereadersrc.c
index 3c63ceb..478f189 100644
--- a/omx/gstomx_filereadersrc.c
+++ b/omx/gstomx_filereadersrc.c
@@ -32,16 +32,6 @@ enum
 GSTOMX_BOILERPLATE (GstOmxFilereaderSrc, gst_omx_filereadersrc, GstOmxBaseSrc,
     GST_OMX_BASE_SRC_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_any ();
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -53,14 +43,9 @@ type_base_init (gpointer g_class)
       "OpenMAX IL filereader src element",
       "None", "Does nothing", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static gboolean
diff --git a/omx/gstomx_g711dec.c b/omx/gstomx_g711dec.c
index 25f97f0..c6711a6 100644
--- a/omx/gstomx_g711dec.c
+++ b/omx/gstomx_g711dec.c
@@ -29,42 +29,6 @@
 GSTOMX_BOILERPLATE (GstOmxG711Dec, gst_omx_g711dec, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", G_TYPE_INT, 8000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("audio/x-alaw",
-      "rate", G_TYPE_INT, 8000, "channels", G_TYPE_INT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  struc = gst_structure_new ("audio/x-mulaw",
-      "rate", G_TYPE_INT, 8000, "channels", G_TYPE_INT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -77,23 +41,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Audio",
       "Decodes audio in G.711 format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
-
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_g711enc.c b/omx/gstomx_g711enc.c
index c1aab07..491d4a9 100644
--- a/omx/gstomx_g711enc.c
+++ b/omx/gstomx_g711enc.c
@@ -28,42 +28,6 @@
 GSTOMX_BOILERPLATE (GstOmxG711Enc, gst_omx_g711enc, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("audio/x-alaw",
-      "rate", G_TYPE_INT, 8000, "channels", G_TYPE_INT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  struc = gst_structure_new ("audio/x-mulaw",
-      "rate", G_TYPE_INT, 8000, "channels", G_TYPE_INT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", G_TYPE_INT, 8000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -76,23 +40,13 @@ type_base_init (gpointer g_class)
       "Codec/Encoder/Audio",
       "Encodes audio in G.711 format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
-
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_g729dec.c b/omx/gstomx_g729dec.c
index e80310f..e3999fa 100644
--- a/omx/gstomx_g729dec.c
+++ b/omx/gstomx_g729dec.c
@@ -25,37 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxG729Dec, gst_omx_g729dec, GstOmxBaseAudioDec,
     GST_OMX_BASE_AUDIODEC_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", G_TYPE_INT, 8000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("audio/G729",
-      "rate", G_TYPE_INT, 8000, "channels", G_TYPE_INT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -68,23 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Audio",
       "Decodes audio in G.729 format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
-
-  {
-    GstPadTemplate *template;
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_g729enc.c b/omx/gstomx_g729enc.c
index c589749..d9b6340 100644
--- a/omx/gstomx_g729enc.c
+++ b/omx/gstomx_g729enc.c
@@ -34,37 +34,6 @@ enum
 GSTOMX_BOILERPLATE (GstOmxG729Enc, gst_omx_g729enc, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("audio/G729",
-      "rate", G_TYPE_INT, 8000, "channels", G_TYPE_INT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", G_TYPE_INT, 8000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -77,23 +46,13 @@ type_base_init (gpointer g_class)
       "Codec/Encoder/Audio",
       "Encodes audio in G.729 format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
-
-  {
-    GstPadTemplate *template;
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
@@ -173,7 +132,7 @@ sink_setcaps (GstPad * pad, GstCaps * caps)
     GstCaps *tmp_caps;
 
     /* src template are fixed caps */
-    tmp_caps = generate_src_template ();
+    tmp_caps = gstomx_template_caps (G_TYPE_FROM_INSTANCE (omx_base), "src");
 
     ret = gst_pad_set_caps (omx_base->srcpad, tmp_caps);
     gst_caps_unref (tmp_caps);
diff --git a/omx/gstomx_h263dec.c b/omx/gstomx_h263dec.c
index 4cd5e38..7a0301d 100644
--- a/omx/gstomx_h263dec.c
+++ b/omx/gstomx_h263dec.c
@@ -25,25 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxH263Dec, gst_omx_h263dec, GstOmxBaseVideoDec,
     GST_OMX_BASE_VIDEODEC_TYPE);
 
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("video/x-h263",
-      "variant", G_TYPE_STRING, "itu",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -56,14 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Video",
       "Decodes video in H.263 format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_h263enc.c b/omx/gstomx_h263enc.c
index 71c5361..a8a7a71 100644
--- a/omx/gstomx_h263enc.c
+++ b/omx/gstomx_h263enc.c
@@ -25,20 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxH263Enc, gst_omx_h263enc, GstOmxBaseVideoEnc,
     GST_OMX_BASE_VIDEOENC_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("video/x-h263",
-      "variant", G_TYPE_STRING, "itu",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -51,14 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Encoder/Video",
       "Encodes video in H.263 format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_h264dec.c b/omx/gstomx_h264dec.c
index 167d9d3..0507952 100644
--- a/omx/gstomx_h264dec.c
+++ b/omx/gstomx_h264dec.c
@@ -25,24 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxH264Dec, gst_omx_h264dec, GstOmxBaseVideoDec,
     GST_OMX_BASE_VIDEODEC_TYPE);
 
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("video/x-h264",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -55,14 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Video",
       "Decodes video in H.264/AVC format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_h264enc.c b/omx/gstomx_h264enc.c
index 86585ca..4b2d59c 100644
--- a/omx/gstomx_h264enc.c
+++ b/omx/gstomx_h264enc.c
@@ -25,19 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxH264Enc, gst_omx_h264enc, GstOmxBaseVideoEnc,
     GST_OMX_BASE_VIDEOENC_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("video/x-h264",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -50,14 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Encoder/Video",
       "Encodes video in H.264/AVC format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_ilbcdec.c b/omx/gstomx_ilbcdec.c
index 580d658..084960f 100644
--- a/omx/gstomx_ilbcdec.c
+++ b/omx/gstomx_ilbcdec.c
@@ -27,57 +27,6 @@
 GSTOMX_BOILERPLATE (GstOmxIlbcDec, gst_omx_ilbcdec, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", G_TYPE_INT, 8000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("audio/x-iLBC", NULL);
-
-  {
-    GValue list;
-    GValue val;
-
-    list.g_type = val.g_type = 0;
-
-    g_value_init (&list, GST_TYPE_LIST);
-    g_value_init (&val, G_TYPE_INT);
-
-    g_value_set_int (&val, 20);
-    gst_value_list_append_value (&list, &val);
-
-    g_value_set_int (&val, 30);
-    gst_value_list_append_value (&list, &val);
-
-    gst_structure_set_value (struc, "mode", &list);
-
-    g_value_unset (&val);
-    g_value_unset (&list);
-  }
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -90,23 +39,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Audio",
       "Decodes audio in iLBC format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_ilbcenc.c b/omx/gstomx_ilbcenc.c
index b7bf6af..898418c 100644
--- a/omx/gstomx_ilbcenc.c
+++ b/omx/gstomx_ilbcenc.c
@@ -26,57 +26,6 @@
 GSTOMX_BOILERPLATE (GstOmxIlbcEnc, gst_omx_ilbcenc, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("audio/x-iLBC", NULL);
-
-  {
-    GValue list;
-    GValue val;
-
-    list.g_type = val.g_type = 0;
-
-    g_value_init (&list, GST_TYPE_LIST);
-    g_value_init (&val, G_TYPE_INT);
-
-    g_value_set_int (&val, 20);
-    gst_value_list_append_value (&list, &val);
-
-    g_value_set_int (&val, 30);
-    gst_value_list_append_value (&list, &val);
-
-    gst_structure_set_value (struc, "mode", &list);
-
-    g_value_unset (&val);
-    g_value_unset (&list);
-  }
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", G_TYPE_INT, 8000,
-      "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -89,23 +38,13 @@ type_base_init (gpointer g_class)
       "Codec/Encoder/Audio",
       "Encodes audio in iLBC format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_jpegenc.c b/omx/gstomx_jpegenc.c
index 3e83f03..3cbb8ba 100644
--- a/omx/gstomx_jpegenc.c
+++ b/omx/gstomx_jpegenc.c
@@ -37,55 +37,6 @@ enum
 GSTOMX_BOILERPLATE (GstOmxJpegEnc, gst_omx_jpegenc, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("image/jpeg",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("video/x-raw-yuv",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  {
-    GValue list = { 0 };
-    GValue val = { 0 };
-
-    g_value_init (&list, GST_TYPE_LIST);
-    g_value_init (&val, GST_TYPE_FOURCC);
-
-    gst_value_set_fourcc (&val, GST_MAKE_FOURCC ('I', '4', '2', '0'));
-    gst_value_list_append_value (&list, &val);
-
-    gst_value_set_fourcc (&val, GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'));
-    gst_value_list_append_value (&list, &val);
-
-    gst_structure_set_value (struc, "format", &list);
-
-    g_value_unset (&val);
-    g_value_unset (&list);
-  }
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
 
 static void
 type_base_init (gpointer g_class)
@@ -99,23 +50,13 @@ type_base_init (gpointer g_class)
       "Codec/Encoder/Image",
       "Encodes image in JPEG format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
-
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_mp2dec.c b/omx/gstomx_mp2dec.c
index 0211f08..25f94f6 100644
--- a/omx/gstomx_mp2dec.c
+++ b/omx/gstomx_mp2dec.c
@@ -26,37 +26,6 @@
 GSTOMX_BOILERPLATE (GstOmxMp2Dec, gst_omx_mp2dec, GstOmxBaseAudioDec,
     GST_OMX_BASE_AUDIODEC_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000,
-      "signed", G_TYPE_BOOLEAN, TRUE,
-      "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/mpeg",
-      "mpegversion", G_TYPE_INT, 1,
-      "layer", G_TYPE_INT, 2,
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000,
-      "channels", GST_TYPE_INT_RANGE, 1, 2,
-      "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -69,23 +38,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Audio",
       "Decodes audio in MP2 format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
-
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_mp3dec.c b/omx/gstomx_mp3dec.c
index a617771..a5fa69a 100644
--- a/omx/gstomx_mp3dec.c
+++ b/omx/gstomx_mp3dec.c
@@ -25,37 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxMp3Dec, gst_omx_mp3dec, GstOmxBaseAudioDec,
     GST_OMX_BASE_AUDIODEC_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000,
-      "signed", G_TYPE_BOOLEAN, TRUE,
-      "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/mpeg",
-      "mpegversion", G_TYPE_INT, 1,
-      "layer", G_TYPE_INT, 3,
-      "rate", GST_TYPE_INT_RANGE, 8000, 48000,
-      "channels", GST_TYPE_INT_RANGE, 1, 8,
-      "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -68,23 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Audio",
       "Decodes audio in MP3 format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
-
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_mpeg4dec.c b/omx/gstomx_mpeg4dec.c
index f112ecb..1286f65 100644
--- a/omx/gstomx_mpeg4dec.c
+++ b/omx/gstomx_mpeg4dec.c
@@ -25,48 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxMpeg4Dec, gst_omx_mpeg4dec, GstOmxBaseVideoDec,
     GST_OMX_BASE_VIDEODEC_TYPE);
 
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("video/mpeg",
-      "mpegversion", G_TYPE_INT, 4,
-      "systemstream", G_TYPE_BOOLEAN, FALSE,
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  struc = gst_structure_new ("video/x-divx",
-      "divxversion", GST_TYPE_INT_RANGE, 4, 5,
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  struc = gst_structure_new ("video/x-xvid",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  struc = gst_structure_new ("video/x-3ivx",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -79,14 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Video",
       "Decodes video in MPEG-4 format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_mpeg4enc.c b/omx/gstomx_mpeg4enc.c
index ca6d4ed..394cc7b 100644
--- a/omx/gstomx_mpeg4enc.c
+++ b/omx/gstomx_mpeg4enc.c
@@ -25,21 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxMpeg4Enc, gst_omx_mpeg4enc, GstOmxBaseVideoEnc,
     GST_OMX_BASE_VIDEOENC_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("video/mpeg",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1,
-      "mpegversion", G_TYPE_INT, 4,
-      "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -52,14 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Encoder/Video",
       "Encodes video in MPEG-4 format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_videosink.c b/omx/gstomx_videosink.c
index e58b8d3..cb295f6 100644
--- a/omx/gstomx_videosink.c
+++ b/omx/gstomx_videosink.c
@@ -36,48 +36,6 @@ enum
   ARG_ROTATION,
 };
 
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("video/x-raw-yuv",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  {
-    GValue list;
-    GValue val;
-
-    list.g_type = val.g_type = 0;
-
-    g_value_init (&list, GST_TYPE_LIST);
-    g_value_init (&val, GST_TYPE_FOURCC);
-
-    gst_value_set_fourcc (&val, GST_MAKE_FOURCC ('I', '4', '2', '0'));
-    gst_value_list_append_value (&list, &val);
-
-    gst_value_set_fourcc (&val, GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'));
-    gst_value_list_append_value (&list, &val);
-
-    gst_value_set_fourcc (&val, GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'));
-    gst_value_list_append_value (&list, &val);
-
-    gst_structure_set_value (struc, "format", &list);
-
-    g_value_unset (&val);
-    g_value_unset (&list);
-  }
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -89,14 +47,9 @@ type_base_init (gpointer g_class)
       "OpenMAX IL videosink element",
       "Video/Sink", "Renders video", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 }
 
 static gboolean
diff --git a/omx/gstomx_volume.c b/omx/gstomx_volume.c
index 2315060..28a9b14 100644
--- a/omx/gstomx_volume.c
+++ b/omx/gstomx_volume.c
@@ -27,38 +27,6 @@
 GSTOMX_BOILERPLATE (GstOmxVolume, gst_omx_volume, GstOmxBaseFilter,
     GST_OMX_BASE_FILTER_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", GST_TYPE_INT_RANGE, 8000, 48000,
-      "signed", G_TYPE_BOOLEAN, TRUE,
-      "channels", GST_TYPE_INT_RANGE, 1, 8, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16,
-      "rate", GST_TYPE_INT_RANGE, 8000, 48000,
-      "signed", G_TYPE_BOOLEAN, TRUE,
-      "channels", GST_TYPE_INT_RANGE, 1, 8, NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -71,23 +39,13 @@ type_base_init (gpointer g_class)
       "Filter/Effect/Audio",
       "Changes the volume with OpenMAX IL", "Frederik Vernelen");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_vorbisdec.c b/omx/gstomx_vorbisdec.c
index f14c1d8..a16988c 100644
--- a/omx/gstomx_vorbisdec.c
+++ b/omx/gstomx_vorbisdec.c
@@ -25,31 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxVorbisDec, gst_omx_vorbisdec, GstOmxBaseAudioDec,
     GST_OMX_BASE_AUDIODEC_TYPE);
 
-static GstCaps *
-generate_src_template (void)
-{
-  GstCaps *caps = NULL;
-
-  caps = gst_caps_new_simple ("audio/x-raw-int",
-      "rate", GST_TYPE_INT_RANGE, 8000, 96000,
-      "signed", G_TYPE_BOOLEAN, TRUE,
-      "endianness", G_TYPE_INT, G_BYTE_ORDER,
-      "width", G_TYPE_INT, 16,
-      "depth", G_TYPE_INT, 16, "channels", GST_TYPE_INT_RANGE, 1, 256, NULL);
-
-  return caps;
-}
-
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps = NULL;
-
-  caps = gst_caps_new_simple ("application/ogg", NULL);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -62,23 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Audio",
       "Decodes audio in Vorbis format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("src", GST_PAD_SRC,
-        GST_PAD_ALWAYS, generate_src_template ());
-
-    gst_element_class_add_pad_template (element_class, template);
-  }
-
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
diff --git a/omx/gstomx_wmvdec.c b/omx/gstomx_wmvdec.c
index f99308f..77326cf 100644
--- a/omx/gstomx_wmvdec.c
+++ b/omx/gstomx_wmvdec.c
@@ -25,24 +25,6 @@
 GSTOMX_BOILERPLATE (GstOmxWmvDec, gst_omx_wmvdec, GstOmxBaseVideoDec,
     GST_OMX_BASE_VIDEODEC_TYPE);
 
-static GstCaps *
-generate_sink_template (void)
-{
-  GstCaps *caps;
-  GstStructure *struc;
-
-  caps = gst_caps_new_empty ();
-
-  struc = gst_structure_new ("video/x-wmv",
-      "width", GST_TYPE_INT_RANGE, 16, 4096,
-      "height", GST_TYPE_INT_RANGE, 16, 4096,
-      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
-
-  gst_caps_append_structure (caps, struc);
-
-  return caps;
-}
-
 static void
 type_base_init (gpointer g_class)
 {
@@ -55,14 +37,13 @@ type_base_init (gpointer g_class)
       "Codec/Decoder/Video",
       "Decodes video in WMV format with OpenMAX IL", "Felipe Contreras");
 
-  {
-    GstPadTemplate *template;
-
-    template = gst_pad_template_new ("sink", GST_PAD_SINK,
-        GST_PAD_ALWAYS, generate_sink_template ());
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
 
-    gst_element_class_add_pad_template (element_class, template);
-  }
+  gst_element_class_add_pad_template (element_class,
+      gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+          gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
 }
 
 static void
-- 
1.7.1.1





More information about the Gstreamer-openmax mailing list