[xiph-commits] r7409 - icecast/trunk/ices0/src
brendan at dactyl.lonelymoon.com
brendan
Wed Jul 28 18:17:26 PDT 2004
Author: brendan
Date: Wed Jul 28 18:17:26 2004
New Revision: 7409
Modified:
icecast/trunk/ices0/src/
icecast/trunk/ices0/src/crossfade.c
icecast/trunk/ices0/src/ices_config.c
icecast/trunk/ices0/src/icestypes.h
icecast/trunk/ices0/src/reencode.c
icecast/trunk/ices0/src/setup.c
icecast/trunk/ices0/src/stream.c
Log:
Init/shutdown hooks for plugin (crossfade politely returns memory on shutdown).
Property changes on: icecast/trunk/ices0/src
___________________________________________________________________
Name: svn:ignore
- Makefile.in
+ Makefile.in
TAGS
Modified: icecast/trunk/ices0/src/crossfade.c
===================================================================
--- icecast/trunk/ices0/src/crossfade.c 2004-07-29 01:15:58 UTC (rev 7408)
+++ icecast/trunk/ices0/src/crossfade.c 2004-07-29 01:17:26 UTC (rev 7409)
@@ -21,22 +21,26 @@
#include "definitions.h"
+static int cf_init(void);
static void cf_new_track(input_stream_t *source);
static int cf_process(int ilen, int16_t* il, int16_t* ir);
+static void cf_shutdown(void);
static ices_plugin_t Crossfader = {
"crossfade",
+ cf_init,
cf_new_track,
cf_process,
+ cf_shutdown,
NULL
};
static int FadeSamples;
-static int16_t* FL;
-static int16_t* FR;
-static int16_t* Swap;
+static int16_t* FL = NULL;
+static int16_t* FR = NULL;
+static int16_t* Swap = NULL;
static int fpos = 0;
static int flen = 0;
@@ -45,15 +49,28 @@
/* public functions */
ices_plugin_t *crossfade_plugin(int secs) {
FadeSamples = secs * 44100;
- FL = malloc(FadeSamples * 2);
- FR = malloc(FadeSamples * 2);
- Swap = malloc(FadeSamples *2);
- ices_log_debug("Crossfading %d seconds between tracks", secs);
return &Crossfader;
}
/* private functions */
+static int cf_init(void) {
+ if (!(FL = malloc(FadeSamples * 2)))
+ goto err;
+ if (!(FR = malloc(FadeSamples * 2)))
+ goto err;
+ if (!(Swap = malloc(FadeSamples * 2)))
+ goto err;
+
+ ices_log_debug("Crossfading %d seconds between tracks", FadeSamples / 44100);
+ return 0;
+
+ err:
+ ices_log_error("Crossfader could not allocate memory");
+ cf_shutdown();
+ return -1;
+}
+
static void cf_new_track(input_stream_t *source) {
static int skipnext = 0;
static input_stream_t lasttrack;
@@ -133,3 +150,20 @@
return i;
}
+
+static void cf_shutdown(void) {
+ if (FL) {
+ free(FL);
+ FL = NULL;
+ }
+ if (FR) {
+ free(FR);
+ FR = NULL;
+ }
+ if (Swap) {
+ free(Swap);
+ Swap = NULL;
+ }
+
+ ices_log_debug("Crossfader shutting down");
+}
Modified: icecast/trunk/ices0/src/ices_config.c
===================================================================
--- icecast/trunk/ices0/src/ices_config.c 2004-07-29 01:15:58 UTC (rev 7408)
+++ icecast/trunk/ices0/src/ices_config.c 2004-07-29 01:17:26 UTC (rev 7409)
@@ -280,7 +280,8 @@
ices_util_strdup (ices_xml_read_node (doc, cur));
} else if (strcmp (cur->name, "Crossfade") == 0) {
if ((i = atoi (ices_xml_read_node (doc, cur))) > 0)
- ices_config->plugin = crossfade_plugin(i);
+ /* TODO: stack plugins */
+ ices_config->plugins = crossfade_plugin(i);
} else {
ices_log ("Unknown playlist keyword: %s", cur->name);
}
Modified: icecast/trunk/ices0/src/icestypes.h
===================================================================
--- icecast/trunk/ices0/src/icestypes.h 2004-07-29 01:15:58 UTC (rev 7408)
+++ icecast/trunk/ices0/src/icestypes.h 2004-07-29 01:17:26 UTC (rev 7409)
@@ -105,8 +105,10 @@
typedef struct _ices_plugin {
const char *name;
+ int (*init)(void);
void (*new_track)(input_stream_t *source);
int (*process)(int ilen, int16_t *il, int16_t *ir);
+ void (*shutdown)(void);
struct _ices_plugin *next;
} ices_plugin_t;
@@ -121,6 +123,6 @@
ices_stream_t* streams;
playlist_module_t pm;
- ices_plugin_t *plugin;
+ ices_plugin_t *plugins;
} ices_config_t;
#endif
Modified: icecast/trunk/ices0/src/reencode.c
===================================================================
--- icecast/trunk/ices0/src/reencode.c 2004-07-29 01:15:58 UTC (rev 7408)
+++ icecast/trunk/ices0/src/reencode.c 2004-07-29 01:17:26 UTC (rev 7409)
@@ -48,7 +48,7 @@
if (! ices_config.reencode)
return;
- ices_log_debug ("Using LAME version %s\n", get_lame_version ());
+ ices_log_debug ("Using LAME version %s", get_lame_version ());
}
/* For each song, reset the liblame engine, otherwise it craps out if
Modified: icecast/trunk/ices0/src/setup.c
===================================================================
--- icecast/trunk/ices0/src/setup.c 2004-07-29 01:15:58 UTC (rev 7408)
+++ icecast/trunk/ices0/src/setup.c 2004-07-29 01:17:26 UTC (rev 7409)
@@ -48,6 +48,7 @@
ices_setup_initialize (void)
{
ices_stream_t* stream;
+ ices_plugin_t* plugin;
shout_init();
@@ -79,7 +80,16 @@
#ifdef HAVE_LIBLAME
/* Initialize liblame for reeencoding */
ices_reencode_initialize ();
+
+ while (ices_config.plugins && ices_config.plugins->init() < 0)
+ ices_config.plugins = ices_config.plugins->next;
+
+ for (plugin = ices_config.plugins; plugin->next; plugin = plugin->next)
+ if (plugin->next->init() < 0)
+ plugin->next = plugin->next->next;
#endif
+
+ ices_log_debug("Startup complete\n");
}
/* Top level ices shutdown function.
@@ -88,6 +98,7 @@
ices_setup_shutdown (void)
{
ices_stream_t* stream;
+ ices_plugin_t* plugin;
/* Tell libshout to disconnect from server */
for (stream = ices_config.streams; stream; stream = stream->next)
@@ -95,6 +106,9 @@
shout_close (stream->conn);
#ifdef HAVE_LIBLAME
+ for (plugin = ices_config.plugins; plugin; plugin = plugin->next)
+ plugin->shutdown();
+
/* Order the reencoding engine to shutdown */
ices_reencode_shutdown ();
#endif
@@ -336,7 +350,8 @@
case 'C':
arg++;
if (atoi(argv[arg]) > 0)
- ices_config->plugin = crossfade_plugin(atoi(argv[arg]));
+ /* TODO: stack plugins */
+ ices_config->plugins = crossfade_plugin(atoi(argv[arg]));
case 'c':
arg++;
break;
Modified: icecast/trunk/ices0/src/stream.c
===================================================================
--- icecast/trunk/ices0/src/stream.c 2004-07-29 01:15:58 UTC (rev 7408)
+++ icecast/trunk/ices0/src/stream.c 2004-07-29 01:17:26 UTC (rev 7409)
@@ -164,10 +164,10 @@
if (config->reencode) {
ices_reencode_reset (source);
- if (config->plugin) {
+ if (config->plugins) {
decode = 1;
- for (plugin = config->plugin; plugin; plugin = plugin->next)
- config->plugin->new_track(source);
+ for (plugin = config->plugins; plugin; plugin = plugin->next)
+ plugin->new_track(source);
} else
for (stream = config->streams; stream; stream = stream->next)
if (stream->reencode && stream_needs_reencoding (source, stream)) {
@@ -208,7 +208,7 @@
#ifdef HAVE_LIBLAME
/* run output through plugin */
- for (plugin = config->plugin; plugin; plugin = plugin->next)
+ for (plugin = config->plugins; plugin; plugin = plugin->next)
if (samples)
samples = plugin->process(samples, left, right);
#endif
@@ -228,7 +228,7 @@
for (stream = config->streams; stream; stream = stream->next) {
/* don't reencode if the source is MP3 and the same bitrate */
#ifdef HAVE_LIBLAME
- if (stream->reencode && (config->plugin || stream_needs_reencoding (source, stream))) {
+ if (stream->reencode && (config->plugins || stream_needs_reencoding (source, stream))) {
if (samples > 0) {
/* for some reason we have to manually duplicate right from left to get
* LAME to output stereo from a mono source */
More information about the commits
mailing list