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