1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 /* instruct simulator code to not redefine any symbols when compiling codecs.
23 (the CODEC macro is defined in apps/codecs/Makefile) */
25 #define NO_REDEFINES_PLEASE
43 #if (CONFIG_CODEC == SWCODEC)
44 #if !defined(SIMULATOR) && defined(HAVE_RECORDING)
45 #include "pcm_record.h"
52 #if defined(DEBUG) || defined(SIMULATOR)
54 #define DEBUGF ci->debugf
56 #define LDEBUGF ci->debugf
62 #ifdef ROCKBOX_HAS_LOGF
72 #define PREFIX(_x_) sim_ ## _x_
74 #define PREFIX(_x_) _x_
77 /* magic for normal codecs */
78 #define CODEC_MAGIC 0x52434F44 /* RCOD */
79 /* magic for encoder codecs */
80 #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
82 /* increase this every time the api struct changes */
83 #define CODEC_API_VERSION 23
85 /* update this to latest version if a change to the api struct breaks
86 backwards compatibility (and please take the opportunity to sort in any
87 new function which are "waiting" at the end of the function table) */
88 #define CODEC_MIN_API_VERSION 23
90 /* codec return codes */
97 /* NOTE: To support backwards compatibility, only add new functions at
98 the end of the structure. Every time you add a new function,
99 remember to increase CODEC_API_VERSION. If you make changes to the
100 existing APIs then also update CODEC_MIN_API_VERSION to current
105 off_t filesize
; /* Total file length */
106 off_t curpos
; /* Current buffer position */
108 /* For gapless mp3 */
109 struct mp3entry
*id3
; /* TAG metadata pointer */
110 bool *taginfo_ready
; /* Is metadata read */
112 /* Codec should periodically check if stop_codec is set to true.
113 In case it is, codec must return immediately */
115 /* Codec should periodically check if new_track is non zero.
116 When it is, the codec should request a new track. */
118 /* If seek_time != 0, codec should seek to that song position (in ms)
119 if codec supports seeking. */
122 /* The dsp instance to be used for audio output */
123 struct dsp_config
*dsp
;
125 /* Returns buffer to malloc array. Only codeclib should need this. */
126 void* (*get_codec_memory
)(size_t *size
);
127 /* Insert PCM data into audio buffer for playback. Playback will start
129 bool (*pcmbuf_insert
)(const void *ch1
, const void *ch2
, int count
);
130 /* Set song position in WPS (value in ms). */
131 void (*set_elapsed
)(unsigned int value
);
133 /* Read next <size> amount bytes from file buffer to <ptr>.
134 Will return number of bytes read or 0 if end of file. */
135 size_t (*read_filebuf
)(void *ptr
, size_t size
);
136 /* Request pointer to file buffer which can be used to read
137 <realsize> amount of data. <reqsize> tells the buffer system
138 how much data it should try to allocate. If <realsize> is 0,
139 end of file is reached. */
140 void* (*request_buffer
)(size_t *realsize
, size_t reqsize
);
141 /* Advance file buffer position by <amount> amount of bytes. */
142 void (*advance_buffer
)(size_t amount
);
143 /* Advance file buffer to a pointer location inside file buffer. */
144 void (*advance_buffer_loc
)(void *ptr
);
145 /* Seek file buffer to position <newpos> beginning of file. */
146 bool (*seek_buffer
)(size_t newpos
);
147 /* Codec should call this function when it has done the seeking. */
148 void (*seek_complete
)(void);
149 /* Calculate mp3 seek position from given time data in ms. */
150 off_t (*mp3_get_filepos
)(int newtime
);
151 /* Request file change from file buffer. Returns true is next
152 track is available and changed. If return value is false,
153 codec should exit immediately with PLUGIN_OK status. */
154 bool (*request_next_track
)(void);
155 /* Free the buffer area of the current codec after its loaded */
156 void (*discard_codec
)(void);
158 void (*set_offset
)(size_t value
);
159 /* Configure different codec buffer parameters. */
160 void (*configure
)(int setting
, intptr_t value
);
163 void (*PREFIX(sleep
))(int ticks
);
167 struct thread_entry
*
168 (*create_thread
)(void (*function
)(void), void* stack
,
169 size_t stack_size
, unsigned flags
, const char *name
170 IF_PRIO(, int priority
)
171 IF_COP(, unsigned int core
));
173 void (*thread_thaw
)(struct thread_entry
*thread
);
174 void (*thread_wait
)(struct thread_entry
*thread
);
175 void (*semaphore_init
)(struct semaphore
*s
, int max
, int start
);
176 void (*semaphore_wait
)(struct semaphore
*s
);
177 void (*semaphore_release
)(struct semaphore
*s
);
178 void (*event_init
)(struct event
*e
, unsigned int flags
);
179 void (*event_wait
)(struct event
*e
, unsigned int for_state
);
180 void (*event_set_state
)(struct event
*e
, unsigned int state
);
181 #endif /* NUM_CORES */
183 #ifdef CACHE_FUNCTIONS_AS_CALL
184 void (*flush_icache
)(void);
185 void (*invalidate_icache
)(void);
188 /* strings and memory */
189 char* (*strcpy
)(char *dst
, const char *src
);
190 char* (*strncpy
)(char *dst
, const char *src
, size_t length
);
191 size_t (*strlen
)(const char *str
);
192 int (*strcmp
)(const char *, const char *);
193 char *(*strcat
)(char *s1
, const char *s2
);
194 void* (*memset
)(void *dst
, int c
, size_t length
);
195 void* (*memcpy
)(void *out
, const void *in
, size_t n
);
196 void* (*memmove
)(void *out
, const void *in
, size_t n
);
197 int (*memcmp
)(const void *s1
, const void *s2
, size_t n
);
198 void *(*memchr
)(const void *s1
, int c
, size_t n
);
200 #if defined(DEBUG) || defined(SIMULATOR)
201 void (*debugf
)(const char *fmt
, ...) ATTRIBUTE_PRINTF(1, 2);
203 #ifdef ROCKBOX_HAS_LOGF
204 void (*logf
)(const char *fmt
, ...) ATTRIBUTE_PRINTF(1, 2);
207 /* Tremor requires qsort */
208 void (*qsort
)(void *base
, size_t nmemb
, size_t size
,
209 int(*compar
)(const void *, const void *));
211 /* The ADX codec accesses global_settings to test for REPEAT_ONE mode */
212 struct user_settings
* global_settings
;
215 void (*profile_thread
)(void);
216 void (*profstop
)(void);
217 void (*profile_func_enter
)(void *this_fn
, void *call_site
);
218 void (*profile_func_exit
)(void *this_fn
, void *call_site
);
221 #if defined(HAVE_RECORDING) && !defined(SIMULATOR)
222 volatile bool stop_encoder
;
223 volatile int enc_codec_loaded
; /* <0=error, 0=pending, >0=ok */
224 void (*enc_get_inputs
)(struct enc_inputs
*inputs
);
225 void (*enc_set_parameters
)(struct enc_parameters
*params
);
226 struct enc_chunk_hdr
* (*enc_get_chunk
)(void);
227 void (*enc_finish_chunk
)(void);
228 unsigned char * (*enc_get_pcm_data
)(size_t size
);
229 size_t (*enc_unget_pcm_data
)(size_t size
);
232 int (*PREFIX(open
))(const char* pathname
, int flags
);
233 int (*close
)(int fd
);
234 ssize_t (*read
)(int fd
, void* buf
, size_t count
);
235 off_t (*PREFIX(lseek
))(int fd
, off_t offset
, int whence
);
236 ssize_t (*write
)(int fd
, const void* buf
, size_t count
);
237 int (*round_value_to_list32
)(unsigned long value
,
238 const unsigned long list
[],
243 /* new stuff at the end, sort into place next time
244 the API gets incompatible */
249 struct codec_header
{
250 unsigned long magic
; /* RCOD or RENC */
251 unsigned short target_id
;
252 unsigned short api_version
;
253 unsigned char *load_addr
;
254 unsigned char *end_addr
;
255 enum codec_status(*entry_point
)(struct codec_api
*);
260 /* plugin_* is correct, codecs use the plugin linker script */
261 extern unsigned char plugin_start_addr
[];
262 extern unsigned char plugin_end_addr
[];
264 #define CODEC_HEADER \
265 const struct codec_header __header \
266 __attribute__ ((section (".header")))= { \
267 CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
268 plugin_start_addr, plugin_end_addr, codec_start };
270 #define CODEC_ENC_HEADER \
271 const struct codec_header __header \
272 __attribute__ ((section (".header")))= { \
273 CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
274 plugin_start_addr, plugin_end_addr, codec_start };
276 #else /* def SIMULATOR */
278 #define CODEC_HEADER \
279 const struct codec_header __header \
280 __attribute__((visibility("default"))) = { \
281 CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
282 NULL, NULL, codec_start };
284 #define CODEC_ENC_HEADER \
285 const struct codec_header __header = { \
286 CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
287 NULL, NULL, codec_start };
288 #endif /* SIMULATOR */
291 /* create full codec path from root filenames in audio_formats[]
292 assumes buffer size is MAX_PATH */
293 void codec_get_full_path(char *path
, const char *codec_root_fn
);
295 /* defined by the codec loader (codec.c) */
296 int codec_load_buf(unsigned int hid
, struct codec_api
*api
);
297 int codec_load_file(const char* codec
, struct codec_api
*api
);
299 /* defined by the codec */
300 enum codec_status
codec_start(struct codec_api
* rockbox
);
302 #ifndef CACHE_FUNCTION_WRAPPERS
304 #ifdef CACHE_FUNCTIONS_AS_CALL
305 #define CACHE_FUNCTION_WRAPPERS(api) \
306 void flush_icache(void) \
308 (api)->flush_icache(); \
310 void invalidate_icache(void) \
312 (api)->invalidate_icache(); \
315 #define CACHE_FUNCTION_WRAPPERS(api)
316 #endif /* CACHE_FUNCTIONS_AS_CALL */
318 #endif /* CACHE_FUNCTION_WRAPPERS */