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