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

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: rebase 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"
20 #include "media/audio/pulse/pulse_util.h"
19 #endif 21 #endif
20 22
21 namespace media { 23 namespace media {
22 24
23 enum LinuxAudioIO { 25 enum LinuxAudioIO {
24 kPulse, 26 kPulse,
25 kAlsa, 27 kAlsa,
26 kCras, 28 kCras,
27 kAudioIOMax = kCras // Must always be equal to largest logged entry. 29 kAudioIOMax = kCras // Must always be equal to largest logged entry.
28 }; 30 };
29 31
30 ScopedAudioManagerPtr CreateAudioManager( 32 std::unique_ptr<media::AudioManager> CreateAudioManager(
31 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 33 std::unique_ptr<AudioThread> audio_thread,
32 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
33 AudioLogFactory* audio_log_factory) { 34 AudioLogFactory* audio_log_factory) {
34 #if defined(USE_CRAS) 35 #if defined(USE_CRAS)
35 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseCras)) { 36 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseCras)) {
36 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kCras, kAudioIOMax + 1); 37 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kCras, kAudioIOMax + 1);
37 return ScopedAudioManagerPtr( 38 return base::MakeUnique<AudioManagerCras>(std::move(audio_thread),
38 new AudioManagerCras(std::move(task_runner), 39 audio_log_factory);
39 std::move(worker_task_runner), audio_log_factory));
40 } 40 }
41 #endif 41 #endif
42 42
43 #if defined(USE_PULSEAUDIO) 43 #if defined(USE_PULSEAUDIO)
44 // Do not move task runners when creating AudioManagerPulse. 44 pa_threaded_mainloop* pa_mainloop = nullptr;
45 // If the creation fails, we need to use the task runners to create other 45 pa_context* pa_context = nullptr;
46 // AudioManager implementations. 46 if (pulse::InitPulse(&pa_mainloop, &pa_context)) {
47 std::unique_ptr<AudioManagerPulse, AudioManagerDeleter> manager(
48 new AudioManagerPulse(task_runner, worker_task_runner,
49 audio_log_factory));
50 if (manager->Init()) {
51 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kPulse, kAudioIOMax + 1); 47 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kPulse, kAudioIOMax + 1);
52 return std::move(manager); 48 return base::MakeUnique<AudioManagerPulse>(
49 std::move(audio_thread), audio_log_factory, pa_mainloop, pa_context);
53 } 50 }
54 DVLOG(1) << "PulseAudio is not available on the OS"; 51 DVLOG(1) << "PulseAudio is not available on the OS";
55 #endif 52 #endif
56 53
57 #if defined(USE_ALSA) 54 #if defined(USE_ALSA)
58 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kAlsa, kAudioIOMax + 1); 55 UMA_HISTOGRAM_ENUMERATION("Media.LinuxAudioIO", kAlsa, kAudioIOMax + 1);
59 return ScopedAudioManagerPtr( 56 return base::MakeUnique<AudioManagerAlsa>(std::move(audio_thread),
60 new AudioManagerAlsa(std::move(task_runner), 57 audio_log_factory);
61 std::move(worker_task_runner), audio_log_factory));
62 #else 58 #else
63 return ScopedAudioManagerPtr( 59 return base::MakeUnique<FakeAudioManager>(std::move(audio_thread),
64 new FakeAudioManager(std::move(task_runner), 60 audio_log_factory);
65 std::move(worker_task_runner), audio_log_factory));
66 #endif 61 #endif
67 } 62 }
68 63
69 } // namespace media 64 } // 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