Cleaner solution to plugin-included core files.
[kugel-rb.git] / apps / plugin.c
blob3efd31ccc96951405fb9a786ff1bee801d4b0018
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,
213 viewportmanager_set_statusbar,
215 /* list */
216 gui_synclist_init,
217 gui_synclist_set_nb_items,
218 gui_synclist_set_icon_callback,
219 gui_synclist_get_nb_items,
220 gui_synclist_get_sel_pos,
221 gui_synclist_draw,
222 gui_synclist_select_item,
223 gui_synclist_add_item,
224 gui_synclist_del_item,
225 gui_synclist_limit_scroll,
226 gui_synclist_do_button,
227 gui_synclist_set_title,
228 gui_syncyesno_run,
229 simplelist_info_init,
230 simplelist_show_list,
232 /* button */
233 button_get,
234 button_get_w_tmo,
235 button_status,
236 #ifdef HAVE_BUTTON_DATA
237 button_get_data,
238 #endif
239 button_clear_queue,
240 button_queue_count,
241 #ifdef HAS_BUTTON_HOLD
242 button_hold,
243 #endif
244 #ifdef HAVE_TOUCHSCREEN
245 touchscreen_set_mode,
246 #endif
248 #ifdef HAVE_BUTTON_LIGHT
249 buttonlight_set_timeout,
250 buttonlight_off,
251 buttonlight_on,
252 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
253 buttonlight_set_brightness,
254 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
255 #endif /* HAVE_BUTTON_LIGHT */
257 /* file */
258 (open_func)PREFIX(open),
259 PREFIX(close),
260 (read_func)PREFIX(read),
261 PREFIX(lseek),
262 (creat_func)PREFIX(creat),
263 (write_func)PREFIX(write),
264 PREFIX(remove),
265 PREFIX(rename),
266 PREFIX(ftruncate),
267 PREFIX(filesize),
268 fdprintf,
269 read_line,
270 settings_parseline,
271 storage_sleep,
272 storage_spin,
273 storage_spindown,
274 #if USING_STORAGE_CALLBACK
275 register_storage_idle_func,
276 unregister_storage_idle_func,
277 #endif /* USING_STORAGE_CALLBACK */
278 reload_directory,
279 create_numbered_filename,
280 file_exists,
282 /* dir */
283 opendir,
284 closedir,
285 readdir,
286 mkdir,
287 rmdir,
288 dir_exists,
290 /* kernel/ system */
291 PREFIX(sleep),
292 yield,
293 &current_tick,
294 default_event_handler,
295 default_event_handler_ex,
296 threads,
297 create_thread,
298 thread_exit,
299 thread_wait,
300 #if (CONFIG_CODEC == SWCODEC)
301 mutex_init,
302 mutex_lock,
303 mutex_unlock,
304 align_buffer,
305 #endif
307 reset_poweroff_timer,
308 #ifndef SIMULATOR
309 system_memory_guard,
310 &cpu_frequency,
312 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
313 #ifdef CPU_BOOST_LOGGING
314 cpu_boost_,
315 #else
316 cpu_boost,
317 #endif
318 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
319 #endif /* !SIMULATOR */
320 #ifdef HAVE_SCHEDULER_BOOSTCTRL
321 trigger_cpu_boost,
322 cancel_cpu_boost,
323 #endif
324 #ifdef CACHE_FUNCTIONS_AS_CALL
325 flush_icache,
326 invalidate_icache,
327 #endif
328 timer_register,
329 timer_unregister,
330 timer_set_period,
332 queue_init,
333 queue_delete,
334 queue_post,
335 queue_wait_w_tmo,
336 #if CONFIG_CODEC == SWCODEC
337 queue_enable_queue_send,
338 queue_empty,
339 queue_wait,
340 queue_send,
341 queue_reply,
342 #endif
343 usb_acknowledge,
344 #ifdef RB_PROFILE
345 profile_thread,
346 profstop,
347 __cyg_profile_func_enter,
348 __cyg_profile_func_exit,
349 #endif
351 #ifdef SIMULATOR
352 /* special simulator hooks */
353 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
354 sim_lcd_ex_init,
355 sim_lcd_ex_update_rect,
356 #endif
357 #endif
359 /* strings and memory */
360 snprintf,
361 vsnprintf,
362 strcpy,
363 strncpy,
364 strlen,
365 strrchr,
366 strcmp,
367 strncmp,
368 strcasecmp,
369 strncasecmp,
370 memset,
371 memcpy,
372 memmove,
373 _ctype_,
374 atoi,
375 strchr,
376 strcat,
377 memchr,
378 memcmp,
379 strcasestr,
380 strtok_r,
381 /* unicode stuff */
382 utf8decode,
383 iso_decode,
384 utf16LEdecode,
385 utf16BEdecode,
386 utf8encode,
387 utf8length,
388 utf8seek,
390 /* sound */
391 sound_set,
392 sound_default,
393 sound_min,
394 sound_max,
395 sound_unit,
396 sound_val2phys,
397 #ifndef SIMULATOR
398 mp3_play_data,
399 mp3_play_pause,
400 mp3_play_stop,
401 mp3_is_playing,
402 #if CONFIG_CODEC != SWCODEC
403 bitswap,
404 #endif
405 #endif
406 #if CONFIG_CODEC == SWCODEC
407 &audio_master_sampr_list[0],
408 &hw_freq_sampr[0],
409 pcm_apply_settings,
410 pcm_play_data,
411 pcm_play_stop,
412 pcm_set_frequency,
413 pcm_is_playing,
414 pcm_is_paused,
415 pcm_play_pause,
416 pcm_get_bytes_waiting,
417 pcm_calculate_peaks,
418 pcm_play_lock,
419 pcm_play_unlock,
420 #ifdef HAVE_RECORDING
421 &rec_freq_sampr[0],
422 pcm_init_recording,
423 pcm_close_recording,
424 pcm_record_data,
425 pcm_record_more,
426 pcm_stop_recording,
427 pcm_calculate_rec_peaks,
428 audio_set_recording_gain,
429 #endif /* HAVE_RECORDING */
430 #if INPUT_SRC_CAPS != 0
431 audio_set_output_source,
432 audio_set_input_source,
433 #endif
434 dsp_set_crossfeed,
435 dsp_set_eq,
436 dsp_dither_enable,
437 dsp_configure,
438 dsp_process,
439 #endif /* CONFIG_CODEC == SWCODEC */
441 /* playback control */
442 playlist_amount,
443 playlist_resume,
444 playlist_start,
445 PREFIX(audio_play),
446 audio_stop,
447 audio_pause,
448 audio_resume,
449 audio_next,
450 audio_prev,
451 audio_ff_rewind,
452 audio_next_track,
453 audio_status,
454 audio_has_changed_track,
455 audio_current_track,
456 audio_flush_and_reload_tracks,
457 audio_get_file_pos,
458 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
459 mpeg_get_last_header,
460 #endif
461 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
462 (CONFIG_CODEC == SWCODEC)
463 sound_set_pitch,
464 #endif
466 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
467 /* MAS communication */
468 mas_readmem,
469 mas_writemem,
470 mas_readreg,
471 mas_writereg,
472 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
473 mas_codec_writereg,
474 mas_codec_readreg,
475 i2c_begin,
476 i2c_end,
477 i2c_write,
478 #endif
479 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
481 /* menu */
482 do_menu,
483 /* statusbars */
484 &statusbars,
485 gui_syncstatusbar_draw,
486 /* options */
487 get_settings_list,
488 find_setting,
489 option_screen,
490 set_option,
491 set_bool_options,
492 set_int,
493 set_bool,
494 #ifdef HAVE_LCD_COLOR
495 set_color,
496 #endif
498 /* action handling */
499 get_custom_action,
500 get_action,
501 action_userabort,
503 /* power */
504 battery_level,
505 battery_level_safe,
506 battery_time,
507 #ifndef SIMULATOR
508 battery_voltage,
509 #endif
510 #if CONFIG_CHARGING
511 charger_inserted,
512 # if CONFIG_CHARGING == CHARGING_MONITOR
513 charging_state,
514 # endif
515 #endif
516 #ifdef HAVE_USB_POWER
517 usb_powered,
518 #endif
520 /* misc */
521 srand,
522 rand,
523 (qsort_func)qsort,
524 kbd_input,
525 get_time,
526 set_time,
527 #if CONFIG_RTC
528 mktime,
529 #endif
530 plugin_get_buffer,
531 plugin_get_audio_buffer,
532 plugin_tsr,
533 plugin_get_current_filename,
534 #ifdef PLUGIN_USE_IRAM
535 plugin_iram_init,
536 #endif
537 #if defined(DEBUG) || defined(SIMULATOR)
538 debugf,
539 #endif
540 #ifdef ROCKBOX_HAS_LOGF
541 _logf,
542 #endif
543 &global_settings,
544 &global_status,
545 talk_disable,
546 #if CONFIG_CODEC == SWCODEC
547 codec_load_file,
548 get_codec_filename,
549 get_metadata,
550 #endif
551 mp3info,
552 count_mp3_frames,
553 create_xing_header,
554 find_next_frame,
555 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
556 peak_meter_scale_value,
557 peak_meter_set_use_dbfs,
558 peak_meter_get_use_dbfs,
559 #endif
560 #ifdef HAVE_LCD_BITMAP
561 read_bmp_file,
562 screen_dump_set_hook,
563 #endif
564 show_logo,
565 tree_get_context,
566 set_current_file,
567 set_dirfilter,
569 #ifdef HAVE_WHEEL_POSITION
570 wheel_status,
571 wheel_send_events,
572 #endif
574 #ifdef IRIVER_H100_SERIES
575 /* Routines for the iriver_flash -plugin. */
576 detect_original_firmware,
577 detect_flashed_ramimage,
578 detect_flashed_romimage,
579 #endif
580 led,
581 #if (CONFIG_CODEC == SWCODEC)
582 bufopen,
583 bufalloc,
584 bufclose,
585 bufseek,
586 bufadvance,
587 bufread,
588 bufgetdata,
589 bufgettail,
590 bufcuttail,
592 buf_get_offset,
593 buf_handle_offset,
594 buf_request_buffer_handle,
595 buf_set_base_handle,
596 buf_used,
597 #endif
599 #ifdef HAVE_TAGCACHE
600 tagcache_search,
601 tagcache_search_set_uniqbuf,
602 tagcache_search_add_filter,
603 tagcache_get_next,
604 tagcache_retrieve,
605 tagcache_search_finish,
606 tagcache_get_numeric,
607 #endif
609 #ifdef HAVE_ALBUMART
610 find_albumart,
611 search_albumart_files,
612 #endif
614 thread_thaw,
616 #ifdef HAVE_SEMAPHORE_OBJECTS
617 semaphore_init,
618 semaphore_wait,
619 semaphore_release,
620 #endif
622 appsversion,
623 /* new stuff at the end, sort into place next time
624 the API gets incompatible */
627 int plugin_load(const char* plugin, const void* parameter)
629 int rc;
630 struct plugin_header *hdr;
631 #ifdef SIMULATOR
632 void *pd;
633 #else /* !SIMULATOR */
634 int fd;
635 ssize_t readsize;
636 #if NUM_CORES > 1
637 unsigned my_core;
638 #endif
639 #endif /* !SIMULATOR */
641 #if LCD_DEPTH > 1
642 fb_data* old_backdrop;
643 #endif
645 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
647 if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false )
649 /* not allowing another plugin to load */
650 return PLUGIN_OK;
652 pfn_tsr_exit = NULL;
653 plugin_loaded = false;
656 splash(0, ID2P(LANG_WAIT));
657 strcpy(current_plugin, plugin);
659 #ifdef SIMULATOR
660 hdr = sim_plugin_load((char *)plugin, &pd);
661 if (pd == NULL) {
662 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
663 return -1;
665 if (hdr == NULL
666 || hdr->magic != PLUGIN_MAGIC
667 || hdr->target_id != TARGET_ID) {
668 sim_plugin_close(pd);
669 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
670 return -1;
672 if (hdr->api_version > PLUGIN_API_VERSION
673 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
674 sim_plugin_close(pd);
675 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
676 return -1;
678 #else
679 fd = open(plugin, O_RDONLY);
680 if (fd < 0) {
681 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
682 return fd;
684 #if NUM_CORES > 1
685 /* Make sure COP cache is flushed and invalidated before loading */
686 my_core = switch_core(CURRENT_CORE ^ 1);
687 invalidate_icache();
688 switch_core(my_core);
689 #endif
691 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
692 close(fd);
694 if (readsize < 0) {
695 splashf(HZ*2, str(LANG_READ_FAILED), plugin);
696 return -1;
698 hdr = (struct plugin_header *)pluginbuf;
700 if ((unsigned)readsize <= sizeof(struct plugin_header)
701 || hdr->magic != PLUGIN_MAGIC
702 || hdr->target_id != TARGET_ID
703 || hdr->load_addr != pluginbuf
704 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
705 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
706 return -1;
708 if (hdr->api_version > PLUGIN_API_VERSION
709 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
710 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
711 return -1;
713 plugin_size = hdr->end_addr - pluginbuf;
715 /* zero out bss area only, above guards end of pluginbuf */
716 if (plugin_size > readsize)
717 memset(pluginbuf + readsize, 0, plugin_size - readsize);
718 #endif
720 plugin_loaded = true;
723 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
724 old_backdrop = lcd_get_backdrop();
725 #endif
726 lcd_clear_display();
727 lcd_update();
729 #ifdef HAVE_REMOTE_LCD
730 lcd_remote_clear_display();
731 lcd_remote_update();
732 #endif
734 invalidate_icache();
735 viewportmanager_set_statusbar(false);
737 rc = hdr->entry_point(&rockbox_api, parameter);
739 viewportmanager_set_statusbar(true);
741 button_clear_queue();
743 #ifdef HAVE_LCD_BITMAP
744 #if LCD_DEPTH > 1
745 lcd_set_backdrop(old_backdrop);
746 #ifdef HAVE_LCD_COLOR
747 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
748 global_settings.bg_color);
749 #else
750 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
751 #endif
752 #else /* LCD_DEPTH == 1 */
753 lcd_set_drawmode(DRMODE_SOLID);
754 #endif /* LCD_DEPTH */
755 #endif /* HAVE_LCD_BITMAP */
757 lcd_clear_display();
758 lcd_update();
760 #ifdef HAVE_REMOTE_LCD
761 #if LCD_REMOTE_DEPTH > 1
762 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG,
763 LCD_REMOTE_DEFAULT_BG);
764 #else
765 lcd_remote_set_drawmode(DRMODE_SOLID);
766 #endif
767 lcd_remote_clear_display();
770 lcd_remote_update();
773 #endif
775 if (pfn_tsr_exit == NULL)
776 plugin_loaded = false;
778 sim_plugin_close(pd);
780 switch (rc) {
781 case PLUGIN_OK:
782 break;
784 case PLUGIN_USB_CONNECTED:
785 return PLUGIN_USB_CONNECTED;
787 default:
788 splash(HZ*2, str(LANG_PLUGIN_ERROR));
789 break;
792 return PLUGIN_OK;
795 /* Returns a pointer to the portion of the plugin buffer that is not already
796 being used. If no plugin is loaded, returns the entire plugin buffer */
797 void* plugin_get_buffer(size_t *buffer_size)
799 int buffer_pos;
801 if (plugin_loaded)
803 if (plugin_size >= PLUGIN_BUFFER_SIZE)
804 return NULL;
806 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
807 buffer_pos = plugin_size;
809 else
811 *buffer_size = PLUGIN_BUFFER_SIZE;
812 buffer_pos = 0;
815 return &pluginbuf[buffer_pos];
818 /* Returns a pointer to the mp3 buffer.
819 Playback gets stopped, to avoid conflicts.
820 Talk buffer is stolen as well.
822 void* plugin_get_audio_buffer(size_t *buffer_size)
824 #if CONFIG_CODEC == SWCODEC
825 return audio_get_buffer(true, buffer_size);
826 #else
827 audio_stop();
828 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
829 *buffer_size = audiobufend - audiobuf;
830 return audiobuf;
831 #endif
834 #ifdef PLUGIN_USE_IRAM
835 /* Initializes plugin IRAM */
836 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
837 char *iedata, size_t iedata_size)
839 /* We need to stop audio playback in order to use codec IRAM */
840 audio_hard_stop();
841 memcpy(iramstart, iramcopy, iram_size);
842 memset(iedata, 0, iedata_size);
843 memset(iramcopy, 0, iram_size);
844 #if NUM_CORES > 1
845 /* writeback cleared iedata and iramcopy areas */
846 flush_icache();
847 #endif
849 #endif /* PLUGIN_USE_IRAM */
851 /* The plugin wants to stay resident after leaving its main function, e.g.
852 runs from timer or own thread. The callback is registered to later
853 instruct it to free its resources before a new plugin gets loaded. */
854 void plugin_tsr(bool (*exit_callback)(bool))
856 pfn_tsr_exit = exit_callback; /* remember the callback for later */
859 char *plugin_get_current_filename(void)
861 return current_plugin;