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
ConstructorDescriptionCaps()
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 Caps
any()
Creates a newGstCaps
that indicates that it is compatible with any media format.void
Appends the structures contained incaps2
to this Caps.void
appendStructure
(Structure structure) Appendsstructure
to this Caps.void
appendStructureFull
(Structure structure, @Nullable CapsFeatures features) Appendsstructure
withfeatures
to this Caps.boolean
canIntersect
(Caps caps2) Tries intersecting this Caps andcaps2
and reports whether the result would not be emptycopy()
Creates a newGstCaps
as a copy of the old this Caps.copyNth
(int nth) Creates a newGstCaps
and appends a copy of the nth structure contained in this Caps.static Caps
empty()
Creates a newGstCaps
that is empty.static Caps
emptySimple
(String mediaType) Creates a newGstCaps
that contains oneGstStructure
with namemediaType
.void
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.boolean
foreach
(CapsForeachFunc func) Calls the provided function once for each structure and caps feature in theGstCaps
.static Caps
fromString
(String string) Convertscaps
from a string representation.static Caps
Creates a newGstCaps
and adds all the structures listed as arguments.getFeatures
(int index) Finds the features in this Caps atindex
, and returns it.static MemoryLayout
The memory layout of the native struct.int
getSize()
Gets the number of structures contained in this Caps.getStructure
(int index) Finds the structure in this Caps atindex
, and returns it.static Type
getType()
Get the GType of the Caps classCreates a newGstCaps
that contains all the formats that are common to both this Caps andcaps2
.intersectFull
(Caps caps2, CapsIntersectMode mode) Creates a newGstCaps
that contains all the formats that are common to both this Caps andcaps2
, the order is defined by theGstCapsIntersectMode
used.boolean
isAlwaysCompatible
(Caps caps2) A givenGstCaps
structure is always compatible with another if every media format that is in the first is also contained in the second.boolean
isAny()
Determines if this Caps represents any media format.boolean
isEmpty()
Determines if this Caps represents no media formats.boolean
Checks if the given caps represent the same set of caps.boolean
isEqualFixed
(Caps caps2) Tests if twoGstCaps
are equal.boolean
isFixed()
FixedGstCaps
describe exactly one format, that is, they have exactly one structure, and each field in the structure describes a fixed type.boolean
isStrictlyEqual
(Caps caps2) Checks if the given caps are exactly the same set of caps.boolean
Checks if all caps represented by this Caps are also represented bysuperset
.boolean
isSubsetStructure
(Structure structure) Checks ifstructure
is a subset of this Caps.boolean
isSubsetStructureFull
(Structure structure, @Nullable CapsFeatures features) Checks ifstructure
is a subset of this Caps.boolean
mapInPlace
(CapsMapFunc func) Calls the provided function once for each structure and caps feature in theGstCaps
.Appends the structures contained incaps2
to this Caps if they are not yet expressed by this Caps.mergeStructure
(Structure structure) Appendsstructure
to this Caps if it is not already expressed by this Caps.mergeStructureFull
(Structure structure, @Nullable CapsFeatures features) Appendsstructure
withfeatures
to this Caps if its not already expressed by this Caps.Returns aGstCaps
that represents the same set of formats as this Caps, but contains no lists.Read the value of the fieldmini_object
.ref()
Adds a reference to aGstCaps
object.void
removeStructure
(int idx) Removes the structure with the given index from the list of structures contained in this Caps.static boolean
Modifies a pointer to aGstCaps
to 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.void
setFeatures
(int index, @Nullable CapsFeatures features) Sets thefeatures
for the structure atindex
.void
setFeaturesSimple
(@Nullable CapsFeatures features) Sets thefeatures
for all the structures of this Caps.void
Sets fields in aGstCaps
.void
Sets the givenfield
on all structures of this Caps to the givenvalue
.static Caps
Creates a newGstCaps
that contains oneGstStructure
.simplify()
Converts the given this Caps into a representation that represents the same set of formats, but in a simpler form.stealStructure
(int index) Retrieves the structure with the given index from the list of structures contained in this Caps.Subtracts thesubtrahend
from the this Caps.static boolean
Modifies a pointer to aGstCaps
to point to a differentGstCaps
.toString()
Converts this Caps to a string representation.truncate()
Discards all but the first structure from this Caps.void
unref()
Unrefs aGstCaps
and frees all its structures and the structures' values when the refcount reaches 0.void
writeMiniObject
(MiniObject miniObject) Write a value in the fieldmini_object
.Methods inherited from class io.github.jwharm.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 fieldminiObject
arena
- 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 newGstCaps
that indicates that it is compatible with any media format.- Returns:
- the new
GstCaps
-
empty
Creates a newGstCaps
that is empty. That is, the returnedGstCaps
contains no media formats. TheGstCaps
is guaranteed to be writable.- Returns:
- the new
GstCaps
-
emptySimple
-
full
Creates a newGstCaps
and adds all the structures listed as arguments. The list must benull
-terminated. The structures are not copied; the returnedGstCaps
owns the structures.- Parameters:
struct1
- the first structure to addvarargs
- additional structures to add- Returns:
- the new
GstCaps
-
simple
Creates a newGstCaps
that 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
-
fromString
Convertscaps
from a string representation.The implementation of serialization up to 1.20 would lead to unexpected results when there were nested
GstCaps
/GstStructure
deeper than one level.- Parameters:
string
- a string to convert toGstCaps
- Returns:
- a newly allocated
GstCaps
-
replace
public static boolean replace(@Nullable @Nullable Out<Caps> oldCaps, @Nullable @Nullable Caps newCaps) Modifies a pointer to aGstCaps
to 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
newCaps
or theGstCaps
pointed to byoldCaps
may benull
.- Parameters:
oldCaps
- pointer to a pointer to aGstCaps
to be replaced.newCaps
- pointer to aGstCaps
that will replace the caps pointed to byoldCaps
.- Returns:
true
ifnewCaps
was different fromoldCaps
-
take
Modifies a pointer to aGstCaps
to 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 aGstCaps
to be replaced.newCaps
- pointer to aGstCaps
that will replace the caps pointed to byoldCaps
.- Returns:
true
ifnewCaps
was different fromoldCaps
-
append
Appends the structures contained incaps2
to this Caps. The structures incaps2
are not copied -- they are transferred to this Caps, and thencaps2
is freed. If either caps is ANY, the resulting caps will be ANY.- Parameters:
caps2
- theGstCaps
to append
-
appendStructure
Appendsstructure
to this Caps. The structure is not copied; this Caps becomes the owner ofstructure
.- Parameters:
structure
- theGstStructure
to append
-
appendStructureFull
Appendsstructure
withfeatures
to this Caps. The structure is not copied; this Caps becomes the owner ofstructure
.- Parameters:
structure
- theGstStructure
to appendfeatures
- theGstCapsFeatures
to append
-
canIntersect
Tries intersecting this Caps andcaps2
and reports whether the result would not be empty- Parameters:
caps2
- aGstCaps
to intersect- Returns:
true
if intersection would be not empty
-
copy
Creates a newGstCaps
as a copy of the old this Caps. 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 newGstCaps
and appends a copy of the nth structure contained in this Caps.- Parameters:
nth
- the nth structure to copy- Returns:
- the new
GstCaps
-
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 iffalse
is returned from the function. The caps must be mutable.- Parameters:
func
- a function to call for each field
-
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:
true
if the supplied function returnstrue
for each call,false
otherwise.
-
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 constantGstCaps
should 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
GstCapsFeatures
corresponding toindex
-
getSize
public int getSize()Gets the number of structures contained in this Caps.- 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 constantGstCaps
should 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
GstStructure
corresponding toindex
-
intersect
Creates a newGstCaps
that contains all the formats that are common to both this Caps andcaps2
. Defaults toCapsIntersectMode.ZIG_ZAG
mode.- Parameters:
caps2
- aGstCaps
to intersect- Returns:
- the new
GstCaps
-
intersectFull
Creates a newGstCaps
that contains all the formats that are common to both this Caps andcaps2
, the order is defined by theGstCapsIntersectMode
used.- Parameters:
caps2
- aGstCaps
to intersectmode
- The intersection algorithm/mode to use- Returns:
- the new
GstCaps
-
isAlwaysCompatible
A givenGstCaps
structure 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
- theGstCaps
to test- Returns:
true
if this Caps is a subset ofcaps2
.
-
isAny
public boolean isAny()Determines if this Caps represents any media format.- Returns:
true
if this Caps represents any format.
-
isEmpty
public boolean isEmpty()Determines if this Caps represents no media formats.- Returns:
true
if this Caps represents no formats.
-
isEqual
Checks if the given caps represent the same set of caps.- Parameters:
caps2
- anotherGstCaps
- Returns:
true
if both caps are equal.
-
isEqualFixed
Tests if twoGstCaps
are equal. This function only works on fixedGstCaps
.- Parameters:
caps2
- theGstCaps
to test- Returns:
true
if the arguments represent the same format
-
isFixed
public boolean isFixed()FixedGstCaps
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.- Returns:
true
if this Caps is fixed
-
isStrictlyEqual
Checks if the given caps are exactly the same set of caps.- Parameters:
caps2
- anotherGstCaps
- Returns:
true
if both caps are strictly equal.
-
isSubset
Checks if all caps represented by this Caps are also represented bysuperset
.- Parameters:
superset
- a potentially greaterGstCaps
- Returns:
true
if this Caps is a subset ofsuperset
-
isSubsetStructure
Checks ifstructure
is a subset of this Caps. See gst_caps_is_subset() for more information.- Parameters:
structure
- a potentialGstStructure
subset of this Caps- Returns:
true
ifstructure
is a subset of this Caps
-
isSubsetStructureFull
public boolean isSubsetStructureFull(Structure structure, @Nullable @Nullable CapsFeatures features) Checks ifstructure
is a subset of this Caps. See gst_caps_is_subset() for more information.- Parameters:
structure
- a potentialGstStructure
subset of this Capsfeatures
- aGstCapsFeatures
forstructure
- Returns:
true
ifstructure
is a subset of this Caps
-
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:
true
if the supplied function returnstrue
for each call,false
otherwise.
-
merge
Appends the structures contained incaps2
to this Caps if they are not yet expressed by this Caps. The structures incaps2
are not copied -- they are transferred to a writable copy of this Caps, and thencaps2
is freed. If either caps is ANY, the resulting caps will be ANY.- Parameters:
caps2
- theGstCaps
to merge in- Returns:
- the merged caps.
-
mergeStructure
-
mergeStructureFull
Appendsstructure
withfeatures
to this Caps if its not already expressed by this Caps.- Parameters:
structure
- theGstStructure
to mergefeatures
- theGstCapsFeatures
to merge- Returns:
- the merged caps.
-
normalize
Returns aGstCaps
that represents the same set of formats as this Caps, 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 aGstCaps
object.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
GstCaps
object, 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
GstCaps
object.
-
removeStructure
public void removeStructure(int idx) Removes the structure with the given index from the list of structures contained in this Caps.- Parameters:
idx
- Index of the structure to remove
-
serialize
Converts this Caps to a string representation. This string representation can be converted back to aGstCaps
by 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_COMPAT
is passed asflag
.- Parameters:
flags
- aGstSerializeFlags
- Returns:
- a newly allocated string representing this Caps.
-
serialize
Converts this Caps to a string representation. This string representation can be converted back to aGstCaps
by 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_COMPAT
is passed asflag
.- Parameters:
flags
- aGstSerializeFlags
- Returns:
- a newly allocated string representing this Caps.
-
setFeatures
Sets thefeatures
for the structure atindex
.- Parameters:
index
- the index of the structurefeatures
- theGstCapsFeatures
to set
-
setFeaturesSimple
Sets thefeatures
for all the structures of this Caps.- Parameters:
features
- theGstCapsFeatures
to set
-
setSimple
-
setValue
-
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 this Caps.
- Returns:
- The simplified caps.
-
stealStructure
Retrieves the structure with the given index from the list of structures contained in this Caps. The caller becomes the owner of the returned structure.- Parameters:
index
- Index of the structure to retrieve- Returns:
- a pointer to the
GstStructure
corresponding toindex
.
-
subtract
-
toString
Converts this Caps to a string representation. This string representation can be converted back to aGstCaps
by 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
/GstStructure
deeper than one level. -
truncate
Discards all but the first structure from this Caps. 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 aGstCaps
and frees all its structures and the structures' values when the refcount reaches 0.
-