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"
72 #include "codec_thread.h"
74 #include "recording.h"
78 #endif /* CONFIG_CODEC == SWCODEC */
82 #ifdef HAVE_LCD_BITMAP
83 #include "screendump.h"
84 #include "scrollbar.h"
85 #include "jpeg_load.h"
86 #include "../recorder/bmp.h"
88 #include "statusbar.h"
90 #include "rbunicode.h"
93 #include "color_picker.h"
94 #include "buffering.h"
97 #include "ata_idle_notify.h"
98 #include "settings_list.h"
99 #include "timefuncs.h"
103 #include "albumart.h"
106 #ifdef HAVE_REMOTE_LCD
107 #include "lcd-remote.h"
112 #include "filetypes.h"
114 #ifdef USB_ENABLE_HID
115 #include "usbstack/usb_hid_usage_tables.h"
119 /* on some platforms strcmp() seems to be a tricky define which
120 * breaks if we write down strcmp's prototype */
125 #if defined(DEBUG) || defined(SIMULATOR)
127 #define DEBUGF rb->debugf
129 #define LDEBUGF rb->debugf
132 #define DEBUGF(...) do { } while(0)
134 #define LDEBUGF(...) do { } while(0)
137 #ifdef ROCKBOX_HAS_LOGF
139 #define LOGF rb->logf
146 #define PLUGIN_MAGIC 0x526F634B /* RocK */
148 /* increase this every time the api struct changes */
149 #define PLUGIN_API_VERSION 210
151 /* update this to latest version if a change to the api struct breaks
152 backwards compatibility (and please take the opportunity to sort in any
153 new function which are "waiting" at the end of the function table) */
154 #define PLUGIN_MIN_API_VERSION 210
156 /* plugin return codes */
157 /* internal returns start at 0x100 to make exit(1..255) work */
158 #define INTERNAL_PLUGIN_RETVAL_START 0x100
160 PLUGIN_OK
= 0, /* PLUGIN_OK == EXIT_SUCCESS */
161 /* 1...255 reserved for exit() */
162 PLUGIN_USB_CONNECTED
= INTERNAL_PLUGIN_RETVAL_START
,
168 /* NOTE: To support backwards compatibility, only add new functions at
169 the end of the structure. Every time you add a new function,
170 remember to increase PLUGIN_API_VERSION. If you make changes to the
171 existing APIs then also update PLUGIN_MIN_API_VERSION to current
178 #ifdef HAVE_LCD_CONTRAST
179 void (*lcd_set_contrast
)(int x
);
181 void (*lcd_update
)(void);
182 void (*lcd_clear_display
)(void);
183 int (*lcd_getstringsize
)(const unsigned char *str
, int *w
, int *h
);
184 void (*lcd_putsxy
)(int x
, int y
, const unsigned char *string
);
185 void (*lcd_putsxyf
)(int x
, int y
, const unsigned char *fmt
, ...);
186 void (*lcd_puts
)(int x
, int y
, const unsigned char *string
);
187 void (*lcd_putsf
)(int x
, int y
, const unsigned char *fmt
, ...);
188 void (*lcd_puts_scroll
)(int x
, int y
, const unsigned char* string
);
189 void (*lcd_stop_scroll
)(void);
190 #ifdef HAVE_LCD_CHARCELLS
191 void (*lcd_define_pattern
)(unsigned long ucs
, const char *pattern
);
192 unsigned long (*lcd_get_locked_pattern
)(void);
193 void (*lcd_unlock_pattern
)(unsigned long ucs
);
194 void (*lcd_putc
)(int x
, int y
, unsigned long ucs
);
195 void (*lcd_put_cursor
)(int x
, int y
, unsigned long ucs
);
196 void (*lcd_remove_cursor
)(void);
197 void (*lcd_icon
)(int icon
, bool enable
);
198 void (*lcd_double_height
)(bool on
);
199 #else /* HAVE_LCD_BITMAP */
200 fb_data
* lcd_framebuffer
;
201 void (*lcd_update_rect
)(int x
, int y
, int width
, int height
);
202 void (*lcd_set_drawmode
)(int mode
);
203 int (*lcd_get_drawmode
)(void);
204 void (*lcd_setfont
)(int font
);
205 void (*lcd_drawpixel
)(int x
, int y
);
206 void (*lcd_drawline
)(int x1
, int y1
, int x2
, int y2
);
207 void (*lcd_hline
)(int x1
, int x2
, int y
);
208 void (*lcd_vline
)(int x
, int y1
, int y2
);
209 void (*lcd_drawrect
)(int x
, int y
, int width
, int height
);
210 void (*lcd_fillrect
)(int x
, int y
, int width
, int height
);
211 void (*lcd_mono_bitmap_part
)(const unsigned char *src
, int src_x
, int src_y
,
212 int stride
, int x
, int y
, int width
, int height
);
213 void (*lcd_mono_bitmap
)(const unsigned char *src
, int x
, int y
,
214 int width
, int height
);
216 void (*lcd_set_foreground
)(unsigned foreground
);
217 unsigned (*lcd_get_foreground
)(void);
218 void (*lcd_set_background
)(unsigned foreground
);
219 unsigned (*lcd_get_background
)(void);
220 void (*lcd_bitmap_part
)(const fb_data
*src
, int src_x
, int src_y
,
221 int stride
, int x
, int y
, int width
, int height
);
222 void (*lcd_bitmap
)(const fb_data
*src
, int x
, int y
, int width
,
224 fb_data
* (*lcd_get_backdrop
)(void);
225 void (*lcd_set_backdrop
)(fb_data
* backdrop
);
228 void (*lcd_bitmap_transparent_part
)(const fb_data
*src
,
229 int src_x
, int src_y
, int stride
,
230 int x
, int y
, int width
, int height
);
231 void (*lcd_bitmap_transparent
)(const fb_data
*src
, int x
, int y
,
232 int width
, int height
);
234 void (*lcd_blit_yuv
)(unsigned char * const src
[3],
235 int src_x
, int src_y
, int stride
,
236 int x
, int y
, int width
, int height
);
237 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
238 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630) \
239 || defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(SANSA_FUZEV2) \
240 || defined(TOSHIBA_GIGABEAT_S) || defined(PHILIPS_SA9200)
241 void (*lcd_yuv_set_options
)(unsigned options
);
243 #endif /* MEMORYSIZE > 2 */
244 #elif (LCD_DEPTH < 4) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
245 void (*lcd_blit_mono
)(const unsigned char *data
, int x
, int by
, int width
,
246 int bheight
, int stride
);
247 void (*lcd_blit_grey_phase
)(unsigned char *values
, unsigned char *phases
,
248 int bx
, int by
, int bwidth
, int bheight
,
250 #endif /* LCD_DEPTH */
251 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
252 void (*lcd_blit_pal256
)(unsigned char *src
, int src_x
, int src_y
, int x
, int y
,
253 int width
, int height
);
254 void (*lcd_pal256_update_pal
)(fb_data
*palette
);
256 void (*lcd_puts_style
)(int x
, int y
, const unsigned char *str
, int style
);
257 void (*lcd_puts_scroll_style
)(int x
, int y
, const unsigned char* string
,
259 #ifdef HAVE_LCD_INVERT
260 void (*lcd_set_invert_display
)(bool yesno
);
261 #endif /* HAVE_LCD_INVERT */
262 #if defined(HAVE_LCD_MODES)
263 void (*lcd_set_mode
)(int mode
);
266 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
267 struct event_queue
*button_queue
;
269 unsigned short *(*bidi_l2v
)( const unsigned char *str
, int orientation
);
270 #ifdef HAVE_LCD_BITMAP
271 bool (*is_diacritic
)(const unsigned short char_code
, bool *is_rtl
);
273 const unsigned char *(*font_get_bits
)( struct font
*pf
, unsigned short char_code
);
274 int (*font_load
)(struct font
*, const char *path
);
275 struct font
* (*font_get
)(int font
);
276 int (*font_getstringsize
)(const unsigned char *str
, int *w
, int *h
,
278 int (*font_get_width
)(struct font
* pf
, unsigned short char_code
);
279 void (*screen_clear_area
)(struct screen
* display
, int xstart
, int ystart
,
280 int width
, int height
);
281 void (*gui_scrollbar_draw
)(struct screen
* screen
, int x
, int y
,
282 int width
, int height
, int items
,
283 int min_shown
, int max_shown
,
285 #endif /* HAVE_LCD_BITMAP */
286 const char* (*get_codepage_name
)(int cp
);
289 /* The backlight_* functions must be present in the API regardless whether
290 * HAVE_BACKLIGHT is defined or not. The reason is that the stock Ondio has
291 * no backlight but can be modded to have backlight (it's prepared on the
292 * PCB). This makes backlight an all-target feature API wise, and keeps API
293 * compatible between stock and modded Ondio.
294 * For OLED targets like the Sansa Clip, the backlight_* functions control
295 * the display enable, which has essentially the same effect. */
296 void (*backlight_on
)(void);
297 void (*backlight_off
)(void);
298 void (*backlight_set_timeout
)(int index
);
299 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
300 void (*backlight_set_brightness
)(int val
);
301 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
304 void (*backlight_set_timeout_plugged
)(int index
);
306 bool (*is_backlight_on
)(bool ignore_always_off
);
307 void (*splash
)(int ticks
, const char *str
);
308 void (*splashf
)(int ticks
, const char *fmt
, ...) ATTRIBUTE_PRINTF(2, 3);
310 #ifdef HAVE_REMOTE_LCD
312 void (*lcd_remote_set_contrast
)(int x
);
313 void (*lcd_remote_clear_display
)(void);
314 void (*lcd_remote_puts
)(int x
, int y
, const unsigned char *string
);
315 void (*lcd_remote_puts_scroll
)(int x
, int y
, const unsigned char* string
);
316 void (*lcd_remote_stop_scroll
)(void);
317 void (*lcd_remote_set_drawmode
)(int mode
);
318 int (*lcd_remote_get_drawmode
)(void);
319 void (*lcd_remote_setfont
)(int font
);
320 int (*lcd_remote_getstringsize
)(const unsigned char *str
, int *w
, int *h
);
321 void (*lcd_remote_drawpixel
)(int x
, int y
);
322 void (*lcd_remote_drawline
)(int x1
, int y1
, int x2
, int y2
);
323 void (*lcd_remote_hline
)(int x1
, int x2
, int y
);
324 void (*lcd_remote_vline
)(int x
, int y1
, int y2
);
325 void (*lcd_remote_drawrect
)(int x
, int y
, int nx
, int ny
);
326 void (*lcd_remote_fillrect
)(int x
, int y
, int nx
, int ny
);
327 void (*lcd_remote_mono_bitmap_part
)(const unsigned char *src
, int src_x
,
328 int src_y
, int stride
, int x
, int y
,
329 int width
, int height
);
330 void (*lcd_remote_mono_bitmap
)(const unsigned char *src
, int x
, int y
,
331 int width
, int height
);
332 void (*lcd_remote_putsxy
)(int x
, int y
, const unsigned char *string
);
333 void (*lcd_remote_puts_style
)(int x
, int y
, const unsigned char *str
, int style
);
334 void (*lcd_remote_puts_scroll_style
)(int x
, int y
, const unsigned char* string
,
336 fb_remote_data
* lcd_remote_framebuffer
;
337 void (*lcd_remote_update
)(void);
338 void (*lcd_remote_update_rect
)(int x
, int y
, int width
, int height
);
340 void (*remote_backlight_on
)(void);
341 void (*remote_backlight_off
)(void);
342 void (*remote_backlight_set_timeout
)(int index
);
344 void (*remote_backlight_set_timeout_plugged
)(int index
);
346 #endif /* HAVE_REMOTE_LCD */
347 struct screen
* screens
[NB_SCREENS
];
348 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
349 void (*lcd_remote_set_foreground
)(unsigned foreground
);
350 unsigned (*lcd_remote_get_foreground
)(void);
351 void (*lcd_remote_set_background
)(unsigned background
);
352 unsigned (*lcd_remote_get_background
)(void);
353 void (*lcd_remote_bitmap_part
)(const fb_remote_data
*src
,
354 int src_x
, int src_y
, int stride
,
355 int x
, int y
, int width
, int height
);
356 void (*lcd_remote_bitmap
)(const fb_remote_data
*src
, int x
, int y
,
357 int width
, int height
);
359 void (*viewport_set_defaults
)(struct viewport
*vp
,
360 const enum screen_type screen
);
361 #ifdef HAVE_LCD_BITMAP
362 void (*viewportmanager_theme_enable
)(enum screen_type screen
, bool enable
,
363 struct viewport
*viewport
);
364 void (*viewportmanager_theme_undo
)(enum screen_type screen
, bool force_redraw
);
367 void (*gui_synclist_init
)(struct gui_synclist
* lists
,
368 list_get_name callback_get_item_name
, void * data
,
369 bool scroll_all
,int selected_size
,
370 struct viewport parent
[NB_SCREENS
]);
371 void (*gui_synclist_set_nb_items
)(struct gui_synclist
* lists
, int nb_items
);
372 void (*gui_synclist_set_icon_callback
)(struct gui_synclist
* lists
,
373 list_get_icon icon_callback
);
374 int (*gui_synclist_get_nb_items
)(struct gui_synclist
* lists
);
375 int (*gui_synclist_get_sel_pos
)(struct gui_synclist
* lists
);
376 void (*gui_synclist_draw
)(struct gui_synclist
* lists
);
377 void (*gui_synclist_select_item
)(struct gui_synclist
* lists
,
379 void (*gui_synclist_add_item
)(struct gui_synclist
* lists
);
380 void (*gui_synclist_del_item
)(struct gui_synclist
* lists
);
381 void (*gui_synclist_limit_scroll
)(struct gui_synclist
* lists
, bool scroll
);
382 bool (*gui_synclist_do_button
)(struct gui_synclist
* lists
,
383 int *action
, enum list_wrap wrap
);
384 void (*gui_synclist_set_title
)(struct gui_synclist
*lists
, char* title
,
385 enum themable_icons icon
);
386 enum yesno_res (*gui_syncyesno_run
)(const struct text_message
* main_message
,
387 const struct text_message
* yes_message
,
388 const struct text_message
* no_message
);
389 void (*simplelist_info_init
)(struct simplelist_info
*info
, char* title
,
390 int count
, void* data
);
391 bool (*simplelist_show_list
)(struct simplelist_info
*info
);
394 long (*button_get
)(bool block
);
395 long (*button_get_w_tmo
)(int ticks
);
396 int (*button_status
)(void);
397 #ifdef HAVE_BUTTON_DATA
398 intptr_t (*button_get_data
)(void);
399 int (*button_status_wdata
)(int *pdata
);
401 void (*button_clear_queue
)(void);
402 int (*button_queue_count
)(void);
403 #ifdef HAS_BUTTON_HOLD
404 bool (*button_hold
)(void);
406 #ifdef HAVE_TOUCHSCREEN
407 void (*touchscreen_set_mode
)(enum touchscreen_mode
);
409 #ifdef HAVE_BUTTON_LIGHT
410 void (*buttonlight_set_timeout
)(int value
);
411 void (*buttonlight_off
)(void);
412 void (*buttonlight_on
)(void);
413 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
414 void (*buttonlight_set_brightness
)(int val
);
415 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
416 #endif /* HAVE_BUTTON_LIGHT */
419 int (*open_utf8
)(const char* pathname
, int flags
);
420 int (*open
)(const char* pathname
, int flags
, ...);
421 int (*close
)(int fd
);
422 ssize_t (*read
)(int fd
, void* buf
, size_t count
);
423 off_t (*lseek
)(int fd
, off_t offset
, int whence
);
424 int (*creat
)(const char *pathname
, mode_t mode
);
425 ssize_t (*write
)(int fd
, const void* buf
, size_t count
);
426 int (*remove
)(const char* pathname
);
427 int (*rename
)(const char* path
, const char* newname
);
428 int (*ftruncate
)(int fd
, off_t length
);
429 off_t (*filesize
)(int fd
);
430 int (*fdprintf
)(int fd
, const char *fmt
, ...) ATTRIBUTE_PRINTF(2, 3);
431 int (*read_line
)(int fd
, char* buffer
, int buffer_size
);
432 bool (*settings_parseline
)(char* line
, char** name
, char** value
);
433 void (*storage_sleep
)(void);
434 void (*storage_spin
)(void);
435 void (*storage_spindown
)(int seconds
);
436 #if USING_STORAGE_CALLBACK
437 void (*register_storage_idle_func
)(void (*function
)(void *data
));
438 void (*unregister_storage_idle_func
)(void (*function
)(void *data
), bool run
);
439 #endif /* USING_STORAGE_CALLBACK */
440 void (*reload_directory
)(void);
441 char *(*create_numbered_filename
)(char *buffer
, const char *path
,
442 const char *prefix
, const char *suffix
,
443 int numberlen
IF_CNFN_NUM_(, int *num
));
444 bool (*file_exists
)(const char *file
);
445 char* (*strip_extension
)(char* buffer
, int buffer_size
, const char *filename
);
446 unsigned (*crc_32
)(const void *src
, unsigned len
, unsigned crc32
);
448 int (*filetype_get_attr
)(const char* file
);
453 DIR* (*opendir
)(const char* name
);
454 int (*closedir
)(DIR* dir
);
455 struct dirent
* (*readdir
)(DIR* dir
);
456 int (*mkdir
)(const char *name
);
457 int (*rmdir
)(const char *name
);
458 bool (*dir_exists
)(const char *path
);
459 struct dirinfo (*dir_get_info
)(DIR* parent
, struct dirent
*entry
);
462 void (*browse_context_init
)(struct browse_context
*browse
,
463 int dirfilter
, unsigned flags
,
464 char *title
, enum themable_icons icon
,
465 const char *root
, const char *selected
);
466 int (*rockbox_browse
)(struct browse_context
*browse
);
469 #if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
470 void (*__div0
)(void);
472 unsigned (*sleep
)(unsigned ticks
);
474 volatile long* current_tick
;
475 long (*default_event_handler
)(long event
);
476 long (*default_event_handler_ex
)(long event
,
477 void (*callback
)(void *), void *parameter
);
478 unsigned int (*create_thread
)(void (*function
)(void), void* stack
,
479 size_t stack_size
, unsigned flags
,
481 IF_PRIO(, int priority
)
482 IF_COP(, unsigned int core
));
483 unsigned int (*thread_self
)(void);
484 void (*thread_exit
)(void);
485 void (*thread_wait
)(unsigned int thread_id
);
486 #if CONFIG_CODEC == SWCODEC
487 void (*thread_thaw
)(unsigned int thread_id
);
488 #ifdef HAVE_PRIORITY_SCHEDULING
489 int (*thread_set_priority
)(unsigned int thread_id
, int priority
);
491 void (*mutex_init
)(struct mutex
*m
);
492 void (*mutex_lock
)(struct mutex
*m
);
493 void (*mutex_unlock
)(struct mutex
*m
);
496 void (*reset_poweroff_timer
)(void);
497 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
498 int (*system_memory_guard
)(int newmode
);
500 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
501 #ifdef CPU_BOOST_LOGGING
502 void (*cpu_boost_
)(bool on_off
,char*location
,int line
);
504 void (*cpu_boost
)(bool on_off
);
506 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
507 #endif /* PLATFORM_NATIVE */
508 #ifdef HAVE_SCHEDULER_BOOSTCTRL
509 void (*trigger_cpu_boost
)(void);
510 void (*cancel_cpu_boost
)(void);
513 void (*cpucache_flush
)(void);
514 void (*cpucache_invalidate
)(void);
516 /* load code api for overlay */
517 void* (*lc_open
)(const char *filename
, unsigned char *buf
, size_t buf_size
);
518 void* (*lc_open_from_mem
)(void* addr
, size_t blob_size
);
519 void* (*lc_get_header
)(void *handle
);
520 void (*lc_close
)(void *handle
);
522 bool (*timer_register
)(int reg_prio
, void (*unregister_callback
)(void),
523 long cycles
, void (*timer_callback
)(void)
525 void (*timer_unregister
)(void);
526 bool (*timer_set_period
)(long count
);
528 void (*queue_init
)(struct event_queue
*q
, bool register_queue
);
529 void (*queue_delete
)(struct event_queue
*q
);
530 void (*queue_post
)(struct event_queue
*q
, long id
, intptr_t data
);
531 void (*queue_wait_w_tmo
)(struct event_queue
*q
, struct queue_event
*ev
,
533 #if CONFIG_CODEC == SWCODEC
534 void (*queue_enable_queue_send
)(struct event_queue
*q
,
535 struct queue_sender_list
*send
,
536 unsigned int thread_id
);
537 bool (*queue_empty
)(const struct event_queue
*q
);
538 void (*queue_wait
)(struct event_queue
*q
, struct queue_event
*ev
);
539 intptr_t (*queue_send
)(struct event_queue
*q
, long id
,
541 void (*queue_reply
)(struct event_queue
*q
, intptr_t retval
);
542 #endif /* CONFIG_CODEC == SWCODEC */
544 void (*usb_acknowledge
)(long id
);
545 #ifdef USB_ENABLE_HID
546 void (*usb_hid_send
)(usage_page_t usage_page
, int id
);
549 void (*profile_thread
)(void);
550 void (*profstop
)(void);
551 void (*profile_func_enter
)(void *this_fn
, void *call_site
);
552 void (*profile_func_exit
)(void *this_fn
, void *call_site
);
555 bool (*add_event
)(unsigned short id
, bool oneshot
, void (*handler
)(void *data
));
556 void (*remove_event
)(unsigned short id
, void (*handler
)(void *data
));
557 void (*send_event
)(unsigned short id
, void *data
);
559 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
560 /* special simulator hooks */
561 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
562 void (*sim_lcd_ex_init
)(unsigned long (*getpixel
)(int, int));
563 void (*sim_lcd_ex_update_rect
)(int x
, int y
, int width
, int height
);
567 /* strings and memory */
568 int (*snprintf
)(char *buf
, size_t size
, const char *fmt
, ...)
569 ATTRIBUTE_PRINTF(3, 4);
570 int (*vsnprintf
)(char *buf
, size_t size
, const char *fmt
, va_list ap
);
571 char* (*strcpy
)(char *dst
, const char *src
);
572 size_t (*strlcpy
)(char *dst
, const char *src
, size_t length
);
573 size_t (*strlen
)(const char *str
);
574 char * (*strrchr
)(const char *s
, int c
);
575 int (*strcmp
)(const char *, const char *);
576 int (*strncmp
)(const char *, const char *, size_t);
577 int (*strcasecmp
)(const char *, const char *);
578 int (*strncasecmp
)(const char *s1
, const char *s2
, size_t n
);
579 void* (*memset
)(void *dst
, int c
, size_t length
);
580 void* (*memcpy
)(void *out
, const void *in
, size_t n
);
581 void* (*memmove
)(void *out
, const void *in
, size_t n
);
582 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
583 const unsigned char *_rbctype_
;
585 int (*atoi
)(const char *str
);
586 char *(*strchr
)(const char *s
, int c
);
587 char *(*strcat
)(char *s1
, const char *s2
);
588 size_t (*strlcat
)(char *dst
, const char *src
, size_t length
);
589 void *(*memchr
)(const void *s1
, int c
, size_t n
);
590 int (*memcmp
)(const void *s1
, const void *s2
, size_t n
);
591 char *(*strcasestr
) (const char* phaystack
, const char* pneedle
);
592 char* (*strtok_r
)(char *ptr
, const char *sep
, char **end
);
594 const unsigned char* (*utf8decode
)(const unsigned char *utf8
, unsigned short *ucs
);
595 unsigned char* (*iso_decode
)(const unsigned char *iso
, unsigned char *utf8
, int cp
, int count
);
596 unsigned char* (*utf16LEdecode
)(const unsigned char *utf16
, unsigned char *utf8
, int count
);
597 unsigned char* (*utf16BEdecode
)(const unsigned char *utf16
, unsigned char *utf8
, int count
);
598 unsigned char* (*utf8encode
)(unsigned long ucs
, unsigned char *utf8
);
599 unsigned long (*utf8length
)(const unsigned char *utf8
);
600 int (*utf8seek
)(const unsigned char* utf8
, int offset
);
603 void (*sound_set
)(int setting
, int value
);
604 int (*sound_default
)(int setting
);
605 int (*sound_min
)(int setting
);
606 int (*sound_max
)(int setting
);
607 const char * (*sound_unit
)(int setting
);
608 int (*sound_val2phys
)(int setting
, int value
);
609 #ifdef AUDIOHW_HAVE_EQ
610 int (*sound_enum_hw_eq_band_setting
)(unsigned int band
,
611 unsigned int band_setting
);
612 #endif /* AUDIOHW_HAVE_EQ */
613 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
614 void (*mp3_play_data
)(const unsigned char* start
, int size
,
615 void (*get_more
)(unsigned char** start
, size_t* size
));
616 void (*mp3_play_pause
)(bool play
);
617 void (*mp3_play_stop
)(void);
618 bool (*mp3_is_playing
)(void);
619 #if CONFIG_CODEC != SWCODEC
620 void (*bitswap
)(unsigned char *data
, int length
);
622 #endif /* PLATFORM_NATIVE */
623 #if CONFIG_CODEC == SWCODEC
624 const unsigned long *audio_master_sampr_list
;
625 const unsigned long *hw_freq_sampr
;
626 void (*pcm_apply_settings
)(void);
627 void (*pcm_play_data
)(pcm_play_callback_type get_more
,
628 unsigned char* start
, size_t size
);
629 void (*pcm_play_stop
)(void);
630 void (*pcm_set_frequency
)(unsigned int frequency
);
631 bool (*pcm_is_playing
)(void);
632 bool (*pcm_is_paused
)(void);
633 void (*pcm_play_pause
)(bool play
);
634 size_t (*pcm_get_bytes_waiting
)(void);
635 void (*pcm_calculate_peaks
)(int *left
, int *right
);
636 const void* (*pcm_get_peak_buffer
)(int *count
);
637 void (*pcm_play_lock
)(void);
638 void (*pcm_play_unlock
)(void);
639 void (*beep_play
)(unsigned int frequency
, unsigned int duration
,
640 unsigned int amplitude
);
641 #ifdef HAVE_RECORDING
642 const unsigned long *rec_freq_sampr
;
643 void (*pcm_init_recording
)(void);
644 void (*pcm_close_recording
)(void);
645 void (*pcm_record_data
)(pcm_rec_callback_type more_ready
,
646 void *start
, size_t size
);
647 void (*pcm_stop_recording
)(void);
648 void (*pcm_calculate_rec_peaks
)(int *left
, int *right
);
649 void (*audio_set_recording_gain
)(int left
, int right
, int type
);
650 #endif /* HAVE_RECORDING */
651 #if INPUT_SRC_CAPS != 0
652 void (*audio_set_output_source
)(int monitor
);
653 void (*audio_set_input_source
)(int source
, unsigned flags
);
655 void (*dsp_set_crossfeed
)(bool enable
);
656 void (*dsp_set_eq
)(bool enable
);
657 void (*dsp_dither_enable
)(bool enable
);
658 intptr_t (*dsp_configure
)(struct dsp_config
*dsp
, int setting
,
660 int (*dsp_process
)(struct dsp_config
*dsp
, char *dest
,
661 const char *src
[], int count
);
662 int (*dsp_input_count
)(struct dsp_config
*dsp
, int count
);
663 int (*dsp_output_count
)(struct dsp_config
*dsp
, int count
);
665 enum channel_status (*mixer_channel_status
)(enum pcm_mixer_channel channel
);
666 void * (*mixer_channel_get_buffer
)(enum pcm_mixer_channel channel
, int *count
);
667 void (*mixer_channel_calculate_peaks
)(enum pcm_mixer_channel channel
,
668 int *left
, int *right
);
669 void (*mixer_channel_play_data
)(enum pcm_mixer_channel channel
,
670 pcm_play_callback_type get_more
,
671 unsigned char *start
, size_t size
);
672 void (*mixer_channel_play_pause
)(enum pcm_mixer_channel channel
, bool play
);
673 void (*mixer_channel_stop
)(enum pcm_mixer_channel channel
);
674 void (*mixer_channel_set_amplitude
)(enum pcm_mixer_channel channel
,
675 unsigned int amplitude
);
676 size_t (*mixer_channel_get_bytes_waiting
)(enum pcm_mixer_channel channel
);
678 void (*system_sound_play
)(enum system_sound sound
);
679 void (*keyclick_click
)(int button
);
680 #endif /* CONFIG_CODEC == SWCODC */
682 /* playback control */
683 int (*playlist_amount
)(void);
684 int (*playlist_resume
)(void);
685 void (*playlist_start
)(int start_index
, int offset
);
686 int (*playlist_add
)(const char *filename
);
687 void (*playlist_sync
)(struct playlist_info
* playlist
);
688 int (*playlist_remove_all_tracks
)(struct playlist_info
*playlist
);
689 int (*playlist_create
)(const char *dir
, const char *file
);
690 int (*playlist_insert_track
)(struct playlist_info
* playlist
,
691 const char *filename
, int position
, bool queue
, bool sync
);
692 int (*playlist_insert_directory
)(struct playlist_info
* playlist
,
693 const char *dirname
, int position
, bool queue
,
695 int (*playlist_shuffle
)(int random_seed
, int start_index
);
696 void (*audio_play
)(long offset
);
697 void (*audio_stop
)(void);
698 void (*audio_pause
)(void);
699 void (*audio_resume
)(void);
700 void (*audio_next
)(void);
701 void (*audio_prev
)(void);
702 void (*audio_ff_rewind
)(long newtime
);
703 struct mp3entry
* (*audio_next_track
)(void);
704 int (*audio_status
)(void);
705 struct mp3entry
* (*audio_current_track
)(void);
706 void (*audio_flush_and_reload_tracks
)(void);
707 int (*audio_get_file_pos
)(void);
708 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
709 unsigned long (*mpeg_get_last_header
)(void);
711 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
712 (CONFIG_CODEC == SWCODEC)) && defined (HAVE_PITCHSCREEN)
713 void (*sound_set_pitch
)(int32_t pitch
);
716 /* MAS communication */
717 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
718 int (*mas_readmem
)(int bank
, int addr
, unsigned long* dest
, int len
);
719 int (*mas_writemem
)(int bank
, int addr
, const unsigned long* src
, int len
);
720 int (*mas_readreg
)(int reg
);
721 int (*mas_writereg
)(int reg
, unsigned int val
);
722 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
723 int (*mas_codec_writereg
)(int reg
, unsigned int val
);
724 int (*mas_codec_readreg
)(int reg
);
725 void (*i2c_begin
)(void);
726 void (*i2c_end
)(void);
727 int (*i2c_write
)(int address
, const unsigned char* buf
, int count
);
732 int (*do_menu
)(const struct menu_item_ex
*menu
, int *start_selected
,
733 struct viewport parent
[NB_SCREENS
], bool hide_theme
);
736 struct gui_syncstatusbar
*statusbars
;
737 void (*gui_syncstatusbar_draw
)(struct gui_syncstatusbar
* bars
, bool force_redraw
);
740 const struct settings_list
* (*get_settings_list
)(int*count
);
741 const struct settings_list
* (*find_setting
)(const void* variable
, int *id
);
742 bool (*option_screen
)(const struct settings_list
*setting
,
743 struct viewport parent
[NB_SCREENS
],
744 bool use_temp_var
, unsigned char* option_title
);
745 bool (*set_option
)(const char* string
, const void* variable
,
746 enum optiontype type
, const struct opt_items
* options
,
747 int numoptions
, void (*function
)(int));
748 bool (*set_bool_options
)(const char* string
, const bool* variable
,
749 const char* yes_str
, int yes_voice
,
750 const char* no_str
, int no_voice
,
751 void (*function
)(bool));
752 bool (*set_int
)(const unsigned char* string
, const char* unit
, int voice_unit
,
753 const int* variable
, void (*function
)(int), int step
,
755 const char* (*formatter
)(char*, size_t, int, const char*) );
756 bool (*set_bool
)(const char* string
, const bool* variable
);
758 #ifdef HAVE_LCD_COLOR
759 bool (*set_color
)(struct screen
*display
, char *title
,
760 unsigned *color
, unsigned banned_color
);
762 /* action handling */
763 int (*get_custom_action
)(int context
,int timeout
,
764 const struct button_mapping
* (*get_context_map
)(int));
765 int (*get_action
)(int context
, int timeout
);
766 #ifdef HAVE_TOUCHSCREEN
767 int (*action_get_touchscreen_press
)(short *x
, short *y
);
769 bool (*action_userabort
)(int timeout
);
772 int (*battery_level
)(void);
773 bool (*battery_level_safe
)(void);
774 int (*battery_time
)(void);
775 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
776 unsigned int (*battery_voltage
)(void);
779 bool (*charger_inserted
)(void);
780 # if CONFIG_CHARGING >= CHARGING_MONITOR
781 bool (*charging_state
)(void);
784 #ifdef HAVE_USB_POWER
785 bool (*usb_powered
)(void);
789 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
792 void (*srand
)(unsigned int seed
);
794 void (*qsort
)(void *base
, size_t nmemb
, size_t size
,
795 int(*compar
)(const void *, const void *));
796 int (*kbd_input
)(char* buffer
, int buflen
);
797 struct tm
* (*get_time
)(void);
798 int (*set_time
)(const struct tm
*tm
);
800 time_t (*mktime
)(struct tm
*t
);
802 void* (*plugin_get_buffer
)(size_t *buffer_size
);
803 void* (*plugin_get_audio_buffer
)(size_t *buffer_size
);
804 void (*plugin_tsr
)(bool (*exit_callback
)(bool reenter
));
805 char* (*plugin_get_current_filename
)(void);
806 #if defined(DEBUG) || defined(SIMULATOR)
807 void (*debugf
)(const char *fmt
, ...) ATTRIBUTE_PRINTF(1, 2);
809 #ifdef ROCKBOX_HAS_LOGF
810 void (*logf
)(const char *fmt
, ...) ATTRIBUTE_PRINTF(1, 2);
812 struct user_settings
* global_settings
;
813 struct system_status
*global_status
;
814 void (*talk_disable
)(bool disable
);
815 #if CONFIG_CODEC == SWCODEC
816 void (*codec_thread_do_callback
)(void (*fn
)(void),
817 unsigned int *audio_thread_id
);
818 int (*codec_load_file
)(const char* codec
, struct codec_api
*api
);
819 int (*codec_run_proc
)(void);
820 int (*codec_close
)(void);
821 const char *(*get_codec_filename
)(int cod_spec
);
822 void ** (*find_array_ptr
)(void **arr
, void *ptr
);
823 int (*remove_array_ptr
)(void **arr
, void *ptr
);
824 int (*round_value_to_list32
)(unsigned long value
,
825 const unsigned long list
[],
828 #endif /* CONFIG_CODEC == SWCODEC */
829 bool (*get_metadata
)(struct mp3entry
* id3
, int fd
, const char* trackname
);
830 bool (*mp3info
)(struct mp3entry
*entry
, const char *filename
);
831 int (*count_mp3_frames
)(int fd
, int startpos
, int filesize
,
832 void (*progressfunc
)(int),
833 unsigned char* buf
, size_t buflen
);
834 int (*create_xing_header
)(int fd
, long startpos
, long filesize
,
835 unsigned char *buf
, unsigned long num_frames
,
836 unsigned long rec_time
, unsigned long header_template
,
837 void (*progressfunc
)(int), bool generate_toc
,
838 unsigned char* tempbuf
, size_t tempbuf_len
);
839 unsigned long (*find_next_frame
)(int fd
, long *offset
,
840 long max_offset
, unsigned long reference_header
);
842 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
843 unsigned short (*peak_meter_scale_value
)(unsigned short val
,
845 void (*peak_meter_set_use_dbfs
)(bool use
);
846 bool (*peak_meter_get_use_dbfs
)(void);
848 #ifdef HAVE_LCD_BITMAP
849 int (*read_bmp_file
)(const char* filename
, struct bitmap
*bm
, int maxsize
,
850 int format
, const struct custom_format
*cformat
);
851 int (*read_bmp_fd
)(int fd
, struct bitmap
*bm
, int maxsize
,
852 int format
, const struct custom_format
*cformat
);
854 int (*read_jpeg_file
)(const char* filename
, struct bitmap
*bm
, int maxsize
,
855 int format
, const struct custom_format
*cformat
);
856 int (*read_jpeg_fd
)(int fd
, struct bitmap
*bm
, int maxsize
,
857 int format
, const struct custom_format
*cformat
);
859 void (*screen_dump_set_hook
)(void (*hook
)(int fh
));
861 int (*show_logo
)(void);
862 struct tree_context
* (*tree_get_context
)(void);
863 void (*set_current_file
)(const char* path
);
864 void (*set_dirfilter
)(int l_dirfilter
);
866 #ifdef HAVE_WHEEL_POSITION
867 int (*wheel_status
)(void);
868 void (*wheel_send_events
)(bool send
);
871 #ifdef IRIVER_H100_SERIES
872 /* Routines for the iriver_flash -plugin. */
873 bool (*detect_original_firmware
)(void);
874 bool (*detect_flashed_ramimage
)(void);
875 bool (*detect_flashed_romimage
)(void);
878 void (*led
)(bool on
);
880 #if (CONFIG_CODEC == SWCODEC)
882 int (*bufopen
)(const char *file
, size_t offset
, enum data_type type
,
884 int (*bufalloc
)(const void *src
, size_t size
, enum data_type type
);
885 bool (*bufclose
)(int handle_id
);
886 int (*bufseek
)(int handle_id
, size_t newpos
);
887 int (*bufadvance
)(int handle_id
, off_t offset
);
888 ssize_t (*bufread
)(int handle_id
, size_t size
, void *dest
);
889 ssize_t (*bufgetdata
)(int handle_id
, size_t size
, void **data
);
890 ssize_t (*bufgettail
)(int handle_id
, size_t size
, void **data
);
891 ssize_t (*bufcuttail
)(int handle_id
, size_t size
);
893 ssize_t (*buf_handle_offset
)(int handle_id
);
894 void (*buf_set_base_handle
)(int handle_id
);
895 size_t (*buf_used
)(void);
899 bool (*tagcache_search
)(struct tagcache_search
*tcs
, int tag
);
900 void (*tagcache_search_set_uniqbuf
)(struct tagcache_search
*tcs
,
901 void *buffer
, long length
);
902 bool (*tagcache_search_add_filter
)(struct tagcache_search
*tcs
,
904 bool (*tagcache_get_next
)(struct tagcache_search
*tcs
);
905 bool (*tagcache_retrieve
)(struct tagcache_search
*tcs
, int idxid
,
906 int tag
, char *buf
, long size
);
907 void (*tagcache_search_finish
)(struct tagcache_search
*tcs
);
908 long (*tagcache_get_numeric
)(const struct tagcache_search
*tcs
, int tag
);
909 #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
910 bool (*tagcache_fill_tags
)(struct mp3entry
*id3
, const char *filename
);
915 bool (*search_albumart_files
)(const struct mp3entry
*id3
, const char *size_string
,
916 char *buf
, int buflen
);
919 #ifdef HAVE_SEMAPHORE_OBJECTS
920 void (*semaphore_init
)(struct semaphore
*s
, int max
, int start
);
921 int (*semaphore_wait
)(struct semaphore
*s
, int timeout
);
922 void (*semaphore_release
)(struct semaphore
*s
);
925 const char *rbversion
;
927 /* new stuff at the end, sort into place next time
928 the API gets incompatible */
929 struct entry
* (*tree_get_entries
)(struct tree_context
* t
);
930 struct entry
* (*tree_get_entry_at
)(struct tree_context
* t
, int index
);
934 struct plugin_header
{
935 struct lc_header lc_hdr
; /* must be the first */
936 enum plugin_status(*entry_point
)(const void*);
937 const struct plugin_api
**api
;
941 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
942 extern unsigned char plugin_start_addr
[];
943 extern unsigned char plugin_end_addr
[];
944 #define PLUGIN_HEADER \
945 const struct plugin_api *rb DATA_ATTR; \
946 const struct plugin_header __header \
947 __attribute__ ((section (".header")))= { \
948 { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
949 plugin_start_addr, plugin_end_addr }, plugin__start, &rb };
950 #else /* PLATFORM_HOSTED */
951 #define PLUGIN_HEADER \
952 const struct plugin_api *rb DATA_ATTR; \
953 const struct plugin_header __header \
954 __attribute__((visibility("default"))) = { \
955 { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, NULL, NULL }, \
956 plugin__start, &rb };
957 #endif /* CONFIG_PLATFORM */
960 int plugin_load(const char* plugin
, const void* parameter
);
961 void* plugin_get_audio_buffer(size_t *buffer_size
);
964 callback returns true to allow the new plugin to load,
965 reenter means the currently running plugin is being reloaded */
966 void plugin_tsr(bool (*exit_callback
)(bool reenter
));
968 /* defined by the plugin */
969 extern const struct plugin_api
*rb
;
970 enum plugin_status
plugin__start(const void* parameter
)
973 #endif /* __PCTOOL__ */