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 8c901137945dd58a475a9faca8dfcf36b92ed237..b370b0870b9e3ef356ddda42d54b1a946fbeece9 100644 |
| --- a/remoting/host/audio_capturer_win.cc |
| +++ b/remoting/host/audio_capturer_win.cc |
| @@ -54,6 +54,7 @@ bool AudioCapturerWin::Start(const PacketCapturedCallback& callback) { |
| DCHECK(!audio_capture_client_.get()); |
| DCHECK(!audio_client_.get()); |
| DCHECK(!mm_device_.get()); |
| + DCHECK(!audio_volume_.get()); |
| DCHECK(static_cast<PWAVEFORMATEX>(wave_format_ex_) == nullptr); |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| @@ -193,6 +194,15 @@ bool AudioCapturerWin::Start(const PacketCapturedCallback& callback) { |
| return false; |
| } |
| + // Initialize ISimpleAudioVolume. |
| + // TODO(zijiehe): Do we need to control per process volume? |
| + hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume), |
| + audio_volume_.ReceiveVoid()); |
| + if (FAILED(hr)) { |
| + LOG(ERROR) << "Failed to get an ISimpleAudioVolume. Error " << hr; |
| + return false; |
| + } |
| + |
| silence_detector_.Reset(sampling_rate_, kChannels); |
| // Start capturing. |
| @@ -203,6 +213,20 @@ bool AudioCapturerWin::Start(const PacketCapturedCallback& callback) { |
| return true; |
| } |
| +bool AudioCapturerWin::IsMuted(float* level) { |
|
joedow
2016/03/02 15:25:52
Couldn't this function return a float (just return
Sergey Ulanov
2016/03/02 20:09:40
+1
Hzj_jie
2016/03/03 09:33:39
Yes, current logic treat 0 volume exactly the same
|
| + DCHECK(level); |
| + BOOL mute; |
| + HRESULT hr = audio_volume_->GetMute(&mute); |
| + if (!FAILED(hr) && mute) { |
| + return true; |
| + } |
| + hr = audio_volume_->GetMasterVolume(level); |
| + if (FAILED(hr) || *level > 1 || *level < 0) { |
|
joedow
2016/03/02 15:25:52
If the level is less than zero, should you clamp i
Hzj_jie
2016/03/03 09:33:39
I am OK with both values, we definitely should not
|
| + *level = 1; |
|
joedow
2016/03/02 15:25:52
Per my previous comment, I think the decision to d
Sergey Ulanov
2016/03/02 20:09:40
look at it as the host's volume setting being igno
Hzj_jie
2016/03/03 09:33:39
Yes, if anything wrong, current design ignores hos
|
| + } |
| + return *level == 0; |
| +} |
| + |
| void AudioCapturerWin::DoCapture() { |
| DCHECK(AudioCapturer::IsValidSampleRate(sampling_rate_)); |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| @@ -227,17 +251,32 @@ void AudioCapturerWin::DoCapture() { |
| if (FAILED(hr)) |
| break; |
| - if ((flags & AUDCLNT_BUFFERFLAGS_SILENT) == 0 && |
| - !silence_detector_.IsSilence(reinterpret_cast<const int16_t*>(data), |
| - frames * kChannels)) { |
| - scoped_ptr<AudioPacket> packet(new AudioPacket()); |
| - packet->add_data(data, frames * wave_format_ex_->nBlockAlign); |
| - packet->set_encoding(AudioPacket::ENCODING_RAW); |
| - packet->set_sampling_rate(sampling_rate_); |
| - packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); |
| - packet->set_channels(AudioPacket::CHANNELS_STEREO); |
| - |
| - callback_.Run(std::move(packet)); |
| + if (frames > 0 && (flags & AUDCLNT_BUFFERFLAGS_SILENT) == 0) { |
| + float level; |
| + if (!IsMuted(&level)) { |
|
Sergey Ulanov
2016/03/02 20:09:40
Sorry for not being clear about it on my previous
Hzj_jie
2016/03/03 09:33:39
Done.
|
| + int16_t* samples = reinterpret_cast<int16_t*>(data); |
| + // BYTE to int16_t |
|
joedow
2016/03/02 15:25:51
I don't think this comment adds much value, remove
Hzj_jie
2016/03/03 09:33:39
Done.
|
| + size_t sample_count = frames * kChannels * kBytesPerSample |
| + * sizeof(BYTE) / sizeof(int16_t); |
|
Sergey Ulanov
2016/03/02 20:09:39
I still think sizeof(BYTE) is useless here. Someth
Hzj_jie
2016/03/03 09:33:39
Good point, thank you.
|
| + static_assert(sizeof(samples[0]) == kBytesPerSample, |
| + "expect 16 bits per sample"); |
| + if (level < 1) { |
|
joedow
2016/03/02 15:25:52
A comment might be good here to describe why we ne
Hzj_jie
2016/03/03 09:33:39
Done.
|
| + 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; |
| + } |
| + } |
| + if (!silence_detector_.IsSilence(samples, sample_count)) { |
|
Sergey Ulanov
2016/03/02 20:09:40
Here almost all data is being dropped (as audio is
Hzj_jie
2016/03/03 09:33:39
I believe network is more precious than processor,
Sergey Ulanov
2016/03/04 21:30:03
You already have explicit check for volume=0, so s
Hzj_jie
2016/03/09 19:47:57
Not really, if the volume is close to 0, but sampl
|
| + scoped_ptr<AudioPacket> packet(new AudioPacket()); |
| + packet->add_data(data, frames * wave_format_ex_->nBlockAlign); |
|
Sergey Ulanov
2016/03/02 20:09:39
So here the data is copied from data to a new buff
Hzj_jie
2016/03/03 09:33:39
Same as comment above.
|
| + packet->set_encoding(AudioPacket::ENCODING_RAW); |
| + packet->set_sampling_rate(sampling_rate_); |
| + packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); |
| + packet->set_channels(AudioPacket::CHANNELS_STEREO); |
| + |
| + callback_.Run(std::move(packet)); |
| + } |
| + } |
| } |
| hr = audio_capture_client_->ReleaseBuffer(frames); |