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 <avrt.h> | 7 #include <avrt.h> |
8 #include <mmreg.h> | 8 #include <mmreg.h> |
9 #include <mmsystem.h> | 9 #include <mmsystem.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <windows.h> | 12 #include <windows.h> |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/ptr_util.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 const int kChannels = 2; | 21 const int kChannels = 2; |
21 const int kBytesPerSample = 2; | 22 const int kBytesPerSample = 2; |
22 const int kBitsPerSample = kBytesPerSample * 8; | 23 const int kBitsPerSample = kBytesPerSample * 8; |
23 // Conversion factor from 100ns to 1ms. | 24 // Conversion factor from 100ns to 1ms. |
24 const int k100nsPerMillisecond = 10000; | 25 const int k100nsPerMillisecond = 10000; |
25 | 26 |
26 // Tolerance for catching packets of silence. If all samples have absolute | 27 // Tolerance for catching packets of silence. If all samples have absolute |
27 // value less than this threshold, the packet will be counted as a packet of | 28 // value less than this threshold, the packet will be counted as a packet of |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 261 |
261 if (level < 1) { | 262 if (level < 1) { |
262 // Windows API does not provide volume adjusted audio sample as Linux does. | 263 // Windows API does not provide volume adjusted audio sample as Linux does. |
263 // So we need to manually append volume signal to the samples. | 264 // So we need to manually append volume signal to the samples. |
264 int32_t level_int = static_cast<int32_t>(level * 65536); | 265 int32_t level_int = static_cast<int32_t>(level * 65536); |
265 for (size_t i = 0; i < sample_count; i++) { | 266 for (size_t i = 0; i < sample_count; i++) { |
266 samples[i] = (static_cast<int32_t>(samples[i]) * level_int) >> 16; | 267 samples[i] = (static_cast<int32_t>(samples[i]) * level_int) >> 16; |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 scoped_ptr<AudioPacket> packet(new AudioPacket()); | 271 std::unique_ptr<AudioPacket> packet(new AudioPacket()); |
271 packet->add_data(data, frames * wave_format_ex_->nBlockAlign); | 272 packet->add_data(data, frames * wave_format_ex_->nBlockAlign); |
272 packet->set_encoding(AudioPacket::ENCODING_RAW); | 273 packet->set_encoding(AudioPacket::ENCODING_RAW); |
273 packet->set_sampling_rate(sampling_rate_); | 274 packet->set_sampling_rate(sampling_rate_); |
274 packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); | 275 packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); |
275 packet->set_channels(AudioPacket::CHANNELS_STEREO); | 276 packet->set_channels(AudioPacket::CHANNELS_STEREO); |
276 | 277 |
277 callback_.Run(std::move(packet)); | 278 callback_.Run(std::move(packet)); |
278 } | 279 } |
279 | 280 |
280 void AudioCapturerWin::DoCapture() { | 281 void AudioCapturerWin::DoCapture() { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 last_capture_error_ = hr; | 319 last_capture_error_ = hr; |
319 LOG(ERROR) << "Failed to capture an audio packet: 0x" | 320 LOG(ERROR) << "Failed to capture an audio packet: 0x" |
320 << std::hex << hr << std::dec << "."; | 321 << std::hex << hr << std::dec << "."; |
321 } | 322 } |
322 } | 323 } |
323 | 324 |
324 bool AudioCapturer::IsSupported() { | 325 bool AudioCapturer::IsSupported() { |
325 return true; | 326 return true; |
326 } | 327 } |
327 | 328 |
328 scoped_ptr<AudioCapturer> AudioCapturer::Create() { | 329 std::unique_ptr<AudioCapturer> AudioCapturer::Create() { |
329 return make_scoped_ptr(new AudioCapturerWin()); | 330 return base::WrapUnique(new AudioCapturerWin()); |
330 } | 331 } |
331 | 332 |
332 } // namespace remoting | 333 } // namespace remoting |
OLD | NEW |