From 18771879b638629eab26644c85e6a962b3faf5b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 2 Mar 2007 20:07:33 +0000 Subject: Fixed content type detection for AAC (seekable) streams with ID3v2 tags prefixed clobbering the preview buffer, by skipping over the tag. CVS patchset: 8632 CVS date: 2007/03/02 20:07:33 --- ChangeLog | 6 +++-- src/demuxers/demux_aac.c | 61 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 76c9d8c00..dc82eb15e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,8 @@ xine-lib (1.1.5) Vincent Torri, Jamey Sharp and Christophe Thommeret. * Fix race condition in alsa audio out driver. * Fixed a crash in the eq2 plugin. [Bug 1644312] + * Fixed content type detection for AAC (seekable) streams with ID3v2 + tags prefixed clobbering the preview buffer, by skipping over the tag. xine-lib (1.1.4) * Mark string-type configuration items according to whether they're plain @@ -31,7 +33,7 @@ xine-lib (1.1.4) by Roland Kay. [bug #1602631] * Don't check for libpostproc version and assume that if libavcodec is found correctly, libpostproc is of the same version, too. Reported by Ville - Skyttä. [bug #1617344] + Skyttä. [bug #1617344] * Fix Shorten demuxer: the whole "ajkg" signature has to be found, not only one character of it. [bug #1601134] * Implement at least a partial content-based detection of ModPlug-decoded @@ -1276,7 +1278,7 @@ xine (0.5.0) unstable; urgency=low * artsd support * dxr3/h+ support now finally in the official tree * 4/5/5.1 audio channel output (OSS/ ALSA?) - * a new default skin by Jérôme Villette + * a new default skin by Jérôme Villette -- Guenter Bartsch Sun, 22 Jul 2001 13:10:52 +0200 diff --git a/src/demuxers/demux_aac.c b/src/demuxers/demux_aac.c index 3a81404c1..26a273017 100644 --- a/src/demuxers/demux_aac.c +++ b/src/demuxers/demux_aac.c @@ -21,7 +21,7 @@ * This demuxer detects ADIF and ADTS headers in AAC files. * Then it shovels buffer-sized chunks over to the AAC decoder. * - * $Id: demux_aac.c,v 1.13 2007/01/19 00:26:39 dgp85 Exp $ + * $Id: demux_aac.c,v 1.14 2007/03/02 20:07:33 dgp85 Exp $ */ #ifdef HAVE_CONFIG_H @@ -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 @@ typedef struct { 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 @@ static int open_aac_file(demux_aac_t *this) { 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 @@ static int open_aac_file(demux_aac_t *this) { } /* 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; idata_start = i - 2; + data_start = i - 2; lprintf("found ADTS header at offset %d\n", i-2); break; } @@ -99,27 +126,27 @@ static int open_aac_file(demux_aac_t *this) { } /* 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; } } -- cgit v1.2.3