Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(964)

Unified Diff: remoting/host/audio_capturer_win.cc

Issue 1867213002: Support audio in curtain mode, and use endpoint volume instead of session volume to adjust audio st… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve review comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/audio_capturer_win.h ('k') | remoting/host/win/rdp_client_window.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..cdcc061a02b8f7e68c864f86d03f0678944cad46 100644
--- a/remoting/host/audio_capturer_win.cc
+++ b/remoting/host/audio_capturer_win.cc
@@ -48,6 +48,9 @@ AudioCapturerWin::AudioCapturerWin()
AudioCapturerWin::~AudioCapturerWin() {
DCHECK(thread_checker_.CalledOnValidThread());
+ if (audio_client_) {
+ audio_client_->Stop();
+ }
}
bool AudioCapturerWin::Start(const PacketCapturedCallback& callback) {
@@ -194,12 +197,12 @@ 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,
+ 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 apply volume to the samples.
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))
« no previous file with comments | « remoting/host/audio_capturer_win.h ('k') | remoting/host/win/rdp_client_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698