1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-12-04 14:46:31 -05:00

Add new <metadata_refreshinterval/> feature

Add new <metadata_refreshinterval/> feature and configuration option. Based on
a patch by Matthew Adams (thanks!), with minor changes and documentation
additions by me.

(cherry picked from commit 4176545211)
This commit is contained in:
moritz 2010-06-21 18:39:26 +00:00 committed by Moritz Grimm
parent 3042e74ee0
commit 549af56184
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: Changes in 0.5.6, released on 2009-08-31:
* ezstream-file.sh: * ezstream-file.sh:

View File

@ -275,6 +275,17 @@ See the
.Sy METADATA .Sy METADATA
section for details on how metadata is handled by section for details on how metadata is handled by
.Nm . .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\ /\&> .It Sy \&<stream_once\ /\&>
Set to Set to
.Sy 1 .Sy 1

View File

@ -20,6 +20,8 @@
<metadata_progname>meta.sh</metadata_progname> <metadata_progname>meta.sh</metadata_progname>
<!-- Set the metadata string according to this format: --> <!-- Set the metadata string according to this format: -->
<metadata_format>@s@: @a@ - @t@</metadata_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. 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 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; xmlNodePtr cur;
char *ls_xmlContentPtr; char *ls_xmlContentPtr;
int program_set, reconnect_set, shuffle_set, int program_set, reconnect_set, shuffle_set,
streamOnce_set, svrinfopublic_set; streamOnce_set, svrinfopublic_set,
refresh_set;
unsigned int config_error; unsigned int config_error;
xmlLineNumbersDefault(1); xmlLineNumbersDefault(1);
@ -106,14 +107,17 @@ parseConfig(const char *fileName)
return (0); return (0);
} }
memset(&ezConfig, '\000', sizeof(ezConfig)); memset(&ezConfig, 0, sizeof(ezConfig));
ezConfig.metadataRefreshInterval = -1;
config_error = 0; config_error = 0;
program_set = 0; program_set = 0;
reconnect_set = 0; reconnect_set = 0;
refresh_set = 0;
shuffle_set = 0; shuffle_set = 0;
streamOnce_set = 0; streamOnce_set = 0;
svrinfopublic_set = 0; svrinfopublic_set = 0;
for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next) { for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
if (!xmlStrcmp(cur->name, (const xmlChar *)"url")) { if (!xmlStrcmp(cur->name, (const xmlChar *)"url")) {
if (ezConfig.URL != NULL) { 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 (!xmlStrcmp(cur->name, (const xmlChar *)"playlist_program")) {
if (program_set) { if (program_set) {
printf("%s[%ld]: Error: Cannot have multiple <playlist_program> elements\n", printf("%s[%ld]: Error: Cannot have multiple <playlist_program> elements\n",

View File

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

View File

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