blob: a4761c6fc9cd9ee5f70d796f290414e3a968b512 [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
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000011#ifndef WEBRTC_VOICE_ENGINE_CHANNEL_H_
12#define WEBRTC_VOICE_ENGINE_CHANNEL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
kwibergb7f89d62016-02-17 10:04:18 -080014#include <memory>
15
aleloiaed581a2016-10-20 06:32:39 -070016#include "webrtc/api/audio/audio_mixer.h"
kjellandera69d9732016-08-31 07:33:05 -070017#include "webrtc/api/call/audio_sink.h"
Stefan Holmerb86d4e42015-12-07 10:26:18 +010018#include "webrtc/base/criticalsection.h"
henrik.lundin96bd5022016-04-06 04:13:56 -070019#include "webrtc/base/optional.h"
tommi0a2391f2017-03-21 02:31:51 -070020#include "webrtc/base/thread_checker.h"
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000021#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000022#include "webrtc/common_types.h"
kwibergc8d071e2016-04-06 12:22:38 -070023#include "webrtc/modules/audio_coding/acm2/codec_manager.h"
24#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
kjellander3e6db232015-11-26 04:44:54 -080025#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010026#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000027#include "webrtc/modules/audio_processing/rms_level.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010028#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
29#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
30#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
henrik.lundin92a7a182017-03-07 01:58:55 -080031#include "webrtc/voice_engine/audio_level.h"
kwiberg97744472017-01-10 01:12:51 -080032#include "webrtc/voice_engine/file_player.h"
33#include "webrtc/voice_engine/file_recorder.h"
solenberg88499ec2016-09-07 07:34:41 -070034#include "webrtc/voice_engine/include/voe_base.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000035#include "webrtc/voice_engine/include/voe_network.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000036#include "webrtc/voice_engine/shared_data.h"
37#include "webrtc/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;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000046class FileWrapper;
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;
54class RtpReceiver;
55class RTPReceiverAudio;
nisse657bab22017-02-21 06:28:10 -080056class RtpPacketReceived;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000057class RtpRtcp;
nisseb8f9a322017-03-27 05:36:15 -070058class RtpTransportControllerSendInterface;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000059class TelephoneEventHandler;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000060class VoERTPObserver;
61class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
63struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000064struct ReportBlock;
65struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000066
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000067namespace voe {
68
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000069class OutputMixer;
ivoc14d5dbe2016-07-04 07:06:55 -070070class RtcEventLogProxy;
michaelt9332b7d2016-11-30 07:51:13 -080071class RtcpRttStatsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010072class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000073class Statistics;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010074class TransportFeedbackProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010075class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000076class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000077
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000078// Helper class to simplify locking scheme for members that are accessed from
79// multiple threads.
80// Example: a member can be set on thread T1 and read by an internal audio
81// thread T2. Accessing the member via this class ensures that we are
82// safe and also avoid TSan v2 warnings.
83class ChannelState {
84 public:
kwiberg55b97fe2016-01-28 05:22:45 -080085 struct State {
solenberg11ace152016-09-15 04:29:13 -070086 bool output_file_playing = false;
87 bool input_file_playing = false;
88 bool playing = false;
89 bool sending = false;
kwiberg55b97fe2016-01-28 05:22:45 -080090 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000091
kwiberg55b97fe2016-01-28 05:22:45 -080092 ChannelState() {}
93 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000094
kwiberg55b97fe2016-01-28 05:22:45 -080095 void Reset() {
96 rtc::CritScope lock(&lock_);
97 state_ = State();
98 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000099
kwiberg55b97fe2016-01-28 05:22:45 -0800100 State Get() const {
101 rtc::CritScope lock(&lock_);
102 return state_;
103 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000104
kwiberg55b97fe2016-01-28 05:22:45 -0800105 void SetOutputFilePlaying(bool enable) {
106 rtc::CritScope lock(&lock_);
107 state_.output_file_playing = enable;
108 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000109
kwiberg55b97fe2016-01-28 05:22:45 -0800110 void SetInputFilePlaying(bool enable) {
111 rtc::CritScope lock(&lock_);
112 state_.input_file_playing = enable;
113 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000114
kwiberg55b97fe2016-01-28 05:22:45 -0800115 void SetPlaying(bool enable) {
116 rtc::CritScope lock(&lock_);
117 state_.playing = enable;
118 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000119
kwiberg55b97fe2016-01-28 05:22:45 -0800120 void SetSending(bool enable) {
121 rtc::CritScope lock(&lock_);
122 state_.sending = enable;
123 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000124
kwiberg55b97fe2016-01-28 05:22:45 -0800125 private:
pbosd8de1152016-02-01 09:00:51 -0800126 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800127 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000128};
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
kwiberg55b97fe2016-01-28 05:22:45 -0800130class Channel
131 : public RtpData,
132 public RtpFeedback,
133 public FileCallback, // receiving notification from file player &
134 // recorder
135 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800136 public AudioPacketizationCallback, // receive encoded packets from the
137 // ACM
michaeltbf65be52016-12-15 06:24:49 -0800138 public MixerParticipant, // supplies output mixer with audio frames
139 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();
ossu5f7cfa52016-05-30 08:11:28 -0700146 static int32_t CreateChannel(
147 Channel*& channel,
148 int32_t channelId,
149 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700150 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800151 Channel(int32_t channelId,
152 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700153 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800154 int32_t Init();
tommi0a2391f2017-03-21 02:31:51 -0700155 void Terminate();
kwiberg55b97fe2016-01-28 05:22:45 -0800156 int32_t SetEngineInformation(Statistics& engineStatistics,
157 OutputMixer& outputMixer,
kwiberg55b97fe2016-01-28 05:22:45 -0800158 ProcessThread& moduleProcessThread,
159 AudioDeviceModule& audioDeviceModule,
160 VoiceEngineObserver* voiceEngineObserver,
161 rtc::CriticalSection* callbackCritSect);
162 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000163
kwibergb7f89d62016-02-17 10:04:18 -0800164 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100165
ossu29b1a8d2016-06-13 07:34:51 -0700166 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
167 // passed into AudioReceiveStream is the same as the one set when creating the
168 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
169 // go.
170 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
171
kwiberg55b97fe2016-01-28 05:22:45 -0800172 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000173
kwiberg55b97fe2016-01-28 05:22:45 -0800174 // VoEBase
175 int32_t StartPlayout();
176 int32_t StopPlayout();
177 int32_t StartSend();
178 int32_t StopSend();
kwiberg55b97fe2016-01-28 05:22:45 -0800179 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
180 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
kwiberg55b97fe2016-01-28 05:22:45 -0800182 // VoECodec
183 int32_t GetSendCodec(CodecInst& codec);
184 int32_t GetRecCodec(CodecInst& codec);
185 int32_t SetSendCodec(const CodecInst& codec);
minyue78b4d562016-11-30 04:47:39 -0800186 void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
kwiberg55b97fe2016-01-28 05:22:45 -0800187 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
188 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
189 int32_t SetRecPayloadType(const CodecInst& codec);
kwibergd32bf752017-01-19 07:03:59 -0800190 int32_t SetRecPayloadType(int payload_type, const SdpAudioFormat& format);
kwiberg55b97fe2016-01-28 05:22:45 -0800191 int32_t GetRecPayloadType(CodecInst& codec);
192 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
193 int SetOpusMaxPlaybackRate(int frequency_hz);
194 int SetOpusDtx(bool enable_dtx);
ivoc85228d62016-07-27 04:53:47 -0700195 int GetOpusDtx(bool* enabled);
minyue7e304322016-10-12 05:00:55 -0700196 bool EnableAudioNetworkAdaptor(const std::string& config_string);
197 void DisableAudioNetworkAdaptor();
198 void SetReceiverFrameLengthRange(int min_frame_length_ms,
199 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000200
kwiberg55b97fe2016-01-28 05:22:45 -0800201 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700202 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800203 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700204 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800205 size_t length,
206 const PacketTime& packet_time);
nisse657bab22017-02-21 06:28:10 -0800207 // TODO(nisse, solenberg): Delete when VoENetwork is deleted.
mflodman3d7db262016-04-29 00:57:13 -0700208 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
nisse657bab22017-02-21 06:28:10 -0800209 void OnRtpPacket(const RtpPacketReceived& packet);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000210
kwiberg55b97fe2016-01-28 05:22:45 -0800211 // VoEFile
212 int StartPlayingFileLocally(const char* fileName,
213 bool loop,
214 FileFormats format,
215 int startPosition,
216 float volumeScaling,
217 int stopPosition,
218 const CodecInst* codecInst);
219 int StartPlayingFileLocally(InStream* stream,
220 FileFormats format,
221 int startPosition,
222 float volumeScaling,
223 int stopPosition,
224 const CodecInst* codecInst);
225 int StopPlayingFileLocally();
226 int IsPlayingFileLocally() const;
227 int RegisterFilePlayingToMixer();
228 int StartPlayingFileAsMicrophone(const char* fileName,
229 bool loop,
230 FileFormats format,
231 int startPosition,
232 float volumeScaling,
233 int stopPosition,
234 const CodecInst* codecInst);
235 int StartPlayingFileAsMicrophone(InStream* stream,
236 FileFormats format,
237 int startPosition,
238 float volumeScaling,
239 int stopPosition,
240 const CodecInst* codecInst);
241 int StopPlayingFileAsMicrophone();
242 int IsPlayingFileAsMicrophone() const;
243 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
244 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
245 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000246
kwiberg55b97fe2016-01-28 05:22:45 -0800247 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000248
solenberg8d73f8c2017-03-08 01:52:20 -0800249 // Muting, Volume and Level.
250 void SetInputMute(bool enable);
251 void SetChannelOutputVolumeScaling(float scaling);
252 int GetSpeechOutputLevel() const;
253 int GetSpeechOutputLevelFullRange() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000254
solenbergc6192a92017-03-13 02:36:19 -0700255 // Stats.
kwiberg55b97fe2016-01-28 05:22:45 -0800256 int GetNetworkStatistics(NetworkStatistics& stats);
257 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
solenbergc6192a92017-03-13 02:36:19 -0700259 // Audio+Video Sync.
kwiberg55b97fe2016-01-28 05:22:45 -0800260 uint32_t GetDelayEstimate() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800261 int SetMinimumPlayoutDelay(int delayMs);
262 int GetPlayoutTimestamp(unsigned int& timestamp);
kwiberg55b97fe2016-01-28 05:22:45 -0800263 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000264
solenbergc6192a92017-03-13 02:36:19 -0700265 // DTMF.
solenberg8842c3e2016-03-11 03:06:41 -0800266 int SendTelephoneEventOutband(int event, int duration_ms);
solenbergffbbcac2016-11-17 05:25:37 -0800267 int SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000268
kwiberg55b97fe2016-01-28 05:22:45 -0800269 // VoERTP_RTCP
270 int SetLocalSSRC(unsigned int ssrc);
271 int GetLocalSSRC(unsigned int& ssrc);
272 int GetRemoteSSRC(unsigned int& ssrc);
273 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
274 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
kwiberg55b97fe2016-01-28 05:22:45 -0800275 void EnableSendTransportSequenceNumber(int id);
276 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100277
stefan7de8d642017-02-07 07:14:08 -0800278 void RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -0700279 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -0800280 RtcpBandwidthObserver* bandwidth_observer);
281 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
282 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100283
kwiberg55b97fe2016-01-28 05:22:45 -0800284 void SetRTCPStatus(bool enable);
285 int GetRTCPStatus(bool& enabled);
286 int SetRTCP_CNAME(const char cName[256]);
287 int GetRemoteRTCP_CNAME(char cName[256]);
kwiberg55b97fe2016-01-28 05:22:45 -0800288 int SendApplicationDefinedRTCPPacket(unsigned char subType,
289 unsigned int name,
290 const char* data,
291 unsigned short dataLengthInBytes);
kwiberg55b97fe2016-01-28 05:22:45 -0800292 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
293 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800294 int SetCodecFECStatus(bool enable);
295 bool GetCodecFECStatus();
296 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000297
kwiberg55b97fe2016-01-28 05:22:45 -0800298 // From AudioPacketizationCallback in the ACM
299 int32_t SendData(FrameType frameType,
300 uint8_t payloadType,
301 uint32_t timeStamp,
302 const uint8_t* payloadData,
303 size_t payloadSize,
304 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000305
kwiberg55b97fe2016-01-28 05:22:45 -0800306 // From RtpData in the RTP/RTCP module
307 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
308 size_t payloadSize,
309 const WebRtcRTPHeader* rtpHeader) override;
310 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000311
kwiberg55b97fe2016-01-28 05:22:45 -0800312 // From RtpFeedback in the RTP/RTCP module
313 int32_t OnInitializeDecoder(int8_t payloadType,
314 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
315 int frequency,
316 size_t channels,
317 uint32_t rate) override;
318 void OnIncomingSSRCChanged(uint32_t ssrc) override;
319 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000320
kwiberg55b97fe2016-01-28 05:22:45 -0800321 // From Transport (called by the RTP/RTCP module)
322 bool SendRtp(const uint8_t* data,
323 size_t len,
324 const PacketOptions& packet_options) override;
325 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000326
kwiberg55b97fe2016-01-28 05:22:45 -0800327 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700328 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
329 int32_t id,
330 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800331 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000332
aleloiaed581a2016-10-20 06:32:39 -0700333 // From AudioMixer::Source.
aleloi6c278492016-10-20 14:24:39 -0700334 AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
335 int sample_rate_hz,
336 AudioFrame* audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700337
kwiberg55b97fe2016-01-28 05:22:45 -0800338 // From FileCallback
339 void PlayNotification(int32_t id, uint32_t durationMs) override;
340 void RecordNotification(int32_t id, uint32_t durationMs) override;
341 void PlayFileEnded(int32_t id) override;
342 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000343
kwiberg55b97fe2016-01-28 05:22:45 -0800344 uint32_t InstanceId() const { return _instanceId; }
345 int32_t ChannelId() const { return _channelId; }
346 bool Playing() const { return channel_state_.Get().playing; }
347 bool Sending() const { return channel_state_.Get().sending; }
kwiberg55b97fe2016-01-28 05:22:45 -0800348 bool ExternalTransport() const {
349 rtc::CritScope cs(&_callbackCritSect);
350 return _externalTransport;
351 }
kwiberg55b97fe2016-01-28 05:22:45 -0800352 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
353 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
354 uint32_t Demultiplex(const AudioFrame& audioFrame);
355 // Demultiplex the data to the channel's |_audioFrame|. The difference
356 // between this method and the overloaded method above is that |audio_data|
357 // does not go through transmit_mixer and APM.
358 void Demultiplex(const int16_t* audio_data,
359 int sample_rate,
360 size_t number_of_frames,
361 size_t number_of_channels);
362 uint32_t PrepareEncodeAndSend(int mixingFrequency);
363 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000364
kwiberg55b97fe2016-01-28 05:22:45 -0800365 // Associate to a send channel.
366 // Used for obtaining RTT for a receive-only channel.
solenberg7602aab2016-11-14 11:30:07 -0800367 void set_associate_send_channel(const ChannelOwner& channel);
kwiberg55b97fe2016-01-28 05:22:45 -0800368 // Disassociate a send channel if it was associated.
369 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200370
ivoc14d5dbe2016-07-04 07:06:55 -0700371 // Set a RtcEventLog logging object.
372 void SetRtcEventLog(RtcEventLog* event_log);
373
michaelt9332b7d2016-11-30 07:51:13 -0800374 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
nisse284542b2017-01-10 08:58:32 -0800375 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800376
michaeltbf65be52016-12-15 06:24:49 -0800377 // From OverheadObserver in the RTP/RTCP module
378 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
379
elad.alond12a8e12017-03-23 11:04:48 -0700380 // The existence of this function alongside OnUplinkPacketLossRate is
381 // a compromise. We want the encoder to be agnostic of the PLR source, but
382 // we also don't want it to receive conflicting information from TWCC and
383 // from RTCP-XR.
384 void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000385
elad.alondadb4dc2017-03-23 15:29:50 -0700386 void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate);
387
kwiberg55b97fe2016-01-28 05:22:45 -0800388 private:
elad.alond12a8e12017-03-23 11:04:48 -0700389 void OnUplinkPacketLossRate(float packet_loss_rate);
390
solenberg8d73f8c2017-03-08 01:52:20 -0800391 bool InputMute() const;
nisse657bab22017-02-21 06:28:10 -0800392 bool OnRtpPacketWithHeader(const uint8_t* received_packet,
393 size_t length,
394 RTPHeader *header);
kwiberg55b97fe2016-01-28 05:22:45 -0800395 bool ReceivePacket(const uint8_t* packet,
396 size_t packet_length,
397 const RTPHeader& header,
398 bool in_order);
399 bool HandleRtxPacket(const uint8_t* packet,
400 size_t packet_length,
401 const RTPHeader& header);
402 bool IsPacketInOrder(const RTPHeader& header) const;
403 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
404 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800405 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
406 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
407 void UpdatePlayoutTimestamp(bool rtcp);
kwiberg55b97fe2016-01-28 05:22:45 -0800408 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000409
kwiberg55b97fe2016-01-28 05:22:45 -0800410 int SetSendRtpHeaderExtension(bool enable,
411 RTPExtensionType type,
412 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000413
hbos3fd31fe2017-02-28 05:43:16 -0800414 void UpdateOverheadForEncoder()
415 EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
nisse284542b2017-01-10 08:58:32 -0800416
ossue280cde2016-10-12 11:04:10 -0700417 int GetRtpTimestampRateHz() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800418 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000419
pbosd8de1152016-02-01 09:00:51 -0800420 rtc::CriticalSection _fileCritSect;
421 rtc::CriticalSection _callbackCritSect;
422 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800423 uint32_t _instanceId;
424 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000425
kwiberg55b97fe2016-01-28 05:22:45 -0800426 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000427
ivoc14d5dbe2016-07-04 07:06:55 -0700428 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
michaelt9332b7d2016-11-30 07:51:13 -0800429 std::unique_ptr<voe::RtcpRttStatsProxy> rtcp_rtt_stats_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200430
kwibergb7f89d62016-02-17 10:04:18 -0800431 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
432 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
433 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
kwibergb7f89d62016-02-17 10:04:18 -0800434 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700435 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800436 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
437 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700438 acm2::CodecManager codec_manager_;
439 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800440 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800441 AudioLevel _outputAudioLevel;
442 bool _externalTransport;
443 AudioFrame _audioFrame;
444 // Downsamples to the codec rate if necessary.
445 PushResampler<int16_t> input_resampler_;
kwiberg5a25d952016-08-17 07:31:12 -0700446 std::unique_ptr<FilePlayer> input_file_player_;
447 std::unique_ptr<FilePlayer> output_file_player_;
448 std::unique_ptr<FileRecorder> output_file_recorder_;
kwiberg55b97fe2016-01-28 05:22:45 -0800449 int _inputFilePlayerId;
450 int _outputFilePlayerId;
451 int _outputFileRecorderId;
452 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800453 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000454
kwiberg55b97fe2016-01-28 05:22:45 -0800455 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000456
kwiberg55b97fe2016-01-28 05:22:45 -0800457 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700458 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
solenbergfe7dd6d2017-03-11 08:10:43 -0800459
460 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800461 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800462 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800463 uint16_t send_sequence_number_;
464 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000465
pbosd8de1152016-02-01 09:00:51 -0800466 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000467
kwibergb7f89d62016-02-17 10:04:18 -0800468 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800469 // The rtp timestamp of the first played out audio frame.
470 int64_t capture_start_rtp_time_stamp_;
471 // The capture ntp time (in local timebase) of the first played out audio
472 // frame.
473 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000474
kwiberg55b97fe2016-01-28 05:22:45 -0800475 // uses
476 Statistics* _engineStatisticsPtr;
477 OutputMixer* _outputMixerPtr;
kwiberg55b97fe2016-01-28 05:22:45 -0800478 ProcessThread* _moduleProcessThreadPtr;
479 AudioDeviceModule* _audioDeviceModulePtr;
480 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
481 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
482 Transport* _transportPtr; // WebRtc socket or external transport
henrik.lundin50499422016-11-29 04:26:24 -0800483 RmsLevel rms_level_;
solenberg1c2af8e2016-03-24 10:36:00 -0700484 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
485 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
solenberg1c2af8e2016-03-24 10:36:00 -0700486 float _outputGain GUARDED_BY(volume_settings_critsect_);
solenberg8d73f8c2017-03-08 01:52:20 -0800487 // VoEBase
488 bool _mixFileWithMicrophone;
kwiberg55b97fe2016-01-28 05:22:45 -0800489 // VoeRTP_RTCP
490 uint32_t _lastLocalTimeStamp;
491 int8_t _lastPayloadType;
492 bool _includeAudioLevelIndication;
hbos3fd31fe2017-02-28 05:43:16 -0800493 size_t transport_overhead_per_packet_ GUARDED_BY(overhead_per_packet_lock_);
494 size_t rtp_overhead_per_packet_ GUARDED_BY(overhead_per_packet_lock_);
495 rtc::CriticalSection overhead_per_packet_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800496 // VoENetwork
497 AudioFrame::SpeechType _outputSpeechType;
solenbergfe7dd6d2017-03-11 08:10:43 -0800498 // DTX.
kwiberg55b97fe2016-01-28 05:22:45 -0800499 bool restored_packet_in_use_;
500 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800501 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800502 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800503 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800504 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100505
kwiberg55b97fe2016-01-28 05:22:45 -0800506 bool pacing_enabled_;
507 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800508 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
509 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
510 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200511 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700512
513 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
514 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
tommi0a2391f2017-03-21 02:31:51 -0700515
516 rtc::ThreadChecker construction_thread_;
elad.alond12a8e12017-03-23 11:04:48 -0700517
518 const bool use_twcc_plr_for_ana_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000519};
520
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000521} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000522} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000523
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000524#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_