[xiph-cvs] cvs commit: ices/src encode.c im_oss.c im_playlist.c im_stdinpcm.c input.c output.c process.c process.h

Michael Smith msmith at xiph.org
Fri Feb 8 19:55:39 PST 2002



msmith      02/02/08 19:55:38

  Modified:    src      Tag: branch-beta2-rewrite encode.c im_oss.c
                        im_playlist.c im_stdinpcm.c input.c No tag output.c
                        process.c process.h
  Log:
  Make encoder work right when on input chain.

Revision  Changes    Path
No                   revision

<p>No                   revision

<p>1.6.2.4   +24 -9     ices/src/encode.c

Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/encode.c,v
retrieving revision 1.6.2.3
retrieving revision 1.6.2.4
diff -u -r1.6.2.3 -r1.6.2.4
--- encode.c	2002/02/08 12:54:08	1.6.2.3
+++ encode.c	2002/02/09 03:55:36	1.6.2.4
@@ -1,7 +1,7 @@
 /* encode.c
  * - runtime encoding of PCM data.
  *
- * $Id: encode.c,v 1.6.2.3 2002/02/08 12:54:08 msmith Exp $
+ * $Id: encode.c,v 1.6.2.4 2002/02/09 03:55:36 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -70,14 +70,24 @@
 
 }
 
-static void append_page(ref_buffer *buf, ogg_page *page)
+static ref_buffer *append_page(ref_buffer *buf, ogg_page *page, int *aux_avail)
 {
     int old = buf->len;
     buf->len += page->header_len + page->body_len;
     buf->buf = realloc(buf->buf, buf->len);
     memcpy(buf->buf + old, page->header, page->header_len);
     memcpy(buf->buf + old + page->header_len, page->body, page->body_len);
-    buf->aux_data = -1;
+    if(*aux_avail < 2) {
+        *aux_avail += 8;
+        buf = realloc(buf, sizeof(ref_buffer) + 
+                (buf->aux_data_len + *aux_avail)*sizeof(int));
+    }
+
+    buf->aux_data[buf->aux_data_len++] = page->header_len;
+    buf->aux_data[buf->aux_data_len++] = page->body_len;
+    *aux_avail -= 2;
+
+    return buf;
 }
 
 static int encode_flush(encoder_state *s, ogg_page *og)
@@ -263,6 +273,7 @@
 {
     encoder_state *enc = self;
     ogg_page page;
+    int aux_avail;
 
     *out = NULL;
 
@@ -270,9 +281,11 @@
         if(enc->initialised) {
             encode_finish(enc);
             while(encode_flush(enc, &page) > 0) {
-                if(*out == NULL)
-                    *out = new_ref_buffer(MEDIA_VORBIS, NULL, 0);
-                append_page(*out, &page);
+                if(*out == NULL) {
+                    *out = new_ref_buffer(MEDIA_VORBIS, NULL, 0, 4);
+                    aux_avail = 4;
+                }
+                *out = append_page(*out, &page, &aux_avail);
             }
             /* FIXME: rewrite the below func. 
             encode_clear(enc);
@@ -295,9 +308,11 @@
     }
 
     while(encode_dataout(enc, &page) > 0) {
-        if(*out == NULL)
-            *out = new_ref_buffer(MEDIA_VORBIS, NULL, 0);
-        append_page(*out, &page);
+        if(*out == NULL) {
+            *out = new_ref_buffer(MEDIA_VORBIS, NULL, 0, 4);
+            aux_avail = 4;
+        }
+        *out = append_page(*out, &page, &aux_avail);
     }
 
     release_buffer(in);

<p><p>1.5.2.2   +4 -2      ices/src/im_oss.c

Index: im_oss.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_oss.c,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -r1.5.2.1 -r1.5.2.2
--- im_oss.c	2002/02/07 09:11:11	1.5.2.1
+++ im_oss.c	2002/02/09 03:55:36	1.5.2.2
@@ -1,7 +1,7 @@
 /* im_oss.c
  * - Raw PCM input from OSS devices
  *
- * $Id: im_oss.c,v 1.5.2.1 2002/02/07 09:11:11 msmith Exp $
+ * $Id: im_oss.c,v 1.5.2.2 2002/02/09 03:55:36 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -116,7 +116,7 @@
         im_oss_state *s = self;
     ref_buffer *rb;
     
-    rb = new_ref_buffer(MEDIA_PCM, NULL, 0);
+    rb = new_ref_buffer(MEDIA_PCM, NULL, 0, 1);
     *out = rb;
 
         rb->buf = malloc(BUFSIZE*2*s->channels);
@@ -126,6 +126,8 @@
     rb->subtype = SUBTYPE_PCM_LE_16;
     rb->channels = s->channels;
     rb->rate = s->rate;
+    rb->aux_data[0] = s->rate*s->channels*2;
+    rb->aux_data_len = 1;
 
         if(s->newtrack)
         {

<p><p>1.3.2.2   +5 -3      ices/src/im_playlist.c

Index: im_playlist.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_playlist.c,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -r1.3.2.1 -r1.3.2.2
--- im_playlist.c	2002/02/07 09:11:11	1.3.2.1
+++ im_playlist.c	2002/02/09 03:55:36	1.3.2.2
@@ -1,7 +1,7 @@
 /* playlist.c
  * - Basic playlist functionality
  *
- * $Id: im_playlist.c,v 1.3.2.1 2002/02/07 09:11:11 msmith Exp $
+ * $Id: im_playlist.c,v 1.3.2.2 2002/02/09 03:55:36 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -159,11 +159,13 @@
                 {
             void *buf = malloc(og.header_len + og.body_len);
             *out = new_ref_buffer(MEDIA_VORBIS, buf, 
-                    og.header_len + og.body_len);
+                    og.header_len + og.body_len, 2);
 
-			(*out)->aux_data = og.header_len;
             (*out)->channels = -1; /* We don't know yet, and it's unimportant */
             (*out)->rate = -1;
+            (*out)->aux_data[0] = og.header_len;
+            (*out)->aux_data[1] = og.body_len;
+            (*out)->aux_data_len = 2;
 
                         memcpy((*out)->buf, og.header, og.header_len);
                         memcpy((*out)->buf+og.header_len, og.body, og.body_len);

<p><p>1.2.2.4   +4 -3      ices/src/im_stdinpcm.c

Index: im_stdinpcm.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_stdinpcm.c,v
retrieving revision 1.2.2.3
retrieving revision 1.2.2.4
diff -u -r1.2.2.3 -r1.2.2.4
--- im_stdinpcm.c	2002/02/08 12:54:08	1.2.2.3
+++ im_stdinpcm.c	2002/02/09 03:55:36	1.2.2.4
@@ -1,7 +1,7 @@
 /* im_stdinpcm.c
  * - Raw PCM input from stdin
  *
- * $Id: im_stdinpcm.c,v 1.2.2.3 2002/02/08 12:54:08 msmith Exp $
+ * $Id: im_stdinpcm.c,v 1.2.2.4 2002/02/09 03:55:36 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -67,7 +67,7 @@
         stdinpcm_state *s = self;
     ref_buffer *rb;
 
-    rb = new_ref_buffer(MEDIA_PCM, NULL, 0);
+    rb = new_ref_buffer(MEDIA_PCM, NULL, 0, 1);
 
         rb->buf = malloc(BUFSIZE);
         result = fread(rb->buf, 1,BUFSIZE, stdin);
@@ -76,7 +76,8 @@
     rb->rate = s->rate;
     rb->channels = s->channels;
     rb->subtype = SUBTYPE_PCM_LE_16;
-    rb->aux_data = s->rate*s->channels*2;
+    rb->aux_data[0] = s->rate*s->channels*2;
+    rb->aux_data_len = 1;
 
         if(s->newtrack)
         {

<p><p>1.12.2.4  +27 -15    ices/src/input.c

Index: input.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/input.c,v
retrieving revision 1.12.2.3
retrieving revision 1.12.2.4
diff -u -r1.12.2.3 -r1.12.2.4
--- input.c	2002/02/08 12:54:08	1.12.2.3
+++ input.c	2002/02/09 03:55:36	1.12.2.4
@@ -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.12.2.3 2002/02/08 12:54:08 msmith Exp $
+ * $Id: input.c,v 1.12.2.4 2002/02/09 03:55:36 msmith Exp $
  * 
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -68,16 +68,16 @@
         if(control->starttime == 0)
                 control->starttime = timing_get_time();
 
-	control->senttime += ((double)buf->len * 1000000.)/((double)buf->aux_data);
+	control->senttime += ((double)buf->len * 1000000.)/
+        ((double)buf->aux_data[0]);
 
     return 0;
 }
 
-static int _calculate_ogg_sleep(ref_buffer *buf, timing_control *control)
+static int _calculate_ogg_sleep_page(timing_control *control, ogg_page *og)
 {
         /* Largely copied from shout_send(), without the sending happening.*/
         ogg_stream_state os;
-	ogg_page og;
         ogg_packet op;
         vorbis_info vi;
         vorbis_comment vc;
@@ -85,14 +85,9 @@
         if(control->starttime == 0)
                 control->starttime = timing_get_time();
 
-	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(control->serialno != ogg_page_serialno(&og)) {
-        LOG_DEBUG1("New ogg stream, serial %d", ogg_page_serialno(&og));
-		control->serialno = ogg_page_serialno(&og);
+	if(control->serialno != ogg_page_serialno(og)) {
+        LOG_DEBUG1("New ogg stream, serial %d", ogg_page_serialno(og));
+		control->serialno = ogg_page_serialno(og);
 
                 control->oldsamples = 0;
 
@@ -100,7 +95,7 @@
                 vorbis_info_init(&vi);
                 vorbis_comment_init(&vc);
 
-        if(ogg_stream_pagein(&os, &og) < 0) {
+        if(ogg_stream_pagein(&os, og) < 0) {
             LOG_ERROR0("Error submitting page to libogg");
             goto fail;
         }
@@ -127,8 +122,8 @@
                 ogg_stream_clear(&os);
         }
 
-	control->samples = ogg_page_granulepos(&og) - control->oldsamples;
-	control->oldsamples = ogg_page_granulepos(&og);
+	control->samples = ogg_page_granulepos(og) - control->oldsamples;
+	control->oldsamples = ogg_page_granulepos(og);
 
     if(control->samplerate) 
             control->senttime += ((double)control->samples * 1000000 / 
@@ -141,6 +136,23 @@
     vorbis_info_clear(&vi);
     ogg_stream_clear(&os);
     return -1;
+}
+
+static int _calculate_ogg_sleep(ref_buffer *buf, timing_control *control)
+{
+	ogg_page og;
+    int ret,i;
+
+    for(i=0; i < buf->aux_data_len; i += 2) {
+	    og.header_len = buf->aux_data[i];
+    	og.body_len = buf->aux_data[i+1];
+	    og.header = buf->buf;
+    	og.body = buf->buf + og.header_len;
+
+        if((ret = _calculate_ogg_sleep_page(control, &og)) < 0)
+            return ret;
+    }
+    return 0;
 }
 
 void input_flush_queue(buffer_queue *queue, int keep_critical)

<p><p>No                   revision

<p>No                   revision

<p>1.2       +2 -4      ices/src/output.c

Index: output.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/output.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- output.c	2002/02/07 09:11:12	1.1
+++ output.c	2002/02/09 03:55:37	1.2
@@ -1,7 +1,7 @@
 /* output.c
  * - Manage output instances
  *
- * $Id: output.c,v 1.1 2002/02/07 09:11:12 msmith Exp $
+ * $Id: output.c,v 1.2 2002/02/09 03:55:37 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -84,10 +84,8 @@
     while(1) {
         in = instance_wait_for_data(instance);
 
-        if(!in) {
-            LOG_DEBUG0("null buffer from feeder");
+        if(!in)
             break;
-        }
 
         if(!in->buf || in->len <= 0) {
             LOG_WARN0("Bad buffer dequeued.");

<p><p>1.2       +3 -3      ices/src/process.c

Index: process.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/process.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- process.c	2002/02/07 09:11:12	1.1
+++ process.c	2002/02/09 03:55:37	1.2
@@ -2,7 +2,7 @@
  * - Processing chains - data sources, sinks, processing effects, reencoding,
  *   etc.
  *
- * $Id: process.c,v 1.1 2002/02/07 09:11:12 msmith Exp $
+ * $Id: process.c,v 1.2 2002/02/09 03:55:37 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -29,9 +29,9 @@
 
 
 /* Return a newly allocate buffer, with refcount initialised to 1. */
-ref_buffer *new_ref_buffer(media_type media, void *data, int len)
+ref_buffer *new_ref_buffer(media_type media, void *data, int len, int aux)
 {
-    ref_buffer *new = calloc(1, sizeof(ref_buffer));
+    ref_buffer *new = calloc(1, sizeof(ref_buffer) + (sizeof(int)*(aux-1)));
     new->type = media;
     new->buf = data;
     new->len = len;

<p><p>1.2       +5 -4      ices/src/process.h

Index: process.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/process.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- process.h	2002/02/07 09:11:12	1.1
+++ process.h	2002/02/09 03:55:37	1.2
@@ -1,7 +1,7 @@
 /* process.h
  * - Processing chains
  *
- * $Id: process.h,v 1.1 2002/02/07 09:11:12 msmith Exp $
+ * $Id: process.h,v 1.2 2002/02/09 03:55:37 msmith Exp $
  *
  * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -42,12 +42,13 @@
     int rate;
 
         void *buf;            /* Actual data */
-	long len;             /* Length of data (usually bytes, sometimes samples */
+	int len;             /* Length of data (usually bytes, sometimes samples */
 
         short count;          /* Reference count */
 
         buffer_flags flags;   /* Flag: critical chunks must be processed fully */
-	long aux_data;        /* Auxilliary data used for various purposes */
+    int aux_data_len;
+	long aux_data[1];     /* Auxilliary data used for various purposes */
 } ref_buffer;
 
 /* Need some forward declarations */
@@ -96,7 +97,7 @@
 int process_chain(struct _instance_t *instance, process_chain_element *chain,
         ref_buffer *in, ref_buffer **out);
 
-ref_buffer *new_ref_buffer(media_type media, void *data, int len);
+ref_buffer *new_ref_buffer(media_type media, void *data, int len, int aux);
 void acquire_buffer(ref_buffer *buf);
 void release_buffer(ref_buffer *buf);
 

<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