aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutput_shout.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-10-25 21:36:08 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-10-25 21:36:08 +0000
commit0da404ebb2a61677eed22abc0add7964ded73937 (patch)
treef1f8cd78a50a91b4edfd4c4da4ad10b80ce83e89 /src/audioOutput_shout.c
parent61a88f1692304d12c8bad0cb7335d20c65ed8b94 (diff)
downloadmpd-0da404ebb2a61677eed22abc0add7964ded73937.tar.gz
mpd-0da404ebb2a61677eed22abc0add7964ded73937.tar.xz
mpd-0da404ebb2a61677eed22abc0add7964ded73937.zip
little more robust error handling
git-svn-id: https://svn.musicpd.org/mpd/trunk@2341 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/audioOutput_shout.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/audioOutput_shout.c b/src/audioOutput_shout.c
index 777fe9c41..b33cc5820 100644
--- a/src/audioOutput_shout.c
+++ b/src/audioOutput_shout.c
@@ -224,31 +224,35 @@ static void shout_closeDevice(AudioOutput * audioOutput) {
audioOutput->open = 0;
}
-static void shout_handleError(ShoutData * sd, int err) {
+static int shout_handleError(ShoutData * sd, int err) {
switch(err) {
case SHOUTERR_SUCCESS:
break;
case SHOUTERR_UNCONNECTED:
case SHOUTERR_SOCKET:
- ERROR("Lost shout connection, attempting to reconnect\n");
- shout_close(sd->shoutConn);
- shout_open(sd->shoutConn);
- break;
+ ERROR("Lost shout connection\n");
+ return -1;
default:
ERROR("shout: error: %s\n", shout_get_error(sd->shoutConn));
- break;
+ return -1;
}
-}
-static void write_page(ShoutData * sd) {
- if(!sd->og.header_len || !sd->og.body_len) return;
+ return 0;
+}
+static int write_page(ShoutData * sd) {
shout_sync(sd->shoutConn);
int err = shout_send(sd->shoutConn, sd->og.header, sd->og.header_len);
- shout_handleError(sd, err);
+ if(shout_handleError(sd, err) < 0) goto fail;
err = shout_send(sd->shoutConn, sd->og.body, sd->og.body_len);
- shout_handleError(sd, err);
+ if(shout_handleError(sd, err) < 0) goto fail;
/*shout_sync(sd->shoutConn);*/
+
+ return 0;
+
+fail:
+ shout_closeShoutConn(sd);
+ return -1;
}
static int initEncoder(ShoutData * sd) {
@@ -277,7 +281,7 @@ static int shout_openDevice(AudioOutput * audioOutput,
{
ShoutData * sd = (ShoutData *)audioOutput->data;
- memcpy(&(sd->inAudioFormat), audioFormat, sizeof(AudioFormat));
+ memmove(&(sd->inAudioFormat), audioFormat, sizeof(AudioFormat));
if(0 == memcmp(&(sd->inAudioFormat), &(sd->outAudioFormat),
sizeof(AudioFormat)))
@@ -314,7 +318,7 @@ static int shout_openDevice(AudioOutput * audioOutput,
while(ogg_stream_flush(&(sd->os), &(sd->og)))
{
- write_page(sd);
+ if(write_page(sd) < 0) return -1;
}
sd->opened = 1;
@@ -348,6 +352,12 @@ static int shout_play(AudioOutput * audioOutput, char * playChunk, int size) {
int samples;
int bytes = sd->outAudioFormat.bits/8;
+ if(!sd->opened) {
+ if(shout_openDevice(audioOutput, &(sd->inAudioFormat)) < 0) {
+ return -1;
+ }
+ }
+
if(sd->audioFormatConvert) {
shout_convertAudioFormat(sd, &playChunk, &size);
}
@@ -377,7 +387,7 @@ static int shout_play(AudioOutput * audioOutput, char * playChunk, int size) {
if(ogg_stream_pageout(&(sd->os), &(sd->og)) == 0) {
break;
}
- write_page(sd);
+ if(write_page(sd) < 0) return -1;
} while(ogg_page_eos(&(sd->og)));
}
}
@@ -417,7 +427,7 @@ static void shout_sendMetadata(AudioOutput * audioOutput, MpdTag * tag) {
while(ogg_stream_flush(&(sd->os), &(sd->og)))
{
- write_page(sd);
+ if(write_page(sd) < 0) return -1;
}
}