blob: d023f87753635ff94221c885f36e123af6e52a35 [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"
19#include "api/optional.h"
20#include "common_audio/resampler/include/push_resampler.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020021#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "modules/audio_coding/acm2/codec_manager.h"
23#include "modules/audio_coding/acm2/rent_a_codec.h"
24#include "modules/audio_coding/include/audio_coding_module.h"
25#include "modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
26#include "modules/audio_processing/rms_level.h"
27#include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
28#include "modules/rtp_rtcp/include/rtp_header_parser.h"
29#include "modules/rtp_rtcp/include/rtp_receiver.h"
30#include "modules/rtp_rtcp/include/rtp_rtcp.h"
31#include "rtc_base/criticalsection.h"
32#include "rtc_base/event.h"
33#include "rtc_base/thread_checker.h"
34#include "voice_engine/audio_level.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "voice_engine/include/voe_base.h"
36#include "voice_engine/include/voe_network.h"
37#include "voice_engine/shared_data.h"
38#include "voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000039
wu@webrtc.org94454b72014-06-05 20:34:08 +000040namespace rtc {
wu@webrtc.org94454b72014-06-05 20:34:08 +000041class TimestampWrapAroundHandler;
42}
43
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000044namespace webrtc {
45
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000046class AudioDeviceModule;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010047class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000048class ProcessThread;
Erik Språng737336d2016-07-29 12:59:36 +020049class RateLimiter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000050class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000051class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070052class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000053class RTPPayloadRegistry;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000054class RTPReceiverAudio;
nisse657bab22017-02-21 06:28:10 -080055class RtpPacketReceived;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000056class RtpRtcp;
nisseb8f9a322017-03-27 05:36:15 -070057class RtpTransportControllerSendInterface;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000058class TelephoneEventHandler;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000059class VoERTPObserver;
60class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
62struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000063struct ReportBlock;
64struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000065
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000066namespace voe {
67
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000068class OutputMixer;
ivoc14d5dbe2016-07-04 07:06:55 -070069class RtcEventLogProxy;
michaelt9332b7d2016-11-30 07:51:13 -080070class RtcpRttStatsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010071class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000072class Statistics;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010073class TransportFeedbackProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010074class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000075class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000076
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000077// Helper class to simplify locking scheme for members that are accessed from
78// multiple threads.
79// Example: a member can be set on thread T1 and read by an internal audio
80// thread T2. Accessing the member via this class ensures that we are
81// safe and also avoid TSan v2 warnings.
82class ChannelState {
83 public:
kwiberg55b97fe2016-01-28 05:22:45 -080084 struct State {
solenberg11ace152016-09-15 04:29:13 -070085 bool playing = false;
86 bool sending = false;
kwiberg55b97fe2016-01-28 05:22:45 -080087 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000088
kwiberg55b97fe2016-01-28 05:22:45 -080089 ChannelState() {}
90 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000091
kwiberg55b97fe2016-01-28 05:22:45 -080092 void Reset() {
93 rtc::CritScope lock(&lock_);
94 state_ = State();
95 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000096
kwiberg55b97fe2016-01-28 05:22:45 -080097 State Get() const {
98 rtc::CritScope lock(&lock_);
99 return state_;
100 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000101
kwiberg55b97fe2016-01-28 05:22:45 -0800102 void SetPlaying(bool enable) {
103 rtc::CritScope lock(&lock_);
104 state_.playing = enable;
105 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000106
kwiberg55b97fe2016-01-28 05:22:45 -0800107 void SetSending(bool enable) {
108 rtc::CritScope lock(&lock_);
109 state_.sending = enable;
110 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000111
kwiberg55b97fe2016-01-28 05:22:45 -0800112 private:
pbosd8de1152016-02-01 09:00:51 -0800113 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800114 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000115};
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
kwiberg55b97fe2016-01-28 05:22:45 -0800117class Channel
118 : public RtpData,
119 public RtpFeedback,
kwiberg55b97fe2016-01-28 05:22:45 -0800120 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800121 public AudioPacketizationCallback, // receive encoded packets from the
122 // ACM
michaeltbf65be52016-12-15 06:24:49 -0800123 public MixerParticipant, // supplies output mixer with audio frames
124 public OverheadObserver {
kwiberg55b97fe2016-01-28 05:22:45 -0800125 public:
126 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000127
kwiberg55b97fe2016-01-28 05:22:45 -0800128 enum { KNumSocketThreads = 1 };
129 enum { KNumberOfSocketBuffers = 8 };
130 virtual ~Channel();
henrikaec6fbd22017-03-31 05:43:36 -0700131 static int32_t CreateChannel(Channel*& channel,
132 int32_t channelId,
133 uint32_t instanceId,
134 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800135 Channel(int32_t channelId,
136 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700137 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800138 int32_t Init();
kwiberg1c07c702017-03-27 07:15:49 -0700139 void RegisterLegacyReceiveCodecs();
tommi0a2391f2017-03-21 02:31:51 -0700140 void Terminate();
kwiberg55b97fe2016-01-28 05:22:45 -0800141 int32_t SetEngineInformation(Statistics& engineStatistics,
142 OutputMixer& outputMixer,
kwiberg55b97fe2016-01-28 05:22:45 -0800143 ProcessThread& moduleProcessThread,
144 AudioDeviceModule& audioDeviceModule,
145 VoiceEngineObserver* voiceEngineObserver,
henrikaec6fbd22017-03-31 05:43:36 -0700146 rtc::CriticalSection* callbackCritSect,
147 rtc::TaskQueue* encoder_queue);
niklase@google.com470e71d2011-07-07 08:21:25 +0000148
kwibergb7f89d62016-02-17 10:04:18 -0800149 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100150
ossu29b1a8d2016-06-13 07:34:51 -0700151 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
152 // passed into AudioReceiveStream is the same as the one set when creating the
153 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
154 // go.
155 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
156
kwiberg1c07c702017-03-27 07:15:49 -0700157 void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
158
ossu1ffbd6c2017-04-06 12:05:04 -0700159 // Send using this encoder, with this payload type.
160 bool SetEncoder(int payload_type, std::unique_ptr<AudioEncoder> encoder);
ossu20a4b3f2017-04-27 02:08:52 -0700161 void ModifyEncoder(
162 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier);
ossu1ffbd6c2017-04-06 12:05:04 -0700163
kwiberg55b97fe2016-01-28 05:22:45 -0800164 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000165
kwiberg55b97fe2016-01-28 05:22:45 -0800166 // VoEBase
167 int32_t StartPlayout();
168 int32_t StopPlayout();
169 int32_t StartSend();
henrikaec6fbd22017-03-31 05:43:36 -0700170 void StopSend();
kwiberg55b97fe2016-01-28 05:22:45 -0800171 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
172 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000173
kwiberg55b97fe2016-01-28 05:22:45 -0800174 // VoECodec
175 int32_t GetSendCodec(CodecInst& codec);
176 int32_t GetRecCodec(CodecInst& codec);
177 int32_t SetSendCodec(const CodecInst& codec);
minyue78b4d562016-11-30 04:47:39 -0800178 void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
kwiberg55b97fe2016-01-28 05:22:45 -0800179 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
180 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
181 int32_t SetRecPayloadType(const CodecInst& codec);
kwibergd32bf752017-01-19 07:03:59 -0800182 int32_t SetRecPayloadType(int payload_type, const SdpAudioFormat& format);
kwiberg55b97fe2016-01-28 05:22:45 -0800183 int32_t GetRecPayloadType(CodecInst& codec);
184 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
185 int SetOpusMaxPlaybackRate(int frequency_hz);
186 int SetOpusDtx(bool enable_dtx);
ivoc85228d62016-07-27 04:53:47 -0700187 int GetOpusDtx(bool* enabled);
minyue7e304322016-10-12 05:00:55 -0700188 bool EnableAudioNetworkAdaptor(const std::string& config_string);
189 void DisableAudioNetworkAdaptor();
190 void SetReceiverFrameLengthRange(int min_frame_length_ms,
191 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000192
kwiberg55b97fe2016-01-28 05:22:45 -0800193 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700194 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800195 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700196 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800197 size_t length,
198 const PacketTime& packet_time);
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
kwiberg55b97fe2016-01-28 05:22:45 -0800228 // VoERTP_RTCP
229 int SetLocalSSRC(unsigned int ssrc);
230 int GetLocalSSRC(unsigned int& ssrc);
231 int GetRemoteSSRC(unsigned int& ssrc);
232 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
233 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
kwiberg55b97fe2016-01-28 05:22:45 -0800234 void EnableSendTransportSequenceNumber(int id);
235 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100236
stefan7de8d642017-02-07 07:14:08 -0800237 void RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -0700238 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -0800239 RtcpBandwidthObserver* bandwidth_observer);
240 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
nissefdbfdc92017-03-31 05:44:52 -0700241 void ResetSenderCongestionControlObjects();
242 void ResetReceiverCongestionControlObjects();
kwiberg55b97fe2016-01-28 05:22:45 -0800243 void SetRTCPStatus(bool enable);
244 int GetRTCPStatus(bool& enabled);
245 int SetRTCP_CNAME(const char cName[256]);
246 int GetRemoteRTCP_CNAME(char cName[256]);
kwiberg55b97fe2016-01-28 05:22:45 -0800247 int SendApplicationDefinedRTCPPacket(unsigned char subType,
248 unsigned int name,
249 const char* data,
250 unsigned short dataLengthInBytes);
kwiberg55b97fe2016-01-28 05:22:45 -0800251 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
252 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800253 int SetCodecFECStatus(bool enable);
254 bool GetCodecFECStatus();
255 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000256
kwiberg55b97fe2016-01-28 05:22:45 -0800257 // From AudioPacketizationCallback in the ACM
258 int32_t SendData(FrameType frameType,
259 uint8_t payloadType,
260 uint32_t timeStamp,
261 const uint8_t* payloadData,
262 size_t payloadSize,
263 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000264
kwiberg55b97fe2016-01-28 05:22:45 -0800265 // From RtpData in the RTP/RTCP module
266 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
267 size_t payloadSize,
268 const WebRtcRTPHeader* rtpHeader) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000269
kwiberg55b97fe2016-01-28 05:22:45 -0800270 // From RtpFeedback in the RTP/RTCP module
271 int32_t OnInitializeDecoder(int8_t payloadType,
272 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
273 int frequency,
274 size_t channels,
275 uint32_t rate) override;
276 void OnIncomingSSRCChanged(uint32_t ssrc) override;
277 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000278
kwiberg55b97fe2016-01-28 05:22:45 -0800279 // From Transport (called by the RTP/RTCP module)
280 bool SendRtp(const uint8_t* data,
281 size_t len,
282 const PacketOptions& packet_options) override;
283 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000284
kwiberg55b97fe2016-01-28 05:22:45 -0800285 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700286 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
287 int32_t id,
288 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800289 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000290
aleloiaed581a2016-10-20 06:32:39 -0700291 // From AudioMixer::Source.
aleloi6c278492016-10-20 14:24:39 -0700292 AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
293 int sample_rate_hz,
294 AudioFrame* audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700295
kwiberg55b97fe2016-01-28 05:22:45 -0800296 uint32_t InstanceId() const { return _instanceId; }
297 int32_t ChannelId() const { return _channelId; }
298 bool Playing() const { return channel_state_.Get().playing; }
299 bool Sending() const { return channel_state_.Get().sending; }
kwiberg55b97fe2016-01-28 05:22:45 -0800300 bool ExternalTransport() const {
301 rtc::CritScope cs(&_callbackCritSect);
302 return _externalTransport;
303 }
kwiberg55b97fe2016-01-28 05:22:45 -0800304 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
305 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
henrikaec6fbd22017-03-31 05:43:36 -0700306
307 // ProcessAndEncodeAudio() creates an audio frame copy and posts a task
308 // on the shared encoder task queue, wich in turn calls (on the queue)
309 // ProcessAndEncodeAudioOnTaskQueue() where the actual processing of the
310 // audio takes place. The processing mainly consists of encoding and preparing
311 // the result for sending by adding it to a send queue.
312 // The main reason for using a task queue here is to release the native,
313 // OS-specific, audio capture thread as soon as possible to ensure that it
314 // can go back to sleep and be prepared to deliver an new captured audio
315 // packet.
316 void ProcessAndEncodeAudio(const AudioFrame& audio_input);
317
318 // This version of ProcessAndEncodeAudio() is used by PushCaptureData() in
319 // VoEBase and the audio in |audio_data| has not been subject to any APM
320 // processing. Some extra steps are therfore needed when building up the
321 // audio frame copy before using the same task as in the default call to
322 // ProcessAndEncodeAudio(const AudioFrame& audio_input).
323 void ProcessAndEncodeAudio(const int16_t* audio_data,
324 int sample_rate,
325 size_t number_of_frames,
326 size_t number_of_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000327
kwiberg55b97fe2016-01-28 05:22:45 -0800328 // Associate to a send channel.
329 // Used for obtaining RTT for a receive-only channel.
solenberg7602aab2016-11-14 11:30:07 -0800330 void set_associate_send_channel(const ChannelOwner& channel);
kwiberg55b97fe2016-01-28 05:22:45 -0800331 // Disassociate a send channel if it was associated.
332 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200333
ivoc14d5dbe2016-07-04 07:06:55 -0700334 // Set a RtcEventLog logging object.
335 void SetRtcEventLog(RtcEventLog* event_log);
336
michaelt9332b7d2016-11-30 07:51:13 -0800337 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
nisse284542b2017-01-10 08:58:32 -0800338 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800339
michaeltbf65be52016-12-15 06:24:49 -0800340 // From OverheadObserver in the RTP/RTCP module
341 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
342
elad.alond12a8e12017-03-23 11:04:48 -0700343 // The existence of this function alongside OnUplinkPacketLossRate is
344 // a compromise. We want the encoder to be agnostic of the PLR source, but
345 // we also don't want it to receive conflicting information from TWCC and
346 // from RTCP-XR.
347 void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000348
elad.alondadb4dc2017-03-23 15:29:50 -0700349 void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate);
350
hbos8d609f62017-04-10 07:39:05 -0700351 std::vector<RtpSource> GetSources() const {
352 return rtp_receiver_->GetSources();
353 }
354
kwiberg55b97fe2016-01-28 05:22:45 -0800355 private:
henrikaec6fbd22017-03-31 05:43:36 -0700356 class ProcessAndEncodeAudioTask;
elad.alond12a8e12017-03-23 11:04:48 -0700357
henrikaec6fbd22017-03-31 05:43:36 -0700358 void OnUplinkPacketLossRate(float packet_loss_rate);
solenberg8d73f8c2017-03-08 01:52:20 -0800359 bool InputMute() const;
nisse657bab22017-02-21 06:28:10 -0800360 bool OnRtpPacketWithHeader(const uint8_t* received_packet,
361 size_t length,
362 RTPHeader *header);
nisse30e89312017-05-29 08:16:37 -0700363 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length);
364
kwiberg55b97fe2016-01-28 05:22:45 -0800365 bool ReceivePacket(const uint8_t* packet,
366 size_t packet_length,
367 const RTPHeader& header,
368 bool in_order);
kwiberg55b97fe2016-01-28 05:22:45 -0800369 bool IsPacketInOrder(const RTPHeader& header) const;
370 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
371 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800372 void UpdatePlayoutTimestamp(bool rtcp);
kwiberg55b97fe2016-01-28 05:22:45 -0800373 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000374
kwiberg55b97fe2016-01-28 05:22:45 -0800375 int SetSendRtpHeaderExtension(bool enable,
376 RTPExtensionType type,
377 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000378
hbos3fd31fe2017-02-28 05:43:16 -0800379 void UpdateOverheadForEncoder()
danilchapa37de392017-09-09 04:17:22 -0700380 RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
nisse284542b2017-01-10 08:58:32 -0800381
ossue280cde2016-10-12 11:04:10 -0700382 int GetRtpTimestampRateHz() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800383 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000384
henrikaec6fbd22017-03-31 05:43:36 -0700385 // Called on the encoder task queue when a new input audio frame is ready
386 // for encoding.
387 void ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input);
388
389 uint32_t _instanceId;
390 int32_t _channelId;
391
pbosd8de1152016-02-01 09:00:51 -0800392 rtc::CriticalSection _callbackCritSect;
393 rtc::CriticalSection volume_settings_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000394
kwiberg55b97fe2016-01-28 05:22:45 -0800395 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000396
ivoc14d5dbe2016-07-04 07:06:55 -0700397 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
michaelt9332b7d2016-11-30 07:51:13 -0800398 std::unique_ptr<voe::RtcpRttStatsProxy> rtcp_rtt_stats_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200399
kwibergb7f89d62016-02-17 10:04:18 -0800400 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
401 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
402 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
kwibergb7f89d62016-02-17 10:04:18 -0800403 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700404 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800405 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
406 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700407 acm2::CodecManager codec_manager_;
408 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800409 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800410 AudioLevel _outputAudioLevel;
411 bool _externalTransport;
kwiberg55b97fe2016-01-28 05:22:45 -0800412 // Downsamples to the codec rate if necessary.
413 PushResampler<int16_t> input_resampler_;
danilchapa37de392017-09-09 04:17:22 -0700414 uint32_t _timeStamp RTC_ACCESS_ON(encoder_queue_);
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000415
danilchapa37de392017-09-09 04:17:22 -0700416 RemoteNtpTimeEstimator ntp_estimator_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000417
kwiberg55b97fe2016-01-28 05:22:45 -0800418 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700419 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
solenbergfe7dd6d2017-03-11 08:10:43 -0800420
421 rtc::CriticalSection video_sync_lock_;
danilchapa37de392017-09-09 04:17:22 -0700422 uint32_t playout_timestamp_rtp_ RTC_GUARDED_BY(video_sync_lock_);
423 uint32_t playout_delay_ms_ RTC_GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800424 uint16_t send_sequence_number_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000425
pbosd8de1152016-02-01 09:00:51 -0800426 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000427
kwibergb7f89d62016-02-17 10:04:18 -0800428 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800429 // The rtp timestamp of the first played out audio frame.
430 int64_t capture_start_rtp_time_stamp_;
431 // The capture ntp time (in local timebase) of the first played out audio
432 // frame.
danilchapa37de392017-09-09 04:17:22 -0700433 int64_t capture_start_ntp_time_ms_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000434
kwiberg55b97fe2016-01-28 05:22:45 -0800435 // uses
436 Statistics* _engineStatisticsPtr;
437 OutputMixer* _outputMixerPtr;
kwiberg55b97fe2016-01-28 05:22:45 -0800438 ProcessThread* _moduleProcessThreadPtr;
439 AudioDeviceModule* _audioDeviceModulePtr;
440 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
441 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
442 Transport* _transportPtr; // WebRtc socket or external transport
danilchapa37de392017-09-09 04:17:22 -0700443 RmsLevel rms_level_ RTC_ACCESS_ON(encoder_queue_);
444 bool input_mute_ RTC_GUARDED_BY(volume_settings_critsect_);
445 bool previous_frame_muted_ RTC_ACCESS_ON(encoder_queue_);
446 float _outputGain RTC_GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800447 // VoeRTP_RTCP
henrikaec6fbd22017-03-31 05:43:36 -0700448 // TODO(henrika): can today be accessed on the main thread and on the
449 // task queue; hence potential race.
kwiberg55b97fe2016-01-28 05:22:45 -0800450 bool _includeAudioLevelIndication;
danilchapa37de392017-09-09 04:17:22 -0700451 size_t transport_overhead_per_packet_
452 RTC_GUARDED_BY(overhead_per_packet_lock_);
453 size_t rtp_overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_);
hbos3fd31fe2017-02-28 05:43:16 -0800454 rtc::CriticalSection overhead_per_packet_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800455 // VoENetwork
456 AudioFrame::SpeechType _outputSpeechType;
kwiberg55b97fe2016-01-28 05:22:45 -0800457 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800458 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800459 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800460 rtc::CriticalSection assoc_send_channel_lock_;
danilchapa37de392017-09-09 04:17:22 -0700461 ChannelOwner associate_send_channel_ RTC_GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100462
kwiberg55b97fe2016-01-28 05:22:45 -0800463 bool pacing_enabled_;
464 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800465 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
466 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
467 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200468 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700469
470 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
471 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
tommi0a2391f2017-03-21 02:31:51 -0700472
ossu76d29f92017-06-09 07:30:13 -0700473 rtc::Optional<CodecInst> cached_send_codec_;
474
tommi0a2391f2017-03-21 02:31:51 -0700475 rtc::ThreadChecker construction_thread_;
elad.alond12a8e12017-03-23 11:04:48 -0700476
477 const bool use_twcc_plr_for_ana_;
henrikaec6fbd22017-03-31 05:43:36 -0700478
henrika4515fa02017-05-03 08:30:15 -0700479 rtc::CriticalSection encoder_queue_lock_;
480
danilchapa37de392017-09-09 04:17:22 -0700481 bool encoder_queue_is_active_ RTC_GUARDED_BY(encoder_queue_lock_) = false;
henrika4515fa02017-05-03 08:30:15 -0700482
henrikaec6fbd22017-03-31 05:43:36 -0700483 rtc::TaskQueue* encoder_queue_ = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000484};
485
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000486} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000487} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000488
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200489#endif // VOICE_ENGINE_CHANNEL_H_