summaryrefslogtreecommitdiff
path: root/apps/metadata.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/metadata.c')
-rw-r--r--apps/metadata.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/apps/metadata.c b/apps/metadata.c
index a4d8ef0f64..ee0100ecf7 100644
--- a/apps/metadata.c
+++ b/apps/metadata.c
@@ -760,13 +760,14 @@ static bool get_vorbis_metadata(int fd, struct mp3entry* id3)
760 return false; 760 return false;
761 } 761 }
762 762
763 id3->length = ((int64_t) id3->samples * 1000) / id3->frequency;
764
763 if (id3->length <= 0) 765 if (id3->length <= 0)
764 { 766 {
765 logf("ogg length invalid!"); 767 logf("ogg length invalid!");
766 return false; 768 return false;
767 } 769 }
768 770
769 id3->length = (id3->samples / id3->frequency) * 1000;
770 id3->bitrate = (((int64_t) id3->filesize - comment_size) * 8) / id3->length; 771 id3->bitrate = (((int64_t) id3->filesize - comment_size) * 8) / id3->length;
771 id3->vbr = true; 772 id3->vbr = true;
772 773
@@ -829,7 +830,14 @@ static bool get_flac_metadata(int fd, struct mp3entry* id3)
829 | (buf[16] << 8) | buf[17]; 830 | (buf[16] << 8) | buf[17];
830 831
831 /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */ 832 /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */
832 id3->length = (totalsamples / id3->frequency) * 1000; 833 id3->length = ((int64_t) totalsamples * 1000) / id3->frequency;
834
835 if (id3->length <= 0)
836 {
837 logf("flac length invalid!");
838 return false;
839 }
840
833 id3->bitrate = (id3->filesize * 8) / id3->length; 841 id3->bitrate = (id3->filesize * 8) / id3->length;
834 } 842 }
835 else if ((buf[0] & 0x7f) == 4) /* 4 is the VORBIS_COMMENT block */ 843 else if ((buf[0] & 0x7f) == 4) /* 4 is the VORBIS_COMMENT block */
@@ -957,7 +965,7 @@ static bool get_wave_metadata(int fd, struct mp3entry* id3)
957 id3->filesize = filesize(fd); 965 id3->filesize = filesize(fd);
958 966
959 /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */ 967 /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */
960 id3->length = (totalsamples / id3->frequency) * 1000; 968 id3->length = ((int64_t) totalsamples * 1000) / id3->frequency;
961 969
962 return true; 970 return true;
963} 971}
@@ -1329,7 +1337,14 @@ static bool get_mp4_metadata(int fd, struct mp3entry* id3)
1329 return false; 1337 return false;
1330 } 1338 }
1331 1339
1332 id3->length = (id3->samples / id3->frequency) * 1000; 1340 id3->length = ((int64_t) id3->samples * 1000) / id3->frequency;
1341
1342 if (id3->length <= 0)
1343 {
1344 logf("mp4 length invalid!");
1345 return false;
1346 }
1347
1333 id3->bitrate = ((int64_t) id3->filesize * 8) / id3->length; 1348 id3->bitrate = ((int64_t) id3->filesize * 8) / id3->length;
1334 DEBUGF("MP4 bitrate %d, frequency %d Hz, length %d ms\n", 1349 DEBUGF("MP4 bitrate %d, frequency %d Hz, length %d ms\n",
1335 id3->bitrate, id3->frequency, id3->length); 1350 id3->bitrate, id3->frequency, id3->length);
@@ -1421,9 +1436,16 @@ static bool get_musepack_metadata(int fd, struct mp3entry *id3)
1421 id3->vbr = true; 1436 id3->vbr = true;
1422 /* Estimate bitrate, we should probably subtract the various header sizes 1437 /* Estimate bitrate, we should probably subtract the various header sizes
1423 here for super-accurate results */ 1438 here for super-accurate results */
1424 id3->length = samples/id3->frequency*1000; 1439 id3->length = ((int64_t) samples * 1000) / id3->frequency;
1440
1441 if (id3->length <= 0)
1442 {
1443 logf("mpc length invalid!");
1444 return false;
1445 }
1446
1425 id3->filesize = filesize(fd); 1447 id3->filesize = filesize(fd);
1426 id3->bitrate = id3->filesize*8/id3->length; 1448 id3->bitrate = id3->filesize * 8 / id3->length;
1427 return true; 1449 return true;
1428} 1450}
1429 1451
@@ -1629,7 +1651,8 @@ static bool get_aiff_metadata(int fd, struct mp3entry* id3)
1629 /* save format infos */ 1651 /* save format infos */
1630 id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000; 1652 id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000;
1631 id3->frequency = sampleRate; 1653 id3->frequency = sampleRate;
1632 id3->length = (numSampleFrames / id3->frequency) * 1000; 1654 id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency;
1655
1633 id3->vbr = false; /* AIFF files are CBR */ 1656 id3->vbr = false; /* AIFF files are CBR */
1634 id3->filesize = filesize(fd); 1657 id3->filesize = filesize(fd);
1635 } 1658 }