audio_manager_chromeos.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright 2020 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. #ifndef MEDIA_AUDIO_CRAS_AUDIO_MANAGER_CHROMEOS_H_
  5. #define MEDIA_AUDIO_CRAS_AUDIO_MANAGER_CHROMEOS_H_
  6. #include <cras_types.h>
  7. #include <memory>
  8. #include <string>
  9. #include <vector>
  10. #include "base/compiler_specific.h"
  11. #include "base/memory/ref_counted.h"
  12. #include "chromeos/ash/components/audio/audio_device.h"
  13. #include "chromeos/ash/components/audio/cras_audio_handler.h"
  14. #include "media/audio/audio_manager_base.h"
  15. #include "media/audio/cras/audio_manager_cras_base.h"
  16. namespace media {
  17. class MEDIA_EXPORT AudioManagerChromeOS : public AudioManagerCrasBase {
  18. public:
  19. AudioManagerChromeOS(std::unique_ptr<AudioThread> audio_thread,
  20. AudioLogFactory* audio_log_factory);
  21. AudioManagerChromeOS(const AudioManagerChromeOS&) = delete;
  22. AudioManagerChromeOS& operator=(const AudioManagerChromeOS&) = delete;
  23. ~AudioManagerChromeOS() override;
  24. // AudioManager implementation.
  25. bool HasAudioOutputDevices() override;
  26. bool HasAudioInputDevices() override;
  27. void GetAudioInputDeviceNames(AudioDeviceNames* device_names) override;
  28. void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override;
  29. AudioParameters GetInputStreamParameters(
  30. const std::string& device_id) override;
  31. std::string GetAssociatedOutputDeviceID(
  32. const std::string& input_device_id) override;
  33. std::string GetDefaultInputDeviceID() override;
  34. std::string GetDefaultOutputDeviceID() override;
  35. std::string GetGroupIDOutput(const std::string& output_device_id) override;
  36. std::string GetGroupIDInput(const std::string& input_device_id) override;
  37. bool Shutdown() override;
  38. // AudioManagerCrasBase implementation.
  39. bool IsDefault(const std::string& device_id, bool is_input) override;
  40. enum CRAS_CLIENT_TYPE GetClientType() override;
  41. // Stores information about the system audio processing effects and
  42. // properties that are provided by the system audio processing module (APM).
  43. struct SystemAudioProcessingInfo {
  44. bool aec_supported = false;
  45. int32_t aec_group_id = ash::CrasAudioHandler::kSystemAecGroupIdNotAvailable;
  46. bool ns_supported = false;
  47. bool agc_supported = false;
  48. };
  49. // Produces AudioParameters for the system, including audio processing
  50. // capabilities tailored for the system,
  51. static AudioParameters GetStreamParametersForSystem(
  52. int user_buffer_size,
  53. const AudioManagerChromeOS::SystemAudioProcessingInfo& system_apm_info);
  54. protected:
  55. AudioParameters GetPreferredOutputStreamParameters(
  56. const std::string& output_device_id,
  57. const AudioParameters& input_params) override;
  58. private:
  59. // Get default output buffer size for this board.
  60. int GetDefaultOutputBufferSizePerBoard();
  61. // Get any system APM effects that are supported for this board.
  62. SystemAudioProcessingInfo GetSystemApmEffectsSupportedPerBoard();
  63. void GetAudioDeviceNamesImpl(bool is_input, AudioDeviceNames* device_names);
  64. std::string GetHardwareDeviceFromDeviceId(const ash::AudioDeviceList& devices,
  65. bool is_input,
  66. const std::string& device_id);
  67. void GetAudioDevices(ash::AudioDeviceList* devices);
  68. void GetAudioDevicesOnMainThread(ash::AudioDeviceList* devices,
  69. base::WaitableEvent* event);
  70. uint64_t GetPrimaryActiveInputNode();
  71. uint64_t GetPrimaryActiveOutputNode();
  72. void GetPrimaryActiveInputNodeOnMainThread(uint64_t* active_input_node_id,
  73. base::WaitableEvent* event);
  74. void GetPrimaryActiveOutputNodeOnMainThread(uint64_t* active_output_node_id,
  75. base::WaitableEvent* event);
  76. void GetDefaultOutputBufferSizeOnMainThread(int32_t* buffer_size,
  77. base::WaitableEvent* event);
  78. void GetSystemApmEffectsSupportedOnMainThread(
  79. SystemAudioProcessingInfo* system_apm_info,
  80. base::WaitableEvent* event);
  81. void WaitEventOrShutdown(base::WaitableEvent* event);
  82. // Signaled if AudioManagerCras is shutting down.
  83. base::WaitableEvent on_shutdown_;
  84. // Task runner of browser main thread. CrasAudioHandler should be only
  85. // accessed on this thread.
  86. scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
  87. // For posting tasks from audio thread to |main_task_runner_|.
  88. base::WeakPtr<AudioManagerChromeOS> weak_this_;
  89. base::WeakPtrFactory<AudioManagerChromeOS> weak_ptr_factory_;
  90. };
  91. } // namespace media
  92. #endif // MEDIA_AUDIO_CRAS_AUDIO_MANAGER_CHROMEOS_H_