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 Windows using Windows Core Audio | 5 // Implementation of AudioInputStream for Windows using Windows Core Audio |
6 // WASAPI for low latency capturing. | 6 // WASAPI for low latency capturing. |
7 // | 7 // |
8 // Overview of operation: | 8 // Overview of operation: |
9 // | 9 // |
10 // - An object of WASAPIAudioInputStream is created by the AudioManager | 10 // - An object of WASAPIAudioInputStream is created by the AudioManager |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // require the use of the IAudioEndpointVolume". | 58 // require the use of the IAudioEndpointVolume". |
59 // | 59 // |
60 #ifndef MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ | 60 #ifndef MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ |
61 #define MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ | 61 #define MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ |
62 | 62 |
63 #include <Audioclient.h> | 63 #include <Audioclient.h> |
64 #include <MMDeviceAPI.h> | 64 #include <MMDeviceAPI.h> |
65 | 65 |
66 #include <string> | 66 #include <string> |
67 | 67 |
| 68 #include "base/atomicops.h" |
68 #include "base/compiler_specific.h" | 69 #include "base/compiler_specific.h" |
69 #include "base/threading/non_thread_safe.h" | 70 #include "base/threading/non_thread_safe.h" |
70 #include "base/threading/platform_thread.h" | 71 #include "base/threading/platform_thread.h" |
71 #include "base/threading/simple_thread.h" | 72 #include "base/threading/simple_thread.h" |
| 73 #include "base/time.h" |
72 #include "base/win/scoped_co_mem.h" | 74 #include "base/win/scoped_co_mem.h" |
73 #include "base/win/scoped_com_initializer.h" | 75 #include "base/win/scoped_com_initializer.h" |
74 #include "base/win/scoped_comptr.h" | 76 #include "base/win/scoped_comptr.h" |
75 #include "base/win/scoped_handle.h" | 77 #include "base/win/scoped_handle.h" |
76 #include "media/audio/audio_io.h" | 78 #include "media/audio/audio_io.h" |
77 #include "media/audio/audio_parameters.h" | 79 #include "media/audio/audio_parameters.h" |
78 #include "media/base/media_export.h" | 80 #include "media/base/media_export.h" |
79 | 81 |
80 class AudioManagerWin; | 82 class AudioManagerWin; |
81 | 83 |
(...skipping 13 matching lines...) Expand all Loading... |
95 virtual ~WASAPIAudioInputStream(); | 97 virtual ~WASAPIAudioInputStream(); |
96 | 98 |
97 // Implementation of AudioInputStream. | 99 // Implementation of AudioInputStream. |
98 virtual bool Open() OVERRIDE; | 100 virtual bool Open() OVERRIDE; |
99 virtual void Start(AudioInputCallback* callback) OVERRIDE; | 101 virtual void Start(AudioInputCallback* callback) OVERRIDE; |
100 virtual void Stop() OVERRIDE; | 102 virtual void Stop() OVERRIDE; |
101 virtual void Close() OVERRIDE; | 103 virtual void Close() OVERRIDE; |
102 virtual double GetMaxVolume() OVERRIDE; | 104 virtual double GetMaxVolume() OVERRIDE; |
103 virtual void SetVolume(double volume) OVERRIDE; | 105 virtual void SetVolume(double volume) OVERRIDE; |
104 virtual double GetVolume() OVERRIDE; | 106 virtual double GetVolume() OVERRIDE; |
| 107 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; |
| 108 virtual bool GetAutomaticGainControl() OVERRIDE; |
105 | 109 |
106 // Retrieves the sample rate used by the audio engine for its internal | 110 // Retrieves the sample rate used by the audio engine for its internal |
107 // processing/mixing of shared-mode streams given a specifed device. | 111 // processing/mixing of shared-mode streams given a specifed device. |
108 static double HardwareSampleRate(const std::string& device_id); | 112 static double HardwareSampleRate(const std::string& device_id); |
109 | 113 |
110 // Retrieves the number of audio channels used by the audio engine for its | 114 // Retrieves the number of audio channels used by the audio engine for its |
111 // internal processing/mixing of shared-mode streams given a specifed device. | 115 // internal processing/mixing of shared-mode streams given a specifed device. |
112 static uint32 HardwareChannelCount(const std::string& device_id); | 116 static uint32 HardwareChannelCount(const std::string& device_id); |
113 | 117 |
114 bool started() const { return started_; } | 118 bool started() const { return started_; } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 std::string device_id_; | 173 std::string device_id_; |
170 | 174 |
171 // Conversion factor used in delay-estimation calculations. | 175 // Conversion factor used in delay-estimation calculations. |
172 // Converts a raw performance counter value to 100-nanosecond unit. | 176 // Converts a raw performance counter value to 100-nanosecond unit. |
173 double perf_count_to_100ns_units_; | 177 double perf_count_to_100ns_units_; |
174 | 178 |
175 // Conversion factor used in delay-estimation calculations. | 179 // Conversion factor used in delay-estimation calculations. |
176 // Converts from milliseconds to audio frames. | 180 // Converts from milliseconds to audio frames. |
177 double ms_to_frame_count_; | 181 double ms_to_frame_count_; |
178 | 182 |
| 183 // Keeps track of last time a new volume level was fed to the client in an |
| 184 // OnData() callback. |
| 185 base::Time last_volume_update_time_; |
| 186 |
| 187 // Contains last result of internal call to GetVolume(). We save resources |
| 188 // but not querying the capture volume for each callback. |
| 189 double volume_; |
| 190 |
| 191 // True when Automatic Gain Control is enabled, false otherwise. |
| 192 // This member is modified on the audio thread and read on the internal |
| 193 // WASAPI capture thread in each capture callback. |
| 194 base::subtle::Atomic32 agc_is_enabled_; |
| 195 |
179 // Pointer to the object that will receive the recorded audio samples. | 196 // Pointer to the object that will receive the recorded audio samples. |
180 AudioInputCallback* sink_; | 197 AudioInputCallback* sink_; |
181 | 198 |
182 // Windows Multimedia Device (MMDevice) API interfaces. | 199 // Windows Multimedia Device (MMDevice) API interfaces. |
183 | 200 |
184 // An IMMDevice interface which represents an audio endpoint device. | 201 // An IMMDevice interface which represents an audio endpoint device. |
185 base::win::ScopedComPtr<IMMDevice> endpoint_device_; | 202 base::win::ScopedComPtr<IMMDevice> endpoint_device_; |
186 | 203 |
187 // Windows Audio Session API (WASAP) interfaces. | 204 // Windows Audio Session API (WASAP) interfaces. |
188 | 205 |
(...skipping 15 matching lines...) Expand all Loading... |
204 // recorded. | 221 // recorded. |
205 base::win::ScopedHandle audio_samples_ready_event_; | 222 base::win::ScopedHandle audio_samples_ready_event_; |
206 | 223 |
207 // This event will be signaled when capturing shall stop. | 224 // This event will be signaled when capturing shall stop. |
208 base::win::ScopedHandle stop_capture_event_; | 225 base::win::ScopedHandle stop_capture_event_; |
209 | 226 |
210 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); | 227 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); |
211 }; | 228 }; |
212 | 229 |
213 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ | 230 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ |
OLD | NEW |