summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Juul <zpon.dk@gmail.com>2017-02-10 10:53:05 +0100
committerSebastian Dröge <sebastian@centricular.com>2017-02-19 12:55:36 +0200
commit856473b215520e42f4748e01f94ed97f17fa0482 (patch)
tree5b8b21bd447f948a59144d0eae2555dc257d5926
parent2284fc579c1b9a7b0dba9abf4313803cd904bf16 (diff)
downloadgstreamer-plugins-good-856473b215520e42f4748e01f94ed97f17fa0482.tar.gz
icydemux: reset tags on empty value
Some radio streams uses StreamTitle='' to reset the title after a track stopped playing, e.g. while the host talks between tracks or during news segments. This change forces an empty tag object to be distributed if StreamTitle or StreamUrl is received with empty value, thus allowing downstream elements to get notified about this. https://bugzilla.gnome.org/show_bug.cgi?id=778437
-rw-r--r--gst/icydemux/gsticydemux.c5
-rw-r--r--tests/check/elements/icydemux.c77
2 files changed, 81 insertions, 1 deletions
diff --git a/gst/icydemux/gsticydemux.c b/gst/icydemux/gsticydemux.c
index dc0c266ab..12fdad24a 100644
--- a/gst/icydemux/gsticydemux.c
+++ b/gst/icydemux/gsticydemux.c
@@ -323,6 +323,7 @@ gst_icydemux_parse_and_send_tags (GstICYDemux * icydemux)
GstTagList *tags;
const guint8 *data;
int length, i;
+ gboolean tags_found = FALSE;
gchar *buffer;
gchar **strings;
@@ -340,6 +341,7 @@ gst_icydemux_parse_and_send_tags (GstICYDemux * icydemux)
for (i = 0; strings[i]; i++) {
if (!g_ascii_strncasecmp (strings[i], "StreamTitle=", 12)) {
char *title = gst_icydemux_unicodify (strings[i] + 13);
+ tags_found = TRUE;
if (title && *title) {
gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_TITLE,
@@ -348,6 +350,7 @@ gst_icydemux_parse_and_send_tags (GstICYDemux * icydemux)
}
} else if (!g_ascii_strncasecmp (strings[i], "StreamUrl=", 10)) {
char *url = gst_icydemux_unicodify (strings[i] + 11);
+ tags_found = TRUE;
if (url && *url) {
gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_HOMEPAGE,
@@ -362,7 +365,7 @@ gst_icydemux_parse_and_send_tags (GstICYDemux * icydemux)
gst_adapter_unmap (icydemux->meta_adapter);
gst_adapter_flush (icydemux->meta_adapter, length);
- if (!gst_tag_list_is_empty (tags))
+ if (tags_found)
gst_icydemux_tag_found (icydemux, tags);
else
gst_tag_list_unref (tags);
diff --git a/tests/check/elements/icydemux.c b/tests/check/elements/icydemux.c
index 1a17e79b6..b5e43b434 100644
--- a/tests/check/elements/icydemux.c
+++ b/tests/check/elements/icydemux.c
@@ -31,12 +31,23 @@
#define ICY_METADATA \
"StreamTitle='" TEST_METADATA "';\0\0\0\0"
+#define EMPTY_ICY_STREAM_TITLE_METADATA \
+ "StreamTitle='';\0"
+
#define ICY_DATA \
"aaaaaaaa" \
"\x02" \
ICY_METADATA \
"bbbbbbbb"
+#define ICY_DATA_EMPTY_METADATA \
+ ICY_DATA \
+ "\x00" \
+ "dddddddd" \
+ "\x01" \
+ EMPTY_ICY_STREAM_TITLE_METADATA \
+ "cccccccc"
+
#define ICYCAPS "application/x-icy, metadata-interval = (int)8"
#define SRC_CAPS "application/x-icy, metadata-interval = (int)[0, MAX]"
@@ -220,6 +231,71 @@ GST_START_TEST (test_demux)
GST_END_TEST;
+GST_START_TEST (test_demux_empty_data)
+{
+ GstMessage *message;
+ GstTagList *tags;
+ const GValue *tag_val;
+ const gchar *tag;
+ GstCaps *caps;
+
+ fail_unless (gst_type_find_register (NULL, "success", GST_RANK_PRIMARY,
+ typefind_succeed, NULL, gst_static_caps_get (&typefind_caps), NULL,
+ NULL));
+
+ fake_typefind_caps = TRUE;
+
+ caps = gst_caps_from_string (ICYCAPS);
+
+ create_icydemux ();
+ gst_check_setup_events (srcpad, icydemux, caps, GST_FORMAT_TIME);
+
+ push_data ((guint8 *) ICY_DATA_EMPTY_METADATA,
+ sizeof (ICY_DATA_EMPTY_METADATA), -1);
+
+ message = gst_bus_poll (bus, GST_MESSAGE_TAG, -1);
+ fail_unless (message != NULL);
+
+ gst_message_parse_tag (message, &tags);
+ fail_unless (tags != NULL);
+
+ tag_val = gst_tag_list_get_value_index (tags, GST_TAG_TITLE, 0);
+ fail_unless (tag_val != NULL);
+
+ tag = g_value_get_string (tag_val);
+ fail_unless (tag != NULL);
+
+ fail_unless_equals_string (TEST_METADATA, (char *) tag);
+
+ gst_tag_list_unref (tags);
+ gst_message_unref (message);
+
+ message = gst_bus_poll (bus, GST_MESSAGE_TAG, -1);
+ fail_unless (message != NULL);
+
+ gst_message_parse_tag (message, &tags);
+ fail_unless (tags != NULL);
+
+ tag_val = gst_tag_list_get_value_index (tags, GST_TAG_TITLE, 0);
+ fail_unless (tag_val == NULL);
+
+ gst_message_unref (message);
+
+ /* Ensure that no further tag messages are received, i.e. the empty ICY tag
+ * is skipped */
+ message = gst_bus_poll (bus, GST_MESSAGE_TAG, 100000000);
+ fail_unless (message == NULL);
+
+ gst_tag_list_unref (tags);
+ gst_caps_unref (caps);
+
+ cleanup_icydemux ();
+
+ fake_typefind_caps = FALSE;
+}
+
+GST_END_TEST;
+
/* run this test first before the custom typefind function is set up */
GST_START_TEST (test_first_buf_offset_when_merged_for_typefinding)
{
@@ -292,6 +368,7 @@ icydemux_suite (void)
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_demux);
+ tcase_add_test (tc_chain, test_demux_empty_data);
tcase_add_test (tc_chain, test_first_buf_offset_when_merged_for_typefinding);
tcase_add_test (tc_chain, test_not_negotiated);