[xiph-commits] r8226 - icecast/trunk/icecast/src

oddsock at motherfish-iii.xiph.org oddsock at motherfish-iii.xiph.org
Thu Nov 18 15:49:59 PST 2004


Author: oddsock
Date: 2004-11-18 15:49:59 -0800 (Thu, 18 Nov 2004)
New Revision: 8226

Modified:
   icecast/trunk/icecast/src/admin.c
   icecast/trunk/icecast/src/connection.c
   icecast/trunk/icecast/src/format.c
   icecast/trunk/icecast/src/format.h
   icecast/trunk/icecast/src/format_mp3.c
   icecast/trunk/icecast/src/format_vorbis.c
   icecast/trunk/icecast/src/source.c
   icecast/trunk/icecast/src/yp.c
Log:
handle supported content-types in a more generic way now.  This will allow things like AAC, AACPlus, NSV, and others to be streamed through icecast.  We have a special case for vorbis streams, and everything else falls into the generic case.


Modified: icecast/trunk/icecast/src/admin.c
===================================================================
--- icecast/trunk/icecast/src/admin.c	2004-11-18 22:07:21 UTC (rev 8225)
+++ icecast/trunk/icecast/src/admin.c	2004-11-18 23:49:59 UTC (rev 8226)
@@ -217,8 +217,8 @@
             snprintf(buf, sizeof(buf), "%lu",
                     (unsigned long)(now - source->con->con_time));
             xmlNewChild(srcnode, NULL, "Connected", buf);
-            xmlNewChild(srcnode, NULL, "Format", 
-                    source->format->format_description);
+            xmlNewChild(srcnode, NULL, "content-type", 
+                    source->format->contenttype);
             if (source->authenticator) {
                 xmlNewChild(srcnode, NULL, "authenticator", 
                     source->authenticator->type);
@@ -816,10 +816,8 @@
     COMMAND_REQUIRE(client, "mode", action);
     COMMAND_REQUIRE(client, "song", value);
 
-    if ((source->format->type != FORMAT_TYPE_MP3) &&
-        (source->format->type != FORMAT_TYPE_NSV))
-    {
-        client_send_400 (client, "Not mp3, cannot update metadata");
+    if (source->format->type == FORMAT_TYPE_VORBIS) {
+        client_send_400 (client, "Cannot update metadata on vorbis streams");
         return;
     }
 
@@ -866,10 +864,8 @@
     config_source_pass = strdup(config->source_password);
     config_release_config();
 
-    if ((source->format->type != FORMAT_TYPE_MP3) &&
-        (source->format->type != FORMAT_TYPE_NSV))
-    {
-        client_send_400 (client, "Not mp3 or NSV, cannot update metadata");
+    if (source->format->type == FORMAT_TYPE_VORBIS) {
+        client_send_400 (client, "Cannot update metadata on vorbis streams");
         return;
     }
 

Modified: icecast/trunk/icecast/src/connection.c
===================================================================
--- icecast/trunk/icecast/src/connection.c	2004-11-18 22:07:21 UTC (rev 8225)
+++ icecast/trunk/icecast/src/connection.c	2004-11-18 23:49:59 UTC (rev 8226)
@@ -472,7 +472,7 @@
         {
             WARN0("No content-type header, falling back to backwards compatibility mode "
                     "for icecast 1.x relays. Assuming content is mp3.");
-            format_type = FORMAT_TYPE_MP3;
+            format_type = FORMAT_TYPE_GENERIC;
         }
 
         if (format_get_plugin (format_type, source) < 0)

Modified: icecast/trunk/icecast/src/format.c
===================================================================
--- icecast/trunk/icecast/src/format.c	2004-11-18 22:07:21 UTC (rev 8225)
+++ icecast/trunk/icecast/src/format.c	2004-11-18 23:49:59 UTC (rev 8226)
@@ -54,33 +54,12 @@
         return FORMAT_TYPE_VORBIS; /* Backwards compatibility */
     else if(strcmp(contenttype, "application/ogg") == 0)
         return FORMAT_TYPE_VORBIS; /* Now blessed by IANA */
-    else if(strcmp(contenttype, "audio/mpeg") == 0)
-        return FORMAT_TYPE_MP3; 
-    else if(strcmp(contenttype, "audio/x-mpeg") == 0)
-        return FORMAT_TYPE_MP3; /* Relay-compatibility for some servers */
-    else if(strcmp(contenttype, "video/nsv") == 0)
-        return FORMAT_TYPE_NSV; 
-    else
-        return FORMAT_ERROR;
+    else 
+        /* We default to the Generic format handler, which
+           can handle many more formats than just mp3 */
+        return FORMAT_TYPE_GENERIC; 
 }
 
-char *format_get_mimetype(format_type_t type)
-{
-    switch(type) {
-        case FORMAT_TYPE_VORBIS:
-            return "application/ogg";
-            break;
-        case FORMAT_TYPE_MP3:
-            return "audio/mpeg";
-            break;
-        case FORMAT_TYPE_NSV:
-            return "video/nsv";
-            break;
-        default:
-            return NULL;
-    }
-}
-
 int format_get_plugin(format_type_t type, source_t *source)
 {
     int ret = -1;
@@ -89,19 +68,14 @@
     case FORMAT_TYPE_VORBIS:
         ret = format_vorbis_get_plugin (source);
         break;
-    case FORMAT_TYPE_MP3:
+    case FORMAT_TYPE_GENERIC:
         ret = format_mp3_get_plugin (source);
         break;
-    case FORMAT_TYPE_NSV:
-        ret = format_mp3_get_plugin (source);
-        source->format->format_description = "NSV Video";
-        source->format->type = FORMAT_TYPE_NSV;
-        break;
     default:
         break;
     }
     stats_event (source->mount, "content-type", 
-                 format_get_mimetype(source->format->type));
+                 source->format->contenttype);
 
     return ret;
 }

Modified: icecast/trunk/icecast/src/format.h
===================================================================
--- icecast/trunk/icecast/src/format.h	2004-11-18 22:07:21 UTC (rev 8225)
+++ icecast/trunk/icecast/src/format.h	2004-11-18 23:49:59 UTC (rev 8226)
@@ -27,8 +27,7 @@
 typedef enum _format_type_tag
 {
     FORMAT_TYPE_VORBIS,
-    FORMAT_TYPE_MP3,
-    FORMAT_TYPE_NSV,
+    FORMAT_TYPE_GENERIC,
     FORMAT_ERROR /* No format, source not processable */
 } format_type_t;
 
@@ -39,7 +38,7 @@
     /* we need to know the mount to report statistics */
     char *mount;
 
-    char *format_description;
+    char *contenttype;
 
     refbuf_t *(*get_buffer)(struct source_tag *);
     int (*write_buf_to_client)(struct _format_plugin_tag *format, client_t *client);

Modified: icecast/trunk/icecast/src/format_mp3.c
===================================================================
--- icecast/trunk/icecast/src/format_mp3.c	2004-11-18 22:07:21 UTC (rev 8225)
+++ icecast/trunk/icecast/src/format_mp3.c	2004-11-18 23:49:59 UTC (rev 8226)
@@ -82,15 +82,20 @@
 
     plugin = (format_plugin_t *)malloc(sizeof(format_plugin_t));
 
-    plugin->type = FORMAT_TYPE_MP3;
+    plugin->type = FORMAT_TYPE_GENERIC;
     plugin->get_buffer = mp3_get_no_meta;
     plugin->write_buf_to_client = format_mp3_write_buf_to_client;
     plugin->write_buf_to_file = write_mp3_to_file;
     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->contenttype = httpp_getvar (source->parser, "content-type");
+    if (plugin->contenttype == NULL) {
+        /* We default to MP3 audio for old clients without content types */
+        plugin->contenttype = "audio/mpeg";
+    }
+
     plugin->_state = state;
 
     /* initial metadata needs to be blank for sending to clients and for
@@ -617,7 +622,7 @@
             "HTTP/1.0 200 OK\r\n" 
             "Content-Type: %s\r\n"
             "%s", 
-            format_get_mimetype(source->format->type),
+            source->format->contenttype,
             content_length);
 
     if (bytes > 0)

Modified: icecast/trunk/icecast/src/format_vorbis.c
===================================================================
--- icecast/trunk/icecast/src/format_vorbis.c	2004-11-18 22:07:21 UTC (rev 8225)
+++ icecast/trunk/icecast/src/format_vorbis.c	2004-11-18 23:49:59 UTC (rev 8226)
@@ -87,7 +87,7 @@
     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";
+    plugin->contenttype = "application/ogg";
 
     state = (vstate_t *)calloc(1, sizeof(vstate_t));
     ogg_sync_init(&state->oy);
@@ -320,7 +320,7 @@
     bytes = sock_write(client->con->sock, 
             "HTTP/1.0 200 OK\r\n" 
             "Content-Type: %s\r\n", 
-            format_get_mimetype(source->format->type));
+            source->format->contenttype);
 
     if(bytes > 0) client->con->sent_bytes += bytes;
 

Modified: icecast/trunk/icecast/src/source.c
===================================================================
--- icecast/trunk/icecast/src/source.c	2004-11-18 22:07:21 UTC (rev 8225)
+++ icecast/trunk/icecast/src/source.c	2004-11-18 23:49:59 UTC (rev 8226)
@@ -542,7 +542,6 @@
     stats_event_inc (NULL, "sources");
     stats_event_inc (NULL, "source_total_connections");
     stats_event (source->mount, "listeners", "0");
-    stats_event (source->mount, "type", source->format->format_description);
 
     sock_set_blocking (source->con->sock, SOCK_NONBLOCK);
 

Modified: icecast/trunk/icecast/src/yp.c
===================================================================
--- icecast/trunk/icecast/src/yp.c	2004-11-18 22:07:21 UTC (rev 8225)
+++ icecast/trunk/icecast/src/yp.c	2004-11-18 23:49:59 UTC (rev 8226)
@@ -493,7 +493,7 @@
             break;
 
         /* ice-* is icecast, icy-* is shoutcast */
-        add_yp_info (yp, "server_type", source->format->format_description, YP_SERVER_TYPE);
+        add_yp_info (yp, "server_type", source->format->contenttype, YP_SERVER_TYPE);
         if ((s = httpp_getvar(source->parser, "ice-name"))) {
             add_yp_info (yp, "server_name", s, YP_SERVER_NAME);
         }



More information about the commits mailing list