Fix charcell build
[maemo-rb.git] / apps / codecs.h
blob527c59ac9c9ebe25d338b4bdbfe2a15ebc5d2ac0
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 #include <stdbool.h>
31 #include <stdlib.h>
32 #include "strlcpy.h"
33 #include "config.h"
34 #include "system.h"
35 #include "metadata.h"
36 #include "audio.h"
37 #ifdef RB_PROFILE
38 #include "profile.h"
39 #include "thread.h"
40 #endif
41 #if (CONFIG_CODEC == SWCODEC)
42 #ifdef HAVE_RECORDING
43 #include "pcm_record.h"
44 #endif
45 #include "dsp.h"
46 #endif
48 #include "gcc_extensions.h"
49 #include "load_code.h"
51 #ifdef CODEC
52 #if defined(DEBUG) || defined(SIMULATOR)
53 #undef DEBUGF
54 #define DEBUGF ci->debugf
55 #undef LDEBUGF
56 #define LDEBUGF ci->debugf
57 #else
58 #define DEBUGF(...)
59 #define LDEBUGF(...)
60 #endif
62 #ifdef ROCKBOX_HAS_LOGF
63 #undef LOGF
64 #define LOGF ci->logf
65 #else
66 #define LOGF(...)
67 #endif
69 #endif
71 /* magic for normal codecs */
72 #define CODEC_MAGIC 0x52434F44 /* RCOD */
73 /* magic for encoder codecs */
74 #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
76 /* increase this every time the api struct changes */
77 #define CODEC_API_VERSION 43
79 /* update this to latest version if a change to the api struct breaks
80 backwards compatibility (and please take the opportunity to sort in any
81 new function which are "waiting" at the end of the function table) */
82 #define CODEC_MIN_API_VERSION 43
84 /* reasons for calling codec main entrypoint */
85 enum codec_entry_call_reason {
86 CODEC_LOAD = 0,
87 CODEC_UNLOAD
90 /* codec return codes */
91 enum codec_status {
92 CODEC_OK = 0,
93 CODEC_ERROR = -1,
96 /* codec command action codes */
97 enum codec_command_action {
98 CODEC_ACTION_HALT = -1,
99 CODEC_ACTION_NULL = 0,
100 CODEC_ACTION_SEEK_TIME = 1,
103 /* NOTE: To support backwards compatibility, only add new functions at
104 the end of the structure. Every time you add a new function,
105 remember to increase CODEC_API_VERSION. If you make changes to the
106 existing APIs then also update CODEC_MIN_API_VERSION to current
107 version
109 struct codec_api {
110 off_t filesize; /* Total file length */
111 off_t curpos; /* Current buffer position */
113 struct mp3entry *id3; /* TAG metadata pointer */
114 int audio_hid; /* Current audio handle */
116 /* The dsp instance to be used for audio output */
117 struct dsp_config *dsp;
119 /* Returns buffer to malloc array. Only codeclib should need this. */
120 void* (*codec_get_buffer)(size_t *size);
121 /* Insert PCM data into audio buffer for playback. Playback will start
122 automatically. */
123 void (*pcmbuf_insert)(const void *ch1, const void *ch2, int count);
124 /* Set song position in WPS (value in ms). */
125 void (*set_elapsed)(unsigned long value);
127 /* Read next <size> amount bytes from file buffer to <ptr>.
128 Will return number of bytes read or 0 if end of file. */
129 size_t (*read_filebuf)(void *ptr, size_t size);
130 /* Request pointer to file buffer which can be used to read
131 <realsize> amount of data. <reqsize> tells the buffer system
132 how much data it should try to allocate. If <realsize> is 0,
133 end of file is reached. */
134 void* (*request_buffer)(size_t *realsize, size_t reqsize);
135 /* Advance file buffer position by <amount> amount of bytes. */
136 void (*advance_buffer)(size_t amount);
137 /* Seek file buffer to position <newpos> beginning of file. */
138 bool (*seek_buffer)(size_t newpos);
139 /* Codec should call this function when it has done the seeking. */
140 void (*seek_complete)(void);
141 /* Update the current position */
142 void (*set_offset)(size_t value);
143 /* Configure different codec buffer parameters. */
144 void (*configure)(int setting, intptr_t value);
145 /* Obtain command action on what to do next */
146 enum codec_command_action (*get_command)(intptr_t *param);
147 /* Determine whether the track should be looped, if applicable. */
148 bool (*loop_track)(void);
150 /* kernel/ system */
151 #if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
152 void (*__div0)(void);
153 #endif
154 unsigned (*sleep)(unsigned ticks);
155 void (*yield)(void);
157 #if NUM_CORES > 1
158 unsigned int
159 (*create_thread)(void (*function)(void), void* stack,
160 size_t stack_size, unsigned flags, const char *name
161 IF_PRIO(, int priority)
162 IF_COP(, unsigned int core));
164 void (*thread_thaw)(unsigned int thread_id);
165 void (*thread_wait)(unsigned int thread_id);
166 void (*semaphore_init)(struct semaphore *s, int max, int start);
167 int (*semaphore_wait)(struct semaphore *s, int timeout);
168 void (*semaphore_release)(struct semaphore *s);
169 #endif /* NUM_CORES */
171 void (*cpucache_flush)(void);
172 void (*cpucache_invalidate)(void);
174 /* strings and memory */
175 char* (*strcpy)(char *dst, const char *src);
176 size_t (*strlen)(const char *str);
177 int (*strcmp)(const char *, const char *);
178 char *(*strcat)(char *s1, const char *s2);
179 void* (*memset)(void *dst, int c, size_t length);
180 void* (*memcpy)(void *out, const void *in, size_t n);
181 void* (*memmove)(void *out, const void *in, size_t n);
182 int (*memcmp)(const void *s1, const void *s2, size_t n);
183 void *(*memchr)(const void *s1, int c, size_t n);
185 #if defined(DEBUG) || defined(SIMULATOR)
186 void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
187 #endif
188 #ifdef ROCKBOX_HAS_LOGF
189 void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
190 #endif
192 /* Tremor requires qsort */
193 void (*qsort)(void *base, size_t nmemb, size_t size,
194 int(*compar)(const void *, const void *));
196 #ifdef RB_PROFILE
197 void (*profile_thread)(void);
198 void (*profstop)(void);
199 void (*profile_func_enter)(void *this_fn, void *call_site);
200 void (*profile_func_exit)(void *this_fn, void *call_site);
201 #endif
203 #ifdef HAVE_RECORDING
204 void (*enc_get_inputs)(struct enc_inputs *inputs);
205 void (*enc_set_parameters)(struct enc_parameters *params);
206 struct enc_chunk_hdr * (*enc_get_chunk)(void);
207 void (*enc_finish_chunk)(void);
208 unsigned char * (*enc_get_pcm_data)(size_t size);
209 size_t (*enc_unget_pcm_data)(size_t size);
211 /* file */
212 int (*open)(const char* pathname, int flags, ...);
213 int (*close)(int fd);
214 ssize_t (*read)(int fd, void* buf, size_t count);
215 off_t (*lseek)(int fd, off_t offset, int whence);
216 ssize_t (*write)(int fd, const void* buf, size_t count);
217 int (*round_value_to_list32)(unsigned long value,
218 const unsigned long list[],
219 int count,
220 bool signd);
221 #endif
223 /* new stuff at the end, sort into place next time
224 the API gets incompatible */
227 /* codec header */
228 struct codec_header {
229 struct lc_header lc_hdr; /* must be first */
230 enum codec_status(*entry_point)(enum codec_entry_call_reason reason);
231 enum codec_status(*run_proc)(void);
232 struct codec_api **api;
235 #ifdef CODEC
236 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
237 /* plugin_* is correct, codecs use the plugin linker script */
238 extern unsigned char plugin_start_addr[];
239 extern unsigned char plugin_end_addr[];
240 /* decoders */
241 #define CODEC_HEADER \
242 const struct codec_header __header \
243 __attribute__ ((section (".header")))= { \
244 { CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
245 plugin_start_addr, plugin_end_addr }, codec_start, \
246 codec_run, &ci };
247 /* encoders */
248 #define CODEC_ENC_HEADER \
249 const struct codec_header __header \
250 __attribute__ ((section (".header")))= { \
251 { CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
252 plugin_start_addr, plugin_end_addr }, codec_start, \
253 codec_run, &ci };
255 #else /* def SIMULATOR */
256 /* decoders */
257 #define CODEC_HEADER \
258 const struct codec_header __header \
259 __attribute__((visibility("default"))) = { \
260 { CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, NULL, NULL }, \
261 codec_start, codec_run, &ci };
262 /* encoders */
263 #define CODEC_ENC_HEADER \
264 const struct codec_header __header = { \
265 { CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, NULL, NULL }, \
266 codec_start, codec_run, &ci };
267 #endif /* SIMULATOR */
268 #endif /* CODEC */
270 /* create full codec path from root filenames in audio_formats[]
271 assumes buffer size is MAX_PATH */
272 void codec_get_full_path(char *path, const char *codec_root_fn);
274 /* Returns pointer to and size of free codec RAM */
275 void *codec_get_buffer_callback(size_t *size);
277 /* defined by the codec loader (codec.c) */
278 int codec_load_buf(int hid, struct codec_api *api);
279 int codec_load_file(const char* codec, struct codec_api *api);
280 int codec_run_proc(void);
281 int codec_halt(void);
282 int codec_close(void);
284 /* defined by the codec */
285 enum codec_status codec_start(enum codec_entry_call_reason reason);
286 enum codec_status codec_main(enum codec_entry_call_reason reason);
287 enum codec_status codec_run(void);
289 #endif /* _CODECS_H_ */