tor-browser

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

file_audio_device.h (5801B)


      1 /*
      2 *  Copyright (c) 2014 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 AUDIO_DEVICE_FILE_AUDIO_DEVICE_H_
     12 #define AUDIO_DEVICE_FILE_AUDIO_DEVICE_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 #include <string>
     17 
     18 #include "absl/strings/string_view.h"
     19 #include "api/audio/audio_device.h"
     20 #include "api/audio/audio_device_defines.h"
     21 #include "modules/audio_device/audio_device_buffer.h"
     22 #include "modules/audio_device/audio_device_generic.h"
     23 #include "rtc_base/platform_thread.h"
     24 #include "rtc_base/synchronization/mutex.h"
     25 #include "rtc_base/system/file_wrapper.h"
     26 
     27 namespace webrtc {
     28 
     29 // This is a fake audio device which plays audio from a file as its microphone
     30 // and plays out into a file.
     31 class FileAudioDevice : public AudioDeviceGeneric {
     32 public:
     33  // Constructs a file audio device with `id`. It will read audio from
     34  // `inputFilename` and record output audio to `outputFilename`.
     35  //
     36  // The input file should be a readable 48k stereo raw file, and the output
     37  // file should point to a writable location. The output format will also be
     38  // 48k stereo raw audio.
     39  FileAudioDevice(absl::string_view inputFilename,
     40                  absl::string_view outputFilename);
     41  virtual ~FileAudioDevice();
     42 
     43  // Retrieve the currently utilized audio layer
     44  int32_t ActiveAudioLayer(
     45      AudioDeviceModule::AudioLayer& audioLayer) const override;
     46 
     47  // Main initializaton and termination
     48  InitStatus Init() override;
     49  int32_t Terminate() override;
     50  bool Initialized() const override;
     51 
     52  // Device enumeration
     53  int16_t PlayoutDevices() override;
     54  int16_t RecordingDevices() override;
     55  int32_t PlayoutDeviceName(uint16_t index,
     56                            char name[kAdmMaxDeviceNameSize],
     57                            char guid[kAdmMaxGuidSize]) override;
     58  int32_t RecordingDeviceName(uint16_t index,
     59                              char name[kAdmMaxDeviceNameSize],
     60                              char guid[kAdmMaxGuidSize]) override;
     61 
     62  // Device selection
     63  int32_t SetPlayoutDevice(uint16_t index) override;
     64  int32_t SetPlayoutDevice(
     65      AudioDeviceModule::WindowsDeviceType device) override;
     66  int32_t SetRecordingDevice(uint16_t index) override;
     67  int32_t SetRecordingDevice(
     68      AudioDeviceModule::WindowsDeviceType device) override;
     69 
     70  // Audio transport initialization
     71  int32_t PlayoutIsAvailable(bool& available) override;
     72  int32_t InitPlayout() override;
     73  bool PlayoutIsInitialized() const override;
     74  int32_t RecordingIsAvailable(bool& available) override;
     75  int32_t InitRecording() override;
     76  bool RecordingIsInitialized() const override;
     77 
     78  // Audio transport control
     79  int32_t StartPlayout() override;
     80  int32_t StopPlayout() override;
     81  bool Playing() const override;
     82  int32_t StartRecording() override;
     83  int32_t StopRecording() override;
     84  bool Recording() const override;
     85 
     86  // Audio mixer initialization
     87  int32_t InitSpeaker() override;
     88  bool SpeakerIsInitialized() const override;
     89  int32_t InitMicrophone() override;
     90  bool MicrophoneIsInitialized() const override;
     91 
     92  // Speaker volume controls
     93  int32_t SpeakerVolumeIsAvailable(bool& available) override;
     94  int32_t SetSpeakerVolume(uint32_t volume) override;
     95  int32_t SpeakerVolume(uint32_t& volume) const override;
     96  int32_t MaxSpeakerVolume(uint32_t& maxVolume) const override;
     97  int32_t MinSpeakerVolume(uint32_t& minVolume) const override;
     98 
     99  // Microphone volume controls
    100  int32_t MicrophoneVolumeIsAvailable(bool& available) override;
    101  int32_t SetMicrophoneVolume(uint32_t volume) override;
    102  int32_t MicrophoneVolume(uint32_t& volume) const override;
    103  int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const override;
    104  int32_t MinMicrophoneVolume(uint32_t& minVolume) const override;
    105 
    106  // Speaker mute control
    107  int32_t SpeakerMuteIsAvailable(bool& available) override;
    108  int32_t SetSpeakerMute(bool enable) override;
    109  int32_t SpeakerMute(bool& enabled) const override;
    110 
    111  // Microphone mute control
    112  int32_t MicrophoneMuteIsAvailable(bool& available) override;
    113  int32_t SetMicrophoneMute(bool enable) override;
    114  int32_t MicrophoneMute(bool& enabled) const override;
    115 
    116  // Stereo support
    117  int32_t StereoPlayoutIsAvailable(bool& available) override;
    118  int32_t SetStereoPlayout(bool enable) override;
    119  int32_t StereoPlayout(bool& enabled) const override;
    120  int32_t StereoRecordingIsAvailable(bool& available) override;
    121  int32_t SetStereoRecording(bool enable) override;
    122  int32_t StereoRecording(bool& enabled) const override;
    123 
    124  // Delay information and control
    125  int32_t PlayoutDelay(uint16_t& delayMS) const override;
    126 
    127  void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override;
    128 
    129 private:
    130  static void RecThreadFunc(void*);
    131  static void PlayThreadFunc(void*);
    132  bool RecThreadProcess();
    133  bool PlayThreadProcess();
    134 
    135  int32_t _playout_index;
    136  int32_t _record_index;
    137  AudioDeviceBuffer* _ptrAudioBuffer;
    138  int8_t* _recordingBuffer;  // In bytes.
    139  int8_t* _playoutBuffer;    // In bytes.
    140  uint32_t _recordingFramesLeft;
    141  uint32_t _playoutFramesLeft;
    142  Mutex mutex_;
    143 
    144  size_t _recordingBufferSizeIn10MS;
    145  size_t _recordingFramesIn10MS;
    146  size_t _playoutFramesIn10MS;
    147 
    148  PlatformThread _ptrThreadRec;
    149  PlatformThread _ptrThreadPlay;
    150 
    151  bool _playing;
    152  bool _recording;
    153  int64_t _lastCallPlayoutMillis;
    154  int64_t _lastCallRecordMillis;
    155 
    156  FileWrapper _outputFile;
    157  FileWrapper _inputFile;
    158  std::string _outputFilename;
    159  std::string _inputFilename;
    160 };
    161 
    162 }  // namespace webrtc
    163 
    164 #endif  // AUDIO_DEVICE_FILE_AUDIO_DEVICE_H_