[xiph-cvs] cvs commit: ices/src config.h input.c savefile.c stream.c stream_shared.c
Michael Smith
msmith at xiph.org
Sun Sep 23 23:34:34 PDT 2001
msmith 01/09/23 23:34:34
Modified: src config.h input.c savefile.c stream.c
stream_shared.c
Log:
Implement ability to save all streams on output, so you can actually save
what was being streamed out, instead of the significantly less useful saving
of what was fed in.
Revision Changes Path
1.4 +1 -1 ices/src/config.h
Index: config.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/config.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- config.h 2001/09/24 03:45:12 1.3
+++ config.h 2001/09/24 06:34:33 1.4
@@ -44,7 +44,7 @@
int channels;
/* private */
-
+ FILE *savefile;
int serial;
int buffer_failures;
int died;
1.3 +3 -2 ices/src/input.c
Index: input.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/input.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- input.c 2001/09/24 03:45:12 1.2
+++ input.c 2001/09/24 06:34:33 1.3
@@ -231,10 +231,11 @@
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);
- else
- thread_create("stream", ices_instance_stream, arg, 1);
+ */
+ thread_create("stream", ices_instance_stream, arg, 1);
instance = instance->next;
}
1.2 +2 -0 ices/src/savefile.c
Index: savefile.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/savefile.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- savefile.c 2001/09/10 02:30:54 1.1
+++ savefile.c 2001/09/24 06:34:33 1.2
@@ -7,6 +7,8 @@
* Public License, version 2. You may use, modify, and redistribute
* it under the terms of this license. A copy should be included
* with this source.
+ *
+ * NOTE: Not currently actually used.
*/
#include <stdio.h>
1.4 +22 -10 ices/src/stream.c
Index: stream.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- stream.c 2001/09/24 03:53:01 1.3
+++ stream.c 2001/09/24 06:34:33 1.4
@@ -44,7 +44,6 @@
void *ices_instance_stream(void *arg)
{
int ret;
- int errors=0;
ref_buffer *buffer;
stream_description *sdsc = arg;
instance_t *stream = sdsc->stream;
@@ -88,6 +87,16 @@
else if(reencoding)
sdsc->reenc = reencode_init(stream);
+ if(stream->savefilename != NULL)
+ {
+ stream->savefile = fopen(stream->savefilename, "wb");
+ if(!stream->savefile)
+ LOG_ERROR2("Failed to open stream save file %s: %s",
+ stream->savefilename, strerror(errno));
+ else
+ LOG_INFO1("Saving stream to file %s", stream->savefilename);
+ }
+
if(shout_connect(&sdsc->conn))
{
LOG_INFO3("Connected to server: %s:%d%s",
@@ -95,7 +104,7 @@
while(1)
{
- if(errors > MAX_ERRORS)
+ if(stream->buffer_failures > MAX_ERRORS)
{
LOG_WARN0("Too many errors, shutting down");
break;
@@ -117,19 +126,22 @@
if(!buffer->buf || !buffer->len)
{
LOG_WARN0("Bad buffer dequeued!");
- errors++;
+ stream->buffer_failures++;
continue;
}
ret = process_and_send_buffer(sdsc, buffer);
+ /* No data produced */
if(ret == -1)
continue;
+ /* Fatal error */
else if(ret == -2)
{
- errors = MAX_ERRORS+1;
+ stream->buffer_failures = MAX_ERRORS+1;
continue;
}
+ /* Non-fatal shout error */
else if(ret == 0)
{
LOG_ERROR1("Send error: %s",
@@ -172,7 +184,8 @@
{
LOG_ERROR0("Reconnect failed too many times, "
"giving up.");
- errors = MAX_ERRORS+1; /* We want to die now */
+ /* We want to die now */
+ stream->buffer_failures = MAX_ERRORS+1;
}
else /* Don't try again too soon */
sleep(stream->reconnect_delay);
@@ -180,13 +193,9 @@
}
stream->skip = 0;
}
- errors++;
+ stream->buffer_failures++;
}
- else
- errors=0;
-
stream_release_buffer(buffer);
-
}
}
else
@@ -197,6 +206,9 @@
}
shout_disconnect(&sdsc->conn);
+
+ if(stream->savefile != NULL)
+ fclose(stream->savefile);
free(sdsc->conn.ip);
encode_clear(sdsc->enc);
1.3 +19 -6 ices/src/stream_shared.c
Index: stream_shared.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream_shared.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- stream_shared.c 2001/09/24 03:45:12 1.2
+++ stream_shared.c 2001/09/24 06:34:33 1.3
@@ -25,6 +25,19 @@
#define MODULE "stream-shared/"
#include "logging.h"
+int stream_send_data(stream_description *s, unsigned char *buf,
+ unsigned long len)
+{
+ if(s->stream->savefile)
+ {
+ int ret = fwrite(buf, 1, len, s->stream->savefile);
+ if(ret != len)
+ LOG_ERROR1("Failed to write %d bytes to savefile", len);
+ }
+
+ return shout_send_data(&s->conn, buf, len);
+}
+
void stream_release_buffer(ref_buffer *buf)
{
thread_mutex_lock(&ices_config->refcount_lock);
@@ -95,7 +108,7 @@
ret = reencode_page(sdsc->reenc, buffer, &buf, &buflen);
if(ret > 0)
{
- ret = shout_send_data(&sdsc->conn, buf, buflen);
+ ret = stream_send_data(sdsc, buf, buflen);
free(buf);
return ret;
}
@@ -119,8 +132,8 @@
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);
+ ret = stream_send_data(sdsc, og.header, og.header_len);
+ ret = stream_send_data(sdsc, og.body, og.body_len);
}
encode_clear(sdsc->enc);
@@ -141,13 +154,13 @@
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);
+ ret = stream_send_data(sdsc, og.header, og.header_len);
+ ret = stream_send_data(sdsc, og.body, og.body_len);
}
return ret;
}
else
- return shout_send_data(&sdsc->conn, buffer->buf, buffer->len);
+ return stream_send_data(sdsc, buffer->buf, buffer->len);
}
--- >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