blob: 5b885bdc6cc93698fe0384d86752828e0fb75f3e [file] [log] [blame]
Fredrik Solenberg2a877972017-12-15 16:42:15 +01001/*
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"
Mirko Bonadeid9708072019-01-25 20:26:48 +010017#include "api/scoped_refptr.h"
Fredrik Solenberg2a877972017-12-15 16:42:15 +010018#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"
Markus Handell62872802020-07-06 15:15:07 +020022#include "rtc_base/synchronization/mutex.h"
Fredrik Solenberg2a877972017-12-15 16:42:15 +010023#include "rtc_base/thread_annotations.h"
Fredrik Solenberg2a877972017-12-15 16:42:15 +010024
25namespace webrtc {
26
Tim Nab8c775a2020-01-10 10:33:05 -080027class AudioSender;
Fredrik Solenberg2a877972017-12-15 16:42:15 +010028
29class AudioTransportImpl : public AudioTransport {
30 public:
Yves Gerey665174f2018-06-19 15:03:05 +020031 AudioTransportImpl(AudioMixer* mixer, AudioProcessing* audio_processing);
Niels Möllerde953292020-09-29 09:46:21 +020032
33 AudioTransportImpl() = delete;
34 AudioTransportImpl(const AudioTransportImpl&) = delete;
35 AudioTransportImpl& operator=(const AudioTransportImpl&) = delete;
36
Fredrik Solenberg2a877972017-12-15 16:42:15 +010037 ~AudioTransportImpl() override;
38
39 int32_t RecordedDataIsAvailable(const void* audioSamples,
40 const size_t nSamples,
41 const size_t nBytesPerSample,
42 const size_t nChannels,
43 const uint32_t samplesPerSec,
44 const uint32_t totalDelayMS,
45 const int32_t clockDrift,
46 const uint32_t currentMicLevel,
47 const bool keyPressed,
48 uint32_t& newMicLevel) override;
49
50 int32_t NeedMorePlayData(const size_t nSamples,
51 const size_t nBytesPerSample,
52 const size_t nChannels,
53 const uint32_t samplesPerSec,
54 void* audioSamples,
55 size_t& nSamplesOut,
56 int64_t* elapsed_time_ms,
57 int64_t* ntp_time_ms) override;
58
59 void PullRenderData(int bits_per_sample,
60 int sample_rate,
61 size_t number_of_channels,
62 size_t number_of_frames,
63 void* audio_data,
64 int64_t* elapsed_time_ms,
65 int64_t* ntp_time_ms) override;
66
Tim Nab8c775a2020-01-10 10:33:05 -080067 void UpdateAudioSenders(std::vector<AudioSender*> senders,
68 int send_sample_rate_hz,
69 size_t send_num_channels);
Fredrik Solenberg2a877972017-12-15 16:42:15 +010070 void SetStereoChannelSwapping(bool enable);
71 bool typing_noise_detected() const;
Fredrik Solenberg2a877972017-12-15 16:42:15 +010072
73 private:
74 // Shared.
75 AudioProcessing* audio_processing_ = nullptr;
76
77 // Capture side.
Markus Handell62872802020-07-06 15:15:07 +020078 mutable Mutex capture_lock_;
Tim Nab8c775a2020-01-10 10:33:05 -080079 std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_);
Fredrik Solenberg2a877972017-12-15 16:42:15 +010080 int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000;
81 size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1;
82 bool typing_noise_detected_ RTC_GUARDED_BY(capture_lock_) = false;
83 bool swap_stereo_channels_ RTC_GUARDED_BY(capture_lock_) = false;
Fredrik Solenberg2a877972017-12-15 16:42:15 +010084 PushResampler<int16_t> capture_resampler_;
Fredrik Solenberg2a877972017-12-15 16:42:15 +010085 TypingDetection typing_detection_;
86
87 // Render side.
88 rtc::scoped_refptr<AudioMixer> mixer_;
89 AudioFrame mixed_frame_;
90 // Converts mixed audio to the audio device output rate.
91 PushResampler<int16_t> render_resampler_;
Fredrik Solenberg2a877972017-12-15 16:42:15 +010092};
93} // namespace webrtc
94
95#endif // AUDIO_AUDIO_TRANSPORT_IMPL_H_