video: Add support for a list of any video formats

Adds list of formats that should be used by element in needs to passthrough
video. It contains the full list of video format plus DMA_DRM format
and will be extended in the future as needed. This patches includes 3 new
symbols:

  - GST_VIDEO_FORMATS_ANY_STR
  - GST_VIDEO_FORMATS_ANY
  - gst_video_formats_any()

The last one can be used by bindings or for code that prefers having
GstVideoFormat values instead of strings.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5386>
This commit is contained in:
Nicolas Dufresne 2023-09-24 17:31:45 +02:00 committed by GStreamer Marge Bot
parent 6c84d7ef0d
commit 0fc63b58d0
4 changed files with 115 additions and 7 deletions

View file

@ -2977,6 +2977,20 @@ Formats are sorted by decreasing "quality", using these criteria by priority:
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h"/>
<type name="utf8" c:type="gchar*"/>
</constant>
<constant name="VIDEO_FORMATS_ANY" value="{ " c:type="GST_VIDEO_FORMATS_ANY" version="1.24">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h">This is similar to %GST_VIDEO_FORMATS_ALL but includes formats like DMA_DRM
that do not have a software converter. This should be used for passthrough
template caps.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h"/>
<type name="utf8" c:type="gchar*"/>
</constant>
<constant name="VIDEO_FORMATS_ANY_STR" value="DMA_DRM, " c:type="GST_VIDEO_FORMATS_ANY_STR" version="1.24">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h">This is similar to %GST_VIDEO_FORMATS_ALL_STR but includes formats like
DMA_DRM for which no software converter exists. This should be used for
passthrough template caps.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h"/>
<type name="utf8" c:type="gchar*"/>
</constant>
<function-macro name="VIDEO_FORMAT_INFO_BITS" c:identifier="GST_VIDEO_FORMAT_INFO_BITS" introspectable="0">
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h"/>
<parameters>
@ -18499,6 +18513,25 @@ the #GstVideoFormat if there is one, or NULL otherwise.</doc>
</parameter>
</parameters>
</function>
<function name="video_formats_any" c:identifier="gst_video_formats_any" version="1.24">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c">Return all the raw video formats supported by GStreamer including
special opaque formats such as %GST_VIDEO_FORMAT_DMA_DRM for which
no software conversion exists. This should be use for passthrough
template cpas.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h"/>
<return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c">an array of #GstVideoFormat</doc>
<array length="0" zero-terminated="0" c:type="const GstVideoFormat*">
<type name="VideoFormat" c:type="GstVideoFormat"/>
</array>
</return-value>
<parameters>
<parameter name="len" direction="out" caller-allocates="0" transfer-ownership="full">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c">the number of elements in the returned array</doc>
<type name="guint" c:type="guint*"/>
</parameter>
</parameters>
</function>
<function name="video_formats_raw" c:identifier="gst_video_formats_raw" version="1.18">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c">Return all the raw video formats supported by GStreamer.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h"/>

View file

@ -8041,6 +8041,7 @@ gst_video_format_from_string (const gchar * format)
if (strcmp (GST_VIDEO_FORMAT_INFO_NAME (&formats[i].info), format) == 0)
return GST_VIDEO_FORMAT_INFO_FORMAT (&formats[i].info);
}
return GST_VIDEO_FORMAT_UNKNOWN;
}
@ -8204,8 +8205,8 @@ struct RawVideoFormats
guint n;
};
static gpointer
generate_raw_video_formats (gpointer data)
static struct RawVideoFormats *
generate_video_formats (const gchar * formats)
{
GValue list = G_VALUE_INIT;
struct RawVideoFormats *all = g_new (struct RawVideoFormats, 1);
@ -8217,7 +8218,7 @@ generate_raw_video_formats (gpointer data)
/* Workaround a bug in our parser that would lead to segfaults
* when deserializing container types using static strings,
* see https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/446 */
tmp = g_strdup (GST_VIDEO_FORMATS_ALL);
tmp = g_strdup (formats);
res = gst_value_deserialize (&list, tmp);
g_assert (res);
g_free (tmp);
@ -8230,8 +8231,7 @@ generate_raw_video_formats (gpointer data)
all->formats[i] = gst_video_format_from_string (g_value_get_string (v));
g_assert (all->formats[i] != GST_VIDEO_FORMAT_UNKNOWN
&& all->formats[i] != GST_VIDEO_FORMAT_ENCODED
&& all->formats[i] != GST_VIDEO_FORMAT_DMA_DRM);
&& all->formats[i] != GST_VIDEO_FORMAT_ENCODED);
}
g_value_unset (&list);
@ -8239,6 +8239,18 @@ generate_raw_video_formats (gpointer data)
return all;
}
static gpointer
generate_raw_video_formats (gpointer data)
{
return generate_video_formats (GST_VIDEO_FORMATS_ALL);
}
static gpointer
generate_any_video_formats (gpointer data)
{
return generate_video_formats (GST_VIDEO_FORMATS_ANY);
}
/**
* gst_video_formats_raw:
* @len: (out): the number of elements in the returned array
@ -8263,6 +8275,33 @@ gst_video_formats_raw (guint * len)
return all->formats;
}
/**
* gst_video_formats_any:
* @len: (out): the number of elements in the returned array
*
* Return all the raw video formats supported by GStreamer including
* special opaque formats such as %GST_VIDEO_FORMAT_DMA_DRM for which
* no software conversion exists. This should be use for passthrough
* template cpas.
*
* Returns: (transfer none) (array length=len): an array of #GstVideoFormat
* Since: 1.24
*/
const GstVideoFormat *
gst_video_formats_any (guint * len)
{
static GOnce any_video_formats_once = G_ONCE_INIT;
struct RawVideoFormats *all;
g_return_val_if_fail (len, NULL);
g_once (&any_video_formats_once, generate_any_video_formats, NULL);
all = any_video_formats_once.retval;
*len = all->n;
return all->formats;
}
/**
* gst_video_make_raw_caps:
* @formats: (array length=len) (nullable): an array of raw #GstVideoFormat, or %NULL
@ -8318,8 +8357,7 @@ gst_video_make_raw_caps_with_features (const GstVideoFormat formats[],
GValue v = G_VALUE_INIT;
g_return_val_if_fail (formats[i] != GST_VIDEO_FORMAT_UNKNOWN
&& formats[i] != GST_VIDEO_FORMAT_ENCODED
&& formats[i] != GST_VIDEO_FORMAT_DMA_DRM, NULL);
&& formats[i] != GST_VIDEO_FORMAT_ENCODED, NULL);
g_value_init (&v, G_TYPE_STRING);
g_value_set_static_string (&v, gst_video_format_to_string (formats[i]));

View file

@ -1116,6 +1116,17 @@ gconstpointer gst_video_format_get_palette (GstVideoFormat format, gsi
"GRAY10_LE32, GRAY8"
#endif
/**
* GST_VIDEO_FORMATS_ANY_STR:
*
* This is similar to %GST_VIDEO_FORMATS_ALL_STR but includes formats like
* DMA_DRM for which no software converter exists. This should be used for
* passthrough template caps.
*
* Since: 1.24
*/
#define GST_VIDEO_FORMATS_ANY_STR "DMA_DRM, " GST_VIDEO_FORMATS_ALL_STR
/**
* GST_VIDEO_FORMATS_ALL:
*
@ -1137,9 +1148,23 @@ gconstpointer gst_video_format_get_palette (GstVideoFormat format, gsi
*/
#define GST_VIDEO_FORMATS_ALL "{ " GST_VIDEO_FORMATS_ALL_STR " }"
/**
* GST_VIDEO_FORMATS_ANY:
*
* This is similar to %GST_VIDEO_FORMATS_ALL but includes formats like DMA_DRM
* that do not have a software converter. This should be used for passthrough
* template caps.
*
* Since: 1.24
*/
#define GST_VIDEO_FORMATS_ANY "{ " GST_VIDEO_FORMATS_ANY_STR " }"
GST_VIDEO_API
const GstVideoFormat * gst_video_formats_raw (guint * len);
GST_VIDEO_API
const GstVideoFormat * gst_video_formats_any (guint * len);
/**
* GST_VIDEO_CAPS_MAKE:
* @format: string format that describes the pixel layout, as string

View file

@ -4027,6 +4027,18 @@ GST_START_TEST (test_video_make_raw_caps)
fail_unless (gst_caps_is_equal (caps, expected));
gst_caps_unref (caps);
gst_caps_unref (expected);
guint len;
const GstVideoFormat *formats = gst_video_formats_any (&len);
caps =
gst_video_make_raw_caps_with_features (formats, len,
gst_caps_features_new_any ());
expected =
gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES ("ANY",
GST_VIDEO_FORMATS_ANY));
fail_unless (gst_caps_is_equal (caps, expected));
gst_caps_unref (caps);
gst_caps_unref (expected);
}
GST_END_TEST;