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

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

Issue 10823420: Added more error checking for audio packets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 4 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 | Annotate | Revision Log
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 <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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 LOG(ERROR) << "Failed to GetBuffer. Error " << hr; 287 LOG(ERROR) << "Failed to GetBuffer. Error " << hr;
288 return; 288 return;
289 } 289 }
290 290
291 if (!IsPacketOfSilence( 291 if (!IsPacketOfSilence(
292 reinterpret_cast<const int16*>(data), 292 reinterpret_cast<const int16*>(data),
293 frames * kChannels)) { 293 frames * kChannels)) {
294 scoped_ptr<AudioPacket> packet = 294 scoped_ptr<AudioPacket> packet =
295 scoped_ptr<AudioPacket>(new AudioPacket()); 295 scoped_ptr<AudioPacket>(new AudioPacket());
296 packet->add_data(data, frames * wave_format_ex_->nBlockAlign); 296 packet->add_data(data, frames * wave_format_ex_->nBlockAlign);
297 packet->set_encoding(AudioPacket::ENCODING_RAW);
297 packet->set_sampling_rate(sampling_rate_); 298 packet->set_sampling_rate(sampling_rate_);
298 packet->set_bytes_per_sample( 299 packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2);
299 static_cast<AudioPacket::BytesPerSample>(sizeof(int16))); 300 packet->set_channels(AudioPacket::CHANNELS_STEREO);
300 packet->set_encoding(AudioPacket::ENCODING_RAW);
301 301
302 callback_.Run(packet.Pass()); 302 callback_.Run(packet.Pass());
303 } 303 }
304 304
305 hr = audio_capture_client_->ReleaseBuffer(frames); 305 hr = audio_capture_client_->ReleaseBuffer(frames);
306 if (FAILED(hr)) { 306 if (FAILED(hr)) {
307 LOG(ERROR) << "Failed to ReleaseBuffer. Error " << hr; 307 LOG(ERROR) << "Failed to ReleaseBuffer. Error " << hr;
308 return; 308 return;
309 } 309 }
310 } 310 }
311 } 311 }
312 312
313 // Detects whether there is audio playing in a packet of samples. 313 // Detects whether there is audio playing in a packet of samples.
314 // Windows can give nonzero samples, even when there is no audio playing, so 314 // Windows can give nonzero samples, even when there is no audio playing, so
315 // extremely low amplitude samples are counted as silence. 315 // extremely low amplitude samples are counted as silence.
316 bool AudioCapturerWin::IsPacketOfSilence( 316 bool AudioCapturerWin::IsPacketOfSilence(
317 const int16* samples, int number_of_samples) { 317 const int16* samples, int number_of_samples) {
318 for (int i = 0; i < number_of_samples; i++) { 318 for (int i = 0; i < number_of_samples; i++) {
319 if (abs(samples[i]) > kSilenceThreshold) 319 if (abs(samples[i]) > kSilenceThreshold)
320 return false; 320 return false;
321 } 321 }
322 return true; 322 return true;
323 } 323 }
324 324
325 scoped_ptr<AudioCapturer> AudioCapturer::Create() { 325 scoped_ptr<AudioCapturer> AudioCapturer::Create() {
326 return scoped_ptr<AudioCapturer>(new AudioCapturerWin()); 326 return scoped_ptr<AudioCapturer>(new AudioCapturerWin());
327 } 327 }
328 328
329 } // namespace remoting 329 } // namespace remoting
OLDNEW
« remoting/codec/audio_decoder_verbatim.cc ('K') | « remoting/codec/audio_encoder_verbatim.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698