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
This commit is contained in:
Søren Juul 2017-02-10 10:53:05 +01:00 committed by Sebastian Dröge
parent 49002fa8a7
commit 1184429e21
2 changed files with 81 additions and 1 deletions

View file

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

View file

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