Index: media/audio/android/opensles_output.h |
diff --git a/media/audio/android/opensles_output.h b/media/audio/android/opensles_output.h |
index f505b5165cd4d2016ef3560d3a47e270c65c5977..7232d5da5f76210dee252f44946d141d075e19be 100644 |
--- a/media/audio/android/opensles_output.h |
+++ b/media/audio/android/opensles_output.h |
@@ -9,6 +9,8 @@ |
#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" |
@@ -18,9 +20,12 @@ namespace media { |
class AudioManagerAndroid; |
// Implements PCM audio output 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 OpenSLESOutputStream : public AudioOutputStream { |
public: |
- static const int kNumOfQueuesInBuffer = 2; |
+ static const int kMaxNumOfBuffersInQueue = 2; |
OpenSLESOutputStream(AudioManagerAndroid* manager, |
const AudioParameters& params); |
@@ -38,11 +43,18 @@ class OpenSLESOutputStream : public AudioOutputStream { |
private: |
bool CreatePlayer(); |
+ // Called from OpenSLES specific audio worker thread. |
static void SimpleBufferQueueCallback( |
- SLAndroidSimpleBufferQueueItf buffer_queue, void* instance); |
+ SLAndroidSimpleBufferQueueItf buffer_queue, |
+ void* instance); |
+ // Fills up one buffer by asking the registered source for data. |
+ // Called from OpenSLES specific audio worker thread. |
void FillBufferQueue(); |
+ // Called from the audio manager thread. |
+ void FillBufferQueueNoLock(); |
+ |
// Called in Open(); |
void SetupAudioBuffer(); |
@@ -53,6 +65,12 @@ class OpenSLESOutputStream : public AudioOutputStream { |
// the attached AudioOutputCallback::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_; |
AudioSourceCallback* callback_; |
@@ -69,10 +87,11 @@ class OpenSLESOutputStream : public AudioOutputStream { |
SLDataFormat_PCM format_; |
- // Audio buffer arrays that are allocated in the constructor. |
- uint8* audio_data_[kNumOfQueuesInBuffer]; |
+ // Audio buffers that are allocated in the constructor based on |
+ // info from audio parameters. |
+ uint8* audio_data_[kMaxNumOfBuffersInQueue]; |
- int active_queue_; |
+ int active_buffer_index_; |
size_t buffer_size_bytes_; |
bool started_; |
@@ -88,4 +107,4 @@ class OpenSLESOutputStream : public AudioOutputStream { |
} // namespace media |
-#endif // MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_ |
+#endif // MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_ |