2005-06-22 19:41:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-05-05 10:32:46 +00:00
|
|
|
* Copyright (C) 2002 Björn Stenberg
|
2005-06-22 19:41:30 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2005-06-22 19:41:30 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2005-06-27 21:23:03 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2008-04-28 16:18:04 +00:00
|
|
|
#include <stdlib.h>
|
2005-06-22 19:41:30 +00:00
|
|
|
#include <timefuncs.h>
|
|
|
|
#include <ctype.h>
|
2010-05-06 21:04:40 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include "string-extra.h"
|
2010-08-27 00:29:50 +00:00
|
|
|
#include "load_code.h"
|
2005-06-22 19:41:30 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "codecs.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "keyboard.h"
|
2007-11-02 14:06:48 +00:00
|
|
|
#include "buffering.h"
|
2005-06-22 19:41:30 +00:00
|
|
|
#include "mp3_playback.h"
|
|
|
|
#include "backlight.h"
|
2008-11-01 16:14:28 +00:00
|
|
|
#include "storage.h"
|
2005-06-22 19:41:30 +00:00
|
|
|
#include "talk.h"
|
|
|
|
#include "mp3data.h"
|
|
|
|
#include "powermgmt.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "sound.h"
|
2005-11-16 15:12:15 +00:00
|
|
|
#include "splash.h"
|
2006-11-06 18:07:30 +00:00
|
|
|
#include "general.h"
|
2011-08-30 19:40:09 +00:00
|
|
|
#include "rbpaths.h"
|
2005-11-16 15:12:15 +00:00
|
|
|
|
2009-11-03 20:57:13 +00:00
|
|
|
#define LOGF_ENABLE
|
2007-10-24 22:06:36 +00:00
|
|
|
#include "logf.h"
|
|
|
|
|
2011-02-27 23:42:37 +00:00
|
|
|
#if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA))
|
2010-06-21 16:53:00 +00:00
|
|
|
#define PREFIX(_x_) sim_ ## _x_
|
2010-09-01 21:29:34 +00:00
|
|
|
#else
|
|
|
|
#define PREFIX(_x_) _x_
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
|
2011-05-08 20:18:35 +00:00
|
|
|
/* For PLATFORM_HOSTED this buffer must be define here. */
|
|
|
|
static unsigned char codecbuf[CODEC_SIZE];
|
|
|
|
#else
|
|
|
|
/* For PLATFORM_NATIVE this buffer is defined in *.lds files. */
|
|
|
|
extern unsigned char codecbuf[];
|
2005-06-22 19:41:30 +00:00
|
|
|
#endif
|
|
|
|
|
2011-05-08 20:18:35 +00:00
|
|
|
static size_t codec_size;
|
2008-10-19 12:35:53 +00:00
|
|
|
|
2007-04-21 18:38:25 +00:00
|
|
|
extern void* plugin_get_audio_buffer(size_t *buffer_size);
|
2005-06-22 19:41:30 +00:00
|
|
|
|
2010-08-27 00:29:50 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_NATIVE) && defined(HAVE_RECORDING)
|
2010-05-06 17:35:13 +00:00
|
|
|
#undef open
|
|
|
|
static int open(const char* pathname, int flags, ...)
|
|
|
|
{
|
|
|
|
return file_open(pathname, flags);
|
2010-08-27 00:16:26 +00:00
|
|
|
}
|
2010-08-27 00:29:50 +00:00
|
|
|
#endif
|
2005-06-22 21:16:28 +00:00
|
|
|
struct codec_api ci = {
|
2005-06-22 19:41:30 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
0, /* filesize */
|
|
|
|
0, /* curpos */
|
2005-06-22 19:41:30 +00:00
|
|
|
NULL, /* id3 */
|
2011-04-27 03:08:23 +00:00
|
|
|
ERR_HANDLE_NOT_FOUND, /* audio_hid */
|
2008-03-25 02:34:12 +00:00
|
|
|
NULL, /* struct dsp_config *dsp */
|
2008-10-19 12:35:53 +00:00
|
|
|
NULL, /* codec_get_buffer */
|
2006-04-15 02:03:11 +00:00
|
|
|
NULL, /* pcmbuf_insert */
|
|
|
|
NULL, /* set_elapsed */
|
|
|
|
NULL, /* read_filebuf */
|
|
|
|
NULL, /* request_buffer */
|
|
|
|
NULL, /* advance_buffer */
|
|
|
|
NULL, /* seek_buffer */
|
|
|
|
NULL, /* seek_complete */
|
|
|
|
NULL, /* set_offset */
|
|
|
|
NULL, /* configure */
|
2011-04-27 03:08:23 +00:00
|
|
|
NULL, /* get_command */
|
2011-08-30 19:40:09 +00:00
|
|
|
NULL, /* loop_track */
|
2005-06-22 19:41:30 +00:00
|
|
|
|
|
|
|
/* kernel/ system */
|
2010-08-03 19:00:29 +00:00
|
|
|
#if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
|
2009-02-11 16:37:12 +00:00
|
|
|
__div0,
|
|
|
|
#endif
|
2010-09-01 21:29:34 +00:00
|
|
|
sleep,
|
2005-06-22 19:41:30 +00:00
|
|
|
yield,
|
|
|
|
|
2008-03-25 02:34:12 +00:00
|
|
|
#if NUM_CORES > 1
|
|
|
|
create_thread,
|
|
|
|
thread_thaw,
|
|
|
|
thread_wait,
|
|
|
|
semaphore_init,
|
|
|
|
semaphore_wait,
|
|
|
|
semaphore_release,
|
|
|
|
#endif
|
|
|
|
|
2011-12-17 07:27:24 +00:00
|
|
|
commit_dcache,
|
|
|
|
commit_discard_dcache,
|
2008-03-25 02:34:12 +00:00
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
/* strings and memory */
|
|
|
|
strcpy,
|
|
|
|
strlen,
|
|
|
|
strcmp,
|
2007-05-07 11:09:45 +00:00
|
|
|
strcat,
|
2005-06-22 19:41:30 +00:00
|
|
|
memset,
|
|
|
|
memcpy,
|
2006-03-24 13:43:15 +00:00
|
|
|
memmove,
|
2005-06-22 19:41:30 +00:00
|
|
|
memcmp,
|
2006-01-18 00:05:14 +00:00
|
|
|
memchr,
|
2005-06-22 19:41:30 +00:00
|
|
|
#if defined(DEBUG) || defined(SIMULATOR)
|
|
|
|
debugf,
|
2006-01-18 00:05:14 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ROCKBOX_HAS_LOGF
|
|
|
|
logf,
|
2005-06-22 19:41:30 +00:00
|
|
|
#endif
|
2007-05-07 11:09:45 +00:00
|
|
|
|
|
|
|
(qsort_func)qsort,
|
2005-06-22 19:41:30 +00:00
|
|
|
|
2006-01-18 20:54:13 +00:00
|
|
|
#ifdef RB_PROFILE
|
|
|
|
profile_thread,
|
|
|
|
profstop,
|
2008-07-28 22:43:41 +00:00
|
|
|
__cyg_profile_func_enter,
|
|
|
|
__cyg_profile_func_exit,
|
2006-01-18 20:54:13 +00:00
|
|
|
#endif
|
2005-06-22 19:41:30 +00:00
|
|
|
|
2010-07-04 13:37:52 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2006-08-28 22:38:41 +00:00
|
|
|
enc_get_inputs,
|
|
|
|
enc_set_parameters,
|
2006-11-06 18:07:30 +00:00
|
|
|
enc_get_chunk,
|
|
|
|
enc_finish_chunk,
|
|
|
|
enc_get_pcm_data,
|
2007-03-04 04:16:53 +00:00
|
|
|
enc_unget_pcm_data,
|
2007-05-07 11:09:45 +00:00
|
|
|
|
|
|
|
/* file */
|
|
|
|
(open_func)PREFIX(open),
|
2010-07-04 13:37:52 +00:00
|
|
|
PREFIX(close),
|
|
|
|
(read_func)PREFIX(read),
|
2007-05-07 11:09:45 +00:00
|
|
|
PREFIX(lseek),
|
2010-07-04 13:37:52 +00:00
|
|
|
(write_func)PREFIX(write),
|
2007-05-07 11:09:45 +00:00
|
|
|
round_value_to_list32,
|
|
|
|
|
2010-07-04 13:37:52 +00:00
|
|
|
#endif /* HAVE_RECORDING */
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2006-02-03 00:12:11 +00:00
|
|
|
/* new stuff at the end, sort into place next time
|
|
|
|
the API gets incompatible */
|
2011-12-17 07:27:24 +00:00
|
|
|
|
|
|
|
commit_discard_idcache,
|
2005-06-22 19:41:30 +00:00
|
|
|
};
|
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
void codec_get_full_path(char *path, const char *codec_root_fn)
|
2006-08-28 22:38:41 +00:00
|
|
|
{
|
2011-05-31 21:26:18 +00:00
|
|
|
snprintf(path, MAX_PATH-1, CODECS_DIR "/" CODEC_PREFIX "%s."
|
|
|
|
CODEC_EXTENSION, codec_root_fn);
|
2006-08-28 22:38:41 +00:00
|
|
|
}
|
|
|
|
|
2011-05-08 20:18:35 +00:00
|
|
|
/* Returns pointer to and size of free codec RAM. Aligns to CACHEALIGN_SIZE. */
|
2011-05-09 19:34:45 +00:00
|
|
|
void *codec_get_buffer_callback(size_t *size)
|
2011-05-08 20:18:35 +00:00
|
|
|
{
|
|
|
|
void *buf = &codecbuf[codec_size];
|
2011-05-09 20:43:35 +00:00
|
|
|
ssize_t s = CODEC_SIZE - codec_size;
|
2011-05-08 20:18:35 +00:00
|
|
|
|
2011-05-09 20:43:35 +00:00
|
|
|
if (s <= 0)
|
2011-05-08 20:18:35 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-05-09 20:43:35 +00:00
|
|
|
*size = s;
|
|
|
|
ALIGN_BUFFER(buf, *size, CACHEALIGN_SIZE);
|
|
|
|
|
2011-05-08 20:18:35 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/** codec loading and call interface **/
|
|
|
|
static void *curr_handle = NULL;
|
|
|
|
static struct codec_header *c_hdr = NULL;
|
|
|
|
|
|
|
|
static int codec_load_ram(struct codec_api *api)
|
2005-06-22 19:41:30 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
struct lc_header *hdr;
|
|
|
|
|
|
|
|
c_hdr = lc_get_header(curr_handle);
|
|
|
|
hdr = c_hdr ? &c_hdr->lc_hdr : NULL;
|
2010-08-27 00:29:50 +00:00
|
|
|
|
|
|
|
if (hdr == NULL
|
2006-11-06 18:07:30 +00:00
|
|
|
|| (hdr->magic != CODEC_MAGIC
|
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
&& hdr->magic != CODEC_ENC_MAGIC
|
|
|
|
#endif
|
|
|
|
)
|
2006-01-18 00:05:14 +00:00
|
|
|
|| hdr->target_id != TARGET_ID
|
2010-08-27 00:29:50 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
|
2006-01-18 00:05:14 +00:00
|
|
|
|| hdr->load_addr != codecbuf
|
2010-08-27 00:29:50 +00:00
|
|
|
|| hdr->end_addr > codecbuf + CODEC_SIZE
|
|
|
|
#endif
|
|
|
|
)
|
2006-01-21 08:17:40 +00:00
|
|
|
{
|
|
|
|
logf("codec header error");
|
2011-04-27 03:08:23 +00:00
|
|
|
lc_close(curr_handle);
|
|
|
|
curr_handle = NULL;
|
|
|
|
return CODEC_ERROR;
|
2006-01-18 00:05:14 +00:00
|
|
|
}
|
2008-10-19 12:35:53 +00:00
|
|
|
|
2006-01-18 00:05:14 +00:00
|
|
|
if (hdr->api_version > CODEC_API_VERSION
|
|
|
|
|| hdr->api_version < CODEC_MIN_API_VERSION) {
|
2010-08-27 00:29:50 +00:00
|
|
|
logf("codec api version error");
|
2011-04-27 03:08:23 +00:00
|
|
|
lc_close(curr_handle);
|
|
|
|
curr_handle = NULL;
|
|
|
|
return CODEC_ERROR;
|
2006-01-18 00:05:14 +00:00
|
|
|
}
|
2005-07-10 16:33:03 +00:00
|
|
|
|
2010-08-27 00:29:50 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
|
|
|
|
codec_size = hdr->end_addr - codecbuf;
|
|
|
|
#else
|
|
|
|
codec_size = 0;
|
|
|
|
#endif
|
|
|
|
|
2010-09-09 16:17:21 +00:00
|
|
|
*(c_hdr->api) = api;
|
2006-01-18 00:05:14 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
logf("Codec: calling entrypoint");
|
|
|
|
return c_hdr->entry_point(CODEC_LOAD);
|
2005-06-22 19:41:30 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
int codec_load_buf(int hid, struct codec_api *api)
|
2008-10-19 12:35:53 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
int rc = bufread(hid, CODEC_SIZE, codecbuf);
|
|
|
|
|
2007-11-02 14:06:48 +00:00
|
|
|
if (rc < 0) {
|
2011-02-23 14:31:13 +00:00
|
|
|
logf("Codec: cannot read buf handle");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2007-11-02 14:06:48 +00:00
|
|
|
}
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
curr_handle = lc_open_from_mem(codecbuf, rc);
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (curr_handle == NULL) {
|
|
|
|
logf("Codec: load error");
|
|
|
|
return CODEC_ERROR;
|
2010-08-27 00:29:50 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return codec_load_ram(api);
|
2007-11-02 14:06:48 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
int codec_load_file(const char *plugin, struct codec_api *api)
|
2005-06-22 19:41:30 +00:00
|
|
|
{
|
2006-08-28 22:38:41 +00:00
|
|
|
char path[MAX_PATH];
|
|
|
|
|
|
|
|
codec_get_full_path(path, plugin);
|
2010-08-27 00:29:50 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
curr_handle = lc_open(path, codecbuf, CODEC_SIZE);
|
2010-08-27 00:29:50 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (curr_handle == NULL) {
|
2011-02-23 14:31:13 +00:00
|
|
|
logf("Codec: cannot read file");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2005-06-22 19:41:30 +00:00
|
|
|
}
|
2005-07-10 16:33:03 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return codec_load_ram(api);
|
2005-06-22 19:41:30 +00:00
|
|
|
}
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
int codec_run_proc(void)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
if (curr_handle == NULL) {
|
|
|
|
logf("Codec: no codec to run");
|
|
|
|
return CODEC_ERROR;
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
logf("Codec: entering run state");
|
|
|
|
return c_hdr->run_proc();
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
int codec_close(void)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
int status = CODEC_OK;
|
|
|
|
|
|
|
|
if (curr_handle != NULL) {
|
|
|
|
logf("Codec: cleaning up");
|
|
|
|
status = c_hdr->entry_point(CODEC_UNLOAD);
|
|
|
|
lc_close(curr_handle);
|
|
|
|
curr_handle = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|