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

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

Issue 2510093003: Handle audio node stable device ID change (Closed)
Patch Set: fix a typo Created 4 years 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 | « extensions/browser/api/audio/audio_apitest.cc ('k') | media/audio/audio_manager_unittest.cc » ('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) 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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "chromeos/audio/audio_device.h" 14 #include "chromeos/audio/audio_device.h"
15 #include "chromeos/audio/cras_audio_handler.h" 15 #include "chromeos/audio/cras_audio_handler.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 17
18 using content::BrowserThread; 18 using content::BrowserThread;
19 19
20 namespace extensions { 20 namespace extensions {
21 21
22 using api::audio::OutputDeviceInfo; 22 using api::audio::OutputDeviceInfo;
23 using api::audio::InputDeviceInfo; 23 using api::audio::InputDeviceInfo;
24 using api::audio::AudioDeviceInfo; 24 using api::audio::AudioDeviceInfo;
25 25
26 uint64_t GetStableDeviceId(const chromeos::AudioDevice& device) {
27 // TODO(tbarzic): Update audio API to expose new stable device ID version.
28 // For now, for the sake of backward compatibility, use deprecated version.
29 // http://crbug.com/673392
30 if (device.stable_device_id_version == 1)
31 return device.stable_device_id;
32 if (device.stable_device_id_version == 2)
33 return device.deprecated_stable_device_id;
34 NOTREACHED() << "Unsupported stable audio devide id version.";
35 return 0;
36 }
37
26 class AudioServiceImpl : public AudioService, 38 class AudioServiceImpl : public AudioService,
27 public chromeos::CrasAudioHandler::AudioObserver { 39 public chromeos::CrasAudioHandler::AudioObserver {
28 public: 40 public:
29 AudioServiceImpl(); 41 AudioServiceImpl();
30 ~AudioServiceImpl() override; 42 ~AudioServiceImpl() override;
31 43
32 // Called by listeners to this service to add/remove themselves as observers. 44 // Called by listeners to this service to add/remove themselves as observers.
33 void AddObserver(AudioService::Observer* observer) override; 45 void AddObserver(AudioService::Observer* observer) override;
34 void RemoveObserver(AudioService::Observer* observer) override; 46 void RemoveObserver(AudioService::Observer* observer) override;
35 47
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 info.is_muted = 274 info.is_muted =
263 devices[i].is_input 275 devices[i].is_input
264 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) 276 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id)
265 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); 277 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id);
266 info.level = 278 info.level =
267 devices[i].is_input 279 devices[i].is_input
268 ? cras_audio_handler_->GetOutputVolumePercentForDevice( 280 ? cras_audio_handler_->GetOutputVolumePercentForDevice(
269 devices[i].id) 281 devices[i].id)
270 : cras_audio_handler_->GetInputGainPercentForDevice(devices[i].id); 282 : cras_audio_handler_->GetInputGainPercentForDevice(devices[i].id);
271 info.stable_device_id.reset( 283 info.stable_device_id.reset(
272 new std::string(base::Uint64ToString(devices[i].stable_device_id))); 284 new std::string(base::Uint64ToString(GetStableDeviceId(devices[i]))));
273 285
274 devices_info_list.push_back(std::move(info)); 286 devices_info_list.push_back(std::move(info));
275 } 287 }
276 288
277 for (auto& observer : observer_list_) 289 for (auto& observer : observer_list_)
278 observer.OnDevicesChanged(devices_info_list); 290 observer.OnDevicesChanged(devices_info_list);
279 291
280 // Notify DeviceChanged event for backward compatibility. 292 // Notify DeviceChanged event for backward compatibility.
281 // TODO(jennyz): remove this code when the old version of hotrod retires. 293 // TODO(jennyz): remove this code when the old version of hotrod retires.
282 NotifyDeviceChanged(); 294 NotifyDeviceChanged();
283 } 295 }
284 296
285 AudioService* AudioService::CreateInstance() { 297 AudioService* AudioService::CreateInstance() {
286 return new AudioServiceImpl; 298 return new AudioServiceImpl;
287 } 299 }
288 300
289 } // namespace extensions 301 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/audio/audio_apitest.cc ('k') | media/audio/audio_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698