blob: 307b61ebcc8a9e45b3d8dcfd71e648769345159c [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
kjellandera69d9732016-08-31 07:33:05 -070016#include "webrtc/api/call/audio_sink.h"
Stefan Holmerb86d4e42015-12-07 10:26:18 +010017#include "webrtc/base/criticalsection.h"
henrik.lundin96bd5022016-04-06 04:13:56 -070018#include "webrtc/base/optional.h"
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000019#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000020#include "webrtc/common_types.h"
kwibergc8d071e2016-04-06 12:22:38 -070021#include "webrtc/modules/audio_coding/acm2/codec_manager.h"
22#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
kjellander3e6db232015-11-26 04:44:54 -080023#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010024#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000025#include "webrtc/modules/audio_processing/rms_level.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010026#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
27#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
28#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
kwiberg9d7eb132016-08-16 04:08:30 -070029#include "webrtc/modules/utility/include/file_player.h"
30#include "webrtc/modules/utility/include/file_recorder.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000031#include "webrtc/voice_engine/include/voe_audio_processing.h"
solenberg88499ec2016-09-07 07:34:41 -070032#include "webrtc/voice_engine/include/voe_base.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000033#include "webrtc/voice_engine/include/voe_network.h"
34#include "webrtc/voice_engine/level_indicator.h"
minyue@webrtc.org74aaf292014-07-16 21:28:26 +000035#include "webrtc/voice_engine/network_predictor.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;
56class RtpRtcp;
57class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000058class VoEMediaProcess;
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;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010070class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000071class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000072class StatisticsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010073class TransportFeedbackProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000074class TransmitMixer;
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 {
86 State()
87 : rx_apm_is_enabled(false),
88 input_external_media(false),
89 output_file_playing(false),
90 input_file_playing(false),
91 playing(false),
92 sending(false),
93 receiving(false) {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000094
kwiberg55b97fe2016-01-28 05:22:45 -080095 bool rx_apm_is_enabled;
96 bool input_external_media;
97 bool output_file_playing;
98 bool input_file_playing;
99 bool playing;
100 bool sending;
101 bool receiving;
102 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000103
kwiberg55b97fe2016-01-28 05:22:45 -0800104 ChannelState() {}
105 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000106
kwiberg55b97fe2016-01-28 05:22:45 -0800107 void Reset() {
108 rtc::CritScope lock(&lock_);
109 state_ = State();
110 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000111
kwiberg55b97fe2016-01-28 05:22:45 -0800112 State Get() const {
113 rtc::CritScope lock(&lock_);
114 return state_;
115 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000116
kwiberg55b97fe2016-01-28 05:22:45 -0800117 void SetRxApmIsEnabled(bool enable) {
118 rtc::CritScope lock(&lock_);
119 state_.rx_apm_is_enabled = enable;
120 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000121
kwiberg55b97fe2016-01-28 05:22:45 -0800122 void SetInputExternalMedia(bool enable) {
123 rtc::CritScope lock(&lock_);
124 state_.input_external_media = enable;
125 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000126
kwiberg55b97fe2016-01-28 05:22:45 -0800127 void SetOutputFilePlaying(bool enable) {
128 rtc::CritScope lock(&lock_);
129 state_.output_file_playing = enable;
130 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000131
kwiberg55b97fe2016-01-28 05:22:45 -0800132 void SetInputFilePlaying(bool enable) {
133 rtc::CritScope lock(&lock_);
134 state_.input_file_playing = enable;
135 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000136
kwiberg55b97fe2016-01-28 05:22:45 -0800137 void SetPlaying(bool enable) {
138 rtc::CritScope lock(&lock_);
139 state_.playing = enable;
140 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000141
kwiberg55b97fe2016-01-28 05:22:45 -0800142 void SetSending(bool enable) {
143 rtc::CritScope lock(&lock_);
144 state_.sending = enable;
145 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000146
kwiberg55b97fe2016-01-28 05:22:45 -0800147 void SetReceiving(bool enable) {
148 rtc::CritScope lock(&lock_);
149 state_.receiving = enable;
150 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000151
kwiberg55b97fe2016-01-28 05:22:45 -0800152 private:
pbosd8de1152016-02-01 09:00:51 -0800153 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800154 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000155};
niklase@google.com470e71d2011-07-07 08:21:25 +0000156
kwiberg55b97fe2016-01-28 05:22:45 -0800157class Channel
158 : public RtpData,
159 public RtpFeedback,
160 public FileCallback, // receiving notification from file player &
161 // recorder
162 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800163 public AudioPacketizationCallback, // receive encoded packets from the
164 // ACM
165 public ACMVADCallback, // receive voice activity from the ACM
166 public MixerParticipant // supplies output mixer with audio frames
niklase@google.com470e71d2011-07-07 08:21:25 +0000167{
kwiberg55b97fe2016-01-28 05:22:45 -0800168 public:
169 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000170
kwiberg55b97fe2016-01-28 05:22:45 -0800171 enum { KNumSocketThreads = 1 };
172 enum { KNumberOfSocketBuffers = 8 };
173 virtual ~Channel();
ossu5f7cfa52016-05-30 08:11:28 -0700174 static int32_t CreateChannel(
175 Channel*& channel,
176 int32_t channelId,
177 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700178 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800179 Channel(int32_t channelId,
180 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700181 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800182 int32_t Init();
183 int32_t SetEngineInformation(Statistics& engineStatistics,
184 OutputMixer& outputMixer,
185 TransmitMixer& transmitMixer,
186 ProcessThread& moduleProcessThread,
187 AudioDeviceModule& audioDeviceModule,
188 VoiceEngineObserver* voiceEngineObserver,
189 rtc::CriticalSection* callbackCritSect);
190 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000191
kwibergb7f89d62016-02-17 10:04:18 -0800192 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100193
ossu29b1a8d2016-06-13 07:34:51 -0700194 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
195 // passed into AudioReceiveStream is the same as the one set when creating the
196 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
197 // go.
198 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
199
kwiberg55b97fe2016-01-28 05:22:45 -0800200 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
kwiberg55b97fe2016-01-28 05:22:45 -0800202 // VoEBase
203 int32_t StartPlayout();
204 int32_t StopPlayout();
205 int32_t StartSend();
206 int32_t StopSend();
207 int32_t StartReceiving();
208 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000209
kwiberg55b97fe2016-01-28 05:22:45 -0800210 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
211 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
kwiberg55b97fe2016-01-28 05:22:45 -0800213 // VoECodec
214 int32_t GetSendCodec(CodecInst& codec);
215 int32_t GetRecCodec(CodecInst& codec);
216 int32_t SetSendCodec(const CodecInst& codec);
217 void SetBitRate(int bitrate_bps);
218 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
219 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
220 int32_t SetRecPayloadType(const CodecInst& codec);
221 int32_t GetRecPayloadType(CodecInst& codec);
222 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
223 int SetOpusMaxPlaybackRate(int frequency_hz);
224 int SetOpusDtx(bool enable_dtx);
ivoc85228d62016-07-27 04:53:47 -0700225 int GetOpusDtx(bool* enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000226
kwiberg55b97fe2016-01-28 05:22:45 -0800227 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700228 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800229 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700230 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800231 size_t length,
232 const PacketTime& packet_time);
mflodman3d7db262016-04-29 00:57:13 -0700233 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000234
kwiberg55b97fe2016-01-28 05:22:45 -0800235 // VoEFile
236 int StartPlayingFileLocally(const char* fileName,
237 bool loop,
238 FileFormats format,
239 int startPosition,
240 float volumeScaling,
241 int stopPosition,
242 const CodecInst* codecInst);
243 int StartPlayingFileLocally(InStream* stream,
244 FileFormats format,
245 int startPosition,
246 float volumeScaling,
247 int stopPosition,
248 const CodecInst* codecInst);
249 int StopPlayingFileLocally();
250 int IsPlayingFileLocally() const;
251 int RegisterFilePlayingToMixer();
252 int StartPlayingFileAsMicrophone(const char* fileName,
253 bool loop,
254 FileFormats format,
255 int startPosition,
256 float volumeScaling,
257 int stopPosition,
258 const CodecInst* codecInst);
259 int StartPlayingFileAsMicrophone(InStream* stream,
260 FileFormats format,
261 int startPosition,
262 float volumeScaling,
263 int stopPosition,
264 const CodecInst* codecInst);
265 int StopPlayingFileAsMicrophone();
266 int IsPlayingFileAsMicrophone() const;
267 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
268 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
269 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000270
kwiberg55b97fe2016-01-28 05:22:45 -0800271 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000272
kwiberg55b97fe2016-01-28 05:22:45 -0800273 // VoEExternalMediaProcessing
274 int RegisterExternalMediaProcessing(ProcessingTypes type,
275 VoEMediaProcess& processObject);
276 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
277 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000278
kwiberg55b97fe2016-01-28 05:22:45 -0800279 // VoEVolumeControl
280 int GetSpeechOutputLevel(uint32_t& level) const;
281 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
solenberg1c2af8e2016-03-24 10:36:00 -0700282 int SetInputMute(bool enable);
283 bool InputMute() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800284 int SetOutputVolumePan(float left, float right);
285 int GetOutputVolumePan(float& left, float& right) const;
286 int SetChannelOutputVolumeScaling(float scaling);
287 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000288
kwiberg55b97fe2016-01-28 05:22:45 -0800289 // VoENetEqStats
290 int GetNetworkStatistics(NetworkStatistics& stats);
291 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000292
kwiberg55b97fe2016-01-28 05:22:45 -0800293 // VoEVideoSync
294 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
295 int* playout_buffer_delay_ms) const;
296 uint32_t GetDelayEstimate() const;
297 int LeastRequiredDelayMs() const;
298 int SetMinimumPlayoutDelay(int delayMs);
299 int GetPlayoutTimestamp(unsigned int& timestamp);
300 int SetInitTimestamp(unsigned int timestamp);
301 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000302
kwiberg55b97fe2016-01-28 05:22:45 -0800303 // VoEVideoSyncExtended
304 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000305
solenberg31642aa2016-03-14 08:00:37 -0700306 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800307 int SendTelephoneEventOutband(int event, int duration_ms);
solenberg31642aa2016-03-14 08:00:37 -0700308 int SetSendTelephoneEventPayloadType(int payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000309
kwiberg55b97fe2016-01-28 05:22:45 -0800310 // VoEAudioProcessingImpl
311 int UpdateRxVadDetection(AudioFrame& audioFrame);
312 int RegisterRxVadObserver(VoERxVadCallback& observer);
313 int DeRegisterRxVadObserver();
314 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000315#ifdef WEBRTC_VOICE_ENGINE_AGC
kwiberg55b97fe2016-01-28 05:22:45 -0800316 int SetRxAgcStatus(bool enable, AgcModes mode);
317 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
318 int SetRxAgcConfig(AgcConfig config);
319 int GetRxAgcConfig(AgcConfig& config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000320#endif
321#ifdef WEBRTC_VOICE_ENGINE_NR
kwiberg55b97fe2016-01-28 05:22:45 -0800322 int SetRxNsStatus(bool enable, NsModes mode);
323 int GetRxNsStatus(bool& enabled, NsModes& mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000324#endif
325
kwiberg55b97fe2016-01-28 05:22:45 -0800326 // VoERTP_RTCP
327 int SetLocalSSRC(unsigned int ssrc);
328 int GetLocalSSRC(unsigned int& ssrc);
329 int GetRemoteSSRC(unsigned int& ssrc);
330 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
331 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
332 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
333 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
334 void EnableSendTransportSequenceNumber(int id);
335 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100336
stefanbba9dec2016-02-01 04:39:55 -0800337 void RegisterSenderCongestionControlObjects(
338 RtpPacketSender* rtp_packet_sender,
339 TransportFeedbackObserver* transport_feedback_observer,
340 PacketRouter* packet_router);
341 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
342 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100343
kwiberg55b97fe2016-01-28 05:22:45 -0800344 void SetRTCPStatus(bool enable);
345 int GetRTCPStatus(bool& enabled);
346 int SetRTCP_CNAME(const char cName[256]);
347 int GetRemoteRTCP_CNAME(char cName[256]);
348 int GetRemoteRTCPData(unsigned int& NTPHigh,
349 unsigned int& NTPLow,
350 unsigned int& timestamp,
351 unsigned int& playoutTimestamp,
352 unsigned int* jitter,
353 unsigned short* fractionLost);
354 int SendApplicationDefinedRTCPPacket(unsigned char subType,
355 unsigned int name,
356 const char* data,
357 unsigned short dataLengthInBytes);
358 int GetRTPStatistics(unsigned int& averageJitterMs,
359 unsigned int& maxJitterMs,
360 unsigned int& discardedPackets);
361 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
362 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800363 int SetCodecFECStatus(bool enable);
364 bool GetCodecFECStatus();
365 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000366
kwiberg55b97fe2016-01-28 05:22:45 -0800367 // From AudioPacketizationCallback in the ACM
368 int32_t SendData(FrameType frameType,
369 uint8_t payloadType,
370 uint32_t timeStamp,
371 const uint8_t* payloadData,
372 size_t payloadSize,
373 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000374
kwiberg55b97fe2016-01-28 05:22:45 -0800375 // From ACMVADCallback in the ACM
376 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000377
kwiberg55b97fe2016-01-28 05:22:45 -0800378 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000379
kwiberg55b97fe2016-01-28 05:22:45 -0800380 // From RtpData in the RTP/RTCP module
381 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
382 size_t payloadSize,
383 const WebRtcRTPHeader* rtpHeader) override;
384 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000385
kwiberg55b97fe2016-01-28 05:22:45 -0800386 // From RtpFeedback in the RTP/RTCP module
387 int32_t OnInitializeDecoder(int8_t payloadType,
388 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
389 int frequency,
390 size_t channels,
391 uint32_t rate) override;
392 void OnIncomingSSRCChanged(uint32_t ssrc) override;
393 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000394
kwiberg55b97fe2016-01-28 05:22:45 -0800395 // From Transport (called by the RTP/RTCP module)
396 bool SendRtp(const uint8_t* data,
397 size_t len,
398 const PacketOptions& packet_options) override;
399 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000400
kwiberg55b97fe2016-01-28 05:22:45 -0800401 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700402 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
403 int32_t id,
404 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800405 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000406
kwiberg55b97fe2016-01-28 05:22:45 -0800407 // From FileCallback
408 void PlayNotification(int32_t id, uint32_t durationMs) override;
409 void RecordNotification(int32_t id, uint32_t durationMs) override;
410 void PlayFileEnded(int32_t id) override;
411 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000412
kwiberg55b97fe2016-01-28 05:22:45 -0800413 uint32_t InstanceId() const { return _instanceId; }
414 int32_t ChannelId() const { return _channelId; }
415 bool Playing() const { return channel_state_.Get().playing; }
416 bool Sending() const { return channel_state_.Get().sending; }
417 bool Receiving() const { return channel_state_.Get().receiving; }
418 bool ExternalTransport() const {
419 rtc::CritScope cs(&_callbackCritSect);
420 return _externalTransport;
421 }
422 bool ExternalMixing() const { return _externalMixing; }
423 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
424 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
425 uint32_t Demultiplex(const AudioFrame& audioFrame);
426 // Demultiplex the data to the channel's |_audioFrame|. The difference
427 // between this method and the overloaded method above is that |audio_data|
428 // does not go through transmit_mixer and APM.
429 void Demultiplex(const int16_t* audio_data,
430 int sample_rate,
431 size_t number_of_frames,
432 size_t number_of_channels);
433 uint32_t PrepareEncodeAndSend(int mixingFrequency);
434 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000435
kwiberg55b97fe2016-01-28 05:22:45 -0800436 // Associate to a send channel.
437 // Used for obtaining RTT for a receive-only channel.
438 void set_associate_send_channel(const ChannelOwner& channel) {
439 assert(_channelId != channel.channel()->ChannelId());
440 rtc::CritScope lock(&assoc_send_channel_lock_);
441 associate_send_channel_ = channel;
442 }
Minyue2013aec2015-05-13 14:14:42 +0200443
kwiberg55b97fe2016-01-28 05:22:45 -0800444 // Disassociate a send channel if it was associated.
445 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200446
ivoc14d5dbe2016-07-04 07:06:55 -0700447 // Set a RtcEventLog logging object.
448 void SetRtcEventLog(RtcEventLog* event_log);
449
kwiberg55b97fe2016-01-28 05:22:45 -0800450 protected:
451 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000452
kwiberg55b97fe2016-01-28 05:22:45 -0800453 private:
454 bool ReceivePacket(const uint8_t* packet,
455 size_t packet_length,
456 const RTPHeader& header,
457 bool in_order);
458 bool HandleRtxPacket(const uint8_t* packet,
459 size_t packet_length,
460 const RTPHeader& header);
461 bool IsPacketInOrder(const RTPHeader& header) const;
462 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
463 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800464 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
465 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
466 void UpdatePlayoutTimestamp(bool rtcp);
kwiberg55b97fe2016-01-28 05:22:45 -0800467 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000468
kwiberg55b97fe2016-01-28 05:22:45 -0800469 int SetSendRtpHeaderExtension(bool enable,
470 RTPExtensionType type,
471 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000472
henrik.lundinb3e30012016-08-31 14:09:51 -0700473 int32_t GetPlayoutFrequency() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800474 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000475
pbosd8de1152016-02-01 09:00:51 -0800476 rtc::CriticalSection _fileCritSect;
477 rtc::CriticalSection _callbackCritSect;
478 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800479 uint32_t _instanceId;
480 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000481
kwiberg55b97fe2016-01-28 05:22:45 -0800482 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000483
ivoc14d5dbe2016-07-04 07:06:55 -0700484 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200485
kwibergb7f89d62016-02-17 10:04:18 -0800486 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
487 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
488 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
489 std::unique_ptr<StatisticsProxy> statistics_proxy_;
490 std::unique_ptr<RtpReceiver> rtp_receiver_;
kwiberg55b97fe2016-01-28 05:22:45 -0800491 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800492 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
493 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700494 acm2::CodecManager codec_manager_;
495 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800496 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800497 AudioLevel _outputAudioLevel;
498 bool _externalTransport;
499 AudioFrame _audioFrame;
500 // Downsamples to the codec rate if necessary.
501 PushResampler<int16_t> input_resampler_;
kwiberg5a25d952016-08-17 07:31:12 -0700502 std::unique_ptr<FilePlayer> input_file_player_;
503 std::unique_ptr<FilePlayer> output_file_player_;
504 std::unique_ptr<FileRecorder> output_file_recorder_;
kwiberg55b97fe2016-01-28 05:22:45 -0800505 int _inputFilePlayerId;
506 int _outputFilePlayerId;
507 int _outputFileRecorderId;
508 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800509 bool _outputExternalMedia;
510 VoEMediaProcess* _inputExternalMediaCallbackPtr;
511 VoEMediaProcess* _outputExternalMediaCallbackPtr;
512 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000513
kwiberg55b97fe2016-01-28 05:22:45 -0800514 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000515
kwiberg55b97fe2016-01-28 05:22:45 -0800516 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700517 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
kwiberg55b97fe2016-01-28 05:22:45 -0800518 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
519 uint32_t playout_timestamp_rtcp_;
520 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
521 uint32_t _numberOfDiscardedPackets;
522 uint16_t send_sequence_number_;
523 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000524
pbosd8de1152016-02-01 09:00:51 -0800525 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000526
kwibergb7f89d62016-02-17 10:04:18 -0800527 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800528 // The rtp timestamp of the first played out audio frame.
529 int64_t capture_start_rtp_time_stamp_;
530 // The capture ntp time (in local timebase) of the first played out audio
531 // frame.
532 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000533
kwiberg55b97fe2016-01-28 05:22:45 -0800534 // uses
535 Statistics* _engineStatisticsPtr;
536 OutputMixer* _outputMixerPtr;
537 TransmitMixer* _transmitMixerPtr;
538 ProcessThread* _moduleProcessThreadPtr;
539 AudioDeviceModule* _audioDeviceModulePtr;
540 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
541 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
542 Transport* _transportPtr; // WebRtc socket or external transport
543 RMSLevel rms_level_;
kwibergb7f89d62016-02-17 10:04:18 -0800544 std::unique_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800545 VoERxVadCallback* _rxVadObserverPtr;
546 int32_t _oldVadDecision;
547 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
548 // VoEBase
549 bool _externalMixing;
550 bool _mixFileWithMicrophone;
551 // VoEVolumeControl
solenberg1c2af8e2016-03-24 10:36:00 -0700552 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
553 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
554 float _panLeft GUARDED_BY(volume_settings_critsect_);
555 float _panRight GUARDED_BY(volume_settings_critsect_);
556 float _outputGain GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800557 // VoeRTP_RTCP
558 uint32_t _lastLocalTimeStamp;
559 int8_t _lastPayloadType;
560 bool _includeAudioLevelIndication;
561 // VoENetwork
562 AudioFrame::SpeechType _outputSpeechType;
563 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800564 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800565 // VoEAudioProcessing
566 bool _RxVadDetection;
567 bool _rxAgcIsEnabled;
568 bool _rxNsIsEnabled;
569 bool restored_packet_in_use_;
570 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800571 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
572 std::unique_ptr<NetworkPredictor> network_predictor_;
kwiberg55b97fe2016-01-28 05:22:45 -0800573 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800574 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800575 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100576
kwiberg55b97fe2016-01-28 05:22:45 -0800577 bool pacing_enabled_;
578 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800579 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
580 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
581 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200582 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700583
584 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
585 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000586};
587
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000588} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000589} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000590
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000591#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_