lets try this soltuion to sending metadata, here we store metadata to send on the next shout_play
git-svn-id: https://svn.musicpd.org/mpd/trunk@2346 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
91c7621376
commit
547448eee9
@ -64,6 +64,8 @@ typedef struct _ShoutData {
|
|||||||
int audioFormatConvert;
|
int audioFormatConvert;
|
||||||
|
|
||||||
int opened;
|
int opened;
|
||||||
|
|
||||||
|
MpdTag * tag;
|
||||||
} ShoutData;
|
} ShoutData;
|
||||||
|
|
||||||
static ShoutData * newShoutData() {
|
static ShoutData * newShoutData() {
|
||||||
@ -73,12 +75,14 @@ static ShoutData * newShoutData() {
|
|||||||
ret->convBuffer = NULL;
|
ret->convBuffer = NULL;
|
||||||
ret->convBufferLen = 0;
|
ret->convBufferLen = 0;
|
||||||
ret->opened = 0;
|
ret->opened = 0;
|
||||||
|
ret->tag = NULL;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void freeShoutData(ShoutData * sd) {
|
static void freeShoutData(ShoutData * sd) {
|
||||||
if(sd->shoutConn) shout_free(sd->shoutConn);
|
if(sd->shoutConn) shout_free(sd->shoutConn);
|
||||||
|
if(sd->tag) freeMpdTag(sd->tag);
|
||||||
|
|
||||||
free(sd);
|
free(sd);
|
||||||
}
|
}
|
||||||
@ -345,6 +349,45 @@ static void shout_convertAudioFormat(ShoutData * sd, char ** chunkArgPtr,
|
|||||||
*chunkArgPtr = sd->convBuffer;
|
*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;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
vorbis_analysis_headerout(&(sd->vd), &(sd->vc), &(sd->header_main),
|
||||||
|
&(sd->header_comments), &(sd->header_codebooks));
|
||||||
|
|
||||||
|
ogg_stream_packetin(&(sd->os), &(sd->header_main));
|
||||||
|
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);
|
||||||
|
sd->tag = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int shout_play(AudioOutput * audioOutput, char * playChunk, int size) {
|
static int shout_play(AudioOutput * audioOutput, char * playChunk, int size) {
|
||||||
int i,j;
|
int i,j;
|
||||||
ShoutData * sd = (ShoutData *)audioOutput->data;
|
ShoutData * sd = (ShoutData *)audioOutput->data;
|
||||||
@ -358,6 +401,8 @@ static int shout_play(AudioOutput * audioOutput, char * playChunk, int size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sd->tag) shout_sendMetadata(sd);
|
||||||
|
|
||||||
if(sd->audioFormatConvert) {
|
if(sd->audioFormatConvert) {
|
||||||
shout_convertAudioFormat(sd, &playChunk, &size);
|
shout_convertAudioFormat(sd, &playChunk, &size);
|
||||||
}
|
}
|
||||||
@ -395,42 +440,15 @@ static int shout_play(AudioOutput * audioOutput, char * playChunk, int size) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define addTag(name, value) { \
|
static void shout_setTag(AudioOutput * audioOutput, MpdTag * tag) {
|
||||||
if(value) vorbis_comment_add_tag(&(sd->vc), name, value); \
|
|
||||||
}
|
|
||||||
|
|
||||||
static void shout_sendMetadata(AudioOutput * audioOutput, MpdTag * tag) {
|
|
||||||
ShoutData * sd = (ShoutData *)audioOutput->data;
|
ShoutData * sd = (ShoutData *)audioOutput->data;
|
||||||
ogg_int64_t granulepos = sd->vd.granulepos;
|
|
||||||
|
|
||||||
if(!sd->opened) return;
|
if(sd->tag) freeMpdTag(sd->tag);
|
||||||
|
sd->tag = NULL;
|
||||||
|
|
||||||
clearEncoder(sd);
|
if(!tag) return;
|
||||||
if(initEncoder(sd) < 0) return;
|
|
||||||
|
|
||||||
sd->vd.granulepos = granulepos;
|
sd->tag = mpdTagDup(tag);
|
||||||
|
|
||||||
if(tag) {
|
|
||||||
addTag("ARTIST", tag->artist);
|
|
||||||
addTag("ALBUM", tag->album);
|
|
||||||
addTag("TITLE", tag->title);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
vorbis_analysis_headerout(&(sd->vd), &(sd->vc), &(sd->header_main),
|
|
||||||
&(sd->header_comments), &(sd->header_codebooks));
|
|
||||||
|
|
||||||
ogg_stream_packetin(&(sd->os), &(sd->header_main));
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioOutputPlugin shoutPlugin =
|
AudioOutputPlugin shoutPlugin =
|
||||||
@ -441,7 +459,7 @@ AudioOutputPlugin shoutPlugin =
|
|||||||
shout_openDevice,
|
shout_openDevice,
|
||||||
shout_play,
|
shout_play,
|
||||||
shout_closeDevice,
|
shout_closeDevice,
|
||||||
shout_sendMetadata
|
shout_setTag
|
||||||
};
|
};
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user