[xiph-cvs] cvs commit: ices/src stream.c

Brendan brendan at xiph.org
Thu Mar 13 15:29:11 PST 2003



brendan     03/03/13 18:29:11

  Modified:    .        BUGS
               src      stream.c
  Log:
  Finally did the math on MP3 buffer sizes. It should be much harder to overrun
  buffers now.
  
  Later I may wish to only read a max of n samples per loop, but that is only
  a memory usage optimisation and may not be worth the trouble.

Revision  Changes    Path
1.6       +1 -2      ices/BUGS

Index: BUGS
===================================================================
RCS file: /cvs/ice/ices/BUGS,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BUGS	11 Mar 2003 23:15:46 -0000	1.5
+++ BUGS	13 Mar 2003 23:29:11 -0000	1.6
@@ -1,3 +1,2 @@
 * Handles error conditions poorly.
-* Unreliable at reencoding VBR files (fixed?)
-* May crash when reencoding if bad input is fed to the lame library.
+* Doesn't update metadata on server on reconnect until next track.
\ No newline at end of file

<p><p>1.50      +29 -17    ices/src/stream.c

Index: stream.c
===================================================================
RCS file: /cvs/ice/ices/src/stream.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- stream.c	13 Mar 2003 05:32:47 -0000	1.49
+++ stream.c	13 Mar 2003 23:29:11 -0000	1.50
@@ -38,7 +38,7 @@
 #endif
 
 #define INPUT_BUFSIZ 4096
-#define OUTPUT_BUFSIZ 8192
+#define OUTPUT_BUFSIZ 32768
 /* sleep this long in ms when every stream has errors */
 #define ERROR_DELAY 999
 
@@ -175,8 +175,9 @@
 #ifdef HAVE_LIBLAME
   int decode = 0;
   buffer_t obuf;
-  static int16_t left[INPUT_BUFSIZ * 30];
-  static int16_t right[INPUT_BUFSIZ * 30];
+  /* worst case decode: 22050 Hz at 8kbs = 44.1 samples/byte */
+  static int16_t left[INPUT_BUFSIZ * 45];
+  static int16_t right[INPUT_BUFSIZ * 45];
 #endif
 
 #ifdef HAVE_LIBLAME
@@ -189,13 +190,16 @@
       if (stream->bitrate != source->bitrate) {
         decode = 1;
         ices_reencode_reset (source);
-        if (!(obuf.data = malloc(OUTPUT_BUFSIZ))) {
-	  ices_log_error("Error allocating output buffer");
-	  return -1;
-	}
-	obuf.len = OUTPUT_BUFSIZ;
         break;
       }
+
+    if (decode) {
+      obuf.len = OUTPUT_BUFSIZ;
+      if (!(obuf.data = malloc(OUTPUT_BUFSIZ))) {
+        ices_log_error("Error allocating encode buffer");
+	return -1;
+      }
+    }
 #endif
 
   for (stream = config->streams; stream; stream = stream->next)
@@ -226,30 +230,37 @@
           /* don't reencode if the source is MP3 and the same bitrate */
           if (!stream->reencode || (source->read &&
                                     (stream->bitrate == source->bitrate))) {
-	    shout_sync(stream->conn);
             rc = stream_send_data (stream, ibuf, len);
           }
 #ifdef HAVE_LIBLAME
           else {
             if (samples > 0) {
-	      while ((olen = ices_reencode (stream, samples, left, right, obuf.data,
-	          obuf.len)) == -1) {
-	        char* tmpbuf;
+	      if (obuf.len < 7200 + samples + samples / 4) {
+	        char *tmpbuf;
 
-                if (!(tmpbuf = realloc(obuf.data, obuf.len + OUTPUT_BUFSIZ))) {
+		/* pessimistic estimate from lame.h */
+                obuf.len = 7200 + 5 * samples / 2;
+		if (!(tmpbuf = realloc(obuf.data, obuf.len))) {
                   ices_log_error ("Error growing output buffer, aborting track");
                   goto err;
                 }
                 obuf.data = tmpbuf;
-		obuf.len += OUTPUT_BUFSIZ;
                 ices_log_debug ("Grew output buffer to %d bytes", obuf.len);
               }
-
-	      if (olen < 0) {
+	      if ((olen = ices_reencode (stream, samples, left, right, obuf.data,
+	          obuf.len)) < -1) {
                 ices_log_error ("Reencoding error, aborting track");
                 goto err;
+	      } else if (olen == -1) {
+	        char *tmpbuf;
+
+		if ((tmpbuf = realloc(obuf.data, obuf.len + OUTPUT_BUFSIZ))) {
+                  obuf.data = tmpbuf;
+		  obuf.len += OUTPUT_BUFSIZ;
+		  ices_log_debug ("Grew output buffer to %d bytes", obuf.len);
+		} else
+		  ices_log_debug ("%d byte output buffer is too small", obuf.len);
               } else if (olen > 0) {
-                shout_sync(stream->conn);
                 rc = stream_send_data (stream, obuf.data, olen);
               }
             }
@@ -369,6 +380,7 @@
     rc = stream_connect (stream);
 
   if (shout_get_connected (stream->conn) == SHOUTERR_CONNECTED) {
+    shout_sync(stream->conn);
     if (shout_send (stream->conn, buf, len) == SHOUTERR_SUCCESS) {
       stream->errs = 0;
       rc = 0;

<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