[xiph-cvs] cvs commit: ices/src Makefile.am config.c ices.c process.c registry.h savefile.c

Michael Smith msmith at xiph.org
Fri Feb 8 21:07:03 PST 2002


msmith      02/02/08 21:07:03

  Modified:    src      Tag: branch-beta2-rewrite Makefile.am config.c
                        ices.c No tag process.c registry.h Tag:
                        branch-beta2-rewrite savefile.c
  Log:
  Config fixes (now it actually gives error messages on some bad configs, instead
  of just collapsing in a heap trying to use an invalid config).
  
  Reimplemented savefile.

Revision  Changes    Path
No                   revision

<p>No                   revision

<p>1.5.2.3   +1 -1      ices/src/Makefile.am

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/ices/src/Makefile.am,v
retrieving revision 1.5.2.2
retrieving revision 1.5.2.3
diff -u -r1.5.2.2 -r1.5.2.3
--- Makefile.am	2002/02/08 12:54:08	1.5.2.2
+++ Makefile.am	2002/02/09 05:07:01	1.5.2.3
@@ -23,7 +23,7 @@
 #noinst_HEADERS = config.h input.h im_playlist.h signals.h stream.h reencode.h encode.h playlist_basic.h logging.h im_stdinpcm.h $(ossheaders) $(sunheaders) event.h stream_shared.h metadata.h process.h
 #ices_SOURCES = input.c config.c stream.c ices.c signals.c im_playlist.c reencode.c encode.c playlist_basic.c im_stdinpcm.c $(osssources) $(sunsources) stream_shared.c savefile.c metadata.c stream_rewrite.c process.c
 noinst_HEADERS = config.h input.h im_playlist.h signals.h stream.h encode.h playlist_basic.h logging.h process.h $(ossheaders) im_stdinpcm.h
-ices_SOURCES = input.c config.c stream.c ices.c signals.c im_playlist.c encode.c playlist_basic.c process.c output.c $(osssources) im_stdinpcm.c
+ices_SOURCES = input.c config.c stream.c ices.c signals.c im_playlist.c encode.c playlist_basic.c process.c output.c $(osssources) im_stdinpcm.c savefile.c
 
 ices_LDADD = net/libicenet.la thread/libicethread.la log/libicelog.la\
         avl/libiceavl.la timing/libicetiming.la

<p><p>1.6.2.3   +35 -17    ices/src/config.c

Index: config.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/config.c,v
retrieving revision 1.6.2.2
retrieving revision 1.6.2.3
diff -u -r1.6.2.2 -r1.6.2.3
--- config.c	2002/02/08 11:14:03	1.6.2.2
+++ config.c	2002/02/09 05:07:01	1.6.2.3
@@ -1,7 +1,7 @@
 /* config.c
  * - config file reading code, plus default settings.
  *
- * $Id: config.c,v 1.6.2.2 2002/02/08 11:14:03 msmith Exp $
+ * $Id: config.c,v 1.6.2.3 2002/02/09 05:07:01 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -165,7 +165,7 @@
     }
 }
 
-static void _parse_instance(config_t *config, xmlDocPtr doc, xmlNodePtr node)
+static int _parse_instance(config_t *config, xmlDocPtr doc, xmlNodePtr node)
 {
     process_chain_element *chain = NULL;
     instance_t *instance = calloc(1, sizeof(instance_t));
@@ -180,14 +180,15 @@
 
         if (strcmp(node->name, "maxqueuelength") == 0)
             SET_INT(instance->max_queue_length);
-		if (strcmp(node->name, "module") == 0)
+		if (strcmp(node->name, "module") == 0) {
             chain = _parse_module(doc, node, chain);
+            if(!chain) {
+                fprintf(stderr, "Couldn't create processing chain\n");
+                return -1;
+            }
+        }
         } while ((node = node->next));
 
-    if(!chain) {
-        fprintf(stderr, "Couldn't create processing chain\n");
-        return;
-    }
 
     instance->next = NULL;
     instance->output_chain = chain;
@@ -203,9 +204,11 @@
 
         prev->next = instance;
     }
+
+    return 0;
 }
 
-static void _parse_input(config_t *config, xmlDocPtr doc, xmlNodePtr node)
+static int _parse_input(config_t *config, xmlDocPtr doc, xmlNodePtr node)
 {
     process_chain_element *chain = NULL;
 
@@ -219,24 +222,36 @@
         } while ((node = node->next));
 
     config->input_chain = chain;
+
+    if(!chain) {
+        fprintf(stderr, "Could not create input processing chain.\n");
+        return -1;
+    }
+
+    return 0;
 }
 
-static void _parse_stream(config_t *config, xmlDocPtr doc, xmlNodePtr node)
+static int _parse_stream(config_t *config, xmlDocPtr doc, xmlNodePtr node)
 {
+    int ret = 0;
         do 
         {
                 if (node == NULL) break;
                 if (xmlIsBlankNode(node)) continue;
 
                 if (strcmp(node->name, "input") == 0)
-			_parse_input(config, doc, node->xmlChildrenNode);
+			ret = _parse_input(config, doc, node->xmlChildrenNode);
                 else if (strcmp(node->name, "instance") == 0)
-			_parse_instance(config, doc, node->xmlChildrenNode);
-	} while ((node = node->next));
+			ret = _parse_instance(config, doc, node->xmlChildrenNode);
+	} while (!ret && (node = node->next));
+
+    return ret;
 }
 
-static void _parse_root(config_t *config, xmlDocPtr doc, xmlNodePtr node)
+static int _parse_root(config_t *config, xmlDocPtr doc, xmlNodePtr node)
 {
+    int ret = -1;
+
         do 
         {
                 if (node == NULL) break;
@@ -253,8 +268,10 @@
         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);
+			ret = _parse_stream(config, doc, node->xmlChildrenNode);
         } while ((node = node->next));
+
+    return ret;
 }
 
 void config_initialise(void)
@@ -275,6 +292,7 @@
 {
         xmlDocPtr doc;
         xmlNodePtr node;
+    int ret;
 
         if (fn == NULL || strcmp(fn, "") == 0) return -1;
 
@@ -285,14 +303,14 @@
         if (node == NULL || strcmp(node->name, "ices") != 0) 
         {
                 xmlFreeDoc(doc);
-		return 0;
+		return -1;
         }
 
-	_parse_root(ices_config, doc, node->xmlChildrenNode);
+	ret = _parse_root(ices_config, doc, node->xmlChildrenNode);
 
         xmlFreeDoc(doc);
 
-	return 1;
+	return ret;
 }
 
 

<p><p>1.4.2.3   +2 -2      ices/src/ices.c

Index: ices.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/ices.c,v
retrieving revision 1.4.2.2
retrieving revision 1.4.2.3
diff -u -r1.4.2.2 -r1.4.2.3
--- ices.c	2002/02/08 11:14:03	1.4.2.2
+++ ices.c	2002/02/09 05:07:01	1.4.2.3
@@ -1,7 +1,7 @@
 /* ices.c
  * - Main startup, thread launching, and cleanup code.
  *
- * $Id: ices.c,v 1.4.2.2 2002/02/08 11:14:03 msmith Exp $
+ * $Id: ices.c,v 1.4.2.3 2002/02/09 05:07:01 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -52,7 +52,7 @@
         ** make it so you can specify all parameters on the commandline
         ** too.
         */
-	if (config_read(argv[1]) <= 0) 
+	if (config_read(argv[1]) < 0) 
         {
                 fprintf(stderr, "Failed to read config file \"%s\"\n", argv[1]);
                 goto fail;

<p><p>No                   revision

<p>No                   revision

<p>1.3       +6 -6      ices/src/process.c

Index: process.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/process.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- process.c	2002/02/09 03:55:37	1.2
+++ process.c	2002/02/09 05:07:01	1.3
@@ -2,7 +2,7 @@
  * - Processing chains - data sources, sinks, processing effects, reencoding,
  *   etc.
  *
- * $Id: process.c,v 1.2 2002/02/09 03:55:37 msmith Exp $
+ * $Id: process.c,v 1.3 2002/02/09 05:07:01 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -100,9 +100,9 @@
             LOG_ERROR0("NULL input buffer where input required.");
             return -2;
         }
-
-        if(chain->input_type != MEDIA_NONE && in->type != chain->input_type) {
-            LOG_ERROR2("Chain input does not match expected input! (%d != %d",
+        else if(chain->input_type != MEDIA_NONE && chain->input_type != 
+                MEDIA_DATA && in->type != chain->input_type) {
+            LOG_ERROR2("Chain input does not match expected input! (%d != %d)",
                     in->type, chain->input_type);
             return -2;
         }
@@ -113,8 +113,8 @@
             return ret;
         }
 
-        if(chain->output_type != MEDIA_NONE &&  
-                (*out)->type != chain->output_type) {
+        if(chain->output_type != MEDIA_NONE && chain->output_type != MEDIA_DATA
+                 && (*out)->type != chain->output_type) {
             LOG_ERROR0("Chain did not produce expected output type.");
             return -2;
         }

<p><p>1.2       +5 -1      ices/src/registry.h

Index: registry.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/registry.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- registry.h	2002/02/07 09:11:12	1.1
+++ registry.h	2002/02/09 05:07:01	1.2
@@ -1,7 +1,7 @@
 /* registry.h
  * - Registry of input/output/processing modules.
  *
- * $Id: registry.h,v 1.1 2002/02/07 09:11:12 msmith Exp $
+ * $Id: registry.h,v 1.2 2002/02/09 05:07:01 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -36,11 +36,15 @@
         open_func open;
 } module;
 
+/* Some others we don't have headers for */
+int savefile_open_module(process_chain_element *mod, module_param_t *params);
+
 static module registered_modules[] = {
     { "encode", encode_open_module},
     { "stream", stream_open_module},
     { "playlist", playlist_open_module},
     { "stdinpcm", stdin_open_module}, 
+    { "savestream", savefile_open_module},
 #ifdef HAVE_OSS
     { "oss", oss_open_module}, 
 #endif

<p><p>No                   revision

<p>No                   revision

<p>1.3.2.2   +104 -54   ices/src/savefile.c

Index: savefile.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/savefile.c,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -r1.3.2.1 -r1.3.2.2
--- savefile.c	2002/02/07 09:11:12	1.3.2.1
+++ savefile.c	2002/02/09 05:07:01	1.3.2.2
@@ -1,7 +1,7 @@
 /* savefile.c
- * - Stream saving to file.
+ * - Save a stream to a file, for archival purposes
  *
- * $Id: savefile.c,v 1.3.2.1 2002/02/07 09:11:12 msmith Exp $
+ * $Id: savefile.c,v 1.3.2.2 2002/02/09 05:07:01 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -9,81 +9,131 @@
  * 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>
 #include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
 #include <string.h>
+#include <errno.h>
+#include <ogg/ogg.h>
+
+#include "thread.h"
 
 #include "config.h"
-#include "input.h"
-#include "inputmodule.h"
-#include "stream_shared.h"
 #include "stream.h"
 
-#define MODULE "stream-save/"
+#include "process.h"
+
+#define MODULE "savefile/"
 #include "logging.h"
 
+/* FIXME: Extend savefile to be able to create a new output file either 
+ * whenever a new stream is reached, or when a certain filesize is reached.
+ */
 
-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)
+typedef struct {
+    FILE *file;
+    char *filename;
+} savefile_state;
+
+static int event_handler(process_chain_element *mod, event_type ev, 
+        void *param)
+{
+	switch(ev)
         {
-		LOG_ERROR1("Couldn't open file to save stream: %s", filename);
-		stream->died = 1;
-		return NULL;
+		case EVENT_SHUTDOWN:
+			if(mod)
+			{
+				if(mod->priv_data) {
+                    if(((savefile_state *)mod->priv_data)->filename)
+                        free(((savefile_state *)mod->priv_data)->filename);
+					free(mod->priv_data);
+                }
+			}
+			break;
+		default:
+			return -1;
         }
 
-	LOG_INFO1("Saving stream to file: %s", filename);
+	return 0;
+}
 
-	while(1)
-	{
-		buf = stream_wait_for_data(stream);
+/* Core streaming function for this module
+ * This is what actually produces the data which gets streamed.
+ *
+ * returns:  >0  Number of bytes read
+ *            0  Non-fatal error.
+ *           <0  Fatal error.
+ */
+static int savefile_read(instance_t *instance, void *self, 
+        ref_buffer *in, ref_buffer **out)
+{
+	savefile_state *s = self;
+    int ret;
 
-		if(!buf)
-			break;
+    /* If this isn't set up right, don't cause errors... */
+    if(!s->file) {
+        *out = in;
+        return in->len;
+    }
+
+    ret = fwrite(in->buf, 1, in->len, s->file);
+
+    if(ret < in->len) {
+        if(ret >= 0)
+            LOG_WARN2("Could only write %d of %d bytes to savefile", 
+                ret, in->len);
+        else {
+            LOG_ERROR2("Error writing to savefile (%s): %s", s->filename, 
+                    strerror(errno));
+            return -1;
+        }
+    }
 
-		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;
-		}
+    *out = in;
+
+	return in->len;
+}
+
+int savefile_open_module(process_chain_element *mod, module_param_t *params)
+{
+	savefile_state *s;
+	module_param_t *current;
+
+    mod->name = "process-savefile";
+
+    /* We actually don't care what input and output are, so we use MEDIA_DATA */
+    mod->input_type = MEDIA_DATA;
+	mod->output_type = MEDIA_DATA;
+
+	mod->process = savefile_read;
+	mod->event_handler = event_handler;
+
+	mod->priv_data = calloc(1, sizeof(savefile_state));
+	s = mod->priv_data;
+
+	current = params;
+
+	while(current)
+	{
+		if(!strcmp(current->name, "filename"))
+			s->filename = strdup(current->value);
+		else
+			LOG_WARN1("Unknown parameter %s for savefile module",current->name);
 
-		stream_release_buffer(buf);
+		current = current->next;
         }
+    config_free_params(params);
 
-	fclose(file);
+    s->file = fopen(s->filename, "wb");
+    if(!s->file)
+        LOG_ERROR2("Error opening file for savefile %s: %s", s->filename, 
+                strerror(errno));
+    else
+        LOG_INFO1("Opened file %s for savestream", s->filename);
 
-	stream->died = 1;
-	return NULL;
+	return 0;
 }
-	
-		
-		
 
 

<p><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