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

Side by Side 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: Feedback from tommi@ 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 unified diff | Download patch
OLDNEW
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 {
22 public: 24 public:
23 static const int kNumOfQueuesInBuffer = 2; 25 static const int kMaxNumOfBuffersInQueue = 2;
24 26
25 OpenSLESInputStream(AudioManagerAndroid* manager, 27 OpenSLESInputStream(AudioManagerAndroid* manager,
26 const AudioParameters& params); 28 const AudioParameters& params);
27 29
28 virtual ~OpenSLESInputStream(); 30 virtual ~OpenSLESInputStream();
29 31
30 // Implementation of AudioInputStream. 32 // Implementation of AudioInputStream.
31 virtual bool Open() OVERRIDE; 33 virtual bool Open() OVERRIDE;
32 virtual void Start(AudioInputCallback* callback) OVERRIDE; 34 virtual void Start(AudioInputCallback* callback) OVERRIDE;
33 virtual void Stop() OVERRIDE; 35 virtual void Stop() OVERRIDE;
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 // Protects |started_|, |callback_|, |active_queue_|, |audio_data_|,
66 // |buffer_size_bytes_| and |simple_buffer_queue_|.
67 base::Lock lock_;
68
59 AudioManagerAndroid* audio_manager_; 69 AudioManagerAndroid* audio_manager_;
60 70
61 AudioInputCallback* callback_; 71 AudioInputCallback* callback_;
62 72
63 // Shared engine interfaces for the app. 73 // Shared engine interfaces for the app.
64 media::ScopedSLObjectItf recorder_object_; 74 media::ScopedSLObjectItf recorder_object_;
65 media::ScopedSLObjectItf engine_object_; 75 media::ScopedSLObjectItf engine_object_;
66 76
67 SLRecordItf recorder_; 77 SLRecordItf recorder_;
68 78
69 // Buffer queue recorder interface. 79 // Buffer queue recorder interface.
70 SLAndroidSimpleBufferQueueItf simple_buffer_queue_; 80 SLAndroidSimpleBufferQueueItf simple_buffer_queue_;
71 81
72 SLDataFormat_PCM format_; 82 SLDataFormat_PCM format_;
73 83
74 // Audio buffers that are allocated in the constructor based on 84 // Audio buffers that are allocated in the constructor based on
75 // info from audio parameters. 85 // info from audio parameters.
76 uint8* audio_data_[kNumOfQueuesInBuffer]; 86 uint8* audio_data_[kMaxNumOfBuffersInQueue];
77 87
78 int active_queue_; 88 int active_buffer_;
79 int buffer_size_bytes_; 89 int buffer_size_bytes_;
80 90
81 bool started_; 91 bool started_;
82 92
83 DISALLOW_COPY_AND_ASSIGN(OpenSLESInputStream); 93 DISALLOW_COPY_AND_ASSIGN(OpenSLESInputStream);
84 }; 94 };
85 95
86 } // namespace media 96 } // namespace media
87 97
88 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_ 98 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_INPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698