:right-sidebar: True Caps =================================================================== .. currentmodule:: gi.repository.Gst .. class:: Caps(*args, **kwargs) :no-contents-entry: Caps (capabilities) are lightweight refcounted objects describing media types. They are composed of an array of :obj:`~gi.repository.Gst.Structure`\. Caps are exposed on :obj:`~gi.repository.Gst.PadTemplate` to describe all possible types a given pad can handle. They are also stored in the :obj:`~gi.repository.Gst.Registry` along with a description of the :obj:`~gi.repository.Gst.Element`\. Caps are exposed on the element pads using the :func:`~gi.repository.Gst.Pad.query_caps` pad function. This function describes the possible types that the pad can handle or produce at runtime. A :obj:`~gi.repository.Gst.Caps` can be constructed with the following code fragment: .. code-block:: C :dedent: 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 :obj:`~gi.repository.Gst.Caps` is fixed when it has no fields with ranges or lists. Use :func:`~gi.repository.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 :obj:`~gi.repository.Gst.Caps` / :obj:`~gi.repository.Gst.Structure` serialization into string had limited support for nested :obj:`~gi.repository.Gst.Caps` / :obj:`~gi.repository.Gst.Structure` fields. It could only support one level of nesting. Using more levels would lead to unexpected behavior when using serialization features, such as :func:`~gi.repository.Gst.Caps.to_string` or :func:`~gi.repository.Gst.value_serialize` and their counterparts. Constructors ------------ .. rst-class:: interim-class .. class:: Caps :no-index: .. classmethod:: new_any() -> ~gi.repository.Gst.Caps Creates a new :obj:`~gi.repository.Gst.Caps` that indicates that it is compatible with any media format. .. classmethod:: new_empty() -> ~gi.repository.Gst.Caps Creates a new :obj:`~gi.repository.Gst.Caps` that is empty. That is, the returned :obj:`~gi.repository.Gst.Caps` contains no media formats. The :obj:`~gi.repository.Gst.Caps` is guaranteed to be writable. .. classmethod:: new_empty_simple(media_type: str) -> ~gi.repository.Gst.Caps Creates a new :obj:`~gi.repository.Gst.Caps` that contains one :obj:`~gi.repository.Gst.Structure` with name ``media_type``\. :param media_type: the media type of the structure Methods ------- .. rst-class:: interim-class .. class:: Caps :no-index: .. method:: append(caps2: ~gi.repository.Gst.Caps) -> None 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. :param caps2: the :obj:`~gi.repository.Gst.Caps` to append .. method:: append_structure(structure: ~gi.repository.Gst.Structure) -> None Appends ``structure`` to ``caps``\. The structure is not copied; ``caps`` becomes the owner of ``structure``\. :param structure: the :obj:`~gi.repository.Gst.Structure` to append .. method:: append_structure_full(structure: ~gi.repository.Gst.Structure, features: ~gi.repository.Gst.CapsFeatures | None = None) -> None Appends ``structure`` with ``features`` to ``caps``\. The structure is not copied; ``caps`` becomes the owner of ``structure``\. .. versionadded:: 1.2 :param structure: the :obj:`~gi.repository.Gst.Structure` to append :param features: the :obj:`~gi.repository.Gst.CapsFeatures` to append .. method:: can_intersect(caps2: ~gi.repository.Gst.Caps) -> bool Tries intersecting ``caps1`` and ``caps2`` and reports whether the result would not be empty :param caps2: a :obj:`~gi.repository.Gst.Caps` to intersect .. method:: filter_and_map_in_place(func: ~typing.Callable[[~gi.repository.Gst.CapsFeatures, ~gi.repository.Gst.Structure, ~typing.Any], bool], user_data: ~typing.Any = None) -> None Calls the provided function once for each structure and caps feature in the :obj:`~gi.repository.Gst.Caps`\. In contrast to :func:`~gi.repository.Gst.Caps.foreach`, the function may modify the structure and features. In contrast to :func:`~gi.repository.Gst.Caps.map_in_place`, the structure and features are removed from the caps if :const:`False` is returned from the function. The caps must be mutable. .. versionadded:: 1.6 :param func: a function to call for each field :param user_data: private data .. method:: fixate() -> ~gi.repository.Gst.Caps Modifies the given ``caps`` into a representation with only fixed values. First the caps will be truncated and then the first structure will be fixated with :func:`~gi.repository.Gst.Structure.fixate`. This function takes ownership of ``caps`` and will call :func:`~gi.repository.Gst.caps_make_writable` on it so you must not use ``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 ``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. .. method:: foreach(func: ~typing.Callable[[~gi.repository.Gst.CapsFeatures, ~gi.repository.Gst.Structure, ~typing.Any], bool], user_data: ~typing.Any = None) -> bool Calls the provided function once for each structure and caps feature in the :obj:`~gi.repository.Gst.Caps`\. The function must not modify the fields. Also see :func:`~gi.repository.Gst.Caps.map_in_place` and :func:`~gi.repository.Gst.Caps.filter_and_map_in_place`. .. versionadded:: 1.6 :param func: a function to call for each field :param user_data: private data .. classmethod:: from_string() -> ~gi.repository.Gst.Caps | None Converts ``caps`` from a string representation. The implementation of serialization up to 1.20 would lead to unexpected results when there were nested :obj:`~gi.repository.Gst.Caps` / :obj:`~gi.repository.Gst.Structure` deeper than one level. .. method:: get_features(index: int) -> ~gi.repository.Gst.CapsFeatures | None Finds the features in ``caps`` at ``index``\, and returns it. WARNING: This function takes a ``const GstCaps *``\, but returns a non-const ``GstCapsFeatures *``\. This is for programming convenience -- the caller should be aware that features inside a constant :obj:`~gi.repository.Gst.Caps` should not be modified. However, if you know the caps are writable, either because you have just copied them or made them writable with :func:`~gi.repository.Gst.caps_make_writable`, you may modify the features returned in the usual way, e.g. with functions like :func:`~gi.repository.Gst.CapsFeatures.add`. .. versionadded:: 1.2 :param index: the index of the structure .. method:: get_size() -> int Gets the number of structures contained in ``caps``\. .. method:: get_structure(index: int) -> ~gi.repository.Gst.Structure Finds the structure in ``caps`` at ``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 :obj:`~gi.repository.Gst.Caps` should not be modified. However, if you know the caps are writable, either because you have just copied them or made them writable with :func:`~gi.repository.Gst.caps_make_writable`, you may modify the structure returned in the usual way, e.g. with functions like :func:`~gi.repository.Gst.Structure.set`. :param index: the index of the structure .. method:: intersect(caps2: ~gi.repository.Gst.Caps) -> ~gi.repository.Gst.Caps Creates a new :obj:`~gi.repository.Gst.Caps` that contains all the formats that are common to both ``caps1`` and ``caps2``\. Defaults to :const:`~gi.repository.Gst.CapsIntersectMode.ZIG_ZAG` mode. :param caps2: a :obj:`~gi.repository.Gst.Caps` to intersect .. method:: intersect_full(caps2: ~gi.repository.Gst.Caps, mode: ~gi.repository.Gst.CapsIntersectMode) -> ~gi.repository.Gst.Caps Creates a new :obj:`~gi.repository.Gst.Caps` that contains all the formats that are common to both ``caps1`` and ``caps2``\, the order is defined by the :obj:`~gi.repository.Gst.CapsIntersectMode` used. :param caps2: a :obj:`~gi.repository.Gst.Caps` to intersect :param mode: The intersection algorithm/mode to use .. method:: is_always_compatible(caps2: ~gi.repository.Gst.Caps) -> bool A given :obj:`~gi.repository.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``\. :param caps2: the :obj:`~gi.repository.Gst.Caps` to test .. method:: is_any() -> bool Determines if ``caps`` represents any media format. .. method:: is_empty() -> bool Determines if ``caps`` represents no media formats. .. method:: is_equal(caps2: ~gi.repository.Gst.Caps) -> bool Checks if the given caps represent the same set of caps. :param caps2: another :obj:`~gi.repository.Gst.Caps` .. method:: is_equal_fixed(caps2: ~gi.repository.Gst.Caps) -> bool Tests if two :obj:`~gi.repository.Gst.Caps` are equal. This function only works on fixed :obj:`~gi.repository.Gst.Caps`\. :param caps2: the :obj:`~gi.repository.Gst.Caps` to test .. method:: is_fixed() -> bool Fixed :obj:`~gi.repository.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. .. method:: is_strictly_equal(caps2: ~gi.repository.Gst.Caps) -> bool Checks if the given caps are exactly the same set of caps. :param caps2: another :obj:`~gi.repository.Gst.Caps` .. method:: is_subset(superset: ~gi.repository.Gst.Caps) -> bool Checks if all caps represented by ``subset`` are also represented by ``superset``\. :param superset: a potentially greater :obj:`~gi.repository.Gst.Caps` .. method:: is_subset_structure(structure: ~gi.repository.Gst.Structure) -> bool Checks if ``structure`` is a subset of ``caps``\. See :func:`~gi.repository.Gst.Caps.is_subset` for more information. :param structure: a potential :obj:`~gi.repository.Gst.Structure` subset of ``caps`` .. method:: is_subset_structure_full(structure: ~gi.repository.Gst.Structure, features: ~gi.repository.Gst.CapsFeatures | None = None) -> bool Checks if ``structure`` is a subset of ``caps``\. See :func:`~gi.repository.Gst.Caps.is_subset` for more information. .. versionadded:: 1.2 :param structure: a potential :obj:`~gi.repository.Gst.Structure` subset of ``caps`` :param features: a :obj:`~gi.repository.Gst.CapsFeatures` for ``structure`` .. method:: map_in_place(func: ~typing.Callable[[~gi.repository.Gst.CapsFeatures, ~gi.repository.Gst.Structure, ~typing.Any], bool], user_data: ~typing.Any = None) -> bool Calls the provided function once for each structure and caps feature in the :obj:`~gi.repository.Gst.Caps`\. In contrast to :func:`~gi.repository.Gst.Caps.foreach`, the function may modify but not delete the structures and features. The caps must be mutable. .. versionadded:: 1.6 :param func: a function to call for each field :param user_data: private data .. method:: merge(caps2: ~gi.repository.Gst.Caps) -> ~gi.repository.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 a writable copy of ``caps1``\, and then ``caps2`` is freed. If either caps is ANY, the resulting caps will be ANY. :param caps2: the :obj:`~gi.repository.Gst.Caps` to merge in .. method:: merge_structure(structure: ~gi.repository.Gst.Structure) -> ~gi.repository.Gst.Caps Appends ``structure`` to ``caps`` if it is not already expressed by ``caps``\. :param structure: the :obj:`~gi.repository.Gst.Structure` to merge .. method:: merge_structure_full(structure: ~gi.repository.Gst.Structure, features: ~gi.repository.Gst.CapsFeatures | None = None) -> ~gi.repository.Gst.Caps Appends ``structure`` with ``features`` to ``caps`` if its not already expressed by ``caps``\. .. versionadded:: 1.2 :param structure: the :obj:`~gi.repository.Gst.Structure` to merge :param features: the :obj:`~gi.repository.Gst.CapsFeatures` to merge .. method:: normalize() -> ~gi.repository.Gst.Caps Returns a :obj:`~gi.repository.Gst.Caps` that represents the same set of formats as ``caps``\, but contains no lists. Each list is expanded into separate :obj:`~gi.repository.Gst.Structure`\. This function takes ownership of ``caps`` and will call :func:`~gi.repository.Gst.caps_make_writable` on it so you must not use ``caps`` afterwards unless you keep an additional reference to it with gst_caps_ref(). .. method:: remove_structure(idx: int) -> None Removes the structure with the given index from the list of structures contained in ``caps``\. :param idx: Index of the structure to remove .. method:: serialize(flags: ~gi.repository.Gst.SerializeFlags) -> str Converts ``caps`` to a string representation. This string representation can be converted back to a :obj:`~gi.repository.Gst.Caps` by :func:`~gi.repository.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 as ``flag``\. .. versionadded:: 1.20 :param flags: a :obj:`~gi.repository.Gst.SerializeFlags` .. method:: set_features(index: int, features: ~gi.repository.Gst.CapsFeatures | None = None) -> None Sets the ``features`` for the structure at ``index``\. .. versionadded:: 1.2 :param index: the index of the structure :param features: the :obj:`~gi.repository.Gst.CapsFeatures` to set .. method:: set_features_simple(features: ~gi.repository.Gst.CapsFeatures | None = None) -> None Sets the ``features`` for all the structures of ``caps``\. .. versionadded:: 1.16 :param features: the :obj:`~gi.repository.Gst.CapsFeatures` to set .. method:: set_value(field: str, value: ~gi.repository.GObject.Value) -> None Sets the given ``field`` on all structures of ``caps`` to the given ``value``\. This is a convenience function for calling :func:`~gi.repository.Gst.Structure.set_value` on all structures of ``caps``\. :param field: name of the field to set :param value: value to set the field to .. method:: simplify() -> ~gi.repository.Gst.Caps Converts the given ``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 ``caps`` and will call :func:`~gi.repository.Gst.caps_make_writable` on it if necessary, so you must not use ``caps`` afterwards unless you keep an additional reference to it with gst_caps_ref(). This method does not preserve the original order of ``caps``\. .. method:: subtract(subtrahend: ~gi.repository.Gst.Caps) -> ~gi.repository.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. :param subtrahend: :obj:`~gi.repository.Gst.Caps` to subtract .. method:: to_string() -> str Converts ``caps`` to a string representation. This string representation can be converted back to a :obj:`~gi.repository.Gst.Caps` by :func:`~gi.repository.Gst.Caps.from_string`. For debugging purposes its easier to do something like this: .. code-block:: C :dedent: 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 :obj:`~gi.repository.Gst.Caps` / :obj:`~gi.repository.Gst.Structure` deeper than one level. .. method:: truncate() -> ~gi.repository.Gst.Caps Discards all but the first structure from ``caps``\. Useful when fixating. This function takes ownership of ``caps`` and will call :func:`~gi.repository.Gst.caps_make_writable` on it if necessary, so you must not use ``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 ``caps`` is any or empty caps then the returned caps will be the same and contain no structure at all. Fields ------ .. rst-class:: interim-class .. class:: Caps :no-index: .. attribute:: mini_object The parent type