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/renderer/media/audio_device_factory.h" | 5 #include "content/renderer/media/audio_device_factory.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/common/content_constants_internal.h" | 10 #include "content/common/content_constants_internal.h" |
11 #include "content/renderer/media/audio_input_message_filter.h" | 11 #include "content/renderer/media/audio_input_message_filter.h" |
12 #include "content/renderer/media/audio_message_filter.h" | 12 #include "content/renderer/media/audio_message_filter.h" |
13 #include "content/renderer/media/audio_renderer_mixer_manager.h" | 13 #include "content/renderer/media/audio_renderer_mixer_manager.h" |
14 #include "content/renderer/render_thread_impl.h" | 14 #include "content/renderer/render_thread_impl.h" |
15 #include "media/audio/audio_input_device.h" | 15 #include "media/audio/audio_input_device.h" |
16 #include "media/audio/audio_output_device.h" | 16 #include "media/audio/audio_output_device.h" |
| 17 #include "media/base/audio_latency.h" |
17 #include "media/base/audio_renderer_mixer_input.h" | 18 #include "media/base/audio_renderer_mixer_input.h" |
18 #include "url/origin.h" | 19 #include "url/origin.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 // static | 23 // static |
23 AudioDeviceFactory* AudioDeviceFactory::factory_ = NULL; | 24 AudioDeviceFactory* AudioDeviceFactory::factory_ = NULL; |
24 | 25 |
25 namespace { | 26 namespace { |
26 const int64_t kMaxAuthorizationTimeoutMs = 4000; | 27 const int64_t kMaxAuthorizationTimeoutMs = 4000; |
27 | 28 |
| 29 media::AudioLatency::LatencyType GetSourceLatencyType( |
| 30 AudioDeviceFactory::SourceType source) { |
| 31 switch (source) { |
| 32 case AudioDeviceFactory::kSourceWebAudioInteractive: |
| 33 return media::AudioLatency::LATENCY_INTERACTIVE; |
| 34 case AudioDeviceFactory::kSourceNone: |
| 35 case AudioDeviceFactory::kSourceWebRtc: |
| 36 case AudioDeviceFactory::kSourceNonRtcAudioTrack: |
| 37 case AudioDeviceFactory::kSourceWebAudioBalanced: |
| 38 return media::AudioLatency::LATENCY_RTC; |
| 39 case AudioDeviceFactory::kSourceMediaElement: |
| 40 case AudioDeviceFactory::kSourceWebAudioPlayback: |
| 41 return media::AudioLatency::LATENCY_PLAYBACK; |
| 42 case AudioDeviceFactory::kSourceWebAudioExact: |
| 43 return media::AudioLatency::LATENCY_EXACT_MS; |
| 44 } |
| 45 NOTREACHED(); |
| 46 return media::AudioLatency::LATENCY_INTERACTIVE; |
| 47 } |
| 48 |
28 scoped_refptr<media::AudioOutputDevice> NewOutputDevice( | 49 scoped_refptr<media::AudioOutputDevice> NewOutputDevice( |
29 int render_frame_id, | 50 int render_frame_id, |
30 int session_id, | 51 int session_id, |
31 const std::string& device_id, | 52 const std::string& device_id, |
32 const url::Origin& security_origin) { | 53 const url::Origin& security_origin) { |
33 AudioMessageFilter* const filter = AudioMessageFilter::Get(); | 54 AudioMessageFilter* const filter = AudioMessageFilter::Get(); |
34 scoped_refptr<media::AudioOutputDevice> device(new media::AudioOutputDevice( | 55 scoped_refptr<media::AudioOutputDevice> device(new media::AudioOutputDevice( |
35 filter->CreateAudioOutputIPC(render_frame_id), filter->io_task_runner(), | 56 filter->CreateAudioOutputIPC(render_frame_id), filter->io_task_runner(), |
36 session_id, device_id, security_origin, | 57 session_id, device_id, security_origin, |
37 // Set authorization request timeout at 80% of renderer hung timeout, but | 58 // Set authorization request timeout at 80% of renderer hung timeout, but |
38 // no more than kMaxAuthorizationTimeout. | 59 // no more than kMaxAuthorizationTimeout. |
39 base::TimeDelta::FromMilliseconds(std::min(kHungRendererDelayMs * 8 / 10, | 60 base::TimeDelta::FromMilliseconds(std::min(kHungRendererDelayMs * 8 / 10, |
40 kMaxAuthorizationTimeoutMs)))); | 61 kMaxAuthorizationTimeoutMs)))); |
41 device->RequestDeviceAuthorization(); | 62 device->RequestDeviceAuthorization(); |
42 return device; | 63 return device; |
43 } | 64 } |
44 | 65 |
45 // This is where we decide which audio will go to mixers and which one to | 66 // This is where we decide which audio will go to mixers and which one to |
46 // AudioOutpuDevice directly. | 67 // AudioOutpuDevice directly. |
47 bool IsMixable(AudioDeviceFactory::SourceType source_type) { | 68 bool IsMixable(AudioDeviceFactory::SourceType source_type) { |
48 if (source_type == AudioDeviceFactory::kSourceMediaElement) | 69 if (source_type == AudioDeviceFactory::kSourceMediaElement) |
49 return true; // Must ALWAYS go through mixer. | 70 return true; // Must ALWAYS go through mixer. |
50 | 71 |
51 // TODO(olka): make a decision for the rest of the sources basing on OS | 72 // TODO(olka): make a decision for the rest of the sources basing on OS |
52 // type and configuration parameters. | 73 // type and configuration parameters. |
53 return false; | 74 return false; |
54 } | 75 } |
55 | 76 |
56 scoped_refptr<media::SwitchableAudioRendererSink> NewMixableSink( | 77 scoped_refptr<media::SwitchableAudioRendererSink> NewMixableSink( |
| 78 AudioDeviceFactory::SourceType source_type, |
57 int render_frame_id, | 79 int render_frame_id, |
58 int session_id, | 80 int session_id, |
59 const std::string& device_id, | 81 const std::string& device_id, |
60 const url::Origin& security_origin) { | 82 const url::Origin& security_origin) { |
61 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 83 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
62 return scoped_refptr<media::AudioRendererMixerInput>( | 84 return scoped_refptr<media::AudioRendererMixerInput>( |
63 render_thread->GetAudioRendererMixerManager()->CreateInput( | 85 render_thread->GetAudioRendererMixerManager()->CreateInput( |
64 render_frame_id, session_id, device_id, security_origin)); | 86 render_frame_id, session_id, device_id, security_origin, |
| 87 GetSourceLatencyType(source_type))); |
65 } | 88 } |
66 | 89 |
67 } // namespace | 90 } // namespace |
68 | 91 |
69 scoped_refptr<media::AudioRendererSink> | 92 scoped_refptr<media::AudioRendererSink> |
70 AudioDeviceFactory::NewAudioRendererMixerSink( | 93 AudioDeviceFactory::NewAudioRendererMixerSink( |
71 int render_frame_id, | 94 int render_frame_id, |
72 int session_id, | 95 int session_id, |
73 const std::string& device_id, | 96 const std::string& device_id, |
74 const url::Origin& security_origin) { | 97 const url::Origin& security_origin) { |
(...skipping 11 matching lines...) Expand all Loading... |
86 if (factory_) { | 109 if (factory_) { |
87 scoped_refptr<media::AudioRendererSink> device = | 110 scoped_refptr<media::AudioRendererSink> device = |
88 factory_->CreateAudioRendererSink(source_type, render_frame_id, | 111 factory_->CreateAudioRendererSink(source_type, render_frame_id, |
89 session_id, device_id, | 112 session_id, device_id, |
90 security_origin); | 113 security_origin); |
91 if (device) | 114 if (device) |
92 return device; | 115 return device; |
93 } | 116 } |
94 | 117 |
95 if (IsMixable(source_type)) | 118 if (IsMixable(source_type)) |
96 return NewMixableSink(render_frame_id, session_id, device_id, | 119 return NewMixableSink(source_type, render_frame_id, session_id, device_id, |
97 security_origin); | 120 security_origin); |
98 | 121 |
99 return NewFinalAudioRendererSink(render_frame_id, session_id, device_id, | 122 return NewFinalAudioRendererSink(render_frame_id, session_id, device_id, |
100 security_origin); | 123 security_origin); |
101 } | 124 } |
102 | 125 |
103 // static | 126 // static |
104 scoped_refptr<media::SwitchableAudioRendererSink> | 127 scoped_refptr<media::SwitchableAudioRendererSink> |
105 AudioDeviceFactory::NewSwitchableAudioRendererSink( | 128 AudioDeviceFactory::NewSwitchableAudioRendererSink( |
106 SourceType source_type, | 129 SourceType source_type, |
107 int render_frame_id, | 130 int render_frame_id, |
108 int session_id, | 131 int session_id, |
109 const std::string& device_id, | 132 const std::string& device_id, |
110 const url::Origin& security_origin) { | 133 const url::Origin& security_origin) { |
111 if (factory_) { | 134 if (factory_) { |
112 scoped_refptr<media::SwitchableAudioRendererSink> sink = | 135 scoped_refptr<media::SwitchableAudioRendererSink> sink = |
113 factory_->CreateSwitchableAudioRendererSink(source_type, | 136 factory_->CreateSwitchableAudioRendererSink(source_type, |
114 render_frame_id, session_id, | 137 render_frame_id, session_id, |
115 device_id, security_origin); | 138 device_id, security_origin); |
116 if (sink) | 139 if (sink) |
117 return sink; | 140 return sink; |
118 } | 141 } |
119 | 142 |
120 if (IsMixable(source_type)) | 143 if (IsMixable(source_type)) |
121 return NewMixableSink(render_frame_id, session_id, device_id, | 144 return NewMixableSink(source_type, render_frame_id, session_id, device_id, |
122 security_origin); | 145 security_origin); |
123 | 146 |
124 // AudioOutputDevice is not RestartableAudioRendererSink, so we can't return | 147 // AudioOutputDevice is not RestartableAudioRendererSink, so we can't return |
125 // anything for those who wants to create an unmixable sink. | 148 // anything for those who wants to create an unmixable sink. |
126 NOTIMPLEMENTED(); | 149 NOTIMPLEMENTED(); |
127 return nullptr; | 150 return nullptr; |
128 } | 151 } |
129 | 152 |
130 // static | 153 // static |
131 scoped_refptr<media::AudioCapturerSource> | 154 scoped_refptr<media::AudioCapturerSource> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 device_id, security_origin); | 200 device_id, security_origin); |
178 if (sink) | 201 if (sink) |
179 return sink; | 202 return sink; |
180 } | 203 } |
181 | 204 |
182 return NewOutputDevice(render_frame_id, session_id, device_id, | 205 return NewOutputDevice(render_frame_id, session_id, device_id, |
183 security_origin); | 206 security_origin); |
184 } | 207 } |
185 | 208 |
186 } // namespace content | 209 } // namespace content |
OLD | NEW |