blob: 9018f9f7a281c7c98473df67f78e3c6120336ec4 [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"
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/include/audio_coding_module.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "modules/audio_processing/rms_level.h"
24#include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
25#include "modules/rtp_rtcp/include/rtp_header_parser.h"
26#include "modules/rtp_rtcp/include/rtp_receiver.h"
27#include "modules/rtp_rtcp/include/rtp_rtcp.h"
28#include "rtc_base/criticalsection.h"
29#include "rtc_base/event.h"
30#include "rtc_base/thread_checker.h"
31#include "voice_engine/audio_level.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "voice_engine/include/voe_base.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "voice_engine/shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000034
wu@webrtc.org94454b72014-06-05 20:34:08 +000035namespace rtc {
wu@webrtc.org94454b72014-06-05 20:34:08 +000036class TimestampWrapAroundHandler;
37}
38
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000039namespace webrtc {
40
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000041class AudioDeviceModule;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010042class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000043class ProcessThread;
Erik Språng737336d2016-07-29 12:59:36 +020044class RateLimiter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000045class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000046class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070047class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000048class RTPPayloadRegistry;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049class RTPReceiverAudio;
nisse657bab22017-02-21 06:28:10 -080050class RtpPacketReceived;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000051class RtpRtcp;
nisseb8f9a322017-03-27 05:36:15 -070052class RtpTransportControllerSendInterface;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000053class TelephoneEventHandler;
niklase@google.com470e71d2011-07-07 08:21:25 +000054
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000055struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
solenbergdd3abbb2017-09-18 07:05:30 -070057struct CallStatistics {
58 unsigned short fractionLost;
59 unsigned int cumulativeLost;
60 unsigned int extendedMax;
61 unsigned int jitterSamples;
62 int64_t rttMs;
63 size_t bytesSent;
64 int packetsSent;
65 size_t bytesReceived;
66 int packetsReceived;
67 // The capture ntp time (in local timebase) of the first played out audio
68 // frame.
69 int64_t capture_start_ntp_time_ms_;
70};
71
72// See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details.
73struct ReportBlock {
74 uint32_t sender_SSRC; // SSRC of sender
75 uint32_t source_SSRC;
76 uint8_t fraction_lost;
77 uint32_t cumulative_num_packets_lost;
78 uint32_t extended_highest_sequence_number;
79 uint32_t interarrival_jitter;
80 uint32_t last_SR_timestamp;
81 uint32_t delay_since_last_SR;
82};
83
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000084namespace voe {
85
ivoc14d5dbe2016-07-04 07:06:55 -070086class RtcEventLogProxy;
michaelt9332b7d2016-11-30 07:51:13 -080087class RtcpRttStatsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010088class RtpPacketSenderProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010089class TransportFeedbackProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010090class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000091class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000092
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000093// Helper class to simplify locking scheme for members that are accessed from
94// multiple threads.
95// Example: a member can be set on thread T1 and read by an internal audio
96// thread T2. Accessing the member via this class ensures that we are
97// safe and also avoid TSan v2 warnings.
98class ChannelState {
99 public:
kwiberg55b97fe2016-01-28 05:22:45 -0800100 struct State {
solenberg11ace152016-09-15 04:29:13 -0700101 bool playing = false;
102 bool sending = false;
kwiberg55b97fe2016-01-28 05:22:45 -0800103 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000104
kwiberg55b97fe2016-01-28 05:22:45 -0800105 ChannelState() {}
106 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000107
kwiberg55b97fe2016-01-28 05:22:45 -0800108 void Reset() {
109 rtc::CritScope lock(&lock_);
110 state_ = State();
111 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000112
kwiberg55b97fe2016-01-28 05:22:45 -0800113 State Get() const {
114 rtc::CritScope lock(&lock_);
115 return state_;
116 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000117
kwiberg55b97fe2016-01-28 05:22:45 -0800118 void SetPlaying(bool enable) {
119 rtc::CritScope lock(&lock_);
120 state_.playing = enable;
121 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000122
kwiberg55b97fe2016-01-28 05:22:45 -0800123 void SetSending(bool enable) {
124 rtc::CritScope lock(&lock_);
125 state_.sending = enable;
126 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000127
kwiberg55b97fe2016-01-28 05:22:45 -0800128 private:
pbosd8de1152016-02-01 09:00:51 -0800129 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800130 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000131};
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
kwiberg55b97fe2016-01-28 05:22:45 -0800133class Channel
134 : public RtpData,
135 public RtpFeedback,
kwiberg55b97fe2016-01-28 05:22:45 -0800136 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800137 public AudioPacketizationCallback, // receive encoded packets from the
138 // ACM
michaeltbf65be52016-12-15 06:24:49 -0800139 public OverheadObserver {
kwiberg55b97fe2016-01-28 05:22:45 -0800140 public:
141 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000142
kwiberg55b97fe2016-01-28 05:22:45 -0800143 enum { KNumSocketThreads = 1 };
144 enum { KNumberOfSocketBuffers = 8 };
145 virtual ~Channel();
henrikaec6fbd22017-03-31 05:43:36 -0700146 static int32_t CreateChannel(Channel*& channel,
147 int32_t channelId,
148 uint32_t instanceId,
149 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800150 Channel(int32_t channelId,
151 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700152 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800153 int32_t Init();
tommi0a2391f2017-03-21 02:31:51 -0700154 void Terminate();
solenberg1c239d42017-09-29 06:00:28 -0700155 int32_t SetEngineInformation(ProcessThread& moduleProcessThread,
kwiberg55b97fe2016-01-28 05:22:45 -0800156 AudioDeviceModule& audioDeviceModule,
henrikaec6fbd22017-03-31 05:43:36 -0700157 rtc::TaskQueue* encoder_queue);
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
kwibergb7f89d62016-02-17 10:04:18 -0800159 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100160
ossu29b1a8d2016-06-13 07:34:51 -0700161 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
162 // passed into AudioReceiveStream is the same as the one set when creating the
163 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
164 // go.
165 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
166
kwiberg1c07c702017-03-27 07:15:49 -0700167 void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
168
ossu1ffbd6c2017-04-06 12:05:04 -0700169 // Send using this encoder, with this payload type.
170 bool SetEncoder(int payload_type, std::unique_ptr<AudioEncoder> encoder);
ossu20a4b3f2017-04-27 02:08:52 -0700171 void ModifyEncoder(
172 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier);
ossu1ffbd6c2017-04-06 12:05:04 -0700173
kwiberg55b97fe2016-01-28 05:22:45 -0800174 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000175
kwiberg55b97fe2016-01-28 05:22:45 -0800176 // VoEBase
177 int32_t StartPlayout();
178 int32_t StopPlayout();
179 int32_t StartSend();
henrikaec6fbd22017-03-31 05:43:36 -0700180 void StopSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
solenberg6dc20382017-09-18 05:22:39 -0700182 // Codecs
kwiberg55b97fe2016-01-28 05:22:45 -0800183 int32_t GetRecCodec(CodecInst& codec);
minyue78b4d562016-11-30 04:47:39 -0800184 void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
minyue7e304322016-10-12 05:00:55 -0700185 bool EnableAudioNetworkAdaptor(const std::string& config_string);
186 void DisableAudioNetworkAdaptor();
187 void SetReceiverFrameLengthRange(int min_frame_length_ms,
188 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
solenberg946d8862017-09-21 04:02:53 -0700190 // Network
solenberg1c239d42017-09-29 06:00:28 -0700191 void RegisterTransport(Transport* transport);
nisse657bab22017-02-21 06:28:10 -0800192 // TODO(nisse, solenberg): Delete when VoENetwork is deleted.
mflodman3d7db262016-04-29 00:57:13 -0700193 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
nisse657bab22017-02-21 06:28:10 -0800194 void OnRtpPacket(const RtpPacketReceived& packet);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000195
solenberg8d73f8c2017-03-08 01:52:20 -0800196 // Muting, Volume and Level.
197 void SetInputMute(bool enable);
198 void SetChannelOutputVolumeScaling(float scaling);
199 int GetSpeechOutputLevel() const;
200 int GetSpeechOutputLevelFullRange() const;
zsteine76bd3a2017-07-14 12:17:49 -0700201 // See description of "totalAudioEnergy" in the WebRTC stats spec:
202 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
203 double GetTotalOutputEnergy() const;
204 double GetTotalOutputDuration() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000205
solenbergc6192a92017-03-13 02:36:19 -0700206 // Stats.
kwiberg55b97fe2016-01-28 05:22:45 -0800207 int GetNetworkStatistics(NetworkStatistics& stats);
208 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
ivoce1198e02017-09-08 08:13:19 -0700209 ANAStats GetANAStatistics() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
solenbergc6192a92017-03-13 02:36:19 -0700211 // Audio+Video Sync.
kwiberg55b97fe2016-01-28 05:22:45 -0800212 uint32_t GetDelayEstimate() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800213 int SetMinimumPlayoutDelay(int delayMs);
214 int GetPlayoutTimestamp(unsigned int& timestamp);
kwiberg55b97fe2016-01-28 05:22:45 -0800215 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000216
solenbergc6192a92017-03-13 02:36:19 -0700217 // DTMF.
solenberg8842c3e2016-03-11 03:06:41 -0800218 int SendTelephoneEventOutband(int event, int duration_ms);
solenbergffbbcac2016-11-17 05:25:37 -0800219 int SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000220
solenbergdd3abbb2017-09-18 07:05:30 -0700221 // RTP+RTCP
kwiberg55b97fe2016-01-28 05:22:45 -0800222 int SetLocalSSRC(unsigned int ssrc);
kwiberg55b97fe2016-01-28 05:22:45 -0800223 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
224 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
kwiberg55b97fe2016-01-28 05:22:45 -0800225 void EnableSendTransportSequenceNumber(int id);
226 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100227
stefan7de8d642017-02-07 07:14:08 -0800228 void RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -0700229 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -0800230 RtcpBandwidthObserver* bandwidth_observer);
231 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
nissefdbfdc92017-03-31 05:44:52 -0700232 void ResetSenderCongestionControlObjects();
233 void ResetReceiverCongestionControlObjects();
kwiberg55b97fe2016-01-28 05:22:45 -0800234 void SetRTCPStatus(bool enable);
kwiberg55b97fe2016-01-28 05:22:45 -0800235 int SetRTCP_CNAME(const char cName[256]);
kwiberg55b97fe2016-01-28 05:22:45 -0800236 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
237 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800238 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000239
kwiberg55b97fe2016-01-28 05:22:45 -0800240 // From AudioPacketizationCallback in the ACM
241 int32_t SendData(FrameType frameType,
242 uint8_t payloadType,
243 uint32_t timeStamp,
244 const uint8_t* payloadData,
245 size_t payloadSize,
246 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000247
kwiberg55b97fe2016-01-28 05:22:45 -0800248 // From RtpData in the RTP/RTCP module
249 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
250 size_t payloadSize,
251 const WebRtcRTPHeader* rtpHeader) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000252
kwiberg55b97fe2016-01-28 05:22:45 -0800253 // From RtpFeedback in the RTP/RTCP module
Karl Wibergc62f6c72017-10-04 12:38:53 +0200254 int32_t OnInitializeDecoder(int payload_type,
255 const SdpAudioFormat& audio_format,
kwiberg55b97fe2016-01-28 05:22:45 -0800256 uint32_t rate) override;
257 void OnIncomingSSRCChanged(uint32_t ssrc) override;
258 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000259
kwiberg55b97fe2016-01-28 05:22:45 -0800260 // From Transport (called by the RTP/RTCP module)
261 bool SendRtp(const uint8_t* data,
262 size_t len,
263 const PacketOptions& packet_options) override;
264 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000265
aleloiaed581a2016-10-20 06:32:39 -0700266 // From AudioMixer::Source.
aleloi6c278492016-10-20 14:24:39 -0700267 AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
268 int sample_rate_hz,
269 AudioFrame* audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700270
solenberg2397b9a2017-09-22 06:48:10 -0700271 int PreferredSampleRate() const;
272
kwiberg55b97fe2016-01-28 05:22:45 -0800273 uint32_t InstanceId() const { return _instanceId; }
274 int32_t ChannelId() const { return _channelId; }
275 bool Playing() const { return channel_state_.Get().playing; }
276 bool Sending() const { return channel_state_.Get().sending; }
kwiberg55b97fe2016-01-28 05:22:45 -0800277 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
278 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
henrikaec6fbd22017-03-31 05:43:36 -0700279
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100280 // ProcessAndEncodeAudio() posts a task on the shared encoder task queue,
281 // which in turn calls (on the queue) ProcessAndEncodeAudioOnTaskQueue() where
282 // the actual processing of the audio takes place. The processing mainly
283 // consists of encoding and preparing the result for sending by adding it to a
284 // send queue.
henrikaec6fbd22017-03-31 05:43:36 -0700285 // The main reason for using a task queue here is to release the native,
286 // OS-specific, audio capture thread as soon as possible to ensure that it
287 // can go back to sleep and be prepared to deliver an new captured audio
288 // packet.
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100289 void ProcessAndEncodeAudio(std::unique_ptr<AudioFrame> audio_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +0000290
kwiberg55b97fe2016-01-28 05:22:45 -0800291 // Associate to a send channel.
292 // Used for obtaining RTT for a receive-only channel.
solenberg7602aab2016-11-14 11:30:07 -0800293 void set_associate_send_channel(const ChannelOwner& channel);
kwiberg55b97fe2016-01-28 05:22:45 -0800294 // Disassociate a send channel if it was associated.
295 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200296
ivoc14d5dbe2016-07-04 07:06:55 -0700297 // Set a RtcEventLog logging object.
298 void SetRtcEventLog(RtcEventLog* event_log);
299
michaelt9332b7d2016-11-30 07:51:13 -0800300 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
nisse284542b2017-01-10 08:58:32 -0800301 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800302
michaeltbf65be52016-12-15 06:24:49 -0800303 // From OverheadObserver in the RTP/RTCP module
304 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
305
elad.alond12a8e12017-03-23 11:04:48 -0700306 // The existence of this function alongside OnUplinkPacketLossRate is
307 // a compromise. We want the encoder to be agnostic of the PLR source, but
308 // we also don't want it to receive conflicting information from TWCC and
309 // from RTCP-XR.
310 void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000311
elad.alondadb4dc2017-03-23 15:29:50 -0700312 void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate);
313
hbos8d609f62017-04-10 07:39:05 -0700314 std::vector<RtpSource> GetSources() const {
315 return rtp_receiver_->GetSources();
316 }
317
kwiberg55b97fe2016-01-28 05:22:45 -0800318 private:
henrikaec6fbd22017-03-31 05:43:36 -0700319 class ProcessAndEncodeAudioTask;
elad.alond12a8e12017-03-23 11:04:48 -0700320
solenbergdd3abbb2017-09-18 07:05:30 -0700321 int GetRemoteSSRC(unsigned int& ssrc);
henrikaec6fbd22017-03-31 05:43:36 -0700322 void OnUplinkPacketLossRate(float packet_loss_rate);
solenberg8d73f8c2017-03-08 01:52:20 -0800323 bool InputMute() const;
nisse30e89312017-05-29 08:16:37 -0700324 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length);
325
kwiberg55b97fe2016-01-28 05:22:45 -0800326 bool ReceivePacket(const uint8_t* packet,
327 size_t packet_length,
Niels Möller22ec9522017-10-05 08:39:15 +0200328 const RTPHeader& header);
kwiberg55b97fe2016-01-28 05:22:45 -0800329 bool IsPacketInOrder(const RTPHeader& header) const;
330 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
331 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800332 void UpdatePlayoutTimestamp(bool rtcp);
kwiberg55b97fe2016-01-28 05:22:45 -0800333 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000334
kwiberg55b97fe2016-01-28 05:22:45 -0800335 int SetSendRtpHeaderExtension(bool enable,
336 RTPExtensionType type,
337 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000338
hbos3fd31fe2017-02-28 05:43:16 -0800339 void UpdateOverheadForEncoder()
danilchapa37de392017-09-09 04:17:22 -0700340 RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
nisse284542b2017-01-10 08:58:32 -0800341
ossue280cde2016-10-12 11:04:10 -0700342 int GetRtpTimestampRateHz() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800343 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000344
henrikaec6fbd22017-03-31 05:43:36 -0700345 // Called on the encoder task queue when a new input audio frame is ready
346 // for encoding.
347 void ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input);
348
349 uint32_t _instanceId;
350 int32_t _channelId;
351
pbosd8de1152016-02-01 09:00:51 -0800352 rtc::CriticalSection _callbackCritSect;
353 rtc::CriticalSection volume_settings_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000354
kwiberg55b97fe2016-01-28 05:22:45 -0800355 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000356
ivoc14d5dbe2016-07-04 07:06:55 -0700357 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
michaelt9332b7d2016-11-30 07:51:13 -0800358 std::unique_ptr<voe::RtcpRttStatsProxy> rtcp_rtt_stats_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200359
kwibergb7f89d62016-02-17 10:04:18 -0800360 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
361 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
362 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
kwibergb7f89d62016-02-17 10:04:18 -0800363 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700364 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800365 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
366 std::unique_ptr<AudioCodingModule> audio_coding_;
367 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800368 AudioLevel _outputAudioLevel;
danilchapa37de392017-09-09 04:17:22 -0700369 uint32_t _timeStamp RTC_ACCESS_ON(encoder_queue_);
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000370
danilchapa37de392017-09-09 04:17:22 -0700371 RemoteNtpTimeEstimator ntp_estimator_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000372
kwiberg55b97fe2016-01-28 05:22:45 -0800373 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700374 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
solenbergfe7dd6d2017-03-11 08:10:43 -0800375
376 rtc::CriticalSection video_sync_lock_;
danilchapa37de392017-09-09 04:17:22 -0700377 uint32_t playout_timestamp_rtp_ RTC_GUARDED_BY(video_sync_lock_);
378 uint32_t playout_delay_ms_ RTC_GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800379 uint16_t send_sequence_number_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000380
pbosd8de1152016-02-01 09:00:51 -0800381 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000382
kwibergb7f89d62016-02-17 10:04:18 -0800383 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800384 // The rtp timestamp of the first played out audio frame.
385 int64_t capture_start_rtp_time_stamp_;
386 // The capture ntp time (in local timebase) of the first played out audio
387 // frame.
danilchapa37de392017-09-09 04:17:22 -0700388 int64_t capture_start_ntp_time_ms_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000389
kwiberg55b97fe2016-01-28 05:22:45 -0800390 // uses
kwiberg55b97fe2016-01-28 05:22:45 -0800391 ProcessThread* _moduleProcessThreadPtr;
392 AudioDeviceModule* _audioDeviceModulePtr;
kwiberg55b97fe2016-01-28 05:22:45 -0800393 Transport* _transportPtr; // WebRtc socket or external transport
danilchapa37de392017-09-09 04:17:22 -0700394 RmsLevel rms_level_ RTC_ACCESS_ON(encoder_queue_);
395 bool input_mute_ RTC_GUARDED_BY(volume_settings_critsect_);
396 bool previous_frame_muted_ RTC_ACCESS_ON(encoder_queue_);
397 float _outputGain RTC_GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800398 // VoeRTP_RTCP
henrikaec6fbd22017-03-31 05:43:36 -0700399 // TODO(henrika): can today be accessed on the main thread and on the
400 // task queue; hence potential race.
kwiberg55b97fe2016-01-28 05:22:45 -0800401 bool _includeAudioLevelIndication;
danilchapa37de392017-09-09 04:17:22 -0700402 size_t transport_overhead_per_packet_
403 RTC_GUARDED_BY(overhead_per_packet_lock_);
404 size_t rtp_overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_);
hbos3fd31fe2017-02-28 05:43:16 -0800405 rtc::CriticalSection overhead_per_packet_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800406 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800407 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800408 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800409 rtc::CriticalSection assoc_send_channel_lock_;
danilchapa37de392017-09-09 04:17:22 -0700410 ChannelOwner associate_send_channel_ RTC_GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100411
kwiberg55b97fe2016-01-28 05:22:45 -0800412 bool pacing_enabled_;
413 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800414 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
415 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
416 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200417 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700418
419 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
420 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
tommi0a2391f2017-03-21 02:31:51 -0700421
422 rtc::ThreadChecker construction_thread_;
elad.alond12a8e12017-03-23 11:04:48 -0700423
424 const bool use_twcc_plr_for_ana_;
henrikaec6fbd22017-03-31 05:43:36 -0700425
henrika4515fa02017-05-03 08:30:15 -0700426 rtc::CriticalSection encoder_queue_lock_;
427
danilchapa37de392017-09-09 04:17:22 -0700428 bool encoder_queue_is_active_ RTC_GUARDED_BY(encoder_queue_lock_) = false;
henrika4515fa02017-05-03 08:30:15 -0700429
henrikaec6fbd22017-03-31 05:43:36 -0700430 rtc::TaskQueue* encoder_queue_ = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000431};
432
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000433} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000434} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000435
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200436#endif // VOICE_ENGINE_CHANNEL_H_