OLD | NEW |
| (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/renderer_audio_output_stream_facto
ry_context_impl.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/memory/ptr_util.h" | |
10 #include "content/browser/media/capture/audio_mirroring_manager.h" | |
11 #include "content/browser/media/media_internals.h" | |
12 #include "content/browser/renderer_host/media/audio_output_delegate_impl.h" | |
13 #include "content/browser/renderer_host/media/media_stream_manager.h" | |
14 #include "content/browser/renderer_host/media/render_frame_audio_output_stream_f
actory.h" | |
15 #include "content/common/media/renderer_audio_output_stream_factory.mojom.h" | |
16 #include "content/public/browser/browser_thread.h" | |
17 #include "content/public/browser/content_browser_client.h" | |
18 #include "media/audio/audio_system.h" | |
19 | |
20 namespace content { | |
21 | |
22 RendererAudioOutputStreamFactoryContextImpl:: | |
23 RendererAudioOutputStreamFactoryContextImpl( | |
24 int render_process_id, | |
25 media::AudioSystem* audio_system, | |
26 media::AudioManager* audio_manager, | |
27 MediaStreamManager* media_stream_manager, | |
28 const std::string& salt) | |
29 : salt_(salt), | |
30 audio_system_(audio_system), | |
31 audio_manager_(audio_manager), | |
32 media_stream_manager_(media_stream_manager), | |
33 authorization_handler_(audio_system_, | |
34 media_stream_manager_, | |
35 render_process_id, | |
36 salt_), | |
37 render_process_id_(render_process_id) {} | |
38 | |
39 RendererAudioOutputStreamFactoryContextImpl:: | |
40 ~RendererAudioOutputStreamFactoryContextImpl() { | |
41 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
42 } | |
43 | |
44 void RendererAudioOutputStreamFactoryContextImpl::CreateFactory( | |
45 int frame_host_id, | |
46 mojo::InterfaceRequest<mojom::RendererAudioOutputStreamFactory> request) { | |
47 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
48 | |
49 factories_.AddBinding(base::MakeUnique<RenderFrameAudioOutputStreamFactory>( | |
50 frame_host_id, this), | |
51 std::move(request)); | |
52 } | |
53 | |
54 int RendererAudioOutputStreamFactoryContextImpl::GetRenderProcessId() const { | |
55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
56 return render_process_id_; | |
57 } | |
58 | |
59 std::string RendererAudioOutputStreamFactoryContextImpl::GetHMACForDeviceId( | |
60 const url::Origin& origin, | |
61 const std::string& raw_device_id) const { | |
62 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
63 return MediaStreamManager::GetHMACForMediaDeviceID(salt_, origin, | |
64 raw_device_id); | |
65 } | |
66 | |
67 void RendererAudioOutputStreamFactoryContextImpl::RequestDeviceAuthorization( | |
68 int render_frame_id, | |
69 int session_id, | |
70 const std::string& device_id, | |
71 const url::Origin& security_origin, | |
72 AuthorizationCompletedCallback cb) const { | |
73 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
74 authorization_handler_.RequestDeviceAuthorization( | |
75 render_frame_id, session_id, device_id, security_origin, std::move(cb)); | |
76 } | |
77 | |
78 std::unique_ptr<media::AudioOutputDelegate> | |
79 RendererAudioOutputStreamFactoryContextImpl::CreateDelegate( | |
80 const std::string& unique_device_id, | |
81 int render_frame_id, | |
82 const media::AudioParameters& params, | |
83 media::AudioOutputDelegate::EventHandler* handler) { | |
84 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
85 int stream_id = next_stream_id_++; | |
86 MediaObserver* const media_observer = | |
87 GetContentClient()->browser()->GetMediaObserver(); | |
88 | |
89 MediaInternals* const media_internals = MediaInternals::GetInstance(); | |
90 std::unique_ptr<media::AudioLog> audio_log = media_internals->CreateAudioLog( | |
91 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER); | |
92 media_internals->SetWebContentsTitleForAudioLogEntry( | |
93 stream_id, render_process_id_, render_frame_id, audio_log.get()); | |
94 | |
95 return base::MakeUnique<AudioOutputDelegateImpl>( | |
96 handler, audio_manager_, std::move(audio_log), | |
97 AudioMirroringManager::GetInstance(), media_observer, stream_id, | |
98 render_frame_id, render_process_id_, params, unique_device_id); | |
99 } | |
100 | |
101 } // namespace content | |
OLD | NEW |