Commit 731f24d0 authored by Ed "oddsock" Zaleski's avatar Ed "oddsock" Zaleski

handle supported content-types in a more generic way now. This will allow...

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
parent 524d467a
......@@ -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;
}
......
......@@ -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)
......
......@@ -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:
ret = format_mp3_get_plugin (source);
break;
case FORMAT_TYPE_NSV:
case FORMAT_TYPE_GENERIC:
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;
}
......
......@@ -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);
......
......@@ -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)
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment