blob: 53b8cd0ce394c51fb1846e7ba2c6ffd9189e4fe2 [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/acm2/codec_manager.h"
24#include "modules/audio_coding/acm2/rent_a_codec.h"
25#include "modules/audio_coding/include/audio_coding_module.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#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"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "voice_engine/shared_data.h"
37#include "voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000038
wu@webrtc.org94454b72014-06-05 20:34:08 +000039namespace rtc {
wu@webrtc.org94454b72014-06-05 20:34:08 +000040class TimestampWrapAroundHandler;
41}
42
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000043namespace webrtc {
44
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000045class AudioDeviceModule;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010046class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000047class ProcessThread;
Erik Språng737336d2016-07-29 12:59:36 +020048class RateLimiter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000050class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070051class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000052class RTPPayloadRegistry;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000053class RTPReceiverAudio;
nisse657bab22017-02-21 06:28:10 -080054class RtpPacketReceived;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000055class RtpRtcp;
nisseb8f9a322017-03-27 05:36:15 -070056class RtpTransportControllerSendInterface;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000057class TelephoneEventHandler;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000058class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000059
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000060struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
solenbergdd3abbb2017-09-18 07:05:30 -070062struct CallStatistics {
63 unsigned short fractionLost;
64 unsigned int cumulativeLost;
65 unsigned int extendedMax;
66 unsigned int jitterSamples;
67 int64_t rttMs;
68 size_t bytesSent;
69 int packetsSent;
70 size_t bytesReceived;
71 int packetsReceived;
72 // The capture ntp time (in local timebase) of the first played out audio
73 // frame.
74 int64_t capture_start_ntp_time_ms_;
75};
76
77// See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details.
78struct ReportBlock {
79 uint32_t sender_SSRC; // SSRC of sender
80 uint32_t source_SSRC;
81 uint8_t fraction_lost;
82 uint32_t cumulative_num_packets_lost;
83 uint32_t extended_highest_sequence_number;
84 uint32_t interarrival_jitter;
85 uint32_t last_SR_timestamp;
86 uint32_t delay_since_last_SR;
87};
88
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000089namespace voe {
90
ivoc14d5dbe2016-07-04 07:06:55 -070091class RtcEventLogProxy;
michaelt9332b7d2016-11-30 07:51:13 -080092class RtcpRttStatsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010093class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000094class Statistics;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010095class TransportFeedbackProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010096class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000097class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000098
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000099// Helper class to simplify locking scheme for members that are accessed from
100// multiple threads.
101// Example: a member can be set on thread T1 and read by an internal audio
102// thread T2. Accessing the member via this class ensures that we are
103// safe and also avoid TSan v2 warnings.
104class ChannelState {
105 public:
kwiberg55b97fe2016-01-28 05:22:45 -0800106 struct State {
solenberg11ace152016-09-15 04:29:13 -0700107 bool playing = false;
108 bool sending = false;
kwiberg55b97fe2016-01-28 05:22:45 -0800109 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000110
kwiberg55b97fe2016-01-28 05:22:45 -0800111 ChannelState() {}
112 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000113
kwiberg55b97fe2016-01-28 05:22:45 -0800114 void Reset() {
115 rtc::CritScope lock(&lock_);
116 state_ = State();
117 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000118
kwiberg55b97fe2016-01-28 05:22:45 -0800119 State Get() const {
120 rtc::CritScope lock(&lock_);
121 return state_;
122 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000123
kwiberg55b97fe2016-01-28 05:22:45 -0800124 void SetPlaying(bool enable) {
125 rtc::CritScope lock(&lock_);
126 state_.playing = enable;
127 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000128
kwiberg55b97fe2016-01-28 05:22:45 -0800129 void SetSending(bool enable) {
130 rtc::CritScope lock(&lock_);
131 state_.sending = enable;
132 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000133
kwiberg55b97fe2016-01-28 05:22:45 -0800134 private:
pbosd8de1152016-02-01 09:00:51 -0800135 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800136 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000137};
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
kwiberg55b97fe2016-01-28 05:22:45 -0800139class Channel
140 : public RtpData,
141 public RtpFeedback,
kwiberg55b97fe2016-01-28 05:22:45 -0800142 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800143 public AudioPacketizationCallback, // receive encoded packets from the
144 // ACM
michaeltbf65be52016-12-15 06:24:49 -0800145 public OverheadObserver {
kwiberg55b97fe2016-01-28 05:22:45 -0800146 public:
147 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000148
kwiberg55b97fe2016-01-28 05:22:45 -0800149 enum { KNumSocketThreads = 1 };
150 enum { KNumberOfSocketBuffers = 8 };
151 virtual ~Channel();
henrikaec6fbd22017-03-31 05:43:36 -0700152 static int32_t CreateChannel(Channel*& channel,
153 int32_t channelId,
154 uint32_t instanceId,
155 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800156 Channel(int32_t channelId,
157 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700158 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800159 int32_t Init();
tommi0a2391f2017-03-21 02:31:51 -0700160 void Terminate();
kwiberg55b97fe2016-01-28 05:22:45 -0800161 int32_t SetEngineInformation(Statistics& engineStatistics,
kwiberg55b97fe2016-01-28 05:22:45 -0800162 ProcessThread& moduleProcessThread,
163 AudioDeviceModule& audioDeviceModule,
164 VoiceEngineObserver* voiceEngineObserver,
henrikaec6fbd22017-03-31 05:43:36 -0700165 rtc::CriticalSection* callbackCritSect,
166 rtc::TaskQueue* encoder_queue);
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
kwibergb7f89d62016-02-17 10:04:18 -0800168 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100169
ossu29b1a8d2016-06-13 07:34:51 -0700170 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
171 // passed into AudioReceiveStream is the same as the one set when creating the
172 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
173 // go.
174 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
175
kwiberg1c07c702017-03-27 07:15:49 -0700176 void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
177
ossu1ffbd6c2017-04-06 12:05:04 -0700178 // Send using this encoder, with this payload type.
179 bool SetEncoder(int payload_type, std::unique_ptr<AudioEncoder> encoder);
ossu20a4b3f2017-04-27 02:08:52 -0700180 void ModifyEncoder(
181 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier);
ossu1ffbd6c2017-04-06 12:05:04 -0700182
kwiberg55b97fe2016-01-28 05:22:45 -0800183 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000184
kwiberg55b97fe2016-01-28 05:22:45 -0800185 // VoEBase
186 int32_t StartPlayout();
187 int32_t StopPlayout();
188 int32_t StartSend();
henrikaec6fbd22017-03-31 05:43:36 -0700189 void StopSend();
kwiberg55b97fe2016-01-28 05:22:45 -0800190 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
191 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000192
solenberg6dc20382017-09-18 05:22:39 -0700193 // Codecs
kwiberg55b97fe2016-01-28 05:22:45 -0800194 int32_t GetSendCodec(CodecInst& codec);
195 int32_t GetRecCodec(CodecInst& codec);
196 int32_t SetSendCodec(const CodecInst& codec);
minyue78b4d562016-11-30 04:47:39 -0800197 void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
minyue7e304322016-10-12 05:00:55 -0700198 bool EnableAudioNetworkAdaptor(const std::string& config_string);
199 void DisableAudioNetworkAdaptor();
200 void SetReceiverFrameLengthRange(int min_frame_length_ms,
201 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
solenberg946d8862017-09-21 04:02:53 -0700203 // Network
mflodman3d7db262016-04-29 00:57:13 -0700204 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800205 int32_t DeRegisterExternalTransport();
nisse657bab22017-02-21 06:28:10 -0800206 // TODO(nisse, solenberg): Delete when VoENetwork is deleted.
mflodman3d7db262016-04-29 00:57:13 -0700207 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
nisse657bab22017-02-21 06:28:10 -0800208 void OnRtpPacket(const RtpPacketReceived& packet);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000209
solenberg8d73f8c2017-03-08 01:52:20 -0800210 // Muting, Volume and Level.
211 void SetInputMute(bool enable);
212 void SetChannelOutputVolumeScaling(float scaling);
213 int GetSpeechOutputLevel() const;
214 int GetSpeechOutputLevelFullRange() const;
zsteine76bd3a2017-07-14 12:17:49 -0700215 // See description of "totalAudioEnergy" in the WebRTC stats spec:
216 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
217 double GetTotalOutputEnergy() const;
218 double GetTotalOutputDuration() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000219
solenbergc6192a92017-03-13 02:36:19 -0700220 // Stats.
kwiberg55b97fe2016-01-28 05:22:45 -0800221 int GetNetworkStatistics(NetworkStatistics& stats);
222 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
ivoce1198e02017-09-08 08:13:19 -0700223 ANAStats GetANAStatistics() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000224
solenbergc6192a92017-03-13 02:36:19 -0700225 // Audio+Video Sync.
kwiberg55b97fe2016-01-28 05:22:45 -0800226 uint32_t GetDelayEstimate() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800227 int SetMinimumPlayoutDelay(int delayMs);
228 int GetPlayoutTimestamp(unsigned int& timestamp);
kwiberg55b97fe2016-01-28 05:22:45 -0800229 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000230
solenbergc6192a92017-03-13 02:36:19 -0700231 // DTMF.
solenberg8842c3e2016-03-11 03:06:41 -0800232 int SendTelephoneEventOutband(int event, int duration_ms);
solenbergffbbcac2016-11-17 05:25:37 -0800233 int SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000234
solenbergdd3abbb2017-09-18 07:05:30 -0700235 // RTP+RTCP
kwiberg55b97fe2016-01-28 05:22:45 -0800236 int SetLocalSSRC(unsigned int ssrc);
kwiberg55b97fe2016-01-28 05:22:45 -0800237 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
238 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
kwiberg55b97fe2016-01-28 05:22:45 -0800239 void EnableSendTransportSequenceNumber(int id);
240 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100241
stefan7de8d642017-02-07 07:14:08 -0800242 void RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -0700243 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -0800244 RtcpBandwidthObserver* bandwidth_observer);
245 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
nissefdbfdc92017-03-31 05:44:52 -0700246 void ResetSenderCongestionControlObjects();
247 void ResetReceiverCongestionControlObjects();
kwiberg55b97fe2016-01-28 05:22:45 -0800248 void SetRTCPStatus(bool enable);
kwiberg55b97fe2016-01-28 05:22:45 -0800249 int SetRTCP_CNAME(const char cName[256]);
kwiberg55b97fe2016-01-28 05:22:45 -0800250 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
251 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800252 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
kwiberg55b97fe2016-01-28 05:22:45 -0800254 // From AudioPacketizationCallback in the ACM
255 int32_t SendData(FrameType frameType,
256 uint8_t payloadType,
257 uint32_t timeStamp,
258 const uint8_t* payloadData,
259 size_t payloadSize,
260 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000261
kwiberg55b97fe2016-01-28 05:22:45 -0800262 // From RtpData in the RTP/RTCP module
263 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
264 size_t payloadSize,
265 const WebRtcRTPHeader* rtpHeader) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000266
kwiberg55b97fe2016-01-28 05:22:45 -0800267 // From RtpFeedback in the RTP/RTCP module
268 int32_t OnInitializeDecoder(int8_t payloadType,
269 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
270 int frequency,
271 size_t channels,
272 uint32_t rate) override;
273 void OnIncomingSSRCChanged(uint32_t ssrc) override;
274 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000275
kwiberg55b97fe2016-01-28 05:22:45 -0800276 // From Transport (called by the RTP/RTCP module)
277 bool SendRtp(const uint8_t* data,
278 size_t len,
279 const PacketOptions& packet_options) override;
280 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000281
aleloiaed581a2016-10-20 06:32:39 -0700282 // From AudioMixer::Source.
aleloi6c278492016-10-20 14:24:39 -0700283 AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
284 int sample_rate_hz,
285 AudioFrame* audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700286
solenberg2397b9a2017-09-22 06:48:10 -0700287 int PreferredSampleRate() const;
288
kwiberg55b97fe2016-01-28 05:22:45 -0800289 uint32_t InstanceId() const { return _instanceId; }
290 int32_t ChannelId() const { return _channelId; }
291 bool Playing() const { return channel_state_.Get().playing; }
292 bool Sending() const { return channel_state_.Get().sending; }
kwiberg55b97fe2016-01-28 05:22:45 -0800293 bool ExternalTransport() const {
294 rtc::CritScope cs(&_callbackCritSect);
295 return _externalTransport;
296 }
kwiberg55b97fe2016-01-28 05:22:45 -0800297 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
298 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
henrikaec6fbd22017-03-31 05:43:36 -0700299
300 // ProcessAndEncodeAudio() creates an audio frame copy and posts a task
301 // on the shared encoder task queue, wich in turn calls (on the queue)
302 // ProcessAndEncodeAudioOnTaskQueue() where the actual processing of the
303 // audio takes place. The processing mainly consists of encoding and preparing
304 // the result for sending by adding it to a send queue.
305 // The main reason for using a task queue here is to release the native,
306 // OS-specific, audio capture thread as soon as possible to ensure that it
307 // can go back to sleep and be prepared to deliver an new captured audio
308 // packet.
309 void ProcessAndEncodeAudio(const AudioFrame& audio_input);
310
311 // This version of ProcessAndEncodeAudio() is used by PushCaptureData() in
312 // VoEBase and the audio in |audio_data| has not been subject to any APM
313 // processing. Some extra steps are therfore needed when building up the
314 // audio frame copy before using the same task as in the default call to
315 // ProcessAndEncodeAudio(const AudioFrame& audio_input).
316 void ProcessAndEncodeAudio(const int16_t* audio_data,
317 int sample_rate,
318 size_t number_of_frames,
319 size_t number_of_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000320
kwiberg55b97fe2016-01-28 05:22:45 -0800321 // Associate to a send channel.
322 // Used for obtaining RTT for a receive-only channel.
solenberg7602aab2016-11-14 11:30:07 -0800323 void set_associate_send_channel(const ChannelOwner& channel);
kwiberg55b97fe2016-01-28 05:22:45 -0800324 // Disassociate a send channel if it was associated.
325 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200326
ivoc14d5dbe2016-07-04 07:06:55 -0700327 // Set a RtcEventLog logging object.
328 void SetRtcEventLog(RtcEventLog* event_log);
329
michaelt9332b7d2016-11-30 07:51:13 -0800330 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
nisse284542b2017-01-10 08:58:32 -0800331 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800332
michaeltbf65be52016-12-15 06:24:49 -0800333 // From OverheadObserver in the RTP/RTCP module
334 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
335
elad.alond12a8e12017-03-23 11:04:48 -0700336 // The existence of this function alongside OnUplinkPacketLossRate is
337 // a compromise. We want the encoder to be agnostic of the PLR source, but
338 // we also don't want it to receive conflicting information from TWCC and
339 // from RTCP-XR.
340 void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000341
elad.alondadb4dc2017-03-23 15:29:50 -0700342 void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate);
343
hbos8d609f62017-04-10 07:39:05 -0700344 std::vector<RtpSource> GetSources() const {
345 return rtp_receiver_->GetSources();
346 }
347
kwiberg55b97fe2016-01-28 05:22:45 -0800348 private:
henrikaec6fbd22017-03-31 05:43:36 -0700349 class ProcessAndEncodeAudioTask;
elad.alond12a8e12017-03-23 11:04:48 -0700350
solenbergdd3abbb2017-09-18 07:05:30 -0700351 int GetRemoteSSRC(unsigned int& ssrc);
henrikaec6fbd22017-03-31 05:43:36 -0700352 void OnUplinkPacketLossRate(float packet_loss_rate);
solenberg8d73f8c2017-03-08 01:52:20 -0800353 bool InputMute() const;
nisse30e89312017-05-29 08:16:37 -0700354 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length);
355
kwiberg55b97fe2016-01-28 05:22:45 -0800356 bool ReceivePacket(const uint8_t* packet,
357 size_t packet_length,
358 const RTPHeader& header,
359 bool in_order);
kwiberg55b97fe2016-01-28 05:22:45 -0800360 bool IsPacketInOrder(const RTPHeader& header) const;
361 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
362 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800363 void UpdatePlayoutTimestamp(bool rtcp);
kwiberg55b97fe2016-01-28 05:22:45 -0800364 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000365
kwiberg55b97fe2016-01-28 05:22:45 -0800366 int SetSendRtpHeaderExtension(bool enable,
367 RTPExtensionType type,
368 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000369
hbos3fd31fe2017-02-28 05:43:16 -0800370 void UpdateOverheadForEncoder()
danilchapa37de392017-09-09 04:17:22 -0700371 RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
nisse284542b2017-01-10 08:58:32 -0800372
ossue280cde2016-10-12 11:04:10 -0700373 int GetRtpTimestampRateHz() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800374 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000375
henrikaec6fbd22017-03-31 05:43:36 -0700376 // Called on the encoder task queue when a new input audio frame is ready
377 // for encoding.
378 void ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input);
379
380 uint32_t _instanceId;
381 int32_t _channelId;
382
pbosd8de1152016-02-01 09:00:51 -0800383 rtc::CriticalSection _callbackCritSect;
384 rtc::CriticalSection volume_settings_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000385
kwiberg55b97fe2016-01-28 05:22:45 -0800386 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000387
ivoc14d5dbe2016-07-04 07:06:55 -0700388 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
michaelt9332b7d2016-11-30 07:51:13 -0800389 std::unique_ptr<voe::RtcpRttStatsProxy> rtcp_rtt_stats_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200390
kwibergb7f89d62016-02-17 10:04:18 -0800391 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
392 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
393 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
kwibergb7f89d62016-02-17 10:04:18 -0800394 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700395 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800396 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
397 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700398 acm2::CodecManager codec_manager_;
399 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800400 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800401 AudioLevel _outputAudioLevel;
402 bool _externalTransport;
kwiberg55b97fe2016-01-28 05:22:45 -0800403 // Downsamples to the codec rate if necessary.
404 PushResampler<int16_t> input_resampler_;
danilchapa37de392017-09-09 04:17:22 -0700405 uint32_t _timeStamp RTC_ACCESS_ON(encoder_queue_);
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000406
danilchapa37de392017-09-09 04:17:22 -0700407 RemoteNtpTimeEstimator ntp_estimator_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000408
kwiberg55b97fe2016-01-28 05:22:45 -0800409 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700410 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
solenbergfe7dd6d2017-03-11 08:10:43 -0800411
412 rtc::CriticalSection video_sync_lock_;
danilchapa37de392017-09-09 04:17:22 -0700413 uint32_t playout_timestamp_rtp_ RTC_GUARDED_BY(video_sync_lock_);
414 uint32_t playout_delay_ms_ RTC_GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800415 uint16_t send_sequence_number_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000416
pbosd8de1152016-02-01 09:00:51 -0800417 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000418
kwibergb7f89d62016-02-17 10:04:18 -0800419 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800420 // The rtp timestamp of the first played out audio frame.
421 int64_t capture_start_rtp_time_stamp_;
422 // The capture ntp time (in local timebase) of the first played out audio
423 // frame.
danilchapa37de392017-09-09 04:17:22 -0700424 int64_t capture_start_ntp_time_ms_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000425
kwiberg55b97fe2016-01-28 05:22:45 -0800426 // uses
427 Statistics* _engineStatisticsPtr;
kwiberg55b97fe2016-01-28 05:22:45 -0800428 ProcessThread* _moduleProcessThreadPtr;
429 AudioDeviceModule* _audioDeviceModulePtr;
430 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
431 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
432 Transport* _transportPtr; // WebRtc socket or external transport
danilchapa37de392017-09-09 04:17:22 -0700433 RmsLevel rms_level_ RTC_ACCESS_ON(encoder_queue_);
434 bool input_mute_ RTC_GUARDED_BY(volume_settings_critsect_);
435 bool previous_frame_muted_ RTC_ACCESS_ON(encoder_queue_);
436 float _outputGain RTC_GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800437 // VoeRTP_RTCP
henrikaec6fbd22017-03-31 05:43:36 -0700438 // TODO(henrika): can today be accessed on the main thread and on the
439 // task queue; hence potential race.
kwiberg55b97fe2016-01-28 05:22:45 -0800440 bool _includeAudioLevelIndication;
danilchapa37de392017-09-09 04:17:22 -0700441 size_t transport_overhead_per_packet_
442 RTC_GUARDED_BY(overhead_per_packet_lock_);
443 size_t rtp_overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_);
hbos3fd31fe2017-02-28 05:43:16 -0800444 rtc::CriticalSection overhead_per_packet_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800445 // VoENetwork
446 AudioFrame::SpeechType _outputSpeechType;
kwiberg55b97fe2016-01-28 05:22:45 -0800447 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800448 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800449 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800450 rtc::CriticalSection assoc_send_channel_lock_;
danilchapa37de392017-09-09 04:17:22 -0700451 ChannelOwner associate_send_channel_ RTC_GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100452
kwiberg55b97fe2016-01-28 05:22:45 -0800453 bool pacing_enabled_;
454 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800455 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
456 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
457 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200458 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700459
460 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
461 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
tommi0a2391f2017-03-21 02:31:51 -0700462
ossu76d29f92017-06-09 07:30:13 -0700463 rtc::Optional<CodecInst> cached_send_codec_;
464
tommi0a2391f2017-03-21 02:31:51 -0700465 rtc::ThreadChecker construction_thread_;
elad.alond12a8e12017-03-23 11:04:48 -0700466
467 const bool use_twcc_plr_for_ana_;
henrikaec6fbd22017-03-31 05:43:36 -0700468
henrika4515fa02017-05-03 08:30:15 -0700469 rtc::CriticalSection encoder_queue_lock_;
470
danilchapa37de392017-09-09 04:17:22 -0700471 bool encoder_queue_is_active_ RTC_GUARDED_BY(encoder_queue_lock_) = false;
henrika4515fa02017-05-03 08:30:15 -0700472
henrikaec6fbd22017-03-31 05:43:36 -0700473 rtc::TaskQueue* encoder_queue_ = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000474};
475
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000476} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000477} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000478
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200479#endif // VOICE_ENGINE_CHANNEL_H_