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.Device; 26 27 private import glib.Str; 28 private import gobject.ObjectG; 29 private import gobject.Signals; 30 private import gstreamer.Caps; 31 private import gstreamer.Element; 32 private import gstreamer.ObjectGst; 33 private import gstreamer.Structure; 34 private import gstreamerc.gstreamer; 35 public import gstreamerc.gstreamertypes; 36 public import gtkc.gdktypes; 37 private import std.algorithm; 38 39 40 /** 41 * #GstDevice are objects representing a device, they contain 42 * relevant metadata about the device, such as its class and the #GstCaps 43 * representing the media types it can produce or handle. 44 * 45 * #GstDevice are created by #GstDeviceProvider objects which can be 46 * aggregated by #GstDeviceMonitor objects. 47 * 48 * Since: 1.4 49 */ 50 public class Device : ObjectGst 51 { 52 /** the main Gtk struct */ 53 protected GstDevice* gstDevice; 54 55 /** Get the main Gtk struct */ 56 public GstDevice* getDeviceStruct() 57 { 58 return gstDevice; 59 } 60 61 /** the main Gtk struct as a void* */ 62 protected override void* getStruct() 63 { 64 return cast(void*)gstDevice; 65 } 66 67 protected override void setStruct(GObject* obj) 68 { 69 gstDevice = cast(GstDevice*)obj; 70 super.setStruct(obj); 71 } 72 73 /** 74 * Sets our main struct and passes it to the parent class. 75 */ 76 public this (GstDevice* gstDevice, bool ownedRef = false) 77 { 78 this.gstDevice = gstDevice; 79 super(cast(GstObject*)gstDevice, ownedRef); 80 } 81 82 83 /** */ 84 public static GType getType() 85 { 86 return gst_device_get_type(); 87 } 88 89 /** 90 * Creates the element with all of the required parameters set to use 91 * this device. 92 * 93 * Params: 94 * name = name of new element, or %NULL to automatically 95 * create a unique name. 96 * 97 * Return: a new #GstElement configured to use this device 98 * 99 * Since: 1.4 100 */ 101 public Element createElement(string name) 102 { 103 auto p = gst_device_create_element(gstDevice, Str.toStringz(name)); 104 105 if(p is null) 106 { 107 return null; 108 } 109 110 return ObjectG.getDObject!(Element)(cast(GstElement*) p, true); 111 } 112 113 /** 114 * Getter for the #GstCaps that this device supports. 115 * 116 * Return: The #GstCaps supported by this device. Unref with 117 * gst_caps_unref() when done. 118 * 119 * Since: 1.4 120 */ 121 public Caps getCaps() 122 { 123 auto p = gst_device_get_caps(gstDevice); 124 125 if(p is null) 126 { 127 return null; 128 } 129 130 return ObjectG.getDObject!(Caps)(cast(GstCaps*) p, true); 131 } 132 133 /** 134 * Gets the "class" of a device. This is a "/" separated list of 135 * classes that represent this device. They are a subset of the 136 * classes of the #GstDeviceProvider that produced this device. 137 * 138 * Return: The device class. Free with g_free() after use. 139 * 140 * Since: 1.4 141 */ 142 public string getDeviceClass() 143 { 144 auto retStr = gst_device_get_device_class(gstDevice); 145 146 scope(exit) Str.freeString(retStr); 147 return Str.toString(retStr); 148 } 149 150 /** 151 * Gets the user-friendly name of the device. 152 * 153 * Return: The device name. Free with g_free() after use. 154 * 155 * Since: 1.4 156 */ 157 public string getDisplayName() 158 { 159 auto retStr = gst_device_get_display_name(gstDevice); 160 161 scope(exit) Str.freeString(retStr); 162 return Str.toString(retStr); 163 } 164 165 /** 166 * Gets the extra properties of a device. 167 * 168 * Return: The extra properties or %NULL when there are none. 169 * Free with gst_structure_free() after use. 170 * 171 * Since: 1.6 172 */ 173 public Structure getProperties() 174 { 175 auto p = gst_device_get_properties(gstDevice); 176 177 if(p is null) 178 { 179 return null; 180 } 181 182 return ObjectG.getDObject!(Structure)(cast(GstStructure*) p, true); 183 } 184 185 /** 186 * Check if @device matches all of the given classes 187 * 188 * Params: 189 * classes = a "/"-separated list of device classes to match, only match if 190 * all classes are matched 191 * 192 * Return: %TRUE if @device matches. 193 * 194 * Since: 1.4 195 */ 196 public bool hasClasses(string classes) 197 { 198 return gst_device_has_classes(gstDevice, Str.toStringz(classes)) != 0; 199 } 200 201 /** 202 * Check if @factory matches all of the given classes 203 * 204 * Params: 205 * classes = a %NULL terminated array of classes 206 * to match, only match if all classes are matched 207 * 208 * Return: %TRUE if @device matches. 209 * 210 * Since: 1.4 211 */ 212 public bool hasClassesv(string[] classes) 213 { 214 return gst_device_has_classesv(gstDevice, Str.toStringzArray(classes)) != 0; 215 } 216 217 /** 218 * Tries to reconfigure an existing element to use the device. If this 219 * function fails, then one must destroy the element and create a new one 220 * using gst_device_create_element(). 221 * 222 * Note: This should only be implemented for elements can change their 223 * device in the PLAYING state. 224 * 225 * Params: 226 * element = a #GstElement 227 * 228 * Return: %TRUE if the element could be reconfigured to use this device, 229 * %FALSE otherwise. 230 * 231 * Since: 1.4 232 */ 233 public bool reconfigureElement(Element element) 234 { 235 return gst_device_reconfigure_element(gstDevice, (element is null) ? null : element.getElementStruct()) != 0; 236 } 237 238 protected class OnRemovedDelegateWrapper 239 { 240 void delegate(Device) dlg; 241 gulong handlerId; 242 ConnectFlags flags; 243 this(void delegate(Device) dlg, gulong handlerId, ConnectFlags flags) 244 { 245 this.dlg = dlg; 246 this.handlerId = handlerId; 247 this.flags = flags; 248 } 249 } 250 protected OnRemovedDelegateWrapper[] onRemovedListeners; 251 252 /** */ 253 gulong addOnRemoved(void delegate(Device) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 254 { 255 onRemovedListeners ~= new OnRemovedDelegateWrapper(dlg, 0, connectFlags); 256 onRemovedListeners[onRemovedListeners.length - 1].handlerId = Signals.connectData( 257 this, 258 "removed", 259 cast(GCallback)&callBackRemoved, 260 cast(void*)onRemovedListeners[onRemovedListeners.length - 1], 261 cast(GClosureNotify)&callBackRemovedDestroy, 262 connectFlags); 263 return onRemovedListeners[onRemovedListeners.length - 1].handlerId; 264 } 265 266 extern(C) static void callBackRemoved(GstDevice* deviceStruct,OnRemovedDelegateWrapper wrapper) 267 { 268 wrapper.dlg(wrapper.outer); 269 } 270 271 extern(C) static void callBackRemovedDestroy(OnRemovedDelegateWrapper wrapper, GClosure* closure) 272 { 273 wrapper.outer.internalRemoveOnRemoved(wrapper); 274 } 275 276 protected void internalRemoveOnRemoved(OnRemovedDelegateWrapper source) 277 { 278 foreach(index, wrapper; onRemovedListeners) 279 { 280 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 281 { 282 onRemovedListeners[index] = null; 283 onRemovedListeners = std.algorithm.remove(onRemovedListeners, index); 284 break; 285 } 286 } 287 } 288 289 }