Apply FS#9500. This adds a storage_*() abstraction to replace ata_*(). To do that...
[kugel-rb.git] / apps / plugin.c
blobe46e193129d9421eb1119f9a04e87ccfad166b27
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "plugin.h"
22 #include <ctype.h>
23 #include <string.h>
24 #include <sprintf.h>
25 #include <stdlib.h>
26 #include "debug.h"
27 #include "i2c.h"
28 #include "lang.h"
29 #include "led.h"
30 #include "keyboard.h"
31 #include "buffer.h"
32 #include "backlight.h"
33 #include "sound_menu.h"
34 #include "mp3data.h"
35 #include "powermgmt.h"
36 #include "splash.h"
37 #include "logf.h"
38 #include "option_select.h"
39 #include "talk.h"
40 #include "version.h"
41 #include "storage.h"
43 #if CONFIG_CHARGING
44 #include "power.h"
45 #endif
47 #ifdef HAVE_LCD_BITMAP
48 #include "scrollbar.h"
49 #include "peakmeter.h"
50 #include "bmp.h"
51 #include "bidi.h"
52 #endif
54 #ifdef SIMULATOR
55 static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE];
56 void *sim_plugin_load(char *plugin, void **pd);
57 void sim_plugin_close(void *pd);
58 void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int));
59 void sim_lcd_ex_update_rect(int x, int y, int width, int height);
60 #else
61 #define sim_plugin_close(x)
62 extern unsigned char pluginbuf[];
63 #include "bitswap.h"
64 #endif
66 /* for actual plugins only, not for codecs */
67 static bool plugin_loaded = false;
68 static int plugin_size = 0;
69 static bool (*pfn_tsr_exit)(bool reenter) = NULL; /* TSR exit callback */
70 static char current_plugin[MAX_PATH];
72 char *plugin_get_current_filename(void);
74 extern struct thread_entry threads[MAXTHREADS];
76 static const struct plugin_api rockbox_api = {
78 /* lcd */
79 lcd_set_contrast,
80 lcd_update,
81 lcd_clear_display,
82 lcd_getstringsize,
83 lcd_putsxy,
84 lcd_puts,
85 lcd_puts_scroll,
86 lcd_stop_scroll,
87 #ifdef HAVE_LCD_CHARCELLS
88 lcd_define_pattern,
89 lcd_get_locked_pattern,
90 lcd_unlock_pattern,
91 lcd_putc,
92 lcd_put_cursor,
93 lcd_remove_cursor,
94 lcd_icon,
95 lcd_double_height,
96 #else
97 &lcd_framebuffer[0][0],
98 lcd_update_rect,
99 lcd_set_drawmode,
100 lcd_get_drawmode,
101 lcd_setfont,
102 lcd_drawpixel,
103 lcd_drawline,
104 lcd_hline,
105 lcd_vline,
106 lcd_drawrect,
107 lcd_fillrect,
108 lcd_mono_bitmap_part,
109 lcd_mono_bitmap,
110 #if LCD_DEPTH > 1
111 lcd_set_foreground,
112 lcd_get_foreground,
113 lcd_set_background,
114 lcd_get_background,
115 lcd_bitmap_part,
116 lcd_bitmap,
117 lcd_get_backdrop,
118 lcd_set_backdrop,
119 #endif
120 #if LCD_DEPTH == 16
121 lcd_bitmap_transparent_part,
122 lcd_bitmap_transparent,
123 lcd_blit_yuv,
124 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
125 || defined(IRIVER_H10) || defined(COWON_D2)
126 lcd_yuv_set_options,
127 #endif
128 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
129 lcd_blit_mono,
130 lcd_blit_grey_phase,
131 #endif /* LCD_DEPTH */
132 lcd_puts_style,
133 lcd_puts_scroll_style,
134 #ifdef HAVE_LCD_INVERT
135 lcd_set_invert_display,
136 #endif /* HAVE_LCD_INVERT */
137 #if defined(HAVE_LCD_ENABLE) && defined(HAVE_LCD_COLOR)
138 lcd_set_enable_hook,
139 &button_queue,
140 #endif
141 bidi_l2v,
142 font_get_bits,
143 font_load,
144 font_get,
145 font_getstringsize,
146 font_get_width,
147 screen_clear_area,
148 gui_scrollbar_draw,
149 #endif
151 backlight_on,
152 backlight_off,
153 backlight_set_timeout,
154 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
155 backlight_set_brightness,
156 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
158 #if CONFIG_CHARGING
159 backlight_set_timeout_plugged,
160 #endif
161 is_backlight_on,
162 splash,
163 splashf,
165 #ifdef HAVE_REMOTE_LCD
166 /* remote lcd */
167 lcd_remote_set_contrast,
168 lcd_remote_clear_display,
169 lcd_remote_puts,
170 lcd_remote_puts_scroll,
171 lcd_remote_stop_scroll,
172 lcd_remote_set_drawmode,
173 lcd_remote_get_drawmode,
174 lcd_remote_setfont,
175 lcd_remote_getstringsize,
176 lcd_remote_drawpixel,
177 lcd_remote_drawline,
178 lcd_remote_hline,
179 lcd_remote_vline,
180 lcd_remote_drawrect,
181 lcd_remote_fillrect,
182 lcd_remote_mono_bitmap_part,
183 lcd_remote_mono_bitmap,
184 lcd_remote_putsxy,
185 lcd_remote_puts_style,
186 lcd_remote_puts_scroll_style,
187 &lcd_remote_framebuffer[0][0],
188 lcd_remote_update,
189 lcd_remote_update_rect,
191 remote_backlight_on,
192 remote_backlight_off,
193 remote_backlight_set_timeout,
194 #if CONFIG_CHARGING
195 remote_backlight_set_timeout_plugged,
196 #endif
197 #endif /* HAVE_REMOTE_LCD */
198 #if NB_SCREENS == 2
199 {&screens[SCREEN_MAIN], &screens[SCREEN_REMOTE]},
200 #else
201 {&screens[SCREEN_MAIN]},
202 #endif
203 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
204 lcd_remote_set_foreground,
205 lcd_remote_get_foreground,
206 lcd_remote_set_background,
207 lcd_remote_get_background,
208 lcd_remote_bitmap_part,
209 lcd_remote_bitmap,
210 #endif
211 viewport_set_defaults,
213 /* list */
214 gui_synclist_init,
215 gui_synclist_set_nb_items,
216 gui_synclist_set_icon_callback,
217 gui_synclist_get_nb_items,
218 gui_synclist_get_sel_pos,
219 gui_synclist_draw,
220 gui_synclist_select_item,
221 gui_synclist_add_item,
222 gui_synclist_del_item,
223 gui_synclist_limit_scroll,
224 gui_synclist_do_button,
225 gui_synclist_set_title,
226 gui_syncyesno_run,
227 simplelist_info_init,
228 simplelist_show_list,
230 /* button */
231 button_get,
232 button_get_w_tmo,
233 button_status,
234 #ifdef HAVE_BUTTON_DATA
235 button_get_data,
236 #endif
237 button_clear_queue,
238 button_queue_count,
239 #ifdef HAS_BUTTON_HOLD
240 button_hold,
241 #endif
242 #ifdef HAVE_TOUCHSCREEN
243 touchscreen_set_mode,
244 #endif
246 #ifdef HAVE_BUTTON_LIGHT
247 buttonlight_set_timeout,
248 buttonlight_off,
249 buttonlight_on,
250 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
251 buttonlight_set_brightness,
252 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
253 #endif /* HAVE_BUTTON_LIGHT */
255 /* file */
256 (open_func)PREFIX(open),
257 PREFIX(close),
258 (read_func)PREFIX(read),
259 PREFIX(lseek),
260 (creat_func)PREFIX(creat),
261 (write_func)PREFIX(write),
262 PREFIX(remove),
263 PREFIX(rename),
264 PREFIX(ftruncate),
265 PREFIX(filesize),
266 fdprintf,
267 read_line,
268 settings_parseline,
269 storage_sleep,
270 storage_spin,
271 storage_spindown,
272 #if USING_STORAGE_CALLBACK
273 register_storage_idle_func,
274 unregister_storage_idle_func,
275 #endif /* USING_STORAGE_CALLBACK */
276 reload_directory,
277 create_numbered_filename,
278 file_exists,
280 /* dir */
281 opendir,
282 closedir,
283 readdir,
284 mkdir,
285 rmdir,
286 dir_exists,
288 /* kernel/ system */
289 PREFIX(sleep),
290 yield,
291 &current_tick,
292 default_event_handler,
293 default_event_handler_ex,
294 threads,
295 create_thread,
296 thread_exit,
297 thread_wait,
298 #if (CONFIG_CODEC == SWCODEC)
299 mutex_init,
300 mutex_lock,
301 mutex_unlock,
302 align_buffer,
303 #endif
305 reset_poweroff_timer,
306 #ifndef SIMULATOR
307 system_memory_guard,
308 &cpu_frequency,
310 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
311 #ifdef CPU_BOOST_LOGGING
312 cpu_boost_,
313 #else
314 cpu_boost,
315 #endif
316 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
317 #endif /* !SIMULATOR */
318 #ifdef HAVE_SCHEDULER_BOOSTCTRL
319 trigger_cpu_boost,
320 cancel_cpu_boost,
321 #endif
322 #ifdef CACHE_FUNCTIONS_AS_CALL
323 flush_icache,
324 invalidate_icache,
325 #endif
326 timer_register,
327 timer_unregister,
328 timer_set_period,
330 queue_init,
331 queue_delete,
332 queue_post,
333 queue_wait_w_tmo,
334 #if CONFIG_CODEC == SWCODEC
335 queue_enable_queue_send,
336 queue_empty,
337 queue_wait,
338 queue_send,
339 queue_reply,
340 #endif
341 usb_acknowledge,
342 #ifdef RB_PROFILE
343 profile_thread,
344 profstop,
345 __cyg_profile_func_enter,
346 __cyg_profile_func_exit,
347 #endif
349 #ifdef SIMULATOR
350 /* special simulator hooks */
351 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
352 sim_lcd_ex_init,
353 sim_lcd_ex_update_rect,
354 #endif
355 #endif
357 /* strings and memory */
358 snprintf,
359 vsnprintf,
360 strcpy,
361 strncpy,
362 strlen,
363 strrchr,
364 strcmp,
365 strncmp,
366 strcasecmp,
367 strncasecmp,
368 memset,
369 memcpy,
370 memmove,
371 _ctype_,
372 atoi,
373 strchr,
374 strcat,
375 memchr,
376 memcmp,
377 strcasestr,
378 strtok_r,
379 /* unicode stuff */
380 utf8decode,
381 iso_decode,
382 utf16LEdecode,
383 utf16BEdecode,
384 utf8encode,
385 utf8length,
386 utf8seek,
388 /* sound */
389 sound_set,
390 sound_default,
391 sound_min,
392 sound_max,
393 sound_unit,
394 sound_val2phys,
395 #ifndef SIMULATOR
396 mp3_play_data,
397 mp3_play_pause,
398 mp3_play_stop,
399 mp3_is_playing,
400 #if CONFIG_CODEC != SWCODEC
401 bitswap,
402 #endif
403 #endif
404 #if CONFIG_CODEC == SWCODEC
405 &audio_master_sampr_list[0],
406 &hw_freq_sampr[0],
407 pcm_apply_settings,
408 pcm_play_data,
409 pcm_play_stop,
410 pcm_set_frequency,
411 pcm_is_playing,
412 pcm_is_paused,
413 pcm_play_pause,
414 pcm_get_bytes_waiting,
415 pcm_calculate_peaks,
416 pcm_play_lock,
417 pcm_play_unlock,
418 #ifdef HAVE_RECORDING
419 &rec_freq_sampr[0],
420 pcm_init_recording,
421 pcm_close_recording,
422 pcm_record_data,
423 pcm_record_more,
424 pcm_stop_recording,
425 pcm_calculate_rec_peaks,
426 audio_set_recording_gain,
427 #endif /* HAVE_RECORDING */
428 #if INPUT_SRC_CAPS != 0
429 audio_set_output_source,
430 audio_set_input_source,
431 #endif
432 dsp_set_crossfeed,
433 dsp_set_eq,
434 dsp_dither_enable,
435 dsp_configure,
436 dsp_process,
437 #endif /* CONFIG_CODEC == SWCODEC */
439 /* playback control */
440 playlist_amount,
441 playlist_resume,
442 playlist_start,
443 PREFIX(audio_play),
444 audio_stop,
445 audio_pause,
446 audio_resume,
447 audio_next,
448 audio_prev,
449 audio_ff_rewind,
450 audio_next_track,
451 audio_status,
452 audio_has_changed_track,
453 audio_current_track,
454 audio_flush_and_reload_tracks,
455 audio_get_file_pos,
456 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
457 mpeg_get_last_header,
458 #endif
459 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
460 (CONFIG_CODEC == SWCODEC)
461 sound_set_pitch,
462 #endif
464 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
465 /* MAS communication */
466 mas_readmem,
467 mas_writemem,
468 mas_readreg,
469 mas_writereg,
470 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
471 mas_codec_writereg,
472 mas_codec_readreg,
473 i2c_begin,
474 i2c_end,
475 i2c_write,
476 #endif
477 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
479 /* menu */
480 do_menu,
481 /* statusbars */
482 &statusbars,
483 gui_syncstatusbar_draw,
484 /* options */
485 find_setting,
486 option_screen,
487 set_option,
488 set_bool_options,
489 set_int,
490 set_bool,
491 #ifdef HAVE_LCD_COLOR
492 set_color,
493 #endif
495 /* action handling */
496 get_custom_action,
497 get_action,
498 action_userabort,
500 /* power */
501 battery_level,
502 battery_level_safe,
503 battery_time,
504 #ifndef SIMULATOR
505 battery_voltage,
506 #endif
507 #if CONFIG_CHARGING
508 charger_inserted,
509 # if CONFIG_CHARGING == CHARGING_MONITOR
510 charging_state,
511 # endif
512 #endif
513 #ifdef HAVE_USB_POWER
514 usb_powered,
515 #endif
517 /* misc */
518 srand,
519 rand,
520 (qsort_func)qsort,
521 kbd_input,
522 get_time,
523 set_time,
524 #if CONFIG_RTC
525 mktime,
526 #endif
527 plugin_get_buffer,
528 plugin_get_audio_buffer,
529 plugin_tsr,
530 plugin_get_current_filename,
531 #ifdef PLUGIN_USE_IRAM
532 plugin_iram_init,
533 #endif
534 #if defined(DEBUG) || defined(SIMULATOR)
535 debugf,
536 #endif
537 #ifdef ROCKBOX_HAS_LOGF
538 _logf,
539 #endif
540 &global_settings,
541 &global_status,
542 talk_disable,
543 #if CONFIG_CODEC == SWCODEC
544 codec_load_file,
545 get_codec_filename,
546 get_metadata,
547 #endif
548 mp3info,
549 count_mp3_frames,
550 create_xing_header,
551 find_next_frame,
552 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
553 peak_meter_scale_value,
554 peak_meter_set_use_dbfs,
555 peak_meter_get_use_dbfs,
556 #endif
557 #ifdef HAVE_LCD_BITMAP
558 read_bmp_file,
559 screen_dump_set_hook,
560 #endif
561 show_logo,
562 tree_get_context,
563 set_current_file,
564 set_dirfilter,
566 #ifdef HAVE_WHEEL_POSITION
567 wheel_status,
568 wheel_send_events,
569 #endif
571 #ifdef IRIVER_H100_SERIES
572 /* Routines for the iriver_flash -plugin. */
573 detect_original_firmware,
574 detect_flashed_ramimage,
575 detect_flashed_romimage,
576 #endif
577 led,
578 #if (CONFIG_CODEC == SWCODEC)
579 bufopen,
580 bufalloc,
581 bufclose,
582 bufseek,
583 bufadvance,
584 bufread,
585 bufgetdata,
586 bufgettail,
587 bufcuttail,
589 buf_get_offset,
590 buf_handle_offset,
591 buf_request_buffer_handle,
592 buf_set_base_handle,
593 buf_used,
594 #endif
596 #ifdef HAVE_TAGCACHE
597 tagcache_search,
598 tagcache_search_set_uniqbuf,
599 tagcache_search_add_filter,
600 tagcache_get_next,
601 tagcache_retrieve,
602 tagcache_search_finish,
603 tagcache_get_numeric,
604 #endif
606 #ifdef HAVE_ALBUMART
607 find_albumart,
608 search_albumart_files,
609 #endif
611 thread_thaw,
613 #ifdef HAVE_SEMAPHORE_OBJECTS
614 semaphore_init,
615 semaphore_wait,
616 semaphore_release,
617 #endif
619 appsversion,
620 /* new stuff at the end, sort into place next time
621 the API gets incompatible */
622 get_settings_list,
625 int plugin_load(const char* plugin, const void* parameter)
627 int rc;
628 struct plugin_header *hdr;
629 #ifdef SIMULATOR
630 void *pd;
631 #else /* !SIMULATOR */
632 int fd;
633 ssize_t readsize;
634 #if NUM_CORES > 1
635 unsigned my_core;
636 #endif
637 #endif /* !SIMULATOR */
639 #if LCD_DEPTH > 1
640 fb_data* old_backdrop;
641 #endif
643 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
645 if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false )
647 /* not allowing another plugin to load */
648 return PLUGIN_OK;
650 pfn_tsr_exit = NULL;
651 plugin_loaded = false;
654 splash(0, ID2P(LANG_WAIT));
655 strcpy(current_plugin, plugin);
657 #ifdef SIMULATOR
658 hdr = sim_plugin_load((char *)plugin, &pd);
659 if (pd == NULL) {
660 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
661 return -1;
663 if (hdr == NULL
664 || hdr->magic != PLUGIN_MAGIC
665 || hdr->target_id != TARGET_ID) {
666 sim_plugin_close(pd);
667 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
668 return -1;
670 if (hdr->api_version > PLUGIN_API_VERSION
671 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
672 sim_plugin_close(pd);
673 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
674 return -1;
676 #else
677 fd = open(plugin, O_RDONLY);
678 if (fd < 0) {
679 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
680 return fd;
682 #if NUM_CORES > 1
683 /* Make sure COP cache is flushed and invalidated before loading */
684 my_core = switch_core(CURRENT_CORE ^ 1);
685 invalidate_icache();
686 switch_core(my_core);
687 #endif
689 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
690 close(fd);
692 if (readsize < 0) {
693 splashf(HZ*2, str(LANG_READ_FAILED), plugin);
694 return -1;
696 hdr = (struct plugin_header *)pluginbuf;
698 if ((unsigned)readsize <= sizeof(struct plugin_header)
699 || hdr->magic != PLUGIN_MAGIC
700 || hdr->target_id != TARGET_ID
701 || hdr->load_addr != pluginbuf
702 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
703 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
704 return -1;
706 if (hdr->api_version > PLUGIN_API_VERSION
707 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
708 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
709 return -1;
711 plugin_size = hdr->end_addr - pluginbuf;
713 /* zero out bss area only, above guards end of pluginbuf */
714 if (plugin_size > readsize)
715 memset(pluginbuf + readsize, 0, plugin_size - readsize);
716 #endif
718 plugin_loaded = true;
721 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
722 old_backdrop = lcd_get_backdrop();
723 #endif
724 lcd_clear_display();
725 lcd_update();
727 #ifdef HAVE_REMOTE_LCD
728 lcd_remote_clear_display();
729 lcd_remote_update();
730 #endif
732 invalidate_icache();
734 rc = hdr->entry_point(&rockbox_api, parameter);
736 button_clear_queue();
738 #ifdef HAVE_LCD_BITMAP
739 #if LCD_DEPTH > 1
740 lcd_set_backdrop(old_backdrop);
741 #ifdef HAVE_LCD_COLOR
742 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
743 global_settings.bg_color);
744 #else
745 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
746 #endif
747 #else /* LCD_DEPTH == 1 */
748 lcd_set_drawmode(DRMODE_SOLID);
749 #endif /* LCD_DEPTH */
750 #endif /* HAVE_LCD_BITMAP */
752 lcd_clear_display();
753 lcd_update();
755 #ifdef HAVE_REMOTE_LCD
756 #if LCD_REMOTE_DEPTH > 1
757 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG,
758 LCD_REMOTE_DEFAULT_BG);
759 #else
760 lcd_remote_set_drawmode(DRMODE_SOLID);
761 #endif
762 lcd_remote_clear_display();
765 lcd_remote_update();
768 #endif
770 if (pfn_tsr_exit == NULL)
771 plugin_loaded = false;
773 sim_plugin_close(pd);
775 switch (rc) {
776 case PLUGIN_OK:
777 break;
779 case PLUGIN_USB_CONNECTED:
780 return PLUGIN_USB_CONNECTED;
782 default:
783 splash(HZ*2, str(LANG_PLUGIN_ERROR));
784 break;
786 return PLUGIN_OK;
789 /* Returns a pointer to the portion of the plugin buffer that is not already
790 being used. If no plugin is loaded, returns the entire plugin buffer */
791 void* plugin_get_buffer(size_t *buffer_size)
793 int buffer_pos;
795 if (plugin_loaded)
797 if (plugin_size >= PLUGIN_BUFFER_SIZE)
798 return NULL;
800 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
801 buffer_pos = plugin_size;
803 else
805 *buffer_size = PLUGIN_BUFFER_SIZE;
806 buffer_pos = 0;
809 return &pluginbuf[buffer_pos];
812 /* Returns a pointer to the mp3 buffer.
813 Playback gets stopped, to avoid conflicts.
814 Talk buffer is stolen as well.
816 void* plugin_get_audio_buffer(size_t *buffer_size)
818 #if CONFIG_CODEC == SWCODEC
819 return audio_get_buffer(true, buffer_size);
820 #else
821 audio_stop();
822 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
823 *buffer_size = audiobufend - audiobuf;
824 return audiobuf;
825 #endif
828 #ifdef PLUGIN_USE_IRAM
829 /* Initializes plugin IRAM */
830 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
831 char *iedata, size_t iedata_size)
833 /* We need to stop audio playback in order to use codec IRAM */
834 audio_hard_stop();
835 memcpy(iramstart, iramcopy, iram_size);
836 memset(iedata, 0, iedata_size);
837 memset(iramcopy, 0, iram_size);
838 #if NUM_CORES > 1
839 /* writeback cleared iedata and iramcopy areas */
840 flush_icache();
841 #endif
843 #endif /* PLUGIN_USE_IRAM */
845 /* The plugin wants to stay resident after leaving its main function, e.g.
846 runs from timer or own thread. The callback is registered to later
847 instruct it to free its resources before a new plugin gets loaded. */
848 void plugin_tsr(bool (*exit_callback)(bool))
850 pfn_tsr_exit = exit_callback; /* remember the callback for later */
853 char *plugin_get_current_filename(void)
855 return current_plugin;