1 /* 2 * Copyright (c) 2016 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_AUDIO_TRANSPORT_IMPL_H_ 12 #define AUDIO_AUDIO_TRANSPORT_IMPL_H_ 13 14 #include <vector> 15 16 #include "api/audio/audio_mixer.h" 17 #include "api/scoped_refptr.h" 18 #include "common_audio/resampler/include/push_resampler.h" 19 #include "modules/audio_device/include/audio_device.h" 20 #include "modules/audio_processing/include/audio_processing.h" 21 #include "modules/audio_processing/typing_detection.h" 22 #include "rtc_base/constructor_magic.h" 23 #include "rtc_base/synchronization/mutex.h" 24 #include "rtc_base/thread_annotations.h" 25 26 namespace webrtc { 27 28 class AudioSender; 29 30 class AudioTransportImpl : public AudioTransport { 31 public: 32 AudioTransportImpl(AudioMixer* mixer, AudioProcessing* audio_processing); 33 ~AudioTransportImpl() override; 34 35 int32_t RecordedDataIsAvailable(const void* audioSamples, 36 const size_t nSamples, 37 const size_t nBytesPerSample, 38 const size_t nChannels, 39 const uint32_t samplesPerSec, 40 const uint32_t totalDelayMS, 41 const int32_t clockDrift, 42 const uint32_t currentMicLevel, 43 const bool keyPressed, 44 uint32_t& newMicLevel) override; 45 46 int32_t NeedMorePlayData(const size_t nSamples, 47 const size_t nBytesPerSample, 48 const size_t nChannels, 49 const uint32_t samplesPerSec, 50 void* audioSamples, 51 size_t& nSamplesOut, 52 int64_t* elapsed_time_ms, 53 int64_t* ntp_time_ms) override; 54 55 void PullRenderData(int bits_per_sample, 56 int sample_rate, 57 size_t number_of_channels, 58 size_t number_of_frames, 59 void* audio_data, 60 int64_t* elapsed_time_ms, 61 int64_t* ntp_time_ms) override; 62 63 void UpdateAudioSenders(std::vector<AudioSender*> senders, 64 int send_sample_rate_hz, 65 size_t send_num_channels); 66 void SetStereoChannelSwapping(bool enable); 67 bool typing_noise_detected() const; 68 69 private: 70 // Shared. 71 AudioProcessing* audio_processing_ = nullptr; 72 73 // Capture side. 74 mutable Mutex capture_lock_; 75 std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_); 76 int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000; 77 size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1; 78 bool typing_noise_detected_ RTC_GUARDED_BY(capture_lock_) = false; 79 bool swap_stereo_channels_ RTC_GUARDED_BY(capture_lock_) = false; 80 PushResampler<int16_t> capture_resampler_; 81 TypingDetection typing_detection_; 82 83 // Render side. 84 rtc::scoped_refptr<AudioMixer> mixer_; 85 AudioFrame mixed_frame_; 86 // Converts mixed audio to the audio device output rate. 87 PushResampler<int16_t> render_resampler_; 88 89 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioTransportImpl); 90 }; 91 } // namespace webrtc 92 93 #endif // AUDIO_AUDIO_TRANSPORT_IMPL_H_ 94