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