1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56

media / audio / ios / audio_session_manager_ios.h [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_AUDIO_IOS_AUDIO_SESSION_MANAGER_IOS_H_
#define MEDIA_AUDIO_IOS_AUDIO_SESSION_MANAGER_IOS_H_

#include "base/no_destructor.h"
#include "media/audio/audio_device_name.h"

namespace media {

// This utility class serves as a bridge to convey iOS platform-specific details
// to the AudioManagerIOS. Internally, it relies on iOS platform-specific
// singleton classes such as AVAudioSession and AVAudioApplication.
class AudioSessionManagerIOS {
 public:
  static AudioSessionManagerIOS& GetInstance();

  AudioSessionManagerIOS(const AudioSessionManagerIOS&) = delete;
  AudioSessionManagerIOS& operator=(const AudioSessionManagerIOS&) = delete;

  // Activate and Deactivate AVAudioSession.
  void SetActive(bool active);

  // Methods to support AudioManagerIOS
  bool HasAudioHardware(bool is_input);
  void GetAudioDeviceInfo(bool is_input, media::AudioDeviceNames* device_names);
  std::string GetDefaultOutputDeviceID();
  std::string GetDefaultInputDeviceID();

  // Hardware information
  double HardwareSampleRate();
  double HardwareIOBufferDuration();
  double HardwareLatency(bool is_input);
  long GetDeviceChannels(bool is_input);

  // Gain
  float GetInputGain();
  bool SetInputGain(float volume);
  bool IsInputMuted();
  bool IsInputGainSettable();

 private:
  friend base::NoDestructor<AudioSessionManagerIOS>;

  AudioSessionManagerIOS();
  ~AudioSessionManagerIOS() = default;

  void GetAudioInputDeviceInfo(media::AudioDeviceNames* device_names);
  void GetAudioOutputDeviceInfo(media::AudioDeviceNames* device_names);
};

}  // namespace media

#endif  // MEDIA_AUDIO_IOS_AUDIO_SESSION_MANAGER_IOS_H_