summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2007-03-03 01:41:16 +0000
committerDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2007-03-03 01:41:16 +0000
commit5ff2be1b878d481cbfcce5f41a5fb679c45824ec (patch)
treeee605aafbdf130b5b7bfe8d7891a6632ff3969dc
parent6a16b385d3c32e412e23f9f5d44140d7afd9af79 (diff)
downloadxine-lib-5ff2be1b878d481cbfcce5f41a5fb679c45824ec.tar.gz
xine-lib-5ff2be1b878d481cbfcce5f41a5fb679c45824ec.tar.bz2
Add two extra functions (inline as they are just a return statement) that checks if a preamble is of an ID3v2 tag, and that calculate the size of the tag (to avoid repeating the same code over and over and over; the size of the shared object is reduced. Also make demux_flac use the id3.c functions to parse the eventual ID3 header.
CVS patchset: 8637 CVS date: 2007/03/03 01:41:16
-rw-r--r--src/demuxers/demux_aac.c6
-rw-r--r--src/demuxers/demux_flac.c26
-rw-r--r--src/demuxers/demux_mpgaudio.c11
-rw-r--r--src/demuxers/id3.h19
4 files changed, 37 insertions, 25 deletions
diff --git a/src/demuxers/demux_aac.c b/src/demuxers/demux_aac.c
index dedcaca8a..ab71e8382 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.16 2007/03/03 00:58:52 dgp85 Exp $
+ * $Id: demux_aac.c,v 1.17 2007/03/03 01:41:16 dgp85 Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -83,8 +83,8 @@ static int open_aac_file(demux_aac_t *this) {
return 0;
/* Check if there's an ID3v2 tag at the start */
- if ( peak[0] == 'I' && peak[1] == 'D' && peak[2] == '3' ) {
- id3size = (peak[6] << 7*3) + (peak[7] << 7*2) + (peak[8] << 7) + peak[9] + 10;
+ if ( id3v2_istag(peak) ) {
+ id3size = id3v2_tagsize(&peak[6]);
this->input->seek(this->input, 4, SEEK_SET);
diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c
index 259f4d4e9..c9e3f911a 100644
--- a/src/demuxers/demux_flac.c
+++ b/src/demuxers/demux_flac.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000-2004 the xine project
+ * Copyright (C) 2000-2007 the xine project
*
* This file is part of xine, a free video player.
*
@@ -23,7 +23,7 @@
* For more information on the FLAC file format, visit:
* http://flac.sourceforge.net/
*
- * $Id: demux_flac.c,v 1.15 2007/03/02 23:46:29 dgp85 Exp $
+ * $Id: demux_flac.c,v 1.16 2007/03/03 01:41:16 dgp85 Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -49,6 +49,7 @@
#include "bswap.h"
#include "group_audio.h"
+#include "id3.h"
#include "flacutils.h"
typedef struct {
@@ -81,7 +82,7 @@ typedef struct {
* It returns 1 if flac file was opened successfully. */
static int open_flac_file(demux_flac_t *flac) {
- unsigned char preamble[4];
+ unsigned char preamble[10];
unsigned int block_length;
unsigned char buffer[FLAC_SEEKPOINT_SIZE];
unsigned char *streaminfo = flac->streaminfo + sizeof(xine_waveformatex);
@@ -89,8 +90,9 @@ static int open_flac_file(demux_flac_t *flac) {
flac->seekpoints = NULL;
- /* fetch the file signature */
- if ( flac->input->read(flac->input, preamble, 4) != 4 )
+ /* fetch the file signature, get enough bytes so that id3 can also
+ be skipped and/or parsed */
+ if (_x_demux_read_header(flac->input, preamble, 10) != 10)
return 0;
/* Unfortunately some FLAC files have an ID3 flag prefixed on them
@@ -98,7 +100,7 @@ static int open_flac_file(demux_flac_t *flac) {
* users use them and want them working, so check and skip the ID3
* tag if present.
*/
- if ( preamble[0] == 'I' && preamble[1] == 'D' && preamble[2] == '3' ) {
+ if ( id3v2_istag(preamble) ) {
uint32_t id3size;
/* First 3 bytes are the ID3 signature as above, then comes two bytes
@@ -109,18 +111,16 @@ static int open_flac_file(demux_flac_t *flac) {
* is encoded as four bytes.. but only 7 out of 8 bits of every byte is
* used... don't ask.
*/
- flac->input->seek(flac->input, 6, SEEK_SET);
- if ( flac->input->read(flac->input, preamble, 4) != 4 )
- return 0;
+ id3size = id3v2_tagsize(&preamble[6]);
- id3size = (preamble[0] << 7*3) + (preamble[1] << 7*2) +
- (preamble[2] << 7) + preamble[3];
+ id3v2_parse_tag(flac->input, flac->stream, preamble);
- flac->input->seek(flac->input, id3size, SEEK_CUR);
+ flac->input->seek(flac->input, id3size, SEEK_SET);
if ( flac->input->read(flac->input, preamble, 4) != 4 )
return 0;
- }
+ } else
+ flac->input->seek(flac->input, 4, SEEK_SET);
/* validate signature */
if ((preamble[0] != 'f') || (preamble[1] != 'L') ||
diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c
index b9f35c17d..6c0b6031c 100644
--- a/src/demuxers/demux_mpgaudio.c
+++ b/src/demuxers/demux_mpgaudio.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000-2003 the xine project
+ * Copyright (C) 2000-2007 the xine project
*
* This file is part of xine, a free video player.
*
@@ -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: demux_mpgaudio.c,v 1.150 2007/03/03 00:58:52 dgp85 Exp $
+ * $Id: demux_mpgaudio.c,v 1.151 2007/03/03 01:41:16 dgp85 Exp $
*
* demultiplexer for mpeg audio (i.e. mp3) streams
*
@@ -606,7 +606,7 @@ static int demux_mpgaudio_next (demux_mpgaudio_t *this, int decoder_flags, int s
return parse_frame_payload(this, header_buf, decoder_flags);
- } else if ( header_buf[0] == 'I' && header_buf[1] == 'D' && header_buf[2] == '3' ) {
+ } else if ( id3v2_istag(header_buf) ) {
if (!id3v2_parse_tag(this->input, this->stream, header_buf)) {
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
LOG_MODULE ": ID3V2 tag parsing error\n");
@@ -693,10 +693,7 @@ static int detect_mpgaudio_file(input_plugin_t *input) {
* flac files can contain id3v2 tags
*/
uint8_t *ptr = &buf[6];
- uint32_t tag_size = ((uint32_t)ptr[0] << 21) +
- ((uint32_t)ptr[1] << 14) +
- ((uint32_t)ptr[2] << 7) +
- (uint32_t)ptr[3];
+ uint32_t tag_size = id3v2_tagsize(ptr);
lprintf("try to skip id3v2 tag (%d bytes)\n", tag_size);
if ((10 + tag_size) >= preview_len) {
lprintf("cannot skip id3v2 tag\n");
diff --git a/src/demuxers/id3.h b/src/demuxers/id3.h
index 394488858..9d08f6817 100644
--- a/src/demuxers/id3.h
+++ b/src/demuxers/id3.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000-2003 the xine project
+ * Copyright (C) 2000-2007 the xine project
*
* This file is part of xine, a free video player.
*
@@ -21,7 +21,7 @@
*
* Supported versions: v1, v1.1, v2.2, v2.3, v2.4
*
- * $Id: id3.h,v 1.5 2007/03/03 00:58:52 dgp85 Exp $
+ * $Id: id3.h,v 1.6 2007/03/03 01:41:16 dgp85 Exp $
*/
#ifndef ID3_H
@@ -170,4 +170,19 @@ int id3v2_parse_tag(input_plugin_t *input,
xine_stream_t *stream,
int8_t *mp3_frame_header);
+static inline int id3v2_istag(uint8_t *ptr) {
+ return
+ (ptr[0] == 'I') &&
+ (ptr[1] == 'D') &&
+ (ptr[2] == '3');
+}
+
+static inline uint32_t id3v2_tagsize(uint8_t *ptr) {
+ return
+ ((uint32_t)ptr[0] << 21) +
+ ((uint32_t)ptr[1] << 14) +
+ ((uint32_t)ptr[2] << 7) +
+ (uint32_t)ptr[3];
+}
+
#endif /* ID3_H */