Chromium Code Reviews| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <audioclient.h> | 6 #include <audioclient.h> |
| 7 #include <avrt.h> | 7 #include <avrt.h> |
| 8 #include <mmdeviceapi.h> | 8 #include <mmdeviceapi.h> |
| 9 #include <mmreg.h> | 9 #include <mmreg.h> |
| 10 #include <mmsystem.h> | 10 #include <mmsystem.h> |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 UINT32 frames; | 268 UINT32 frames; |
| 269 DWORD flags; | 269 DWORD flags; |
| 270 hr = audio_capture_client_->GetBuffer( | 270 hr = audio_capture_client_->GetBuffer( |
| 271 &data, &frames, &flags, NULL, NULL); | 271 &data, &frames, &flags, NULL, NULL); |
| 272 if (FAILED(hr)) { | 272 if (FAILED(hr)) { |
| 273 LOG(ERROR) << "Failed to GetBuffer. Error " << hr; | 273 LOG(ERROR) << "Failed to GetBuffer. Error " << hr; |
| 274 return; | 274 return; |
| 275 } | 275 } |
| 276 | 276 |
| 277 scoped_ptr<AudioPacket> packet = scoped_ptr<AudioPacket>(new AudioPacket()); | 277 scoped_ptr<AudioPacket> packet = scoped_ptr<AudioPacket>(new AudioPacket()); |
| 278 packet->set_data(data, frames * wave_format_ex_->nBlockAlign); | 278 packet->add_data(data, frames * wave_format_ex_->nBlockAlign); |
| 279 packet->set_sampling_rate(sampling_rate_); | 279 packet->set_sampling_rate(sampling_rate_); |
| 280 packet->set_bytes_per_sample( | 280 packet->set_bytes_per_sample( |
| 281 static_cast<AudioPacket::BytesPerSample>(sizeof(int16))); | 281 static_cast<AudioPacket::BytesPerSample>(sizeof(int16))); |
| 282 packet->set_encoding(AudioPacket::ENCODING_RAW); | 282 packet->set_encoding(AudioPacket::ENCODING_RAW); |
| 283 | 283 |
| 284 if (!IsPacketOfSilence(packet.get())) | 284 if (!IsPacketOfSilence(packet.get())) |
| 285 callback_.Run(packet.Pass()); | 285 callback_.Run(packet.Pass()); |
| 286 | 286 |
| 287 hr = audio_capture_client_->ReleaseBuffer(frames); | 287 hr = audio_capture_client_->ReleaseBuffer(frames); |
| 288 if (FAILED(hr)) { | 288 if (FAILED(hr)) { |
| 289 LOG(ERROR) << "Failed to ReleaseBuffer. Error " << hr; | 289 LOG(ERROR) << "Failed to ReleaseBuffer. Error " << hr; |
| 290 return; | 290 return; |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 // Detects whether there is audio playing in a packet of samples. | 295 // Detects whether there is audio playing in a packet of samples. |
| 296 // Windows can give nonzero samples, even when there is no audio playing, so | 296 // Windows can give nonzero samples, even when there is no audio playing, so |
| 297 // extremely low amplitude samples are counted as silence. | 297 // extremely low amplitude samples are counted as silence. |
| 298 bool AudioCapturerWin::IsPacketOfSilence(const AudioPacket* packet) { | 298 bool AudioCapturerWin::IsPacketOfSilence(const AudioPacket* packet) { |
|
Sergey Ulanov
2012/08/14 18:50:05
Maybe change this method to look at raw data inste
kxing
2012/08/14 20:56:15
Done.
| |
| 299 DCHECK_EQ(static_cast<AudioPacket::BytesPerSample>(sizeof(int16)), | 299 DCHECK_EQ(static_cast<AudioPacket::BytesPerSample>(sizeof(int16)), |
| 300 packet->bytes_per_sample()); | 300 packet->bytes_per_sample()); |
| 301 const int16* data = reinterpret_cast<const int16*>(packet->data().data()); | 301 DCHECK_EQ(1, packet->data_size()); |
| 302 int number_of_samples = packet->data().size() * kBitsPerByte / kBitsPerSample; | 302 const int16* data = reinterpret_cast<const int16*>(packet->data(0).data()); |
| 303 int number_of_samples = | |
| 304 packet->data(0).size() * kBitsPerByte / kBitsPerSample; | |
| 303 | 305 |
| 304 for (int i = 0; i < number_of_samples; i++) { | 306 for (int i = 0; i < number_of_samples; i++) { |
| 305 if (abs(data[i]) > kSilenceThreshold) | 307 if (abs(data[i]) > kSilenceThreshold) |
| 306 return false; | 308 return false; |
| 307 } | 309 } |
| 308 return true; | 310 return true; |
| 309 } | 311 } |
| 310 | 312 |
| 311 scoped_ptr<AudioCapturer> AudioCapturer::Create() { | 313 scoped_ptr<AudioCapturer> AudioCapturer::Create() { |
| 312 return scoped_ptr<AudioCapturer>(new AudioCapturerWin()); | 314 return scoped_ptr<AudioCapturer>(new AudioCapturerWin()); |
| 313 } | 315 } |
| 314 | 316 |
| 315 } // namespace remoting | 317 } // namespace remoting |
| OLD | NEW |