diff options
-rw-r--r-- | apps/codecs.c | 23 | ||||
-rw-r--r-- | apps/codecs.h | 2 | ||||
-rw-r--r-- | apps/playback.c | 27 | ||||
-rw-r--r-- | uisimulator/common/io.c | 72 |
4 files changed, 112 insertions, 12 deletions
diff --git a/apps/codecs.c b/apps/codecs.c index 400e7fbfcf..dd87ddf0ed 100644 --- a/apps/codecs.c +++ b/apps/codecs.c | |||
@@ -56,8 +56,9 @@ | |||
56 | #if CONFIG_HWCODEC == MASNONE | 56 | #if CONFIG_HWCODEC == MASNONE |
57 | static unsigned char codecbuf[CODEC_SIZE]; | 57 | static unsigned char codecbuf[CODEC_SIZE]; |
58 | #endif | 58 | #endif |
59 | void *sim_codec_load(char *plugin, int *fd); | 59 | void *sim_codec_load_ram(char* codecptr, int size, |
60 | void sim_codec_close(int fd); | 60 | void* ptr2, int bufwrap, int *pd); |
61 | void sim_codec_close(int pd); | ||
61 | #else | 62 | #else |
62 | #define sim_codec_close(x) | 63 | #define sim_codec_close(x) |
63 | extern unsigned char codecbuf[]; | 64 | extern unsigned char codecbuf[]; |
@@ -245,11 +246,12 @@ struct codec_api ci = { | |||
245 | memchr, | 246 | memchr, |
246 | }; | 247 | }; |
247 | 248 | ||
248 | int codec_load_ram(char* codecptr, size_t size, void* ptr2, size_t bufwrap) | 249 | int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap) |
249 | { | 250 | { |
250 | enum codec_status (*codec_start)(const struct codec_api* api); | 251 | enum codec_status (*codec_start)(const struct codec_api* api); |
251 | int copy_n; | ||
252 | int status; | 252 | int status; |
253 | #ifndef SIMULATOR | ||
254 | int copy_n; | ||
253 | 255 | ||
254 | if ((char *)&codecbuf[0] != codecptr) { | 256 | if ((char *)&codecbuf[0] != codecptr) { |
255 | /* zero out codec buffer to ensure a properly zeroed bss area */ | 257 | /* zero out codec buffer to ensure a properly zeroed bss area */ |
@@ -265,8 +267,19 @@ int codec_load_ram(char* codecptr, size_t size, void* ptr2, size_t bufwrap) | |||
265 | } | 267 | } |
266 | codec_start = (void*)&codecbuf; | 268 | codec_start = (void*)&codecbuf; |
267 | 269 | ||
270 | #else /* SIMULATOR */ | ||
271 | int pd; | ||
272 | |||
273 | codec_start = sim_codec_load_ram(codecptr, size, ptr2, bufwrap, &pd); | ||
274 | if (pd < 0) | ||
275 | return CODEC_ERROR; | ||
276 | #endif /* SIMULATOR */ | ||
277 | |||
268 | invalidate_icache(); | 278 | invalidate_icache(); |
269 | status = codec_start(&ci); | 279 | status = codec_start(&ci); |
280 | #ifdef SIMULATOR | ||
281 | sim_codec_close(pd); | ||
282 | #endif | ||
270 | 283 | ||
271 | return status; | 284 | return status; |
272 | } | 285 | } |
@@ -294,7 +307,7 @@ int codec_load_file(const char *plugin) | |||
294 | logf("Codec read error"); | 307 | logf("Codec read error"); |
295 | return CODEC_ERROR; | 308 | return CODEC_ERROR; |
296 | } | 309 | } |
297 | 310 | ||
298 | return codec_load_ram(codecbuf, (size_t)rc, NULL, 0); | 311 | return codec_load_ram(codecbuf, (size_t)rc, NULL, 0); |
299 | } | 312 | } |
300 | 313 | ||
diff --git a/apps/codecs.h b/apps/codecs.h index ea5972968f..73a5709328 100644 --- a/apps/codecs.h +++ b/apps/codecs.h | |||
@@ -331,7 +331,7 @@ struct codec_api { | |||
331 | 331 | ||
332 | /* defined by the codec loader (codec.c) */ | 332 | /* defined by the codec loader (codec.c) */ |
333 | #if CONFIG_HWCODEC == MASNONE | 333 | #if CONFIG_HWCODEC == MASNONE |
334 | int codec_load_ram(char* codecptr, size_t size, void* ptr2, size_t bufwrap); | 334 | int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap); |
335 | int codec_load_file(const char* codec); | 335 | int codec_load_file(const char* codec); |
336 | #endif | 336 | #endif |
337 | 337 | ||
diff --git a/apps/playback.c b/apps/playback.c index a1f098b148..e7c1040378 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -191,15 +191,16 @@ void pcm_flush_buffer(long length) | |||
191 | 191 | ||
192 | void* pcm_request_buffer(long length, long *realsize) | 192 | void* pcm_request_buffer(long length, long *realsize) |
193 | { | 193 | { |
194 | (void)length; | 194 | static char temp_audiobuffer[32768]; |
195 | (void)realsize; | 195 | |
196 | *realsize = MIN((int)sizeof(temp_audiobuffer), length); | ||
196 | 197 | ||
197 | return NULL; | 198 | return temp_audiobuffer; |
198 | } | 199 | } |
199 | 200 | ||
200 | void audiobuffer_add_event(void (*event_handler)(void)) | 201 | void audiobuffer_add_event(void (*event_handler)(void)) |
201 | { | 202 | { |
202 | (void)event_handler; | 203 | event_handler(); |
203 | } | 204 | } |
204 | 205 | ||
205 | unsigned int audiobuffer_get_latency() | 206 | unsigned int audiobuffer_get_latency() |
@@ -1287,6 +1288,18 @@ void audio_change_track(void) | |||
1287 | queue_post(&codec_queue, CODEC_LOAD, 0); | 1288 | queue_post(&codec_queue, CODEC_LOAD, 0); |
1288 | } | 1289 | } |
1289 | 1290 | ||
1291 | static int get_codec_base_type(int type) | ||
1292 | { | ||
1293 | switch (type) { | ||
1294 | case AFMT_MPA_L1: | ||
1295 | case AFMT_MPA_L2: | ||
1296 | case AFMT_MPA_L3: | ||
1297 | return AFMT_MPA_L3; | ||
1298 | } | ||
1299 | |||
1300 | return type; | ||
1301 | } | ||
1302 | |||
1290 | bool codec_request_next_track_callback(void) | 1303 | bool codec_request_next_track_callback(void) |
1291 | { | 1304 | { |
1292 | if (ci.stop_codec || !playing) | 1305 | if (ci.stop_codec || !playing) |
@@ -1361,7 +1374,9 @@ bool codec_request_next_track_callback(void) | |||
1361 | 1374 | ||
1362 | ci.reload_codec = false; | 1375 | ci.reload_codec = false; |
1363 | 1376 | ||
1364 | if (cur_ti->id3.codectype != tracks[track_ridx].id3.codectype) { | 1377 | /* Check if the next codec is the same file. */ |
1378 | if (get_codec_base_type(cur_ti->id3.codectype) != | ||
1379 | get_codec_base_type(tracks[track_ridx].id3.codectype)) { | ||
1365 | logf("New codec:%d/%d", cur_ti->id3.codectype, | 1380 | logf("New codec:%d/%d", cur_ti->id3.codectype, |
1366 | tracks[track_ridx].id3.codectype); | 1381 | tracks[track_ridx].id3.codectype); |
1367 | if (--track_ridx < 0) | 1382 | if (--track_ridx < 0) |
@@ -1436,7 +1451,7 @@ void audio_thread(void) | |||
1436 | ci.stop_codec = true; | 1451 | ci.stop_codec = true; |
1437 | ci.reload_codec = false; | 1452 | ci.reload_codec = false; |
1438 | ci.seek_time = 0; | 1453 | ci.seek_time = 0; |
1439 | if (!pcm_crossfade_init()) | 1454 | if (!pcm_crossfade_init() && !pcm_is_crossfade_active()) |
1440 | pcm_flush_audio(); | 1455 | pcm_flush_audio(); |
1441 | audio_play_start((int)ev.data); | 1456 | audio_play_start((int)ev.data); |
1442 | playlist_update_resume_info(audio_current_track()); | 1457 | playlist_update_resume_info(audio_current_track()); |
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index 78fb835785..7ea2d6878f 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c | |||
@@ -307,6 +307,78 @@ int sim_fsync(int fd) | |||
307 | #include <dlfcn.h> | 307 | #include <dlfcn.h> |
308 | #endif | 308 | #endif |
309 | 309 | ||
310 | void *sim_codec_load_ram(char* codecptr, int size, | ||
311 | void* ptr2, int bufwrap, int *pd_fd) | ||
312 | { | ||
313 | void *pd; | ||
314 | char *path = "archos/_temp_codec.dll"; | ||
315 | int (*codec_start)(void * api); | ||
316 | int fd; | ||
317 | int copy_n; | ||
318 | #ifdef WIN32 | ||
319 | char buf[256]; | ||
320 | #endif | ||
321 | |||
322 | /* We have to create the dynamic link library file from ram | ||
323 | * so we could simulate the codec loading. | ||
324 | */ | ||
325 | *pd_fd = -1; | ||
326 | fd = open(path, O_WRONLY | O_CREAT, S_IRWXU); | ||
327 | if (fd < 0) { | ||
328 | DEBUGF("failed to open for write: %s\n", path); | ||
329 | return NULL; | ||
330 | } | ||
331 | |||
332 | if (bufwrap == 0) | ||
333 | bufwrap = size; | ||
334 | |||
335 | copy_n = bufwrap < size ? bufwrap : size; | ||
336 | if (write(fd, codecptr, copy_n) != copy_n) { | ||
337 | DEBUGF("write failed"); | ||
338 | return NULL; | ||
339 | } | ||
340 | size -= copy_n; | ||
341 | if (size > 0) { | ||
342 | if (write(fd, ptr2, size) != size) { | ||
343 | DEBUGF("write failed [2]"); | ||
344 | return NULL; | ||
345 | } | ||
346 | } | ||
347 | close(fd); | ||
348 | |||
349 | /* Now load the library. */ | ||
350 | pd = dlopen(path, RTLD_NOW); | ||
351 | if (!pd) { | ||
352 | DEBUGF("failed to load %s\n", path); | ||
353 | #ifdef WIN32 | ||
354 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, | ||
355 | buf, sizeof buf, NULL); | ||
356 | DEBUGF("dlopen(%s): %s\n", path, buf); | ||
357 | #else | ||
358 | DEBUGF("dlopen(%s): %s\n", path, dlerror()); | ||
359 | #endif | ||
360 | dlclose(pd); | ||
361 | return NULL; | ||
362 | } | ||
363 | |||
364 | codec_start = dlsym(pd, "codec_start"); | ||
365 | if (!codec_start) { | ||
366 | codec_start = dlsym(pd, "_codec_start"); | ||
367 | if (!codec_start) { | ||
368 | dlclose(pd); | ||
369 | return NULL; | ||
370 | } | ||
371 | } | ||
372 | |||
373 | *pd_fd = (int)pd; | ||
374 | return codec_start; | ||
375 | } | ||
376 | |||
377 | void sim_codec_close(int pd) | ||
378 | { | ||
379 | dlclose((void *)pd); | ||
380 | } | ||
381 | |||
310 | void *sim_plugin_load(char *plugin, int *fd) | 382 | void *sim_plugin_load(char *plugin, int *fd) |
311 | { | 383 | { |
312 | void* pd; | 384 | void* pd; |