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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef _CODECS_H_
|
|
|
|
#define _CODECS_H_
|
|
|
|
|
|
|
|
/* instruct simulator code to not redefine any symbols when compiling codecs.
|
|
|
|
(the CODEC macro is defined in apps/codecs/Makefile) */
|
|
|
|
#ifdef CODEC
|
|
|
|
#define NO_REDEFINES_PLEASE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MEM
|
|
|
|
#define MEM 2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "id3.h"
|
|
|
|
#include "audio.h"
|
2006-01-18 20:54:13 +00:00
|
|
|
#ifdef RB_PROFILE
|
|
|
|
#include "profile.h"
|
2007-05-07 13:32:56 +00:00
|
|
|
#include "thread.h"
|
2006-01-18 20:54:13 +00:00
|
|
|
#endif
|
2005-10-10 15:54:36 +00:00
|
|
|
#if (CONFIG_CODEC == SWCODEC)
|
2006-11-06 18:07:30 +00:00
|
|
|
#if !defined(SIMULATOR) && defined(HAVE_RECORDING)
|
2006-08-28 22:38:41 +00:00
|
|
|
#include "pcm_record.h"
|
|
|
|
#endif
|
2005-10-10 15:54:36 +00:00
|
|
|
#include "dsp.h"
|
2005-06-22 19:41:30 +00:00
|
|
|
#endif
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
#ifdef CODEC
|
|
|
|
#if defined(DEBUG) || defined(SIMULATOR)
|
|
|
|
#undef DEBUGF
|
2006-11-26 18:31:41 +00:00
|
|
|
#define DEBUGF ci->debugf
|
2005-06-22 19:41:30 +00:00
|
|
|
#undef LDEBUGF
|
2006-11-26 18:31:41 +00:00
|
|
|
#define LDEBUGF ci->debugf
|
2005-06-22 19:41:30 +00:00
|
|
|
#else
|
|
|
|
#define DEBUGF(...)
|
|
|
|
#define LDEBUGF(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ROCKBOX_HAS_LOGF
|
|
|
|
#undef LOGF
|
2006-11-26 18:31:41 +00:00
|
|
|
#define LOGF ci->logf
|
2005-06-22 19:41:30 +00:00
|
|
|
#else
|
|
|
|
#define LOGF(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
#define PREFIX(_x_) sim_ ## _x_
|
|
|
|
#else
|
|
|
|
#define PREFIX(_x_) _x_
|
|
|
|
#endif
|
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
/* magic for normal codecs */
|
2006-01-18 00:05:14 +00:00
|
|
|
#define CODEC_MAGIC 0x52434F44 /* RCOD */
|
2006-11-06 18:07:30 +00:00
|
|
|
/* magic for encoder codecs */
|
|
|
|
#define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
|
2006-01-18 00:05:14 +00:00
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
/* increase this every time the api struct changes */
|
2008-08-16 09:35:35 +00:00
|
|
|
#define CODEC_API_VERSION 25
|
2005-06-22 19:41:30 +00:00
|
|
|
|
|
|
|
/* update this to latest version if a change to the api struct breaks
|
2005-08-29 20:07:17 +00:00
|
|
|
backwards compatibility (and please take the opportunity to sort in any
|
2005-06-22 19:41:30 +00:00
|
|
|
new function which are "waiting" at the end of the function table) */
|
2008-08-16 09:35:35 +00:00
|
|
|
#define CODEC_MIN_API_VERSION 25
|
2005-06-22 19:41:30 +00:00
|
|
|
|
|
|
|
/* codec return codes */
|
|
|
|
enum codec_status {
|
|
|
|
CODEC_OK = 0,
|
|
|
|
CODEC_USB_CONNECTED,
|
2006-01-18 00:05:14 +00:00
|
|
|
CODEC_ERROR = -1,
|
2005-06-22 19:41:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
existing APIs then also update CODEC_MIN_API_VERSION to current
|
|
|
|
version
|
|
|
|
*/
|
|
|
|
struct codec_api {
|
|
|
|
|
|
|
|
off_t filesize; /* Total file length */
|
|
|
|
off_t curpos; /* Current buffer position */
|
|
|
|
|
|
|
|
/* For gapless mp3 */
|
|
|
|
struct mp3entry *id3; /* TAG metadata pointer */
|
|
|
|
bool *taginfo_ready; /* Is metadata read */
|
|
|
|
|
|
|
|
/* Codec should periodically check if stop_codec is set to true.
|
2006-04-15 02:03:11 +00:00
|
|
|
In case it is, codec must return immediately */
|
2005-06-22 19:41:30 +00:00
|
|
|
bool stop_codec;
|
2006-04-15 02:03:11 +00:00
|
|
|
/* Codec should periodically check if new_track is non zero.
|
|
|
|
When it is, the codec should request a new track. */
|
|
|
|
int new_track;
|
2005-06-22 19:41:30 +00:00
|
|
|
/* If seek_time != 0, codec should seek to that song position (in ms)
|
|
|
|
if codec supports seeking. */
|
2006-03-03 02:09:58 +00:00
|
|
|
long seek_time;
|
2008-03-25 02:34:12 +00:00
|
|
|
|
|
|
|
/* The dsp instance to be used for audio output */
|
|
|
|
struct dsp_config *dsp;
|
2005-06-22 19:41:30 +00:00
|
|
|
|
|
|
|
/* Returns buffer to malloc array. Only codeclib should need this. */
|
2006-03-24 13:43:15 +00:00
|
|
|
void* (*get_codec_memory)(size_t *size);
|
2005-06-22 19:41:30 +00:00
|
|
|
/* Insert PCM data into audio buffer for playback. Playback will start
|
|
|
|
automatically. */
|
2008-03-28 12:51:33 +00:00
|
|
|
bool (*pcmbuf_insert)(const void *ch1, const void *ch2, int count);
|
2005-06-22 19:41:30 +00:00
|
|
|
/* Set song position in WPS (value in ms). */
|
2008-03-28 12:51:33 +00:00
|
|
|
void (*set_elapsed)(unsigned int value);
|
2005-06-22 19:41:30 +00:00
|
|
|
|
|
|
|
/* Read next <size> amount bytes from file buffer to <ptr>.
|
|
|
|
Will return number of bytes read or 0 if end of file. */
|
2008-03-28 12:51:33 +00:00
|
|
|
size_t (*read_filebuf)(void *ptr, size_t size);
|
2005-06-22 19:41:30 +00:00
|
|
|
/* Request pointer to file buffer which can be used to read
|
|
|
|
<realsize> amount of data. <reqsize> tells the buffer system
|
|
|
|
how much data it should try to allocate. If <realsize> is 0,
|
|
|
|
end of file is reached. */
|
2008-03-28 12:51:33 +00:00
|
|
|
void* (*request_buffer)(size_t *realsize, size_t reqsize);
|
2005-06-22 19:41:30 +00:00
|
|
|
/* Advance file buffer position by <amount> amount of bytes. */
|
2008-03-28 12:51:33 +00:00
|
|
|
void (*advance_buffer)(size_t amount);
|
2005-06-22 19:41:30 +00:00
|
|
|
/* Advance file buffer to a pointer location inside file buffer. */
|
|
|
|
void (*advance_buffer_loc)(void *ptr);
|
|
|
|
/* Seek file buffer to position <newpos> beginning of file. */
|
2008-03-28 12:51:33 +00:00
|
|
|
bool (*seek_buffer)(size_t newpos);
|
2006-01-18 00:05:14 +00:00
|
|
|
/* Codec should call this function when it has done the seeking. */
|
|
|
|
void (*seek_complete)(void);
|
2005-06-22 19:41:30 +00:00
|
|
|
/* Request file change from file buffer. Returns true is next
|
|
|
|
track is available and changed. If return value is false,
|
|
|
|
codec should exit immediately with PLUGIN_OK status. */
|
|
|
|
bool (*request_next_track)(void);
|
2006-04-15 02:03:11 +00:00
|
|
|
/* Free the buffer area of the current codec after its loaded */
|
|
|
|
void (*discard_codec)(void);
|
2005-06-22 19:41:30 +00:00
|
|
|
|
2008-03-28 12:51:33 +00:00
|
|
|
void (*set_offset)(size_t value);
|
2005-06-22 19:41:30 +00:00
|
|
|
/* Configure different codec buffer parameters. */
|
2008-03-28 12:51:33 +00:00
|
|
|
void (*configure)(int setting, intptr_t value);
|
2005-06-22 19:41:30 +00:00
|
|
|
|
|
|
|
/* kernel/ system */
|
2008-03-28 12:51:33 +00:00
|
|
|
void (*PREFIX(sleep))(int ticks);
|
2005-06-22 19:41:30 +00:00
|
|
|
void (*yield)(void);
|
|
|
|
|
2008-03-25 02:34:12 +00:00
|
|
|
#if NUM_CORES > 1
|
|
|
|
struct thread_entry *
|
|
|
|
(*create_thread)(void (*function)(void), void* stack,
|
|
|
|
size_t stack_size, unsigned flags, const char *name
|
|
|
|
IF_PRIO(, int priority)
|
|
|
|
IF_COP(, unsigned int core));
|
|
|
|
|
|
|
|
void (*thread_thaw)(struct thread_entry *thread);
|
|
|
|
void (*thread_wait)(struct thread_entry *thread);
|
|
|
|
void (*semaphore_init)(struct semaphore *s, int max, int start);
|
|
|
|
void (*semaphore_wait)(struct semaphore *s);
|
|
|
|
void (*semaphore_release)(struct semaphore *s);
|
|
|
|
void (*event_init)(struct event *e, unsigned int flags);
|
|
|
|
void (*event_wait)(struct event *e, unsigned int for_state);
|
|
|
|
void (*event_set_state)(struct event *e, unsigned int state);
|
|
|
|
#endif /* NUM_CORES */
|
|
|
|
|
|
|
|
#ifdef CACHE_FUNCTIONS_AS_CALL
|
|
|
|
void (*flush_icache)(void);
|
|
|
|
void (*invalidate_icache)(void);
|
|
|
|
#endif
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
/* strings and memory */
|
|
|
|
char* (*strcpy)(char *dst, const char *src);
|
|
|
|
char* (*strncpy)(char *dst, const char *src, size_t length);
|
|
|
|
size_t (*strlen)(const char *str);
|
|
|
|
int (*strcmp)(const char *, const char *);
|
2007-05-07 11:09:45 +00:00
|
|
|
char *(*strcat)(char *s1, const char *s2);
|
2005-06-22 19:41:30 +00:00
|
|
|
void* (*memset)(void *dst, int c, size_t length);
|
|
|
|
void* (*memcpy)(void *out, const void *in, size_t n);
|
2006-03-24 13:43:15 +00:00
|
|
|
void* (*memmove)(void *out, const void *in, size_t n);
|
2005-06-22 19:41:30 +00:00
|
|
|
int (*memcmp)(const void *s1, const void *s2, size_t n);
|
2006-01-18 00:05:14 +00:00
|
|
|
void *(*memchr)(const void *s1, int c, size_t n);
|
2008-07-26 15:16:10 +00:00
|
|
|
char *(*strcasestr) (const char* phaystack, const char* pneedle);
|
2005-06-22 19:41:30 +00:00
|
|
|
|
|
|
|
#if defined(DEBUG) || defined(SIMULATOR)
|
2007-03-17 09:02:53 +00:00
|
|
|
void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
|
2006-01-18 00:05:14 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ROCKBOX_HAS_LOGF
|
2007-03-17 09:02:53 +00:00
|
|
|
void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
|
2005-06-22 19:41:30 +00:00
|
|
|
#endif
|
2007-05-07 11:09:45 +00:00
|
|
|
|
|
|
|
/* Tremor requires qsort */
|
|
|
|
void (*qsort)(void *base, size_t nmemb, size_t size,
|
|
|
|
int(*compar)(const void *, const void *));
|
|
|
|
|
|
|
|
/* The ADX codec accesses global_settings to test for REPEAT_ONE mode */
|
2005-06-22 19:41:30 +00:00
|
|
|
struct user_settings* global_settings;
|
|
|
|
|
2006-01-18 20:54:13 +00:00
|
|
|
#ifdef RB_PROFILE
|
|
|
|
void (*profile_thread)(void);
|
|
|
|
void (*profstop)(void);
|
|
|
|
void (*profile_func_enter)(void *this_fn, void *call_site);
|
|
|
|
void (*profile_func_exit)(void *this_fn, void *call_site);
|
|
|
|
#endif
|
2006-08-28 22:38:41 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
|
2007-03-04 04:16:53 +00:00
|
|
|
volatile bool stop_encoder;
|
2006-11-06 18:07:30 +00:00
|
|
|
volatile int enc_codec_loaded; /* <0=error, 0=pending, >0=ok */
|
|
|
|
void (*enc_get_inputs)(struct enc_inputs *inputs);
|
|
|
|
void (*enc_set_parameters)(struct enc_parameters *params);
|
|
|
|
struct enc_chunk_hdr * (*enc_get_chunk)(void);
|
|
|
|
void (*enc_finish_chunk)(void);
|
|
|
|
unsigned char * (*enc_get_pcm_data)(size_t size);
|
|
|
|
size_t (*enc_unget_pcm_data)(size_t size);
|
2007-05-07 11:09:45 +00:00
|
|
|
|
|
|
|
/* file */
|
|
|
|
int (*PREFIX(open))(const char* pathname, int flags);
|
|
|
|
int (*close)(int fd);
|
|
|
|
ssize_t (*read)(int fd, void* buf, size_t count);
|
|
|
|
off_t (*PREFIX(lseek))(int fd, off_t offset, int whence);
|
|
|
|
ssize_t (*write)(int fd, const void* buf, size_t count);
|
|
|
|
int (*round_value_to_list32)(unsigned long value,
|
|
|
|
const unsigned long list[],
|
|
|
|
int count,
|
|
|
|
bool signd);
|
2006-08-28 22:38:41 +00:00
|
|
|
#endif
|
2005-07-05 08:43:36 +00:00
|
|
|
|
2006-02-03 00:12:11 +00:00
|
|
|
/* new stuff at the end, sort into place next time
|
|
|
|
the API gets incompatible */
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
};
|
|
|
|
|
2006-01-18 00:05:14 +00:00
|
|
|
/* codec header */
|
|
|
|
struct codec_header {
|
2006-11-06 18:07:30 +00:00
|
|
|
unsigned long magic; /* RCOD or RENC */
|
2006-01-18 00:05:14 +00:00
|
|
|
unsigned short target_id;
|
|
|
|
unsigned short api_version;
|
|
|
|
unsigned char *load_addr;
|
|
|
|
unsigned char *end_addr;
|
|
|
|
enum codec_status(*entry_point)(struct codec_api*);
|
|
|
|
};
|
2006-11-06 18:07:30 +00:00
|
|
|
|
2006-01-18 00:05:14 +00:00
|
|
|
#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[];
|
2006-11-06 18:07:30 +00:00
|
|
|
/* decoders */
|
2006-01-18 00:05:14 +00:00
|
|
|
#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 };
|
2006-11-06 18:07:30 +00:00
|
|
|
/* encoders */
|
|
|
|
#define CODEC_ENC_HEADER \
|
|
|
|
const struct codec_header __header \
|
|
|
|
__attribute__ ((section (".header")))= { \
|
|
|
|
CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
|
|
|
|
plugin_start_addr, plugin_end_addr, codec_start };
|
|
|
|
|
|
|
|
#else /* def SIMULATOR */
|
|
|
|
/* decoders */
|
2006-01-18 00:05:14 +00:00
|
|
|
#define CODEC_HEADER \
|
2007-10-02 09:08:08 +00:00
|
|
|
const struct codec_header __header \
|
|
|
|
__attribute__((visibility("default"))) = { \
|
2006-01-18 00:05:14 +00:00
|
|
|
CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
|
|
|
|
NULL, NULL, codec_start };
|
2006-11-06 18:07:30 +00:00
|
|
|
/* encoders */
|
|
|
|
#define CODEC_ENC_HEADER \
|
|
|
|
const struct codec_header __header = { \
|
|
|
|
CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
|
|
|
|
NULL, NULL, codec_start };
|
|
|
|
#endif /* SIMULATOR */
|
|
|
|
#endif /* CODEC */
|
2006-01-18 00:05:14 +00:00
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
/* create full codec path from root filenames in audio_formats[]
|
2006-08-28 22:38:41 +00:00
|
|
|
assumes buffer size is MAX_PATH */
|
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
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
/* defined by the codec loader (codec.c) */
|
2007-11-03 17:55:29 +00:00
|
|
|
int codec_load_buf(unsigned int hid, struct codec_api *api);
|
2005-08-20 11:13:19 +00:00
|
|
|
int codec_load_file(const char* codec, struct codec_api *api);
|
2005-06-22 19:41:30 +00:00
|
|
|
|
|
|
|
/* defined by the codec */
|
2006-01-18 00:05:14 +00:00
|
|
|
enum codec_status codec_start(struct codec_api* rockbox);
|
2008-08-12 21:27:22 +00:00
|
|
|
enum codec_status codec_main(void);
|
2005-06-22 19:41:30 +00:00
|
|
|
|
2007-09-28 10:20:02 +00:00
|
|
|
#ifndef CACHE_FUNCTION_WRAPPERS
|
|
|
|
|
|
|
|
#ifdef CACHE_FUNCTIONS_AS_CALL
|
|
|
|
#define CACHE_FUNCTION_WRAPPERS(api) \
|
|
|
|
void flush_icache(void) \
|
|
|
|
{ \
|
|
|
|
(api)->flush_icache(); \
|
|
|
|
} \
|
|
|
|
void invalidate_icache(void) \
|
|
|
|
{ \
|
|
|
|
(api)->invalidate_icache(); \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define CACHE_FUNCTION_WRAPPERS(api)
|
|
|
|
#endif /* CACHE_FUNCTIONS_AS_CALL */
|
|
|
|
|
|
|
|
#endif /* CACHE_FUNCTION_WRAPPERS */
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
#endif
|