summaryrefslogtreecommitdiffstats
path: root/src/android/AudioRecorder_to_android.cpp
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2014-04-24 09:29:05 -0700
committerGlenn Kasten <gkasten@google.com>2014-08-27 08:46:37 -0700
commit460bdad43aaec3c6ffe7f259719e00807742ad6d (patch)
tree5c976d1fb176f9cd5dc04f1d68d0af4fe7a4b7b3 /src/android/AudioRecorder_to_android.cpp
parentd0081ece36dcb6ecdadeb9fc0ee912cffb7effc7 (diff)
downloadandroid_frameworks_wilhelm-460bdad43aaec3c6ffe7f259719e00807742ad6d.tar.gz
android_frameworks_wilhelm-460bdad43aaec3c6ffe7f259719e00807742ad6d.tar.bz2
android_frameworks_wilhelm-460bdad43aaec3c6ffe7f259719e00807742ad6d.zip
Audio recorder missing a callback protectorstaging/cm-12.0-caf
Bug: 14291968 Change-Id: I620d5e82f58e57e87097984a649b5c3a25c42963
Diffstat (limited to 'src/android/AudioRecorder_to_android.cpp')
-rw-r--r--src/android/AudioRecorder_to_android.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/android/AudioRecorder_to_android.cpp b/src/android/AudioRecorder_to_android.cpp
index ebb9592..800a767 100644
--- a/src/android/AudioRecorder_to_android.cpp
+++ b/src/android/AudioRecorder_to_android.cpp
@@ -212,6 +212,12 @@ static void audioRecorder_callback(int event, void* user, void *info) {
//SL_LOGV("audioRecorder_callback(%d, %p, %p) entering", event, user, info);
CAudioRecorder *ar = (CAudioRecorder *)user;
+
+ if (!android::CallbackProtector::enterCbIfOk(ar->mCallbackProtector)) {
+ // it is not safe to enter the callback (the track is about to go away)
+ return;
+ }
+
void * callbackPContext = NULL;
switch(event) {
@@ -289,6 +295,8 @@ static void audioRecorder_callback(int event, void* user, void *info) {
break;
}
+
+ ar->mCallbackProtector->exitCb();
}
@@ -312,6 +320,7 @@ SLresult android_audioRecorder_create(CAudioRecorder* ar) {
// microphone to simple buffer queue
ar->mAndroidObjType = AUDIORECORDER_FROM_MIC_TO_PCM_BUFFERQUEUE;
ar->mAudioRecord.clear();
+ ar->mCallbackProtector = new android::CallbackProtector();
ar->mRecordSource = AUDIO_SOURCE_DEFAULT;
} else {
result = SL_RESULT_CONTENT_UNSUPPORTED;
@@ -430,14 +439,29 @@ SLresult android_audioRecorder_realize(CAudioRecorder* ar, SLboolean async) {
//-----------------------------------------------------------------------------
+/**
+ * Called with a lock on AudioRecorder, and blocks until safe to destroy
+ */
+void android_audioRecorder_preDestroy(CAudioRecorder* ar) {
+ object_unlock_exclusive(&ar->mObject);
+ if (ar->mCallbackProtector != 0) {
+ ar->mCallbackProtector->requestCbExitAndWait();
+ }
+ object_lock_exclusive(&ar->mObject);
+}
+
+
+//-----------------------------------------------------------------------------
void android_audioRecorder_destroy(CAudioRecorder* ar) {
SL_LOGV("android_audioRecorder_destroy(%p) entering", ar);
if (ar->mAudioRecord != 0) {
ar->mAudioRecord->stop();
+ ar->mAudioRecord.clear();
}
// explicit destructor
ar->mAudioRecord.~sp();
+ ar->mCallbackProtector.~sp();
#ifdef MONITOR_RECORDING
if (NULL != gMonitorFp) {