aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutput_shout.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-10-20 20:41:21 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-10-20 20:41:21 +0000
commit72a7740fd5755d09e13978bde7f729deb43bdd55 (patch)
tree019f3e630680fabe7cfa5755f1497b142f5f1f34 /src/audioOutput_shout.c
parenteefcf79436c80075fa373e65bf6249ba9b4c9b04 (diff)
downloadmpd-72a7740fd5755d09e13978bde7f729deb43bdd55.tar.gz
mpd-72a7740fd5755d09e13978bde7f729deb43bdd55.tar.xz
mpd-72a7740fd5755d09e13978bde7f729deb43bdd55.zip
shout audioOutput will now connect and disconnect from icecast server
git-svn-id: https://svn.musicpd.org/mpd/trunk@2285 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/audioOutput_shout.c109
1 files changed, 105 insertions, 4 deletions
diff --git a/src/audioOutput_shout.c b/src/audioOutput_shout.c
index a895b63ae..5e14b0467 100644
--- a/src/audioOutput_shout.c
+++ b/src/audioOutput_shout.c
@@ -26,33 +26,127 @@
#include <assert.h>
#include <signal.h>
+#include <shout/shout.h>
+#include <vorbis/vorbisenc.h>
+
+static int shoutInitCount = 0;
+
typedef struct _ShoutData {
+ shout_t * shoutConn;
} ShoutData;
static ShoutData * newShoutData() {
ShoutData * ret = malloc(sizeof(ShoutData));
+ ret->shoutConn = shout_new();
+
return ret;
}
static void freeShoutData(ShoutData * sd) {
+ if(sd->shoutConn) shout_free(sd->shoutConn);
+
free(sd);
}
-static void shout_initDriver(AudioOutput * audioOutput) {
- ShoutData * sd = newShoutData();
+static int shout_initDriver(AudioOutput * audioOutput) {
+ ShoutData * sd;
+ char * test;
+ int port;
+ char * host;
+ char * mount;
+ char * passwd;
+ char * user;
+ char * name;
+
+ if(!getConf()[CONF_SHOUT_HOST]) {
+ return -1;
+ }
+
+ sd = newShoutData();
+
+ if(!getConf()[CONF_SHOUT_MOUNT]) {
+ ERROR("shout host defined but not shout mount point\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if(!getConf()[CONF_SHOUT_PORT]) {
+ ERROR("shout host defined but not shout port\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if(!getConf()[CONF_SHOUT_PASSWD]) {
+ ERROR("shout host defined but not shout password\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if(!getConf()[CONF_SHOUT_NAME]) {
+ ERROR("shout host defined but not shout name\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if(!getConf()[CONF_SHOUT_USER]) {
+ ERROR("shout host defined but not shout user\n");
+ exit(EXIT_FAILURE);
+ }
+
+ host = getConf()[CONF_SHOUT_HOST];
+ passwd = getConf()[CONF_SHOUT_PASSWD];
+ user = getConf()[CONF_SHOUT_USER];
+ mount = getConf()[CONF_SHOUT_MOUNT];
+ name = getConf()[CONF_SHOUT_NAME];
+
+ port = strtol(getConf()[CONF_SHOUT_PORT], &test, 10);
+
+ if(*test != '\0' || port <= 0) {
+ ERROR("shout port \"%s\" is not a positive integer\n",
+ getConf()[CONF_SHOUT_PORT]);
+ exit(EXIT_FAILURE);
+ }
+
+ if(shout_set_host(sd->shoutConn, host) != SHOUTERR_SUCCESS ||
+ shout_set_port(sd->shoutConn, port) != SHOUTERR_SUCCESS ||
+ shout_set_password(sd->shoutConn, passwd) != SHOUTERR_SUCCESS ||
+ shout_set_mount(sd->shoutConn, mount) != SHOUTERR_SUCCESS ||
+ shout_set_name(sd->shoutConn, name) != SHOUTERR_SUCCESS ||
+ shout_set_user(sd->shoutConn, user) != SHOUTERR_SUCCESS ||
+ shout_set_format(sd->shoutConn, SHOUT_FORMAT_VORBIS)
+ != SHOUTERR_SUCCESS ||
+ shout_set_protocol(sd->shoutConn, SHOUT_PROTOCOL_HTTP)
+ != SHOUTERR_SUCCESS)
+ {
+ ERROR("error configuring shout: %s\n",
+ shout_get_error(sd->shoutConn));
+ exit(EXIT_FAILURE);
+ }
audioOutput->data = sd;
+
+ if(shoutInitCount == 0) shout_init();
+
+ shoutInitCount++;
+
+ return 0;
}
static void shout_finishDriver(AudioOutput * audioOutput) {
ShoutData * sd = (ShoutData *)audioOutput->data;
freeShoutData(sd);
+
+ shoutInitCount--;
+
+ if(shoutInitCount == 0) shout_shutdown();
}
static void shout_closeDevice(AudioOutput * audioOutput) {
- /*ShoutData * sd = (ShoutData *) audioOutput->data;*/
+ ShoutData * sd = (ShoutData *) audioOutput->data;
+
+ if(shout_close(sd->shoutConn) != SHOUTERR_SUCCESS)
+ {
+ ERROR("problem closing connection to shout server: %s\n",
+ shout_get_error(sd->shoutConn));
+ }
audioOutput->open = 0;
}
@@ -60,7 +154,14 @@ static void shout_closeDevice(AudioOutput * audioOutput) {
static int shout_openDevice(AudioOutput * audioOutput,
AudioFormat * audioFormat)
{
- /*ShoutData * sd = (ShoutData *)audioOutput->data;*/
+ ShoutData * sd = (ShoutData *)audioOutput->data;
+
+ if(shout_open(sd->shoutConn) != SHOUTERR_SUCCESS)
+ {
+ ERROR("problem opening connection to shout server: %s\n",
+ shout_get_error(sd->shoutConn));
+ return -1;
+ }
audioOutput->open = 1;