diff options
Diffstat (limited to 'apps/codecs.h')
-rw-r--r-- | apps/codecs.h | 97 |
1 files changed, 40 insertions, 57 deletions
diff --git a/apps/codecs.h b/apps/codecs.h index 5d5fbfe75d..320431f3bf 100644 --- a/apps/codecs.h +++ b/apps/codecs.h | |||
@@ -80,32 +80,23 @@ | |||
80 | #define PREFIX(_x_) _x_ | 80 | #define PREFIX(_x_) _x_ |
81 | #endif | 81 | #endif |
82 | 82 | ||
83 | #define CODEC_MAGIC 0x52434F44 /* RCOD */ | ||
84 | |||
83 | /* increase this every time the api struct changes */ | 85 | /* increase this every time the api struct changes */ |
84 | #define CODEC_API_VERSION 44 | 86 | #define CODEC_API_VERSION 1 |
85 | 87 | ||
86 | /* update this to latest version if a change to the api struct breaks | 88 | /* update this to latest version if a change to the api struct breaks |
87 | backwards compatibility (and please take the opportunity to sort in any | 89 | backwards compatibility (and please take the opportunity to sort in any |
88 | new function which are "waiting" at the end of the function table) */ | 90 | new function which are "waiting" at the end of the function table) */ |
89 | #define CODEC_MIN_API_VERSION 44 | 91 | #define CODEC_MIN_API_VERSION 1 |
90 | 92 | ||
91 | /* codec return codes */ | 93 | /* codec return codes */ |
92 | enum codec_status { | 94 | enum codec_status { |
93 | CODEC_OK = 0, | 95 | CODEC_OK = 0, |
94 | CODEC_USB_CONNECTED, | 96 | CODEC_USB_CONNECTED, |
95 | 97 | CODEC_ERROR = -1, | |
96 | CODEC_WRONG_API_VERSION = -1, | ||
97 | CODEC_WRONG_MODEL = -2, | ||
98 | CODEC_ERROR = -3, | ||
99 | }; | 98 | }; |
100 | 99 | ||
101 | /* compatibility test macro */ | ||
102 | #define TEST_CODEC_API(_api_) \ | ||
103 | do { \ | ||
104 | int _rc_ = _api_->codec_test(CODEC_API_VERSION, 1, MEM); \ | ||
105 | if (_rc_<0) \ | ||
106 | return _rc_; \ | ||
107 | } while(0) | ||
108 | |||
109 | /* NOTE: To support backwards compatibility, only add new functions at | 100 | /* NOTE: To support backwards compatibility, only add new functions at |
110 | the end of the structure. Every time you add a new function, | 101 | the end of the structure. Every time you add a new function, |
111 | remember to increase CODEC_API_VERSION. If you make changes to the | 102 | remember to increase CODEC_API_VERSION. If you make changes to the |
@@ -113,10 +104,6 @@ do { \ | |||
113 | version | 104 | version |
114 | */ | 105 | */ |
115 | struct codec_api { | 106 | struct codec_api { |
116 | /* these two fields must always be first, to ensure | ||
117 | TEST_CODEC_API will always work */ | ||
118 | int version; | ||
119 | int (*codec_test)(int api_version, int model, int memsize); | ||
120 | 107 | ||
121 | off_t filesize; /* Total file length */ | 108 | off_t filesize; /* Total file length */ |
122 | off_t curpos; /* Current buffer position */ | 109 | off_t curpos; /* Current buffer position */ |
@@ -158,6 +145,8 @@ struct codec_api { | |||
158 | void (*advance_buffer_loc)(void *ptr); | 145 | void (*advance_buffer_loc)(void *ptr); |
159 | /* Seek file buffer to position <newpos> beginning of file. */ | 146 | /* Seek file buffer to position <newpos> beginning of file. */ |
160 | bool (*seek_buffer)(off_t newpos); | 147 | bool (*seek_buffer)(off_t newpos); |
148 | /* Codec should call this function when it has done the seeking. */ | ||
149 | void (*seek_complete)(void); | ||
161 | /* Calculate mp3 seek position from given time data in ms. */ | 150 | /* Calculate mp3 seek position from given time data in ms. */ |
162 | off_t (*mp3_get_filepos)(int newtime); | 151 | off_t (*mp3_get_filepos)(int newtime); |
163 | /* Request file change from file buffer. Returns true is next | 152 | /* Request file change from file buffer. Returns true is next |
@@ -165,6 +154,7 @@ struct codec_api { | |||
165 | codec should exit immediately with PLUGIN_OK status. */ | 154 | codec should exit immediately with PLUGIN_OK status. */ |
166 | bool (*request_next_track)(void); | 155 | bool (*request_next_track)(void); |
167 | 156 | ||
157 | void (*set_offset)(unsigned int value); | ||
168 | /* Configure different codec buffer parameters. */ | 158 | /* Configure different codec buffer parameters. */ |
169 | void (*configure)(int setting, void *value); | 159 | void (*configure)(int setting, void *value); |
170 | 160 | ||
@@ -228,6 +218,7 @@ struct codec_api { | |||
228 | char *(*strcat)(char *s1, const char *s2); | 218 | char *(*strcat)(char *s1, const char *s2); |
229 | int (*memcmp)(const void *s1, const void *s2, size_t n); | 219 | int (*memcmp)(const void *s1, const void *s2, size_t n); |
230 | char *(*strcasestr) (const char* phaystack, const char* pneedle); | 220 | char *(*strcasestr) (const char* phaystack, const char* pneedle); |
221 | void *(*memchr)(const void *s1, int c, size_t n); | ||
231 | 222 | ||
232 | /* sound */ | 223 | /* sound */ |
233 | void (*sound_set)(int setting, int value); | 224 | void (*sound_set)(int setting, int value); |
@@ -236,9 +227,6 @@ struct codec_api { | |||
236 | void (*mp3_play_pause)(bool play); | 227 | void (*mp3_play_pause)(bool play); |
237 | void (*mp3_play_stop)(void); | 228 | void (*mp3_play_stop)(void); |
238 | bool (*mp3_is_playing)(void); | 229 | bool (*mp3_is_playing)(void); |
239 | #if CONFIG_CODEC != SWCODEC | ||
240 | void (*bitswap)(unsigned char *data, int length); | ||
241 | #endif | ||
242 | #if CONFIG_CODEC == SWCODEC | 230 | #if CONFIG_CODEC == SWCODEC |
243 | void (*pcm_play_data)(void (*get_more)(unsigned char** start, long*size)); | 231 | void (*pcm_play_data)(void (*get_more)(unsigned char** start, long*size)); |
244 | void (*pcm_play_stop)(void); | 232 | void (*pcm_play_stop)(void); |
@@ -263,24 +251,6 @@ struct codec_api { | |||
263 | struct mp3entry* (*audio_current_track)(void); | 251 | struct mp3entry* (*audio_current_track)(void); |
264 | void (*audio_flush_and_reload_tracks)(void); | 252 | void (*audio_flush_and_reload_tracks)(void); |
265 | int (*audio_get_file_pos)(void); | 253 | int (*audio_get_file_pos)(void); |
266 | #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC) | ||
267 | unsigned long (*mpeg_get_last_header)(void); | ||
268 | #endif | ||
269 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | ||
270 | void (*sound_set_pitch)(int pitch); | ||
271 | #endif | ||
272 | |||
273 | /* MAS communication */ | ||
274 | #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC) | ||
275 | int (*mas_readmem)(int bank, int addr, unsigned long* dest, int len); | ||
276 | int (*mas_writemem)(int bank, int addr, const unsigned long* src, int len); | ||
277 | int (*mas_readreg)(int reg); | ||
278 | int (*mas_writereg)(int reg, unsigned int val); | ||
279 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | ||
280 | int (*mas_codec_writereg)(int reg, unsigned int val); | ||
281 | int (*mas_codec_readreg)(int reg); | ||
282 | #endif | ||
283 | #endif | ||
284 | 254 | ||
285 | /* tag database */ | 255 | /* tag database */ |
286 | struct tagdb_header *tagdbheader; | 256 | struct tagdb_header *tagdbheader; |
@@ -301,6 +271,9 @@ struct codec_api { | |||
301 | #if defined(DEBUG) || defined(SIMULATOR) | 271 | #if defined(DEBUG) || defined(SIMULATOR) |
302 | void (*debugf)(const char *fmt, ...); | 272 | void (*debugf)(const char *fmt, ...); |
303 | #endif | 273 | #endif |
274 | #ifdef ROCKBOX_HAS_LOGF | ||
275 | void (*logf)(const char *fmt, ...); | ||
276 | #endif | ||
304 | struct user_settings* global_settings; | 277 | struct user_settings* global_settings; |
305 | bool (*mp3info)(struct mp3entry *entry, const char *filename, bool v1first); | 278 | bool (*mp3info)(struct mp3entry *entry, const char *filename, bool v1first); |
306 | int (*count_mp3_frames)(int fd, int startpos, int filesize, | 279 | int (*count_mp3_frames)(int fd, int startpos, int filesize, |
@@ -313,35 +286,45 @@ struct codec_api { | |||
313 | long max_offset, unsigned long last_header); | 286 | long max_offset, unsigned long last_header); |
314 | int (*battery_level)(void); | 287 | int (*battery_level)(void); |
315 | bool (*battery_level_safe)(void); | 288 | bool (*battery_level_safe)(void); |
316 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | ||
317 | unsigned short (*peak_meter_scale_value)(unsigned short val, | ||
318 | int meterwidth); | ||
319 | void (*peak_meter_set_use_dbfs)(bool use); | ||
320 | bool (*peak_meter_get_use_dbfs)(void); | ||
321 | #endif | ||
322 | 289 | ||
323 | /* new stuff at the end, sort into place next time | 290 | /* new stuff at the end, sort into place next time |
324 | the API gets incompatible */ | 291 | the API gets incompatible */ |
325 | |||
326 | #ifdef ROCKBOX_HAS_LOGF | ||
327 | void (*logf)(const char *fmt, ...); | ||
328 | #endif | ||
329 | 292 | ||
330 | void *(*memchr)(const void *s1, int c, size_t n); | ||
331 | void (*set_offset)(unsigned int value); | ||
332 | /* Codec should call this function when it has done the seeking. */ | ||
333 | void (*seek_complete)(void); | ||
334 | }; | 293 | }; |
335 | 294 | ||
295 | /* codec header */ | ||
296 | struct codec_header { | ||
297 | unsigned long magic; | ||
298 | unsigned short target_id; | ||
299 | unsigned short api_version; | ||
300 | unsigned char *load_addr; | ||
301 | unsigned char *end_addr; | ||
302 | enum codec_status(*entry_point)(struct codec_api*); | ||
303 | }; | ||
304 | #ifdef CODEC | ||
305 | #ifndef SIMULATOR | ||
306 | /* plugin_* is correct, codecs use the plugin linker script */ | ||
307 | extern unsigned char plugin_start_addr[]; | ||
308 | extern unsigned char plugin_end_addr[]; | ||
309 | #define CODEC_HEADER \ | ||
310 | const struct codec_header __header \ | ||
311 | __attribute__ ((section (".header")))= { \ | ||
312 | CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \ | ||
313 | plugin_start_addr, plugin_end_addr, codec_start }; | ||
314 | #else /* SIMULATOR */ | ||
315 | #define CODEC_HEADER \ | ||
316 | const struct codec_header __header = { \ | ||
317 | CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \ | ||
318 | NULL, NULL, codec_start }; | ||
319 | #endif | ||
320 | #endif | ||
321 | |||
336 | /* defined by the codec loader (codec.c) */ | 322 | /* defined by the codec loader (codec.c) */ |
337 | #if CONFIG_CODEC == SWCODEC | ||
338 | int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap, | 323 | int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap, |
339 | struct codec_api *api); | 324 | struct codec_api *api); |
340 | int codec_load_file(const char* codec, struct codec_api *api); | 325 | int codec_load_file(const char* codec, struct codec_api *api); |
341 | #endif | ||
342 | 326 | ||
343 | /* defined by the codec */ | 327 | /* defined by the codec */ |
344 | enum codec_status codec_start(struct codec_api* rockbox) | 328 | enum codec_status codec_start(struct codec_api* rockbox); |
345 | __attribute__ ((section (".entry"))); | ||
346 | 329 | ||
347 | #endif | 330 | #endif |