summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs.c93
-rw-r--r--apps/codecs.h97
-rw-r--r--apps/codecs/Makefile2
-rw-r--r--apps/codecs/a52.c3
-rw-r--r--apps/codecs/aac.c6
-rw-r--r--apps/codecs/alac.c6
-rw-r--r--apps/codecs/flac.c6
-rw-r--r--apps/codecs/mpa.c3
-rw-r--r--apps/codecs/mpc.c3
-rw-r--r--apps/codecs/shorten.c5
-rw-r--r--apps/codecs/vorbis.c3
-rw-r--r--apps/codecs/wav.c4
-rw-r--r--apps/codecs/wavpack.c4
-rw-r--r--firmware/export/config-gmini120.h2
-rw-r--r--firmware/export/config-gminisp.h2
-rw-r--r--firmware/export/config-h100.h2
-rw-r--r--firmware/export/config-h120.h2
-rw-r--r--firmware/export/config-h300.h2
-rw-r--r--firmware/export/config-iaudiox5.h2
-rw-r--r--firmware/export/config-ipodcolor.h2
-rw-r--r--firmware/export/config-ipodnano.h2
-rw-r--r--firmware/export/config-ipodvideo.h2
-rw-r--r--uisimulator/common/io.c29
23 files changed, 117 insertions, 165 deletions
diff --git a/apps/codecs.c b/apps/codecs.c
index 831b9b4f0c..d12b43642f 100644
--- a/apps/codecs.c
+++ b/apps/codecs.c
@@ -68,13 +68,9 @@ extern unsigned char codecbuf[];
68 68
69extern void* plugin_get_audio_buffer(int *buffer_size); 69extern void* plugin_get_audio_buffer(int *buffer_size);
70 70
71static int codec_test(int api_version, int model, int memsize);
72
73struct codec_api ci_voice; 71struct codec_api ci_voice;
74 72
75struct codec_api ci = { 73struct codec_api ci = {
76 CODEC_API_VERSION,
77 codec_test,
78 74
79 0, /* filesize */ 75 0, /* filesize */
80 0, /* curpos */ 76 0, /* curpos */
@@ -95,6 +91,8 @@ struct codec_api ci = {
95 NULL, 91 NULL,
96 NULL, 92 NULL,
97 NULL, 93 NULL,
94 NULL,
95 NULL,
98 96
99 gui_syncsplash, 97 gui_syncsplash,
100 98
@@ -155,6 +153,7 @@ struct codec_api ci = {
155 strcat, 153 strcat,
156 memcmp, 154 memcmp,
157 strcasestr, 155 strcasestr,
156 memchr,
158 157
159 /* sound */ 158 /* sound */
160 sound_set, 159 sound_set,
@@ -163,9 +162,6 @@ struct codec_api ci = {
163 mp3_play_pause, 162 mp3_play_pause,
164 mp3_play_stop, 163 mp3_play_stop,
165 mp3_is_playing, 164 mp3_is_playing,
166#if CONFIG_CODEC != SWCODEC
167 bitswap,
168#endif
169#if CONFIG_CODEC == SWCODEC 165#if CONFIG_CODEC == SWCODEC
170 pcm_play_data, 166 pcm_play_data,
171 pcm_play_stop, 167 pcm_play_stop,
@@ -190,24 +186,6 @@ struct codec_api ci = {
190 audio_current_track, 186 audio_current_track,
191 audio_flush_and_reload_tracks, 187 audio_flush_and_reload_tracks,
192 audio_get_file_pos, 188 audio_get_file_pos,
193#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
194 mpeg_get_last_header,
195#endif
196#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
197 sound_set_pitch,
198#endif
199
200#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
201 /* MAS communication */
202 mas_readmem,
203 mas_writemem,
204 mas_readreg,
205 mas_writereg,
206#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
207 mas_codec_writereg,
208 mas_codec_readreg,
209#endif
210#endif /* !simulator and HWCODEC != SWCODEC */
211 189
212 /* tag database */ 190 /* tag database */
213 &tagdbheader, 191 &tagdbheader,
@@ -227,6 +205,9 @@ struct codec_api ci = {
227#if defined(DEBUG) || defined(SIMULATOR) 205#if defined(DEBUG) || defined(SIMULATOR)
228 debugf, 206 debugf,
229#endif 207#endif
208#ifdef ROCKBOX_HAS_LOGF
209 logf,
210#endif
230 &global_settings, 211 &global_settings,
231 mp3info, 212 mp3info,
232 count_mp3_frames, 213 count_mp3_frames,
@@ -234,28 +215,16 @@ struct codec_api ci = {
234 find_next_frame, 215 find_next_frame,
235 battery_level, 216 battery_level,
236 battery_level_safe, 217 battery_level_safe,
237#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
238 peak_meter_scale_value,
239 peak_meter_set_use_dbfs,
240 peak_meter_get_use_dbfs,
241#endif
242 218
243 /* new stuff at the end, sort into place next time 219 /* new stuff at the end, sort into place next time
244 the API gets incompatible */ 220 the API gets incompatible */
245 221
246#ifdef ROCKBOX_HAS_LOGF
247 logf,
248#endif
249
250 memchr,
251 NULL,
252 NULL,
253}; 222};
254 223
255int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap, 224int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
256 struct codec_api *api) 225 struct codec_api *api)
257{ 226{
258 enum codec_status (*codec_start)(const struct codec_api* api); 227 struct codec_header *hdr;
259 int status; 228 int status;
260#ifndef SIMULATOR 229#ifndef SIMULATOR
261 int copy_n; 230 int copy_n;
@@ -272,22 +241,40 @@ int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
272 memcpy(&codecbuf[copy_n], ptr2, size); 241 memcpy(&codecbuf[copy_n], ptr2, size);
273 } 242 }
274 } 243 }
275 codec_start = (void*)&codecbuf; 244 hdr = (struct codec_header *)codecbuf;
276 245
246 if (hdr->magic != CODEC_MAGIC
247 || hdr->target_id != TARGET_ID
248 || hdr->load_addr != codecbuf
249 || hdr->end_addr > codecbuf + CODEC_SIZE) {
250 return CODEC_ERROR;
251 }
277#else /* SIMULATOR */ 252#else /* SIMULATOR */
278 int pd; 253 int pd;
279 254
280 codec_start = sim_codec_load_ram(codecptr, size, ptr2, bufwrap, &pd); 255 hdr = sim_codec_load_ram(codecptr, size, ptr2, bufwrap, &pd);
281 if (pd < 0) 256 if (pd < 0)
282 return CODEC_ERROR; 257 return CODEC_ERROR;
258
259 if (hdr == NULL
260 || hdr->magic != CODEC_MAGIC
261 || hdr->target_id != TARGET_ID
262 || hdr->entry_point == NULL) {
263 sim_codec_close(pd);
264 return CODEC_ERROR;
265 }
283#endif /* SIMULATOR */ 266#endif /* SIMULATOR */
267 if (hdr->api_version > CODEC_API_VERSION
268 || hdr->api_version < CODEC_MIN_API_VERSION) {
269 sim_codec_close(pd);
270 return CODEC_ERROR;
271 }
284 272
285 invalidate_icache(); 273 invalidate_icache();
286 status = codec_start(api); 274 status = hdr->entry_point(api);
287#ifdef SIMULATOR 275
288 sim_codec_close(pd); 276 sim_codec_close(pd);
289#endif 277
290
291 return status; 278 return status;
292} 279}
293 280
@@ -317,21 +304,3 @@ int codec_load_file(const char *plugin, struct codec_api *api)
317 304
318 return codec_load_ram(codecbuf, (size_t)rc, NULL, 0, api); 305 return codec_load_ram(codecbuf, (size_t)rc, NULL, 0, api);
319} 306}
320
321static int codec_test(int api_version, int model, int memsize)
322{
323 if (api_version < CODEC_MIN_API_VERSION ||
324 api_version > CODEC_API_VERSION)
325 return CODEC_WRONG_API_VERSION;
326
327 (void)model;
328#if 0
329 if (model != MODEL)
330 return CODEC_WRONG_MODEL;
331#endif
332
333 if (memsize != MEM)
334 return CODEC_WRONG_MODEL;
335
336 return CODEC_OK;
337}
diff --git a/apps/codecs.h b/apps/codecs.h
index 5d5fbfe75d..320431f3bf 100644
--- a/apps/codecs.h
+++ b/apps/codecs.h
@@ -80,32 +80,23 @@
80#define PREFIX(_x_) _x_ 80#define PREFIX(_x_) _x_
81#endif 81#endif
82 82
83#define CODEC_MAGIC 0x52434F44 /* RCOD */
84
83/* increase this every time the api struct changes */ 85/* increase this every time the api struct changes */
84#define CODEC_API_VERSION 44 86#define CODEC_API_VERSION 1
85 87
86/* update this to latest version if a change to the api struct breaks 88/* update this to latest version if a change to the api struct breaks
87 backwards compatibility (and please take the opportunity to sort in any 89 backwards compatibility (and please take the opportunity to sort in any
88 new function which are "waiting" at the end of the function table) */ 90 new function which are "waiting" at the end of the function table) */
89#define CODEC_MIN_API_VERSION 44 91#define CODEC_MIN_API_VERSION 1
90 92
91/* codec return codes */ 93/* codec return codes */
92enum codec_status { 94enum codec_status {
93 CODEC_OK = 0, 95 CODEC_OK = 0,
94 CODEC_USB_CONNECTED, 96 CODEC_USB_CONNECTED,
95 97 CODEC_ERROR = -1,
96 CODEC_WRONG_API_VERSION = -1,
97 CODEC_WRONG_MODEL = -2,
98 CODEC_ERROR = -3,
99}; 98};
100 99
101/* compatibility test macro */
102#define TEST_CODEC_API(_api_) \
103do { \
104 int _rc_ = _api_->codec_test(CODEC_API_VERSION, 1, MEM); \
105 if (_rc_<0) \
106 return _rc_; \
107} while(0)
108
109/* NOTE: To support backwards compatibility, only add new functions at 100/* NOTE: To support backwards compatibility, only add new functions at
110 the end of the structure. Every time you add a new function, 101 the end of the structure. Every time you add a new function,
111 remember to increase CODEC_API_VERSION. If you make changes to the 102 remember to increase CODEC_API_VERSION. If you make changes to the
@@ -113,10 +104,6 @@ do { \
113 version 104 version
114 */ 105 */
115struct codec_api { 106struct codec_api {
116 /* these two fields must always be first, to ensure
117 TEST_CODEC_API will always work */
118 int version;
119 int (*codec_test)(int api_version, int model, int memsize);
120 107
121 off_t filesize; /* Total file length */ 108 off_t filesize; /* Total file length */
122 off_t curpos; /* Current buffer position */ 109 off_t curpos; /* Current buffer position */
@@ -158,6 +145,8 @@ struct codec_api {
158 void (*advance_buffer_loc)(void *ptr); 145 void (*advance_buffer_loc)(void *ptr);
159 /* Seek file buffer to position <newpos> beginning of file. */ 146 /* Seek file buffer to position <newpos> beginning of file. */
160 bool (*seek_buffer)(off_t newpos); 147 bool (*seek_buffer)(off_t newpos);
148 /* Codec should call this function when it has done the seeking. */
149 void (*seek_complete)(void);
161 /* Calculate mp3 seek position from given time data in ms. */ 150 /* Calculate mp3 seek position from given time data in ms. */
162 off_t (*mp3_get_filepos)(int newtime); 151 off_t (*mp3_get_filepos)(int newtime);
163 /* Request file change from file buffer. Returns true is next 152 /* Request file change from file buffer. Returns true is next
@@ -165,6 +154,7 @@ struct codec_api {
165 codec should exit immediately with PLUGIN_OK status. */ 154 codec should exit immediately with PLUGIN_OK status. */
166 bool (*request_next_track)(void); 155 bool (*request_next_track)(void);
167 156
157 void (*set_offset)(unsigned int value);
168 /* Configure different codec buffer parameters. */ 158 /* Configure different codec buffer parameters. */
169 void (*configure)(int setting, void *value); 159 void (*configure)(int setting, void *value);
170 160
@@ -228,6 +218,7 @@ struct codec_api {
228 char *(*strcat)(char *s1, const char *s2); 218 char *(*strcat)(char *s1, const char *s2);
229 int (*memcmp)(const void *s1, const void *s2, size_t n); 219 int (*memcmp)(const void *s1, const void *s2, size_t n);
230 char *(*strcasestr) (const char* phaystack, const char* pneedle); 220 char *(*strcasestr) (const char* phaystack, const char* pneedle);
221 void *(*memchr)(const void *s1, int c, size_t n);
231 222
232 /* sound */ 223 /* sound */
233 void (*sound_set)(int setting, int value); 224 void (*sound_set)(int setting, int value);
@@ -236,9 +227,6 @@ struct codec_api {
236 void (*mp3_play_pause)(bool play); 227 void (*mp3_play_pause)(bool play);
237 void (*mp3_play_stop)(void); 228 void (*mp3_play_stop)(void);
238 bool (*mp3_is_playing)(void); 229 bool (*mp3_is_playing)(void);
239#if CONFIG_CODEC != SWCODEC
240 void (*bitswap)(unsigned char *data, int length);
241#endif
242#if CONFIG_CODEC == SWCODEC 230#if CONFIG_CODEC == SWCODEC
243 void (*pcm_play_data)(void (*get_more)(unsigned char** start, long*size)); 231 void (*pcm_play_data)(void (*get_more)(unsigned char** start, long*size));
244 void (*pcm_play_stop)(void); 232 void (*pcm_play_stop)(void);
@@ -263,24 +251,6 @@ struct codec_api {
263 struct mp3entry* (*audio_current_track)(void); 251 struct mp3entry* (*audio_current_track)(void);
264 void (*audio_flush_and_reload_tracks)(void); 252 void (*audio_flush_and_reload_tracks)(void);
265 int (*audio_get_file_pos)(void); 253 int (*audio_get_file_pos)(void);
266#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
267 unsigned long (*mpeg_get_last_header)(void);
268#endif
269#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
270 void (*sound_set_pitch)(int pitch);
271#endif
272
273 /* MAS communication */
274#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
275 int (*mas_readmem)(int bank, int addr, unsigned long* dest, int len);
276 int (*mas_writemem)(int bank, int addr, const unsigned long* src, int len);
277 int (*mas_readreg)(int reg);
278 int (*mas_writereg)(int reg, unsigned int val);
279#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
280 int (*mas_codec_writereg)(int reg, unsigned int val);
281 int (*mas_codec_readreg)(int reg);
282#endif
283#endif
284 254
285 /* tag database */ 255 /* tag database */
286 struct tagdb_header *tagdbheader; 256 struct tagdb_header *tagdbheader;
@@ -301,6 +271,9 @@ struct codec_api {
301#if defined(DEBUG) || defined(SIMULATOR) 271#if defined(DEBUG) || defined(SIMULATOR)
302 void (*debugf)(const char *fmt, ...); 272 void (*debugf)(const char *fmt, ...);
303#endif 273#endif
274#ifdef ROCKBOX_HAS_LOGF
275 void (*logf)(const char *fmt, ...);
276#endif
304 struct user_settings* global_settings; 277 struct user_settings* global_settings;
305 bool (*mp3info)(struct mp3entry *entry, const char *filename, bool v1first); 278 bool (*mp3info)(struct mp3entry *entry, const char *filename, bool v1first);
306 int (*count_mp3_frames)(int fd, int startpos, int filesize, 279 int (*count_mp3_frames)(int fd, int startpos, int filesize,
@@ -313,35 +286,45 @@ struct codec_api {
313 long max_offset, unsigned long last_header); 286 long max_offset, unsigned long last_header);
314 int (*battery_level)(void); 287 int (*battery_level)(void);
315 bool (*battery_level_safe)(void); 288 bool (*battery_level_safe)(void);
316#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
317 unsigned short (*peak_meter_scale_value)(unsigned short val,
318 int meterwidth);
319 void (*peak_meter_set_use_dbfs)(bool use);
320 bool (*peak_meter_get_use_dbfs)(void);
321#endif
322 289
323 /* new stuff at the end, sort into place next time 290 /* new stuff at the end, sort into place next time
324 the API gets incompatible */ 291 the API gets incompatible */
325
326#ifdef ROCKBOX_HAS_LOGF
327 void (*logf)(const char *fmt, ...);
328#endif
329 292
330 void *(*memchr)(const void *s1, int c, size_t n);
331 void (*set_offset)(unsigned int value);
332 /* Codec should call this function when it has done the seeking. */
333 void (*seek_complete)(void);
334}; 293};
335 294
295/* codec header */
296struct codec_header {
297 unsigned long magic;
298 unsigned short target_id;
299 unsigned short api_version;
300 unsigned char *load_addr;
301 unsigned char *end_addr;
302 enum codec_status(*entry_point)(struct codec_api*);
303};
304#ifdef CODEC
305#ifndef SIMULATOR
306/* plugin_* is correct, codecs use the plugin linker script */
307extern unsigned char plugin_start_addr[];
308extern unsigned char plugin_end_addr[];
309#define CODEC_HEADER \
310 const struct codec_header __header \
311 __attribute__ ((section (".header")))= { \
312 CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
313 plugin_start_addr, plugin_end_addr, codec_start };
314#else /* SIMULATOR */
315#define CODEC_HEADER \
316 const struct codec_header __header = { \
317 CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
318 NULL, NULL, codec_start };
319#endif
320#endif
321
336/* defined by the codec loader (codec.c) */ 322/* defined by the codec loader (codec.c) */
337#if CONFIG_CODEC == SWCODEC
338int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap, 323int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
339 struct codec_api *api); 324 struct codec_api *api);
340int codec_load_file(const char* codec, struct codec_api *api); 325int codec_load_file(const char* codec, struct codec_api *api);
341#endif
342 326
343/* defined by the codec */ 327/* defined by the codec */
344enum codec_status codec_start(struct codec_api* rockbox) 328enum codec_status codec_start(struct codec_api* rockbox);
345 __attribute__ ((section (".entry")));
346 329
347#endif 330#endif
diff --git a/apps/codecs/Makefile b/apps/codecs/Makefile
index 5aec2ed983..d0cd97db9b 100644
--- a/apps/codecs/Makefile
+++ b/apps/codecs/Makefile
@@ -10,7 +10,7 @@
10INCLUDES = -I$(FIRMDIR)/include -I$(FIRMDIR)/export -I$(FIRMDIR)/common \ 10INCLUDES = -I$(FIRMDIR)/include -I$(FIRMDIR)/export -I$(FIRMDIR)/common \
11 -I$(FIRMDIR)/drivers -I$(APPSDIR) -Ilib -I$(BUILDDIR) 11 -I$(FIRMDIR)/drivers -I$(APPSDIR) -Ilib -I$(BUILDDIR)
12CFLAGS = $(GCCOPTS) $(INCLUDES) $(TARGET) $(EXTRA_DEFINES) \ 12CFLAGS = $(GCCOPTS) $(INCLUDES) $(TARGET) $(EXTRA_DEFINES) \
13 -DMEM=${MEMORYSIZE} -DCODEC 13 -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DCODEC
14 14
15ifdef APPEXTRA 15ifdef APPEXTRA
16 INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA))) 16 INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA)))
diff --git a/apps/codecs/a52.c b/apps/codecs/a52.c
index dd504e83fd..f12fce1027 100644
--- a/apps/codecs/a52.c
+++ b/apps/codecs/a52.c
@@ -22,6 +22,8 @@
22#include <codecs/liba52/config-a52.h> 22#include <codecs/liba52/config-a52.h>
23#include <codecs/liba52/a52.h> 23#include <codecs/liba52/a52.h>
24 24
25CODEC_HEADER
26
25#define BUFFER_SIZE 4096 27#define BUFFER_SIZE 4096
26 28
27#define A52_SAMPLESPERFRAME (6*256) 29#define A52_SAMPLESPERFRAME (6*256)
@@ -129,7 +131,6 @@ enum codec_status codec_start(struct codec_api *api)
129 int sample_loc; 131 int sample_loc;
130 132
131 /* Generic codec initialisation */ 133 /* Generic codec initialisation */
132 TEST_CODEC_API(api);
133 ci = api; 134 ci = api;
134 135
135 #ifdef USE_IRAM 136 #ifdef USE_IRAM
diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c
index a6ce0170a9..baa3935175 100644
--- a/apps/codecs/aac.c
+++ b/apps/codecs/aac.c
@@ -23,6 +23,8 @@
23#include "libfaad/structs.h" 23#include "libfaad/structs.h"
24#include "libfaad/decoder.h" 24#include "libfaad/decoder.h"
25 25
26CODEC_HEADER
27
26#ifndef SIMULATOR 28#ifndef SIMULATOR
27extern char iramcopy[]; 29extern char iramcopy[];
28extern char iramstart[]; 30extern char iramstart[];
@@ -51,10 +53,8 @@ enum codec_status codec_start(struct codec_api* api)
51 int16_t* decodedbuffer; 53 int16_t* decodedbuffer;
52 54
53 /* Generic codec initialisation */ 55 /* Generic codec initialisation */
54 TEST_CODEC_API(api);
55
56 rb = api; 56 rb = api;
57 ci = (struct codec_api*)api; 57 ci = api;
58 58
59#ifndef SIMULATOR 59#ifndef SIMULATOR
60 rb->memcpy(iramstart, iramcopy, iramend-iramstart); 60 rb->memcpy(iramstart, iramcopy, iramend-iramstart);
diff --git a/apps/codecs/alac.c b/apps/codecs/alac.c
index 30c1ada555..7ca70ce83c 100644
--- a/apps/codecs/alac.c
+++ b/apps/codecs/alac.c
@@ -21,6 +21,8 @@
21#include "libm4a/m4a.h" 21#include "libm4a/m4a.h"
22#include "libalac/decomp.h" 22#include "libalac/decomp.h"
23 23
24CODEC_HEADER
25
24#ifdef USE_IRAM 26#ifdef USE_IRAM
25extern char iramcopy[]; 27extern char iramcopy[];
26extern char iramstart[]; 28extern char iramstart[];
@@ -50,10 +52,8 @@ enum codec_status codec_start(struct codec_api* api)
50 alac_file alac; 52 alac_file alac;
51 53
52 /* Generic codec initialisation */ 54 /* Generic codec initialisation */
53 TEST_CODEC_API(api);
54
55 rb = api; 55 rb = api;
56 ci = (struct codec_api*)api; 56 ci = api;
57 57
58#ifdef USE_IRAM 58#ifdef USE_IRAM
59 rb->memcpy(iramstart, iramcopy, iramend-iramstart); 59 rb->memcpy(iramstart, iramcopy, iramend-iramstart);
diff --git a/apps/codecs/flac.c b/apps/codecs/flac.c
index ae05b0f2aa..a96963dd80 100644
--- a/apps/codecs/flac.c
+++ b/apps/codecs/flac.c
@@ -20,6 +20,8 @@
20#include "codeclib.h" 20#include "codeclib.h"
21#include <codecs/libffmpegFLAC/decoder.h> 21#include <codecs/libffmpegFLAC/decoder.h>
22 22
23CODEC_HEADER
24
23#ifdef USE_IRAM 25#ifdef USE_IRAM
24extern char iramcopy[]; 26extern char iramcopy[];
25extern char iramstart[]; 27extern char iramstart[];
@@ -226,10 +228,8 @@ enum codec_status codec_start(struct codec_api* api)
226 int frame; 228 int frame;
227 229
228 /* Generic codec initialisation */ 230 /* Generic codec initialisation */
229 TEST_CODEC_API(api);
230
231 rb = api; 231 rb = api;
232 ci = (struct codec_api*)api; 232 ci = api;
233 233
234#ifdef USE_IRAM 234#ifdef USE_IRAM
235 ci->memcpy(iramstart, iramcopy, iramend-iramstart); 235 ci->memcpy(iramstart, iramcopy, iramend-iramstart);
diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c
index 3d824d9b39..3c57f3f33f 100644
--- a/apps/codecs/mpa.c
+++ b/apps/codecs/mpa.c
@@ -21,6 +21,8 @@
21#include <codecs/libmad/mad.h> 21#include <codecs/libmad/mad.h>
22#include <inttypes.h> 22#include <inttypes.h>
23 23
24CODEC_HEADER
25
24struct mad_stream stream IBSS_ATTR; 26struct mad_stream stream IBSS_ATTR;
25struct mad_frame frame IBSS_ATTR; 27struct mad_frame frame IBSS_ATTR;
26struct mad_synth synth IBSS_ATTR; 28struct mad_synth synth IBSS_ATTR;
@@ -81,7 +83,6 @@ enum codec_status codec_start(struct codec_api *api)
81 char *inputbuffer; 83 char *inputbuffer;
82 84
83 ci = api; 85 ci = api;
84 TEST_CODEC_API(api);
85 86
86#ifdef USE_IRAM 87#ifdef USE_IRAM
87 ci->memcpy(iramstart, iramcopy, iramend - iramstart); 88 ci->memcpy(iramstart, iramcopy, iramend - iramstart);
diff --git a/apps/codecs/mpc.c b/apps/codecs/mpc.c
index 207a63ce97..1d1ed3a8b7 100644
--- a/apps/codecs/mpc.c
+++ b/apps/codecs/mpc.c
@@ -20,6 +20,8 @@
20#include "codeclib.h" 20#include "codeclib.h"
21#include <codecs/libmusepack/musepack.h> 21#include <codecs/libmusepack/musepack.h>
22 22
23CODEC_HEADER
24
23mpc_decoder decoder; 25mpc_decoder decoder;
24 26
25/* Our implementations of the mpc_reader callback functions. */ 27/* Our implementations of the mpc_reader callback functions. */
@@ -82,7 +84,6 @@ enum codec_status codec_start(struct codec_api *api)
82 mpc_reader reader; 84 mpc_reader reader;
83 mpc_streaminfo info; 85 mpc_streaminfo info;
84 86
85 TEST_CODEC_API(api);
86 #ifdef USE_IRAM 87 #ifdef USE_IRAM
87 ci->memcpy(iramstart, iramcopy, iramend - iramstart); 88 ci->memcpy(iramstart, iramcopy, iramend - iramstart);
88 ci->memset(iedata, 0, iend - iedata); 89 ci->memset(iedata, 0, iend - iedata);
diff --git a/apps/codecs/shorten.c b/apps/codecs/shorten.c
index 9e679f5ea7..ffbd42a9ff 100644
--- a/apps/codecs/shorten.c
+++ b/apps/codecs/shorten.c
@@ -20,6 +20,8 @@
20#include "codeclib.h" 20#include "codeclib.h"
21#include <codecs/libffmpegFLAC/shndec.h> 21#include <codecs/libffmpegFLAC/shndec.h>
22 22
23CODEC_HEADER
24
23#ifdef USE_IRAM 25#ifdef USE_IRAM
24extern char iramcopy[]; 26extern char iramcopy[];
25extern char iramstart[]; 27extern char iramstart[];
@@ -50,9 +52,8 @@ enum codec_status codec_start(struct codec_api* api)
50 long bytesleft; 52 long bytesleft;
51 53
52 /* Generic codec initialisation */ 54 /* Generic codec initialisation */
53 TEST_CODEC_API(api);
54 rb = api; 55 rb = api;
55 ci = (struct codec_api*)api; 56 ci = api;
56 57
57#ifdef USE_IRAM 58#ifdef USE_IRAM
58 ci->memcpy(iramstart, iramcopy, iramend-iramstart); 59 ci->memcpy(iramstart, iramcopy, iramend-iramstart);
diff --git a/apps/codecs/vorbis.c b/apps/codecs/vorbis.c
index 795e689e7d..fdd7a952d4 100644
--- a/apps/codecs/vorbis.c
+++ b/apps/codecs/vorbis.c
@@ -21,6 +21,8 @@
21#include "Tremor/ivorbisfile.h" 21#include "Tremor/ivorbisfile.h"
22#include "Tremor/ogg.h" 22#include "Tremor/ogg.h"
23 23
24CODEC_HEADER
25
24static struct codec_api *rb; 26static struct codec_api *rb;
25 27
26/* Some standard functions and variables needed by Tremor */ 28/* Some standard functions and variables needed by Tremor */
@@ -122,7 +124,6 @@ enum codec_status codec_start(struct codec_api *api)
122 ogg_uint32_t vf_serialnos; 124 ogg_uint32_t vf_serialnos;
123 ogg_int64_t vf_pcmlengths[2]; 125 ogg_int64_t vf_pcmlengths[2];
124 126
125 TEST_CODEC_API(api);
126 rb = api; 127 rb = api;
127 128
128 #ifdef USE_IRAM 129 #ifdef USE_IRAM
diff --git a/apps/codecs/wav.c b/apps/codecs/wav.c
index e86b559caa..1dda2c3d58 100644
--- a/apps/codecs/wav.c
+++ b/apps/codecs/wav.c
@@ -20,6 +20,8 @@
20#include "codeclib.h" 20#include "codeclib.h"
21#include "inttypes.h" 21#include "inttypes.h"
22 22
23CODEC_HEADER
24
23struct codec_api* rb; 25struct codec_api* rb;
24 26
25/* This codec support WAVE files with the following formats: 27/* This codec support WAVE files with the following formats:
@@ -230,8 +232,6 @@ enum codec_status codec_start(struct codec_api* api)
230 int32_t * const int32_samples = (int32_t*)int16_samples; 232 int32_t * const int32_samples = (int32_t*)int16_samples;
231 233
232 /* Generic codec initialisation */ 234 /* Generic codec initialisation */
233 TEST_CODEC_API(api);
234
235 rb = api; 235 rb = api;
236 ci = api; 236 ci = api;
237 237
diff --git a/apps/codecs/wavpack.c b/apps/codecs/wavpack.c
index ff890ba805..2804d3ef72 100644
--- a/apps/codecs/wavpack.c
+++ b/apps/codecs/wavpack.c
@@ -20,6 +20,8 @@
20#include "codeclib.h" 20#include "codeclib.h"
21#include "libwavpack/wavpack.h" 21#include "libwavpack/wavpack.h"
22 22
23CODEC_HEADER
24
23static struct codec_api *ci; 25static struct codec_api *ci;
24 26
25#define FORCE_DSP_USE /* fixes some WavPack bugs; adds about 12% to boost ratio 27#define FORCE_DSP_USE /* fixes some WavPack bugs; adds about 12% to boost ratio
@@ -52,8 +54,6 @@ enum codec_status codec_start(struct codec_api* api)
52 int bps, nchans, sr_100; 54 int bps, nchans, sr_100;
53 55
54 /* Generic codec initialisation */ 56 /* Generic codec initialisation */
55 TEST_CODEC_API(api);
56
57 ci = api; 57 ci = api;
58 58
59#ifdef USE_IRAM 59#ifdef USE_IRAM
diff --git a/firmware/export/config-gmini120.h b/firmware/export/config-gmini120.h
index 29066ecae3..8ffe51c433 100644
--- a/firmware/export/config-gmini120.h
+++ b/firmware/export/config-gmini120.h
@@ -28,7 +28,7 @@
28#define CODEC_SIZE 0x40000 28#define CODEC_SIZE 0x40000
29 29
30/* The number of bytes reserved for loadable plugins */ 30/* The number of bytes reserved for loadable plugins */
31#define PLUGIN_BUFFER_SIZE 0xC0000 31#define PLUGIN_BUFFER_SIZE 0x80000
32 32
33#ifndef SIMULATOR 33#ifndef SIMULATOR
34 34
diff --git a/firmware/export/config-gminisp.h b/firmware/export/config-gminisp.h
index 982e8f3725..4aa4723ca0 100644
--- a/firmware/export/config-gminisp.h
+++ b/firmware/export/config-gminisp.h
@@ -19,7 +19,7 @@
19#define CODEC_SIZE 0x40000 19#define CODEC_SIZE 0x40000
20 20
21/* The number of bytes reserved for loadable plugins */ 21/* The number of bytes reserved for loadable plugins */
22#define PLUGIN_BUFFER_SIZE 0xC0000 22#define PLUGIN_BUFFER_SIZE 0x80000
23 23
24#ifndef SIMULATOR 24#ifndef SIMULATOR
25 25
diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h
index 6d19b44820..34c0cc4f70 100644
--- a/firmware/export/config-h100.h
+++ b/firmware/export/config-h100.h
@@ -45,7 +45,7 @@
45#define CODEC_SIZE 0x80000 45#define CODEC_SIZE 0x80000
46 46
47/* The number of bytes reserved for loadable plugins */ 47/* The number of bytes reserved for loadable plugins */
48#define PLUGIN_BUFFER_SIZE 0xC0000 48#define PLUGIN_BUFFER_SIZE 0x80000
49 49
50#define CONFIG_TUNER TEA5767 50#define CONFIG_TUNER TEA5767
51#define CONFIG_TUNER_XTAL 32768 51#define CONFIG_TUNER_XTAL 32768
diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h
index 5c6f763981..2790063c64 100644
--- a/firmware/export/config-h120.h
+++ b/firmware/export/config-h120.h
@@ -41,7 +41,7 @@
41#define CODEC_SIZE 0x80000 41#define CODEC_SIZE 0x80000
42 42
43/* The number of bytes reserved for loadable plugins */ 43/* The number of bytes reserved for loadable plugins */
44#define PLUGIN_BUFFER_SIZE 0xC0000 44#define PLUGIN_BUFFER_SIZE 0x80000
45 45
46#define CONFIG_TUNER TEA5767 46#define CONFIG_TUNER TEA5767
47#define CONFIG_TUNER_XTAL 32768 47#define CONFIG_TUNER_XTAL 32768
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h
index 2698d12098..806ae0a079 100644
--- a/firmware/export/config-h300.h
+++ b/firmware/export/config-h300.h
@@ -46,7 +46,7 @@
46#define CODEC_SIZE 0x80000 46#define CODEC_SIZE 0x80000
47 47
48/* The number of bytes reserved for loadable plugins */ 48/* The number of bytes reserved for loadable plugins */
49#define PLUGIN_BUFFER_SIZE 0xC0000 49#define PLUGIN_BUFFER_SIZE 0x80000
50 50
51#define CONFIG_TUNER TEA5767 51#define CONFIG_TUNER TEA5767
52#define CONFIG_TUNER_XTAL 32768 52#define CONFIG_TUNER_XTAL 32768
diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h
index a06d22b3c1..ac3073428b 100644
--- a/firmware/export/config-iaudiox5.h
+++ b/firmware/export/config-iaudiox5.h
@@ -38,7 +38,7 @@
38#define CODEC_SIZE 0x40000 38#define CODEC_SIZE 0x40000
39 39
40/* The number of bytes reserved for loadable plugins */ 40/* The number of bytes reserved for loadable plugins */
41#define PLUGIN_BUFFER_SIZE 0xC0000 41#define PLUGIN_BUFFER_SIZE 0x80000
42 42
43#ifndef SIMULATOR 43#ifndef SIMULATOR
44 44
diff --git a/firmware/export/config-ipodcolor.h b/firmware/export/config-ipodcolor.h
index b88c9bc7a4..b413b8681c 100644
--- a/firmware/export/config-ipodcolor.h
+++ b/firmware/export/config-ipodcolor.h
@@ -38,7 +38,7 @@
38#define CODEC_SIZE 0x80000 38#define CODEC_SIZE 0x80000
39 39
40/* The number of bytes reserved for loadable plugins */ 40/* The number of bytes reserved for loadable plugins */
41#define PLUGIN_BUFFER_SIZE 0xC0000 41#define PLUGIN_BUFFER_SIZE 0x80000
42 42
43/* Define this if you have the WM8975 audio codec */ 43/* Define this if you have the WM8975 audio codec */
44#define HAVE_WM8975 44#define HAVE_WM8975
diff --git a/firmware/export/config-ipodnano.h b/firmware/export/config-ipodnano.h
index 207aa18fa2..728c83ef9f 100644
--- a/firmware/export/config-ipodnano.h
+++ b/firmware/export/config-ipodnano.h
@@ -38,7 +38,7 @@
38#define CODEC_SIZE 0x80000 38#define CODEC_SIZE 0x80000
39 39
40/* The number of bytes reserved for loadable plugins */ 40/* The number of bytes reserved for loadable plugins */
41#define PLUGIN_BUFFER_SIZE 0xC0000 41#define PLUGIN_BUFFER_SIZE 0x80000
42 42
43/* Define this if you have the WM8975 audio codec */ 43/* Define this if you have the WM8975 audio codec */
44#define HAVE_WM8975 44#define HAVE_WM8975
diff --git a/firmware/export/config-ipodvideo.h b/firmware/export/config-ipodvideo.h
index d6d9bbc92f..0e6dc153bb 100644
--- a/firmware/export/config-ipodvideo.h
+++ b/firmware/export/config-ipodvideo.h
@@ -38,7 +38,7 @@
38#define CODEC_SIZE 0x80000 38#define CODEC_SIZE 0x80000
39 39
40/* The number of bytes reserved for loadable plugins */ 40/* The number of bytes reserved for loadable plugins */
41#define PLUGIN_BUFFER_SIZE 0xC0000 41#define PLUGIN_BUFFER_SIZE 0x80000
42 42
43/* Define this if you have the WM8975 audio codec */ 43/* Define this if you have the WM8975 audio codec */
44#define HAVE_WM8975 44#define HAVE_WM8975
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index 1871b29395..68eb8933a5 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -306,20 +306,20 @@ int sim_fsync(int fd)
306void *sim_codec_load_ram(char* codecptr, int size, 306void *sim_codec_load_ram(char* codecptr, int size,
307 void* ptr2, int bufwrap, int *pd_fd) 307 void* ptr2, int bufwrap, int *pd_fd)
308{ 308{
309 void *pd; 309 void *pd, *hdr;
310 char *path = "archos/_temp_codec.dll"; 310 const char *path = "archos/_temp_codec.dll";
311 int (*codec_start)(void * api);
312 int fd; 311 int fd;
313 int copy_n; 312 int copy_n;
314#ifdef WIN32 313#ifdef WIN32
315 char buf[256]; 314 char buf[256];
316#endif 315#endif
317 316
317 *pd_fd = 0;
318
318 /* We have to create the dynamic link library file from ram 319 /* We have to create the dynamic link library file from ram
319 * so we could simulate the codec loading. 320 so we could simulate the codec loading. */
320 */ 321
321 *pd_fd = -1; 322 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
322 fd = open(path, O_WRONLY | O_CREAT, S_IRWXU);
323 if (fd < 0) { 323 if (fd < 0) {
324 DEBUGF("failed to open for write: %s\n", path); 324 DEBUGF("failed to open for write: %s\n", path);
325 return NULL; 325 return NULL;
@@ -341,7 +341,7 @@ void *sim_codec_load_ram(char* codecptr, int size,
341 } 341 }
342 } 342 }
343 close(fd); 343 close(fd);
344 344
345 /* Now load the library. */ 345 /* Now load the library. */
346 pd = dlopen(path, RTLD_NOW); 346 pd = dlopen(path, RTLD_NOW);
347 if (!pd) { 347 if (!pd) {
@@ -357,17 +357,12 @@ void *sim_codec_load_ram(char* codecptr, int size,
357 return NULL; 357 return NULL;
358 } 358 }
359 359
360 codec_start = dlsym(pd, "codec_start"); 360 hdr = dlsym(pd, "__header");
361 if (!codec_start) { 361 if (!hdr)
362 codec_start = dlsym(pd, "_codec_start"); 362 hdr = dlsym(pd, "___header");
363 if (!codec_start) {
364 dlclose(pd);
365 return NULL;
366 }
367 }
368 363
369 *pd_fd = (int)pd; 364 *pd_fd = (int)pd;
370 return codec_start; 365 return hdr; /* maybe NULL if symbol not present */
371} 366}
372 367
373void sim_codec_close(int pd) 368void sim_codec_close(int pd)