From 7f7084cd3a63aac4d4d331b35cd16171624b6a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Mon, 25 Apr 2022 10:59:21 +0200 Subject: [PATCH] caps: warn with wrong mediatype in gst_caps_new_empty_simple If passing ANY/EMPTY to gst_caps_new_empty_simple as a mediatype, a warning will be displayed to alert on this misuse of the API. Part-of: --- subprojects/gstreamer/gst/gstcaps.c | 10 ++++++++++ subprojects/gstreamer/tests/check/pipelines/seek.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/subprojects/gstreamer/gst/gstcaps.c b/subprojects/gstreamer/gst/gstcaps.c index bbb9211abf..28a7dfe0ba 100644 --- a/subprojects/gstreamer/gst/gstcaps.c +++ b/subprojects/gstreamer/gst/gstcaps.c @@ -300,6 +300,16 @@ gst_caps_new_empty_simple (const char *media_type) GstStructure *structure; caps = gst_caps_new_empty (); + if (strcmp ("ANY", media_type) == 0) { + g_warning + ("media_type should not be ANY. Please consider using `gst_caps_new_any` or `gst_caps_from_string`."); + } + if (strcmp ("", media_type) == 0 || strcmp ("EMPTY", media_type) == 0 + || strcmp ("NONE", media_type) == 0) { + g_warning + ("media_type should not be `%s`. Please consider using `gst_caps_new_empty` or `gst_caps_from_string`.", + media_type); + } structure = gst_structure_new_empty (media_type); if (structure) gst_caps_append_structure_unchecked (caps, structure, NULL); diff --git a/subprojects/gstreamer/tests/check/pipelines/seek.c b/subprojects/gstreamer/tests/check/pipelines/seek.c index 5f7447bc57..bf89282899 100644 --- a/subprojects/gstreamer/tests/check/pipelines/seek.c +++ b/subprojects/gstreamer/tests/check/pipelines/seek.c @@ -169,7 +169,7 @@ dummy_parser_handle_frame (GstBaseParse * parse, if (((DummyParser *) parse)->caps_set == FALSE) { GstCaps *caps; /* push caps */ - caps = gst_caps_new_empty_simple ("ANY"); + caps = gst_caps_new_empty_simple ("video/x-raw"); gst_pad_set_caps (GST_BASE_PARSE_SRC_PAD (parse), caps); gst_caps_unref (caps); ((DummyParser *) parse)->caps_set = TRUE;