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.zip rockbox-97d2a6ec5ca8ace8daed29c8c69aab9595147b3a.tar.gz rockbox-97d2a6ec5ca8ace8daed29c8c69aab9595147b3a.tar.bz2 rockbox-97d2a6ec5ca8ace8daed29c8c69aab9595147b3a.tar.xz | |
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 b072c65..9e77dd9 100644 --- a/apps/codecs.c +++ b/apps/codecs.c @@ -28,7 +28,6 @@ #include <ctype.h> #include <stdarg.h> #include "string-extra.h" -#include "load_code.h" #include "debug.h" #include "button.h" #include "dir.h" @@ -75,13 +74,26 @@ size_t codec_size; extern void* plugin_get_audio_buffer(size_t *buffer_size); -#if (CONFIG_PLATFORM & PLATFORM_NATIVE) && defined(HAVE_RECORDING) #undef open static int open(const char* pathname, int flags, ...) { +#if (CONFIG_PLATFORM & PLATFORM_HOSTED) + int fd; + if (flags & O_CREAT) + { + va_list ap; + va_start(ap, flags); + fd = sim_open(pathname, flags, va_arg(ap, unsigned int)); + va_end(ap); + } + else + fd = sim_open(pathname, flags); + + return fd; +#else return file_open(pathname, flags); -} #endif +} struct codec_api ci = { 0, /* filesize */ @@ -185,46 +197,62 @@ void codec_get_full_path(char *path, const char *codec_root_fn) CODECS_DIR, codec_root_fn); } -static int codec_load_ram(void *handle, struct codec_api *api) +static int codec_load_ram(int size, struct codec_api *api) { - struct codec_header *hdr = lc_get_header(handle); + struct codec_header *hdr; int status; - - if (hdr == NULL +#if (CONFIG_PLATFORM & PLATFORM_NATIVE) + hdr = (struct codec_header *)codecbuf; + + if (size <= (signed)sizeof(struct codec_header) || (hdr->magic != CODEC_MAGIC #ifdef HAVE_RECORDING && hdr->magic != CODEC_ENC_MAGIC #endif ) || hdr->target_id != TARGET_ID -#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || hdr->load_addr != codecbuf - || hdr->end_addr > codecbuf + CODEC_SIZE -#endif - ) + || hdr->end_addr > codecbuf + CODEC_SIZE) { logf("codec header error"); - lc_close(handle); return CODEC_ERROR; } + codec_size = hdr->end_addr - codecbuf; + +#elif (CONFIG_PLATFORM & PLATFORM_HOSTED) + void *pd; + + hdr = sim_codec_load_ram(codecbuf, size, &pd); + + if (pd == NULL) + return CODEC_ERROR; + + if (hdr == NULL + || (hdr->magic != CODEC_MAGIC +#ifdef HAVE_RECORDING + && hdr->magic != CODEC_ENC_MAGIC +#endif + ) + || hdr->target_id != TARGET_ID) { + sim_codec_close(pd); + return CODEC_ERROR; + } + + codec_size = codecbuf - codecbuf; + +#endif /* CONFIG_PLATFORM */ if (hdr->api_version > CODEC_API_VERSION || hdr->api_version < CODEC_MIN_API_VERSION) { - logf("codec api version error"); - lc_close(handle); + sim_codec_close(pd); return CODEC_ERROR; } -#if (CONFIG_PLATFORM & PLATFORM_NATIVE) - codec_size = hdr->end_addr - codecbuf; -#else - codec_size = 0; -#endif - *(hdr->api) = api; + cpucache_invalidate(); status = hdr->entry_point(); - lc_close(handle); + sim_codec_close(pd); return status; } @@ -232,37 +260,36 @@ static int codec_load_ram(void *handle, struct codec_api *api) int codec_load_buf(unsigned int hid, struct codec_api *api) { int rc; - void *handle; rc = bufread(hid, CODEC_SIZE, codecbuf); if (rc < 0) { logf("error loading codec"); return CODEC_ERROR; } - handle = lc_open_from_mem(codecbuf, rc); - if (handle == NULL) - { - logf("error loading codec"); - return CODEC_ERROR; - } - api->discard_codec(); - return codec_load_ram(handle, api); + return codec_load_ram(rc, api); } int codec_load_file(const char *plugin, struct codec_api *api) { char path[MAX_PATH]; - void *handle; + int fd; + int rc; codec_get_full_path(path, plugin); - - handle = lc_open(path, codecbuf, CODEC_SIZE); - - if (handle == NULL) { - logf("Codec load error"); + + fd = open(path, O_RDONLY); + if (fd < 0) { + logf("Codec load error:%d", fd); splashf(HZ*2, "Couldn't load codec: %s", path); + return fd; + } + + rc = read(fd, &codecbuf[0], CODEC_SIZE); + close(fd); + if (rc <= 0) { + logf("Codec read error"); return CODEC_ERROR; } - return codec_load_ram(handle, api); + return codec_load_ram((size_t)rc, api); } |