summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-16 09:14:51 +0000
committeralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-16 09:14:51 +0000
commita21883d8a69532071ea2c89d37634618b565e16d (patch)
treeb02ee8cbf2e0e653dc669cb26e39a1ad89ea6079
parentfa1ba18a0d57f585228ccde32f80a2933d980cfe (diff)
downloadchromium_src-a21883d8a69532071ea2c89d37634618b565e16d.zip
chromium_src-a21883d8a69532071ea2c89d37634618b565e16d.tar.gz
chromium_src-a21883d8a69532071ea2c89d37634618b565e16d.tar.bz2
Avoid reporting the same error multiple times when repeatedly capturing audio packets.
BUG=187303 Review URL: https://chromiumcodereview.appspot.com/12892002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188554 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--remoting/host/audio_capturer_win.cc36
-rw-r--r--remoting/host/audio_capturer_win.h2
2 files changed, 24 insertions, 14 deletions
diff --git a/remoting/host/audio_capturer_win.cc b/remoting/host/audio_capturer_win.cc
index cca276b..3fc768b 100644
--- a/remoting/host/audio_capturer_win.cc
+++ b/remoting/host/audio_capturer_win.cc
@@ -39,8 +39,9 @@ namespace remoting {
AudioCapturerWin::AudioCapturerWin()
: sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID),
- silence_detector_(kSilenceThreshold){
- thread_checker_.DetachFromThread();
+ silence_detector_(kSilenceThreshold),
+ last_capture_error_(S_OK) {
+ thread_checker_.DetachFromThread();
}
AudioCapturerWin::~AudioCapturerWin() {
@@ -223,13 +224,12 @@ void AudioCapturerWin::DoCapture() {
DCHECK(IsStarted());
// Fetch all packets from the audio capture endpoint buffer.
+ HRESULT hr = S_OK;
while (true) {
UINT32 next_packet_size;
HRESULT hr = audio_capture_client_->GetNextPacketSize(&next_packet_size);
- if (FAILED(hr)) {
- LOG(ERROR) << "Failed to GetNextPacketSize. Error " << hr;
- return;
- }
+ if (FAILED(hr))
+ break;
if (next_packet_size <= 0) {
return;
@@ -239,10 +239,8 @@ void AudioCapturerWin::DoCapture() {
UINT32 frames;
DWORD flags;
hr = audio_capture_client_->GetBuffer(&data, &frames, &flags, NULL, NULL);
- if (FAILED(hr)) {
- LOG(ERROR) << "Failed to GetBuffer. Error " << hr;
- return;
- }
+ if (FAILED(hr))
+ break;
if (!silence_detector_.IsSilence(
reinterpret_cast<const int16*>(data), frames * kChannels)) {
@@ -258,10 +256,20 @@ void AudioCapturerWin::DoCapture() {
}
hr = audio_capture_client_->ReleaseBuffer(frames);
- if (FAILED(hr)) {
- LOG(ERROR) << "Failed to ReleaseBuffer. Error " << hr;
- return;
- }
+ if (FAILED(hr))
+ break;
+ }
+
+ // There is nothing to capture if the audio endpoint device has been unplugged
+ // or disabled.
+ if (hr == AUDCLNT_E_DEVICE_INVALIDATED)
+ return;
+
+ // Avoid reporting the same error multiple times.
+ if (FAILED(hr) && hr != last_capture_error_) {
+ last_capture_error_ = hr;
+ LOG(ERROR) << "Failed to capture an audio packet: 0x"
+ << std::hex << hr << std::dec << ".";
}
}
diff --git a/remoting/host/audio_capturer_win.h b/remoting/host/audio_capturer_win.h
index 771cf20..eb86007 100644
--- a/remoting/host/audio_capturer_win.h
+++ b/remoting/host/audio_capturer_win.h
@@ -48,6 +48,8 @@ class AudioCapturerWin : public AudioCapturer {
base::win::ScopedComPtr<IAudioClient> audio_client_;
base::win::ScopedComPtr<IMMDevice> mm_device_;
+ HRESULT last_capture_error_;
+
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(AudioCapturerWin);