little more robust error handling
git-svn-id: https://svn.musicpd.org/mpd/trunk@2341 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
61a88f1692
commit
0da404ebb2
|
@ -224,31 +224,35 @@ static void shout_closeDevice(AudioOutput * audioOutput) {
|
||||||
audioOutput->open = 0;
|
audioOutput->open = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shout_handleError(ShoutData * sd, int err) {
|
static int shout_handleError(ShoutData * sd, int err) {
|
||||||
switch(err) {
|
switch(err) {
|
||||||
case SHOUTERR_SUCCESS:
|
case SHOUTERR_SUCCESS:
|
||||||
break;
|
break;
|
||||||
case SHOUTERR_UNCONNECTED:
|
case SHOUTERR_UNCONNECTED:
|
||||||
case SHOUTERR_SOCKET:
|
case SHOUTERR_SOCKET:
|
||||||
ERROR("Lost shout connection, attempting to reconnect\n");
|
ERROR("Lost shout connection\n");
|
||||||
shout_close(sd->shoutConn);
|
return -1;
|
||||||
shout_open(sd->shoutConn);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
ERROR("shout: error: %s\n", shout_get_error(sd->shoutConn));
|
ERROR("shout: error: %s\n", shout_get_error(sd->shoutConn));
|
||||||
break;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_page(ShoutData * sd) {
|
static int write_page(ShoutData * sd) {
|
||||||
if(!sd->og.header_len || !sd->og.body_len) return;
|
|
||||||
|
|
||||||
shout_sync(sd->shoutConn);
|
shout_sync(sd->shoutConn);
|
||||||
int err = shout_send(sd->shoutConn, sd->og.header, sd->og.header_len);
|
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);
|
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);*/
|
/*shout_sync(sd->shoutConn);*/
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
shout_closeShoutConn(sd);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int initEncoder(ShoutData * sd) {
|
static int initEncoder(ShoutData * sd) {
|
||||||
|
@ -277,7 +281,7 @@ static int shout_openDevice(AudioOutput * audioOutput,
|
||||||
{
|
{
|
||||||
ShoutData * sd = (ShoutData *)audioOutput->data;
|
ShoutData * sd = (ShoutData *)audioOutput->data;
|
||||||
|
|
||||||
memcpy(&(sd->inAudioFormat), audioFormat, sizeof(AudioFormat));
|
memmove(&(sd->inAudioFormat), audioFormat, sizeof(AudioFormat));
|
||||||
|
|
||||||
if(0 == memcmp(&(sd->inAudioFormat), &(sd->outAudioFormat),
|
if(0 == memcmp(&(sd->inAudioFormat), &(sd->outAudioFormat),
|
||||||
sizeof(AudioFormat)))
|
sizeof(AudioFormat)))
|
||||||
|
@ -314,7 +318,7 @@ static int shout_openDevice(AudioOutput * audioOutput,
|
||||||
|
|
||||||
while(ogg_stream_flush(&(sd->os), &(sd->og)))
|
while(ogg_stream_flush(&(sd->os), &(sd->og)))
|
||||||
{
|
{
|
||||||
write_page(sd);
|
if(write_page(sd) < 0) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sd->opened = 1;
|
sd->opened = 1;
|
||||||
|
@ -348,6 +352,12 @@ static int shout_play(AudioOutput * audioOutput, char * playChunk, int size) {
|
||||||
int samples;
|
int samples;
|
||||||
int bytes = sd->outAudioFormat.bits/8;
|
int bytes = sd->outAudioFormat.bits/8;
|
||||||
|
|
||||||
|
if(!sd->opened) {
|
||||||
|
if(shout_openDevice(audioOutput, &(sd->inAudioFormat)) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(sd->audioFormatConvert) {
|
if(sd->audioFormatConvert) {
|
||||||
shout_convertAudioFormat(sd, &playChunk, &size);
|
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) {
|
if(ogg_stream_pageout(&(sd->os), &(sd->og)) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
write_page(sd);
|
if(write_page(sd) < 0) return -1;
|
||||||
} while(ogg_page_eos(&(sd->og)));
|
} 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)))
|
while(ogg_stream_flush(&(sd->os), &(sd->og)))
|
||||||
{
|
{
|
||||||
write_page(sd);
|
if(write_page(sd) < 0) return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue