| Index: content/browser/renderer_host/media/audio_output_service_context_impl.cc
|
| diff --git a/content/browser/renderer_host/media/audio_output_service_context_impl.cc b/content/browser/renderer_host/media/audio_output_service_context_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..450b7eeac7ea3e5b3787f4442b07aacdeb6895a9
|
| --- /dev/null
|
| +++ b/content/browser/renderer_host/media/audio_output_service_context_impl.cc
|
| @@ -0,0 +1,108 @@
|
| +// 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/audio_output_service_context_impl.h"
|
| +
|
| +#include <algorithm>
|
| +#include <memory>
|
| +#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/render_frame_audio_output_service.h"
|
| +#include "content/common/media/audio_output.mojom.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/content_browser_client.h"
|
| +
|
| +namespace content {
|
| +
|
| +AudioOutputServiceContextImpl::AudioOutputServiceContextImpl(
|
| + int render_process_id,
|
| + media::AudioManager* audio_manager,
|
| + MediaStreamManager* media_stream_manager,
|
| + const std::string& salt)
|
| + : render_process_id_(render_process_id),
|
| + audio_manager_(audio_manager),
|
| + media_stream_manager_(media_stream_manager),
|
| + salt_(salt),
|
| + authorization_handler_(audio_manager_,
|
| + media_stream_manager_,
|
| + render_process_id_,
|
| + salt_),
|
| + services_() {}
|
| +
|
| +AudioOutputServiceContextImpl::~AudioOutputServiceContextImpl() {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +}
|
| +
|
| +void AudioOutputServiceContextImpl::CreateService(
|
| + int frame_host_id,
|
| + mojo::InterfaceRequest<mojom::RendererAudioOutputService> request) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +
|
| + services_.push_back(base::MakeUnique<RenderFrameAudioOutputService>(
|
| + this, frame_host_id, std::move(request)));
|
| +}
|
| +
|
| +int AudioOutputServiceContextImpl::GetRenderProcessId() const {
|
| + return render_process_id_;
|
| +}
|
| +
|
| +const std::string& AudioOutputServiceContextImpl::GetSalt() const {
|
| + return salt_;
|
| +}
|
| +
|
| +void AudioOutputServiceContextImpl::RequestDeviceAuthorization(
|
| + int render_frame_id,
|
| + int session_id,
|
| + const std::string& device_id,
|
| + const url::Origin& security_origin,
|
| + AuthorizationCompletedCallback cb) const {
|
| + authorization_handler_.RequestDeviceAuthorization(
|
| + render_frame_id, session_id, device_id, security_origin, std::move(cb));
|
| +}
|
| +
|
| +std::unique_ptr<AudioOutputDelegate>
|
| +AudioOutputServiceContextImpl::CreateDelegate(
|
| + const std::string& unique_device_id,
|
| + int render_frame_id,
|
| + AudioOutputDelegate::EventHandler* handler,
|
| + const media::AudioParameters& params) {
|
| + 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::WrapUnique<AudioOutputDelegate>(new AudioOutputDelegateImpl(
|
| + handler, audio_manager_, std::move(audio_log),
|
| + AudioMirroringManager::GetInstance(), media_observer, stream_id,
|
| + render_frame_id, render_process_id_, params, unique_device_id));
|
| +}
|
| +
|
| +void AudioOutputServiceContextImpl::OnServiceFinished(
|
| + mojom::RendererAudioOutputService* service) {
|
| + auto it = std::find_if(
|
| + services_.begin(), services_.end(),
|
| + [service](
|
| + const std::unique_ptr<mojom::RendererAudioOutputService>& other) {
|
| + return other.get() == service;
|
| + });
|
| +
|
| + // It is possible that the service is already gone, in case destruction
|
| + // triggered a connection error.
|
| + if (it != services_.end()) {
|
| + std::swap(*it, services_.back());
|
| + services_.pop_back();
|
| + }
|
| +}
|
| +
|
| +} // namespace content
|
|
|