Android: Partly revert r29569 and only call the new getJavaEnvironment() when needed.
[maemo-rb.git] / apps / codecs.h
blobdaf2c8694e278176be258e4ea801dfd929cec652
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
47 #include "settings.h"
49 #include "gcc_extensions.h"
50 #include "load_code.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 40
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 40
85 /* codec return codes */
86 enum codec_status {
87 CODEC_OK = 0,
88 CODEC_ERROR = -1,
91 /* NOTE: To support backwards compatibility, only add new functions at
92 the end of the structure. Every time you add a new function,
93 remember to increase CODEC_API_VERSION. If you make changes to the
94 existing APIs then also update CODEC_MIN_API_VERSION to current
95 version
97 struct codec_api {
99 off_t filesize; /* Total file length */
100 off_t curpos; /* Current buffer position */
102 /* For gapless mp3 */
103 struct mp3entry *id3; /* TAG metadata pointer */
104 bool *taginfo_ready; /* Is metadata read */
106 /* Codec should periodically check if stop_codec is set to true.
107 In case it is, codec must return immediately */
108 volatile bool stop_codec;
109 /* Codec should periodically check if new_track is non zero.
110 When it is, the codec should request a new track. */
111 volatile int new_track;
112 /* If seek_time != 0, codec should seek to that song position (in ms)
113 if codec supports seeking. */
114 volatile long seek_time;
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 /* Request file change from file buffer. Returns true is next
142 track is available and changed. If return value is false,
143 codec should exit immediately with PLUGIN_OK status. */
144 bool (*request_next_track)(void);
146 void (*set_offset)(size_t value);
147 /* Configure different codec buffer parameters. */
148 void (*configure)(int setting, intptr_t value);
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);
184 char *(*strcasestr) (const char* phaystack, const char* pneedle);
186 #if defined(DEBUG) || defined(SIMULATOR)
187 void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
188 #endif
189 #ifdef ROCKBOX_HAS_LOGF
190 void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
191 #endif
193 /* Tremor requires qsort */
194 void (*qsort)(void *base, size_t nmemb, size_t size,
195 int(*compar)(const void *, const void *));
197 /* The ADX codec accesses global_settings to test for REPEAT_ONE mode */
198 struct user_settings* global_settings;
200 #ifdef RB_PROFILE
201 void (*profile_thread)(void);
202 void (*profstop)(void);
203 void (*profile_func_enter)(void *this_fn, void *call_site);
204 void (*profile_func_exit)(void *this_fn, void *call_site);
205 #endif
207 #ifdef HAVE_RECORDING
208 void (*enc_get_inputs)(struct enc_inputs *inputs);
209 void (*enc_set_parameters)(struct enc_parameters *params);
210 struct enc_chunk_hdr * (*enc_get_chunk)(void);
211 void (*enc_finish_chunk)(void);
212 unsigned char * (*enc_get_pcm_data)(size_t size);
213 size_t (*enc_unget_pcm_data)(size_t size);
215 /* file */
216 int (*open)(const char* pathname, int flags, ...);
217 int (*close)(int fd);
218 ssize_t (*read)(int fd, void* buf, size_t count);
219 off_t (*lseek)(int fd, off_t offset, int whence);
220 ssize_t (*write)(int fd, const void* buf, size_t count);
221 int (*round_value_to_list32)(unsigned long value,
222 const unsigned long list[],
223 int count,
224 bool signd);
225 #endif
227 /* new stuff at the end, sort into place next time
228 the API gets incompatible */
231 /* codec header */
232 struct codec_header {
233 struct lc_header lc_hdr; /* must be first */
234 enum codec_status(*entry_point)(void);
235 struct codec_api **api;
238 extern unsigned char codecbuf[];
239 extern size_t codec_size;
241 #ifdef CODEC
242 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
243 /* plugin_* is correct, codecs use the plugin linker script */
244 extern unsigned char plugin_start_addr[];
245 extern unsigned char plugin_end_addr[];
246 /* decoders */
247 #define CODEC_HEADER \
248 const struct codec_header __header \
249 __attribute__ ((section (".header")))= { \
250 { CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
251 plugin_start_addr, plugin_end_addr }, codec_start, &ci };
252 /* encoders */
253 #define CODEC_ENC_HEADER \
254 const struct codec_header __header \
255 __attribute__ ((section (".header")))= { \
256 { CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
257 plugin_start_addr, plugin_end_addr }, codec_start, &ci };
259 #else /* def SIMULATOR */
260 /* decoders */
261 #define CODEC_HEADER \
262 const struct codec_header __header \
263 __attribute__((visibility("default"))) = { \
264 { CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, NULL, NULL }, \
265 codec_start, &ci };
266 /* encoders */
267 #define CODEC_ENC_HEADER \
268 const struct codec_header __header = { \
269 { CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, NULL, NULL }, \
270 codec_start, &ci };
271 #endif /* SIMULATOR */
272 #endif /* CODEC */
274 /* create full codec path from root filenames in audio_formats[]
275 assumes buffer size is MAX_PATH */
276 void codec_get_full_path(char *path, const char *codec_root_fn);
278 /* defined by the codec loader (codec.c) */
279 void * codec_load_buf(int hid, struct codec_api *api);
280 void * codec_load_file(const char* codec, struct codec_api *api);
281 int codec_begin(void *handle);
282 void codec_close(void *handle);
284 /* defined by the codec */
285 enum codec_status codec_start(void);
286 enum codec_status codec_main(void);
288 #endif