Update several codec Makefiles so that the codec libs build again on Coldfire targets...
[Rockbox.git] / apps / codecs.h
blob96804a889b0df3f98d45c3383dd82ce7b6409799
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #ifndef _CODECS_H_
20 #define _CODECS_H_
22 /* instruct simulator code to not redefine any symbols when compiling codecs.
23 (the CODEC macro is defined in apps/codecs/Makefile) */
24 #ifdef CODEC
25 #define NO_REDEFINES_PLEASE
26 #endif
28 #ifndef MEM
29 #define MEM 2
30 #endif
32 #include <stdbool.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <sys/types.h>
36 #include "config.h"
37 #include "dir.h"
38 #include "kernel.h"
39 #include "font.h"
40 #include "system.h"
41 #include "id3.h"
42 #include "mpeg.h"
43 #include "audio.h"
44 #include "mp3_playback.h"
45 #ifdef RB_PROFILE
46 #include "profile.h"
47 #endif
48 #if (CONFIG_CODEC == SWCODEC)
49 #if !defined(SIMULATOR)
50 #include "pcm_record.h"
51 #endif
52 #include "dsp.h"
53 #include "playback.h"
54 #endif
55 #include "settings.h"
56 #include "thread.h"
57 #include "playlist.h"
58 #include "sound.h"
60 #ifdef CODEC
62 #if defined(DEBUG) || defined(SIMULATOR)
63 #undef DEBUGF
64 #define DEBUGF rb->debugf
65 #undef LDEBUGF
66 #define LDEBUGF rb->debugf
67 #else
68 #define DEBUGF(...)
69 #define LDEBUGF(...)
70 #endif
72 #ifdef ROCKBOX_HAS_LOGF
73 #undef LOGF
74 #define LOGF rb->logf
75 #else
76 #define LOGF(...)
77 #endif
79 #endif
81 #ifdef SIMULATOR
82 #define PREFIX(_x_) sim_ ## _x_
83 #else
84 #define PREFIX(_x_) _x_
85 #endif
87 #define CODEC_MAGIC 0x52434F44 /* RCOD */
89 /* increase this every time the api struct changes */
90 #define CODEC_API_VERSION 9
92 /* update this to latest version if a change to the api struct breaks
93 backwards compatibility (and please take the opportunity to sort in any
94 new function which are "waiting" at the end of the function table) */
95 #define CODEC_MIN_API_VERSION 8
97 /* codec return codes */
98 enum codec_status {
99 CODEC_OK = 0,
100 CODEC_USB_CONNECTED,
101 CODEC_ERROR = -1,
104 /* NOTE: To support backwards compatibility, only add new functions at
105 the end of the structure. Every time you add a new function,
106 remember to increase CODEC_API_VERSION. If you make changes to the
107 existing APIs then also update CODEC_MIN_API_VERSION to current
108 version
110 struct codec_api {
112 off_t filesize; /* Total file length */
113 off_t curpos; /* Current buffer position */
115 /* For gapless mp3 */
116 struct mp3entry *id3; /* TAG metadata pointer */
117 bool *taginfo_ready; /* Is metadata read */
119 /* Codec should periodically check if stop_codec is set to true.
120 In case it is, codec must return immediately */
121 bool stop_codec;
122 /* Codec should periodically check if new_track is non zero.
123 When it is, the codec should request a new track. */
124 int new_track;
125 /* If seek_time != 0, codec should seek to that song position (in ms)
126 if codec supports seeking. */
127 long seek_time;
129 /* Returns buffer to malloc array. Only codeclib should need this. */
130 void* (*get_codec_memory)(size_t *size);
131 /* Insert PCM data into audio buffer for playback. Playback will start
132 automatically. */
133 bool (*pcmbuf_insert)(const char *data, size_t length);
134 bool (*pcmbuf_insert_split)(const void *ch1, const void *ch2, size_t length);
135 /* Set song position in WPS (value in ms). */
136 void (*set_elapsed)(unsigned int value);
138 /* Read next <size> amount bytes from file buffer to <ptr>.
139 Will return number of bytes read or 0 if end of file. */
140 size_t (*read_filebuf)(void *ptr, size_t size);
141 /* Request pointer to file buffer which can be used to read
142 <realsize> amount of data. <reqsize> tells the buffer system
143 how much data it should try to allocate. If <realsize> is 0,
144 end of file is reached. */
145 void* (*request_buffer)(size_t *realsize, size_t reqsize);
146 /* Advance file buffer position by <amount> amount of bytes. */
147 void (*advance_buffer)(size_t amount);
148 /* Advance file buffer to a pointer location inside file buffer. */
149 void (*advance_buffer_loc)(void *ptr);
150 /* Seek file buffer to position <newpos> beginning of file. */
151 bool (*seek_buffer)(size_t newpos);
152 /* Codec should call this function when it has done the seeking. */
153 void (*seek_complete)(void);
154 /* Calculate mp3 seek position from given time data in ms. */
155 off_t (*mp3_get_filepos)(int newtime);
156 /* Request file change from file buffer. Returns true is next
157 track is available and changed. If return value is false,
158 codec should exit immediately with PLUGIN_OK status. */
159 bool (*request_next_track)(void);
160 /* Free the buffer area of the current codec after its loaded */
161 void (*discard_codec)(void);
163 void (*set_offset)(size_t value);
164 /* Configure different codec buffer parameters. */
165 void (*configure)(int setting, void *value);
167 void (*splash)(int ticks, bool center, const unsigned char *fmt, ...);
169 /* file */
170 int (*PREFIX(open))(const char* pathname, int flags);
171 int (*close)(int fd);
172 ssize_t (*read)(int fd, void* buf, size_t count);
173 off_t (*PREFIX(lseek))(int fd, off_t offset, int whence);
174 int (*PREFIX(creat))(const char *pathname, mode_t mode);
175 ssize_t (*write)(int fd, const void* buf, size_t count);
176 int (*PREFIX(remove))(const char* pathname);
177 int (*PREFIX(rename))(const char* path, const char* newname);
178 int (*PREFIX(ftruncate))(int fd, off_t length);
180 int (*fdprintf)(int fd, const char *fmt, ...);
181 int (*read_line)(int fd, char* buffer, int buffer_size);
182 bool (*settings_parseline)(char* line, char** name, char** value);
183 #ifndef SIMULATOR
184 void (*ata_sleep)(void);
185 #endif
187 /* dir */
188 DIR* (*PREFIX(opendir))(const char* name);
189 int (*PREFIX(closedir))(DIR* dir);
190 struct dirent* (*PREFIX(readdir))(DIR* dir);
191 int (*PREFIX(mkdir))(const char *name, int mode);
193 /* kernel/ system */
194 void (*PREFIX(sleep))(int ticks);
195 void (*yield)(void);
196 long* current_tick;
197 long (*default_event_handler)(long event);
198 long (*default_event_handler_ex)(long event, void (*callback)(void *), void *parameter);
199 struct thread_entry* (*create_thread)(unsigned int core, void (*function)(void),
200 void* stack, int stack_size, const char *name
201 IF_PRIO(, int priority));
202 void (*remove_thread)(struct thread_entry *thread);
203 void (*reset_poweroff_timer)(void);
204 #ifndef SIMULATOR
205 int (*system_memory_guard)(int newmode);
206 long *cpu_frequency;
207 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
208 void (*cpu_boost)(bool on_off);
209 #endif
210 #endif
212 /* strings and memory */
213 int (*snprintf)(char *buf, size_t size, const char *fmt, ...);
214 char* (*strcpy)(char *dst, const char *src);
215 char* (*strncpy)(char *dst, const char *src, size_t length);
216 size_t (*strlen)(const char *str);
217 char * (*strrchr)(const char *s, int c);
218 int (*strcmp)(const char *, const char *);
219 int (*strcasecmp)(const char *, const char *);
220 int (*strncasecmp)(const char *s1, const char *s2, size_t n);
221 void* (*memset)(void *dst, int c, size_t length);
222 void* (*memcpy)(void *out, const void *in, size_t n);
223 void* (*memmove)(void *out, const void *in, size_t n);
224 const char *_ctype_;
225 int (*atoi)(const char *str);
226 char *(*strchr)(const char *s, int c);
227 char *(*strcat)(char *s1, const char *s2);
228 int (*memcmp)(const void *s1, const void *s2, size_t n);
229 char *(*strcasestr) (const char* phaystack, const char* pneedle);
230 void *(*memchr)(const void *s1, int c, size_t n);
232 /* sound */
233 void (*sound_set)(int setting, int value);
234 #ifndef SIMULATOR
235 void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, int* size));
236 void (*mp3_play_pause)(bool play);
237 void (*mp3_play_stop)(void);
238 bool (*mp3_is_playing)(void);
239 #endif /* !SIMULATOR */
241 /* playback control */
242 void (*PREFIX(audio_play))(long offset);
243 void (*audio_stop)(void);
244 void (*audio_pause)(void);
245 void (*audio_resume)(void);
246 void (*audio_next)(void);
247 void (*audio_prev)(void);
248 void (*audio_ff_rewind)(long newtime);
249 struct mp3entry* (*audio_next_track)(void);
250 int (*playlist_amount)(void);
251 int (*audio_status)(void);
252 bool (*audio_has_changed_track)(void);
253 struct mp3entry* (*audio_current_track)(void);
254 void (*audio_flush_and_reload_tracks)(void);
255 int (*audio_get_file_pos)(void);
257 /* misc */
258 void (*srand)(unsigned int seed);
259 int (*rand)(void);
260 void (*qsort)(void *base, size_t nmemb, size_t size,
261 int(*compar)(const void *, const void *));
262 int (*kbd_input)(char* buffer, int buflen);
263 struct tm* (*get_time)(void);
264 int (*set_time)(const struct tm *tm);
265 void* (*plugin_get_audio_buffer)(int* buffer_size);
267 #if defined(DEBUG) || defined(SIMULATOR)
268 void (*debugf)(const char *fmt, ...);
269 #endif
270 #ifdef ROCKBOX_HAS_LOGF
271 void (*logf)(const char *fmt, ...);
272 #endif
273 struct user_settings* global_settings;
274 bool (*mp3info)(struct mp3entry *entry, const char *filename, bool v1first);
275 int (*count_mp3_frames)(int fd, int startpos, int filesize,
276 void (*progressfunc)(int));
277 int (*create_xing_header)(int fd, long startpos, long filesize,
278 unsigned char *buf, unsigned long num_frames,
279 unsigned long rec_time, unsigned long header_template,
280 void (*progressfunc)(int), bool generate_toc);
281 unsigned long (*find_next_frame)(int fd, long *offset,
282 long max_offset, unsigned long last_header);
283 int (*battery_level)(void);
284 bool (*battery_level_safe)(void);
286 #ifdef RB_PROFILE
287 void (*profile_thread)(void);
288 void (*profstop)(void);
289 void (*profile_func_enter)(void *this_fn, void *call_site);
290 void (*profile_func_exit)(void *this_fn, void *call_site);
291 #endif
293 #if defined(HAVE_RECORDING) && !defined(SIMULATOR)
294 bool enc_codec_loaded;
295 void (*enc_get_inputs)(int *buffer_size,
296 int *channels, int *quality);
297 void (*enc_set_parameters)(int chunk_size, int num_chunks,
298 int samp_per_chunk, char *head_ptr, int head_size,
299 int enc_id);
300 unsigned int* (*enc_alloc_chunk)(void);
301 void (*enc_free_chunk)(void);
302 int (*enc_wavbuf_near_empty)(void);
303 char* (*enc_get_wav_data)(int size);
304 void (**enc_set_header_callback)(void *head_buffer,
305 int head_size, int num_samples, bool is_file_header);
306 #endif
308 /* new stuff at the end, sort into place next time
309 the API gets incompatible */
313 /* codec header */
314 struct codec_header {
315 unsigned long magic;
316 unsigned short target_id;
317 unsigned short api_version;
318 unsigned char *load_addr;
319 unsigned char *end_addr;
320 enum codec_status(*entry_point)(struct codec_api*);
322 #ifdef CODEC
323 #ifndef SIMULATOR
324 /* plugin_* is correct, codecs use the plugin linker script */
325 extern unsigned char plugin_start_addr[];
326 extern unsigned char plugin_end_addr[];
327 #define CODEC_HEADER \
328 const struct codec_header __header \
329 __attribute__ ((section (".header")))= { \
330 CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
331 plugin_start_addr, plugin_end_addr, codec_start };
332 #else /* SIMULATOR */
333 #define CODEC_HEADER \
334 const struct codec_header __header = { \
335 CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
336 NULL, NULL, codec_start };
337 #endif
338 #endif
340 /* create full codec path from filenames in audio_formats[]
341 assumes buffer size is MAX_PATH */
342 void codec_get_full_path(char *path, const char *codec_fn);
344 /* defined by the codec loader (codec.c) */
345 int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
346 struct codec_api *api);
347 int codec_load_file(const char* codec, struct codec_api *api);
349 /* defined by the codec */
350 enum codec_status codec_start(struct codec_api* rockbox);
352 #endif