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.DeviceProvider; 26 27 private import glib.ListG; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gstreamer.Bus; 32 private import gstreamer.Device; 33 private import gstreamer.DeviceProviderFactory; 34 private import gstreamer.ObjectGst; 35 private import gstreamer.Plugin; 36 private import gstreamerc.gstreamer; 37 public import gstreamerc.gstreamertypes; 38 private import std.algorithm; 39 40 41 /** 42 * A #GstDeviceProvider subclass is provided by a plugin that handles devices 43 * if there is a way to programatically list connected devices. It can also 44 * optionally provide updates to the list of connected devices. 45 * 46 * Each #GstDeviceProvider subclass is a singleton, a plugin should 47 * normally provide a single subclass for all devices. 48 * 49 * Applications would normally use a #GstDeviceMonitor to monitor devices 50 * from all relevant providers. 51 * 52 * Since: 1.4 53 */ 54 public class DeviceProvider : ObjectGst 55 { 56 /** the main Gtk struct */ 57 protected GstDeviceProvider* gstDeviceProvider; 58 59 /** Get the main Gtk struct */ 60 public GstDeviceProvider* getDeviceProviderStruct(bool transferOwnership = false) 61 { 62 if (transferOwnership) 63 ownedRef = false; 64 return gstDeviceProvider; 65 } 66 67 /** the main Gtk struct as a void* */ 68 protected override void* getStruct() 69 { 70 return cast(void*)gstDeviceProvider; 71 } 72 73 protected override void setStruct(GObject* obj) 74 { 75 gstDeviceProvider = cast(GstDeviceProvider*)obj; 76 super.setStruct(obj); 77 } 78 79 /** 80 * Sets our main struct and passes it to the parent class. 81 */ 82 public this (GstDeviceProvider* gstDeviceProvider, bool ownedRef = false) 83 { 84 this.gstDeviceProvider = gstDeviceProvider; 85 super(cast(GstObject*)gstDeviceProvider, ownedRef); 86 } 87 88 89 /** */ 90 public static GType getType() 91 { 92 return gst_device_provider_get_type(); 93 } 94 95 /** 96 * Create a new device providerfactory capable of instantiating objects of the 97 * @type and add the factory to @plugin. 98 * 99 * Params: 100 * plugin = #GstPlugin to register the device provider with, or %NULL for 101 * a static device provider. 102 * name = name of device providers of this type 103 * rank = rank of device provider (higher rank means more importance when autoplugging) 104 * type = GType of device provider to register 105 * 106 * Returns: %TRUE, if the registering succeeded, %FALSE on error 107 * 108 * Since: 1.4 109 */ 110 public static bool register(Plugin plugin, string name, uint rank, GType type) 111 { 112 return gst_device_provider_register((plugin is null) ? null : plugin.getPluginStruct(), Str.toStringz(name), rank, type) != 0; 113 } 114 115 /** */ 116 public bool canMonitor() 117 { 118 return gst_device_provider_can_monitor(gstDeviceProvider) != 0; 119 } 120 121 /** 122 * Posts a message on the provider's #GstBus to inform applications that 123 * a new device has been added. 124 * 125 * This is for use by subclasses. 126 * 127 * Params: 128 * device = a #GstDevice that has been added 129 * 130 * Since: 1.4 131 */ 132 public void deviceAdd(Device device) 133 { 134 gst_device_provider_device_add(gstDeviceProvider, (device is null) ? null : device.getDeviceStruct()); 135 } 136 137 /** 138 * Posts a message on the provider's #GstBus to inform applications that 139 * a device has been removed. 140 * 141 * This is for use by subclasses. 142 * 143 * Params: 144 * device = a #GstDevice that has been removed 145 * 146 * Since: 1.4 147 */ 148 public void deviceRemove(Device device) 149 { 150 gst_device_provider_device_remove(gstDeviceProvider, (device is null) ? null : device.getDeviceStruct()); 151 } 152 153 /** 154 * Gets the #GstBus of this #GstDeviceProvider 155 * 156 * Returns: a #GstBus 157 * 158 * Since: 1.4 159 */ 160 public Bus getBus() 161 { 162 auto p = gst_device_provider_get_bus(gstDeviceProvider); 163 164 if(p is null) 165 { 166 return null; 167 } 168 169 return ObjectG.getDObject!(Bus)(cast(GstBus*) p, true); 170 } 171 172 /** 173 * Gets a list of devices that this provider understands. This may actually 174 * probe the hardware if the provider is not currently started. 175 * 176 * Returns: a #GList of 177 * #GstDevice 178 * 179 * Since: 1.4 180 */ 181 public ListG getDevices() 182 { 183 auto p = gst_device_provider_get_devices(gstDeviceProvider); 184 185 if(p is null) 186 { 187 return null; 188 } 189 190 return new ListG(cast(GList*) p, true); 191 } 192 193 /** 194 * Retrieves the factory that was used to create this device provider. 195 * 196 * Returns: the #GstDeviceProviderFactory used for 197 * creating this device provider. no refcounting is needed. 198 * 199 * Since: 1.4 200 */ 201 public DeviceProviderFactory getFactory() 202 { 203 auto p = gst_device_provider_get_factory(gstDeviceProvider); 204 205 if(p is null) 206 { 207 return null; 208 } 209 210 return ObjectG.getDObject!(DeviceProviderFactory)(cast(GstDeviceProviderFactory*) p); 211 } 212 213 /** 214 * Get the provider factory names of the #GstDeviceProvider instances that 215 * are hidden by @provider. 216 * 217 * Returns: a list of hidden providers factory names or %NULL when 218 * nothing is hidden by @provider. Free with g_strfreev. 219 * 220 * Since: 1.6 221 */ 222 public string[] getHiddenProviders() 223 { 224 auto retStr = gst_device_provider_get_hidden_providers(gstDeviceProvider); 225 226 scope(exit) Str.freeStringArray(retStr); 227 return Str.toStringArray(retStr); 228 } 229 230 /** 231 * Make @provider hide the devices from the factory with @name. 232 * 233 * This function is used when @provider will also provide the devices reported 234 * by provider factory @name. A monitor should stop monitoring the 235 * device provider with @name to avoid duplicate devices. 236 * 237 * Params: 238 * name = a provider factory name 239 * 240 * Since: 1.6 241 */ 242 public void hideProvider(string name) 243 { 244 gst_device_provider_hide_provider(gstDeviceProvider, Str.toStringz(name)); 245 } 246 247 /** 248 * Starts providering the devices. This will cause #GST_MESSAGE_DEVICE_ADDED 249 * and #GST_MESSAGE_DEVICE_REMOVED messages to be posted on the provider's bus 250 * when devices are added or removed from the system. 251 * 252 * Since the #GstDeviceProvider is a singleton, 253 * gst_device_provider_start() may already have been called by another 254 * user of the object, gst_device_provider_stop() needs to be called the same 255 * number of times. 256 * 257 * Returns: %TRUE if the device providering could be started 258 * 259 * Since: 1.4 260 */ 261 public bool start() 262 { 263 return gst_device_provider_start(gstDeviceProvider) != 0; 264 } 265 266 /** 267 * Decreases the use-count by one. If the use count reaches zero, this 268 * #GstDeviceProvider will stop providering the devices. This needs to be 269 * called the same number of times that gst_device_provider_start() was called. 270 * 271 * Since: 1.4 272 */ 273 public void stop() 274 { 275 gst_device_provider_stop(gstDeviceProvider); 276 } 277 278 /** 279 * Make @provider unhide the devices from factory @name. 280 * 281 * This function is used when @provider will no longer provide the devices 282 * reported by provider factory @name. A monitor should start 283 * monitoring the devices from provider factory @name in order to see 284 * all devices again. 285 * 286 * Params: 287 * name = a provider factory name 288 * 289 * Since: 1.6 290 */ 291 public void unhideProvider(string name) 292 { 293 gst_device_provider_unhide_provider(gstDeviceProvider, Str.toStringz(name)); 294 } 295 296 protected class OnProviderHiddenDelegateWrapper 297 { 298 static OnProviderHiddenDelegateWrapper[] listeners; 299 void delegate(string, DeviceProvider) dlg; 300 gulong handlerId; 301 302 this(void delegate(string, DeviceProvider) dlg) 303 { 304 this.dlg = dlg; 305 this.listeners ~= this; 306 } 307 308 void remove(OnProviderHiddenDelegateWrapper source) 309 { 310 foreach(index, wrapper; listeners) 311 { 312 if (wrapper.handlerId == source.handlerId) 313 { 314 listeners[index] = null; 315 listeners = std.algorithm.remove(listeners, index); 316 break; 317 } 318 } 319 } 320 } 321 322 /** */ 323 gulong addOnProviderHidden(void delegate(string, DeviceProvider) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 324 { 325 auto wrapper = new OnProviderHiddenDelegateWrapper(dlg); 326 wrapper.handlerId = Signals.connectData( 327 this, 328 "provider-hidden", 329 cast(GCallback)&callBackProviderHidden, 330 cast(void*)wrapper, 331 cast(GClosureNotify)&callBackProviderHiddenDestroy, 332 connectFlags); 333 return wrapper.handlerId; 334 } 335 336 extern(C) static void callBackProviderHidden(GstDeviceProvider* deviceproviderStruct, char* object, OnProviderHiddenDelegateWrapper wrapper) 337 { 338 wrapper.dlg(Str.toString(object), wrapper.outer); 339 } 340 341 extern(C) static void callBackProviderHiddenDestroy(OnProviderHiddenDelegateWrapper wrapper, GClosure* closure) 342 { 343 wrapper.remove(wrapper); 344 } 345 346 protected class OnProviderUnhiddenDelegateWrapper 347 { 348 static OnProviderUnhiddenDelegateWrapper[] listeners; 349 void delegate(string, DeviceProvider) dlg; 350 gulong handlerId; 351 352 this(void delegate(string, DeviceProvider) dlg) 353 { 354 this.dlg = dlg; 355 this.listeners ~= this; 356 } 357 358 void remove(OnProviderUnhiddenDelegateWrapper source) 359 { 360 foreach(index, wrapper; listeners) 361 { 362 if (wrapper.handlerId == source.handlerId) 363 { 364 listeners[index] = null; 365 listeners = std.algorithm.remove(listeners, index); 366 break; 367 } 368 } 369 } 370 } 371 372 /** */ 373 gulong addOnProviderUnhidden(void delegate(string, DeviceProvider) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 374 { 375 auto wrapper = new OnProviderUnhiddenDelegateWrapper(dlg); 376 wrapper.handlerId = Signals.connectData( 377 this, 378 "provider-unhidden", 379 cast(GCallback)&callBackProviderUnhidden, 380 cast(void*)wrapper, 381 cast(GClosureNotify)&callBackProviderUnhiddenDestroy, 382 connectFlags); 383 return wrapper.handlerId; 384 } 385 386 extern(C) static void callBackProviderUnhidden(GstDeviceProvider* deviceproviderStruct, char* object, OnProviderUnhiddenDelegateWrapper wrapper) 387 { 388 wrapper.dlg(Str.toString(object), wrapper.outer); 389 } 390 391 extern(C) static void callBackProviderUnhiddenDestroy(OnProviderUnhiddenDelegateWrapper wrapper, GClosure* closure) 392 { 393 wrapper.remove(wrapper); 394 } 395 }