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

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: Rebase Created 4 years, 4 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
« no previous file with comments | « media/audio/cras/cras_input.h ('k') | media/audio/win/audio_low_latency_input_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 10 matching lines...) Expand all
21 const std::string& device_id) 21 const std::string& device_id)
22 : audio_manager_(manager), 22 : audio_manager_(manager),
23 bytes_per_frame_(0), 23 bytes_per_frame_(0),
24 callback_(NULL), 24 callback_(NULL),
25 client_(NULL), 25 client_(NULL),
26 params_(params), 26 params_(params),
27 started_(false), 27 started_(false),
28 stream_id_(0), 28 stream_id_(0),
29 stream_direction_(CRAS_STREAM_INPUT), 29 stream_direction_(CRAS_STREAM_INPUT),
30 pin_device_(NO_DEVICE), 30 pin_device_(NO_DEVICE),
31 is_loopback_(device_id == 31 is_loopback_(
32 AudioDeviceDescription::kLoopbackInputDeviceId) { 32 device_id == AudioDeviceDescription::kLoopbackInputDeviceId ||
33 device_id == AudioDeviceDescription::kLoopbackWithMuteDeviceId),
34 mute_system_audio_(device_id ==
35 AudioDeviceDescription::kLoopbackWithMuteDeviceId),
36 mute_done_(false) {
33 DCHECK(audio_manager_); 37 DCHECK(audio_manager_);
34 audio_bus_ = AudioBus::Create(params_); 38 audio_bus_ = AudioBus::Create(params_);
35 if (!IsDefault(device_id)) { 39 if (!IsDefault(device_id)) {
36 uint64_t cras_node_id; 40 uint64_t cras_node_id;
37 base::StringToUint64(device_id, &cras_node_id); 41 base::StringToUint64(device_id, &cras_node_id);
38 pin_device_ = dev_index_of(cras_node_id); 42 pin_device_ = dev_index_of(cras_node_id);
39 } 43 }
40 } 44 }
41 45
42 CrasInputStream::~CrasInputStream() { 46 CrasInputStream::~CrasInputStream() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 96
93 if (is_loopback_) { 97 if (is_loopback_) {
94 if (cras_client_connected_wait(client_) < 0) { 98 if (cras_client_connected_wait(client_) < 0) {
95 DLOG(WARNING) << "Couldn't synchronize data."; 99 DLOG(WARNING) << "Couldn't synchronize data.";
96 // TODO(chinyue): Add a DestroyClientOnError method to de-duplicate the 100 // TODO(chinyue): Add a DestroyClientOnError method to de-duplicate the
97 // cleanup code. 101 // cleanup code.
98 cras_client_destroy(client_); 102 cras_client_destroy(client_);
99 client_ = NULL; 103 client_ = NULL;
100 return false; 104 return false;
101 } 105 }
106
102 pin_device_ = cras_client_get_first_dev_type_idx(client_, 107 pin_device_ = cras_client_get_first_dev_type_idx(client_,
103 CRAS_NODE_TYPE_POST_MIX_PRE_DSP, CRAS_STREAM_INPUT); 108 CRAS_NODE_TYPE_POST_MIX_PRE_DSP, CRAS_STREAM_INPUT);
104 if (pin_device_ < 0) { 109 if (pin_device_ < 0) {
105 DLOG(WARNING) << "Couldn't find CRAS loopback device."; 110 DLOG(WARNING) << "Couldn't find CRAS loopback device.";
106 cras_client_destroy(client_); 111 cras_client_destroy(client_);
107 client_ = NULL; 112 client_ = NULL;
108 return false; 113 return false;
109 } 114 }
110 } 115 }
111 116
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 bytes_per_frame_ = cras_client_format_bytes_per_frame(audio_format); 221 bytes_per_frame_ = cras_client_format_bytes_per_frame(audio_format);
217 222
218 // Adding the stream will start the audio callbacks. 223 // Adding the stream will start the audio callbacks.
219 if (cras_client_add_pinned_stream(client_, pin_device_, &stream_id_, 224 if (cras_client_add_pinned_stream(client_, pin_device_, &stream_id_,
220 stream_params)) { 225 stream_params)) {
221 DLOG(WARNING) << "Failed to add the stream."; 226 DLOG(WARNING) << "Failed to add the stream.";
222 callback_->OnError(this); 227 callback_->OnError(this);
223 callback_ = NULL; 228 callback_ = NULL;
224 } 229 }
225 230
231 // Mute system audio if requested.
232 if (mute_system_audio_ && !cras_client_get_system_muted(client_)) {
233 cras_client_set_system_mute(client_, 1);
234 mute_done_ = true;
235 }
236
226 // Done with config params. 237 // Done with config params.
227 cras_audio_format_destroy(audio_format); 238 cras_audio_format_destroy(audio_format);
228 cras_client_stream_params_destroy(stream_params); 239 cras_client_stream_params_destroy(stream_params);
229 240
230 started_ = true; 241 started_ = true;
231 } 242 }
232 243
233 void CrasInputStream::Stop() { 244 void CrasInputStream::Stop() {
234 if (!client_) 245 if (!client_)
235 return; 246 return;
236 247
237 if (!callback_ || !started_) 248 if (!callback_ || !started_)
238 return; 249 return;
239 250
251 if (mute_system_audio_ && mute_done_) {
252 cras_client_set_system_mute(client_, 0);
253 mute_done_ = false;
254 }
255
240 StopAgc(); 256 StopAgc();
241 257
242 // Removing the stream from the client stops audio. 258 // Removing the stream from the client stops audio.
243 cras_client_rm_stream(client_, stream_id_); 259 cras_client_rm_stream(client_, stream_id_);
244 260
245 started_ = false; 261 started_ = false;
246 callback_ = NULL; 262 callback_ = NULL;
247 } 263 }
248 264
249 // Static callback asking for samples. Run on high priority thread. 265 // Static callback asking for samples. Run on high priority thread.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 365
350 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { 366 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const {
351 return pow(10, dB / 20.0); 367 return pow(10, dB / 20.0);
352 } 368 }
353 369
354 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { 370 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const {
355 return 20 * log10(volume_ratio); 371 return 20 * log10(volume_ratio);
356 } 372 }
357 373
358 } // namespace media 374 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/cras/cras_input.h ('k') | media/audio/win/audio_low_latency_input_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698