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

Side by Side Diff: media/audio/cras/cras_input.cc

Issue 2144333002: MuteSource Audio During Full Screen Cast (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mute system audio for getUserMedia(audio:System) Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/audio/cras/cras_input.h" 5 #include "media/audio/cras/cras_input.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "media/audio/audio_device_description.h" 12 #include "media/audio/audio_device_description.h"
13 #include "media/audio/audio_manager.h" 13 #include "media/audio/audio_manager.h"
14 #include "media/audio/cras/audio_manager_cras.h" 14 #include "media/audio/cras/audio_manager_cras.h"
15 15
16 namespace media { 16 namespace media {
17 17
18 CrasInputStream::CrasInputStream(const AudioParameters& params, 18 CrasInputStream::CrasInputStream(const AudioParameters& params,
19 AudioManagerCras* manager, 19 AudioManagerCras* manager,
20 const std::string& device_id) 20 const std::string& device_id)
21 : audio_manager_(manager), 21 : audio_manager_(manager),
22 bytes_per_frame_(0), 22 bytes_per_frame_(0),
23 callback_(NULL), 23 callback_(NULL),
24 client_(NULL), 24 client_(NULL),
25 params_(params), 25 params_(params),
26 started_(false), 26 started_(false),
27 stream_id_(0), 27 stream_id_(0),
28 stream_direction_(CRAS_STREAM_INPUT), 28 stream_direction_(CRAS_STREAM_INPUT),
29 pin_device_(NO_DEVICE), 29 pin_device_(NO_DEVICE),
30 is_loopback_(device_id == 30 is_loopback_(
31 AudioDeviceDescription::kLoopbackInputDeviceId) { 31 device_id == AudioDeviceDescription::kLoopbackInputDeviceId ||
32 device_id == AudioDeviceDescription::kLoopbackWithMuteDeviceId),
33 mute_system_audio_(device_id ==
34 AudioDeviceDescription::kLoopbackWithMuteDeviceId) {
32 DCHECK(audio_manager_); 35 DCHECK(audio_manager_);
33 audio_bus_ = AudioBus::Create(params_); 36 audio_bus_ = AudioBus::Create(params_);
34 } 37 }
35 38
36 CrasInputStream::~CrasInputStream() { 39 CrasInputStream::~CrasInputStream() {
37 DCHECK(!client_); 40 DCHECK(!client_);
38 } 41 }
39 42
40 bool CrasInputStream::Open() { 43 bool CrasInputStream::Open() {
41 if (client_) { 44 if (client_) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 89
87 if (is_loopback_) { 90 if (is_loopback_) {
88 if (cras_client_connected_wait(client_) < 0) { 91 if (cras_client_connected_wait(client_) < 0) {
89 DLOG(WARNING) << "Couldn't synchronize data."; 92 DLOG(WARNING) << "Couldn't synchronize data.";
90 // TODO(chinyue): Add a DestroyClientOnError method to de-duplicate the 93 // TODO(chinyue): Add a DestroyClientOnError method to de-duplicate the
91 // cleanup code. 94 // cleanup code.
92 cras_client_destroy(client_); 95 cras_client_destroy(client_);
93 client_ = NULL; 96 client_ = NULL;
94 return false; 97 return false;
95 } 98 }
99 if (mute_system_audio_)
100 cras_client_set_system_mute(client_, 1);
miu 2016/07/19 01:09:44 What if the system audio was already muted? Perhap
qiangchen 2016/07/20 22:13:22 Done.
96 pin_device_ = cras_client_get_first_dev_type_idx(client_, 101 pin_device_ = cras_client_get_first_dev_type_idx(client_,
97 CRAS_NODE_TYPE_POST_MIX_PRE_DSP, CRAS_STREAM_INPUT); 102 CRAS_NODE_TYPE_POST_MIX_PRE_DSP, CRAS_STREAM_INPUT);
98 if (pin_device_ < 0) { 103 if (pin_device_ < 0) {
99 DLOG(WARNING) << "Couldn't find CRAS loopback device."; 104 DLOG(WARNING) << "Couldn't find CRAS loopback device.";
100 cras_client_destroy(client_); 105 cras_client_destroy(client_);
101 client_ = NULL; 106 client_ = NULL;
102 return false; 107 return false;
103 } 108 }
104 } 109 }
105 110
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 started_ = true; 229 started_ = true;
225 } 230 }
226 231
227 void CrasInputStream::Stop() { 232 void CrasInputStream::Stop() {
228 if (!client_) 233 if (!client_)
229 return; 234 return;
230 235
231 if (!callback_ || !started_) 236 if (!callback_ || !started_)
232 return; 237 return;
233 238
239 if (mute_system_audio_) {
240 cras_client_set_system_mute(client_, 0);
241 }
242
234 StopAgc(); 243 StopAgc();
235 244
236 // Removing the stream from the client stops audio. 245 // Removing the stream from the client stops audio.
237 cras_client_rm_stream(client_, stream_id_); 246 cras_client_rm_stream(client_, stream_id_);
238 247
239 started_ = false; 248 started_ = false;
240 callback_ = NULL; 249 callback_ = NULL;
241 } 250 }
242 251
243 // Static callback asking for samples. Run on high priority thread. 252 // Static callback asking for samples. Run on high priority thread.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 344
336 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { 345 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const {
337 return pow(10, dB / 20.0); 346 return pow(10, dB / 20.0);
338 } 347 }
339 348
340 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { 349 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const {
341 return 20 * log10(volume_ratio); 350 return 20 * log10(volume_ratio);
342 } 351 }
343 352
344 } // namespace media 353 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698