OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 int render_view_id) { | 63 int render_view_id) { |
64 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
65 if (render_view_id == MSG_ROUTING_NONE || !ResourceDispatcherHostImpl::Get()) | 65 if (render_view_id == MSG_ROUTING_NONE || !ResourceDispatcherHostImpl::Get()) |
66 return; | 66 return; |
67 | 67 |
68 ResourceDispatcherHostImpl::Get()->OnAudioRenderHostStreamStateChanged( | 68 ResourceDispatcherHostImpl::Get()->OnAudioRenderHostStreamStateChanged( |
69 render_process_id, render_view_id, is_playing); | 69 render_process_id, render_view_id, is_playing); |
70 } | 70 } |
71 | 71 |
72 media::AudioParameters DummyParams() { | 72 media::AudioParameters DummyParams() { |
73 return media::AudioParameters(media::AudioParameters::AUDIO_PCM_LINEAR, | 73 return media::AudioParameters( |
74 media::CHANNEL_LAYOUT_STEREO, | 74 media::AudioParameters::AUDIO_FAKE, media::CHANNEL_LAYOUT_STEREO, |
75 media::limits::kMinSampleRate, 1, 1); | 75 media::AudioParameters::kAudioCDSampleRate, 16, |
| 76 media::AudioParameters::kAudioCDSampleRate / 10); |
76 } | 77 } |
77 | 78 |
78 std::pair<int, std::pair<bool, std::string>> MakeAuthorizationData( | 79 std::pair<int, std::pair<bool, std::string>> MakeAuthorizationData( |
79 int stream_id, | 80 int stream_id, |
80 bool authorized, | 81 bool authorized, |
81 const std::string& device_unique_id) { | 82 const std::string& device_unique_id) { |
82 return std::make_pair(stream_id, | 83 return std::make_pair(stream_id, |
83 std::make_pair(authorized, device_unique_id)); | 84 std::make_pair(authorized, device_unique_id)); |
84 } | 85 } |
85 | 86 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { | 127 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { |
127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 128 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
128 | 129 |
129 RenderProcessHost* render_process_host = | 130 RenderProcessHost* render_process_host = |
130 RenderProcessHost::FromID(render_process_id); | 131 RenderProcessHost::FromID(render_process_id); |
131 | 132 |
132 if (render_process_host) | 133 if (render_process_host) |
133 render_process_host->AudioStateChanged(); | 134 render_process_host->AudioStateChanged(); |
134 } | 135 } |
135 | 136 |
| 137 void MaybeFixAudioParameters(media::AudioParameters* params) { |
| 138 // If the number of output channels is greater than the maximum, use the |
| 139 // maximum allowed value. Hardware channels are ignored upstream, so it is |
| 140 // better to report a valid value if this is the only problem. |
| 141 if (params->channels() > media::limits::kMaxChannels) |
| 142 params->set_channels_for_discrete(media::limits::kMaxChannels); |
| 143 |
| 144 // If hardware parameters are still invalid, use dummy parameters with |
| 145 // fake audio path and let the client handle the error. |
| 146 if (!params->IsValid()) |
| 147 *params = DummyParams(); |
| 148 } |
| 149 |
136 } // namespace | 150 } // namespace |
137 | 151 |
138 class AudioRendererHost::AudioEntry | 152 class AudioRendererHost::AudioEntry |
139 : public media::AudioOutputController::EventHandler { | 153 : public media::AudioOutputController::EventHandler { |
140 public: | 154 public: |
141 AudioEntry(AudioRendererHost* host, | 155 AudioEntry(AudioRendererHost* host, |
142 int stream_id, | 156 int stream_id, |
143 int render_frame_id, | 157 int render_frame_id, |
144 const media::AudioParameters& params, | 158 const media::AudioParameters& params, |
145 const std::string& output_device_id, | 159 const std::string& output_device_id, |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 if (info) { | 464 if (info) { |
451 media::AudioParameters output_params( | 465 media::AudioParameters output_params( |
452 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 466 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
453 static_cast<media::ChannelLayout>( | 467 static_cast<media::ChannelLayout>( |
454 info->device.matched_output.channel_layout), | 468 info->device.matched_output.channel_layout), |
455 info->device.matched_output.sample_rate, 16, | 469 info->device.matched_output.sample_rate, 16, |
456 info->device.matched_output.frames_per_buffer); | 470 info->device.matched_output.frames_per_buffer); |
457 output_params.set_effects(info->device.matched_output.effects); | 471 output_params.set_effects(info->device.matched_output.effects); |
458 authorizations_.insert(MakeAuthorizationData( | 472 authorizations_.insert(MakeAuthorizationData( |
459 stream_id, true, info->device.matched_output_device_id)); | 473 stream_id, true, info->device.matched_output_device_id)); |
| 474 MaybeFixAudioParameters(&output_params); |
460 Send(new AudioMsg_NotifyDeviceAuthorized( | 475 Send(new AudioMsg_NotifyDeviceAuthorized( |
461 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); | 476 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); |
462 return; | 477 return; |
463 } | 478 } |
464 } | 479 } |
465 | 480 |
466 authorizations_.insert( | 481 authorizations_.insert( |
467 MakeAuthorizationData(stream_id, false, std::string())); | 482 MakeAuthorizationData(stream_id, false, std::string())); |
468 GURL gurl_security_origin = ConvertToGURL(security_origin); | 483 GURL gurl_security_origin = ConvertToGURL(security_origin); |
469 CheckOutputDeviceAccess( | 484 CheckOutputDeviceAccess( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 540 |
526 if (!device_found) { | 541 if (!device_found) { |
527 authorizations_.erase(auth_data); | 542 authorizations_.erase(auth_data); |
528 Send(new AudioMsg_NotifyDeviceAuthorized( | 543 Send(new AudioMsg_NotifyDeviceAuthorized( |
529 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams())); | 544 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams())); |
530 return; | 545 return; |
531 } | 546 } |
532 | 547 |
533 auth_data->second.first = true; | 548 auth_data->second.first = true; |
534 auth_data->second.second = device_info.unique_id; | 549 auth_data->second.second = device_info.unique_id; |
| 550 |
| 551 media::AudioParameters output_params = device_info.output_params; |
| 552 MaybeFixAudioParameters(&output_params); |
535 Send(new AudioMsg_NotifyDeviceAuthorized( | 553 Send(new AudioMsg_NotifyDeviceAuthorized( |
536 stream_id, media::OUTPUT_DEVICE_STATUS_OK, device_info.output_params)); | 554 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); |
537 } | 555 } |
538 | 556 |
539 void AudioRendererHost::OnCreateStream(int stream_id, | 557 void AudioRendererHost::OnCreateStream(int stream_id, |
540 int render_frame_id, | 558 int render_frame_id, |
541 const media::AudioParameters& params) { | 559 const media::AudioParameters& params) { |
542 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 560 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
543 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" | 561 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" |
544 << "(stream_id=" << stream_id << ")"; | 562 << "(stream_id=" << stream_id << ")"; |
545 | 563 |
546 const auto& auth_data = authorizations_.find(stream_id); | 564 const auto& auth_data = authorizations_.find(stream_id); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 callback.Run(false, device_info); | 858 callback.Run(false, device_info); |
841 } | 859 } |
842 | 860 |
843 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 861 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
844 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 862 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
845 const auto& i = authorizations_.find(stream_id); | 863 const auto& i = authorizations_.find(stream_id); |
846 return i != authorizations_.end(); | 864 return i != authorizations_.end(); |
847 } | 865 } |
848 | 866 |
849 } // namespace content | 867 } // namespace content |
OLD | NEW |