From 22e802e80048defd401462e062afcb10093ac793 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Thu, 30 May 2013 11:24:16 +0200 Subject: playback,talk: Share audiobuffer via core_alloc_maximum(). This fixes the radioart crash that was the result of buffering.c working on a freed buffer at the same time as buflib (radioart uses buffering.c for the images). With this change the buffer is owned by buflib exclusively so this cannot happen. As a result, audio_get_buffer() doesn't exist anymore. Callers should call core_alloc_maximum() directly. This buffer needs to be protected as usual against movement if necessary (previously it was not protected at all which cased the radioart crash), To get most of it they can adjust the willingness of the talk engine to give its buffer away (at the expense of disabling voice interface) with the new talk_buffer_set_policy() function. Change-Id: I52123012208d04967876a304451d634e2bef3a33 --- apps/plugin.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'apps/plugin.c') diff --git a/apps/plugin.c b/apps/plugin.c index 18c49f4c27..d80e6a1e0e 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -801,6 +801,8 @@ static const struct plugin_api rockbox_api = { the API gets incompatible */ }; +static int plugin_buffer_handle; + int plugin_load(const char* plugin, const void* parameter) { struct plugin_header *p_hdr; @@ -815,6 +817,8 @@ int plugin_load(const char* plugin, const void* parameter) } lc_close(current_plugin_handle); current_plugin_handle = pfn_tsr_exit = NULL; + if (plugin_buffer_handle > 0) + plugin_buffer_handle = core_free(plugin_buffer_handle); } splash(0, ID2P(LANG_WAIT)); @@ -878,6 +882,9 @@ int plugin_load(const char* plugin, const void* parameter) touchscreen_set_mode(TOUCHSCREEN_BUTTON); #endif + /* allow voice to back off if the plugin needs lots of memory */ + talk_buffer_set_policy(TALK_BUFFER_LOOSE); + #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE open_files = 0; #endif @@ -891,8 +898,12 @@ int plugin_load(const char* plugin, const void* parameter) { /* close handle if plugin is no tsr one */ lc_close(current_plugin_handle); current_plugin_handle = NULL; + if (plugin_buffer_handle > 0) + plugin_buffer_handle = core_free(plugin_buffer_handle); } + talk_buffer_set_policy(TALK_BUFFER_DEFAULT); + /* Go back to the global setting in case the plugin changed it */ #ifdef HAVE_TOUCHSCREEN touchscreen_set_mode(global_settings.touch_mode); @@ -984,8 +995,12 @@ void* plugin_get_buffer(size_t *buffer_size) */ void* plugin_get_audio_buffer(size_t *buffer_size) { - audio_stop(); - return audio_get_buffer(true, buffer_size); + /* dummy ops with no callbacks, needed because by + * default buflib buffers can be moved around which must be avoided */ + static struct buflib_callbacks dummy_ops; + plugin_buffer_handle = core_alloc_maximum("plugin audio buf", buffer_size, + &dummy_ops); + return core_get_data(plugin_buffer_handle); } /* The plugin wants to stay resident after leaving its main function, e.g. -- cgit v1.2.3