blob: c5d243cac4ac0f9b4d92b9f1b14ea8829d80fa3c [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010011#ifndef AUDIO_CHANNEL_H_
12#define AUDIO_CHANNEL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010014#include <map>
kwibergb7f89d62016-02-17 10:04:18 -080015#include <memory>
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010016#include <string>
17#include <vector>
kwibergb7f89d62016-02-17 10:04:18 -080018
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/audio/audio_mixer.h"
20#include "api/audio_codecs/audio_encoder.h"
21#include "api/call/audio_sink.h"
solenberg946d8862017-09-21 04:02:53 -070022#include "api/call/transport.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "api/optional.h"
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010024#include "audio/audio_level.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020025#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "modules/audio_coding/include/audio_coding_module.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "modules/audio_processing/rms_level.h"
28#include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
29#include "modules/rtp_rtcp/include/rtp_header_parser.h"
30#include "modules/rtp_rtcp/include/rtp_receiver.h"
31#include "modules/rtp_rtcp/include/rtp_rtcp.h"
32#include "rtc_base/criticalsection.h"
33#include "rtc_base/event.h"
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010034#include "rtc_base/task_queue.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "rtc_base/thread_checker.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000036
wu@webrtc.org94454b72014-06-05 20:34:08 +000037namespace rtc {
wu@webrtc.org94454b72014-06-05 20:34:08 +000038class TimestampWrapAroundHandler;
39}
40
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000041namespace webrtc {
42
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000043class AudioDeviceModule;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010044class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000045class ProcessThread;
Erik Språng737336d2016-07-29 12:59:36 +020046class RateLimiter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000047class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000048class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070049class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000050class RTPPayloadRegistry;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000051class RTPReceiverAudio;
nisse657bab22017-02-21 06:28:10 -080052class RtpPacketReceived;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000053class RtpRtcp;
nisseb8f9a322017-03-27 05:36:15 -070054class RtpTransportControllerSendInterface;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000055class TelephoneEventHandler;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000057struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
solenbergdd3abbb2017-09-18 07:05:30 -070059struct CallStatistics {
60 unsigned short fractionLost;
61 unsigned int cumulativeLost;
62 unsigned int extendedMax;
63 unsigned int jitterSamples;
64 int64_t rttMs;
65 size_t bytesSent;
66 int packetsSent;
67 size_t bytesReceived;
68 int packetsReceived;
69 // The capture ntp time (in local timebase) of the first played out audio
70 // frame.
71 int64_t capture_start_ntp_time_ms_;
72};
73
74// See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details.
75struct ReportBlock {
76 uint32_t sender_SSRC; // SSRC of sender
77 uint32_t source_SSRC;
78 uint8_t fraction_lost;
79 uint32_t cumulative_num_packets_lost;
80 uint32_t extended_highest_sequence_number;
81 uint32_t interarrival_jitter;
82 uint32_t last_SR_timestamp;
83 uint32_t delay_since_last_SR;
84};
85
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000086namespace voe {
87
ivoc14d5dbe2016-07-04 07:06:55 -070088class RtcEventLogProxy;
michaelt9332b7d2016-11-30 07:51:13 -080089class RtcpRttStatsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010090class RtpPacketSenderProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010091class TransportFeedbackProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010092class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000093class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000094
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000095// Helper class to simplify locking scheme for members that are accessed from
96// multiple threads.
97// Example: a member can be set on thread T1 and read by an internal audio
98// thread T2. Accessing the member via this class ensures that we are
99// safe and also avoid TSan v2 warnings.
100class ChannelState {
101 public:
kwiberg55b97fe2016-01-28 05:22:45 -0800102 struct State {
solenberg11ace152016-09-15 04:29:13 -0700103 bool playing = false;
104 bool sending = false;
kwiberg55b97fe2016-01-28 05:22:45 -0800105 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000106
kwiberg55b97fe2016-01-28 05:22:45 -0800107 ChannelState() {}
108 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000109
kwiberg55b97fe2016-01-28 05:22:45 -0800110 void Reset() {
111 rtc::CritScope lock(&lock_);
112 state_ = State();
113 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000114
kwiberg55b97fe2016-01-28 05:22:45 -0800115 State Get() const {
116 rtc::CritScope lock(&lock_);
117 return state_;
118 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000119
kwiberg55b97fe2016-01-28 05:22:45 -0800120 void SetPlaying(bool enable) {
121 rtc::CritScope lock(&lock_);
122 state_.playing = enable;
123 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000124
kwiberg55b97fe2016-01-28 05:22:45 -0800125 void SetSending(bool enable) {
126 rtc::CritScope lock(&lock_);
127 state_.sending = enable;
128 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000129
kwiberg55b97fe2016-01-28 05:22:45 -0800130 private:
pbosd8de1152016-02-01 09:00:51 -0800131 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800132 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000133};
niklase@google.com470e71d2011-07-07 08:21:25 +0000134
kwiberg55b97fe2016-01-28 05:22:45 -0800135class Channel
136 : public RtpData,
137 public RtpFeedback,
kwiberg55b97fe2016-01-28 05:22:45 -0800138 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800139 public AudioPacketizationCallback, // receive encoded packets from the
140 // ACM
michaeltbf65be52016-12-15 06:24:49 -0800141 public OverheadObserver {
kwiberg55b97fe2016-01-28 05:22:45 -0800142 public:
143 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000144
kwiberg55b97fe2016-01-28 05:22:45 -0800145 enum { KNumSocketThreads = 1 };
146 enum { KNumberOfSocketBuffers = 8 };
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100147 // Used for send streams.
148 Channel(rtc::TaskQueue* encoder_queue,
149 ProcessThread* module_process_thread,
150 AudioDeviceModule* audio_device_module);
151 // Used for receive streams.
152 Channel(ProcessThread* module_process_thread,
153 AudioDeviceModule* audio_device_module,
154 size_t jitter_buffer_max_packets,
155 bool jitter_buffer_fast_playout,
156 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory);
kwiberg55b97fe2016-01-28 05:22:45 -0800157 virtual ~Channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100159 void SetSink(AudioSinkInterface* sink);
ossu29b1a8d2016-06-13 07:34:51 -0700160
kwiberg1c07c702017-03-27 07:15:49 -0700161 void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
162
ossu1ffbd6c2017-04-06 12:05:04 -0700163 // Send using this encoder, with this payload type.
164 bool SetEncoder(int payload_type, std::unique_ptr<AudioEncoder> encoder);
ossu20a4b3f2017-04-27 02:08:52 -0700165 void ModifyEncoder(
166 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier);
ossu1ffbd6c2017-04-06 12:05:04 -0700167
kwiberg55b97fe2016-01-28 05:22:45 -0800168 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000169
kwiberg55b97fe2016-01-28 05:22:45 -0800170 // VoEBase
171 int32_t StartPlayout();
172 int32_t StopPlayout();
173 int32_t StartSend();
henrikaec6fbd22017-03-31 05:43:36 -0700174 void StopSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000175
solenberg6dc20382017-09-18 05:22:39 -0700176 // Codecs
kwiberg55b97fe2016-01-28 05:22:45 -0800177 int32_t GetRecCodec(CodecInst& codec);
minyue78b4d562016-11-30 04:47:39 -0800178 void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
minyue7e304322016-10-12 05:00:55 -0700179 bool EnableAudioNetworkAdaptor(const std::string& config_string);
180 void DisableAudioNetworkAdaptor();
181 void SetReceiverFrameLengthRange(int min_frame_length_ms,
182 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000183
solenberg946d8862017-09-21 04:02:53 -0700184 // Network
solenberg1c239d42017-09-29 06:00:28 -0700185 void RegisterTransport(Transport* transport);
nisse657bab22017-02-21 06:28:10 -0800186 // TODO(nisse, solenberg): Delete when VoENetwork is deleted.
mflodman3d7db262016-04-29 00:57:13 -0700187 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
nisse657bab22017-02-21 06:28:10 -0800188 void OnRtpPacket(const RtpPacketReceived& packet);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000189
solenberg8d73f8c2017-03-08 01:52:20 -0800190 // Muting, Volume and Level.
191 void SetInputMute(bool enable);
192 void SetChannelOutputVolumeScaling(float scaling);
193 int GetSpeechOutputLevel() const;
194 int GetSpeechOutputLevelFullRange() const;
zsteine76bd3a2017-07-14 12:17:49 -0700195 // See description of "totalAudioEnergy" in the WebRTC stats spec:
196 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
197 double GetTotalOutputEnergy() const;
198 double GetTotalOutputDuration() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000199
solenbergc6192a92017-03-13 02:36:19 -0700200 // Stats.
kwiberg55b97fe2016-01-28 05:22:45 -0800201 int GetNetworkStatistics(NetworkStatistics& stats);
202 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
ivoce1198e02017-09-08 08:13:19 -0700203 ANAStats GetANAStatistics() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000204
solenbergc6192a92017-03-13 02:36:19 -0700205 // Audio+Video Sync.
kwiberg55b97fe2016-01-28 05:22:45 -0800206 uint32_t GetDelayEstimate() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800207 int SetMinimumPlayoutDelay(int delayMs);
208 int GetPlayoutTimestamp(unsigned int& timestamp);
kwiberg55b97fe2016-01-28 05:22:45 -0800209 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
solenbergc6192a92017-03-13 02:36:19 -0700211 // DTMF.
solenberg8842c3e2016-03-11 03:06:41 -0800212 int SendTelephoneEventOutband(int event, int duration_ms);
solenbergffbbcac2016-11-17 05:25:37 -0800213 int SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000214
solenbergdd3abbb2017-09-18 07:05:30 -0700215 // RTP+RTCP
kwiberg55b97fe2016-01-28 05:22:45 -0800216 int SetLocalSSRC(unsigned int ssrc);
kwiberg55b97fe2016-01-28 05:22:45 -0800217 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
kwiberg55b97fe2016-01-28 05:22:45 -0800218 void EnableSendTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100219
stefan7de8d642017-02-07 07:14:08 -0800220 void RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -0700221 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -0800222 RtcpBandwidthObserver* bandwidth_observer);
223 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
nissefdbfdc92017-03-31 05:44:52 -0700224 void ResetSenderCongestionControlObjects();
225 void ResetReceiverCongestionControlObjects();
kwiberg55b97fe2016-01-28 05:22:45 -0800226 void SetRTCPStatus(bool enable);
kwiberg55b97fe2016-01-28 05:22:45 -0800227 int SetRTCP_CNAME(const char cName[256]);
kwiberg55b97fe2016-01-28 05:22:45 -0800228 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
229 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800230 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000231
kwiberg55b97fe2016-01-28 05:22:45 -0800232 // From AudioPacketizationCallback in the ACM
233 int32_t SendData(FrameType frameType,
234 uint8_t payloadType,
235 uint32_t timeStamp,
236 const uint8_t* payloadData,
237 size_t payloadSize,
238 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000239
kwiberg55b97fe2016-01-28 05:22:45 -0800240 // From RtpData in the RTP/RTCP module
241 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
242 size_t payloadSize,
243 const WebRtcRTPHeader* rtpHeader) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000244
kwiberg55b97fe2016-01-28 05:22:45 -0800245 // From RtpFeedback in the RTP/RTCP module
Karl Wibergc62f6c72017-10-04 12:38:53 +0200246 int32_t OnInitializeDecoder(int payload_type,
247 const SdpAudioFormat& audio_format,
kwiberg55b97fe2016-01-28 05:22:45 -0800248 uint32_t rate) override;
249 void OnIncomingSSRCChanged(uint32_t ssrc) override;
250 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000251
kwiberg55b97fe2016-01-28 05:22:45 -0800252 // From Transport (called by the RTP/RTCP module)
253 bool SendRtp(const uint8_t* data,
254 size_t len,
255 const PacketOptions& packet_options) override;
256 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000257
aleloiaed581a2016-10-20 06:32:39 -0700258 // From AudioMixer::Source.
aleloi6c278492016-10-20 14:24:39 -0700259 AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
260 int sample_rate_hz,
261 AudioFrame* audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700262
solenberg2397b9a2017-09-22 06:48:10 -0700263 int PreferredSampleRate() const;
264
kwiberg55b97fe2016-01-28 05:22:45 -0800265 bool Playing() const { return channel_state_.Get().playing; }
266 bool Sending() const { return channel_state_.Get().sending; }
kwiberg55b97fe2016-01-28 05:22:45 -0800267 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
268 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
henrikaec6fbd22017-03-31 05:43:36 -0700269
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100270 // ProcessAndEncodeAudio() posts a task on the shared encoder task queue,
271 // which in turn calls (on the queue) ProcessAndEncodeAudioOnTaskQueue() where
272 // the actual processing of the audio takes place. The processing mainly
273 // consists of encoding and preparing the result for sending by adding it to a
274 // send queue.
henrikaec6fbd22017-03-31 05:43:36 -0700275 // The main reason for using a task queue here is to release the native,
276 // OS-specific, audio capture thread as soon as possible to ensure that it
277 // can go back to sleep and be prepared to deliver an new captured audio
278 // packet.
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100279 void ProcessAndEncodeAudio(std::unique_ptr<AudioFrame> audio_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +0000280
kwiberg55b97fe2016-01-28 05:22:45 -0800281 // Associate to a send channel.
282 // Used for obtaining RTT for a receive-only channel.
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100283 void SetAssociatedSendChannel(Channel* channel);
Minyue2013aec2015-05-13 14:14:42 +0200284
ivoc14d5dbe2016-07-04 07:06:55 -0700285 // Set a RtcEventLog logging object.
286 void SetRtcEventLog(RtcEventLog* event_log);
287
michaelt9332b7d2016-11-30 07:51:13 -0800288 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
nisse284542b2017-01-10 08:58:32 -0800289 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800290
michaeltbf65be52016-12-15 06:24:49 -0800291 // From OverheadObserver in the RTP/RTCP module
292 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
293
elad.alond12a8e12017-03-23 11:04:48 -0700294 // The existence of this function alongside OnUplinkPacketLossRate is
295 // a compromise. We want the encoder to be agnostic of the PLR source, but
296 // we also don't want it to receive conflicting information from TWCC and
297 // from RTCP-XR.
298 void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000299
elad.alondadb4dc2017-03-23 15:29:50 -0700300 void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate);
301
hbos8d609f62017-04-10 07:39:05 -0700302 std::vector<RtpSource> GetSources() const {
303 return rtp_receiver_->GetSources();
304 }
305
kwiberg55b97fe2016-01-28 05:22:45 -0800306 private:
henrikaec6fbd22017-03-31 05:43:36 -0700307 class ProcessAndEncodeAudioTask;
elad.alond12a8e12017-03-23 11:04:48 -0700308
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100309 void Init();
310 void Terminate();
311
solenbergdd3abbb2017-09-18 07:05:30 -0700312 int GetRemoteSSRC(unsigned int& ssrc);
henrikaec6fbd22017-03-31 05:43:36 -0700313 void OnUplinkPacketLossRate(float packet_loss_rate);
solenberg8d73f8c2017-03-08 01:52:20 -0800314 bool InputMute() const;
nisse30e89312017-05-29 08:16:37 -0700315
kwiberg55b97fe2016-01-28 05:22:45 -0800316 bool ReceivePacket(const uint8_t* packet,
317 size_t packet_length,
Niels Möller22ec9522017-10-05 08:39:15 +0200318 const RTPHeader& header);
kwiberg55b97fe2016-01-28 05:22:45 -0800319 bool IsPacketInOrder(const RTPHeader& header) const;
320 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
321 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800322 void UpdatePlayoutTimestamp(bool rtcp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000323
kwiberg55b97fe2016-01-28 05:22:45 -0800324 int SetSendRtpHeaderExtension(bool enable,
325 RTPExtensionType type,
326 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000327
hbos3fd31fe2017-02-28 05:43:16 -0800328 void UpdateOverheadForEncoder()
danilchapa37de392017-09-09 04:17:22 -0700329 RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
nisse284542b2017-01-10 08:58:32 -0800330
ossue280cde2016-10-12 11:04:10 -0700331 int GetRtpTimestampRateHz() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800332 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000333
henrikaec6fbd22017-03-31 05:43:36 -0700334 // Called on the encoder task queue when a new input audio frame is ready
335 // for encoding.
336 void ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input);
337
pbosd8de1152016-02-01 09:00:51 -0800338 rtc::CriticalSection _callbackCritSect;
339 rtc::CriticalSection volume_settings_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000340
kwiberg55b97fe2016-01-28 05:22:45 -0800341 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000342
ivoc14d5dbe2016-07-04 07:06:55 -0700343 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
michaelt9332b7d2016-11-30 07:51:13 -0800344 std::unique_ptr<voe::RtcpRttStatsProxy> rtcp_rtt_stats_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200345
kwibergb7f89d62016-02-17 10:04:18 -0800346 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
347 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
kwibergb7f89d62016-02-17 10:04:18 -0800348 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700349 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800350 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
351 std::unique_ptr<AudioCodingModule> audio_coding_;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100352 AudioSinkInterface* audio_sink_ = nullptr;
kwiberg55b97fe2016-01-28 05:22:45 -0800353 AudioLevel _outputAudioLevel;
danilchapa37de392017-09-09 04:17:22 -0700354 uint32_t _timeStamp RTC_ACCESS_ON(encoder_queue_);
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000355
danilchapa37de392017-09-09 04:17:22 -0700356 RemoteNtpTimeEstimator ntp_estimator_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000357
kwiberg55b97fe2016-01-28 05:22:45 -0800358 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700359 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
solenbergfe7dd6d2017-03-11 08:10:43 -0800360
361 rtc::CriticalSection video_sync_lock_;
danilchapa37de392017-09-09 04:17:22 -0700362 uint32_t playout_timestamp_rtp_ RTC_GUARDED_BY(video_sync_lock_);
363 uint32_t playout_delay_ms_ RTC_GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800364 uint16_t send_sequence_number_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000365
pbosd8de1152016-02-01 09:00:51 -0800366 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000367
kwibergb7f89d62016-02-17 10:04:18 -0800368 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800369 // The rtp timestamp of the first played out audio frame.
370 int64_t capture_start_rtp_time_stamp_;
371 // The capture ntp time (in local timebase) of the first played out audio
372 // frame.
danilchapa37de392017-09-09 04:17:22 -0700373 int64_t capture_start_ntp_time_ms_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000374
kwiberg55b97fe2016-01-28 05:22:45 -0800375 // uses
kwiberg55b97fe2016-01-28 05:22:45 -0800376 ProcessThread* _moduleProcessThreadPtr;
377 AudioDeviceModule* _audioDeviceModulePtr;
kwiberg55b97fe2016-01-28 05:22:45 -0800378 Transport* _transportPtr; // WebRtc socket or external transport
danilchapa37de392017-09-09 04:17:22 -0700379 RmsLevel rms_level_ RTC_ACCESS_ON(encoder_queue_);
380 bool input_mute_ RTC_GUARDED_BY(volume_settings_critsect_);
381 bool previous_frame_muted_ RTC_ACCESS_ON(encoder_queue_);
382 float _outputGain RTC_GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800383 // VoeRTP_RTCP
henrikaec6fbd22017-03-31 05:43:36 -0700384 // TODO(henrika): can today be accessed on the main thread and on the
385 // task queue; hence potential race.
kwiberg55b97fe2016-01-28 05:22:45 -0800386 bool _includeAudioLevelIndication;
danilchapa37de392017-09-09 04:17:22 -0700387 size_t transport_overhead_per_packet_
388 RTC_GUARDED_BY(overhead_per_packet_lock_);
389 size_t rtp_overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_);
hbos3fd31fe2017-02-28 05:43:16 -0800390 rtc::CriticalSection overhead_per_packet_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800391 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800392 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800393 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800394 rtc::CriticalSection assoc_send_channel_lock_;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100395 Channel* associated_send_channel_ RTC_GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100396
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100397 bool pacing_enabled_ = true;
kwiberg55b97fe2016-01-28 05:22:45 -0800398 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800399 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
400 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
401 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200402 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700403
tommi0a2391f2017-03-21 02:31:51 -0700404 rtc::ThreadChecker construction_thread_;
elad.alond12a8e12017-03-23 11:04:48 -0700405
406 const bool use_twcc_plr_for_ana_;
henrikaec6fbd22017-03-31 05:43:36 -0700407
henrika4515fa02017-05-03 08:30:15 -0700408 rtc::CriticalSection encoder_queue_lock_;
danilchapa37de392017-09-09 04:17:22 -0700409 bool encoder_queue_is_active_ RTC_GUARDED_BY(encoder_queue_lock_) = false;
henrikaec6fbd22017-03-31 05:43:36 -0700410 rtc::TaskQueue* encoder_queue_ = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000411};
412
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000413} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000414} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000415
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +0100416#endif // AUDIO_CHANNEL_H_