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 2610e6e2b692eed2523b0dfe2047d3222b379996..6c851518bb286948ced67cf847d72590a7e52057 100644 |
| --- a/remoting/host/audio_capturer_win.cc |
| +++ b/remoting/host/audio_capturer_win.cc |
| @@ -21,7 +21,6 @@ |
| #include "remoting/host/win/default_audio_device_change_detector.h" |
| namespace { |
| -const int kChannels = 2; |
| const int kBytesPerSample = 2; |
| const int kBitsPerSample = kBytesPerSample * 8; |
| // Conversion factor from 100ns to 1ms. |
| @@ -39,6 +38,20 @@ const int kMinTimerInterval = 30; |
| // Upper bound for the timer precision error, in milliseconds. |
| // Timers are supposed to be accurate to 20ms, so we use 30ms to be safe. |
| const int kMaxExpectedTimerLag = 30; |
| + |
| +int ChooseChannels(int channel_count) { |
|
joedow
2017/05/26 16:01:50
This function doesn't choose a channel, it convert
Hzj_jie
2017/05/26 20:08:03
Before this change, we always select stereo. But t
Sergey Ulanov
2017/05/26 22:24:45
If I understand correctly this function defines ch
Hzj_jie
2017/05/28 20:58:58
IMO, it's still worthy to have a shot: it won't wa
Sergey Ulanov
2017/06/05 18:03:19
I still don't think this is necessary. The problem
Hzj_jie
2017/06/06 03:21:42
Then I would prefer to rewrite the wave_format_ex_
chcunningham
2017/06/09 19:25:28
This is fine for this CL, but we have seen more th
Hzj_jie
2017/06/09 21:33:47
IMO, a long-term solution is to migrate to AudioIn
|
| + using remoting::AudioPacket; |
| + // The condition should match AudioPacket::Channels enum in audio.proto. |
| + if (channel_count == AudioPacket::CHANNELS_MONO || |
| + channel_count == AudioPacket::CHANNELS_STEREO || |
| + channel_count == AudioPacket::CHANNELS_5_1 || |
| + channel_count == AudioPacket::CHANNELS_6_1 || |
| + channel_count == AudioPacket::CHANNELS_7_1) { |
| + return channel_count; |
| + } |
| + return AudioPacket::CHANNELS_STEREO; |
| +} |
| + |
| } // namespace |
| namespace remoting { |
| @@ -163,11 +176,12 @@ bool AudioCapturerWin::Initialize() { |
| wave_format_ex_->nSamplesPerSec); |
| wave_format_ex_->wFormatTag = WAVE_FORMAT_PCM; |
| - wave_format_ex_->nChannels = kChannels; |
| + wave_format_ex_->nChannels = ChooseChannels(wave_format_ex_->nChannels); |
| wave_format_ex_->wBitsPerSample = kBitsPerSample; |
| - wave_format_ex_->nBlockAlign = kChannels * kBytesPerSample; |
| + wave_format_ex_->nBlockAlign = |
| + wave_format_ex_->nChannels * kBytesPerSample; |
| wave_format_ex_->nAvgBytesPerSec = |
| - sampling_rate_ * kChannels * kBytesPerSample; |
| + sampling_rate_ * wave_format_ex_->nChannels * kBytesPerSample; |
| break; |
| case WAVE_FORMAT_EXTENSIBLE: { |
| PWAVEFORMATEXTENSIBLE wave_format_extensible = |
| @@ -186,13 +200,15 @@ bool AudioCapturerWin::Initialize() { |
| wave_format_extensible->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; |
| wave_format_extensible->Samples.wValidBitsPerSample = kBitsPerSample; |
| - wave_format_extensible->Format.nChannels = kChannels; |
| + wave_format_extensible->Format.nChannels = |
| + ChooseChannels(wave_format_extensible->Format.nChannels); |
|
Sergey Ulanov
2017/05/26 22:24:45
If you change number of channels here then you pro
Hzj_jie
2017/05/28 20:58:59
According to MSDN, https://social.msdn.microsoft.c
Sergey Ulanov
2017/05/30 19:18:19
My point was that, if the API will never downmix t
Hzj_jie
2017/05/31 00:12:08
Got you. I will update both nChannels and dwChanne
Sergey Ulanov
2017/05/31 00:44:43
Is this useful given that we know that windows wil
Hzj_jie
2017/05/31 02:49:28
Trying to initialize in stereo does not really was
Sergey Ulanov
2017/06/05 18:03:19
I don't think it can cause any problems. It's reas
Hzj_jie
2017/06/06 03:21:42
Done.
|
| wave_format_extensible->Format.nSamplesPerSec = sampling_rate_; |
| wave_format_extensible->Format.wBitsPerSample = kBitsPerSample; |
| wave_format_extensible->Format.nBlockAlign = |
| - kChannels * kBytesPerSample; |
| + wave_format_extensible->Format.nChannels * kBytesPerSample; |
| wave_format_extensible->Format.nAvgBytesPerSec = |
| - sampling_rate_ * kChannels * kBytesPerSample; |
| + sampling_rate_ * wave_format_extensible->Format.nChannels * |
| + kBytesPerSample; |
| } else { |
| LOG(ERROR) << "Failed to force 16-bit samples"; |
| return false; |
| @@ -233,7 +249,7 @@ bool AudioCapturerWin::Initialize() { |
| } |
| volume_filter_.ActivateBy(mm_device_.Get()); |
| - volume_filter_.Initialize(sampling_rate_, kChannels); |
| + volume_filter_.Initialize(sampling_rate_, wave_format_ex_->nChannels); |
| return true; |
| } |
| @@ -280,7 +296,8 @@ void AudioCapturerWin::DoCapture() { |
| 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); |
| + packet->set_channels(static_cast<AudioPacket::Channels>( |
| + wave_format_ex_->nChannels)); |
| callback_.Run(std::move(packet)); |
| } |