| 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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 << "(stream_id=" << stream_id | 420 << "(stream_id=" << stream_id |
| 421 << ", render_frame_id=" << render_frame_id | 421 << ", render_frame_id=" << render_frame_id |
| 422 << ", session_id=" << session_id << ", device_id=" << device_id | 422 << ", session_id=" << session_id << ", device_id=" << device_id |
| 423 << ", security_origin=" << security_origin << ")"; | 423 << ", security_origin=" << security_origin << ")"; |
| 424 | 424 |
| 425 if (LookupById(stream_id) || IsAuthorizationStarted(stream_id)) | 425 if (LookupById(stream_id) || IsAuthorizationStarted(stream_id)) |
| 426 return; | 426 return; |
| 427 | 427 |
| 428 if (!IsValidDeviceId(device_id)) { | 428 if (!IsValidDeviceId(device_id)) { |
| 429 Send(new AudioMsg_NotifyDeviceAuthorized( | 429 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 430 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams())); | 430 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams(), |
| 431 std::string())); |
| 431 return; | 432 return; |
| 432 } | 433 } |
| 433 | 434 |
| 434 // If |device_id| is not empty, ignore |session_id| and select the device | 435 // If |device_id| is not empty, ignore |session_id| and select the device |
| 435 // indicated by |device_id|. | 436 // indicated by |device_id|. |
| 436 // If |device_id| is empty and |session_id| is nonzero, try to use the | 437 // 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 | 438 // output device associated with the opened input device designated by |
| 438 // |session_id| and, if such output device is found, reuse the input device | 439 // |session_id| and, if such output device is found, reuse the input device |
| 439 // permissions. | 440 // permissions. |
| 440 if (session_id != 0 && device_id.empty()) { | 441 if (session_id != 0 && device_id.empty()) { |
| 441 const StreamDeviceInfo* info = | 442 const StreamDeviceInfo* info = |
| 442 media_stream_manager_->audio_input_device_manager() | 443 media_stream_manager_->audio_input_device_manager() |
| 443 ->GetOpenedDeviceInfoById(session_id); | 444 ->GetOpenedDeviceInfoById(session_id); |
| 444 if (info) { | 445 if (info) { |
| 445 media::AudioParameters output_params( | 446 media::AudioParameters output_params( |
| 446 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 447 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 447 static_cast<media::ChannelLayout>( | 448 static_cast<media::ChannelLayout>( |
| 448 info->device.matched_output.channel_layout), | 449 info->device.matched_output.channel_layout), |
| 449 info->device.matched_output.sample_rate, 16, | 450 info->device.matched_output.sample_rate, 16, |
| 450 info->device.matched_output.frames_per_buffer); | 451 info->device.matched_output.frames_per_buffer); |
| 451 output_params.set_effects(info->device.matched_output.effects); | 452 output_params.set_effects(info->device.matched_output.effects); |
| 452 authorizations_.insert(MakeAuthorizationData( | 453 authorizations_.insert(MakeAuthorizationData( |
| 453 stream_id, true, info->device.matched_output_device_id)); | 454 stream_id, true, info->device.matched_output_device_id)); |
| 454 MaybeFixAudioParameters(&output_params); | 455 MaybeFixAudioParameters(&output_params); |
| 456 // Hash matched device id and pass it to the renderer |
| 457 GURL gurl_security_origin = ConvertToGURL(security_origin); |
| 455 Send(new AudioMsg_NotifyDeviceAuthorized( | 458 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 456 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); | 459 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params, |
| 460 GetHMACForMediaDeviceID( |
| 461 salt_callback_, gurl_security_origin, |
| 462 info->device.matched_output_device_id.empty() |
| 463 ? media::AudioManagerBase::kDefaultDeviceId |
| 464 : info->device.matched_output_device_id))); |
| 457 return; | 465 return; |
| 458 } | 466 } |
| 459 } | 467 } |
| 460 | 468 |
| 461 authorizations_.insert( | 469 authorizations_.insert( |
| 462 MakeAuthorizationData(stream_id, false, std::string())); | 470 MakeAuthorizationData(stream_id, false, std::string())); |
| 463 GURL gurl_security_origin = ConvertToGURL(security_origin); | 471 GURL gurl_security_origin = ConvertToGURL(security_origin); |
| 464 CheckOutputDeviceAccess( | 472 CheckOutputDeviceAccess( |
| 465 render_frame_id, device_id, gurl_security_origin, | 473 render_frame_id, device_id, gurl_security_origin, |
| 466 base::Bind(&AudioRendererHost::OnDeviceAuthorized, this, stream_id, | 474 base::Bind(&AudioRendererHost::OnDeviceAuthorized, this, stream_id, |
| 467 device_id, gurl_security_origin)); | 475 device_id, gurl_security_origin)); |
| 468 } | 476 } |
| 469 | 477 |
| 470 void AudioRendererHost::OnDeviceAuthorized(int stream_id, | 478 void AudioRendererHost::OnDeviceAuthorized(int stream_id, |
| 471 const std::string& device_id, | 479 const std::string& device_id, |
| 472 const GURL& gurl_security_origin, | 480 const GURL& gurl_security_origin, |
| 473 bool have_access) { | 481 bool have_access) { |
| 474 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 482 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 475 const auto& auth_data = authorizations_.find(stream_id); | 483 const auto& auth_data = authorizations_.find(stream_id); |
| 476 | 484 |
| 477 // A close request was received while access check was in progress. | 485 // A close request was received while access check was in progress. |
| 478 if (auth_data == authorizations_.end()) | 486 if (auth_data == authorizations_.end()) |
| 479 return; | 487 return; |
| 480 | 488 |
| 481 if (!have_access) { | 489 if (!have_access) { |
| 482 authorizations_.erase(auth_data); | 490 authorizations_.erase(auth_data); |
| 483 Send(new AudioMsg_NotifyDeviceAuthorized( | 491 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 484 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, | 492 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, |
| 485 DummyParams())); | 493 DummyParams(), std::string())); |
| 486 return; | 494 return; |
| 487 } | 495 } |
| 488 | 496 |
| 489 // If enumerator caching is disabled, avoid the enumeration if the default | 497 // If enumerator caching is disabled, avoid the enumeration if the default |
| 490 // device is requested, since no device ID translation is needed. | 498 // device is requested, since no device ID translation is needed. |
| 491 // If enumerator caching is enabled, it is better to use its cache, even | 499 // If enumerator caching is enabled, it is better to use its cache, even |
| 492 // for the default device. | 500 // for the default device. |
| 493 if (IsDefaultDeviceId(device_id) && | 501 if (IsDefaultDeviceId(device_id) && |
| 494 !media_stream_manager_->audio_output_device_enumerator() | 502 !media_stream_manager_->audio_output_device_enumerator() |
| 495 ->IsCacheEnabled()) { | 503 ->IsCacheEnabled()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 514 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 522 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 515 const auto& auth_data = authorizations_.find(stream_id); | 523 const auto& auth_data = authorizations_.find(stream_id); |
| 516 | 524 |
| 517 // A close request was received while translation was in progress | 525 // A close request was received while translation was in progress |
| 518 if (auth_data == authorizations_.end()) | 526 if (auth_data == authorizations_.end()) |
| 519 return; | 527 return; |
| 520 | 528 |
| 521 if (!device_found) { | 529 if (!device_found) { |
| 522 authorizations_.erase(auth_data); | 530 authorizations_.erase(auth_data); |
| 523 Send(new AudioMsg_NotifyDeviceAuthorized( | 531 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 524 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams())); | 532 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, DummyParams(), |
| 533 std::string())); |
| 525 return; | 534 return; |
| 526 } | 535 } |
| 527 | 536 |
| 528 auth_data->second.first = true; | 537 auth_data->second.first = true; |
| 529 auth_data->second.second = device_info.unique_id; | 538 auth_data->second.second = device_info.unique_id; |
| 530 | 539 |
| 531 media::AudioParameters output_params = device_info.output_params; | 540 media::AudioParameters output_params = device_info.output_params; |
| 532 MaybeFixAudioParameters(&output_params); | 541 MaybeFixAudioParameters(&output_params); |
| 533 Send(new AudioMsg_NotifyDeviceAuthorized( | 542 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 534 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params)); | 543 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params, std::string())); |
| 535 } | 544 } |
| 536 | 545 |
| 537 void AudioRendererHost::OnCreateStream(int stream_id, | 546 void AudioRendererHost::OnCreateStream(int stream_id, |
| 538 int render_frame_id, | 547 int render_frame_id, |
| 539 const media::AudioParameters& params) { | 548 const media::AudioParameters& params) { |
| 540 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 549 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 541 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" | 550 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" |
| 542 << "(stream_id=" << stream_id << ")"; | 551 << "(stream_id=" << stream_id << ")"; |
| 543 | 552 |
| 544 const auto& auth_data = authorizations_.find(stream_id); | 553 const auto& auth_data = authorizations_.find(stream_id); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 callback.Run(false, device_info); | 831 callback.Run(false, device_info); |
| 823 } | 832 } |
| 824 | 833 |
| 825 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 834 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
| 826 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 835 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 827 const auto& i = authorizations_.find(stream_id); | 836 const auto& i = authorizations_.find(stream_id); |
| 828 return i != authorizations_.end(); | 837 return i != authorizations_.end(); |
| 829 } | 838 } |
| 830 | 839 |
| 831 } // namespace content | 840 } // namespace content |
| OLD | NEW |