Mercurial > audlegacy-plugins
changeset 2193:80d7ab8f2ec5
removed some duplicated code
author | Eugene Zagidullin <e.asphyx@gmail.com> |
---|---|
date | Wed, 28 Nov 2007 16:19:57 +0300 |
parents | e5401b6c4665 |
children | 9773d2c69857 |
files | src/demac/ape.c src/demac/ape.h src/demac/apev2.c |
diffstat | 3 files changed, 29 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/src/demac/ape.c Wed Nov 28 03:51:34 2007 +0300 +++ b/src/demac/ape.c Wed Nov 28 16:19:57 2007 +0300 @@ -58,7 +58,7 @@ #define TAG(name, field) {name, offsetof(AVFormatContext, field), sizeof(((AVFormatContext *)0)->field)} -static uint16_t get_le16(VFSFile *vfd) +uint16_t get_le16(VFSFile *vfd) { unsigned char tmp[2]; @@ -66,7 +66,7 @@ return tmp[0] | (tmp[1] << 8); } -static uint32_t get_le32(VFSFile *vfd) +uint32_t get_le32(VFSFile *vfd) { unsigned char tmp[4]; @@ -74,6 +74,15 @@ return tmp[0] | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24); } +uint64_t get_le64(VFSFile *vfd) +{ + unsigned char tmp[8]; + + if(aud_vfs_fread(tmp, 1, 8, vfd) != 8) return -1; + return (uint64_t)tmp[0] | ((uint64_t)tmp[1] << 8) | ((uint64_t)tmp[2] << 16) | ((uint64_t)tmp[3] << 24) | + ((uint64_t)tmp[4] << 32) | ((uint64_t)tmp[5] << 40) | ((uint64_t)tmp[6] << 48) | ((uint64_t)tmp[7] << 56); +} + #ifdef DEBUG static void ape_dumpinfo(APEContext * ape_ctx) {
--- a/src/demac/ape.h Wed Nov 28 03:51:34 2007 +0300 +++ b/src/demac/ape.h Wed Nov 28 16:19:57 2007 +0300 @@ -32,7 +32,10 @@ #define av_log(a, b, ...) ; #endif -#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) +#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) +#define MKTAG64(a,b,c,d,e,f,g,h) ((uint64_t)a | ((uint64_t)b << 8) | ((uint64_t)c << 16) | ((uint64_t)d << 24) | \ + ((uint64_t)e << 32) | ((uint64_t)f << 40) | ((uint64_t)g << 48) | ((uint64_t)h << 56)) + #define AV_TIME_BASE 1000 #define AV_WL16(a,b) { \ ((uint8_t*)(a))[0] = (uint16_t)(b) & 0x00ff; \ @@ -285,6 +288,10 @@ else return a; } +uint16_t get_le16(VFSFile *vfd); +uint32_t get_le32(VFSFile *vfd); +uint64_t get_le64(VFSFile *vfd); + int ape_read_header(APEContext *ape, VFSFile *pb, int probe_only); int ape_read_packet(APEContext *ape, VFSFile *pb, uint8_t *pkt, int *pkt_size); int ape_read_close(APEContext *ape);
--- a/src/demac/apev2.c Wed Nov 28 03:51:34 2007 +0300 +++ b/src/demac/apev2.c Wed Nov 28 16:19:57 2007 +0300 @@ -28,24 +28,9 @@ #include <audacious/vfs.h> #include <audacious/plugin.h> +#include "ape.h" #include "apev2.h" - -static int read_uint32(VFSFile *vfd, guint32* x) { - unsigned char tmp[4]; - int n; - - n = aud_vfs_fread(tmp, 1, 4, vfd); - - if (n != 4) - return -1; - - /* convert to native endianness */ - *x = tmp[0] | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24); - - return 0; -} - #define TMP_BUFSIZE 256 #ifndef MIN #define MIN(a,b) ((a) < (b) ? (a) : (b)) @@ -69,6 +54,7 @@ GHashTable* parse_apev2_tag(VFSFile *vfd) { unsigned char tmp[TMP_BUFSIZE+1]; unsigned char tmp2[TMP_BUFSIZE+1]; + guint64 signature; guint32 tag_version; guint32 tag_size, item_size, item_flags; guint32 tag_items; @@ -76,19 +62,18 @@ GHashTable *hash; aud_vfs_fseek(vfd, -32, SEEK_END); - aud_vfs_fread(tmp, 1, 8, vfd); - if ((tmp[0]!='A')||(tmp[1]!='P')||(tmp[2]!='E')||(tmp[3]!='T')|| - (tmp[4]!='A')||(tmp[5]!='G')||(tmp[6]!='E')||(tmp[7]!='X')) { + signature = get_le64(vfd); + if (signature != MKTAG64('A', 'P', 'E', 'T', 'A', 'G', 'E', 'X')) { #ifdef DEBUG fprintf(stderr, "** demac: apev2.c: APE tag not found\n"); #endif return NULL; } - read_uint32(vfd, &tag_version); - read_uint32(vfd, &tag_size); - read_uint32(vfd, &tag_items); - read_uint32(vfd, &tag_flags); + tag_version = get_le32(vfd); + tag_size = get_le32(vfd); + tag_items = get_le32(vfd); + tag_flags = get_le32(vfd); #ifdef DEBUG fprintf(stderr, "** demac: apev2.c: found APE tag version %d contains %d items, flags %08x\n", tag_version, tag_items, tag_flags); #endif @@ -105,8 +90,8 @@ int i; unsigned char *p; for(i=0; i<tag_items; i++) { - read_uint32(vfd, &item_size); - read_uint32(vfd, &item_flags); + item_size = get_le32(vfd); + item_flags = get_le32(vfd); /* read key */ for(p = tmp; p <= tmp+TMP_BUFSIZE; p++) {