Class Caps
- All Implemented Interfaces:
Proxy
GstStructure.
Caps are exposed on GstPadTemplate to describe all possible types a
given pad can handle. They are also stored in the GstRegistry along with
a description of the GstElement.
Caps are exposed on the element pads using the gst_pad_query_caps() pad function. This function describes the possible types that the pad can handle or produce at runtime.
A GstCaps can be constructed with the following code fragment:
GstCaps *caps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "I420",
"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 GstCaps is fixed when it has no fields with ranges or lists. Use
gst_caps_is_fixed() to test for fixed caps. Fixed caps can be used in a
caps event to notify downstream elements of the current media type.
Various methods exist to work with the media types such as subtracting or intersecting.
Be aware that until 1.20 the GstCaps / GstStructure serialization into string
had limited support for nested GstCaps / GstStructure fields. It could only
support one level of nesting. Using more levels would lead to unexpected
behavior when using serialization features, such as gst_caps_to_string() or
gst_value_serialize() and their counterparts.
-
Constructor Summary
ConstructorsConstructorDescriptionCaps()Allocate a new Caps.Allocate a new Caps.Caps(MemorySegment address) Create a Caps proxy instance for the provided memory address.Caps(MiniObject miniObject) Allocate a new Caps with the fields set to the provided values.Caps(MiniObject miniObject, Arena arena) Allocate a new Caps with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionstatic Capsany()Creates a newGstCapsthat indicates that it is compatible with any media format.voidAppends the structures contained incaps2tocaps1.The structures incaps2are not copied -- they are transferred tocaps1,and thencaps2is freed.voidappendStructure(Structure structure) Appendsstructuretocaps.The structure is not copied; this Caps becomes the owner ofstructure.voidappendStructureFull(Structure structure, @Nullable CapsFeatures features) Appendsstructurewithfeaturestocaps.The structure is not copied; this Caps becomes the owner ofstructure.booleancanIntersect(Caps caps2) Tries intersecting this Caps andcaps2and reports whether the result would not be emptycopy()Creates a newGstCapsas a copy of the oldcaps.The new caps will have a refcount of 1, owned by the caller.copyNth(int nth) Creates a newGstCapsand appends a copy of the nth structure contained incaps.static Capsempty()Creates a newGstCapsthat is empty.static CapsemptySimple(String mediaType) Creates a newGstCapsthat contains oneGstStructurewith namemediaType.voidfilterAndMapInPlace(@Nullable CapsFilterMapFunc func) Calls the provided function once for each structure and caps feature in theGstCaps.fixate()Modifies the given this Caps into a representation with only fixed values.booleanforeach(@Nullable CapsForeachFunc func) Calls the provided function once for each structure and caps feature in theGstCaps.static @Nullable CapsfromString(String string) Convertscapsfrom a string representation.static CapsCreates a newGstCapsand adds all the structures listed as arguments.@Nullable CapsFeaturesgetFeatures(int index) Finds the features in this Caps atindex,and returns it.static MemoryLayoutThe memory layout of the native struct.intgetSize()Gets the number of structures contained incaps.getStructure(int index) Finds the structure in this Caps atindex,and returns it.static @Nullable TypegetType()Get the GType of the Caps classstatic CapsidStrEmptySimple(IdStr mediaType) Creates a newGstCapsthat contains oneGstStructurewith namemediaType.voididStrSetSimple(IdStr field, Object... varargs) Sets fields in aGstCaps.voididStrSetValue(IdStr field, Value value) Sets the givenfieldon all structures of this Caps to the givenvalue.This is a convenience function for calling gst_structure_set_value() on all structures ofcaps.static CapsidStrSimple(IdStr mediaType, IdStr fieldname, Object... varargs) Creates a newGstCapsthat contains oneGstStructure.Creates a newGstCapsthat contains all the formats that are common to both this Caps andcaps2.Defaults toCapsIntersectMode.ZIG_ZAGmode.intersectFull(Caps caps2, CapsIntersectMode mode) Creates a newGstCapsthat contains all the formats that are common to both this Caps andcaps2,the order is defined by theGstCapsIntersectModeused.booleanisAlwaysCompatible(Caps caps2) A givenGstCapsstructure is always compatible with another if every media format that is in the first is also contained in the second.booleanisAny()Determines if this Caps represents any media format.booleanisEmpty()Determines if this Caps represents no media formats.booleanChecks if the given caps represent the same set of caps.booleanisEqualFixed(Caps caps2) Tests if twoGstCapsare equal.booleanisFixed()FixedGstCapsdescribe exactly one format, that is, they have exactly one structure, and each field in the structure describes a fixed type.booleanisStrictlyEqual(Caps caps2) Checks if the given caps are exactly the same set of caps.booleanChecks if all caps represented by this Caps are also represented bysuperset.booleanisSubsetStructure(Structure structure) Checks ifstructureis a subset ofcaps.See gst_caps_is_subset() for more information.booleanisSubsetStructureFull(Structure structure, @Nullable CapsFeatures features) Checks ifstructureis a subset ofcaps.See gst_caps_is_subset() for more information.booleanmapInPlace(@Nullable CapsMapFunc func) Calls the provided function once for each structure and caps feature in theGstCaps.Appends the structures contained incaps2to this Caps if they are not yet expressed bycaps1.The structures incaps2are not copied -- they are transferred to a writable copy ofcaps1,and thencaps2is freed.mergeStructure(Structure structure) Appendsstructureto this Caps if it is not already expressed bycaps.mergeStructureFull(Structure structure, @Nullable CapsFeatures features) Appendsstructurewithfeaturesto this Caps if its not already expressed bycaps.Returns aGstCapsthat represents the same set of formats ascaps,but contains no lists.@Nullable MiniObjectRead the value of the fieldmini_object.ref()Adds a reference to aGstCapsobject.voidremoveStructure(int idx) Removes the structure with the given index from the list of structures contained incaps.static booleanModifies a pointer to aGstCapsto point to a differentGstCaps.serialize(Set<SerializeFlags> flags) Converts this Caps to a string representation.serialize(SerializeFlags... flags) Converts this Caps to a string representation.voidsetFeatures(int index, @Nullable CapsFeatures features) Sets thefeaturesfor the structure atindex.voidsetFeaturesSimple(@Nullable CapsFeatures features) Sets thefeaturesfor all the structures ofcaps.voidSets fields in aGstCaps.voidsetSimpleStaticStr(String field, Object... varargs) Sets fields in aGstCaps.voidSets the givenfieldon all structures of this Caps to the givenvalue.This is a convenience function for calling gst_structure_set_value() on all structures ofcaps.voidsetValueStaticStr(String field, Value value) Sets the givenfieldon all structures of this Caps to the givenvalue.This is a convenience function for calling gst_structure_set_value() on all structures ofcaps.static CapsCreates a newGstCapsthat contains oneGstStructure.simplify()Converts the given this Caps into a representation that represents the same set of formats, but in a simpler form.static CapsstaticStrEmptySimple(String mediaType) Creates a newGstCapsthat contains oneGstStructurewith namemediaType.static CapsstaticStrSimple(String mediaType, String fieldname, Object... varargs) Creates a newGstCapsthat contains oneGstStructure.@Nullable StructurestealStructure(int index) Retrieves the structure with the given index from the list of structures contained incaps.The caller becomes the owner of the returned structure.Subtracts thesubtrahendfrom theminuend.This function does not work reliably if optional properties for caps are included on one caps and omitted on the other.static booleanModifies a pointer to aGstCapsto point to a differentGstCaps.toString()Converts this Caps to a string representation.truncate()Discards all but the first structure fromcaps.Useful when fixating.voidunref()Unrefs aGstCapsand frees all its structures and the structures' values when the refcount reaches 0.voidwriteMiniObject(@Nullable MiniObject miniObject) Write a value in the fieldmini_object.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Caps
Create a Caps proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Caps
Allocate a new Caps.- Parameters:
arena- to control the memory allocation scope
-
Caps
public Caps()Allocate a new Caps. The memory is allocated withArena.ofAuto(). -
Caps
Allocate a new Caps with the fields set to the provided values.- Parameters:
miniObject- value for the fieldminiObjectarena- to control the memory allocation scope
-
Caps
Allocate a new Caps with the fields set to the provided values. The memory is allocated withArena.ofAuto().- Parameters:
miniObject- value for the fieldminiObject
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readMiniObject
Read the value of the fieldmini_object.- Returns:
- The value of the field
mini_object
-
writeMiniObject
Write a value in the fieldmini_object.- Parameters:
miniObject- The new value for the fieldmini_object
-
any
Creates a newGstCapsthat indicates that it is compatible with any media format.- Returns:
- the new
GstCaps
-
empty
Creates a newGstCapsthat is empty. That is, the returnedGstCapscontains no media formats. TheGstCapsis guaranteed to be writable.- Returns:
- the new
GstCaps
-
emptySimple
-
full
Creates a newGstCapsand adds all the structures listed as arguments. The list must benull-terminated. The structures are not copied; the returnedGstCapsowns the structures.- Parameters:
struct1- the first structure to addvarargs- additional structures to add- Returns:
- the new
GstCaps
-
idStrEmptySimple
-
idStrSimple
Creates a newGstCapsthat contains oneGstStructure. The structure is defined by the arguments, which have the same format as gst_structure_new().- Parameters:
mediaType- the media type of the structurefieldname- first field to setvarargs- additional arguments- Returns:
- the new
GstCaps - Since:
- 1.26
-
simple
Creates a newGstCapsthat contains oneGstStructure. The structure is defined by the arguments, which have the same format as gst_structure_new().- Parameters:
mediaType- the media type of the structurefieldname- first field to setvarargs- additional arguments- Returns:
- the new
GstCaps
-
staticStrEmptySimple
Creates a newGstCapsthat contains oneGstStructurewith namemediaType.mediaTypeneeds to be valid for the remaining lifetime of the process, e.g. has to be a static string.- Parameters:
mediaType- the media type of the structure- Returns:
- the new
GstCaps - Since:
- 1.26
-
staticStrSimple
Creates a newGstCapsthat contains oneGstStructure. The structure is defined by the arguments, which have the same format as gst_structure_new().mediaType,fieldnameand all other fieldnames need to be valid for the remaining lifetime of the process, e.g. have to be static strings.- Parameters:
mediaType- the media type of the structurefieldname- first field to setvarargs- additional arguments- Returns:
- the new
GstCaps - Since:
- 1.26
-
fromString
Convertscapsfrom a string representation.The implementation of serialization up to 1.20 would lead to unexpected results when there were nested
GstCaps/GstStructuredeeper than one level.- Parameters:
string- a string to convert toGstCaps- Returns:
- a newly allocated
GstCaps
-
replace
Modifies a pointer to aGstCapsto point to a differentGstCaps. The modification is done atomically (so this is useful for ensuring thread safety in some cases), and the reference counts are updated appropriately (the old caps is unreffed, the new is reffed).Either
newCapsor theGstCapspointed to byoldCapsmay benull.- Parameters:
oldCaps- pointer to a pointer to aGstCapsto be replaced.newCaps- pointer to aGstCapsthat will replace the caps pointed to byoldCaps.- Returns:
trueifnewCapswas different fromoldCaps
-
take
Modifies a pointer to aGstCapsto point to a differentGstCaps. This function is similar to gst_caps_replace() except that it takes ownership ofnewCaps.- Parameters:
oldCaps- pointer to a pointer to aGstCapsto be replaced.newCaps- pointer to aGstCapsthat will replace the caps pointed to byoldCaps.- Returns:
trueifnewCapswas different fromoldCaps
-
append
Appends the structures contained incaps2tocaps1.The structures incaps2are not copied -- they are transferred tocaps1,and thencaps2is freed. If either caps is ANY, the resulting caps will be ANY.- Parameters:
caps2- theGstCapsto append
-
appendStructure
Appendsstructuretocaps.The structure is not copied; this Caps becomes the owner ofstructure.- Parameters:
structure- theGstStructureto append
-
appendStructureFull
Appendsstructurewithfeaturestocaps.The structure is not copied; this Caps becomes the owner ofstructure.- Parameters:
structure- theGstStructureto appendfeatures- theGstCapsFeaturesto append- Since:
- 1.2
-
canIntersect
Tries intersecting this Caps andcaps2and reports whether the result would not be empty- Parameters:
caps2- aGstCapsto intersect- Returns:
trueif intersection would be not empty
-
copy
Creates a newGstCapsas a copy of the oldcaps.The new caps will have a refcount of 1, owned by the caller. The structures are copied as well.Note that this function is the semantic equivalent of a gst_caps_ref() followed by a gst_caps_make_writable(). If you only want to hold on to a reference to the data, you should use gst_caps_ref().
- Returns:
- the new
GstCaps
-
copyNth
Creates a newGstCapsand appends a copy of the nth structure contained incaps.- Parameters:
nth- the nth structure to copy- Returns:
- the new
GstCaps - Since:
- 1.16
-
filterAndMapInPlace
Calls the provided function once for each structure and caps feature in theGstCaps. In contrast to gst_caps_foreach(), the function may modify the structure and features. In contrast to gst_caps_map_in_place(), the structure and features are removed from the caps iffalseis returned from the function. The caps must be mutable.- Parameters:
func- a function to call for each field- Since:
- 1.6
-
fixate
Modifies the given this Caps into a representation with only fixed values. First the caps will be truncated and then the first structure will be fixated with gst_structure_fixate().This function takes ownership of this Caps and will call gst_caps_make_writable() on it so you must not use this Caps afterwards unless you keep an additional reference to it with gst_caps_ref().
Note that it is not guaranteed that the returned caps have exactly one structure. If this Caps are empty caps then the returned caps will be the empty too and contain no structure at all.
Calling this function with ANY caps is not allowed.
- Returns:
- the fixated caps
-
foreach
Calls the provided function once for each structure and caps feature in theGstCaps. The function must not modify the fields. Also see gst_caps_map_in_place() and gst_caps_filter_and_map_in_place().- Parameters:
func- a function to call for each field- Returns:
trueif the supplied function returnstruefor each call,falseotherwise.- Since:
- 1.6
-
getFeatures
Finds the features in this Caps atindex,and returns it.WARNING: This function takes a
const GstCaps *, but returns a non-constGstCapsFeatures *. This is for programming convenience -- the caller should be aware that features inside a constantGstCapsshould not be modified. However, if you know the caps are writable, either because you have just copied them or made them writable with gst_caps_make_writable(), you may modify the features returned in the usual way, e.g. with functions like gst_caps_features_add().- Parameters:
index- the index of the structure- Returns:
- a pointer to the
GstCapsFeaturescorresponding toindex - Since:
- 1.2
-
getSize
public int getSize()Gets the number of structures contained incaps.- Returns:
- the number of structures that this Caps contains
-
getStructure
Finds the structure in this Caps atindex,and returns it.WARNING: This function takes a
const GstCaps *, but returns a non-constGstStructure *. This is for programming convenience -- the caller should be aware that structures inside a constantGstCapsshould not be modified. However, if you know the caps are writable, either because you have just copied them or made them writable with gst_caps_make_writable(), you may modify the structure returned in the usual way, e.g. with functions like gst_structure_set().- Parameters:
index- the index of the structure- Returns:
- a pointer to the
GstStructurecorresponding toindex
-
idStrSetSimple
-
idStrSetValue
Sets the givenfieldon all structures of this Caps to the givenvalue.This is a convenience function for calling gst_structure_set_value() on all structures ofcaps.- Parameters:
field- name of the field to setvalue- value to set the field to- Since:
- 1.26
-
intersect
Creates a newGstCapsthat contains all the formats that are common to both this Caps andcaps2.Defaults toCapsIntersectMode.ZIG_ZAGmode.- Parameters:
caps2- aGstCapsto intersect- Returns:
- the new
GstCaps
-
intersectFull
Creates a newGstCapsthat contains all the formats that are common to both this Caps andcaps2,the order is defined by theGstCapsIntersectModeused.- Parameters:
caps2- aGstCapsto intersectmode- The intersection algorithm/mode to use- Returns:
- the new
GstCaps
-
isAlwaysCompatible
A givenGstCapsstructure is always compatible with another if every media format that is in the first is also contained in the second. That is, this Caps is a subset ofcaps2.- Parameters:
caps2- theGstCapsto test- Returns:
trueif this Caps is a subset ofcaps2.
-
isAny
public boolean isAny()Determines if this Caps represents any media format.- Returns:
trueif this Caps represents any format.
-
isEmpty
public boolean isEmpty()Determines if this Caps represents no media formats.- Returns:
trueif this Caps represents no formats.
-
isEqual
Checks if the given caps represent the same set of caps.- Parameters:
caps2- anotherGstCaps- Returns:
trueif both caps are equal.
-
isEqualFixed
Tests if twoGstCapsare equal. This function only works on fixedGstCaps.- Parameters:
caps2- theGstCapsto test- Returns:
trueif the arguments represent the same format
-
isFixed
public boolean isFixed()FixedGstCapsdescribe 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.- Returns:
trueif this Caps is fixed
-
isStrictlyEqual
Checks if the given caps are exactly the same set of caps.- Parameters:
caps2- anotherGstCaps- Returns:
trueif both caps are strictly equal.
-
isSubset
Checks if all caps represented by this Caps are also represented bysuperset.- Parameters:
superset- a potentially greaterGstCaps- Returns:
trueif this Caps is a subset ofsuperset
-
isSubsetStructure
Checks ifstructureis a subset ofcaps.See gst_caps_is_subset() for more information.- Parameters:
structure- a potentialGstStructuresubset of this Caps- Returns:
trueifstructureis a subset of this Caps
-
isSubsetStructureFull
Checks ifstructureis a subset ofcaps.See gst_caps_is_subset() for more information.- Parameters:
structure- a potentialGstStructuresubset of this Capsfeatures- aGstCapsFeaturesforstructure- Returns:
trueifstructureis a subset of this Caps- Since:
- 1.2
-
mapInPlace
Calls the provided function once for each structure and caps feature in theGstCaps. In contrast to gst_caps_foreach(), the function may modify but not delete the structures and features. The caps must be mutable.- Parameters:
func- a function to call for each field- Returns:
trueif the supplied function returnstruefor each call,falseotherwise.- Since:
- 1.6
-
merge
Appends the structures contained incaps2to this Caps if they are not yet expressed bycaps1.The structures incaps2are not copied -- they are transferred to a writable copy ofcaps1,and thencaps2is freed. If either caps is ANY, the resulting caps will be ANY.- Parameters:
caps2- theGstCapsto merge in- Returns:
- the merged caps.
-
mergeStructure
-
mergeStructureFull
Appendsstructurewithfeaturesto this Caps if its not already expressed bycaps.- Parameters:
structure- theGstStructureto mergefeatures- theGstCapsFeaturesto merge- Returns:
- the merged caps.
- Since:
- 1.2
-
normalize
Returns aGstCapsthat represents the same set of formats ascaps,but contains no lists. Each list is expanded into separateGstStructure.This function takes ownership of this Caps and will call gst_caps_make_writable() on it so you must not use this Caps afterwards unless you keep an additional reference to it with gst_caps_ref().
- Returns:
- the normalized
GstCaps
-
ref
Adds a reference to aGstCapsobject.From this point on, until the caller calls gst_caps_unref() or gst_caps_make_writable(), it is guaranteed that the caps object will not change. This means its structures won't change, etc. To use a
GstCapsobject, you must always have a refcount on it -- either the one made implicitly by e.g. gst_caps_new_simple(), or via taking one explicitly with this function.- Returns:
- the same
GstCapsobject.
-
removeStructure
public void removeStructure(int idx) Removes the structure with the given index from the list of structures contained incaps.- Parameters:
idx- Index of the structure to remove
-
serialize
Converts this Caps to a string representation. This string representation can be converted back to aGstCapsby gst_caps_from_string().This prints the caps in human readable form.
This version of the caps serialization function introduces support for nested structures and caps but the resulting strings won't be parsable with GStreamer prior to 1.20 unless
GST_SERIALIZE_FLAG_BACKWARD_COMPATis passed asflag.- Parameters:
flags- aGstSerializeFlags- Returns:
- a newly allocated string representing
caps. - Since:
- 1.20
-
serialize
Converts this Caps to a string representation. This string representation can be converted back to aGstCapsby gst_caps_from_string().This prints the caps in human readable form.
This version of the caps serialization function introduces support for nested structures and caps but the resulting strings won't be parsable with GStreamer prior to 1.20 unless
GST_SERIALIZE_FLAG_BACKWARD_COMPATis passed asflag.- Parameters:
flags- aGstSerializeFlags- Returns:
- a newly allocated string representing
caps. - Since:
- 1.20
-
setFeatures
Sets thefeaturesfor the structure atindex.- Parameters:
index- the index of the structurefeatures- theGstCapsFeaturesto set- Since:
- 1.2
-
setFeaturesSimple
Sets thefeaturesfor all the structures ofcaps.- Parameters:
features- theGstCapsFeaturesto set- Since:
- 1.16
-
setSimple
-
setSimpleStaticStr
Sets fields in aGstCaps. The arguments must be passed in the same manner as gst_structure_set(), and benull-terminated.fieldand all other field names need to be valid for the remaining lifetime of the process, e.g. have to be static strings.- Parameters:
field- first field to setvarargs- additional parameters- Since:
- 1.26
-
setValue
-
setValueStaticStr
Sets the givenfieldon all structures of this Caps to the givenvalue.This is a convenience function for calling gst_structure_set_value() on all structures ofcaps.fieldneeds to be valid for the remaining lifetime of the process, e.g. has to be a static string.- Parameters:
field- name of the field to setvalue- value to set the field to- Since:
- 1.26
-
simplify
Converts the given this Caps 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.This function takes ownership of this Caps and will call gst_caps_make_writable() on it if necessary, so you must not use this Caps afterwards unless you keep an additional reference to it with gst_caps_ref().
This method does not preserve the original order of
caps.- Returns:
- The simplified caps.
-
stealStructure
Retrieves the structure with the given index from the list of structures contained incaps.The caller becomes the owner of the returned structure.- Parameters:
index- Index of the structure to retrieve- Returns:
- a pointer to the
GstStructurecorresponding toindex.
-
subtract
-
toString
Converts this Caps to a string representation. This string representation can be converted back to aGstCapsby gst_caps_from_string().For debugging purposes its easier to do something like this:
GST_LOG ("caps are %" GST_PTR_FORMAT, caps);This prints the caps in human readable form.
The implementation of serialization up to 1.20 would lead to unexpected results when there were nested
GstCaps/GstStructuredeeper than one level. -
truncate
Discards all but the first structure fromcaps.Useful when fixating.This function takes ownership of this Caps and will call gst_caps_make_writable() on it if necessary, so you must not use this Caps afterwards unless you keep an additional reference to it with gst_caps_ref().
Note that it is not guaranteed that the returned caps have exactly one structure. If this Caps is any or empty caps then the returned caps will be the same and contain no structure at all.
- Returns:
- truncated caps
-
unref
public void unref()Unrefs aGstCapsand frees all its structures and the structures' values when the refcount reaches 0.
-