Xobox - clear display for all. Fixes problem on colour screens with one or both dimen...
[kugel-rb.git] / apps / codecs.h
blob3eab1d35c29a85afc61613d3d9e8e922986ee0a6
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 "config.h"
37 #include "system.h"
38 #include "metadata.h"
39 #include "audio.h"
40 #ifdef RB_PROFILE
41 #include "profile.h"
42 #include "thread.h"
43 #endif
44 #if (CONFIG_CODEC == SWCODEC)
45 #if !defined(SIMULATOR) && defined(HAVE_RECORDING)
46 #include "pcm_record.h"
47 #endif
48 #include "dsp.h"
49 #endif
50 #include "settings.h"
52 #ifdef CODEC
53 #if defined(DEBUG) || defined(SIMULATOR)
54 #undef DEBUGF
55 #define DEBUGF ci->debugf
56 #undef LDEBUGF
57 #define LDEBUGF ci->debugf
58 #else
59 #define DEBUGF(...)
60 #define LDEBUGF(...)
61 #endif
63 #ifdef ROCKBOX_HAS_LOGF
64 #undef LOGF
65 #define LOGF ci->logf
66 #else
67 #define LOGF(...)
68 #endif
70 #endif
72 /* magic for normal codecs */
73 #define CODEC_MAGIC 0x52434F44 /* RCOD */
74 /* magic for encoder codecs */
75 #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
77 /* increase this every time the api struct changes */
78 #define CODEC_API_VERSION 31
80 /* update this to latest version if a change to the api struct breaks
81 backwards compatibility (and please take the opportunity to sort in any
82 new function which are "waiting" at the end of the function table) */
83 #define CODEC_MIN_API_VERSION 30
85 /* codec return codes */
86 enum codec_status {
87 CODEC_OK = 0,
88 CODEC_USB_CONNECTED,
89 CODEC_ERROR = -1,
92 /* NOTE: To support backwards compatibility, only add new functions at
93 the end of the structure. Every time you add a new function,
94 remember to increase CODEC_API_VERSION. If you make changes to the
95 existing APIs then also update CODEC_MIN_API_VERSION to current
96 version
98 struct codec_api {
100 off_t filesize; /* Total file length */
101 off_t curpos; /* Current buffer position */
103 /* For gapless mp3 */
104 struct mp3entry *id3; /* TAG metadata pointer */
105 bool *taginfo_ready; /* Is metadata read */
107 /* Codec should periodically check if stop_codec is set to true.
108 In case it is, codec must return immediately */
109 bool stop_codec;
110 /* Codec should periodically check if new_track is non zero.
111 When it is, the codec should request a new track. */
112 int new_track;
113 /* If seek_time != 0, codec should seek to that song position (in ms)
114 if codec supports seeking. */
115 long seek_time;
117 /* The dsp instance to be used for audio output */
118 struct dsp_config *dsp;
120 /* Returns buffer to malloc array. Only codeclib should need this. */
121 void* (*codec_get_buffer)(size_t *size);
122 /* Insert PCM data into audio buffer for playback. Playback will start
123 automatically. */
124 bool (*pcmbuf_insert)(const void *ch1, const void *ch2, int count);
125 /* Set song position in WPS (value in ms). */
126 void (*set_elapsed)(unsigned int value);
128 /* Read next <size> amount bytes from file buffer to <ptr>.
129 Will return number of bytes read or 0 if end of file. */
130 size_t (*read_filebuf)(void *ptr, size_t size);
131 /* Request pointer to file buffer which can be used to read
132 <realsize> amount of data. <reqsize> tells the buffer system
133 how much data it should try to allocate. If <realsize> is 0,
134 end of file is reached. */
135 void* (*request_buffer)(size_t *realsize, size_t reqsize);
136 /* Advance file buffer position by <amount> amount of bytes. */
137 void (*advance_buffer)(size_t amount);
138 /* Advance file buffer to a pointer location inside file buffer. */
139 void (*advance_buffer_loc)(void *ptr);
140 /* Seek file buffer to position <newpos> beginning of file. */
141 bool (*seek_buffer)(size_t newpos);
142 /* Codec should call this function when it has done the seeking. */
143 void (*seek_complete)(void);
144 /* Request file change from file buffer. Returns true is next
145 track is available and changed. If return value is false,
146 codec should exit immediately with PLUGIN_OK status. */
147 bool (*request_next_track)(void);
148 /* Free the buffer area of the current codec after its loaded */
149 void (*discard_codec)(void);
151 void (*set_offset)(size_t value);
152 /* Configure different codec buffer parameters. */
153 void (*configure)(int setting, intptr_t value);
155 /* kernel/ system */
156 void (*sleep)(int ticks);
157 void (*yield)(void);
159 #if NUM_CORES > 1
160 unsigned int
161 (*create_thread)(void (*function)(void), void* stack,
162 size_t stack_size, unsigned flags, const char *name
163 IF_PRIO(, int priority)
164 IF_COP(, unsigned int core));
166 void (*thread_thaw)(unsigned int thread_id);
167 void (*thread_wait)(unsigned int thread_id);
168 void (*semaphore_init)(struct semaphore *s, int max, int start);
169 void (*semaphore_wait)(struct semaphore *s);
170 void (*semaphore_release)(struct semaphore *s);
171 #endif /* NUM_CORES */
173 #ifdef CACHE_FUNCTIONS_AS_CALL
174 void (*flush_icache)(void);
175 void (*invalidate_icache)(void);
176 #endif
178 /* strings and memory */
179 char* (*strcpy)(char *dst, const char *src);
180 char* (*strncpy)(char *dst, const char *src, size_t length);
181 size_t (*strlen)(const char *str);
182 int (*strcmp)(const char *, const char *);
183 char *(*strcat)(char *s1, const char *s2);
184 void* (*memset)(void *dst, int c, size_t length);
185 void* (*memcpy)(void *out, const void *in, size_t n);
186 void* (*memmove)(void *out, const void *in, size_t n);
187 int (*memcmp)(const void *s1, const void *s2, size_t n);
188 void *(*memchr)(const void *s1, int c, size_t n);
189 char *(*strcasestr) (const char* phaystack, const char* pneedle);
191 #if defined(DEBUG) || defined(SIMULATOR)
192 void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
193 #endif
194 #ifdef ROCKBOX_HAS_LOGF
195 void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
196 #endif
198 /* Tremor requires qsort */
199 void (*qsort)(void *base, size_t nmemb, size_t size,
200 int(*compar)(const void *, const void *));
202 /* The ADX codec accesses global_settings to test for REPEAT_ONE mode */
203 struct user_settings* global_settings;
205 #ifdef RB_PROFILE
206 void (*profile_thread)(void);
207 void (*profstop)(void);
208 void (*profile_func_enter)(void *this_fn, void *call_site);
209 void (*profile_func_exit)(void *this_fn, void *call_site);
210 #endif
212 #if defined(HAVE_RECORDING) && !defined(SIMULATOR)
213 volatile bool stop_encoder;
214 volatile int enc_codec_loaded; /* <0=error, 0=pending, >0=ok */
215 void (*enc_get_inputs)(struct enc_inputs *inputs);
216 void (*enc_set_parameters)(struct enc_parameters *params);
217 struct enc_chunk_hdr * (*enc_get_chunk)(void);
218 void (*enc_finish_chunk)(void);
219 unsigned char * (*enc_get_pcm_data)(size_t size);
220 size_t (*enc_unget_pcm_data)(size_t size);
222 /* file */
223 int (*open)(const char* pathname, int flags);
224 int (*close)(int fd);
225 ssize_t (*read)(int fd, void* buf, size_t count);
226 off_t (*lseek)(int fd, off_t offset, int whence);
227 ssize_t (*write)(int fd, const void* buf, size_t count);
228 int (*round_value_to_list32)(unsigned long value,
229 const unsigned long list[],
230 int count,
231 bool signd);
232 #endif
234 /* new stuff at the end, sort into place next time
235 the API gets incompatible */
236 #ifdef CPU_ARM
237 void (*__div0)(void);
238 #endif
241 /* codec header */
242 struct codec_header {
243 unsigned long magic; /* RCOD or RENC */
244 unsigned short target_id;
245 unsigned short api_version;
246 unsigned char *load_addr;
247 unsigned char *end_addr;
248 enum codec_status(*entry_point)(void);
249 struct codec_api **api;
252 extern unsigned char codecbuf[];
253 extern size_t codec_size;
255 #ifdef CODEC
256 #ifndef SIMULATOR
257 /* plugin_* is correct, codecs use the plugin linker script */
258 extern unsigned char plugin_start_addr[];
259 extern unsigned char plugin_end_addr[];
260 /* decoders */
261 #define CODEC_HEADER \
262 const struct codec_header __header \
263 __attribute__ ((section (".header")))= { \
264 CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
265 plugin_start_addr, plugin_end_addr, codec_start, &ci };
266 /* encoders */
267 #define CODEC_ENC_HEADER \
268 const struct codec_header __header \
269 __attribute__ ((section (".header")))= { \
270 CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
271 plugin_start_addr, plugin_end_addr, codec_start, &ci };
273 #else /* def SIMULATOR */
274 /* decoders */
275 #define CODEC_HEADER \
276 const struct codec_header __header \
277 __attribute__((visibility("default"))) = { \
278 CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
279 NULL, NULL, codec_start, &ci };
280 /* encoders */
281 #define CODEC_ENC_HEADER \
282 const struct codec_header __header = { \
283 CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
284 NULL, NULL, codec_start, &ci };
285 #endif /* SIMULATOR */
286 #endif /* CODEC */
288 /* create full codec path from root filenames in audio_formats[]
289 assumes buffer size is MAX_PATH */
290 void codec_get_full_path(char *path, const char *codec_root_fn);
292 /* defined by the codec loader (codec.c) */
293 int codec_load_buf(unsigned int hid, struct codec_api *api);
294 int codec_load_file(const char* codec, struct codec_api *api);
296 /* defined by the codec */
297 enum codec_status codec_start(void);
298 enum codec_status codec_main(void);
300 #ifndef CACHE_FUNCTION_WRAPPERS
302 #ifdef CACHE_FUNCTIONS_AS_CALL
303 #define CACHE_FUNCTION_WRAPPERS(api) \
304 void flush_icache(void) \
306 (api)->flush_icache(); \
308 void invalidate_icache(void) \
310 (api)->invalidate_icache(); \
312 #else
313 #define CACHE_FUNCTION_WRAPPERS(api)
314 #endif /* CACHE_FUNCTIONS_AS_CALL */
316 #endif /* CACHE_FUNCTION_WRAPPERS */
318 #endif