[xiph-cvs] cvs commit: ices/src config.h input.c input.h metadata.c signals.c stream.c stream_shared.c stream_shared.h
Michael Smith
msmith at xiph.org
Sun Sep 23 20:45:14 PDT 2001
msmith 01/09/23 20:45:14
Modified: src config.h input.c input.h metadata.c signals.c
stream.c stream_shared.c stream_shared.h
Log:
General code cleanup and reorganisation
Revision Changes Path
1.3 +1 -0 ices/src/config.h
Index: config.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/config.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- config.h 2001/09/23 09:49:02 1.2
+++ config.h 2001/09/24 03:45:12 1.3
@@ -83,6 +83,7 @@
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;
1.2 +3 -1 ices/src/input.c
Index: input.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/input.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- input.c 2001/09/10 02:30:53 1.1
+++ input.c 2001/09/24 03:45:12 1.2
@@ -215,6 +215,7 @@
ices_config->inmod = inmod;
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);
@@ -227,7 +228,7 @@
while(instance)
{
- stream_description *arg = malloc(sizeof(stream_description));
+ stream_description *arg = calloc(1, sizeof(stream_description));
arg->stream = instance;
arg->input = inmod;
if(instance->savefilename != NULL)
@@ -392,6 +393,7 @@
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);
1.2 +9 -0 ices/src/input.h
Index: input.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/input.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- input.h 2001/09/10 02:30:49 1.1
+++ input.h 2001/09/24 03:45:12 1.2
@@ -12,13 +12,22 @@
#ifndef __INPUT_H__
#define __INPUT_H__
+#include <shout/shout.h>
+#include <vorbis/codec.h>
+
#include "config.h"
#include "inputmodule.h"
#include "stream.h"
+#include "reencode.h"
+#include "encode.h"
typedef struct {
instance_t *stream;
input_module_t *input;
+ reencode_state *reenc;
+ encoder_state *enc;
+ shout_conn_t conn;
+ vorbis_comment vc;
} stream_description;
1.4 +2 -1 ices/src/metadata.c
Index: metadata.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/metadata.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- metadata.c 2001/09/23 09:57:55 1.3
+++ metadata.c 2001/09/24 03:45:12 1.4
@@ -18,6 +18,7 @@
#include "config.h"
#include "inputmodule.h"
#include "event.h"
+#include "thread/thread.h"
#define MODULE "metadata/"
#include "logging.h"
@@ -74,7 +75,7 @@
FILE *file;
while(metadata_update_signalled == 0)
- sleep(1);
+ thread_cond_wait(&ices_config->event_pending_cond);
metadata_update_signalled = 0;
1.3 +1 -1 ices/src/signals.c
Index: signals.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/signals.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- signals.c 2001/09/23 09:49:03 1.2
+++ signals.c 2001/09/24 03:45:12 1.3
@@ -30,6 +30,7 @@
{
LOG_INFO0("Metadata update requested");
metadata_update_signalled = 1;
+ thread_cond_broadcast(&ices_config->event_pending_cond);
signal(SIGUSR1, signal_usr1_handler);
}
@@ -42,7 +43,6 @@
/* Now, let's tell it to move to the next track */
ices_config->inmod->handle_event(ices_config->inmod,EVENT_NEXTTRACK,NULL);
- /* Do we need to do this? */
signal(SIGHUP, signal_hup_handler);
}
1.2 +42 -103 ices/src/stream.c
Index: stream.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- stream.c 2001/09/10 02:30:51 1.1
+++ stream.c 2001/09/24 03:45:12 1.2
@@ -43,61 +43,55 @@
*/
void *ices_instance_stream(void *arg)
{
- shout_conn_t conn;
int ret;
int errors=0;
ref_buffer *buffer;
stream_description *sdsc = arg;
instance_t *stream = sdsc->stream;
input_module_t *inmod = sdsc->input;
- queue_item *old;
- reencode_state *reenc=NULL;
int reencoding = (inmod->type == ICES_INPUT_VORBIS) && stream->encode;
int encoding = (inmod->type == ICES_INPUT_PCM) && stream->encode;
- encoder_state *enc=NULL;
- vorbis_comment vc;
- vorbis_comment_init(&vc);
+ vorbis_comment_init(&sdsc->vc);
-
- shout_init_connection(&conn);
+ shout_init_connection(&sdsc->conn);
signal(SIGPIPE, signal_hup_handler);
- conn.ip = malloc(16);
- if(!resolver_getip(stream->hostname, conn.ip, 16))
+ sdsc->conn.ip = malloc(16);
+ if(!resolver_getip(stream->hostname, sdsc->conn.ip, 16))
{
LOG_ERROR1("Could not resolve hostname \"%s\"", stream->hostname);
- free(conn.ip);
+ free(sdsc->conn.ip);
stream->died = 1;
return NULL;
}
- conn.port = stream->port;
- conn.password = strdup(stream->password);
- conn.mount = strdup(stream->mount);
+ sdsc->conn.port = stream->port;
+ sdsc->conn.password = strdup(stream->password);
+ sdsc->conn.mount = strdup(stream->mount);
/* set the metadata for the stream */
if (ices_config->stream_name)
- conn.name = strdup(ices_config->stream_name);
+ sdsc->conn.name = strdup(ices_config->stream_name);
if (ices_config->stream_genre)
- conn.genre = strdup(ices_config->stream_genre);
+ sdsc->conn.genre = strdup(ices_config->stream_genre);
if (ices_config->stream_description)
- conn.description = strdup(ices_config->stream_description);
+ sdsc->conn.description = strdup(ices_config->stream_description);
if(encoding)
{
if(inmod->metadata_update)
- inmod->metadata_update(inmod->internal, &vc);
- enc = encode_initialise(stream->channels, stream->samplerate,
- stream->bitrate, stream->serial++, &vc);
+ inmod->metadata_update(inmod->internal, &sdsc->vc);
+ sdsc->enc = encode_initialise(stream->channels, stream->samplerate,
+ stream->bitrate, stream->serial++, &sdsc->vc);
}
else if(reencoding)
- reenc = reencode_init(stream);
+ sdsc->reenc = reencode_init(stream);
- if(shout_connect(&conn))
+ if(shout_connect(&sdsc->conn))
{
LOG_INFO3("Connected to server: %s:%d%s",
- conn.ip, conn.port, conn.mount);
+ sdsc->conn.ip, sdsc->conn.port, sdsc->conn.mount);
while(1)
{
@@ -126,75 +120,21 @@
errors++;
continue;
}
-
- if(encoding)
- {
- ogg_page og;
- int be = (inmod->subtype == INPUT_PCM_BE_16)?1:0;
-
- /* We use critical as a flag to say 'start a new stream' */
- if(buffer->critical)
- {
- encode_finish(enc);
- while(encode_flush(enc, &og) != 0)
- {
- ret = shout_send_data(&conn, og.header, og.header_len);
- ret = shout_send_data(&conn, og.body, og.body_len);
- }
- encode_clear(enc);
-
-
- if(inmod->metadata_update)
- {
- vorbis_comment_clear(&vc);
- vorbis_comment_init(&vc);
-
- inmod->metadata_update(inmod->internal, &vc);
- }
-
- enc = encode_initialise(stream->channels,stream->samplerate,
- stream->bitrate, stream->serial++, &vc);
- }
-
- encode_data(enc, (signed char *)(buffer->buf), buffer->len, be);
-
- while(encode_dataout(enc, &og) > 0)
- {
- /* FIXME: This is wrong. Get the return values right. */
- ret=shout_send_data(&conn, og.header, og.header_len);
- ret=shout_send_data(&conn, og.body, og.body_len);
- }
- }
- else if(reencoding)
- {
- unsigned char *buf;
- int buflen,ret2;
- ret2 = reencode_page(reenc, buffer, &buf, &buflen);
- if(ret2 > 0)
- {
- ret = shout_send_data(&conn, buf, buflen);
- free(buf);
- }
- else if(ret2==0)
- {
- ret = -1; /* This way we don't enter the error handling
- code */
- }
- else
- {
- LOG_ERROR0("Fatal reencoding error encountered");
- errors = MAX_ERRORS+1;
- continue;
- }
- }
- else
- ret = shout_send_data(&conn, buffer->buf, buffer->len);
+ ret = process_and_send_buffer(sdsc, buffer);
- if(!ret)
+ if(ret == -1)
+ continue;
+ else if(ret == -2)
+ {
+ errors = MAX_ERRORS+1;
+ continue;
+ }
+ else if(ret == 0)
{
- LOG_ERROR1("Send error: %s", shout_strerror(&conn, conn.error));
- if(conn.error == SHOUTERR_SOCKET)
+ LOG_ERROR1("Send error: %s",
+ shout_strerror(&sdsc->conn, sdsc->conn.error));
+ if(sdsc->conn.error == SHOUTERR_SOCKET)
{
int i=0;
@@ -214,18 +154,19 @@
{
i++;
LOG_WARN0("Trying reconnect after server socket error");
- shout_disconnect(&conn);
- if(shout_connect(&conn))
+ shout_disconnect(&sdsc->conn);
+ if(shout_connect(&sdsc->conn))
{
LOG_INFO3("Connected to server: %s:%d%s",
- conn.ip, conn.port, conn.mount);
+ sdsc->conn.ip, sdsc->conn.port,
+ sdsc->conn.mount);
break;
}
else
{
LOG_ERROR3("Failed to reconnect to %s:%d (%s)",
- conn.ip,conn.port,
- shout_strerror(&conn,conn.error));
+ sdsc->conn.ip,sdsc->conn.port,
+ shout_strerror(&sdsc->conn,sdsc->conn.error));
if(i==stream->reconnect_attempts)
{
LOG_ERROR0("Reconnect failed too many times, "
@@ -250,20 +191,18 @@
else
{
LOG_ERROR3("Failed initial connect to %s:%d (%s)",
- conn.ip,conn.port,shout_strerror(&conn,conn.error));
+ sdsc->conn.ip,sdsc->conn.port,
+ shout_strerror(&sdsc->conn,sdsc->conn.error));
}
- shout_disconnect(&conn);
+ shout_disconnect(&sdsc->conn);
- free(conn.ip);
- encode_clear(enc);
- reencode_clear(reenc);
- vorbis_comment_clear(&vc);
+ free(sdsc->conn.ip);
+ encode_clear(sdsc->enc);
+ reencode_clear(sdsc->reenc);
+ vorbis_comment_clear(&sdsc->vc);
stream->died = 1;
return NULL;
}
-
-
-
1.2 +72 -3 ices/src/stream_shared.c
Index: stream_shared.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream_shared.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- stream_shared.c 2001/09/10 02:30:54 1.1
+++ stream_shared.c 2001/09/24 03:45:12 1.2
@@ -19,6 +19,8 @@
#include "inputmodule.h"
#include "stream_shared.h"
#include "stream.h"
+#include "reencode.h"
+#include "encode.h"
#define MODULE "stream-shared/"
#include "logging.h"
@@ -77,8 +79,75 @@
return buffer;
}
-
-
-
+/* Process a buffer (including reencoding or encoding, if desired).
+ * Returns: >0 - success
+ * 0 - shout error occurred
+ * -1 - no data produced
+ * -2 - fatal error occurred
+ */
+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 = shout_send_data(&sdsc->conn, buf, buflen);
+ free(buf);
+ return ret;
+ }
+ else if(ret==0)
+ return -1;
+ 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;
+ int ret=1;
+
+ /* We use critical as a flag to say 'start a new stream' */
+ if(buffer->critical)
+ {
+ encode_finish(sdsc->enc);
+ while(encode_flush(sdsc->enc, &og) != 0)
+ {
+ ret = shout_send_data(&sdsc->conn, og.header, og.header_len);
+ ret = shout_send_data(&sdsc->conn, og.body, og.body_len);
+ }
+ encode_clear(sdsc->enc);
+
+ if(sdsc->input->metadata_update)
+ {
+ vorbis_comment_clear(&sdsc->vc);
+ vorbis_comment_init(&sdsc->vc);
+
+ sdsc->input->metadata_update(sdsc->input->internal, &sdsc->vc);
+ }
+
+ sdsc->enc = encode_initialise(sdsc->stream->channels,
+ sdsc->stream->samplerate, sdsc->stream->bitrate,
+ sdsc->stream->serial++, &sdsc->vc);
+ }
+
+ encode_data(sdsc->enc, (signed char *)(buffer->buf), buffer->len, be);
+
+ while(encode_dataout(sdsc->enc, &og) > 0)
+ {
+ ret = shout_send_data(&sdsc->conn, og.header, og.header_len);
+ ret = shout_send_data(&sdsc->conn, og.body, og.body_len);
+ }
+
+ return ret;
+ }
+ else
+ return shout_send_data(&sdsc->conn, buffer->buf, buffer->len);
+}
1.2 +2 -0 ices/src/stream_shared.h
Index: stream_shared.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream_shared.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- stream_shared.h 2001/09/10 02:30:54 1.1
+++ stream_shared.h 2001/09/24 03:45:12 1.2
@@ -14,9 +14,11 @@
#include "stream.h"
#include "config.h"
+#include "input.h"
ref_buffer *stream_wait_for_data(instance_t *stream);
void stream_release_buffer(ref_buffer *buf);
+int process_and_send_buffer(stream_description *sdsc, ref_buffer *buffer);
#endif
--- >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