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