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