tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

audio_device.h (7066B)


      1 /*
      2 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #ifndef API_AUDIO_AUDIO_DEVICE_H_
     12 #define API_AUDIO_AUDIO_DEVICE_H_
     13 
     14 #include <cstdint>
     15 #include <optional>
     16 
     17 #include "api/audio/audio_device_defines.h"
     18 #include "api/ref_count.h"
     19 
     20 namespace webrtc {
     21 
     22 class AudioDeviceModuleForTest;
     23 
     24 class AudioDeviceModule : public RefCountInterface {
     25 public:
     26  enum AudioLayer {
     27    kPlatformDefaultAudio = 0,
     28    kWindowsCoreAudio,
     29    kWindowsCoreAudio2,
     30    kLinuxAlsaAudio,
     31    kLinuxPulseAudio,
     32    kAndroidJavaAudio,
     33    kAndroidOpenSLESAudio,
     34    kAndroidJavaInputAndOpenSLESOutputAudio,
     35    kAndroidAAudioAudio,
     36    kAndroidJavaInputAndAAudioOutputAudio,
     37    kDummyAudio,
     38  };
     39 
     40  enum WindowsDeviceType {
     41    kDefaultCommunicationDevice = -1,
     42    kDefaultDevice = -2
     43  };
     44 
     45 // Only supported on iOS.
     46 #if defined(WEBRTC_IOS)
     47  enum MutedSpeechEvent { kMutedSpeechStarted, kMutedSpeechEnded };
     48  typedef void (^MutedSpeechEventHandler)(MutedSpeechEvent event);
     49 #endif  // WEBRTC_IOS
     50 
     51  struct Stats {
     52    // The fields below correspond to similarly-named fields in the WebRTC stats
     53    // spec. https://w3c.github.io/webrtc-stats/#playoutstats-dict*
     54    double synthesized_samples_duration_s = 0;
     55    uint64_t synthesized_samples_events = 0;
     56    double total_samples_duration_s = 0;
     57    double total_playout_delay_s = 0;
     58    uint64_t total_samples_count = 0;
     59  };
     60 
     61 public:
     62  // Retrieve the currently utilized audio layer
     63  virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const = 0;
     64 
     65  // Full-duplex transportation of PCM audio
     66  virtual int32_t RegisterAudioCallback(AudioTransport* audioCallback) = 0;
     67 
     68  // Main initialization and termination
     69  virtual int32_t Init() = 0;
     70  virtual int32_t Terminate() = 0;
     71  virtual bool Initialized() const = 0;
     72 
     73  // Device enumeration
     74  virtual int16_t PlayoutDevices() = 0;
     75  virtual int16_t RecordingDevices() = 0;
     76  virtual int32_t PlayoutDeviceName(uint16_t index,
     77                                    char name[kAdmMaxDeviceNameSize],
     78                                    char guid[kAdmMaxGuidSize]) = 0;
     79  virtual int32_t RecordingDeviceName(uint16_t index,
     80                                      char name[kAdmMaxDeviceNameSize],
     81                                      char guid[kAdmMaxGuidSize]) = 0;
     82 
     83  // Device selection
     84  virtual int32_t SetPlayoutDevice(uint16_t index) = 0;
     85  virtual int32_t SetPlayoutDevice(WindowsDeviceType device) = 0;
     86  virtual int32_t SetRecordingDevice(uint16_t index) = 0;
     87  virtual int32_t SetRecordingDevice(WindowsDeviceType device) = 0;
     88 
     89  // Audio transport initialization
     90  virtual int32_t PlayoutIsAvailable(bool* available) = 0;
     91  virtual int32_t InitPlayout() = 0;
     92  virtual bool PlayoutIsInitialized() const = 0;
     93  virtual int32_t RecordingIsAvailable(bool* available) = 0;
     94  virtual int32_t InitRecording() = 0;
     95  virtual bool RecordingIsInitialized() const = 0;
     96 
     97  // Audio transport control
     98  virtual int32_t StartPlayout() = 0;
     99  virtual int32_t StopPlayout() = 0;
    100  virtual bool Playing() const = 0;
    101  virtual int32_t StartRecording() = 0;
    102  virtual int32_t StopRecording() = 0;
    103  virtual bool Recording() const = 0;
    104 
    105  // Audio mixer initialization
    106  virtual int32_t InitSpeaker() = 0;
    107  virtual bool SpeakerIsInitialized() const = 0;
    108  virtual int32_t InitMicrophone() = 0;
    109  virtual bool MicrophoneIsInitialized() const = 0;
    110 
    111  // Speaker volume controls
    112  virtual int32_t SpeakerVolumeIsAvailable(bool* available) = 0;
    113  virtual int32_t SetSpeakerVolume(uint32_t volume) = 0;
    114  virtual int32_t SpeakerVolume(uint32_t* volume) const = 0;
    115  virtual int32_t MaxSpeakerVolume(uint32_t* maxVolume) const = 0;
    116  virtual int32_t MinSpeakerVolume(uint32_t* minVolume) const = 0;
    117 
    118  // Microphone volume controls
    119  virtual int32_t MicrophoneVolumeIsAvailable(bool* available) = 0;
    120  virtual int32_t SetMicrophoneVolume(uint32_t volume) = 0;
    121  virtual int32_t MicrophoneVolume(uint32_t* volume) const = 0;
    122  virtual int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const = 0;
    123  virtual int32_t MinMicrophoneVolume(uint32_t* minVolume) const = 0;
    124 
    125  // Speaker mute control
    126  virtual int32_t SpeakerMuteIsAvailable(bool* available) = 0;
    127  virtual int32_t SetSpeakerMute(bool enable) = 0;
    128  virtual int32_t SpeakerMute(bool* enabled) const = 0;
    129 
    130  // Microphone mute control
    131  virtual int32_t MicrophoneMuteIsAvailable(bool* available) = 0;
    132  virtual int32_t SetMicrophoneMute(bool enable) = 0;
    133  virtual int32_t MicrophoneMute(bool* enabled) const = 0;
    134 
    135  // Stereo support
    136  virtual int32_t StereoPlayoutIsAvailable(bool* available) const = 0;
    137  virtual int32_t SetStereoPlayout(bool enable) = 0;
    138  virtual int32_t StereoPlayout(bool* enabled) const = 0;
    139  virtual int32_t StereoRecordingIsAvailable(bool* available) const = 0;
    140  virtual int32_t SetStereoRecording(bool enable) = 0;
    141  virtual int32_t StereoRecording(bool* enabled) const = 0;
    142 
    143  // Playout delay
    144  virtual int32_t PlayoutDelay(uint16_t* delayMS) const = 0;
    145 
    146  // Only supported on Android.
    147  virtual bool BuiltInAECIsAvailable() const = 0;
    148  virtual bool BuiltInAGCIsAvailable() const = 0;
    149  virtual bool BuiltInNSIsAvailable() const = 0;
    150 
    151  // Enables the built-in audio effects. Only supported on Android.
    152  virtual int32_t EnableBuiltInAEC(bool enable) = 0;
    153  virtual int32_t EnableBuiltInAGC(bool enable) = 0;
    154  virtual int32_t EnableBuiltInNS(bool enable) = 0;
    155 
    156  // Play underrun count. Only supported on Android.
    157  // TODO(alexnarest): Make it abstract after upstream projects support it.
    158  virtual int32_t GetPlayoutUnderrunCount() const { return -1; }
    159 
    160  // Used to generate RTC stats. If not implemented, RTCAudioPlayoutStats will
    161  // not be present in the stats.
    162  virtual std::optional<Stats> GetStats() const { return std::nullopt; }
    163 
    164 // Only supported on iOS.
    165 #if defined(WEBRTC_IOS)
    166  virtual int GetPlayoutAudioParameters(AudioParameters* params) const = 0;
    167  virtual int GetRecordAudioParameters(AudioParameters* params) const = 0;
    168 #endif  // WEBRTC_IOS
    169 
    170 protected:
    171  ~AudioDeviceModule() override {}
    172 };
    173 
    174 // Extends the default ADM interface with some extra test methods.
    175 // Intended for usage in tests only and requires a unique factory method.
    176 class AudioDeviceModuleForTest : public AudioDeviceModule {
    177 public:
    178  // Triggers internal restart sequences of audio streaming. Can be used by
    179  // tests to emulate events corresponding to e.g. removal of an active audio
    180  // device or other actions which causes the stream to be disconnected.
    181  virtual int RestartPlayoutInternally() = 0;
    182  virtual int RestartRecordingInternally() = 0;
    183 
    184  virtual int SetPlayoutSampleRate(uint32_t sample_rate) = 0;
    185  virtual int SetRecordingSampleRate(uint32_t sample_rate) = 0;
    186 };
    187 
    188 }  // namespace webrtc
    189 
    190 #endif  // API_AUDIO_AUDIO_DEVICE_H_