1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
24 /* instruct simulator code to not redefine any symbols when compiling plugins.
25 (the PLUGIN macro is defined in apps/plugins/Makefile) */
27 #define NO_REDEFINES_PLEASE
32 #include <sys/types.h>
37 #include "string-extra.h"
38 #include "gcc_extensions.h"
40 char* strncpy(char *, const char *, size_t);
41 void* plugin_get_buffer(size_t *buffer_size
);
52 #include "load_code.h"
60 #include "mp3_playback.h"
66 #include "filefuncs.h"
67 #if (CONFIG_CODEC == SWCODEC)
68 #include "pcm_mixer.h"
73 #include "codec_thread.h"
75 #include "recording.h"
79 #endif /* CONFIG_CODEC == SWCODEC */
83 #ifdef HAVE_LCD_BITMAP
84 #include "screendump.h"
85 #include "scrollbar.h"
86 #include "jpeg_load.h"
87 #include "../recorder/bmp.h"
89 #include "statusbar.h"
91 #include "rbunicode.h"
94 #include "color_picker.h"
96 #include "buffering.h"
99 #include "ata_idle_notify.h"
100 #include "settings_list.h"
101 #include "timefuncs.h"
106 #include "albumart.h"
109 #ifdef HAVE_REMOTE_LCD
110 #include "lcd-remote.h"
115 #include "filetypes.h"
117 #ifdef USB_ENABLE_HID
118 #include "usbstack/usb_hid_usage_tables.h"
122 /* on some platforms strcmp() seems to be a tricky define which
123 * breaks if we write down strcmp's prototype */
130 #if defined(DEBUG) || defined(SIMULATOR)
132 #define DEBUGF rb->debugf
134 #define LDEBUGF rb->debugf
137 #define DEBUGF(...) do { } while(0)
139 #define LDEBUGF(...) do { } while(0)
142 #ifdef ROCKBOX_HAS_LOGF
144 #define LOGF rb->logf
151 #define PLUGIN_MAGIC 0x526F634B /* RocK */
153 /* increase this every time the api struct changes */
154 #define PLUGIN_API_VERSION 215
156 /* update this to latest version if a change to the api struct breaks
157 backwards compatibility (and please take the opportunity to sort in any
158 new function which are "waiting" at the end of the function table) */
159 #define PLUGIN_MIN_API_VERSION 214
161 /* plugin return codes */
162 /* internal returns start at 0x100 to make exit(1..255) work */
163 #define INTERNAL_PLUGIN_RETVAL_START 0x100
165 PLUGIN_OK
= 0, /* PLUGIN_OK == EXIT_SUCCESS */
166 /* 1...255 reserved for exit() */
167 PLUGIN_USB_CONNECTED
= INTERNAL_PLUGIN_RETVAL_START
,
173 /* NOTE: To support backwards compatibility, only add new functions at
174 the end of the structure. Every time you add a new function,
175 remember to increase PLUGIN_API_VERSION. If you make changes to the
176 existing APIs then also update PLUGIN_MIN_API_VERSION to current
183 #ifdef HAVE_LCD_CONTRAST
184 void (*lcd_set_contrast
)(int x
);
186 void (*lcd_update
)(void);
187 void (*lcd_clear_display
)(void);
188 int (*lcd_getstringsize
)(const unsigned char *str
, int *w
, int *h
);
189 void (*lcd_putsxy
)(int x
, int y
, const unsigned char *string
);
190 void (*lcd_putsxyf
)(int x
, int y
, const unsigned char *fmt
, ...);
191 void (*lcd_puts
)(int x
, int y
, const unsigned char *string
);
192 void (*lcd_putsf
)(int x
, int y
, const unsigned char *fmt
, ...);
193 void (*lcd_puts_scroll
)(int x
, int y
, const unsigned char* string
);
194 void (*lcd_stop_scroll
)(void);
195 #ifdef HAVE_LCD_CHARCELLS
196 void (*lcd_define_pattern
)(unsigned long ucs
, const char *pattern
);
197 unsigned long (*lcd_get_locked_pattern
)(void);
198 void (*lcd_unlock_pattern
)(unsigned long ucs
);
199 void (*lcd_putc
)(int x
, int y
, unsigned long ucs
);
200 void (*lcd_put_cursor
)(int x
, int y
, unsigned long ucs
);
201 void (*lcd_remove_cursor
)(void);
202 void (*lcd_icon
)(int icon
, bool enable
);
203 void (*lcd_double_height
)(bool on
);
204 #else /* HAVE_LCD_BITMAP */
205 fb_data
* lcd_framebuffer
;
206 void (*lcd_update_rect
)(int x
, int y
, int width
, int height
);
207 void (*lcd_set_drawmode
)(int mode
);
208 int (*lcd_get_drawmode
)(void);
209 void (*lcd_setfont
)(int font
);
210 void (*lcd_drawpixel
)(int x
, int y
);
211 void (*lcd_drawline
)(int x1
, int y1
, int x2
, int y2
);
212 void (*lcd_hline
)(int x1
, int x2
, int y
);
213 void (*lcd_vline
)(int x
, int y1
, int y2
);
214 void (*lcd_drawrect
)(int x
, int y
, int width
, int height
);
215 void (*lcd_fillrect
)(int x
, int y
, int width
, int height
);
216 void (*lcd_mono_bitmap_part
)(const unsigned char *src
, int src_x
, int src_y
,
217 int stride
, int x
, int y
, int width
, int height
);
218 void (*lcd_mono_bitmap
)(const unsigned char *src
, int x
, int y
,
219 int width
, int height
);
221 void (*lcd_set_foreground
)(unsigned foreground
);
222 unsigned (*lcd_get_foreground
)(void);
223 void (*lcd_set_background
)(unsigned foreground
);
224 unsigned (*lcd_get_background
)(void);
225 void (*lcd_bitmap_part
)(const fb_data
*src
, int src_x
, int src_y
,
226 int stride
, int x
, int y
, int width
, int height
);
227 void (*lcd_bitmap
)(const fb_data
*src
, int x
, int y
, int width
,
229 fb_data
* (*lcd_get_backdrop
)(void);
230 void (*lcd_set_backdrop
)(fb_data
* backdrop
);
233 void (*lcd_bitmap_transparent_part
)(const fb_data
*src
,
234 int src_x
, int src_y
, int stride
,
235 int x
, int y
, int width
, int height
);
236 void (*lcd_bitmap_transparent
)(const fb_data
*src
, int x
, int y
,
237 int width
, int height
);
239 void (*lcd_blit_yuv
)(unsigned char * const src
[3],
240 int src_x
, int src_y
, int stride
,
241 int x
, int y
, int width
, int height
);
242 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
243 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630) \
244 || defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(SANSA_FUZEV2) \
245 || defined(TOSHIBA_GIGABEAT_S) || defined(PHILIPS_SA9200)
246 void (*lcd_yuv_set_options
)(unsigned options
);
248 #endif /* MEMORYSIZE > 2 */
249 #elif (LCD_DEPTH < 4) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
250 void (*lcd_blit_mono
)(const unsigned char *data
, int x
, int by
, int width
,
251 int bheight
, int stride
);
252 void (*lcd_blit_grey_phase
)(unsigned char *values
, unsigned char *phases
,
253 int bx
, int by
, int bwidth
, int bheight
,
255 #endif /* LCD_DEPTH */
256 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
257 void (*lcd_blit_pal256
)(unsigned char *src
, int src_x
, int src_y
, int x
, int y
,
258 int width
, int height
);
259 void (*lcd_pal256_update_pal
)(fb_data
*palette
);
261 void (*lcd_puts_style
)(int x
, int y
, const unsigned char *str
, int style
);
262 void (*lcd_puts_scroll_style
)(int x
, int y
, const unsigned char* string
,
264 #ifdef HAVE_LCD_INVERT
265 void (*lcd_set_invert_display
)(bool yesno
);
266 #endif /* HAVE_LCD_INVERT */
267 #if defined(HAVE_LCD_MODES)
268 void (*lcd_set_mode
)(int mode
);
271 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
272 struct event_queue
*button_queue
;
274 unsigned short *(*bidi_l2v
)( const unsigned char *str
, int orientation
);
275 #ifdef HAVE_LCD_BITMAP
276 bool (*is_diacritic
)(const unsigned short char_code
, bool *is_rtl
);
278 const unsigned char *(*font_get_bits
)( struct font
*pf
, unsigned short char_code
);
279 int (*font_load
)(const char *path
);
280 void (*font_unload
)(int font_id
);
281 struct font
* (*font_get
)(int font
);
282 int (*font_getstringsize
)(const unsigned char *str
, int *w
, int *h
,
284 int (*font_get_width
)(struct font
* pf
, unsigned short char_code
);
285 void (*screen_clear_area
)(struct screen
* display
, int xstart
, int ystart
,
286 int width
, int height
);
287 void (*gui_scrollbar_draw
)(struct screen
* screen
, int x
, int y
,
288 int width
, int height
, int items
,
289 int min_shown
, int max_shown
,
291 #endif /* HAVE_LCD_BITMAP */
292 const char* (*get_codepage_name
)(int cp
);
295 /* The backlight_* functions must be present in the API regardless whether
296 * HAVE_BACKLIGHT is defined or not. The reason is that the stock Ondio has
297 * no backlight but can be modded to have backlight (it's prepared on the
298 * PCB). This makes backlight an all-target feature API wise, and keeps API
299 * compatible between stock and modded Ondio.
300 * For OLED targets like the Sansa Clip, the backlight_* functions control
301 * the display enable, which has essentially the same effect. */
302 void (*backlight_on
)(void);
303 void (*backlight_off
)(void);
304 void (*backlight_set_timeout
)(int index
);
305 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
306 void (*backlight_set_brightness
)(int val
);
307 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
310 void (*backlight_set_timeout_plugged
)(int index
);
312 bool (*is_backlight_on
)(bool ignore_always_off
);
313 void (*splash
)(int ticks
, const char *str
);
314 void (*splashf
)(int ticks
, const char *fmt
, ...) ATTRIBUTE_PRINTF(2, 3);
316 #ifdef HAVE_REMOTE_LCD
318 void (*lcd_remote_set_contrast
)(int x
);
319 void (*lcd_remote_clear_display
)(void);
320 void (*lcd_remote_puts
)(int x
, int y
, const unsigned char *string
);
321 void (*lcd_remote_puts_scroll
)(int x
, int y
, const unsigned char* string
);
322 void (*lcd_remote_stop_scroll
)(void);
323 void (*lcd_remote_set_drawmode
)(int mode
);
324 int (*lcd_remote_get_drawmode
)(void);
325 void (*lcd_remote_setfont
)(int font
);
326 int (*lcd_remote_getstringsize
)(const unsigned char *str
, int *w
, int *h
);
327 void (*lcd_remote_drawpixel
)(int x
, int y
);
328 void (*lcd_remote_drawline
)(int x1
, int y1
, int x2
, int y2
);
329 void (*lcd_remote_hline
)(int x1
, int x2
, int y
);
330 void (*lcd_remote_vline
)(int x
, int y1
, int y2
);
331 void (*lcd_remote_drawrect
)(int x
, int y
, int nx
, int ny
);
332 void (*lcd_remote_fillrect
)(int x
, int y
, int nx
, int ny
);
333 void (*lcd_remote_mono_bitmap_part
)(const unsigned char *src
, int src_x
,
334 int src_y
, int stride
, int x
, int y
,
335 int width
, int height
);
336 void (*lcd_remote_mono_bitmap
)(const unsigned char *src
, int x
, int y
,
337 int width
, int height
);
338 void (*lcd_remote_putsxy
)(int x
, int y
, const unsigned char *string
);
339 void (*lcd_remote_puts_style
)(int x
, int y
, const unsigned char *str
, int style
);
340 void (*lcd_remote_puts_scroll_style
)(int x
, int y
, const unsigned char* string
,
342 fb_remote_data
* lcd_remote_framebuffer
;
343 void (*lcd_remote_update
)(void);
344 void (*lcd_remote_update_rect
)(int x
, int y
, int width
, int height
);
346 void (*remote_backlight_on
)(void);
347 void (*remote_backlight_off
)(void);
348 void (*remote_backlight_set_timeout
)(int index
);
350 void (*remote_backlight_set_timeout_plugged
)(int index
);
352 #endif /* HAVE_REMOTE_LCD */
353 struct screen
* screens
[NB_SCREENS
];
354 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
355 void (*lcd_remote_set_foreground
)(unsigned foreground
);
356 unsigned (*lcd_remote_get_foreground
)(void);
357 void (*lcd_remote_set_background
)(unsigned background
);
358 unsigned (*lcd_remote_get_background
)(void);
359 void (*lcd_remote_bitmap_part
)(const fb_remote_data
*src
,
360 int src_x
, int src_y
, int stride
,
361 int x
, int y
, int width
, int height
);
362 void (*lcd_remote_bitmap
)(const fb_remote_data
*src
, int x
, int y
,
363 int width
, int height
);
365 void (*viewport_set_defaults
)(struct viewport
*vp
,
366 const enum screen_type screen
);
367 #ifdef HAVE_LCD_BITMAP
368 void (*viewportmanager_theme_enable
)(enum screen_type screen
, bool enable
,
369 struct viewport
*viewport
);
370 void (*viewportmanager_theme_undo
)(enum screen_type screen
, bool force_redraw
);
373 void (*gui_synclist_init
)(struct gui_synclist
* lists
,
374 list_get_name callback_get_item_name
, void * data
,
375 bool scroll_all
,int selected_size
,
376 struct viewport parent
[NB_SCREENS
]);
377 void (*gui_synclist_set_nb_items
)(struct gui_synclist
* lists
, int nb_items
);
378 void (*gui_synclist_set_icon_callback
)(struct gui_synclist
* lists
,
379 list_get_icon icon_callback
);
380 int (*gui_synclist_get_nb_items
)(struct gui_synclist
* lists
);
381 int (*gui_synclist_get_sel_pos
)(struct gui_synclist
* lists
);
382 void (*gui_synclist_draw
)(struct gui_synclist
* lists
);
383 void (*gui_synclist_select_item
)(struct gui_synclist
* lists
,
385 void (*gui_synclist_add_item
)(struct gui_synclist
* lists
);
386 void (*gui_synclist_del_item
)(struct gui_synclist
* lists
);
387 void (*gui_synclist_limit_scroll
)(struct gui_synclist
* lists
, bool scroll
);
388 bool (*gui_synclist_do_button
)(struct gui_synclist
* lists
,
389 int *action
, enum list_wrap wrap
);
390 void (*gui_synclist_set_title
)(struct gui_synclist
*lists
, char* title
,
391 enum themable_icons icon
);
392 enum yesno_res (*gui_syncyesno_run
)(const struct text_message
* main_message
,
393 const struct text_message
* yes_message
,
394 const struct text_message
* no_message
);
395 void (*simplelist_info_init
)(struct simplelist_info
*info
, char* title
,
396 int count
, void* data
);
397 bool (*simplelist_show_list
)(struct simplelist_info
*info
);
400 long (*button_get
)(bool block
);
401 long (*button_get_w_tmo
)(int ticks
);
402 int (*button_status
)(void);
403 #ifdef HAVE_BUTTON_DATA
404 intptr_t (*button_get_data
)(void);
405 int (*button_status_wdata
)(int *pdata
);
407 void (*button_clear_queue
)(void);
408 int (*button_queue_count
)(void);
409 #ifdef HAS_BUTTON_HOLD
410 bool (*button_hold
)(void);
412 #ifdef HAVE_TOUCHSCREEN
413 void (*touchscreen_set_mode
)(enum touchscreen_mode
);
415 #ifdef HAVE_BUTTON_LIGHT
416 void (*buttonlight_set_timeout
)(int value
);
417 void (*buttonlight_off
)(void);
418 void (*buttonlight_on
)(void);
419 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
420 void (*buttonlight_set_brightness
)(int val
);
421 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
422 #endif /* HAVE_BUTTON_LIGHT */
425 int (*open_utf8
)(const char* pathname
, int flags
);
426 int (*open
)(const char* pathname
, int flags
, ...);
427 int (*close
)(int fd
);
428 ssize_t (*read
)(int fd
, void* buf
, size_t count
);
429 off_t (*lseek
)(int fd
, off_t offset
, int whence
);
430 int (*creat
)(const char *pathname
, mode_t mode
);
431 ssize_t (*write
)(int fd
, const void* buf
, size_t count
);
432 int (*remove
)(const char* pathname
);
433 int (*rename
)(const char* path
, const char* newname
);
434 int (*ftruncate
)(int fd
, off_t length
);
435 off_t (*filesize
)(int fd
);
436 int (*fdprintf
)(int fd
, const char *fmt
, ...) ATTRIBUTE_PRINTF(2, 3);
437 int (*read_line
)(int fd
, char* buffer
, int buffer_size
);
438 bool (*settings_parseline
)(char* line
, char** name
, char** value
);
439 void (*storage_sleep
)(void);
440 void (*storage_spin
)(void);
441 void (*storage_spindown
)(int seconds
);
442 #if USING_STORAGE_CALLBACK
443 void (*register_storage_idle_func
)(void (*function
)(void *data
));
444 void (*unregister_storage_idle_func
)(void (*function
)(void *data
), bool run
);
445 #endif /* USING_STORAGE_CALLBACK */
446 void (*reload_directory
)(void);
447 char *(*create_numbered_filename
)(char *buffer
, const char *path
,
448 const char *prefix
, const char *suffix
,
449 int numberlen
IF_CNFN_NUM_(, int *num
));
450 bool (*file_exists
)(const char *file
);
451 char* (*strip_extension
)(char* buffer
, int buffer_size
, const char *filename
);
452 unsigned (*crc_32
)(const void *src
, unsigned len
, unsigned crc32
);
454 int (*filetype_get_attr
)(const char* file
);
459 DIR* (*opendir
)(const char* name
);
460 int (*closedir
)(DIR* dir
);
461 struct dirent
* (*readdir
)(DIR* dir
);
462 int (*mkdir
)(const char *name
);
463 int (*rmdir
)(const char *name
);
464 bool (*dir_exists
)(const char *path
);
465 struct dirinfo (*dir_get_info
)(DIR* parent
, struct dirent
*entry
);
468 void (*browse_context_init
)(struct browse_context
*browse
,
469 int dirfilter
, unsigned flags
,
470 char *title
, enum themable_icons icon
,
471 const char *root
, const char *selected
);
472 int (*rockbox_browse
)(struct browse_context
*browse
);
475 #if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
476 void (*__div0
)(void);
478 unsigned (*sleep
)(unsigned ticks
);
480 volatile long* current_tick
;
481 long (*default_event_handler
)(long event
);
482 long (*default_event_handler_ex
)(long event
,
483 void (*callback
)(void *), void *parameter
);
484 unsigned int (*create_thread
)(void (*function
)(void), void* stack
,
485 size_t stack_size
, unsigned flags
,
487 IF_PRIO(, int priority
)
488 IF_COP(, unsigned int core
));
489 unsigned int (*thread_self
)(void);
490 void (*thread_exit
)(void);
491 void (*thread_wait
)(unsigned int thread_id
);
492 #if CONFIG_CODEC == SWCODEC
493 void (*thread_thaw
)(unsigned int thread_id
);
494 #ifdef HAVE_PRIORITY_SCHEDULING
495 int (*thread_set_priority
)(unsigned int thread_id
, int priority
);
497 void (*mutex_init
)(struct mutex
*m
);
498 void (*mutex_lock
)(struct mutex
*m
);
499 void (*mutex_unlock
)(struct mutex
*m
);
502 void (*reset_poweroff_timer
)(void);
503 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
504 int (*system_memory_guard
)(int newmode
);
506 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
507 #ifdef CPU_BOOST_LOGGING
508 void (*cpu_boost_
)(bool on_off
,char*location
,int line
);
510 void (*cpu_boost
)(bool on_off
);
512 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
513 #endif /* PLATFORM_NATIVE */
514 #ifdef HAVE_SCHEDULER_BOOSTCTRL
515 void (*trigger_cpu_boost
)(void);
516 void (*cancel_cpu_boost
)(void);
519 void (*commit_dcache
)(void);
520 void (*commit_discard_dcache
)(void);
522 /* load code api for overlay */
523 void* (*lc_open
)(const char *filename
, unsigned char *buf
, size_t buf_size
);
524 void* (*lc_open_from_mem
)(void* addr
, size_t blob_size
);
525 void* (*lc_get_header
)(void *handle
);
526 void (*lc_close
)(void *handle
);
528 bool (*timer_register
)(int reg_prio
, void (*unregister_callback
)(void),
529 long cycles
, void (*timer_callback
)(void)
531 void (*timer_unregister
)(void);
532 bool (*timer_set_period
)(long count
);
534 void (*queue_init
)(struct event_queue
*q
, bool register_queue
);
535 void (*queue_delete
)(struct event_queue
*q
);
536 void (*queue_post
)(struct event_queue
*q
, long id
, intptr_t data
);
537 void (*queue_wait_w_tmo
)(struct event_queue
*q
, struct queue_event
*ev
,
539 #if CONFIG_CODEC == SWCODEC
540 void (*queue_enable_queue_send
)(struct event_queue
*q
,
541 struct queue_sender_list
*send
,
542 unsigned int thread_id
);
543 bool (*queue_empty
)(const struct event_queue
*q
);
544 void (*queue_wait
)(struct event_queue
*q
, struct queue_event
*ev
);
545 intptr_t (*queue_send
)(struct event_queue
*q
, long id
,
547 void (*queue_reply
)(struct event_queue
*q
, intptr_t retval
);
548 #endif /* CONFIG_CODEC == SWCODEC */
550 void (*usb_acknowledge
)(long id
);
551 #ifdef USB_ENABLE_HID
552 void (*usb_hid_send
)(usage_page_t usage_page
, int id
);
555 void (*profile_thread
)(void);
556 void (*profstop
)(void);
557 void (*profile_func_enter
)(void *this_fn
, void *call_site
);
558 void (*profile_func_exit
)(void *this_fn
, void *call_site
);
561 bool (*add_event
)(unsigned short id
, bool oneshot
, void (*handler
)(void *data
));
562 void (*remove_event
)(unsigned short id
, void (*handler
)(void *data
));
563 void (*send_event
)(unsigned short id
, void *data
);
565 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
566 /* special simulator hooks */
567 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
568 void (*sim_lcd_ex_init
)(unsigned long (*getpixel
)(int, int));
569 void (*sim_lcd_ex_update_rect
)(int x
, int y
, int width
, int height
);
573 /* strings and memory */
574 int (*snprintf
)(char *buf
, size_t size
, const char *fmt
, ...)
575 ATTRIBUTE_PRINTF(3, 4);
576 int (*vsnprintf
)(char *buf
, size_t size
, const char *fmt
, va_list ap
);
577 char* (*strcpy
)(char *dst
, const char *src
);
578 size_t (*strlcpy
)(char *dst
, const char *src
, size_t length
);
579 size_t (*strlen
)(const char *str
);
580 char * (*strrchr
)(const char *s
, int c
);
581 int (*strcmp
)(const char *, const char *);
582 int (*strncmp
)(const char *, const char *, size_t);
583 int (*strcasecmp
)(const char *, const char *);
584 int (*strncasecmp
)(const char *s1
, const char *s2
, size_t n
);
585 void* (*memset
)(void *dst
, int c
, size_t length
);
586 void* (*memcpy
)(void *out
, const void *in
, size_t n
);
587 void* (*memmove
)(void *out
, const void *in
, size_t n
);
588 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
589 const unsigned char *_rbctype_
;
591 int (*atoi
)(const char *str
);
592 char *(*strchr
)(const char *s
, int c
);
593 char *(*strcat
)(char *s1
, const char *s2
);
594 size_t (*strlcat
)(char *dst
, const char *src
, size_t length
);
595 void *(*memchr
)(const void *s1
, int c
, size_t n
);
596 int (*memcmp
)(const void *s1
, const void *s2
, size_t n
);
597 char *(*strcasestr
) (const char* phaystack
, const char* pneedle
);
598 char* (*strtok_r
)(char *ptr
, const char *sep
, char **end
);
600 const unsigned char* (*utf8decode
)(const unsigned char *utf8
, unsigned short *ucs
);
601 unsigned char* (*iso_decode
)(const unsigned char *iso
, unsigned char *utf8
, int cp
, int count
);
602 unsigned char* (*utf16LEdecode
)(const unsigned char *utf16
, unsigned char *utf8
, int count
);
603 unsigned char* (*utf16BEdecode
)(const unsigned char *utf16
, unsigned char *utf8
, int count
);
604 unsigned char* (*utf8encode
)(unsigned long ucs
, unsigned char *utf8
);
605 unsigned long (*utf8length
)(const unsigned char *utf8
);
606 int (*utf8seek
)(const unsigned char* utf8
, int offset
);
608 /* the buflib memory management library */
609 void (*buflib_init
)(struct buflib_context
* ctx
, void* buf
, size_t size
);
610 size_t (*buflib_available
)(struct buflib_context
* ctx
);
611 int (*buflib_alloc
)(struct buflib_context
* ctx
, size_t size
);
612 int (*buflib_alloc_ex
)(struct buflib_context
* ctx
, size_t size
,
613 const char* name
, struct buflib_callbacks
*ops
);
614 int (*buflib_alloc_maximum
)(struct buflib_context
* ctx
, const char* name
,
615 size_t* size
, struct buflib_callbacks
*ops
);
616 void (*buflib_buffer_in
)(struct buflib_context
* ctx
, int size
);
617 void* (*buflib_buffer_out
)(struct buflib_context
* ctx
, size_t* size
);
618 int (*buflib_free
)(struct buflib_context
* ctx
, int handle
);
619 bool (*buflib_shrink
)(struct buflib_context
* ctx
, int handle
,
620 void* new_start
, size_t new_size
);
621 void* (*buflib_get_data
)(struct buflib_context
* ctx
, int handle
);
622 const char* (*buflib_get_name
)(struct buflib_context
* ctx
, int handle
);
625 void (*sound_set
)(int setting
, int value
);
626 int (*sound_default
)(int setting
);
627 int (*sound_min
)(int setting
);
628 int (*sound_max
)(int setting
);
629 const char * (*sound_unit
)(int setting
);
630 int (*sound_val2phys
)(int setting
, int value
);
631 #ifdef AUDIOHW_HAVE_EQ
632 int (*sound_enum_hw_eq_band_setting
)(unsigned int band
,
633 unsigned int band_setting
);
634 #endif /* AUDIOHW_HAVE_EQ */
635 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
636 void (*mp3_play_data
)(const unsigned char* start
, int size
,
637 void (*get_more
)(unsigned char** start
, size_t* size
));
638 void (*mp3_play_pause
)(bool play
);
639 void (*mp3_play_stop
)(void);
640 bool (*mp3_is_playing
)(void);
641 #if CONFIG_CODEC != SWCODEC
642 void (*bitswap
)(unsigned char *data
, int length
);
644 #endif /* PLATFORM_NATIVE */
645 #if CONFIG_CODEC == SWCODEC
646 const unsigned long *audio_master_sampr_list
;
647 const unsigned long *hw_freq_sampr
;
648 void (*pcm_apply_settings
)(void);
649 void (*pcm_play_data
)(pcm_play_callback_type get_more
,
650 unsigned char* start
, size_t size
);
651 void (*pcm_play_stop
)(void);
652 void (*pcm_set_frequency
)(unsigned int frequency
);
653 bool (*pcm_is_playing
)(void);
654 bool (*pcm_is_paused
)(void);
655 void (*pcm_play_pause
)(bool play
);
656 size_t (*pcm_get_bytes_waiting
)(void);
657 void (*pcm_calculate_peaks
)(int *left
, int *right
);
658 const void* (*pcm_get_peak_buffer
)(int *count
);
659 void (*pcm_play_lock
)(void);
660 void (*pcm_play_unlock
)(void);
661 void (*beep_play
)(unsigned int frequency
, unsigned int duration
,
662 unsigned int amplitude
);
663 #ifdef HAVE_RECORDING
664 const unsigned long *rec_freq_sampr
;
665 void (*pcm_init_recording
)(void);
666 void (*pcm_close_recording
)(void);
667 void (*pcm_record_data
)(pcm_rec_callback_type more_ready
,
668 void *start
, size_t size
);
669 void (*pcm_stop_recording
)(void);
670 void (*pcm_calculate_rec_peaks
)(int *left
, int *right
);
671 void (*audio_set_recording_gain
)(int left
, int right
, int type
);
672 #endif /* HAVE_RECORDING */
673 #if INPUT_SRC_CAPS != 0
674 void (*audio_set_output_source
)(int monitor
);
675 void (*audio_set_input_source
)(int source
, unsigned flags
);
677 void (*dsp_set_crossfeed
)(bool enable
);
678 void (*dsp_set_eq
)(bool enable
);
679 void (*dsp_dither_enable
)(bool enable
);
680 intptr_t (*dsp_configure
)(struct dsp_config
*dsp
, int setting
,
682 int (*dsp_process
)(struct dsp_config
*dsp
, char *dest
,
683 const char *src
[], int count
);
684 int (*dsp_input_count
)(struct dsp_config
*dsp
, int count
);
685 int (*dsp_output_count
)(struct dsp_config
*dsp
, int count
);
687 enum channel_status (*mixer_channel_status
)(enum pcm_mixer_channel channel
);
688 void * (*mixer_channel_get_buffer
)(enum pcm_mixer_channel channel
, int *count
);
689 void (*mixer_channel_calculate_peaks
)(enum pcm_mixer_channel channel
,
690 int *left
, int *right
);
691 void (*mixer_channel_play_data
)(enum pcm_mixer_channel channel
,
692 pcm_play_callback_type get_more
,
693 unsigned char *start
, size_t size
);
694 void (*mixer_channel_play_pause
)(enum pcm_mixer_channel channel
, bool play
);
695 void (*mixer_channel_stop
)(enum pcm_mixer_channel channel
);
696 void (*mixer_channel_set_amplitude
)(enum pcm_mixer_channel channel
,
697 unsigned int amplitude
);
698 size_t (*mixer_channel_get_bytes_waiting
)(enum pcm_mixer_channel channel
);
700 void (*system_sound_play
)(enum system_sound sound
);
701 void (*keyclick_click
)(int button
);
702 #endif /* CONFIG_CODEC == SWCODC */
704 /* playback control */
705 int (*playlist_amount
)(void);
706 int (*playlist_resume
)(void);
707 void (*playlist_start
)(int start_index
, int offset
);
708 int (*playlist_add
)(const char *filename
);
709 void (*playlist_sync
)(struct playlist_info
* playlist
);
710 int (*playlist_remove_all_tracks
)(struct playlist_info
*playlist
);
711 int (*playlist_create
)(const char *dir
, const char *file
);
712 int (*playlist_insert_track
)(struct playlist_info
* playlist
,
713 const char *filename
, int position
, bool queue
, bool sync
);
714 int (*playlist_insert_directory
)(struct playlist_info
* playlist
,
715 const char *dirname
, int position
, bool queue
,
717 int (*playlist_shuffle
)(int random_seed
, int start_index
);
718 void (*audio_play
)(long offset
);
719 void (*audio_stop
)(void);
720 void (*audio_pause
)(void);
721 void (*audio_resume
)(void);
722 void (*audio_next
)(void);
723 void (*audio_prev
)(void);
724 void (*audio_ff_rewind
)(long newtime
);
725 struct mp3entry
* (*audio_next_track
)(void);
726 int (*audio_status
)(void);
727 struct mp3entry
* (*audio_current_track
)(void);
728 void (*audio_flush_and_reload_tracks
)(void);
729 int (*audio_get_file_pos
)(void);
730 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
731 unsigned long (*mpeg_get_last_header
)(void);
733 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
734 (CONFIG_CODEC == SWCODEC)) && defined (HAVE_PITCHSCREEN)
735 void (*sound_set_pitch
)(int32_t pitch
);
738 /* MAS communication */
739 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
740 int (*mas_readmem
)(int bank
, int addr
, unsigned long* dest
, int len
);
741 int (*mas_writemem
)(int bank
, int addr
, const unsigned long* src
, int len
);
742 int (*mas_readreg
)(int reg
);
743 int (*mas_writereg
)(int reg
, unsigned int val
);
744 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
745 int (*mas_codec_writereg
)(int reg
, unsigned int val
);
746 int (*mas_codec_readreg
)(int reg
);
747 void (*i2c_begin
)(void);
748 void (*i2c_end
)(void);
749 int (*i2c_write
)(int address
, const unsigned char* buf
, int count
);
754 int (*do_menu
)(const struct menu_item_ex
*menu
, int *start_selected
,
755 struct viewport parent
[NB_SCREENS
], bool hide_theme
);
758 struct gui_syncstatusbar
*statusbars
;
759 void (*gui_syncstatusbar_draw
)(struct gui_syncstatusbar
* bars
, bool force_redraw
);
762 const struct settings_list
* (*get_settings_list
)(int*count
);
763 const struct settings_list
* (*find_setting
)(const void* variable
, int *id
);
764 bool (*option_screen
)(const struct settings_list
*setting
,
765 struct viewport parent
[NB_SCREENS
],
766 bool use_temp_var
, unsigned char* option_title
);
767 bool (*set_option
)(const char* string
, const void* variable
,
768 enum optiontype type
, const struct opt_items
* options
,
769 int numoptions
, void (*function
)(int));
770 bool (*set_bool_options
)(const char* string
, const bool* variable
,
771 const char* yes_str
, int yes_voice
,
772 const char* no_str
, int no_voice
,
773 void (*function
)(bool));
774 bool (*set_int
)(const unsigned char* string
, const char* unit
, int voice_unit
,
775 const int* variable
, void (*function
)(int), int step
,
777 const char* (*formatter
)(char*, size_t, int, const char*) );
778 bool (*set_bool
)(const char* string
, const bool* variable
);
780 #ifdef HAVE_LCD_COLOR
781 bool (*set_color
)(struct screen
*display
, char *title
,
782 unsigned *color
, unsigned banned_color
);
784 /* action handling */
785 int (*get_custom_action
)(int context
,int timeout
,
786 const struct button_mapping
* (*get_context_map
)(int));
787 int (*get_action
)(int context
, int timeout
);
788 #ifdef HAVE_TOUCHSCREEN
789 int (*action_get_touchscreen_press
)(short *x
, short *y
);
791 bool (*action_userabort
)(int timeout
);
794 int (*battery_level
)(void);
795 bool (*battery_level_safe
)(void);
796 int (*battery_time
)(void);
797 int (*battery_voltage
)(void);
799 bool (*charger_inserted
)(void);
800 # if CONFIG_CHARGING >= CHARGING_MONITOR
801 bool (*charging_state
)(void);
804 #ifdef HAVE_USB_POWER
805 bool (*usb_powered
)(void);
809 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
812 void (*srand
)(unsigned int seed
);
814 void (*qsort
)(void *base
, size_t nmemb
, size_t size
,
815 int(*compar
)(const void *, const void *));
816 int (*kbd_input
)(char* buffer
, int buflen
);
817 struct tm
* (*get_time
)(void);
818 int (*set_time
)(const struct tm
*tm
);
820 time_t (*mktime
)(struct tm
*t
);
822 void* (*plugin_get_buffer
)(size_t *buffer_size
);
823 void* (*plugin_get_audio_buffer
)(size_t *buffer_size
);
824 void (*plugin_tsr
)(bool (*exit_callback
)(bool reenter
));
825 char* (*plugin_get_current_filename
)(void);
826 #if defined(DEBUG) || defined(SIMULATOR)
827 void (*debugf
)(const char *fmt
, ...) ATTRIBUTE_PRINTF(1, 2);
829 #ifdef ROCKBOX_HAS_LOGF
830 void (*logf
)(const char *fmt
, ...) ATTRIBUTE_PRINTF(1, 2);
832 struct user_settings
* global_settings
;
833 struct system_status
*global_status
;
834 void (*talk_disable
)(bool disable
);
835 #if CONFIG_CODEC == SWCODEC
836 void (*codec_thread_do_callback
)(void (*fn
)(void),
837 unsigned int *audio_thread_id
);
838 int (*codec_load_file
)(const char* codec
, struct codec_api
*api
);
839 int (*codec_run_proc
)(void);
840 int (*codec_close
)(void);
841 const char *(*get_codec_filename
)(int cod_spec
);
842 void ** (*find_array_ptr
)(void **arr
, void *ptr
);
843 int (*remove_array_ptr
)(void **arr
, void *ptr
);
844 int (*round_value_to_list32
)(unsigned long value
,
845 const unsigned long list
[],
848 #endif /* CONFIG_CODEC == SWCODEC */
849 bool (*get_metadata
)(struct mp3entry
* id3
, int fd
, const char* trackname
);
850 bool (*mp3info
)(struct mp3entry
*entry
, const char *filename
);
851 int (*count_mp3_frames
)(int fd
, int startpos
, int filesize
,
852 void (*progressfunc
)(int),
853 unsigned char* buf
, size_t buflen
);
854 int (*create_xing_header
)(int fd
, long startpos
, long filesize
,
855 unsigned char *buf
, unsigned long num_frames
,
856 unsigned long rec_time
, unsigned long header_template
,
857 void (*progressfunc
)(int), bool generate_toc
,
858 unsigned char* tempbuf
, size_t tempbuf_len
);
859 unsigned long (*find_next_frame
)(int fd
, long *offset
,
860 long max_offset
, unsigned long reference_header
);
862 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
863 unsigned short (*peak_meter_scale_value
)(unsigned short val
,
865 void (*peak_meter_set_use_dbfs
)(bool use
);
866 bool (*peak_meter_get_use_dbfs
)(void);
868 #ifdef HAVE_LCD_BITMAP
869 int (*read_bmp_file
)(const char* filename
, struct bitmap
*bm
, int maxsize
,
870 int format
, const struct custom_format
*cformat
);
871 int (*read_bmp_fd
)(int fd
, struct bitmap
*bm
, int maxsize
,
872 int format
, const struct custom_format
*cformat
);
874 int (*read_jpeg_file
)(const char* filename
, struct bitmap
*bm
, int maxsize
,
875 int format
, const struct custom_format
*cformat
);
876 int (*read_jpeg_fd
)(int fd
, struct bitmap
*bm
, int maxsize
,
877 int format
, const struct custom_format
*cformat
);
879 void (*screen_dump_set_hook
)(void (*hook
)(int fh
));
881 int (*show_logo
)(void);
882 struct tree_context
* (*tree_get_context
)(void);
883 struct entry
* (*tree_get_entries
)(struct tree_context
* t
);
884 struct entry
* (*tree_get_entry_at
)(struct tree_context
* t
, int index
);
886 void (*set_current_file
)(const char* path
);
887 void (*set_dirfilter
)(int l_dirfilter
);
889 #ifdef HAVE_WHEEL_POSITION
890 int (*wheel_status
)(void);
891 void (*wheel_send_events
)(bool send
);
894 #ifdef IRIVER_H100_SERIES
895 /* Routines for the iriver_flash -plugin. */
896 bool (*detect_original_firmware
)(void);
897 bool (*detect_flashed_ramimage
)(void);
898 bool (*detect_flashed_romimage
)(void);
901 void (*led
)(bool on
);
903 #if (CONFIG_CODEC == SWCODEC)
905 int (*bufopen
)(const char *file
, size_t offset
, enum data_type type
,
907 int (*bufalloc
)(const void *src
, size_t size
, enum data_type type
);
908 bool (*bufclose
)(int handle_id
);
909 int (*bufseek
)(int handle_id
, size_t newpos
);
910 int (*bufadvance
)(int handle_id
, off_t offset
);
911 ssize_t (*bufread
)(int handle_id
, size_t size
, void *dest
);
912 ssize_t (*bufgetdata
)(int handle_id
, size_t size
, void **data
);
913 ssize_t (*bufgettail
)(int handle_id
, size_t size
, void **data
);
914 ssize_t (*bufcuttail
)(int handle_id
, size_t size
);
916 ssize_t (*buf_handle_offset
)(int handle_id
);
917 void (*buf_set_base_handle
)(int handle_id
);
918 size_t (*buf_used
)(void);
922 bool (*tagcache_search
)(struct tagcache_search
*tcs
, int tag
);
923 void (*tagcache_search_set_uniqbuf
)(struct tagcache_search
*tcs
,
924 void *buffer
, long length
);
925 bool (*tagcache_search_add_filter
)(struct tagcache_search
*tcs
,
927 bool (*tagcache_get_next
)(struct tagcache_search
*tcs
);
928 bool (*tagcache_retrieve
)(struct tagcache_search
*tcs
, int idxid
,
929 int tag
, char *buf
, long size
);
930 void (*tagcache_search_finish
)(struct tagcache_search
*tcs
);
931 long (*tagcache_get_numeric
)(const struct tagcache_search
*tcs
, int tag
);
932 #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
933 bool (*tagcache_fill_tags
)(struct mp3entry
*id3
, const char *filename
);
938 bool (*search_albumart_files
)(const struct mp3entry
*id3
, const char *size_string
,
939 char *buf
, int buflen
);
942 #ifdef HAVE_SEMAPHORE_OBJECTS
943 void (*semaphore_init
)(struct semaphore
*s
, int max
, int start
);
944 int (*semaphore_wait
)(struct semaphore
*s
, int timeout
);
945 void (*semaphore_release
)(struct semaphore
*s
);
948 const char *rbversion
;
950 /* new stuff at the end, sort into place next time
951 the API gets incompatible */
953 void (*commit_discard_idcache
)(void);
957 struct plugin_header
{
958 struct lc_header lc_hdr
; /* must be the first */
959 enum plugin_status(*entry_point
)(const void*);
960 const struct plugin_api
**api
;
964 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
965 extern unsigned char plugin_start_addr
[];
966 extern unsigned char plugin_end_addr
[];
967 #define PLUGIN_HEADER \
968 const struct plugin_api *rb DATA_ATTR; \
969 const struct plugin_header __header \
970 __attribute__ ((section (".header")))= { \
971 { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
972 plugin_start_addr, plugin_end_addr }, plugin__start, &rb };
973 #else /* PLATFORM_HOSTED */
974 #define PLUGIN_HEADER \
975 const struct plugin_api *rb DATA_ATTR; \
976 const struct plugin_header __header \
977 __attribute__((visibility("default"))) = { \
978 { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, NULL, NULL }, \
979 plugin__start, &rb };
980 #endif /* CONFIG_PLATFORM */
983 int plugin_load(const char* plugin
, const void* parameter
);
984 void* plugin_get_audio_buffer(size_t *buffer_size
);
987 callback returns true to allow the new plugin to load,
988 reenter means the currently running plugin is being reloaded */
989 void plugin_tsr(bool (*exit_callback
)(bool reenter
));
991 /* defined by the plugin */
992 extern const struct plugin_api
*rb
;
993 enum plugin_status
plugin_start(const void* parameter
);
994 enum plugin_status
plugin__start(const void* parameter
)
997 #endif /* __PCTOOL__ */