shout2: fix compiler warnings and bump req to libshout >= 2.4.2

Fix compiler warnings with latest libshout version (2.4.6).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2473>
This commit is contained in:
Tim-Philipp Müller 2022-05-23 20:23:38 +01:00
parent fedb48c68f
commit e64c6f0b93
3 changed files with 85 additions and 45 deletions

View file

@ -45,10 +45,13 @@
#include <glib/gi18n-lib.h> #include <glib/gi18n-lib.h>
#ifndef HAVE_SHOUT_2_4_6_OR_NEWER
#define shout_set_metadata_utf8 shout_set_metadata
#endif
GST_DEBUG_CATEGORY_STATIC (shout2_debug); GST_DEBUG_CATEGORY_STATIC (shout2_debug);
#define GST_CAT_DEFAULT shout2_debug #define GST_CAT_DEFAULT shout2_debug
enum enum
{ {
SIGNAL_CONNECTION_PROBLEM, /* FIXME 2.0: remove this */ SIGNAL_CONNECTION_PROBLEM, /* FIXME 2.0: remove this */
@ -93,18 +96,9 @@ enum
#define DEFAULT_TIMEOUT 10000 #define DEFAULT_TIMEOUT 10000
#define DEFAULT_SEND_TITLE_INFO TRUE #define DEFAULT_SEND_TITLE_INFO TRUE
#ifdef SHOUT_FORMAT_WEBM #define SHOUT2SEND_CAPS "application/ogg; audio/ogg; video/ogg; "\
#define WEBM_CAPS "; video/webm; audio/webm" "audio/mpeg, mpegversion = (int) 1, layer = (int) [ 1, 3 ]; " \
#else "video/webm; audio/webm"
#define WEBM_CAPS ""
#endif
#define SHOUT2SEND_BASIC_CAPS "application/ogg; audio/ogg; video/ogg; "\
"audio/mpeg, mpegversion = (int) 1, layer = (int) [ 1, 3 ]"
#define SHOUT2SEND_DOC_CAPS SHOUT2SEND_BASIC_CAPS "; video/webm; audio/webm"
#define SHOUT2SEND_CAPS SHOUT2SEND_BASIC_CAPS WEBM_CAPS
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
@ -172,7 +166,6 @@ gst_shout2send_class_init (GstShout2sendClass * klass)
GstElementClass *gstelement_class; GstElementClass *gstelement_class;
GstBaseSinkClass *gstbasesink_class; GstBaseSinkClass *gstbasesink_class;
GstPadTemplate *tmpl; GstPadTemplate *tmpl;
GstCaps *doc_caps;
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass; gstelement_class = (GstElementClass *) klass;
@ -282,11 +275,6 @@ gst_shout2send_class_init (GstShout2sendClass * klass)
tmpl = gst_static_pad_template_get (&sink_template); tmpl = gst_static_pad_template_get (&sink_template);
gst_element_class_add_pad_template (gstelement_class, tmpl); gst_element_class_add_pad_template (gstelement_class, tmpl);
/* our caps depend on the libshout2 version */
doc_caps = gst_caps_from_string (SHOUT2SEND_DOC_CAPS);
gst_pad_template_set_documentation_caps (tmpl, doc_caps);
gst_clear_caps (&doc_caps);
gst_element_class_set_static_metadata (gstelement_class, gst_element_class_set_static_metadata (gstelement_class,
"Icecast network sink", "Icecast network sink",
"Sink/Network", "Sends data to an icecast server", "Sink/Network", "Sends data to an icecast server",
@ -320,6 +308,7 @@ gst_shout2send_init (GstShout2send * shout2send)
shout2send->timeout = DEFAULT_TIMEOUT; shout2send->timeout = DEFAULT_TIMEOUT;
shout2send->format = -1; shout2send->format = -1;
shout2send->usage = SHOUT_USAGE_UNKNOWN;
shout2send->tags = gst_tag_list_new_empty (); shout2send->tags = gst_tag_list_new_empty ();
shout2send->conn = NULL; shout2send->conn = NULL;
shout2send->connected = FALSE; shout2send->connected = FALSE;
@ -467,13 +456,21 @@ gst_shout2send_event (GstBaseSink * sink, GstEvent * event)
set_shout_metadata, shout2send); set_shout_metadata, shout2send);
if (shout2send->songmetadata && shout2send->connected) { if (shout2send->songmetadata && shout2send->connected) {
shout_metadata_t *pmetadata; shout_metadata_t *pmetadata;
int shout_ret;
GST_DEBUG_OBJECT (shout2send, "metadata now: %s", GST_DEBUG_OBJECT (shout2send, "metadata now: %s",
shout2send->songmetadata); shout2send->songmetadata);
pmetadata = shout_metadata_new (); pmetadata = shout_metadata_new ();
shout_metadata_add (pmetadata, "song", shout2send->songmetadata); shout_ret =
shout_set_metadata (shout2send->conn, pmetadata); shout_metadata_add (pmetadata, "song", shout2send->songmetadata);
if (shout_ret == SHOUTERR_SUCCESS) {
shout_ret = shout_set_metadata_utf8 (shout2send->conn, pmetadata);
if (shout_ret != SHOUTERR_SUCCESS) {
GST_WARNING_OBJECT (shout2send, "Failed to set metadata: %s",
shout_get_error (shout2send->conn));
}
}
shout_metadata_free (pmetadata); shout_metadata_free (pmetadata);
} }
} }
@ -492,6 +489,21 @@ gst_shout2send_event (GstBaseSink * sink, GstEvent * event)
return ret; return ret;
} }
static gboolean
gst_shout2send_set_meta (GstShout2send * sink, const char *meta,
const char *val)
{
GST_DEBUG_OBJECT (sink, "setting %s: %s", meta, val);
if (shout_set_meta (sink->conn, meta, val) == SHOUTERR_SUCCESS)
return TRUE;
GST_ELEMENT_ERROR (sink, LIBRARY, SETTINGS, (NULL),
("Error setting %s: %s", meta, shout_get_error (sink->conn)));
return FALSE;
}
static gboolean static gboolean
gst_shout2send_start (GstBaseSink * basesink) gst_shout2send_start (GstBaseSink * basesink)
{ {
@ -541,20 +553,15 @@ gst_shout2send_start (GstBaseSink * basesink)
(sink->ispublic ? 1 : 0)) != SHOUTERR_SUCCESS) (sink->ispublic ? 1 : 0)) != SHOUTERR_SUCCESS)
goto set_failed; goto set_failed;
cur_prop = "streamname"; if (!gst_shout2send_set_meta (sink, SHOUT_META_NAME, sink->streamname))
GST_DEBUG_OBJECT (sink, "setting %s: %s", cur_prop, sink->streamname); goto set_meta_failed;
if (shout_set_name (sink->conn, sink->streamname) != SHOUTERR_SUCCESS)
goto set_failed;
cur_prop = "description"; if (!gst_shout2send_set_meta (sink, SHOUT_META_DESCRIPTION,
GST_DEBUG_OBJECT (sink, "setting %s: %s", cur_prop, sink->description); sink->description))
if (shout_set_description (sink->conn, sink->description) != SHOUTERR_SUCCESS) goto set_meta_failed;
goto set_failed;
cur_prop = "genre"; if (!gst_shout2send_set_meta (sink, SHOUT_META_GENRE, sink->genre))
GST_DEBUG_OBJECT (sink, "setting %s: %s", cur_prop, sink->genre); goto set_meta_failed;
if (shout_set_genre (sink->conn, sink->genre) != SHOUTERR_SUCCESS)
goto set_failed;
cur_prop = "mount"; cur_prop = "mount";
GST_DEBUG_OBJECT (sink, "setting %s: %s", cur_prop, sink->mount); GST_DEBUG_OBJECT (sink, "setting %s: %s", cur_prop, sink->mount);
@ -579,6 +586,10 @@ set_failed:
{ {
GST_ELEMENT_ERROR (sink, LIBRARY, SETTINGS, (NULL), GST_ELEMENT_ERROR (sink, LIBRARY, SETTINGS, (NULL),
("Error setting %s: %s", cur_prop, shout_get_error (sink->conn))); ("Error setting %s: %s", cur_prop, shout_get_error (sink->conn)));
/* fallthrough */
}
set_meta_failed:
{
shout_free (sink->conn); shout_free (sink->conn);
sink->conn = NULL; sink->conn = NULL;
return FALSE; return FALSE;
@ -600,8 +611,17 @@ gst_shout2send_connect (GstShout2send * sink)
if (shout_set_nonblocking (sink->conn, 1) != SHOUTERR_SUCCESS) if (shout_set_nonblocking (sink->conn, 1) != SHOUTERR_SUCCESS)
goto could_not_set_nonblocking; goto could_not_set_nonblocking;
if (shout_set_format (sink->conn, sink->format) != SHOUTERR_SUCCESS) {
goto could_not_set_format; #ifdef HAVE_SHOUT_2_4_6_OR_NEWER
ret =
shout_set_content_format (sink->conn, sink->format, sink->usage, NULL);
#else
ret = shout_set_format (sink->conn, sink->format);
#endif
if (ret != SHOUTERR_SUCCESS)
goto could_not_set_format;
}
GST_DEBUG_OBJECT (sink, "connecting"); GST_DEBUG_OBJECT (sink, "connecting");
@ -609,13 +629,9 @@ gst_shout2send_connect (GstShout2send * sink)
ret = shout_open (sink->conn); ret = shout_open (sink->conn);
/* wait for connection or timeout */ /* wait for connection or timeout */
#ifdef SHOUTERR_RETRY
/* starting with libshout 2.4.2, shout_open() has broken API + ABI and /* starting with libshout 2.4.2, shout_open() has broken API + ABI and
* can also return SHOUTERR_RETRY (a new define) to mean "try again" */ * can also return SHOUTERR_RETRY (a new define) to mean "try again" */
while (ret == SHOUTERR_BUSY || ret == SHOUTERR_RETRY) { while (ret == SHOUTERR_BUSY || ret == SHOUTERR_RETRY) {
#else
while (ret == SHOUTERR_BUSY) {
#endif
if (gst_util_get_timestamp () - start_ts > sink->timeout * GST_MSECOND) { if (gst_util_get_timestamp () - start_ts > sink->timeout * GST_MSECOND) {
goto connection_timeout; goto connection_timeout;
} }
@ -647,8 +663,14 @@ gst_shout2send_connect (GstShout2send * sink)
GST_DEBUG_OBJECT (sink, "shout metadata now: %s", sink->songmetadata); GST_DEBUG_OBJECT (sink, "shout metadata now: %s", sink->songmetadata);
pmetadata = shout_metadata_new (); pmetadata = shout_metadata_new ();
shout_metadata_add (pmetadata, "song", sink->songmetadata); ret = shout_metadata_add (pmetadata, "song", sink->songmetadata);
shout_set_metadata (sink->conn, pmetadata); if (ret == SHOUTERR_SUCCESS) {
ret = shout_set_metadata_utf8 (sink->conn, pmetadata);
if (ret != SHOUTERR_SUCCESS) {
GST_WARNING_OBJECT (sink, "Failed to set metadata: %s",
shout_get_error (sink->conn));
}
}
shout_metadata_free (pmetadata); shout_metadata_free (pmetadata);
} }
@ -717,6 +739,7 @@ gst_shout2send_stop (GstBaseSink * basesink)
sink->connected = FALSE; sink->connected = FALSE;
sink->format = -1; sink->format = -1;
sink->usage = SHOUT_USAGE_UNKNOWN;
return TRUE; return TRUE;
} }
@ -994,12 +1017,23 @@ gst_shout2send_setcaps (GstBaseSink * basesink, GstCaps * caps)
if (!strcmp (mimetype, "audio/mpeg")) { if (!strcmp (mimetype, "audio/mpeg")) {
shout2send->format = SHOUT_FORMAT_MP3; shout2send->format = SHOUT_FORMAT_MP3;
shout2send->usage = SHOUT_USAGE_AUDIO;
} else if (g_str_has_suffix (mimetype, "/ogg")) { } else if (g_str_has_suffix (mimetype, "/ogg")) {
shout2send->format = SHOUT_FORMAT_OGG; shout2send->format = SHOUT_FORMAT_OGG;
#ifdef SHOUT_FORMAT_WEBM if (g_str_has_prefix (mimetype, "audio/"))
shout2send->usage = SHOUT_USAGE_AUDIO;
else if (g_str_has_prefix (mimetype, "video/"))
shout2send->usage = SHOUT_USAGE_VISUAL | SHOUT_USAGE_AUDIO;
else
shout2send->usage = SHOUT_USAGE_UNKNOWN;
} else if (g_str_has_suffix (mimetype, "/webm")) { } else if (g_str_has_suffix (mimetype, "/webm")) {
shout2send->format = SHOUT_FORMAT_WEBM; shout2send->format = SHOUT_FORMAT_WEBM;
#endif if (g_str_has_prefix (mimetype, "audio/"))
shout2send->usage = SHOUT_USAGE_AUDIO;
else if (g_str_has_prefix (mimetype, "video/"))
shout2send->usage = SHOUT_USAGE_VISUAL | SHOUT_USAGE_AUDIO;
else
shout2send->usage = SHOUT_USAGE_UNKNOWN;
} else { } else {
ret = FALSE; ret = FALSE;
} }

View file

@ -72,6 +72,7 @@ struct _GstShout2send {
gchar *user_agent; gchar *user_agent;
gint format; gint format;
guint timeout; guint timeout;
guint usage; /* SHOUT_USAGE_* */
GstTagList* tags; GstTagList* tags;
}; };

View file

@ -1,11 +1,16 @@
shout2_sources = ['gstshout2.c'] shout2_sources = ['gstshout2.c']
shout2_dep = dependency('shout', version : '>= 2.0', required : get_option('shout2')) shout2_dep = dependency('shout', version : '>= 2.4.2', required : get_option('shout2'))
if shout2_dep.found() if shout2_dep.found()
shout2_extra_args = []
if shout2_dep.version().version_compare('>= 2.4.6')
shout2_extra_args += ['-DHAVE_SHOUT_2_4_6_OR_NEWER']
endif
gstshout2 = library('gstshout2', gstshout2 = library('gstshout2',
shout2_sources, shout2_sources,
c_args : gst_plugins_good_args, c_args : gst_plugins_good_args + shout2_extra_args,
include_directories : [configinc, libsinc], include_directories : [configinc, libsinc],
dependencies : [gstbase_dep, shout2_dep], dependencies : [gstbase_dep, shout2_dep],
install : true, install : true,