diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-24 01:25:21 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-03-18 12:00:39 +0100 |
commit | b5716df4cb2837bbbc42195cf1aefcf03e21d6a6 (patch) | |
tree | 130cd712e2e00893b6df9959a375a8d9523a1aca /apps/metadata/ape.c | |
parent | 24bd9d5393dbe39a5c6194877bc00ede669b1d5d (diff) | |
download | rockbox-b5716df4cb2837bbbc42195cf1aefcf03e21d6a6.tar.gz rockbox-b5716df4cb2837bbbc42195cf1aefcf03e21d6a6.zip |
Build librbcodec with DSP and metadata.
All associated files are moved to /lib/rbcodec.
Change-Id: I572ddd2b8a996aae1e98c081d06b1ed356dce222
Diffstat (limited to 'apps/metadata/ape.c')
-rw-r--r-- | apps/metadata/ape.c | 182 |
1 files changed, 0 insertions, 182 deletions
diff --git a/apps/metadata/ape.c b/apps/metadata/ape.c deleted file mode 100644 index 0bd2477431..0000000000 --- a/apps/metadata/ape.c +++ /dev/null | |||
@@ -1,182 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 Dave Chapman | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include <stdio.h> | ||
22 | #include <string.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <ctype.h> | ||
25 | #include <inttypes.h> | ||
26 | |||
27 | #include "system.h" | ||
28 | #include "metadata.h" | ||
29 | #include "metadata_common.h" | ||
30 | #include "metadata_parsers.h" | ||
31 | #include "structec.h" | ||
32 | |||
33 | #define APETAG_HEADER_LENGTH 32 | ||
34 | #define APETAG_HEADER_FORMAT "8llll8" | ||
35 | #define APETAG_ITEM_HEADER_FORMAT "ll" | ||
36 | #define APETAG_ITEM_TYPE_MASK 3 | ||
37 | |||
38 | #ifdef HAVE_ALBUMART | ||
39 | /* The AA header consists of the pseudo filename "Album Cover (Front).ext" | ||
40 | * whereas ".ext" is the file extension. For now ".jpg" and ".png" are | ||
41 | * supported by this APE metadata parser. Therefore the length is 22. */ | ||
42 | #define APETAG_AA_HEADER_LENGTH 22 | ||
43 | #endif | ||
44 | |||
45 | struct apetag_header | ||
46 | { | ||
47 | char id[8]; | ||
48 | long version; | ||
49 | long length; | ||
50 | long item_count; | ||
51 | long flags; | ||
52 | char reserved[8]; | ||
53 | }; | ||
54 | |||
55 | struct apetag_item_header | ||
56 | { | ||
57 | long length; | ||
58 | long flags; | ||
59 | }; | ||
60 | |||
61 | /* Read the items in an APEV2 tag. Only looks for a tag at the end of a | ||
62 | * file. Returns true if a tag was found and fully read, false otherwise. | ||
63 | */ | ||
64 | bool read_ape_tags(int fd, struct mp3entry* id3) | ||
65 | { | ||
66 | struct apetag_header header; | ||
67 | |||
68 | if ((lseek(fd, -APETAG_HEADER_LENGTH, SEEK_END) < 0) | ||
69 | || (ecread(fd, &header, 1, APETAG_HEADER_FORMAT, IS_BIG_ENDIAN) | ||
70 | != APETAG_HEADER_LENGTH) | ||
71 | || (memcmp(header.id, "APETAGEX", sizeof(header.id)))) | ||
72 | { | ||
73 | return false; | ||
74 | } | ||
75 | |||
76 | if ((header.version == 2000) && (header.item_count > 0) | ||
77 | && (header.length > APETAG_HEADER_LENGTH)) | ||
78 | { | ||
79 | char *buf = id3->id3v2buf; | ||
80 | unsigned int buf_remaining = sizeof(id3->id3v2buf) | ||
81 | + sizeof(id3->id3v1buf); | ||
82 | unsigned int tag_remaining = header.length - APETAG_HEADER_LENGTH; | ||
83 | int i; | ||
84 | |||
85 | if (lseek(fd, -header.length, SEEK_END) < 0) | ||
86 | { | ||
87 | return false; | ||
88 | } | ||
89 | |||
90 | for (i = 0; i < header.item_count; i++) | ||
91 | { | ||
92 | struct apetag_item_header item; | ||
93 | char name[TAG_NAME_LENGTH]; | ||
94 | char value[TAG_VALUE_LENGTH]; | ||
95 | long r; | ||
96 | |||
97 | if (tag_remaining < sizeof(item)) | ||
98 | { | ||
99 | break; | ||
100 | } | ||
101 | |||
102 | if (ecread(fd, &item, 1, APETAG_ITEM_HEADER_FORMAT, IS_BIG_ENDIAN) | ||
103 | < (long) sizeof(item)) | ||
104 | { | ||
105 | return false; | ||
106 | } | ||
107 | |||
108 | tag_remaining -= sizeof(item); | ||
109 | r = read_string(fd, name, sizeof(name), 0, tag_remaining); | ||
110 | |||
111 | if (r == -1) | ||
112 | { | ||
113 | return false; | ||
114 | } | ||
115 | |||
116 | tag_remaining -= r + item.length; | ||
117 | |||
118 | if ((item.flags & APETAG_ITEM_TYPE_MASK) == 0) | ||
119 | { | ||
120 | long len; | ||
121 | |||
122 | if (read_string(fd, value, sizeof(value), -1, item.length) | ||
123 | != item.length) | ||
124 | { | ||
125 | return false; | ||
126 | } | ||
127 | |||
128 | len = parse_tag(name, value, id3, buf, buf_remaining, | ||
129 | TAGTYPE_APE); | ||
130 | buf += len; | ||
131 | buf_remaining -= len; | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | #ifdef HAVE_ALBUMART | ||
136 | if (strcasecmp(name, "cover art (front)") == 0) | ||
137 | { | ||
138 | /* Allow to read at least APETAG_AA_HEADER_LENGTH bytes. */ | ||
139 | r = read_string(fd, name, sizeof(name), 0, APETAG_AA_HEADER_LENGTH); | ||
140 | if (r == -1) | ||
141 | { | ||
142 | return false; | ||
143 | } | ||
144 | |||
145 | /* Gather the album art format from the pseudo file name's ending. */ | ||
146 | strcpy(name, name + strlen(name) - 4); | ||
147 | id3->albumart.type = AA_TYPE_UNKNOWN; | ||
148 | if (strcasecmp(name, ".jpg") == 0) | ||
149 | { | ||
150 | id3->albumart.type = AA_TYPE_JPG; | ||
151 | } | ||
152 | else if (strcasecmp(name, ".png") == 0) | ||
153 | { | ||
154 | id3->albumart.type = AA_TYPE_PNG; | ||
155 | } | ||
156 | |||
157 | /* Set the album art size and position. */ | ||
158 | if (id3->albumart.type != AA_TYPE_UNKNOWN) | ||
159 | { | ||
160 | id3->albumart.pos = lseek(fd, 0, SEEK_CUR); | ||
161 | id3->albumart.size = item.length - r; | ||
162 | id3->has_embedded_albumart = true; | ||
163 | } | ||
164 | |||
165 | /* Seek back to this APE items begin. */ | ||
166 | if (lseek(fd, -r, SEEK_CUR) < 0) | ||
167 | { | ||
168 | return false; | ||
169 | } | ||
170 | } | ||
171 | #endif | ||
172 | /* Seek to the next APE item. */ | ||
173 | if (lseek(fd, item.length, SEEK_CUR) < 0) | ||
174 | { | ||
175 | return false; | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | |||
181 | return true; | ||
182 | } | ||