diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-08-27 00:16:26 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-08-27 00:16:26 +0000 |
commit | 97d2a6ec5ca8ace8daed29c8c69aab9595147b3a (patch) | |
tree | 8f67645f080416576b9356dfc4385b8181eeb152 /apps/codecs.c | |
parent | 73f057be6fcb849d5379073267e21e9526576ccd (diff) | |
download | rockbox-97d2a6ec5ca8ace8daed29c8c69aab9595147b3a.tar.gz rockbox-97d2a6ec5ca8ace8daed29c8c69aab9595147b3a.zip |
Revert "Introduce a small api for loading code (codecs,plugins) from disk/memory."
I don't understand the build error at all, plugin_bss_start is clearly defined in plugin.lds
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27901 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs.c')
-rw-r--r-- | apps/codecs.c | 101 |
1 files changed, 64 insertions, 37 deletions
diff --git a/apps/codecs.c b/apps/codecs.c index b072c65f40..9e77dd9099 100644 --- a/apps/codecs.c +++ b/apps/codecs.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include <ctype.h> | 28 | #include <ctype.h> |
29 | #include <stdarg.h> | 29 | #include <stdarg.h> |
30 | #include "string-extra.h" | 30 | #include "string-extra.h" |
31 | #include "load_code.h" | ||
32 | #include "debug.h" | 31 | #include "debug.h" |
33 | #include "button.h" | 32 | #include "button.h" |
34 | #include "dir.h" | 33 | #include "dir.h" |
@@ -75,13 +74,26 @@ size_t codec_size; | |||
75 | 74 | ||
76 | extern void* plugin_get_audio_buffer(size_t *buffer_size); | 75 | extern void* plugin_get_audio_buffer(size_t *buffer_size); |
77 | 76 | ||
78 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) && defined(HAVE_RECORDING) | ||
79 | #undef open | 77 | #undef open |
80 | static int open(const char* pathname, int flags, ...) | 78 | static int open(const char* pathname, int flags, ...) |
81 | { | 79 | { |
80 | #if (CONFIG_PLATFORM & PLATFORM_HOSTED) | ||
81 | int fd; | ||
82 | if (flags & O_CREAT) | ||
83 | { | ||
84 | va_list ap; | ||
85 | va_start(ap, flags); | ||
86 | fd = sim_open(pathname, flags, va_arg(ap, unsigned int)); | ||
87 | va_end(ap); | ||
88 | } | ||
89 | else | ||
90 | fd = sim_open(pathname, flags); | ||
91 | |||
92 | return fd; | ||
93 | #else | ||
82 | return file_open(pathname, flags); | 94 | return file_open(pathname, flags); |
83 | } | ||
84 | #endif | 95 | #endif |
96 | } | ||
85 | struct codec_api ci = { | 97 | struct codec_api ci = { |
86 | 98 | ||
87 | 0, /* filesize */ | 99 | 0, /* filesize */ |
@@ -185,46 +197,62 @@ void codec_get_full_path(char *path, const char *codec_root_fn) | |||
185 | CODECS_DIR, codec_root_fn); | 197 | CODECS_DIR, codec_root_fn); |
186 | } | 198 | } |
187 | 199 | ||
188 | static int codec_load_ram(void *handle, struct codec_api *api) | 200 | static int codec_load_ram(int size, struct codec_api *api) |
189 | { | 201 | { |
190 | struct codec_header *hdr = lc_get_header(handle); | 202 | struct codec_header *hdr; |
191 | int status; | 203 | int status; |
192 | 204 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | |
193 | if (hdr == NULL | 205 | hdr = (struct codec_header *)codecbuf; |
206 | |||
207 | if (size <= (signed)sizeof(struct codec_header) | ||
194 | || (hdr->magic != CODEC_MAGIC | 208 | || (hdr->magic != CODEC_MAGIC |
195 | #ifdef HAVE_RECORDING | 209 | #ifdef HAVE_RECORDING |
196 | && hdr->magic != CODEC_ENC_MAGIC | 210 | && hdr->magic != CODEC_ENC_MAGIC |
197 | #endif | 211 | #endif |
198 | ) | 212 | ) |
199 | || hdr->target_id != TARGET_ID | 213 | || hdr->target_id != TARGET_ID |
200 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | ||
201 | || hdr->load_addr != codecbuf | 214 | || hdr->load_addr != codecbuf |
202 | || hdr->end_addr > codecbuf + CODEC_SIZE | 215 | || hdr->end_addr > codecbuf + CODEC_SIZE) |
203 | #endif | ||
204 | ) | ||
205 | { | 216 | { |
206 | logf("codec header error"); | 217 | logf("codec header error"); |
207 | lc_close(handle); | ||
208 | return CODEC_ERROR; | 218 | return CODEC_ERROR; |
209 | } | 219 | } |
210 | 220 | ||
221 | codec_size = hdr->end_addr - codecbuf; | ||
222 | |||
223 | #elif (CONFIG_PLATFORM & PLATFORM_HOSTED) | ||
224 | void *pd; | ||
225 | |||
226 | hdr = sim_codec_load_ram(codecbuf, size, &pd); | ||
227 | |||
228 | if (pd == NULL) | ||
229 | return CODEC_ERROR; | ||
230 | |||
231 | if (hdr == NULL | ||
232 | || (hdr->magic != CODEC_MAGIC | ||
233 | #ifdef HAVE_RECORDING | ||
234 | && hdr->magic != CODEC_ENC_MAGIC | ||
235 | #endif | ||
236 | ) | ||
237 | || hdr->target_id != TARGET_ID) { | ||
238 | sim_codec_close(pd); | ||
239 | return CODEC_ERROR; | ||
240 | } | ||
241 | |||
242 | codec_size = codecbuf - codecbuf; | ||
243 | |||
244 | #endif /* CONFIG_PLATFORM */ | ||
211 | if (hdr->api_version > CODEC_API_VERSION | 245 | if (hdr->api_version > CODEC_API_VERSION |
212 | || hdr->api_version < CODEC_MIN_API_VERSION) { | 246 | || hdr->api_version < CODEC_MIN_API_VERSION) { |
213 | logf("codec api version error"); | 247 | sim_codec_close(pd); |
214 | lc_close(handle); | ||
215 | return CODEC_ERROR; | 248 | return CODEC_ERROR; |
216 | } | 249 | } |
217 | 250 | ||
218 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | ||
219 | codec_size = hdr->end_addr - codecbuf; | ||
220 | #else | ||
221 | codec_size = 0; | ||
222 | #endif | ||
223 | |||
224 | *(hdr->api) = api; | 251 | *(hdr->api) = api; |
252 | cpucache_invalidate(); | ||
225 | status = hdr->entry_point(); | 253 | status = hdr->entry_point(); |
226 | 254 | ||
227 | lc_close(handle); | 255 | sim_codec_close(pd); |
228 | 256 | ||
229 | return status; | 257 | return status; |
230 | } | 258 | } |
@@ -232,37 +260,36 @@ static int codec_load_ram(void *handle, struct codec_api *api) | |||
232 | int codec_load_buf(unsigned int hid, struct codec_api *api) | 260 | int codec_load_buf(unsigned int hid, struct codec_api *api) |
233 | { | 261 | { |
234 | int rc; | 262 | int rc; |
235 | void *handle; | ||
236 | rc = bufread(hid, CODEC_SIZE, codecbuf); | 263 | rc = bufread(hid, CODEC_SIZE, codecbuf); |
237 | if (rc < 0) { | 264 | if (rc < 0) { |
238 | logf("error loading codec"); | 265 | logf("error loading codec"); |
239 | return CODEC_ERROR; | 266 | return CODEC_ERROR; |
240 | } | 267 | } |
241 | handle = lc_open_from_mem(codecbuf, rc); | ||
242 | if (handle == NULL) | ||
243 | { | ||
244 | logf("error loading codec"); | ||
245 | return CODEC_ERROR; | ||
246 | } | ||
247 | |||
248 | api->discard_codec(); | 268 | api->discard_codec(); |
249 | return codec_load_ram(handle, api); | 269 | return codec_load_ram(rc, api); |
250 | } | 270 | } |
251 | 271 | ||
252 | int codec_load_file(const char *plugin, struct codec_api *api) | 272 | int codec_load_file(const char *plugin, struct codec_api *api) |
253 | { | 273 | { |
254 | char path[MAX_PATH]; | 274 | char path[MAX_PATH]; |
255 | void *handle; | 275 | int fd; |
276 | int rc; | ||
256 | 277 | ||
257 | codec_get_full_path(path, plugin); | 278 | codec_get_full_path(path, plugin); |
258 | 279 | ||
259 | handle = lc_open(path, codecbuf, CODEC_SIZE); | 280 | fd = open(path, O_RDONLY); |
260 | 281 | if (fd < 0) { | |
261 | if (handle == NULL) { | 282 | logf("Codec load error:%d", fd); |
262 | logf("Codec load error"); | ||
263 | splashf(HZ*2, "Couldn't load codec: %s", path); | 283 | splashf(HZ*2, "Couldn't load codec: %s", path); |
284 | return fd; | ||
285 | } | ||
286 | |||
287 | rc = read(fd, &codecbuf[0], CODEC_SIZE); | ||
288 | close(fd); | ||
289 | if (rc <= 0) { | ||
290 | logf("Codec read error"); | ||
264 | return CODEC_ERROR; | 291 | return CODEC_ERROR; |
265 | } | 292 | } |
266 | 293 | ||
267 | return codec_load_ram(handle, api); | 294 | return codec_load_ram((size_t)rc, api); |
268 | } | 295 | } |