Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(709)

Side by Side Diff: remoting/host/audio_capturer_win.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/audio_capturer_win.h ('k') | remoting/host/audio_pump.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « remoting/host/audio_capturer_win.h ('k') | remoting/host/audio_pump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698