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

Brendan brendan at xiph.org
Sun Mar 16 18:22:38 PST 2003



brendan     03/03/16 21:22:38

  Modified:    src      mp3.c
  Log:
  MP3 trimming adjustment - use information already garnered about stream to
  help avoid false synch at the end. Still #ifdef'd off.

Revision  Changes    Path
1.30      +13 -10    ices/src/mp3.c

Index: mp3.c
===================================================================
RCS file: /cvs/ice/ices/src/mp3.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- mp3.c	17 Mar 2003 00:45:10 -0000	1.29
+++ mp3.c	17 Mar 2003 02:22:38 -0000	1.30
@@ -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.29 2003/03/17 00:45:10 brendan Exp $
+ * $Id: mp3.c,v 1.30 2003/03/17 02:22:38 brendan Exp $
  */
 
 #include "definitions.h"
@@ -86,7 +86,7 @@
 #endif
 static int ices_mp3_close (input_stream_t* self);
 static int mp3_fill_buffer (input_stream_t* self, size_t len);
-static void mp3_trim_file (input_stream_t* self);
+static void mp3_trim_file (input_stream_t* self, mp3_header_t* header);
 static int mp3_parse_frame(const unsigned char* buf, mp3_header_t* header);
 static int mp3_check_vbr(input_stream_t* source, mp3_header_t* header);
 static size_t mp3_frame_length(mp3_header_t* header);
@@ -114,11 +114,6 @@
   if (! strncmp ("ID3", mp3_data->buf, 3))
     ices_id3v2_parse (source);
 
-  /* adjust file size for short frames */
-#ifdef TRIM_FILE
-  mp3_trim_file (source);
-#endif
-
   /* ensure we have at least 4 bytes in the read buffer */
   if (!mp3_data->buf || mp3_data->len - mp3_data->pos < 4)
     mp3_fill_buffer (source, MP3_BUFFER_SIZE);
@@ -195,6 +190,11 @@
   if (off)
     ices_log_debug("Skipped %d bytes of garbage before MP3", off);
 
+#ifdef TRIM_FILE
+  /* adjust file size for short frames */
+  mp3_trim_file (source, &mh);
+#endif
+
   if (source->bitrate)
     ices_log_debug ("%s layer %s, %d kbps, %d Hz, %s", version_names[mh.version],
                     layer_names[mh.layer - 1], mh.bitrate, mh.samplerate, mode_names[mh.mode]);
@@ -316,9 +316,9 @@
 }
 
 /* trim short frame from end of file if necessary */
-static void mp3_trim_file (input_stream_t* self) {
+static void mp3_trim_file (input_stream_t* self, mp3_header_t* header) {
   char buf[MP3_BUFFER_SIZE];
-  mp3_header_t header;
+  mp3_header_t match;
   off_t cur, start, end;
   int framelen;
   int rlen, len;
@@ -346,7 +346,10 @@
 
     /* search buffer backwards looking for sync */
     for (len -= 4; len >= 0; len--) {
-      if (mp3_parse_frame (buf + len, &header) && (framelen = mp3_frame_length (&header))) {
+      if (mp3_parse_frame (buf + len, &match) && (framelen = mp3_frame_length (&match))
+          && header->version == match.version && header->layer == match.layer
+          && header->samplerate == match.samplerate
+          && (!self->bitrate || self->bitrate == match.bitrate)) {
         if (start + len + framelen < self->filesize) {
           self->filesize = start + len + framelen;
           ices_log_debug ("Trimmed file to %d bytes", self->filesize);

<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