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.DeviceMonitor; 26 27 private import glib.ConstructionException; 28 private import glib.ListG; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gstreamer.Bus; 32 private import gstreamer.Caps; 33 private import gstreamer.ObjectGst; 34 private import gstreamerc.gstreamer; 35 public import gstreamerc.gstreamertypes; 36 37 38 /** 39 * Applications should create a #GstDeviceMonitor when they want 40 * to probe, list and monitor devices of a specific type. The 41 * #GstDeviceMonitor will create the appropriate 42 * #GstDeviceProvider objects and manage them. It will then post 43 * messages on its #GstBus for devices that have been added and 44 * removed. 45 * 46 * The device monitor will monitor all devices matching the filters that 47 * the application has set. 48 * 49 * 50 * The basic use pattern of a device monitor is as follows: 51 * |[ 52 * static gboolean 53 * my_bus_func (GstBus * bus, GstMessage * message, gpointer user_data) 54 * { 55 * GstDevice *device; 56 * gchar *name; 57 * 58 * switch (GST_MESSAGE_TYPE (message)) { 59 * case GST_MESSAGE_DEVICE_ADDED: 60 * gst_message_parse_device_added (message, &device); 61 * name = gst_device_get_display_name (device); 62 * g_print("Device added: %s\n", name); 63 * g_free (name); 64 * break; 65 * case GST_MESSAGE_DEVICE_REMOVED: 66 * gst_message_parse_device_removed (message, &device); 67 * name = gst_device_get_display_name (device); 68 * g_print("Device removed: %s\n", name); 69 * g_free (name); 70 * break; 71 * default: 72 * break; 73 * } 74 * 75 * return G_SOURCE_CONTINUE; 76 * } 77 * 78 * GstDeviceMonitor * 79 * setup_raw_video_source_device_monitor (void) { 80 * GstDeviceMonitor *monitor; 81 * GstBus *bus; 82 * GstCaps *caps; 83 * 84 * monitor = gst_device_monitor_new (); 85 * 86 * bus = gst_device_monitor_get_bus (monitor); 87 * gst_bus_add_watch (bus, my_bus_func, NULL); 88 * gst_object_unref (bus); 89 * 90 * caps = gst_caps_new_empty_simple ("video/x-raw"); 91 * gst_device_monitor_add_filter (monitor, "Video/Source", caps); 92 * gst_caps_unref (caps); 93 * 94 * gst_device_monitor_start (monitor); 95 * 96 * return monitor; 97 * } 98 * ]| 99 * 100 * Since: 1.4 101 */ 102 public class DeviceMonitor : ObjectGst 103 { 104 /** the main Gtk struct */ 105 protected GstDeviceMonitor* gstDeviceMonitor; 106 107 /** Get the main Gtk struct */ 108 public GstDeviceMonitor* getDeviceMonitorStruct() 109 { 110 return gstDeviceMonitor; 111 } 112 113 /** the main Gtk struct as a void* */ 114 protected override void* getStruct() 115 { 116 return cast(void*)gstDeviceMonitor; 117 } 118 119 protected override void setStruct(GObject* obj) 120 { 121 gstDeviceMonitor = cast(GstDeviceMonitor*)obj; 122 super.setStruct(obj); 123 } 124 125 /** 126 * Sets our main struct and passes it to the parent class. 127 */ 128 public this (GstDeviceMonitor* gstDeviceMonitor, bool ownedRef = false) 129 { 130 this.gstDeviceMonitor = gstDeviceMonitor; 131 super(cast(GstObject*)gstDeviceMonitor, ownedRef); 132 } 133 134 135 /** */ 136 public static GType getType() 137 { 138 return gst_device_monitor_get_type(); 139 } 140 141 /** 142 * Create a new #GstDeviceMonitor 143 * 144 * Return: a new device monitor. 145 * 146 * Since: 1.4 147 * 148 * Throws: ConstructionException GTK+ fails to create the object. 149 */ 150 public this() 151 { 152 auto p = gst_device_monitor_new(); 153 154 if(p is null) 155 { 156 throw new ConstructionException("null returned by new"); 157 } 158 159 this(cast(GstDeviceMonitor*) p, true); 160 } 161 162 /** 163 * Adds a filter for which #GstDevice will be monitored, any device that matches 164 * all these classes and the #GstCaps will be returned. 165 * 166 * If this function is called multiple times to add more filters, each will be 167 * matched independently. That is, adding more filters will not further restrict 168 * what devices are matched. 169 * 170 * The #GstCaps supported by the device as returned by gst_device_get_caps() are 171 * not intersected with caps filters added using this function. 172 * 173 * Filters must be added before the #GstDeviceMonitor is started. 174 * 175 * Params: 176 * classes = device classes to use as filter or %NULL for any class 177 * caps = the #GstCaps to filter or %NULL for ANY 178 * 179 * Return: The id of the new filter or 0 if no provider matched the filter's 180 * classes. 181 * 182 * Since: 1.4 183 */ 184 public uint addFilter(string classes, Caps caps) 185 { 186 return gst_device_monitor_add_filter(gstDeviceMonitor, Str.toStringz(classes), (caps is null) ? null : caps.getCapsStruct()); 187 } 188 189 /** 190 * Gets the #GstBus of this #GstDeviceMonitor 191 * 192 * Return: a #GstBus 193 * 194 * Since: 1.4 195 */ 196 public Bus getBus() 197 { 198 auto p = gst_device_monitor_get_bus(gstDeviceMonitor); 199 200 if(p is null) 201 { 202 return null; 203 } 204 205 return ObjectG.getDObject!(Bus)(cast(GstBus*) p, true); 206 } 207 208 /** 209 * Gets a list of devices from all of the relevant monitors. This may actually 210 * probe the hardware if the monitor is not currently started. 211 * 212 * Return: a #GList of 213 * #GstDevice 214 * 215 * Since: 1.4 216 */ 217 public ListG getDevices() 218 { 219 auto p = gst_device_monitor_get_devices(gstDeviceMonitor); 220 221 if(p is null) 222 { 223 return null; 224 } 225 226 return new ListG(cast(GList*) p, true); 227 } 228 229 /** 230 * Get a list of the currently selected device provider factories. 231 * 232 * This 233 * 234 * Return: A list of device provider factory names that are currently being 235 * monitored by @monitor or %NULL when nothing is being monitored. 236 * 237 * Since: 1.6 238 */ 239 public string[] getProviders() 240 { 241 auto retStr = gst_device_monitor_get_providers(gstDeviceMonitor); 242 243 scope(exit) Str.freeStringArray(retStr); 244 return Str.toStringArray(retStr); 245 } 246 247 /** 248 * Get if @monitor is curretly showing all devices, even those from hidden 249 * providers. 250 * 251 * Return: %TRUE when all devices will be shown. 252 * 253 * Since: 1.6 254 */ 255 public bool getShowAllDevices() 256 { 257 return gst_device_monitor_get_show_all_devices(gstDeviceMonitor) != 0; 258 } 259 260 /** 261 * Removes a filter from the #GstDeviceMonitor using the id that was returned 262 * by gst_device_monitor_add_filter(). 263 * 264 * Params: 265 * filterId = the id of the filter 266 * 267 * Return: %TRUE of the filter id was valid, %FALSE otherwise 268 * 269 * Since: 1.4 270 */ 271 public bool removeFilter(uint filterId) 272 { 273 return gst_device_monitor_remove_filter(gstDeviceMonitor, filterId) != 0; 274 } 275 276 /** 277 * Set if all devices should be visible, even those devices from hidden 278 * providers. Setting @show_all to true might show some devices multiple times. 279 * 280 * Params: 281 * showAll = show all devices 282 * 283 * Since: 1.6 284 */ 285 public void setShowAllDevices(bool showAll) 286 { 287 gst_device_monitor_set_show_all_devices(gstDeviceMonitor, showAll); 288 } 289 290 /** 291 * Starts monitoring the devices, one this has succeeded, the 292 * %GST_MESSAGE_DEVICE_ADDED and %GST_MESSAGE_DEVICE_REMOVED messages 293 * will be emitted on the bus when the list of devices changes. 294 * 295 * Return: %TRUE if the device monitoring could be started 296 * 297 * Since: 1.4 298 */ 299 public bool start() 300 { 301 return gst_device_monitor_start(gstDeviceMonitor) != 0; 302 } 303 304 /** 305 * Stops monitoring the devices. 306 * 307 * Since: 1.4 308 */ 309 public void stop() 310 { 311 gst_device_monitor_stop(gstDeviceMonitor); 312 } 313 }