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

Side by Side Diff: media/audio/linux/audio_manager_linux.cc

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: chromeos and android build Created 3 years, 7 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
« no previous file with comments | « media/audio/fake_audio_manager.cc ('k') | media/audio/mac/audio_auhal_mac_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/ptr_util.h"
6 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
7 #include "media/base/media_switches.h" 8 #include "media/base/media_switches.h"
8 9
9 #if defined(USE_ALSA) 10 #if defined(USE_ALSA)
10 #include "media/audio/alsa/audio_manager_alsa.h" 11 #include "media/audio/alsa/audio_manager_alsa.h"
11 #else 12 #else
12 #include "media/audio/fake_audio_manager.h" 13 #include "media/audio/fake_audio_manager.h"
13 #endif 14 #endif
14 #if defined(USE_CRAS) 15 #if defined(USE_CRAS)
15 #include "media/audio/cras/audio_manager_cras.h" 16 #include "media/audio/cras/audio_manager_cras.h"
16 #endif 17 #endif
17 #if defined(USE_PULSEAUDIO) 18 #if defined(USE_PULSEAUDIO)
18 #include "media/audio/pulse/audio_manager_pulse.h" 19 #include "media/audio/pulse/audio_manager_pulse.h"
19 #endif 20 #endif
20 21
21 namespace media { 22 namespace media {
22 23
23 enum LinuxAudioIO { 24 enum LinuxAudioIO {
24 kPulse, 25 kPulse,
25 kAlsa, 26 kAlsa,
26 kCras, 27 kCras,
27 kAudioIOMax = kCras // Must always be equal to largest logged entry. 28 kAudioIOMax = kCras // Must always be equal to largest logged entry.
28 }; 29 };
29 30
30 ScopedAudioManagerPtr CreateAudioManager( 31 std::unique_ptr<media::AudioManager> CreateAudioManager(
31 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 32 std::unique_ptr<AudioThread> audio_thread,
32 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
33 AudioLogFactory* audio_log_factory) { 33 AudioLogFactory* audio_log_factory) {
34 #if defined(USE_CRAS) 34 #if defined(USE_CRAS)
35 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseCras)) { 35 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseCras)) {
36 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kCras, kAudioIOMax + 1); 36 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kCras, kAudioIOMax + 1);
37 return ScopedAudioManagerPtr( 37 return base::MakeUnique<AudioManagerCras>(std::move(audio_thread),
38 new AudioManagerCras(std::move(task_runner), 38 audio_log_factory);
39 std::move(worker_task_runner), audio_log_factory));
40 } 39 }
41 #endif 40 #endif
42 41
43 #if defined(USE_PULSEAUDIO) 42 #if defined(USE_PULSEAUDIO)
44 // Do not move task runners when creating AudioManagerPulse. 43 // Do not move task runners when creating AudioManagerPulse.
45 // If the creation fails, we need to use the task runners to create other 44 // If the creation fails, we need to use the task runners to create other
46 // AudioManager implementations. 45 // AudioManager implementations.
47 std::unique_ptr<AudioManagerPulse, AudioManagerDeleter> manager( 46 // TODO(alokp): Fix fallback to alsa/fake path.
48 new AudioManagerPulse(task_runner, worker_task_runner, 47 auto manager = base::MakeUnique<AudioManagerPulse>(std::move(audio_thread),
alokp 2017/04/26 20:55:00 Dale: Is there an alternate way to check if pulsea
DaleCurtis 2017/04/26 20:56:35 No, but there's no reason we can't extract Init()
alokp 2017/04/26 21:02:50 Are you suggesting that the static Init return pa_
DaleCurtis 2017/04/26 21:07:09 Yup.
49 audio_log_factory)); 48 audio_log_factory);
50 if (manager->Init()) { 49 if (manager->Init()) {
51 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kPulse, kAudioIOMax + 1); 50 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kPulse, kAudioIOMax + 1);
52 return std::move(manager); 51 return manager;
53 } 52 }
54 DVLOG(1) << "PulseAudio is not available on the OS"; 53 DVLOG(1) << "PulseAudio is not available on the OS";
55 #endif 54 #endif
56 55
57 #if defined(USE_ALSA) 56 #if defined(USE_ALSA)
58 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kAlsa, kAudioIOMax + 1); 57 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kAlsa, kAudioIOMax + 1);
59 return ScopedAudioManagerPtr( 58 return base::MakeUnique<AudioManagerAlsa>(std::move(audio_thread),
60 new AudioManagerAlsa(std::move(task_runner), 59 audio_log_factory);
61 std::move(worker_task_runner), audio_log_factory));
62 #else 60 #else
63 return ScopedAudioManagerPtr( 61 return base::MakeUnique<FakeAudioManager>(std::move(audio_thread),
64 new FakeAudioManager(std::move(task_runner), 62 audio_log_factory);
65 std::move(worker_task_runner), audio_log_factory));
66 #endif 63 #endif
67 } 64 }
68 65
69 } // namespace media 66 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/fake_audio_manager.cc ('k') | media/audio/mac/audio_auhal_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698