blob: e0aaa5ed51760f8201a27996df0aff3816dba58c [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"
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010017#include "audio/audio_level.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"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "rtc_base/constructor_magic.h"
23#include "rtc_base/critical_section.h"
Fredrik Solenberg2a877972017-12-15 16:42:15 +010024#include "rtc_base/scoped_ref_ptr.h"
25#include "rtc_base/thread_annotations.h"
Fredrik Solenberg2a877972017-12-15 16:42:15 +010026
27namespace webrtc {
28
29class AudioSendStream;
30
31class AudioTransportImpl : public AudioTransport {
32 public:
Yves Gerey665174f2018-06-19 15:03:05 +020033 AudioTransportImpl(AudioMixer* mixer, AudioProcessing* audio_processing);
Fredrik Solenberg2a877972017-12-15 16:42:15 +010034 ~AudioTransportImpl() override;
35
36 int32_t RecordedDataIsAvailable(const void* audioSamples,
37 const size_t nSamples,
38 const size_t nBytesPerSample,
39 const size_t nChannels,
40 const uint32_t samplesPerSec,
41 const uint32_t totalDelayMS,
42 const int32_t clockDrift,
43 const uint32_t currentMicLevel,
44 const bool keyPressed,
45 uint32_t& newMicLevel) override;
46
47 int32_t NeedMorePlayData(const size_t nSamples,
48 const size_t nBytesPerSample,
49 const size_t nChannels,
50 const uint32_t samplesPerSec,
51 void* audioSamples,
52 size_t& nSamplesOut,
53 int64_t* elapsed_time_ms,
54 int64_t* ntp_time_ms) override;
55
56 void PullRenderData(int bits_per_sample,
57 int sample_rate,
58 size_t number_of_channels,
59 size_t number_of_frames,
60 void* audio_data,
61 int64_t* elapsed_time_ms,
62 int64_t* ntp_time_ms) override;
63
64 void UpdateSendingStreams(std::vector<AudioSendStream*> streams,
Yves Gerey665174f2018-06-19 15:03:05 +020065 int send_sample_rate_hz,
66 size_t send_num_channels);
Fredrik Solenberg2a877972017-12-15 16:42:15 +010067 void SetStereoChannelSwapping(bool enable);
68 bool typing_noise_detected() const;
Yves Gerey665174f2018-06-19 15:03:05 +020069 const voe::AudioLevel& audio_level() const { return audio_level_; }
Fredrik Solenberg2a877972017-12-15 16:42:15 +010070
71 private:
72 // Shared.
73 AudioProcessing* audio_processing_ = nullptr;
74
75 // Capture side.
76 rtc::CriticalSection capture_lock_;
77 std::vector<AudioSendStream*> sending_streams_ RTC_GUARDED_BY(capture_lock_);
78 int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000;
79 size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1;
80 bool typing_noise_detected_ RTC_GUARDED_BY(capture_lock_) = false;
81 bool swap_stereo_channels_ RTC_GUARDED_BY(capture_lock_) = false;
Fredrik Solenberg2a877972017-12-15 16:42:15 +010082 PushResampler<int16_t> capture_resampler_;
83 voe::AudioLevel audio_level_;
84 TypingDetection typing_detection_;
85
86 // Render side.
87 rtc::scoped_refptr<AudioMixer> mixer_;
88 AudioFrame mixed_frame_;
89 // Converts mixed audio to the audio device output rate.
90 PushResampler<int16_t> render_resampler_;
91
92 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioTransportImpl);
93};
94} // namespace webrtc
95
96#endif // AUDIO_AUDIO_TRANSPORT_IMPL_H_