[xiph-cvs] cvs commit: icecast/src format.c format.h format_vorbis.c source.c stats.c
Jack Moffitt
jack at xiph.org
Sun Feb 3 23:08:53 PST 2002
jack 02/02/03 23:08:53
Modified: src format.c format.h format_vorbis.c source.c stats.c
Log:
Two things:
1) vorbis tags (ARTIST and TITLE) now appear in the stats. Oddsock did
the first cut of this.
2) stats bug fixed. if a stats value was NULL a segfault occurred.
strdup(NULL) is fun!
Revision Changes Path
1.3 +2 -1 icecast/src/format.c
Index: format.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- format.c 2001/10/20 06:43:04 1.2
+++ format.c 2002/02/04 07:08:52 1.3
@@ -15,13 +15,14 @@
#include "format_vorbis.h"
-format_plugin_t *format_get_plugin(format_type_t type)
+format_plugin_t *format_get_plugin(format_type_t type, char *mount)
{
format_plugin_t *plugin;
switch (type) {
case FORMAT_TYPE_VORBIS:
plugin = format_vorbis_get_plugin();
+ if (plugin) plugin->mount = mount;
break;
default:
plugin = NULL;
<p><p>1.3 +4 -1 icecast/src/format.h
Index: format.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- format.h 2002/01/05 00:29:27 1.2
+++ format.h 2002/02/04 07:08:52 1.3
@@ -16,6 +16,9 @@
{
format_type_t type;
+ /* we need to know the mount to report statistics */
+ char *mount;
+
/* set this is the data format has a header that
** we must send before regular data
*/
@@ -29,7 +32,7 @@
void *_state;
} format_plugin_t;
-format_plugin_t *format_get_plugin(format_type_t type);
+format_plugin_t *format_get_plugin(format_type_t type, char *mount);
#endif /* __FORMAT_H__ */
<p><p>1.3 +54 -5 icecast/src/format_vorbis.c
Index: format_vorbis.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format_vorbis.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- format_vorbis.c 2002/01/05 00:29:27 1.2
+++ format_vorbis.c 2002/02/04 07:08:52 1.3
@@ -18,10 +18,15 @@
typedef struct _vstate_tag
{
ogg_sync_state oy;
+ ogg_stream_state os;
+ vorbis_info vi;
+ vorbis_comment vc;
+
ogg_page og;
unsigned long serialno;
int header;
refbuf_t *headbuf[10];
+ int packets;
} vstate_t;
void format_vorbis_free_plugin(format_plugin_t *self);
@@ -58,6 +63,9 @@
/* free state memory */
ogg_sync_clear(&state->oy);
+ ogg_stream_clear(&state->os);
+ vorbis_comment_clear(&state->vc);
+ vorbis_info_clear(&state->vi);
for (i = 0; i < 10; i++) {
if (state->headbuf[i]) {
@@ -76,7 +84,9 @@
{
char *buffer;
refbuf_t *refbuf;
- int i;
+ int i, result;
+ ogg_packet op;
+ char *tag;
vstate_t *state = (vstate_t *)self->_state;
if (data) {
@@ -95,28 +105,67 @@
if (state->serialno != ogg_page_serialno(&state->og)) {
/* this is a new logical bitstream */
state->header = 0;
+ state->packets = 0;
+
+ /* release old headers, stream state, vorbis data */
for (i = 0; i < 10; i++) {
if (state->headbuf[i]) {
refbuf_release(state->headbuf[i]);
state->headbuf[i] = NULL;
}
}
-
+
state->serialno = ogg_page_serialno(&state->og);
+ ogg_stream_init(&state->os, state->serialno);
+ vorbis_info_init(&state->vi);
+ vorbis_comment_init(&state->vc);
}
if (state->header >= 0) {
if (ogg_page_granulepos(&state->og) == 0) {
state->header++;
} else {
- state->header = 0;
+ /* we're done caching headers */
+ state->header = -1;
+
+ /* put known comments in the stats */
+ tag = vorbis_comment_query(&state->vc, "TITLE", 0);
+ if (tag) stats_event_args(self->mount, "title", tag);
+ else stats_event_args(self->mount, "title", "unknown");
+ tag = vorbis_comment_query(&state->vc, "ARTIST", 0);
+ if (tag) stats_event_args(self->mount, "artist", tag);
+ else stats_event_args(self->mount, "artist", "unknown");
+
+ /* don't need these now */
+ ogg_stream_clear(&state->os);
+ vorbis_comment_clear(&state->vc);
+ vorbis_info_clear(&state->vi);
}
}
- /* cache first three pages */
- if (state->header) {
+ /* cache header pages */
+ if (state->header > 0) {
refbuf_addref(refbuf);
state->headbuf[state->header - 1] = refbuf;
+
+ if (state->packets >= 0 && state->packets < 2) {
+ ogg_stream_pagein(&state->os, &state->og);
+ while (state->packets < 2) {
+ result = ogg_stream_packetout(&state->os, &op);
+ if (result == 0) break; /* need more data */
+ if (result < 0) {
+ state->packets = -1;
+ break;
+ }
+
+ state->packets++;
+
+ if (vorbis_synthesis_headerin(&state->vi, &state->vc, &op) < 0) {
+ state->packets = -1;
+ break;
+ }
+ }
+ }
}
}
<p><p>1.7 +11 -2 icecast/src/source.c
Index: source.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- source.c 2002/01/21 04:28:30 1.6
+++ source.c 2002/02/04 07:08:52 1.7
@@ -41,10 +41,10 @@
source_t *src;
src = (source_t *)malloc(sizeof(source_t));
- src->format = format_get_plugin(type);
+ src->mount = (char *)strdup(mount);
+ src->format = format_get_plugin(type, src->mount);
src->con = con;
src->parser = parser;
- src->mount = (char *)strdup(mount);
src->client_tree = avl_tree_new(_compare_clients, NULL);
src->pending_tree = avl_tree_new(_compare_clients, NULL);
@@ -110,6 +110,7 @@
int ret, timeout;
client_t *client;
avl_node *client_node;
+ char *s;
refbuf_t *refbuf, *abuf;
int data_done;
@@ -134,6 +135,14 @@
/* start off the statistics */
stats_event(source->mount, "listeners", "0");
+ if ((s = httpp_getvar(source->parser, "ice-name")))
+ stats_event(source->mount, "name", s);
+ if ((s = httpp_getvar(source->parser, "ice-url")))
+ stats_event(source->mount, "url", s);
+ if ((s = httpp_getvar(source->parser, "ice-bitrate")))
+ stats_event(source->mount, "bitrate", s);
+ if ((s = httpp_getvar(source->parser, "ice-description")))
+ stats_event(source->mount, "description", s);
while (global.running == ICE_RUNNING) {
refbuf = source->format->get_buffer(source->format, NULL, 0);
<p><p>1.6 +5 -2 icecast/src/stats.c
Index: stats.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/stats.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- stats.c 2001/10/21 02:06:08 1.5
+++ stats.c 2002/02/04 07:08:52 1.6
@@ -286,7 +286,10 @@
else
copy->source = NULL;
copy->name = (char *)strdup(event->name);
- copy->value = (char *)strdup(event->value);
+ if (event->value)
+ copy->value = (char *)strdup(event->value);
+ else
+ copy->value = NULL;
copy->next = NULL;
return copy;
@@ -480,7 +483,7 @@
int ret;
/* send data to the client!!!! */
- ret = sock_write(con->sock, "EVENT %s %s %s\n", (event->source != NULL) ? event->source : "global", event->name, event->value);
+ ret = sock_write(con->sock, "EVENT %s %s %s\n", (event->source != NULL) ? event->source : "global", event->name, event->value ? event->value : "null");
return (ret == -1) ? 0 : 1;
}
<p><p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list