1
0
Fork 0
forked from len0rd/rockbox

New codec loader, using the same mechanism as the new plugin loader. API version numbering restarted for the new system. Uses the target ID from configure, so don't change that too often. * Fixed sim_plugin_load_ram() to truncate the tempfile. * Reduced plugin buffer size to 512KB for iriver and iPod.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8362 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2006-01-18 00:05:14 +00:00
parent 507ff53c9c
commit b8749fdf21
23 changed files with 117 additions and 165 deletions

View file

@ -68,13 +68,9 @@ extern unsigned char codecbuf[];
extern void* plugin_get_audio_buffer(int *buffer_size);
static int codec_test(int api_version, int model, int memsize);
struct codec_api ci_voice;
struct codec_api ci = {
CODEC_API_VERSION,
codec_test,
0, /* filesize */
0, /* curpos */
@ -95,6 +91,8 @@ struct codec_api ci = {
NULL,
NULL,
NULL,
NULL,
NULL,
gui_syncsplash,
@ -155,6 +153,7 @@ struct codec_api ci = {
strcat,
memcmp,
strcasestr,
memchr,
/* sound */
sound_set,
@ -163,9 +162,6 @@ struct codec_api ci = {
mp3_play_pause,
mp3_play_stop,
mp3_is_playing,
#if CONFIG_CODEC != SWCODEC
bitswap,
#endif
#if CONFIG_CODEC == SWCODEC
pcm_play_data,
pcm_play_stop,
@ -190,24 +186,6 @@ struct codec_api ci = {
audio_current_track,
audio_flush_and_reload_tracks,
audio_get_file_pos,
#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
mpeg_get_last_header,
#endif
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
sound_set_pitch,
#endif
#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
/* MAS communication */
mas_readmem,
mas_writemem,
mas_readreg,
mas_writereg,
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
mas_codec_writereg,
mas_codec_readreg,
#endif
#endif /* !simulator and HWCODEC != SWCODEC */
/* tag database */
&tagdbheader,
@ -226,6 +204,9 @@ struct codec_api ci = {
#if defined(DEBUG) || defined(SIMULATOR)
debugf,
#endif
#ifdef ROCKBOX_HAS_LOGF
logf,
#endif
&global_settings,
mp3info,
@ -234,28 +215,16 @@ struct codec_api ci = {
find_next_frame,
battery_level,
battery_level_safe,
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
peak_meter_scale_value,
peak_meter_set_use_dbfs,
peak_meter_get_use_dbfs,
#endif
/* new stuff at the end, sort into place next time
the API gets incompatible */
#ifdef ROCKBOX_HAS_LOGF
logf,
#endif
memchr,
NULL,
NULL,
};
int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
struct codec_api *api)
{
enum codec_status (*codec_start)(const struct codec_api* api);
struct codec_header *hdr;
int status;
#ifndef SIMULATOR
int copy_n;
@ -272,21 +241,39 @@ int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
memcpy(&codecbuf[copy_n], ptr2, size);
}
}
codec_start = (void*)&codecbuf;
hdr = (struct codec_header *)codecbuf;
if (hdr->magic != CODEC_MAGIC
|| hdr->target_id != TARGET_ID
|| hdr->load_addr != codecbuf
|| hdr->end_addr > codecbuf + CODEC_SIZE) {
return CODEC_ERROR;
}
#else /* SIMULATOR */
int pd;
codec_start = sim_codec_load_ram(codecptr, size, ptr2, bufwrap, &pd);
hdr = sim_codec_load_ram(codecptr, size, ptr2, bufwrap, &pd);
if (pd < 0)
return CODEC_ERROR;
if (hdr == NULL
|| hdr->magic != CODEC_MAGIC
|| hdr->target_id != TARGET_ID
|| hdr->entry_point == NULL) {
sim_codec_close(pd);
return CODEC_ERROR;
}
#endif /* SIMULATOR */
if (hdr->api_version > CODEC_API_VERSION
|| hdr->api_version < CODEC_MIN_API_VERSION) {
sim_codec_close(pd);
return CODEC_ERROR;
}
invalidate_icache();
status = codec_start(api);
#ifdef SIMULATOR
status = hdr->entry_point(api);
sim_codec_close(pd);
#endif
return status;
}
@ -317,21 +304,3 @@ int codec_load_file(const char *plugin, struct codec_api *api)
return codec_load_ram(codecbuf, (size_t)rc, NULL, 0, api);
}
static int codec_test(int api_version, int model, int memsize)
{
if (api_version < CODEC_MIN_API_VERSION ||
api_version > CODEC_API_VERSION)
return CODEC_WRONG_API_VERSION;
(void)model;
#if 0
if (model != MODEL)
return CODEC_WRONG_MODEL;
#endif
if (memsize != MEM)
return CODEC_WRONG_MODEL;
return CODEC_OK;
}

View file

@ -80,32 +80,23 @@
#define PREFIX(_x_) _x_
#endif
#define CODEC_MAGIC 0x52434F44 /* RCOD */
/* increase this every time the api struct changes */
#define CODEC_API_VERSION 44
#define CODEC_API_VERSION 1
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */
#define CODEC_MIN_API_VERSION 44
#define CODEC_MIN_API_VERSION 1
/* codec return codes */
enum codec_status {
CODEC_OK = 0,
CODEC_USB_CONNECTED,
CODEC_WRONG_API_VERSION = -1,
CODEC_WRONG_MODEL = -2,
CODEC_ERROR = -3,
CODEC_ERROR = -1,
};
/* compatibility test macro */
#define TEST_CODEC_API(_api_) \
do { \
int _rc_ = _api_->codec_test(CODEC_API_VERSION, 1, MEM); \
if (_rc_<0) \
return _rc_; \
} while(0)
/* NOTE: To support backwards compatibility, only add new functions at
the end of the structure. Every time you add a new function,
remember to increase CODEC_API_VERSION. If you make changes to the
@ -113,10 +104,6 @@ do { \
version
*/
struct codec_api {
/* these two fields must always be first, to ensure
TEST_CODEC_API will always work */
int version;
int (*codec_test)(int api_version, int model, int memsize);
off_t filesize; /* Total file length */
off_t curpos; /* Current buffer position */
@ -158,6 +145,8 @@ struct codec_api {
void (*advance_buffer_loc)(void *ptr);
/* Seek file buffer to position <newpos> beginning of file. */
bool (*seek_buffer)(off_t newpos);
/* Codec should call this function when it has done the seeking. */
void (*seek_complete)(void);
/* Calculate mp3 seek position from given time data in ms. */
off_t (*mp3_get_filepos)(int newtime);
/* Request file change from file buffer. Returns true is next
@ -165,6 +154,7 @@ struct codec_api {
codec should exit immediately with PLUGIN_OK status. */
bool (*request_next_track)(void);
void (*set_offset)(unsigned int value);
/* Configure different codec buffer parameters. */
void (*configure)(int setting, void *value);
@ -228,6 +218,7 @@ struct codec_api {
char *(*strcat)(char *s1, const char *s2);
int (*memcmp)(const void *s1, const void *s2, size_t n);
char *(*strcasestr) (const char* phaystack, const char* pneedle);
void *(*memchr)(const void *s1, int c, size_t n);
/* sound */
void (*sound_set)(int setting, int value);
@ -236,9 +227,6 @@ struct codec_api {
void (*mp3_play_pause)(bool play);
void (*mp3_play_stop)(void);
bool (*mp3_is_playing)(void);
#if CONFIG_CODEC != SWCODEC
void (*bitswap)(unsigned char *data, int length);
#endif
#if CONFIG_CODEC == SWCODEC
void (*pcm_play_data)(void (*get_more)(unsigned char** start, long*size));
void (*pcm_play_stop)(void);
@ -263,24 +251,6 @@ struct codec_api {
struct mp3entry* (*audio_current_track)(void);
void (*audio_flush_and_reload_tracks)(void);
int (*audio_get_file_pos)(void);
#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
unsigned long (*mpeg_get_last_header)(void);
#endif
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
void (*sound_set_pitch)(int pitch);
#endif
/* MAS communication */
#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
int (*mas_readmem)(int bank, int addr, unsigned long* dest, int len);
int (*mas_writemem)(int bank, int addr, const unsigned long* src, int len);
int (*mas_readreg)(int reg);
int (*mas_writereg)(int reg, unsigned int val);
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
int (*mas_codec_writereg)(int reg, unsigned int val);
int (*mas_codec_readreg)(int reg);
#endif
#endif
/* tag database */
struct tagdb_header *tagdbheader;
@ -300,6 +270,9 @@ struct codec_api {
#if defined(DEBUG) || defined(SIMULATOR)
void (*debugf)(const char *fmt, ...);
#endif
#ifdef ROCKBOX_HAS_LOGF
void (*logf)(const char *fmt, ...);
#endif
struct user_settings* global_settings;
bool (*mp3info)(struct mp3entry *entry, const char *filename, bool v1first);
@ -313,35 +286,45 @@ struct codec_api {
long max_offset, unsigned long last_header);
int (*battery_level)(void);
bool (*battery_level_safe)(void);
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
unsigned short (*peak_meter_scale_value)(unsigned short val,
int meterwidth);
void (*peak_meter_set_use_dbfs)(bool use);
bool (*peak_meter_get_use_dbfs)(void);
#endif
/* new stuff at the end, sort into place next time
the API gets incompatible */
#ifdef ROCKBOX_HAS_LOGF
void (*logf)(const char *fmt, ...);
#endif
void *(*memchr)(const void *s1, int c, size_t n);
void (*set_offset)(unsigned int value);
/* Codec should call this function when it has done the seeking. */
void (*seek_complete)(void);
};
/* codec header */
struct codec_header {
unsigned long magic;
unsigned short target_id;
unsigned short api_version;
unsigned char *load_addr;
unsigned char *end_addr;
enum codec_status(*entry_point)(struct codec_api*);
};
#ifdef CODEC
#ifndef SIMULATOR
/* plugin_* is correct, codecs use the plugin linker script */
extern unsigned char plugin_start_addr[];
extern unsigned char plugin_end_addr[];
#define CODEC_HEADER \
const struct codec_header __header \
__attribute__ ((section (".header")))= { \
CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
plugin_start_addr, plugin_end_addr, codec_start };
#else /* SIMULATOR */
#define CODEC_HEADER \
const struct codec_header __header = { \
CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
NULL, NULL, codec_start };
#endif
#endif
/* defined by the codec loader (codec.c) */
#if CONFIG_CODEC == SWCODEC
int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
struct codec_api *api);
int codec_load_file(const char* codec, struct codec_api *api);
#endif
/* defined by the codec */
enum codec_status codec_start(struct codec_api* rockbox)
__attribute__ ((section (".entry")));
enum codec_status codec_start(struct codec_api* rockbox);
#endif

View file

@ -10,7 +10,7 @@
INCLUDES = -I$(FIRMDIR)/include -I$(FIRMDIR)/export -I$(FIRMDIR)/common \
-I$(FIRMDIR)/drivers -I$(APPSDIR) -Ilib -I$(BUILDDIR)
CFLAGS = $(GCCOPTS) $(INCLUDES) $(TARGET) $(EXTRA_DEFINES) \
-DMEM=${MEMORYSIZE} -DCODEC
-DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DCODEC
ifdef APPEXTRA
INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA)))

View file

@ -22,6 +22,8 @@
#include <codecs/liba52/config-a52.h>
#include <codecs/liba52/a52.h>
CODEC_HEADER
#define BUFFER_SIZE 4096
#define A52_SAMPLESPERFRAME (6*256)
@ -129,7 +131,6 @@ enum codec_status codec_start(struct codec_api *api)
int sample_loc;
/* Generic codec initialisation */
TEST_CODEC_API(api);
ci = api;
#ifdef USE_IRAM

View file

@ -23,6 +23,8 @@
#include "libfaad/structs.h"
#include "libfaad/decoder.h"
CODEC_HEADER
#ifndef SIMULATOR
extern char iramcopy[];
extern char iramstart[];
@ -51,10 +53,8 @@ enum codec_status codec_start(struct codec_api* api)
int16_t* decodedbuffer;
/* Generic codec initialisation */
TEST_CODEC_API(api);
rb = api;
ci = (struct codec_api*)api;
ci = api;
#ifndef SIMULATOR
rb->memcpy(iramstart, iramcopy, iramend-iramstart);

View file

@ -21,6 +21,8 @@
#include "libm4a/m4a.h"
#include "libalac/decomp.h"
CODEC_HEADER
#ifdef USE_IRAM
extern char iramcopy[];
extern char iramstart[];
@ -50,10 +52,8 @@ enum codec_status codec_start(struct codec_api* api)
alac_file alac;
/* Generic codec initialisation */
TEST_CODEC_API(api);
rb = api;
ci = (struct codec_api*)api;
ci = api;
#ifdef USE_IRAM
rb->memcpy(iramstart, iramcopy, iramend-iramstart);

View file

@ -20,6 +20,8 @@
#include "codeclib.h"
#include <codecs/libffmpegFLAC/decoder.h>
CODEC_HEADER
#ifdef USE_IRAM
extern char iramcopy[];
extern char iramstart[];
@ -226,10 +228,8 @@ enum codec_status codec_start(struct codec_api* api)
int frame;
/* Generic codec initialisation */
TEST_CODEC_API(api);
rb = api;
ci = (struct codec_api*)api;
ci = api;
#ifdef USE_IRAM
ci->memcpy(iramstart, iramcopy, iramend-iramstart);

View file

@ -21,6 +21,8 @@
#include <codecs/libmad/mad.h>
#include <inttypes.h>
CODEC_HEADER
struct mad_stream stream IBSS_ATTR;
struct mad_frame frame IBSS_ATTR;
struct mad_synth synth IBSS_ATTR;
@ -81,7 +83,6 @@ enum codec_status codec_start(struct codec_api *api)
char *inputbuffer;
ci = api;
TEST_CODEC_API(api);
#ifdef USE_IRAM
ci->memcpy(iramstart, iramcopy, iramend - iramstart);

View file

@ -20,6 +20,8 @@
#include "codeclib.h"
#include <codecs/libmusepack/musepack.h>
CODEC_HEADER
mpc_decoder decoder;
/* Our implementations of the mpc_reader callback functions. */
@ -82,7 +84,6 @@ enum codec_status codec_start(struct codec_api *api)
mpc_reader reader;
mpc_streaminfo info;
TEST_CODEC_API(api);
#ifdef USE_IRAM
ci->memcpy(iramstart, iramcopy, iramend - iramstart);
ci->memset(iedata, 0, iend - iedata);

View file

@ -20,6 +20,8 @@
#include "codeclib.h"
#include <codecs/libffmpegFLAC/shndec.h>
CODEC_HEADER
#ifdef USE_IRAM
extern char iramcopy[];
extern char iramstart[];
@ -50,9 +52,8 @@ enum codec_status codec_start(struct codec_api* api)
long bytesleft;
/* Generic codec initialisation */
TEST_CODEC_API(api);
rb = api;
ci = (struct codec_api*)api;
ci = api;
#ifdef USE_IRAM
ci->memcpy(iramstart, iramcopy, iramend-iramstart);

View file

@ -21,6 +21,8 @@
#include "Tremor/ivorbisfile.h"
#include "Tremor/ogg.h"
CODEC_HEADER
static struct codec_api *rb;
/* Some standard functions and variables needed by Tremor */
@ -122,7 +124,6 @@ enum codec_status codec_start(struct codec_api *api)
ogg_uint32_t vf_serialnos;
ogg_int64_t vf_pcmlengths[2];
TEST_CODEC_API(api);
rb = api;
#ifdef USE_IRAM

View file

@ -20,6 +20,8 @@
#include "codeclib.h"
#include "inttypes.h"
CODEC_HEADER
struct codec_api* rb;
/* This codec support WAVE files with the following formats:
@ -230,8 +232,6 @@ enum codec_status codec_start(struct codec_api* api)
int32_t * const int32_samples = (int32_t*)int16_samples;
/* Generic codec initialisation */
TEST_CODEC_API(api);
rb = api;
ci = api;

View file

@ -20,6 +20,8 @@
#include "codeclib.h"
#include "libwavpack/wavpack.h"
CODEC_HEADER
static struct codec_api *ci;
#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)
int bps, nchans, sr_100;
/* Generic codec initialisation */
TEST_CODEC_API(api);
ci = api;
#ifdef USE_IRAM

View file

@ -28,7 +28,7 @@
#define CODEC_SIZE 0x40000
/* The number of bytes reserved for loadable plugins */
#define PLUGIN_BUFFER_SIZE 0xC0000
#define PLUGIN_BUFFER_SIZE 0x80000
#ifndef SIMULATOR

View file

@ -19,7 +19,7 @@
#define CODEC_SIZE 0x40000
/* The number of bytes reserved for loadable plugins */
#define PLUGIN_BUFFER_SIZE 0xC0000
#define PLUGIN_BUFFER_SIZE 0x80000
#ifndef SIMULATOR

View file

@ -45,7 +45,7 @@
#define CODEC_SIZE 0x80000
/* The number of bytes reserved for loadable plugins */
#define PLUGIN_BUFFER_SIZE 0xC0000
#define PLUGIN_BUFFER_SIZE 0x80000
#define CONFIG_TUNER TEA5767
#define CONFIG_TUNER_XTAL 32768

View file

@ -41,7 +41,7 @@
#define CODEC_SIZE 0x80000
/* The number of bytes reserved for loadable plugins */
#define PLUGIN_BUFFER_SIZE 0xC0000
#define PLUGIN_BUFFER_SIZE 0x80000
#define CONFIG_TUNER TEA5767
#define CONFIG_TUNER_XTAL 32768

View file

@ -46,7 +46,7 @@
#define CODEC_SIZE 0x80000
/* The number of bytes reserved for loadable plugins */
#define PLUGIN_BUFFER_SIZE 0xC0000
#define PLUGIN_BUFFER_SIZE 0x80000
#define CONFIG_TUNER TEA5767
#define CONFIG_TUNER_XTAL 32768

View file

@ -38,7 +38,7 @@
#define CODEC_SIZE 0x40000
/* The number of bytes reserved for loadable plugins */
#define PLUGIN_BUFFER_SIZE 0xC0000
#define PLUGIN_BUFFER_SIZE 0x80000
#ifndef SIMULATOR

View file

@ -38,7 +38,7 @@
#define CODEC_SIZE 0x80000
/* The number of bytes reserved for loadable plugins */
#define PLUGIN_BUFFER_SIZE 0xC0000
#define PLUGIN_BUFFER_SIZE 0x80000
/* Define this if you have the WM8975 audio codec */
#define HAVE_WM8975

View file

@ -38,7 +38,7 @@
#define CODEC_SIZE 0x80000
/* The number of bytes reserved for loadable plugins */
#define PLUGIN_BUFFER_SIZE 0xC0000
#define PLUGIN_BUFFER_SIZE 0x80000
/* Define this if you have the WM8975 audio codec */
#define HAVE_WM8975

View file

@ -38,7 +38,7 @@
#define CODEC_SIZE 0x80000
/* The number of bytes reserved for loadable plugins */
#define PLUGIN_BUFFER_SIZE 0xC0000
#define PLUGIN_BUFFER_SIZE 0x80000
/* Define this if you have the WM8975 audio codec */
#define HAVE_WM8975

View file

@ -306,20 +306,20 @@ int sim_fsync(int fd)
void *sim_codec_load_ram(char* codecptr, int size,
void* ptr2, int bufwrap, int *pd_fd)
{
void *pd;
char *path = "archos/_temp_codec.dll";
int (*codec_start)(void * api);
void *pd, *hdr;
const char *path = "archos/_temp_codec.dll";
int fd;
int copy_n;
#ifdef WIN32
char buf[256];
#endif
*pd_fd = 0;
/* We have to create the dynamic link library file from ram
* so we could simulate the codec loading.
*/
*pd_fd = -1;
fd = open(path, O_WRONLY | O_CREAT, S_IRWXU);
so we could simulate the codec loading. */
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
if (fd < 0) {
DEBUGF("failed to open for write: %s\n", path);
return NULL;
@ -357,17 +357,12 @@ void *sim_codec_load_ram(char* codecptr, int size,
return NULL;
}
codec_start = dlsym(pd, "codec_start");
if (!codec_start) {
codec_start = dlsym(pd, "_codec_start");
if (!codec_start) {
dlclose(pd);
return NULL;
}
}
hdr = dlsym(pd, "__header");
if (!hdr)
hdr = dlsym(pd, "___header");
*pd_fd = (int)pd;
return codec_start;
return hdr; /* maybe NULL if symbol not present */
}
void sim_codec_close(int pd)