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  = gstreamer-GstCaps.html
27  * outPack = gstreamer
28  * outFile = Caps
29  * strct   = GstCaps
30  * realStrct=
31  * ctorStrct=
32  * clss    = Caps
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_caps_
41  * 	- gst_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * 	- gst_caps_save_thyself
46  * 	- gst_caps_load_thyself
47  * 	- gst_caps_new_any
48  * omit signals:
49  * imports:
50  * 	- glib.Str
51  * 	- gstreamer.Structure
52  * structWrap:
53  * 	- GstCaps* -> Caps
54  * 	- GstStructure* -> Structure
55  * module aliases:
56  * local aliases:
57  * overrides:
58  * 	- toString
59  */
60 
61 module gstreamer.Caps;
62 
63 public  import gstreamerc.gstreamertypes;
64 
65 private import gstreamerc.gstreamer;
66 private import glib.ConstructionException;
67 private import gobject.ObjectG;
68 
69 
70 private import glib.Str;
71 private import gstreamer.Structure;
72 
73 
74 
75 
76 /**
77  * Description
78  * Caps (capabilities) are lighweight refcounted objects describing media types.
79  * They are composed of an array of GstStructure.
80  * Caps are exposed on GstPadTemplate to describe all possible types a
81  * given pad can handle. They are also stored in the GstRegistry along with
82  * a description of the GstElement.
83  * Caps are exposed on the element pads using the gst_pad_get_caps() pad
84  * function. This function describes the possible types that the pad can
85  * handle or produce at runtime.
86  * Caps are also attached to buffers to describe to content of the data
87  * pointed to by the buffer with gst_buffer_set_caps(). Caps attached to
88  * a GstBuffer allow for format negotiation upstream and downstream.
89  * A GstCaps can be constructed with the following code fragment:
90  * $(DDOC_COMMENT example)
91  * A GstCaps is fixed when it has no properties with ranges or lists. Use
92  * gst_caps_is_fixed() to test for fixed caps. Only fixed caps can be
93  * set on a GstPad or GstBuffer.
94  * Various methods exist to work with the media types such as subtracting
95  * or intersecting.
96  * Last reviewed on 2007-02-13 (0.10.10)
97  */
98 public class Caps
99 {
100 	
101 	/** the main Gtk struct */
102 	protected GstCaps* gstCaps;
103 	
104 	
105 	public GstCaps* getCapsStruct()
106 	{
107 		return gstCaps;
108 	}
109 	
110 	
111 	/** the main Gtk struct as a void* */
112 	protected void* getStruct()
113 	{
114 		return cast(void*)gstCaps;
115 	}
116 	
117 	/**
118 	 * Sets our main struct and passes it to the parent class
119 	 */
120 	public this (GstCaps* gstCaps)
121 	{
122 		this.gstCaps = gstCaps;
123 	}
124 	
125 	/**
126 	 * Creates a new GstCaps that indicates that it is compatible with
127 	 * any media format.
128 	 * Returns:
129 	 *  the new GstCaps
130 	 */
131 	public static Caps newAny()
132 	{
133 		// GstCaps* gst_caps_new_any (void);
134 		return new Caps(cast(GstCaps*)gst_caps_new_any() );
135 	}
136 	
137 	/**
138 	 */
139 	
140 	/**
141 	 * Creates a new GstCaps that is empty. That is, the returned
142 	 * GstCaps contains no media formats.
143 	 * Caller is responsible for unreffing the returned caps.
144 	 * Throws: ConstructionException GTK+ fails to create the object.
145 	 */
146 	public this ()
147 	{
148 		// GstCaps* gst_caps_new_empty (void);
149 		auto p = gst_caps_new_empty();
150 		if(p is null)
151 		{
152 			throw new ConstructionException("null returned by gst_caps_new_empty()");
153 		}
154 		this(cast(GstCaps*) p);
155 	}
156 	
157 	/**
158 	 * Creates a new GstCaps and adds all the structures listed as
159 	 * arguments. The list must be NULL-terminated. The structures
160 	 * are not copied; the returned GstCaps owns the structures.
161 	 * Params:
162 	 * structure = the first structure to add
163 	 * varArgs = additional structures to add
164 	 * Throws: ConstructionException GTK+ fails to create the object.
165 	 */
166 	public this (Structure structure, void* varArgs)
167 	{
168 		// GstCaps* gst_caps_new_full_valist (GstStructure *structure,  va_list var_args);
169 		auto p = gst_caps_new_full_valist((structure is null) ? null : structure.getStructureStruct(), varArgs);
170 		if(p is null)
171 		{
172 			throw new ConstructionException("null returned by gst_caps_new_full_valist((structure is null) ? null : structure.getStructureStruct(), varArgs)");
173 		}
174 		this(cast(GstCaps*) p);
175 	}
176 	
177 	/**
178 	 * Creates a new GstCaps as a copy of the old caps. The new caps will have a
179 	 * refcount of 1, owned by the caller. The structures are copied as well.
180 	 * Note that this function is the semantic equivalent of a gst_caps_ref()
181 	 * followed by a gst_caps_make_writable(). If you only want to hold on to a
182 	 * reference to the data, you should use gst_caps_ref().
183 	 * When you are finished with the caps, call gst_caps_unref() on it.
184 	 * Returns: the new GstCaps
185 	 */
186 	public Caps copy()
187 	{
188 		// GstCaps* gst_caps_copy (const GstCaps *caps);
189 		auto p = gst_caps_copy(gstCaps);
190 		
191 		if(p is null)
192 		{
193 			return null;
194 		}
195 		
196 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
197 	}
198 	
199 	/**
200 	 * Creates a new GstCaps and appends a copy of the nth structure
201 	 * contained in caps.
202 	 * Params:
203 	 * nth = the nth structure to copy
204 	 * Returns: the new GstCaps
205 	 */
206 	public Caps copyNth(uint nth)
207 	{
208 		// GstCaps* gst_caps_copy_nth (const GstCaps *caps,  guint nth);
209 		auto p = gst_caps_copy_nth(gstCaps, nth);
210 		
211 		if(p is null)
212 		{
213 			return null;
214 		}
215 		
216 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
217 	}
218 	
219 	/**
220 	 * Converts a GstStaticCaps to a GstCaps.
221 	 * Params:
222 	 * staticCaps = the GstStaticCaps to convert
223 	 * Returns: A pointer to the GstCaps. Unref after usage. Since the core holds an additional ref to the returned caps, use gst_caps_make_writable() on the returned caps to modify it.
224 	 */
225 	public static Caps staticCapsGet(GstStaticCaps* staticCaps)
226 	{
227 		// GstCaps* gst_static_caps_get (GstStaticCaps *static_caps);
228 		auto p = gst_static_caps_get(staticCaps);
229 		
230 		if(p is null)
231 		{
232 			return null;
233 		}
234 		
235 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
236 	}
237 	
238 	/**
239 	 * Appends the structures contained in caps2 to caps1. The structures in
240 	 * caps2 are not copied -- they are transferred to caps1, and then caps2 is
241 	 * freed. If either caps is ANY, the resulting caps will be ANY.
242 	 * Params:
243 	 * caps2 = the GstCaps to append
244 	 */
245 	public void append(Caps caps2)
246 	{
247 		// void gst_caps_append (GstCaps *caps1,  GstCaps *caps2);
248 		gst_caps_append(gstCaps, (caps2 is null) ? null : caps2.getCapsStruct());
249 	}
250 	
251 	/**
252 	 * Appends the structures contained in caps2 to caps1 if they are not yet
253 	 * expressed by caps1. The structures in caps2 are not copied -- they are
254 	 * transferred to caps1, and then caps2 is freed.
255 	 * If either caps is ANY, the resulting caps will be ANY.
256 	 * Params:
257 	 * caps2 = the GstCaps to merge in
258 	 * Since 0.10.10
259 	 */
260 	public void merge(Caps caps2)
261 	{
262 		// void gst_caps_merge (GstCaps *caps1,  GstCaps *caps2);
263 		gst_caps_merge(gstCaps, (caps2 is null) ? null : caps2.getCapsStruct());
264 	}
265 	
266 	/**
267 	 * Appends structure to caps. The structure is not copied; caps
268 	 * becomes the owner of structure.
269 	 * Params:
270 	 * structure = the GstStructure to append
271 	 */
272 	public void appendStructure(Structure structure)
273 	{
274 		// void gst_caps_append_structure (GstCaps *caps,  GstStructure *structure);
275 		gst_caps_append_structure(gstCaps, (structure is null) ? null : structure.getStructureStruct());
276 	}
277 	
278 	/**
279 	 * removes the stucture with the given index from the list of structures
280 	 * contained in caps.
281 	 * Params:
282 	 * idx = Index of the structure to remove
283 	 */
284 	public void removeStructure(uint idx)
285 	{
286 		// void gst_caps_remove_structure (GstCaps *caps,  guint idx);
287 		gst_caps_remove_structure(gstCaps, idx);
288 	}
289 	
290 	/**
291 	 * Appends structure to caps if its not already expressed by caps. The
292 	 * structure is not copied; caps becomes the owner of structure.
293 	 * Params:
294 	 * structure = the GstStructure to merge
295 	 */
296 	public void mergeStructure(Structure structure)
297 	{
298 		// void gst_caps_merge_structure (GstCaps *caps,  GstStructure *structure);
299 		gst_caps_merge_structure(gstCaps, (structure is null) ? null : structure.getStructureStruct());
300 	}
301 	
302 	/**
303 	 * Gets the number of structures contained in caps.
304 	 * Returns: the number of structures that caps contains
305 	 */
306 	public uint getSize()
307 	{
308 		// guint gst_caps_get_size (const GstCaps *caps);
309 		return gst_caps_get_size(gstCaps);
310 	}
311 	
312 	/**
313 	 * Finds the structure in caps that has the index index, and
314 	 * returns it.
315 	 * WARNING: This function takes a const GstCaps *, but returns a
316 	 * non-const GstStructure *. This is for programming convenience --
317 	 * the caller should be aware that structures inside a constant
318 	 * GstCaps should not be modified.
319 	 * Params:
320 	 * index = the index of the structure
321 	 * Returns: a pointer to the GstStructure corresponding to index
322 	 */
323 	public Structure getStructure(uint index)
324 	{
325 		// GstStructure* gst_caps_get_structure (const GstCaps *caps,  guint index);
326 		auto p = gst_caps_get_structure(gstCaps, index);
327 		
328 		if(p is null)
329 		{
330 			return null;
331 		}
332 		
333 		return ObjectG.getDObject!(Structure)(cast(GstStructure*) p);
334 	}
335 	
336 	/**
337 	 * Sets fields in a simple GstCaps. A simple GstCaps is one that
338 	 * only has one structure. The arguments must be passed in the same
339 	 * manner as gst_structure_set(), and be NULL-terminated.
340 	 * Params:
341 	 * field = first field to set
342 	 * varargs = additional parameters
343 	 */
344 	public void setSimpleValist(string field, void* varargs)
345 	{
346 		// void gst_caps_set_simple_valist (GstCaps *caps,  char *field,  va_list varargs);
347 		gst_caps_set_simple_valist(gstCaps, Str.toStringz(field), varargs);
348 	}
349 	
350 	/**
351 	 * Determines if caps represents any media format.
352 	 * Returns: TRUE if caps represents any format.
353 	 */
354 	public int isAny()
355 	{
356 		// gboolean gst_caps_is_any (const GstCaps *caps);
357 		return gst_caps_is_any(gstCaps);
358 	}
359 	
360 	/**
361 	 * Determines if caps represents no media formats.
362 	 * Returns: TRUE if caps represents no formats.
363 	 */
364 	public int isEmpty()
365 	{
366 		// gboolean gst_caps_is_empty (const GstCaps *caps);
367 		return gst_caps_is_empty(gstCaps);
368 	}
369 	
370 	/**
371 	 * Fixed GstCaps describe exactly one format, that is, they have exactly
372 	 * one structure, and each field in the structure describes a fixed type.
373 	 * Examples of non-fixed types are GST_TYPE_INT_RANGE and GST_TYPE_LIST.
374 	 * Returns: TRUE if caps is fixed
375 	 */
376 	public int isFixed()
377 	{
378 		// gboolean gst_caps_is_fixed (const GstCaps *caps);
379 		return gst_caps_is_fixed(gstCaps);
380 	}
381 	
382 	/**
383 	 * Checks if the given caps represent the same set of caps.
384 	 * Note
385 	 * This function does not work reliably if optional properties for caps
386 	 * are included on one caps and omitted on the other.
387 	 * This function deals correctly with passing NULL for any of the caps.
388 	 * Params:
389 	 * caps2 = another GstCaps
390 	 * Returns: TRUE if both caps are equal.
391 	 */
392 	public int isEqual(Caps caps2)
393 	{
394 		// gboolean gst_caps_is_equal (const GstCaps *caps1,  const GstCaps *caps2);
395 		return gst_caps_is_equal(gstCaps, (caps2 is null) ? null : caps2.getCapsStruct());
396 	}
397 	
398 	/**
399 	 * Tests if two GstCaps are equal. This function only works on fixed
400 	 * GstCaps.
401 	 * Params:
402 	 * caps2 = the GstCaps to test
403 	 * Returns: TRUE if the arguments represent the same format
404 	 */
405 	public int isEqualFixed(Caps caps2)
406 	{
407 		// gboolean gst_caps_is_equal_fixed (const GstCaps *caps1,  const GstCaps *caps2);
408 		return gst_caps_is_equal_fixed(gstCaps, (caps2 is null) ? null : caps2.getCapsStruct());
409 	}
410 	
411 	/**
412 	 * A given GstCaps structure is always compatible with another if
413 	 * every media format that is in the first is also contained in the
414 	 * second. That is, caps1 is a subset of caps2.
415 	 * Params:
416 	 * caps2 = the GstCaps to test
417 	 * Returns: TRUE if caps1 is a subset of caps2.
418 	 */
419 	public int isAlwaysCompatible(Caps caps2)
420 	{
421 		// gboolean gst_caps_is_always_compatible (const GstCaps *caps1,  const GstCaps *caps2);
422 		return gst_caps_is_always_compatible(gstCaps, (caps2 is null) ? null : caps2.getCapsStruct());
423 	}
424 	
425 	/**
426 	 * Checks if all caps represented by subset are also represented by superset.
427 	 * Note
428 	 * This function does not work reliably if optional properties for caps
429 	 * are included on one caps and omitted on the other.
430 	 * Params:
431 	 * superset = a potentially greater GstCaps
432 	 * Returns: TRUE if subset is a subset of superset
433 	 */
434 	public int isSubset(Caps superset)
435 	{
436 		// gboolean gst_caps_is_subset (const GstCaps *subset,  const GstCaps *superset);
437 		return gst_caps_is_subset(gstCaps, (superset is null) ? null : superset.getCapsStruct());
438 	}
439 	
440 	/**
441 	 * Creates a new GstCaps that contains all the formats that are common
442 	 * to both caps1 and caps2.
443 	 * Params:
444 	 * caps2 = a GstCaps to intersect
445 	 * Returns: the new GstCaps
446 	 */
447 	public Caps intersect(Caps caps2)
448 	{
449 		// GstCaps* gst_caps_intersect (const GstCaps *caps1,  const GstCaps *caps2);
450 		auto p = gst_caps_intersect(gstCaps, (caps2 is null) ? null : caps2.getCapsStruct());
451 		
452 		if(p is null)
453 		{
454 			return null;
455 		}
456 		
457 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
458 	}
459 	
460 	/**
461 	 * Creates a new GstCaps that contains all the formats that are in
462 	 * either caps1 and caps2.
463 	 * Params:
464 	 * caps2 = a GstCaps to union
465 	 * Returns: the new GstCaps
466 	 */
467 	public Caps unio(Caps caps2)
468 	{
469 		// GstCaps* gst_caps_union (const GstCaps *caps1,  const GstCaps *caps2);
470 		auto p = gst_caps_union(gstCaps, (caps2 is null) ? null : caps2.getCapsStruct());
471 		
472 		if(p is null)
473 		{
474 			return null;
475 		}
476 		
477 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
478 	}
479 	
480 	/**
481 	 * Creates a new GstCaps that represents the same set of formats as
482 	 * caps, but contains no lists. Each list is expanded into separate
483 	 * GstStructures.
484 	 * Returns: the new GstCaps
485 	 */
486 	public Caps normalize()
487 	{
488 		// GstCaps* gst_caps_normalize (const GstCaps *caps);
489 		auto p = gst_caps_normalize(gstCaps);
490 		
491 		if(p is null)
492 		{
493 			return null;
494 		}
495 		
496 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
497 	}
498 	
499 	/**
500 	 * Modifies the given caps inplace into a representation that represents the
501 	 * same set of formats, but in a simpler form. Component structures that are
502 	 * identical are merged. Component structures that have values that can be
503 	 * merged are also merged.
504 	 * Returns: TRUE, if the caps could be simplified
505 	 */
506 	public int doSimplify()
507 	{
508 		// gboolean gst_caps_do_simplify (GstCaps *caps);
509 		return gst_caps_do_simplify(gstCaps);
510 	}
511 	
512 	/**
513 	 * Replaces *caps with newcaps. Unrefs the GstCaps in the location
514 	 * pointed to by caps, if applicable, then modifies caps to point to
515 	 * newcaps. An additional ref on newcaps is taken.
516 	 * This function does not take any locks so you might want to lock
517 	 * the object owning caps pointer.
518 	 * Params:
519 	 * caps = a pointer to GstCaps
520 	 * newcaps = a GstCaps to replace *caps
521 	 */
522 	public static void replace(ref Caps caps, Caps newcaps)
523 	{
524 		// void gst_caps_replace (GstCaps **caps,  GstCaps *newcaps);
525 		GstCaps* outcaps = (caps is null) ? null : caps.getCapsStruct();
526 		
527 		gst_caps_replace(&outcaps, (newcaps is null) ? null : newcaps.getCapsStruct());
528 		
529 		caps = ObjectG.getDObject!(Caps)(outcaps);
530 	}
531 	
532 	/**
533 	 * Converts caps to a string representation. This string representation
534 	 * can be converted back to a GstCaps by gst_caps_from_string().
535 	 * Returns: a newly allocated string representing caps.
536 	 */
537 	public override string toString()
538 	{
539 		// gchar* gst_caps_to_string (const GstCaps *caps);
540 		return Str.toString(gst_caps_to_string(gstCaps));
541 	}
542 	
543 	/**
544 	 * Converts caps from a string representation.
545 	 * Params:
546 	 * string = a string to convert to GstCaps
547 	 * Returns: a newly allocated GstCaps
548 	 */
549 	public static Caps fromString(string string)
550 	{
551 		// GstCaps* gst_caps_from_string (const gchar *string);
552 		auto p = gst_caps_from_string(Str.toStringz(string));
553 		
554 		if(p is null)
555 		{
556 			return null;
557 		}
558 		
559 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
560 	}
561 	
562 	/**
563 	 * Subtracts the subtrahend from the minuend.
564 	 * Note
565 	 * This function does not work reliably if optional properties for caps
566 	 * are included on one caps and omitted on the other.
567 	 * Params:
568 	 * subtrahend = GstCaps to substract
569 	 * Returns: the resulting caps
570 	 */
571 	public Caps subtract(Caps subtrahend)
572 	{
573 		// GstCaps* gst_caps_subtract (const GstCaps *minuend,  const GstCaps *subtrahend);
574 		auto p = gst_caps_subtract(gstCaps, (subtrahend is null) ? null : subtrahend.getCapsStruct());
575 		
576 		if(p is null)
577 		{
578 			return null;
579 		}
580 		
581 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
582 	}
583 	
584 	/**
585 	 * Returns a writable copy of caps.
586 	 * If there is only one reference count on caps, the caller must be the owner,
587 	 * and so this function will return the caps object unchanged. If on the other
588 	 * hand there is more than one reference on the object, a new caps object will
589 	 * be returned. The caller's reference on caps will be removed, and instead the
590 	 * caller will own a reference to the returned object.
591 	 * In short, this function unrefs the caps in the argument and refs the caps
592 	 * that it returns. Don't access the argument after calling this function. See
593 	 * also: gst_caps_ref().
594 	 * Returns: the same GstCaps object.
595 	 */
596 	public Caps makeWritable()
597 	{
598 		// GstCaps* gst_caps_make_writable (GstCaps *caps);
599 		auto p = gst_caps_make_writable(gstCaps);
600 		
601 		if(p is null)
602 		{
603 			return null;
604 		}
605 		
606 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
607 	}
608 	
609 	/**
610 	 * Add a reference to a GstCaps object.
611 	 * From this point on, until the caller calls gst_caps_unref() or
612 	 * gst_caps_make_writable(), it is guaranteed that the caps object will not
613 	 * change. This means its structures won't change, etc. To use a GstCaps
614 	 * object, you must always have a refcount on it -- either the one made
615 	 * implicitly by gst_caps_new(), or via taking one explicitly with this
616 	 * function.
617 	 * Returns: the same GstCaps object.
618 	 */
619 	public Caps doref()
620 	{
621 		// GstCaps* gst_caps_ref (GstCaps *caps);
622 		auto p = gst_caps_ref(gstCaps);
623 		
624 		if(p is null)
625 		{
626 			return null;
627 		}
628 		
629 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
630 	}
631 	
632 	/**
633 	 * Destructively discard all but the first structure from caps. Useful when
634 	 * fixating. caps must be writable.
635 	 */
636 	public void truncate()
637 	{
638 		// void gst_caps_truncate (GstCaps *caps);
639 		gst_caps_truncate(gstCaps);
640 	}
641 	
642 	/**
643 	 * Unref a GstCaps and and free all its structures and the
644 	 * structures' values when the refcount reaches 0.
645 	 */
646 	public void unref()
647 	{
648 		// void gst_caps_unref (GstCaps *caps);
649 		gst_caps_unref(gstCaps);
650 	}
651 }