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  * Conversion parameters:
26  * inFile  = GstBin.html
27  * outPack = gstreamer
28  * outFile = Bin
29  * strct   = GstBin
30  * realStrct=
31  * ctorStrct=GstElement
32  * clss    = Bin
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_bin_
41  * 	- gst_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- gstreamer.Element
49  * 	- gstreamer.Iterator
50  * 	- gstreamer.Pad
51  * structWrap:
52  * 	- GstBin* -> Bin
53  * 	- GstElement* -> Element
54  * 	- GstIterator* -> Iterator
55  * 	- GstPad* -> Pad
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module gstreamer.Bin;
62 
63 public  import gstreamerc.gstreamertypes;
64 
65 private import gstreamerc.gstreamer;
66 private import glib.ConstructionException;
67 private import gobject.ObjectG;
68 
69 private import gobject.Signals;
70 public  import gtkc.gdktypes;
71 
72 private import glib.Str;
73 private import gstreamer.Element;
74 private import gstreamer.Iterator;
75 private import gstreamer.Pad;
76 
77 
78 
79 private import gstreamer.Element;
80 
81 /**
82  * Description
83  * GstBin is an element that can contain other GstElement, allowing them to be
84  * managed as a group.
85  * Pads from the child elements can be ghosted to the bin, see GstGhostPad.
86  * This makes the bin look like any other elements and enables creation of
87  * higher-level abstraction elements.
88  * A new GstBin is created with gst_bin_new(). Use a GstPipeline instead if you
89  * want to create a toplevel bin because a normal bin doesn't have a bus or
90  * handle clock distribution of its own.
91  * After the bin has been created you will typically add elements to it with
92  * gst_bin_add(). You can remove elements with gst_bin_remove().
93  * An element can be retrieved from a bin with gst_bin_get_by_name(), using the
94  * elements name. gst_bin_get_by_name_recurse_up() is mainly used for internal
95  * purposes and will query the parent bins when the element is not found in the
96  * current bin.
97  * An iterator of elements in a bin can be retrieved with
98  * gst_bin_iterate_elements(). Various other iterators exist to retrieve the
99  * elements in a bin.
100  * gst_object_unref() is used to drop your reference to the bin.
101  * The element-added signal is
102  * fired whenever a new element is added to the bin. Likewise the element-removed signal is fired
103  * whenever an element is removed from the bin.
104  * Notes
105  * A GstBin internally intercepts every GstMessage posted by its children and
106  * implements the following default behaviour for each of them:
107  * GST_MESSAGE_EOS
108  * This message is only posted by sinks in the PLAYING
109  *  state. If all sinks posted the EOS message, this bin will post and EOS
110  *  message upwards.
111  * GST_MESSAGE_SEGMENT_START
112  * just collected and never forwarded upwards.
113  *  The messages are used to decide when all elements have completed playback
114  *  of their segment.
115  * GST_MESSAGE_SEGMENT_DONE
116  *  Is posted by GstBin when all elements that posted
117  *  a SEGMENT_START have posted a SEGMENT_DONE.
118  * GST_MESSAGE_DURATION
119  *  Is posted by an element that detected a change
120  *  in the stream duration. The default bin behaviour is to clear any
121  *  cached duration values so that the next duration query will perform
122  *  a full duration recalculation. The duration change is posted to the
123  *  application so that it can refetch the new duration with a duration
124  *  query.
125  * GST_MESSAGE_CLOCK_LOST
126  *  This message is posted by an element when it
127  *  can no longer provide a clock. The default bin behaviour is to
128  *  check if the lost clock was the one provided by the bin. If so and
129  *  the bin is currently in the PLAYING state, the message is forwarded to
130  *  the bin parent.
131  *  This message is also generated when a clock provider is removed from
132  *  the bin. If this message is received by the application, it should
133  *  PAUSE the pipeline and set it back to PLAYING to force a new clock
134  *  distribution.
135  * GST_MESSAGE_CLOCK_PROVIDE
136  *  This message is generated when an element
137  *  can provide a clock. This mostly happens when a new clock
138  *  provider is added to the bin. The default behaviour of the bin is to
139  *  mark the currently selected clock as dirty, which will perform a clock
140  *  recalculation the next time the bin is asked to provide a clock.
141  *  This message is never sent tot the application but is forwarded to
142  *  the parent of the bin.
143  * OTHERS
144  *  posted upwards.
145  * A GstBin implements the following default behaviour for answering to a
146  * GstQuery:
147  * GST_QUERY_DURATION
148  * If the query has been asked before with the same format
149  *  and the bin is a toplevel bin (ie. has no parent),
150  *  use the cached previous value. If no previous value was cached, the
151  *  query is sent to all sink elements in the bin and the MAXIMUM of all
152  *  values is returned. If the bin is a toplevel bin the value is cached.
153  *  If no sinks are available in the bin, the query fails.
154  * GST_QUERY_POSITION
155  * The query is sent to all sink elements in the bin and the
156  *  MAXIMUM of all values is returned. If no sinks are available in the bin,
157  *  the query fails.
158  * OTHERS
159  * the query is forwarded to all sink elements, the result
160  *  of the first sink that answers the query successfully is returned. If no
161  *  sink is in the bin, the query fails.
162  * A GstBin will by default forward any event sent to it to all sink elements.
163  * If all the sinks return TRUE, the bin will also return TRUE, else FALSE is
164  * returned. If no sinks are in the bin, the event handler will return TRUE.
165  * Last reviewed on 2006-04-28 (0.10.6)
166  */
167 public class Bin : Element
168 {
169 	
170 	/** the main Gtk struct */
171 	protected GstBin* gstBin;
172 	
173 	
174 	public GstBin* getBinStruct()
175 	{
176 		return gstBin;
177 	}
178 	
179 	
180 	/** the main Gtk struct as a void* */
181 	protected override void* getStruct()
182 	{
183 		return cast(void*)gstBin;
184 	}
185 	
186 	/**
187 	 * Sets our main struct and passes it to the parent class
188 	 */
189 	public this (GstBin* gstBin)
190 	{
191 		super(cast(GstElement*)gstBin);
192 		this.gstBin = gstBin;
193 	}
194 	
195 	protected override void setStruct(GObject* obj)
196 	{
197 		super.setStruct(obj);
198 		gstBin = cast(GstBin*)obj;
199 	}
200 	
201 	/** */
202 	public this(Element elem)
203 	{
204 		super( elem.getElementStruct() );
205 		this.gstBin = cast(GstBin*)elem.getElementStruct();
206 	}
207 	
208 	/**
209 	 */
210 	int[string] connectedSignals;
211 	
212 	void delegate(Element, Bin)[] onElementAddedListeners;
213 	/**
214 	 * Will be emitted after the element was added to the bin.
215 	 */
216 	void addOnElementAdded(void delegate(Element, Bin) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
217 	{
218 		if ( !("element-added" in connectedSignals) )
219 		{
220 			Signals.connectData(
221 			getStruct(),
222 			"element-added",
223 			cast(GCallback)&callBackElementAdded,
224 			cast(void*)this,
225 			null,
226 			connectFlags);
227 			connectedSignals["element-added"] = 1;
228 		}
229 		onElementAddedListeners ~= dlg;
230 	}
231 	extern(C) static void callBackElementAdded(GstBin* binStruct, GstElement* element, Bin _bin)
232 	{
233 		foreach ( void delegate(Element, Bin) dlg ; _bin.onElementAddedListeners )
234 		{
235 			dlg(ObjectG.getDObject!(Element)(element), _bin);
236 		}
237 	}
238 	
239 	void delegate(Element, Bin)[] onElementRemovedListeners;
240 	/**
241 	 * Will be emitted after the element was removed from the bin.
242 	 */
243 	void addOnElementRemoved(void delegate(Element, Bin) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
244 	{
245 		if ( !("element-removed" in connectedSignals) )
246 		{
247 			Signals.connectData(
248 			getStruct(),
249 			"element-removed",
250 			cast(GCallback)&callBackElementRemoved,
251 			cast(void*)this,
252 			null,
253 			connectFlags);
254 			connectedSignals["element-removed"] = 1;
255 		}
256 		onElementRemovedListeners ~= dlg;
257 	}
258 	extern(C) static void callBackElementRemoved(GstBin* binStruct, GstElement* element, Bin _bin)
259 	{
260 		foreach ( void delegate(Element, Bin) dlg ; _bin.onElementRemovedListeners )
261 		{
262 			dlg(ObjectG.getDObject!(Element)(element), _bin);
263 		}
264 	}
265 	
266 	
267 	/**
268 	 * Creates a new bin with the given name.
269 	 * Params:
270 	 * name = the name of the new bin
271 	 * Throws: ConstructionException GTK+ fails to create the object.
272 	 */
273 	public this (string name)
274 	{
275 		// GstElement* gst_bin_new (const gchar *name);
276 		auto p = gst_bin_new(Str.toStringz(name));
277 		if(p is null)
278 		{
279 			throw new ConstructionException("null returned by gst_bin_new(Str.toStringz(name))");
280 		}
281 		this(cast(GstBin*) p);
282 	}
283 	
284 	/**
285 	 * Adds the given element to the bin. Sets the element's parent, and thus
286 	 * takes ownership of the element. An element can only be added to one bin.
287 	 * If the element's pads are linked to other pads, the pads will be unlinked
288 	 * before the element is added to the bin.
289 	 * MT safe.
290 	 * Params:
291 	 * element = the GstElement to add
292 	 * Returns: TRUE if the element could be added, FALSE if the bin does not want to accept the element.
293 	 */
294 	public int add(Element element)
295 	{
296 		// gboolean gst_bin_add (GstBin *bin,  GstElement *element);
297 		return gst_bin_add(gstBin, (element is null) ? null : element.getElementStruct());
298 	}
299 	
300 	/**
301 	 * Removes the element from the bin, unparenting it as well.
302 	 * Unparenting the element means that the element will be dereferenced,
303 	 * so if the bin holds the only reference to the element, the element
304 	 * will be freed in the process of removing it from the bin. If you
305 	 * want the element to still exist after removing, you need to call
306 	 * gst_object_ref() before removing it from the bin.
307 	 * If the element's pads are linked to other pads, the pads will be unlinked
308 	 * before the element is removed from the bin.
309 	 * MT safe.
310 	 * Params:
311 	 * element = the GstElement to remove
312 	 * Returns: TRUE if the element could be removed, FALSE if the bin does not want to remove the element.
313 	 */
314 	public int remove(Element element)
315 	{
316 		// gboolean gst_bin_remove (GstBin *bin,  GstElement *element);
317 		return gst_bin_remove(gstBin, (element is null) ? null : element.getElementStruct());
318 	}
319 	
320 	/**
321 	 * Gets the element with the given name from a bin. This
322 	 * function recurses into child bins.
323 	 * Returns NULL if no element with the given name is found in the bin.
324 	 * MT safe. Caller owns returned reference.
325 	 * Params:
326 	 * name = the element name to search for
327 	 * Returns: the GstElement with the given name, or NULL
328 	 */
329 	public Element getByName(string name)
330 	{
331 		// GstElement* gst_bin_get_by_name (GstBin *bin,  const gchar *name);
332 		auto p = gst_bin_get_by_name(gstBin, Str.toStringz(name));
333 		
334 		if(p is null)
335 		{
336 			return null;
337 		}
338 		
339 		return ObjectG.getDObject!(Element)(cast(GstElement*) p);
340 	}
341 	
342 	/**
343 	 * Gets the element with the given name from this bin. If the
344 	 * element is not found, a recursion is performed on the parent bin.
345 	 * Params:
346 	 * name = the element name to search for
347 	 * Returns: the GstElement with the given name, or NULL
348 	 */
349 	public Element getByNameRecurseUp(string name)
350 	{
351 		// GstElement* gst_bin_get_by_name_recurse_up (GstBin *bin,  const gchar *name);
352 		auto p = gst_bin_get_by_name_recurse_up(gstBin, Str.toStringz(name));
353 		
354 		if(p is null)
355 		{
356 			return null;
357 		}
358 		
359 		return ObjectG.getDObject!(Element)(cast(GstElement*) p);
360 	}
361 	
362 	/**
363 	 * Looks for an element inside the bin that implements the given
364 	 * interface. If such an element is found, it returns the element.
365 	 * You can cast this element to the given interface afterwards. If you want
366 	 * all elements that implement the interface, use
367 	 * gst_bin_iterate_all_by_interface(). This function recurses into child bins.
368 	 * MT safe. Caller owns returned reference.
369 	 * Params:
370 	 * iface = the GType of an interface
371 	 * Returns: A GstElement inside the bin implementing the interface
372 	 */
373 	public Element getByInterface(GType iface)
374 	{
375 		// GstElement* gst_bin_get_by_interface (GstBin *bin,  GType iface);
376 		auto p = gst_bin_get_by_interface(gstBin, iface);
377 		
378 		if(p is null)
379 		{
380 			return null;
381 		}
382 		
383 		return ObjectG.getDObject!(Element)(cast(GstElement*) p);
384 	}
385 	
386 	/**
387 	 * Gets an iterator for the elements in this bin.
388 	 * Each element yielded by the iterator will have its refcount increased, so
389 	 * unref after use.
390 	 * MT safe. Caller owns returned value.
391 	 * Returns: a GstIterator of GstElement, or NULL
392 	 */
393 	public Iterator iterateElements()
394 	{
395 		// GstIterator* gst_bin_iterate_elements (GstBin *bin);
396 		auto p = gst_bin_iterate_elements(gstBin);
397 		
398 		if(p is null)
399 		{
400 			return null;
401 		}
402 		
403 		return ObjectG.getDObject!(Iterator)(cast(GstIterator*) p);
404 	}
405 	
406 	/**
407 	 * Gets an iterator for the elements in this bin.
408 	 * This iterator recurses into GstBin children.
409 	 * Each element yielded by the iterator will have its refcount increased, so
410 	 * unref after use.
411 	 * MT safe. Caller owns returned value.
412 	 * Returns: a GstIterator of GstElement, or NULL
413 	 */
414 	public Iterator iterateRecurse()
415 	{
416 		// GstIterator* gst_bin_iterate_recurse (GstBin *bin);
417 		auto p = gst_bin_iterate_recurse(gstBin);
418 		
419 		if(p is null)
420 		{
421 			return null;
422 		}
423 		
424 		return ObjectG.getDObject!(Iterator)(cast(GstIterator*) p);
425 	}
426 	
427 	/**
428 	 * Gets an iterator for all elements in the bin that have the
429 	 * GST_ELEMENT_IS_SINK flag set.
430 	 * Each element yielded by the iterator will have its refcount increased, so
431 	 * unref after use.
432 	 * MT safe. Caller owns returned value.
433 	 * Returns: a GstIterator of GstElement, or NULL
434 	 */
435 	public Iterator iterateSinks()
436 	{
437 		// GstIterator* gst_bin_iterate_sinks (GstBin *bin);
438 		auto p = gst_bin_iterate_sinks(gstBin);
439 		
440 		if(p is null)
441 		{
442 			return null;
443 		}
444 		
445 		return ObjectG.getDObject!(Iterator)(cast(GstIterator*) p);
446 	}
447 	
448 	/**
449 	 * Gets an iterator for the elements in this bin in topologically
450 	 * sorted order. This means that the elements are returned from
451 	 * the most downstream elements (sinks) to the sources.
452 	 * This function is used internally to perform the state changes
453 	 * of the bin elements.
454 	 * Each element yielded by the iterator will have its refcount increased, so
455 	 * unref after use.
456 	 * MT safe. Caller owns returned value.
457 	 * Returns: a GstIterator of GstElement, or NULL
458 	 */
459 	public Iterator iterateSorted()
460 	{
461 		// GstIterator* gst_bin_iterate_sorted (GstBin *bin);
462 		auto p = gst_bin_iterate_sorted(gstBin);
463 		
464 		if(p is null)
465 		{
466 			return null;
467 		}
468 		
469 		return ObjectG.getDObject!(Iterator)(cast(GstIterator*) p);
470 	}
471 	
472 	/**
473 	 * Gets an iterator for all elements in the bin that have no sinkpads and have
474 	 * the GST_ELEMENT_IS_SINK flag unset.
475 	 * Each element yielded by the iterator will have its refcount increased, so
476 	 * unref after use.
477 	 * MT safe. Caller owns returned value.
478 	 * Returns: a GstIterator of GstElement, or NULL
479 	 */
480 	public Iterator iterateSources()
481 	{
482 		// GstIterator* gst_bin_iterate_sources (GstBin *bin);
483 		auto p = gst_bin_iterate_sources(gstBin);
484 		
485 		if(p is null)
486 		{
487 			return null;
488 		}
489 		
490 		return ObjectG.getDObject!(Iterator)(cast(GstIterator*) p);
491 	}
492 	
493 	/**
494 	 * Looks for all elements inside the bin that implements the given
495 	 * interface. You can safely cast all returned elements to the given interface.
496 	 * The function recurses inside child bins. The iterator will yield a series
497 	 * of GstElement that should be unreffed after use.
498 	 * Each element yielded by the iterator will have its refcount increased, so
499 	 * unref after use.
500 	 * MT safe. Caller owns returned value.
501 	 * Params:
502 	 * iface = the GType of an interface
503 	 * Returns: a GstIterator of GstElement for all elements in the bin implementing the given interface, or NULL
504 	 */
505 	public Iterator iterateAllByInterface(GType iface)
506 	{
507 		// GstIterator* gst_bin_iterate_all_by_interface (GstBin *bin,  GType iface);
508 		auto p = gst_bin_iterate_all_by_interface(gstBin, iface);
509 		
510 		if(p is null)
511 		{
512 			return null;
513 		}
514 		
515 		return ObjectG.getDObject!(Iterator)(cast(GstIterator*) p);
516 	}
517 	
518 	/**
519 	 * Recursively looks for elements with an unconnected pad of the given
520 	 * direction within the specified bin and returns an unconnected pad
521 	 * if one is found, or NULL otherwise. If a pad is found, the caller
522 	 * owns a reference to it and should use gst_object_unref() on the
523 	 * pad when it is not needed any longer.
524 	 * Params:
525 	 * direction = whether to look for an unconnected source or sink pad
526 	 * Returns: unconnected pad of the given direction, or NULL. Since 0.10.3
527 	 */
528 	public Pad findUnconnectedPad(GstPadDirection direction)
529 	{
530 		// GstPad* gst_bin_find_unconnected_pad (GstBin *bin,  GstPadDirection direction);
531 		auto p = gst_bin_find_unconnected_pad(gstBin, direction);
532 		
533 		if(p is null)
534 		{
535 			return null;
536 		}
537 		
538 		return ObjectG.getDObject!(Pad)(cast(GstPad*) p);
539 	}
540 }