Chromium Code Reviews| 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, change | |
| 139 // to the maximum allowed value. Hardware channels are ignored upstream, | |
| 140 // so it is better to report status OK if the only problem is that the number | |
| 141 // of hardware channels is too large. | |
| 142 if (!params->IsValid() && | |
|
DaleCurtis
2016/01/07 19:14:51
Seems these first two conditions aren't necessary?
Guido Urdaneta
2016/01/08 11:20:34
Done.
| |
| 143 params->channel_layout() == media::CHANNEL_LAYOUT_DISCRETE && | |
| 144 params->channels() > media::limits::kMaxChannels) { | |
| 145 params->set_channels_for_discrete(media::limits::kMaxChannels); | |
| 146 } | |
| 147 | |
| 148 // If hardware parameters are still invalid, use dummy parameters with | |
| 149 // fake audio path. | |
| 150 if (!params->IsValid()) { | |
| 151 *params = DummyParams(); | |
| 152 } | |
| 153 } | |
| 154 | |
| 136 } // namespace | 155 } // namespace |
| 137 | 156 |
| 138 class AudioRendererHost::AudioEntry | 157 class AudioRendererHost::AudioEntry |
| 139 : public media::AudioOutputController::EventHandler { | 158 : public media::AudioOutputController::EventHandler { |
| 140 public: | 159 public: |
| 141 AudioEntry(AudioRendererHost* host, | 160 AudioEntry(AudioRendererHost* host, |
| 142 int stream_id, | 161 int stream_id, |
| 143 int render_frame_id, | 162 int render_frame_id, |
| 144 const media::AudioParameters& params, | 163 const media::AudioParameters& params, |
| 145 const std::string& output_device_id, | 164 const std::string& output_device_id, |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 if (info) { | 469 if (info) { |
| 451 media::AudioParameters output_params( | 470 media::AudioParameters output_params( |
| 452 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 471 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 453 static_cast<media::ChannelLayout>( | 472 static_cast<media::ChannelLayout>( |
| 454 info->device.matched_output.channel_layout), | 473 info->device.matched_output.channel_layout), |
| 455 info->device.matched_output.sample_rate, 16, | 474 info->device.matched_output.sample_rate, 16, |
| 456 info->device.matched_output.frames_per_buffer); | 475 info->device.matched_output.frames_per_buffer); |
| 457 output_params.set_effects(info->device.matched_output.effects); | 476 output_params.set_effects(info->device.matched_output.effects); |
| 458 authorizations_.insert(MakeAuthorizationData( | 477 authorizations_.insert(MakeAuthorizationData( |
| 459 stream_id, true, info->device.matched_output_device_id)); | 478 stream_id, true, info->device.matched_output_device_id)); |
| 479 MaybeFixAudioParameters(&output_params); | |
| 460 Send(new AudioMsg_NotifyDeviceAuthorized( | 480 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 461 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); | 481 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); |
| 462 return; | 482 return; |
| 463 } | 483 } |
| 464 } | 484 } |
| 465 | 485 |
| 466 authorizations_.insert( | 486 authorizations_.insert( |
| 467 MakeAuthorizationData(stream_id, false, std::string())); | 487 MakeAuthorizationData(stream_id, false, std::string())); |
| 468 GURL gurl_security_origin = ConvertToGURL(security_origin); | 488 GURL gurl_security_origin = ConvertToGURL(security_origin); |
| 469 CheckOutputDeviceAccess( | 489 CheckOutputDeviceAccess( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 | 545 |
| 526 if (!device_found) { | 546 if (!device_found) { |
| 527 authorizations_.erase(auth_data); | 547 authorizations_.erase(auth_data); |
| 528 Send(new AudioMsg_NotifyDeviceAuthorized( | 548 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 529 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams())); | 549 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams())); |
| 530 return; | 550 return; |
| 531 } | 551 } |
| 532 | 552 |
| 533 auth_data->second.first = true; | 553 auth_data->second.first = true; |
| 534 auth_data->second.second = device_info.unique_id; | 554 auth_data->second.second = device_info.unique_id; |
| 555 | |
| 556 media::AudioParameters output_params = device_info.output_params; | |
| 557 MaybeFixAudioParameters(&output_params); | |
| 535 Send(new AudioMsg_NotifyDeviceAuthorized( | 558 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 536 stream_id, media::OUTPUT_DEVICE_STATUS_OK, device_info.output_params)); | 559 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); |
| 537 } | 560 } |
| 538 | 561 |
| 539 void AudioRendererHost::OnCreateStream(int stream_id, | 562 void AudioRendererHost::OnCreateStream(int stream_id, |
| 540 int render_frame_id, | 563 int render_frame_id, |
| 541 const media::AudioParameters& params) { | 564 const media::AudioParameters& params) { |
| 542 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 565 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 543 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" | 566 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" |
| 544 << "(stream_id=" << stream_id << ")"; | 567 << "(stream_id=" << stream_id << ")"; |
| 545 | 568 |
| 546 const auto& auth_data = authorizations_.find(stream_id); | 569 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); | 863 callback.Run(false, device_info); |
| 841 } | 864 } |
| 842 | 865 |
| 843 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 866 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
| 844 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 867 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 845 const auto& i = authorizations_.find(stream_id); | 868 const auto& i = authorizations_.find(stream_id); |
| 846 return i != authorizations_.end(); | 869 return i != authorizations_.end(); |
| 847 } | 870 } |
| 848 | 871 |
| 849 } // namespace content | 872 } // namespace content |
| OLD | NEW |