[xiph-commits] r18383 - trunk/vorbis-tools/oggenc

tterribe at svn.xiph.org tterribe at svn.xiph.org
Tue Jun 12 19:17:09 PDT 2012


Author: tterribe
Date: 2012-06-12 19:17:09 -0700 (Tue, 12 Jun 2012)
New Revision: 18383

Modified:
   trunk/vorbis-tools/oggenc/audio.c
   trunk/vorbis-tools/oggenc/oggenc.c
Log:
Restore --ignorelength to working order.

This option was accidentally disconnected in r16793.
This patch restores the option's functionality, and allows the code
 to distinguish between an actual unknown length (totalframes==-1)
 and an empty file (totalframes==0).
Fixes #1803.


Modified: trunk/vorbis-tools/oggenc/audio.c
===================================================================
--- trunk/vorbis-tools/oggenc/audio.c	2012-06-13 01:59:26 UTC (rev 18382)
+++ trunk/vorbis-tools/oggenc/audio.c	2012-06-13 02:17:09 UTC (rev 18383)
@@ -332,7 +332,11 @@
         (format.samplesize == 16 || format.samplesize == 8))
     {
         /* From here on, this is very similar to the wav code. Oh well. */
-        
+        if(opt->ignorelength)
+        {
+            format.totalframes = -1;
+        }
+
         opt->rate = format.rate;
         opt->channels = format.channels;
         opt->read_samples = wav_read; /* Similar enough, so we use the same */
@@ -547,25 +551,34 @@
                                             of trying to abstract stuff. */
         wav->samplesize = format.samplesize;
 
-        if(len)
+        if(opt->ignorelength)
         {
-            opt->total_samples_per_channel = len/(format.channels*samplesize);
+            opt->total_samples_per_channel = -1;
         }
         else
         {
-            long pos;
-            pos = ftell(in);
-            if(fseek(in, 0, SEEK_END) == -1)
+            if(len)
             {
-                opt->total_samples_per_channel = 0; /* Give up */
+                opt->total_samples_per_channel =
+                    len/(format.channels*samplesize);
             }
             else
             {
-                opt->total_samples_per_channel = (ftell(in) - pos)/
-                    (format.channels*samplesize);
-                fseek(in,pos, SEEK_SET);
+                long pos;
+                pos = ftell(in);
+                if(fseek(in, 0, SEEK_END) == -1)
+                {
+                    opt->total_samples_per_channel = 0; /* Give up */
+                }
+                else
+                {
+                    opt->total_samples_per_channel = (ftell(in) - pos)/
+                        (format.channels*samplesize);
+                    fseek(in,pos, SEEK_SET);
+                }
             }
         }
+
         wav->totalsamples = opt->total_samples_per_channel;
 
         opt->readdata = (void *)wav;
@@ -601,7 +614,7 @@
     long realsamples;
     int *ch_permute = f->channel_permute;
 
-    if(f->totalsamples && f->samplesread + 
+    if(f->totalsamples > 0 && f->samplesread + 
             bytes_read/(sampbyte*f->channels) > f->totalsamples) {
         bytes_read = sampbyte*f->channels*(f->totalsamples - f->samplesread);
     }
@@ -684,7 +697,7 @@
     long realsamples;
 
 
-    if(f->totalsamples && f->samplesread +
+    if(f->totalsamples > 0 && f->samplesread +
             bytes_read/(4*f->channels) > f->totalsamples)
         bytes_read = 4*f->channels*(f->totalsamples - f->samplesread);
     realsamples = bytes_read/(4*f->channels);
@@ -724,14 +737,14 @@
     wav->bigendian =     opt->endianness;
     wav->channels =      format.channels;
     wav->samplesize =    opt->samplesize;
-    wav->totalsamples =  0;
+    wav->totalsamples =  -1;
     wav->channel_permute = malloc(wav->channels * sizeof(int));
     for (i=0; i < wav->channels; i++)
       wav->channel_permute[i] = i;
 
     opt->read_samples = wav_read;
     opt->readdata = (void *)wav;
-    opt->total_samples_per_channel = 0; /* raw mode, don't bother */
+    opt->total_samples_per_channel = -1; /* raw mode, don't bother */
     return 1;
 }
 
@@ -796,7 +809,7 @@
 
     opt->read_samples = read_resampled;
     opt->readdata = rs;
-    if(opt->total_samples_per_channel)
+    if(opt->total_samples_per_channel > 0)
         opt->total_samples_per_channel = (int)((float)opt->total_samples_per_channel * 
             ((float)opt->resamplefreq/(float)opt->rate));
     opt->rate = opt->resamplefreq;

Modified: trunk/vorbis-tools/oggenc/oggenc.c
===================================================================
--- trunk/vorbis-tools/oggenc/oggenc.c	2012-06-13 01:59:26 UTC (rev 18382)
+++ trunk/vorbis-tools/oggenc/oggenc.c	2012-06-13 02:17:09 UTC (rev 18383)
@@ -418,7 +418,7 @@
         }
 
 
-        if(!enc_opts.total_samples_per_channel)
+        if(enc_opts.total_samples_per_channel <= 0)
             enc_opts.progress_update = update_statistics_notime;
 
         if(opt.quiet)



More information about the commits mailing list