summaryrefslogtreecommitdiff
path: root/apps/plugin.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2013-05-30 11:24:16 +0200
committerThomas Martitz <kugel@rockbox.org>2013-12-23 12:17:38 +0100
commit22e802e80048defd401462e062afcb10093ac793 (patch)
tree09d24f7eb2a3b18e6563e838398b2715394f7c4c /apps/plugin.c
parent64b9e1fa7b645daa36ca0018dc168d4f871fd538 (diff)
downloadrockbox-22e802e80048defd401462e062afcb10093ac793.zip
rockbox-22e802e80048defd401462e062afcb10093ac793.tar.gz
rockbox-22e802e80048defd401462e062afcb10093ac793.tar.bz2
rockbox-22e802e80048defd401462e062afcb10093ac793.tar.xz
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
Diffstat (limited to '')
-rw-r--r--apps/plugin.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 18c49f4..d80e6a1 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.