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.ObjectGst;
26 
27 private import glib.ErrorG;
28 private import glib.ListG;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gobject.ParamSpec;
32 private import gobject.Signals;
33 private import gobject.Value;
34 private import gstreamer.ControlBinding;
35 private import gstreamerc.gstreamer;
36 public  import gstreamerc.gstreamertypes;
37 public  import gtkc.gdktypes;
38 
39 
40 /**
41  * #GstObject provides a root for the object hierarchy tree filed in by the
42  * GStreamer library.  It is currently a thin wrapper on top of
43  * #GInitiallyUnowned. It is an abstract class that is not very usable on its own.
44  * 
45  * #GstObject gives us basic refcounting, parenting functionality and locking.
46  * Most of the functions are just extended for special GStreamer needs and can be
47  * found under the same name in the base class of #GstObject which is #GObject
48  * (e.g. g_object_ref() becomes gst_object_ref()).
49  * 
50  * Since #GstObject derives from #GInitiallyUnowned, it also inherits the
51  * floating reference. Be aware that functions such as gst_bin_add() and
52  * gst_element_add_pad() take ownership of the floating reference.
53  * 
54  * In contrast to #GObject instances, #GstObject adds a name property. The functions
55  * gst_object_set_name() and gst_object_get_name() are used to set/get the name
56  * of the object.
57  * 
58  * <refsect2>
59  * <title>controlled properties</title>
60  * <para>
61  * Controlled properties offers a lightweight way to adjust gobject properties
62  * over stream-time. It works by using time-stamped value pairs that are queued
63  * for element-properties. At run-time the elements continuously pull value
64  * changes for the current stream-time.
65  * 
66  * What needs to be changed in a #GstElement?
67  * Very little - it is just two steps to make a plugin controllable!
68  * <orderedlist>
69  * <listitem><para>
70  * mark gobject-properties paramspecs that make sense to be controlled,
71  * by GST_PARAM_CONTROLLABLE.
72  * </para></listitem>
73  * <listitem><para>
74  * when processing data (get, chain, loop function) at the beginning call
75  * gst_object_sync_values(element,timestamp).
76  * This will make the controller update all GObject properties that are
77  * under its control with the current values based on the timestamp.
78  * </para></listitem>
79  * </orderedlist>
80  * 
81  * What needs to be done in applications?
82  * Again it's not a lot to change.
83  * <orderedlist>
84  * <listitem><para>
85  * create a #GstControlSource.
86  * csource = gst_interpolation_control_source_new ();
87  * g_object_set (csource, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
88  * </para></listitem>
89  * <listitem><para>
90  * Attach the #GstControlSource on the controller to a property.
91  * gst_object_add_control_binding (object, gst_direct_control_binding_new (object, "prop1", csource));
92  * </para></listitem>
93  * <listitem><para>
94  * Set the control values
95  * gst_timed_value_control_source_set ((GstTimedValueControlSource *)csource,0 * GST_SECOND, value1);
96  * gst_timed_value_control_source_set ((GstTimedValueControlSource *)csource,1 * GST_SECOND, value2);
97  * </para></listitem>
98  * <listitem><para>
99  * start your pipeline
100  * </para></listitem>
101  * </orderedlist>
102  * </para>
103  * </refsect2>
104  */
105 public class ObjectGst : ObjectG
106 {
107 	/** the main Gtk struct */
108 	protected GstObject* gstObject;
109 
110 	/** Get the main Gtk struct */
111 	public GstObject* getObjectGstStruct()
112 	{
113 		return gstObject;
114 	}
115 
116 	/** the main Gtk struct as a void* */
117 	protected override void* getStruct()
118 	{
119 		return cast(void*)gstObject;
120 	}
121 
122 	protected override void setStruct(GObject* obj)
123 	{
124 		gstObject = cast(GstObject*)obj;
125 		super.setStruct(obj);
126 	}
127 
128 	/**
129 	 * Sets our main struct and passes it to the parent class.
130 	 */
131 	public this (GstObject* gstObject, bool ownedRef = false)
132 	{
133 		this.gstObject = gstObject;
134 		super(cast(GObject*)gstObject, ownedRef);
135 	}
136 
137 	/**
138 	 */
139 
140 	public static GType getType()
141 	{
142 		return gst_object_get_type();
143 	}
144 
145 	/**
146 	 * Checks to see if there is any object named @name in @list. This function
147 	 * does not do any locking of any kind. You might want to protect the
148 	 * provided list with the lock of the owner of the list. This function
149 	 * will lock each #GstObject in the list to compare the name, so be
150 	 * careful when passing a list with a locked object.
151 	 *
152 	 * Params:
153 	 *     list = a list of #GstObject to
154 	 *         check through
155 	 *     name = the name to search for
156 	 *
157 	 * Return: %TRUE if a #GstObject named @name does not appear in @list,
158 	 *     %FALSE if it does.
159 	 *
160 	 *     MT safe. Grabs and releases the LOCK of each object in the list.
161 	 */
162 	public static bool checkUniqueness(ListG list, string name)
163 	{
164 		return gst_object_check_uniqueness((list is null) ? null : list.getListGStruct(), Str.toStringz(name)) != 0;
165 	}
166 
167 	/**
168 	 * A default deep_notify signal callback for an object. The user data
169 	 * should contain a pointer to an array of strings that should be excluded
170 	 * from the notify. The default handler will print the new value of the property
171 	 * using g_print.
172 	 *
173 	 * MT safe. This function grabs and releases @object's LOCK for getting its
174 	 * path string.
175 	 *
176 	 * Params:
177 	 *     object = the #GObject that signalled the notify.
178 	 *     orig = a #GstObject that initiated the notify.
179 	 *     pspec = a #GParamSpec of the property.
180 	 *     excludedProps = a set of user-specified properties to exclude or %NULL to show
181 	 *         all changes.
182 	 */
183 	public static void defaultDeepNotify(ObjectG object, ObjectGst orig, ParamSpec pspec, string[] excludedProps)
184 	{
185 		gst_object_default_deep_notify((object is null) ? null : object.getObjectGStruct(), (orig is null) ? null : orig.getObjectGstStruct(), (pspec is null) ? null : pspec.getParamSpecStruct(), Str.toStringzArray(excludedProps));
186 	}
187 
188 	/**
189 	 * Increase the reference count of @object, and possibly remove the floating
190 	 * reference, if @object has a floating reference.
191 	 *
192 	 * In other words, if the object is floating, then this call "assumes ownership"
193 	 * of the floating reference, converting it to a normal reference by clearing
194 	 * the floating flag while leaving the reference count unchanged. If the object
195 	 * is not floating, then this call adds a new normal reference increasing the
196 	 * reference count by one.
197 	 *
198 	 * Params:
199 	 *     object = a #GstObject to sink
200 	 */
201 	public static void* refSink(void* object)
202 	{
203 		return gst_object_ref_sink(object);
204 	}
205 
206 	/**
207 	 * Atomically modifies a pointer to point to a new object.
208 	 * The reference count of @oldobj is decreased and the reference count of
209 	 * @newobj is increased.
210 	 *
211 	 * Either @newobj and the value pointed to by @oldobj may be %NULL.
212 	 *
213 	 * Params:
214 	 *     oldobj = pointer to a place of
215 	 *         a #GstObject to replace
216 	 *     newobj = a new #GstObject
217 	 *
218 	 * Return: %TRUE if @newobj was different from @oldobj
219 	 */
220 	public static bool replace(ref ObjectGst oldobj, ObjectGst newobj)
221 	{
222 		GstObject* outoldobj = oldobj.getObjectGstStruct();
223 		
224 		auto p = gst_object_replace(&outoldobj, (newobj is null) ? null : newobj.getObjectGstStruct()) != 0;
225 		
226 		oldobj = ObjectG.getDObject!(ObjectGst)(outoldobj);
227 		
228 		return p;
229 	}
230 
231 	/**
232 	 * Attach the #GstControlBinding to the object. If there already was a
233 	 * #GstControlBinding for this property it will be replaced.
234 	 *
235 	 * The @object will take ownership of the @binding.
236 	 *
237 	 * Params:
238 	 *     binding = the #GstControlBinding that should be used
239 	 *
240 	 * Return: %FALSE if the given @binding has not been setup for this object or
241 	 *     has been setup for a non suitable property, %TRUE otherwise.
242 	 */
243 	public bool addControlBinding(ControlBinding binding)
244 	{
245 		return gst_object_add_control_binding(gstObject, (binding is null) ? null : binding.getControlBindingStruct()) != 0;
246 	}
247 
248 	/**
249 	 * A default error function that uses g_printerr() to display the error message
250 	 * and the optional debug sting..
251 	 *
252 	 * The default handler will simply print the error string using g_print.
253 	 *
254 	 * Params:
255 	 *     error = the GError.
256 	 *     dbg = an additional debug information string, or %NULL
257 	 */
258 	public void defaultError(ErrorG error, string dbg)
259 	{
260 		gst_object_default_error(gstObject, (error is null) ? null : error.getErrorGStruct(), Str.toStringz(dbg));
261 	}
262 
263 	/**
264 	 * Gets the corresponding #GstControlBinding for the property. This should be
265 	 * unreferenced again after use.
266 	 *
267 	 * Params:
268 	 *     propertyName = name of the property
269 	 *
270 	 * Return: the #GstControlBinding for
271 	 *     @property_name or %NULL if the property is not controlled.
272 	 */
273 	public ControlBinding getControlBinding(string propertyName)
274 	{
275 		auto p = gst_object_get_control_binding(gstObject, Str.toStringz(propertyName));
276 		
277 		if(p is null)
278 		{
279 			return null;
280 		}
281 		
282 		return ObjectG.getDObject!(ControlBinding)(cast(GstControlBinding*) p, true);
283 	}
284 
285 	/**
286 	 * Obtain the control-rate for this @object. Audio processing #GstElement
287 	 * objects will use this rate to sub-divide their processing loop and call
288 	 * gst_object_sync_values() inbetween. The length of the processing segment
289 	 * should be up to @control-rate nanoseconds.
290 	 *
291 	 * If the @object is not under property control, this will return
292 	 * %GST_CLOCK_TIME_NONE. This allows the element to avoid the sub-dividing.
293 	 *
294 	 * The control-rate is not expected to change if the element is in
295 	 * %GST_STATE_PAUSED or %GST_STATE_PLAYING.
296 	 *
297 	 * Return: the control rate in nanoseconds
298 	 */
299 	public GstClockTime getControlRate()
300 	{
301 		return gst_object_get_control_rate(gstObject);
302 	}
303 
304 	/**
305 	 * Gets a number of #GValues for the given controlled property starting at the
306 	 * requested time. The array @values need to hold enough space for @n_values of
307 	 * #GValue.
308 	 *
309 	 * This function is useful if one wants to e.g. draw a graph of the control
310 	 * curve or apply a control curve sample by sample.
311 	 *
312 	 * Params:
313 	 *     propertyName = the name of the property to get
314 	 *     timestamp = the time that should be processed
315 	 *     interval = the time spacing between subsequent values
316 	 *     nValues = the number of values
317 	 *     values = array to put control-values in
318 	 *
319 	 * Return: %TRUE if the given array could be filled, %FALSE otherwise
320 	 */
321 	public bool getGValueArray(string propertyName, GstClockTime timestamp, GstClockTime interval, uint nValues, Value values)
322 	{
323 		return gst_object_get_g_value_array(gstObject, Str.toStringz(propertyName), timestamp, interval, nValues, (values is null) ? null : values.getValueStruct()) != 0;
324 	}
325 
326 	/**
327 	 * Returns a copy of the name of @object.
328 	 * Caller should g_free() the return value after usage.
329 	 * For a nameless object, this returns %NULL, which you can safely g_free()
330 	 * as well.
331 	 *
332 	 * Free-function: g_free
333 	 *
334 	 * Return: the name of @object. g_free()
335 	 *     after usage.
336 	 *
337 	 *     MT safe. This function grabs and releases @object's LOCK.
338 	 */
339 	public string getName()
340 	{
341 		return Str.toString(gst_object_get_name(gstObject));
342 	}
343 
344 	/**
345 	 * Returns the parent of @object. This function increases the refcount
346 	 * of the parent object so you should gst_object_unref() it after usage.
347 	 *
348 	 * Return: parent of @object, this can be
349 	 *     %NULL if @object has no parent. unref after usage.
350 	 *
351 	 *     MT safe. Grabs and releases @object's LOCK.
352 	 */
353 	public ObjectGst getParent()
354 	{
355 		auto p = gst_object_get_parent(gstObject);
356 		
357 		if(p is null)
358 		{
359 			return null;
360 		}
361 		
362 		return ObjectG.getDObject!(ObjectGst)(cast(GstObject*) p, true);
363 	}
364 
365 	/**
366 	 * Generates a string describing the path of @object in
367 	 * the object hierarchy. Only useful (or used) for debugging.
368 	 *
369 	 * Free-function: g_free
370 	 *
371 	 * Return: a string describing the path of @object. You must
372 	 *     g_free() the string after usage.
373 	 *
374 	 *     MT safe. Grabs and releases the #GstObject's LOCK for all objects
375 	 *     in the hierarchy.
376 	 */
377 	public string getPathString()
378 	{
379 		return Str.toString(gst_object_get_path_string(gstObject));
380 	}
381 
382 	/**
383 	 * Gets the value for the given controlled property at the requested time.
384 	 *
385 	 * Params:
386 	 *     propertyName = the name of the property to get
387 	 *     timestamp = the time the control-change should be read from
388 	 *
389 	 * Return: the GValue of the property at the given time,
390 	 *     or %NULL if the property isn't controlled.
391 	 */
392 	public Value getValue(string propertyName, GstClockTime timestamp)
393 	{
394 		auto p = gst_object_get_value(gstObject, Str.toStringz(propertyName), timestamp);
395 		
396 		if(p is null)
397 		{
398 			return null;
399 		}
400 		
401 		return ObjectG.getDObject!(Value)(cast(GValue*) p);
402 	}
403 
404 	/**
405 	 * Gets a number of values for the given controlled property starting at the
406 	 * requested time. The array @values need to hold enough space for @n_values of
407 	 * the same type as the objects property's type.
408 	 *
409 	 * This function is useful if one wants to e.g. draw a graph of the control
410 	 * curve or apply a control curve sample by sample.
411 	 *
412 	 * The values are unboxed and ready to be used. The similar function
413 	 * gst_object_get_g_value_array() returns the array as #GValues and is
414 	 * better suites for bindings.
415 	 *
416 	 * Params:
417 	 *     propertyName = the name of the property to get
418 	 *     timestamp = the time that should be processed
419 	 *     interval = the time spacing between subsequent values
420 	 *     nValues = the number of values
421 	 *     values = array to put control-values in
422 	 *
423 	 * Return: %TRUE if the given array could be filled, %FALSE otherwise
424 	 */
425 	public bool getValueArray(string propertyName, GstClockTime timestamp, GstClockTime interval, uint nValues, void* values)
426 	{
427 		return gst_object_get_value_array(gstObject, Str.toStringz(propertyName), timestamp, interval, nValues, values) != 0;
428 	}
429 
430 	/**
431 	 * Check if the @object has an active controlled properties.
432 	 *
433 	 * Return: %TRUE if the object has active controlled properties
434 	 */
435 	public bool hasActiveControlBindings()
436 	{
437 		return gst_object_has_active_control_bindings(gstObject) != 0;
438 	}
439 
440 	/**
441 	 * Check if @object has an ancestor @ancestor somewhere up in
442 	 * the hierarchy. One can e.g. check if a #GstElement is inside a #GstPipeline.
443 	 *
444 	 * Params:
445 	 *     ancestor = a #GstObject to check as ancestor
446 	 *
447 	 * Return: %TRUE if @ancestor is an ancestor of @object.
448 	 *
449 	 *     MT safe. Grabs and releases @object's locks.
450 	 */
451 	public bool hasAncestor(ObjectGst ancestor)
452 	{
453 		return gst_object_has_ancestor(gstObject, (ancestor is null) ? null : ancestor.getObjectGstStruct()) != 0;
454 	}
455 
456 	/**
457 	 * Increments the reference count on @object. This function
458 	 * does not take the lock on @object because it relies on
459 	 * atomic refcounting.
460 	 *
461 	 * This object returns the input parameter to ease writing
462 	 * constructs like :
463 	 * result = gst_object_ref (object->parent);
464 	 *
465 	 * Return: A pointer to @object
466 	 */
467 	public override ObjectGst doref()
468 	{
469 		auto p = gst_object_ref(gstObject);
470 		
471 		if(p is null)
472 		{
473 			return null;
474 		}
475 		
476 		return ObjectG.getDObject!(ObjectGst)(cast(GstObject*) p, true);
477 	}
478 
479 	/**
480 	 * Removes the corresponding #GstControlBinding. If it was the
481 	 * last ref of the binding, it will be disposed.
482 	 *
483 	 * Params:
484 	 *     binding = the binding
485 	 *
486 	 * Return: %TRUE if the binding could be removed.
487 	 */
488 	public bool removeControlBinding(ControlBinding binding)
489 	{
490 		return gst_object_remove_control_binding(gstObject, (binding is null) ? null : binding.getControlBindingStruct()) != 0;
491 	}
492 
493 	/**
494 	 * This function is used to disable the control bindings on a property for
495 	 * some time, i.e. gst_object_sync_values() will do nothing for the
496 	 * property.
497 	 *
498 	 * Params:
499 	 *     propertyName = property to disable
500 	 *     disabled = boolean that specifies whether to disable the controller
501 	 *         or not.
502 	 */
503 	public void setControlBindingDisabled(string propertyName, bool disabled)
504 	{
505 		gst_object_set_control_binding_disabled(gstObject, Str.toStringz(propertyName), disabled);
506 	}
507 
508 	/**
509 	 * This function is used to disable all controlled properties of the @object for
510 	 * some time, i.e. gst_object_sync_values() will do nothing.
511 	 *
512 	 * Params:
513 	 *     disabled = boolean that specifies whether to disable the controller
514 	 *         or not.
515 	 */
516 	public void setControlBindingsDisabled(bool disabled)
517 	{
518 		gst_object_set_control_bindings_disabled(gstObject, disabled);
519 	}
520 
521 	/**
522 	 * Change the control-rate for this @object. Audio processing #GstElement
523 	 * objects will use this rate to sub-divide their processing loop and call
524 	 * gst_object_sync_values() inbetween. The length of the processing segment
525 	 * should be up to @control-rate nanoseconds.
526 	 *
527 	 * The control-rate should not change if the element is in %GST_STATE_PAUSED or
528 	 * %GST_STATE_PLAYING.
529 	 *
530 	 * Params:
531 	 *     controlRate = the new control-rate in nanoseconds.
532 	 */
533 	public void setControlRate(GstClockTime controlRate)
534 	{
535 		gst_object_set_control_rate(gstObject, controlRate);
536 	}
537 
538 	/**
539 	 * Sets the name of @object, or gives @object a guaranteed unique
540 	 * name (if @name is %NULL).
541 	 * This function makes a copy of the provided name, so the caller
542 	 * retains ownership of the name it sent.
543 	 *
544 	 * Params:
545 	 *     name = new name of object
546 	 *
547 	 * Return: %TRUE if the name could be set. Since Objects that have
548 	 *     a parent cannot be renamed, this function returns %FALSE in those
549 	 *     cases.
550 	 *
551 	 *     MT safe.  This function grabs and releases @object's LOCK.
552 	 */
553 	public bool setName(string name)
554 	{
555 		return gst_object_set_name(gstObject, Str.toStringz(name)) != 0;
556 	}
557 
558 	/**
559 	 * Sets the parent of @object to @parent. The object's reference count will
560 	 * be incremented, and any floating reference will be removed (see gst_object_ref_sink()).
561 	 *
562 	 * Params:
563 	 *     parent = new parent of object
564 	 *
565 	 * Return: %TRUE if @parent could be set or %FALSE when @object
566 	 *     already had a parent or @object and @parent are the same.
567 	 *
568 	 *     MT safe. Grabs and releases @object's LOCK.
569 	 */
570 	public bool setParent(ObjectGst parent)
571 	{
572 		return gst_object_set_parent(gstObject, (parent is null) ? null : parent.getObjectGstStruct()) != 0;
573 	}
574 
575 	/**
576 	 * Returns a suggestion for timestamps where buffers should be split
577 	 * to get best controller results.
578 	 *
579 	 * Return: Returns the suggested timestamp or %GST_CLOCK_TIME_NONE
580 	 *     if no control-rate was set.
581 	 */
582 	public GstClockTime suggestNextSync()
583 	{
584 		return gst_object_suggest_next_sync(gstObject);
585 	}
586 
587 	/**
588 	 * Sets the properties of the object, according to the #GstControlSources that
589 	 * (maybe) handle them and for the given timestamp.
590 	 *
591 	 * If this function fails, it is most likely the application developers fault.
592 	 * Most probably the control sources are not setup correctly.
593 	 *
594 	 * Params:
595 	 *     timestamp = the time that should be processed
596 	 *
597 	 * Return: %TRUE if the controller values could be applied to the object
598 	 *     properties, %FALSE otherwise
599 	 */
600 	public bool syncValues(GstClockTime timestamp)
601 	{
602 		return gst_object_sync_values(gstObject, timestamp) != 0;
603 	}
604 
605 	/**
606 	 * Clear the parent of @object, removing the associated reference.
607 	 * This function decreases the refcount of @object.
608 	 *
609 	 * MT safe. Grabs and releases @object's lock.
610 	 */
611 	public void unparent()
612 	{
613 		gst_object_unparent(gstObject);
614 	}
615 
616 	/**
617 	 * Decrements the reference count on @object.  If reference count hits
618 	 * zero, destroy @object. This function does not take the lock
619 	 * on @object as it relies on atomic refcounting.
620 	 *
621 	 * The unref method should never be called with the LOCK held since
622 	 * this might deadlock the dispose function.
623 	 */
624 	public override void unref()
625 	{
626 		gst_object_unref(gstObject);
627 	}
628 
629 	int[string] connectedSignals;
630 
631 	void delegate(ObjectGst, ParamSpec, ObjectGst)[] onDeepNotifyListeners;
632 	/**
633 	 * The deep notify signal is used to be notified of property changes. It is
634 	 * typically attached to the toplevel bin to receive notifications from all
635 	 * the elements contained in that bin.
636 	 *
637 	 * Params:
638 	 *     propObject = the object that originated the signal
639 	 *     prop = the property that changed
640 	 */
641 	void addOnDeepNotify(void delegate(ObjectGst, ParamSpec, ObjectGst) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
642 	{
643 		if ( "deep-notify" !in connectedSignals )
644 		{
645 			Signals.connectData(
646 				this,
647 				"deep-notify",
648 				cast(GCallback)&callBackDeepNotify,
649 				cast(void*)this,
650 				null,
651 				connectFlags);
652 			connectedSignals["deep-notify"] = 1;
653 		}
654 		onDeepNotifyListeners ~= dlg;
655 	}
656 	extern(C) static void callBackDeepNotify(GstObject* objectgstStruct, GstObject* propObject, GParamSpec* prop, ObjectGst _objectgst)
657 	{
658 		foreach ( void delegate(ObjectGst, ParamSpec, ObjectGst) dlg; _objectgst.onDeepNotifyListeners )
659 		{
660 			dlg(ObjectG.getDObject!(ObjectGst)(propObject), ObjectG.getDObject!(ParamSpec)(prop), _objectgst);
661 		}
662 	}
663 }