diff options
Diffstat (limited to 'apps/metadata.c')
-rw-r--r-- | apps/metadata.c | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/apps/metadata.c b/apps/metadata.c index 41ea0196c0..531969b8aa 100644 --- a/apps/metadata.c +++ b/apps/metadata.c | |||
@@ -78,6 +78,8 @@ static const struct format_list formats[] = | |||
78 | { AFMT_ALAC, "m4a" }, | 78 | { AFMT_ALAC, "m4a" }, |
79 | { AFMT_AAC, "mp4" }, | 79 | { AFMT_AAC, "mp4" }, |
80 | { AFMT_SHN, "shn" }, | 80 | { AFMT_SHN, "shn" }, |
81 | { AFMT_AIFF, "aif" }, | ||
82 | { AFMT_AIFF, "aiff" }, | ||
81 | }; | 83 | }; |
82 | 84 | ||
83 | static const unsigned short a52_bitrates[] = | 85 | static const unsigned short a52_bitrates[] = |
@@ -894,7 +896,6 @@ static bool get_wave_metadata(int fd, struct mp3entry* id3) | |||
894 | } | 896 | } |
895 | 897 | ||
896 | 898 | ||
897 | |||
898 | static bool get_m4a_metadata(int fd, struct mp3entry* id3) | 899 | static bool get_m4a_metadata(int fd, struct mp3entry* id3) |
899 | { | 900 | { |
900 | unsigned char* buf; | 901 | unsigned char* buf; |
@@ -1245,6 +1246,76 @@ static bool get_musepack_metadata(int fd, struct mp3entry *id3) | |||
1245 | return true; | 1246 | return true; |
1246 | } | 1247 | } |
1247 | 1248 | ||
1249 | static bool get_aiff_metadata(int fd, struct mp3entry* id3) | ||
1250 | { | ||
1251 | /* Use the trackname part of the id3 structure as a temporary buffer */ | ||
1252 | unsigned char* buf = id3->path; | ||
1253 | unsigned long numChannels = 0; | ||
1254 | unsigned long numSampleFrames = 0; | ||
1255 | unsigned long sampleSize = 0; | ||
1256 | unsigned long sampleRate = 0; | ||
1257 | unsigned long numbytes = 0; | ||
1258 | int read_bytes; | ||
1259 | int i; | ||
1260 | |||
1261 | if ((lseek(fd, 0, SEEK_SET) < 0) | ||
1262 | || ((read_bytes = read(fd, buf, sizeof(id3->path))) < 44)) | ||
1263 | { | ||
1264 | return false; | ||
1265 | } | ||
1266 | |||
1267 | if ((memcmp(buf, "FORM",4) != 0) | ||
1268 | || (memcmp(&buf[8], "AIFF", 4) !=0 )) | ||
1269 | { | ||
1270 | return false; | ||
1271 | } | ||
1272 | |||
1273 | buf += 12; | ||
1274 | read_bytes -= 12; | ||
1275 | |||
1276 | while ((numbytes == 0) && (read_bytes >= 8)) | ||
1277 | { | ||
1278 | /* chunkSize */ | ||
1279 | i = ((buf[4]<<24)|(buf[5]<<16)|(buf[6]<<8)|buf[7]); | ||
1280 | |||
1281 | if (memcmp(buf, "COMM", 4) == 0) | ||
1282 | { | ||
1283 | /* numChannels */ | ||
1284 | numChannels = ((buf[8]<<8)|buf[9]); | ||
1285 | /* numSampleFrames */ | ||
1286 | numSampleFrames =((buf[10]<<24)|(buf[11]<<16)|(buf[12]<<8)|buf[13]); | ||
1287 | /* sampleSize */ | ||
1288 | sampleSize = ((buf[14]<<8)|buf[15]); | ||
1289 | /* sampleRate */ | ||
1290 | sampleRate = ((buf[18]<<24)|(buf[19]<<16)|(buf[20]<<8)|buf[21]); | ||
1291 | sampleRate = sampleRate >> (16+14-buf[17]); | ||
1292 | /* save format infos */ | ||
1293 | id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000; | ||
1294 | id3->frequency = sampleRate; | ||
1295 | id3->length = (numSampleFrames / id3->frequency) * 1000; | ||
1296 | id3->vbr = false; /* AIFF files are CBR */ | ||
1297 | id3->filesize = filesize(fd); | ||
1298 | } | ||
1299 | else if (memcmp(buf, "SSND", 4) == 0) | ||
1300 | { | ||
1301 | numbytes = i - 8; | ||
1302 | } | ||
1303 | |||
1304 | if (i & 0x01) | ||
1305 | { | ||
1306 | i++; /* odd chunk sizes must be padded */ | ||
1307 | } | ||
1308 | buf += i + 8; | ||
1309 | read_bytes -= i + 8; | ||
1310 | } | ||
1311 | |||
1312 | if ((numbytes == 0) || (numChannels == 0)) | ||
1313 | { | ||
1314 | return false; | ||
1315 | } | ||
1316 | return true; | ||
1317 | } | ||
1318 | |||
1248 | /* Simple file type probing by looking at the filename extension. */ | 1319 | /* Simple file type probing by looking at the filename extension. */ |
1249 | static unsigned int probe_file_format(const char *filename) | 1320 | static unsigned int probe_file_format(const char *filename) |
1250 | { | 1321 | { |
@@ -1448,6 +1519,14 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname, | |||
1448 | /* TODO: read the id3v2 header if it exists */ | 1519 | /* TODO: read the id3v2 header if it exists */ |
1449 | break; | 1520 | break; |
1450 | 1521 | ||
1522 | case AFMT_AIFF: | ||
1523 | if (!get_aiff_metadata(fd, &(track->id3))) | ||
1524 | { | ||
1525 | return false; | ||
1526 | } | ||
1527 | |||
1528 | break; | ||
1529 | |||
1451 | default: | 1530 | default: |
1452 | /* If we don't know how to read the metadata, assume we can't play | 1531 | /* If we don't know how to read the metadata, assume we can't play |
1453 | the file */ | 1532 | the file */ |