OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_ | 5 #ifndef MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_ |
6 #define MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_ | 6 #define MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_ |
7 | 7 |
8 #include <SLES/OpenSLES.h> | 8 #include <SLES/OpenSLES.h> |
9 #include <SLES/OpenSLES_Android.h> | 9 #include <SLES/OpenSLES_Android.h> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/synchronization/lock.h" |
| 13 #include "base/threading/thread_checker.h" |
12 #include "media/audio/audio_io.h" | 14 #include "media/audio/audio_io.h" |
13 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
14 #include "media/audio/android/opensles_util.h" | 16 #include "media/audio/android/opensles_util.h" |
15 | 17 |
16 namespace media { | 18 namespace media { |
17 | 19 |
18 class AudioManagerAndroid; | 20 class AudioManagerAndroid; |
19 | 21 |
20 // Implements PCM audio input support for Android using the OpenSLES API. | 22 // Implements PCM audio input support for Android using the OpenSLES API. |
21 class OpenSLESInputStream : public AudioInputStream { | 23 class OpenSLESInputStream : public AudioInputStream { |
(...skipping 12 matching lines...) Expand all Loading... |
34 virtual void Close() OVERRIDE; | 36 virtual void Close() OVERRIDE; |
35 virtual double GetMaxVolume() OVERRIDE; | 37 virtual double GetMaxVolume() OVERRIDE; |
36 virtual void SetVolume(double volume) OVERRIDE; | 38 virtual void SetVolume(double volume) OVERRIDE; |
37 virtual double GetVolume() OVERRIDE; | 39 virtual double GetVolume() OVERRIDE; |
38 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; | 40 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; |
39 virtual bool GetAutomaticGainControl() OVERRIDE; | 41 virtual bool GetAutomaticGainControl() OVERRIDE; |
40 | 42 |
41 private: | 43 private: |
42 bool CreateRecorder(); | 44 bool CreateRecorder(); |
43 | 45 |
| 46 // Called from OpenSLES specific audio worker thread. |
44 static void SimpleBufferQueueCallback( | 47 static void SimpleBufferQueueCallback( |
45 SLAndroidSimpleBufferQueueItf buffer_queue, void* instance); | 48 SLAndroidSimpleBufferQueueItf buffer_queue, void* instance); |
46 | 49 |
| 50 // Called from OpenSLES specific audio worker thread. |
47 void ReadBufferQueue(); | 51 void ReadBufferQueue(); |
48 | 52 |
49 // Called in Open(); | 53 // Called in Open(); |
50 void SetupAudioBuffer(); | 54 void SetupAudioBuffer(); |
51 | 55 |
52 // Called in Close(); | 56 // Called in Close(); |
53 void ReleaseAudioBuffer(); | 57 void ReleaseAudioBuffer(); |
54 | 58 |
55 // If OpenSLES reports an error this function handles it and passes it to | 59 // If OpenSLES reports an error this function handles it and passes it to |
56 // the attached AudioInputCallback::OnError(). | 60 // the attached AudioInputCallback::OnError(). |
57 void HandleError(SLresult error); | 61 void HandleError(SLresult error); |
58 | 62 |
| 63 base::ThreadChecker thread_checker_; |
| 64 |
| 65 base::Lock lock_; |
| 66 |
59 AudioManagerAndroid* audio_manager_; | 67 AudioManagerAndroid* audio_manager_; |
60 | 68 |
61 AudioInputCallback* callback_; | 69 AudioInputCallback* callback_; |
62 | 70 |
63 // Shared engine interfaces for the app. | 71 // Shared engine interfaces for the app. |
64 media::ScopedSLObjectItf recorder_object_; | 72 media::ScopedSLObjectItf recorder_object_; |
65 media::ScopedSLObjectItf engine_object_; | 73 media::ScopedSLObjectItf engine_object_; |
66 | 74 |
67 SLRecordItf recorder_; | 75 SLRecordItf recorder_; |
68 | 76 |
(...skipping 10 matching lines...) Expand all Loading... |
79 int buffer_size_bytes_; | 87 int buffer_size_bytes_; |
80 | 88 |
81 bool started_; | 89 bool started_; |
82 | 90 |
83 DISALLOW_COPY_AND_ASSIGN(OpenSLESInputStream); | 91 DISALLOW_COPY_AND_ASSIGN(OpenSLESInputStream); |
84 }; | 92 }; |
85 | 93 |
86 } // namespace media | 94 } // namespace media |
87 | 95 |
88 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_ | 96 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_ |
OLD | NEW |