1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-11-03 04:17:18 -05:00

Add new <metadata_refreshinterval/> feature and configuration option. Based on

a patch by Matthew Adams (thanks!), with minor changes and documentation
additions by me.


git-svn-id: https://svn.xiph.org/trunk/ezstream@17301 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
moritz 2010-06-21 18:39:26 +00:00
parent e189a36789
commit 4176545211
6 changed files with 77 additions and 15 deletions

10
NEWS
View File

@ -1,3 +1,13 @@
Changes in 0.5.7, released on XXXX-XX-XX:
* various:
- [NEW] Add new <metadata_refreshinterval/> feature from Matthew Adams
(with minor changes plus documentation.) This allows for recurring
and custom metadata updates inbetween song changes via
<metadata_progname/>.
Changes in 0.5.6, released on 2009-08-31:
* ezstream-file.sh:

View File

@ -275,6 +275,17 @@ See the
.Sy METADATA
section for details on how metadata is handled by
.Nm .
.It Sy \&<metadata_refreshinterval\ /\&>
.Pq Optional.
Configures the time
.Pq in seconds
inbetween additional metadata updates via
.Li \&<metadata_progname/\&> .
A value of 0
.Pq zero
triggers updates as fast as possible, while a value of \&-1
.Pq minus one
or the absence of this configuration element disables this feature.
.It Sy \&<stream_once\ /\&>
Set to
.Sy 1

View File

@ -20,6 +20,8 @@
<metadata_progname>meta.sh</metadata_progname>
<!-- Set the metadata string according to this format: -->
<metadata_format>@s@: @a@ - @t@</metadata_format>
<!-- Update metadata from meta.sh at least once every 10 seconds: -->
<metadata_refreshinterval>10</metadata_refreshinterval>
<!--
The following settings are used to describe your stream to the server.
It's up to you to make sure that the bitrate/quality/samplerate/channels

View File

@ -89,7 +89,8 @@ parseConfig(const char *fileName)
xmlNodePtr cur;
char *ls_xmlContentPtr;
int program_set, reconnect_set, shuffle_set,
streamOnce_set, svrinfopublic_set;
streamOnce_set, svrinfopublic_set,
refresh_set;
unsigned int config_error;
xmlLineNumbersDefault(1);
@ -106,14 +107,17 @@ parseConfig(const char *fileName)
return (0);
}
memset(&ezConfig, '\000', sizeof(ezConfig));
memset(&ezConfig, 0, sizeof(ezConfig));
ezConfig.metadataRefreshInterval = -1;
config_error = 0;
program_set = 0;
reconnect_set = 0;
refresh_set = 0;
shuffle_set = 0;
streamOnce_set = 0;
svrinfopublic_set = 0;
for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
if (!xmlStrcmp(cur->name, (const xmlChar *)"url")) {
if (ezConfig.URL != NULL) {
@ -230,6 +234,27 @@ parseConfig(const char *fileName)
}
}
}
if (!xmlStrcmp(cur->name, (const xmlChar *)"metadata_refreshinterval")) {
if (refresh_set) {
printf("%s[%ld]: Error: Cannot have multiple <metadata_refreshinterval> elements\n",
fileName, xmlGetLineNo(cur));
config_error++;
continue;
}
if (cur->xmlChildrenNode != NULL) {
const char *errstr;
ls_xmlContentPtr = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
ezConfig.metadataRefreshInterval = (unsigned int)strtonum(ls_xmlContentPtr, -1LL, (long long)INT_MAX, &errstr);
if (errstr) {
printf("%s[%ld]: Error: In <metadata_refreshinterval>: '%s' is %s\n",
fileName, xmlGetLineNo(cur), ls_xmlContentPtr, errstr);
config_error++;
continue;
}
xmlFree(ls_xmlContentPtr);
refresh_set = 1;
}
}
if (!xmlStrcmp(cur->name, (const xmlChar *)"playlist_program")) {
if (program_set) {
printf("%s[%ld]: Error: Cannot have multiple <playlist_program> elements\n",

View File

@ -66,6 +66,7 @@ typedef struct tag_EZCONFIG {
int fileNameIsProgram;
int streamOnce;
unsigned int reconnectAttempts;
int metadataRefreshInterval;
} EZCONFIG;
EZCONFIG * getEZConfig(void);

View File

@ -750,6 +750,7 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
int ret;
double kbps = -1.0;
struct timeval timeStamp, *startTime = tv;
struct timeval callTime, currentTime;
if (startTime == NULL) {
printf("%s: sendStream(): Internal error: startTime is NULL\n",
@ -757,6 +758,8 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
abort();
}
ez_gettimeofday((void *)&callTime);
timeStamp.tv_sec = startTime->tv_sec;
timeStamp.tv_usec = startTime->tv_usec;
@ -795,7 +798,15 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
ret = STREAM_SKIP;
break;
}
if (queryMetadata) {
ez_gettimeofday((void *)&currentTime);
if (queryMetadata ||
(pezConfig->metadataRefreshInterval != -1
&& (currentTime.tv_sec - callTime.tv_sec
>= pezConfig->metadataRefreshInterval)
)
) {
queryMetadata = 0;
if (metadataFromProgram) {
ret = STREAM_UPDMDATA;
@ -805,8 +816,7 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
total += bytes_read;
if (qFlag && vFlag) {
struct timeval tval;
double oldTime, newTime;
double oldTime, newTime;
if (!isStdin && playlistMode) {
if (pezConfig->fileNameIsProgram) {
@ -822,20 +832,22 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
oldTime = (double)timeStamp.tv_sec
+ (double)timeStamp.tv_usec / 1000000.0;
ez_gettimeofday((void *)&tval);
newTime = (double)tval.tv_sec
+ (double)tval.tv_usec / 1000000.0;
newTime = (double)currentTime.tv_sec
+ (double)currentTime.tv_usec / 1000000.0;
if (songLenStr == NULL)
printf(" [ %s]",
getTimeString(tval.tv_sec - startTime->tv_sec));
getTimeString(currentTime.tv_sec -
startTime->tv_sec));
else
printf(" [ %s/%s]",
getTimeString(tval.tv_sec - startTime->tv_sec),
getTimeString(currentTime.tv_sec -
startTime->tv_sec),
songLenStr);
if (newTime - oldTime >= 1.0) {
kbps = (((double)(total - oldTotal) / (newTime - oldTime)) * 8.0) / 1000.0;
timeStamp.tv_sec = tval.tv_sec;
timeStamp.tv_usec = tval.tv_usec;
kbps = (((double)(total - oldTotal)
/ (newTime - oldTime)) * 8.0) / 1000.0;
timeStamp.tv_sec = currentTime.tv_sec;
timeStamp.tv_usec = currentTime.tv_usec;
oldTotal = total;
}
if (kbps < 0)
@ -954,8 +966,9 @@ streamFile(shout_t *shout, const char *fileName)
continue;
}
metadata_free(&prog_mdata);
printf("%s: New metadata: ``%s''\n",
__progname, mdataStr);
if (vFlag > 1)
printf("%s: New metadata: ``%s''\n",
__progname, mdataStr);
xfree(mdataStr);
}
}