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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/metrics/histogram.h" | 6 #include "base/metrics/histogram.h" |
7 #include "media/base/media_switches.h" | |
8 | |
7 #if defined(USE_ALSA) | 9 #if defined(USE_ALSA) |
8 #include "media/audio/alsa/audio_manager_alsa.h" | 10 #include "media/audio/alsa/audio_manager_alsa.h" |
9 #else | 11 #else |
10 #include "media/audio/fake_audio_manager.h" | 12 #include "media/audio/fake_audio_manager.h" |
11 #endif | 13 #endif |
12 #if defined(USE_CRAS) | 14 #if defined(USE_CRAS) |
13 #include "media/audio/cras/audio_manager_cras.h" | 15 #include "media/audio/cras/audio_manager_cras.h" |
14 #endif | 16 #endif |
15 #if defined(USE_PULSEAUDIO) | 17 #if defined(USE_PULSEAUDIO) |
16 #include "media/audio/pulse/audio_manager_pulse.h" | 18 #include "media/audio/pulse/audio_manager_pulse.h" |
17 #endif | 19 #endif |
18 #include "media/base/media_switches.h" | |
19 | 20 |
20 namespace media { | 21 namespace media { |
21 | 22 |
22 enum LinuxAudioIO { | 23 enum LinuxAudioIO { |
23 kPulse, | 24 kPulse, |
24 kAlsa, | 25 kAlsa, |
25 kCras, | 26 kCras, |
26 kAudioIOMax = kCras // Must always be equal to largest logged entry. | 27 kAudioIOMax = kCras // Must always be equal to largest logged entry. |
27 }; | 28 }; |
28 | 29 |
29 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { | 30 ScopedAudioManagerPtr CreateAudioManager( |
31 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
32 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | |
33 AudioLogFactory* audio_log_factory) { | |
30 #if defined(USE_CRAS) | 34 #if defined(USE_CRAS) |
31 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseCras)) { | 35 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseCras)) { |
32 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kCras, kAudioIOMax + 1); | 36 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kCras, kAudioIOMax + 1); |
33 return new AudioManagerCras(audio_log_factory); | 37 return ScopedAudioManagerPtr( |
38 new AudioManagerCras(std::move(task_runner), | |
39 std::move(worker_task_runner), audio_log_factory)); | |
34 } | 40 } |
35 #endif | 41 #endif |
36 | 42 |
37 #if defined(USE_PULSEAUDIO) | 43 #if defined(USE_PULSEAUDIO) |
38 AudioManager* manager = AudioManagerPulse::Create(audio_log_factory); | 44 // Do not move task runners when creating AudioManagerPulse. |
39 if (manager) { | 45 // If the creation fails, we need to use the task runners to create other |
46 // AudioManager implementations. | |
47 std::unique_ptr<AudioManagerPulse, AudioManagerDeleter> manager( | |
48 new AudioManagerPulse(task_runner, worker_task_runner, | |
49 audio_log_factory)); | |
50 if (manager->Init()) { | |
40 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kPulse, kAudioIOMax + 1); | 51 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kPulse, kAudioIOMax + 1); |
41 return manager; | 52 return std::move(manager); |
53 } else { | |
tommi (sloooow) - chröme
2016/04/13 07:31:51
nit: no need for this scope since there's an early
alokp
2016/04/17 16:55:19
Done.
| |
54 DVLOG(1) << "PulseAudio is not available on the OS"; | |
55 manager.reset(); | |
42 } | 56 } |
43 #endif | 57 #endif |
44 | 58 |
45 #if defined(USE_ALSA) | 59 #if defined(USE_ALSA) |
46 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kAlsa, kAudioIOMax + 1); | 60 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kAlsa, kAudioIOMax + 1); |
47 return new AudioManagerAlsa(audio_log_factory); | 61 return ScopedAudioManagerPtr( |
62 new AudioManagerAlsa(std::move(task_runner), | |
63 std::move(worker_task_runner), audio_log_factory)); | |
48 #else | 64 #else |
49 return new FakeAudioManager(audio_log_factory); | 65 return ScopedAudioManagerPtr( |
66 new FakeAudioManager(std::move(task_runner), | |
67 std::move(worker_task_runner), audio_log_factory)); | |
50 #endif | 68 #endif |
51 } | 69 } |
52 | 70 |
53 } // namespace media | 71 } // namespace media |
OLD | NEW |