1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05:00

Feature: Added basic text streaming support

See: #2084
This commit is contained in:
Philipp Schafft 2021-06-28 18:57:02 +00:00
parent d6be48e207
commit b7c878cee9
3 changed files with 60 additions and 0 deletions

View File

@ -71,6 +71,8 @@ format_type_t format_get_type (const char *contenttype)
return FORMAT_TYPE_EBML;
else if(strcmp(contenttype, "video/x-matroska-3d") == 0)
return FORMAT_TYPE_EBML;
else if(strcmp(contenttype, "text/plain") == 0)
return FORMAT_TYPE_TEXT;
else
/* We default to the Generic format handler, which
can handle many more formats than just mp3.
@ -90,6 +92,9 @@ int format_get_plugin(format_type_t type, source_t *source)
case FORMAT_TYPE_EBML:
ret = format_ebml_get_plugin(source);
break;
case FORMAT_TYPE_TEXT:
ret = format_text_get_plugin(source);
break;
case FORMAT_TYPE_GENERIC:
ret = format_mp3_get_plugin(source);
break;

View File

@ -32,6 +32,7 @@ typedef enum _format_type_tag
FORMAT_ERROR, /* No format, source not processable */
FORMAT_TYPE_OGG,
FORMAT_TYPE_EBML,
FORMAT_TYPE_TEXT,
FORMAT_TYPE_GENERIC
} format_type_t;

View File

@ -12,9 +12,63 @@
#include <config.h>
#endif
#include <stdlib.h>
#include "source.h"
#include "format.h"
#include "format_text.h"
#define CATMODULE "format-text"
#include "logging.h"
static void text_free_plugin(format_plugin_t *plugin)
{
free(plugin);
}
static refbuf_t *text_get_buffer(source_t *source)
{
format_plugin_t *format = source->format;
refbuf_t *refbuf = refbuf_new(1024);
ssize_t bytes;
bytes = client_body_read(source->client, refbuf->data, refbuf->len);
if (bytes < 0) {
/* Why do we do this here (not source.c)? -- ph3-der-loewe, 2018-04-17 */
if (client_body_eof(source->client)) {
refbuf_release (refbuf);
}
return NULL;
}
refbuf->len = bytes;
refbuf->sync_point = 1;
format->read_bytes += bytes;
ICECAST_LOG_DDEBUG("Got buffer for source %p with %zi bytes", source, bytes);
return refbuf;
}
int format_text_get_plugin(source_t *source)
{
format_plugin_t *plugin = calloc(1, sizeof(format_plugin_t));
ICECAST_LOG_DEBUG("Opening text format for source %p", source);
plugin->get_buffer = text_get_buffer;
plugin->write_buf_to_client = format_generic_write_to_client;
plugin->create_client_data = NULL;
plugin->free_plugin = text_free_plugin;
plugin->write_buf_to_file = NULL;
plugin->set_tag = NULL;
plugin->apply_settings = NULL;
plugin->contenttype = httpp_getvar(source->parser, "content-type");
plugin->_state = NULL;
vorbis_comment_init(&plugin->vc);
source->format = plugin;
return 0;
}