blob: 548b331ea75e40371a458b1f9330dc91392892c6 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef VOICE_ENGINE_CHANNEL_H_
12#define VOICE_ENGINE_CHANNEL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
kwibergb7f89d62016-02-17 10:04:18 -080014#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/audio/audio_mixer.h"
17#include "api/audio_codecs/audio_encoder.h"
18#include "api/call/audio_sink.h"
solenberg946d8862017-09-21 04:02:53 -070019#include "api/call/transport.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "api/optional.h"
21#include "common_audio/resampler/include/push_resampler.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020022#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "modules/audio_coding/include/audio_coding_module.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "modules/audio_processing/rms_level.h"
25#include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
26#include "modules/rtp_rtcp/include/rtp_header_parser.h"
27#include "modules/rtp_rtcp/include/rtp_receiver.h"
28#include "modules/rtp_rtcp/include/rtp_rtcp.h"
29#include "rtc_base/criticalsection.h"
30#include "rtc_base/event.h"
31#include "rtc_base/thread_checker.h"
32#include "voice_engine/audio_level.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "voice_engine/include/voe_base.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020034#include "voice_engine/shared_data.h"
35#include "voice_engine/voice_engine_defines.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 };
147 virtual ~Channel();
henrikaec6fbd22017-03-31 05:43:36 -0700148 static int32_t CreateChannel(Channel*& channel,
149 int32_t channelId,
150 uint32_t instanceId,
151 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800152 Channel(int32_t channelId,
153 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700154 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800155 int32_t Init();
tommi0a2391f2017-03-21 02:31:51 -0700156 void Terminate();
solenberg1c239d42017-09-29 06:00:28 -0700157 int32_t SetEngineInformation(ProcessThread& moduleProcessThread,
kwiberg55b97fe2016-01-28 05:22:45 -0800158 AudioDeviceModule& audioDeviceModule,
henrikaec6fbd22017-03-31 05:43:36 -0700159 rtc::TaskQueue* encoder_queue);
niklase@google.com470e71d2011-07-07 08:21:25 +0000160
kwibergb7f89d62016-02-17 10:04:18 -0800161 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100162
ossu29b1a8d2016-06-13 07:34:51 -0700163 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
164 // passed into AudioReceiveStream is the same as the one set when creating the
165 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
166 // go.
167 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
168
kwiberg1c07c702017-03-27 07:15:49 -0700169 void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
170
ossu1ffbd6c2017-04-06 12:05:04 -0700171 // Send using this encoder, with this payload type.
172 bool SetEncoder(int payload_type, std::unique_ptr<AudioEncoder> encoder);
ossu20a4b3f2017-04-27 02:08:52 -0700173 void ModifyEncoder(
174 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier);
ossu1ffbd6c2017-04-06 12:05:04 -0700175
kwiberg55b97fe2016-01-28 05:22:45 -0800176 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000177
kwiberg55b97fe2016-01-28 05:22:45 -0800178 // VoEBase
179 int32_t StartPlayout();
180 int32_t StopPlayout();
181 int32_t StartSend();
henrikaec6fbd22017-03-31 05:43:36 -0700182 void StopSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000183
solenberg6dc20382017-09-18 05:22:39 -0700184 // Codecs
Karl Wiberg88182372017-10-17 01:02:46 +0200185 struct EncoderProps {
186 int sample_rate_hz;
187 size_t num_channels;
188 };
189 rtc::Optional<EncoderProps> GetEncoderProps() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800190 int32_t GetRecCodec(CodecInst& codec);
minyue78b4d562016-11-30 04:47:39 -0800191 void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
minyue7e304322016-10-12 05:00:55 -0700192 bool EnableAudioNetworkAdaptor(const std::string& config_string);
193 void DisableAudioNetworkAdaptor();
194 void SetReceiverFrameLengthRange(int min_frame_length_ms,
195 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
solenberg946d8862017-09-21 04:02:53 -0700197 // Network
solenberg1c239d42017-09-29 06:00:28 -0700198 void RegisterTransport(Transport* transport);
nisse657bab22017-02-21 06:28:10 -0800199 // TODO(nisse, solenberg): Delete when VoENetwork is deleted.
mflodman3d7db262016-04-29 00:57:13 -0700200 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
nisse657bab22017-02-21 06:28:10 -0800201 void OnRtpPacket(const RtpPacketReceived& packet);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000202
solenberg8d73f8c2017-03-08 01:52:20 -0800203 // Muting, Volume and Level.
204 void SetInputMute(bool enable);
205 void SetChannelOutputVolumeScaling(float scaling);
206 int GetSpeechOutputLevel() const;
207 int GetSpeechOutputLevelFullRange() const;
zsteine76bd3a2017-07-14 12:17:49 -0700208 // See description of "totalAudioEnergy" in the WebRTC stats spec:
209 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
210 double GetTotalOutputEnergy() const;
211 double GetTotalOutputDuration() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
solenbergc6192a92017-03-13 02:36:19 -0700213 // Stats.
kwiberg55b97fe2016-01-28 05:22:45 -0800214 int GetNetworkStatistics(NetworkStatistics& stats);
215 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
ivoce1198e02017-09-08 08:13:19 -0700216 ANAStats GetANAStatistics() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000217
solenbergc6192a92017-03-13 02:36:19 -0700218 // Audio+Video Sync.
kwiberg55b97fe2016-01-28 05:22:45 -0800219 uint32_t GetDelayEstimate() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800220 int SetMinimumPlayoutDelay(int delayMs);
221 int GetPlayoutTimestamp(unsigned int& timestamp);
kwiberg55b97fe2016-01-28 05:22:45 -0800222 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000223
solenbergc6192a92017-03-13 02:36:19 -0700224 // DTMF.
solenberg8842c3e2016-03-11 03:06:41 -0800225 int SendTelephoneEventOutband(int event, int duration_ms);
solenbergffbbcac2016-11-17 05:25:37 -0800226 int SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000227
solenbergdd3abbb2017-09-18 07:05:30 -0700228 // RTP+RTCP
kwiberg55b97fe2016-01-28 05:22:45 -0800229 int SetLocalSSRC(unsigned int ssrc);
kwiberg55b97fe2016-01-28 05:22:45 -0800230 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
231 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
kwiberg55b97fe2016-01-28 05:22:45 -0800232 void EnableSendTransportSequenceNumber(int id);
233 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100234
stefan7de8d642017-02-07 07:14:08 -0800235 void RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -0700236 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -0800237 RtcpBandwidthObserver* bandwidth_observer);
238 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
nissefdbfdc92017-03-31 05:44:52 -0700239 void ResetSenderCongestionControlObjects();
240 void ResetReceiverCongestionControlObjects();
kwiberg55b97fe2016-01-28 05:22:45 -0800241 void SetRTCPStatus(bool enable);
kwiberg55b97fe2016-01-28 05:22:45 -0800242 int SetRTCP_CNAME(const char cName[256]);
kwiberg55b97fe2016-01-28 05:22:45 -0800243 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
244 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800245 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000246
kwiberg55b97fe2016-01-28 05:22:45 -0800247 // From AudioPacketizationCallback in the ACM
248 int32_t SendData(FrameType frameType,
249 uint8_t payloadType,
250 uint32_t timeStamp,
251 const uint8_t* payloadData,
252 size_t payloadSize,
253 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000254
kwiberg55b97fe2016-01-28 05:22:45 -0800255 // From RtpData in the RTP/RTCP module
256 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
257 size_t payloadSize,
258 const WebRtcRTPHeader* rtpHeader) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000259
kwiberg55b97fe2016-01-28 05:22:45 -0800260 // From RtpFeedback in the RTP/RTCP module
Karl Wibergc62f6c72017-10-04 12:38:53 +0200261 int32_t OnInitializeDecoder(int payload_type,
262 const SdpAudioFormat& audio_format,
kwiberg55b97fe2016-01-28 05:22:45 -0800263 uint32_t rate) override;
264 void OnIncomingSSRCChanged(uint32_t ssrc) override;
265 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000266
kwiberg55b97fe2016-01-28 05:22:45 -0800267 // From Transport (called by the RTP/RTCP module)
268 bool SendRtp(const uint8_t* data,
269 size_t len,
270 const PacketOptions& packet_options) override;
271 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000272
aleloiaed581a2016-10-20 06:32:39 -0700273 // From AudioMixer::Source.
aleloi6c278492016-10-20 14:24:39 -0700274 AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
275 int sample_rate_hz,
276 AudioFrame* audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700277
solenberg2397b9a2017-09-22 06:48:10 -0700278 int PreferredSampleRate() const;
279
kwiberg55b97fe2016-01-28 05:22:45 -0800280 uint32_t InstanceId() const { return _instanceId; }
281 int32_t ChannelId() const { return _channelId; }
282 bool Playing() const { return channel_state_.Get().playing; }
283 bool Sending() const { return channel_state_.Get().sending; }
kwiberg55b97fe2016-01-28 05:22:45 -0800284 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
285 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
henrikaec6fbd22017-03-31 05:43:36 -0700286
287 // ProcessAndEncodeAudio() creates an audio frame copy and posts a task
288 // on the shared encoder task queue, wich in turn calls (on the queue)
289 // ProcessAndEncodeAudioOnTaskQueue() where the actual processing of the
290 // audio takes place. The processing mainly consists of encoding and preparing
291 // the result for sending by adding it to a send queue.
292 // The main reason for using a task queue here is to release the native,
293 // OS-specific, audio capture thread as soon as possible to ensure that it
294 // can go back to sleep and be prepared to deliver an new captured audio
295 // packet.
296 void ProcessAndEncodeAudio(const AudioFrame& audio_input);
297
298 // This version of ProcessAndEncodeAudio() is used by PushCaptureData() in
299 // VoEBase and the audio in |audio_data| has not been subject to any APM
300 // processing. Some extra steps are therfore needed when building up the
301 // audio frame copy before using the same task as in the default call to
302 // ProcessAndEncodeAudio(const AudioFrame& audio_input).
303 void ProcessAndEncodeAudio(const int16_t* audio_data,
304 int sample_rate,
305 size_t number_of_frames,
306 size_t number_of_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000307
kwiberg55b97fe2016-01-28 05:22:45 -0800308 // Associate to a send channel.
309 // Used for obtaining RTT for a receive-only channel.
solenberg7602aab2016-11-14 11:30:07 -0800310 void set_associate_send_channel(const ChannelOwner& channel);
kwiberg55b97fe2016-01-28 05:22:45 -0800311 // Disassociate a send channel if it was associated.
312 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200313
ivoc14d5dbe2016-07-04 07:06:55 -0700314 // Set a RtcEventLog logging object.
315 void SetRtcEventLog(RtcEventLog* event_log);
316
michaelt9332b7d2016-11-30 07:51:13 -0800317 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
nisse284542b2017-01-10 08:58:32 -0800318 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800319
michaeltbf65be52016-12-15 06:24:49 -0800320 // From OverheadObserver in the RTP/RTCP module
321 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
322
elad.alond12a8e12017-03-23 11:04:48 -0700323 // The existence of this function alongside OnUplinkPacketLossRate is
324 // a compromise. We want the encoder to be agnostic of the PLR source, but
325 // we also don't want it to receive conflicting information from TWCC and
326 // from RTCP-XR.
327 void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000328
elad.alondadb4dc2017-03-23 15:29:50 -0700329 void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate);
330
hbos8d609f62017-04-10 07:39:05 -0700331 std::vector<RtpSource> GetSources() const {
332 return rtp_receiver_->GetSources();
333 }
334
kwiberg55b97fe2016-01-28 05:22:45 -0800335 private:
henrikaec6fbd22017-03-31 05:43:36 -0700336 class ProcessAndEncodeAudioTask;
elad.alond12a8e12017-03-23 11:04:48 -0700337
solenbergdd3abbb2017-09-18 07:05:30 -0700338 int GetRemoteSSRC(unsigned int& ssrc);
henrikaec6fbd22017-03-31 05:43:36 -0700339 void OnUplinkPacketLossRate(float packet_loss_rate);
solenberg8d73f8c2017-03-08 01:52:20 -0800340 bool InputMute() const;
nisse30e89312017-05-29 08:16:37 -0700341 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length);
342
kwiberg55b97fe2016-01-28 05:22:45 -0800343 bool ReceivePacket(const uint8_t* packet,
344 size_t packet_length,
Niels Möller22ec9522017-10-05 08:39:15 +0200345 const RTPHeader& header);
kwiberg55b97fe2016-01-28 05:22:45 -0800346 bool IsPacketInOrder(const RTPHeader& header) const;
347 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
348 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800349 void UpdatePlayoutTimestamp(bool rtcp);
kwiberg55b97fe2016-01-28 05:22:45 -0800350 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000351
kwiberg55b97fe2016-01-28 05:22:45 -0800352 int SetSendRtpHeaderExtension(bool enable,
353 RTPExtensionType type,
354 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000355
hbos3fd31fe2017-02-28 05:43:16 -0800356 void UpdateOverheadForEncoder()
danilchapa37de392017-09-09 04:17:22 -0700357 RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
nisse284542b2017-01-10 08:58:32 -0800358
ossue280cde2016-10-12 11:04:10 -0700359 int GetRtpTimestampRateHz() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800360 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000361
henrikaec6fbd22017-03-31 05:43:36 -0700362 // Called on the encoder task queue when a new input audio frame is ready
363 // for encoding.
364 void ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input);
365
366 uint32_t _instanceId;
367 int32_t _channelId;
368
pbosd8de1152016-02-01 09:00:51 -0800369 rtc::CriticalSection _callbackCritSect;
370 rtc::CriticalSection volume_settings_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000371
kwiberg55b97fe2016-01-28 05:22:45 -0800372 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000373
ivoc14d5dbe2016-07-04 07:06:55 -0700374 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
michaelt9332b7d2016-11-30 07:51:13 -0800375 std::unique_ptr<voe::RtcpRttStatsProxy> rtcp_rtt_stats_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200376
kwibergb7f89d62016-02-17 10:04:18 -0800377 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
378 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
379 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
kwibergb7f89d62016-02-17 10:04:18 -0800380 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700381 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800382 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
383 std::unique_ptr<AudioCodingModule> audio_coding_;
384 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800385 AudioLevel _outputAudioLevel;
kwiberg55b97fe2016-01-28 05:22:45 -0800386 // Downsamples to the codec rate if necessary.
387 PushResampler<int16_t> input_resampler_;
danilchapa37de392017-09-09 04:17:22 -0700388 uint32_t _timeStamp RTC_ACCESS_ON(encoder_queue_);
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000389
danilchapa37de392017-09-09 04:17:22 -0700390 RemoteNtpTimeEstimator ntp_estimator_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000391
kwiberg55b97fe2016-01-28 05:22:45 -0800392 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700393 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
solenbergfe7dd6d2017-03-11 08:10:43 -0800394
395 rtc::CriticalSection video_sync_lock_;
danilchapa37de392017-09-09 04:17:22 -0700396 uint32_t playout_timestamp_rtp_ RTC_GUARDED_BY(video_sync_lock_);
397 uint32_t playout_delay_ms_ RTC_GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800398 uint16_t send_sequence_number_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000399
pbosd8de1152016-02-01 09:00:51 -0800400 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000401
kwibergb7f89d62016-02-17 10:04:18 -0800402 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800403 // The rtp timestamp of the first played out audio frame.
404 int64_t capture_start_rtp_time_stamp_;
405 // The capture ntp time (in local timebase) of the first played out audio
406 // frame.
danilchapa37de392017-09-09 04:17:22 -0700407 int64_t capture_start_ntp_time_ms_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000408
kwiberg55b97fe2016-01-28 05:22:45 -0800409 // uses
kwiberg55b97fe2016-01-28 05:22:45 -0800410 ProcessThread* _moduleProcessThreadPtr;
411 AudioDeviceModule* _audioDeviceModulePtr;
kwiberg55b97fe2016-01-28 05:22:45 -0800412 Transport* _transportPtr; // WebRtc socket or external transport
danilchapa37de392017-09-09 04:17:22 -0700413 RmsLevel rms_level_ RTC_ACCESS_ON(encoder_queue_);
414 bool input_mute_ RTC_GUARDED_BY(volume_settings_critsect_);
415 bool previous_frame_muted_ RTC_ACCESS_ON(encoder_queue_);
416 float _outputGain RTC_GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800417 // VoeRTP_RTCP
henrikaec6fbd22017-03-31 05:43:36 -0700418 // TODO(henrika): can today be accessed on the main thread and on the
419 // task queue; hence potential race.
kwiberg55b97fe2016-01-28 05:22:45 -0800420 bool _includeAudioLevelIndication;
danilchapa37de392017-09-09 04:17:22 -0700421 size_t transport_overhead_per_packet_
422 RTC_GUARDED_BY(overhead_per_packet_lock_);
423 size_t rtp_overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_);
hbos3fd31fe2017-02-28 05:43:16 -0800424 rtc::CriticalSection overhead_per_packet_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800425 // VoENetwork
426 AudioFrame::SpeechType _outputSpeechType;
kwiberg55b97fe2016-01-28 05:22:45 -0800427 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800428 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800429 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800430 rtc::CriticalSection assoc_send_channel_lock_;
danilchapa37de392017-09-09 04:17:22 -0700431 ChannelOwner associate_send_channel_ RTC_GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100432
kwiberg55b97fe2016-01-28 05:22:45 -0800433 bool pacing_enabled_;
434 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800435 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
436 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
437 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200438 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700439
440 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
441 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
tommi0a2391f2017-03-21 02:31:51 -0700442
Karl Wiberg88182372017-10-17 01:02:46 +0200443 rtc::Optional<EncoderProps> cached_encoder_props_;
ossu76d29f92017-06-09 07:30:13 -0700444
tommi0a2391f2017-03-21 02:31:51 -0700445 rtc::ThreadChecker construction_thread_;
elad.alond12a8e12017-03-23 11:04:48 -0700446
447 const bool use_twcc_plr_for_ana_;
henrikaec6fbd22017-03-31 05:43:36 -0700448
henrika4515fa02017-05-03 08:30:15 -0700449 rtc::CriticalSection encoder_queue_lock_;
450
danilchapa37de392017-09-09 04:17:22 -0700451 bool encoder_queue_is_active_ RTC_GUARDED_BY(encoder_queue_lock_) = false;
henrika4515fa02017-05-03 08:30:15 -0700452
henrikaec6fbd22017-03-31 05:43:36 -0700453 rtc::TaskQueue* encoder_queue_ = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000454};
455
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000456} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000457} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000458
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200459#endif // VOICE_ENGINE_CHANNEL_H_