[xiph-cvs] cvs commit: icecast/src client.h connection.c format.c format.h format_mp3.c format_mp3.h format_vorbis.c global.c slave.c source.c source.h

Michael Smith msmith at xiph.org
Sun Dec 29 23:55:57 PST 2002



msmith      02/12/30 02:55:56

  Modified:    src      client.h connection.c format.c format.h
                        format_mp3.c format_mp3.h format_vorbis.c global.c
                        slave.c source.c source.h
  Log:
  mp3 metadata work (incomplete)

Revision  Changes    Path
1.5       +2 -0      icecast/src/client.h

Index: client.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/client.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- client.h	29 Dec 2002 08:10:10 -0000	1.4
+++ client.h	30 Dec 2002 07:55:56 -0000	1.5
@@ -6,6 +6,8 @@
 #ifndef __CLIENT_H__
 #define __CLIENT_H__
 
+#include "connection.h"
+
 typedef struct _client_tag
 {
         /* the clients connection */

<p><p>1.35      +5 -24     icecast/src/connection.c

Index: connection.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/connection.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- connection.c	30 Dec 2002 01:59:03 -0000	1.34
+++ connection.c	30 Dec 2002 07:55:56 -0000	1.35
@@ -31,12 +31,11 @@
 #include "refbuf.h"
 #include "client.h"
 #include "stats.h"
-#include "format.h"
 #include "logging.h"
 #include "xslt.h"
 #include "fserve.h"
-
 #include "source.h"
+#include "format.h"
 
 #define CATMODULE "connection"
 
@@ -482,8 +481,6 @@
 {
     char *fullpath;
         client_t *client;
-	avl_node *node;
-	http_var_t *var;
     int bytes;
         struct stat statbuf;
         source_t *source;
@@ -636,26 +633,10 @@
                 global.clients++;
                 global_unlock();
                                                 
-		client->respcode = 200;
-		bytes = sock_write(client->con->sock, 
-                "HTTP/1.0 200 OK\r\n"
-                "Content-Type: %s\r\n", 
-                format_get_mimetype(source->format->type));
-        if(bytes > 0) client->con->sent_bytes += bytes;
-		/* iterate through source http headers and send to client */
-		avl_tree_rlock(source->parser->vars);
-		node = avl_get_first(source->parser->vars);
-		while (node) {
-			var = (http_var_t *)node->key;
-			if (strcasecmp(var->name, "ice-password") && 
-                    !strncasecmp("ice-", var->name, 4)) {
-				bytes = sock_write(client->con->sock, 
-                        "%s: %s\r\n", var->name, var->value);
-                if(bytes > 0) client->con->sent_bytes += bytes;
-			}
-			node = avl_get_next(node);
-		}
-		avl_tree_unlock(source->parser->vars);
+        client->format_data = source->format->create_client_data(
+                source->format, source, client);
+
+        source->format->client_send_headers(source->format, source, client);
                                                 
                 bytes = sock_write(client->con->sock, "\r\n");
         if(bytes > 0) client->con->sent_bytes += bytes;

<p><p>1.10      +25 -0     icecast/src/format.c

Index: format.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- format.c	29 Dec 2002 15:46:32 -0000	1.9
+++ format.c	30 Dec 2002 07:55:56 -0000	1.10
@@ -11,6 +11,7 @@
 #include "connection.h"
 #include "refbuf.h"
 
+#include "source.h"
 #include "format.h"
 
 #include "format_vorbis.h"
@@ -82,5 +83,29 @@
         client->con->sent_bytes += ret;
 
     return ret;
+}
+
+void format_send_general_headers(format_plugin_t *format,
+        source_t *source, client_t *client)
+{
+    http_var_t *var;
+    avl_node *node;
+    int bytes;
+
+	/* iterate through source http headers and send to client */
+	avl_tree_rlock(source->parser->vars);
+	node = avl_get_first(source->parser->vars);
+	while (node) {
+		var = (http_var_t *)node->key;
+		if (strcasecmp(var->name, "ice-password") && 
+                (!strncasecmp("ice-", var->name, 4) ||
+                 !strncasecmp("icy-", var->name, 4))) { 
+            bytes = sock_write(client->con->sock, 
+                    "%s: %s\r\n", var->name, var->value);
+            if(bytes > 0) client->con->sent_bytes += bytes;
+		}
+		node = avl_get_next(node);
+	}
+	avl_tree_unlock(source->parser->vars);
 }
 

<p><p>1.9       +8 -1      icecast/src/format.h

Index: format.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- format.h	29 Dec 2002 08:10:10 -0000	1.8
+++ format.h	30 Dec 2002 07:55:56 -0000	1.9
@@ -9,6 +9,8 @@
 #include "client.h"
 #include "refbuf.h"
 
+struct source_tag;
+
 typedef enum _format_type_tag
 {
         FORMAT_TYPE_VORBIS,
@@ -34,7 +36,10 @@
         refbuf_queue_t *(*get_predata)(struct _format_plugin_tag *self);
     int (*write_buf_to_client)(struct _format_plugin_tag *format, 
             client_t *client, unsigned char *buf, int len);
-    void *(*create_client_data)(struct _format_plugin_tag *format);
+    void *(*create_client_data)(struct _format_plugin_tag *format,
+            struct source_tag *source, client_t *client);
+    void (*client_send_headers)(struct _format_plugin_tag *format, 
+            struct source_tag *source, client_t *client);
 
         void (*free_plugin)(struct _format_plugin_tag *self);
 
@@ -48,6 +53,8 @@
 
 int format_generic_write_buf_to_client(format_plugin_t *format, 
         client_t *client, unsigned char *buf, int len);
+void format_send_general_headers(format_plugin_t *format, 
+        struct source_tag *source, client_t *client);
 
 #endif  /* __FORMAT_H__ */
 

<p><p>1.4       +90 -9     icecast/src/format_mp3.c

Index: format_mp3.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format_mp3.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- format_mp3.c	29 Dec 2002 08:10:10 -0000	1.3
+++ format_mp3.c	30 Dec 2002 07:55:56 -0000	1.4
@@ -1,6 +1,6 @@
 /* format_mp3.c
 **
-** format plugin for mp3 (no metadata)
+** format plugin for mp3
 **
 */
 
@@ -9,15 +9,38 @@
 #include <string.h>
 
 #include "refbuf.h"
+#include "source.h"
+#include "client.h"
 
 #include "stats.h"
 #include "format.h"
+#include "httpp/httpp.h"
+
+#include "log.h"
+#include "logging.h"
+
+#include "format_mp3.h"
+
+#define CATMODULE "format-mp3"
+
+#define ICY_METADATA_INTERVAL 16000
 
 static void format_mp3_free_plugin(format_plugin_t *self);
 static int format_mp3_get_buffer(format_plugin_t *self, char *data, 
         unsigned long len, refbuf_t **buffer);
 static refbuf_queue_t *format_mp3_get_predata(format_plugin_t *self);
-static void *format_mp3_create_client_data(format_plugin_t *self);
+static void *format_mp3_create_client_data(format_plugin_t *self,
+        source_t *source, client_t *client);
+static int format_mp3_write_buf_to_client(format_plugin_t *self,
+        client_t *client, unsigned char *buf, int len);
+static void format_mp3_send_headers(format_plugin_t *self, 
+        source_t *source, client_t *client);
+
+typedef struct {
+   int interval;
+   int offset;
+   int metadata;
+} mp3_client_data;
 
 format_plugin_t *format_mp3_get_plugin(void)
 {
@@ -29,23 +52,44 @@
         plugin->has_predata = 0;
         plugin->get_buffer = format_mp3_get_buffer;
         plugin->get_predata = format_mp3_get_predata;
-    plugin->write_buf_to_client = format_generic_write_buf_to_client;
+    plugin->write_buf_to_client = format_mp3_write_buf_to_client;
     plugin->create_client_data = format_mp3_create_client_data;
+    plugin->client_send_headers = format_mp3_send_headers;
         plugin->free_plugin = format_mp3_free_plugin;
     plugin->format_description = "MP3 audio";
 
-	plugin->_state = NULL;
+	plugin->_state = calloc(1, sizeof(mp3_state));
 
         return plugin;
 }
 
-void format_mp3_free_plugin(format_plugin_t *self)
+static int format_mp3_write_buf_to_client(format_plugin_t *self, 
+    client_t *client, unsigned char *buf, int len) 
+{
+    int ret;
+
+    ret = sock_write_bytes(client->con->sock, buf, len);
+
+    if(ret < 0) {
+        if(sock_recoverable(ret)) {
+            DEBUG1("Client had recoverable error %ld", ret);
+            ret = 0;
+        }
+    }
+    else
+        client->con->sent_bytes += ret;
+
+    return ret;
+}
+
+static void format_mp3_free_plugin(format_plugin_t *self)
 {
         /* free the plugin instance */
         free(self);
 }
 
-int format_mp3_get_buffer(format_plugin_t *self, char *data, unsigned long len, refbuf_t **buffer)
+static int format_mp3_get_buffer(format_plugin_t *self, char *data, 
+    unsigned long len, refbuf_t **buffer)
 {
         refbuf_t *refbuf;
     if(!data) {
@@ -60,13 +104,50 @@
         return 0;
 }
 
-refbuf_queue_t *format_mp3_get_predata(format_plugin_t *self)
+static refbuf_queue_t *format_mp3_get_predata(format_plugin_t *self)
 {
     return NULL;
 }
 
-static void *format_mp3_create_client_data(format_plugin_t *self) {
-    return NULL;
+static void *format_mp3_create_client_data(format_plugin_t *self, 
+        source_t *source, client_t *client) 
+{
+    mp3_client_data *data = calloc(1,sizeof(mp3_client_data));
+    char *metadata;
+
+    data->interval = ICY_METADATA_INTERVAL;
+    data->offset = 0;
+
+    metadata = httpp_getvar(source->parser, "icy-metadata");
+    if(metadata)
+    data->metadata = atoi(metadata)>0?1:0;
+
+    return data;
 }
+
+static void format_mp3_send_headers(format_plugin_t *self,
+        source_t *source, client_t *client)
+{
+    int bytes;
+    
+    client->respcode = 200;
+    bytes = sock_write(client->con->sock, 
+            "HTTP/1.0 200 OK\r\n" 
+            "Content-Type: %s\r\n", 
+            format_get_mimetype(source->format->type));
+
+    if(bytes > 0) client->con->sent_bytes += bytes;
+
+    format_send_general_headers(self, source, client);
+
+    if(0 && ((mp3_client_data *)(client->format_data))->metadata) {
+        int bytes = sock_write(client->con->sock, "icy-metaint: %d\r\n", 
+                ICY_METADATA_INTERVAL);
+        if(bytes > 0)
+            client->con->sent_bytes += bytes;
+    }
+}
+
+
 
 

<p><p>1.2       +5 -0      icecast/src/format_mp3.h

Index: format_mp3.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format_mp3.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- format_mp3.h	23 Jul 2002 15:15:11 -0000	1.1
+++ format_mp3.h	30 Dec 2002 07:55:56 -0000	1.2
@@ -6,6 +6,11 @@
 #ifndef __FORMAT_MP3_H__
 #define __FORMAT_MP3_H__
 
+typedef struct {
+    char *metadata;
+    int metadata_age;
+} mp3_state;
+
 format_plugin_t *format_mp3_get_plugin(void);
 
 #endif  /* __FORMAT_MP3_H__ */

<p><p>1.11      +26 -2     icecast/src/format_vorbis.c

Index: format_vorbis.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format_vorbis.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- format_vorbis.c	29 Dec 2002 08:10:10 -0000	1.10
+++ format_vorbis.c	30 Dec 2002 07:55:56 -0000	1.11
@@ -12,6 +12,8 @@
 #include <vorbis/codec.h>
 
 #include "refbuf.h"
+#include "source.h"
+#include "client.h"
 
 #include "stats.h"
 #include "format.h"
@@ -40,7 +42,10 @@
 static int format_vorbis_get_buffer(format_plugin_t *self, char *data, 
         unsigned long len, refbuf_t **buffer);
 static refbuf_queue_t *format_vorbis_get_predata(format_plugin_t *self);
-static void *format_vorbis_create_client_data(format_plugin_t *self);
+static void *format_vorbis_create_client_data(format_plugin_t *self,
+        source_t *source, client_t *client);
+static void format_vorbis_send_headers(format_plugin_t *self,
+        source_t *source, client_t *client);
 
 format_plugin_t *format_vorbis_get_plugin(void)
 {
@@ -55,6 +60,7 @@
         plugin->get_predata = format_vorbis_get_predata;
     plugin->write_buf_to_client = format_generic_write_buf_to_client;
     plugin->create_client_data = format_vorbis_create_client_data;
+    plugin->client_send_headers = format_vorbis_send_headers;
         plugin->free_plugin = format_vorbis_free_plugin;
     plugin->format_description = "Ogg Vorbis";
 
@@ -218,8 +224,26 @@
         return queue;
 }
 
-static void *format_vorbis_create_client_data(format_plugin_t *self) {
+static void *format_vorbis_create_client_data(format_plugin_t *self,
+        source_t *source, client_t *client) 
+{
     return NULL;
+}
+
+static void format_vorbis_send_headers(format_plugin_t *self,
+        source_t *source, client_t *client)
+{
+    int bytes;
+    
+    client->respcode = 200;
+    bytes = sock_write(client->con->sock, 
+            "HTTP/1.0 200 OK\r\n" 
+            "Content-Type: %s\r\n", 
+            format_get_mimetype(source->format->type));
+
+    if(bytes > 0) client->con->sent_bytes += bytes;
+
+    format_send_general_headers(self, source, client);
 }
 
 

<p><p>1.4       +1 -1      icecast/src/global.c

Index: global.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/global.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- global.c	22 Nov 2002 13:00:44 -0000	1.3
+++ global.c	30 Dec 2002 07:55:56 -0000	1.4
@@ -4,9 +4,9 @@
 #include "httpp.h"
 #include "connection.h"
 #include "refbuf.h"
-#include "format.h"
 #include "client.h"
 #include "source.h"
+#include "format.h"
 
 #include "global.h"
 

<p><p>1.10      +1 -2      icecast/src/slave.c

Index: slave.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/slave.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- slave.c	29 Dec 2002 15:46:32 -0000	1.9
+++ slave.c	30 Dec 2002 07:55:56 -0000	1.10
@@ -37,10 +37,9 @@
 #include "refbuf.h"
 #include "client.h"
 #include "stats.h"
-#include "format.h"
 #include "logging.h"
-
 #include "source.h"
+#include "format.h"
 
 #define CATMODULE "slave"
 

<p><p>1.25      +1 -4      icecast/src/source.c

Index: source.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- source.c	29 Dec 2002 08:10:10 -0000	1.24
+++ source.c	30 Dec 2002 07:55:56 -0000	1.25
@@ -23,13 +23,12 @@
 #include "refbuf.h"
 #include "client.h"
 #include "stats.h"
-#include "format.h"
 #include "log.h"
 #include "logging.h"
 #include "config.h"
 #include "util.h"
-
 #include "source.h"
+#include "format.h"
 
 #undef CATMODULE
 #define CATMODULE "source"
@@ -325,8 +324,6 @@
                         */
                         if (source->format->has_predata) {
                                 client = (client_t *)client_node->key;
-                client->format_data = source->format->create_client_data(
-                        source->format);
                                 client->queue = source->format->get_predata(source->format);
                         }
 

<p><p>1.3       +3 -1      icecast/src/source.h

Index: source.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- source.h	16 Aug 2002 14:26:48 -0000	1.2
+++ source.h	30 Dec 2002 07:55:56 -0000	1.3
@@ -1,6 +1,8 @@
 #ifndef __SOURCE_H__
 #define __SOURCE_H__
 
+#include "format.h"
+
 typedef struct source_tag
 {
     client_t *client;
@@ -8,7 +10,7 @@
         http_parser_t *parser;
         
         char *mount;
-	format_plugin_t *format;
+	struct _format_plugin_tag *format;
 
         avl_tree *client_tree;
         avl_tree *pending_tree;

<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