[xiph-cvs] cvs commit: ices/src icestypes.h mp3.c reencode.c stream.c

Brendan brendan at xiph.org
Sun Mar 16 20:45:04 PST 2003



brendan     03/03/16 23:45:04

  Modified:    src      icestypes.h mp3.c reencode.c stream.c
  Log:
  Better check for whether a source needs reencoding.

Revision  Changes    Path
1.23      +1 -0      ices/src/icestypes.h

Index: icestypes.h
===================================================================
RCS file: /cvs/ice/ices/src/icestypes.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- icestypes.h	16 Mar 2003 08:32:34 -0000	1.22
+++ icestypes.h	17 Mar 2003 04:45:03 -0000	1.23
@@ -103,6 +103,7 @@
   size_t bytes_read;
   unsigned int bitrate;
   unsigned int samplerate;
+  unsigned int channels;
 
   void* data;
 

<p><p>1.31      +2 -1      ices/src/mp3.c

Index: mp3.c
===================================================================
RCS file: /cvs/ice/ices/src/mp3.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- mp3.c	17 Mar 2003 02:22:38 -0000	1.30
+++ mp3.c	17 Mar 2003 04:45:03 -0000	1.31
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Id: mp3.c,v 1.30 2003/03/17 02:22:38 brendan Exp $
+ * $Id: mp3.c,v 1.31 2003/03/17 04:45:03 brendan Exp $
  */
 
 #include "definitions.h"
@@ -149,6 +149,7 @@
 
         source->samplerate = mh.samplerate;
         source->bitrate = mh.bitrate;
+        source->channels = mh.channels;
 
         if (mp3_check_vbr (source, &mh)) {
           source->bitrate = 0;

<p><p>1.21      +5 -1      ices/src/reencode.c

Index: reencode.c
===================================================================
RCS file: /cvs/ice/ices/src/reencode.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- reencode.c	13 Mar 2003 20:51:36 -0000	1.20
+++ reencode.c	17 Mar 2003 04:45:03 -0000	1.21
@@ -98,7 +98,7 @@
     if (stream->out_samplerate > 0)
       lame_set_out_samplerate (lame, stream->out_samplerate);
     lame_set_original (lame, 0);
-
+    
     lame_set_in_samplerate (lame, source->samplerate);
     /* lame_init_params isn't more specific about the problem */
     if (lame_init_params (lame) < 0) {
@@ -106,6 +106,10 @@
       lame_close (lame);
       ices_setup_shutdown ();
     }
+
+    /* adjust default stream sample rate to LAME default for lazy reencoding tests */
+    if (stream->out_samplerate <= 0)
+      stream->out_samplerate = lame_get_out_samplerate (lame);
   }
 }
 

<p><p>1.52      +24 -16    ices/src/stream.c

Index: stream.c
===================================================================
RCS file: /cvs/ice/ices/src/stream.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- stream.c	16 Mar 2003 08:32:34 -0000	1.51
+++ stream.c	17 Mar 2003 04:45:03 -0000	1.52
@@ -55,6 +55,7 @@
 static int stream_send_data (ices_stream_t* stream, unsigned char* buf,
                              size_t len);
 static int stream_open_source (input_stream_t* source);
+static int stream_needs_reencoding (input_stream_t* source, ices_stream_t* stream);
 
 /* Public function definitions */
 
@@ -177,22 +178,22 @@
   obuf.data = NULL;
   obuf.len = 0;
 
-  if (config->reencode)
-    /* only actually decode/reencode if the bitrate of the stream != source */
+  if (config->reencode) {
+    ices_reencode_reset (source);
     for (stream = config->streams; stream; stream = stream->next)
-      if (stream->bitrate != source->bitrate) {
+      if (stream->reencode && stream_needs_reencoding (source, stream)) {
         decode = 1;
-        ices_reencode_reset (source);
         break;
       }
+  }
 
-    if (decode) {
-      obuf.len = OUTPUT_BUFSIZ;
-      if (!(obuf.data = malloc(OUTPUT_BUFSIZ))) {
-        ices_log_error("Error allocating encode buffer");
-        return -1;
-      }
+  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)
@@ -230,10 +231,8 @@
       rc = olen = 0;
       for (stream = config->streams; stream; stream = stream->next) {
         /* don't reencode if the source is MP3 and the same bitrate */
-        if (!stream->reencode || (source->read && (stream->bitrate == source->bitrate))) {
-          rc = stream_send_data (stream, ibuf, len);
 #ifdef HAVE_LIBLAME
-        } else {
+        if (stream->reencode && stream_needs_reencoding (source, stream)) {
           if (samples > 0) {
             if (obuf.len < 7200 + samples + samples / 4) {
               char *tmpbuf;
@@ -264,8 +263,9 @@
               rc = stream_send_data (stream, obuf.data, olen);
             }
           }
-        }
+        } else
 #endif
+          rc = stream_send_data (stream, ibuf, len);
 
         if (rc < 0) {
           if (stream->errs > 10) {
@@ -292,8 +292,7 @@
 
 #ifdef HAVE_LIBLAME
   for (stream = config->streams; stream; stream = stream->next)
-    if (stream->reencode && (!source->read
-        || (source->bitrate != stream->bitrate))) {
+    if (stream->reencode && stream_needs_reencoding (source, stream)) {
       len = ices_reencode_flush (stream, obuf.data, obuf.len);
       if (len > 0)
         rc = shout_send (stream->conn, obuf.data, len);
@@ -412,6 +411,15 @@
   ices_log ("Mounted on http://%s:%d%s%s", shout_get_host (stream->conn),
             shout_get_port (stream->conn),
             (mount && mount[0] == '/') ? "" : "/", ices_util_nullcheck (mount));
+
+  return 0;
+}
+
+static int stream_needs_reencoding (input_stream_t* source, ices_stream_t* stream) {
+    if (!source->read || source->bitrate != stream->bitrate
+        || (stream->out_samplerate > 0 && source->samplerate != stream->out_samplerate)
+        || (stream->out_numchannels > 0 && source->channels != stream->out_numchannels))
+      return 1;
 
   return 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