| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 int render_view_id) { | 55 int render_view_id) { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 57 if (render_view_id == MSG_ROUTING_NONE || !ResourceDispatcherHostImpl::Get()) | 57 if (render_view_id == MSG_ROUTING_NONE || !ResourceDispatcherHostImpl::Get()) |
| 58 return; | 58 return; |
| 59 | 59 |
| 60 ResourceDispatcherHostImpl::Get()->OnAudioRenderHostStreamStateChanged( | 60 ResourceDispatcherHostImpl::Get()->OnAudioRenderHostStreamStateChanged( |
| 61 render_process_id, render_view_id, is_playing); | 61 render_process_id, render_view_id, is_playing); |
| 62 } | 62 } |
| 63 | 63 |
| 64 media::AudioParameters DummyParams() { | 64 media::AudioParameters DummyParams() { |
| 65 return media::AudioParameters(media::AudioParameters::AUDIO_PCM_LINEAR, | 65 return media::AudioParameters( |
| 66 media::CHANNEL_LAYOUT_STEREO, | 66 media::AudioParameters::AUDIO_FAKE, media::CHANNEL_LAYOUT_STEREO, |
| 67 media::limits::kMinSampleRate, 1, 1); | 67 media::AudioParameters::kAudioCDSampleRate, 16, |
| 68 media::AudioParameters::kAudioCDSampleRate / 10); |
| 68 } | 69 } |
| 69 | 70 |
| 70 std::pair<int, std::pair<bool, std::string>> MakeAuthorizationData( | 71 std::pair<int, std::pair<bool, std::string>> MakeAuthorizationData( |
| 71 int stream_id, | 72 int stream_id, |
| 72 bool authorized, | 73 bool authorized, |
| 73 const std::string& device_unique_id) { | 74 const std::string& device_unique_id) { |
| 74 return std::make_pair(stream_id, | 75 return std::make_pair(stream_id, |
| 75 std::make_pair(authorized, device_unique_id)); | 76 std::make_pair(authorized, device_unique_id)); |
| 76 } | 77 } |
| 77 | 78 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { | 119 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { |
| 119 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 120 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 120 | 121 |
| 121 RenderProcessHost* render_process_host = | 122 RenderProcessHost* render_process_host = |
| 122 RenderProcessHost::FromID(render_process_id); | 123 RenderProcessHost::FromID(render_process_id); |
| 123 | 124 |
| 124 if (render_process_host) | 125 if (render_process_host) |
| 125 render_process_host->AudioStateChanged(); | 126 render_process_host->AudioStateChanged(); |
| 126 } | 127 } |
| 127 | 128 |
| 129 void MaybeFixAudioParameters(media::AudioParameters* params) { |
| 130 // If the number of output channels is greater than the maximum, use the |
| 131 // maximum allowed value. Hardware channels are ignored upstream, so it is |
| 132 // better to report a valid value if this is the only problem. |
| 133 if (params->channels() > media::limits::kMaxChannels) |
| 134 params->set_channels_for_discrete(media::limits::kMaxChannels); |
| 135 |
| 136 // If hardware parameters are still invalid, use dummy parameters with |
| 137 // fake audio path and let the client handle the error. |
| 138 if (!params->IsValid()) |
| 139 *params = DummyParams(); |
| 140 } |
| 141 |
| 128 } // namespace | 142 } // namespace |
| 129 | 143 |
| 130 class AudioRendererHost::AudioEntry | 144 class AudioRendererHost::AudioEntry |
| 131 : public media::AudioOutputController::EventHandler { | 145 : public media::AudioOutputController::EventHandler { |
| 132 public: | 146 public: |
| 133 AudioEntry(AudioRendererHost* host, | 147 AudioEntry(AudioRendererHost* host, |
| 134 int stream_id, | 148 int stream_id, |
| 135 int render_frame_id, | 149 int render_frame_id, |
| 136 const media::AudioParameters& params, | 150 const media::AudioParameters& params, |
| 137 const std::string& output_device_id, | 151 const std::string& output_device_id, |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 if (info) { | 441 if (info) { |
| 428 media::AudioParameters output_params( | 442 media::AudioParameters output_params( |
| 429 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 443 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 430 static_cast<media::ChannelLayout>( | 444 static_cast<media::ChannelLayout>( |
| 431 info->device.matched_output.channel_layout), | 445 info->device.matched_output.channel_layout), |
| 432 info->device.matched_output.sample_rate, 16, | 446 info->device.matched_output.sample_rate, 16, |
| 433 info->device.matched_output.frames_per_buffer); | 447 info->device.matched_output.frames_per_buffer); |
| 434 output_params.set_effects(info->device.matched_output.effects); | 448 output_params.set_effects(info->device.matched_output.effects); |
| 435 authorizations_.insert(MakeAuthorizationData( | 449 authorizations_.insert(MakeAuthorizationData( |
| 436 stream_id, true, info->device.matched_output_device_id)); | 450 stream_id, true, info->device.matched_output_device_id)); |
| 451 MaybeFixAudioParameters(&output_params); |
| 437 Send(new AudioMsg_NotifyDeviceAuthorized( | 452 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 438 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); | 453 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); |
| 439 return; | 454 return; |
| 440 } | 455 } |
| 441 } | 456 } |
| 442 | 457 |
| 443 authorizations_.insert( | 458 authorizations_.insert( |
| 444 MakeAuthorizationData(stream_id, false, std::string())); | 459 MakeAuthorizationData(stream_id, false, std::string())); |
| 445 GURL gurl_security_origin = ConvertToGURL(security_origin); | 460 GURL gurl_security_origin = ConvertToGURL(security_origin); |
| 446 CheckOutputDeviceAccess( | 461 CheckOutputDeviceAccess( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 517 |
| 503 if (!device_found) { | 518 if (!device_found) { |
| 504 authorizations_.erase(auth_data); | 519 authorizations_.erase(auth_data); |
| 505 Send(new AudioMsg_NotifyDeviceAuthorized( | 520 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 506 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams())); | 521 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams())); |
| 507 return; | 522 return; |
| 508 } | 523 } |
| 509 | 524 |
| 510 auth_data->second.first = true; | 525 auth_data->second.first = true; |
| 511 auth_data->second.second = device_info.unique_id; | 526 auth_data->second.second = device_info.unique_id; |
| 527 |
| 528 media::AudioParameters output_params = device_info.output_params; |
| 529 MaybeFixAudioParameters(&output_params); |
| 512 Send(new AudioMsg_NotifyDeviceAuthorized( | 530 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 513 stream_id, media::OUTPUT_DEVICE_STATUS_OK, device_info.output_params)); | 531 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); |
| 514 } | 532 } |
| 515 | 533 |
| 516 void AudioRendererHost::OnCreateStream(int stream_id, | 534 void AudioRendererHost::OnCreateStream(int stream_id, |
| 517 int render_frame_id, | 535 int render_frame_id, |
| 518 const media::AudioParameters& params) { | 536 const media::AudioParameters& params) { |
| 519 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 537 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 520 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" | 538 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" |
| 521 << "(stream_id=" << stream_id << ")"; | 539 << "(stream_id=" << stream_id << ")"; |
| 522 | 540 |
| 523 const auto& auth_data = authorizations_.find(stream_id); | 541 const auto& auth_data = authorizations_.find(stream_id); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 callback.Run(false, device_info); | 829 callback.Run(false, device_info); |
| 812 } | 830 } |
| 813 | 831 |
| 814 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 832 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
| 815 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 833 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 816 const auto& i = authorizations_.find(stream_id); | 834 const auto& i = authorizations_.find(stream_id); |
| 817 return i != authorizations_.end(); | 835 return i != authorizations_.end(); |
| 818 } | 836 } |
| 819 | 837 |
| 820 } // namespace content | 838 } // namespace content |
| OLD | NEW |