[xiph-cvs] cvs commit: ices/src config.c config.h encode.c encode.h event.h ices.c im_alsa.c im_alsa.h im_oss.c im_oss.h im_playlist.c im_playlist.h im_stdinpcm.c im_stdinpcm.h im_sun.c im_sun.h input.c input.h inputmodule.h metadata.c output.c playlist_basic.c playlist_basic.h process.c process.h reencode.c reencode.h resample.c resample.h savefile.c signals.c stream.c stream.h stream_rewrite.c stream_shared.c
Michael Smith
msmith at xiph.org
Sun Mar 16 06:21:51 PST 2003
msmith 03/03/16 09:21:50
Modified: src config.c config.h encode.c encode.h event.h ices.c
im_alsa.c im_alsa.h im_oss.c im_oss.h im_playlist.c
im_playlist.h im_stdinpcm.c im_stdinpcm.h im_sun.c
im_sun.h input.c input.h inputmodule.h metadata.c
output.c playlist_basic.c playlist_basic.h
process.c process.h reencode.c reencode.h
resample.c resample.h savefile.c signals.c stream.c
stream.h stream_rewrite.c stream_shared.c
Log:
Make other annoying people stop complaining about indentation styles by
converting this to consistent use of spaces as well.
Revision Changes Path
1.14 +289 -289 ices/src/config.c
Index: config.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/config.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- config.c 16 Aug 2002 14:23:43 -0000 1.13
+++ config.c 16 Mar 2003 14:21:48 -0000 1.14
@@ -1,7 +1,7 @@
/* config.c
* - config file reading code, plus default settings.
*
- * $Id: config.c,v 1.13 2002/08/16 14:23:43 msmith Exp $
+ * $Id: config.c,v 1.14 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -57,30 +57,30 @@
** stupid code over and over
*/
#define SET_STRING(x) \
- do {\
- if (x) free(x);\
- (x) = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);\
- } while (0)
+ do {\
+ if (x) free(x);\
+ (x) = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);\
+ } while (0)
#define SET_INT(x) \
- do {\
- char *tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);\
- (x) = atoi(tmp);\
- if (tmp) free(tmp);\
- } while (0)
+ do {\
+ char *tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);\
+ (x) = atoi(tmp);\
+ if (tmp) free(tmp);\
+ } while (0)
#define SET_FLOAT(x) \
- do {\
- char *tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);\
- (x) = atof(tmp);\
- if (tmp) free(tmp);\
- } while (0)
+ do {\
+ char *tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);\
+ (x) = atof(tmp);\
+ if (tmp) free(tmp);\
+ } while (0)
#define SET_PARM_STRING(p,x) \
do {\
if (x) free(x);\
(x) = (char *)xmlGetProp(node, p);\
- } while (0)
+ } while (0)
/* this is the global config variable */
@@ -90,65 +90,65 @@
static void _free_instances(instance_t *instance)
{
- instance_t *next;
-
- next = NULL;
- do
- {
- config_free_instance(instance);
- next = instance->next;
- free(instance);
-
- instance = next;
- } while (next != NULL);
+ instance_t *next;
+
+ next = NULL;
+ do
+ {
+ config_free_instance(instance);
+ next = instance->next;
+ free(instance);
+
+ instance = next;
+ } while (next != NULL);
}
void config_free_instance(instance_t *instance)
{
- if (instance->hostname) free(instance->hostname);
- if (instance->password) free(instance->password);
- if (instance->user) free(instance->user);
- if (instance->mount) free(instance->mount);
- if (instance->queue)
- {
- thread_mutex_destroy(&instance->queue->lock);
- free(instance->queue);
- }
+ if (instance->hostname) free(instance->hostname);
+ if (instance->password) free(instance->password);
+ if (instance->user) free(instance->user);
+ if (instance->mount) free(instance->mount);
+ if (instance->queue)
+ {
+ thread_mutex_destroy(&instance->queue->lock);
+ free(instance->queue);
+ }
}
static void _set_instance_defaults(instance_t *instance)
{
- instance->hostname = strdup(DEFAULT_HOSTNAME);
- instance->port = DEFAULT_PORT;
- instance->password = strdup(DEFAULT_PASSWORD);
- instance->user = DEFAULT_USERNAME;
- instance->mount = strdup(DEFAULT_MOUNT);
+ instance->hostname = strdup(DEFAULT_HOSTNAME);
+ instance->port = DEFAULT_PORT;
+ instance->password = strdup(DEFAULT_PASSWORD);
+ instance->user = DEFAULT_USERNAME;
+ instance->mount = strdup(DEFAULT_MOUNT);
instance->managed = DEFAULT_MANAGED;
- instance->min_br = DEFAULT_MIN_BITRATE;
- instance->nom_br = DEFAULT_NOM_BITRATE;
- instance->max_br = DEFAULT_MAX_BITRATE;
+ instance->min_br = DEFAULT_MIN_BITRATE;
+ instance->nom_br = DEFAULT_NOM_BITRATE;
+ instance->max_br = DEFAULT_MAX_BITRATE;
instance->quality = DEFAULT_QUALITY;
- instance->encode = DEFAULT_REENCODE;
+ instance->encode = DEFAULT_REENCODE;
instance->downmix = DEFAULT_DOWNMIX;
instance->resampleinrate = DEFAULT_RESAMPLE;
instance->resampleoutrate = DEFAULT_RESAMPLE;
- instance->reconnect_delay = DEFAULT_RECONN_DELAY;
- instance->reconnect_attempts = DEFAULT_RECONN_ATTEMPTS;
- instance->max_queue_length = DEFAULT_MAXQUEUELENGTH;
- instance->savefilename = DEFAULT_SAVEFILENAME;
-
- instance->queue = calloc(1, sizeof(buffer_queue));
- thread_mutex_create(&instance->queue->lock);
- instance->serial = rand();
+ instance->reconnect_delay = DEFAULT_RECONN_DELAY;
+ instance->reconnect_attempts = DEFAULT_RECONN_ATTEMPTS;
+ instance->max_queue_length = DEFAULT_MAXQUEUELENGTH;
+ instance->savefilename = DEFAULT_SAVEFILENAME;
+
+ instance->queue = calloc(1, sizeof(buffer_queue));
+ thread_mutex_create(&instance->queue->lock);
+ instance->serial = rand();
- instance->next = NULL;
+ instance->next = NULL;
}
static void _parse_resample(instance_t *instance,xmlDocPtr doc, xmlNodePtr node)
{
- do {
- if (node == NULL) break;
- if (xmlIsBlankNode(node)) continue;
+ do {
+ if (node == NULL) break;
+ if (xmlIsBlankNode(node)) continue;
if(strcmp(node->name, "in-rate") == 0)
SET_INT(instance->resampleinrate);
@@ -159,326 +159,326 @@
static void _parse_encode(instance_t *instance,xmlDocPtr doc, xmlNodePtr node)
{
- instance->encode = 1;
- do {
- if (node == NULL) break;
- if (xmlIsBlankNode(node)) continue;
+ instance->encode = 1;
+ do {
+ if (node == NULL) break;
+ if (xmlIsBlankNode(node)) continue;
if (strcmp(node->name, "nominal-bitrate") == 0)
- SET_INT(instance->nom_br);
+ SET_INT(instance->nom_br);
else if (strcmp(node->name, "minimum-bitrate") == 0)
- SET_INT(instance->min_br);
+ SET_INT(instance->min_br);
else if (strcmp(node->name, "maximum-bitrate") == 0)
- SET_INT(instance->max_br);
+ SET_INT(instance->max_br);
else if (strcmp(node->name, "quality") == 0)
- SET_FLOAT(instance->quality);
- else if (strcmp(node->name, "samplerate") == 0)
- SET_INT(instance->samplerate);
- else if (strcmp(node->name, "channels") == 0)
- SET_INT(instance->channels);
+ SET_FLOAT(instance->quality);
+ else if (strcmp(node->name, "samplerate") == 0)
+ SET_INT(instance->samplerate);
+ else if (strcmp(node->name, "channels") == 0)
+ SET_INT(instance->channels);
else if (strcmp(node->name, "managed") == 0)
SET_INT(instance->managed);
- } while ((node = node->next));
+ } while ((node = node->next));
}
static void _parse_metadata(instance_t *instance, config_t *config,
xmlDocPtr doc, xmlNodePtr node)
{
- do
- {
- if (node == NULL) break;
- if (xmlIsBlankNode(node)) continue;
+ do
+ {
+ if (node == NULL) break;
+ if (xmlIsBlankNode(node)) continue;
- if (strcmp(node->name, "name") == 0) {
+ if (strcmp(node->name, "name") == 0) {
if(instance)
- SET_STRING(instance->stream_name);
+ SET_STRING(instance->stream_name);
else
- SET_STRING(config->stream_name);
+ SET_STRING(config->stream_name);
}
- else if (strcmp(node->name, "genre") == 0) {
+ else if (strcmp(node->name, "genre") == 0) {
if(instance)
- SET_STRING(instance->stream_genre);
+ SET_STRING(instance->stream_genre);
else
- SET_STRING(config->stream_genre);
+ SET_STRING(config->stream_genre);
}
- else if (strcmp(node->name, "description") == 0) {
+ else if (strcmp(node->name, "description") == 0) {
if(instance)
- SET_STRING(instance->stream_description);
+ SET_STRING(instance->stream_description);
else
- SET_STRING(config->stream_description);
+ SET_STRING(config->stream_description);
}
- } while ((node = node->next));
+ } while ((node = node->next));
}
static void _parse_instance(config_t *config, xmlDocPtr doc, xmlNodePtr node)
{
- instance_t *instance, *i;
+ instance_t *instance, *i;
- instance = (instance_t *)calloc(1, sizeof(instance_t));
- _set_instance_defaults(instance);
+ instance = (instance_t *)calloc(1, sizeof(instance_t));
+ _set_instance_defaults(instance);
- do
- {
- if (node == NULL) break;
- if (xmlIsBlankNode(node)) continue;
-
- if (strcmp(node->name, "hostname") == 0)
- SET_STRING(instance->hostname);
- else if (strcmp(node->name, "port") == 0)
- SET_INT(instance->port);
- else if (strcmp(node->name, "password") == 0)
- SET_STRING(instance->password);
- else if (strcmp(node->name, "username") == 0)
- SET_STRING(instance->user);
- else if (strcmp(node->name, "savefile") == 0)
- SET_STRING(instance->savefilename);
- else if (strcmp(node->name, "mount") == 0)
- SET_STRING(instance->mount);
- else if(strcmp(node->name, "reconnectdelay") == 0)
- SET_INT(instance->reconnect_delay);
- else if(strcmp(node->name, "reconnectattempts") == 0)
- SET_INT(instance->reconnect_attempts);
- else if(strcmp(node->name, "maxqueuelength") == 0)
- SET_INT(instance->max_queue_length);
+ do
+ {
+ if (node == NULL) break;
+ if (xmlIsBlankNode(node)) continue;
+
+ if (strcmp(node->name, "hostname") == 0)
+ SET_STRING(instance->hostname);
+ else if (strcmp(node->name, "port") == 0)
+ SET_INT(instance->port);
+ else if (strcmp(node->name, "password") == 0)
+ SET_STRING(instance->password);
+ else if (strcmp(node->name, "username") == 0)
+ SET_STRING(instance->user);
+ else if (strcmp(node->name, "savefile") == 0)
+ SET_STRING(instance->savefilename);
+ else if (strcmp(node->name, "mount") == 0)
+ SET_STRING(instance->mount);
+ else if(strcmp(node->name, "reconnectdelay") == 0)
+ SET_INT(instance->reconnect_delay);
+ else if(strcmp(node->name, "reconnectattempts") == 0)
+ SET_INT(instance->reconnect_attempts);
+ else if(strcmp(node->name, "maxqueuelength") == 0)
+ SET_INT(instance->max_queue_length);
else if(strcmp(node->name, "downmix") == 0)
SET_INT(instance->downmix);
else if(strcmp(node->name, "resample") == 0)
_parse_resample(instance, doc, node->xmlChildrenNode);
- else if (strcmp(node->name, "encode") == 0)
- _parse_encode(instance, doc, node->xmlChildrenNode);
+ else if (strcmp(node->name, "encode") == 0)
+ _parse_encode(instance, doc, node->xmlChildrenNode);
else if (strcmp(node->name, "metadata") == 0)
- _parse_metadata(instance, config, doc, node->xmlChildrenNode);
- } while ((node = node->next));
+ _parse_metadata(instance, config, doc, node->xmlChildrenNode);
+ } while ((node = node->next));
- instance->next = NULL;
+ instance->next = NULL;
- if (_using_default_instance)
- {
- _using_default_instance = 0;
- _free_instances(config->instances);
- config->instances = NULL;
- }
-
- if (config->instances == NULL)
- {
- config->instances = instance;
- }
- else
- {
- i = config->instances;
- while (i->next != NULL) i = i->next;
- i->next = instance;
- }
+ if (_using_default_instance)
+ {
+ _using_default_instance = 0;
+ _free_instances(config->instances);
+ config->instances = NULL;
+ }
+
+ if (config->instances == NULL)
+ {
+ config->instances = instance;
+ }
+ else
+ {
+ i = config->instances;
+ while (i->next != NULL) i = i->next;
+ i->next = instance;
+ }
}
static void _parse_input(config_t *config, xmlDocPtr doc, xmlNodePtr node)
{
- module_param_t *param, *p;
+ module_param_t *param, *p;
- do
- {
- if (node == NULL) break;
- if (xmlIsBlankNode(node)) continue;
-
- if (strcmp(node->name, "module") == 0)
- SET_STRING(config->playlist_module);
- else if (strcmp(node->name, "param") == 0) {
- param = (module_param_t *)calloc(1, sizeof(module_param_t));
- SET_PARM_STRING("name", param->name);
- SET_STRING(param->value);
- param->next = NULL;
-
- if (config->module_params == NULL)
- {
- config->module_params = param;
- }
- else
- {
- p = config->module_params;
- while (p->next != NULL) p = p->next;
- p->next = param;
- }
- }
- } while ((node = node->next));
+ do
+ {
+ if (node == NULL) break;
+ if (xmlIsBlankNode(node)) continue;
+
+ if (strcmp(node->name, "module") == 0)
+ SET_STRING(config->playlist_module);
+ else if (strcmp(node->name, "param") == 0) {
+ param = (module_param_t *)calloc(1, sizeof(module_param_t));
+ SET_PARM_STRING("name", param->name);
+ SET_STRING(param->value);
+ param->next = NULL;
+
+ if (config->module_params == NULL)
+ {
+ config->module_params = param;
+ }
+ else
+ {
+ p = config->module_params;
+ while (p->next != NULL) p = p->next;
+ p->next = param;
+ }
+ }
+ } while ((node = node->next));
}
static void _parse_stream(config_t *config, xmlDocPtr doc, xmlNodePtr node)
{
- do
- {
- if (node == NULL) break;
- if (xmlIsBlankNode(node)) continue;
-
- if (strcmp(node->name, "metadata") == 0)
- _parse_metadata(NULL, config, doc, node->xmlChildrenNode);
- else if (strcmp(node->name, "input") == 0)
- _parse_input(config, doc, node->xmlChildrenNode);
- else if (strcmp(node->name, "instance") == 0)
- _parse_instance(config, doc, node->xmlChildrenNode);
- } while ((node = node->next));
+ do
+ {
+ if (node == NULL) break;
+ if (xmlIsBlankNode(node)) continue;
+
+ if (strcmp(node->name, "metadata") == 0)
+ _parse_metadata(NULL, config, doc, node->xmlChildrenNode);
+ else if (strcmp(node->name, "input") == 0)
+ _parse_input(config, doc, node->xmlChildrenNode);
+ else if (strcmp(node->name, "instance") == 0)
+ _parse_instance(config, doc, node->xmlChildrenNode);
+ } while ((node = node->next));
}
static void _parse_root(config_t *config, xmlDocPtr doc, xmlNodePtr node)
{
- do
- {
- if (node == NULL) break;
- if (xmlIsBlankNode(node)) continue;
-
- if (strcmp(node->name, "background") == 0)
- SET_INT(config->background);
- else if (strcmp(node->name, "logpath") == 0)
- SET_STRING(config->logpath);
- else if (strcmp(node->name, "logfile") == 0)
- SET_STRING(config->logfile);
- else if (strcmp(node->name, "loglevel") == 0)
- SET_INT(config->loglevel);
+ do
+ {
+ if (node == NULL) break;
+ if (xmlIsBlankNode(node)) continue;
+
+ if (strcmp(node->name, "background") == 0)
+ SET_INT(config->background);
+ else if (strcmp(node->name, "logpath") == 0)
+ SET_STRING(config->logpath);
+ else if (strcmp(node->name, "logfile") == 0)
+ SET_STRING(config->logfile);
+ else if (strcmp(node->name, "loglevel") == 0)
+ SET_INT(config->loglevel);
else if (strcmp(node->name, "consolelog") == 0)
SET_INT(config->log_stderr);
- else if (strcmp(node->name, "stream") == 0)
- _parse_stream(config, doc, node->xmlChildrenNode);
- } while ((node = node->next));
+ else if (strcmp(node->name, "stream") == 0)
+ _parse_stream(config, doc, node->xmlChildrenNode);
+ } while ((node = node->next));
}
static void _set_defaults(config_t *c)
{
- instance_t *instance;
+ instance_t *instance;
- c->background = DEFAULT_BACKGROUND;
- c->logpath = strdup(DEFAULT_LOGPATH);
- c->logfile = strdup(DEFAULT_LOGFILE);
- c->loglevel = DEFAULT_LOGLEVEL;
+ c->background = DEFAULT_BACKGROUND;
+ c->logpath = strdup(DEFAULT_LOGPATH);
+ c->logfile = strdup(DEFAULT_LOGFILE);
+ c->loglevel = DEFAULT_LOGLEVEL;
c->log_stderr = DEFAULT_LOG_STDERR;
- c->stream_name = strdup(DEFAULT_STREAM_NAME);
- c->stream_genre = strdup(DEFAULT_STREAM_GENRE);
- c->stream_description = strdup(DEFAULT_STREAM_DESCRIPTION);
-
- c->playlist_module = strdup(DEFAULT_PLAYLIST_MODULE);
-
- c->module_params = NULL;
-
- instance = (instance_t *)malloc(sizeof(instance_t));
- _set_instance_defaults(instance);
- c->instances = instance;
+ c->stream_name = strdup(DEFAULT_STREAM_NAME);
+ c->stream_genre = strdup(DEFAULT_STREAM_GENRE);
+ c->stream_description = strdup(DEFAULT_STREAM_DESCRIPTION);
+
+ c->playlist_module = strdup(DEFAULT_PLAYLIST_MODULE);
+
+ c->module_params = NULL;
+
+ instance = (instance_t *)malloc(sizeof(instance_t));
+ _set_instance_defaults(instance);
+ c->instances = instance;
}
static void _free_params(module_param_t *param)
{
- module_param_t *next;
- next = NULL;
- do
- {
- if (param->name) free(param->name);
- if (param->value) free(param->value);
- next = param->next;
- free(param);
-
- param = next;
- } while (next != NULL);
+ module_param_t *next;
+ next = NULL;
+ do
+ {
+ if (param->name) free(param->name);
+ if (param->value) free(param->value);
+ next = param->next;
+ free(param);
+
+ param = next;
+ } while (next != NULL);
}
void config_initialize(void)
{
- ices_config = (config_t *)calloc(1, sizeof(config_t));
- _set_defaults(ices_config);
- srand(time(NULL));
+ ices_config = (config_t *)calloc(1, sizeof(config_t));
+ _set_defaults(ices_config);
+ srand(time(NULL));
xmlInitParser();
}
void config_shutdown(void)
{
- if (ices_config == NULL) return;
+ if (ices_config == NULL) return;
- if (ices_config->module_params != NULL)
- {
- _free_params(ices_config->module_params);
- ices_config->module_params = NULL;
- }
-
- if (ices_config->instances != NULL)
- {
- _free_instances(ices_config->instances);
- ices_config->instances = NULL;
- }
+ if (ices_config->module_params != NULL)
+ {
+ _free_params(ices_config->module_params);
+ ices_config->module_params = NULL;
+ }
+
+ if (ices_config->instances != NULL)
+ {
+ _free_instances(ices_config->instances);
+ ices_config->instances = NULL;
+ }
- free(ices_config);
- ices_config = NULL;
+ free(ices_config);
+ ices_config = NULL;
xmlCleanupParser();
}
int config_read(const char *fn)
{
- xmlDocPtr doc;
- xmlNodePtr node;
+ xmlDocPtr doc;
+ xmlNodePtr node;
- if (fn == NULL || strcmp(fn, "") == 0) return -1;
+ if (fn == NULL || strcmp(fn, "") == 0) return -1;
- doc = xmlParseFile(fn);
- if (doc == NULL) return -1;
+ doc = xmlParseFile(fn);
+ if (doc == NULL) return -1;
- node = xmlDocGetRootElement(doc);
- if (node == NULL || strcmp(node->name, "ices") != 0)
- {
- xmlFreeDoc(doc);
- return 0;
- }
+ node = xmlDocGetRootElement(doc);
+ if (node == NULL || strcmp(node->name, "ices") != 0)
+ {
+ xmlFreeDoc(doc);
+ return 0;
+ }
- _parse_root(ices_config, doc, node->xmlChildrenNode);
+ _parse_root(ices_config, doc, node->xmlChildrenNode);
- xmlFreeDoc(doc);
+ xmlFreeDoc(doc);
- return 1;
+ return 1;
}
void config_dump(void)
{
- config_t *c = ices_config;
- module_param_t *param;
- instance_t *i;
-
- fprintf(stderr, "ices config dump:\n");
- fprintf(stderr, "background = %d\n", c->background);
- fprintf(stderr, "logpath = %s\n", c->logpath);
- fprintf(stderr, "logfile = %s\n", c->logfile);
- fprintf(stderr, "loglevel = %d\n", c->loglevel);
- fprintf(stderr, "\n");
- fprintf(stderr, "stream_name = %s\n", c->stream_name);
- fprintf(stderr, "stream_genre = %s\n", c->stream_genre);
- fprintf(stderr, "stream_description = %s\n", c->stream_description);
- fprintf(stderr, "\n");
- fprintf(stderr, "playlist_module = %s\n", c->playlist_module);
- param = c->module_params;
- while(param)
- {
- fprintf(stderr, "module_param: %s = %s\n", param->name, param->value);
- param = param->next;
- }
- fprintf(stderr, "\ninstances:\n\n");
-
- i = c->instances;
- while (i)
- {
- fprintf(stderr, "hostname = %s\n", i->hostname);
- fprintf(stderr, "port = %d\n", i->port);
- fprintf(stderr, "password = %s\n", i->password);
- fprintf(stderr, "mount = %s\n", i->mount);
- fprintf(stderr, "minimum bitrate = %d\n", i->min_br);
- fprintf(stderr, "nominal bitrate = %d\n", i->nom_br);
- fprintf(stderr, "maximum bitrate = %d\n", i->max_br);
- fprintf(stderr, "quality = %f\n", i->quality);
- fprintf(stderr, "managed = %d\n", i->managed);
- fprintf(stderr, "reencode = %d\n", i->encode);
- fprintf(stderr, "reconnect: %d times at %d second intervals\n",
- i->reconnect_attempts, i->reconnect_delay);
- fprintf(stderr, "maxqueuelength = %d\n", i->max_queue_length);
- fprintf(stderr, "\n");
-
- i = i->next;
- }
-
- fprintf(stderr, "\n");
+ config_t *c = ices_config;
+ module_param_t *param;
+ instance_t *i;
+
+ fprintf(stderr, "ices config dump:\n");
+ fprintf(stderr, "background = %d\n", c->background);
+ fprintf(stderr, "logpath = %s\n", c->logpath);
+ fprintf(stderr, "logfile = %s\n", c->logfile);
+ fprintf(stderr, "loglevel = %d\n", c->loglevel);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "stream_name = %s\n", c->stream_name);
+ fprintf(stderr, "stream_genre = %s\n", c->stream_genre);
+ fprintf(stderr, "stream_description = %s\n", c->stream_description);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "playlist_module = %s\n", c->playlist_module);
+ param = c->module_params;
+ while(param)
+ {
+ fprintf(stderr, "module_param: %s = %s\n", param->name, param->value);
+ param = param->next;
+ }
+ fprintf(stderr, "\ninstances:\n\n");
+
+ i = c->instances;
+ while (i)
+ {
+ fprintf(stderr, "hostname = %s\n", i->hostname);
+ fprintf(stderr, "port = %d\n", i->port);
+ fprintf(stderr, "password = %s\n", i->password);
+ fprintf(stderr, "mount = %s\n", i->mount);
+ fprintf(stderr, "minimum bitrate = %d\n", i->min_br);
+ fprintf(stderr, "nominal bitrate = %d\n", i->nom_br);
+ fprintf(stderr, "maximum bitrate = %d\n", i->max_br);
+ fprintf(stderr, "quality = %f\n", i->quality);
+ fprintf(stderr, "managed = %d\n", i->managed);
+ fprintf(stderr, "reencode = %d\n", i->encode);
+ fprintf(stderr, "reconnect: %d times at %d second intervals\n",
+ i->reconnect_attempts, i->reconnect_delay);
+ fprintf(stderr, "maxqueuelength = %d\n", i->max_queue_length);
+ fprintf(stderr, "\n");
+
+ i = i->next;
+ }
+
+ fprintf(stderr, "\n");
}
<p><p>1.16 +57 -57 ices/src/config.h
Index: config.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/config.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- config.h 16 Aug 2002 15:47:36 -0000 1.15
+++ config.h 16 Mar 2003 14:21:48 -0000 1.16
@@ -1,7 +1,7 @@
/* config.h
* - configuration, and global structures built from config
*
- * $Id: config.h,v 1.15 2002/08/16 15:47:36 msmith Exp $
+ * $Id: config.h,v 1.16 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -21,10 +21,10 @@
typedef struct _module_param_tag
{
- char *name;
- char *value;
+ char *name;
+ char *value;
- struct _module_param_tag *next;
+ struct _module_param_tag *next;
} module_param_t;
/* FIXME: orward declaraction because my headers are a mess. */
@@ -32,81 +32,81 @@
typedef struct _instance_tag
{
- char *hostname;
- int port;
- char *password;
+ char *hostname;
+ int port;
+ char *password;
char *user;
- char *mount;
- int reconnect_delay;
- int reconnect_attempts;
- int encode;
+ char *mount;
+ int reconnect_delay;
+ int reconnect_attempts;
+ int encode;
int downmix;
int resampleinrate;
int resampleoutrate;
- int max_queue_length;
- char *savefilename;
+ int max_queue_length;
+ char *savefilename;
/* local metadata */
- char *stream_name;
- char *stream_genre;
- char *stream_description;
+ char *stream_name;
+ char *stream_genre;
+ char *stream_description;
- /* Parameters for re-encoding */
+ /* Parameters for re-encoding */
int managed;
- int min_br, nom_br, max_br;
+ int min_br, nom_br, max_br;
float quality;
- int samplerate;
- int channels;
-
- /* private */
+ int samplerate;
+ int channels;
+
+ /* private */
FILE *savefile;
- int serial;
- int buffer_failures;
- int died;
- int kill;
- int skip;
+ int serial;
+ int buffer_failures;
+ int died;
+ int kill;
+ int skip;
int wait_for_critical;
- struct buffer_queue *queue;
+ struct buffer_queue *queue;
- struct _instance_tag *next;
+ struct _instance_tag *next;
} instance_t;
typedef struct _config_tag
{
- int background;
- char *logpath;
- char *logfile;
- int loglevel;
+ int background;
+ char *logpath;
+ char *logfile;
+ int loglevel;
int log_stderr;
- /* <stream> */
+ /* <stream> */
- /* <metadata> */
+ /* <metadata> */
- char *stream_name;
- char *stream_genre;
- char *stream_description;
-
- /* <playlist> */
-
- char *playlist_module;
- module_param_t *module_params;
-
- /* <instance> */
-
- instance_t *instances;
-
- /* private */
- int log_id;
- int shutdown;
+ char *stream_name;
+ char *stream_genre;
+ char *stream_description;
+
+ /* <playlist> */
+
+ char *playlist_module;
+ module_param_t *module_params;
+
+ /* <instance> */
+
+ instance_t *instances;
+
+ /* private */
+ int log_id;
+ int shutdown;
char *metadata_filename;
- cond_t queue_cond;
- cond_t event_pending_cond;
- mutex_t refcount_lock;
- mutex_t flush_lock;
- input_module_t *inmod;
- struct _config_tag *next;
+ cond_t queue_cond;
+ cond_t event_pending_cond;
+ mutex_t refcount_lock;
+ mutex_t flush_lock;
+ input_module_t *inmod;
+ struct _config_tag *next;
} config_t;
extern config_t *ices_config;
<p><p>1.14 +154 -154 ices/src/encode.c
Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/encode.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- encode.c 22 Nov 2002 13:01:34 -0000 1.13
+++ encode.c 16 Mar 2003 14:21:48 -0000 1.14
@@ -1,7 +1,7 @@
/* encode.c
* - runtime encoding of PCM data.
*
- * $Id: encode.c,v 1.13 2002/11/22 13:01:34 msmith Exp $
+ * $Id: encode.c,v 1.14 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -27,115 +27,115 @@
void encode_clear(encoder_state *s)
{
- if(s)
- {
- LOG_DEBUG0("Clearing encoder engine");
- ogg_stream_clear(&s->os);
- vorbis_block_clear(&s->vb);
- vorbis_dsp_clear(&s->vd);
- vorbis_info_clear(&s->vi);
- free(s);
- }
+ if(s)
+ {
+ LOG_DEBUG0("Clearing encoder engine");
+ ogg_stream_clear(&s->os);
+ vorbis_block_clear(&s->vb);
+ vorbis_dsp_clear(&s->vd);
+ vorbis_info_clear(&s->vi);
+ free(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 serial, vorbis_comment *vc)
{
- encoder_state *s = calloc(1, sizeof(encoder_state));
- ogg_packet h1,h2,h3;
+ encoder_state *s = calloc(1, sizeof(encoder_state));
+ ogg_packet h1,h2,h3;
- /* If none of these are set, it's obviously not supposed to be managed */
- if (nom_br < 0 && min_br < 0 && max_br < 0) {
- managed = 0;
- }
-
- if (managed) {
- LOG_INFO5("Encoder initialising with bitrate management: %d "
- "channels, %d Hz, minimum bitrate %d, nominal %d, "
- "maximum %d", channels, rate, min_br, nom_br, max_br);
- } else {
- if (min_br > 0 || max_br > 0) {
- LOG_INFO5("Encoder initialising in constrained VBR mode: %d "
- "channels, %d Hz, quality %f, minimum bitrate %d, "
- "maximum %d", channels, rate, quality, min_br, max_br);
- } else {
- LOG_INFO3("Encoder initialising in VBR mode: %d channel(s), %d Hz, "
- "quality %f", channels, rate, quality);
- }
- }
-
- /* Have vorbisenc choose a mode for us */
- vorbis_info_init(&s->vi);
-
- if (managed) {
- if (vorbis_encode_setup_managed(&s->vi, channels, rate,
- max_br>0?max_br:-1, nom_br, min_br>0?min_br:-1)) {
- LOG_ERROR5("Failed to configure managed encoding for "
- "%d channel(s), at %d Hz, with bitrates %d max %d "
- "nominal, %d min", channels, rate, max_br, nom_br, min_br);
- vorbis_info_clear(&s->vi);
- free(s);
- return NULL;
- }
- } else {
- if (vorbis_encode_setup_vbr(&s->vi, channels, rate, quality*0.1)) {
- LOG_ERROR3("Failed to configure VBR encoding for %d channel(s), "
- "at %d Hz, quality level %f", channels, rate, quality);
- vorbis_info_clear(&s->vi);
- free(s);
- return NULL;
- }
-
- if (max_br > 0 || min_br > 0) {
- struct ovectl_ratemanage_arg ai;
- vorbis_encode_ctl(&s->vi, OV_ECTL_RATEMANAGE_GET, &ai);
- ai.bitrate_hard_min = min_br;
- ai.bitrate_hard_max = max_br;
- ai.management_active = 1;
- vorbis_encode_ctl(&s->vi, OV_ECTL_RATEMANAGE_SET, &ai);
- }
- }
-
- if (managed && nom_br < 0) {
- vorbis_encode_ctl(&s->vi, OV_ECTL_RATEMANAGE_AVG, NULL);
- } else if (!managed) {
- vorbis_encode_ctl(&s->vi, OV_ECTL_RATEMANAGE_SET, NULL);
- }
+ /* If none of these are set, it's obviously not supposed to be managed */
+ if (nom_br < 0 && min_br < 0 && max_br < 0) {
+ managed = 0;
+ }
+
+ if (managed) {
+ LOG_INFO5("Encoder initialising with bitrate management: %d "
+ "channels, %d Hz, minimum bitrate %d, nominal %d, "
+ "maximum %d", channels, rate, min_br, nom_br, max_br);
+ } else {
+ if (min_br > 0 || max_br > 0) {
+ LOG_INFO5("Encoder initialising in constrained VBR mode: %d "
+ "channels, %d Hz, quality %f, minimum bitrate %d, "
+ "maximum %d", channels, rate, quality, min_br, max_br);
+ } else {
+ LOG_INFO3("Encoder initialising in VBR mode: %d channel(s), %d Hz, "
+ "quality %f", channels, rate, quality);
+ }
+ }
+
+ /* Have vorbisenc choose a mode for us */
+ vorbis_info_init(&s->vi);
+
+ if (managed) {
+ if (vorbis_encode_setup_managed(&s->vi, channels, rate,
+ max_br>0?max_br:-1, nom_br, min_br>0?min_br:-1)) {
+ LOG_ERROR5("Failed to configure managed encoding for "
+ "%d channel(s), at %d Hz, with bitrates %d max %d "
+ "nominal, %d min", channels, rate, max_br, nom_br, min_br);
+ vorbis_info_clear(&s->vi);
+ free(s);
+ return NULL;
+ }
+ } else {
+ if (vorbis_encode_setup_vbr(&s->vi, channels, rate, quality*0.1)) {
+ LOG_ERROR3("Failed to configure VBR encoding for %d channel(s), "
+ "at %d Hz, quality level %f", channels, rate, quality);
+ vorbis_info_clear(&s->vi);
+ free(s);
+ return NULL;
+ }
+
+ if (max_br > 0 || min_br > 0) {
+ struct ovectl_ratemanage_arg ai;
+ vorbis_encode_ctl(&s->vi, OV_ECTL_RATEMANAGE_GET, &ai);
+ ai.bitrate_hard_min = min_br;
+ ai.bitrate_hard_max = max_br;
+ ai.management_active = 1;
+ vorbis_encode_ctl(&s->vi, OV_ECTL_RATEMANAGE_SET, &ai);
+ }
+ }
+
+ if (managed && nom_br < 0) {
+ vorbis_encode_ctl(&s->vi, OV_ECTL_RATEMANAGE_AVG, NULL);
+ } else if (!managed) {
+ vorbis_encode_ctl(&s->vi, OV_ECTL_RATEMANAGE_SET, NULL);
+ }
vorbis_encode_setup_init(&s->vi);
- vorbis_analysis_init(&s->vd, &s->vi);
- vorbis_block_init(&s->vd, &s->vb);
+ 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, serial);
- vorbis_analysis_headerout(&s->vd, vc, &h1,&h2,&h3);
- ogg_stream_packetin(&s->os, &h1);
- ogg_stream_packetin(&s->os, &h2);
- ogg_stream_packetin(&s->os, &h3);
+ vorbis_analysis_headerout(&s->vd, vc, &h1,&h2,&h3);
+ ogg_stream_packetin(&s->os, &h1);
+ ogg_stream_packetin(&s->os, &h2);
+ ogg_stream_packetin(&s->os, &h3);
- s->in_header = 1;
+ s->in_header = 1;
s->samplerate = rate;
s->samples_in_current_page = 0;
s->prevgranulepos = 0;
- return s;
+ return s;
}
void encode_data_float(encoder_state *s, float **pcm, int samples)
{
- float **buf;
- int i;
+ float **buf;
+ int i;
- buf = vorbis_analysis_buffer(&s->vd, samples);
+ buf = vorbis_analysis_buffer(&s->vd, samples);
- for(i=0; i < s->vi.channels; i++)
- {
- memcpy(buf[i], pcm[i], samples*sizeof(float));
- }
+ for(i=0; i < s->vi.channels; i++)
+ {
+ memcpy(buf[i], pcm[i], samples*sizeof(float));
+ }
- vorbis_analysis_wrote(&s->vd, samples);
+ vorbis_analysis_wrote(&s->vd, samples);
s->samples_in_current_page += samples;
}
@@ -143,37 +143,37 @@
/* Requires little endian data (currently) */
void encode_data(encoder_state *s, signed char *buf, int bytes, int bigendian)
{
- float **buffer;
- int i,j;
- int channels = s->vi.channels;
- int samples = bytes/(2*channels);
-
- buffer = vorbis_analysis_buffer(&s->vd, samples);
-
- if(bigendian)
- {
- for(i=0; i < samples; i++)
- {
- for(j=0; j < channels; j++)
- {
- buffer[j][i]=((buf[2*(i*channels + j)]<<8) |
- (0x00ff&(int)buf[2*(i*channels + j)+1]))/32768.f;
- }
- }
- }
- else
- {
- for(i=0; i < samples; i++)
- {
- for(j=0; j < channels; j++)
- {
- buffer[j][i]=((buf[2*(i*channels + j) + 1]<<8) |
- (0x00ff&(int)buf[2*(i*channels + j)]))/32768.f;
- }
- }
- }
+ float **buffer;
+ int i,j;
+ int channels = s->vi.channels;
+ int samples = bytes/(2*channels);
+
+ buffer = vorbis_analysis_buffer(&s->vd, samples);
+
+ if(bigendian)
+ {
+ for(i=0; i < samples; i++)
+ {
+ for(j=0; j < channels; j++)
+ {
+ buffer[j][i]=((buf[2*(i*channels + j)]<<8) |
+ (0x00ff&(int)buf[2*(i*channels + j)+1]))/32768.f;
+ }
+ }
+ }
+ else
+ {
+ for(i=0; i < samples; i++)
+ {
+ for(j=0; j < channels; j++)
+ {
+ buffer[j][i]=((buf[2*(i*channels + j) + 1]<<8) |
+ (0x00ff&(int)buf[2*(i*channels + j)]))/32768.f;
+ }
+ }
+ }
- vorbis_analysis_wrote(&s->vd, samples);
+ vorbis_analysis_wrote(&s->vd, samples);
s->samples_in_current_page += samples;
}
@@ -188,30 +188,30 @@
*/
int encode_dataout(encoder_state *s, ogg_page *og)
{
- ogg_packet op;
- int result;
+ ogg_packet op;
+ int result;
- if(s->in_header)
- {
- result = ogg_stream_flush(&s->os, og);
- if(result==0)
- {
- s->in_header = 0;
- return encode_dataout(s,og);
- }
- else
- return 1;
- }
- else
- {
- while(vorbis_analysis_blockout(&s->vd, &s->vb)==1)
- {
- vorbis_analysis(&s->vb, NULL);
+ if(s->in_header)
+ {
+ result = ogg_stream_flush(&s->os, og);
+ if(result==0)
+ {
+ s->in_header = 0;
+ return encode_dataout(s,og);
+ }
+ else
+ return 1;
+ }
+ else
+ {
+ while(vorbis_analysis_blockout(&s->vd, &s->vb)==1)
+ {
+ vorbis_analysis(&s->vb, NULL);
vorbis_bitrate_addblock(&s->vb);
while(vorbis_bitrate_flushpacket(&s->vd, &op))
- ogg_stream_packetin(&s->os, &op);
- }
+ ogg_stream_packetin(&s->os, &op);
+ }
/* FIXME: Make this threshold configurable.
* We don't want to buffer too many samples in one page when doing
@@ -226,43 +226,43 @@
result = ogg_stream_flush(&s->os, og);
}
else
- result = ogg_stream_pageout(&s->os, og);
+ result = ogg_stream_pageout(&s->os, og);
- if(result==0)
- return 0;
- else /* Page found! */
+ if(result==0)
+ return 0;
+ else /* Page found! */
{
s->samples_in_current_page -= ogg_page_granulepos(og) -
s->prevgranulepos;
s->prevgranulepos = ogg_page_granulepos(og);
- return 1;
+ return 1;
}
- }
+ }
}
void encode_finish(encoder_state *s)
{
- ogg_packet op;
- vorbis_analysis_wrote(&s->vd, 0);
+ ogg_packet op;
+ vorbis_analysis_wrote(&s->vd, 0);
- while(vorbis_analysis_blockout(&s->vd, &s->vb)==1)
- {
+ while(vorbis_analysis_blockout(&s->vd, &s->vb)==1)
+ {
vorbis_analysis(&s->vb, NULL);
vorbis_bitrate_addblock(&s->vb);
while(vorbis_bitrate_flushpacket(&s->vd, &op))
- ogg_stream_packetin(&s->os, &op);
- }
+ ogg_stream_packetin(&s->os, &op);
+ }
}
int encode_flush(encoder_state *s, ogg_page *og)
{
- int result = ogg_stream_pageout(&s->os, og);
+ int result = ogg_stream_pageout(&s->os, og);
- if(result<=0)
- return 0;
- else
- return 1;
+ if(result<=0)
+ return 0;
+ else
+ return 1;
}
<p><p>1.4 +7 -7 ices/src/encode.h
Index: encode.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/encode.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- encode.h 28 Jan 2002 00:19:15 -0000 1.3
+++ encode.h 16 Mar 2003 14:21:48 -0000 1.4
@@ -1,7 +1,7 @@
/* encode.h
* - encoding functions
*
- * $Id: encode.h,v 1.3 2002/01/28 00:19:15 msmith Exp $
+ * $Id: encode.h,v 1.4 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -18,20 +18,20 @@
#include <vorbis/codec.h>
typedef struct {
- ogg_stream_state os;
- vorbis_block vb;
- vorbis_dsp_state vd;
- vorbis_info vi;
+ ogg_stream_state os;
+ vorbis_block vb;
+ vorbis_dsp_state vd;
+ vorbis_info vi;
int samples_in_current_page;
int samplerate;
ogg_int64_t prevgranulepos;
- int in_header;
+ int in_header;
} 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 serial, 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);
<p><p>1.3 +6 -6 ices/src/event.h
Index: event.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/event.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- event.h 25 Sep 2001 12:04:21 -0000 1.2
+++ event.h 16 Mar 2003 14:21:48 -0000 1.3
@@ -1,7 +1,7 @@
/* event.h
* - Generic interface for passing events to modules.
*
- * $Id: event.h,v 1.2 2001/09/25 12:04:21 msmith Exp $
+ * $Id: event.h,v 1.3 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -15,11 +15,11 @@
#define __EVENT_H__
enum event_type {
- EVENT_SHUTDOWN, /* Full/final shutdown. MUST NOT ignore */
- EVENT_PAUSE, /* temporary shutdown. Can be ignored */
- EVENT_NEXTTRACK, /* Start a new track in some way */
- EVENT_RECONF, /* Reconfigure self, if possible */
- EVENT_METADATAUPDATE, /* Incoming new metadata */
+ EVENT_SHUTDOWN, /* Full/final shutdown. MUST NOT ignore */
+ EVENT_PAUSE, /* temporary shutdown. Can be ignored */
+ EVENT_NEXTTRACK, /* Start a new track in some way */
+ EVENT_RECONF, /* Reconfigure self, if possible */
+ EVENT_METADATAUPDATE, /* Incoming new metadata */
};
#endif /* __EVENT_H__ */
<p><p>1.6 +45 -45 ices/src/ices.c
Index: ices.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/ices.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ices.c 16 Aug 2002 15:47:36 -0000 1.5
+++ ices.c 16 Mar 2003 14:21:48 -0000 1.6
@@ -1,7 +1,7 @@
/* ices.c
* - Main startup, thread launching, and cleanup code.
*
- * $Id: ices.c,v 1.5 2002/08/16 15:47:36 msmith Exp $
+ * $Id: ices.c,v 1.6 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
*
@@ -29,63 +29,63 @@
int main(int argc, char **argv)
{
- char logpath[FILENAME_MAX];
- int log;
+ char logpath[FILENAME_MAX];
+ int log;
- if (argc != 2)
- {
- fprintf(stderr, VERSIONSTRING "\n"
- " (c) Copyright 2001-2002 Michael Smith <msmith at icecast.org>\n"
- "\n"
- "Usage: \"ices config.xml\"\n");
- return 1;
- }
-
- log_initialize();
- thread_initialize();
- resolver_initialize();
- config_initialize();
-
- signals_setup();
-
- /* right now you must have a config file, but we should probably
- ** make it so you can specify all parameters on the commandline
- ** too.
- */
- if (config_read(argv[1]) <= 0)
- {
- fprintf(stderr, "Failed to read config file \"%s\"\n", argv[1]);
- goto fail;
- }
+ if (argc != 2)
+ {
+ fprintf(stderr, VERSIONSTRING "\n"
+ " (c) Copyright 2001-2002 Michael Smith <msmith at icecast.org>\n"
+ "\n"
+ "Usage: \"ices config.xml\"\n");
+ return 1;
+ }
+
+ log_initialize();
+ thread_initialize();
+ resolver_initialize();
+ config_initialize();
+
+ signals_setup();
+
+ /* right now you must have a config file, but we should probably
+ ** make it so you can specify all parameters on the commandline
+ ** too.
+ */
+ if (config_read(argv[1]) <= 0)
+ {
+ fprintf(stderr, "Failed to read config file \"%s\"\n", argv[1]);
+ goto fail;
+ }
- snprintf(logpath, FILENAME_MAX, "%s/%s", ices_config->logpath,
- ices_config->logfile);
+ snprintf(logpath, FILENAME_MAX, "%s/%s", ices_config->logpath,
+ ices_config->logfile);
if(ices_config->log_stderr)
log = log_open_file(stderr);
else
- log = log_open(logpath);
- /* Set the log level, if requested - defaults to 2 (WARN) otherwise */
- if (ices_config->loglevel)
- log_set_level(log, ices_config->loglevel);
+ log = log_open(logpath);
+ /* Set the log level, if requested - defaults to 2 (WARN) otherwise */
+ if (ices_config->loglevel)
+ log_set_level(log, ices_config->loglevel);
- ices_config->log_id = log;
+ ices_config->log_id = log;
- LOG_INFO0("ices started...");
+ LOG_INFO0("ices started...");
- /* Start the core streaming loop */
- input_loop();
+ /* Start the core streaming loop */
+ input_loop();
- LOG_INFO0("Shutdown complete");
+ LOG_INFO0("Shutdown complete");
- log_close(log);
+ log_close(log);
fail:
- config_shutdown();
- resolver_shutdown();
- thread_shutdown();
- log_shutdown();
+ config_shutdown();
+ resolver_shutdown();
+ thread_shutdown();
+ log_shutdown();
- return 0;
+ return 0;
}
<p><p>1.2 +184 -184 ices/src/im_alsa.c
Index: im_alsa.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_alsa.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- im_alsa.c 29 Dec 2002 10:28:30 -0000 1.1
+++ im_alsa.c 16 Mar 2003 14:21:48 -0000 1.2
@@ -1,7 +1,7 @@
/* im_alsa.c
* - Raw PCM input from ALSA devices
*
- * $Id: im_alsa.c,v 1.1 2002/12/29 10:28:30 msmith Exp $
+ * $Id: im_alsa.c,v 1.2 2003/03/16 14:21:48 msmith Exp $
*
* by Jason Chu <jchu at uvic.ca>, based
* on im_oss.c which is...
@@ -40,68 +40,68 @@
static void close_module(input_module_t *mod)
{
- if(mod)
- {
- if(mod->internal)
- {
- im_alsa_state *s = mod->internal;
- if(s->fd != NULL)
- snd_pcm_close(s->fd);
- thread_mutex_destroy(&s->metadatalock);
- free(s);
- }
- free(mod);
- }
+ if(mod)
+ {
+ if(mod->internal)
+ {
+ im_alsa_state *s = mod->internal;
+ if(s->fd != NULL)
+ snd_pcm_close(s->fd);
+ thread_mutex_destroy(&s->metadatalock);
+ free(s);
+ }
+ free(mod);
+ }
}
static int event_handler(input_module_t *mod, enum event_type ev, void *param)
{
- im_alsa_state *s = mod->internal;
+ im_alsa_state *s = mod->internal;
- switch(ev)
- {
- case EVENT_SHUTDOWN:
- close_module(mod);
- break;
- case EVENT_NEXTTRACK:
- s->newtrack = 1;
- break;
- case EVENT_METADATAUPDATE:
- thread_mutex_lock(&s->metadatalock);
- if(s->metadata)
- {
- char **md = s->metadata;
- while(*md)
- free(*md++);
- free(s->metadata);
- }
- s->metadata = (char **)param;
- s->newtrack = 1;
- thread_mutex_unlock(&s->metadatalock);
- break;
- default:
- LOG_WARN1("Unhandled event %d", ev);
- return -1;
- }
+ switch(ev)
+ {
+ case EVENT_SHUTDOWN:
+ close_module(mod);
+ break;
+ case EVENT_NEXTTRACK:
+ s->newtrack = 1;
+ break;
+ case EVENT_METADATAUPDATE:
+ thread_mutex_lock(&s->metadatalock);
+ if(s->metadata)
+ {
+ char **md = s->metadata;
+ while(*md)
+ free(*md++);
+ free(s->metadata);
+ }
+ s->metadata = (char **)param;
+ s->newtrack = 1;
+ thread_mutex_unlock(&s->metadatalock);
+ break;
+ default:
+ LOG_WARN1("Unhandled event %d", ev);
+ return -1;
+ }
- return 0;
+ return 0;
}
static void metadata_update(void *self, vorbis_comment *vc)
{
- im_alsa_state *s = self;
- char **md;
+ im_alsa_state *s = self;
+ char **md;
- thread_mutex_lock(&s->metadatalock);
+ thread_mutex_lock(&s->metadatalock);
- md = s->metadata;
+ md = s->metadata;
- if(md)
- {
- while(*md)
- vorbis_comment_add(vc, *md++);
- }
+ if(md)
+ {
+ while(*md)
+ vorbis_comment_add(vc, *md++);
+ }
- thread_mutex_unlock(&s->metadatalock);
+ thread_mutex_unlock(&s->metadatalock);
}
/* Core streaming function for this module
@@ -113,157 +113,157 @@
*/
static int alsa_read(void *self, ref_buffer *rb)
{
- int result;
- im_alsa_state *s = self;
+ int result;
+ im_alsa_state *s = self;
- rb->buf = malloc(BUFSIZE*2*s->channels);
+ rb->buf = malloc(BUFSIZE*2*s->channels);
if(!rb->buf)
return -1;
- result = snd_pcm_readi(s->fd, rb->buf, BUFSIZE>>2);
+ result = snd_pcm_readi(s->fd, rb->buf, BUFSIZE>>2);
- rb->len = result*4;
- rb->aux_data = s->rate*s->channels*2;
+ rb->len = result*4;
+ rb->aux_data = s->rate*s->channels*2;
- if(s->newtrack)
- {
- rb->critical = 1;
- s->newtrack = 0;
- }
-
- if (result == -EPIPE)
- {
- snd_pcm_prepare(s->fd);
- return 0;
- }
- else if (result == -EBADFD)
- {
- LOG_ERROR0("Bad descriptor passed to snd_pcm_readi");
- free(rb->buf);
- return -1;
- }
+ if(s->newtrack)
+ {
+ rb->critical = 1;
+ s->newtrack = 0;
+ }
+
+ if (result == -EPIPE)
+ {
+ snd_pcm_prepare(s->fd);
+ return 0;
+ }
+ else if (result == -EBADFD)
+ {
+ LOG_ERROR0("Bad descriptor passed to snd_pcm_readi");
+ free(rb->buf);
+ return -1;
+ }
- return rb->len;
+ return rb->len;
}
input_module_t *alsa_open_module(module_param_t *params)
{
- input_module_t *mod = calloc(1, sizeof(input_module_t));
- im_alsa_state *s;
- module_param_t *current;
- char *device = "plughw:0,0"; /* default device */
- int format = AFMT_S16_LE;
- int channels, rate;
- int use_metadata = 1; /* Default to on */
-
- snd_pcm_stream_t stream = SND_PCM_STREAM_CAPTURE;
- snd_pcm_hw_params_t *hwparams;
-
- int err;
-
- mod->type = ICES_INPUT_PCM;
- mod->subtype = INPUT_PCM_LE_16;
- mod->getdata = alsa_read;
- mod->handle_event = event_handler;
- mod->metadata_update = metadata_update;
-
- mod->internal = calloc(1, sizeof(im_alsa_state));
- s = mod->internal;
-
- s->fd = NULL; /* Set it to something invalid, for now */
- s->rate = 44100; /* Defaults */
- s->channels = 2;
-
- thread_mutex_create(&s->metadatalock);
-
- current = params;
-
- while(current)
- {
- if(!strcmp(current->name, "rate"))
- s->rate = atoi(current->value);
- else if(!strcmp(current->name, "channels"))
- s->channels = atoi(current->value);
- else if(!strcmp(current->name, "device"))
- device = current->value;
- else if(!strcmp(current->name, "metadata"))
- use_metadata = atoi(current->value);
- else if(!strcmp(current->name, "metadatafilename"))
- ices_config->metadata_filename = current->value;
- else
- LOG_WARN1("Unknown parameter %s for alsa module", current->name);
-
- current = current->next;
- }
-
- snd_pcm_hw_params_alloca(&hwparams);
-
- if ((err = snd_pcm_open(&s->fd, device, stream, 0)) < 0)
- {
- LOG_ERROR2("Failed to open audio device %s: %s", device, snd_strerror(err));
- goto fail;
- }
-
- if ((err = snd_pcm_hw_params_any(s->fd, hwparams)) < 0)
- {
- LOG_ERROR1("Failed to initialize hwparams: %s", snd_strerror(err));
- goto fail;
- }
- if ((err = snd_pcm_hw_params_set_access(s->fd, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
- {
- LOG_ERROR1("Error setting access: %s", snd_strerror(err));
- goto fail;
- }
- if ((err = snd_pcm_hw_params_set_format(s->fd, hwparams, SND_PCM_FORMAT_S16_LE)) < 0)
- {
- LOG_ERROR1("Couldn't set sample format to SND_PCM_FORMAT_S16_LE: %s", snd_strerror(err));
- goto fail;
- }
- if ((err = snd_pcm_hw_params_set_rate_near(s->fd, hwparams, s->rate, 0)) < 0)
- {
- LOG_ERROR1("Error setting rate: %s", snd_strerror(err));
- goto fail;
- }
- s->rate = snd_pcm_hw_params_get_rate(hwparams, 0);
- if ((err = snd_pcm_hw_params_set_channels(s->fd, hwparams, s->channels)) < 0)
- {
- LOG_ERROR1("Error setting channels: %s", snd_strerror(err));
- goto fail;
- }
- s->channels = snd_pcm_hw_params_get_channels(hwparams);
- if ((err = snd_pcm_hw_params_set_periods(s->fd, hwparams, 2, 0)) < 0)
- {
- LOG_ERROR1("Error setting periods: %s", snd_strerror(err));
- goto fail;
- }
- if ((err = snd_pcm_hw_params_set_buffer_size_near(s->fd, hwparams, (BUFSIZE * 2)>>2)) < 0)
- {
- LOG_ERROR1("Error setting buffersize: %s", snd_strerror(err));
- goto fail;
- }
- if ((err = snd_pcm_hw_params(s->fd, hwparams)) < 0)
- {
- LOG_ERROR1("Error setting HW params: %s", snd_strerror(err));
- goto fail;
- }
-
- /* We're done, and we didn't fail! */
- LOG_INFO3("Opened audio device %s at %d channel(s), %d Hz",
- device, s->channels, s->rate);
+ input_module_t *mod = calloc(1, sizeof(input_module_t));
+ im_alsa_state *s;
+ module_param_t *current;
+ char *device = "plughw:0,0"; /* default device */
+ int format = AFMT_S16_LE;
+ int channels, rate;
+ int use_metadata = 1; /* Default to on */
+
+ snd_pcm_stream_t stream = SND_PCM_STREAM_CAPTURE;
+ snd_pcm_hw_params_t *hwparams;
+
+ int err;
+
+ mod->type = ICES_INPUT_PCM;
+ mod->subtype = INPUT_PCM_LE_16;
+ mod->getdata = alsa_read;
+ mod->handle_event = event_handler;
+ mod->metadata_update = metadata_update;
+
+ mod->internal = calloc(1, sizeof(im_alsa_state));
+ s = mod->internal;
+
+ s->fd = NULL; /* Set it to something invalid, for now */
+ s->rate = 44100; /* Defaults */
+ s->channels = 2;
+
+ thread_mutex_create(&s->metadatalock);
+
+ current = params;
+
+ while(current)
+ {
+ if(!strcmp(current->name, "rate"))
+ s->rate = atoi(current->value);
+ else if(!strcmp(current->name, "channels"))
+ s->channels = atoi(current->value);
+ else if(!strcmp(current->name, "device"))
+ device = current->value;
+ else if(!strcmp(current->name, "metadata"))
+ use_metadata = atoi(current->value);
+ else if(!strcmp(current->name, "metadatafilename"))
+ ices_config->metadata_filename = current->value;
+ else
+ LOG_WARN1("Unknown parameter %s for alsa module", current->name);
+
+ current = current->next;
+ }
+
+ snd_pcm_hw_params_alloca(&hwparams);
+
+ if ((err = snd_pcm_open(&s->fd, device, stream, 0)) < 0)
+ {
+ LOG_ERROR2("Failed to open audio device %s: %s", device, snd_strerror(err));
+ goto fail;
+ }
+
+ if ((err = snd_pcm_hw_params_any(s->fd, hwparams)) < 0)
+ {
+ LOG_ERROR1("Failed to initialize hwparams: %s", snd_strerror(err));
+ goto fail;
+ }
+ if ((err = snd_pcm_hw_params_set_access(s->fd, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
+ {
+ LOG_ERROR1("Error setting access: %s", snd_strerror(err));
+ goto fail;
+ }
+ if ((err = snd_pcm_hw_params_set_format(s->fd, hwparams, SND_PCM_FORMAT_S16_LE)) < 0)
+ {
+ LOG_ERROR1("Couldn't set sample format to SND_PCM_FORMAT_S16_LE: %s", snd_strerror(err));
+ goto fail;
+ }
+ if ((err = snd_pcm_hw_params_set_rate_near(s->fd, hwparams, s->rate, 0)) < 0)
+ {
+ LOG_ERROR1("Error setting rate: %s", snd_strerror(err));
+ goto fail;
+ }
+ s->rate = snd_pcm_hw_params_get_rate(hwparams, 0);
+ if ((err = snd_pcm_hw_params_set_channels(s->fd, hwparams, s->channels)) < 0)
+ {
+ LOG_ERROR1("Error setting channels: %s", snd_strerror(err));
+ goto fail;
+ }
+ s->channels = snd_pcm_hw_params_get_channels(hwparams);
+ if ((err = snd_pcm_hw_params_set_periods(s->fd, hwparams, 2, 0)) < 0)
+ {
+ LOG_ERROR1("Error setting periods: %s", snd_strerror(err));
+ goto fail;
+ }
+ if ((err = snd_pcm_hw_params_set_buffer_size_near(s->fd, hwparams, (BUFSIZE * 2)>>2)) < 0)
+ {
+ LOG_ERROR1("Error setting buffersize: %s", snd_strerror(err));
+ goto fail;
+ }
+ if ((err = snd_pcm_hw_params(s->fd, hwparams)) < 0)
+ {
+ LOG_ERROR1("Error setting HW params: %s", snd_strerror(err));
+ goto fail;
+ }
+
+ /* We're done, and we didn't fail! */
+ LOG_INFO3("Opened audio device %s at %d channel(s), %d Hz",
+ device, s->channels, s->rate);
- if(use_metadata)
- {
+ if(use_metadata)
+ {
if(ices_config->metadata_filename)
thread_create("im_alsa-metadata", metadata_thread_signal, mod, 1);
else
- thread_create("im_alsa-metadata", metadata_thread_stdin, mod, 1);
- LOG_INFO0("Started metadata update thread");
- }
+ thread_create("im_alsa-metadata", metadata_thread_stdin, mod, 1);
+ LOG_INFO0("Started metadata update thread");
+ }
- return mod;
+ return mod;
fail:
- close_module(mod); /* safe, this checks for valid contents */
- return NULL;
+ close_module(mod); /* safe, this checks for valid contents */
+ return NULL;
}
<p><p>1.2 +7 -7 ices/src/im_alsa.h
Index: im_alsa.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_alsa.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- im_alsa.h 29 Dec 2002 10:28:30 -0000 1.1
+++ im_alsa.h 16 Mar 2003 14:21:48 -0000 1.2
@@ -1,7 +1,7 @@
/* im_alsa.h
* - read pcm data from oss devices
*
- * $Id: im_alsa.h,v 1.1 2002/12/29 10:28:30 msmith Exp $
+ * $Id: im_alsa.h,v 1.2 2003/03/16 14:21:48 msmith Exp $
*
* by Jason Chu <jchu at uvic.ca>, based
* on im_oss.c which is...
@@ -23,13 +23,13 @@
typedef struct
{
- int rate;
- int channels;
+ int rate;
+ int channels;
- snd_pcm_t *fd;
- char **metadata;
- int newtrack;
- mutex_t metadatalock;
+ snd_pcm_t *fd;
+ char **metadata;
+ int newtrack;
+ mutex_t metadatalock;
} im_alsa_state;
input_module_t *alsa_open_module(module_param_t *params);
<p><p>1.10 +179 -179 ices/src/im_oss.c
Index: im_oss.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_oss.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- im_oss.c 2 Mar 2003 21:10:13 -0000 1.9
+++ im_oss.c 16 Mar 2003 14:21:48 -0000 1.10
@@ -1,7 +1,7 @@
/* im_oss.c
* - Raw PCM input from OSS devices
*
- * $Id: im_oss.c,v 1.9 2003/03/02 21:10:13 karl Exp $
+ * $Id: im_oss.c,v 1.10 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -45,68 +45,68 @@
static void close_module(input_module_t *mod)
{
- if(mod)
- {
- if(mod->internal)
- {
- im_oss_state *s = mod->internal;
- if(s->fd >= 0)
- close(s->fd);
- thread_mutex_destroy(&s->metadatalock);
- free(s);
- }
- free(mod);
- }
+ if(mod)
+ {
+ if(mod->internal)
+ {
+ im_oss_state *s = mod->internal;
+ if(s->fd >= 0)
+ close(s->fd);
+ thread_mutex_destroy(&s->metadatalock);
+ free(s);
+ }
+ free(mod);
+ }
}
static int event_handler(input_module_t *mod, enum event_type ev, void *param)
{
- im_oss_state *s = mod->internal;
+ im_oss_state *s = mod->internal;
- switch(ev)
- {
- case EVENT_SHUTDOWN:
- close_module(mod);
- break;
- case EVENT_NEXTTRACK:
- s->newtrack = 1;
- break;
- case EVENT_METADATAUPDATE:
- thread_mutex_lock(&s->metadatalock);
- if(s->metadata)
- {
- char **md = s->metadata;
- while(*md)
- free(*md++);
- free(s->metadata);
- }
- s->metadata = (char **)param;
- s->newtrack = 1;
- thread_mutex_unlock(&s->metadatalock);
- break;
- default:
- LOG_WARN1("Unhandled event %d", ev);
- return -1;
- }
+ switch(ev)
+ {
+ case EVENT_SHUTDOWN:
+ close_module(mod);
+ break;
+ case EVENT_NEXTTRACK:
+ s->newtrack = 1;
+ break;
+ case EVENT_METADATAUPDATE:
+ thread_mutex_lock(&s->metadatalock);
+ if(s->metadata)
+ {
+ char **md = s->metadata;
+ while(*md)
+ free(*md++);
+ free(s->metadata);
+ }
+ s->metadata = (char **)param;
+ s->newtrack = 1;
+ thread_mutex_unlock(&s->metadatalock);
+ break;
+ default:
+ LOG_WARN1("Unhandled event %d", ev);
+ return -1;
+ }
- return 0;
+ return 0;
}
static void metadata_update(void *self, vorbis_comment *vc)
{
- im_oss_state *s = self;
- char **md;
+ im_oss_state *s = self;
+ char **md;
- thread_mutex_lock(&s->metadatalock);
+ thread_mutex_lock(&s->metadatalock);
- md = s->metadata;
+ md = s->metadata;
- if(md)
- {
- while(*md)
- vorbis_comment_add(vc, *md++);
- }
+ if(md)
+ {
+ while(*md)
+ vorbis_comment_add(vc, *md++);
+ }
- thread_mutex_unlock(&s->metadatalock);
+ thread_mutex_unlock(&s->metadatalock);
}
/* Core streaming function for this module
@@ -118,152 +118,152 @@
*/
static int oss_read(void *self, ref_buffer *rb)
{
- int result;
- im_oss_state *s = self;
+ int result;
+ im_oss_state *s = self;
- rb->buf = malloc(BUFSIZE*2*s->channels);
+ rb->buf = malloc(BUFSIZE*2*s->channels);
if(!rb->buf)
return -1;
- result = read(s->fd, rb->buf, BUFSIZE*2*s->channels);
+ result = read(s->fd, rb->buf, BUFSIZE*2*s->channels);
- rb->len = result;
- rb->aux_data = s->rate*s->channels*2;
+ rb->len = result;
+ rb->aux_data = s->rate*s->channels*2;
- if(s->newtrack)
- {
- rb->critical = 1;
- s->newtrack = 0;
- }
-
- if(result == -1 && (errno == EINTR || errno == ERESTART))
- {
- return 0; /* Non-fatal error */
- }
- else if(result <= 0)
- {
- if(result == 0)
- LOG_INFO0("Reached EOF, no more data available");
- else
- LOG_ERROR1("Error reading from audio device: %s", strerror(errno));
- free(rb->buf);
- return -1;
- }
+ if(s->newtrack)
+ {
+ rb->critical = 1;
+ s->newtrack = 0;
+ }
+
+ if(result == -1 && (errno == EINTR || errno == ERESTART))
+ {
+ return 0; /* Non-fatal error */
+ }
+ else if(result <= 0)
+ {
+ if(result == 0)
+ LOG_INFO0("Reached EOF, no more data available");
+ else
+ LOG_ERROR1("Error reading from audio device: %s", strerror(errno));
+ free(rb->buf);
+ return -1;
+ }
- return rb->len;
+ return rb->len;
}
input_module_t *oss_open_module(module_param_t *params)
{
- input_module_t *mod = calloc(1, sizeof(input_module_t));
- im_oss_state *s;
- module_param_t *current;
- char *device = "/dev/dsp"; /* default device */
- int format = AFMT_S16_LE;
- int channels, rate;
- int use_metadata = 1; /* Default to on */
-
- mod->type = ICES_INPUT_PCM;
- mod->subtype = INPUT_PCM_LE_16;
- mod->getdata = oss_read;
- mod->handle_event = event_handler;
- mod->metadata_update = metadata_update;
-
- mod->internal = calloc(1, sizeof(im_oss_state));
- s = mod->internal;
-
- s->fd = -1; /* Set it to something invalid, for now */
- s->rate = 44100; /* Defaults */
- s->channels = 2;
-
- thread_mutex_create(&s->metadatalock);
-
- current = params;
-
- while(current)
- {
- if(!strcmp(current->name, "rate"))
- s->rate = atoi(current->value);
- else if(!strcmp(current->name, "channels"))
- s->channels = atoi(current->value);
- else if(!strcmp(current->name, "device"))
- device = current->value;
- else if(!strcmp(current->name, "metadata"))
- use_metadata = atoi(current->value);
- else if(!strcmp(current->name, "metadatafilename"))
- ices_config->metadata_filename = current->value;
- else
- LOG_WARN1("Unknown parameter %s for oss module", current->name);
-
- current = current->next;
- }
-
- /* First up, lets open the audio device */
- if((s->fd = open(device, O_RDONLY, 0)) == -1)
- {
- /* Open failed */
- LOG_ERROR2("Failed to open audio device %s: %s",
- device, strerror(errno));
- goto fail;
- }
-
- /* Now, set the required parameters on that device */
-
- if(ioctl(s->fd, SNDCTL_DSP_SETFMT, &format) == -1)
- {
- LOG_ERROR2("Failed to set sample format on audio device %s: %s",
- device, strerror(errno));
- goto fail;
- }
- if(format != AFMT_S16_LE)
- {
- LOG_ERROR0("Couldn't set sample format to AFMT_S16_LE");
- goto fail;
- }
-
- channels = s->channels;
- if(ioctl(s->fd, SNDCTL_DSP_CHANNELS, &channels) == -1)
- {
- LOG_ERROR2("Failed to set number of channels on audio device %s: %s",
- device, strerror(errno));
- goto fail;
- }
- if(channels != s->channels)
- {
- LOG_ERROR0("Couldn't set number of channels");
- goto fail;
- }
-
- rate = s->rate;
- if(ioctl(s->fd, SNDCTL_DSP_SPEED, &rate) == -1)
- {
- LOG_ERROR2("Failed to set sampling rate on audio device %s: %s",
- device, strerror(errno));
- goto fail;
- }
- if(rate != s->rate)
- {
- LOG_ERROR0("Couldn't set sampling rate");
- goto fail;
- }
-
- /* We're done, and we didn't fail! */
- LOG_INFO3("Opened audio device %s at %d channel(s), %d Hz",
- device, channels, rate);
+ input_module_t *mod = calloc(1, sizeof(input_module_t));
+ im_oss_state *s;
+ module_param_t *current;
+ char *device = "/dev/dsp"; /* default device */
+ int format = AFMT_S16_LE;
+ int channels, rate;
+ int use_metadata = 1; /* Default to on */
+
+ mod->type = ICES_INPUT_PCM;
+ mod->subtype = INPUT_PCM_LE_16;
+ mod->getdata = oss_read;
+ mod->handle_event = event_handler;
+ mod->metadata_update = metadata_update;
+
+ mod->internal = calloc(1, sizeof(im_oss_state));
+ s = mod->internal;
+
+ s->fd = -1; /* Set it to something invalid, for now */
+ s->rate = 44100; /* Defaults */
+ s->channels = 2;
+
+ thread_mutex_create(&s->metadatalock);
+
+ current = params;
+
+ while(current)
+ {
+ if(!strcmp(current->name, "rate"))
+ s->rate = atoi(current->value);
+ else if(!strcmp(current->name, "channels"))
+ s->channels = atoi(current->value);
+ else if(!strcmp(current->name, "device"))
+ device = current->value;
+ else if(!strcmp(current->name, "metadata"))
+ use_metadata = atoi(current->value);
+ else if(!strcmp(current->name, "metadatafilename"))
+ ices_config->metadata_filename = current->value;
+ else
+ LOG_WARN1("Unknown parameter %s for oss module", current->name);
+
+ current = current->next;
+ }
+
+ /* First up, lets open the audio device */
+ if((s->fd = open(device, O_RDONLY, 0)) == -1)
+ {
+ /* Open failed */
+ LOG_ERROR2("Failed to open audio device %s: %s",
+ device, strerror(errno));
+ goto fail;
+ }
+
+ /* Now, set the required parameters on that device */
+
+ if(ioctl(s->fd, SNDCTL_DSP_SETFMT, &format) == -1)
+ {
+ LOG_ERROR2("Failed to set sample format on audio device %s: %s",
+ device, strerror(errno));
+ goto fail;
+ }
+ if(format != AFMT_S16_LE)
+ {
+ LOG_ERROR0("Couldn't set sample format to AFMT_S16_LE");
+ goto fail;
+ }
+
+ channels = s->channels;
+ if(ioctl(s->fd, SNDCTL_DSP_CHANNELS, &channels) == -1)
+ {
+ LOG_ERROR2("Failed to set number of channels on audio device %s: %s",
+ device, strerror(errno));
+ goto fail;
+ }
+ if(channels != s->channels)
+ {
+ LOG_ERROR0("Couldn't set number of channels");
+ goto fail;
+ }
+
+ rate = s->rate;
+ if(ioctl(s->fd, SNDCTL_DSP_SPEED, &rate) == -1)
+ {
+ LOG_ERROR2("Failed to set sampling rate on audio device %s: %s",
+ device, strerror(errno));
+ goto fail;
+ }
+ if(rate != s->rate)
+ {
+ LOG_ERROR0("Couldn't set sampling rate");
+ goto fail;
+ }
+
+ /* We're done, and we didn't fail! */
+ LOG_INFO3("Opened audio device %s at %d channel(s), %d Hz",
+ device, channels, rate);
- if(use_metadata)
- {
+ if(use_metadata)
+ {
if(ices_config->metadata_filename)
thread_create("im_oss-metadata", metadata_thread_signal, mod, 1);
else
- thread_create("im_oss-metadata", metadata_thread_stdin, mod, 1);
- LOG_INFO0("Started metadata update thread");
- }
+ thread_create("im_oss-metadata", metadata_thread_stdin, mod, 1);
+ LOG_INFO0("Started metadata update thread");
+ }
- return mod;
+ return mod;
fail:
- close_module(mod); /* safe, this checks for valid contents */
- return NULL;
+ close_module(mod); /* safe, this checks for valid contents */
+ return NULL;
}
<p><p>1.3 +7 -7 ices/src/im_oss.h
Index: im_oss.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_oss.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- im_oss.h 25 Sep 2001 12:04:21 -0000 1.2
+++ im_oss.h 16 Mar 2003 14:21:48 -0000 1.3
@@ -1,7 +1,7 @@
/* im_oss.h
* - read pcm data from oss devices
*
- * $Id: im_oss.h,v 1.2 2001/09/25 12:04:21 msmith Exp $
+ * $Id: im_oss.h,v 1.3 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -20,13 +20,13 @@
typedef struct
{
- int rate;
- int channels;
+ int rate;
+ int channels;
- int fd;
- char **metadata;
- int newtrack;
- mutex_t metadatalock;
+ int fd;
+ char **metadata;
+ int newtrack;
+ mutex_t metadatalock;
} im_oss_state;
input_module_t *oss_open_module(module_param_t *params);
<p><p>1.8 +181 -181 ices/src/im_playlist.c
Index: im_playlist.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_playlist.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- im_playlist.c 7 Mar 2003 04:20:55 -0000 1.7
+++ im_playlist.c 16 Mar 2003 14:21:48 -0000 1.8
@@ -1,7 +1,7 @@
/* playlist.c
* - Basic playlist functionality
*
- * $Id: im_playlist.c,v 1.7 2003/03/07 04:20:55 karl Exp $
+ * $Id: im_playlist.c,v 1.8 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -36,47 +36,47 @@
typedef struct _module
{
- char *name;
- int (*init)(module_param_t *, playlist_state_t *);
+ char *name;
+ int (*init)(module_param_t *, playlist_state_t *);
} module;
static module modules[] = {
- { "basic", playlist_basic_initialise},
- { "script", playlist_script_initialise},
- {NULL,NULL}
+ { "basic", playlist_basic_initialise},
+ { "script", playlist_script_initialise},
+ {NULL,NULL}
};
static void close_module(input_module_t *mod)
{
- if (mod == NULL) return;
+ if (mod == NULL) return;
- if (mod->internal)
- {
- playlist_state_t *pl = (playlist_state_t *)mod->internal;
- pl->clear(pl->data);
- ogg_sync_clear(&pl->oy);
- free(pl);
- }
- free(mod);
+ if (mod->internal)
+ {
+ playlist_state_t *pl = (playlist_state_t *)mod->internal;
+ pl->clear(pl->data);
+ ogg_sync_clear(&pl->oy);
+ free(pl);
+ }
+ free(mod);
}
static int event_handler(input_module_t *mod, enum event_type ev, void *param)
{
- switch(ev)
- {
- case EVENT_SHUTDOWN:
- close_module(mod);
- break;
- case EVENT_NEXTTRACK:
- LOG_INFO0("Moving to next file in playlist.");
- ((playlist_state_t *)mod->internal)->nexttrack = 1;
- break;
- default:
- LOG_WARN1("Unhandled event %d", ev);
- return -1;
- }
+ switch(ev)
+ {
+ case EVENT_SHUTDOWN:
+ close_module(mod);
+ break;
+ case EVENT_NEXTTRACK:
+ LOG_INFO0("Moving to next file in playlist.");
+ ((playlist_state_t *)mod->internal)->nexttrack = 1;
+ break;
+ default:
+ LOG_WARN1("Unhandled event %d", ev);
+ return -1;
+ }
- return 0;
+ return 0;
}
/* Core streaming function for this module
@@ -88,184 +88,184 @@
*/
static int playlist_read(void *self, ref_buffer *rb)
{
- playlist_state_t *pl = (playlist_state_t *)self;
- int bytes;
- unsigned char *buf;
- char *newfn;
- int result;
- ogg_page og;
-
- if (pl->errors > 5)
- {
- LOG_WARN0("Too many consecutive errors - exiting");
- return -1;
- }
-
- if (!pl->current_file || pl->nexttrack)
- {
- pl->nexttrack = 0;
+ playlist_state_t *pl = (playlist_state_t *)self;
+ int bytes;
+ unsigned char *buf;
+ char *newfn;
+ int result;
+ ogg_page og;
+
+ if (pl->errors > 5)
+ {
+ LOG_WARN0("Too many consecutive errors - exiting");
+ return -1;
+ }
+
+ if (!pl->current_file || pl->nexttrack)
+ {
+ pl->nexttrack = 0;
- if(pl->current_file)
+ if(pl->current_file)
{
- fclose(pl->current_file);
+ fclose(pl->current_file);
pl->current_file = NULL;
}
- newfn = pl->get_filename(pl->data);
+ newfn = pl->get_filename(pl->data);
if(!newfn)
return -1; /* No more files available */
- if(pl->filename && !strcmp(pl->filename, newfn))
- {
- LOG_ERROR0("Cannot play same file twice in a row, skipping");
- pl->errors++;
- return 0;
- }
+ if(pl->filename && !strcmp(pl->filename, newfn))
+ {
+ LOG_ERROR0("Cannot play same file twice in a row, skipping");
+ pl->errors++;
+ return 0;
+ }
pl->free_filename(pl->data, pl->filename);
- pl->filename = newfn;
+ pl->filename = newfn;
+
+ if(!pl->filename)
+ {
+ LOG_INFO0("No more filenames available, end of playlist");
+ return -1;
+ }
+
+ pl->current_file = fopen(pl->filename, "rb");
+
+ LOG_INFO1("Currently playing %s", pl->filename);
- if(!pl->filename)
- {
- LOG_INFO0("No more filenames available, end of playlist");
- return -1;
- }
-
- pl->current_file = fopen(pl->filename, "rb");
-
- LOG_INFO1("Currently playing %s", pl->filename);
-
- if (!pl->current_file)
- {
- LOG_WARN2("Error opening file %s: %s",pl->filename, strerror(errno));
- pl->errors++;
- return 0;
- }
-
- /* Reinit sync, so that dead data from previous file is discarded */
- ogg_sync_clear(&pl->oy);
- ogg_sync_init(&pl->oy);
- }
-
- while(1)
- {
- result = ogg_sync_pageout(&pl->oy, &og);
- if(result < 0)
- LOG_WARN1("Corrupt or missing data in file (%s)", pl->filename);
- else if(result > 0)
- {
+ if (!pl->current_file)
+ {
+ LOG_WARN2("Error opening file %s: %s",pl->filename, strerror(errno));
+ pl->errors++;
+ return 0;
+ }
+
+ /* Reinit sync, so that dead data from previous file is discarded */
+ ogg_sync_clear(&pl->oy);
+ ogg_sync_init(&pl->oy);
+ }
+
+ while(1)
+ {
+ result = ogg_sync_pageout(&pl->oy, &og);
+ if(result < 0)
+ LOG_WARN1("Corrupt or missing data in file (%s)", pl->filename);
+ else if(result > 0)
+ {
if (input_calculate_ogg_sleep (&og) < 0)
{
pl->nexttrack = 1;
return 0;
}
- rb->len = og.header_len + og.body_len;
- rb->buf = malloc(rb->len);
- rb->aux_data = og.header_len;
-
- memcpy(rb->buf, og.header, og.header_len);
- memcpy(rb->buf+og.header_len, og.body, og.body_len);
- if(ogg_page_granulepos(&og)==0)
- rb->critical = 1;
- break;
- }
-
- /* If we got to here, we didn't have enough data. */
- buf = ogg_sync_buffer(&pl->oy, BUFSIZE);
- bytes = fread(buf,1, BUFSIZE, pl->current_file);
- if (bytes <= 0)
- {
- if (feof(pl->current_file))
- {
- pl->nexttrack = 1;
- return playlist_read(pl,rb);
- }
- else
- {
- LOG_ERROR2("Read error from %s: %s",
- pl->filename, strerror(errno));
- fclose(pl->current_file);
- pl->current_file=NULL;
- pl->errors++;
- return 0;
- }
- }
- else
- ogg_sync_wrote(&pl->oy, bytes);
- }
+ rb->len = og.header_len + og.body_len;
+ rb->buf = malloc(rb->len);
+ rb->aux_data = og.header_len;
+
+ memcpy(rb->buf, og.header, og.header_len);
+ memcpy(rb->buf+og.header_len, og.body, og.body_len);
+ if(ogg_page_granulepos(&og)==0)
+ rb->critical = 1;
+ break;
+ }
+
+ /* If we got to here, we didn't have enough data. */
+ buf = ogg_sync_buffer(&pl->oy, BUFSIZE);
+ bytes = fread(buf,1, BUFSIZE, pl->current_file);
+ if (bytes <= 0)
+ {
+ if (feof(pl->current_file))
+ {
+ pl->nexttrack = 1;
+ return playlist_read(pl,rb);
+ }
+ else
+ {
+ LOG_ERROR2("Read error from %s: %s",
+ pl->filename, strerror(errno));
+ fclose(pl->current_file);
+ pl->current_file=NULL;
+ pl->errors++;
+ return 0;
+ }
+ }
+ else
+ ogg_sync_wrote(&pl->oy, bytes);
+ }
- pl->errors=0;
+ pl->errors=0;
input_sleep ();
- return rb->len;
+ return rb->len;
}
input_module_t *playlist_open_module(module_param_t *params)
{
- input_module_t *mod = calloc(1, sizeof(input_module_t));
- playlist_state_t *pl;
- module_param_t *current;
- int (*init)(module_param_t *, playlist_state_t *)=NULL;
-
- mod->type = ICES_INPUT_VORBIS;
- mod->getdata = playlist_read;
- mod->handle_event = event_handler;
- mod->metadata_update = NULL; /* Not used for playlists */
-
- mod->internal = calloc(1, sizeof(playlist_state_t));
- pl = (playlist_state_t *)mod->internal;
-
- current = params;
- while(current)
- {
- if (!strcmp(current->name, "type"))
- {
- int current_module = 0;
-
- while(modules[current_module].init)
- {
- if(!strcmp(current->value, modules[current_module].name))
- {
- init = modules[current_module].init;
- break;
- }
- current_module++;
- }
-
- if(!init)
- {
- LOG_ERROR1("Unknown playlist type \"%s\"", current->value);
- goto fail;
- }
- }
- current = current->next;
- }
-
- if(init)
- {
- if(init(params, pl))
- {
- LOG_ERROR0("Playlist initialisation failed");
- goto fail;
- }
- else
- {
- ogg_sync_init(&pl->oy);
- return mod; /* Success. Finished initialising */
- }
- }
- else
- LOG_ERROR0("No playlist type given, cannot initialise playlist module");
+ input_module_t *mod = calloc(1, sizeof(input_module_t));
+ playlist_state_t *pl;
+ module_param_t *current;
+ int (*init)(module_param_t *, playlist_state_t *)=NULL;
+
+ mod->type = ICES_INPUT_VORBIS;
+ mod->getdata = playlist_read;
+ mod->handle_event = event_handler;
+ mod->metadata_update = NULL; /* Not used for playlists */
+
+ mod->internal = calloc(1, sizeof(playlist_state_t));
+ pl = (playlist_state_t *)mod->internal;
+
+ current = params;
+ while(current)
+ {
+ if (!strcmp(current->name, "type"))
+ {
+ int current_module = 0;
+
+ while(modules[current_module].init)
+ {
+ if(!strcmp(current->value, modules[current_module].name))
+ {
+ init = modules[current_module].init;
+ break;
+ }
+ current_module++;
+ }
+
+ if(!init)
+ {
+ LOG_ERROR1("Unknown playlist type \"%s\"", current->value);
+ goto fail;
+ }
+ }
+ current = current->next;
+ }
+
+ if(init)
+ {
+ if(init(params, pl))
+ {
+ LOG_ERROR0("Playlist initialisation failed");
+ goto fail;
+ }
+ else
+ {
+ ogg_sync_init(&pl->oy);
+ return mod; /* Success. Finished initialising */
+ }
+ }
+ else
+ LOG_ERROR0("No playlist type given, cannot initialise playlist module");
fail:
- if (mod)
- {
- if (mod->internal)
- free(mod->internal);
- free(mod);
- }
+ if (mod)
+ {
+ if (mod->internal)
+ free(mod->internal);
+ free(mod);
+ }
- return NULL;
+ return NULL;
}
<p><p>1.4 +10 -10 ices/src/im_playlist.h
Index: im_playlist.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_playlist.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- im_playlist.h 7 Jul 2002 11:07:55 -0000 1.3
+++ im_playlist.h 16 Mar 2003 14:21:48 -0000 1.4
@@ -1,7 +1,7 @@
/* im_playlist.h
* - Basic playlist functionality
*
- * $Id: im_playlist.h,v 1.3 2002/07/07 11:07:55 msmith Exp $
+ * $Id: im_playlist.h,v 1.4 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -19,18 +19,18 @@
typedef struct _playlist_state_tag
{
- FILE *current_file;
- char *filename; /* Currently streaming file */
- int errors; /* Consecutive errors */
- int nexttrack;
- ogg_sync_state oy;
-
- char *(*get_filename)(void *data); /* returns the next desired filename */
+ FILE *current_file;
+ char *filename; /* Currently streaming file */
+ int errors; /* Consecutive errors */
+ int nexttrack;
+ ogg_sync_state oy;
+
+ char *(*get_filename)(void *data); /* returns the next desired filename */
void (*free_filename)(void *data, char *fn); /* Called when im_playlist is
done with this filename */
- void (*clear)(void *data); /* module clears self here */
+ void (*clear)(void *data); /* module clears self here */
- void *data; /* Internal data for this particular playlist module */
+ void *data; /* Internal data for this particular playlist module */
} playlist_state_t;
<p><p>1.5 +66 -66 ices/src/im_stdinpcm.c
Index: im_stdinpcm.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_stdinpcm.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- im_stdinpcm.c 7 Mar 2003 04:20:55 -0000 1.4
+++ im_stdinpcm.c 16 Mar 2003 14:21:48 -0000 1.5
@@ -1,7 +1,7 @@
/* im_stdinpcm.c
* - Raw PCM input from stdin
*
- * $Id: im_stdinpcm.c,v 1.4 2003/03/07 04:20:55 karl Exp $
+ * $Id: im_stdinpcm.c,v 1.5 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -33,25 +33,25 @@
static int event_handler(input_module_t *mod, enum event_type ev, void *param)
{
- switch(ev)
- {
- case EVENT_SHUTDOWN:
- if(mod)
- {
- if(mod->internal)
- free(mod->internal);
- free(mod);
- }
- break;
- case EVENT_NEXTTRACK:
- ((stdinpcm_state *)mod->internal)->newtrack = 1;
- break;
- default:
- LOG_WARN1("Unhandled event %d", ev);
- return -1;
- }
+ switch(ev)
+ {
+ case EVENT_SHUTDOWN:
+ if(mod)
+ {
+ if(mod->internal)
+ free(mod->internal);
+ free(mod);
+ }
+ break;
+ case EVENT_NEXTTRACK:
+ ((stdinpcm_state *)mod->internal)->newtrack = 1;
+ break;
+ default:
+ LOG_WARN1("Unhandled event %d", ev);
+ return -1;
+ }
- return 0;
+ return 0;
}
/* Core streaming function for this module
@@ -63,67 +63,67 @@
*/
static int stdin_read(void *self, ref_buffer *rb)
{
- int result;
- stdinpcm_state *s = self;
+ int result;
+ stdinpcm_state *s = self;
- rb->buf = malloc(BUFSIZE);
+ rb->buf = malloc(BUFSIZE);
if(!rb->buf)
return -1;
- result = fread(rb->buf, 1,BUFSIZE, stdin);
+ result = fread(rb->buf, 1,BUFSIZE, stdin);
- rb->len = result;
- rb->aux_data = s->rate*s->channels*2;
- if(s->newtrack)
- {
- rb->critical = 1;
- s->newtrack = 0;
- }
-
- if(rb->len <= 0)
- {
- LOG_INFO0("Reached EOF, no more data available\n");
- free(rb->buf);
- return -1;
- }
+ rb->len = result;
+ rb->aux_data = s->rate*s->channels*2;
+ if(s->newtrack)
+ {
+ rb->critical = 1;
+ s->newtrack = 0;
+ }
+
+ if(rb->len <= 0)
+ {
+ LOG_INFO0("Reached EOF, no more data available\n");
+ free(rb->buf);
+ return -1;
+ }
input_calculate_pcm_sleep (rb->len, rb->aux_data);
input_sleep ();
- return rb->len;
+ return rb->len;
}
input_module_t *stdin_open_module(module_param_t *params)
{
- input_module_t *mod = calloc(1, sizeof(input_module_t));
- stdinpcm_state *s;
- module_param_t *current;
-
- mod->type = ICES_INPUT_PCM;
- mod->getdata = stdin_read;
- mod->handle_event = event_handler;
- mod->metadata_update = NULL;
-
- mod->internal = malloc(sizeof(stdinpcm_state));
- s = mod->internal;
-
- s->rate = 44100; /* Defaults */
- s->channels = 2;
-
- current = params;
-
- while(current)
- {
- if(!strcmp(current->name, "rate"))
- s->rate = atoi(current->value);
- else if(!strcmp(current->name, "channels"))
- s->channels = atoi(current->value);
- else
- LOG_WARN1("Unknown parameter %s for stdinpcm module", current->name);
+ input_module_t *mod = calloc(1, sizeof(input_module_t));
+ stdinpcm_state *s;
+ module_param_t *current;
+
+ mod->type = ICES_INPUT_PCM;
+ mod->getdata = stdin_read;
+ mod->handle_event = event_handler;
+ mod->metadata_update = NULL;
+
+ mod->internal = malloc(sizeof(stdinpcm_state));
+ s = mod->internal;
+
+ s->rate = 44100; /* Defaults */
+ s->channels = 2;
+
+ current = params;
+
+ while(current)
+ {
+ if(!strcmp(current->name, "rate"))
+ s->rate = atoi(current->value);
+ else if(!strcmp(current->name, "channels"))
+ s->channels = atoi(current->value);
+ else
+ LOG_WARN1("Unknown parameter %s for stdinpcm module", current->name);
- current = current->next;
- }
+ current = current->next;
+ }
- return mod;
+ return mod;
}
<p><p>1.3 +4 -4 ices/src/im_stdinpcm.h
Index: im_stdinpcm.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_stdinpcm.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- im_stdinpcm.h 25 Sep 2001 12:04:21 -0000 1.2
+++ im_stdinpcm.h 16 Mar 2003 14:21:48 -0000 1.3
@@ -1,7 +1,7 @@
/* im_stdinpcm.h
* - stdin reading
*
- * $Id: im_stdinpcm.h,v 1.2 2001/09/25 12:04:21 msmith Exp $
+ * $Id: im_stdinpcm.h,v 1.3 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -19,9 +19,9 @@
typedef struct
{
- int rate;
- int channels;
- int newtrack;
+ int rate;
+ int channels;
+ int newtrack;
} stdinpcm_state;
input_module_t *stdin_open_module(module_param_t *params);
<p><p>1.8 +166 -166 ices/src/im_sun.c
Index: im_sun.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_sun.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- im_sun.c 3 Aug 2002 15:05:39 -0000 1.7
+++ im_sun.c 16 Mar 2003 14:21:48 -0000 1.8
@@ -1,7 +1,7 @@
/* im_sun.c
* - Raw PCM input from Solaris audio devices
*
- * $Id: im_sun.c,v 1.7 2002/08/03 15:05:39 msmith Exp $
+ * $Id: im_sun.c,v 1.8 2003/03/16 14:21:48 msmith Exp $
*
* by Ciaran Anscomb <ciarana at rd.bbc.co.uk>, based
* on im_oss.c which is...
@@ -41,68 +41,68 @@
static void close_module(input_module_t *mod)
{
- if(mod)
- {
- if(mod->internal)
- {
- im_sun_state *s = mod->internal;
- if(s->fd >= 0)
- close(s->fd);
- thread_mutex_destroy(&s->metadatalock);
- free(s);
- }
- free(mod);
- }
+ if(mod)
+ {
+ if(mod->internal)
+ {
+ im_sun_state *s = mod->internal;
+ if(s->fd >= 0)
+ close(s->fd);
+ thread_mutex_destroy(&s->metadatalock);
+ free(s);
+ }
+ free(mod);
+ }
}
static int event_handler(input_module_t *mod, enum event_type ev, void *param)
{
- im_sun_state *s = mod->internal;
+ im_sun_state *s = mod->internal;
- switch(ev)
- {
- case EVENT_SHUTDOWN:
- close_module(mod);
- break;
- case EVENT_NEXTTRACK:
- s->newtrack = 1;
- break;
- case EVENT_METADATAUPDATE:
- thread_mutex_lock(&s->metadatalock);
- if(s->metadata)
- {
- char **md = s->metadata;
- while(*md)
- free(*md++);
- free(s->metadata);
- }
- s->metadata = (char **)param;
- s->newtrack = 1;
- thread_mutex_unlock(&s->metadatalock);
- break;
- default:
- LOG_WARN1("Unhandled event %d", ev);
- return -1;
- }
+ switch(ev)
+ {
+ case EVENT_SHUTDOWN:
+ close_module(mod);
+ break;
+ case EVENT_NEXTTRACK:
+ s->newtrack = 1;
+ break;
+ case EVENT_METADATAUPDATE:
+ thread_mutex_lock(&s->metadatalock);
+ if(s->metadata)
+ {
+ char **md = s->metadata;
+ while(*md)
+ free(*md++);
+ free(s->metadata);
+ }
+ s->metadata = (char **)param;
+ s->newtrack = 1;
+ thread_mutex_unlock(&s->metadatalock);
+ break;
+ default:
+ LOG_WARN1("Unhandled event %d", ev);
+ return -1;
+ }
- return 0;
+ return 0;
}
static void metadata_update(void *self, vorbis_comment *vc)
{
- im_sun_state *s = self;
- char **md;
+ im_sun_state *s = self;
+ char **md;
- thread_mutex_lock(&s->metadatalock);
+ thread_mutex_lock(&s->metadatalock);
- md = s->metadata;
+ md = s->metadata;
- if(md)
- {
- while(*md)
- vorbis_comment_add(vc, *md++);
- }
+ if(md)
+ {
+ while(*md)
+ vorbis_comment_add(vc, *md++);
+ }
- thread_mutex_unlock(&s->metadatalock);
+ thread_mutex_unlock(&s->metadatalock);
}
/* Core streaming function for this module
@@ -114,138 +114,138 @@
*/
static int sun_read(void *self, ref_buffer *rb)
{
- int result;
- im_sun_state *s = self;
- unsigned char *i, j;
+ int result;
+ im_sun_state *s = self;
+ unsigned char *i, j;
- rb->buf = malloc(BUFSIZE*2*s->device_info.record.channels);
+ rb->buf = malloc(BUFSIZE*2*s->device_info.record.channels);
if(!rb->buf)
return -1;
- result = read(s->fd, rb->buf, BUFSIZE*2*s->device_info.record.channels);
+ result = read(s->fd, rb->buf, BUFSIZE*2*s->device_info.record.channels);
- rb->len = result;
- rb->aux_data = s->device_info.record.sample_rate*s->device_info.record.channels*2;
+ rb->len = result;
+ rb->aux_data = s->device_info.record.sample_rate*s->device_info.record.channels*2;
- if(s->newtrack)
- {
- rb->critical = 1;
- s->newtrack = 0;
- }
-
- if(result == -1 && errno == EINTR)
- {
- return 0; /* Non-fatal error */
- }
- else if(result <= 0)
- {
- if(result == 0)
- LOG_INFO0("Reached EOF, no more data available");
- else
- LOG_ERROR1("Error reading from audio device: %s", strerror(errno));
- free(rb->buf);
- return -1;
- }
+ if(s->newtrack)
+ {
+ rb->critical = 1;
+ s->newtrack = 0;
+ }
+
+ if(result == -1 && errno == EINTR)
+ {
+ return 0; /* Non-fatal error */
+ }
+ else if(result <= 0)
+ {
+ if(result == 0)
+ LOG_INFO0("Reached EOF, no more data available");
+ else
+ LOG_ERROR1("Error reading from audio device: %s", strerror(errno));
+ free(rb->buf);
+ return -1;
+ }
- return rb->len;
+ return rb->len;
}
input_module_t *sun_open_module(module_param_t *params)
{
- input_module_t *mod = calloc(1, sizeof(input_module_t));
- im_sun_state *s;
- module_param_t *current;
- char *device = "/dev/audio"; /* default device */
- int sample_rate = 44100;
- int channels = 2;
- int use_metadata = 1; /* Default to on */
-
- mod->type = ICES_INPUT_PCM;
- mod->subtype = INPUT_PCM_BE_16;
- mod->getdata = sun_read;
- mod->handle_event = event_handler;
- mod->metadata_update = metadata_update;
-
- mod->internal = calloc(1, sizeof(im_sun_state));
- s = mod->internal;
-
- s->fd = -1; /* Set it to something invalid, for now */
-
- thread_mutex_create(&s->metadatalock);
-
- current = params;
-
- while (current) {
- if (!strcmp(current->name, "rate"))
- sample_rate = s->device_info.record.sample_rate = atoi(current->value);
- else if (!strcmp(current->name, "channels"))
- channels = s->device_info.record.channels = atoi(current->value);
- else if (!strcmp(current->name, "device"))
- device = current->value;
- else if (!strcmp(current->name, "metadata"))
- use_metadata = atoi(current->value);
- else if(!strcmp(current->name, "metadatafilename"))
- ices_config->metadata_filename = current->value;
- else
- LOG_WARN1("Unknown parameter %s for sun module", current->name);
- current = current->next;
- }
-
- /* First up, lets open the audio device */
- if((s->fd = open(device, O_RDONLY, 0)) < 0) {
- LOG_ERROR2("Failed to open audio device %s: %s",
- device, strerror(errno));
- goto fail;
- }
-
- /* Try and set up what we want */
- AUDIO_INITINFO(&s->device_info);
- s->device_info.record.sample_rate = sample_rate;
- s->device_info.record.channels = channels;
- s->device_info.record.precision = 16;
- s->device_info.record.encoding = AUDIO_ENCODING_LINEAR;
- s->device_info.record.port = AUDIO_LINE_IN;
- if (ioctl(s->fd, AUDIO_SETINFO, &s->device_info) < 0) {
- LOG_ERROR2("Failed to configure audio device %s: %s",
- device, strerror(errno));
- goto fail;
- }
- ioctl(s->fd, I_FLUSH, FLUSHR);
-
- /* Check all went according to plan */
- if (s->device_info.record.sample_rate != sample_rate) {
- LOG_ERROR0("Couldn't set sampling rate");
- goto fail;
- }
- if (s->device_info.record.channels != channels) {
- LOG_ERROR0("Couldn't set number of channels");
- goto fail;
- }
- if (s->device_info.record.precision != 16) {
- LOG_ERROR0("Couldn't set 16 bit precision");
- goto fail;
- }
- if (s->device_info.record.encoding != AUDIO_ENCODING_LINEAR) {
- LOG_ERROR0("Couldn't set linear encoding");
- goto fail;
- }
-
- /* We're done, and we didn't fail! */
- LOG_INFO3("Opened audio device %s at %d channel(s), %d Hz",
- device, channels, sample_rate);
+ input_module_t *mod = calloc(1, sizeof(input_module_t));
+ im_sun_state *s;
+ module_param_t *current;
+ char *device = "/dev/audio"; /* default device */
+ int sample_rate = 44100;
+ int channels = 2;
+ int use_metadata = 1; /* Default to on */
+
+ mod->type = ICES_INPUT_PCM;
+ mod->subtype = INPUT_PCM_BE_16;
+ mod->getdata = sun_read;
+ mod->handle_event = event_handler;
+ mod->metadata_update = metadata_update;
+
+ mod->internal = calloc(1, sizeof(im_sun_state));
+ s = mod->internal;
+
+ s->fd = -1; /* Set it to something invalid, for now */
+
+ thread_mutex_create(&s->metadatalock);
+
+ current = params;
+
+ while (current) {
+ if (!strcmp(current->name, "rate"))
+ sample_rate = s->device_info.record.sample_rate = atoi(current->value);
+ else if (!strcmp(current->name, "channels"))
+ channels = s->device_info.record.channels = atoi(current->value);
+ else if (!strcmp(current->name, "device"))
+ device = current->value;
+ else if (!strcmp(current->name, "metadata"))
+ use_metadata = atoi(current->value);
+ else if(!strcmp(current->name, "metadatafilename"))
+ ices_config->metadata_filename = current->value;
+ else
+ LOG_WARN1("Unknown parameter %s for sun module", current->name);
+ current = current->next;
+ }
+
+ /* First up, lets open the audio device */
+ if((s->fd = open(device, O_RDONLY, 0)) < 0) {
+ LOG_ERROR2("Failed to open audio device %s: %s",
+ device, strerror(errno));
+ goto fail;
+ }
+
+ /* Try and set up what we want */
+ AUDIO_INITINFO(&s->device_info);
+ s->device_info.record.sample_rate = sample_rate;
+ s->device_info.record.channels = channels;
+ s->device_info.record.precision = 16;
+ s->device_info.record.encoding = AUDIO_ENCODING_LINEAR;
+ s->device_info.record.port = AUDIO_LINE_IN;
+ if (ioctl(s->fd, AUDIO_SETINFO, &s->device_info) < 0) {
+ LOG_ERROR2("Failed to configure audio device %s: %s",
+ device, strerror(errno));
+ goto fail;
+ }
+ ioctl(s->fd, I_FLUSH, FLUSHR);
+
+ /* Check all went according to plan */
+ if (s->device_info.record.sample_rate != sample_rate) {
+ LOG_ERROR0("Couldn't set sampling rate");
+ goto fail;
+ }
+ if (s->device_info.record.channels != channels) {
+ LOG_ERROR0("Couldn't set number of channels");
+ goto fail;
+ }
+ if (s->device_info.record.precision != 16) {
+ LOG_ERROR0("Couldn't set 16 bit precision");
+ goto fail;
+ }
+ if (s->device_info.record.encoding != AUDIO_ENCODING_LINEAR) {
+ LOG_ERROR0("Couldn't set linear encoding");
+ goto fail;
+ }
+
+ /* We're done, and we didn't fail! */
+ LOG_INFO3("Opened audio device %s at %d channel(s), %d Hz",
+ device, channels, sample_rate);
- if(use_metadata)
- {
+ if(use_metadata)
+ {
if(ices_config->metadata_filename)
thread_create("im_sun-metadata", metadata_thread_signal, mod, 1);
else
- thread_create("im_sun-metadata", metadata_thread_stdin, mod, 1);
- LOG_INFO0("Started metadata update thread");
- }
+ thread_create("im_sun-metadata", metadata_thread_stdin, mod, 1);
+ LOG_INFO0("Started metadata update thread");
+ }
- return mod;
+ return mod;
fail:
- close_module(mod); /* safe, this checks for valid contents */
- return NULL;
+ close_module(mod); /* safe, this checks for valid contents */
+ return NULL;
}
<p><p>1.3 +7 -7 ices/src/im_sun.h
Index: im_sun.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_sun.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- im_sun.h 25 Sep 2001 12:04:21 -0000 1.2
+++ im_sun.h 16 Mar 2003 14:21:48 -0000 1.3
@@ -1,7 +1,7 @@
/* im_sun.h
* - read pcm data from sun devices
*
- * $Id: im_sun.h,v 1.2 2001/09/25 12:04:21 msmith Exp $
+ * $Id: im_sun.h,v 1.3 2003/03/16 14:21:48 msmith Exp $
*
* by Ciaran Anscomb <ciarana at rd.bbc.co.uk>, based
* on im_oss.c which is...
@@ -23,12 +23,12 @@
typedef struct
{
- audio_info_t device_info;
- int fd;
- int fdctl;
- char **metadata;
- int newtrack;
- mutex_t metadatalock;
+ audio_info_t device_info;
+ int fd;
+ int fdctl;
+ char **metadata;
+ int newtrack;
+ mutex_t metadatalock;
} im_sun_state;
input_module_t *sun_open_module(module_param_t *params);
<p><p>1.25 +275 -275 ices/src/input.c
Index: input.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/input.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- input.c 13 Mar 2003 18:08:06 -0000 1.24
+++ input.c 16 Mar 2003 14:21:48 -0000 1.25
@@ -2,7 +2,7 @@
* - Main producer control loop. Fetches data from input modules, and controls
* submission of these to the instance threads. Timing control happens here.
*
- * $Id: input.c,v 1.24 2003/03/13 18:08:06 karl Exp $
+ * $Id: input.c,v 1.25 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -56,33 +56,33 @@
typedef struct _timing_control_tag
{
- uint64_t starttime;
- uint64_t senttime;
- uint64_t samples;
- uint64_t oldsamples;
- unsigned samplerate;
- long serialno;
+ uint64_t starttime;
+ uint64_t senttime;
+ uint64_t samples;
+ uint64_t oldsamples;
+ unsigned samplerate;
+ long serialno;
} timing_control;
typedef struct _module
{
- char *name;
- input_module_t *(*open)(module_param_t *params);
+ char *name;
+ input_module_t *(*open)(module_param_t *params);
} module;
static module modules[] = {
- { "playlist", playlist_open_module},
- { "stdinpcm", stdin_open_module},
+ { "playlist", playlist_open_module},
+ { "stdinpcm", stdin_open_module},
#ifdef HAVE_OSS
- { "oss", oss_open_module},
+ { "oss", oss_open_module},
#endif
#ifdef HAVE_SUN_AUDIO
- { "sun", sun_open_module},
+ { "sun", sun_open_module},
#endif
#ifdef HAVE_ALSA
- { "alsa", alsa_open_module},
+ { "alsa", alsa_open_module},
#endif
- {NULL,NULL}
+ {NULL,NULL}
};
static timing_control _control, *control = &_control;
@@ -91,13 +91,13 @@
/* This is identical to shout_sync(), really. */
void input_sleep(void)
{
- int64_t sleep;
+ int64_t sleep;
- /* no need to sleep if we haven't sent data */
- if (control->senttime == 0) return;
+ /* no need to sleep if we haven't sent data */
+ if (control->senttime == 0) return;
- sleep = ((double)control->senttime / 1000) -
- (timing_get_time() - control->starttime);
+ sleep = ((double)control->senttime / 1000) -
+ (timing_get_time() - control->starttime);
/* trap for long sleeps, typically indicating a clock change. it's not */
/* perfect though, as low bitrate/low samplerate vorbis can trigger this */
@@ -112,34 +112,34 @@
int input_calculate_pcm_sleep(unsigned bytes, unsigned bytes_per_sec)
{
- control->senttime += ((uint64_t)bytes * 1000000)/bytes_per_sec;
+ control->senttime += ((uint64_t)bytes * 1000000)/bytes_per_sec;
return 0;
}
int input_calculate_ogg_sleep(ogg_page *page)
{
- /* Largely copied from shout_send(), without the sending happening.*/
- ogg_stream_state os;
- ogg_packet op;
- vorbis_info vi;
- vorbis_comment vc;
+ /* Largely copied from shout_send(), without the sending happening.*/
+ ogg_stream_state os;
+ ogg_packet op;
+ vorbis_info vi;
+ vorbis_comment vc;
int ret = 0;
- if (ogg_page_bos (page))
+ if (ogg_page_bos (page))
{
- control->serialno = ogg_page_serialno(page);
+ control->serialno = ogg_page_serialno(page);
- control->oldsamples = 0;
+ control->oldsamples = 0;
- ogg_stream_init(&os, control->serialno);
- ogg_stream_pagein(&os, page);
- ogg_stream_packetout(&os, &op);
+ ogg_stream_init(&os, control->serialno);
+ ogg_stream_pagein(&os, page);
+ ogg_stream_packetout(&os, &op);
- vorbis_info_init(&vi);
- vorbis_comment_init(&vc);
+ vorbis_info_init(&vi);
+ vorbis_comment_init(&vc);
- if(vorbis_synthesis_headerin(&vi, &vc, &op) < 0)
+ if(vorbis_synthesis_headerin(&vi, &vc, &op) < 0)
{
LOG_ERROR0("Timing control: can't determine sample rate for input, "
"not vorbis.");
@@ -147,12 +147,12 @@
ret = -1;
}
else
- control->samplerate = vi.rate;
+ control->samplerate = vi.rate;
- vorbis_comment_clear(&vc);
- vorbis_info_clear(&vi);
- ogg_stream_clear(&os);
- }
+ vorbis_comment_clear(&vc);
+ vorbis_info_clear(&vi);
+ ogg_stream_clear(&os);
+ }
if(ogg_page_granulepos(page) == -1)
{
@@ -160,223 +160,223 @@
return -1;
}
- control->samples = ogg_page_granulepos(page) - control->oldsamples;
- control->oldsamples = ogg_page_granulepos(page);
+ control->samples = ogg_page_granulepos(page) - control->oldsamples;
+ control->oldsamples = ogg_page_granulepos(page);
if(control->samplerate)
- control->senttime += ((double)control->samples * 1000000 /
- (double)control->samplerate);
+ control->senttime += ((double)control->samples * 1000000 /
+ (double)control->samplerate);
return ret;
}
void input_flush_queue(buffer_queue *queue, int keep_critical)
{
- queue_item *item, *next, *prev=NULL;
+ queue_item *item, *next, *prev=NULL;
+
+ LOG_DEBUG0("Input queue flush requested");
+
+ thread_mutex_lock(&queue->lock);
+ if(!queue->head)
+ {
+ thread_mutex_unlock(&queue->lock);
+ return;
+ }
+
+ item = queue->head;
+ while(item)
+ {
+ next = item->next;
+
+ if(!(keep_critical && item->buf->critical))
+ {
+ thread_mutex_lock(&ices_config->refcount_lock);
+ item->buf->count--;
+ if(!item->buf->count)
+ {
+ free(item->buf->buf);
+ free(item->buf);
+ }
+ thread_mutex_unlock(&ices_config->refcount_lock);
+
+ if(prev)
+ prev->next = next;
+ else
+ queue->head = next;
+
+ free(item);
+ item = next;
+
+ queue->length--;
+ }
+ else
+ {
+ prev = item;
+ item = next;
+ }
+ }
- LOG_DEBUG0("Input queue flush requested");
+ /* Now, fix up the tail pointer */
+ queue->tail = NULL;
+ item = queue->head;
- thread_mutex_lock(&queue->lock);
- if(!queue->head)
- {
- thread_mutex_unlock(&queue->lock);
- return;
- }
-
- item = queue->head;
- while(item)
- {
- next = item->next;
-
- if(!(keep_critical && item->buf->critical))
- {
- thread_mutex_lock(&ices_config->refcount_lock);
- item->buf->count--;
- if(!item->buf->count)
- {
- free(item->buf->buf);
- free(item->buf);
- }
- thread_mutex_unlock(&ices_config->refcount_lock);
-
- if(prev)
- prev->next = next;
- else
- queue->head = next;
-
- free(item);
- item = next;
-
- queue->length--;
- }
- else
- {
- prev = item;
- item = next;
- }
- }
-
- /* Now, fix up the tail pointer */
- queue->tail = NULL;
- item = queue->head;
-
- while(item)
- {
- queue->tail = item;
- item = item->next;
- }
+ while(item)
+ {
+ queue->tail = item;
+ item = item->next;
+ }
- thread_mutex_unlock(&queue->lock);
+ thread_mutex_unlock(&queue->lock);
}
void input_loop(void)
{
- input_module_t *inmod=NULL;
- instance_t *instance, *prev, *next;
- queue_item *queued;
- int shutdown = 0;
- int current_module = 0;
+ input_module_t *inmod=NULL;
+ instance_t *instance, *prev, *next;
+ queue_item *queued;
+ int shutdown = 0;
+ int current_module = 0;
int valid_stream = 1;
int inc_count;
int not_waiting_for_critical;
- thread_cond_create(&ices_config->queue_cond);
- thread_cond_create(&ices_config->event_pending_cond);
- thread_mutex_create(&ices_config->refcount_lock);
- thread_mutex_create(&ices_config->flush_lock);
+ thread_cond_create(&ices_config->queue_cond);
+ thread_cond_create(&ices_config->event_pending_cond);
+ thread_mutex_create(&ices_config->refcount_lock);
+ thread_mutex_create(&ices_config->flush_lock);
memset (control, 0, sizeof (*control));
- while(ices_config->playlist_module && modules[current_module].open)
- {
- if(!strcmp(ices_config->playlist_module, modules[current_module].name))
- {
- inmod = modules[current_module].open(ices_config->module_params);
- break;
- }
- current_module++;
- }
-
- if(!inmod)
- {
- LOG_ERROR1("Couldn't initialise input module \"%s\"\n",
- ices_config->playlist_module);
- return;
- }
-
- ices_config->inmod = inmod;
-
-
- /* ok, basic config stuff done. Now, we want to start all our listening
- * threads.
- */
-
- instance = ices_config->instances;
-
- while(instance)
- {
- stream_description *arg = calloc(1, sizeof(stream_description));
- arg->stream = instance;
- arg->input = inmod;
+ while(ices_config->playlist_module && modules[current_module].open)
+ {
+ if(!strcmp(ices_config->playlist_module, modules[current_module].name))
+ {
+ inmod = modules[current_module].open(ices_config->module_params);
+ break;
+ }
+ current_module++;
+ }
+
+ if(!inmod)
+ {
+ LOG_ERROR1("Couldn't initialise input module \"%s\"\n",
+ ices_config->playlist_module);
+ return;
+ }
+
+ ices_config->inmod = inmod;
+
+
+ /* ok, basic config stuff done. Now, we want to start all our listening
+ * threads.
+ */
+
+ instance = ices_config->instances;
+
+ while(instance)
+ {
+ stream_description *arg = calloc(1, sizeof(stream_description));
+ arg->stream = instance;
+ arg->input = inmod;
/*
- if(instance->savefilename != NULL)
- thread_create("savefile", savefile_stream, arg, 1);
+ if(instance->savefilename != NULL)
+ thread_create("savefile", savefile_stream, arg, 1);
*/
- thread_create("stream", ices_instance_stream, arg, 1);
+ thread_create("stream", ices_instance_stream, arg, 1);
- instance = instance->next;
- }
+ instance = instance->next;
+ }
/* treat as if a signal has arrived straight away */
signal_usr1_handler (0);
- /* now we go into the main loop
- * We shut down the main thread ONLY once all the instances
- * have killed themselves.
- */
- while(!shutdown)
- {
- ref_buffer *chunk = calloc(1, sizeof(ref_buffer));
- buffer_queue *current;
- int ret;
-
- instance = ices_config->instances;
- prev = NULL;
-
- while(instance)
- {
- /* if an instance has died, get rid of it
- ** this should be replaced with something that tries to
- ** restart the instance, probably.
- */
- if (instance->died)
- {
- LOG_DEBUG0("An instance died, removing it");
- next = instance->next;
-
- if (prev)
- prev->next = next;
- else
- ices_config->instances = next;
-
- /* Just in case, flush any existing buffers
- * Locks shouldn't be needed, but lets be SURE */
- thread_mutex_lock(&ices_config->flush_lock);
- input_flush_queue(instance->queue, 0);
- thread_mutex_unlock(&ices_config->flush_lock);
-
- config_free_instance(instance);
- free(instance);
-
- instance = next;
- continue;
- }
-
- prev = instance;
- instance = instance->next;
- }
-
- instance = ices_config->instances;
-
- if(!instance)
- {
- shutdown = 1;
- free(chunk);
- continue;
- }
-
- if(ices_config->shutdown) /* We've been signalled to shut down, but */
- { /* the instances haven't done so yet... */
- timing_sleep(250); /* sleep for quarter of a second */
- free(chunk);
- continue;
- }
+ /* now we go into the main loop
+ * We shut down the main thread ONLY once all the instances
+ * have killed themselves.
+ */
+ while(!shutdown)
+ {
+ ref_buffer *chunk = calloc(1, sizeof(ref_buffer));
+ buffer_queue *current;
+ int ret;
+
+ instance = ices_config->instances;
+ prev = NULL;
+
+ while(instance)
+ {
+ /* if an instance has died, get rid of it
+ ** this should be replaced with something that tries to
+ ** restart the instance, probably.
+ */
+ if (instance->died)
+ {
+ LOG_DEBUG0("An instance died, removing it");
+ next = instance->next;
+
+ if (prev)
+ prev->next = next;
+ else
+ ices_config->instances = next;
+
+ /* Just in case, flush any existing buffers
+ * Locks shouldn't be needed, but lets be SURE */
+ thread_mutex_lock(&ices_config->flush_lock);
+ input_flush_queue(instance->queue, 0);
+ thread_mutex_unlock(&ices_config->flush_lock);
+
+ config_free_instance(instance);
+ free(instance);
+
+ instance = next;
+ continue;
+ }
+
+ prev = instance;
+ instance = instance->next;
+ }
+
+ instance = ices_config->instances;
+
+ if(!instance)
+ {
+ shutdown = 1;
+ free(chunk);
+ continue;
+ }
+
+ if(ices_config->shutdown) /* We've been signalled to shut down, but */
+ { /* the instances haven't done so yet... */
+ timing_sleep(250); /* sleep for quarter of a second */
+ free(chunk);
+ continue;
+ }
/* If this is the first time through, set initial time. This should
* be done before the call to inmod->getdata() below, in order to
* properly keep time if this input module blocks.
*/
- if(control->starttime == 0)
- control->starttime = timing_get_time();
+ if(control->starttime == 0)
+ control->starttime = timing_get_time();
- /* get a chunk of data from the input module */
- ret = inmod->getdata(inmod->internal, chunk);
+ /* get a chunk of data from the input module */
+ ret = inmod->getdata(inmod->internal, chunk);
- /* input module signalled non-fatal error. Skip this chunk */
- if(ret==0)
- {
- free(chunk);
- continue;
- }
-
- /* Input module signalled fatal error, shut down - nothing we can do
- * from here */
- if(ret < 0)
- {
- ices_config->shutdown = 1;
- thread_cond_broadcast(&ices_config->queue_cond);
- free(chunk);
- continue;
- }
+ /* input module signalled non-fatal error. Skip this chunk */
+ if(ret==0)
+ {
+ free(chunk);
+ continue;
+ }
+
+ /* Input module signalled fatal error, shut down - nothing we can do
+ * from here */
+ if(ret < 0)
+ {
+ ices_config->shutdown = 1;
+ thread_cond_broadcast(&ices_config->queue_cond);
+ free(chunk);
+ continue;
+ }
if(chunk->critical)
valid_stream = 1;
@@ -384,7 +384,7 @@
if(ret < 0) {
/* Tell the input module to go to the next track, hopefully allowing
* resync. */
- ices_config->inmod->handle_event(ices_config->inmod,
+ ices_config->inmod->handle_event(ices_config->inmod,
EVENT_NEXTTRACK,NULL);
valid_stream = 0;
}
@@ -394,8 +394,8 @@
if(valid_stream)
{
- while(instance)
- {
+ while(instance)
+ {
if(instance->wait_for_critical && !chunk->critical)
{
instance = instance->next;
@@ -406,85 +406,85 @@
not_waiting_for_critical = 1;
if(instance->skip)
- {
- instance = instance->next;
- continue;
- }
+ {
+ instance = instance->next;
+ continue;
+ }
- queued = malloc(sizeof(queue_item));
+ queued = malloc(sizeof(queue_item));
- queued->buf = chunk;
- current = instance->queue;
+ queued->buf = chunk;
+ current = instance->queue;
inc_count++;
- thread_mutex_lock(¤t->lock);
+ thread_mutex_lock(¤t->lock);
- if(current->head == NULL)
- {
- current->head = current->tail = queued;
- current->head->next = current->tail->next = NULL;
- }
- else
- {
- current->tail->next = queued;
- queued->next = NULL;
- current->tail = queued;
- }
+ if(current->head == NULL)
+ {
+ current->head = current->tail = queued;
+ current->head->next = current->tail->next = NULL;
+ }
+ else
+ {
+ current->tail->next = queued;
+ queued->next = NULL;
+ current->tail = queued;
+ }
- current->length++;
- thread_mutex_unlock(¤t->lock);
+ current->length++;
+ thread_mutex_unlock(¤t->lock);
- instance = instance->next;
- }
+ instance = instance->next;
+ }
}
/* If everything is waiting for a critical buffer, force one
* early. (This will take effect on the next pass through)
*/
if(valid_stream && !not_waiting_for_critical) {
- ices_config->inmod->handle_event(ices_config->inmod,
+ ices_config->inmod->handle_event(ices_config->inmod,
EVENT_NEXTTRACK,NULL);
- instance = ices_config->instances;
+ instance = ices_config->instances;
while(instance) {
- thread_mutex_lock(&ices_config->flush_lock);
- input_flush_queue(instance->queue, 0);
+ thread_mutex_lock(&ices_config->flush_lock);
+ input_flush_queue(instance->queue, 0);
instance->wait_for_critical = 0;
- thread_mutex_unlock(&ices_config->flush_lock);
- instance = instance->next;
+ thread_mutex_unlock(&ices_config->flush_lock);
+ instance = instance->next;
}
}
- /* Make sure we don't end up with a 0-refcount buffer that
- * will never hit any of the free points. (this happens
- * if all threads are set to skip, for example).
- */
- thread_mutex_lock(&ices_config->refcount_lock);
+ /* Make sure we don't end up with a 0-refcount buffer that
+ * will never hit any of the free points. (this happens
+ * if all threads are set to skip, for example).
+ */
+ thread_mutex_lock(&ices_config->refcount_lock);
chunk->count += inc_count;
- if(!chunk->count)
- {
- free(chunk->buf);
- free(chunk);
- }
- thread_mutex_unlock(&ices_config->refcount_lock);
+ if(!chunk->count)
+ {
+ free(chunk->buf);
+ free(chunk);
+ }
+ thread_mutex_unlock(&ices_config->refcount_lock);
if(valid_stream) {
- /* wake up the instances */
- thread_cond_broadcast(&ices_config->queue_cond);
+ /* wake up the instances */
+ thread_cond_broadcast(&ices_config->queue_cond);
}
- }
+ }
- LOG_DEBUG0("All instances removed, shutting down control thread.");
+ LOG_DEBUG0("All instances removed, shutting down control thread.");
- thread_cond_destroy(&ices_config->queue_cond);
- thread_cond_destroy(&ices_config->event_pending_cond);
- thread_mutex_destroy(&ices_config->flush_lock);
- thread_mutex_destroy(&ices_config->refcount_lock);
+ thread_cond_destroy(&ices_config->queue_cond);
+ thread_cond_destroy(&ices_config->event_pending_cond);
+ thread_mutex_destroy(&ices_config->flush_lock);
+ thread_mutex_destroy(&ices_config->refcount_lock);
- inmod->handle_event(inmod, EVENT_SHUTDOWN, NULL);
+ inmod->handle_event(inmod, EVENT_SHUTDOWN, NULL);
- return;
+ return;
}
<p><p>1.8 +3 -3 ices/src/input.h
Index: input.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/input.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- input.h 7 Mar 2003 04:20:55 -0000 1.7
+++ input.h 16 Mar 2003 14:21:48 -0000 1.8
@@ -1,7 +1,7 @@
/* input.h
* - Input functions
*
- * $Id: input.h,v 1.7 2003/03/07 04:20:55 karl Exp $
+ * $Id: input.h,v 1.8 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -25,8 +25,8 @@
#include "audio.h"
typedef struct {
- instance_t *stream;
- input_module_t *input;
+ instance_t *stream;
+ input_module_t *input;
reencode_state *reenc;
encoder_state *enc;
downmix_state *downmix;
<p><p>1.3 +13 -13 ices/src/inputmodule.h
Index: inputmodule.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/inputmodule.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- inputmodule.h 25 Sep 2001 12:04:21 -0000 1.2
+++ inputmodule.h 16 Mar 2003 14:21:48 -0000 1.3
@@ -1,7 +1,7 @@
/* inputmodule.h
* - the interface for input modules to implement.
*
- * $Id: inputmodule.h,v 1.2 2001/09/25 12:04:21 msmith Exp $
+ * $Id: inputmodule.h,v 1.3 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -20,25 +20,25 @@
#include <vorbis/codec.h>
typedef enum _input_type {
- ICES_INPUT_PCM,
- ICES_INPUT_VORBIS,
- /* Can add others here in the future, if we want */
+ ICES_INPUT_PCM,
+ ICES_INPUT_VORBIS,
+ /* Can add others here in the future, if we want */
} input_type;
typedef enum _input_subtype {
- INPUT_PCM_LE_16,
- INPUT_PCM_BE_16,
+ INPUT_PCM_LE_16,
+ INPUT_PCM_BE_16,
} input_subtype;
typedef struct _input_module_tag {
- input_type type;
- input_subtype subtype;
- int (*getdata)(void *self, ref_buffer *rb);
- int (*handle_event)(struct _input_module_tag *self, enum event_type event,
- void *param);
- void (*metadata_update)(void *self, vorbis_comment *vc);
+ input_type type;
+ input_subtype subtype;
+ int (*getdata)(void *self, ref_buffer *rb);
+ int (*handle_event)(struct _input_module_tag *self, enum event_type event,
+ void *param);
+ void (*metadata_update)(void *self, vorbis_comment *vc);
- void *internal; /* For the modules internal state data */
+ void *internal; /* For the modules internal state data */
} input_module_t;
#endif /* __INPUTMODULE_H__ */
<p><p>1.9 +62 -62 ices/src/metadata.c
Index: metadata.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/metadata.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- metadata.c 2 Mar 2003 21:18:28 -0000 1.8
+++ metadata.c 16 Mar 2003 14:21:48 -0000 1.9
@@ -1,7 +1,7 @@
/* metadata.c
* - Metadata manipulation
*
- * $Id: metadata.c,v 1.8 2003/03/02 21:18:28 karl Exp $
+ * $Id: metadata.c,v 1.9 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -29,51 +29,51 @@
void *metadata_thread_stdin(void *arg)
{
- char buf[1024];
- input_module_t *mod = arg;
+ char buf[1024];
+ input_module_t *mod = arg;
- while(1)
- {
- char **md = NULL;
- int comments = 0;
-
- while(fgets(buf, 1024, stdin))
- {
- if(buf[0] == '\n')
- break;
- else
- {
- if(buf[strlen(buf)-1] == '\n')
- buf[strlen(buf)-1] = 0;
- md = realloc(md, (comments+2)*sizeof(char *));
- md[comments] = malloc(strlen(buf)+1);
-
- memcpy(md[comments], buf, strlen(buf)+1);
- comments++;
- }
- }
-
- if(md) /* Don't update if there's nothing there */
- {
- md[comments]=0;
-
- /* Now, let's actually use the new data */
- LOG_INFO0("Updating metadata");
- mod->handle_event(mod,EVENT_METADATAUPDATE,md);
- }
+ while(1)
+ {
+ char **md = NULL;
+ int comments = 0;
+
+ while(fgets(buf, 1024, stdin))
+ {
+ if(buf[0] == '\n')
+ break;
+ else
+ {
+ if(buf[strlen(buf)-1] == '\n')
+ buf[strlen(buf)-1] = 0;
+ md = realloc(md, (comments+2)*sizeof(char *));
+ md[comments] = malloc(strlen(buf)+1);
+
+ memcpy(md[comments], buf, strlen(buf)+1);
+ comments++;
+ }
+ }
+
+ if(md) /* Don't update if there's nothing there */
+ {
+ md[comments]=0;
+
+ /* Now, let's actually use the new data */
+ LOG_INFO0("Updating metadata");
+ mod->handle_event(mod,EVENT_METADATAUPDATE,md);
+ }
- }
+ }
}
void *metadata_thread_signal(void *arg)
{
- char buf[1024];
- input_module_t *mod = arg;
+ char buf[1024];
+ input_module_t *mod = arg;
- while(1)
- {
- char **md = NULL;
- int comments = 0;
+ while(1)
+ {
+ char **md = NULL;
+ int comments = 0;
FILE *file;
while(metadata_update_signalled == 0){
@@ -89,35 +89,35 @@
continue;
}
- while(fgets(buf, 1024, file))
- {
- if(buf[0] == '\n')
- break;
- else
- {
- if(buf[strlen(buf)-1] == '\n')
- buf[strlen(buf)-1] = 0;
- md = realloc(md, (comments+2)*sizeof(char *));
- md[comments] = malloc(strlen(buf)+1);
+ while(fgets(buf, 1024, file))
+ {
+ if(buf[0] == '\n')
+ break;
+ else
+ {
+ if(buf[strlen(buf)-1] == '\n')
+ buf[strlen(buf)-1] = 0;
+ md = realloc(md, (comments+2)*sizeof(char *));
+ md[comments] = malloc(strlen(buf)+1);
- memcpy(md[comments], buf, strlen(buf)+1);
- comments++;
+ memcpy(md[comments], buf, strlen(buf)+1);
+ comments++;
LOG_INFO2 ("tag %d is %s", comments, buf);
- }
- }
+ }
+ }
fclose(file);
- if(md) /* Don't update if there's nothing there */
- {
- md[comments]=0;
-
- /* Now, let's actually use the new data */
- LOG_INFO0("Updating metadata");
- mod->handle_event(mod,EVENT_METADATAUPDATE,md);
- }
+ if(md) /* Don't update if there's nothing there */
+ {
+ md[comments]=0;
+
+ /* Now, let's actually use the new data */
+ LOG_INFO0("Updating metadata");
+ mod->handle_event(mod,EVENT_METADATAUPDATE,md);
+ }
- }
+ }
}
<p><p>1.3 +37 -37 ices/src/output.c
Index: output.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/output.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- output.c 9 Feb 2002 03:55:37 -0000 1.2
+++ output.c 16 Mar 2003 14:21:48 -0000 1.3
@@ -1,7 +1,7 @@
/* output.c
* - Manage output instances
*
- * $Id: output.c,v 1.2 2002/02/09 03:55:37 msmith Exp $
+ * $Id: output.c,v 1.3 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
*
@@ -28,44 +28,44 @@
ref_buffer *instance_wait_for_data(instance_t *stream)
{
- ref_buffer *buffer;
- queue_item *old;
+ ref_buffer *buffer;
+ queue_item *old;
- thread_mutex_lock(&stream->queue->lock);
- while(!stream->queue->head && !ices_config->shutdown && !stream->kill)
- {
- thread_mutex_unlock(&stream->queue->lock);
- thread_cond_wait(&ices_config->queue_cond);
- thread_mutex_lock(&stream->queue->lock);
- }
-
- if(ices_config->shutdown || stream->kill)
- {
- LOG_DEBUG0("Shutdown signalled: thread shutting down");
- thread_mutex_unlock(&stream->queue->lock);
- return NULL;
- }
-
- buffer = stream->queue->head->buf;
- old = stream->queue->head;
-
- stream->queue->head = stream->queue->head->next;
- if(!stream->queue->head)
- stream->queue->tail = NULL;
-
- free(old);
- stream->queue->length--;
- thread_mutex_unlock(&stream->queue->lock);
-
- /* ok, we pulled something off the queue and the queue is
- * now empty - this means we're probably keeping up, so
- * clear one of the errors. This way, very occasional errors
- * don't cause eventual shutdown
- */
- if(!stream->queue->head && stream->buffer_failures>0)
- stream->buffer_failures--;
+ thread_mutex_lock(&stream->queue->lock);
+ while(!stream->queue->head && !ices_config->shutdown && !stream->kill)
+ {
+ thread_mutex_unlock(&stream->queue->lock);
+ thread_cond_wait(&ices_config->queue_cond);
+ thread_mutex_lock(&stream->queue->lock);
+ }
+
+ if(ices_config->shutdown || stream->kill)
+ {
+ LOG_DEBUG0("Shutdown signalled: thread shutting down");
+ thread_mutex_unlock(&stream->queue->lock);
+ return NULL;
+ }
+
+ buffer = stream->queue->head->buf;
+ old = stream->queue->head;
+
+ stream->queue->head = stream->queue->head->next;
+ if(!stream->queue->head)
+ stream->queue->tail = NULL;
+
+ free(old);
+ stream->queue->length--;
+ thread_mutex_unlock(&stream->queue->lock);
+
+ /* ok, we pulled something off the queue and the queue is
+ * now empty - this means we're probably keeping up, so
+ * clear one of the errors. This way, very occasional errors
+ * don't cause eventual shutdown
+ */
+ if(!stream->queue->head && stream->buffer_failures>0)
+ stream->buffer_failures--;
- return buffer;
+ return buffer;
}
/* The main loop for each instance. Gets data passed to it from the stream
<p><p>1.8 +125 -125 ices/src/playlist_basic.c
Index: playlist_basic.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/playlist_basic.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- playlist_basic.c 10 Aug 2002 04:26:52 -0000 1.7
+++ playlist_basic.c 16 Mar 2003 14:21:48 -0000 1.8
@@ -1,7 +1,7 @@
/* playlist_basic.c
* - Simple built-in unscripted playlist
*
- * $Id: playlist_basic.c,v 1.7 2002/08/10 04:26:52 msmith Exp $
+ * $Id: playlist_basic.c,v 1.8 2003/03/16 14:21:48 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -29,59 +29,59 @@
static void shuffle(char **buf, int len)
{
- /* From ices1 src/playlist_basic/rand.c */
- int n,d;
- char *temp;
-
- n = len;
- while(n > 1)
- {
- d = (int)(((double) rand() / RAND_MAX) * n);
- temp = buf[d];
- buf[d] = buf[n-1];
- buf[n-1] = temp;
- --n;
- }
+ /* From ices1 src/playlist_basic/rand.c */
+ int n,d;
+ char *temp;
+
+ n = len;
+ while(n > 1)
+ {
+ d = (int)(((double) rand() / RAND_MAX) * n);
+ temp = buf[d];
+ buf[d] = buf[n-1];
+ buf[n-1] = temp;
+ --n;
+ }
}
static int load_playlist(basic_playlist *data)
{
- FILE *file;
- struct stat st;
- char buf[1024];
- int buflen;
-
- if(stat(data->file, &st))
- {
- LOG_ERROR2("Couldn't stat file \"%s\": %s", data->file, strerror(errno));
- return -1;
- }
- data->mtime = st.st_mtime;
-
- file = fopen(data->file, "rb");
-
- if (file == NULL)
- {
- LOG_ERROR2("Playlist file %s could not be opened: %s",
- data->file, strerror(errno));
- return -1;
- }
+ FILE *file;
+ struct stat st;
+ char buf[1024];
+ int buflen;
+
+ if(stat(data->file, &st))
+ {
+ LOG_ERROR2("Couldn't stat file \"%s\": %s", data->file, strerror(errno));
+ return -1;
+ }
+ data->mtime = st.st_mtime;
+
+ file = fopen(data->file, "rb");
+
+ if (file == NULL)
+ {
+ LOG_ERROR2("Playlist file %s could not be opened: %s",
+ data->file, strerror(errno));
+ return -1;
+ }
- if(data->pl)
+ if(data->pl)
{
int i;
for(i = 0; i < data->len; i++)
free(data->pl[i]);
- free(data->pl);
+ free(data->pl);
}
- data->pl = NULL;
- data->len = 0;
- buflen = 0;
- while (1)
- {
- if(fgets(buf,1024, file) == NULL) break;
- if(buf[0]==0) break;
+ data->pl = NULL;
+ data->len = 0;
+ buflen = 0;
+ while (1)
+ {
+ if(fgets(buf,1024, file) == NULL) break;
+ if(buf[0]==0) break;
if(buf[0]=='\n' || (buf[0]=='\r' && buf[1]=='\n'))
continue;
@@ -89,79 +89,79 @@
if(buf[0] == '#') /* Commented out entry */
continue;
- buf[strlen(buf)-1] = 0;
+ buf[strlen(buf)-1] = 0;
- /* De-fuck windows files. */
- if(strlen(buf) > 0 && buf[strlen(buf)-1] == '\r')
- buf[strlen(buf)-1] = 0;
+ /* De-fuck windows files. */
+ if(strlen(buf) > 0 && buf[strlen(buf)-1] == '\r')
+ buf[strlen(buf)-1] = 0;
- if(buflen < data->len+1)
- {
- buflen += 100;
- data->pl = realloc(data->pl, buflen*sizeof(char *));
- }
+ if(buflen < data->len+1)
+ {
+ buflen += 100;
+ data->pl = realloc(data->pl, buflen*sizeof(char *));
+ }
- data->pl[data->len++] = strdup(buf);
- }
+ data->pl[data->len++] = strdup(buf);
+ }
- if(data->random)
- shuffle(data->pl, data->len);
+ if(data->random)
+ shuffle(data->pl, data->len);
- return 0;
+ return 0;
}
void playlist_basic_clear(void *data)
{
- basic_playlist *pl = data;
- if(pl)
- {
- if(pl->pl)
+ basic_playlist *pl = data;
+ if(pl)
+ {
+ if(pl->pl)
{
int i;
for(i=0; i < pl->len; i++)
free(pl->pl[i]);
- free(pl->pl);
+ free(pl->pl);
}
- free(pl);
- }
+ free(pl);
+ }
}
char *playlist_basic_get_next_filename(void *data)
{
- basic_playlist *pl = (basic_playlist *)data;
- struct stat st;
+ basic_playlist *pl = (basic_playlist *)data;
+ struct stat st;
- if (!pl->pl) return NULL;
+ if (!pl->pl) return NULL;
- if(stat(pl->file, &st))
- {
- LOG_ERROR2("Couldn't stat file \"%s\": %s", pl->file, strerror(errno));
- return NULL;
- }
-
- if(st.st_mtime != pl->mtime)
- {
- LOG_INFO1("Reloading playlist after file \"%s\" changed", pl->file);
- if(load_playlist(pl) < 0)
+ if(stat(pl->file, &st))
+ {
+ LOG_ERROR2("Couldn't stat file \"%s\": %s", pl->file, strerror(errno));
+ return NULL;
+ }
+
+ if(st.st_mtime != pl->mtime)
+ {
+ LOG_INFO1("Reloading playlist after file \"%s\" changed", pl->file);
+ if(load_playlist(pl) < 0)
return NULL;
if(pl->restartafterreread)
pl->pos = 0;
- }
+ }
- if (pl->pos < pl->len)
- {
- return pl->pl[pl->pos++];
- }
- else if(!pl->once)
- {
- if(pl->random)
- shuffle(pl->pl, pl->len);
- pl->pos = 1;
- return pl->pl[0];
- }
- else
- return NULL; /* Once-through mode, at end */
+ if (pl->pos < pl->len)
+ {
+ return pl->pl[pl->pos++];
+ }
+ else if(!pl->once)
+ {
+ if(pl->random)
+ shuffle(pl->pl, pl->len);
+ pl->pos = 1;
+ return pl->pl[0];
+ }
+ else
+ return NULL; /* Once-through mode, at end */
}
void playlist_basic_free_filename(void *data, char *fn)
@@ -170,44 +170,44 @@
int playlist_basic_initialise(module_param_t *params, playlist_state_t *pl)
{
- basic_playlist *data;
+ basic_playlist *data;
- pl->get_filename = playlist_basic_get_next_filename;
- pl->clear = playlist_basic_clear;
+ pl->get_filename = playlist_basic_get_next_filename;
+ pl->clear = playlist_basic_clear;
pl->free_filename = playlist_basic_free_filename;
- pl->data = calloc(1, sizeof(basic_playlist));
- data = (basic_playlist *)pl->data;
+ pl->data = calloc(1, sizeof(basic_playlist));
+ data = (basic_playlist *)pl->data;
- while (params != NULL) {
- if (!strcmp(params->name, "file"))
- {
- if (data->file) free(data->file);
- data->file = params->value;
- }
- else if (!strcmp(params->name, "random"))
- data->random = atoi(params->value);
- else if(!strcmp(params->name, "once"))
- data->once = atoi(params->value);
- else if(!strcmp(params->name, "restart-after-reread"))
- data->restartafterreread = atoi(params->value);
- else if(!strcmp(params->name, "type"))
- ; /* We recognise this, but don't want to do anything with it */
- else
- {
- LOG_WARN1("Unknown parameter to playlist input module: %s",
- params->name);
- }
- params = params->next;
- }
-
- if (!data->file)
- {
- LOG_ERROR0("No filename specified for playlist module");
- free(data);
- return -1;
- }
+ while (params != NULL) {
+ if (!strcmp(params->name, "file"))
+ {
+ if (data->file) free(data->file);
+ data->file = params->value;
+ }
+ else if (!strcmp(params->name, "random"))
+ data->random = atoi(params->value);
+ else if(!strcmp(params->name, "once"))
+ data->once = atoi(params->value);
+ else if(!strcmp(params->name, "restart-after-reread"))
+ data->restartafterreread = atoi(params->value);
+ else if(!strcmp(params->name, "type"))
+ ; /* We recognise this, but don't want to do anything with it */
+ else
+ {
+ LOG_WARN1("Unknown parameter to playlist input module: %s",
+ params->name);
+ }
+ params = params->next;
+ }
+
+ if (!data->file)
+ {
+ LOG_ERROR0("No filename specified for playlist module");
+ free(data);
+ return -1;
+ }
- return load_playlist(data);
+ return load_playlist(data);
}
<p><p>1.5 +8 -8 ices/src/playlist_basic.h
Index: playlist_basic.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/playlist_basic.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- playlist_basic.h 29 Jun 2002 15:19:18 -0000 1.4
+++ playlist_basic.h 16 Mar 2003 14:21:49 -0000 1.5
@@ -1,7 +1,7 @@
/* playlist_basic.h
* - Simple unscripted playlist
*
- * $Id: playlist_basic.h,v 1.4 2002/06/29 15:19:18 msmith Exp $
+ * $Id: playlist_basic.h,v 1.5 2003/03/16 14:21:49 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -16,13 +16,13 @@
typedef struct
{
- char **pl;
- int len;
- int pos;
- char *file; /* Playlist file */
- time_t mtime;
- int random;
- int once;
+ char **pl;
+ int len;
+ int pos;
+ char *file; /* Playlist file */
+ time_t mtime;
+ int random;
+ int once;
int restartafterreread;
} basic_playlist;
<p><p>1.4 +12 -12 ices/src/process.c
Index: process.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/process.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- process.c 9 Feb 2002 05:07:01 -0000 1.3
+++ process.c 16 Mar 2003 14:21:49 -0000 1.4
@@ -2,7 +2,7 @@
* - Processing chains - data sources, sinks, processing effects, reencoding,
* etc.
*
- * $Id: process.c,v 1.3 2002/02/09 05:07:01 msmith Exp $
+ * $Id: process.c,v 1.4 2003/03/16 14:21:49 msmith Exp $
*
* Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
*
@@ -48,7 +48,7 @@
#ifdef DEBUG_BUFFERS
if(!buf) {
LOG_ERROR0("Null buffer aquired?");
- thread_mutex_unlock(&ices_config->refcount_lock);
+ thread_mutex_unlock(&ices_config->refcount_lock);
return;
}
if(buf->count < 0)
@@ -57,31 +57,31 @@
buf->count++;
- thread_mutex_unlock(&ices_config->refcount_lock);
+ thread_mutex_unlock(&ices_config->refcount_lock);
}
void release_buffer(ref_buffer *buf)
{
- thread_mutex_lock(&ices_config->refcount_lock);
+ thread_mutex_lock(&ices_config->refcount_lock);
#ifdef DEBUG_BUFFERS
if(!buf) {
LOG_ERROR0("Null buffer released?");
- thread_mutex_unlock(&ices_config->refcount_lock);
+ thread_mutex_unlock(&ices_config->refcount_lock);
return;
}
if(buf->count <= 0)
LOG_ERROR1("Error: refbuf has count %d before decrement.", buf->count);
#endif
- buf->count--;
+ buf->count--;
- if(!buf->count)
- {
- free(buf->buf);
- free(buf);
- }
- thread_mutex_unlock(&ices_config->refcount_lock);
+ if(!buf->count)
+ {
+ free(buf->buf);
+ free(buf);
+ }
+ thread_mutex_unlock(&ices_config->refcount_lock);
}
/* return values:
<p><p>1.3 +11 -11 ices/src/process.h
Index: process.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/process.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- process.h 9 Feb 2002 03:55:37 -0000 1.2
+++ process.h 16 Mar 2003 14:21:49 -0000 1.3
@@ -1,7 +1,7 @@
/* process.h
* - Processing chains
*
- * $Id: process.h,v 1.2 2002/02/09 03:55:37 msmith Exp $
+ * $Id: process.h,v 1.3 2003/03/16 14:21:49 msmith Exp $
*
* Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
*
@@ -41,14 +41,14 @@
short channels;
int rate;
- void *buf; /* Actual data */
- int len; /* Length of data (usually bytes, sometimes samples */
+ void *buf; /* Actual data */
+ int len; /* Length of data (usually bytes, sometimes samples */
- short count; /* Reference count */
+ short count; /* Reference count */
- buffer_flags flags; /* Flag: critical chunks must be processed fully */
+ buffer_flags flags; /* Flag: critical chunks must be processed fully */
int aux_data_len;
- long aux_data[1]; /* Auxilliary data used for various purposes */
+ long aux_data[1]; /* Auxilliary data used for various purposes */
} ref_buffer;
/* Need some forward declarations */
@@ -81,13 +81,13 @@
typedef struct _instance_t
{
- int buffer_failures;
- int died;
- int kill;
- int skip;
+ int buffer_failures;
+ int died;
+ int kill;
+ int skip;
int wait_for_critical;
- struct buffer_queue *queue;
+ struct buffer_queue *queue;
int max_queue_length;
process_chain_element *output_chain;
<p><p>1.7 +141 -141 ices/src/reencode.c
Index: reencode.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/reencode.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- reencode.c 3 Aug 2002 14:41:10 -0000 1.6
+++ reencode.c 16 Mar 2003 14:21:49 -0000 1.7
@@ -1,7 +1,7 @@
/* reencode.c
* - runtime reencoding of vorbis audio (usually to lower bitrates).
*
- * $Id: reencode.c,v 1.6 2002/08/03 14:41:10 msmith Exp $
+ * $Id: reencode.c,v 1.7 2003/03/16 14:21:49 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -29,129 +29,129 @@
reencode_state *reencode_init(instance_t *stream)
{
- reencode_state *new = calloc(1, sizeof(reencode_state));
+ reencode_state *new = calloc(1, sizeof(reencode_state));
- new->out_min_br = stream->min_br;
- new->out_nom_br = stream->nom_br;
- new->out_max_br = stream->max_br;
- new->quality = stream->quality;
- new->managed = stream->managed;
-
- new->out_samplerate = stream->samplerate;
- new->out_channels = stream->channels;
- new->current_serial = -1; /* FIXME: that's a valid serial */
- new->need_headers = 0;
+ new->out_min_br = stream->min_br;
+ new->out_nom_br = stream->nom_br;
+ new->out_max_br = stream->max_br;
+ new->quality = stream->quality;
+ new->managed = stream->managed;
+
+ new->out_samplerate = stream->samplerate;
+ new->out_channels = stream->channels;
+ new->current_serial = -1; /* FIXME: that's a valid serial */
+ new->need_headers = 0;
- return new;
+ return new;
}
void reencode_clear(reencode_state *s)
{
- if(s)
- {
+ if(s)
+ {
LOG_DEBUG0("Clearing reencoder");
- ogg_stream_clear(&s->os);
- vorbis_block_clear(&s->vb);
- vorbis_dsp_clear(&s->vd);
- vorbis_comment_clear(&s->vc);
- vorbis_info_clear(&s->vi);
+ ogg_stream_clear(&s->os);
+ vorbis_block_clear(&s->vb);
+ vorbis_dsp_clear(&s->vd);
+ vorbis_comment_clear(&s->vc);
+ vorbis_info_clear(&s->vi);
- free(s);
- }
+ free(s);
+ }
}
/* Returns: -1 fatal death failure, argh!
- * 0 haven't produced any output yet
- * >0 success
+ * 0 haven't produced any output yet
+ * >0 success
*/
int reencode_page(reencode_state *s, ref_buffer *buf,
- unsigned char **outbuf, int *outlen)
+ unsigned char **outbuf, int *outlen)
{
- ogg_page og, encog;
- ogg_packet op;
- int retbuflen=0, old;
- unsigned char *retbuf=NULL;
-
-
- og.header_len = buf->aux_data;
- og.body_len = buf->len - buf->aux_data;
- og.header = buf->buf;
- og.body = buf->buf + og.header_len;
-
- if(s->current_serial != ogg_page_serialno(&og))
- {
- s->current_serial = ogg_page_serialno(&og);
+ ogg_page og, encog;
+ ogg_packet op;
+ int retbuflen=0, old;
+ unsigned char *retbuf=NULL;
+
+
+ og.header_len = buf->aux_data;
+ og.body_len = buf->len - buf->aux_data;
+ og.header = buf->buf;
+ og.body = buf->buf + og.header_len;
+
+ if(s->current_serial != ogg_page_serialno(&og))
+ {
+ s->current_serial = ogg_page_serialno(&og);
- if(s->encoder)
- {
+ if(s->encoder)
+ {
if(s->resamp) {
resample_finish(s->resamp);
encode_data_float(s->encoder, s->resamp->buffers,
s->resamp->buffill);
}
- encode_finish(s->encoder);
- while(encode_flush(s->encoder, &encog) != 0)
- {
- old = retbuflen;
- retbuflen += encog.header_len + encog.body_len;
- retbuf = realloc(retbuf, retbuflen);
- memcpy(retbuf+old, encog.header, encog.header_len);
- memcpy(retbuf+old+encog.header_len, encog.body,
- encog.body_len);
- }
- }
- encode_clear(s->encoder);
+ encode_finish(s->encoder);
+ while(encode_flush(s->encoder, &encog) != 0)
+ {
+ old = retbuflen;
+ retbuflen += encog.header_len + encog.body_len;
+ retbuf = realloc(retbuf, retbuflen);
+ memcpy(retbuf+old, encog.header, encog.header_len);
+ memcpy(retbuf+old+encog.header_len, encog.body,
+ encog.body_len);
+ }
+ }
+ encode_clear(s->encoder);
s->encoder = NULL;
resample_clear(s->resamp);
s->resamp = NULL;
downmix_clear(s->downmix);
s->downmix = NULL;
- ogg_stream_clear(&s->os);
- ogg_stream_init(&s->os, s->current_serial);
- ogg_stream_pagein(&s->os, &og);
-
- vorbis_block_clear(&s->vb);
- vorbis_dsp_clear(&s->vd);
- vorbis_comment_clear(&s->vc);
- vorbis_info_clear(&s->vi);
-
- vorbis_info_init(&s->vi);
- vorbis_comment_init(&s->vc);
-
- if(ogg_stream_packetout(&s->os, &op) != 1)
- {
- LOG_ERROR0("Invalid primary header in stream");
- return -1;
- }
-
- if(vorbis_synthesis_headerin(&s->vi, &s->vc, &op) < 0)
- {
- LOG_ERROR0("Input stream not vorbis, can't reencode");
- return -1;
- }
-
- s->need_headers = 2; /* We still need two more header packets */
- LOG_DEBUG0("Reinitialising reencoder for new logical stream");
- }
- else
- {
- ogg_stream_pagein(&s->os, &og);
- while(ogg_stream_packetout(&s->os, &op) > 0)
- {
- if(s->need_headers)
- {
- vorbis_synthesis_headerin(&s->vi, &s->vc, &op);
- /* If this was the last header, init the rest */
- if(!--s->need_headers)
- {
- vorbis_block_init(&s->vd, &s->vb);
- vorbis_synthesis_init(&s->vd, &s->vi);
-
- s->encoder = encode_initialise(s->out_channels,
- s->out_samplerate, s->managed,
+ ogg_stream_clear(&s->os);
+ ogg_stream_init(&s->os, s->current_serial);
+ ogg_stream_pagein(&s->os, &og);
+
+ vorbis_block_clear(&s->vb);
+ vorbis_dsp_clear(&s->vd);
+ vorbis_comment_clear(&s->vc);
+ vorbis_info_clear(&s->vi);
+
+ vorbis_info_init(&s->vi);
+ vorbis_comment_init(&s->vc);
+
+ if(ogg_stream_packetout(&s->os, &op) != 1)
+ {
+ LOG_ERROR0("Invalid primary header in stream");
+ return -1;
+ }
+
+ if(vorbis_synthesis_headerin(&s->vi, &s->vc, &op) < 0)
+ {
+ LOG_ERROR0("Input stream not vorbis, can't reencode");
+ return -1;
+ }
+
+ s->need_headers = 2; /* We still need two more header packets */
+ LOG_DEBUG0("Reinitialising reencoder for new logical stream");
+ }
+ else
+ {
+ ogg_stream_pagein(&s->os, &og);
+ while(ogg_stream_packetout(&s->os, &op) > 0)
+ {
+ if(s->need_headers)
+ {
+ vorbis_synthesis_headerin(&s->vi, &s->vc, &op);
+ /* If this was the last header, init the rest */
+ if(!--s->need_headers)
+ {
+ vorbis_block_init(&s->vd, &s->vb);
+ vorbis_synthesis_init(&s->vd, &s->vi);
+
+ 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->current_serial, &s->vc);
if(!s->encoder) {
LOG_ERROR0("Failed to configure encoder for reencoding");
@@ -176,21 +176,21 @@
}
else
s->downmix = NULL;
- }
- }
- else
- {
- float **pcm;
- int samples;
+ }
+ }
+ else
+ {
+ float **pcm;
+ int samples;
- if(vorbis_synthesis(&s->vb, &op)==0)
- {
- vorbis_synthesis_blockin(&s->vd, &s->vb);
- }
+ if(vorbis_synthesis(&s->vb, &op)==0)
+ {
+ vorbis_synthesis_blockin(&s->vd, &s->vb);
+ }
- while((samples = vorbis_synthesis_pcmout(&s->vd, &pcm))>0)
- {
+ while((samples = vorbis_synthesis_pcmout(&s->vd, &pcm))>0)
+ {
if(s->downmix) {
downmix_buffer_float(s->downmix, pcm, samples);
if(s->resamp) {
@@ -209,38 +209,38 @@
s->resamp->buffill);
}
else
- encode_data_float(s->encoder, pcm, samples);
- vorbis_synthesis_read(&s->vd, samples);
- }
-
- while(encode_dataout(s->encoder, &encog) != 0)
- {
-
- old = retbuflen;
- retbuflen += encog.header_len + encog.body_len;
- retbuf = realloc(retbuf, retbuflen);
- memcpy(retbuf+old, encog.header, encog.header_len);
- memcpy(retbuf+old+encog.header_len, encog.body,
- encog.body_len);
- }
- }
- }
- }
-
- /* We've completed every packet from this page, so
- * now we can return what we wanted, depending on whether
- * we actually got data out or not
- */
- if(retbuflen > 0)
- {
- *outbuf = retbuf;
- *outlen = retbuflen;
- return retbuflen;
- }
- else
- {
- return 0;
- }
+ encode_data_float(s->encoder, pcm, samples);
+ vorbis_synthesis_read(&s->vd, samples);
+ }
+
+ while(encode_dataout(s->encoder, &encog) != 0)
+ {
+
+ old = retbuflen;
+ retbuflen += encog.header_len + encog.body_len;
+ retbuf = realloc(retbuf, retbuflen);
+ memcpy(retbuf+old, encog.header, encog.header_len);
+ memcpy(retbuf+old+encog.header_len, encog.body,
+ encog.body_len);
+ }
+ }
+ }
+ }
+
+ /* We've completed every packet from this page, so
+ * now we can return what we wanted, depending on whether
+ * we actually got data out or not
+ */
+ if(retbuflen > 0)
+ {
+ *outbuf = retbuf;
+ *outlen = retbuflen;
+ return retbuflen;
+ }
+ else
+ {
+ return 0;
+ }
}
<p><p>1.5 +17 -17 ices/src/reencode.h
Index: reencode.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/reencode.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- reencode.h 3 Aug 2002 14:41:10 -0000 1.4
+++ reencode.h 16 Mar 2003 14:21:49 -0000 1.5
@@ -1,7 +1,7 @@
/* reencode.h
* - reencoding functions
*
- * $Id: reencode.h,v 1.4 2002/08/03 14:41:10 msmith Exp $
+ * $Id: reencode.h,v 1.5 2003/03/16 14:21:49 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -23,28 +23,28 @@
#include "audio.h"
typedef struct {
- int out_min_br;
- int out_nom_br;
- int out_max_br;
+ int out_min_br;
+ int out_nom_br;
+ int out_max_br;
float quality;
int managed;
- int out_samplerate;
- int out_channels;
+ int out_samplerate;
+ int out_channels;
- int in_samplerate;
- int in_channels;
+ int in_samplerate;
+ int in_channels;
- long current_serial;
- int need_headers;
+ long current_serial;
+ int need_headers;
- ogg_stream_state os;
- vorbis_info vi;
- vorbis_comment vc;
- vorbis_dsp_state vd;
- vorbis_block vb;
+ ogg_stream_state os;
+ vorbis_info vi;
+ vorbis_comment vc;
+ vorbis_dsp_state vd;
+ vorbis_block vb;
- encoder_state *encoder;
+ encoder_state *encoder;
downmix_state *downmix;
resample_state *resamp;
@@ -52,7 +52,7 @@
reencode_state *reencode_init(instance_t *stream);
int reencode_page(reencode_state *s, ref_buffer *buf,
- unsigned char **outbuf, int *outlen);
+ unsigned char **outbuf, int *outlen);
void reencode_clear(reencode_state *s);
<p><p>1.3 +330 -330 ices/src/resample.c
Index: resample.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/resample.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- resample.c 15 Mar 2003 02:24:18 -0000 1.2
+++ resample.c 16 Mar 2003 14:21:49 -0000 1.3
@@ -15,427 +15,427 @@
static int hcf(int arg1, int arg2)
{
- int mult = 1;
+ int mult = 1;
- while (~(arg1 | arg2) & 1)
- arg1 >>= 1, arg2 >>= 1, mult <<= 1;
+ while (~(arg1 | arg2) & 1)
+ arg1 >>= 1, arg2 >>= 1, mult <<= 1;
- while (arg1 > 0)
- {
- if (~(arg1 & arg2) & 1)
- {
- arg1 >>= (~arg1 & 1);
- arg2 >>= (~arg2 & 1);
- }
- else if (arg1 < arg2)
- arg2 = (arg2 - arg1) >> 1;
- else
- arg1 = (arg1 - arg2) >> 1;
- }
+ while (arg1 > 0)
+ {
+ if (~(arg1 & arg2) & 1)
+ {
+ arg1 >>= (~arg1 & 1);
+ arg2 >>= (~arg2 & 1);
+ }
+ else if (arg1 < arg2)
+ arg2 = (arg2 - arg1) >> 1;
+ else
+ arg1 = (arg1 - arg2) >> 1;
+ }
- return arg2 * mult;
+ return arg2 * mult;
}
static void filt_sinc(float *dest, int N, int step, double fc, double gain, int width)
{
- double s = fc / step;
- int mid, x;
- float *endpoint = dest + N,
- *base = dest,
- *origdest = dest;
-
- assert(width <= N);
-
- if ((N & 1) == 0)
- {
- *dest = 0.0;
- dest += width;
- if (dest >= endpoint)
- dest = ++base;
- N--;
- }
-
- mid = N / 2;
- x = -mid;
-
- while (N--)
- {
- *dest = (x ? sin(x * M_PI * s) / (x * M_PI) * step : fc) * gain;
- x++;
- dest += width;
- if (dest >= endpoint)
- dest = ++base;
- }
- assert(dest == origdest + width);
+ double s = fc / step;
+ int mid, x;
+ float *endpoint = dest + N,
+ *base = dest,
+ *origdest = dest;
+
+ assert(width <= N);
+
+ if ((N & 1) == 0)
+ {
+ *dest = 0.0;
+ dest += width;
+ if (dest >= endpoint)
+ dest = ++base;
+ N--;
+ }
+
+ mid = N / 2;
+ x = -mid;
+
+ while (N--)
+ {
+ *dest = (x ? sin(x * M_PI * s) / (x * M_PI) * step : fc) * gain;
+ x++;
+ dest += width;
+ if (dest >= endpoint)
+ dest = ++base;
+ }
+ assert(dest == origdest + width);
}
static double I_zero(double x)
{
- int n = 0;
- double u = 1.0,
- s = 1.0,
- t;
-
- do
- {
- n += 2;
- t = x / n;
- u *= t * t;
- s += u;
- } while (u > 1e-21 * s);
+ int n = 0;
+ double u = 1.0,
+ s = 1.0,
+ t;
+
+ do
+ {
+ n += 2;
+ t = x / n;
+ u *= t * t;
+ s += u;
+ } while (u > 1e-21 * s);
- return s;
+ return s;
}
static void win_kaiser(float *dest, int N, double alpha, int width)
{
- double I_alpha, midsq;
- int x;
- float *endpoint = dest + N,
- *base = dest,
- *origdest = dest;
-
- assert(width <= N);
-
- if ((N & 1) == 0)
- {
- *dest = 0.0;
- dest += width;
- if (dest >= endpoint)
- dest = ++base;
- N--;
- }
-
- x = -(N / 2);
- midsq = (double)(x - 1) * (double)(x - 1);
- I_alpha = I_zero(alpha);
-
- while (N--)
- {
- *dest *= I_zero(alpha * sqrt(1.0 - ((double)x * (double)x) / midsq)) / I_alpha;
- x++;
- dest += width;
- if (dest >= endpoint)
- dest = ++base;
- }
- assert(dest == origdest + width);
+ double I_alpha, midsq;
+ int x;
+ float *endpoint = dest + N,
+ *base = dest,
+ *origdest = dest;
+
+ assert(width <= N);
+
+ if ((N & 1) == 0)
+ {
+ *dest = 0.0;
+ dest += width;
+ if (dest >= endpoint)
+ dest = ++base;
+ N--;
+ }
+
+ x = -(N / 2);
+ midsq = (double)(x - 1) * (double)(x - 1);
+ I_alpha = I_zero(alpha);
+
+ while (N--)
+ {
+ *dest *= I_zero(alpha * sqrt(1.0 - ((double)x * (double)x) / midsq)) / I_alpha;
+ x++;
+ dest += width;
+ if (dest >= endpoint)
+ dest = ++base;
+ }
+ assert(dest == origdest + width);
}
int resampler_init(resampler_state *state, int channels, int outfreq, int infreq, resampler_parameter op1, ...)
{
- double beta = 16.0,
- cutoff = 0.80,
- gain = 1.0;
- int taps = 45;
-
- int factor;
-
- assert(state);
- assert(channels > 0);
- assert(outfreq > 0);
- assert(infreq > 0);
- assert(taps > 0);
-
- if (state == NULL || channels <= 0 || outfreq <= 0 || infreq <= 0 || taps <= 0)
- return -1;
-
- if (op1 != RES_END)
- {
- va_list argp;
- va_start(argp, op1);
- do
- {
- switch (op1)
- {
- case RES_GAIN:
- gain = va_arg(argp, double);
- break;
-
- case RES_CUTOFF:
- cutoff = va_arg(argp, double);
- assert(cutoff > 0.01 && cutoff <= 1.0);
- break;
-
- case RES_TAPS:
- taps = va_arg(argp, int);
- assert(taps > 2 && taps < 1000);
- break;
-
- case RES_BETA:
- beta = va_arg(argp, double);
- assert(beta > 2.0);
- break;
- default:
- assert("arglist" == "valid");
- return -1;
- }
- op1 = va_arg(argp, resampler_parameter);
- } while (op1 != RES_END);
- va_end(argp);
- }
-
- factor = hcf(infreq, outfreq);
- outfreq /= factor;
- infreq /= factor;
-
- /* adjust to rational values for downsampling */
- if (outfreq < infreq)
- {
- /* push the cutoff frequency down to the output frequency */
- cutoff = cutoff * outfreq / infreq;
+ double beta = 16.0,
+ cutoff = 0.80,
+ gain = 1.0;
+ int taps = 45;
+
+ int factor;
+
+ assert(state);
+ assert(channels > 0);
+ assert(outfreq > 0);
+ assert(infreq > 0);
+ assert(taps > 0);
+
+ if (state == NULL || channels <= 0 || outfreq <= 0 || infreq <= 0 || taps <= 0)
+ return -1;
+
+ if (op1 != RES_END)
+ {
+ va_list argp;
+ va_start(argp, op1);
+ do
+ {
+ switch (op1)
+ {
+ case RES_GAIN:
+ gain = va_arg(argp, double);
+ break;
+
+ case RES_CUTOFF:
+ cutoff = va_arg(argp, double);
+ assert(cutoff > 0.01 && cutoff <= 1.0);
+ break;
+
+ case RES_TAPS:
+ taps = va_arg(argp, int);
+ assert(taps > 2 && taps < 1000);
+ break;
+
+ case RES_BETA:
+ beta = va_arg(argp, double);
+ assert(beta > 2.0);
+ break;
+ default:
+ assert("arglist" == "valid");
+ return -1;
+ }
+ op1 = va_arg(argp, resampler_parameter);
+ } while (op1 != RES_END);
+ va_end(argp);
+ }
+
+ factor = hcf(infreq, outfreq);
+ outfreq /= factor;
+ infreq /= factor;
+
+ /* adjust to rational values for downsampling */
+ if (outfreq < infreq)
+ {
+ /* push the cutoff frequency down to the output frequency */
+ cutoff = cutoff * outfreq / infreq;
/* compensate for the sharper roll-off requirement
* by using a bigger hammer */
taps = taps * infreq/outfreq;
- }
+ }
- assert(taps >= (infreq + outfreq - 1) / outfreq);
+ assert(taps >= (infreq + outfreq - 1) / outfreq);
- if ((state->table = calloc(outfreq * taps, sizeof(float))) == NULL)
- return -1;
- if ((state->pool = calloc(channels * taps, sizeof(SAMPLE))) == NULL)
- {
- free(state->table);
- state->table = NULL;
- return -1;
- }
-
- state->poolfill = taps / 2 + 1;
- state->channels = channels;
- state->outfreq = outfreq;
- state->infreq = infreq;
- state->taps = taps;
- state->offset = 0;
+ if ((state->table = calloc(outfreq * taps, sizeof(float))) == NULL)
+ return -1;
+ if ((state->pool = calloc(channels * taps, sizeof(SAMPLE))) == NULL)
+ {
+ free(state->table);
+ state->table = NULL;
+ return -1;
+ }
+
+ state->poolfill = taps / 2 + 1;
+ state->channels = channels;
+ state->outfreq = outfreq;
+ state->infreq = infreq;
+ state->taps = taps;
+ state->offset = 0;
- filt_sinc(state->table, outfreq * taps, outfreq, cutoff, gain, taps);
- win_kaiser(state->table, outfreq * taps, beta, taps);
+ filt_sinc(state->table, outfreq * taps, outfreq, cutoff, gain, taps);
+ win_kaiser(state->table, outfreq * taps, beta, taps);
- return 0;
+ return 0;
}
static SAMPLE sum(float const *scale, int count, SAMPLE const *source, SAMPLE const *trigger, SAMPLE const *reset, int srcstep)
{
- float total = 0.0;
+ float total = 0.0;
- while (count--)
- {
- total += *source * *scale;
-
- if (source == trigger)
- source = reset, srcstep = 1;
- source -= srcstep;
- scale++;
- }
+ while (count--)
+ {
+ total += *source * *scale;
+
+ if (source == trigger)
+ source = reset, srcstep = 1;
+ source -= srcstep;
+ scale++;
+ }
- return total;
+ return total;
}
static int push(resampler_state const * const state, SAMPLE *pool, int * const poolfill, int * const offset, SAMPLE *dest, int dststep, SAMPLE const *source, int srcstep, size_t srclen)
{
- SAMPLE * const destbase = dest,
- *poolhead = pool + *poolfill,
- *poolend = pool + state->taps,
- *newpool = pool;
- SAMPLE const *refill, *base, *endpoint;
- int lencheck;
-
-
- assert(state);
- assert(pool);
- assert(poolfill);
- assert(dest);
- assert(source);
-
- assert(state->poolfill != -1);
-
- lencheck = resampler_push_check(state, srclen);
-
- /* fill the pool before diving in */
- while (poolhead < poolend && srclen > 0)
- {
- *poolhead++ = *source;
- source += srcstep;
- srclen--;
- }
-
- if (srclen <= 0)
- return 0;
-
- base = source;
- endpoint = source + srclen * srcstep;
-
- while (source < endpoint)
- {
- *dest = sum(state->table + *offset * state->taps, state->taps, source, base, poolend, srcstep);
- dest += dststep;
- *offset += state->infreq;
- while (*offset >= state->outfreq)
- {
- *offset -= state->outfreq;
- source += srcstep;
- }
- }
-
- assert(dest == destbase + lencheck * dststep);
-
- /* pretend that source has that underrun data we're not going to get */
- srclen += (source - endpoint) / srcstep;
-
- /* if we didn't get enough to completely replace the pool, then shift things about a bit */
- if (srclen < state->taps)
- {
- refill = pool + srclen;
- while (refill < poolend)
- *newpool++ = *refill++;
-
- refill = source - srclen * srcstep;
- }
- else
- refill = source - state->taps * srcstep;
-
- /* pull in fresh pool data */
- while (refill < endpoint)
- {
- *newpool++ = *refill;
- refill += srcstep;
- }
+ SAMPLE * const destbase = dest,
+ *poolhead = pool + *poolfill,
+ *poolend = pool + state->taps,
+ *newpool = pool;
+ SAMPLE const *refill, *base, *endpoint;
+ int lencheck;
+
+
+ assert(state);
+ assert(pool);
+ assert(poolfill);
+ assert(dest);
+ assert(source);
+
+ assert(state->poolfill != -1);
+
+ lencheck = resampler_push_check(state, srclen);
+
+ /* fill the pool before diving in */
+ while (poolhead < poolend && srclen > 0)
+ {
+ *poolhead++ = *source;
+ source += srcstep;
+ srclen--;
+ }
+
+ if (srclen <= 0)
+ return 0;
+
+ base = source;
+ endpoint = source + srclen * srcstep;
+
+ while (source < endpoint)
+ {
+ *dest = sum(state->table + *offset * state->taps, state->taps, source, base, poolend, srcstep);
+ dest += dststep;
+ *offset += state->infreq;
+ while (*offset >= state->outfreq)
+ {
+ *offset -= state->outfreq;
+ source += srcstep;
+ }
+ }
+
+ assert(dest == destbase + lencheck * dststep);
+
+ /* pretend that source has that underrun data we're not going to get */
+ srclen += (source - endpoint) / srcstep;
+
+ /* if we didn't get enough to completely replace the pool, then shift things about a bit */
+ if (srclen < state->taps)
+ {
+ refill = pool + srclen;
+ while (refill < poolend)
+ *newpool++ = *refill++;
+
+ refill = source - srclen * srcstep;
+ }
+ else
+ refill = source - state->taps * srcstep;
+
+ /* pull in fresh pool data */
+ while (refill < endpoint)
+ {
+ *newpool++ = *refill;
+ refill += srcstep;
+ }
- assert(newpool > pool);
- assert(newpool <= poolend);
+ assert(newpool > pool);
+ assert(newpool <= poolend);
- *poolfill = newpool - pool;
+ *poolfill = newpool - pool;
- return (dest - destbase) / dststep;
+ return (dest - destbase) / dststep;
}
int resampler_push_max_input(resampler_state const * const state, size_t maxoutput)
{
- return maxoutput * state->infreq / state->outfreq;
+ return maxoutput * state->infreq / state->outfreq;
}
int resampler_push_check(resampler_state const * const state, size_t srclen)
{
- if (state->poolfill < state->taps)
- srclen -= state->taps - state->poolfill;
+ if (state->poolfill < state->taps)
+ srclen -= state->taps - state->poolfill;
- return (srclen * state->outfreq - state->offset + state->infreq - 1) / state->infreq;
+ return (srclen * state->outfreq - state->offset + state->infreq - 1) / state->infreq;
}
int resampler_push(resampler_state *state, SAMPLE **dstlist, SAMPLE const **srclist, size_t srclen)
{
- int result = -1, poolfill = -1, offset = -1, i;
+ int result = -1, poolfill = -1, offset = -1, i;
- assert(state);
- assert(dstlist);
- assert(srclist);
- assert(state->poolfill >= 0);
-
- for (i = 0; i < state->channels; i++)
- {
- poolfill = state->poolfill;
- offset = state->offset;
- result = push(state, state->pool + i * state->taps, &poolfill, &offset, dstlist[i], 1, srclist[i], 1, srclen);
- }
- state->poolfill = poolfill;
- state->offset = offset;
+ assert(state);
+ assert(dstlist);
+ assert(srclist);
+ assert(state->poolfill >= 0);
+
+ for (i = 0; i < state->channels; i++)
+ {
+ poolfill = state->poolfill;
+ offset = state->offset;
+ result = push(state, state->pool + i * state->taps, &poolfill, &offset, dstlist[i], 1, srclist[i], 1, srclen);
+ }
+ state->poolfill = poolfill;
+ state->offset = offset;
- return result;
+ return result;
}
int resampler_push_interleaved(resampler_state *state, SAMPLE *dest, SAMPLE const *source, size_t srclen)
{
- int result = -1, poolfill = -1, offset = -1, i;
-
- assert(state);
- assert(dest);
- assert(source);
- assert(state->poolfill >= 0);
-
- for (i = 0; i < state->channels; i++)
- {
- poolfill = state->poolfill;
- offset = state->offset;
- result = push(state, state->pool + i * state->taps, &poolfill, &offset, dest + i, state->channels, source + i, state->channels, srclen);
- }
- state->poolfill = poolfill;
- state->offset = offset;
+ int result = -1, poolfill = -1, offset = -1, i;
+
+ assert(state);
+ assert(dest);
+ assert(source);
+ assert(state->poolfill >= 0);
+
+ for (i = 0; i < state->channels; i++)
+ {
+ poolfill = state->poolfill;
+ offset = state->offset;
+ result = push(state, state->pool + i * state->taps, &poolfill, &offset, dest + i, state->channels, source + i, state->channels, srclen);
+ }
+ state->poolfill = poolfill;
+ state->offset = offset;
- return result;
+ return result;
}
int resampler_drain(resampler_state *state, SAMPLE **dstlist)
{
- SAMPLE *tail;
- int result = -1, poolfill = -1, offset = -1, i;
+ SAMPLE *tail;
+ int result = -1, poolfill = -1, offset = -1, i;
- assert(state);
- assert(dstlist);
- assert(state->poolfill >= 0);
-
- if ((tail = calloc(state->taps, sizeof(SAMPLE))) == NULL)
- return -1;
-
- for (i = 0; i < state->channels; i++)
- {
- poolfill = state->poolfill;
- offset = state->offset;
- result = push(state, state->pool + i * state->taps, &poolfill, &offset, dstlist[i], 1, tail, 1, state->taps / 2 - 1);
- }
-
- free(tail);
+ assert(state);
+ assert(dstlist);
+ assert(state->poolfill >= 0);
+
+ if ((tail = calloc(state->taps, sizeof(SAMPLE))) == NULL)
+ return -1;
+
+ for (i = 0; i < state->channels; i++)
+ {
+ poolfill = state->poolfill;
+ offset = state->offset;
+ result = push(state, state->pool + i * state->taps, &poolfill, &offset, dstlist[i], 1, tail, 1, state->taps / 2 - 1);
+ }
+
+ free(tail);
- state->poolfill = -1;
+ state->poolfill = -1;
- return result;
+ return result;
}
int resampler_drain_interleaved(resampler_state *state, SAMPLE *dest)
{
- SAMPLE *tail;
- int result = -1, poolfill = -1, offset = -1, i;
+ SAMPLE *tail;
+ int result = -1, poolfill = -1, offset = -1, i;
- assert(state);
- assert(dest);
- assert(state->poolfill >= 0);
-
- if ((tail = calloc(state->taps, sizeof(SAMPLE))) == NULL)
- return -1;
-
- for (i = 0; i < state->channels; i++)
- {
- poolfill = state->poolfill;
- offset = state->offset;
- result = push(state, state->pool + i * state->taps, &poolfill, &offset, dest + i, state->channels, tail, 1, state->taps / 2 - 1);
- }
-
- free(tail);
+ assert(state);
+ assert(dest);
+ assert(state->poolfill >= 0);
+
+ if ((tail = calloc(state->taps, sizeof(SAMPLE))) == NULL)
+ return -1;
+
+ for (i = 0; i < state->channels; i++)
+ {
+ poolfill = state->poolfill;
+ offset = state->offset;
+ result = push(state, state->pool + i * state->taps, &poolfill, &offset, dest + i, state->channels, tail, 1, state->taps / 2 - 1);
+ }
+
+ free(tail);
- state->poolfill = -1;
+ state->poolfill = -1;
- return result;
+ return result;
}
void resampler_clear(resampler_state *state)
{
- assert(state);
- assert(state->table);
- assert(state->pool);
-
- free(state->table);
- free(state->pool);
- memset(state, 0, sizeof(*state));
+ assert(state);
+ assert(state->table);
+ assert(state->pool);
+
+ free(state->table);
+ free(state->pool);
+ memset(state, 0, sizeof(*state));
}
<p><p>1.3 +14 -14 ices/src/resample.h
Index: resample.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/resample.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- resample.h 15 Mar 2003 02:24:18 -0000 1.2
+++ resample.h 16 Mar 2003 14:21:49 -0000 1.3
@@ -7,14 +7,14 @@
* A resampler
*
* reference:
- * 'Digital Filters', third edition, by R. W. Hamming ISBN 0-486-65088-X
+ * 'Digital Filters', third edition, by R. W. Hamming ISBN 0-486-65088-X
*
* history:
- * 2002-05-31 ready for the world (or some small section thereof)
+ * 2002-05-31 ready for the world (or some small section thereof)
*
*
* TOOD:
- * zero-crossing clipping in coefficient table
+ * zero-crossing clipping in coefficient table
*/
#ifndef _RESAMPLE_H_INCLUDED
@@ -24,22 +24,22 @@
typedef struct
{
- unsigned int channels, infreq, outfreq, taps;
- float *table;
- SAMPLE *pool;
+ unsigned int channels, infreq, outfreq, taps;
+ float *table;
+ SAMPLE *pool;
- /* dynamic bits */
- int poolfill;
- int offset;
+ /* dynamic bits */
+ int poolfill;
+ int offset;
} resampler_state;
typedef enum
{
- RES_END,
- RES_GAIN, /* (double)1.0 */
- RES_CUTOFF, /* (double)0.80 */
- RES_TAPS, /* (int)45 */
- RES_BETA /* (double)16.0 */
+ RES_END,
+ RES_GAIN, /* (double)1.0 */
+ RES_CUTOFF, /* (double)0.80 */
+ RES_TAPS, /* (int)45 */
+ RES_BETA /* (double)16.0 */
} resampler_parameter;
int resampler_init(resampler_state *state, int channels, int outfreq, int infreq, resampler_parameter op1, ...);
<p><p>1.4 +51 -51 ices/src/savefile.c
Index: savefile.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/savefile.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- savefile.c 25 Sep 2001 12:04:22 -0000 1.3
+++ savefile.c 16 Mar 2003 14:21:49 -0000 1.4
@@ -1,7 +1,7 @@
/* savefile.c
* - Stream saving to file.
*
- * $Id: savefile.c,v 1.3 2001/09/25 12:04:22 msmith Exp $
+ * $Id: savefile.c,v 1.4 2003/03/16 14:21:49 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -31,59 +31,59 @@
void *savefile_stream(void *arg)
{
- stream_description *sdsc = arg;
- instance_t *stream = sdsc->stream;
- ref_buffer *buf;
- FILE *file;
- int ret;
- char *filename = stream->savefilename;
-
- /* FIXME: Check for file existence, and append some unique string
- * if it already exists.
- */
- file = fopen(filename, "wb");
-
- if(!file)
- {
- LOG_ERROR1("Couldn't open file to save stream: %s", filename);
- stream->died = 1;
- return NULL;
- }
-
- LOG_INFO1("Saving stream to file: %s", filename);
-
- while(1)
- {
- buf = stream_wait_for_data(stream);
-
- if(!buf)
- break;
-
- if(!buf->buf || !buf->len)
- {
- LOG_WARN0("Bad buffer dequeue, not saving");
- continue;
- }
-
- ret = fwrite(buf->buf, 1, buf->len, file);
-
- if(ret != buf->len)
- {
- LOG_ERROR1("Error writing to file: %s", strerror(errno));
- /* FIXME: Try writing to a new file, or something */
- break;
- }
+ stream_description *sdsc = arg;
+ instance_t *stream = sdsc->stream;
+ ref_buffer *buf;
+ FILE *file;
+ int ret;
+ char *filename = stream->savefilename;
+
+ /* FIXME: Check for file existence, and append some unique string
+ * if it already exists.
+ */
+ file = fopen(filename, "wb");
+
+ if(!file)
+ {
+ LOG_ERROR1("Couldn't open file to save stream: %s", filename);
+ stream->died = 1;
+ return NULL;
+ }
+
+ LOG_INFO1("Saving stream to file: %s", filename);
+
+ while(1)
+ {
+ buf = stream_wait_for_data(stream);
+
+ if(!buf)
+ break;
+
+ if(!buf->buf || !buf->len)
+ {
+ LOG_WARN0("Bad buffer dequeue, not saving");
+ continue;
+ }
+
+ ret = fwrite(buf->buf, 1, buf->len, file);
+
+ if(ret != buf->len)
+ {
+ LOG_ERROR1("Error writing to file: %s", strerror(errno));
+ /* FIXME: Try writing to a new file, or something */
+ break;
+ }
- stream_release_buffer(buf);
- }
+ stream_release_buffer(buf);
+ }
- fclose(file);
+ fclose(file);
- stream->died = 1;
- return NULL;
+ stream->died = 1;
+ return NULL;
}
-
-
-
+
+
+
<p><p>1.5 +22 -22 ices/src/signals.c
Index: signals.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/signals.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- signals.c 25 Sep 2001 12:04:22 -0000 1.4
+++ signals.c 16 Mar 2003 14:21:49 -0000 1.5
@@ -1,7 +1,7 @@
/* signals.c
* - signal handling/setup
*
- * $Id: signals.c,v 1.4 2001/09/25 12:04:22 msmith Exp $
+ * $Id: signals.c,v 1.5 2003/03/16 14:21:49 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -30,45 +30,45 @@
void signal_usr1_handler(int signum)
{
- LOG_INFO0("Metadata update requested");
+ LOG_INFO0("Metadata update requested");
metadata_update_signalled = 1;
thread_cond_broadcast(&ices_config->event_pending_cond);
- signal(SIGUSR1, signal_usr1_handler);
+ signal(SIGUSR1, signal_usr1_handler);
}
void signal_hup_handler(int signum)
{
- LOG_INFO0("Flushing logs");
- log_flush(ices_config->log_id);
+ LOG_INFO0("Flushing logs");
+ log_flush(ices_config->log_id);
- /* Now, let's tell it to move to the next track */
- ices_config->inmod->handle_event(ices_config->inmod,EVENT_NEXTTRACK,NULL);
+ /* Now, let's tell it to move to the next track */
+ ices_config->inmod->handle_event(ices_config->inmod,EVENT_NEXTTRACK,NULL);
- signal(SIGHUP, signal_hup_handler);
+ signal(SIGHUP, signal_hup_handler);
}
void signal_int_handler(int signum)
{
- /* Is a mutex needed here? Probably */
- if (!ices_config->shutdown)
- {
- LOG_INFO0("Shutdown requested...");
- ices_config->shutdown = 1;
- thread_cond_broadcast(&ices_config->queue_cond);
-
- /* If user gives a second sigint, just die. */
- signal(SIGINT, SIG_DFL);
- }
+ /* Is a mutex needed here? Probably */
+ if (!ices_config->shutdown)
+ {
+ LOG_INFO0("Shutdown requested...");
+ ices_config->shutdown = 1;
+ thread_cond_broadcast(&ices_config->queue_cond);
+
+ /* If user gives a second sigint, just die. */
+ signal(SIGINT, SIG_DFL);
+ }
}
void signals_setup(void)
{
- signal(SIGHUP, signal_hup_handler);
- signal(SIGINT, signal_int_handler);
- signal(SIGUSR1, signal_usr1_handler);
- signal(SIGPIPE, SIG_IGN);
+ signal(SIGHUP, signal_hup_handler);
+ signal(SIGINT, signal_int_handler);
+ signal(SIGUSR1, signal_usr1_handler);
+ signal(SIGPIPE, SIG_IGN);
}
<p><p>1.25 +165 -165 ices/src/stream.c
Index: stream.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- stream.c 2 Mar 2003 18:36:02 -0000 1.24
+++ stream.c 16 Mar 2003 14:21:49 -0000 1.25
@@ -1,7 +1,7 @@
/* stream.c
* - Core streaming functions/main loop.
*
- * $Id: stream.c,v 1.24 2003/03/02 18:36:02 karl Exp $
+ * $Id: stream.c,v 1.25 2003/03/16 14:21:49 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -46,64 +46,64 @@
*/
void *ices_instance_stream(void *arg)
{
- int ret, shouterr;
- ref_buffer *buffer;
- 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 ret, shouterr;
+ ref_buffer *buffer;
+ 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;
char *stream_name = NULL, *stream_genre = NULL, *stream_description = NULL;
char *user = NULL;
char audio_info[11];
-
- vorbis_comment_init(&sdsc->vc);
+
+ vorbis_comment_init(&sdsc->vc);
- sdsc->shout = shout_new();
+ sdsc->shout = shout_new();
- /* we only support the ice protocol and vorbis streams currently */
- shout_set_format(sdsc->shout, SHOUT_FORMAT_VORBIS);
- //shout_set_protocol(sdsc->shout, SHOUT_PROTOCOL_ICE);
- shout_set_protocol(sdsc->shout, SHOUT_PROTOCOL_HTTP);
+ /* we only support the ice protocol and vorbis streams currently */
+ shout_set_format(sdsc->shout, SHOUT_FORMAT_VORBIS);
+ //shout_set_protocol(sdsc->shout, SHOUT_PROTOCOL_ICE);
+ shout_set_protocol(sdsc->shout, SHOUT_PROTOCOL_HTTP);
signal(SIGPIPE, signal_hup_handler);
- if (!(shout_set_host(sdsc->shout, stream->hostname)) == SHOUTERR_SUCCESS) {
- LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
- stream->died = 1;
- return NULL;
- }
-
- shout_set_port(sdsc->shout, stream->port);
- if (!(shout_set_password(sdsc->shout, stream->password)) == SHOUTERR_SUCCESS) {
- LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
- stream->died = 1;
- return NULL;
- }
+ if (!(shout_set_host(sdsc->shout, stream->hostname)) == SHOUTERR_SUCCESS) {
+ LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
+ stream->died = 1;
+ return NULL;
+ }
+
+ shout_set_port(sdsc->shout, stream->port);
+ if (!(shout_set_password(sdsc->shout, stream->password)) == SHOUTERR_SUCCESS) {
+ LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
+ stream->died = 1;
+ return NULL;
+ }
if (stream->user)
user = stream->user;
else
user = "source";
if(shout_set_user(sdsc->shout, user) != SHOUTERR_SUCCESS) {
- LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
- stream->died = 1;
- return NULL;
- }
-
- if (!(shout_set_agent(sdsc->shout, VERSIONSTRING)) == SHOUTERR_SUCCESS) {
- LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
- stream->died = 1;
- return NULL;
- }
-
- if (!(shout_set_mount(sdsc->shout, stream->mount)) == SHOUTERR_SUCCESS) {
- LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
- stream->died = 1;
- return NULL;
- }
+ LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
+ stream->died = 1;
+ return NULL;
+ }
+
+ if (!(shout_set_agent(sdsc->shout, VERSIONSTRING)) == SHOUTERR_SUCCESS) {
+ LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
+ stream->died = 1;
+ return NULL;
+ }
+
+ if (!(shout_set_mount(sdsc->shout, stream->mount)) == SHOUTERR_SUCCESS) {
+ LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
+ stream->died = 1;
+ return NULL;
+ }
- /* set the metadata for the stream */
+ /* set the metadata for the stream */
if(stream->stream_name)
stream_name = stream->stream_name;
else if (ices_config->stream_name)
@@ -120,23 +120,23 @@
stream_genre = ices_config->stream_genre;
if(stream_name)
- if (!(shout_set_name(sdsc->shout, stream_name)) == SHOUTERR_SUCCESS) {
- LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
- stream->died = 1;
- return NULL;
- }
- if (stream_genre)
- if (!(shout_set_genre(sdsc->shout, stream_genre)) == SHOUTERR_SUCCESS) {
- LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
- stream->died = 1;
- return NULL;
- }
- if (stream_description)
- if (!(shout_set_description(sdsc->shout, stream_description)) == SHOUTERR_SUCCESS) {
- LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
- stream->died = 1;
- return NULL;
- }
+ if (!(shout_set_name(sdsc->shout, stream_name)) == SHOUTERR_SUCCESS) {
+ LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
+ stream->died = 1;
+ return NULL;
+ }
+ if (stream_genre)
+ if (!(shout_set_genre(sdsc->shout, stream_genre)) == SHOUTERR_SUCCESS) {
+ LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
+ stream->died = 1;
+ return NULL;
+ }
+ if (stream_description)
+ if (!(shout_set_description(sdsc->shout, stream_description)) == SHOUTERR_SUCCESS) {
+ LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout));
+ stream->died = 1;
+ return NULL;
+ }
if(stream->downmix && encoding && stream->channels == 1) {
stream->channels = 1;
@@ -165,21 +165,21 @@
shout_set_audio_info(sdsc->shout, SHOUT_AI_QUALITY, audio_info);
}
- if(encoding)
- {
- if(inmod->metadata_update)
- 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,
+ if(encoding)
+ {
+ if(inmod->metadata_update)
+ 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);
if(!sdsc->enc) {
LOG_ERROR0("Failed to configure encoder");
- stream->died = 1;
+ stream->died = 1;
return NULL; /* FIXME: probably leaking some memory here */
}
- }
- else if(reencoding)
- sdsc->reenc = reencode_init(stream);
+ }
+ else if(reencoding)
+ sdsc->reenc = reencode_init(stream);
if(stream->savefilename != NULL)
{
@@ -191,38 +191,38 @@
LOG_INFO1("Saving stream to file %s", stream->savefilename);
}
- if((shouterr = shout_open(sdsc->shout)) == SHOUTERR_SUCCESS)
- {
- LOG_INFO3("Connected to server: %s:%d%s",
- shout_get_host(sdsc->shout), shout_get_port(sdsc->shout), shout_get_mount(sdsc->shout));
-
- while(1)
- {
- if(stream->buffer_failures > MAX_ERRORS)
- {
- LOG_WARN0("Too many errors, shutting down");
- break;
- }
-
- buffer = stream_wait_for_data(stream);
-
- /* buffer being NULL means that either a fatal error occured,
- * or we've been told to shut down
- */
- if(!buffer)
- break;
-
- /* If data is NULL or length is 0, we should just skip this one.
- * Probably, we've been signalled to shut down, and that'll be
- * caught next iteration. Add to the error count just in case,
- * so that we eventually break out anyway
- */
- if(!buffer->buf || !buffer->len)
- {
- LOG_WARN0("Bad buffer dequeued!");
- stream->buffer_failures++;
- continue;
- }
+ if((shouterr = shout_open(sdsc->shout)) == SHOUTERR_SUCCESS)
+ {
+ LOG_INFO3("Connected to server: %s:%d%s",
+ shout_get_host(sdsc->shout), shout_get_port(sdsc->shout), shout_get_mount(sdsc->shout));
+
+ while(1)
+ {
+ if(stream->buffer_failures > MAX_ERRORS)
+ {
+ LOG_WARN0("Too many errors, shutting down");
+ break;
+ }
+
+ buffer = stream_wait_for_data(stream);
+
+ /* buffer being NULL means that either a fatal error occured,
+ * or we've been told to shut down
+ */
+ if(!buffer)
+ break;
+
+ /* If data is NULL or length is 0, we should just skip this one.
+ * Probably, we've been signalled to shut down, and that'll be
+ * caught next iteration. Add to the error count just in case,
+ * so that we eventually break out anyway
+ */
+ if(!buffer->buf || !buffer->len)
+ {
+ LOG_WARN0("Bad buffer dequeued!");
+ stream->buffer_failures++;
+ continue;
+ }
if(stream->wait_for_critical)
{
@@ -250,34 +250,34 @@
}
/* Non-fatal shout error */
else if(ret == 0)
- {
- LOG_ERROR2("Send error: %s (%s)",
+ {
+ LOG_ERROR2("Send error: %s (%s)",
shout_get_error(sdsc->shout), strerror(errno));
- if(shout_get_errno(sdsc->shout) == SHOUTERR_SOCKET)
- {
- int i=0;
-
- /* While we're trying to reconnect, don't receive data
- * to this instance, or we'll overflow once reconnect
- * succeeds
- */
- thread_mutex_lock(&ices_config->flush_lock);
- stream->skip = 1;
-
- /* Also, flush the current queue */
- input_flush_queue(stream->queue, 1);
- thread_mutex_unlock(&ices_config->flush_lock);
-
- while((i < stream->reconnect_attempts ||
- stream->reconnect_attempts==-1) &&
+ if(shout_get_errno(sdsc->shout) == SHOUTERR_SOCKET)
+ {
+ int i=0;
+
+ /* While we're trying to reconnect, don't receive data
+ * to this instance, or we'll overflow once reconnect
+ * succeeds
+ */
+ thread_mutex_lock(&ices_config->flush_lock);
+ stream->skip = 1;
+
+ /* Also, flush the current queue */
+ input_flush_queue(stream->queue, 1);
+ thread_mutex_unlock(&ices_config->flush_lock);
+
+ while((i < stream->reconnect_attempts ||
+ stream->reconnect_attempts==-1) &&
!ices_config->shutdown)
- {
- i++;
- LOG_WARN0("Trying reconnect after server socket error");
- shout_close(sdsc->shout);
- if((shouterr = shout_open(sdsc->shout)) == SHOUTERR_SUCCESS)
- {
- LOG_INFO3("Connected to server: %s:%d%s",
+ {
+ i++;
+ LOG_WARN0("Trying reconnect after server socket error");
+ shout_close(sdsc->shout);
+ if((shouterr = shout_open(sdsc->shout)) == SHOUTERR_SUCCESS)
+ {
+ LOG_INFO3("Connected to server: %s:%d%s",
shout_get_host(sdsc->shout), shout_get_port(sdsc->shout),
shout_get_mount(sdsc->shout));
/* This stream can't restart until the next
@@ -290,50 +290,50 @@
stream->wait_for_critical = 1;
input_flush_queue(stream->queue, 0);
thread_mutex_unlock(&ices_config->flush_lock);
- break;
- }
- else
- {
- LOG_ERROR3("Failed to reconnect to %s:%d (%s)",
- shout_get_host(sdsc->shout),shout_get_port(sdsc->shout),
- shout_get_error(sdsc->shout));
- if(i==stream->reconnect_attempts)
- {
- LOG_ERROR0("Reconnect failed too many times, "
- "giving up.");
+ break;
+ }
+ else
+ {
+ LOG_ERROR3("Failed to reconnect to %s:%d (%s)",
+ shout_get_host(sdsc->shout),shout_get_port(sdsc->shout),
+ shout_get_error(sdsc->shout));
+ if(i==stream->reconnect_attempts)
+ {
+ LOG_ERROR0("Reconnect failed too many times, "
+ "giving up.");
/* We want to die now */
- stream->buffer_failures = MAX_ERRORS+1;
- }
- else /* Don't try again too soon */
- sleep(stream->reconnect_delay);
- }
- }
- stream->skip = 0;
- }
- stream->buffer_failures++;
- }
- stream_release_buffer(buffer);
- }
- }
- else
- {
- LOG_ERROR3("Failed initial connect to %s:%d (%s)",
- shout_get_host(sdsc->shout),shout_get_port(sdsc->shout), shout_get_error(sdsc->shout));
- }
-
- shout_close(sdsc->shout);
+ stream->buffer_failures = MAX_ERRORS+1;
+ }
+ else /* Don't try again too soon */
+ sleep(stream->reconnect_delay);
+ }
+ }
+ stream->skip = 0;
+ }
+ stream->buffer_failures++;
+ }
+ stream_release_buffer(buffer);
+ }
+ }
+ else
+ {
+ LOG_ERROR4("Failed initial connect to %s:%d (%s: %s)",
+ shout_get_host(sdsc->shout),shout_get_port(sdsc->shout), shout_get_error(sdsc->shout), strerror(errno));
+ }
+
+ shout_close(sdsc->shout);
if(stream->savefile != NULL)
fclose(stream->savefile);
shout_free(sdsc->shout);
- encode_clear(sdsc->enc);
- reencode_clear(sdsc->reenc);
+ encode_clear(sdsc->enc);
+ reencode_clear(sdsc->reenc);
downmix_clear(sdsc->downmix);
resample_clear(sdsc->resamp);
- vorbis_comment_clear(&sdsc->vc);
+ vorbis_comment_clear(&sdsc->vc);
- stream->died = 1;
- return NULL;
+ stream->died = 1;
+ return NULL;
}
<p><p>1.3 +11 -11 ices/src/stream.h
Index: stream.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- stream.h 25 Sep 2001 12:04:22 -0000 1.2
+++ stream.h 16 Mar 2003 14:21:49 -0000 1.3
@@ -1,7 +1,7 @@
/* stream.h
* - Core streaming functions/main loop.
*
- * $Id: stream.h,v 1.2 2001/09/25 12:04:22 msmith Exp $
+ * $Id: stream.h,v 1.3 2003/03/16 14:21:49 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -21,22 +21,22 @@
#include "config.h"
typedef struct {
- unsigned char *buf;
- long len;
- int count;
- int critical;
- long aux_data;
+ unsigned char *buf;
+ long len;
+ int count;
+ int critical;
+ long aux_data;
} ref_buffer;
typedef struct _queue_item {
- ref_buffer *buf;
- struct _queue_item *next;
+ ref_buffer *buf;
+ struct _queue_item *next;
} queue_item;
typedef struct buffer_queue {
- queue_item *head, *tail;
- int length;
- mutex_t lock;
+ queue_item *head, *tail;
+ int length;
+ mutex_t lock;
} buffer_queue;
void *ices_instance_stream(void *arg);
<p><p>1.4 +70 -70 ices/src/stream_rewrite.c
Index: stream_rewrite.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream_rewrite.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- stream_rewrite.c 10 Nov 2001 04:47:24 -0000 1.3
+++ stream_rewrite.c 16 Mar 2003 14:21:49 -0000 1.4
@@ -5,7 +5,7 @@
*
* Heavily based on vcedit.c from vorbiscomment.
*
- * $Id: stream_rewrite.c,v 1.3 2001/11/10 04:47:24 msmith Exp $
+ * $Id: stream_rewrite.c,v 1.4 2003/03/16 14:21:49 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -53,92 +53,92 @@
*/
static void _v_writestring(oggpack_buffer *o,char *s, int len)
{
- while(len--)
- {
- oggpack_write(o,*s++,8);
- }
+ while(len--)
+ {
+ oggpack_write(o,*s++,8);
+ }
}
static int _commentheader_out(vorbis_comment *vc, char *vendor, ogg_packet *op)
{
- oggpack_buffer opb;
+ oggpack_buffer opb;
- oggpack_writeinit(&opb);
+ oggpack_writeinit(&opb);
- /* preamble */
- oggpack_write(&opb,0x03,8);
- _v_writestring(&opb,"vorbis", 6);
-
- /* vendor */
- oggpack_write(&opb,strlen(vendor),32);
- _v_writestring(&opb,vendor, strlen(vendor));
-
- /* comments */
- oggpack_write(&opb,vc->comments,32);
- if(vc->comments){
- int i;
- for(i=0;i<vc->comments;i++){
- if(vc->user_comments[i]){
- oggpack_write(&opb,vc->comment_lengths[i],32);
- _v_writestring(&opb,vc->user_comments[i], vc->comment_lengths[i]);
- }else{
- oggpack_write(&opb,0,32);
- }
- }
- }
- oggpack_write(&opb,1,1);
-
- op->packet = _ogg_malloc(oggpack_bytes(&opb));
- memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
-
- op->bytes=oggpack_bytes(&opb);
- op->b_o_s=0;
- op->e_o_s=0;
- op->granulepos=0;
+ /* preamble */
+ oggpack_write(&opb,0x03,8);
+ _v_writestring(&opb,"vorbis", 6);
+
+ /* vendor */
+ oggpack_write(&opb,strlen(vendor),32);
+ _v_writestring(&opb,vendor, strlen(vendor));
+
+ /* comments */
+ oggpack_write(&opb,vc->comments,32);
+ if(vc->comments){
+ int i;
+ for(i=0;i<vc->comments;i++){
+ if(vc->user_comments[i]){
+ oggpack_write(&opb,vc->comment_lengths[i],32);
+ _v_writestring(&opb,vc->user_comments[i], vc->comment_lengths[i]);
+ }else{
+ oggpack_write(&opb,0,32);
+ }
+ }
+ }
+ oggpack_write(&opb,1,1);
+
+ op->packet = _ogg_malloc(oggpack_bytes(&opb));
+ memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
+
+ op->bytes=oggpack_bytes(&opb);
+ op->b_o_s=0;
+ op->e_o_s=0;
+ op->granulepos=0;
- return 0;
+ return 0;
}
static int _blocksize(stream_rewriter *s, ogg_packet *p)
{
- int this = vorbis_packet_blocksize(&s->vi, p);
- int ret = (this + s->prevW)/4;
+ int this = vorbis_packet_blocksize(&s->vi, p);
+ int ret = (this + s->prevW)/4;
- if(!s->prevW)
- {
- s->prevW = this;
- return 0;
- }
+ if(!s->prevW)
+ {
+ s->prevW = this;
+ return 0;
+ }
- s->prevW = this;
- return ret;
+ s->prevW = this;
+ return ret;
}
static int _fetch_next_packet(stream_rewriter *s, ogg_packet *p)
{
- int result;
- ogg_page og;
- char *buffer;
- int bytes;
-
- result = ogg_stream_packetout(&s->stream_in, p);
-
- if(result > 0)
- return 1;
- else
- {
- while(ogg_sync_pageout(&s->sync, &og) <= 0)
- {
- buffer = ogg_sync_buffer(&s->sync, CHUNKSIZE);
- bytes = fread(buffer,1, CHUNKSIZE, s->in);
- ogg_sync_wrote(&s->sync, bytes);
- if(bytes == 0)
- return 0;
- }
-
- ogg_stream_pagein(&s->stream_in, &og);
- return _fetch_next_packet(s, p);
- }
+ int result;
+ ogg_page og;
+ char *buffer;
+ int bytes;
+
+ result = ogg_stream_packetout(&s->stream_in, p);
+
+ if(result > 0)
+ return 1;
+ else
+ {
+ while(ogg_sync_pageout(&s->sync, &og) <= 0)
+ {
+ buffer = ogg_sync_buffer(&s->sync, CHUNKSIZE);
+ bytes = fread(buffer,1, CHUNKSIZE, s->in);
+ ogg_sync_wrote(&s->sync, bytes);
+ if(bytes == 0)
+ return 0;
+ }
+
+ ogg_stream_pagein(&s->stream_in, &og);
+ return _fetch_next_packet(s, p);
+ }
}
static int _get_next_page(stream_rewriter *s, ogg_page *page)
<p><p>1.13 +90 -90 ices/src/stream_shared.c
Index: stream_shared.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream_shared.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- stream_shared.c 17 Aug 2002 05:17:57 -0000 1.12
+++ stream_shared.c 16 Mar 2003 14:21:49 -0000 1.13
@@ -1,7 +1,7 @@
/* stream_shared.c
* - Stream utility functions.
*
- * $Id: stream_shared.c,v 1.12 2002/08/17 05:17:57 msmith Exp $
+ * $Id: stream_shared.c,v 1.13 2003/03/16 14:21:49 msmith Exp $
*
* Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
*
@@ -49,56 +49,56 @@
void stream_release_buffer(ref_buffer *buf)
{
- thread_mutex_lock(&ices_config->refcount_lock);
- buf->count--;
- if(!buf->count)
- {
- free(buf->buf);
- free(buf);
- }
- thread_mutex_unlock(&ices_config->refcount_lock);
+ thread_mutex_lock(&ices_config->refcount_lock);
+ buf->count--;
+ if(!buf->count)
+ {
+ free(buf->buf);
+ free(buf);
+ }
+ thread_mutex_unlock(&ices_config->refcount_lock);
}
ref_buffer *stream_wait_for_data(instance_t *stream)
{
- ref_buffer *buffer;
- queue_item *old;
+ ref_buffer *buffer;
+ queue_item *old;
+
+ thread_mutex_lock(&stream->queue->lock);
+ while(!stream->queue->head && !ices_config->shutdown && !stream->kill)
+ {
+ thread_mutex_unlock(&stream->queue->lock);
+ thread_cond_wait(&ices_config->queue_cond);
+ thread_mutex_lock(&stream->queue->lock);
+ }
- thread_mutex_lock(&stream->queue->lock);
- while(!stream->queue->head && !ices_config->shutdown && !stream->kill)
- {
- thread_mutex_unlock(&stream->queue->lock);
- thread_cond_wait(&ices_config->queue_cond);
- thread_mutex_lock(&stream->queue->lock);
- }
-
- if(ices_config->shutdown || stream->kill)
- {
- LOG_DEBUG0("Shutdown signalled: thread shutting down");
- thread_mutex_unlock(&stream->queue->lock);
- return NULL;
- }
-
- buffer = stream->queue->head->buf;
- old = stream->queue->head;
-
- stream->queue->head = stream->queue->head->next;
- if(!stream->queue->head)
- stream->queue->tail = NULL;
-
- free(old);
- stream->queue->length--;
- thread_mutex_unlock(&stream->queue->lock);
-
- /* ok, we pulled something off the queue and the queue is
- * now empty - this means we're probably keeping up, so
- * clear one of the errors. This way, very occasional errors
- * don't cause eventual shutdown
- */
- if(!stream->queue->head && stream->buffer_failures>0)
- stream->buffer_failures--;
+ if(ices_config->shutdown || stream->kill)
+ {
+ LOG_DEBUG0("Shutdown signalled: thread shutting down");
+ thread_mutex_unlock(&stream->queue->lock);
+ return NULL;
+ }
+
+ buffer = stream->queue->head->buf;
+ old = stream->queue->head;
- return buffer;
+ stream->queue->head = stream->queue->head->next;
+ if(!stream->queue->head)
+ stream->queue->tail = NULL;
+
+ free(old);
+ stream->queue->length--;
+ thread_mutex_unlock(&stream->queue->lock);
+
+ /* ok, we pulled something off the queue and the queue is
+ * now empty - this means we're probably keeping up, so
+ * clear one of the errors. This way, very occasional errors
+ * don't cause eventual shutdown
+ */
+ if(!stream->queue->head && stream->buffer_failures>0)
+ stream->buffer_failures--;
+
+ return buffer;
}
/* Process a buffer (including reencoding or encoding, if desired).
@@ -109,59 +109,59 @@
*/
int process_and_send_buffer(stream_description *sdsc, ref_buffer *buffer)
{
- if(sdsc->reenc)
- {
- unsigned char *buf;
- int buflen,ret;
-
- ret = reencode_page(sdsc->reenc, buffer, &buf, &buflen);
- if(ret > 0)
- {
- ret = stream_send_data(sdsc, buf, buflen);
- free(buf);
+ if(sdsc->reenc)
+ {
+ unsigned char *buf;
+ int buflen,ret;
+
+ ret = reencode_page(sdsc->reenc, buffer, &buf, &buflen);
+ if(ret > 0)
+ {
+ ret = stream_send_data(sdsc, buf, buflen);
+ free(buf);
return ret;
- }
- else if(ret==0) /* No data produced by reencode */
+ }
+ else if(ret==0) /* No data produced by reencode */
return -1;
- else
- {
- LOG_ERROR0("Fatal reencoding error encountered");
+ else
+ {
+ LOG_ERROR0("Fatal reencoding error encountered");
return -2;
- }
- }
+ }
+ }
else if (sdsc->enc)
{
- ogg_page og;
- int be = (sdsc->input->subtype == INPUT_PCM_BE_16)?1:0;
+ ogg_page og;
+ int be = (sdsc->input->subtype == INPUT_PCM_BE_16)?1:0;
int ret=1;
- /* We use critical as a flag to say 'start a new stream' */
- if(buffer->critical)
- {
+ /* We use critical as a flag to say 'start a new stream' */
+ if(buffer->critical)
+ {
if(sdsc->resamp) {
resample_finish(sdsc->resamp);
encode_data_float(sdsc->enc, sdsc->resamp->buffers,
sdsc->resamp->buffill);
}
- encode_finish(sdsc->enc);
- while(encode_flush(sdsc->enc, &og) != 0)
- {
- if ((ret = stream_send_data(sdsc, og.header, og.header_len)) == 0)
+ encode_finish(sdsc->enc);
+ while(encode_flush(sdsc->enc, &og) != 0)
+ {
+ if ((ret = stream_send_data(sdsc, og.header, og.header_len)) == 0)
return 0;
- if ((ret = stream_send_data(sdsc, og.body, og.body_len)) == 0)
+ if ((ret = stream_send_data(sdsc, og.body, og.body_len)) == 0)
return 0;
- }
- encode_clear(sdsc->enc);
+ }
+ encode_clear(sdsc->enc);
- if(sdsc->input->metadata_update)
+ if(sdsc->input->metadata_update)
{
- vorbis_comment_clear(&sdsc->vc);
- vorbis_comment_init(&sdsc->vc);
+ vorbis_comment_clear(&sdsc->vc);
+ vorbis_comment_init(&sdsc->vc);
- sdsc->input->metadata_update(sdsc->input->internal, &sdsc->vc);
- }
+ sdsc->input->metadata_update(sdsc->input->internal, &sdsc->vc);
+ }
- sdsc->enc = encode_initialise(sdsc->stream->channels,
+ sdsc->enc = encode_initialise(sdsc->stream->channels,
sdsc->stream->samplerate, sdsc->stream->managed,
sdsc->stream->min_br, sdsc->stream->nom_br,
sdsc->stream->max_br, sdsc->stream->quality,
@@ -171,7 +171,7 @@
return -2;
}
- }
+ }
if(sdsc->downmix) {
downmix_buffer(sdsc->downmix, buffer->buf, buffer->len, be);
@@ -192,21 +192,21 @@
sdsc->resamp->buffill);
}
else {
- encode_data(sdsc->enc, (signed char *)(buffer->buf),
+ encode_data(sdsc->enc, (signed char *)(buffer->buf),
buffer->len, be);
}
- while(encode_dataout(sdsc->enc, &og) > 0)
- {
- if ((ret = stream_send_data(sdsc, og.header, og.header_len)) == 0)
+ while(encode_dataout(sdsc->enc, &og) > 0)
+ {
+ if ((ret = stream_send_data(sdsc, og.header, og.header_len)) == 0)
return 0;
- if ((ret = stream_send_data(sdsc, og.body, og.body_len)) == 0)
+ if ((ret = stream_send_data(sdsc, og.body, og.body_len)) == 0)
return 0;
- }
+ }
return ret;
- }
- else
- return stream_send_data(sdsc, buffer->buf, buffer->len);
+ }
+ else
+ return stream_send_data(sdsc, buffer->buf, buffer->len);
}
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list