Chromium Code Reviews| Index: content/browser/renderer_host/media/renderer_audio_output_stream_factory_context_impl.cc |
| diff --git a/content/browser/renderer_host/media/renderer_audio_output_stream_factory_context_impl.cc b/content/browser/renderer_host/media/renderer_audio_output_stream_factory_context_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6d92d46bd3758a874e7108b813b00cb57bb085a4 |
| --- /dev/null |
| +++ b/content/browser/renderer_host/media/renderer_audio_output_stream_factory_context_impl.cc |
| @@ -0,0 +1,99 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/renderer_host/media/renderer_audio_output_stream_factory_context_impl.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "content/browser/media/capture/audio_mirroring_manager.h" |
| +#include "content/browser/media/media_internals.h" |
| +#include "content/browser/renderer_host/media/audio_output_delegate_impl.h" |
| +#include "content/browser/renderer_host/media/media_stream_manager.h" |
| +#include "content/browser/renderer_host/media/render_frame_audio_output_stream_factory.h" |
| +#include "content/common/media/renderer_audio_output_stream_factory.mojom.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/content_browser_client.h" |
| +#include "media/audio/audio_system.h" |
| + |
| +namespace content { |
| + |
| +RendererAudioOutputStreamFactoryContextImpl:: |
| + RendererAudioOutputStreamFactoryContextImpl( |
| + int render_process_id, |
| + media::AudioSystem* audio_system, |
| + MediaStreamManager* media_stream_manager, |
| + const std::string& salt) |
| + : salt_(salt), |
| + render_process_id_(render_process_id), |
| + audio_system_(audio_system), |
| + media_stream_manager_(media_stream_manager), |
| + authorization_handler_(audio_system_, |
| + media_stream_manager_, |
| + render_process_id_, |
| + salt_) {} |
| + |
| +RendererAudioOutputStreamFactoryContextImpl:: |
| + ~RendererAudioOutputStreamFactoryContextImpl() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| +} |
| + |
| +void RendererAudioOutputStreamFactoryContextImpl::CreateFactory( |
| + int frame_host_id, |
| + mojo::InterfaceRequest<mojom::RendererAudioOutputStreamFactory> request) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + |
| + factories_.AddBinding(base::MakeUnique<RenderFrameAudioOutputStreamFactory>( |
| + frame_host_id, this), |
| + std::move(request)); |
| +} |
| + |
| +int RendererAudioOutputStreamFactoryContextImpl::GetRenderProcessId() const { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + return render_process_id_; |
| +} |
| + |
| +std::string RendererAudioOutputStreamFactoryContextImpl::GetHMACForDeviceId( |
| + const url::Origin& origin, |
| + const std::string& raw_device_id) const { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + return MediaStreamManager::GetHMACForMediaDeviceID(salt_, origin, |
| + raw_device_id); |
| +} |
| + |
| +void RendererAudioOutputStreamFactoryContextImpl::RequestDeviceAuthorization( |
| + int render_frame_id, |
| + int session_id, |
| + const std::string& device_id, |
| + const url::Origin& security_origin, |
| + AuthorizationCompletedCallback cb) const { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + authorization_handler_.RequestDeviceAuthorization( |
| + render_frame_id, session_id, device_id, security_origin, std::move(cb)); |
| +} |
| + |
| +std::unique_ptr<media::AudioOutputDelegate> |
| +RendererAudioOutputStreamFactoryContextImpl::CreateDelegate( |
| + const std::string& unique_device_id, |
| + int render_frame_id, |
| + const media::AudioParameters& params, |
| + media::AudioOutputDelegate::EventHandler* handler) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + int stream_id = next_stream_id_++; |
| + MediaObserver* const media_observer = |
| + GetContentClient()->browser()->GetMediaObserver(); |
| + |
| + MediaInternals* const media_internals = MediaInternals::GetInstance(); |
| + std::unique_ptr<media::AudioLog> audio_log = media_internals->CreateAudioLog( |
| + media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER); |
| + media_internals->SetWebContentsTitleForAudioLogEntry( |
| + stream_id, render_process_id_, render_frame_id, audio_log.get()); |
| + |
| + return base::MakeUnique<AudioOutputDelegateImpl>( |
| + handler, audio_system_->GetAudioManager(), std::move(audio_log), |
|
o1ka
2017/03/29 08:13:48
Could we switch to passing AudioManager interface
Max Morin
2017/03/30 12:48:50
Done.
|
| + AudioMirroringManager::GetInstance(), media_observer, stream_id, |
| + render_frame_id, render_process_id_, params, unique_device_id); |
| +} |
| + |
| +} // namespace content |