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..361352a6cc3bf275b3216c294eabbe2af47934ea 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,21 @@ 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; |
+ |
+// Chooses a similar and supported channel configuration. |channels| represents |
+// the selected channels. It can be nullptr. |
+void ChooseChannels(WORD* channel_count, DWORD* channels) { |
+ // We supports mono to 7.1. |
+ if (*channel_count >= 1 && *channel_count <= 8) { |
+ return; |
+ } |
+ |
+ *channel_count = remoting::AudioPacket::CHANNELS_STEREO; |
+ if (channels) { |
+ *channels = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; |
+ } |
+} |
+ |
} // namespace |
namespace remoting { |
@@ -163,11 +177,12 @@ bool AudioCapturerWin::Initialize() { |
wave_format_ex_->nSamplesPerSec); |
wave_format_ex_->wFormatTag = WAVE_FORMAT_PCM; |
- wave_format_ex_->nChannels = kChannels; |
+ ChooseChannels(&wave_format_ex_->nChannels, nullptr); |
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 +201,15 @@ bool AudioCapturerWin::Initialize() { |
wave_format_extensible->SubFormat = KSDATAFORMAT_SUBTYPE_PCM; |
wave_format_extensible->Samples.wValidBitsPerSample = kBitsPerSample; |
- wave_format_extensible->Format.nChannels = kChannels; |
+ ChooseChannels(&wave_format_extensible->Format.nChannels, |
+ &wave_format_extensible->dwChannelMask); |
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 +250,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 +297,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>( |
Sergey Ulanov
2017/06/05 18:03:19
I think this would be the right place to add a com
Hzj_jie
2017/06/06 03:21:43
Done.
|
+ wave_format_ex_->nChannels)); |
callback_.Run(std::move(packet)); |
} |