SA9200: Give LCD about an 8% speedup. Sync optional LCD settings to defaults in lcd_i...
[kugel-rb.git] / apps / codecs.h
blob1c0b9da6ba851d92b9f901c40f4c62a1e0986229
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef _CODECS_H_
22 #define _CODECS_H_
24 /* instruct simulator code to not redefine any symbols when compiling codecs.
25 (the CODEC macro is defined in apps/codecs/Makefile) */
26 #ifdef CODEC
27 #define NO_REDEFINES_PLEASE
28 #endif
30 #ifndef MEM
31 #define MEM 2
32 #endif
34 #include <stdbool.h>
35 #include <stdlib.h>
36 #include "strlcpy.h"
37 #include "config.h"
38 #include "system.h"
39 #include "metadata.h"
40 #include "audio.h"
41 #ifdef RB_PROFILE
42 #include "profile.h"
43 #include "thread.h"
44 #endif
45 #if (CONFIG_CODEC == SWCODEC)
46 #ifdef HAVE_RECORDING
47 #include "pcm_record.h"
48 #endif
49 #include "dsp.h"
50 #endif
51 #include "settings.h"
53 #include "gcc_extensions.h"
54 #include "load_code.h"
56 #ifdef CODEC
57 #if defined(DEBUG) || defined(SIMULATOR)
58 #undef DEBUGF
59 #define DEBUGF ci->debugf
60 #undef LDEBUGF
61 #define LDEBUGF ci->debugf
62 #else
63 #define DEBUGF(...)
64 #define LDEBUGF(...)
65 #endif
67 #ifdef ROCKBOX_HAS_LOGF
68 #undef LOGF
69 #define LOGF ci->logf
70 #else
71 #define LOGF(...)
72 #endif
74 #endif
76 /* magic for normal codecs */
77 #define CODEC_MAGIC 0x52434F44 /* RCOD */
78 /* magic for encoder codecs */
79 #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
81 /* increase this every time the api struct changes */
82 #define CODEC_API_VERSION 35
84 /* update this to latest version if a change to the api struct breaks
85 backwards compatibility (and please take the opportunity to sort in any
86 new function which are "waiting" at the end of the function table) */
87 #define CODEC_MIN_API_VERSION 35
89 /* codec return codes */
90 enum codec_status {
91 CODEC_OK = 0,
92 CODEC_USB_CONNECTED,
93 CODEC_ERROR = -1,
96 /* NOTE: To support backwards compatibility, only add new functions at
97 the end of the structure. Every time you add a new function,
98 remember to increase CODEC_API_VERSION. If you make changes to the
99 existing APIs then also update CODEC_MIN_API_VERSION to current
100 version
102 struct codec_api {
104 off_t filesize; /* Total file length */
105 off_t curpos; /* Current buffer position */
107 /* For gapless mp3 */
108 struct mp3entry *id3; /* TAG metadata pointer */
109 bool *taginfo_ready; /* Is metadata read */
111 /* Codec should periodically check if stop_codec is set to true.
112 In case it is, codec must return immediately */
113 bool stop_codec;
114 /* Codec should periodically check if new_track is non zero.
115 When it is, the codec should request a new track. */
116 int new_track;
117 /* If seek_time != 0, codec should seek to that song position (in ms)
118 if codec supports seeking. */
119 long seek_time;
121 /* The dsp instance to be used for audio output */
122 struct dsp_config *dsp;
124 /* Returns buffer to malloc array. Only codeclib should need this. */
125 void* (*codec_get_buffer)(size_t *size);
126 /* Insert PCM data into audio buffer for playback. Playback will start
127 automatically. */
128 void (*pcmbuf_insert)(const void *ch1, const void *ch2, int count);
129 /* Set song position in WPS (value in ms). */
130 void (*set_elapsed)(unsigned long value);
132 /* Read next <size> amount bytes from file buffer to <ptr>.
133 Will return number of bytes read or 0 if end of file. */
134 size_t (*read_filebuf)(void *ptr, size_t size);
135 /* Request pointer to file buffer which can be used to read
136 <realsize> amount of data. <reqsize> tells the buffer system
137 how much data it should try to allocate. If <realsize> is 0,
138 end of file is reached. */
139 void* (*request_buffer)(size_t *realsize, size_t reqsize);
140 /* Advance file buffer position by <amount> amount of bytes. */
141 void (*advance_buffer)(size_t amount);
142 /* Advance file buffer to a pointer location inside file buffer. */
143 void (*advance_buffer_loc)(void *ptr);
144 /* Seek file buffer to position <newpos> beginning of file. */
145 bool (*seek_buffer)(size_t newpos);
146 /* Codec should call this function when it has done the seeking. */
147 void (*seek_complete)(void);
148 /* Request file change from file buffer. Returns true is next
149 track is available and changed. If return value is false,
150 codec should exit immediately with PLUGIN_OK status. */
151 bool (*request_next_track)(void);
152 /* Free the buffer area of the current codec after its loaded */
153 void (*discard_codec)(void);
155 void (*set_offset)(size_t value);
156 /* Configure different codec buffer parameters. */
157 void (*configure)(int setting, intptr_t value);
159 /* kernel/ system */
160 #if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
161 void (*__div0)(void);
162 #endif
163 unsigned (*sleep)(unsigned ticks);
164 void (*yield)(void);
166 #if NUM_CORES > 1
167 unsigned int
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)(unsigned int thread_id);
174 void (*thread_wait)(unsigned int thread_id);
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 #endif /* NUM_CORES */
180 void (*cpucache_flush)(void);
181 void (*cpucache_invalidate)(void);
183 /* strings and memory */
184 char* (*strcpy)(char *dst, const char *src);
185 size_t (*strlen)(const char *str);
186 int (*strcmp)(const char *, const char *);
187 char *(*strcat)(char *s1, const char *s2);
188 void* (*memset)(void *dst, int c, size_t length);
189 void* (*memcpy)(void *out, const void *in, size_t n);
190 void* (*memmove)(void *out, const void *in, size_t n);
191 int (*memcmp)(const void *s1, const void *s2, size_t n);
192 void *(*memchr)(const void *s1, int c, size_t n);
193 char *(*strcasestr) (const char* phaystack, const char* pneedle);
195 #if defined(DEBUG) || defined(SIMULATOR)
196 void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
197 #endif
198 #ifdef ROCKBOX_HAS_LOGF
199 void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
200 #endif
202 /* Tremor requires qsort */
203 void (*qsort)(void *base, size_t nmemb, size_t size,
204 int(*compar)(const void *, const void *));
206 /* The ADX codec accesses global_settings to test for REPEAT_ONE mode */
207 struct user_settings* global_settings;
209 #ifdef RB_PROFILE
210 void (*profile_thread)(void);
211 void (*profstop)(void);
212 void (*profile_func_enter)(void *this_fn, void *call_site);
213 void (*profile_func_exit)(void *this_fn, void *call_site);
214 #endif
216 #ifdef HAVE_RECORDING
217 volatile bool stop_encoder;
218 volatile int enc_codec_loaded; /* <0=error, 0=pending, >0=ok */
219 void (*enc_get_inputs)(struct enc_inputs *inputs);
220 void (*enc_set_parameters)(struct enc_parameters *params);
221 struct enc_chunk_hdr * (*enc_get_chunk)(void);
222 void (*enc_finish_chunk)(void);
223 unsigned char * (*enc_get_pcm_data)(size_t size);
224 size_t (*enc_unget_pcm_data)(size_t size);
226 /* file */
227 int (*open)(const char* pathname, int flags, ...);
228 int (*close)(int fd);
229 ssize_t (*read)(int fd, void* buf, size_t count);
230 off_t (*lseek)(int fd, off_t offset, int whence);
231 ssize_t (*write)(int fd, const void* buf, size_t count);
232 int (*round_value_to_list32)(unsigned long value,
233 const unsigned long list[],
234 int count,
235 bool signd);
236 #endif
238 /* new stuff at the end, sort into place next time
239 the API gets incompatible */
242 /* codec header */
243 struct codec_header {
244 struct lc_header lc_hdr; /* must be first */
245 enum codec_status(*entry_point)(void);
246 struct codec_api **api;
249 extern unsigned char codecbuf[];
250 extern size_t codec_size;
252 #ifdef CODEC
253 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
254 /* plugin_* is correct, codecs use the plugin linker script */
255 extern unsigned char plugin_start_addr[];
256 extern unsigned char plugin_end_addr[];
257 /* decoders */
258 #define CODEC_HEADER \
259 const struct codec_header __header \
260 __attribute__ ((section (".header")))= { \
261 { CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
262 plugin_start_addr, plugin_end_addr }, codec_start, &ci };
263 /* encoders */
264 #define CODEC_ENC_HEADER \
265 const struct codec_header __header \
266 __attribute__ ((section (".header")))= { \
267 { CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
268 plugin_start_addr, plugin_end_addr }, codec_start, &ci };
270 #else /* def SIMULATOR */
271 /* decoders */
272 #define CODEC_HEADER \
273 const struct codec_header __header \
274 __attribute__((visibility("default"))) = { \
275 { CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, NULL, NULL }, \
276 codec_start, &ci };
277 /* encoders */
278 #define CODEC_ENC_HEADER \
279 const struct codec_header __header = { \
280 { CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, NULL, NULL }, \
281 codec_start, &ci };
282 #endif /* SIMULATOR */
283 #endif /* CODEC */
285 /* create full codec path from root filenames in audio_formats[]
286 assumes buffer size is MAX_PATH */
287 void codec_get_full_path(char *path, const char *codec_root_fn);
289 /* defined by the codec loader (codec.c) */
290 int codec_load_buf(unsigned int hid, struct codec_api *api);
291 int codec_load_file(const char* codec, struct codec_api *api);
293 /* defined by the codec */
294 enum codec_status codec_start(void);
295 enum codec_status codec_main(void);
297 #endif