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

Side by Side Diff: content/browser/renderer_host/media/audio_output_authorization_handler.cc

Issue 2692203003: Switching AudioOutputAuthorizationHandler from using AudioManager interface to AudioSystem one. (Closed)
Patch Set: AudioSystem comments updated according to discussion with tommi@ 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/renderer_host/media/audio_output_authorization_handler .h" 5 #include "content/browser/renderer_host/media/audio_output_authorization_handler .h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/task_runner_util.h" 8 #include "base/task_runner_util.h"
9 #include "content/browser/bad_message.h" 9 #include "content/browser/bad_message.h"
10 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 10 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/media_device_id.h" 12 #include "content/public/browser/media_device_id.h"
13 #include "media/audio/audio_system.h"
13 #include "media/base/limits.h" 14 #include "media/base/limits.h"
14 15
15 namespace { 16 namespace {
16 17
17 media::AudioParameters TryToFixAudioParameters( 18 media::AudioParameters TryToFixAudioParameters(
18 const media::AudioParameters& params) { 19 const media::AudioParameters& params) {
19 DCHECK(!params.IsValid()); 20 DCHECK(!params.IsValid());
20 media::AudioParameters params_copy(params); 21 media::AudioParameters params_copy(params);
21 22
22 // If the number of output channels is greater than the maximum, use the 23 // If the number of output channels is greater than the maximum, use the
23 // maximum allowed value. Hardware channels are ignored upstream, so it is 24 // maximum allowed value. Hardware channels are ignored upstream, so it is
24 // better to report a valid value if this is the only problem. 25 // better to report a valid value if this is the only problem.
25 if (params.channels() > media::limits::kMaxChannels) { 26 if (params.channels() > media::limits::kMaxChannels) {
26 DCHECK(params.channel_layout() == media::CHANNEL_LAYOUT_DISCRETE); 27 DCHECK(params.channel_layout() == media::CHANNEL_LAYOUT_DISCRETE);
27 params_copy.set_channels_for_discrete(media::limits::kMaxChannels); 28 params_copy.set_channels_for_discrete(media::limits::kMaxChannels);
28 } 29 }
29 30
30 // If hardware parameters are still invalid, use dummy parameters with 31 // If hardware parameters are still invalid, use dummy parameters with
31 // fake audio path and let the client handle the error. 32 // fake audio path and let the client handle the error.
32 return params_copy.IsValid() 33 return params_copy.IsValid()
33 ? params_copy 34 ? params_copy
34 : media::AudioParameters::UnavailableDeviceParams(); 35 : media::AudioParameters::UnavailableDeviceParams();
35 } 36 }
36 37
37 media::AudioParameters GetDeviceParametersOnDeviceThread(
38 media::AudioManager* audio_manager,
39 const std::string& unique_id) {
40 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread());
41
42 return media::AudioDeviceDescription::IsDefaultDevice(unique_id)
43 ? audio_manager->GetDefaultOutputStreamParameters()
44 : audio_manager->GetOutputStreamParameters(unique_id);
45 }
46
47 } // namespace 38 } // namespace
48 39
49 namespace content { 40 namespace content {
50 41
51 AudioOutputAuthorizationHandler::AudioOutputAuthorizationHandler( 42 AudioOutputAuthorizationHandler::AudioOutputAuthorizationHandler(
52 media::AudioManager* audio_manager, 43 media::AudioSystem* audio_system,
53 MediaStreamManager* media_stream_manager, 44 MediaStreamManager* media_stream_manager,
54 int render_process_id, 45 int render_process_id,
55 const std::string& salt) 46 const std::string& salt)
56 : audio_manager_(audio_manager), 47 : audio_system_(audio_system),
57 media_stream_manager_(media_stream_manager), 48 media_stream_manager_(media_stream_manager),
58 permission_checker_(base::MakeUnique<MediaDevicesPermissionChecker>()), 49 permission_checker_(base::MakeUnique<MediaDevicesPermissionChecker>()),
59 render_process_id_(render_process_id), 50 render_process_id_(render_process_id),
60 salt_(salt), 51 salt_(salt),
61 weak_factory_(this) { 52 weak_factory_(this) {
62 DCHECK(media_stream_manager_); 53 DCHECK(media_stream_manager_);
63 } 54 }
64 55
65 void AudioOutputAuthorizationHandler::OverridePermissionsForTesting( 56 void AudioOutputAuthorizationHandler::OverridePermissionsForTesting(
66 bool override_value) { 57 bool override_value) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 175 }
185 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false, 176 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false,
186 media::AudioParameters::UnavailableDeviceParams(), std::string()); 177 media::AudioParameters::UnavailableDeviceParams(), std::string());
187 } 178 }
188 179
189 void AudioOutputAuthorizationHandler::GetDeviceParameters( 180 void AudioOutputAuthorizationHandler::GetDeviceParameters(
190 AuthorizationCompletedCallback cb, 181 AuthorizationCompletedCallback cb,
191 const std::string& raw_device_id) const { 182 const std::string& raw_device_id) const {
192 DCHECK_CURRENTLY_ON(BrowserThread::IO); 183 DCHECK_CURRENTLY_ON(BrowserThread::IO);
193 DCHECK(!raw_device_id.empty()); 184 DCHECK(!raw_device_id.empty());
194 base::PostTaskAndReplyWithResult( 185 audio_system_->GetOutputStreamParameters(
195 // Note: In the case of a shutdown, the task to delete |audio_manager_| is 186 raw_device_id,
196 // posted to the audio thread after the IO thread is stopped, so the task
197 // to delete the audio manager hasn't been posted yet. This means that
198 // unretained is safe here.
199 // Mac is a special case. Since the audio manager lives on the UI thread
200 // on Mac, this task is posted to the UI thread, but tasks posted to the
201 // UI task runner will be ignored when the shutdown has progressed to
202 // deleting the audio manager, so this is still safe.
203 audio_manager_->GetTaskRunner(), FROM_HERE,
204 base::Bind(&GetDeviceParametersOnDeviceThread,
205 base::Unretained(audio_manager_), raw_device_id),
206 base::Bind(&AudioOutputAuthorizationHandler::DeviceParametersReceived, 187 base::Bind(&AudioOutputAuthorizationHandler::DeviceParametersReceived,
207 weak_factory_.GetWeakPtr(), std::move(cb), false, 188 weak_factory_.GetWeakPtr(), std::move(cb), false,
208 raw_device_id)); 189 raw_device_id));
209 } 190 }
210 191
211 void AudioOutputAuthorizationHandler::DeviceParametersReceived( 192 void AudioOutputAuthorizationHandler::DeviceParametersReceived(
212 AuthorizationCompletedCallback cb, 193 AuthorizationCompletedCallback cb,
213 bool should_send_id, 194 bool should_send_id,
214 const std::string& raw_device_id, 195 const std::string& raw_device_id,
215 const media::AudioParameters& output_params) const { 196 const media::AudioParameters& output_params) const {
216 DCHECK_CURRENTLY_ON(BrowserThread::IO); 197 DCHECK_CURRENTLY_ON(BrowserThread::IO);
217 DCHECK(!raw_device_id.empty()); 198 DCHECK(!raw_device_id.empty());
218 199
219 cb.Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id, 200 cb.Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id,
220 output_params.IsValid() ? output_params 201 output_params.IsValid() ? output_params
221 : TryToFixAudioParameters(output_params), 202 : TryToFixAudioParameters(output_params),
222 raw_device_id); 203 raw_device_id);
223 } 204 }
224 205
225 } // namespace content 206 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698