A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
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 _PLUGIN_H_
22#define _PLUGIN_H_
23
24/* instruct simulator code to not redefine any symbols when compiling plugins.
25 (the PLUGIN macro is defined in apps/plugins/Makefile) */
26#ifdef PLUGIN
27#define NO_REDEFINES_PLEASE
28#endif
29
30#include <stdbool.h>
31#include <inttypes.h>
32#include <sys/types.h>
33#include <stdarg.h>
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37#include <ctype.h>
38#include "string-extra.h"
39#include "gcc_extensions.h"
40
41
42
43/* on some platforms strcmp() seems to be a tricky define which
44 * breaks if we write down strcmp's prototype */
45#undef strcmp
46#undef strncmp
47#undef strchr
48#undef strtok_r
49#ifdef __APPLE__
50#undef strncpy
51#undef snprintf
52#undef strcpy
53#undef strcat
54#undef memset
55#undef memcpy
56#undef memmove
57#undef vsnprintf
58#undef vsprintf
59#endif
60
61#define splash(__ticks, __str) splashf(__ticks, __str)
62
63char* strncpy(char *, const char *, size_t);
64void* plugin_get_buffer(size_t *buffer_size);
65size_t plugin_reserve_buffer(size_t buffer_size);
66int plugin_open(const char *plugin, const char *parameter);
67
68#ifndef __PCTOOL__
69#include "config.h"
70#include "system.h"
71#include "dir.h"
72#include "general.h"
73#include "kernel.h"
74#include "thread.h"
75#include "button.h"
76#include "action.h"
77#include "load_code.h"
78#include "usb.h"
79#include "font.h"
80#include "lcd.h"
81#include "scroll_engine.h"
82#include "metadata.h"
83#include "sound.h"
84#include "audio.h"
85#include "voice_thread.h"
86#include "root_menu.h"
87#include "talk.h"
88#include "lang_enum.h"
89#ifdef RB_PROFILE
90#include "profile.h"
91#endif
92#include "misc.h"
93#include "pathfuncs.h"
94#include "pcm_mixer.h"
95#include "dsp-util.h"
96#include "dsp_core.h"
97#include "dsp_proc_settings.h"
98#include "codecs.h"
99#include "playback.h"
100#include "codec_thread.h"
101#ifdef HAVE_RECORDING
102#include "recording.h"
103#endif
104#include "settings.h"
105#include "timer.h"
106#include "playlist.h"
107#include "screendump.h"
108#include "scrollbar.h"
109#include "jpeg_load.h"
110#include "../recorder/bmp.h"
111#include "menu.h"
112#include "rbunicode.h"
113#include "list.h"
114#include "tree.h"
115#include "color_picker.h"
116#include "buflib.h"
117#include "buffering.h"
118#include "tagcache.h"
119#include "tagtree.h"
120#include "viewport.h"
121#include "ata_idle_notify.h"
122#include "settings_list.h"
123#include "timefuncs.h"
124#include "crc32.h"
125#include "rbpaths.h"
126#include "core_alloc.h"
127#include "screen_access.h"
128#include "onplay.h"
129#include "screens.h"
130#include "vuprintf.h"
131
132#ifdef HAVE_ALBUMART
133#include "albumart.h"
134#endif
135
136#ifdef HAVE_REMOTE_LCD
137#include "lcd-remote.h"
138#endif
139
140#include "yesno.h"
141
142#include "filetypes.h"
143
144#ifdef USB_ENABLE_HID
145#include "usbstack/usb_hid_usage_tables.h"
146#endif
147
148
149#ifdef PLUGIN
150
151#if defined(DEBUG) || defined(SIMULATOR)
152#undef DEBUGF
153#define DEBUGF rb->debugf
154#undef LDEBUGF
155#define LDEBUGF rb->debugf
156#else
157#undef DEBUGF
158#define DEBUGF(...) do { } while(0)
159#undef LDEBUGF
160#define LDEBUGF(...) do { } while(0)
161#endif
162
163#ifdef ROCKBOX_HAS_LOGF
164#undef LOGF
165#define LOGF rb->logf
166#else
167#define LOGF(...)
168#endif
169
170#endif
171
172#define PLUGIN_MAGIC 0x526F634B /* RocK */
173
174/*
175 * Increment this whenever a change breaks the plugin ABI,
176 * when this happens please take the opportunity to sort in
177 * any new functions "waiting" at the end of the list.
178 */
179#define PLUGIN_API_VERSION 274
180
181/* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */
182
183/* plugin return codes */
184/* internal returns start at 0x100 to make exit(1..255) work */
185#define INTERNAL_PLUGIN_RETVAL_START 0x100
186enum plugin_status {
187 PLUGIN_OK = 0, /* PLUGIN_OK == EXIT_SUCCESS */
188 /* 1...255 reserved for exit() */
189 PLUGIN_USB_CONNECTED = INTERNAL_PLUGIN_RETVAL_START,
190 PLUGIN_POWEROFF,
191 PLUGIN_GOTO_WPS,
192 PLUGIN_GOTO_PLUGIN,
193 PLUGIN_ERROR = -1,
194};
195
196enum plugin_tsr_status {
197 PLUGIN_TSR_CONTINUE = 0, /* TSR continues running */
198 PLUGIN_TSR_SUSPEND, /* TSR exits but will restart later */
199 PLUGIN_TSR_TERMINATE, /* TSR exits and will not be restarted */
200};
201
202/* NOTE: To support backwards compatibility, only add new functions at
203 the end of the structure. Every time you add a new function,
204 remember to increase PLUGIN_API_VERSION. If you make changes to the
205 existing APIs then also update PLUGIN_MIN_API_VERSION to current
206 version
207 */
208struct plugin_api {
209 const char *rbversion;
210 struct user_settings* global_settings;
211 struct system_status *global_status;
212 unsigned char **language_strings;
213 const struct cbmp_bitmap_info_entry *core_bitmaps;
214
215 /* lcd */
216 void (*splashf)(int ticks, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
217 void (*splash_progress)(int current, int total, const char *fmt, ...) ATTRIBUTE_PRINTF(3, 4);
218 void (*splash_progress_set_delay)(long delay_ticks);
219#ifdef HAVE_LCD_CONTRAST
220 void (*lcd_set_contrast)(int x);
221#endif
222 void (*lcd_update)(void);
223 void (*lcd_clear_display)(void);
224 int (*lcd_getstringsize)(const unsigned char *str, int *w, int *h);
225 void (*lcd_putsxy)(int x, int y, const unsigned char *string);
226 void (*lcd_putsxyf)(int x, int y, const unsigned char *fmt, ...);
227 void (*lcd_puts)(int x, int y, const unsigned char *string);
228 void (*lcd_putsf)(int x, int y, const unsigned char *fmt, ...);
229 bool (*lcd_puts_scroll)(int x, int y, const unsigned char* string);
230 void (*lcd_scroll_stop)(void);
231 struct viewport* (*lcd_set_viewport)(struct viewport* vp);
232 void (*lcd_bmp_part)(const struct bitmap *bm, int src_x, int src_y,
233 int x, int y, int width, int height);
234 void (*lcd_update_rect)(int x, int y, int width, int height);
235 void (*lcd_set_drawmode)(int mode);
236 int (*lcd_get_drawmode)(void);
237 void (*lcd_setfont)(int font);
238 void (*lcd_drawpixel)(int x, int y);
239 void (*lcd_drawline)(int x1, int y1, int x2, int y2);
240 void (*lcd_hline)(int x1, int x2, int y);
241 void (*lcd_vline)(int x, int y1, int y2);
242 void (*lcd_drawrect)(int x, int y, int width, int height);
243 void (*lcd_fillrect)(int x, int y, int width, int height);
244 void (*lcd_mono_bitmap_part)(const unsigned char *src, int src_x, int src_y,
245 int stride, int x, int y, int width, int height);
246 void (*lcd_mono_bitmap)(const unsigned char *src, int x, int y,
247 int width, int height);
248#if LCD_DEPTH > 1
249 void (*lcd_set_foreground)(unsigned foreground);
250 unsigned (*lcd_get_foreground)(void);
251 void (*lcd_set_background)(unsigned foreground);
252 unsigned (*lcd_get_background)(void);
253 void (*lcd_bitmap_part)(const fb_data *src, int src_x, int src_y,
254 int stride, int x, int y, int width, int height);
255 void (*lcd_bitmap)(const fb_data *src, int x, int y, int width,
256 int height);
257 fb_data* (*lcd_get_backdrop)(void);
258 void (*lcd_set_backdrop)(fb_data* backdrop);
259#endif
260#if LCD_DEPTH >= 16
261 void (*lcd_bitmap_transparent_part)(const fb_data *src,
262 int src_x, int src_y, int stride,
263 int x, int y, int width, int height);
264 void (*lcd_bitmap_transparent)(const fb_data *src, int x, int y,
265 int width, int height);
266#if MEMORYSIZE > 2
267 void (*lcd_blit_yuv)(unsigned char * const src[3],
268 int src_x, int src_y, int stride,
269 int x, int y, int width, int height);
270#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
271 || defined(IRIVER_H10) || defined(COWON_D2) || defined(PHILIPS_HDD1630) \
272 || defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(SANSA_FUZEV2) \
273 || defined(TOSHIBA_GIGABEAT_S) || defined(PHILIPS_SA9200)
274 void (*lcd_yuv_set_options)(unsigned options);
275#endif
276#endif /* MEMORYSIZE > 2 */
277#elif (LCD_DEPTH < 4) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
278 void (*lcd_blit_mono)(const unsigned char *data, int x, int by, int width,
279 int bheight, int stride);
280 void (*lcd_blit_grey_phase)(unsigned char *values, unsigned char *phases,
281 int bx, int by, int bwidth, int bheight,
282 int stride);
283#endif /* LCD_DEPTH */
284#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
285 void (*lcd_blit_pal256)(unsigned char *src, int src_x, int src_y, int x, int y,
286 int width, int height);
287 void (*lcd_pal256_update_pal)(fb_data *palette);
288#endif
289#ifdef HAVE_LCD_INVERT
290 void (*lcd_set_invert_display)(bool yesno);
291#endif /* HAVE_LCD_INVERT */
292#if defined(HAVE_LCD_MODES)
293 void (*lcd_set_mode)(int mode);
294#endif
295
296#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
297 void (*button_queue_post)(long id, intptr_t data);
298#endif
299 ucschar_t *(*bidi_l2v)(const unsigned char *str, int orientation);
300 bool (*is_diacritic)(const ucschar_t char_code, bool *is_rtl);
301 const unsigned char *(*font_get_bits)(struct font *pf, ucschar_t char_code);
302 int (*font_load)(const char *path);
303 void (*font_unload)(int font_id);
304 struct font* (*font_get)(int font);
305 int (*font_getstringsize)(const unsigned char *str, int *w, int *h,
306 int fontnumber);
307 int (*font_get_width)(struct font* pf, ucschar_t char_code);
308 void (*screen_clear_area)(struct screen * display, int xstart, int ystart,
309 int width, int height);
310 void (*gui_scrollbar_draw)(struct screen * screen, int x, int y,
311 int width, int height, int items,
312 int min_shown, int max_shown,
313 unsigned flags);
314 const char* (*get_codepage_name)(int cp);
315
316#ifdef HAVE_REMOTE_LCD
317 /* 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 bool (*lcd_remote_puts_scroll)(int x, int y, const unsigned char* string);
322 void (*lcd_remote_scroll_stop)(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_update)(void);
340 void (*lcd_remote_update_rect)(int x, int y, int width, int height);
341#if (LCD_REMOTE_DEPTH > 1)
342 void (*lcd_remote_set_foreground)(unsigned foreground);
343 unsigned (*lcd_remote_get_foreground)(void);
344 void (*lcd_remote_set_background)(unsigned background);
345 unsigned (*lcd_remote_get_background)(void);
346 void (*lcd_remote_bitmap_part)(const fb_remote_data *src,
347 int src_x, int src_y, int stride,
348 int x, int y, int width, int height);
349 void (*lcd_remote_bitmap)(const fb_remote_data *src, int x, int y,
350 int width, int height);
351#endif
352#endif /* HAVE_REMOTE_LCD */
353 struct screen* screens[NB_SCREENS];
354
355 void (*viewport_set_defaults)(struct viewport *vp,
356 const enum screen_type screen);
357 void (*viewportmanager_theme_enable)(enum screen_type screen, bool enable,
358 struct viewport *viewport);
359 void (*viewportmanager_theme_undo)(enum screen_type screen, bool force_redraw);
360 void (*viewport_set_fullscreen)(struct viewport *vp,
361 const enum screen_type screen);
362 void (*viewport_set_buffer)(struct viewport *vp, struct frame_buffer_t *buffer,
363 const enum screen_type screen);
364
365#ifdef HAVE_BACKLIGHT
366 /* lcd backlight */
367 /* For OLED targets like the Sansa Clip, the backlight_* functions control
368 * the display enable, which has essentially the same effect. */
369 bool (*is_backlight_on)(bool ignore_always_off);
370 void (*backlight_on)(void);
371 void (*backlight_off)(void);
372 void (*backlight_set_timeout)(int index);
373#ifdef HAVE_BACKLIGHT_BRIGHTNESS
374 void (*backlight_set_brightness)(int val);
375#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
376
377#if CONFIG_CHARGING
378 void (*backlight_set_timeout_plugged)(int index);
379#endif
380
381#ifdef HAVE_REMOTE_LCD
382 void (*remote_backlight_on)(void);
383 void (*remote_backlight_off)(void);
384 void (*remote_backlight_set_timeout)(int index);
385#if CONFIG_CHARGING
386 void (*remote_backlight_set_timeout_plugged)(int index);
387#endif
388#endif /* HAVE_REMOTE_LCD */
389#endif /* HAVE_BACKLIGHT */
390
391 /* list */
392 void (*gui_synclist_init)(struct gui_synclist * lists,
393 list_get_name callback_get_item_name, void * data,
394 bool scroll_all,int selected_size,
395 struct viewport parent[NB_SCREENS]);
396 void (*gui_synclist_set_nb_items)(struct gui_synclist * lists, int nb_items);
397 void (*gui_synclist_set_voice_callback)(struct gui_synclist * lists, list_speak_item voice_callback);
398 void (*gui_synclist_set_icon_callback)(struct gui_synclist * lists,
399 list_get_icon icon_callback);
400 int (*gui_synclist_get_nb_items)(struct gui_synclist * lists);
401 int (*gui_synclist_get_sel_pos)(struct gui_synclist * lists);
402 void (*gui_synclist_draw)(struct gui_synclist * lists);
403 void (*gui_synclist_speak_item)(struct gui_synclist * lists);
404 void (*gui_synclist_select_item)(struct gui_synclist * lists,
405 int item_number);
406 void (*gui_synclist_add_item)(struct gui_synclist * lists);
407 void (*gui_synclist_del_item)(struct gui_synclist * lists);
408 bool (*gui_synclist_do_button)(struct gui_synclist * lists, int *action);
409 void (*gui_synclist_set_title)(struct gui_synclist *lists, const char* title,
410 enum themable_icons icon);
411 enum yesno_res (*gui_syncyesno_run)(const struct text_message * main_message,
412 const struct text_message * yes_message,
413 const struct text_message * no_message);
414 void (*simplelist_info_init)(struct simplelist_info *info, char* title,
415 int count, void* data);
416 bool (*simplelist_show_list)(struct simplelist_info *info);
417 bool (*yesno_pop)(const char* text);
418
419 /* action handling */
420 int (*get_custom_action)(int context,int timeout,
421 const struct button_mapping* (*get_context_map)(int));
422 int (*get_action)(int context, int timeout);
423#ifdef HAVE_TOUCHSCREEN
424 int (*action_get_touchscreen_press)(short *x, short *y);
425 int (*action_get_touchscreen_press_in_vp)(short *x1, short *y1, struct viewport *vp);
426#endif
427 bool (*action_userabort)(int timeout);
428 int (*core_set_keyremap)(struct button_mapping* core_keymap, int count);
429
430 /* button */
431 long (*button_get)(bool block);
432 long (*button_get_w_tmo)(int ticks);
433 int (*button_status)(void);
434#ifdef HAVE_BUTTON_DATA
435 intptr_t (*button_get_data)(void);
436 int (*button_status_wdata)(int *pdata);
437#endif
438 void (*button_clear_queue)(void);
439 int (*button_queue_count)(void);
440#ifdef HAS_BUTTON_HOLD
441 bool (*button_hold)(void);
442#endif
443#ifdef HAVE_SW_POWEROFF
444 void (*button_set_sw_poweroff_state)(bool enable);
445 bool (*button_get_sw_poweroff_state)(void);
446#endif
447#ifdef HAVE_TOUCHSCREEN
448 void (*touchscreen_set_mode)(enum touchscreen_mode);
449 enum touchscreen_mode (*touchscreen_get_mode)(void);
450#endif
451#ifdef HAVE_BUTTON_LIGHT
452 void (*buttonlight_set_timeout)(int value);
453 void (*buttonlight_off)(void);
454 void (*buttonlight_on)(void);
455#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
456 void (*buttonlight_set_brightness)(int val);
457#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
458#endif /* HAVE_BUTTON_LIGHT */
459
460 /* file */
461 int (*open_utf8)(const char* pathname, int flags);
462 int (*open)(const char *path, int oflag, ...);
463 int (*creat)(const char *path, mode_t mode);
464 int (*close)(int fildes);
465 ssize_t (*read)(int fildes, void *buf, size_t nbyte);
466 off_t (*lseek)(int fildes, off_t offset, int whence);
467 ssize_t (*write)(int fildes, const void *buf, size_t nbyte);
468 int (*remove)(const char *path);
469 int (*rename)(const char *old, const char *new);
470 int (*ftruncate)(int fildes, off_t length);
471 off_t (*filesize)(int fildes);
472 int (*fdprintf)(int fildes, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
473 int (*read_line)(int fd, char* buffer, int buffer_size);
474 bool (*settings_parseline)(char* line, char** name, char** value);
475 void (*storage_sleep)(void);
476 void (*storage_spin)(void);
477 void (*storage_spindown)(int seconds);
478#ifdef USING_STORAGE_CALLBACK
479 void (*register_storage_idle_func)(void (*function)(void));
480 void (*unregister_storage_idle_func)(void (*function)(void), bool run);
481#endif /* USING_STORAGE_CALLBACK */
482 void (*reload_directory)(void);
483 char *(*create_numbered_filename)(char *buffer, const char *path,
484 const char *prefix, const char *suffix,
485 int numberlen IF_CNFN_NUM_(, int *num));
486 bool (*file_exists)(const char *path);
487 char* (*strip_extension)(char* buffer, int buffer_size, const char *filename);
488 uint32_t (*crc_32)(const void *src, uint32_t len, uint32_t crc32);
489 uint32_t (*crc_32r)(const void *src, uint32_t len, uint32_t crc32);
490
491 int (*filetype_get_attr)(const char* file);
492 char* (*filetype_get_plugin)(int attr, char *buffer, size_t buffer_len);
493
494 /* dir */
495 DIR * (*opendir)(const char *dirname);
496 int (*closedir)(DIR *dirp);
497 struct dirent * (*readdir)(DIR *dirp);
498 int (*mkdir)(const char *path);
499 int (*rmdir)(const char *path);
500 bool (*dir_exists)(const char *dirname);
501 struct dirinfo (*dir_get_info)(DIR *dirp, struct dirent *entry);
502
503 /* browsing */
504 int (*rockbox_browse)(struct browse_context *browse);
505 struct tree_context* (*tree_get_context)(void);
506 struct entry* (*tree_get_entries)(struct tree_context* t);
507 struct entry* (*tree_get_entry_at)(struct tree_context* t, int index);
508
509 void (*set_current_file)(const char* path);
510 void (*set_dirfilter)(int l_dirfilter);
511
512 void (*onplay_show_playlist_menu)(const char* path, int attr, void (*playlist_insert_cb));
513 void (*onplay_show_playlist_cat_menu)(const char* track_name, int attr,
514 void (*add_to_pl_cb));
515 bool (*browse_id3)(struct mp3entry *id3,
516 int playlist_display_index, int playlist_amount,
517 struct tm *modified, int track_ct,
518 int (*view_text)(const char *title, const char *text));
519
520 /* talking */
521 int (*talk_id)(int32_t id, bool enqueue);
522 int (*talk_idarray)(const long *idarray, bool enqueue);
523 int (*talk_file)(const char *root, const char *dir, const char *file,
524 const char *ext, const long *prefix_ids, bool enqueue);
525 int (*talk_file_or_spell)(const char *dirname, const char* filename,
526 const long *prefix_ids, bool enqueue);
527 int (*talk_fullpath)(const char* path, bool enqueue);
528 int (*talk_dir_or_spell)(const char* filename,
529 const long *prefix_ids, bool enqueue);
530 int (*talk_number)(long n, bool enqueue);
531 int (*talk_value_decimal)(long n, int unit, int decimals, bool enqueue);
532 int (*talk_spell)(const char* spell, bool enqueue);
533 void (*talk_time)(const struct tm *tm, bool enqueue);
534 void (*talk_date)(const struct tm *tm, bool enqueue);
535 void (*talk_disable)(bool disable);
536 void (*talk_shutup)(void);
537 void (*talk_force_shutup)(void);
538 void (*talk_force_enqueue_next)(void);
539
540 /* kernel/ system */
541#if defined(ARM_NEED_DIV0)
542 void (*__div0)(void);
543#endif
544 unsigned (*sleep)(unsigned ticks);
545 void (*yield)(void);
546 volatile long* current_tick;
547 long (*default_event_handler)(long event);
548 long (*default_event_handler_ex)(long event,
549 void (*callback)(void *), void *parameter);
550 unsigned int (*create_thread)(void (*function)(void), void* stack,
551 size_t stack_size, unsigned flags,
552 const char *name
553 IF_PRIO(, int priority)
554 IF_COP(, unsigned int core));
555 unsigned int (*thread_self)(void);
556 void (*thread_exit)(void);
557 void (*thread_wait)(unsigned int thread_id);
558 void (*thread_thaw)(unsigned int thread_id);
559#ifdef HAVE_PRIORITY_SCHEDULING
560 int (*thread_set_priority)(unsigned int thread_id, int priority);
561#endif
562 void (*mutex_init)(struct mutex *m);
563 void (*mutex_lock)(struct mutex *m);
564 void (*mutex_unlock)(struct mutex *m);
565#ifdef HAVE_SEMAPHORE_OBJECTS
566 void (*semaphore_init)(struct semaphore *s, int max, int start);
567 int (*semaphore_wait)(struct semaphore *s, int timeout);
568 void (*semaphore_release)(struct semaphore *s);
569#endif
570 void (*reset_poweroff_timer)(void);
571 void (*set_sleeptimer_duration)(int minutes);
572 int (*get_sleep_timer)(void);
573#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
574 int (*system_memory_guard)(int newmode);
575 long *cpu_frequency;
576#ifdef HAVE_ADJUSTABLE_CPU_FREQ
577#ifdef CPU_BOOST_LOGGING
578 void (*cpu_boost_)(bool on_off,char*location,int line);
579#else
580 void (*cpu_boost)(bool on_off);
581#endif
582#endif /* HAVE_ADJUSTABLE_CPU_FREQ */
583#endif /* PLATFORM_NATIVE */
584#ifdef HAVE_SCHEDULER_BOOSTCTRL
585 void (*trigger_cpu_boost)(void);
586 void (*cancel_cpu_boost)(void);
587#endif
588
589 void (*commit_dcache)(void);
590 void (*commit_discard_dcache)(void);
591 void (*commit_discard_idcache)(void);
592
593 /* load code api for overlay */
594 void* (*lc_open)(const char *filename, unsigned char *buf, size_t buf_size);
595 void* (*lc_open_from_mem)(void* addr, size_t blob_size);
596 void* (*lc_get_header)(void *handle);
597 void (*lc_close)(void *handle);
598
599 bool (*timer_register)(int reg_prio, void (*unregister_callback)(void),
600 long cycles, void (*timer_callback)(void)
601 IF_COP(, int core));
602 void (*timer_unregister)(void);
603 bool (*timer_set_period)(long count);
604
605 void (*queue_init)(struct event_queue *q, bool register_queue);
606 void (*queue_delete)(struct event_queue *q);
607 void (*queue_post)(struct event_queue *q, long id, intptr_t data);
608 void (*queue_wait_w_tmo)(struct event_queue *q, struct queue_event *ev,
609 int ticks);
610 void (*queue_enable_queue_send)(struct event_queue *q,
611 struct queue_sender_list *send,
612 unsigned int thread_id);
613 bool (*queue_empty)(const struct event_queue *q);
614 void (*queue_wait)(struct event_queue *q, struct queue_event *ev);
615 intptr_t (*queue_send)(struct event_queue *q, long id,
616 intptr_t data);
617 void (*queue_reply)(struct event_queue *q, intptr_t retval);
618 void (*queue_remove_from_head)(struct event_queue *q, long id);
619
620#ifdef RB_PROFILE
621 void (*profile_thread)(void);
622 void (*profstop)(void);
623 void (*profile_func_enter)(void *this_fn, void *call_site);
624 void (*profile_func_exit)(void *this_fn, void *call_site);
625#endif
626 /* event api */
627 bool (*add_event)(unsigned short id, void (*handler)(unsigned short id, void *data));
628 void (*remove_event)(unsigned short id, void (*handler)(unsigned short id, void *data));
629 void (*send_event)(unsigned short id, void *data);
630
631#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
632 /* special simulator hooks */
633#if LCD_DEPTH < 8
634 void (*sim_lcd_ex_init)(unsigned long (*getpixel)(int, int));
635 void (*sim_lcd_ex_update_rect)(int x, int y, int width, int height);
636#endif
637#endif
638
639 /* strings and memory */
640 int (*snprintf)(char *buf, size_t size, const char *fmt, ...)
641 ATTRIBUTE_PRINTF(3, 4);
642 int (*vsnprintf)(char *buf, size_t size, const char *fmt, va_list ap);
643 int (*vuprintf)(vuprintf_push_cb push, void *userp, const char *fmt, va_list ap);
644 char* (*strcpy)(char *dst, const char *src);
645 size_t (*strlcpy)(char *dst, const char *src, size_t length);
646 size_t (*strlen)(const char *str);
647 char * (*strrchr)(const char *s, int c);
648 int (*strcmp)(const char *, const char *);
649 int (*strncmp)(const char *, const char *, size_t);
650 int (*strcasecmp)(const char *, const char *);
651 int (*strncasecmp)(const char *s1, const char *s2, size_t n);
652 void* (*memset)(void *dst, int c, size_t length);
653 void* (*memcpy)(void *out, const void *in, size_t n);
654 void* (*memmove)(void *out, const void *in, size_t n);
655#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
656 const unsigned char *_rbctype_;
657#endif
658 int (*atoi)(const char *str);
659 char *(*strchr)(const char *s, int c);
660 char *(*strcat)(char *s1, const char *s2);
661 size_t (*strlcat)(char *dst, const char *src, size_t length);
662 void *(*memchr)(const void *s1, int c, size_t n);
663 int (*memcmp)(const void *s1, const void *s2, size_t n);
664 char *(*strcasestr) (const char* phaystack, const char* pneedle);
665 char* (*strtok_r)(char *ptr, const char *sep, char **end);
666 char* (*output_dyn_value)(char *buf, int buf_size, int64_t value,
667 const unsigned char * const *units,
668 unsigned int unit_count, bool binary_scale);
669 /* unicode stuff */
670 const unsigned char* (*utf8decode)(const unsigned char *utf8, ucschar_t *ucs);
671 unsigned char* (*iso_decode)(const unsigned char *iso, unsigned char *utf8, int cp, int count);
672 unsigned char* (*utf16LEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
673 unsigned char* (*utf16BEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
674 unsigned char* (*utf8encode)(unsigned long ucs, unsigned char *utf8);
675 unsigned long (*utf8length)(const unsigned char *utf8);
676 int (*utf8seek)(const unsigned char* utf8, int offset);
677
678 /* language */
679 int (*lang_is_rtl)(void);
680
681 /* the buflib memory management library */
682 void (*buflib_init)(struct buflib_context* ctx, void* buf, size_t size);
683 size_t (*buflib_available)(struct buflib_context* ctx);
684 int (*buflib_alloc)(struct buflib_context* ctx, size_t size);
685 int (*buflib_alloc_ex)(struct buflib_context* ctx, size_t size,
686 struct buflib_callbacks *ops);
687 int (*buflib_alloc_maximum)(struct buflib_context* ctx,
688 size_t* size, struct buflib_callbacks *ops);
689 void (*buflib_buffer_in)(struct buflib_context* ctx, int size);
690 void* (*buflib_buffer_out)(struct buflib_context* ctx, size_t* size);
691 int (*buflib_free)(struct buflib_context* ctx, int handle);
692 bool (*buflib_shrink)(struct buflib_context* ctx, int handle,
693 void* new_start, size_t new_size);
694 void* (*buflib_get_data)(struct buflib_context* ctx, int handle);
695
696 /* sound */
697 void (*adjust_volume)(int steps);
698 void (*sound_set)(int setting, int value);
699 int (*sound_current)(int setting); /*stub*/
700 int (*sound_default)(int setting);
701 int (*sound_min)(int setting);
702 int (*sound_max)(int setting);
703 const char * (*sound_unit)(int setting);
704 int (*sound_val2phys)(int setting, int value);
705#ifdef AUDIOHW_HAVE_EQ
706 int (*sound_enum_hw_eq_band_setting)(unsigned int band,
707 unsigned int band_setting);
708#endif /* AUDIOHW_HAVE_EQ */
709#if defined (HAVE_PITCHCONTROL)
710 int32_t (*sound_get_pitch)(void);
711 void (*sound_set_pitch)(int32_t pitch);
712#endif
713 const unsigned long *audio_master_sampr_list;
714 const unsigned long *hw_freq_sampr;
715 void (*pcm_apply_settings)(void);
716 void (*pcm_play_data)(pcm_play_callback_type get_more,
717 pcm_status_callback_type status_cb,
718 const void *start, size_t size);
719 void (*pcm_play_stop)(void);
720 void (*pcm_set_frequency)(unsigned int frequency);
721 bool (*pcm_is_playing)(void);
722 void (*pcm_play_lock)(void);
723 void (*pcm_play_unlock)(void);
724 void (*beep_play)(unsigned int frequency, unsigned int duration,
725 unsigned int amplitude);
726#ifdef HAVE_RECORDING
727 const unsigned long *rec_freq_sampr;
728 void (*pcm_init_recording)(void);
729 void (*pcm_close_recording)(void);
730 void (*pcm_record_data)(pcm_rec_callback_type more_ready,
731 pcm_status_callback_type status_cb,
732 void *start, size_t size);
733 void (*pcm_stop_recording)(void);
734 void (*pcm_calculate_rec_peaks)(int *left, int *right);
735 void (*audio_set_recording_gain)(int left, int right, int type);
736#endif /* HAVE_RECORDING */
737#if INPUT_SRC_CAPS != 0
738 void (*audio_set_output_source)(int monitor);
739 void (*audio_set_input_source)(int source, unsigned flags);
740#endif
741 void (*dsp_set_crossfeed_type)(int type);
742 void (*dsp_eq_enable)(bool enable);
743 void (*dsp_dither_enable)(bool enable);
744#ifdef HAVE_PITCHCONTROL
745 int32_t (*dsp_get_timestretch)(void);
746 void (*dsp_set_timestretch)(int32_t percent);
747 void (*dsp_timestretch_enable)(bool enabled);
748 bool (*dsp_timestretch_available)(void);
749#endif
750 intptr_t (*dsp_configure)(struct dsp_config *dsp,
751 unsigned int setting, intptr_t value);
752 struct dsp_config * (*dsp_get_config)(unsigned int dsp_id);
753 void (*dsp_process)(struct dsp_config *dsp, struct dsp_buffer *src,
754 struct dsp_buffer *dst, bool thread_yield);
755
756 enum channel_status (*mixer_channel_status)(enum pcm_mixer_channel channel);
757 const void * (*mixer_channel_get_buffer)(enum pcm_mixer_channel channel,
758 int *count);
759 void (*mixer_channel_calculate_peaks)(enum pcm_mixer_channel channel,
760 struct pcm_peaks *peaks);
761 void (*mixer_channel_play_data)(enum pcm_mixer_channel channel,
762 pcm_play_callback_type get_more,
763 const void *start, size_t size);
764 void (*mixer_channel_play_pause)(enum pcm_mixer_channel channel, bool play);
765 void (*mixer_channel_stop)(enum pcm_mixer_channel channel);
766 void (*mixer_channel_set_amplitude)(enum pcm_mixer_channel channel,
767 unsigned int amplitude);
768 size_t (*mixer_channel_get_bytes_waiting)(enum pcm_mixer_channel channel);
769 void (*mixer_channel_set_buffer_hook)(enum pcm_mixer_channel channel,
770 chan_buffer_hook_fn_type fn);
771 void (*mixer_set_frequency)(unsigned int samplerate);
772 unsigned int (*mixer_get_frequency)(void);
773 void (*pcmbuf_fade)(bool fade, bool in);
774 void (*pcmbuf_set_low_latency)(bool state);
775 void (*system_sound_play)(enum system_sound sound);
776 void (*keyclick_click)(bool rawbutton, int action);
777
778 /* metadata */
779 bool (*get_metadata)(struct mp3entry* id3, int fd, const char* trackname);
780 const char* (*get_codec_string)(int codectype);
781 int (*count_mp3_frames)(int fd, int startpos, int filesize,
782 void (*progressfunc)(int),
783 unsigned char* buf, size_t buflen);
784 int (*create_xing_header)(int fd, long startpos, long filesize,
785 unsigned char *buf, unsigned long num_frames,
786 unsigned long rec_time, unsigned long header_template,
787 void (*progressfunc)(int), bool generate_toc,
788 unsigned char* tempbuf, size_t tempbuf_len);
789#ifdef HAVE_TAGCACHE
790 bool (*tagcache_search)(struct tagcache_search *tcs, int tag);
791 void (*tagcache_search_set_uniqbuf)(struct tagcache_search *tcs,
792 void *buffer, long length);
793 bool (*tagcache_search_add_filter)(struct tagcache_search *tcs,
794 int tag, int seek);
795 bool (*tagcache_get_next)(struct tagcache_search *tcs, char *buf, long size);
796 bool (*tagcache_retrieve)(struct tagcache_search *tcs, int idxid,
797 int tag, char *buf, long size);
798 void (*tagcache_search_finish)(struct tagcache_search *tcs);
799 long (*tagcache_get_numeric)(const struct tagcache_search *tcs, int tag);
800 struct tagcache_stat* (*tagcache_get_stat)(void);
801 void (*tagcache_commit_finalize)(void);
802#if defined(HAVE_TC_RAMCACHE)
803 bool (*tagcache_is_in_ram)(void);
804#if defined(HAVE_DIRCACHE)
805 bool (*tagcache_fill_tags)(struct mp3entry *id3, const char *filename);
806#endif
807#endif
808 bool (*tagtree_subentries_do_action)(bool (*action_cb)(const char *file_name));
809#endif /* HAVE_TAGCACHE */
810
811#ifdef HAVE_ALBUMART
812 bool (*search_albumart_files)(const struct mp3entry *id3, const char *size_string,
813 char *buf, int buflen);
814#endif
815
816 /* playback control */
817 struct playlist_info* (*playlist_get_current)(void);
818 int (*playlist_get_resume_info)(int *resume_index);
819 int (*playlist_get_track_info)(struct playlist_info* playlist, int index,
820 struct playlist_track_info* info);
821 int (*playlist_get_first_index)(const struct playlist_info* playlist);
822 int (*playlist_get_display_index)(void);
823 bool (*playlist_entries_iterate)(const char *filename,
824 struct playlist_insert_context *pl_context,
825 bool (*action_cb)(const char *file_name));
826 int (*playlist_amount)(void);
827 int (*playlist_resume)(void);
828 void (*playlist_resume_track)(int start_index, unsigned int crc,
829 unsigned long elapsed, unsigned long offset);
830 void (*playlist_set_modified)(struct playlist_info *playlist, bool modified);
831 void (*playlist_start)(int start_index, unsigned long elapsed,
832 unsigned long offset);
833 void (*playlist_sync)(struct playlist_info* playlist);
834 int (*playlist_remove_all_tracks)(struct playlist_info *playlist);
835 int (*playlist_create)(const char *dir, const char *file);
836 int (*playlist_insert_track)(struct playlist_info* playlist,
837 const char *filename, int position, bool queue, bool sync);
838 int (*playlist_insert_directory)(struct playlist_info* playlist,
839 const char *dirname, int position, bool queue,
840 bool recurse);
841 int (*playlist_insert_playlist)(struct playlist_info* playlist,
842 const char *filename, int position, bool queue);
843 int (*playlist_shuffle)(int random_seed, int start_index);
844 bool (*warn_on_pl_erase)(void);
845 void (*audio_play)(unsigned long elapsed, unsigned long offset);
846 void (*audio_stop)(void);
847 void (*audio_pause)(void);
848 void (*audio_resume)(void);
849 void (*audio_next)(void);
850 void (*audio_prev)(void);
851 void (*audio_ff_rewind)(long newtime);
852 struct mp3entry* (*audio_next_track)(void);
853 int (*audio_status)(void);
854 struct mp3entry* (*audio_current_track)(void);
855 void (*audio_flush_and_reload_tracks)(void);
856 int (*audio_get_file_pos)(void);
857#ifdef PLUGIN_USE_IRAM
858 void (*audio_hard_stop)(void);
859#endif
860
861 /* menu */
862 struct menu_table *(*root_menu_get_options)(int *nb_options);
863 int (*do_menu)(const struct menu_item_ex *menu, int *start_selected,
864 struct viewport parent[NB_SCREENS], bool hide_theme);
865 void (*root_menu_set_default)(void* setting, void* defaultval);
866 char* (*root_menu_write_to_cfg)(void* setting, char*buf, int buf_len);
867 void (*root_menu_load_from_cfg)(void* setting, char *value);
868
869 /* options */
870 const struct settings_list* (*get_settings_list)(int*count);
871 const struct settings_list* (*find_setting)(const void* variable);
872 int (*settings_save)(void);
873 bool (*option_screen)(const struct settings_list *setting,
874 struct viewport parent[NB_SCREENS],
875 bool use_temp_var, const unsigned char* option_title);
876 bool (*set_option)(const char* string, const void* variable,
877 enum optiontype type, const struct opt_items* options,
878 int numoptions, void (*function)(int));
879 bool (*set_bool_options)(const char* string, const bool* variable,
880 const char* yes_str, int yes_voice,
881 const char* no_str, int no_voice,
882 void (*function)(bool));
883 bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit,
884 const int* variable, void (*function)(int), int step,
885 int min, int max,
886 const char* (*formatter)(char*, size_t, int, const char*) );
887 bool (*set_int_ex)(const unsigned char* string, const char* unit, int voice_unit,
888 const int* variable, void (*function)(int), int step,
889 int min, int max,
890 const char* (*formatter)(char*, size_t, int, const char*) ,
891 int32_t (*get_talk_id)(int, int));
892 bool (*set_bool)(const char* string, const bool* variable );
893
894#ifdef HAVE_LCD_COLOR
895 bool (*set_color)(struct screen *display, char *title,
896 unsigned *color, unsigned banned_color);
897#endif
898
899 /* power */
900 int (*battery_level)(void);
901 bool (*battery_level_safe)(void);
902 int (*battery_time)(void);
903 int (*battery_voltage)(void);
904 int (*battery_current)(void);
905#if CONFIG_CHARGING
906 bool (*charger_inserted)(void);
907# if CONFIG_CHARGING >= CHARGING_MONITOR
908 bool (*charging_state)(void);
909# endif
910#endif
911 /* usb */
912 bool (*usb_inserted)(void);
913 void (*usb_acknowledge)(long id);
914#ifdef USB_ENABLE_HID
915 void (*usb_hid_send)(usage_page_t usage_page, int id);
916#endif
917 /* misc */
918#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
919 int * (*__errno)(void);
920#endif
921 void (*led)(bool on);
922 void (*srand)(unsigned int seed);
923 int (*rand)(void);
924 void (*qsort)(void *base, size_t nmemb, size_t size,
925 int(*compar)(const void *, const void *));
926 int (*kbd_input)(char* buffer, int buflen, ucschar_t *kbd);
927 struct tm* (*get_time)(void);
928 struct tm * (*gmtime_r)(const time_t *timep, struct tm *tm);
929#if CONFIG_RTC
930 time_t (*mktime)(struct tm *t);
931#endif
932 const char* (*format_time_auto)(char *buffer, int buf_len, long value,
933 int unit_idx, bool supress_unit);
934#if defined(DEBUG) || defined(SIMULATOR)
935 void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
936#endif
937#ifdef ROCKBOX_HAS_LOGF
938 void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
939#endif
940 void (*codec_thread_do_callback)(void (*fn)(void),
941 unsigned int *audio_thread_id);
942 int (*codec_load_file)(const char* codec, struct codec_api *api);
943 int (*codec_run_proc)(void);
944 int (*codec_close)(void);
945 const char *(*get_codec_filename)(int cod_spec);
946 void ** (*find_array_ptr)(void **arr, void *ptr);
947 int (*remove_array_ptr)(void **arr, void *ptr);
948 int (*round_value_to_list32)(unsigned long value,
949 const unsigned long list[],
950 int count,
951 bool signd);
952
953 int (*read_bmp_file)(const char* filename, struct bitmap *bm, int maxsize,
954 int format, const struct custom_format *cformat);
955 int (*read_bmp_fd)(int fd, struct bitmap *bm, int maxsize,
956 int format, const struct custom_format *cformat);
957#ifdef HAVE_JPEG
958 int (*read_jpeg_file)(const char* filename, struct bitmap *bm, int maxsize,
959 int format, const struct custom_format *cformat);
960 int (*read_jpeg_fd)(int fd, struct bitmap *bm, int maxsize,
961 int format, const struct custom_format *cformat);
962#endif
963 void (*screen_dump_set_hook)(void (*hook)(int fh));
964
965#ifdef HAVE_WHEEL_POSITION
966 int (*wheel_status)(void);
967 void (*wheel_send_events)(bool send);
968#endif
969
970#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
971 /* Routines for the iriver_flash -plugin. */
972 bool (*detect_original_firmware)(void);
973 bool (*detect_flashed_ramimage)(void);
974 bool (*detect_flashed_romimage)(void);
975#endif
976 /*plugin*/
977 int (*plugin_open)(const char *path, const char *parameter);
978 void* (*plugin_get_buffer)(size_t *buffer_size);
979 void* (*plugin_get_audio_buffer)(size_t *buffer_size);
980 void (*plugin_release_audio_buffer)(void);
981 void (*plugin_tsr)(int (*exit_callback)(bool reenter));
982 char* (*plugin_get_current_filename)(void);
983 size_t (*plugin_reserve_buffer)(size_t buffer_size);
984 /* reboot and poweroff */
985 void (*sys_poweroff)(void);
986 void (*sys_reboot)(void);
987 /* pathfuncs */
988 void (*fix_path_part)(char* path, int offset, int count);
989#ifdef HAVE_MULTIVOLUME
990 int (*path_strip_volume)(const char *name, const char **nameptr, bool greedy);
991#endif
992 /* new stuff at the end, sort into place next time
993 the API gets incompatible */
994 void (*add_playbacklog)(struct mp3entry *id3);
995 struct battery_tables_t *device_battery_tables;
996 bool (*yesno_pop_confirm)(const char* text);
997#ifdef USB_ENABLE_AUDIO
998 bool (*usb_audio_get_playing)(void);
999#endif
1000};
1001
1002/* plugin header */
1003struct plugin_header {
1004 struct lc_header lc_hdr; /* must be the first */
1005 enum plugin_status(*entry_point)(const void*);
1006 const struct plugin_api **api;
1007 size_t api_size;
1008};
1009
1010#ifdef PLUGIN
1011#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
1012extern unsigned char plugin_start_addr[];
1013extern unsigned char plugin_end_addr[];
1014#define PLUGIN_HEADER \
1015 const struct plugin_api *rb DATA_ATTR; \
1016 const struct plugin_header __header \
1017 __attribute__ ((section (".header")))= { \
1018 { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
1019 plugin_start_addr, plugin_end_addr, }, \
1020 plugin__start, &rb, sizeof(struct plugin_api) };
1021#else /* PLATFORM_HOSTED */
1022#define PLUGIN_HEADER \
1023 const struct plugin_api *rb DATA_ATTR; \
1024 const struct plugin_header __header \
1025 __attribute__((visibility("default"))) = { \
1026 { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, NULL, NULL }, \
1027 plugin__start, &rb, sizeof(struct plugin_api) };
1028#endif /* CONFIG_PLATFORM */
1029#endif /* PLUGIN */
1030
1031/*
1032 * The str() macro/functions is how to access strings that might be
1033 * translated. Use it like str(MACRO) and expect a string to be
1034 * returned!
1035 */
1036#define str(x) language_strings[x]
1037
1038int plugin_load(const char* plugin, const void* parameter);
1039
1040/* defined by the plugin */
1041extern const struct plugin_api *rb;
1042enum plugin_status plugin_start(const void* parameter);
1043enum plugin_status plugin__start(const void* parameter)
1044 NO_PROF_ATTR;
1045
1046#endif /* __PCTOOL__ */
1047#endif