summaryrefslogtreecommitdiff
path: root/apps/codecs.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs.c')
-rw-r--r--apps/codecs.c93
1 files changed, 31 insertions, 62 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}