diff --git a/girs/GstAudio-1.0.gir b/girs/GstAudio-1.0.gir
index a5ee361f15..7189f47d1c 100644
--- a/girs/GstAudio-1.0.gir
+++ b/girs/GstAudio-1.0.gir
@@ -794,6 +794,11 @@ format.
+
+ Number of audio formats in #GstAudioFormat.
+
+
+
@@ -6413,12 +6418,18 @@ string is not a known format.
+ Returns a string containing a descriptive name for the #GstAudioFormat.
+
+Since 1.26 this can also be used with %GST_AUDIO_FORMAT_UNKNOWN, previous
+versions were printing a critical warning and returned %NULL.
+ the name corresponding to @format
+ a #GstAudioFormat audio format
@@ -10919,12 +10930,18 @@ string is not a known format.
+ Returns a string containing a descriptive name for the #GstAudioFormat.
+
+Since 1.26 this can also be used with %GST_AUDIO_FORMAT_UNKNOWN, previous
+versions were printing a critical warning and returned %NULL.
+ the name corresponding to @format
+ a #GstAudioFormat audio format
diff --git a/girs/GstVideo-1.0.gir b/girs/GstVideo-1.0.gir
index 972f61db89..5b23131504 100644
--- a/girs/GstVideo-1.0.gir
+++ b/girs/GstVideo-1.0.gir
@@ -3403,6 +3403,11 @@ Return the width of one tile in pixels, zero if its not an integer.
+
+ Number of video formats in #GstVideoFormat.
+
+
+
@@ -10414,8 +10419,10 @@ no corresponding FOURCC value, 0 is returned.
- Returns a string containing a descriptive name for
-the #GstVideoFormat if there is one, or NULL otherwise.
+ Returns a string containing a descriptive name for the #GstVideoFormat.
+
+Since 1.26 this can also be used with %GST_VIDEO_FORMAT_UNKNOWN, previous
+versions were printing a critical warning and returned %NULL.
the name corresponding to @format
@@ -18669,8 +18676,10 @@ no corresponding FOURCC value, 0 is returned.
- Returns a string containing a descriptive name for
-the #GstVideoFormat if there is one, or NULL otherwise.
+ Returns a string containing a descriptive name for the #GstVideoFormat.
+
+Since 1.26 this can also be used with %GST_VIDEO_FORMAT_UNKNOWN, previous
+versions were printing a critical warning and returned %NULL.
the name corresponding to @format
diff --git a/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.c b/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.c
index b1b8d60a17..72a90b3387 100644
--- a/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.c
+++ b/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.c
@@ -424,11 +424,23 @@ gst_audio_format_from_string (const gchar * format)
return GST_AUDIO_FORMAT_UNKNOWN;
}
+/**
+ * gst_audio_format_to_string:
+ * @format: a #GstAudioFormat audio format
+ *
+ * Returns a string containing a descriptive name for the #GstAudioFormat.
+ *
+ * Since 1.26 this can also be used with %GST_AUDIO_FORMAT_UNKNOWN, previous
+ * versions were printing a critical warning and returned %NULL.
+ *
+ * Returns: the name corresponding to @format
+ */
const gchar *
gst_audio_format_to_string (GstAudioFormat format)
{
- g_return_val_if_fail (format != GST_AUDIO_FORMAT_UNKNOWN, NULL);
+ g_return_val_if_fail ((gint) format < G_N_ELEMENTS (formats), NULL);
+ /* In case glib checks are disabled */
if ((gint) format >= G_N_ELEMENTS (formats))
return NULL;
diff --git a/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.h b/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.h
index c7aeef8de3..7d46e671e7 100644
--- a/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.h
+++ b/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.h
@@ -128,6 +128,9 @@ typedef enum {
GST_AUDIO_FORMAT_F32BE,
GST_AUDIO_FORMAT_F64LE,
GST_AUDIO_FORMAT_F64BE,
+
+ /* Update GST_AUDIO_FORMAT_LAST below when adding more formats here */
+
/* native endianness equivalents */
GST_AUDIO_FORMAT_S16 = _GST_AUDIO_FORMAT_NE(S16),
GST_AUDIO_FORMAT_U16 = _GST_AUDIO_FORMAT_NE(U16),
@@ -145,6 +148,14 @@ typedef enum {
GST_AUDIO_FORMAT_F64 = _GST_AUDIO_FORMAT_NE(F64)
} GstAudioFormat;
+/**
+ * GST_AUDIO_FORMAT_LAST:
+ *
+ * Number of audio formats in #GstAudioFormat.
+ *
+ * Since: 1.26
+ */
+#define GST_AUDIO_FORMAT_LAST (GST_AUDIO_FORMAT_F64BE + 1)
typedef struct _GstAudioFormatInfo GstAudioFormatInfo;
diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c b/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c
index a8b1a47e80..c80115a7d7 100644
--- a/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c
+++ b/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c
@@ -8106,16 +8106,19 @@ gst_video_format_to_fourcc (GstVideoFormat format)
* gst_video_format_to_string:
* @format: a #GstVideoFormat video format
*
- * Returns a string containing a descriptive name for
- * the #GstVideoFormat if there is one, or NULL otherwise.
+ * Returns a string containing a descriptive name for the #GstVideoFormat.
+ *
+ * Since 1.26 this can also be used with %GST_VIDEO_FORMAT_UNKNOWN, previous
+ * versions were printing a critical warning and returned %NULL.
*
* Returns: the name corresponding to @format
*/
const gchar *
gst_video_format_to_string (GstVideoFormat format)
{
- g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
+ g_return_val_if_fail ((gint) format < G_N_ELEMENTS (formats), NULL);
+ /* In case glib checks are disabled */
if ((gint) format >= G_N_ELEMENTS (formats))
return NULL;
diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h b/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h
index b853485329..e9892a8964 100644
--- a/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h
+++ b/subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h
@@ -619,8 +619,19 @@ typedef enum {
* Since: 1.24
*/
GST_VIDEO_FORMAT_RBGA,
+
+ /* Update GST_VIDEO_FORMAT_LAST below when adding more formats here */
} GstVideoFormat;
+/**
+ * GST_VIDEO_FORMAT_LAST:
+ *
+ * Number of video formats in #GstVideoFormat.
+ *
+ * Since: 1.26
+ */
+#define GST_VIDEO_FORMAT_LAST (GST_VIDEO_FORMAT_RBGA + 1)
+
#define GST_VIDEO_MAX_PLANES 4
#define GST_VIDEO_MAX_COMPONENTS 4
diff --git a/subprojects/gst-plugins-base/tests/check/elements/videoconvert.c b/subprojects/gst-plugins-base/tests/check/elements/videoconvert.c
index b42d4a72f3..420564a908 100644
--- a/subprojects/gst-plugins-base/tests/check/elements/videoconvert.c
+++ b/subprojects/gst-plugins-base/tests/check/elements/videoconvert.c
@@ -31,17 +31,6 @@
#include
#include
-static guint
-get_num_formats (void)
-{
- guint i = 2;
-
- while (gst_video_format_to_string ((GstVideoFormat) i) != NULL)
- ++i;
-
- return i;
-}
-
static void
check_pad_template (GstPadTemplate * tmpl)
{
@@ -49,10 +38,9 @@ check_pad_template (GstPadTemplate * tmpl)
GstStructure *s;
gboolean *formats_supported;
GstCaps *caps;
- guint i, num_formats;
+ guint i;
- num_formats = get_num_formats ();
- formats_supported = g_new0 (gboolean, num_formats);
+ formats_supported = g_new0 (gboolean, GST_VIDEO_FORMAT_LAST);
caps = gst_pad_template_get_caps (tmpl);
@@ -84,7 +72,7 @@ check_pad_template (GstPadTemplate * tmpl)
gst_caps_unref (caps);
- for (i = 2; i < num_formats; ++i) {
+ for (i = 2; i < GST_VIDEO_FORMAT_LAST; ++i) {
if (i == GST_VIDEO_FORMAT_DMA_DRM)
continue;
diff --git a/subprojects/gst-plugins-base/tests/check/elements/videoscale.c b/subprojects/gst-plugins-base/tests/check/elements/videoscale.c
index 6b1fbda327..2c6ff8009e 100644
--- a/subprojects/gst-plugins-base/tests/check/elements/videoscale.c
+++ b/subprojects/gst-plugins-base/tests/check/elements/videoscale.c
@@ -33,17 +33,6 @@
#ifndef VSCALE_TEST_GROUP
-static guint
-get_num_formats (void)
-{
- guint i = 2;
-
- while (gst_video_format_to_string ((GstVideoFormat) i) != NULL)
- ++i;
-
- return i;
-}
-
static void
check_pad_template (GstPadTemplate * tmpl)
{
@@ -51,10 +40,9 @@ check_pad_template (GstPadTemplate * tmpl)
GstStructure *s;
gboolean *formats_supported;
GstCaps *caps;
- guint i, num_formats;
+ guint i;
- num_formats = get_num_formats ();
- formats_supported = g_new0 (gboolean, num_formats);
+ formats_supported = g_new0 (gboolean, GST_VIDEO_FORMAT_LAST);
caps = gst_pad_template_get_caps (tmpl);
@@ -87,7 +75,7 @@ check_pad_template (GstPadTemplate * tmpl)
gst_caps_unref (caps);
- for (i = 2; i < num_formats; ++i) {
+ for (i = 2; i < GST_VIDEO_FORMAT_LAST; ++i) {
if (!formats_supported[i]) {
const gchar *fmt_str = gst_video_format_to_string ((GstVideoFormat) i);
diff --git a/subprojects/gst-plugins-base/tests/check/libs/video.c b/subprojects/gst-plugins-base/tests/check/libs/video.c
index 939f9d8dee..d7442032e8 100644
--- a/subprojects/gst-plugins-base/tests/check/libs/video.c
+++ b/subprojects/gst-plugins-base/tests/check/libs/video.c
@@ -365,25 +365,12 @@ video_format_is_packed (GstVideoFormat fmt)
return FALSE;
}
-static gint
-get_num_formats (void)
-{
- gint num_formats = 200;
- fail_unless (gst_video_format_to_string (num_formats) == NULL);
- while (gst_video_format_to_string (num_formats) == NULL)
- --num_formats;
- GST_INFO ("number of known video formats: %d", num_formats);
- return num_formats + 1;
-}
-
GST_START_TEST (test_video_formats_all)
{
GstStructure *s;
const GValue *val, *list_val;
GstCaps *caps;
- guint num, n, num_formats;
-
- num_formats = get_num_formats ();
+ guint num, n;
caps = gst_caps_from_string ("video/x-raw, format=" GST_VIDEO_FORMATS_ALL);
s = gst_caps_get_structure (caps, 0);
@@ -403,7 +390,7 @@ GST_START_TEST (test_video_formats_all)
GST_VIDEO_FORMAT_UNKNOWN);
}
/* Take into account GST_VIDEO_FORMAT_ENCODED, UNKNOWN and DMA_DRM. */
- fail_unless_equals_int (num, num_formats - 3);
+ fail_unless_equals_int (num, GST_VIDEO_FORMAT_LAST - 3);
gst_caps_unref (caps);
}
@@ -414,11 +401,7 @@ GST_END_TEST;
#define HEIGHT 20
GST_START_TEST (test_video_formats_pack_unpack)
{
- guint n, num_formats;
-
- num_formats = get_num_formats ();
-
- for (n = GST_VIDEO_FORMAT_ENCODED + 1; n < num_formats; ++n) {
+ for (guint n = GST_VIDEO_FORMAT_ENCODED + 1; n < GST_VIDEO_FORMAT_LAST; ++n) {
const GstVideoFormatInfo *vfinfo, *unpackinfo;
GstVideoFormat fmt = n;
GstVideoInfo vinfo;
@@ -2174,7 +2157,7 @@ GST_START_TEST (test_video_pack_unpack2)
{
GstVideoFormat format;
GTimer *timer;
- gint num_formats, i;
+ gint i;
GArray *packarray, *unpackarray;
#define WIDTH 320
@@ -2186,11 +2169,9 @@ GST_START_TEST (test_video_pack_unpack2)
packarray = g_array_new (FALSE, FALSE, sizeof (ConvertResult));
unpackarray = g_array_new (FALSE, FALSE, sizeof (ConvertResult));
- num_formats = get_num_formats ();
-
GST_DEBUG ("pack/sec\t unpack/sec \tpack GB/sec\tunpack GB/sec\tformat");
- for (format = GST_VIDEO_FORMAT_I420; format < num_formats; format++) {
+ for (format = GST_VIDEO_FORMAT_I420; format < GST_VIDEO_FORMAT_LAST; format++) {
GstVideoInfo info;
const GstVideoFormatInfo *finfo, *fuinfo;
GstBuffer *buffer;
@@ -2528,11 +2509,8 @@ static void
run_video_color_convert (ColorType in_type, ColorType out_type)
{
GstVideoFormat infmt, outfmt;
- gint num_formats;
- num_formats = get_num_formats ();
-
- for (infmt = GST_VIDEO_FORMAT_I420; infmt < num_formats; infmt++) {
+ for (infmt = GST_VIDEO_FORMAT_I420; infmt < GST_VIDEO_FORMAT_LAST; infmt++) {
GstVideoInfo ininfo;
GstVideoFrame inframe;
GstBuffer *inbuffer;
@@ -2548,7 +2526,8 @@ run_video_color_convert (ColorType in_type, ColorType out_type)
gst_buffer_memset (inbuffer, 0, 0, -1);
gst_video_frame_map (&inframe, &ininfo, inbuffer, GST_MAP_READ);
- for (outfmt = GST_VIDEO_FORMAT_I420; outfmt < num_formats; outfmt++) {
+ for (outfmt = GST_VIDEO_FORMAT_I420; outfmt < GST_VIDEO_FORMAT_LAST;
+ outfmt++) {
GstVideoInfo outinfo;
GstVideoFrame outframe;
GstBuffer *outbuffer;
@@ -2632,16 +2611,14 @@ GST_START_TEST (test_video_size_convert)
{
GstVideoFormat infmt, outfmt;
GTimer *timer;
- gint num_formats, i;
+ gint i;
GArray *array;
array = g_array_new (FALSE, FALSE, sizeof (ConvertResult));
timer = g_timer_new ();
- num_formats = get_num_formats ();
-
- for (infmt = GST_VIDEO_FORMAT_I420; infmt < num_formats; infmt++) {
+ for (infmt = GST_VIDEO_FORMAT_I420; infmt < GST_VIDEO_FORMAT_LAST; infmt++) {
GstVideoInfo ininfo, outinfo;
GstVideoFrame inframe, outframe;
GstBuffer *inbuffer, *outbuffer;
@@ -3267,8 +3244,7 @@ GST_START_TEST (test_video_formats_pstrides)
{
GstVideoFormat fmt = GST_VIDEO_FORMAT_I420;
-
- while ((gst_video_format_to_string (fmt) != NULL)) {
+ while (fmt < GST_VIDEO_FORMAT_LAST) {
const GstVideoFormatInfo *vf_info = gst_video_format_get_info (fmt);
guint n_comps = GST_VIDEO_FORMAT_INFO_N_COMPONENTS (vf_info);
@@ -4101,10 +4077,9 @@ GST_END_TEST;
GST_START_TEST (test_video_extrapolate_stride)
{
- guint num_formats = get_num_formats ();
GstVideoFormat format;
- for (format = 2; format < num_formats; format++) {
+ for (format = 2; format < GST_VIDEO_FORMAT_LAST; format++) {
GstVideoInfo info;
guint p;