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 "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "content/common/content_constants_internal.h" | 12 #include "content/common/content_constants_internal.h" |
13 #include "content/renderer/media/audio_input_message_filter.h" | 13 #include "content/renderer/media/audio_input_message_filter.h" |
14 #include "content/renderer/media/audio_message_filter.h" | 14 #include "content/renderer/media/audio_output_ipc_factory.h" |
15 #include "content/renderer/media/audio_renderer_mixer_manager.h" | 15 #include "content/renderer/media/audio_renderer_mixer_manager.h" |
16 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
17 #include "media/audio/audio_input_device.h" | 17 #include "media/audio/audio_input_device.h" |
18 #include "media/audio/audio_output_device.h" | 18 #include "media/audio/audio_output_device.h" |
19 #include "media/base/audio_renderer_mixer_input.h" | 19 #include "media/base/audio_renderer_mixer_input.h" |
20 #include "media/base/media_switches.h" | 20 #include "media/base/media_switches.h" |
21 #include "url/origin.h" | 21 #include "url/origin.h" |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 // static | 25 // static |
26 AudioDeviceFactory* AudioDeviceFactory::factory_ = NULL; | 26 AudioDeviceFactory* AudioDeviceFactory::factory_ = NULL; |
27 | 27 |
28 namespace { | 28 namespace { |
29 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
30 // Due to driver deadlock issues on Windows (http://crbug/422522) there is a | 30 // Due to driver deadlock issues on Windows (http://crbug/422522) there is a |
31 // chance device authorization response is never received from the browser side. | 31 // chance device authorization response is never received from the browser side. |
32 // In this case we will time out, to avoid renderer hang forever waiting for | 32 // In this case we will time out, to avoid renderer hang forever waiting for |
33 // device authorization (http://crbug/615589). This will result in "no audio". | 33 // device authorization (http://crbug/615589). This will result in "no audio". |
34 const int64_t kMaxAuthorizationTimeoutMs = 1000; | 34 const int64_t kMaxAuthorizationTimeoutMs = 1000; |
35 #else | 35 #else |
36 const int64_t kMaxAuthorizationTimeoutMs = 0; // No timeout. | 36 const int64_t kMaxAuthorizationTimeoutMs = 0; // No timeout. |
37 #endif // defined(OS_WIN) | 37 #endif // defined(OS_WIN) |
38 | 38 |
39 scoped_refptr<media::AudioOutputDevice> NewOutputDevice( | 39 scoped_refptr<media::AudioOutputDevice> NewOutputDevice( |
40 int render_frame_id, | 40 int render_frame_id, |
41 int session_id, | 41 int session_id, |
42 const std::string& device_id, | 42 const std::string& device_id, |
43 const url::Origin& security_origin) { | 43 const url::Origin& security_origin) { |
44 AudioMessageFilter* const filter = AudioMessageFilter::Get(); | 44 const scoped_refptr<AudioOutputIPCFactory> factory = |
| 45 AudioOutputIPCFactory::Get(); |
45 scoped_refptr<media::AudioOutputDevice> device(new media::AudioOutputDevice( | 46 scoped_refptr<media::AudioOutputDevice> device(new media::AudioOutputDevice( |
46 filter->CreateAudioOutputIPC(render_frame_id), filter->io_task_runner(), | 47 factory->CreateAudioOutputIPC(render_frame_id), factory->io_task_runner(), |
47 session_id, device_id, security_origin, | 48 session_id, device_id, security_origin, |
48 // Set authorization request timeout at 80% of renderer hung timeout, but | 49 // Set authorization request timeout at 80% of renderer hung timeout, but |
49 // no more than kMaxAuthorizationTimeout. | 50 // no more than kMaxAuthorizationTimeout. |
50 base::TimeDelta::FromMilliseconds(std::min(kHungRendererDelayMs * 8 / 10, | 51 base::TimeDelta::FromMilliseconds(std::min(kHungRendererDelayMs * 8 / 10, |
51 kMaxAuthorizationTimeoutMs)))); | 52 kMaxAuthorizationTimeoutMs)))); |
52 device->RequestDeviceAuthorization(); | 53 device->RequestDeviceAuthorization(); |
53 return device; | 54 return device; |
54 } | 55 } |
55 | 56 |
56 // This is where we decide which audio will go to mixers and which one to | 57 // This is where we decide which audio will go to mixers and which one to |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 device_id, security_origin); | 212 device_id, security_origin); |
212 if (sink) | 213 if (sink) |
213 return sink; | 214 return sink; |
214 } | 215 } |
215 | 216 |
216 return NewOutputDevice(render_frame_id, session_id, device_id, | 217 return NewOutputDevice(render_frame_id, session_id, device_id, |
217 security_origin); | 218 security_origin); |
218 } | 219 } |
219 | 220 |
220 } // namespace content | 221 } // namespace content |
OLD | NEW |