Updated Dutch (Nederlands) translation
[kugel-rb.git] / apps / metadata.c
blob676108116d76458583b1ef0b94d84dec2571d7c0
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Dave Chapman
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
22 #include <ctype.h>
23 #include <inttypes.h>
25 #include "metadata.h"
26 #include "mp3_playback.h"
27 #include "logf.h"
28 #include "atoi.h"
29 #include "replaygain.h"
30 #include "debug.h"
31 #include "system.h"
33 enum tagtype { TAGTYPE_APE = 1, TAGTYPE_VORBIS };
35 #define APETAG_HEADER_LENGTH 32
36 #define APETAG_HEADER_FORMAT "8LLLL"
37 #define APETAG_ITEM_HEADER_FORMAT "LL"
38 #define APETAG_ITEM_TYPE_MASK 3
40 #define TAG_NAME_LENGTH 32
41 #define TAG_VALUE_LENGTH 128
43 struct apetag_header
45 char id[8];
46 long version;
47 long length;
48 long item_count;
49 long flags;
50 char reserved[8];
53 struct apetag_item_header
55 long length;
56 long flags;
59 struct format_list
61 char format;
62 char extension[5];
65 static const struct format_list formats[] =
67 { AFMT_MPA_L1, "mp1" },
68 { AFMT_MPA_L2, "mp2" },
69 { AFMT_MPA_L2, "mpa" },
70 { AFMT_MPA_L3, "mp3" },
71 #if CONFIG_CODEC == SWCODEC
72 { AFMT_OGG_VORBIS, "ogg" },
73 { AFMT_PCM_WAV, "wav" },
74 { AFMT_FLAC, "flac" },
75 { AFMT_MPC, "mpc" },
76 { AFMT_A52, "a52" },
77 { AFMT_A52, "ac3" },
78 { AFMT_WAVPACK, "wv" },
79 { AFMT_ALAC, "m4a" },
80 { AFMT_AAC, "mp4" },
81 { AFMT_SHN, "shn" },
82 { AFMT_AIFF, "aif" },
83 { AFMT_AIFF, "aiff" },
84 { AFMT_SID, "sid" },
85 #endif
88 #if CONFIG_CODEC == SWCODEC
89 static const unsigned short a52_bitrates[] =
91 32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
92 192, 224, 256, 320, 384, 448, 512, 576, 640
95 /* Only store frame sizes for 44.1KHz - others are simply multiples
96 of the bitrate */
97 static const unsigned short a52_441framesizes[] =
99 69 * 2, 70 * 2, 87 * 2, 88 * 2, 104 * 2, 105 * 2, 121 * 2,
100 122 * 2, 139 * 2, 140 * 2, 174 * 2, 175 * 2, 208 * 2, 209 * 2,
101 243 * 2, 244 * 2, 278 * 2, 279 * 2, 348 * 2, 349 * 2, 417 * 2,
102 418 * 2, 487 * 2, 488 * 2, 557 * 2, 558 * 2, 696 * 2, 697 * 2,
103 835 * 2, 836 * 2, 975 * 2, 976 * 2, 1114 * 2, 1115 * 2, 1253 * 2,
104 1254 * 2, 1393 * 2, 1394 * 2
107 static const long wavpack_sample_rates [] =
109 6000, 8000, 9600, 11025, 12000, 16000, 22050, 24000,
110 32000, 44100, 48000, 64000, 88200, 96000, 192000
113 /* Read a string from the file. Read up to size bytes, or, if eos != -1,
114 * until the eos character is found (eos is not stored in buf, unless it is
115 * nil). Writes up to buf_size chars to buf, always terminating with a nil.
116 * Returns number of chars read or -1 on read error.
118 static long read_string(int fd, char* buf, long buf_size, int eos, long size)
120 long read_bytes = 0;
121 char c;
123 while (size != 0)
125 if (read(fd, &c, 1) != 1)
127 read_bytes = -1;
128 break;
131 read_bytes++;
132 size--;
134 if ((eos != -1) && (eos == (unsigned char) c))
136 break;
139 if (buf_size > 1)
141 *buf++ = c;
142 buf_size--;
146 *buf = 0;
147 return read_bytes;
150 /* Convert a little-endian structure to native format using a format string.
151 * Does nothing on a little-endian machine.
153 static void convert_endian(void *data, const char *format)
155 while (*format)
157 switch (*format)
159 case 'L':
161 long* d = (long*) data;
163 *d = letoh32(*d);
164 data = d + 1;
167 break;
169 case 'S':
171 short* d = (short*) data;
173 *d = letoh16(*d);
174 data = d + 1;
177 break;
179 default:
180 if (isdigit(*format))
182 data = ((char*) data) + *format - '0';
185 break;
188 format++;
192 /* read_uint32be() - read an unsigned integer from a big-endian
193 (e.g. Quicktime) file. This is used by the .m4a parser
195 #ifdef ROCKBOX_BIG_ENDIAN
196 #define read_uint32be(fd,buf) read((fd),(buf),4)
197 #else
198 int read_uint32be(int fd, unsigned int* buf) {
199 char tmp;
200 char* p=(char*)buf;
201 size_t n;
203 n=read(fd,p,4);
204 if (n==4) {
205 tmp=p[0];
206 p[0]=p[3];
207 p[3]=tmp;
208 tmp=p[2];
209 p[2]=p[1];
210 p[1]=tmp;
213 return(n);
215 #endif
217 /* Read an unaligned 32-bit little endian long from buffer. */
218 static unsigned long get_long(void* buf)
220 unsigned char* p = (unsigned char*) buf;
222 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
225 /* Read a string tag from an M4A file */
226 void read_m4a_tag_string(int fd, int len,char** bufptr,size_t* bytes_remaining, char** dest)
228 int data_length;
230 if (bytes_remaining==0) {
231 lseek(fd,len,SEEK_CUR); /* Skip everything */
232 } else {
233 /* Skip the data tag header - maybe we should parse it properly? */
234 lseek(fd,16,SEEK_CUR);
235 len-=16;
237 *dest=*bufptr;
238 if ((size_t)len+1 > *bytes_remaining) {
239 read(fd,*bufptr,*bytes_remaining-1);
240 lseek(fd,len-(*bytes_remaining-1),SEEK_CUR);
241 *bufptr+=(*bytes_remaining-1);
242 } else {
243 read(fd,*bufptr,len);
244 *bufptr+=len;
246 **bufptr=(char)0;
248 data_length = strlen(*dest)+1;
249 *bufptr=(*dest)+data_length;
250 *bytes_remaining-=data_length;
254 /* Parse the tag (the name-value pair) and fill id3 and buffer accordingly.
255 * String values to keep are written to buf. Returns number of bytes written
256 * to buf (including end nil).
258 static long parse_tag(const char* name, char* value, struct mp3entry* id3,
259 char* buf, long buf_remaining, enum tagtype type)
261 long len = 0;
262 char** p;
264 if ((((strcasecmp(name, "track") == 0) && (type == TAGTYPE_APE)))
265 || ((strcasecmp(name, "tracknumber") == 0) && (type == TAGTYPE_VORBIS)))
267 id3->tracknum = atoi(value);
268 p = &(id3->track_string);
270 else if (((strcasecmp(name, "year") == 0) && (type == TAGTYPE_APE))
271 || ((strcasecmp(name, "date") == 0) && (type == TAGTYPE_VORBIS)))
273 /* Date can be in more any format in a Vorbis tag, so don't try to
274 * parse it.
276 if (type != TAGTYPE_VORBIS)
278 id3->year = atoi(value);
281 p = &(id3->year_string);
283 else if (strcasecmp(name, "title") == 0)
285 p = &(id3->title);
287 else if (strcasecmp(name, "artist") == 0)
289 p = &(id3->artist);
291 else if (strcasecmp(name, "album") == 0)
293 p = &(id3->album);
295 else if (strcasecmp(name, "genre") == 0)
297 p = &(id3->genre_string);
299 else if (strcasecmp(name, "composer") == 0)
301 p = &(id3->composer);
303 else
305 len = parse_replaygain(name, value, id3, buf, buf_remaining);
306 p = NULL;
309 if (p)
311 len = strlen(value);
312 len = MIN(len, buf_remaining - 1);
314 if (len > 0)
316 strncpy(buf, value, len);
317 buf[len] = 0;
318 *p = buf;
319 len++;
321 else
323 len = 0;
327 return len;
330 /* Read the items in an APEV2 tag. Only looks for a tag at the end of a
331 * file. Returns true if a tag was found and fully read, false otherwise.
333 static bool read_ape_tags(int fd, struct mp3entry* id3)
335 struct apetag_header header;
337 if ((lseek(fd, -APETAG_HEADER_LENGTH, SEEK_END) < 0)
338 || (read(fd, &header, APETAG_HEADER_LENGTH) != APETAG_HEADER_LENGTH)
339 || (memcmp(header.id, "APETAGEX", sizeof(header.id))))
341 return false;
344 convert_endian(&header, APETAG_HEADER_FORMAT);
345 id3->genre = 0xff;
347 if ((header.version == 2000) && (header.item_count > 0)
348 && (header.length > APETAG_HEADER_LENGTH))
350 char *buf = id3->id3v2buf;
351 unsigned int buf_remaining = sizeof(id3->id3v2buf)
352 + sizeof(id3->id3v1buf);
353 unsigned int tag_remaining = header.length - APETAG_HEADER_LENGTH;
354 int i;
356 if (lseek(fd, -header.length, SEEK_END) < 0)
358 return false;
361 for (i = 0; i < header.item_count; i++)
363 struct apetag_item_header item;
364 char name[TAG_NAME_LENGTH];
365 char value[TAG_VALUE_LENGTH];
366 long r;
368 if (tag_remaining < sizeof(item))
370 break;
373 if (read(fd, &item, sizeof(item)) < (long) sizeof(item))
375 return false;
378 convert_endian(&item, APETAG_ITEM_HEADER_FORMAT);
379 tag_remaining -= sizeof(item);
380 r = read_string(fd, name, sizeof(name), 0, tag_remaining);
382 if (r == -1)
384 return false;
387 tag_remaining -= r + item.length;
389 if ((item.flags & APETAG_ITEM_TYPE_MASK) == 0)
391 long len;
393 if (read_string(fd, value, sizeof(value), -1, item.length)
394 != item.length)
396 return false;
399 len = parse_tag(name, value, id3, buf, buf_remaining,
400 TAGTYPE_APE);
401 buf += len;
402 buf_remaining -= len;
404 else
406 if (lseek(fd, item.length, SEEK_CUR) < 0)
408 return false;
414 return true;
417 /* Read the items in a Vorbis comment packet. Returns true the items were
418 * fully read, false otherwise.
420 static bool read_vorbis_tags(int fd, struct mp3entry *id3,
421 long tag_remaining)
423 char *buf = id3->id3v2buf;
424 long comment_count;
425 long len;
426 int buf_remaining = sizeof(id3->id3v2buf) + sizeof(id3->id3v1buf);
427 int i;
429 id3->genre = 255;
431 if (read(fd, &len, sizeof(len)) < (long) sizeof(len))
433 return false;
436 convert_endian(&len, "L");
438 if ((lseek(fd, len, SEEK_CUR) < 0)
439 || (read(fd, &comment_count, sizeof(comment_count))
440 < (long) sizeof(comment_count)))
442 return false;
445 convert_endian(&comment_count, "L");
446 tag_remaining -= len + sizeof(len) + sizeof(comment_count);
448 if (tag_remaining <= 0)
450 return true;
453 for (i = 0; i < comment_count; i++)
455 char name[TAG_NAME_LENGTH];
456 char value[TAG_VALUE_LENGTH];
457 long read_len;
459 if (tag_remaining < 4)
461 break;
464 if (read(fd, &len, sizeof(len)) < (long) sizeof(len))
466 return false;
469 convert_endian(&len, "L");
470 tag_remaining -= 4;
472 /* Quit if we've passed the end of the page */
473 if (tag_remaining < len)
475 break;
478 tag_remaining -= len;
479 read_len = read_string(fd, name, sizeof(name), '=', len);
481 if (read_len < 0)
483 return false;
486 len -= read_len;
488 if (read_string(fd, value, sizeof(value), -1, len) < 0)
490 return false;
493 len = parse_tag(name, value, id3, buf, buf_remaining,
494 TAGTYPE_VORBIS);
495 buf += len;
496 buf_remaining -= len;
499 /* Skip to the end of the block */
500 if (tag_remaining)
502 if (lseek(fd, tag_remaining, SEEK_CUR) < 0)
504 return false;
508 return true;
511 /* Skip an ID3v2 tag if it can be found. We assume the tag is located at the
512 * start of the file, which should be true in all cases where we need to skip it.
513 * Returns true if successfully skipped or not skipped, and false if
514 * something went wrong while skipping.
516 static bool skip_id3v2(int fd, struct mp3entry *id3)
518 char buf[4];
520 read(fd, buf, 4);
521 if (memcmp(buf, "ID3", 3) == 0)
523 /* We have found an ID3v2 tag at the start of the file - find its
524 length and then skip it. */
525 if ((id3->first_frame_offset = getid3v2len(fd)) == 0)
526 return false;
528 if ((lseek(fd, id3->first_frame_offset, SEEK_SET) < 0))
529 return false;
531 return true;
532 } else {
533 lseek(fd, 0, SEEK_SET);
534 id3->first_frame_offset = 0;
535 return true;
539 /* A simple parser to read vital metadata from an Ogg Vorbis file. Returns
540 * false if metadata needed by the Vorbis codec couldn't be read.
542 static bool get_vorbis_metadata(int fd, struct mp3entry* id3)
544 /* An Ogg File is split into pages, each starting with the string
545 * "OggS". Each page has a timestamp (in PCM samples) referred to as
546 * the "granule position".
548 * An Ogg Vorbis has the following structure:
549 * 1) Identification header (containing samplerate, numchannels, etc)
550 * 2) Comment header - containing the Vorbis Comments
551 * 3) Setup header - containing codec setup information
552 * 4) Many audio packets...
555 /* Use the path name of the id3 structure as a temporary buffer. */
556 unsigned char* buf = id3->path;
557 long comment_size;
558 long remaining = 0;
559 long last_serial = 0;
560 long serial, r;
561 int segments;
562 int i;
563 bool eof = false;
565 if ((lseek(fd, 0, SEEK_SET) < 0) || (read(fd, buf, 58) < 4))
567 return false;
570 if ((memcmp(buf, "OggS", 4) != 0) || (memcmp(&buf[29], "vorbis", 6) != 0))
572 return false;
575 /* We need to ensure the serial number from this page is the same as the
576 * one from the last page (since we only support a single bitstream).
578 serial = get_long(&buf[14]);
579 id3->frequency = get_long(&buf[40]);
580 id3->filesize = filesize(fd);
582 /* Comments are in second Ogg page */
583 if (lseek(fd, 58, SEEK_SET) < 0)
585 return false;
588 /* Minimum header length for Ogg pages is 27. */
589 if (read(fd, buf, 27) < 27)
591 return false;
594 if (memcmp(buf, "OggS", 4) !=0 )
596 return false;
599 segments = buf[26];
601 /* read in segment table */
602 if (read(fd, buf, segments) < segments)
604 return false;
607 /* The second packet in a vorbis stream is the comment packet. It *may*
608 * extend beyond the second page, but usually does not. Here we find the
609 * length of the comment packet (or the rest of the page if the comment
610 * packet extends to the third page).
612 for (i = 0; i < segments; i++)
614 remaining += buf[i];
616 /* The last segment of a packet is always < 255 bytes */
617 if (buf[i] < 255)
619 break;
623 /* Now read in packet header (type and id string) */
624 if (read(fd, buf, 7) < 7)
626 return false;
629 comment_size = remaining;
630 remaining -= 7;
632 /* The first byte of a packet is the packet type; comment packets are
633 * type 3.
635 if ((buf[0] != 3) || (memcmp(buf + 1, "vorbis", 6) !=0))
637 return false;
640 /* Failure to read the tags isn't fatal. */
641 read_vorbis_tags(fd, id3, remaining);
643 /* We now need to search for the last page in the file - identified by
644 * by ('O','g','g','S',0) and retrieve totalsamples.
647 /* A page is always < 64 kB */
648 if (lseek(fd, -(MIN(64 * 1024, id3->filesize)), SEEK_END) < 0)
650 return false;
653 remaining = 0;
655 while (!eof)
657 r = read(fd, &buf[remaining], MAX_PATH - remaining);
659 if (r <= 0)
661 eof = true;
663 else
665 remaining += r;
668 /* Inefficient (but simple) search */
669 i = 0;
671 while (i < (remaining - 3))
673 if ((buf[i] == 'O') && (memcmp(&buf[i], "OggS", 4) == 0))
675 if (i < (remaining - 17))
677 /* Note that this only reads the low 32 bits of a
678 * 64 bit value.
680 id3->samples = get_long(&buf[i + 6]);
681 last_serial = get_long(&buf[i + 14]);
683 /* If this page is very small the beginning of the next
684 * header could be in buffer. Jump near end of this header
685 * and continue */
686 i += 27;
688 else
690 break;
693 else
695 i++;
699 if (i < remaining)
701 /* Move the remaining bytes to start of buffer.
702 * Reuse var 'segments' as it is no longer needed */
703 segments = 0;
704 while (i < remaining)
706 buf[segments++] = buf[i++];
708 remaining = segments;
710 else
712 /* Discard the rest of the buffer */
713 remaining = 0;
717 /* This file has mutiple vorbis bitstreams (or is corrupt). */
718 /* FIXME we should display an error here. */
719 if (serial != last_serial)
721 logf("serialno mismatch");
722 logf("%ld", serial);
723 logf("%ld", last_serial);
724 return false;
727 id3->length = (id3->samples / id3->frequency) * 1000;
728 id3->bitrate = (((int64_t) id3->filesize - comment_size) * 8) / id3->length;
729 id3->vbr = true;
731 return true;
734 static bool get_flac_metadata(int fd, struct mp3entry* id3)
736 /* A simple parser to read vital metadata from a FLAC file - length,
737 * frequency, bitrate etc. This code should either be moved to a
738 * seperate file, or discarded in favour of the libFLAC code.
739 * The FLAC stream specification can be found at
740 * http://flac.sourceforge.net/format.html#stream
743 /* Use the trackname part of the id3 structure as a temporary buffer */
744 unsigned char* buf = id3->path;
745 bool rc = false;
747 if (!skip_id3v2(fd, id3) || (read(fd, buf, 4) < 4))
749 return rc;
752 if (memcmp(buf, "fLaC", 4) != 0)
754 return rc;
757 while (true)
759 long i;
761 if (read(fd, buf, 4) < 0)
763 return rc;
766 /* The length of the block */
767 i = (buf[1] << 16) | (buf[2] << 8) | buf[3];
769 if ((buf[0] & 0x7f) == 0) /* 0 is the STREAMINFO block */
771 unsigned long totalsamples;
773 /* FIXME: Don't trust the value of i */
774 if (read(fd, buf, i) < 0)
776 return rc;
779 id3->vbr = true; /* All FLAC files are VBR */
780 id3->filesize = filesize(fd);
781 id3->frequency = (buf[10] << 12) | (buf[11] << 4)
782 | ((buf[12] & 0xf0) >> 4);
783 rc = true; /* Got vital metadata */
785 /* totalsamples is a 36-bit field, but we assume <= 32 bits are used */
786 totalsamples = (buf[14] << 24) | (buf[15] << 16)
787 | (buf[16] << 8) | buf[17];
789 /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */
790 id3->length = (totalsamples / id3->frequency) * 1000;
791 id3->bitrate = (id3->filesize * 8) / id3->length;
793 else if ((buf[0] & 0x7f) == 4) /* 4 is the VORBIS_COMMENT block */
795 /* The next i bytes of the file contain the VORBIS COMMENTS. */
796 if (!read_vorbis_tags(fd, id3, i))
798 return rc;
801 else
803 if (buf[0] & 0x80)
805 /* If we have reached the last metadata block, abort. */
806 break;
808 else
810 /* Skip to next metadata block */
811 if (lseek(fd, i, SEEK_CUR) < 0)
813 return rc;
819 return true;
822 static bool get_wave_metadata(int fd, struct mp3entry* id3)
824 /* Use the trackname part of the id3 structure as a temporary buffer */
825 unsigned char* buf = id3->path;
826 unsigned long totalsamples = 0;
827 unsigned long channels = 0;
828 unsigned long bitspersample = 0;
829 unsigned long numbytes = 0;
830 int read_bytes;
831 int i;
833 /* get RIFF chunk header */
834 if ((lseek(fd, 0, SEEK_SET) < 0)
835 || ((read_bytes = read(fd, buf, 12)) < 12))
837 return false;
840 if ((memcmp(buf, "RIFF",4) != 0)
841 || (memcmp(&buf[8], "WAVE", 4) !=0 ))
843 return false;
846 /* iterate over WAVE chunks until 'data' chunk */
847 while (true)
849 /* get chunk header */
850 if ((read_bytes = read(fd, buf, 8)) < 8)
851 return false;
853 /* chunkSize */
854 i = get_long(&buf[4]);
856 if (memcmp(buf, "fmt ", 4) == 0)
858 /* get rest of chunk */
859 if ((read_bytes = read(fd, buf, 16)) < 16)
860 return false;
862 i -= 16;
864 /* skipping wFormatTag */
865 /* wChannels */
866 channels = buf[2] | (buf[3] << 8);
867 /* dwSamplesPerSec */
868 id3->frequency = get_long(&buf[4]);
869 /* dwAvgBytesPerSec */
870 id3->bitrate = (get_long(&buf[8]) * 8) / 1000;
871 /* skipping wBlockAlign */
872 /* wBitsPerSample */
873 bitspersample = buf[14] | (buf[15] << 8);
875 else if (memcmp(buf, "data", 4) == 0)
877 numbytes = i;
878 break;
880 else if (memcmp(buf, "fact", 4) == 0)
882 /* dwSampleLength */
883 if (i >= 4)
885 /* get rest of chunk */
886 if ((read_bytes = read(fd, buf, 2)) < 2)
887 return false;
889 i -= 2;
890 totalsamples = get_long(buf);
894 /* seek to next chunk (even chunk sizes must be padded) */
895 if (i & 0x01)
896 i++;
898 if(lseek(fd, i, SEEK_CUR) < 0)
899 return false;
902 if ((numbytes == 0) || (channels == 0))
904 return false;
907 if (totalsamples == 0)
909 /* for PCM only */
910 totalsamples = numbytes
911 / ((((bitspersample - 1) / 8) + 1) * channels);
914 id3->vbr = false; /* All WAV files are CBR */
915 id3->filesize = filesize(fd);
917 /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */
918 id3->length = (totalsamples / id3->frequency) * 1000;
920 return true;
923 static bool get_m4a_metadata(int fd, struct mp3entry* id3)
925 unsigned char* buf;
926 unsigned long totalsamples;
927 int i,j,k;
928 size_t n;
929 size_t bytes_remaining;
930 char* id3buf;
931 unsigned int compressedsize;
932 unsigned int sample_count;
933 unsigned int sample_duration;
934 int numentries;
935 int entry_size;
936 int size_remaining;
937 int chunk_len;
938 unsigned char chunk_id[4];
939 int sub_chunk_len;
940 unsigned char sub_chunk_id[4];
942 /* A simple parser to read vital metadata from an ALAC file.
943 This parser also works for AAC files - they are both stored in
944 a Quicktime M4A container. */
946 /* Use the trackname part of the id3 structure as a temporary buffer */
947 buf=id3->path;
949 lseek(fd, 0, SEEK_SET);
951 totalsamples=0;
952 compressedsize=0;
953 /* read the chunks - we stop when we find the mdat chunk and set compressedsize */
954 while (compressedsize==0) {
955 n=read_uint32be(fd,&chunk_len);
957 // This means it was a 64-bit file, so we have problems.
958 if (chunk_len == 1) {
959 logf("need 64bit support\n");
960 return false;
963 n=read(fd,&chunk_id,4);
964 if (n < 4)
965 return false;
967 if (memcmp(&chunk_id,"ftyp",4)==0) {
968 /* Check for M4A type */
969 n=read(fd,&chunk_id,4);
970 if ((memcmp(&chunk_id,"M4A ",4)!=0) &&
971 (memcmp(&chunk_id,"mp42",4)!=0)) {
972 logf("Not an M4A file, aborting\n");
973 return false;
975 /* Skip rest of chunk */
976 lseek(fd, chunk_len - 8 - 4, SEEK_CUR); /* FIXME not 8 */
977 } else if (memcmp(&chunk_id,"moov",4)==0) {
978 size_remaining=chunk_len - 8; /* FIXME not 8 */
980 while (size_remaining > 0) {
981 n=read_uint32be(fd,&sub_chunk_len);
982 if ((sub_chunk_len < 1) || (sub_chunk_len > size_remaining)) {
983 logf("Strange sub_chunk_len value inside moov: %d (remaining: %d)\n",sub_chunk_len,size_remaining);
984 return false;
986 n=read(fd,&sub_chunk_id,4);
987 size_remaining-=8;
989 if (memcmp(&sub_chunk_id,"mvhd",4)==0) {
990 /* We don't need anything from here - skip */
991 lseek(fd, sub_chunk_len - 8, SEEK_CUR); /* FIXME not 8 */
992 size_remaining-=(sub_chunk_len-8);
993 } else if (memcmp(&sub_chunk_id,"udta",4)==0) {
994 /* The udta chunk contains the metadata - track, artist, album etc.
995 The format appears to be:
996 udta
997 meta
998 hdlr
999 ilst
1000 .nam
1001 [rest of tags]
1002 free
1004 NOTE: This code was written by examination of some .m4a files
1005 produced by iTunes v4.9 - it may not therefore be 100%
1006 compliant with all streams. But it should fail gracefully.
1008 j=(sub_chunk_len-8);
1009 size_remaining-=j;
1010 n=read_uint32be(fd,&sub_chunk_len);
1011 n=read(fd,&sub_chunk_id,4);
1012 j-=8;
1013 if (memcmp(&sub_chunk_id,"meta",4)==0) {
1014 lseek(fd, 4, SEEK_CUR);
1015 j-=4;
1016 n=read_uint32be(fd,&sub_chunk_len);
1017 n=read(fd,&sub_chunk_id,4);
1018 j-=8;
1019 if (memcmp(&sub_chunk_id,"hdlr",4)==0) {
1020 lseek(fd, sub_chunk_len - 8, SEEK_CUR);
1021 j-=(sub_chunk_len - 8);
1022 n=read_uint32be(fd,&sub_chunk_len);
1023 n=read(fd,&sub_chunk_id,4);
1024 j-=8;
1025 if (memcmp(&sub_chunk_id,"ilst",4)==0) {
1026 /* Here are the actual tags. We use the id3v2 300-byte buffer
1027 to store the string data */
1028 bytes_remaining=sizeof(id3->id3v2buf);
1029 id3->genre=255; /* Not every track is the Blues */
1030 id3buf=id3->id3v2buf;
1031 k=sub_chunk_len-8;
1032 j-=k;
1033 while (k > 0) {
1034 n=read_uint32be(fd,&sub_chunk_len);
1035 n=read(fd,&sub_chunk_id,4);
1036 k-=8;
1037 if (memcmp(sub_chunk_id,"\251nam",4)==0) {
1038 read_m4a_tag_string(fd,sub_chunk_len-8,&id3buf,&bytes_remaining,&id3->title);
1039 } else if (memcmp(sub_chunk_id,"\251ART",4)==0) {
1040 read_m4a_tag_string(fd,sub_chunk_len-8,&id3buf,&bytes_remaining,&id3->artist);
1041 } else if (memcmp(sub_chunk_id,"\251alb",4)==0) {
1042 read_m4a_tag_string(fd,sub_chunk_len-8,&id3buf,&bytes_remaining,&id3->album);
1043 } else if (memcmp(sub_chunk_id,"\251gen",4)==0) {
1044 read_m4a_tag_string(fd,sub_chunk_len-8,&id3buf,&bytes_remaining,&id3->genre_string);
1045 } else if (memcmp(sub_chunk_id,"\251day",4)==0) {
1046 read_m4a_tag_string(fd,sub_chunk_len-8,&id3buf,&bytes_remaining,&id3->year_string);
1047 } else if (memcmp(sub_chunk_id,"trkn",4)==0) {
1048 if (sub_chunk_len==0x20) {
1049 read(fd,buf,sub_chunk_len-8);
1050 id3->tracknum=buf[19];
1051 } else {
1052 lseek(fd, sub_chunk_len-8,SEEK_CUR);
1054 } else {
1055 lseek(fd, sub_chunk_len-8,SEEK_CUR);
1057 k-=(sub_chunk_len-8);
1062 /* Skip any remaining data in udta chunk */
1063 lseek(fd, j, SEEK_CUR);
1064 } else if (memcmp(&sub_chunk_id,"trak",4)==0) {
1065 /* Format of trak chunk:
1066 tkhd
1067 mdia
1068 mdhd
1069 hdlr
1070 minf
1071 smhd
1072 dinf
1073 stbl
1074 stsd - Samplerate, Samplesize, Numchannels
1075 stts - time_to_sample array - RLE'd table containing duration of each block
1076 stsz - sample_byte_size array - ?Size in bytes of each compressed block
1077 stsc - Seek table related?
1078 stco - Seek table related?
1081 /* Skip tkhd - not needed */
1082 n=read_uint32be(fd,&sub_chunk_len);
1083 n=read(fd,&sub_chunk_id,4);
1084 if (memcmp(&sub_chunk_id,"tkhd",4)!=0) {
1085 logf("Expecting tkhd\n");
1086 return false;
1088 lseek(fd, sub_chunk_len - 8, SEEK_CUR); /* FIXME not 8 */
1089 size_remaining-=sub_chunk_len;
1091 /* Process mdia - skipping possible edts */
1092 n=read_uint32be(fd,&sub_chunk_len);
1093 n=read(fd,&sub_chunk_id,4);
1094 if (memcmp(&sub_chunk_id,"edts",4)==0) {
1095 lseek(fd, sub_chunk_len - 8, SEEK_CUR); /* FIXME not 8 */
1096 size_remaining-=sub_chunk_len;
1097 n=read_uint32be(fd,&sub_chunk_len);
1098 n=read(fd,&sub_chunk_id,4);
1101 if (memcmp(&sub_chunk_id,"mdia",4)!=0) {
1102 logf("Expecting mdia\n");
1103 return false;
1105 size_remaining-=sub_chunk_len;
1106 j=sub_chunk_len-8;
1108 while (j > 0) {
1109 n=read_uint32be(fd,&sub_chunk_len);
1110 n=read(fd,&sub_chunk_id,4);
1111 j-=4;
1112 if (memcmp(&sub_chunk_id,"minf",4)==0) {
1113 j=sub_chunk_len-8;
1114 } else if (memcmp(&sub_chunk_id,"stbl",4)==0) {
1115 j=sub_chunk_len-8;
1116 } else if (memcmp(&sub_chunk_id,"stsd",4)==0) {
1117 n=read(fd,buf,sub_chunk_len-8);
1118 j-=sub_chunk_len;
1119 i=0;
1120 /* Skip version and flags */
1121 i+=4;
1123 numentries=(buf[i]<<24)|(buf[i+1]<<16)|(buf[i+2]<<8)|buf[i+3];
1124 i+=4;
1125 if (numentries!=1) {
1126 logf("ERROR: Expecting only one entry in stsd\n");
1129 entry_size=(buf[i]<<24)|(buf[i+1]<<16)|(buf[i+2]<<8)|buf[i+3];
1130 i+=4;
1132 if (memcmp(&buf[i],"alac",4)==0) {
1133 id3->codectype=AFMT_ALAC;
1134 } else if (memcmp(&buf[i],"mp4a",4)==0) {
1135 id3->codectype=AFMT_AAC;
1136 } else {
1137 logf("Not an ALAC or AAC file\n");
1138 return false;
1141 //numchannels=(buf[i+20]<<8)|buf[i+21]; /* Not used - assume Stereo */
1142 //samplesize=(buf[i+22]<<8)|buf[i+23]; /* Not used - assume 16-bit */
1144 /* Samplerate is 32-bit fixed point, but this works for < 65536 Hz */
1145 id3->frequency=(buf[i+28]<<8)|buf[i+29];
1146 } else if (memcmp(&sub_chunk_id,"stts",4)==0) {
1147 j-=sub_chunk_len;
1148 i=8;
1149 n=read(fd,buf,8);
1150 i+=8;
1151 numentries=(buf[4]<<24)|(buf[5]<<16)|(buf[6]<<8)|buf[7];
1152 for (k=0;k<numentries;k++) {
1153 n=read_uint32be(fd,&sample_count);
1154 n=read_uint32be(fd,&sample_duration);
1155 totalsamples+=sample_count*sample_duration;
1156 i+=8;
1158 if (i > 0) lseek(fd, sub_chunk_len - i, SEEK_CUR);
1159 } else if (memcmp(&sub_chunk_id,"stsz",4)==0) {
1160 j-=sub_chunk_len;
1161 i=8;
1162 n=read(fd,buf,8);
1163 i+=8;
1164 numentries=(buf[4]<<24)|(buf[5]<<16)|(buf[6]<<8)|buf[7];
1165 for (k=0;k<numentries;k++) {
1166 n=read_uint32be(fd,&sample_count);
1167 n=read_uint32be(fd,&sample_duration);
1168 totalsamples+=sample_count*sample_duration;
1169 i+=8;
1171 if (i > 0) lseek(fd, sub_chunk_len - i, SEEK_CUR);
1172 } else {
1173 lseek(fd, sub_chunk_len - 8, SEEK_CUR); /* FIXME not 8 */
1174 j-=sub_chunk_len;
1177 } else {
1178 logf("Unexpected sub_chunk_id inside moov: %c%c%c%c\n",
1179 sub_chunk_id[0],sub_chunk_id[1],sub_chunk_id[2],sub_chunk_id[3]);
1180 return false;
1183 } else if (memcmp(&chunk_id,"mdat",4)==0) {
1184 /* once we hit mdat we stop reading and return.
1185 * this is on the assumption that there is no furhter interesting
1186 * stuff in the stream. if there is stuff will fail (:()).
1187 * But we need the read pointer to be at the mdat stuff
1188 * for the decoder. And we don't want to rely on fseek/ftell,
1189 * as they may not always be avilable */
1190 lseek(fd, chunk_len - 8, SEEK_CUR); /* FIXME not 8 */
1191 compressedsize=chunk_len-8;
1192 } else if (memcmp(&chunk_id,"free",4)==0) {
1193 /* these following atoms can be skipped !!!! */
1194 lseek(fd, chunk_len - 8, SEEK_CUR); /* FIXME not 8 */
1195 } else {
1196 logf("(top) unknown chunk id: %c%c%c%c\n", chunk_id[0],chunk_id[1],chunk_id[2],chunk_id[3]);
1197 return false;
1201 id3->vbr=true; /* All ALAC files are VBR */
1202 id3->filesize=filesize(fd);
1203 id3->samples=totalsamples;
1204 id3->length=(10*totalsamples)/(id3->frequency/100);
1205 id3->bitrate=(compressedsize*8)/id3->length;;
1207 return true;
1210 static bool get_musepack_metadata(int fd, struct mp3entry *id3)
1212 const int32_t sfreqs_sv7[4] = { 44100, 48000, 37800, 32000 };
1213 uint32_t header[8];
1214 uint64_t samples = 0;
1215 int i;
1217 if (!skip_id3v2(fd, id3))
1218 return false;
1219 if (read(fd, header, 4*8) != 4*8) return false;
1220 /* Musepack files are little endian, might need swapping */
1221 for (i = 1; i < 8; i++)
1222 header[i] = letoh32(header[i]);
1223 if (!memcmp(header, "MP+", 3)) { /* Compare to sig "MP+" */
1224 unsigned int streamversion;
1226 header[0] = letoh32(header[0]);
1227 streamversion = (header[0] >> 24) & 15;
1228 if (streamversion >= 8) {
1229 return false; /* SV8 or higher don't exist yet, so no support */
1230 } else if (streamversion == 7) {
1231 unsigned int gapless = (header[5] >> 31) & 0x0001;
1232 unsigned int last_frame_samples = (header[5] >> 20) & 0x07ff;
1233 int track_gain, album_gain;
1234 unsigned int bufused;
1236 id3->frequency = sfreqs_sv7[(header[2] >> 16) & 0x0003];
1237 samples = (uint64_t)header[1]*1152; /* 1152 is mpc frame size */
1238 if (gapless)
1239 samples -= 1152 - last_frame_samples;
1240 else
1241 samples -= 481; /* Musepack subband synth filter delay */
1243 /* Extract ReplayGain data from header */
1244 track_gain = (int16_t)((header[3] >> 16) & 0xffff);
1245 id3->track_gain = get_replaygain_int(track_gain);
1246 id3->track_peak = ((uint16_t)(header[3] & 0xffff)) << 9;
1248 album_gain = (int16_t)((header[4] >> 16) & 0xffff);
1249 id3->album_gain = get_replaygain_int(album_gain);
1250 id3->album_peak = ((uint16_t)(header[4] & 0xffff)) << 9;
1252 /* Write replaygain values to strings for use in id3 screen. We use
1253 the XING header as buffer space since Musepack files shouldn't
1254 need to use it in any other way */
1255 id3->track_gain_string = id3->toc;
1256 bufused = snprintf(id3->track_gain_string, 45,
1257 "%d.%d dB", track_gain/100, abs(track_gain)%100);
1258 id3->album_gain_string = id3->toc + bufused + 1;
1259 bufused = snprintf(id3->album_gain_string, 45,
1260 "%d.%d dB", album_gain/100, abs(album_gain)%100);
1262 } else {
1263 header[0] = letoh32(header[0]);
1264 unsigned int streamversion = (header[0] >> 11) & 0x03FF;
1265 if (streamversion != 4 && streamversion != 5 && streamversion != 6)
1266 return false;
1267 id3->frequency = 44100;
1268 id3->track_gain = 0;
1269 id3->track_peak = 0;
1270 id3->album_gain = 0;
1271 id3->album_peak = 0;
1273 if (streamversion >= 5)
1274 samples = (uint64_t)header[1]*1152; // 32 bit
1275 else
1276 samples = (uint64_t)(header[1] >> 16)*1152; // 16 bit
1278 samples -= 576;
1279 if (streamversion < 6)
1280 samples -= 1152;
1283 id3->vbr = true;
1284 /* Estimate bitrate, we should probably subtract the various header sizes
1285 here for super-accurate results */
1286 id3->length = samples/id3->frequency*1000;
1287 id3->filesize = filesize(fd);
1288 id3->bitrate = id3->filesize*8/id3->length;
1289 return true;
1292 static bool get_sid_metadata(int fd, struct mp3entry* id3)
1294 /* Use the trackname part of the id3 structure as a temporary buffer */
1295 unsigned char* buf = id3->path;
1296 int read_bytes;
1297 char *p;
1300 if ((lseek(fd, 0, SEEK_SET) < 0)
1301 || ((read_bytes = read(fd, buf, sizeof(id3->path))) < 44))
1303 return false;
1306 if ((memcmp(buf, "PSID",4) != 0))
1308 return false;
1311 p = id3->id3v2buf;
1313 /* Copy Title */
1314 strcpy(p, &buf[0x16]);
1315 id3->title = p;
1316 p += strlen(p)+1;
1318 /* Copy Artist */
1319 strcpy(p, &buf[0x36]);
1320 id3->artist = p;
1321 p += strlen(p)+1;
1323 id3->bitrate = 706;
1324 id3->frequency = 44100;
1325 /* New idea as posted by Marco Alanen (ravon):
1326 * Set the songlength in seconds to the number of subsongs
1327 * so every second represents a subsong.
1328 * Users can then skip the current subsong by seeking */
1329 id3->length = (buf[0xf]-1)*1000;
1330 id3->vbr = false;
1331 id3->filesize = filesize(fd);
1333 return true;
1336 #endif /* CONFIG_CODEC == SWCODEC */
1338 static bool get_aiff_metadata(int fd, struct mp3entry* id3)
1340 /* Use the trackname part of the id3 structure as a temporary buffer */
1341 unsigned char* buf = id3->path;
1342 unsigned long numChannels = 0;
1343 unsigned long numSampleFrames = 0;
1344 unsigned long sampleSize = 0;
1345 unsigned long sampleRate = 0;
1346 unsigned long numbytes = 0;
1347 int read_bytes;
1348 int i;
1350 if ((lseek(fd, 0, SEEK_SET) < 0)
1351 || ((read_bytes = read(fd, buf, sizeof(id3->path))) < 44))
1353 return false;
1356 if ((memcmp(buf, "FORM",4) != 0)
1357 || (memcmp(&buf[8], "AIFF", 4) !=0 ))
1359 return false;
1362 buf += 12;
1363 read_bytes -= 12;
1365 while ((numbytes == 0) && (read_bytes >= 8))
1367 /* chunkSize */
1368 i = ((buf[4]<<24)|(buf[5]<<16)|(buf[6]<<8)|buf[7]);
1370 if (memcmp(buf, "COMM", 4) == 0)
1372 /* numChannels */
1373 numChannels = ((buf[8]<<8)|buf[9]);
1374 /* numSampleFrames */
1375 numSampleFrames =((buf[10]<<24)|(buf[11]<<16)|(buf[12]<<8)|buf[13]);
1376 /* sampleSize */
1377 sampleSize = ((buf[14]<<8)|buf[15]);
1378 /* sampleRate */
1379 sampleRate = ((buf[18]<<24)|(buf[19]<<16)|(buf[20]<<8)|buf[21]);
1380 sampleRate = sampleRate >> (16+14-buf[17]);
1381 /* save format infos */
1382 id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000;
1383 id3->frequency = sampleRate;
1384 id3->length = (numSampleFrames / id3->frequency) * 1000;
1385 id3->vbr = false; /* AIFF files are CBR */
1386 id3->filesize = filesize(fd);
1388 else if (memcmp(buf, "SSND", 4) == 0)
1390 numbytes = i - 8;
1393 if (i & 0x01)
1395 i++; /* odd chunk sizes must be padded */
1397 buf += i + 8;
1398 read_bytes -= i + 8;
1401 if ((numbytes == 0) || (numChannels == 0))
1403 return false;
1405 return true;
1408 /* Simple file type probing by looking at the filename extension. */
1409 unsigned int probe_file_format(const char *filename)
1411 char *suffix;
1412 unsigned int i;
1414 suffix = strrchr(filename, '.');
1416 if (suffix == NULL)
1418 return AFMT_UNKNOWN;
1421 suffix += 1;
1423 for (i = 0; i < sizeof(formats) / sizeof(formats[0]); i++)
1425 if (strcasecmp(suffix, formats[i].extension) == 0)
1427 return formats[i].format;
1431 return AFMT_UNKNOWN;
1434 /* Get metadata for track - return false if parsing showed problems with the
1435 * file that would prevent playback.
1437 bool get_metadata(struct track_info* track, int fd, const char* trackname,
1438 bool v1first)
1440 #if CONFIG_CODEC == SWCODEC
1441 unsigned char* buf;
1442 unsigned long totalsamples;
1443 int i;
1444 #endif
1446 /* Take our best guess at the codec type based on file extension */
1447 track->id3.codectype = probe_file_format(trackname);
1449 /* Load codec specific track tag information and confirm the codec type. */
1450 switch (track->id3.codectype)
1452 case AFMT_MPA_L1:
1453 case AFMT_MPA_L2:
1454 case AFMT_MPA_L3:
1455 if (mp3info(&track->id3, trackname, v1first))
1457 return false;
1460 break;
1462 #if CONFIG_CODEC == SWCODEC
1463 case AFMT_FLAC:
1464 if (!get_flac_metadata(fd, &(track->id3)))
1466 return false;
1469 break;
1471 case AFMT_MPC:
1472 if (!get_musepack_metadata(fd, &(track->id3)))
1473 return false;
1474 read_ape_tags(fd, &(track->id3));
1475 break;
1477 case AFMT_OGG_VORBIS:
1478 if (!get_vorbis_metadata(fd, &(track->id3)))
1480 return false;
1483 break;
1485 case AFMT_PCM_WAV:
1486 if (!get_wave_metadata(fd, &(track->id3)))
1488 return false;
1491 break;
1493 case AFMT_WAVPACK:
1494 /* A simple parser to read basic information from a WavPack file. This
1495 * now works with self-extrating WavPack files and also will fail on
1496 * WavPack files containing floating-point audio data (although these
1497 * should be possible to play in theory).
1500 /* Use the trackname part of the id3 structure as a temporary buffer */
1501 buf = track->id3.path;
1503 for (i = 0; i < 256; ++i) {
1505 /* at every 256 bytes into file, try to read a WavPack header */
1507 if ((lseek(fd, i * 256, SEEK_SET) < 0) || (read(fd, buf, 32) < 32))
1509 return false;
1512 /* if valid WavPack 4 header version & not floating data, break */
1514 if (memcmp (buf, "wvpk", 4) == 0 && buf [9] == 4 &&
1515 (buf [8] >= 2 && buf [8] <= 0x10) && !(buf [24] & 0x80))
1517 break;
1521 if (i == 256) {
1522 logf ("%s is not a WavPack file\n", trackname);
1523 return false;
1526 track->id3.vbr = true; /* All WavPack files are VBR */
1527 track->id3.filesize = filesize (fd);
1529 if ((buf [20] | buf [21] | buf [22] | buf [23]) &&
1530 (buf [12] & buf [13] & buf [14] & buf [15]) != 0xff)
1532 int srindx = ((buf [26] >> 7) & 1) + ((buf [27] << 1) & 14);
1534 if (srindx == 15)
1536 track->id3.frequency = 44100;
1538 else
1540 track->id3.frequency = wavpack_sample_rates[srindx];
1543 totalsamples = get_long(&buf[12]);
1544 track->id3.length = totalsamples / (track->id3.frequency / 100) * 10;
1545 track->id3.bitrate = filesize (fd) / (track->id3.length / 8);
1548 read_ape_tags(fd, &track->id3); /* use any apetag info we find */
1549 break;
1551 case AFMT_A52:
1552 /* Use the trackname part of the id3 structure as a temporary buffer */
1553 buf = track->id3.path;
1555 if ((lseek(fd, 0, SEEK_SET) < 0) || (read(fd, buf, 5) < 5))
1557 return false;
1560 if ((buf[0] != 0x0b) || (buf[1] != 0x77))
1562 logf("%s is not an A52/AC3 file\n",trackname);
1563 return false;
1566 i = buf[4] & 0x3e;
1568 if (i > 36)
1570 logf("A52: Invalid frmsizecod: %d\n",i);
1571 return false;
1574 track->id3.bitrate = a52_bitrates[i >> 1];
1575 track->id3.vbr = false;
1576 track->id3.filesize = filesize(fd);
1578 switch (buf[4] & 0xc0)
1580 case 0x00:
1581 track->id3.frequency = 48000;
1582 track->id3.bytesperframe=track->id3.bitrate * 2 * 2;
1583 break;
1585 case 0x40:
1586 track->id3.frequency = 44100;
1587 track->id3.bytesperframe = a52_441framesizes[i];
1588 break;
1590 case 0x80:
1591 track->id3.frequency = 32000;
1592 track->id3.bytesperframe = track->id3.bitrate * 3 * 2;
1593 break;
1595 default:
1596 logf("A52: Invalid samplerate code: 0x%02x\n", buf[4] & 0xc0);
1597 return false;
1598 break;
1601 /* One A52 frame contains 6 blocks, each containing 256 samples */
1602 totalsamples = track->id3.filesize / track->id3.bytesperframe * 6 * 256;
1603 track->id3.length = totalsamples / track->id3.frequency * 1000;
1604 break;
1606 case AFMT_ALAC:
1607 case AFMT_AAC:
1608 if (!get_m4a_metadata(fd, &(track->id3)))
1610 return false;
1613 break;
1615 case AFMT_SHN:
1616 track->id3.vbr = true;
1617 track->id3.filesize = filesize(fd);
1618 if (!skip_id3v2(fd, &(track->id3)))
1620 return false;
1622 /* TODO: read the id3v2 header if it exists */
1623 break;
1625 case AFMT_SID:
1626 if (!get_sid_metadata(fd, &(track->id3)))
1628 return false;
1630 break;
1632 #endif /* CONFIG_CODEC == SWCODEC */
1634 case AFMT_AIFF:
1635 if (!get_aiff_metadata(fd, &(track->id3)))
1637 return false;
1640 break;
1642 default:
1643 /* If we don't know how to read the metadata, assume we can't play
1644 the file */
1645 return false;
1646 break;
1649 /* We have successfully read the metadata from the file */
1651 lseek(fd, 0, SEEK_SET);
1652 strncpy(track->id3.path, trackname, sizeof(track->id3.path));
1653 track->taginfo_ready = true;
1655 return true;