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/recorder/pcm_record.c | 20 +++++++++++++++++++- apps/recorder/recording.c | 10 ---------- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'apps/recorder') diff --git a/apps/recorder/pcm_record.c b/apps/recorder/pcm_record.c index 2170e473bc..799c733948 100644 --- a/apps/recorder/pcm_record.c +++ b/apps/recorder/pcm_record.c @@ -24,6 +24,7 @@ #include "config.h" #include "system.h" #include "kernel.h" +#include "panic.h" #include "string-extra.h" #include "pcm_record.h" #include "codecs.h" @@ -40,6 +41,8 @@ #include "spdif.h" #endif #include "audio_thread.h" +#include "core_alloc.h" +#include "talk.h" /* Macros to enable logf for queues logging on SYS_TIMEOUT can be disabled */ @@ -1402,11 +1405,22 @@ static void tally_prerecord_data(void) /** Event handlers for recording thread **/ +static int pcmrec_handle; /* Q_AUDIO_INIT_RECORDING */ static void on_init_recording(void) { send_event(RECORDING_EVENT_START, NULL); - rec_buffer = audio_get_buffer(true, &rec_buffer_size); + /* dummy ops with no callbacks, needed because by + * default buflib buffers can be moved around which must be avoided + * FIXME: This buffer should play nicer and be shrinkable/movable */ + static struct buflib_callbacks dummy_ops; + talk_buffer_set_policy(TALK_BUFFER_LOOSE); + pcmrec_handle = core_alloc_maximum("pcmrec", &rec_buffer_size, &dummy_ops); + if (pcmrec_handle) + /* someone is abusing core_alloc_maximum(). Fix this evil guy instead of + * trying to handle OOM without hope */ + panicf("%s(): OOM\n", __func__); + rec_buffer = core_get_data(pcmrec_handle); init_rec_buffers(); init_state(); pcm_init_recording(); @@ -1430,6 +1444,10 @@ static void on_close_recording(void) audio_set_output_source(AUDIO_SRC_PLAYBACK); pcm_apply_settings(); + if (pcmrec_handle > 0) + pcmrec_handle = core_free(pcmrec_handle); + talk_buffer_set_policy(TALK_BUFFER_DEFAULT); + send_event(RECORDING_EVENT_STOP, NULL); } diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index 1c3460fbd0..4a7399b01e 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -691,15 +691,8 @@ void rec_set_source(int source, unsigned flags) void rec_set_recording_options(struct audio_recording_options *options) { -#if CONFIG_CODEC != SWCODEC - if (global_settings.rec_prerecord_time) - { - talk_buffer_steal(); /* will use the mp3 buffer */ - } -#else /* == SWCODEC */ rec_set_source(options->rec_source, options->rec_source_flags | SRCF_RECORDING); -#endif /* CONFIG_CODEC != SWCODEC */ audio_set_recording_options(options); } @@ -724,9 +717,6 @@ void rec_command(enum recording_command cmd) /* steal mp3 buffer, create unique filename and start recording */ pm_reset_clipcount(); pm_activate_clipcount(true); -#if CONFIG_CODEC != SWCODEC - talk_buffer_steal(); /* we use the mp3 buffer */ -#endif audio_record(rec_create_filename(path_buffer)); break; case RECORDING_CMD_START_NEWFILE: -- cgit v1.2.3