summaryrefslogtreecommitdiff
path: root/src/demuxers
diff options
context:
space:
mode:
Diffstat (limited to 'src/demuxers')
-rw-r--r--src/demuxers/demux_aac.c2
-rw-r--r--src/demuxers/demux_flac.c25
-rw-r--r--src/demuxers/demux_mpgaudio.c3
-rw-r--r--src/demuxers/id3.c40
-rw-r--r--src/demuxers/id3.h40
5 files changed, 46 insertions, 64 deletions
diff --git a/src/demuxers/demux_aac.c b/src/demuxers/demux_aac.c
index ab71e8382..1775a4e0e 100644
--- a/src/demuxers/demux_aac.c
+++ b/src/demuxers/demux_aac.c
@@ -84,7 +84,7 @@ static int open_aac_file(demux_aac_t *this) {
/* Check if there's an ID3v2 tag at the start */
if ( id3v2_istag(peak) ) {
- id3size = id3v2_tagsize(&peak[6]);
+ id3size = BE_32_synchsafe(&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 116409d1f..ac7458726 100644
--- a/src/demuxers/demux_flac.c
+++ b/src/demuxers/demux_flac.c
@@ -90,37 +90,24 @@ static int open_flac_file(demux_flac_t *flac) {
flac->seekpoints = NULL;
- /* 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)
+ /* fetch the file signature, 4 bytes will read both the fLaC
+ * signature and the */
+ if (_x_demux_read_header(flac->input, preamble, 4) != 4)
return 0;
+ flac->input->seek(flac->input, 4, SEEK_SET);
+
/* Unfortunately some FLAC files have an ID3 flag prefixed on them
* before the actual FLAC headers... these are barely legal, but
* users use them and want them working, so check and skip the ID3
* tag if present.
*/
if ( id3v2_istag(preamble) ) {
- uint32_t id3size;
-
- /* First 3 bytes are the ID3 signature as above, then comes two bytes
- * encoding the major and minor version of ID3 used, that we can ignore
- * as long as we don't try to read the metadata; after those there's a
- * single byte with flags that depends on the ID3 version used; and now
- * after all that stuff, there's the size of the rest of the tag, which
- * is encoded as four bytes.. but only 7 out of 8 bits of every byte is
- * used... don't ask.
- */
- id3size = id3v2_tagsize(&preamble[6]);
-
id3v2_parse_tag(flac->input, flac->stream, preamble);
- 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 bd55c9f0a..64bae2794 100644
--- a/src/demuxers/demux_mpgaudio.c
+++ b/src/demuxers/demux_mpgaudio.c
@@ -697,8 +697,7 @@ static int detect_mpgaudio_file(input_plugin_t *input) {
* id3v2 are not specific to mp3 files,
* flac files can contain id3v2 tags
*/
- uint8_t *ptr = &buf[6];
- uint32_t tag_size = id3v2_tagsize(ptr);
+ uint32_t tag_size = BE_32_synchsafe(&buf[6]);
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.c b/src/demuxers/id3.c
index b707166b6..a59eb6259 100644
--- a/src/demuxers/id3.c
+++ b/src/demuxers/id3.c
@@ -227,38 +227,6 @@ static int id3v2_parse_genre(char* dest, char *src, int len) {
return 1;
}
-#if 0
-/* parse an unsynchronized 16bits integer */
-static uint16_t BE_16_synchsafe(uint8_t buf[2]) {
- return ((uint16_t)(buf[0] & 0x7F) << 7) |
- (uint16_t)(buf[1] & 0x7F);
-}
-#endif
-
-/* parse an unsynchronized 24bits integer */
-static uint32_t BE_24_synchsafe(uint8_t buf[3]) {
- return ((uint32_t)(buf[0] & 0x7F) << 14) |
- ((uint32_t)(buf[1] & 0x7F) << 7) |
- (uint32_t)(buf[2] & 0x7F);
-}
-
-/* parse an unsynchronized 32bits integer */
-static uint32_t BE_32_synchsafe(uint8_t buf[4]) {
- return ((uint32_t)(buf[0] & 0x7F) << 21) |
- ((uint32_t)(buf[1] & 0x7F) << 14) |
- ((uint32_t)(buf[2] & 0x7F) << 7) |
- (uint32_t)(buf[3] & 0x7F);
-}
-
-/* parse an unsynchronized 35bits integer */
-static uint32_t BE_35_synchsafe(uint8_t buf[5]) {
- return ((uint32_t)(buf[0] & 0x07) << 28) |
- ((uint32_t)(buf[1] & 0x7F) << 21) |
- ((uint32_t)(buf[2] & 0x7F) << 14) |
- ((uint32_t)(buf[3] & 0x7F) << 7) |
- (uint32_t)(buf[4] & 0x7F);
-}
-
static int id3v2_parse_header(input_plugin_t *input, uint8_t *mp3_frame_header,
id3v2_header_t *tag_header) {
uint8_t buf[6];
@@ -379,7 +347,7 @@ int id3v22_parse_tag(input_plugin_t *input,
if (tag_header.flags & ID3V22_ZERO_FLAG) {
/* invalid flags */
xprintf(stream->xine, XINE_VERBOSITY_DEBUG,
- "id3: invalid header flags\n");
+ "id3: invalid header flags (%02x)\n", tag_header.flags);
input->seek (input, tag_header.size - pos, SEEK_CUR);
return 0;
}
@@ -573,7 +541,7 @@ int id3v23_parse_tag(input_plugin_t *input,
if (tag_header.flags & ID3V23_ZERO_FLAG) {
/* invalid flags */
xprintf(stream->xine, XINE_VERBOSITY_DEBUG,
- "id3: invalid header flags\n");
+ "id3: invalid header flags (%02x)\n", tag_header.flags);
input->seek (input, tag_header.size - pos, SEEK_CUR);
return 0;
}
@@ -824,7 +792,7 @@ int id3v24_parse_tag(input_plugin_t *input,
if (tag_header.flags & ID3V24_ZERO_FLAG) {
/* invalid flags */
xprintf(stream->xine, XINE_VERBOSITY_DEBUG,
- "id3: invalid header flags\n");
+ "id3: invalid header flags (%02x)\n", tag_header.flags);
input->seek (input, tag_header.size - pos, SEEK_CUR);
return 0;
}
@@ -898,7 +866,7 @@ int id3v2_parse_tag(input_plugin_t *input,
break;
case 4:
- xprintf(stream->xine, XINE_VERBOSITY_LOG, "ID3V2.3 tag\n");
+ xprintf(stream->xine, XINE_VERBOSITY_LOG, "ID3V2.4 tag\n");
result = id3v24_parse_tag(input, stream, mp3_frame_header);
break;
diff --git a/src/demuxers/id3.h b/src/demuxers/id3.h
index 9d08f6817..b8f0984b1 100644
--- a/src/demuxers/id3.h
+++ b/src/demuxers/id3.h
@@ -170,6 +170,10 @@ int id3v2_parse_tag(input_plugin_t *input,
xine_stream_t *stream,
int8_t *mp3_frame_header);
+/**
+ * @brief Checks if the given buffer is an ID3 tag preamble
+ * @param ptr Pointer to the first 10 bytes of the ID3 tag
+ */
static inline int id3v2_istag(uint8_t *ptr) {
return
(ptr[0] == 'I') &&
@@ -177,12 +181,36 @@ static inline int id3v2_istag(uint8_t *ptr) {
(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];
+#if 0
+/* parse an unsynchronized 16bits integer */
+static inline uint16_t BE_16_synchsafe(uint8_t buf[2]) {
+ return ((uint16_t)(buf[0] & 0x7F) << 7) |
+ (uint16_t)(buf[1] & 0x7F);
+}
+#endif
+
+/* parse an unsynchronized 24bits integer */
+static inline uint32_t BE_24_synchsafe(uint8_t buf[3]) {
+ return ((uint32_t)(buf[0] & 0x7F) << 14) |
+ ((uint32_t)(buf[1] & 0x7F) << 7) |
+ (uint32_t)(buf[2] & 0x7F);
+}
+
+/* parse an unsynchronized 32bits integer */
+static inline uint32_t BE_32_synchsafe(uint8_t buf[4]) {
+ return ((uint32_t)(buf[0] & 0x7F) << 21) |
+ ((uint32_t)(buf[1] & 0x7F) << 14) |
+ ((uint32_t)(buf[2] & 0x7F) << 7) |
+ (uint32_t)(buf[3] & 0x7F);
+}
+
+/* parse an unsynchronized 35bits integer */
+static inline uint32_t BE_35_synchsafe(uint8_t buf[5]) {
+ return ((uint32_t)(buf[0] & 0x07) << 28) |
+ ((uint32_t)(buf[1] & 0x7F) << 21) |
+ ((uint32_t)(buf[2] & 0x7F) << 14) |
+ ((uint32_t)(buf[3] & 0x7F) << 7) |
+ (uint32_t)(buf[4] & 0x7F);
}
#endif /* ID3_H */