From 731f24d050fc6e1868ddd328edd913d0695d0cc2 Mon Sep 17 00:00:00 2001 From: oddsock Date: Thu, 18 Nov 2004 23:49:59 +0000 Subject: [PATCH] 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. svn path=/icecast/trunk/icecast/; revision=8226 --- src/admin.c | 16 ++++++---------- src/connection.c | 2 +- src/format.c | 38 ++++++-------------------------------- src/format.h | 5 ++--- src/format_mp3.c | 11 ++++++++--- src/format_vorbis.c | 4 ++-- src/source.c | 1 - src/yp.c | 2 +- 8 files changed, 26 insertions(+), 53 deletions(-) diff --git a/src/admin.c b/src/admin.c index d22b5771..dc340070 100644 --- a/src/admin.c +++ b/src/admin.c @@ -217,8 +217,8 @@ xmlDocPtr admin_build_sourcelist(char *current_source) 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 @@ static void command_metadata(client_t *client, source_t *source) 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 @@ static void command_shoutcast_metadata(client_t *client, source_t *source) 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; } diff --git a/src/connection.c b/src/connection.c index c5cc0880..347f4474 100644 --- a/src/connection.c +++ b/src/connection.c @@ -472,7 +472,7 @@ int connection_complete_source (source_t *source) { 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) diff --git a/src/format.c b/src/format.c index d498a3af..dafa8c8b 100644 --- a/src/format.c +++ b/src/format.c @@ -54,31 +54,10 @@ format_type_t format_get_type(char *contenttype) 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; -} - -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; - } + else + /* We default to the Generic format handler, which + can handle many more formats than just mp3 */ + return FORMAT_TYPE_GENERIC; } int format_get_plugin(format_type_t type, source_t *source) @@ -89,19 +68,14 @@ int format_get_plugin(format_type_t type, source_t *source) 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; } diff --git a/src/format.h b/src/format.h index 52d150ba..cedb98e7 100644 --- a/src/format.h +++ b/src/format.h @@ -27,8 +27,7 @@ struct source_tag; 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 @@ typedef struct _format_plugin_tag /* 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); diff --git a/src/format_mp3.c b/src/format_mp3.c index 4b0f7735..ba8a1e03 100644 --- a/src/format_mp3.c +++ b/src/format_mp3.c @@ -82,14 +82,19 @@ int format_mp3_get_plugin (source_t *source) 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; @@ -617,7 +622,7 @@ static void format_mp3_send_headers(format_plugin_t *self, "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) diff --git a/src/format_vorbis.c b/src/format_vorbis.c index 9f720e62..c394612a 100644 --- a/src/format_vorbis.c +++ b/src/format_vorbis.c @@ -87,7 +87,7 @@ int format_vorbis_get_plugin(source_t *source) 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 @@ static void format_vorbis_send_headers(format_plugin_t *self, 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; diff --git a/src/source.c b/src/source.c index fa4368d2..32d5d7d1 100644 --- a/src/source.c +++ b/src/source.c @@ -542,7 +542,6 @@ static void source_init (source_t *source) 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); diff --git a/src/yp.c b/src/yp.c index a6ec0d3d..648aac39 100644 --- a/src/yp.c +++ b/src/yp.c @@ -493,7 +493,7 @@ static ypdata_t *create_yp_entry (source_t *source) 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); }