Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 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 | |
Olga Sharonova | 09ceed2 | 2020-09-30 18:27:39 +0200 | [diff] [blame] | 14 | #include <memory> |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
| 17 | #include "api/audio/audio_mixer.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 18 | #include "api/scoped_refptr.h" |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 19 | #include "common_audio/resampler/include/push_resampler.h" |
Olga Sharonova | 09ceed2 | 2020-09-30 18:27:39 +0200 | [diff] [blame] | 20 | #include "modules/async_audio_processing/async_audio_processing.h" |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 21 | #include "modules/audio_device/include/audio_device.h" |
| 22 | #include "modules/audio_processing/include/audio_processing.h" |
| 23 | #include "modules/audio_processing/typing_detection.h" |
Markus Handell | 6287280 | 2020-07-06 15:15:07 +0200 | [diff] [blame] | 24 | #include "rtc_base/synchronization/mutex.h" |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 25 | #include "rtc_base/thread_annotations.h" |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
Tim Na | b8c775a | 2020-01-10 10:33:05 -0800 | [diff] [blame] | 29 | class AudioSender; |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 30 | |
| 31 | class AudioTransportImpl : public AudioTransport { |
| 32 | public: |
Olga Sharonova | 09ceed2 | 2020-09-30 18:27:39 +0200 | [diff] [blame] | 33 | AudioTransportImpl( |
| 34 | AudioMixer* mixer, |
| 35 | AudioProcessing* audio_processing, |
| 36 | AsyncAudioProcessing::Factory* async_audio_processing_factory); |
Niels Möller | de95329 | 2020-09-29 09:46:21 +0200 | [diff] [blame] | 37 | |
| 38 | AudioTransportImpl() = delete; |
| 39 | AudioTransportImpl(const AudioTransportImpl&) = delete; |
| 40 | AudioTransportImpl& operator=(const AudioTransportImpl&) = delete; |
| 41 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 42 | ~AudioTransportImpl() override; |
| 43 | |
| 44 | int32_t RecordedDataIsAvailable(const void* audioSamples, |
Ali Tofigh | 6223809 | 2022-01-25 13:27:19 +0100 | [diff] [blame] | 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, |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 53 | uint32_t& newMicLevel) override; |
| 54 | |
Ali Tofigh | 6223809 | 2022-01-25 13:27:19 +0100 | [diff] [blame] | 55 | int32_t NeedMorePlayData(size_t nSamples, |
| 56 | size_t nBytesPerSample, |
| 57 | size_t nChannels, |
| 58 | uint32_t samplesPerSec, |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 59 | void* audioSamples, |
| 60 | size_t& nSamplesOut, |
| 61 | int64_t* elapsed_time_ms, |
| 62 | int64_t* ntp_time_ms) override; |
| 63 | |
| 64 | void PullRenderData(int bits_per_sample, |
| 65 | int sample_rate, |
| 66 | size_t number_of_channels, |
| 67 | size_t number_of_frames, |
| 68 | void* audio_data, |
| 69 | int64_t* elapsed_time_ms, |
| 70 | int64_t* ntp_time_ms) override; |
| 71 | |
Tim Na | b8c775a | 2020-01-10 10:33:05 -0800 | [diff] [blame] | 72 | void UpdateAudioSenders(std::vector<AudioSender*> senders, |
| 73 | int send_sample_rate_hz, |
| 74 | size_t send_num_channels); |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 75 | void SetStereoChannelSwapping(bool enable); |
| 76 | bool typing_noise_detected() const; |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 77 | |
| 78 | private: |
Olga Sharonova | 09ceed2 | 2020-09-30 18:27:39 +0200 | [diff] [blame] | 79 | void SendProcessedData(std::unique_ptr<AudioFrame> audio_frame); |
| 80 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 81 | // Shared. |
| 82 | AudioProcessing* audio_processing_ = nullptr; |
| 83 | |
| 84 | // Capture side. |
Olga Sharonova | 09ceed2 | 2020-09-30 18:27:39 +0200 | [diff] [blame] | 85 | |
| 86 | // Thread-safe. |
| 87 | const std::unique_ptr<AsyncAudioProcessing> async_audio_processing_; |
| 88 | |
Markus Handell | 6287280 | 2020-07-06 15:15:07 +0200 | [diff] [blame] | 89 | mutable Mutex capture_lock_; |
Tim Na | b8c775a | 2020-01-10 10:33:05 -0800 | [diff] [blame] | 90 | std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_); |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 91 | int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000; |
| 92 | size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1; |
| 93 | bool typing_noise_detected_ RTC_GUARDED_BY(capture_lock_) = false; |
| 94 | bool swap_stereo_channels_ RTC_GUARDED_BY(capture_lock_) = false; |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 95 | PushResampler<int16_t> capture_resampler_; |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 96 | TypingDetection typing_detection_; |
| 97 | |
| 98 | // Render side. |
Olga Sharonova | 09ceed2 | 2020-09-30 18:27:39 +0200 | [diff] [blame] | 99 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 100 | rtc::scoped_refptr<AudioMixer> mixer_; |
| 101 | AudioFrame mixed_frame_; |
| 102 | // Converts mixed audio to the audio device output rate. |
| 103 | PushResampler<int16_t> render_resampler_; |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 104 | }; |
| 105 | } // namespace webrtc |
| 106 | |
| 107 | #endif // AUDIO_AUDIO_TRANSPORT_IMPL_H_ |