aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutput_shout.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-10-26 12:56:10 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-10-26 12:56:10 +0000
commitf20de32d0d8cd4c1a2ea4d297777c9328bf92b4d (patch)
tree109eef62551e1b7c2067e61a43d39e393aaff9a2 /src/audioOutput_shout.c
parentd9c89943194f4ea7ed0197b9931cef7e635796f8 (diff)
downloadmpd-f20de32d0d8cd4c1a2ea4d297777c9328bf92b4d.tar.gz
mpd-f20de32d0d8cd4c1a2ea4d297777c9328bf92b4d.tar.xz
mpd-f20de32d0d8cd4c1a2ea4d297777c9328bf92b4d.zip
fix segfault when reconnecting to icecast server, this was due to error sending metadata and not checking afterward if connection is open still
git-svn-id: https://svn.musicpd.org/mpd/trunk@2349 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/audioOutput_shout.c')
-rw-r--r--src/audioOutput_shout.c82
1 files changed, 47 insertions, 35 deletions
diff --git a/src/audioOutput_shout.c b/src/audioOutput_shout.c
index c2be92854..936f7575a 100644
--- a/src/audioOutput_shout.c
+++ b/src/audioOutput_shout.c
@@ -201,12 +201,12 @@ static void clearEncoder(ShoutData * sd) {
static void shout_closeShoutConn(ShoutData * sd) {
if(sd->opened) {
+ clearEncoder(sd);
+
if(shout_close(sd->shoutConn) != SHOUTERR_SUCCESS) {
ERROR("problem closing connection to shout server: "
"%s\n", shout_get_error(sd->shoutConn));
}
-
- clearEncoder(sd);
}
sd->opened = 0;
@@ -259,6 +259,18 @@ fail:
return -1;
}
+#define addTag(name, value) { \
+ if(value) vorbis_comment_add_tag(&(sd->vc), name, value); \
+}
+
+static void copyTagToVorbisComment(ShoutData * sd) {
+ if(sd->tag) {
+ addTag("ARTIST", sd->tag->artist);
+ addTag("ALBUM", sd->tag->album);
+ addTag("TITLE", sd->tag->title);
+ }
+}
+
static int initEncoder(ShoutData * sd) {
vorbis_info_init(&(sd->vi));
@@ -280,24 +292,9 @@ static int initEncoder(ShoutData * sd) {
return 0;
}
-static int shout_openDevice(AudioOutput * audioOutput,
- AudioFormat * audioFormat)
-{
+static int shout_openShoutConn(AudioOutput * audioOutput) {
ShoutData * sd = (ShoutData *)audioOutput->data;
- memmove(&(sd->inAudioFormat), audioFormat, sizeof(AudioFormat));
-
- if(0 == memcmp(&(sd->inAudioFormat), &(sd->outAudioFormat),
- sizeof(AudioFormat)))
- {
- sd->audioFormatConvert = 0;
- }
- else sd->audioFormatConvert = 1;
-
- audioOutput->open = 1;
-
- if(sd->opened) return 0;
-
if(shout_open(sd->shoutConn) != SHOUTERR_SUCCESS)
{
ERROR("problem opening connection to shout server: %s\n",
@@ -313,6 +310,8 @@ static int shout_openDevice(AudioOutput * audioOutput,
return -1;
}
+ copyTagToVorbisComment(sd);
+
vorbis_analysis_headerout(&(sd->vd), &(sd->vc), &(sd->header_main),
&(sd->header_comments), &(sd->header_codebooks));
@@ -325,11 +324,35 @@ static int shout_openDevice(AudioOutput * audioOutput,
if(write_page(sd) < 0) return -1;
}
+ if(sd->tag) freeMpdTag(sd->tag);
+ sd->tag = NULL;
+
sd->opened = 1;
return 0;
}
+static int shout_openDevice(AudioOutput * audioOutput,
+ AudioFormat * audioFormat)
+{
+ ShoutData * sd = (ShoutData *)audioOutput->data;
+
+ memcpy(&(sd->inAudioFormat), audioFormat, sizeof(AudioFormat));
+
+ if(0 == memcmp(&(sd->inAudioFormat), &(sd->outAudioFormat),
+ sizeof(AudioFormat)))
+ {
+ sd->audioFormatConvert = 0;
+ }
+ else sd->audioFormatConvert = 1;
+
+ audioOutput->open = 1;
+
+ if(sd->opened) return 0;
+
+ return shout_openShoutConn(audioOutput);
+}
+
static void shout_convertAudioFormat(ShoutData * sd, char ** chunkArgPtr,
int * sizeArgPtr)
{
@@ -349,25 +372,17 @@ static void shout_convertAudioFormat(ShoutData * sd, char ** chunkArgPtr,
*chunkArgPtr = sd->convBuffer;
}
-#define addTag(name, value) { \
- if(value) vorbis_comment_add_tag(&(sd->vc), name, value); \
-}
-
static void shout_sendMetadata(ShoutData * sd) {
ogg_int64_t granulepos = sd->vd.granulepos;
- if(!sd->opened) return;
+ if(!sd->opened || !sd->tag) return;
clearEncoder(sd);
if(initEncoder(sd) < 0) return;
sd->vd.granulepos = granulepos;
- if(sd->tag) {
- addTag("ARTIST", sd->tag->artist);
- addTag("ALBUM", sd->tag->album);
- addTag("TITLE", sd->tag->title);
- }
+ copyTagToVorbisComment(sd);
vorbis_analysis_headerout(&(sd->vd), &(sd->vc), &(sd->header_main),
&(sd->header_comments), &(sd->header_codebooks));
@@ -376,15 +391,12 @@ static void shout_sendMetadata(ShoutData * sd) {
ogg_stream_packetin(&(sd->os), &(sd->header_comments));
ogg_stream_packetin(&(sd->os), &(sd->header_codebooks));
- /*vorbis_commentheader_out(&(sd->vc), &(sd->header_comments));
- ogg_stream_packetin(&(sd->os), &(sd->header_comments));*/
-
while(ogg_stream_flush(&(sd->os), &(sd->og)))
{
if(write_page(sd) < 0) return;
}
- freeMpdTag(sd->tag);
+ if(sd->tag) freeMpdTag(sd->tag);
sd->tag = NULL;
}
@@ -395,14 +407,14 @@ static int shout_play(AudioOutput * audioOutput, char * playChunk, int size) {
int samples;
int bytes = sd->outAudioFormat.bits/8;
+ if(sd->opened && sd->tag) shout_sendMetadata(sd);
+
if(!sd->opened) {
- if(shout_openDevice(audioOutput, &(sd->inAudioFormat)) < 0) {
+ if(shout_openShoutConn(audioOutput) < 0) {
return -1;
}
}
- if(sd->tag) shout_sendMetadata(sd);
-
if(sd->audioFormatConvert) {
shout_convertAudioFormat(sd, &playChunk, &size);
}