summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/codecs.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/codecs.h')
-rw-r--r--lib/rbcodec/codecs/codecs.h291
1 files changed, 291 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/codecs.h b/lib/rbcodec/codecs/codecs.h
new file mode 100644
index 0000000000..bad8cdd469
--- /dev/null
+++ b/lib/rbcodec/codecs/codecs.h
@@ -0,0 +1,291 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Björn Stenberg
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _CODECS_H_
22#define _CODECS_H_
23
24/* instruct simulator code to not redefine any symbols when compiling codecs.
25 (the CODEC macro is defined in codecs.make) */
26#ifdef CODEC
27#define NO_REDEFINES_PLEASE
28#endif
29
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#include "dsp-util.h"
47#endif
48
49#include "gcc_extensions.h"
50#include "load_code.h"
51
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
62
63#ifdef ROCKBOX_HAS_LOGF
64#undef LOGF
65#define LOGF ci->logf
66#else
67#define LOGF(...)
68#endif
69
70#endif
71
72/* magic for normal codecs */
73#define CODEC_MAGIC 0x52434F44 /* RCOD */
74/* magic for encoder codecs */
75#define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
76
77/* increase this every time the api struct changes */
78#define CODEC_API_VERSION 44
79
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 43
84
85/* reasons for calling codec main entrypoint */
86enum codec_entry_call_reason {
87 CODEC_LOAD = 0,
88 CODEC_UNLOAD
89};
90
91/* codec return codes */
92enum codec_status {
93 CODEC_OK = 0,
94 CODEC_ERROR = -1,
95};
96
97/* codec command action codes */
98enum codec_command_action {
99 CODEC_ACTION_HALT = -1,
100 CODEC_ACTION_NULL = 0,
101 CODEC_ACTION_SEEK_TIME = 1,
102};
103
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
109 */
110struct codec_api {
111 off_t filesize; /* Total file length */
112 off_t curpos; /* Current buffer position */
113
114 struct mp3entry *id3; /* TAG metadata pointer */
115 int audio_hid; /* Current audio handle */
116
117 /* The dsp instance to be used for audio output */
118 struct dsp_config *dsp;
119
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 void (*pcmbuf_insert)(const void *ch1, const void *ch2, int count);
125 /* Set song position in WPS (value in ms). */
126 void (*set_elapsed)(unsigned long value);
127
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 /* Seek file buffer to position <newpos> beginning of file. */
139 bool (*seek_buffer)(size_t newpos);
140 /* Codec should call this function when it has done the seeking. */
141 void (*seek_complete)(void);
142 /* Update the current position */
143 void (*set_offset)(size_t value);
144 /* Configure different codec buffer parameters. */
145 void (*configure)(int setting, intptr_t value);
146 /* Obtain command action on what to do next */
147 enum codec_command_action (*get_command)(intptr_t *param);
148 /* Determine whether the track should be looped, if applicable. */
149 bool (*loop_track)(void);
150
151 /* kernel/ system */
152#if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
153 void (*__div0)(void);
154#endif
155 unsigned (*sleep)(unsigned ticks);
156 void (*yield)(void);
157
158#if NUM_CORES > 1
159 unsigned int
160 (*create_thread)(void (*function)(void), void* stack,
161 size_t stack_size, unsigned flags, const char *name
162 IF_PRIO(, int priority)
163 IF_COP(, unsigned int core));
164
165 void (*thread_thaw)(unsigned int thread_id);
166 void (*thread_wait)(unsigned int thread_id);
167 void (*semaphore_init)(struct semaphore *s, int max, int start);
168 int (*semaphore_wait)(struct semaphore *s, int timeout);
169 void (*semaphore_release)(struct semaphore *s);
170#endif /* NUM_CORES */
171
172 void (*commit_dcache)(void);
173 void (*commit_discard_dcache)(void);
174
175 /* strings and memory */
176 char* (*strcpy)(char *dst, const char *src);
177 size_t (*strlen)(const char *str);
178 int (*strcmp)(const char *, const char *);
179 char *(*strcat)(char *s1, const char *s2);
180 void* (*memset)(void *dst, int c, size_t length);
181 void* (*memcpy)(void *out, const void *in, size_t n);
182 void* (*memmove)(void *out, const void *in, size_t n);
183 int (*memcmp)(const void *s1, const void *s2, size_t n);
184 void *(*memchr)(const void *s1, int c, size_t n);
185
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
192
193 /* Tremor requires qsort */
194 void (*qsort)(void *base, size_t nmemb, size_t size,
195 int(*compar)(const void *, const void *));
196
197#ifdef RB_PROFILE
198 void (*profile_thread)(void);
199 void (*profstop)(void);
200 void (*profile_func_enter)(void *this_fn, void *call_site);
201 void (*profile_func_exit)(void *this_fn, void *call_site);
202#endif
203
204#ifdef HAVE_RECORDING
205 void (*enc_get_inputs)(struct enc_inputs *inputs);
206 void (*enc_set_parameters)(struct enc_parameters *params);
207 struct enc_chunk_hdr * (*enc_get_chunk)(void);
208 void (*enc_finish_chunk)(void);
209 unsigned char * (*enc_get_pcm_data)(size_t size);
210 size_t (*enc_unget_pcm_data)(size_t size);
211
212 /* file */
213 int (*open)(const char* pathname, int flags, ...);
214 int (*close)(int fd);
215 ssize_t (*read)(int fd, void* buf, size_t count);
216 off_t (*lseek)(int fd, off_t offset, int whence);
217 ssize_t (*write)(int fd, const void* buf, size_t count);
218 int (*round_value_to_list32)(unsigned long value,
219 const unsigned long list[],
220 int count,
221 bool signd);
222#endif
223
224 /* new stuff at the end, sort into place next time
225 the API gets incompatible */
226 void (*commit_discard_idcache)(void);
227};
228
229/* codec header */
230struct codec_header {
231 struct lc_header lc_hdr; /* must be first */
232 enum codec_status(*entry_point)(enum codec_entry_call_reason reason);
233 enum codec_status(*run_proc)(void);
234 struct codec_api **api;
235};
236
237#ifdef CODEC
238#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
239/* plugin_* is correct, codecs use the plugin linker script */
240extern unsigned char plugin_start_addr[];
241extern unsigned char plugin_end_addr[];
242/* decoders */
243#define CODEC_HEADER \
244 const struct codec_header __header \
245 __attribute__ ((section (".header")))= { \
246 { CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
247 plugin_start_addr, plugin_end_addr }, codec_start, \
248 codec_run, &ci };
249/* encoders */
250#define CODEC_ENC_HEADER \
251 const struct codec_header __header \
252 __attribute__ ((section (".header")))= { \
253 { CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
254 plugin_start_addr, plugin_end_addr }, codec_start, \
255 codec_run, &ci };
256
257#else /* def SIMULATOR */
258/* decoders */
259#define CODEC_HEADER \
260 const struct codec_header __header \
261 __attribute__((visibility("default"))) = { \
262 { CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, NULL, NULL }, \
263 codec_start, codec_run, &ci };
264/* encoders */
265#define CODEC_ENC_HEADER \
266 const struct codec_header __header = { \
267 { CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, NULL, NULL }, \
268 codec_start, codec_run, &ci };
269#endif /* SIMULATOR */
270#endif /* CODEC */
271
272/* create full codec path from root filenames in audio_formats[]
273 assumes buffer size is MAX_PATH */
274void codec_get_full_path(char *path, const char *codec_root_fn);
275
276/* Returns pointer to and size of free codec RAM */
277void *codec_get_buffer_callback(size_t *size);
278
279/* defined by the codec loader (codec.c) */
280int codec_load_buf(int hid, struct codec_api *api);
281int codec_load_file(const char* codec, struct codec_api *api);
282int codec_run_proc(void);
283int codec_halt(void);
284int codec_close(void);
285
286/* defined by the codec */
287enum codec_status codec_start(enum codec_entry_call_reason reason);
288enum codec_status codec_main(enum codec_entry_call_reason reason);
289enum codec_status codec_run(void);
290
291#endif /* _CODECS_H_ */