FS#6216 Update so MP3 files are only opened once. With corrections and

patch cleanup.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11343 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Miika Pekkarinen 2006-10-25 16:57:53 +00:00
parent 649fc77aea
commit 58ebf47a2b
3 changed files with 26 additions and 14 deletions

View file

@ -1577,8 +1577,6 @@ static bool get_adx_metadata(int fd, struct mp3entry* id3)
return true;
}
#endif /* CONFIG_CODEC == SWCODEC */
static bool get_aiff_metadata(int fd, struct mp3entry* id3)
{
/* Use the trackname part of the id3 structure as a temporary buffer */
@ -1648,6 +1646,8 @@ static bool get_aiff_metadata(int fd, struct mp3entry* id3)
}
return true;
}
#endif /* CONFIG_CODEC == SWCODEC */
/* Simple file type probing by looking at the filename extension. */
unsigned int probe_file_format(const char *filename)
@ -1696,7 +1696,7 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname,
case AFMT_MPA_L1:
case AFMT_MPA_L2:
case AFMT_MPA_L3:
if (mp3info(&track->id3, trackname, v1first))
if (!get_mp3_metadata(fd, &track->id3, trackname, v1first))
{
return false;
}
@ -1881,7 +1881,6 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname,
}
break;
#endif /* CONFIG_CODEC == SWCODEC */
case AFMT_AIFF:
if (!get_aiff_metadata(fd, &(track->id3)))
@ -1891,6 +1890,8 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname,
break;
#endif /* CONFIG_CODEC == SWCODEC */
default:
/* If we don't know how to read the metadata, assume we can't play
the file */

View file

@ -172,6 +172,7 @@ enum {
ID3_VER_2_4
};
bool get_mp3_metadata(int fd, struct mp3entry *entry, const char *filename, bool v1first);
bool mp3info(struct mp3entry *entry, const char *filename, bool v1first);
char* id3_get_genre(const struct mp3entry* id3);
char* id3_get_codec(const struct mp3entry* id3);

View file

@ -1035,16 +1035,11 @@ static int getsonglength(int fd, struct mp3entry *entry)
* Checks all relevant information (such as ID3v1 tag, ID3v2 tag, length etc)
* about an MP3 file and updates it's entry accordingly.
*
*/
bool mp3info(struct mp3entry *entry, const char *filename, bool v1first)
Note, that this returns true for successful, false for error! */
bool get_mp3_metadata(int fd, struct mp3entry *entry, const char *filename, bool v1first)
{
int fd;
int v1found = false;
fd = open(filename, O_RDONLY);
if(-1 == fd)
return true;
#if CONFIG_CODEC != SWCODEC
memset(entry, 0, sizeof(struct mp3entry));
#endif
@ -1074,14 +1069,29 @@ bool mp3info(struct mp3entry *entry, const char *filename, bool v1first)
setid3v1title(fd, entry);
}
close(fd);
if(!entry->length || (entry->filesize < 8 ))
/* no song length or less than 8 bytes is hereby considered to be an
invalid mp3 and won't be played by us! */
return false;
return true;
}
/* Note, that this returns false for successful, true for error! */
bool mp3info(struct mp3entry *entry, const char *filename, bool v1first)
{
int fd;
bool result;
fd = open(filename, O_RDONLY);
if (fd < 0)
return true;
return false;
result = !get_mp3_metadata(fd, entry, filename, v1first);
close(fd);
return result;
}
void adjust_mp3entry(struct mp3entry *entry, void *dest, void *orig)