Next: , Previous: GstBus, Up: Top


5 GstCaps

Structure describing sets of media formats

5.1 Overview

Caps (capabilities) are lighweight refcounted objects describing media types. They are composed of an array of <gst-structure>.

Caps are exposed on <gst-pad-template> to describe all possible types a given pad can handle. They are also stored in the <gst-registry> along with a description of the <gst-element>.

Caps are exposed on the element pads using the gst-pad-get-caps pad function. This function describes the possible types that the pad can handle or produce at runtime.

Caps are also attached to buffers to describe to content of the data pointed to by the buffer with gst-buffer-set-caps. Caps attached to a <gst-buffer> allow for format negotiation upstream and downstream.

A <gst-caps> can be constructed with the following code fragment:

     
      GstCaps *caps;
      caps = gst_caps_new_simple ("video/x-raw-yuv",
           "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'),
           "framerate", GST_TYPE_FRACTION, 25, 1,
           "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
           "width", G_TYPE_INT, 320,
           "height", G_TYPE_INT, 240,
           NULL);
     

A <gst-caps> is fixed when it has no properties with ranges or lists. Use gst-caps-is-fixed to test for fixed caps. Only fixed caps can be set on a <gst-pad> or <gst-buffer>.

Various methods exist to work with the media types such as subtracting or intersecting.

Last reviewed on 2007-02-13 (0.10.10)

5.2 Usage

— Class: <gst-caps>
— Function: gst-caps-new-empty   (ret <gst-caps>)

Creates a new <gst-caps> that is empty. That is, the returned <gst-caps> contains no media formats. Caller is responsible for unreffing the returned caps.

ret
the new <gst-caps>
— Function: gst-caps-new-any   (ret <gst-caps>)

Creates a new <gst-caps> that indicates that it is compatible with any media format.

ret
the new <gst-caps>
— Function: gst-caps-copy-nth (self <gst-caps>) (nth unsigned-int)   (ret <gst-caps>)

Creates a new <gst-caps> and appends a copy of the nth structure contained in caps.

caps
the <gst-caps> to copy
nth
the nth structure to copy
ret
the new <gst-caps>
— Function: gst-static-caps-get (self <gst-static-caps*>)   (ret <gst-caps>)

Converts a <gst-static-caps> to a <gst-caps>.

static-caps
the <gst-static-caps> to convert
ret
A pointer to the <gst-caps>. 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.
— Function: gst-caps-append (self <gst-caps>) (caps2 <gst-caps>)

Appends the structures contained in caps2 to caps1. The structures in caps2 are not copied – they are transferred to caps1, and then caps2 is freed. If either caps is ANY, the resulting caps will be ANY.

caps1
the <gst-caps> that will be appended to
caps2
the <gst-caps> to append
— Function: gst-caps-merge (self <gst-caps>) (caps2 <gst-caps>)

Appends the structures contained in caps2 to caps1 if they are not yet expressed by caps1. The structures in caps2 are not copied – they are transferred to caps1, and then caps2 is freed. If either caps is ANY, the resulting caps will be ANY.

caps1
the <gst-caps> that will take the new entries
caps2
the <gst-caps> to merge in

Since 0.10.10

— Function: gst-caps-append-structure (self <gst-caps>) (structure <gst-structure>)

Appends structure to caps. The structure is not copied; caps becomes the owner of structure.

caps
the <gst-caps> that will be appended to
structure
the <gst-structure> to append
— Function: gst-caps-remove-structure (self <gst-caps>) (idx unsigned-int)

removes the stucture with the given index from the list of structures contained in caps.

caps
the <gst-caps> to remove from
idx
Index of the structure to remove
— Function: gst-caps-merge-structure (self <gst-caps>) (structure <gst-structure>)

Appends structure to caps if its not already expressed by caps. The structure is not copied; caps becomes the owner of structure.

caps
the <gst-caps> that will the the new structure
structure
the <gst-structure> to merge
— Function: gst-caps-get-size (self <gst-caps>)   (ret unsigned-int)

Gets the number of structures contained in caps.

caps
a <gst-caps>
ret
the number of structures that caps contains
— Function: gst-caps-get-structure (self <gst-caps>) (index unsigned-int)   (ret <gst-structure>)

Finds the structure in caps that has the index index, and returns it.

WARNING: This function takes a const GstCaps *, but returns a non-const GstStructure *. This is for programming convenience – the caller should be aware that structures inside a constant <gst-caps> should not be modified.

caps
a <gst-caps>
index
the index of the structure
ret
a pointer to the <gst-structure> corresponding to index
— Function: gst-caps-is-any (self <gst-caps>)   (ret bool)

Determines if caps represents any media format.

caps
the <gst-caps> to test
ret
TRUE if caps represents any format.
— Function: gst-caps-is-empty (self <gst-caps>)   (ret bool)

Determines if caps represents no media formats.

caps
the <gst-caps> to test
ret
TRUE if caps represents no formats.
— Function: gst-caps-is-fixed (self <gst-caps>)   (ret bool)

Fixed <gst-caps> describe exactly one format, that is, they have exactly one structure, and each field in the structure describes a fixed type. Examples of non-fixed types are GST_TYPE_INT_RANGE and GST_TYPE_LIST.

caps
the <gst-caps> to test
ret
TRUE if caps is fixed
— Function: gst-caps-is-equal (self <gst-caps>) (caps2 <gst-caps>)   (ret bool)

Checks if the given caps represent the same set of caps.

This function does not work reliably if optional properties for caps are included on one caps and omitted on the other.

This function deals correctly with passing NULL for any of the caps.

caps1
a <gst-caps>
caps2
another <gst-caps>
ret
TRUE if both caps are equal.
— Function: gst-caps-is-equal-fixed (self <gst-caps>) (caps2 <gst-caps>)   (ret bool)

Tests if two <gst-caps> are equal. This function only works on fixed <gst-caps>.

caps1
the <gst-caps> to test
caps2
the <gst-caps> to test
ret
TRUE if the arguments represent the same format
— Function: gst-caps-is-always-compatible (self <gst-caps>) (caps2 <gst-caps>)   (ret bool)

A given <gst-caps> structure is always compatible with another if every media format that is in the first is also contained in the second. That is, caps1 is a subset of caps2.

caps1
the <gst-caps> to test
caps2
the <gst-caps> to test
ret
TRUE if caps1 is a subset of caps2.
— Function: gst-caps-is-subset (self <gst-caps>) (superset <gst-caps>)   (ret bool)

Checks if all caps represented by subset are also represented by superset.

This function does not work reliably if optional properties for caps are included on one caps and omitted on the other.

subset
a <gst-caps>
superset
a potentially greater <gst-caps>
ret
#t’ if subset is a subset of superset
— Function: gst-caps-intersect (self <gst-caps>) (caps2 <gst-caps>)   (ret <gst-caps>)

Creates a new <gst-caps> that contains all the formats that are common to both caps1 and caps2.

caps1
a <gst-caps> to intersect
caps2
a <gst-caps> to intersect
ret
the new <gst-caps>
— Function: gst-caps-union (self <gst-caps>) (caps2 <gst-caps>)   (ret <gst-caps>)

Creates a new <gst-caps> that contains all the formats that are in either caps1 and caps2.

caps1
a <gst-caps> to union
caps2
a <gst-caps> to union
ret
the new <gst-caps>
— Function: gst-caps-normalize (self <gst-caps>)   (ret <gst-caps>)

Creates a new <gst-caps> that represents the same set of formats as caps, but contains no lists. Each list is expanded into separate gst-structures.

caps
a <gst-caps> to normalize
ret
the new <gst-caps>
— Function: gst-caps-do-simplify (self <gst-caps>)   (ret bool)

Modifies the given caps inplace into a representation that represents the same set of formats, but in a simpler form. Component structures that are identical are merged. Component structures that have values that can be merged are also merged.

caps
a <gst-caps> to simplify
ret
TRUE, if the caps could be simplified
— Function: gst-caps-save-thyself (self <gst-caps>) (parent <xml-node-ptr>)   (ret <xml-node-ptr>)

Serializes a <gst-caps> to XML and adds it as a child node of parent.

caps
a <gst-caps> structure
parent
a XML parent node
ret
a XML node pointer
— Function: gst-caps-load-thyself (parent <xml-node-ptr>)   (ret <gst-caps>)

Creates a <gst-caps> from its XML serialization.

parent
a XML node
ret
a new <gst-caps> structure
— Function: gst-caps-replace (caps <gst-caps**>) (newcaps <gst-caps>)

Replaces *caps with newcaps. Unrefs the <gst-caps> in the location pointed to by caps, if applicable, then modifies caps to point to newcaps. An additional ref on newcaps is taken.

This function does not take any locks so you might want to lock the object owning caps pointer.

caps
a pointer to <gst-caps>
newcaps
a <gst-caps> to replace *caps
— Function: gst-caps-to-string (self <gst-caps>)   (ret mchars)

Converts caps to a string representation. This string representation can be converted back to a <gst-caps> by gst-caps-from-string.

For debugging purposes its easier to do something like this: This prints the caps in human readble form.

          
           GST_LOG ("caps are %" GST_PTR_FORMAT, caps);
caps
a <gst-caps>
ret
a newly allocated string representing caps.
— Function: gst-caps-from-string (string mchars)   (ret <gst-caps>)

Converts caps from a string representation.

string
a string to convert to <gst-caps>
ret
a newly allocated <gst-caps>
— Function: gst-caps-subtract (self <gst-caps>) (subtrahend <gst-caps>)   (ret <gst-caps>)

Subtracts the subtrahend from the minuend.

This function does not work reliably if optional properties for caps are included on one caps and omitted on the other.

minuend
<gst-caps> to substract from
subtrahend
<gst-caps> to substract
ret
the resulting caps
— Function: gst-caps-make-writable (self <gst-caps>)   (ret <gst-caps>)

Returns a writable copy of caps.

If there is only one reference count on caps, the caller must be the owner, and so this function will return the caps object unchanged. If on the other hand there is more than one reference on the object, a new caps object will be returned. The caller's reference on caps will be removed, and instead the caller will own a reference to the returned object.

In short, this function unrefs the caps in the argument and refs the caps that it returns. Don't access the argument after calling this function. See also: gst-caps-ref.

caps
the <gst-caps> to make writable
ret
the same <gst-caps> object.
— Function: gst-caps-truncate (self <gst-caps>)

Destructively discard all but the first structure from caps. Useful when fixating. caps must be writable.

caps
the <gst-caps> to truncate