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 // Implementation of AudioInputStream for Mac OS X using the special AUHAL | 5 // Implementation of AudioInputStream for Mac OS X using the special AUHAL |
6 // input Audio Unit present in OS 10.4 and later. | 6 // input Audio Unit present in OS 10.4 and later. |
7 // The AUHAL input Audio Unit is for low-latency audio I/O. | 7 // The AUHAL input Audio Unit is for low-latency audio I/O. |
8 // | 8 // |
9 // Overview of operation: | 9 // Overview of operation: |
10 // | 10 // |
(...skipping 20 matching lines...) Expand all Loading... | |
31 // 1) Hardware latency, which includes Audio Unit latency, audio device | 31 // 1) Hardware latency, which includes Audio Unit latency, audio device |
32 // latency; | 32 // latency; |
33 // 2) The delay between the actual recording instant and the time when the | 33 // 2) The delay between the actual recording instant and the time when the |
34 // data packet is provided as a callback. | 34 // data packet is provided as a callback. |
35 // | 35 // |
36 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ | 36 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ |
37 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ | 37 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ |
38 | 38 |
39 #include <AudioUnit/AudioUnit.h> | 39 #include <AudioUnit/AudioUnit.h> |
40 | 40 |
41 #include "base/atomicops.h" | |
41 #include "base/memory/scoped_ptr.h" | 42 #include "base/memory/scoped_ptr.h" |
42 #include "base/synchronization/lock.h" | 43 #include "base/synchronization/lock.h" |
44 #include "base/time.h" | |
43 #include "media/audio/audio_io.h" | 45 #include "media/audio/audio_io.h" |
44 #include "media/audio/audio_parameters.h" | 46 #include "media/audio/audio_parameters.h" |
45 | 47 |
46 class AudioManagerMac; | 48 class AudioManagerMac; |
47 | 49 |
48 class AUAudioInputStream : public AudioInputStream { | 50 class AUAudioInputStream : public AudioInputStream { |
49 public: | 51 public: |
50 // The ctor takes all the usual parameters, plus |manager| which is the | 52 // The ctor takes all the usual parameters, plus |manager| which is the |
51 // the audio manager who is creating this object. | 53 // the audio manager who is creating this object. |
52 AUAudioInputStream(AudioManagerMac* manager, | 54 AUAudioInputStream(AudioManagerMac* manager, |
53 const AudioParameters& params, | 55 const AudioParameters& params, |
54 AudioDeviceID audio_device_id); | 56 AudioDeviceID audio_device_id); |
55 // The dtor is typically called by the AudioManager only and it is usually | 57 // The dtor is typically called by the AudioManager only and it is usually |
56 // triggered by calling AudioInputStream::Close(). | 58 // triggered by calling AudioInputStream::Close(). |
57 virtual ~AUAudioInputStream(); | 59 virtual ~AUAudioInputStream(); |
58 | 60 |
59 // Implementation of AudioInputStream. | 61 // Implementation of AudioInputStream. |
60 virtual bool Open() OVERRIDE; | 62 virtual bool Open() OVERRIDE; |
61 virtual void Start(AudioInputCallback* callback) OVERRIDE; | 63 virtual void Start(AudioInputCallback* callback) OVERRIDE; |
62 virtual void Stop() OVERRIDE; | 64 virtual void Stop() OVERRIDE; |
63 virtual void Close() OVERRIDE; | 65 virtual void Close() OVERRIDE; |
64 virtual double GetMaxVolume() OVERRIDE; | 66 virtual double GetMaxVolume() OVERRIDE; |
65 virtual void SetVolume(double volume) OVERRIDE; | 67 virtual void SetVolume(double volume) OVERRIDE; |
66 virtual double GetVolume() OVERRIDE; | 68 virtual double GetVolume() OVERRIDE; |
69 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; | |
70 virtual bool GetAutomaticGainControl() OVERRIDE; | |
67 | 71 |
68 // Returns the current hardware sample rate for the default input device. | 72 // Returns the current hardware sample rate for the default input device. |
69 static double HardwareSampleRate(); | 73 static double HardwareSampleRate(); |
70 | 74 |
71 bool started() const { return started_; } | 75 bool started() const { return started_; } |
72 AudioUnit audio_unit() { return audio_unit_; } | 76 AudioUnit audio_unit() { return audio_unit_; } |
73 AudioBufferList* audio_buffer_list() { return &audio_buffer_list_; } | 77 AudioBufferList* audio_buffer_list() { return &audio_buffer_list_; } |
74 | 78 |
75 private: | 79 private: |
76 // AudioOutputUnit callback. | 80 // AudioOutputUnit callback. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 // True after successfull Start(), false after successful Stop(). | 137 // True after successfull Start(), false after successful Stop(). |
134 bool started_; | 138 bool started_; |
135 | 139 |
136 // Fixed capture hardware latency in frames. | 140 // Fixed capture hardware latency in frames. |
137 double hardware_latency_frames_; | 141 double hardware_latency_frames_; |
138 | 142 |
139 // The number of channels in each frame of audio data, which is used | 143 // The number of channels in each frame of audio data, which is used |
140 // when querying the volume of each channel. | 144 // when querying the volume of each channel. |
141 int number_of_channels_in_frame_; | 145 int number_of_channels_in_frame_; |
142 | 146 |
147 // Keeps track of last time a new volume level was fed to the client in an | |
148 // OnData() callback. | |
149 base::Time last_volume_update_time_; | |
150 | |
151 // Contains last result of internal call to GetVolume(). We save resources | |
152 // by not quering the capture volume for each callback. | |
153 double volume_; | |
154 | |
155 // True when Automatic Gain Control is enabled, false otherwise. | |
156 // This member is modified on the audio thread and read on the internal | |
157 // Audio Unit thread in each capture callback. | |
158 base::subtle::Atomic32 agc_is_enabled_; | |
scherkus (not reviewing)
2012/03/21 09:21:21
please avoid using base::subtle -- it's intended t
henrika (OOO until Aug 14)
2012/03/21 10:16:04
Good idea. I'll come back with a new version and w
| |
159 | |
143 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); | 160 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); |
144 }; | 161 }; |
145 | 162 |
146 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ | 163 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ |
OLD | NEW |