Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: media/audio/android/opensles_input.h

Issue 23296008: Adding audio unit tests for Android (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: wjia@ Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/audio/android/opensles_input.h
diff --git a/media/audio/android/opensles_input.h b/media/audio/android/opensles_input.h
index 9743992fc653e16cacbbce8644acec4e4d361f63..e05831c6712d6302bf2feb366539493ea50f21d6 100644
--- a/media/audio/android/opensles_input.h
+++ b/media/audio/android/opensles_input.h
@@ -9,18 +9,23 @@
#include <SLES/OpenSLES_Android.h>
#include "base/compiler_specific.h"
+#include "base/synchronization/lock.h"
+#include "base/threading/thread_checker.h"
+#include "media/audio/android/opensles_util.h"
#include "media/audio/audio_io.h"
#include "media/audio/audio_parameters.h"
-#include "media/audio/android/opensles_util.h"
namespace media {
class AudioManagerAndroid;
// Implements PCM audio input support for Android using the OpenSLES API.
+// This class is created and lives on the Audio Manager thread but recorded
+// audio buffers are given to us from an internal OpenSLES audio thread.
+// All public methods should be called on the Audio Manager thread.
class OpenSLESInputStream : public AudioInputStream {
public:
- static const int kNumOfQueuesInBuffer = 2;
+ static const int kMaxNumOfBuffersInQueue = 2;
OpenSLESInputStream(AudioManagerAndroid* manager,
const AudioParameters& params);
@@ -41,9 +46,12 @@ class OpenSLESInputStream : public AudioInputStream {
private:
bool CreateRecorder();
+ // Called from OpenSLES specific audio worker thread.
static void SimpleBufferQueueCallback(
- SLAndroidSimpleBufferQueueItf buffer_queue, void* instance);
+ SLAndroidSimpleBufferQueueItf buffer_queue,
+ void* instance);
+ // Called from OpenSLES specific audio worker thread.
void ReadBufferQueue();
// Called in Open();
@@ -56,6 +64,12 @@ class OpenSLESInputStream : public AudioInputStream {
// the attached AudioInputCallback::OnError().
void HandleError(SLresult error);
+ base::ThreadChecker thread_checker_;
+
+ // Protects |callback_|, |active_buffer_index_|, |audio_data_|,
+ // |buffer_size_bytes_| and |simple_buffer_queue_|.
+ base::Lock lock_;
+
AudioManagerAndroid* audio_manager_;
AudioInputCallback* callback_;
@@ -73,9 +87,9 @@ class OpenSLESInputStream : public AudioInputStream {
// Audio buffers that are allocated in the constructor based on
// info from audio parameters.
- uint8* audio_data_[kNumOfQueuesInBuffer];
+ uint8* audio_data_[kMaxNumOfBuffersInQueue];
- int active_queue_;
+ int active_buffer_index_;
int buffer_size_bytes_;
bool started_;

Powered by Google App Engine
This is Rietveld 408576698