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 <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 namespace content { | 43 namespace content { |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
47 // Tracks the maximum number of simultaneous output streams browser-wide. | 47 // Tracks the maximum number of simultaneous output streams browser-wide. |
48 // Accessed on IO thread. | 48 // Accessed on IO thread. |
49 base::LazyInstance<media::AudioStreamsTracker> g_audio_streams_tracker = | 49 base::LazyInstance<media::AudioStreamsTracker> g_audio_streams_tracker = |
50 LAZY_INSTANCE_INITIALIZER; | 50 LAZY_INSTANCE_INITIALIZER; |
51 | 51 |
52 media::AudioParameters DummyParams() { | |
53 return media::AudioParameters( | |
54 media::AudioParameters::AUDIO_FAKE, media::CHANNEL_LAYOUT_STEREO, | |
55 media::AudioParameters::kAudioCDSampleRate, 16, | |
56 media::AudioParameters::kAudioCDSampleRate / 10); | |
57 } | |
58 | |
59 std::pair<int, std::pair<bool, std::string>> MakeAuthorizationData( | 52 std::pair<int, std::pair<bool, std::string>> MakeAuthorizationData( |
60 int stream_id, | 53 int stream_id, |
61 bool authorized, | 54 bool authorized, |
62 const std::string& device_unique_id) { | 55 const std::string& device_unique_id) { |
63 return std::make_pair(stream_id, | 56 return std::make_pair(stream_id, |
64 std::make_pair(authorized, device_unique_id)); | 57 std::make_pair(authorized, device_unique_id)); |
65 } | 58 } |
66 | 59 |
67 GURL ConvertToGURL(const url::Origin& origin) { | 60 GURL ConvertToGURL(const url::Origin& origin) { |
68 return origin.unique() ? GURL() : GURL(origin.Serialize()); | 61 return origin.unique() ? GURL() : GURL(origin.Serialize()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 void MaybeFixAudioParameters(media::AudioParameters* params) { | 110 void MaybeFixAudioParameters(media::AudioParameters* params) { |
118 // If the number of output channels is greater than the maximum, use the | 111 // If the number of output channels is greater than the maximum, use the |
119 // maximum allowed value. Hardware channels are ignored upstream, so it is | 112 // maximum allowed value. Hardware channels are ignored upstream, so it is |
120 // better to report a valid value if this is the only problem. | 113 // better to report a valid value if this is the only problem. |
121 if (params->channels() > media::limits::kMaxChannels) | 114 if (params->channels() > media::limits::kMaxChannels) |
122 params->set_channels_for_discrete(media::limits::kMaxChannels); | 115 params->set_channels_for_discrete(media::limits::kMaxChannels); |
123 | 116 |
124 // If hardware parameters are still invalid, use dummy parameters with | 117 // If hardware parameters are still invalid, use dummy parameters with |
125 // fake audio path and let the client handle the error. | 118 // fake audio path and let the client handle the error. |
126 if (!params->IsValid()) | 119 if (!params->IsValid()) |
127 *params = DummyParams(); | 120 *params = media::AudioParameters::UnavailableDeviceParams(); |
128 } | 121 } |
129 | 122 |
130 } // namespace | 123 } // namespace |
131 | 124 |
132 class AudioRendererHost::AudioEntry | 125 class AudioRendererHost::AudioEntry |
133 : public media::AudioOutputController::EventHandler { | 126 : public media::AudioOutputController::EventHandler { |
134 public: | 127 public: |
135 AudioEntry(AudioRendererHost* host, | 128 AudioEntry(AudioRendererHost* host, |
136 int stream_id, | 129 int stream_id, |
137 int render_frame_id, | 130 int render_frame_id, |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 << "(stream_id=" << stream_id | 413 << "(stream_id=" << stream_id |
421 << ", render_frame_id=" << render_frame_id | 414 << ", render_frame_id=" << render_frame_id |
422 << ", session_id=" << session_id << ", device_id=" << device_id | 415 << ", session_id=" << session_id << ", device_id=" << device_id |
423 << ", security_origin=" << security_origin << ")"; | 416 << ", security_origin=" << security_origin << ")"; |
424 | 417 |
425 if (LookupById(stream_id) || IsAuthorizationStarted(stream_id)) | 418 if (LookupById(stream_id) || IsAuthorizationStarted(stream_id)) |
426 return; | 419 return; |
427 | 420 |
428 if (!IsValidDeviceId(device_id)) { | 421 if (!IsValidDeviceId(device_id)) { |
429 Send(new AudioMsg_NotifyDeviceAuthorized( | 422 Send(new AudioMsg_NotifyDeviceAuthorized( |
430 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams())); | 423 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, |
| 424 media::AudioParameters::UnavailableDeviceParams())); |
431 return; | 425 return; |
432 } | 426 } |
433 | 427 |
434 // If |device_id| is not empty, ignore |session_id| and select the device | 428 // If |device_id| is not empty, ignore |session_id| and select the device |
435 // indicated by |device_id|. | 429 // indicated by |device_id|. |
436 // If |device_id| is empty and |session_id| is nonzero, try to use the | 430 // If |device_id| is empty and |session_id| is nonzero, try to use the |
437 // output device associated with the opened input device designated by | 431 // output device associated with the opened input device designated by |
438 // |session_id| and, if such output device is found, reuse the input device | 432 // |session_id| and, if such output device is found, reuse the input device |
439 // permissions. | 433 // permissions. |
440 if (session_id != 0 && device_id.empty()) { | 434 if (session_id != 0 && device_id.empty()) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 const auto& auth_data = authorizations_.find(stream_id); | 469 const auto& auth_data = authorizations_.find(stream_id); |
476 | 470 |
477 // A close request was received while access check was in progress. | 471 // A close request was received while access check was in progress. |
478 if (auth_data == authorizations_.end()) | 472 if (auth_data == authorizations_.end()) |
479 return; | 473 return; |
480 | 474 |
481 if (!have_access) { | 475 if (!have_access) { |
482 authorizations_.erase(auth_data); | 476 authorizations_.erase(auth_data); |
483 Send(new AudioMsg_NotifyDeviceAuthorized( | 477 Send(new AudioMsg_NotifyDeviceAuthorized( |
484 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, | 478 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, |
485 DummyParams())); | 479 media::AudioParameters::UnavailableDeviceParams())); |
486 return; | 480 return; |
487 } | 481 } |
488 | 482 |
489 // If enumerator caching is disabled, avoid the enumeration if the default | 483 // If enumerator caching is disabled, avoid the enumeration if the default |
490 // device is requested, since no device ID translation is needed. | 484 // device is requested, since no device ID translation is needed. |
491 // If enumerator caching is enabled, it is better to use its cache, even | 485 // If enumerator caching is enabled, it is better to use its cache, even |
492 // for the default device. | 486 // for the default device. |
493 if (IsDefaultDeviceId(device_id) && | 487 if (IsDefaultDeviceId(device_id) && |
494 !media_stream_manager_->audio_output_device_enumerator() | 488 !media_stream_manager_->audio_output_device_enumerator() |
495 ->IsCacheEnabled()) { | 489 ->IsCacheEnabled()) { |
(...skipping 18 matching lines...) Expand all Loading... |
514 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 508 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
515 const auto& auth_data = authorizations_.find(stream_id); | 509 const auto& auth_data = authorizations_.find(stream_id); |
516 | 510 |
517 // A close request was received while translation was in progress | 511 // A close request was received while translation was in progress |
518 if (auth_data == authorizations_.end()) | 512 if (auth_data == authorizations_.end()) |
519 return; | 513 return; |
520 | 514 |
521 if (!device_found) { | 515 if (!device_found) { |
522 authorizations_.erase(auth_data); | 516 authorizations_.erase(auth_data); |
523 Send(new AudioMsg_NotifyDeviceAuthorized( | 517 Send(new AudioMsg_NotifyDeviceAuthorized( |
524 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams())); | 518 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, |
| 519 media::AudioParameters::UnavailableDeviceParams())); |
525 return; | 520 return; |
526 } | 521 } |
527 | 522 |
528 auth_data->second.first = true; | 523 auth_data->second.first = true; |
529 auth_data->second.second = device_info.unique_id; | 524 auth_data->second.second = device_info.unique_id; |
530 | 525 |
531 media::AudioParameters output_params = device_info.output_params; | 526 media::AudioParameters output_params = device_info.output_params; |
532 MaybeFixAudioParameters(&output_params); | 527 MaybeFixAudioParameters(&output_params); |
533 Send(new AudioMsg_NotifyDeviceAuthorized( | 528 Send(new AudioMsg_NotifyDeviceAuthorized( |
534 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); | 529 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 return; | 805 return; |
811 } | 806 } |
812 } else if (content::DoesMediaDeviceIDMatchHMAC(salt_callback_, | 807 } else if (content::DoesMediaDeviceIDMatchHMAC(salt_callback_, |
813 security_origin, device_id, | 808 security_origin, device_id, |
814 device_info.unique_id)) { | 809 device_info.unique_id)) { |
815 callback.Run(true, device_info); | 810 callback.Run(true, device_info); |
816 return; | 811 return; |
817 } | 812 } |
818 } | 813 } |
819 DCHECK(!device_id.empty()); // Default device must always be found | 814 DCHECK(!device_id.empty()); // Default device must always be found |
820 AudioOutputDeviceInfo device_info = {std::string(), std::string(), | 815 AudioOutputDeviceInfo device_info = { |
821 DummyParams()}; | 816 std::string(), std::string(), |
| 817 media::AudioParameters::UnavailableDeviceParams()}; |
822 callback.Run(false, device_info); | 818 callback.Run(false, device_info); |
823 } | 819 } |
824 | 820 |
825 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 821 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
826 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 822 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
827 const auto& i = authorizations_.find(stream_id); | 823 const auto& i = authorizations_.find(stream_id); |
828 return i != authorizations_.end(); | 824 return i != authorizations_.end(); |
829 } | 825 } |
830 | 826 |
831 } // namespace content | 827 } // namespace content |
OLD | NEW |