Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: content/browser/renderer_host/media/audio_output_service_context_impl.cc

Issue 2319493002: Add mojo interface for audio rendering. (Closed)
Patch Set: ++docs Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/media/audio_output_service_context_impl. h"
6
7 #include <algorithm>
8 #include <memory>
9 #include <utility>
10
11 #include "base/memory/ptr_util.h"
12 #include "content/browser/media/capture/audio_mirroring_manager.h"
13 #include "content/browser/media/media_internals.h"
14 #include "content/browser/renderer_host/media/audio_output_delegate_impl.h"
15 #include "content/browser/renderer_host/media/render_frame_audio_output_service. h"
16 #include "content/common/media/audio_output.mojom.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/content_browser_client.h"
19
20 namespace content {
21
22 AudioOutputServiceContextImpl::AudioOutputServiceContextImpl(
23 int render_process_id,
24 media::AudioManager* audio_manager,
25 MediaStreamManager* media_stream_manager,
26 const std::string& salt)
27 : render_process_id_(render_process_id),
28 audio_manager_(audio_manager),
29 media_stream_manager_(media_stream_manager),
30 salt_(salt),
31 authorization_handler_(audio_manager_,
32 media_stream_manager_,
33 render_process_id_,
34 salt_),
35 services_() {}
36
37 AudioOutputServiceContextImpl::~AudioOutputServiceContextImpl() {
38 DCHECK_CURRENTLY_ON(BrowserThread::IO);
39 }
40
41 void AudioOutputServiceContextImpl::CreateService(
42 int frame_host_id,
43 mojo::InterfaceRequest<mojom::RendererAudioOutputService> request) {
44 DCHECK_CURRENTLY_ON(BrowserThread::IO);
45
46 services_.push_back(base::MakeUnique<RenderFrameAudioOutputService>(
47 this, frame_host_id, std::move(request)));
48 }
49
50 int AudioOutputServiceContextImpl::GetRenderProcessId() const {
51 return render_process_id_;
52 }
53
54 const std::string& AudioOutputServiceContextImpl::GetSalt() const {
55 return salt_;
56 }
57
58 void AudioOutputServiceContextImpl::RequestDeviceAuthorization(
59 int render_frame_id,
60 int session_id,
61 const std::string& device_id,
62 const url::Origin& security_origin,
63 AuthorizationCompletedCallback cb) const {
64 authorization_handler_.RequestDeviceAuthorization(
65 render_frame_id, session_id, device_id, security_origin, std::move(cb));
66 }
67
68 std::unique_ptr<AudioOutputDelegate>
69 AudioOutputServiceContextImpl::CreateDelegate(
70 const std::string& unique_device_id,
71 int render_frame_id,
72 AudioOutputDelegate::EventHandler* handler,
73 const media::AudioParameters& params) {
74 DCHECK_CURRENTLY_ON(BrowserThread::IO);
75 int stream_id = next_stream_id_++;
76 MediaObserver* const media_observer =
77 GetContentClient()->browser()->GetMediaObserver();
78
79 MediaInternals* const media_internals = MediaInternals::GetInstance();
80 std::unique_ptr<media::AudioLog> audio_log = media_internals->CreateAudioLog(
81 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER);
82 media_internals->SetWebContentsTitleForAudioLogEntry(
83 stream_id, render_process_id_, render_frame_id, audio_log.get());
84
85 return base::WrapUnique<AudioOutputDelegate>(new AudioOutputDelegateImpl(
86 handler, audio_manager_, std::move(audio_log),
87 AudioMirroringManager::GetInstance(), media_observer, stream_id,
88 render_frame_id, render_process_id_, params, unique_device_id));
89 }
90
91 void AudioOutputServiceContextImpl::OnServiceFinished(
92 mojom::RendererAudioOutputService* service) {
93 auto it = std::find_if(
94 services_.begin(), services_.end(),
95 [service](
96 const std::unique_ptr<mojom::RendererAudioOutputService>& other) {
97 return other.get() == service;
98 });
99
100 // It is possible that the service is already gone, in case destruction
101 // triggered a connection error.
102 if (it != services_.end()) {
103 std::swap(*it, services_.back());
104 services_.pop_back();
105 }
106 }
107
108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698