Fixed m200v4 red build.
[kugel-rb.git] / apps / plugin.c
blobf78b6bf4e1461b1ffcd313a445a8641ed1e5e1b6
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 /* HAVE_LCD_BITMAP */
150 get_codepage_name,
152 backlight_on,
153 backlight_off,
154 backlight_set_timeout,
155 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
156 backlight_set_brightness,
157 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
159 #if CONFIG_CHARGING
160 backlight_set_timeout_plugged,
161 #endif
162 is_backlight_on,
163 splash,
164 splashf,
166 #ifdef HAVE_REMOTE_LCD
167 /* remote lcd */
168 lcd_remote_set_contrast,
169 lcd_remote_clear_display,
170 lcd_remote_puts,
171 lcd_remote_puts_scroll,
172 lcd_remote_stop_scroll,
173 lcd_remote_set_drawmode,
174 lcd_remote_get_drawmode,
175 lcd_remote_setfont,
176 lcd_remote_getstringsize,
177 lcd_remote_drawpixel,
178 lcd_remote_drawline,
179 lcd_remote_hline,
180 lcd_remote_vline,
181 lcd_remote_drawrect,
182 lcd_remote_fillrect,
183 lcd_remote_mono_bitmap_part,
184 lcd_remote_mono_bitmap,
185 lcd_remote_putsxy,
186 lcd_remote_puts_style,
187 lcd_remote_puts_scroll_style,
188 &lcd_remote_framebuffer[0][0],
189 lcd_remote_update,
190 lcd_remote_update_rect,
192 remote_backlight_on,
193 remote_backlight_off,
194 remote_backlight_set_timeout,
195 #if CONFIG_CHARGING
196 remote_backlight_set_timeout_plugged,
197 #endif
198 #endif /* HAVE_REMOTE_LCD */
199 #if NB_SCREENS == 2
200 {&screens[SCREEN_MAIN], &screens[SCREEN_REMOTE]},
201 #else
202 {&screens[SCREEN_MAIN]},
203 #endif
204 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
205 lcd_remote_set_foreground,
206 lcd_remote_get_foreground,
207 lcd_remote_set_background,
208 lcd_remote_get_background,
209 lcd_remote_bitmap_part,
210 lcd_remote_bitmap,
211 #endif
212 viewport_set_defaults,
214 /* list */
215 gui_synclist_init,
216 gui_synclist_set_nb_items,
217 gui_synclist_set_icon_callback,
218 gui_synclist_get_nb_items,
219 gui_synclist_get_sel_pos,
220 gui_synclist_draw,
221 gui_synclist_select_item,
222 gui_synclist_add_item,
223 gui_synclist_del_item,
224 gui_synclist_limit_scroll,
225 gui_synclist_do_button,
226 gui_synclist_set_title,
227 gui_syncyesno_run,
228 simplelist_info_init,
229 simplelist_show_list,
231 /* button */
232 button_get,
233 button_get_w_tmo,
234 button_status,
235 #ifdef HAVE_BUTTON_DATA
236 button_get_data,
237 #endif
238 button_clear_queue,
239 button_queue_count,
240 #ifdef HAS_BUTTON_HOLD
241 button_hold,
242 #endif
243 #ifdef HAVE_TOUCHSCREEN
244 touchscreen_set_mode,
245 #endif
247 #ifdef HAVE_BUTTON_LIGHT
248 buttonlight_set_timeout,
249 buttonlight_off,
250 buttonlight_on,
251 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
252 buttonlight_set_brightness,
253 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
254 #endif /* HAVE_BUTTON_LIGHT */
256 /* file */
257 (open_func)PREFIX(open),
258 PREFIX(close),
259 (read_func)PREFIX(read),
260 PREFIX(lseek),
261 (creat_func)PREFIX(creat),
262 (write_func)PREFIX(write),
263 PREFIX(remove),
264 PREFIX(rename),
265 PREFIX(ftruncate),
266 PREFIX(filesize),
267 fdprintf,
268 read_line,
269 settings_parseline,
270 storage_sleep,
271 storage_spin,
272 storage_spindown,
273 #if USING_STORAGE_CALLBACK
274 register_storage_idle_func,
275 unregister_storage_idle_func,
276 #endif /* USING_STORAGE_CALLBACK */
277 reload_directory,
278 create_numbered_filename,
279 file_exists,
281 /* dir */
282 opendir,
283 closedir,
284 readdir,
285 mkdir,
286 rmdir,
287 dir_exists,
289 /* kernel/ system */
290 PREFIX(sleep),
291 yield,
292 &current_tick,
293 default_event_handler,
294 default_event_handler_ex,
295 threads,
296 create_thread,
297 thread_exit,
298 thread_wait,
299 #if (CONFIG_CODEC == SWCODEC)
300 mutex_init,
301 mutex_lock,
302 mutex_unlock,
303 align_buffer,
304 #endif
306 reset_poweroff_timer,
307 #ifndef SIMULATOR
308 system_memory_guard,
309 &cpu_frequency,
311 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
312 #ifdef CPU_BOOST_LOGGING
313 cpu_boost_,
314 #else
315 cpu_boost,
316 #endif
317 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
318 #endif /* !SIMULATOR */
319 #ifdef HAVE_SCHEDULER_BOOSTCTRL
320 trigger_cpu_boost,
321 cancel_cpu_boost,
322 #endif
323 #ifdef CACHE_FUNCTIONS_AS_CALL
324 flush_icache,
325 invalidate_icache,
326 #endif
327 timer_register,
328 timer_unregister,
329 timer_set_period,
331 queue_init,
332 queue_delete,
333 queue_post,
334 queue_wait_w_tmo,
335 #if CONFIG_CODEC == SWCODEC
336 queue_enable_queue_send,
337 queue_empty,
338 queue_wait,
339 queue_send,
340 queue_reply,
341 #endif
342 usb_acknowledge,
343 #ifdef RB_PROFILE
344 profile_thread,
345 profstop,
346 __cyg_profile_func_enter,
347 __cyg_profile_func_exit,
348 #endif
350 #ifdef SIMULATOR
351 /* special simulator hooks */
352 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
353 sim_lcd_ex_init,
354 sim_lcd_ex_update_rect,
355 #endif
356 #endif
358 /* strings and memory */
359 snprintf,
360 vsnprintf,
361 strcpy,
362 strncpy,
363 strlen,
364 strrchr,
365 strcmp,
366 strncmp,
367 strcasecmp,
368 strncasecmp,
369 memset,
370 memcpy,
371 memmove,
372 _ctype_,
373 atoi,
374 strchr,
375 strcat,
376 memchr,
377 memcmp,
378 strcasestr,
379 strtok_r,
380 /* unicode stuff */
381 utf8decode,
382 iso_decode,
383 utf16LEdecode,
384 utf16BEdecode,
385 utf8encode,
386 utf8length,
387 utf8seek,
389 /* sound */
390 sound_set,
391 sound_default,
392 sound_min,
393 sound_max,
394 sound_unit,
395 sound_val2phys,
396 #ifndef SIMULATOR
397 mp3_play_data,
398 mp3_play_pause,
399 mp3_play_stop,
400 mp3_is_playing,
401 #if CONFIG_CODEC != SWCODEC
402 bitswap,
403 #endif
404 #endif
405 #if CONFIG_CODEC == SWCODEC
406 &audio_master_sampr_list[0],
407 &hw_freq_sampr[0],
408 pcm_apply_settings,
409 pcm_play_data,
410 pcm_play_stop,
411 pcm_set_frequency,
412 pcm_is_playing,
413 pcm_is_paused,
414 pcm_play_pause,
415 pcm_get_bytes_waiting,
416 pcm_calculate_peaks,
417 pcm_play_lock,
418 pcm_play_unlock,
419 #ifdef HAVE_RECORDING
420 &rec_freq_sampr[0],
421 pcm_init_recording,
422 pcm_close_recording,
423 pcm_record_data,
424 pcm_record_more,
425 pcm_stop_recording,
426 pcm_calculate_rec_peaks,
427 audio_set_recording_gain,
428 #endif /* HAVE_RECORDING */
429 #if INPUT_SRC_CAPS != 0
430 audio_set_output_source,
431 audio_set_input_source,
432 #endif
433 dsp_set_crossfeed,
434 dsp_set_eq,
435 dsp_dither_enable,
436 dsp_configure,
437 dsp_process,
438 #endif /* CONFIG_CODEC == SWCODEC */
440 /* playback control */
441 playlist_amount,
442 playlist_resume,
443 playlist_start,
444 PREFIX(audio_play),
445 audio_stop,
446 audio_pause,
447 audio_resume,
448 audio_next,
449 audio_prev,
450 audio_ff_rewind,
451 audio_next_track,
452 audio_status,
453 audio_has_changed_track,
454 audio_current_track,
455 audio_flush_and_reload_tracks,
456 audio_get_file_pos,
457 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
458 mpeg_get_last_header,
459 #endif
460 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
461 (CONFIG_CODEC == SWCODEC)
462 sound_set_pitch,
463 #endif
465 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
466 /* MAS communication */
467 mas_readmem,
468 mas_writemem,
469 mas_readreg,
470 mas_writereg,
471 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
472 mas_codec_writereg,
473 mas_codec_readreg,
474 i2c_begin,
475 i2c_end,
476 i2c_write,
477 #endif
478 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
480 /* menu */
481 do_menu,
482 /* statusbars */
483 &statusbars,
484 gui_syncstatusbar_draw,
485 /* options */
486 get_settings_list,
487 find_setting,
488 option_screen,
489 set_option,
490 set_bool_options,
491 set_int,
492 set_bool,
493 #ifdef HAVE_LCD_COLOR
494 set_color,
495 #endif
497 /* action handling */
498 get_custom_action,
499 get_action,
500 action_userabort,
502 /* power */
503 battery_level,
504 battery_level_safe,
505 battery_time,
506 #ifndef SIMULATOR
507 battery_voltage,
508 #endif
509 #if CONFIG_CHARGING
510 charger_inserted,
511 # if CONFIG_CHARGING == CHARGING_MONITOR
512 charging_state,
513 # endif
514 #endif
515 #ifdef HAVE_USB_POWER
516 usb_powered,
517 #endif
519 /* misc */
520 srand,
521 rand,
522 (qsort_func)qsort,
523 kbd_input,
524 get_time,
525 set_time,
526 #if CONFIG_RTC
527 mktime,
528 #endif
529 plugin_get_buffer,
530 plugin_get_audio_buffer,
531 plugin_tsr,
532 plugin_get_current_filename,
533 #ifdef PLUGIN_USE_IRAM
534 plugin_iram_init,
535 #endif
536 #if defined(DEBUG) || defined(SIMULATOR)
537 debugf,
538 #endif
539 #ifdef ROCKBOX_HAS_LOGF
540 _logf,
541 #endif
542 &global_settings,
543 &global_status,
544 talk_disable,
545 #if CONFIG_CODEC == SWCODEC
546 codec_load_file,
547 get_codec_filename,
548 get_metadata,
549 #endif
550 mp3info,
551 count_mp3_frames,
552 create_xing_header,
553 find_next_frame,
554 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
555 peak_meter_scale_value,
556 peak_meter_set_use_dbfs,
557 peak_meter_get_use_dbfs,
558 #endif
559 #ifdef HAVE_LCD_BITMAP
560 read_bmp_file,
561 screen_dump_set_hook,
562 #endif
563 show_logo,
564 tree_get_context,
565 set_current_file,
566 set_dirfilter,
568 #ifdef HAVE_WHEEL_POSITION
569 wheel_status,
570 wheel_send_events,
571 #endif
573 #ifdef IRIVER_H100_SERIES
574 /* Routines for the iriver_flash -plugin. */
575 detect_original_firmware,
576 detect_flashed_ramimage,
577 detect_flashed_romimage,
578 #endif
579 led,
580 #if (CONFIG_CODEC == SWCODEC)
581 bufopen,
582 bufalloc,
583 bufclose,
584 bufseek,
585 bufadvance,
586 bufread,
587 bufgetdata,
588 bufgettail,
589 bufcuttail,
591 buf_get_offset,
592 buf_handle_offset,
593 buf_request_buffer_handle,
594 buf_set_base_handle,
595 buf_used,
596 #endif
598 #ifdef HAVE_TAGCACHE
599 tagcache_search,
600 tagcache_search_set_uniqbuf,
601 tagcache_search_add_filter,
602 tagcache_get_next,
603 tagcache_retrieve,
604 tagcache_search_finish,
605 tagcache_get_numeric,
606 #endif
608 #ifdef HAVE_ALBUMART
609 find_albumart,
610 search_albumart_files,
611 #endif
613 thread_thaw,
615 #ifdef HAVE_SEMAPHORE_OBJECTS
616 semaphore_init,
617 semaphore_wait,
618 semaphore_release,
619 #endif
621 appsversion,
622 /* new stuff at the end, sort into place next time
623 the API gets incompatible */
626 int plugin_load(const char* plugin, const void* parameter)
628 int rc;
629 struct plugin_header *hdr;
630 #ifdef SIMULATOR
631 void *pd;
632 #else /* !SIMULATOR */
633 int fd;
634 ssize_t readsize;
635 #if NUM_CORES > 1
636 unsigned my_core;
637 #endif
638 #endif /* !SIMULATOR */
640 #if LCD_DEPTH > 1
641 fb_data* old_backdrop;
642 #endif
644 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
646 if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false )
648 /* not allowing another plugin to load */
649 return PLUGIN_OK;
651 pfn_tsr_exit = NULL;
652 plugin_loaded = false;
655 splash(0, ID2P(LANG_WAIT));
656 strcpy(current_plugin, plugin);
658 #ifdef SIMULATOR
659 hdr = sim_plugin_load((char *)plugin, &pd);
660 if (pd == NULL) {
661 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
662 return -1;
664 if (hdr == NULL
665 || hdr->magic != PLUGIN_MAGIC
666 || hdr->target_id != TARGET_ID) {
667 sim_plugin_close(pd);
668 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
669 return -1;
671 if (hdr->api_version > PLUGIN_API_VERSION
672 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
673 sim_plugin_close(pd);
674 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
675 return -1;
677 #else
678 fd = open(plugin, O_RDONLY);
679 if (fd < 0) {
680 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
681 return fd;
683 #if NUM_CORES > 1
684 /* Make sure COP cache is flushed and invalidated before loading */
685 my_core = switch_core(CURRENT_CORE ^ 1);
686 invalidate_icache();
687 switch_core(my_core);
688 #endif
690 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
691 close(fd);
693 if (readsize < 0) {
694 splashf(HZ*2, str(LANG_READ_FAILED), plugin);
695 return -1;
697 hdr = (struct plugin_header *)pluginbuf;
699 if ((unsigned)readsize <= sizeof(struct plugin_header)
700 || hdr->magic != PLUGIN_MAGIC
701 || hdr->target_id != TARGET_ID
702 || hdr->load_addr != pluginbuf
703 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
704 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
705 return -1;
707 if (hdr->api_version > PLUGIN_API_VERSION
708 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
709 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
710 return -1;
712 plugin_size = hdr->end_addr - pluginbuf;
714 /* zero out bss area only, above guards end of pluginbuf */
715 if (plugin_size > readsize)
716 memset(pluginbuf + readsize, 0, plugin_size - readsize);
717 #endif
719 plugin_loaded = true;
722 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
723 old_backdrop = lcd_get_backdrop();
724 #endif
725 lcd_clear_display();
726 lcd_update();
728 #ifdef HAVE_REMOTE_LCD
729 lcd_remote_clear_display();
730 lcd_remote_update();
731 #endif
733 invalidate_icache();
735 rc = hdr->entry_point(&rockbox_api, parameter);
737 button_clear_queue();
739 #ifdef HAVE_LCD_BITMAP
740 #if LCD_DEPTH > 1
741 lcd_set_backdrop(old_backdrop);
742 #ifdef HAVE_LCD_COLOR
743 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
744 global_settings.bg_color);
745 #else
746 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
747 #endif
748 #else /* LCD_DEPTH == 1 */
749 lcd_set_drawmode(DRMODE_SOLID);
750 #endif /* LCD_DEPTH */
751 #endif /* HAVE_LCD_BITMAP */
753 lcd_clear_display();
754 lcd_update();
756 #ifdef HAVE_REMOTE_LCD
757 #if LCD_REMOTE_DEPTH > 1
758 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG,
759 LCD_REMOTE_DEFAULT_BG);
760 #else
761 lcd_remote_set_drawmode(DRMODE_SOLID);
762 #endif
763 lcd_remote_clear_display();
766 lcd_remote_update();
769 #endif
771 if (pfn_tsr_exit == NULL)
772 plugin_loaded = false;
774 sim_plugin_close(pd);
776 switch (rc) {
777 case PLUGIN_OK:
778 break;
780 case PLUGIN_USB_CONNECTED:
781 return PLUGIN_USB_CONNECTED;
783 default:
784 splash(HZ*2, str(LANG_PLUGIN_ERROR));
785 break;
788 return PLUGIN_OK;
791 /* Returns a pointer to the portion of the plugin buffer that is not already
792 being used. If no plugin is loaded, returns the entire plugin buffer */
793 void* plugin_get_buffer(size_t *buffer_size)
795 int buffer_pos;
797 if (plugin_loaded)
799 if (plugin_size >= PLUGIN_BUFFER_SIZE)
800 return NULL;
802 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
803 buffer_pos = plugin_size;
805 else
807 *buffer_size = PLUGIN_BUFFER_SIZE;
808 buffer_pos = 0;
811 return &pluginbuf[buffer_pos];
814 /* Returns a pointer to the mp3 buffer.
815 Playback gets stopped, to avoid conflicts.
816 Talk buffer is stolen as well.
818 void* plugin_get_audio_buffer(size_t *buffer_size)
820 #if CONFIG_CODEC == SWCODEC
821 return audio_get_buffer(true, buffer_size);
822 #else
823 audio_stop();
824 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
825 *buffer_size = audiobufend - audiobuf;
826 return audiobuf;
827 #endif
830 #ifdef PLUGIN_USE_IRAM
831 /* Initializes plugin IRAM */
832 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
833 char *iedata, size_t iedata_size)
835 /* We need to stop audio playback in order to use codec IRAM */
836 audio_hard_stop();
837 memcpy(iramstart, iramcopy, iram_size);
838 memset(iedata, 0, iedata_size);
839 memset(iramcopy, 0, iram_size);
840 #if NUM_CORES > 1
841 /* writeback cleared iedata and iramcopy areas */
842 flush_icache();
843 #endif
845 #endif /* PLUGIN_USE_IRAM */
847 /* The plugin wants to stay resident after leaving its main function, e.g.
848 runs from timer or own thread. The callback is registered to later
849 instruct it to free its resources before a new plugin gets loaded. */
850 void plugin_tsr(bool (*exit_callback)(bool))
852 pfn_tsr_exit = exit_callback; /* remember the callback for later */
855 char *plugin_get_current_filename(void)
857 return current_plugin;