1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gstreamer.PadTemplate; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gstreamer.Caps; 32 private import gstreamer.ObjectGst; 33 private import gstreamer.Pad; 34 private import gstreamer.StaticPadTemplate; 35 private import gstreamer.c.functions; 36 public import gstreamer.c.types; 37 public import gstreamerc.gstreamertypes; 38 private import std.algorithm; 39 40 41 /** 42 * Padtemplates describe the possible media types a pad or an elementfactory can 43 * handle. This allows for both inspection of handled types before loading the 44 * element plugin as well as identifying pads on elements that are not yet 45 * created (request or sometimes pads). 46 * 47 * Pad and PadTemplates have #GstCaps attached to it to describe the media type 48 * they are capable of dealing with. gst_pad_template_get_caps() or 49 * GST_PAD_TEMPLATE_CAPS() are used to get the caps of a padtemplate. It's not 50 * possible to modify the caps of a padtemplate after creation. 51 * 52 * PadTemplates have a #GstPadPresence property which identifies the lifetime 53 * of the pad and that can be retrieved with GST_PAD_TEMPLATE_PRESENCE(). Also 54 * the direction of the pad can be retrieved from the #GstPadTemplate with 55 * GST_PAD_TEMPLATE_DIRECTION(). 56 * 57 * The GST_PAD_TEMPLATE_NAME_TEMPLATE () is important for GST_PAD_REQUEST pads 58 * because it has to be used as the name in the gst_element_get_request_pad() 59 * call to instantiate a pad from this template. 60 * 61 * Padtemplates can be created with gst_pad_template_new() or with 62 * gst_static_pad_template_get (), which creates a #GstPadTemplate from a 63 * #GstStaticPadTemplate that can be filled with the 64 * convenient GST_STATIC_PAD_TEMPLATE() macro. 65 * 66 * A padtemplate can be used to create a pad (see gst_pad_new_from_template() 67 * or gst_pad_new_from_static_template ()) or to add to an element class 68 * (see gst_element_class_add_static_pad_template ()). 69 * 70 * The following code example shows the code to create a pad from a padtemplate. 71 * |[<!-- language="C" --> 72 * GstStaticPadTemplate my_template = 73 * GST_STATIC_PAD_TEMPLATE ( 74 * "sink", // the name of the pad 75 * GST_PAD_SINK, // the direction of the pad 76 * GST_PAD_ALWAYS, // when this pad will be present 77 * GST_STATIC_CAPS ( // the capabilities of the padtemplate 78 * "audio/x-raw, " 79 * "channels = (int) [ 1, 6 ]" 80 * ) 81 * ); 82 * void 83 * my_method (void) 84 * { 85 * GstPad *pad; 86 * pad = gst_pad_new_from_static_template (&my_template, "sink"); 87 * ... 88 * } 89 * ]| 90 * 91 * The following example shows you how to add the padtemplate to an 92 * element class, this is usually done in the class_init of the class: 93 * |[<!-- language="C" --> 94 * static void 95 * my_element_class_init (GstMyElementClass *klass) 96 * { 97 * GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); 98 * 99 * gst_element_class_add_static_pad_template (gstelement_class, &my_template); 100 * } 101 * ]| 102 */ 103 public class PadTemplate : ObjectGst 104 { 105 /** the main Gtk struct */ 106 protected GstPadTemplate* gstPadTemplate; 107 108 /** Get the main Gtk struct */ 109 public GstPadTemplate* getPadTemplateStruct(bool transferOwnership = false) 110 { 111 if (transferOwnership) 112 ownedRef = false; 113 return gstPadTemplate; 114 } 115 116 /** the main Gtk struct as a void* */ 117 protected override void* getStruct() 118 { 119 return cast(void*)gstPadTemplate; 120 } 121 122 /** 123 * Sets our main struct and passes it to the parent class. 124 */ 125 public this (GstPadTemplate* gstPadTemplate, bool ownedRef = false) 126 { 127 this.gstPadTemplate = gstPadTemplate; 128 super(cast(GstObject*)gstPadTemplate, ownedRef); 129 } 130 131 132 /** */ 133 public static GType getType() 134 { 135 return gst_pad_template_get_type(); 136 } 137 138 /** 139 * Creates a new pad template with a name according to the given template 140 * and with the given arguments. 141 * 142 * Params: 143 * nameTemplate = the name template. 144 * direction = the #GstPadDirection of the template. 145 * presence = the #GstPadPresence of the pad. 146 * caps = a #GstCaps set for the template. 147 * 148 * Returns: a new #GstPadTemplate. 149 * 150 * Throws: ConstructionException GTK+ fails to create the object. 151 */ 152 public this(string nameTemplate, GstPadDirection direction, GstPadPresence presence, Caps caps) 153 { 154 auto p = gst_pad_template_new(Str.toStringz(nameTemplate), direction, presence, (caps is null) ? null : caps.getCapsStruct()); 155 156 if(p is null) 157 { 158 throw new ConstructionException("null returned by new"); 159 } 160 161 this(cast(GstPadTemplate*) p); 162 } 163 164 /** 165 * Converts a #GstStaticPadTemplate into a #GstPadTemplate with a type. 166 * 167 * Params: 168 * padTemplate = the static pad template 169 * padType = The #GType of the pad to create 170 * 171 * Returns: a new #GstPadTemplate. 172 * 173 * Since: 1.14 174 * 175 * Throws: ConstructionException GTK+ fails to create the object. 176 */ 177 public this(StaticPadTemplate padTemplate, GType padType) 178 { 179 auto p = gst_pad_template_new_from_static_pad_template_with_gtype((padTemplate is null) ? null : padTemplate.getStaticPadTemplateStruct(), padType); 180 181 if(p is null) 182 { 183 throw new ConstructionException("null returned by new_from_static_pad_template_with_gtype"); 184 } 185 186 this(cast(GstPadTemplate*) p); 187 } 188 189 /** 190 * Creates a new pad template with a name according to the given template 191 * and with the given arguments. 192 * 193 * Params: 194 * nameTemplate = the name template. 195 * direction = the #GstPadDirection of the template. 196 * presence = the #GstPadPresence of the pad. 197 * caps = a #GstCaps set for the template. 198 * padType = The #GType of the pad to create 199 * 200 * Returns: a new #GstPadTemplate. 201 * 202 * Since: 1.14 203 * 204 * Throws: ConstructionException GTK+ fails to create the object. 205 */ 206 public this(string nameTemplate, GstPadDirection direction, GstPadPresence presence, Caps caps, GType padType) 207 { 208 auto p = gst_pad_template_new_with_gtype(Str.toStringz(nameTemplate), direction, presence, (caps is null) ? null : caps.getCapsStruct(), padType); 209 210 if(p is null) 211 { 212 throw new ConstructionException("null returned by new_with_gtype"); 213 } 214 215 this(cast(GstPadTemplate*) p); 216 } 217 218 /** 219 * Gets the capabilities of the pad template. 220 * 221 * Returns: the #GstCaps of the pad template. 222 * Unref after usage. 223 */ 224 public Caps getCaps() 225 { 226 auto p = gst_pad_template_get_caps(gstPadTemplate); 227 228 if(p is null) 229 { 230 return null; 231 } 232 233 return ObjectG.getDObject!(Caps)(cast(GstCaps*) p, true); 234 } 235 236 /** 237 * Emit the pad-created signal for this template when created by this pad. 238 * 239 * Params: 240 * pad = the #GstPad that created it 241 */ 242 public void padCreated(Pad pad) 243 { 244 gst_pad_template_pad_created(gstPadTemplate, (pad is null) ? null : pad.getPadStruct()); 245 } 246 247 /** 248 * This signal is fired when an element creates a pad from this template. 249 * 250 * Params: 251 * pad = the pad that was created. 252 */ 253 gulong addOnPadCreated(void delegate(Pad, PadTemplate) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 254 { 255 return Signals.connect(this, "pad-created", dlg, connectFlags ^ ConnectFlags.SWAPPED); 256 } 257 }