format: Allow GST_AUDIO/VIDEO_FORMAT_UNKNOWN in _to_string() function

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6630>
This commit is contained in:
Xavier Claessens 2024-04-13 17:50:59 -04:00 committed by GStreamer Marge Bot
parent b46383bf5e
commit 686f74e4a4
9 changed files with 89 additions and 75 deletions

View file

@ -794,6 +794,11 @@ format.</doc>
</parameter>
</parameters>
</function-macro>
<constant name="AUDIO_FORMAT_LAST" value="32" c:type="GST_AUDIO_FORMAT_LAST" version="1.26">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.h">Number of audio formats in #GstAudioFormat.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.h"/>
<type name="gint" c:type="gint"/>
</constant>
<function-macro name="AUDIO_INFO_BPF" c:identifier="GST_AUDIO_INFO_BPF" introspectable="0">
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-info.h"/>
<parameters>
@ -6413,12 +6418,18 @@ string is not a known format.</doc>
</parameters>
</function>
<function name="to_string" c:identifier="gst_audio_format_to_string">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.c">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.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.h"/>
<return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.c">the name corresponding to @format</doc>
<type name="utf8" c:type="const gchar*"/>
</return-value>
<parameters>
<parameter name="format" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.c">a #GstAudioFormat audio format</doc>
<type name="AudioFormat" c:type="GstAudioFormat"/>
</parameter>
</parameters>
@ -10919,12 +10930,18 @@ string is not a known format.</doc>
</return-value>
</function>
<function name="audio_format_to_string" c:identifier="gst_audio_format_to_string" moved-to="AudioFormat.to_string">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.c">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.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.h"/>
<return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.c">the name corresponding to @format</doc>
<type name="utf8" c:type="const gchar*"/>
</return-value>
<parameters>
<parameter name="format" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.c">a #GstAudioFormat audio format</doc>
<type name="AudioFormat" c:type="GstAudioFormat"/>
</parameter>
</parameters>

View file

@ -3403,6 +3403,11 @@ Return the width of one tile in pixels, zero if its not an integer.</doc>
</parameter>
</parameters>
</function-macro>
<constant name="VIDEO_FORMAT_LAST" value="134" c:type="GST_VIDEO_FORMAT_LAST" version="1.26">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h">Number of video formats in #GstVideoFormat.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h"/>
<type name="gint" c:type="gint"/>
</constant>
<constant name="VIDEO_FPS_RANGE" value="(fraction) [ 0, max ]" c:type="GST_VIDEO_FPS_RANGE">
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h"/>
<type name="utf8" c:type="gchar*"/>
@ -10414,8 +10419,10 @@ no corresponding FOURCC value, 0 is returned.</doc>
</parameters>
</function>
<function name="to_string" c:identifier="gst_video_format_to_string">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c">Returns a string containing a descriptive name for
the #GstVideoFormat if there is one, or NULL otherwise.</doc>
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c">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.</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">the name corresponding to @format</doc>
@ -18669,8 +18676,10 @@ no corresponding FOURCC value, 0 is returned.</doc>
</parameters>
</function>
<function name="video_format_to_string" c:identifier="gst_video_format_to_string" moved-to="VideoFormat.to_string">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c">Returns a string containing a descriptive name for
the #GstVideoFormat if there is one, or NULL otherwise.</doc>
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c">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.</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">the name corresponding to @format</doc>

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -31,17 +31,6 @@
#include <gst/check/gstharness.h>
#include <gst/video/video.h>
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;

View file

@ -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);

View file

@ -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;