Update of /cvsroot/xine/xine-lib/src/demuxers
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv14594/src/demuxers

Modified Files:
        demux_aac.c 
Log Message:

Fixed content type detection for AAC (seekable) streams with ID3v2 tags 
prefixed clobbering the preview buffer, by skipping over the tag.


Index: demux_aac.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/demuxers/demux_aac.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- demux_aac.c 19 Jan 2007 00:26:39 -0000      1.13
+++ demux_aac.c 2 Mar 2007 20:07:33 -0000       1.14
@@ -37,9 +37,9 @@
 
 #define LOG_MODULE "demux_aac"
 #define LOG_VERBOSE
-/*
+
 #define LOG
-*/
+
 
 #include "xine_internal.h"
 #include "xineutils.h"
@@ -57,7 +57,6 @@
   input_plugin_t      *input;
   int                  status;
 
-  off_t                data_start;
   off_t                data_size;
 
   int                  seek_flag;  /* this is set when a seek just occurred */
@@ -72,11 +71,30 @@
   int i;
   uint8_t peak[MAX_PREVIEW_SIZE];
   uint16_t syncword = 0;
+  uint32_t id3size = 0;
+  off_t data_start;
 
   /* Check for an ADIF header - should be at the start of the file */
   if (_x_demux_read_header(this->input, peak, 4) != 4)
       return 0;
 
+  /* Skip the ID3v2 tag at the start */
+  if ( peak[0] == 'I' && peak[1] == 'D' && peak[2] == '3' ) {
+
+    this->input->seek(this->input, 6, SEEK_SET);
+    if ( this->input->read(this->input, peak, 4) != 4 )
+      return 0;
+
+    id3size = (peak[0] << 7*3) + (peak[1] << 7*2) + (peak[2] << 7) + peak[3] + 
10;
+
+    lprintf("ID3v2 tag encountered, skipping %u bytes.\n", id3size);
+
+    this->input->seek(this->input, id3size-10, SEEK_CUR);
+
+    if ( this->input->read(this->input, peak, 4) != 4 )
+      return 0;
+  }
+
   if ((peak[0] == 'A') && (peak[1] == 'D') &&
       (peak[2] == 'I') && (peak[3] == 'F')) {
     lprintf("found ADIF header\n");
@@ -84,13 +102,22 @@
   }
 
   /* Look for an ADTS header - might not be at the start of the file */
-  if (_x_demux_read_header(this->input, peak, MAX_PREVIEW_SIZE) != 
-      MAX_PREVIEW_SIZE)
+  if ( id3size != 0 && this->input->get_capabilities(this->input) & 
INPUT_CAP_SEEKABLE ) {
+    lprintf("Getting a buffer of size %u starting from %u\n", 
MAX_PREVIEW_SIZE, id3size);
+
+    this->input->seek(this->input, id3size, SEEK_SET);
+    if ( this->input->read(this->input, peak, MAX_PREVIEW_SIZE) != 
MAX_PREVIEW_SIZE )
+      return 0;
+    this->input->seek(this->input, 0, SEEK_SET);
+  } else if (_x_demux_read_header(this->input, peak, MAX_PREVIEW_SIZE) != 
+          MAX_PREVIEW_SIZE)
     return 0;
 
+  data_start = 0;
+
   for (i=0; i<MAX_PREVIEW_SIZE; i++) {
     if ((syncword & 0xfff6) == 0xfff0) {
-      this->data_start = i - 2;
+      data_start = i - 2;
       lprintf("found ADTS header at offset %d\n", i-2);
       break;
     }
@@ -99,27 +126,27 @@
   }
 
   /* Look for second ADTS header to confirm it's really aac */
-  if (this->data_start + 5 < MAX_PREVIEW_SIZE) {
-    int frame_size = ((peak[this->data_start+3] & 0x03) << 11) |
-                      (peak[this->data_start+4] << 3) |
-                     ((peak[this->data_start+5] & 0xe0) >> 5);
+  if (data_start + 5 < MAX_PREVIEW_SIZE) {
+    int frame_size = ((peak[data_start+3] & 0x03) << 11) |
+                      (peak[data_start+4] << 3) |
+                     ((peak[data_start+5] & 0xe0) >> 5);
 
     lprintf("first frame size %d\n", frame_size);
 
     if ((frame_size > 0) &&
-        (this->data_start+frame_size < MAX_PREVIEW_SIZE-1) &&
+        (data_start+frame_size < MAX_PREVIEW_SIZE-1) &&
         /* first 28 bits must be identical */
-        (peak[this->data_start  ]   ==peak[this->data_start+frame_size  ]) &&
-        (peak[this->data_start+1]   ==peak[this->data_start+frame_size+1]) &&
-        (peak[this->data_start+2]   ==peak[this->data_start+frame_size+2]) &&
-        (peak[this->data_start+3]>>4==peak[this->data_start+frame_size+3]>>4))
+        (peak[data_start  ]   ==peak[data_start+frame_size  ]) &&
+        (peak[data_start+1]   ==peak[data_start+frame_size+1]) &&
+        (peak[data_start+2]   ==peak[data_start+frame_size+2]) &&
+        (peak[data_start+3]>>4==peak[data_start+frame_size+3]>>4))
     {
       lprintf("found second ADTS header\n");
 
       _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_VIDEO, 0);
       _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 1);
 
-      this->input->seek(this->input, this->data_start, SEEK_SET);
+      this->input->seek(this->input, data_start+id3size, SEEK_SET);
       return 1;
     }
   }


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Xine-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xine-cvslog

Reply via email to