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

Side by Side Diff: media/audio/audio_system_impl.cc

Issue 2763383002: Switching AudioInputDeviceManager from using AudioManager interface to AudioSystem one. (Closed)
Patch Set: Created 3 years, 9 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/audio_system_impl.h" 5 #include "media/audio/audio_system_impl.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "media/audio/audio_device_description.h" 10 #include "media/audio/audio_device_description.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 if (for_input) 53 if (for_input)
54 audio_manager->GetAudioInputDeviceDescriptions(&descriptions); 54 audio_manager->GetAudioInputDeviceDescriptions(&descriptions);
55 else 55 else
56 audio_manager->GetAudioOutputDeviceDescriptions(&descriptions); 56 audio_manager->GetAudioOutputDeviceDescriptions(&descriptions);
57 return descriptions; 57 return descriptions;
58 } 58 }
59 59
60 } // namespace 60 } // namespace
61 61
62 AudioSystemImpl::AudioSystemImpl(AudioManager* audio_manager) 62 AudioSystemImpl::AudioSystemImpl(AudioManager* audio_manager)
63 : audio_manager_(audio_manager) { 63 : audio_manager_(audio_manager), weak_factory_(this) {
64 DCHECK(audio_manager_); 64 DCHECK(audio_manager_);
65 AudioSystem::SetInstance(this); 65 AudioSystem::SetInstance(this);
66 } 66 }
67 67
68 AudioSystemImpl::~AudioSystemImpl() { 68 AudioSystemImpl::~AudioSystemImpl() {
69 AudioSystem::ClearInstance(this); 69 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
70 } 70 }
71 71
72 // static 72 // static
73 std::unique_ptr<AudioSystem> AudioSystemImpl::Create( 73 AudioSystem::UniquePtr AudioSystemImpl::Create(AudioManager* audio_manager) {
74 AudioManager* audio_manager) { 74 return UniquePtr(new AudioSystemImpl(audio_manager));
75 return base::WrapUnique(new AudioSystemImpl(audio_manager));
76 } 75 }
77 76
78 void AudioSystemImpl::GetInputStreamParameters( 77 void AudioSystemImpl::GetInputStreamParameters(
79 const std::string& device_id, 78 const std::string& device_id,
80 OnAudioParamsCallback on_params_cb) const { 79 OnAudioParamsCallback on_params_cb) const {
81 if (GetTaskRunner()->BelongsToCurrentThread()) { 80 if (GetTaskRunner()->BelongsToCurrentThread()) {
82 GetTaskRunner()->PostTask( 81 GetTaskRunner()->PostTask(
83 FROM_HERE, base::Bind(on_params_cb, GetInputParametersOnDeviceThread( 82 FROM_HERE, base::Bind(on_params_cb, GetInputParametersOnDeviceThread(
84 audio_manager_, device_id))); 83 audio_manager_, device_id)));
85 return; 84 return;
(...skipping 29 matching lines...) Expand all
115 return; 114 return;
116 } 115 }
117 base::PostTaskAndReplyWithResult( 116 base::PostTaskAndReplyWithResult(
118 GetTaskRunner(), FROM_HERE, 117 GetTaskRunner(), FROM_HERE,
119 base::Bind(&AudioManager::HasAudioInputDevices, 118 base::Bind(&AudioManager::HasAudioInputDevices,
120 base::Unretained(audio_manager_)), 119 base::Unretained(audio_manager_)),
121 std::move(on_has_devices_cb)); 120 std::move(on_has_devices_cb));
122 } 121 }
123 122
124 void AudioSystemImpl::GetDeviceDescriptions( 123 void AudioSystemImpl::GetDeviceDescriptions(
125 OnDeviceDescriptionsCallback on_descriptions_cp, 124 OnDeviceDescriptionsCallback on_descriptions_cb,
126 bool for_input) { 125 bool for_input) {
127 if (GetTaskRunner()->BelongsToCurrentThread()) { 126 if (GetTaskRunner()->BelongsToCurrentThread()) {
128 GetTaskRunner()->PostTask( 127 GetTaskRunner()->PostTask(
129 FROM_HERE, base::Bind(on_descriptions_cp, 128 FROM_HERE, base::Bind(on_descriptions_cb,
130 base::Passed(GetDeviceDescriptionsOnDeviceThread( 129 base::Passed(GetDeviceDescriptionsOnDeviceThread(
131 audio_manager_, for_input)))); 130 audio_manager_, for_input))));
132 return; 131 return;
133 } 132 }
134 133
135 base::PostTaskAndReplyWithResult( 134 base::PostTaskAndReplyWithResult(
136 GetTaskRunner(), FROM_HERE, 135 GetTaskRunner(), FROM_HERE,
137 base::Bind(&GetDeviceDescriptionsOnDeviceThread, 136 base::Bind(&GetDeviceDescriptionsOnDeviceThread,
138 base::Unretained(audio_manager_), for_input), 137 base::Unretained(audio_manager_), for_input),
139 std::move(on_descriptions_cp)); 138 std::move(on_descriptions_cb));
139 }
140
141 void AudioSystemImpl::GetAssociatedOutputDeviceID(
142 const std::string& input_device_id,
143 OnDeviceIdCallback on_device_id_cb) {
144 if (GetTaskRunner()->BelongsToCurrentThread()) {
145 GetTaskRunner()->PostTask(
146 FROM_HERE,
147 base::Bind(on_device_id_cb, audio_manager_->GetAssociatedOutputDeviceID(
148 input_device_id)));
149 return;
150 }
151 base::PostTaskAndReplyWithResult(
152 GetTaskRunner(), FROM_HERE,
153 base::Bind(&AudioManager::GetAssociatedOutputDeviceID,
154 base::Unretained(audio_manager_), input_device_id),
155 std::move(on_device_id_cb));
156 }
157
158 base::WeakPtr<AudioSystem> AudioSystemImpl::GetWeakPtr() {
159 return weak_factory_.GetWeakPtr();
160 }
161
162 base::SingleThreadTaskRunner* AudioSystemImpl::GetTaskRunner() const {
163 return audio_manager_->GetTaskRunner();
140 } 164 }
141 165
142 AudioManager* AudioSystemImpl::GetAudioManager() const { 166 AudioManager* AudioSystemImpl::GetAudioManager() const {
143 return audio_manager_; 167 return audio_manager_;
144 } 168 }
145 169
146 base::SingleThreadTaskRunner* AudioSystemImpl::GetTaskRunner() const {
147 return audio_manager_->GetTaskRunner();
148 }
149
150 } // namespace media 170 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698