summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2007-02-14 19:20:13 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2007-02-14 19:20:13 +0000
commit7a395a23bfb17bc7d2df5950fda1b16530efd68d (patch)
tree2d5428767bff3e92f2512653e7458689ec735bcd
parent9d5f73cd85641932791537c7bc89256a8fb84e1d (diff)
downloadrockbox-7a395a23bfb17bc7d2df5950fda1b16530efd68d.tar.gz
rockbox-7a395a23bfb17bc7d2df5950fda1b16530efd68d.tar.bz2
rockbox-7a395a23bfb17bc7d2df5950fda1b16530efd68d.zip
Start using the new endian conversion system outside tagcache also to simplify code.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12309 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/metadata.c90
-rw-r--r--apps/talk.c15
-rw-r--r--firmware/common/structec.c12
3 files changed, 27 insertions, 90 deletions
diff --git a/apps/metadata.c b/apps/metadata.c
index ae2a8ecda8..fef8111127 100644
--- a/apps/metadata.c
+++ b/apps/metadata.c
@@ -31,12 +31,19 @@
#include "debug.h"
#include "system.h"
#include "cuesheet.h"
+#include "structec.h"
enum tagtype { TAGTYPE_APE = 1, TAGTYPE_VORBIS };
+#ifdef ROCKBOX_BIG_ENDIAN
+#define IS_BIG_ENDIAN 1
+#else
+#define IS_BIG_ENDIAN 0
+#endif
+
#define APETAG_HEADER_LENGTH 32
-#define APETAG_HEADER_FORMAT "8LLLL"
-#define APETAG_ITEM_HEADER_FORMAT "LL"
+#define APETAG_HEADER_FORMAT "8llll"
+#define APETAG_ITEM_HEADER_FORMAT "ll"
#define APETAG_ITEM_TYPE_MASK 3
#define TAG_NAME_LENGTH 32
@@ -153,69 +160,6 @@ static long read_string(int fd, char* buf, long buf_size, int eos, long size)
return read_bytes;
}
-/* Convert a little-endian structure to native format using a format string.
- * Does nothing on a little-endian machine.
- */
-static void convert_endian(void *data, const char *format)
-{
-#ifdef ROCKBOX_BIG_ENDIAN
- while (*format)
- {
- switch (*format)
- {
- case 'L':
- {
- long* d = (long*) data;
-
- *d = letoh32(*d);
- data = d + 1;
- }
-
- break;
-
- case 'S':
- {
- short* d = (short*) data;
-
- *d = letoh16(*d);
- data = d + 1;
- }
-
- break;
-
- default:
- if (isdigit(*format))
- {
- data = ((char*) data) + *format - '0';
- }
-
- break;
- }
-
- format++;
- }
-#else
- (void) data;
- (void) format;
-#endif
-}
-
-#if 0 /* not needed atm */
-/* Read an unsigned 16-bit integer from a big-endian file. */
-#ifdef ROCKBOX_BIG_ENDIAN
-#define read_uint16be(fd, buf) read((fd), (buf), 2)
-#else
-static int read_uint16be(int fd, unsigned short* buf)
-{
- size_t n;
-
- n = read(fd, (char*) buf, 2);
- *buf = betoh16(*buf);
- return n;
-}
-#endif
-#endif /* if 0 */
-
/* Read an unsigned 32-bit integer from a big-endian file. */
#ifdef ROCKBOX_BIG_ENDIAN
#define read_uint32be(fd,buf) read((fd), (buf), 4)
@@ -354,13 +298,12 @@ static bool read_ape_tags(int fd, struct mp3entry* id3)
struct apetag_header header;
if ((lseek(fd, -APETAG_HEADER_LENGTH, SEEK_END) < 0)
- || (read(fd, &header, APETAG_HEADER_LENGTH) != APETAG_HEADER_LENGTH)
+ || (ecread(fd, &header, 1, APETAG_HEADER_FORMAT, IS_BIG_ENDIAN) != APETAG_HEADER_LENGTH)
|| (memcmp(header.id, "APETAGEX", sizeof(header.id))))
{
return false;
}
- convert_endian(&header, APETAG_HEADER_FORMAT);
id3->genre = 0xff;
if ((header.version == 2000) && (header.item_count > 0)
@@ -389,12 +332,11 @@ static bool read_ape_tags(int fd, struct mp3entry* id3)
break;
}
- if (read(fd, &item, sizeof(item)) < (long) sizeof(item))
+ if (ecread(fd, &item, 1, APETAG_ITEM_HEADER_FORMAT, IS_BIG_ENDIAN) < (long) sizeof(item))
{
return false;
}
- convert_endian(&item, APETAG_ITEM_HEADER_FORMAT);
tag_remaining -= sizeof(item);
r = read_string(fd, name, sizeof(name), 0, tag_remaining);
@@ -447,21 +389,18 @@ static bool read_vorbis_tags(int fd, struct mp3entry *id3,
id3->genre = 255;
- if (read(fd, &len, sizeof(len)) < (long) sizeof(len))
+ if (ecread(fd, &len, 1, "l", IS_BIG_ENDIAN) < (long) sizeof(len))
{
return false;
}
- convert_endian(&len, "L");
-
if ((lseek(fd, len, SEEK_CUR) < 0)
- || (read(fd, &comment_count, sizeof(comment_count))
+ || (ecread(fd, &comment_count, 1, "l", IS_BIG_ENDIAN)
< (long) sizeof(comment_count)))
{
return false;
}
- convert_endian(&comment_count, "L");
tag_remaining -= len + sizeof(len) + sizeof(comment_count);
if (tag_remaining <= 0)
@@ -480,12 +419,11 @@ static bool read_vorbis_tags(int fd, struct mp3entry *id3,
break;
}
- if (read(fd, &len, sizeof(len)) < (long) sizeof(len))
+ if (ecread(fd, &len, 1, "l", IS_BIG_ENDIAN) < (long) sizeof(len))
{
return false;
}
- convert_endian(&len, "L");
tag_remaining -= 4;
/* Quit if we've passed the end of the page */
diff --git a/apps/talk.c b/apps/talk.c
index c22b70066e..6629bbb2e5 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -35,6 +35,7 @@
#include "id3.h"
#include "logf.h"
#include "bitswap.h"
+#include "structec.h"
#if CONFIG_CODEC == SWCODEC
#include "playback.h"
#endif
@@ -183,12 +184,7 @@ static void load_voicefile(void)
#ifdef ROCKBOX_LITTLE_ENDIAN
logf("Byte swapping voice file");
- p_voicefile = (struct voicefile*)audiobuf;
- p_voicefile->version = swap32(p_voicefile->version);
- p_voicefile->table = swap32(p_voicefile->table);
- p_voicefile->id1_max = swap32(p_voicefile->id1_max);
- p_voicefile->id2_max = swap32(p_voicefile->id2_max);
- p_voicefile = NULL;
+ structec_convert(audiobuf, "llll", 1, true);
#endif
if (((struct voicefile*)audiobuf)->table /* format check */
@@ -208,12 +204,7 @@ static void load_voicefile(void)
#ifdef ROCKBOX_LITTLE_ENDIAN
for (i = 0; i < p_voicefile->id1_max + p_voicefile->id2_max; i++)
- {
- struct clip_entry *ce;
- ce = &p_voicefile->index[i];
- ce->offset = swap32(ce->offset);
- ce->size = swap32(ce->size);
- }
+ structec_convert(&p_voicefile->index[i], "ll", 1, true);
#endif
/* Do a bitswap as necessary. */
diff --git a/firmware/common/structec.c b/firmware/common/structec.c
index 7c76874692..1f4205c67c 100644
--- a/firmware/common/structec.c
+++ b/firmware/common/structec.c
@@ -17,6 +17,7 @@
*
****************************************************************************/
+#include <ctype.h>
#include <string.h>
#include <inttypes.h>
#include "structec.h"
@@ -82,9 +83,14 @@ void structec_convert(void *structure, const char *ecinst,
break;
}
- /* This should be never reached. */
+ /* Skip N bytes, idea taken from metadata.c */
default:
+ {
+ if (isdigit(*ecinst_ring))
+ buf += (*ecinst_ring - '0');
+
break;
+ }
}
ecinst_ring++;
@@ -114,7 +120,9 @@ size_t structec_size(const char *ecinst)
case 'c': size += 1; break;
case 's': size += 2; break;
case 'l': size += 4; break;
- default: break;
+ default:
+ if (isdigit(*ecinst))
+ size += (*ecinst - '0');
}
} while (*(++ecinst) != '\0');