ext/shout2/gstshout2.*: Add a property for username.
[platform/upstream/gst-plugins-good.git] / ext / shout2 / gstshout2.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2006> Tim-Philipp Müller <tim centricular net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "gstshout2.h"
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "gst/gst-i18n-plugin.h"
30
31 GST_DEBUG_CATEGORY_STATIC (shout2_debug);
32 #define GST_CAT_DEFAULT shout2_debug
33
34 static const GstElementDetails shout2send_details =
35 GST_ELEMENT_DETAILS ("Icecast network sink",
36     "Sink/Network",
37     "Sends data to an icecast server",
38     "Wim Taymans <wim.taymans@chello.be>\n"
39     "Pedro Corte-Real <typo@netcabo.pt>\n"
40     "Zaheer Abbas Merali <zaheerabbas at merali dot org>");
41
42
43 enum
44 {
45   SIGNAL_CONNECTION_PROBLEM,    /* 0.11 FIXME: remove this */
46   LAST_SIGNAL
47 };
48
49 enum
50 {
51   ARG_0,
52   ARG_IP,                       /* the ip of the server */
53   ARG_PORT,                     /* the encoder port number on the server */
54   ARG_PASSWORD,                 /* the encoder password on the server */
55   ARG_USERNAME,                 /* the encoder username on the server */
56   ARG_PUBLIC,                   /* is this stream public? */
57   ARG_STREAMNAME,               /* Name of the stream */
58   ARG_DESCRIPTION,              /* Description of the stream */
59   ARG_GENRE,                    /* Genre of the stream */
60
61   ARG_PROTOCOL,                 /* Protocol to connect with */
62
63   ARG_MOUNT,                    /* mountpoint of stream (icecast only) */
64   ARG_URL                       /* Url of stream (I'm guessing) */
65 };
66
67 #define DEFAULT_IP           "127.0.0.1"
68 #define DEFAULT_PORT         8000
69 #define DEFAULT_PASSWORD     "hackme"
70 #define DEFAULT_USERNAME     "source"
71 #define DEFAULT_STREAMNAME   ""
72 #define DEFAULT_DESCRIPTION  ""
73 #define DEFAULT_GENRE        ""
74 #define DEFAULT_MOUNT        ""
75 #define DEFAULT_URL          ""
76 #define DEFAULT_PROTOCOL     SHOUT2SEND_PROTOCOL_HTTP
77
78 static GstElementClass *parent_class = NULL;
79
80 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
81     GST_PAD_SINK,
82     GST_PAD_ALWAYS,
83     GST_STATIC_CAPS ("application/ogg; "
84         "audio/mpeg, mpegversion = (int) 1, layer = (int) [ 1, 3 ]")
85     );
86 static void gst_shout2send_class_init (GstShout2sendClass * klass);
87 static void gst_shout2send_base_init (GstShout2sendClass * klass);
88 static void gst_shout2send_init (GstShout2send * shout2send);
89
90 static gboolean gst_shout2send_event (GstBaseSink * sink, GstEvent * event);
91 static GstFlowReturn gst_shout2send_render (GstBaseSink * sink,
92     GstBuffer * buffer);
93 static gboolean gst_shout2send_start (GstBaseSink * basesink);
94 static gboolean gst_shout2send_stop (GstBaseSink * basesink);
95
96 static void gst_shout2send_set_property (GObject * object, guint prop_id,
97     const GValue * value, GParamSpec * pspec);
98 static void gst_shout2send_get_property (GObject * object, guint prop_id,
99     GValue * value, GParamSpec * pspec);
100
101 static gboolean gst_shout2send_setcaps (GstPad * pad, GstCaps * caps);
102
103 static guint gst_shout2send_signals[LAST_SIGNAL] = { 0 };
104
105 #define GST_TYPE_SHOUT_PROTOCOL (gst_shout2send_protocol_get_type())
106 static GType
107 gst_shout2send_protocol_get_type (void)
108 {
109   static GType shout2send_protocol_type = 0;
110   static const GEnumValue shout2send_protocol[] = {
111     {SHOUT2SEND_PROTOCOL_XAUDIOCAST,
112         "Xaudiocast Protocol (icecast 1.3.x)", "xaudiocast"},
113     {SHOUT2SEND_PROTOCOL_ICY, "Icy Protocol (ShoutCast)", "icy"},
114     {SHOUT2SEND_PROTOCOL_HTTP, "Http Protocol (icecast 2.x)", "http"},
115     {0, NULL, NULL},
116   };
117
118   if (!shout2send_protocol_type) {
119     shout2send_protocol_type =
120         g_enum_register_static ("GstShout2SendProtocol", shout2send_protocol);
121   }
122
123
124   return shout2send_protocol_type;
125 }
126
127 GType
128 gst_shout2send_get_type (void)
129 {
130   static GType shout2send_type = 0;
131
132   if (!shout2send_type) {
133     static const GTypeInfo shout2send_info = {
134       sizeof (GstShout2sendClass),
135       (GBaseInitFunc) gst_shout2send_base_init,
136       NULL,
137       (GClassInitFunc) gst_shout2send_class_init,
138       NULL,
139       NULL,
140       sizeof (GstShout2send),
141       0,
142       (GInstanceInitFunc) gst_shout2send_init,
143     };
144
145     static const GInterfaceInfo tag_setter_info = {
146       NULL,
147       NULL,
148       NULL
149     };
150
151     shout2send_type =
152         g_type_register_static (GST_TYPE_BASE_SINK, "GstShout2send",
153         &shout2send_info, 0);
154
155     g_type_add_interface_static (shout2send_type, GST_TYPE_TAG_SETTER,
156         &tag_setter_info);
157
158   }
159   return shout2send_type;
160 }
161
162 static void
163 gst_shout2send_base_init (GstShout2sendClass * klass)
164 {
165   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
166
167   gst_element_class_add_pad_template (element_class,
168       gst_static_pad_template_get (&sink_template));
169   gst_element_class_set_details (element_class, &shout2send_details);
170
171   GST_DEBUG_CATEGORY_INIT (shout2_debug, "shout2", 0, "shout2send element");
172 }
173
174 static void
175 gst_shout2send_class_init (GstShout2sendClass * klass)
176 {
177   GObjectClass *gobject_class;
178   GstBaseSinkClass *gstbasesink_class;
179
180   gobject_class = (GObjectClass *) klass;
181   gstbasesink_class = (GstBaseSinkClass *) klass;
182
183   parent_class = g_type_class_peek_parent (klass);
184
185   gobject_class->set_property = gst_shout2send_set_property;
186   gobject_class->get_property = gst_shout2send_get_property;
187
188   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_IP,
189       g_param_spec_string ("ip", "ip", "ip", DEFAULT_IP, G_PARAM_READWRITE));
190   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PORT,
191       g_param_spec_int ("port", "port", "port", 1, G_MAXUSHORT, DEFAULT_PORT,
192           G_PARAM_READWRITE));
193
194   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PASSWORD,
195       g_param_spec_string ("password", "password", "password", DEFAULT_PASSWORD,
196           G_PARAM_READWRITE));
197
198   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_USERNAME,
199       g_param_spec_string ("username", "username", "username", DEFAULT_USERNAME,
200           G_PARAM_READWRITE));
201
202   /* metadata */
203   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STREAMNAME,
204       g_param_spec_string ("streamname", "streamname", "name of the stream",
205           DEFAULT_STREAMNAME, G_PARAM_READWRITE));
206
207   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DESCRIPTION,
208       g_param_spec_string ("description", "description", "description",
209           DEFAULT_DESCRIPTION, G_PARAM_READWRITE));
210
211   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_GENRE,
212       g_param_spec_string ("genre", "genre", "genre", DEFAULT_GENRE,
213           G_PARAM_READWRITE));
214
215   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PROTOCOL,
216       g_param_spec_enum ("protocol", "protocol", "Connection Protocol to use",
217           GST_TYPE_SHOUT_PROTOCOL, DEFAULT_PROTOCOL, G_PARAM_READWRITE));
218
219
220   /* icecast only */
221   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MOUNT,
222       g_param_spec_string ("mount", "mount", "mount", DEFAULT_MOUNT,
223           G_PARAM_READWRITE));
224
225   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_URL,
226       g_param_spec_string ("url", "url", "url", DEFAULT_URL,
227           G_PARAM_READWRITE));
228
229   /* signals */
230   gst_shout2send_signals[SIGNAL_CONNECTION_PROBLEM] =
231       g_signal_new ("connection-problem", G_TYPE_FROM_CLASS (klass),
232       G_SIGNAL_RUN_CLEANUP, G_STRUCT_OFFSET (GstShout2sendClass,
233           connection_problem), NULL, NULL, g_cclosure_marshal_VOID__INT,
234       G_TYPE_NONE, 1, G_TYPE_INT);
235
236   gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_shout2send_start);
237   gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_shout2send_stop);
238   gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_shout2send_render);
239   gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_shout2send_event);
240 }
241
242 static void
243 gst_shout2send_init (GstShout2send * shout2send)
244 {
245   gst_base_sink_set_sync (GST_BASE_SINK (shout2send), FALSE);
246
247   gst_pad_set_setcaps_function (GST_BASE_SINK_PAD (shout2send),
248       GST_DEBUG_FUNCPTR (gst_shout2send_setcaps));
249
250   shout2send->ip = g_strdup (DEFAULT_IP);
251   shout2send->port = DEFAULT_PORT;
252   shout2send->password = g_strdup (DEFAULT_PASSWORD);
253   shout2send->username = g_strdup (DEFAULT_USERNAME);
254   shout2send->streamname = g_strdup (DEFAULT_STREAMNAME);
255   shout2send->description = g_strdup (DEFAULT_DESCRIPTION);
256   shout2send->genre = g_strdup (DEFAULT_GENRE);
257   shout2send->mount = g_strdup (DEFAULT_MOUNT);
258   shout2send->url = g_strdup (DEFAULT_URL);
259   shout2send->protocol = DEFAULT_PROTOCOL;
260
261   shout2send->tags = gst_tag_list_new ();
262   shout2send->conn = NULL;
263   shout2send->audio_format = SHOUT_FORMAT_VORBIS;
264   shout2send->connected = FALSE;
265   shout2send->songmetadata = NULL;
266   shout2send->songartist = NULL;
267   shout2send->songtitle = NULL;
268
269 }
270
271 static void
272 set_shout_metadata (const GstTagList * list, const gchar * tag,
273     gpointer user_data)
274 {
275   GstShout2send *shout2send = (GstShout2send *) user_data;
276   char **shout_metadata = &(shout2send->songmetadata);
277   char **song_artist = &(shout2send->songartist);
278   char **song_title = &(shout2send->songtitle);
279
280   gchar *value;
281
282   GST_DEBUG ("tag: %s being added", tag);
283   if (strcmp (tag, GST_TAG_ARTIST) == 0) {
284     if (gst_tag_get_type (tag) == G_TYPE_STRING) {
285       if (!gst_tag_list_get_string (list, tag, &value)) {
286         GST_DEBUG ("Error reading \"%s\" tag value", tag);
287         return;
288       }
289
290       if (*song_artist != NULL)
291         g_free (*song_artist);
292
293       *song_artist = g_strdup (value);
294     }
295   } else if (strcmp (tag, GST_TAG_TITLE) == 0) {
296     if (gst_tag_get_type (tag) == G_TYPE_STRING) {
297       if (!gst_tag_list_get_string (list, tag, &value)) {
298         GST_DEBUG ("Error reading \"%s\" tag value", tag);
299         return;
300       }
301
302       if (*song_title != NULL)
303         g_free (*song_title);
304
305       *song_title = g_strdup (value);
306     }
307   }
308
309   if (*shout_metadata != NULL)
310     g_free (*shout_metadata);
311
312
313   if (*song_title && *song_artist) {
314     *shout_metadata = g_strdup_printf ("%s - %s", *song_artist, *song_title);
315   } else if (*song_title && *song_artist == NULL) {
316     *shout_metadata = g_strdup_printf ("Unknown - %s", *song_title);
317   } else if (*song_title == NULL && *song_artist) {
318     *shout_metadata = g_strdup_printf ("%s - Unknown", *song_artist);
319   } else {
320     *shout_metadata = g_strdup_printf ("Unknown - Unknown");
321   }
322
323   GST_LOG ("shout metadata is now: %s", *shout_metadata);
324 }
325
326 #if 0
327 static void
328 gst_shout2send_set_metadata (GstShout2send * shout2send)
329 {
330   const GstTagList *user_tags;
331   GstTagList *copy;
332   char *tempmetadata;
333   shout_metadata_t *pmetadata;
334
335   g_return_if_fail (shout2send != NULL);
336   user_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (shout2send));
337   if ((shout2send->tags == NULL) && (user_tags == NULL)) {
338     return;
339   }
340   copy = gst_tag_list_merge (user_tags, shout2send->tags,
341       gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (shout2send)));
342   /* lets get the artist and song tags */
343   tempmetadata = NULL;
344   gst_tag_list_foreach ((GstTagList *) copy, set_shout_metadata,
345       (gpointer) & tempmetadata);
346   if (tempmetadata) {
347     pmetadata = shout_metadata_new ();
348     shout_metadata_add (pmetadata, "song", tempmetadata);
349     shout_set_metadata (shout2send->conn, pmetadata);
350     shout_metadata_free (pmetadata);
351   }
352
353   gst_tag_list_free (copy);
354 }
355 #endif
356
357
358 static gboolean
359 gst_shout2send_event (GstBaseSink * sink, GstEvent * event)
360 {
361   GstShout2send *shout2send;
362   gboolean ret = TRUE;
363
364   shout2send = GST_SHOUT2SEND (sink);
365
366   GST_LOG_OBJECT (shout2send, "got %s event", GST_EVENT_TYPE_NAME (event));
367
368   switch (GST_EVENT_TYPE (event)) {
369     case GST_EVENT_TAG:{
370       /* vorbis audio doesnt need metadata setting on the icecast level, only mp3 */
371       if (shout2send->tags && shout2send->audio_format == SHOUT_FORMAT_MP3) {
372         GstTagList *list;
373
374         gst_event_parse_tag (event, &list);
375         GST_DEBUG_OBJECT (shout2send, "tags=%" GST_PTR_FORMAT, list);
376         gst_tag_list_insert (shout2send->tags,
377             list,
378             gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (shout2send)));
379         /* lets get the artist and song tags */
380         gst_tag_list_foreach ((GstTagList *) list,
381             set_shout_metadata, shout2send);
382         if (shout2send->songmetadata && shout2send->connected) {
383           shout_metadata_t *pmetadata;
384
385           GST_DEBUG_OBJECT (shout2send, "metadata now: %s",
386               shout2send->songmetadata);
387
388           pmetadata = shout_metadata_new ();
389           shout_metadata_add (pmetadata, "song", shout2send->songmetadata);
390           shout_set_metadata (shout2send->conn, pmetadata);
391           shout_metadata_free (pmetadata);
392         }
393       }
394       break;
395     }
396     default:{
397       GST_LOG_OBJECT (shout2send, "let base class handle event");
398       if (GST_BASE_SINK_CLASS (parent_class)->event) {
399         event = gst_event_ref (event);
400         ret = GST_BASE_SINK_CLASS (parent_class)->event (sink, event);
401       }
402       break;
403     }
404   }
405
406   return ret;
407 }
408
409 static gboolean
410 gst_shout2send_start (GstBaseSink * basesink)
411 {
412   GstShout2send *sink = GST_SHOUT2SEND (basesink);
413   const gchar *cur_prop;
414   gshort proto = 3;
415   gchar *version_string;
416
417   GST_DEBUG_OBJECT (sink, "starting");
418
419   sink->conn = shout_new ();
420
421   switch (sink->protocol) {
422     case SHOUT2SEND_PROTOCOL_XAUDIOCAST:
423       proto = SHOUT_PROTOCOL_XAUDIOCAST;
424       break;
425     case SHOUT2SEND_PROTOCOL_ICY:
426       proto = SHOUT_PROTOCOL_ICY;
427       break;
428     case SHOUT2SEND_PROTOCOL_HTTP:
429       proto = SHOUT_PROTOCOL_HTTP;
430       break;
431   }
432
433   cur_prop = "protocol";
434   GST_DEBUG_OBJECT (sink, "setting protocol: %d", sink->protocol);
435   if (shout_set_protocol (sink->conn, proto) != SHOUTERR_SUCCESS)
436     goto set_failed;
437
438   /* --- FIXME: shout requires an ip, and fails if it is given a host. */
439   /* may want to put convert_to_ip(shout2send->ip) here */
440   cur_prop = "ip";
441   GST_DEBUG_OBJECT (sink, "setting ip: %s", sink->ip);
442   if (shout_set_host (sink->conn, sink->ip) != SHOUTERR_SUCCESS)
443     goto set_failed;
444
445   cur_prop = "port";
446   GST_DEBUG_OBJECT (sink, "setting port: %u", sink->port);
447   if (shout_set_port (sink->conn, sink->port) != SHOUTERR_SUCCESS)
448     goto set_failed;
449
450   cur_prop = "password";
451   GST_DEBUG_OBJECT (sink, "setting password: %s", sink->password);
452   if (shout_set_password (sink->conn, sink->password) != SHOUTERR_SUCCESS)
453     goto set_failed;
454
455   cur_prop = "streamname";
456   GST_DEBUG_OBJECT (sink, "setting %s: %s", cur_prop, sink->streamname);
457   if (shout_set_name (sink->conn, sink->streamname) != SHOUTERR_SUCCESS)
458     goto set_failed;
459
460   cur_prop = "description";
461   GST_DEBUG_OBJECT (sink, "setting %s: %s", cur_prop, sink->description);
462   if (shout_set_description (sink->conn, sink->description) != SHOUTERR_SUCCESS)
463     goto set_failed;
464
465   cur_prop = "genre";
466   GST_DEBUG_OBJECT (sink, "setting %s: %s", cur_prop, sink->genre);
467   if (shout_set_genre (sink->conn, sink->genre) != SHOUTERR_SUCCESS)
468     goto set_failed;
469
470   cur_prop = "mount";
471   GST_DEBUG_OBJECT (sink, "setting %s: %s", cur_prop, sink->mount);
472   if (shout_set_mount (sink->conn, sink->mount) != SHOUTERR_SUCCESS)
473     goto set_failed;
474
475   cur_prop = "username";
476   GST_DEBUG_OBJECT (sink, "setting %s: %s", cur_prop, "source");
477   if (shout_set_user (sink->conn, sink->username) != SHOUTERR_SUCCESS)
478     goto set_failed;
479
480   version_string = gst_version_string ();
481   cur_prop = "agent";
482   GST_DEBUG_OBJECT (sink, "setting %s: %s", cur_prop, version_string);
483   if (shout_set_agent (sink->conn, version_string) != SHOUTERR_SUCCESS) {
484     g_free (version_string);
485     goto set_failed;
486   }
487
488   g_free (version_string);
489   return TRUE;
490
491 /* ERROR */
492 set_failed:
493   {
494     GST_ELEMENT_ERROR (sink, LIBRARY, SETTINGS, (NULL),
495         ("Error setting %s: %s", cur_prop, shout_get_error (sink->conn)));
496     return FALSE;
497   }
498 }
499
500 static gboolean
501 gst_shout2send_connect (GstShout2send * sink)
502 {
503   GST_DEBUG_OBJECT (sink, "Connection format is: %s",
504       (sink->audio_format == SHOUT_FORMAT_VORBIS) ? "vorbis" :
505       ((sink->audio_format == SHOUT_FORMAT_MP3) ? "mp3" : "unknown"));
506
507   if (shout_set_format (sink->conn, sink->audio_format) != SHOUTERR_SUCCESS)
508     goto could_not_set_format;
509
510   if (shout_open (sink->conn) != SHOUTERR_SUCCESS)
511     goto could_not_connect;
512
513   GST_DEBUG_OBJECT (sink, "connected to server");
514   sink->connected = TRUE;
515
516   /* let's set metadata */
517   if (sink->songmetadata) {
518     shout_metadata_t *pmetadata;
519
520     GST_DEBUG_OBJECT (sink, "shout metadata now: %s", sink->songmetadata);
521     pmetadata = shout_metadata_new ();
522     shout_metadata_add (pmetadata, "song", sink->songmetadata);
523     shout_set_metadata (sink->conn, pmetadata);
524     shout_metadata_free (pmetadata);
525   }
526
527   return TRUE;
528
529 /* ERRORS */
530 could_not_set_format:
531   {
532     GST_ELEMENT_ERROR (sink, LIBRARY, SETTINGS, (NULL),
533         ("Error setting connection format: %s", shout_get_error (sink->conn)));
534     return FALSE;
535   }
536
537 could_not_connect:
538   {
539     GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE,
540         (_("Could not connect to server")),
541         ("shout_open() failed: err=%s", shout_get_error (sink->conn)));
542     g_signal_emit (sink, gst_shout2send_signals[SIGNAL_CONNECTION_PROBLEM], 0,
543         shout_get_errno (sink->conn));
544     return FALSE;
545   }
546 }
547
548 static gboolean
549 gst_shout2send_stop (GstBaseSink * basesink)
550 {
551   GstShout2send *sink = GST_SHOUT2SEND (basesink);
552
553   if (sink->conn) {
554     if (sink->connected)
555       shout_close (sink->conn);
556     shout_free (sink->conn);
557     sink->conn = NULL;
558   }
559
560   if (sink->songmetadata) {
561     g_free (sink->songmetadata);
562     sink->songmetadata = NULL;
563   }
564
565   sink->connected = FALSE;
566
567   return TRUE;
568 }
569
570 static GstFlowReturn
571 gst_shout2send_render (GstBaseSink * basesink, GstBuffer * buf)
572 {
573   GstShout2send *sink;
574   glong ret;
575
576   sink = GST_SHOUT2SEND (basesink);
577
578   /* presumably we connect here because we need to know the format before
579    * we can set up the connection, which we don't know yet in _start() */
580   if (!sink->connected) {
581     if (!gst_shout2send_connect (sink))
582       return GST_FLOW_ERROR;
583   }
584
585   /* FIXME: do we want to do syncing here at all? (tpm) */
586   /* GST_LOG_OBJECT (sink, "using libshout to sync"); */
587   shout_sync (sink->conn);
588
589   GST_LOG_OBJECT (sink, "sending %u bytes of data", GST_BUFFER_SIZE (buf));
590   ret = shout_send (sink->conn, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
591   if (ret != SHOUTERR_SUCCESS)
592     goto send_error;
593
594   return GST_FLOW_OK;
595
596 /* ERRORS */
597 send_error:
598   {
599     GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, (NULL),
600         ("shout_send() failed: %s", shout_get_error (sink->conn)));
601     g_signal_emit (sink, gst_shout2send_signals[SIGNAL_CONNECTION_PROBLEM], 0,
602         shout_get_errno (sink->conn));
603     return GST_FLOW_ERROR;
604   }
605 }
606
607 static void
608 gst_shout2send_set_property (GObject * object, guint prop_id,
609     const GValue * value, GParamSpec * pspec)
610 {
611   GstShout2send *shout2send;
612
613   shout2send = GST_SHOUT2SEND (object);
614   switch (prop_id) {
615
616     case ARG_IP:
617       if (shout2send->ip)
618         g_free (shout2send->ip);
619       shout2send->ip = g_strdup (g_value_get_string (value));
620       break;
621     case ARG_PORT:
622       shout2send->port = g_value_get_int (value);
623       break;
624     case ARG_PASSWORD:
625       if (shout2send->password)
626         g_free (shout2send->password);
627       shout2send->password = g_strdup (g_value_get_string (value));
628       break;
629     case ARG_USERNAME:
630       if (shout2send->username)
631         g_free (shout2send->username);
632       shout2send->username = g_strdup (g_value_get_string (value));
633       break;
634     case ARG_STREAMNAME:       /* Name of the stream */
635       if (shout2send->streamname)
636         g_free (shout2send->streamname);
637       shout2send->streamname = g_strdup (g_value_get_string (value));
638       break;
639     case ARG_DESCRIPTION:      /* Description of the stream */
640       if (shout2send->description)
641         g_free (shout2send->description);
642       shout2send->description = g_strdup (g_value_get_string (value));
643       break;
644     case ARG_GENRE:            /* Genre of the stream */
645       if (shout2send->genre)
646         g_free (shout2send->genre);
647       shout2send->genre = g_strdup (g_value_get_string (value));
648       break;
649     case ARG_PROTOCOL:         /* protocol to connect with */
650       shout2send->protocol = g_value_get_enum (value);
651       break;
652     case ARG_MOUNT:            /* mountpoint of stream (icecast only) */
653       if (shout2send->mount)
654         g_free (shout2send->mount);
655       shout2send->mount = g_strdup (g_value_get_string (value));
656       break;
657     case ARG_URL:              /* Url of the stream (I'm guessing) */
658       if (shout2send->url)
659         g_free (shout2send->url);
660       shout2send->url = g_strdup (g_value_get_string (value));
661       break;
662     default:
663       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
664       break;
665   }
666 }
667
668 static void
669 gst_shout2send_get_property (GObject * object, guint prop_id,
670     GValue * value, GParamSpec * pspec)
671 {
672   GstShout2send *shout2send;
673
674   shout2send = GST_SHOUT2SEND (object);
675   switch (prop_id) {
676
677     case ARG_IP:
678       g_value_set_string (value, shout2send->ip);
679       break;
680     case ARG_PORT:
681       g_value_set_int (value, shout2send->port);
682       break;
683     case ARG_PASSWORD:
684       g_value_set_string (value, shout2send->password);
685       break;
686     case ARG_USERNAME:
687       g_value_set_string (value, shout2send->username);
688       break;
689     case ARG_STREAMNAME:       /* Name of the stream */
690       g_value_set_string (value, shout2send->streamname);
691       break;
692     case ARG_DESCRIPTION:      /* Description of the stream */
693       g_value_set_string (value, shout2send->description);
694       break;
695     case ARG_GENRE:            /* Genre of the stream */
696       g_value_set_string (value, shout2send->genre);
697       break;
698     case ARG_PROTOCOL:         /* protocol to connect with */
699       g_value_set_enum (value, shout2send->protocol);
700       break;
701     case ARG_MOUNT:            /* mountpoint of stream (icecast only) */
702       g_value_set_string (value, shout2send->mount);
703       break;
704     case ARG_URL:              /* Url of stream (I'm guessing) */
705       g_value_set_string (value, shout2send->url);
706       break;
707     default:
708       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
709       break;
710   }
711 }
712
713 static gboolean
714 gst_shout2send_setcaps (GstPad * pad, GstCaps * caps)
715 {
716   const gchar *mimetype;
717   GstShout2send *shout2send;
718   gboolean ret = TRUE;
719
720   shout2send = GST_SHOUT2SEND (GST_OBJECT_PARENT (pad));
721
722   mimetype = gst_structure_get_name (gst_caps_get_structure (caps, 0));
723
724   GST_DEBUG_OBJECT (shout2send, "mimetype of caps given is: %s", mimetype);
725
726   if (!strcmp (mimetype, "audio/mpeg")) {
727     shout2send->audio_format = SHOUT_FORMAT_MP3;
728   } else if (!strcmp (mimetype, "application/ogg")) {
729     shout2send->audio_format = SHOUT_FORMAT_VORBIS;
730   } else {
731     ret = FALSE;
732   }
733
734   return ret;
735 }
736
737 static gboolean
738 plugin_init (GstPlugin * plugin)
739 {
740 #ifdef ENABLE_NLS
741   setlocale (LC_ALL, "");
742   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
743 #endif /* ENABLE_NLS */
744
745   return gst_element_register (plugin, "shout2send", GST_RANK_NONE,
746       GST_TYPE_SHOUT2SEND);
747 }
748
749 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
750     GST_VERSION_MINOR,
751     "shout2send",
752     "Sends data to an icecast server using libshout2",
753     plugin_init,
754     VERSION, "LGPL", "libshout2", "http://www.icecast.org/download.html")