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 gstreamerc.gstreamer; 35 public import gstreamerc.gstreamertypes; 36 public import gtkc.gdktypes; 37 38 39 /** 40 * Padtemplates describe the possible media types a pad or an elementfactory can 41 * handle. This allows for both inspection of handled types before loading the 42 * element plugin as well as identifying pads on elements that are not yet 43 * created (request or sometimes pads). 44 * 45 * Pad and PadTemplates have #GstCaps attached to it to describe the media type 46 * they are capable of dealing with. gst_pad_template_get_caps() or 47 * GST_PAD_TEMPLATE_CAPS() are used to get the caps of a padtemplate. It's not 48 * possible to modify the caps of a padtemplate after creation. 49 * 50 * PadTemplates have a #GstPadPresence property which identifies the lifetime 51 * of the pad and that can be retrieved with GST_PAD_TEMPLATE_PRESENCE(). Also 52 * the direction of the pad can be retrieved from the #GstPadTemplate with 53 * GST_PAD_TEMPLATE_DIRECTION(). 54 * 55 * The GST_PAD_TEMPLATE_NAME_TEMPLATE () is important for GST_PAD_REQUEST pads 56 * because it has to be used as the name in the gst_element_get_request_pad() 57 * call to instantiate a pad from this template. 58 * 59 * Padtemplates can be created with gst_pad_template_new() or with 60 * gst_static_pad_template_get (), which creates a #GstPadTemplate from a 61 * #GstStaticPadTemplate that can be filled with the 62 * convenient GST_STATIC_PAD_TEMPLATE() macro. 63 * 64 * A padtemplate can be used to create a pad (see gst_pad_new_from_template() 65 * or gst_pad_new_from_static_template ()) or to add to an element class 66 * (see gst_element_class_add_pad_template ()). 67 * 68 * The following code example shows the code to create a pad from a padtemplate. 69 * |[ 70 * GstStaticPadTemplate my_template = 71 * GST_STATIC_PAD_TEMPLATE ( 72 * "sink", // the name of the pad 73 * GST_PAD_SINK, // the direction of the pad 74 * GST_PAD_ALWAYS, // when this pad will be present 75 * GST_STATIC_CAPS ( // the capabilities of the padtemplate 76 * "audio/x-raw, " 77 * "channels = (int) [ 1, 6 ]" 78 * ) 79 * ); 80 * void 81 * my_method (void) 82 * { 83 * GstPad *pad; 84 * pad = gst_pad_new_from_static_template (&my_template, "sink"); 85 * ... 86 * } 87 * ]| 88 * 89 * The following example shows you how to add the padtemplate to an 90 * element class, this is usually done in the class_init of the class: 91 * |[ 92 * static void 93 * my_element_class_init (GstMyElementClass *klass) 94 * { 95 * GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); 96 * 97 * gst_element_class_add_pad_template (gstelement_class, 98 * gst_static_pad_template_get (&my_template)); 99 * } 100 * ]| 101 */ 102 public class PadTemplate : ObjectGst 103 { 104 /** the main Gtk struct */ 105 protected GstPadTemplate* gstPadTemplate; 106 107 /** Get the main Gtk struct */ 108 public GstPadTemplate* getPadTemplateStruct() 109 { 110 return gstPadTemplate; 111 } 112 113 /** the main Gtk struct as a void* */ 114 protected override void* getStruct() 115 { 116 return cast(void*)gstPadTemplate; 117 } 118 119 protected override void setStruct(GObject* obj) 120 { 121 gstPadTemplate = cast(GstPadTemplate*)obj; 122 super.setStruct(obj); 123 } 124 125 /** 126 * Sets our main struct and passes it to the parent class. 127 */ 128 public this (GstPadTemplate* gstPadTemplate, bool ownedRef = false) 129 { 130 this.gstPadTemplate = gstPadTemplate; 131 super(cast(GstObject*)gstPadTemplate, ownedRef); 132 } 133 134 /** 135 */ 136 137 public static GType getType() 138 { 139 return gst_pad_template_get_type(); 140 } 141 142 /** 143 * Creates a new pad template with a name according to the given template 144 * and with the given arguments. 145 * 146 * Params: 147 * nameTemplate = the name template. 148 * direction = the #GstPadDirection of the template. 149 * presence = the #GstPadPresence of the pad. 150 * caps = a #GstCaps set for the template. 151 * 152 * Return: a new #GstPadTemplate. 153 * 154 * Throws: ConstructionException GTK+ fails to create the object. 155 */ 156 public this(string nameTemplate, GstPadDirection direction, GstPadPresence presence, Caps caps) 157 { 158 auto p = gst_pad_template_new(Str.toStringz(nameTemplate), direction, presence, (caps is null) ? null : caps.getCapsStruct()); 159 160 if(p is null) 161 { 162 throw new ConstructionException("null returned by new"); 163 } 164 165 this(cast(GstPadTemplate*) p); 166 } 167 168 /** 169 * Gets the capabilities of the pad template. 170 * 171 * Return: the #GstCaps of the pad template. 172 * Unref after usage. 173 */ 174 public Caps getCaps() 175 { 176 auto p = gst_pad_template_get_caps(gstPadTemplate); 177 178 if(p is null) 179 { 180 return null; 181 } 182 183 return ObjectG.getDObject!(Caps)(cast(GstCaps*) p); 184 } 185 186 /** 187 * Emit the pad-created signal for this template when created by this pad. 188 * 189 * Params: 190 * pad = the #GstPad that created it 191 */ 192 public void padCreated(Pad pad) 193 { 194 gst_pad_template_pad_created(gstPadTemplate, (pad is null) ? null : pad.getPadStruct()); 195 } 196 197 int[string] connectedSignals; 198 199 void delegate(Pad, PadTemplate)[] onPadCreatedListeners; 200 /** 201 * This signal is fired when an element creates a pad from this template. 202 * 203 * Params: 204 * pad = the pad that was created. 205 */ 206 void addOnPadCreated(void delegate(Pad, PadTemplate) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 207 { 208 if ( "pad-created" !in connectedSignals ) 209 { 210 Signals.connectData( 211 this, 212 "pad-created", 213 cast(GCallback)&callBackPadCreated, 214 cast(void*)this, 215 null, 216 connectFlags); 217 connectedSignals["pad-created"] = 1; 218 } 219 onPadCreatedListeners ~= dlg; 220 } 221 extern(C) static void callBackPadCreated(GstPadTemplate* padtemplateStruct, GstPad* pad, PadTemplate _padtemplate) 222 { 223 foreach ( void delegate(Pad, PadTemplate) dlg; _padtemplate.onPadCreatedListeners ) 224 { 225 dlg(ObjectG.getDObject!(Pad)(pad), _padtemplate); 226 } 227 } 228 }