[xiph-cvs] cvs commit: log log.c

Michael Smith msmith at xiph.org
Fri Nov 9 20:47:25 PST 2001



msmith      01/11/09 20:47:25

  Modified:    src      config.h encode.c input.c reencode.c stream.c
                        stream_rewrite.c
               .        log.c
  Log:
  Major stability fixes, to make things work better on bad input. Stops some
  memory leaks too, I think.

Revision  Changes    Path
1.8       +4 -1      ices/src/config.h

Index: config.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/config.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- config.h	2001/10/21 02:10:08	1.7
+++ config.h	2001/11/10 04:47:24	1.8
@@ -1,7 +1,7 @@
 /* config.h
  * - configuration, and global structures built from config
  *
- * $Id: config.h,v 1.7 2001/10/21 02:10:08 jack Exp $
+ * $Id: config.h,v 1.8 2001/11/10 04:47:24 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -52,7 +52,10 @@
         int died;
         int kill;
         int skip;
+    int wait_for_critical;
+
         struct buffer_queue *queue;
+
         struct _instance_tag *next;
 } instance_t;
 

1.3       +3 -3      ices/src/encode.c

Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/encode.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- encode.c	2001/09/25 12:04:21	1.2
+++ encode.c	2001/11/10 04:47:24	1.3
@@ -1,7 +1,7 @@
 /* encode.c
  * - runtime encoding of PCM data.
  *
- * $Id: encode.c,v 1.2 2001/09/25 12:04:21 msmith Exp $
+ * $Id: encode.c,v 1.3 2001/11/10 04:47:24 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -27,9 +27,9 @@
 
 void encode_clear(encoder_state *s)
 {
-	LOG_DEBUG0("Clearing encoder engine");
         if(s)
         {
+	    LOG_DEBUG0("Clearing encoder engine");
                 ogg_stream_clear(&s->os);
                 vorbis_block_clear(&s->vb);
                 vorbis_dsp_clear(&s->vd);
@@ -44,7 +44,7 @@
         encoder_state *s = calloc(1, sizeof(encoder_state));
         ogg_packet h1,h2,h3;
 
-	LOG_DEBUG3("Setting up encode at %d channels, %d Hz, bitrate %d", 
+	LOG_INFO3("Encoder initialising at %d channels, %d Hz, bitrate %d", 
                         channels, rate, bitrate);
 
         vorbis_info_init(&s->vi);

1.11      +73 -47    ices/src/input.c

Index: input.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/input.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- input.c	2001/10/21 02:10:08	1.10
+++ input.c	2001/11/10 04:47:24	1.11
@@ -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.10 2001/10/21 02:10:08 jack Exp $
+ * $Id: input.c,v 1.11 2001/11/10 04:47:24 msmith Exp $
  * 
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -92,15 +92,17 @@
         if(sleep > 0) timing_sleep(sleep);
 }
 
-static void _calculate_pcm_sleep(ref_buffer *buf, timing_control *control)
+static int _calculate_pcm_sleep(ref_buffer *buf, timing_control *control)
 {
         if(control->starttime == 0)
                 control->starttime = timing_get_time();
 
         control->senttime += ((double)buf->len * 1000000.)/((double)buf->aux_data);
+
+    return 0;
 }
 
-static void _calculate_ogg_sleep(ref_buffer *buf, timing_control *control)
+static int _calculate_ogg_sleep(ref_buffer *buf, timing_control *control)
 {
         /* Largely copied from shout_send_data(), without the sending happening.*/
         ogg_stream_state os;
@@ -108,6 +110,7 @@
         ogg_packet op;
         vorbis_info vi;
         vorbis_comment vc;
+    int ret = 0;
 
         if(control->starttime == 0)
                 control->starttime = timing_get_time();
@@ -128,9 +131,16 @@
 
                 vorbis_info_init(&vi);
                 vorbis_comment_init(&vc);
-		vorbis_synthesis_headerin(&vi, &vc, &op);
 
-		control->samplerate = vi.rate;
+		if(vorbis_synthesis_headerin(&vi, &vc, &op) < 0) 
+        {
+            LOG_ERROR0("Timing control: can't determine sample rate for input, "
+                       "not vorbis.");
+            control->samplerate = 0;
+            ret = -1;
+        }
+        else
+		    control->samplerate = vi.rate;
 
                 vorbis_comment_clear(&vc);
                 vorbis_info_clear(&vi);
@@ -139,9 +149,12 @@
 
         control->samples = ogg_page_granulepos(&og) - control->oldsamples;
         control->oldsamples = ogg_page_granulepos(&og);
+
+    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)
@@ -211,6 +224,7 @@
         queue_item *queued;
         int shutdown = 0;
         int current_module = 0;
+    int valid_stream = 1;
 
         while(ices_config->playlist_module && modules[current_module].open)
         {
@@ -342,53 +356,63 @@
                         continue;
                 }
 
+        if(chunk->critical)
+            valid_stream = 1;
+
                 /* figure out how much time the data represents */
                 switch(inmod->type)
                 {
                         case ICES_INPUT_VORBIS:
-				_calculate_ogg_sleep(chunk, control);
+				ret = _calculate_ogg_sleep(chunk, control);
                                 break;
                         case ICES_INPUT_PCM:
-				_calculate_pcm_sleep(chunk, control);
+				ret = _calculate_pcm_sleep(chunk, control);
                                 break;
                 }
-
-		while(instance)
-		{
-			if(instance->skip)
-			{
-				instance = instance->next;
-				continue;
-			}
 
-			queued = malloc(sizeof(queue_item));
+        if(ret < 0)
+            valid_stream = 0;
 
-			queued->buf = chunk;
-			current = instance->queue;
-
-			thread_mutex_lock(&ices_config->refcount_lock);
-			chunk->count++;
-			thread_mutex_unlock(&ices_config->refcount_lock);
-
-			thread_mutex_lock(&current->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;
-			}
-
-			current->length++;
-			thread_mutex_unlock(&current->lock);
-
-			instance = instance->next;
-		}
+        if(valid_stream) 
+        {
+    		while(instance)
+	    	{
+		    	if(instance->skip || 
+                        (instance->wait_for_critical && !chunk->critical))
+	    		{
+		    		instance = instance->next;
+			    	continue;
+    			}
+    
+	    		queued = malloc(sizeof(queue_item));
+    
+	    		queued->buf = chunk;
+    			current = instance->queue;
+    
+	    		thread_mutex_lock(&ices_config->refcount_lock);
+		    	chunk->count++;
+			    thread_mutex_unlock(&ices_config->refcount_lock);
+    
+	    		thread_mutex_lock(&current->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;
+	    		}
+
+		    	current->length++;
+			    thread_mutex_unlock(&current->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
@@ -402,10 +426,12 @@
                 }
                 thread_mutex_unlock(&ices_config->refcount_lock);
 
-		/* wake up the instances */
-		thread_cond_broadcast(&ices_config->queue_cond);
+        if(valid_stream) {
+    		/* wake up the instances */
+	    	thread_cond_broadcast(&ices_config->queue_cond);
 
-		_sleep(control);
+		    _sleep(control);
+        }
         }
 
         LOG_DEBUG0("All instances removed, shutting down control thread.");

1.3       +3 -1      ices/src/reencode.c

Index: reencode.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/reencode.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- reencode.c	2001/09/25 12:04:22	1.2
+++ reencode.c	2001/11/10 04:47:24	1.3
@@ -1,7 +1,7 @@
 /* reencode.c
  * - runtime reencoding of vorbis audio (usually to lower bitrates).
  *
- * $Id: reencode.c,v 1.2 2001/09/25 12:04:22 msmith Exp $
+ * $Id: reencode.c,v 1.3 2001/11/10 04:47:24 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -43,6 +43,7 @@
 {
         if(s) 
         {
+        LOG_DEBUG0("Clearing reencoder");
                 ogg_stream_clear(&s->os);
                 vorbis_block_clear(&s->vb);
                 vorbis_dsp_clear(&s->vd);
@@ -89,6 +90,7 @@
                         }
                 }
                 encode_clear(s->encoder);
+        s->encoder = NULL;
 
                 ogg_stream_clear(&s->os);
                 ogg_stream_init(&s->os, s->current_serial);

1.9       +18 -2     ices/src/stream.c

Index: stream.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- stream.c	2001/11/07 13:30:03	1.8
+++ stream.c	2001/11/10 04:47:24	1.9
@@ -1,7 +1,7 @@
 /* stream.c
  * - Core streaming functions/main loop.
  *
- * $Id: stream.c,v 1.8 2001/11/07 13:30:03 msmith Exp $
+ * $Id: stream.c,v 1.9 2001/11/10 04:47:24 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -133,6 +133,12 @@
                                 continue; 
                         }
 
+            if(stream->wait_for_critical)
+            {
+                LOG_INFO0("Trying restart on new substream");
+                stream->wait_for_critical = 0;
+            }
+
             ret = process_and_send_buffer(sdsc, buffer);
 
             /* No data produced, do nothing */
@@ -140,7 +146,17 @@
                 ;
             /* Fatal error */
             else if(ret == -2)
-                stream->buffer_failures = MAX_ERRORS+1;
+            {
+                LOG_ERROR0("Serious error, waiting to restart on "
+                           "next substream. Stream temporarily suspended.");
+                /* Set to wait until a critical buffer comes through (start of
+                 * a new substream, typically), and flush existing queue.
+                 */
+                thread_mutex_lock(&ices_config->flush_lock);
+                stream->wait_for_critical = 1;
+                input_flush_queue(stream->queue, 0);
+                thread_mutex_unlock(&ices_config->flush_lock);
+            }
             /* Non-fatal shout error */
             else if(ret == 0)
                         {

1.3       +6 -6      ices/src/stream_rewrite.c

Index: stream_rewrite.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream_rewrite.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- stream_rewrite.c	2001/10/21 16:17:14	1.2
+++ stream_rewrite.c	2001/11/10 04:47:24	1.3
@@ -5,7 +5,7 @@
  *
  * Heavily based on vcedit.c from vorbiscomment.
  *
- * $Id: stream_rewrite.c,v 1.2 2001/10/21 16:17:14 jack Exp $
+ * $Id: stream_rewrite.c,v 1.3 2001/11/10 04:47:24 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -51,9 +51,9 @@
 /* Next two functions pulled straight from libvorbis, apart from one change
  * - we don't want to overwrite the vendor string.
  */
-static void _v_writestring(oggpack_buffer *o,char *s)
+static void _v_writestring(oggpack_buffer *o,char *s, int len)
 {
-	while(*s)
+	while(len--)
         {
                 oggpack_write(o,*s++,8);
         }
@@ -67,11 +67,11 @@
 
         /* preamble */  
         oggpack_write(&opb,0x03,8);
-	_v_writestring(&opb,"vorbis");
+	_v_writestring(&opb,"vorbis", 6);
 
         /* vendor */
         oggpack_write(&opb,strlen(vendor),32);
-	_v_writestring(&opb,vendor);
+	_v_writestring(&opb,vendor, strlen(vendor));
 
         /* comments */
         oggpack_write(&opb,vc->comments,32);
@@ -80,7 +80,7 @@
                 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]);
+				_v_writestring(&opb,vc->user_comments[i], vc->comment_lengths[i]);
                         }else{
                                 oggpack_write(&opb,0,32);
                         }

1.5       +1 -1      log/log.c

Index: log.c
===================================================================
RCS file: /usr/local/cvsroot/log/log.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- log.c	2001/10/20 16:47:01	1.4
+++ log.c	2001/11/10 04:47:25	1.5
@@ -161,7 +161,7 @@
         vsnprintf(line, LOG_MAXLINELEN, fmt, ap);
 
         now = time(NULL);
-	strftime(tyme, 128, "[%Y-%m-%d  %H:%M:%S]", gmtime(&now)); 
+	strftime(tyme, 128, "[%Y-%m-%d  %H:%M:%S]", localtime(&now)); 
 
         snprintf(pre, 256, "%s %s", prior[priority-1], cat);
 

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