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

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

Issue 2696253004: Revert of Switching AudioOutputAuthorizationHandler from using AudioManager interface to AudioSystem one. (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 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"
14 #include "media/base/limits.h" 13 #include "media/base/limits.h"
15 14
16 namespace { 15 namespace {
17 16
18 media::AudioParameters TryToFixAudioParameters( 17 media::AudioParameters TryToFixAudioParameters(
19 const media::AudioParameters& params) { 18 const media::AudioParameters& params) {
20 DCHECK(!params.IsValid()); 19 DCHECK(!params.IsValid());
21 media::AudioParameters params_copy(params); 20 media::AudioParameters params_copy(params);
22 21
23 // If the number of output channels is greater than the maximum, use the 22 // If the number of output channels is greater than the maximum, use the
24 // maximum allowed value. Hardware channels are ignored upstream, so it is 23 // maximum allowed value. Hardware channels are ignored upstream, so it is
25 // better to report a valid value if this is the only problem. 24 // better to report a valid value if this is the only problem.
26 if (params.channels() > media::limits::kMaxChannels) { 25 if (params.channels() > media::limits::kMaxChannels) {
27 DCHECK(params.channel_layout() == media::CHANNEL_LAYOUT_DISCRETE); 26 DCHECK(params.channel_layout() == media::CHANNEL_LAYOUT_DISCRETE);
28 params_copy.set_channels_for_discrete(media::limits::kMaxChannels); 27 params_copy.set_channels_for_discrete(media::limits::kMaxChannels);
29 } 28 }
30 29
31 // If hardware parameters are still invalid, use dummy parameters with 30 // If hardware parameters are still invalid, use dummy parameters with
32 // fake audio path and let the client handle the error. 31 // fake audio path and let the client handle the error.
33 return params_copy.IsValid() 32 return params_copy.IsValid()
34 ? params_copy 33 ? params_copy
35 : media::AudioParameters::UnavailableDeviceParams(); 34 : media::AudioParameters::UnavailableDeviceParams();
36 } 35 }
37 36
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
38 } // namespace 47 } // namespace
39 48
40 namespace content { 49 namespace content {
41 50
42 AudioOutputAuthorizationHandler::AudioOutputAuthorizationHandler( 51 AudioOutputAuthorizationHandler::AudioOutputAuthorizationHandler(
43 media::AudioSystem* audio_system, 52 media::AudioManager* audio_manager,
44 MediaStreamManager* media_stream_manager, 53 MediaStreamManager* media_stream_manager,
45 int render_process_id, 54 int render_process_id,
46 const std::string& salt) 55 const std::string& salt)
47 : audio_system_(audio_system), 56 : audio_manager_(audio_manager),
48 media_stream_manager_(media_stream_manager), 57 media_stream_manager_(media_stream_manager),
49 permission_checker_(base::MakeUnique<MediaDevicesPermissionChecker>()), 58 permission_checker_(base::MakeUnique<MediaDevicesPermissionChecker>()),
50 render_process_id_(render_process_id), 59 render_process_id_(render_process_id),
51 salt_(salt), 60 salt_(salt),
52 weak_factory_(this) { 61 weak_factory_(this) {
53 DCHECK(media_stream_manager_); 62 DCHECK(media_stream_manager_);
54 } 63 }
55 64
56 void AudioOutputAuthorizationHandler::OverridePermissionsForTesting( 65 void AudioOutputAuthorizationHandler::OverridePermissionsForTesting(
57 bool override_value) { 66 bool override_value) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 184 }
176 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false, 185 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false,
177 media::AudioParameters::UnavailableDeviceParams(), std::string()); 186 media::AudioParameters::UnavailableDeviceParams(), std::string());
178 } 187 }
179 188
180 void AudioOutputAuthorizationHandler::GetDeviceParameters( 189 void AudioOutputAuthorizationHandler::GetDeviceParameters(
181 AuthorizationCompletedCallback cb, 190 AuthorizationCompletedCallback cb,
182 const std::string& raw_device_id) const { 191 const std::string& raw_device_id) const {
183 DCHECK_CURRENTLY_ON(BrowserThread::IO); 192 DCHECK_CURRENTLY_ON(BrowserThread::IO);
184 DCHECK(!raw_device_id.empty()); 193 DCHECK(!raw_device_id.empty());
185 audio_system_->GetOutputStreamParameters( 194 base::PostTaskAndReplyWithResult(
186 raw_device_id, 195 // Note: In the case of a shutdown, the task to delete |audio_manager_| is
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),
187 base::Bind(&AudioOutputAuthorizationHandler::DeviceParametersReceived, 206 base::Bind(&AudioOutputAuthorizationHandler::DeviceParametersReceived,
188 weak_factory_.GetWeakPtr(), std::move(cb), false, 207 weak_factory_.GetWeakPtr(), std::move(cb), false,
189 raw_device_id)); 208 raw_device_id));
190 } 209 }
191 210
192 void AudioOutputAuthorizationHandler::DeviceParametersReceived( 211 void AudioOutputAuthorizationHandler::DeviceParametersReceived(
193 AuthorizationCompletedCallback cb, 212 AuthorizationCompletedCallback cb,
194 bool should_send_id, 213 bool should_send_id,
195 const std::string& raw_device_id, 214 const std::string& raw_device_id,
196 const media::AudioParameters& output_params) const { 215 const media::AudioParameters& output_params) const {
197 DCHECK_CURRENTLY_ON(BrowserThread::IO); 216 DCHECK_CURRENTLY_ON(BrowserThread::IO);
198 DCHECK(!raw_device_id.empty()); 217 DCHECK(!raw_device_id.empty());
199 218
200 cb.Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id, 219 cb.Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id,
201 output_params.IsValid() ? output_params 220 output_params.IsValid() ? output_params
202 : TryToFixAudioParameters(output_params), 221 : TryToFixAudioParameters(output_params),
203 raw_device_id); 222 raw_device_id);
204 } 223 }
205 224
206 } // namespace content 225 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698