Commit 9f15ca20 authored by Karl Heyes's avatar Karl Heyes
Browse files

don't use the same serial number for multiple outgoing encoded streams,

not a problem normally except for when an icecast fallback or moveclients
is invoked.

svn path=/trunk/ices/; revision=5710
parent c51a3e67
/* cfgparse.c
* - cfgparse file reading code, plus default settings.
*
* $Id: cfgparse.c,v 1.8 2003/12/22 01:53:20 karl Exp $
* $Id: cfgparse.c,v 1.9 2003/12/22 14:01:09 karl Exp $
*
* Copyright (c) 2001 Michael Smith <msmith@labyrinth.net.au>
*
......@@ -142,7 +142,6 @@ static void _set_instance_defaults(instance_t *instance)
instance->queue = calloc(1, sizeof(buffer_queue));
thread_mutex_create(&instance->queue->lock);
instance->serial = rand();
instance->next = NULL;
}
......
/* config.h
* - configuration, and global structures built from config
*
* $Id: cfgparse.h,v 1.5 2003/12/21 03:38:53 karl Exp $
* $Id: cfgparse.h,v 1.6 2003/12/22 14:01:09 karl Exp $
*
* Copyright (c) 2001 Michael Smith <msmith@labyrinth.net.au>
*
......@@ -59,7 +59,6 @@ typedef struct _instance_tag
/* private */
FILE *savefile;
int serial;
int buffer_failures;
int died;
int kill;
......
/* encode.c
* - runtime encoding of PCM data.
*
* $Id: encode.c,v 1.18 2003/12/22 01:53:20 karl Exp $
* $Id: encode.c,v 1.19 2003/12/22 14:01:09 karl Exp $
*
* Copyright (c) 2001 Michael Smith <msmith@labyrinth.net.au>
*
......@@ -29,6 +29,23 @@
#define MODULE "encode/"
#include "logging.h"
static mutex_t _serial_lock;
static long _get_serial()
{
static long prev_serial = 0;
long serial;
thread_mutex_lock (&_serial_lock);
serial = prev_serial;
while (serial == prev_serial)
serial = rand();
prev_serial = serial;
thread_mutex_unlock (&_serial_lock);
return serial;
}
void encode_clear(encoder_state *s)
{
if(s)
......@@ -42,9 +59,9 @@ void encode_clear(encoder_state *s)
}
}
encoder_state *encode_initialise(int channels, int rate, int managed,
int min_br, int nom_br, int max_br, float quality,
int serial, vorbis_comment *vc)
int min_br, int nom_br, int max_br, float quality, vorbis_comment *vc)
{
encoder_state *s = calloc(1, sizeof(encoder_state));
ogg_packet h1,h2,h3;
......@@ -112,7 +129,7 @@ encoder_state *encode_initialise(int channels, int rate, int managed,
vorbis_analysis_init(&s->vd, &s->vi);
vorbis_block_init(&s->vd, &s->vb);
ogg_stream_init(&s->os, serial);
ogg_stream_init(&s->os, _get_serial());
vorbis_analysis_headerout(&s->vd, vc, &h1,&h2,&h3);
ogg_stream_packetin(&s->os, &h1);
......@@ -275,5 +292,12 @@ int encode_flush(encoder_state *s, ogg_page *og)
return 1;
}
void encode_init()
{
thread_mutex_create (&_serial_lock);
}
void encode_close()
{
thread_mutex_destroy (&_serial_lock);
}
/* encode.h
* - encoding functions
*
* $Id: encode.h,v 1.4 2003/03/16 14:21:48 msmith Exp $
* $Id: encode.h,v 1.5 2003/12/22 14:01:09 karl Exp $
*
* Copyright (c) 2001 Michael Smith <msmith@labyrinth.net.au>
*
......@@ -30,14 +30,16 @@ typedef struct {
} encoder_state;
encoder_state *encode_initialise(int channels, int rate, int managed,
int min_br, int nom_br, int max_br, float quality,
int serial, vorbis_comment *vc);
int min_br, int nom_br, int max_br, float quality, vorbis_comment *vc);
void encode_clear(encoder_state *s);
void encode_data_float(encoder_state *s, float **pcm, int samples);
void encode_data(encoder_state *s, signed char *buf, int bytes, int bigendian);
int encode_dataout(encoder_state *s, ogg_page *og);
void encode_finish(encoder_state *s);
int encode_flush(encoder_state *s, ogg_page *og);
void encode_init();
void encode_close();
#endif
/* ices.c
* - Main startup, thread launching, and cleanup code.
*
* $Id: ices.c,v 1.13 2003/12/21 03:38:53 karl Exp $
* $Id: ices.c,v 1.14 2003/12/22 14:01:09 karl Exp $
*
* Copyright (c) 2001-2002 Michael Smith <msmith@labyrinth.net.au>
*
......@@ -50,6 +50,7 @@ int main(int argc, char **argv)
thread_initialize();
config_initialize();
shout_init();
encode_init();
signals_setup();
......@@ -100,6 +101,7 @@ int main(int argc, char **argv)
log_close(log);
fail:
encode_close();
shout_shutdown();
config_shutdown();
thread_shutdown();
......
/* reencode.c
* - runtime reencoding of vorbis audio (usually to lower bitrates).
*
* $Id: reencode.c,v 1.9 2003/03/22 02:27:55 karl Exp $
* $Id: reencode.c,v 1.10 2003/12/22 14:01:09 karl Exp $
*
* Copyright (c) 2001 Michael Smith <msmith@labyrinth.net.au>
*
......@@ -155,7 +155,7 @@ int reencode_page(reencode_state *s, ref_buffer *buf,
s->encoder = encode_initialise(s->out_channels,
s->out_samplerate, s->managed,
s->out_min_br, s->out_nom_br, s->out_max_br,
s->quality, s->current_serial, &s->vc);
s->quality, &s->vc);
if(!s->encoder) {
LOG_ERROR0("Failed to configure encoder for reencoding");
......
/* stream.c
* - Core streaming functions/main loop.
*
* $Id: stream.c,v 1.30 2003/07/09 04:26:26 brendan Exp $
* $Id: stream.c,v 1.31 2003/12/22 14:01:09 karl Exp $
*
* Copyright (c) 2001 Michael Smith <msmith@labyrinth.net.au>
*
......@@ -192,7 +192,7 @@ void *ices_instance_stream(void *arg)
inmod->metadata_update(inmod->internal, &sdsc->vc);
sdsc->enc = encode_initialise(stream->channels, stream->samplerate,
stream->managed, stream->min_br, stream->nom_br, stream->max_br,
stream->quality, stream->serial++, &sdsc->vc);
stream->quality, &sdsc->vc);
if(!sdsc->enc) {
LOG_ERROR0("Failed to configure encoder");
stream->died = 1;
......
/* stream_shared.c
* - Stream utility functions.
*
* $Id: stream_shared.c,v 1.16 2003/04/04 16:32:16 karl Exp $
* $Id: stream_shared.c,v 1.17 2003/12/22 14:01:09 karl Exp $
*
* Copyright (c) 2001 Michael Smith <msmith@labyrinth.net.au>
*
......@@ -172,7 +172,7 @@ int process_and_send_buffer(stream_description *sdsc, ref_buffer *buffer)
sdsc->stream->samplerate, sdsc->stream->managed,
sdsc->stream->min_br, sdsc->stream->nom_br,
sdsc->stream->max_br, sdsc->stream->quality,
sdsc->stream->serial++, &sdsc->vc);
&sdsc->vc);
if(!sdsc->enc) {
LOG_ERROR0("Failed to initialise encoder");
return -2;
......
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