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 #include "remoting/host/audio_capturer_win.h" | 5 #include "remoting/host/audio_capturer_win.h" |
6 | 6 |
7 #include <windows.h> | |
8 #include <avrt.h> | 7 #include <avrt.h> |
9 #include <mmreg.h> | 8 #include <mmreg.h> |
10 #include <mmsystem.h> | 9 #include <mmsystem.h> |
11 | |
12 #include <stdint.h> | 10 #include <stdint.h> |
13 #include <stdlib.h> | 11 #include <stdlib.h> |
| 12 #include <windows.h> |
| 13 |
14 #include <algorithm> | 14 #include <algorithm> |
| 15 #include <utility> |
15 | 16 |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 const int kChannels = 2; | 20 const int kChannels = 2; |
20 const int kBytesPerSample = 2; | 21 const int kBytesPerSample = 2; |
21 const int kBitsPerSample = kBytesPerSample * 8; | 22 const int kBitsPerSample = kBytesPerSample * 8; |
22 // Conversion factor from 100ns to 1ms. | 23 // Conversion factor from 100ns to 1ms. |
23 const int k100nsPerMillisecond = 10000; | 24 const int k100nsPerMillisecond = 10000; |
24 | 25 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 if ((flags & AUDCLNT_BUFFERFLAGS_SILENT) == 0 && | 230 if ((flags & AUDCLNT_BUFFERFLAGS_SILENT) == 0 && |
230 !silence_detector_.IsSilence(reinterpret_cast<const int16_t*>(data), | 231 !silence_detector_.IsSilence(reinterpret_cast<const int16_t*>(data), |
231 frames * kChannels)) { | 232 frames * kChannels)) { |
232 scoped_ptr<AudioPacket> packet(new AudioPacket()); | 233 scoped_ptr<AudioPacket> packet(new AudioPacket()); |
233 packet->add_data(data, frames * wave_format_ex_->nBlockAlign); | 234 packet->add_data(data, frames * wave_format_ex_->nBlockAlign); |
234 packet->set_encoding(AudioPacket::ENCODING_RAW); | 235 packet->set_encoding(AudioPacket::ENCODING_RAW); |
235 packet->set_sampling_rate(sampling_rate_); | 236 packet->set_sampling_rate(sampling_rate_); |
236 packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); | 237 packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); |
237 packet->set_channels(AudioPacket::CHANNELS_STEREO); | 238 packet->set_channels(AudioPacket::CHANNELS_STEREO); |
238 | 239 |
239 callback_.Run(packet.Pass()); | 240 callback_.Run(std::move(packet)); |
240 } | 241 } |
241 | 242 |
242 hr = audio_capture_client_->ReleaseBuffer(frames); | 243 hr = audio_capture_client_->ReleaseBuffer(frames); |
243 if (FAILED(hr)) | 244 if (FAILED(hr)) |
244 break; | 245 break; |
245 } | 246 } |
246 | 247 |
247 // There is nothing to capture if the audio endpoint device has been unplugged | 248 // There is nothing to capture if the audio endpoint device has been unplugged |
248 // or disabled. | 249 // or disabled. |
249 if (hr == AUDCLNT_E_DEVICE_INVALIDATED) | 250 if (hr == AUDCLNT_E_DEVICE_INVALIDATED) |
250 return; | 251 return; |
251 | 252 |
252 // Avoid reporting the same error multiple times. | 253 // Avoid reporting the same error multiple times. |
253 if (FAILED(hr) && hr != last_capture_error_) { | 254 if (FAILED(hr) && hr != last_capture_error_) { |
254 last_capture_error_ = hr; | 255 last_capture_error_ = hr; |
255 LOG(ERROR) << "Failed to capture an audio packet: 0x" | 256 LOG(ERROR) << "Failed to capture an audio packet: 0x" |
256 << std::hex << hr << std::dec << "."; | 257 << std::hex << hr << std::dec << "."; |
257 } | 258 } |
258 } | 259 } |
259 | 260 |
260 bool AudioCapturer::IsSupported() { | 261 bool AudioCapturer::IsSupported() { |
261 return true; | 262 return true; |
262 } | 263 } |
263 | 264 |
264 scoped_ptr<AudioCapturer> AudioCapturer::Create() { | 265 scoped_ptr<AudioCapturer> AudioCapturer::Create() { |
265 return make_scoped_ptr(new AudioCapturerWin()); | 266 return make_scoped_ptr(new AudioCapturerWin()); |
266 } | 267 } |
267 | 268 |
268 } // namespace remoting | 269 } // namespace remoting |
OLD | NEW |