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 <memory> 15 #include <vector> 16 17 #include "api/audio/audio_mixer.h" 18 #include "api/scoped_refptr.h" 19 #include "common_audio/resampler/include/push_resampler.h" 20 #include "modules/async_audio_processing/async_audio_processing.h" 21 #include "modules/audio_device/include/audio_device.h" 22 #include "modules/audio_processing/include/audio_processing.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( 33 AudioMixer* mixer, 34 AudioProcessing* audio_processing, 35 AsyncAudioProcessing::Factory* async_audio_processing_factory); 36 37 AudioTransportImpl() = delete; 38 AudioTransportImpl(const AudioTransportImpl&) = delete; 39 AudioTransportImpl& operator=(const AudioTransportImpl&) = delete; 40 41 ~AudioTransportImpl() override; 42 43 // TODO(bugs.webrtc.org/13620) Deprecate this function 44 int32_t RecordedDataIsAvailable(const void* audioSamples, 45 size_t nSamples, 46 size_t nBytesPerSample, 47 size_t nChannels, 48 uint32_t samplesPerSec, 49 uint32_t totalDelayMS, 50 int32_t clockDrift, 51 uint32_t currentMicLevel, 52 bool keyPressed, 53 uint32_t& newMicLevel) override; 54 55 int32_t RecordedDataIsAvailable(const void* audioSamples, 56 size_t nSamples, 57 size_t nBytesPerSample, 58 size_t nChannels, 59 uint32_t samplesPerSec, 60 uint32_t totalDelayMS, 61 int32_t clockDrift, 62 uint32_t currentMicLevel, 63 bool keyPressed, 64 uint32_t& newMicLevel, 65 int64_t estimated_capture_time_ns) override; 66 67 int32_t NeedMorePlayData(size_t nSamples, 68 size_t nBytesPerSample, 69 size_t nChannels, 70 uint32_t samplesPerSec, 71 void* audioSamples, 72 size_t& nSamplesOut, 73 int64_t* elapsed_time_ms, 74 int64_t* ntp_time_ms) override; 75 76 void PullRenderData(int bits_per_sample, 77 int sample_rate, 78 size_t number_of_channels, 79 size_t number_of_frames, 80 void* audio_data, 81 int64_t* elapsed_time_ms, 82 int64_t* ntp_time_ms) override; 83 84 void UpdateAudioSenders(std::vector<AudioSender*> senders, 85 int send_sample_rate_hz, 86 size_t send_num_channels); 87 void SetStereoChannelSwapping(bool enable); 88 89 private: 90 void SendProcessedData(std::unique_ptr<AudioFrame> audio_frame); 91 92 // Shared. 93 AudioProcessing* audio_processing_ = nullptr; 94 95 // Capture side. 96 97 // Thread-safe. 98 const std::unique_ptr<AsyncAudioProcessing> async_audio_processing_; 99 100 mutable Mutex capture_lock_; 101 std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_); 102 int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000; 103 size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1; 104 bool swap_stereo_channels_ RTC_GUARDED_BY(capture_lock_) = false; 105 PushResampler<int16_t> capture_resampler_; 106 107 // Render side. 108 109 rtc::scoped_refptr<AudioMixer> mixer_; 110 AudioFrame mixed_frame_; 111 // Converts mixed audio to the audio device output rate. 112 PushResampler<int16_t> render_resampler_; 113 }; 114 } // namespace webrtc 115 116 #endif // AUDIO_AUDIO_TRANSPORT_IMPL_H_ 117