summaryrefslogtreecommitdiff
path: root/src/demuxers/demux_flac.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/demuxers/demux_flac.c')
-rw-r--r--src/demuxers/demux_flac.c50
1 files changed, 18 insertions, 32 deletions
diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c
index f52da4d03..488a909cb 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') ||
@@ -153,11 +140,11 @@ static int open_flac_file(demux_flac_t *flac) {
flac->streaminfo + sizeof(xine_waveformatex),
FLAC_STREAMINFO_SIZE) != FLAC_STREAMINFO_SIZE)
return 0;
- flac->sample_rate = BE_32(&streaminfo[10]);
+ flac->sample_rate = _X_BE_32(&streaminfo[10]);
flac->channels = ((flac->sample_rate >> 9) & 0x07) + 1;
flac->bits_per_sample = ((flac->sample_rate >> 4) & 0x1F) + 1;
flac->sample_rate >>= 12;
- flac->total_samples = BE_64(&streaminfo[10]) & UINT64_C(0x0FFFFFFFFF); /* 36 bits */
+ flac->total_samples = _X_BE_64(&streaminfo[10]) & UINT64_C(0x0FFFFFFFFF); /* 36 bits */
lprintf ("%d Hz, %d bits, %d channels, %"PRId64" total samples\n",
flac->sample_rate, flac->bits_per_sample,
flac->channels, flac->total_samples);
@@ -179,15 +166,15 @@ static int open_flac_file(demux_flac_t *flac) {
case 3:
lprintf ("SEEKTABLE metadata, %d bytes\n", block_length);
flac->seekpoint_count = block_length / FLAC_SEEKPOINT_SIZE;
- flac->seekpoints = xine_xmalloc(flac->seekpoint_count *
- sizeof(flac_seekpoint_t));
+ flac->seekpoints = xine_xcalloc(flac->seekpoint_count,
+ sizeof(flac_seekpoint_t));
for (i = 0; i < flac->seekpoint_count; i++) {
if (flac->input->read(flac->input, buffer, FLAC_SEEKPOINT_SIZE) != FLAC_SEEKPOINT_SIZE)
return 0;
- flac->seekpoints[i].sample_number = BE_64(&buffer[0]);
+ flac->seekpoints[i].sample_number = _X_BE_64(&buffer[0]);
lprintf (" %d: sample %"PRId64", ", i, flac->seekpoints[i].sample_number);
- flac->seekpoints[i].offset = BE_64(&buffer[8]);
- flac->seekpoints[i].size = BE_16(&buffer[16]);
+ flac->seekpoints[i].offset = _X_BE_64(&buffer[8]);
+ flac->seekpoints[i].size = _X_BE_16(&buffer[16]);
lprintf ("@ 0x%"PRIX64", size = %d bytes, ",
flac->seekpoints[i].offset, flac->seekpoints[i].size);
flac->seekpoints[i].pts = flac->seekpoints[i].sample_number;
@@ -205,9 +192,8 @@ static int open_flac_file(demux_flac_t *flac) {
lprintf ("VORBIS_COMMENT metadata\n");
{
char comments[block_length];
- void *ptr = comments;
- uint32_t length, user_comment_list_length;
- int cn;
+ char *ptr = comments;
+ uint32_t length, user_comment_list_length, cn;
char *comment;
char c;
@@ -215,15 +201,15 @@ static int open_flac_file(demux_flac_t *flac) {
int tracknumber = -1;
int tracktotal = -1;
- length = LE_32(ptr);
+ length = _X_LE_32(ptr);
ptr += 4 + length;
- user_comment_list_length = LE_32(ptr);
+ user_comment_list_length = _X_LE_32(ptr);
ptr += 4;
cn = 0;
for (; cn < user_comment_list_length; cn++) {
- length = LE_32(ptr);
+ length = _X_LE_32(ptr);
ptr += 4;
comment = (char*) ptr;