summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-10-25 16:57:53 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-10-25 16:57:53 +0000
commit58ebf47a2b5cedefdf0aaf48f669f6b926d61913 (patch)
treef819291213cb791b99da70d25a4e4aa1b916fad9
parent649fc77aea5fbf62f6a1600ea6ba545eae4109d6 (diff)
downloadrockbox-58ebf47a2b5cedefdf0aaf48f669f6b926d61913.tar.gz
rockbox-58ebf47a2b5cedefdf0aaf48f669f6b926d61913.zip
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
-rw-r--r--apps/metadata.c9
-rw-r--r--firmware/export/id3.h1
-rw-r--r--firmware/id3.c30
3 files changed, 26 insertions, 14 deletions
diff --git a/apps/metadata.c b/apps/metadata.c
index ff0cb76cbe..9fbf2e19cd 100644
--- a/apps/metadata.c
+++ b/apps/metadata.c
@@ -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 */
diff --git a/firmware/export/id3.h b/firmware/export/id3.h
index 2a42788788..1d07affbfa 100644
--- a/firmware/export/id3.h
+++ b/firmware/export/id3.h
@@ -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);
diff --git a/firmware/id3.c b/firmware/id3.c
index d14134f215..92f60a2095 100644
--- a/firmware/id3.c
+++ b/firmware/id3.c
@@ -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)