audio_manager_linux.cc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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
  3. // found in the LICENSE file.
  4. #include <memory>
  5. #include "base/command_line.h"
  6. #include "base/logging.h"
  7. #include "base/metrics/histogram_macros.h"
  8. #include "build/chromeos_buildflags.h"
  9. #include "media/audio/fake_audio_manager.h"
  10. #include "media/base/media_switches.h"
  11. #if defined(USE_ALSA)
  12. #include "media/audio/alsa/audio_manager_alsa.h"
  13. #endif
  14. #if defined(USE_CRAS) && BUILDFLAG(IS_CHROMEOS_ASH)
  15. #include "media/audio/cras/audio_manager_chromeos.h"
  16. #elif defined(USE_CRAS)
  17. #include "media/audio/cras/audio_manager_cras.h"
  18. #endif
  19. #if defined(USE_PULSEAUDIO)
  20. #include "media/audio/pulse/audio_manager_pulse.h"
  21. #include "media/audio/pulse/pulse_util.h"
  22. #endif
  23. namespace media {
  24. std::unique_ptr<media::AudioManager> CreateAudioManager(
  25. std::unique_ptr<AudioThread> audio_thread,
  26. AudioLogFactory* audio_log_factory) {
  27. // For testing allow audio output to be disabled.
  28. if (base::CommandLine::ForCurrentProcess()->HasSwitch(
  29. switches::kDisableAudioOutput)) {
  30. return std::make_unique<FakeAudioManager>(std::move(audio_thread),
  31. audio_log_factory);
  32. }
  33. #if defined(USE_CRAS)
  34. if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseCras)) {
  35. #if BUILDFLAG(IS_CHROMEOS_ASH)
  36. return std::make_unique<AudioManagerChromeOS>(std::move(audio_thread),
  37. audio_log_factory);
  38. #else
  39. return std::make_unique<AudioManagerCras>(std::move(audio_thread),
  40. audio_log_factory);
  41. #endif
  42. }
  43. #endif // defined(USE_CRAS)
  44. #if defined(USE_PULSEAUDIO)
  45. pa_threaded_mainloop* pa_mainloop = nullptr;
  46. pa_context* pa_context = nullptr;
  47. if (pulse::InitPulse(&pa_mainloop, &pa_context)) {
  48. return std::make_unique<AudioManagerPulse>(
  49. std::move(audio_thread), audio_log_factory, pa_mainloop, pa_context);
  50. }
  51. LOG(WARNING) << "Falling back to ALSA for audio output. PulseAudio is not "
  52. "available or could not be initialized.";
  53. #endif
  54. #if defined(USE_ALSA)
  55. return std::make_unique<AudioManagerAlsa>(std::move(audio_thread),
  56. audio_log_factory);
  57. #else
  58. return std::make_unique<FakeAudioManager>(std::move(audio_thread),
  59. audio_log_factory);
  60. #endif
  61. }
  62. } // namespace media