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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 #include "base/win/scoped_comptr.h" | 75 #include "base/win/scoped_comptr.h" |
76 #include "base/win/scoped_handle.h" | 76 #include "base/win/scoped_handle.h" |
77 #include "media/audio/agc_audio_stream.h" | 77 #include "media/audio/agc_audio_stream.h" |
78 #include "media/base/audio_parameters.h" | 78 #include "media/base/audio_parameters.h" |
79 #include "media/base/media_export.h" | 79 #include "media/base/media_export.h" |
80 | 80 |
81 namespace media { | 81 namespace media { |
82 | 82 |
83 class AudioBus; | 83 class AudioBus; |
84 class AudioManagerWin; | 84 class AudioManagerWin; |
| 85 class MultiChannelResampler; |
85 | 86 |
86 // AudioInputStream implementation using Windows Core Audio APIs. | 87 // AudioInputStream implementation using Windows Core Audio APIs. |
87 class MEDIA_EXPORT WASAPIAudioInputStream | 88 class MEDIA_EXPORT WASAPIAudioInputStream |
88 : public AgcAudioStream<AudioInputStream>, | 89 : public AgcAudioStream<AudioInputStream>, |
89 public base::DelegateSimpleThread::Delegate, | 90 public base::DelegateSimpleThread::Delegate, |
90 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 91 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
91 public: | 92 public: |
92 // The ctor takes all the usual parameters, plus |manager| which is the | 93 // The ctor takes all the usual parameters, plus |manager| which is the |
93 // the audio manager who is creating this object. | 94 // the audio manager who is creating this object. |
94 WASAPIAudioInputStream(AudioManagerWin* manager, | 95 WASAPIAudioInputStream(AudioManagerWin* manager, |
(...skipping 23 matching lines...) Expand all Loading... |
118 // Issues the OnError() callback to the |sink_|. | 119 // Issues the OnError() callback to the |sink_|. |
119 void HandleError(HRESULT err); | 120 void HandleError(HRESULT err); |
120 | 121 |
121 // The Open() method is divided into these sub methods. | 122 // The Open() method is divided into these sub methods. |
122 HRESULT SetCaptureDevice(); | 123 HRESULT SetCaptureDevice(); |
123 HRESULT GetAudioEngineStreamFormat(); | 124 HRESULT GetAudioEngineStreamFormat(); |
124 bool DesiredFormatIsSupported(); | 125 bool DesiredFormatIsSupported(); |
125 HRESULT InitializeAudioEngine(); | 126 HRESULT InitializeAudioEngine(); |
126 void ReportOpenResult() const; | 127 void ReportOpenResult() const; |
127 | 128 |
| 129 // Provides input to the MultiChannelResampler. Called by the resampler when |
| 130 // more data is necessary. |
| 131 void ProvideInput(int resampler_frame_delay, AudioBus* audio_bus); |
| 132 |
128 // Used to track down where we fail during initialization which at the | 133 // Used to track down where we fail during initialization which at the |
129 // moment seems to be happening frequently and we're not sure why. | 134 // moment seems to be happening frequently and we're not sure why. |
130 // The reason might be expected (e.g. trying to open "default" on a machine | 135 // The reason might be expected (e.g. trying to open "default" on a machine |
131 // that has no audio devices). | 136 // that has no audio devices). |
132 // Note: This enum is used to record a histogram value and should not be | 137 // Note: This enum is used to record a histogram value and should not be |
133 // re-ordered. | 138 // re-ordered. |
134 enum StreamOpenResult { | 139 enum StreamOpenResult { |
135 OPEN_RESULT_OK = 0, | 140 OPEN_RESULT_OK = 0, |
136 OPEN_RESULT_CREATE_INSTANCE = 1, | 141 OPEN_RESULT_CREATE_INSTANCE = 1, |
137 OPEN_RESULT_NO_ENDPOINT = 2, | 142 OPEN_RESULT_NO_ENDPOINT = 2, |
138 OPEN_RESULT_NO_STATE = 3, | 143 OPEN_RESULT_NO_STATE = 3, |
139 OPEN_RESULT_DEVICE_NOT_ACTIVE = 4, | 144 OPEN_RESULT_DEVICE_NOT_ACTIVE = 4, |
140 OPEN_RESULT_ACTIVATION_FAILED = 5, | 145 OPEN_RESULT_ACTIVATION_FAILED = 5, |
141 OPEN_RESULT_FORMAT_NOT_SUPPORTED = 6, | 146 OPEN_RESULT_FORMAT_NOT_SUPPORTED = 6, |
142 OPEN_RESULT_AUDIO_CLIENT_INIT_FAILED = 7, | 147 OPEN_RESULT_AUDIO_CLIENT_INIT_FAILED = 7, |
143 OPEN_RESULT_GET_BUFFER_SIZE_FAILED = 8, | 148 OPEN_RESULT_GET_BUFFER_SIZE_FAILED = 8, |
144 OPEN_RESULT_LOOPBACK_ACTIVATE_FAILED = 9, | 149 OPEN_RESULT_LOOPBACK_ACTIVATE_FAILED = 9, |
145 OPEN_RESULT_LOOPBACK_INIT_FAILED = 10, | 150 OPEN_RESULT_LOOPBACK_INIT_FAILED = 10, |
146 OPEN_RESULT_SET_EVENT_HANDLE = 11, | 151 OPEN_RESULT_SET_EVENT_HANDLE = 11, |
147 OPEN_RESULT_NO_CAPTURE_CLIENT = 12, | 152 OPEN_RESULT_NO_CAPTURE_CLIENT = 12, |
148 OPEN_RESULT_NO_AUDIO_VOLUME = 13, | 153 OPEN_RESULT_NO_AUDIO_VOLUME = 13, |
149 OPEN_RESULT_MAX = OPEN_RESULT_NO_AUDIO_VOLUME | 154 OPEN_RESULT_OK_WITH_RESAMPLING = 14, |
| 155 OPEN_RESULT_MAX = OPEN_RESULT_OK_WITH_RESAMPLING |
150 }; | 156 }; |
151 | 157 |
152 // Our creator, the audio manager needs to be notified when we close. | 158 // Our creator, the audio manager needs to be notified when we close. |
153 AudioManagerWin* const manager_; | 159 AudioManagerWin* const manager_; |
154 | 160 |
155 // Capturing is driven by this thread (which has no message loop). | 161 // Capturing is driven by this thread (which has no message loop). |
156 // All OnData() callbacks will be called from this thread. | 162 // All OnData() callbacks will be called from this thread. |
157 std::unique_ptr<base::DelegateSimpleThread> capture_thread_; | 163 std::unique_ptr<base::DelegateSimpleThread> capture_thread_; |
158 | 164 |
159 // Contains the desired audio format which is set up at construction. | 165 // Contains the desired audio format which is set up at construction. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // Extra audio bus used for storage of deinterleaved data for the OnData | 242 // Extra audio bus used for storage of deinterleaved data for the OnData |
237 // callback. | 243 // callback. |
238 std::unique_ptr<media::AudioBus> audio_bus_; | 244 std::unique_ptr<media::AudioBus> audio_bus_; |
239 | 245 |
240 // Never set it through external API. Only used when |device_id_| == | 246 // Never set it through external API. Only used when |device_id_| == |
241 // kLoopbackWithMuteDeviceId. | 247 // kLoopbackWithMuteDeviceId. |
242 // True, if we have muted the system audio for the stream capturing, and | 248 // True, if we have muted the system audio for the stream capturing, and |
243 // indicates that we need to unmute the system audio when stopping capturing. | 249 // indicates that we need to unmute the system audio when stopping capturing. |
244 bool mute_done_ = false; | 250 bool mute_done_ = false; |
245 | 251 |
| 252 // If the caller requires resampling (should only be in exceptional cases and |
| 253 // ideally, never), we support using a MultiChannelResampler. |
| 254 std::unique_ptr<MultiChannelResampler> resampler_; |
| 255 std::unique_ptr<AudioBus> resample_bus_; |
| 256 |
246 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); | 257 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); |
247 }; | 258 }; |
248 | 259 |
249 } // namespace media | 260 } // namespace media |
250 | 261 |
251 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ | 262 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ |
OLD | NEW |