forked from len0rd/rockbox
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
This commit is contained in:
parent
9d5f73cd85
commit
7a395a23bf
3 changed files with 27 additions and 90 deletions
|
|
@ -31,12 +31,19 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "cuesheet.h"
|
#include "cuesheet.h"
|
||||||
|
#include "structec.h"
|
||||||
|
|
||||||
enum tagtype { TAGTYPE_APE = 1, TAGTYPE_VORBIS };
|
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_LENGTH 32
|
||||||
#define APETAG_HEADER_FORMAT "8LLLL"
|
#define APETAG_HEADER_FORMAT "8llll"
|
||||||
#define APETAG_ITEM_HEADER_FORMAT "LL"
|
#define APETAG_ITEM_HEADER_FORMAT "ll"
|
||||||
#define APETAG_ITEM_TYPE_MASK 3
|
#define APETAG_ITEM_TYPE_MASK 3
|
||||||
|
|
||||||
#define TAG_NAME_LENGTH 32
|
#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;
|
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. */
|
/* Read an unsigned 32-bit integer from a big-endian file. */
|
||||||
#ifdef ROCKBOX_BIG_ENDIAN
|
#ifdef ROCKBOX_BIG_ENDIAN
|
||||||
#define read_uint32be(fd,buf) read((fd), (buf), 4)
|
#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;
|
struct apetag_header header;
|
||||||
|
|
||||||
if ((lseek(fd, -APETAG_HEADER_LENGTH, SEEK_END) < 0)
|
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))))
|
|| (memcmp(header.id, "APETAGEX", sizeof(header.id))))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert_endian(&header, APETAG_HEADER_FORMAT);
|
|
||||||
id3->genre = 0xff;
|
id3->genre = 0xff;
|
||||||
|
|
||||||
if ((header.version == 2000) && (header.item_count > 0)
|
if ((header.version == 2000) && (header.item_count > 0)
|
||||||
|
|
@ -389,12 +332,11 @@ static bool read_ape_tags(int fd, struct mp3entry* id3)
|
||||||
break;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert_endian(&item, APETAG_ITEM_HEADER_FORMAT);
|
|
||||||
tag_remaining -= sizeof(item);
|
tag_remaining -= sizeof(item);
|
||||||
r = read_string(fd, name, sizeof(name), 0, tag_remaining);
|
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;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert_endian(&len, "L");
|
|
||||||
|
|
||||||
if ((lseek(fd, len, SEEK_CUR) < 0)
|
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)))
|
< (long) sizeof(comment_count)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert_endian(&comment_count, "L");
|
|
||||||
tag_remaining -= len + sizeof(len) + sizeof(comment_count);
|
tag_remaining -= len + sizeof(len) + sizeof(comment_count);
|
||||||
|
|
||||||
if (tag_remaining <= 0)
|
if (tag_remaining <= 0)
|
||||||
|
|
@ -480,12 +419,11 @@ static bool read_vorbis_tags(int fd, struct mp3entry *id3,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read(fd, &len, sizeof(len)) < (long) sizeof(len))
|
if (ecread(fd, &len, 1, "l", IS_BIG_ENDIAN) < (long) sizeof(len))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
convert_endian(&len, "L");
|
|
||||||
tag_remaining -= 4;
|
tag_remaining -= 4;
|
||||||
|
|
||||||
/* Quit if we've passed the end of the page */
|
/* Quit if we've passed the end of the page */
|
||||||
|
|
|
||||||
15
apps/talk.c
15
apps/talk.c
|
|
@ -35,6 +35,7 @@
|
||||||
#include "id3.h"
|
#include "id3.h"
|
||||||
#include "logf.h"
|
#include "logf.h"
|
||||||
#include "bitswap.h"
|
#include "bitswap.h"
|
||||||
|
#include "structec.h"
|
||||||
#if CONFIG_CODEC == SWCODEC
|
#if CONFIG_CODEC == SWCODEC
|
||||||
#include "playback.h"
|
#include "playback.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -183,12 +184,7 @@ static void load_voicefile(void)
|
||||||
|
|
||||||
#ifdef ROCKBOX_LITTLE_ENDIAN
|
#ifdef ROCKBOX_LITTLE_ENDIAN
|
||||||
logf("Byte swapping voice file");
|
logf("Byte swapping voice file");
|
||||||
p_voicefile = (struct voicefile*)audiobuf;
|
structec_convert(audiobuf, "llll", 1, true);
|
||||||
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;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (((struct voicefile*)audiobuf)->table /* format check */
|
if (((struct voicefile*)audiobuf)->table /* format check */
|
||||||
|
|
@ -208,12 +204,7 @@ static void load_voicefile(void)
|
||||||
|
|
||||||
#ifdef ROCKBOX_LITTLE_ENDIAN
|
#ifdef ROCKBOX_LITTLE_ENDIAN
|
||||||
for (i = 0; i < p_voicefile->id1_max + p_voicefile->id2_max; i++)
|
for (i = 0; i < p_voicefile->id1_max + p_voicefile->id2_max; i++)
|
||||||
{
|
structec_convert(&p_voicefile->index[i], "ll", 1, true);
|
||||||
struct clip_entry *ce;
|
|
||||||
ce = &p_voicefile->index[i];
|
|
||||||
ce->offset = swap32(ce->offset);
|
|
||||||
ce->size = swap32(ce->size);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Do a bitswap as necessary. */
|
/* Do a bitswap as necessary. */
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "structec.h"
|
#include "structec.h"
|
||||||
|
|
@ -82,9 +83,14 @@ void structec_convert(void *structure, const char *ecinst,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This should be never reached. */
|
/* Skip N bytes, idea taken from metadata.c */
|
||||||
default:
|
default:
|
||||||
|
{
|
||||||
|
if (isdigit(*ecinst_ring))
|
||||||
|
buf += (*ecinst_ring - '0');
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ecinst_ring++;
|
ecinst_ring++;
|
||||||
|
|
@ -114,7 +120,9 @@ size_t structec_size(const char *ecinst)
|
||||||
case 'c': size += 1; break;
|
case 'c': size += 1; break;
|
||||||
case 's': size += 2; break;
|
case 's': size += 2; break;
|
||||||
case 'l': size += 4; break;
|
case 'l': size += 4; break;
|
||||||
default: break;
|
default:
|
||||||
|
if (isdigit(*ecinst))
|
||||||
|
size += (*ecinst - '0');
|
||||||
}
|
}
|
||||||
} while (*(++ecinst) != '\0');
|
} while (*(++ecinst) != '\0');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue