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