Commit f89451a1 authored by Philipp Schafft's avatar Philipp Schafft 🦁 Committed by Philipp Schafft

Update: Make Vorbis one of many codecs. No other codecs supported yet.

This update allows later on adding of more codecs.
A generic Ogg type for the stream also got defined. Using that type
we can not alter the stream. But as long as we know the sample rate
we can still serve it to the server.
parent f1f6793c
......@@ -137,6 +137,7 @@ int input_calculate_ogg_sleep(ogg_page *page)
ogg_packet op;
static vorbis_info vi;
static vorbis_comment vc;
static input_type codec = ICES_INPUT_UNKNOWN;
static int need_start_pos, need_headers, state_in_use = 0;
static int serialno = 0;
static uint64_t offset;
......@@ -160,6 +161,7 @@ int input_calculate_ogg_sleep(ogg_page *page)
vorbis_comment_init (&vc);
need_start_pos = 1;
need_headers = 3;
codec = ICES_INPUT_UNKNOWN;
offset = (uint64_t)0;
}
if (need_start_pos)
......@@ -171,16 +173,29 @@ int input_calculate_ogg_sleep(ogg_page *page)
{
if (need_headers)
{
if (vorbis_synthesis_headerin (&vi, &vc, &op) < 0)
/* check for Vorbis. For Vorbis the Magic is {0x01|0x03|0x05}"vorbis" */
if (op.bytes > 7 && memcmp(op.packet+1, "vorbis", 6) == 0)
{
LOG_ERROR0("Timing control: can't determine sample rate for input, not vorbis.");
if (vorbis_synthesis_headerin (&vi, &vc, &op) < 0)
{
LOG_ERROR0("Timing control: can't determine sample rate for input, not vorbis.");
control.samplerate = 0;
vorbis_info_clear (&vi);
ogg_stream_clear (&os);
return -1;
}
control.samplerate = vi.rate;
codec = ICES_INPUT_VORBIS;
}
else if (codec == ICES_INPUT_UNKNOWN)
{
LOG_ERROR0("Timing control: can't determine sample rate for input, unsupported input format.");
control.samplerate = 0;
vorbis_info_clear (&vi);
ogg_stream_clear (&os);
return -1;
}
need_headers--;
control.samplerate = vi.rate;
if (need_headers == 0)
{
......@@ -196,7 +211,10 @@ int input_calculate_ogg_sleep(ogg_page *page)
first_granulepos = op.granulepos;
found_first_granulepos = 1;
}
offset += vorbis_packet_blocksize (&vi, &op) / 4;
if (codec == ICES_INPUT_VORBIS)
{
offset += vorbis_packet_blocksize (&vi, &op) / 4;
}
}
if (!found_first_granulepos)
return 0;
......
......@@ -20,8 +20,10 @@
#include <vorbis/codec.h>
typedef enum _input_type {
ICES_INPUT_UNKNOWN, /* not yet known */
ICES_INPUT_PCM,
ICES_INPUT_VORBIS,
ICES_INPUT_OGG, /* generic Ogg */
/* Can add others here in the future, if we want */
} input_type;
......
......@@ -55,8 +55,8 @@ void *ices_instance_stream(void *arg)
stream_description *sdsc = arg;
instance_t *stream = sdsc->stream;
input_module_t *inmod = sdsc->input;
int reencoding = (inmod->type == ICES_INPUT_VORBIS) && stream->encode;
int encoding = (inmod->type == ICES_INPUT_PCM) && stream->encode;
int reencoding = 0;
int encoding = 0;
char *stream_name = NULL, *stream_genre = NULL, *stream_description = NULL;
char *stream_url = NULL, *user = NULL;
char audio_info[11];
......@@ -65,10 +65,28 @@ void *ices_instance_stream(void *arg)
sdsc->shout = shout_new();
/* we only support the ice protocol and vorbis streams currently */
shout_set_format(sdsc->shout, SHOUT_FORMAT_VORBIS);
/* we only support the ice protocol */
shout_set_protocol(sdsc->shout, SHOUT_PROTOCOL_HTTP);
switch (inmod->type) {
case ICES_INPUT_UNKNOWN:
LOG_ERROR0("Unknown stream type.\n");
stream->died = 1;
return NULL;
break;
case ICES_INPUT_VORBIS:
shout_set_format(sdsc->shout, SHOUT_FORMAT_VORBIS);
reencoding = stream->encode;
break;
case ICES_INPUT_OGG:
shout_set_format(sdsc->shout, SHOUT_FORMAT_OGG);
break;
case ICES_INPUT_PCM:
shout_set_format(sdsc->shout, SHOUT_FORMAT_VORBIS);
encoding = stream->encode;
break;
}
#ifndef _WIN32
signal(SIGPIPE, signal_hup_handler);
#endif
......
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