Chromium Code Reviews| Index: remoting/host/audio_capturer_win.cc |
| diff --git a/remoting/host/audio_capturer_win.cc b/remoting/host/audio_capturer_win.cc |
| index 86fd95951dde2ec6f02bdd35bacc43376ac4093a..3a609826f4e77fc3bd1fd5f78c70df46dc897f4b 100644 |
| --- a/remoting/host/audio_capturer_win.cc |
| +++ b/remoting/host/audio_capturer_win.cc |
| @@ -48,6 +48,7 @@ AudioCapturerWin::AudioCapturerWin() |
| AudioCapturerWin::~AudioCapturerWin() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| + audio_client_->Stop(); |
|
Sergey Ulanov
2016/04/11 17:58:01
if (audio_client_)
Is it necessary to call Stop()
Hzj_jie
2016/04/11 21:37:22
I did not see a clear comment on MSDN to imply IAu
|
| } |
| bool AudioCapturerWin::Start(const PacketCapturedCallback& callback) { |
| @@ -194,12 +195,14 @@ bool AudioCapturerWin::Start(const PacketCapturedCallback& callback) { |
| return false; |
| } |
| - // Initialize ISimpleAudioVolume. |
| + // Initialize IAudioEndpointVolume. |
| // TODO(zijiehe): Do we need to control per process volume? |
| - hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume), |
| - audio_volume_.ReceiveVoid()); |
| + hr = mm_device_->Activate(__uuidof(IAudioEndpointVolume), |
| + CLSCTX_ALL, |
| + nullptr, |
|
Sergey Ulanov
2016/04/11 17:58:01
This parameter can fit on the previous line. clang
Hzj_jie
2016/04/11 21:37:22
Done.
|
| + audio_volume_.ReceiveVoid()); |
| if (FAILED(hr)) { |
| - LOG(ERROR) << "Failed to get an ISimpleAudioVolume. Error " << hr; |
| + LOG(ERROR) << "Failed to get an IAudioEndpointVolume. Error " << hr; |
| return false; |
| } |
| @@ -217,6 +220,8 @@ float AudioCapturerWin::GetAudioLevel() { |
| BOOL mute; |
| HRESULT hr = audio_volume_->GetMute(&mute); |
| if (FAILED(hr)) { |
| + LOG(ERROR) << "Failed to get mute status from IAudioEndpointVolume, error " |
| + << hr; |
| return 1; |
| } |
| if (mute) { |
| @@ -224,8 +229,11 @@ float AudioCapturerWin::GetAudioLevel() { |
| } |
| float level; |
| - hr = audio_volume_->GetMasterVolume(&level); |
| + hr = audio_volume_->GetMasterVolumeLevelScalar(&level); |
| if (FAILED(hr) || level > 1) { |
| + LOG(ERROR) << "Failed to get master volume from IAudioEndpointVolume, " |
| + "error " |
| + << hr; |
| return 1; |
| } |
| if (level < 0) { |
| @@ -234,17 +242,11 @@ float AudioCapturerWin::GetAudioLevel() { |
| return level; |
| } |
| -void AudioCapturerWin::ProcessSamples(uint8_t* data, |
| - size_t frames, |
| - int32_t flags) { |
| +void AudioCapturerWin::ProcessSamples(uint8_t* data, size_t frames) { |
| if (frames == 0) { |
| return; |
| } |
| - if ((flags & AUDCLNT_BUFFERFLAGS_SILENT) == 0) { |
| - return; |
| - } |
| - |
| int16_t* samples = reinterpret_cast<int16_t*>(data); |
| static_assert(sizeof(samples[0]) == kBytesPerSample, |
| "expect 16 bits per sample"); |
| @@ -253,14 +255,14 @@ void AudioCapturerWin::ProcessSamples(uint8_t* data, |
| return; |
| } |
| + // Windows API does not provide volume adjusted audio sample as Linux does. |
| + // So we need to manually append volume signal to the samples. |
|
Sergey Ulanov
2016/04/11 17:58:01
s/append volume signal/apply volume/
Hzj_jie
2016/04/11 21:37:22
Done.
|
| float level = GetAudioLevel(); |
| if (level == 0) { |
| return; |
| } |
| if (level < 1) { |
| - // Windows API does not provide volume adjusted audio sample as Linux does. |
| - // So we need to manually append volume signal to the samples. |
| int32_t level_int = static_cast<int32_t>(level * 65536); |
| for (size_t i = 0; i < sample_count; i++) { |
| samples[i] = (static_cast<int32_t>(samples[i]) * level_int) >> 16; |
| @@ -301,7 +303,7 @@ void AudioCapturerWin::DoCapture() { |
| if (FAILED(hr)) |
| break; |
| - ProcessSamples(data, frames, flags); |
| + ProcessSamples(data, frames); |
| hr = audio_capture_client_->ReleaseBuffer(frames); |
| if (FAILED(hr)) |