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

Side by Side Diff: extensions/browser/api/audio/audio_service_chromeos.cc

Issue 2578473002: chrome.audio API: treat mute as system wide property (Closed)
Patch Set: . Created 3 years, 10 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "extensions/browser/api/audio/audio_service.h" 5 #include "extensions/browser/api/audio/audio_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 21 matching lines...) Expand all
32 // Called by listeners to this service to add/remove themselves as observers. 32 // Called by listeners to this service to add/remove themselves as observers.
33 void AddObserver(AudioService::Observer* observer) override; 33 void AddObserver(AudioService::Observer* observer) override;
34 void RemoveObserver(AudioService::Observer* observer) override; 34 void RemoveObserver(AudioService::Observer* observer) override;
35 35
36 // Start to query audio device information. 36 // Start to query audio device information.
37 bool GetInfo(OutputInfo* output_info_out, InputInfo* input_info_out) override; 37 bool GetInfo(OutputInfo* output_info_out, InputInfo* input_info_out) override;
38 void SetActiveDevices(const DeviceIdList& device_list) override; 38 void SetActiveDevices(const DeviceIdList& device_list) override;
39 bool SetActiveDeviceLists( 39 bool SetActiveDeviceLists(
40 const std::unique_ptr<DeviceIdList>& input_devices, 40 const std::unique_ptr<DeviceIdList>& input_devices,
41 const std::unique_ptr<DeviceIdList>& output_devives) override; 41 const std::unique_ptr<DeviceIdList>& output_devives) override;
42 bool SetDeviceProperties(const std::string& device_id, 42 bool SetDeviceSoundLevel(const std::string& device_id,
43 bool muted,
44 int volume, 43 int volume,
45 int gain) override; 44 int gain) override;
45 bool SetMuteForDevice(const std::string& device_id, bool value) override;
46 bool SetMute(bool is_input, bool value) override;
47 bool GetMute(bool is_input, bool* value) override;
46 48
47 protected: 49 protected:
48 // chromeos::CrasAudioHandler::AudioObserver overrides. 50 // chromeos::CrasAudioHandler::AudioObserver overrides.
49 void OnOutputNodeVolumeChanged(uint64_t id, int volume) override; 51 void OnOutputNodeVolumeChanged(uint64_t id, int volume) override;
50 void OnInputNodeGainChanged(uint64_t id, int gain) override; 52 void OnInputNodeGainChanged(uint64_t id, int gain) override;
51 void OnOutputMuteChanged(bool mute_on, bool system_adjust) override; 53 void OnOutputMuteChanged(bool mute_on, bool system_adjust) override;
52 void OnInputMuteChanged(bool mute_on) override; 54 void OnInputMuteChanged(bool mute_on) override;
53 void OnAudioNodesChanged() override; 55 void OnAudioNodesChanged() override;
54 void OnActiveOutputNodeChanged() override; 56 void OnActiveOutputNodeChanged() override;
55 void OnActiveInputNodeChanged() override; 57 void OnActiveInputNodeChanged() override;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 DCHECK(success); 177 DCHECK(success);
176 } 178 }
177 179
178 if (input_ids.get()) { 180 if (input_ids.get()) {
179 success = success && cras_audio_handler_->SetActiveInputNodes(input_nodes); 181 success = success && cras_audio_handler_->SetActiveInputNodes(input_nodes);
180 DCHECK(success); 182 DCHECK(success);
181 } 183 }
182 return success; 184 return success;
183 } 185 }
184 186
185 bool AudioServiceImpl::SetDeviceProperties(const std::string& device_id, 187 bool AudioServiceImpl::SetDeviceSoundLevel(const std::string& device_id,
186 bool muted,
187 int volume, 188 int volume,
188 int gain) { 189 int gain) {
189 DCHECK(cras_audio_handler_); 190 DCHECK(cras_audio_handler_);
190 if (!cras_audio_handler_) 191 if (!cras_audio_handler_)
191 return false; 192 return false;
192 193
193 const chromeos::AudioDevice* device = 194 const chromeos::AudioDevice* device =
194 cras_audio_handler_->GetDeviceFromId(GetIdFromStr(device_id)); 195 cras_audio_handler_->GetDeviceFromId(GetIdFromStr(device_id));
195 if (!device) 196 if (!device)
196 return false; 197 return false;
197 198
198 cras_audio_handler_->SetMuteForDevice(device->id, muted);
199
200 if (!device->is_input && volume != -1) { 199 if (!device->is_input && volume != -1) {
201 cras_audio_handler_->SetVolumeGainPercentForDevice(device->id, volume); 200 cras_audio_handler_->SetVolumeGainPercentForDevice(device->id, volume);
202 return true; 201 return true;
203 } else if (device->is_input && gain != -1) { 202 } else if (device->is_input && gain != -1) {
204 cras_audio_handler_->SetVolumeGainPercentForDevice(device->id, gain); 203 cras_audio_handler_->SetVolumeGainPercentForDevice(device->id, gain);
205 return true; 204 return true;
206 } 205 }
207 206
208 return false; 207 return false;
209 } 208 }
210 209
210 bool AudioServiceImpl::SetMuteForDevice(const std::string& device_id,
211 bool value) {
212 DCHECK(cras_audio_handler_);
213 if (!cras_audio_handler_)
214 return false;
215
216 const chromeos::AudioDevice* device =
217 cras_audio_handler_->GetDeviceFromId(GetIdFromStr(device_id));
218 if (!device)
219 return false;
220
221 cras_audio_handler_->SetMuteForDevice(device->id, value);
222 return true;
223 }
224
225 bool AudioServiceImpl::SetMute(bool is_input, bool value) {
226 DCHECK(cras_audio_handler_);
227 if (!cras_audio_handler_)
228 return false;
229
230 if (is_input)
231 cras_audio_handler_->SetInputMute(value);
232 else
233 cras_audio_handler_->SetOutputMute(value);
234 return true;
235 }
236
237 bool AudioServiceImpl::GetMute(bool is_input, bool* value) {
238 DCHECK(cras_audio_handler_);
239 if (!cras_audio_handler_)
240 return false;
241
242 if (is_input)
243 *value = cras_audio_handler_->IsInputMuted();
244 else
245 *value = cras_audio_handler_->IsOutputMuted();
246 return true;
247 }
248
211 uint64_t AudioServiceImpl::GetIdFromStr(const std::string& id_str) { 249 uint64_t AudioServiceImpl::GetIdFromStr(const std::string& id_str) {
212 uint64_t device_id; 250 uint64_t device_id;
213 if (!base::StringToUint64(id_str, &device_id)) 251 if (!base::StringToUint64(id_str, &device_id))
214 return 0; 252 return 0;
215 else 253 else
216 return device_id; 254 return device_id;
217 } 255 }
218 256
219 bool AudioServiceImpl::GetAudioNodeIdList( 257 bool AudioServiceImpl::GetAudioNodeIdList(
220 const DeviceIdList& ids, 258 const DeviceIdList& ids,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 void AudioServiceImpl::NotifyDevicesChanged() { 324 void AudioServiceImpl::NotifyDevicesChanged() {
287 DCHECK_CURRENTLY_ON(BrowserThread::UI); 325 DCHECK_CURRENTLY_ON(BrowserThread::UI);
288 DCHECK(cras_audio_handler_); 326 DCHECK(cras_audio_handler_);
289 327
290 DeviceInfoList devices_info_list; 328 DeviceInfoList devices_info_list;
291 chromeos::AudioDeviceList devices; 329 chromeos::AudioDeviceList devices;
292 cras_audio_handler_->GetAudioDevices(&devices); 330 cras_audio_handler_->GetAudioDevices(&devices);
293 for (size_t i = 0; i < devices.size(); ++i) { 331 for (size_t i = 0; i < devices.size(); ++i) {
294 AudioDeviceInfo info; 332 AudioDeviceInfo info;
295 info.id = base::Uint64ToString(devices[i].id); 333 info.id = base::Uint64ToString(devices[i].id);
334 info.stream_type = devices[i].is_input
335 ? extensions::api::audio::STREAM_TYPE_INPUT
336 : extensions::api::audio::STREAM_TYPE_OUTPUT;
296 info.is_input = devices[i].is_input; 337 info.is_input = devices[i].is_input;
297 info.device_type = chromeos::AudioDevice::GetTypeString(devices[i].type); 338 info.device_type = chromeos::AudioDevice::GetTypeString(devices[i].type);
298 info.display_name = devices[i].display_name; 339 info.display_name = devices[i].display_name;
299 info.device_name = devices[i].device_name; 340 info.device_name = devices[i].device_name;
300 info.is_active = devices[i].active; 341 info.is_active = devices[i].active;
301 info.is_muted = 342 info.is_muted =
302 devices[i].is_input 343 devices[i].is_input
303 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) 344 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id)
304 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); 345 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id);
305 info.level = 346 info.level =
(...skipping 13 matching lines...) Expand all
319 // Notify DeviceChanged event for backward compatibility. 360 // Notify DeviceChanged event for backward compatibility.
320 // TODO(jennyz): remove this code when the old version of hotrod retires. 361 // TODO(jennyz): remove this code when the old version of hotrod retires.
321 NotifyDeviceChanged(); 362 NotifyDeviceChanged();
322 } 363 }
323 364
324 AudioService* AudioService::CreateInstance() { 365 AudioService* AudioService::CreateInstance() {
325 return new AudioServiceImpl; 366 return new AudioServiceImpl;
326 } 367 }
327 368
328 } // namespace extensions 369 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/audio/audio_service.cc ('k') | extensions/browser/extension_function_histogram_value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698