blob: 65c34f66c8059a189632784ac732fde19d161526 [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
kjellander@webrtc.org7ffeab52016-02-26 22:46:09 +010016#include "webrtc/audio_sink.h"
Stefan Holmerb86d4e42015-12-07 10:26:18 +010017#include "webrtc/base/criticalsection.h"
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000018#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000019#include "webrtc/common_types.h"
kjellander3e6db232015-11-26 04:44:54 -080020#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010021#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000022#include "webrtc/modules/audio_processing/rms_level.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010023#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
24#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
25#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
26#include "webrtc/modules/utility/include/file_player.h"
27#include "webrtc/modules/utility/include/file_recorder.h"
solenberg3ecb5c82016-03-09 07:31:58 -080028#include "webrtc/voice_engine/dtmf_inband.h"
29#include "webrtc/voice_engine/dtmf_inband_queue.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000030#include "webrtc/voice_engine/include/voe_audio_processing.h"
31#include "webrtc/voice_engine/include/voe_network.h"
32#include "webrtc/voice_engine/level_indicator.h"
minyue@webrtc.org74aaf292014-07-16 21:28:26 +000033#include "webrtc/voice_engine/network_predictor.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000034#include "webrtc/voice_engine/shared_data.h"
35#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000036
wu@webrtc.org94454b72014-06-05 20:34:08 +000037namespace rtc {
38
39class TimestampWrapAroundHandler;
40}
41
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000042namespace webrtc {
43
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000044class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000045class Config;
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;
49class 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;
53class RtpReceiver;
54class RTPReceiverAudio;
55class RtpRtcp;
56class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000057class VoEMediaProcess;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000058class VoERTPObserver;
59class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000060
61struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000062struct ReportBlock;
63struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000065namespace voe {
66
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000067class OutputMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010068class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000069class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000070class StatisticsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010071class TransportFeedbackProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000072class TransmitMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010073class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000074class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000075
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000076// Helper class to simplify locking scheme for members that are accessed from
77// multiple threads.
78// Example: a member can be set on thread T1 and read by an internal audio
79// thread T2. Accessing the member via this class ensures that we are
80// safe and also avoid TSan v2 warnings.
81class ChannelState {
82 public:
kwiberg55b97fe2016-01-28 05:22:45 -080083 struct State {
84 State()
85 : rx_apm_is_enabled(false),
86 input_external_media(false),
87 output_file_playing(false),
88 input_file_playing(false),
89 playing(false),
90 sending(false),
91 receiving(false) {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000092
kwiberg55b97fe2016-01-28 05:22:45 -080093 bool rx_apm_is_enabled;
94 bool input_external_media;
95 bool output_file_playing;
96 bool input_file_playing;
97 bool playing;
98 bool sending;
99 bool receiving;
100 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000101
kwiberg55b97fe2016-01-28 05:22:45 -0800102 ChannelState() {}
103 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000104
kwiberg55b97fe2016-01-28 05:22:45 -0800105 void Reset() {
106 rtc::CritScope lock(&lock_);
107 state_ = State();
108 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000109
kwiberg55b97fe2016-01-28 05:22:45 -0800110 State Get() const {
111 rtc::CritScope lock(&lock_);
112 return state_;
113 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000114
kwiberg55b97fe2016-01-28 05:22:45 -0800115 void SetRxApmIsEnabled(bool enable) {
116 rtc::CritScope lock(&lock_);
117 state_.rx_apm_is_enabled = enable;
118 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000119
kwiberg55b97fe2016-01-28 05:22:45 -0800120 void SetInputExternalMedia(bool enable) {
121 rtc::CritScope lock(&lock_);
122 state_.input_external_media = enable;
123 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000124
kwiberg55b97fe2016-01-28 05:22:45 -0800125 void SetOutputFilePlaying(bool enable) {
126 rtc::CritScope lock(&lock_);
127 state_.output_file_playing = enable;
128 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000129
kwiberg55b97fe2016-01-28 05:22:45 -0800130 void SetInputFilePlaying(bool enable) {
131 rtc::CritScope lock(&lock_);
132 state_.input_file_playing = enable;
133 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000134
kwiberg55b97fe2016-01-28 05:22:45 -0800135 void SetPlaying(bool enable) {
136 rtc::CritScope lock(&lock_);
137 state_.playing = enable;
138 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000139
kwiberg55b97fe2016-01-28 05:22:45 -0800140 void SetSending(bool enable) {
141 rtc::CritScope lock(&lock_);
142 state_.sending = enable;
143 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000144
kwiberg55b97fe2016-01-28 05:22:45 -0800145 void SetReceiving(bool enable) {
146 rtc::CritScope lock(&lock_);
147 state_.receiving = enable;
148 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000149
kwiberg55b97fe2016-01-28 05:22:45 -0800150 private:
pbosd8de1152016-02-01 09:00:51 -0800151 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800152 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000153};
niklase@google.com470e71d2011-07-07 08:21:25 +0000154
kwiberg55b97fe2016-01-28 05:22:45 -0800155class Channel
156 : public RtpData,
157 public RtpFeedback,
158 public FileCallback, // receiving notification from file player &
159 // recorder
160 public Transport,
161 public RtpAudioFeedback,
162 public AudioPacketizationCallback, // receive encoded packets from the
163 // ACM
164 public ACMVADCallback, // receive voice activity from the ACM
165 public MixerParticipant // supplies output mixer with audio frames
niklase@google.com470e71d2011-07-07 08:21:25 +0000166{
kwiberg55b97fe2016-01-28 05:22:45 -0800167 public:
168 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000169
kwiberg55b97fe2016-01-28 05:22:45 -0800170 enum { KNumSocketThreads = 1 };
171 enum { KNumberOfSocketBuffers = 8 };
172 virtual ~Channel();
173 static int32_t CreateChannel(Channel*& channel,
174 int32_t channelId,
175 uint32_t instanceId,
176 RtcEventLog* const event_log,
177 const Config& config);
178 Channel(int32_t channelId,
179 uint32_t instanceId,
180 RtcEventLog* const event_log,
181 const Config& config);
182 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
kwiberg55b97fe2016-01-28 05:22:45 -0800194 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000195
kwiberg55b97fe2016-01-28 05:22:45 -0800196 // VoEBase
197 int32_t StartPlayout();
198 int32_t StopPlayout();
199 int32_t StartSend();
200 int32_t StopSend();
201 int32_t StartReceiving();
202 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000203
kwiberg55b97fe2016-01-28 05:22:45 -0800204 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
205 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000206
kwiberg55b97fe2016-01-28 05:22:45 -0800207 // VoECodec
208 int32_t GetSendCodec(CodecInst& codec);
209 int32_t GetRecCodec(CodecInst& codec);
210 int32_t SetSendCodec(const CodecInst& codec);
211 void SetBitRate(int bitrate_bps);
212 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
213 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
214 int32_t SetRecPayloadType(const CodecInst& codec);
215 int32_t GetRecPayloadType(CodecInst& codec);
216 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
217 int SetOpusMaxPlaybackRate(int frequency_hz);
218 int SetOpusDtx(bool enable_dtx);
niklase@google.com470e71d2011-07-07 08:21:25 +0000219
kwiberg55b97fe2016-01-28 05:22:45 -0800220 // VoENetwork
221 int32_t RegisterExternalTransport(Transport& transport);
222 int32_t DeRegisterExternalTransport();
223 int32_t ReceivedRTPPacket(const int8_t* data,
224 size_t length,
225 const PacketTime& packet_time);
226 int32_t ReceivedRTCPPacket(const int8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000227
kwiberg55b97fe2016-01-28 05:22:45 -0800228 // VoEFile
229 int StartPlayingFileLocally(const char* fileName,
230 bool loop,
231 FileFormats format,
232 int startPosition,
233 float volumeScaling,
234 int stopPosition,
235 const CodecInst* codecInst);
236 int StartPlayingFileLocally(InStream* stream,
237 FileFormats format,
238 int startPosition,
239 float volumeScaling,
240 int stopPosition,
241 const CodecInst* codecInst);
242 int StopPlayingFileLocally();
243 int IsPlayingFileLocally() const;
244 int RegisterFilePlayingToMixer();
245 int StartPlayingFileAsMicrophone(const char* fileName,
246 bool loop,
247 FileFormats format,
248 int startPosition,
249 float volumeScaling,
250 int stopPosition,
251 const CodecInst* codecInst);
252 int StartPlayingFileAsMicrophone(InStream* stream,
253 FileFormats format,
254 int startPosition,
255 float volumeScaling,
256 int stopPosition,
257 const CodecInst* codecInst);
258 int StopPlayingFileAsMicrophone();
259 int IsPlayingFileAsMicrophone() const;
260 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
261 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
262 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000263
kwiberg55b97fe2016-01-28 05:22:45 -0800264 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000265
kwiberg55b97fe2016-01-28 05:22:45 -0800266 // VoEExternalMediaProcessing
267 int RegisterExternalMediaProcessing(ProcessingTypes type,
268 VoEMediaProcess& processObject);
269 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
270 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000271
kwiberg55b97fe2016-01-28 05:22:45 -0800272 // VoEVolumeControl
273 int GetSpeechOutputLevel(uint32_t& level) const;
274 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
275 int SetMute(bool enable);
276 bool Mute() const;
277 int SetOutputVolumePan(float left, float right);
278 int GetOutputVolumePan(float& left, float& right) const;
279 int SetChannelOutputVolumeScaling(float scaling);
280 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000281
kwiberg55b97fe2016-01-28 05:22:45 -0800282 // VoENetEqStats
283 int GetNetworkStatistics(NetworkStatistics& stats);
284 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000285
kwiberg55b97fe2016-01-28 05:22:45 -0800286 // VoEVideoSync
287 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
288 int* playout_buffer_delay_ms) const;
289 uint32_t GetDelayEstimate() const;
290 int LeastRequiredDelayMs() const;
291 int SetMinimumPlayoutDelay(int delayMs);
292 int GetPlayoutTimestamp(unsigned int& timestamp);
293 int SetInitTimestamp(unsigned int timestamp);
294 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000295
kwiberg55b97fe2016-01-28 05:22:45 -0800296 // VoEVideoSyncExtended
297 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000298
solenberg3ecb5c82016-03-09 07:31:58 -0800299 // VoEDtmf
solenberg8842c3e2016-03-11 03:06:41 -0800300 int SendTelephoneEventOutband(int event, int duration_ms);
solenberg3ecb5c82016-03-09 07:31:58 -0800301 int SendTelephoneEventInband(unsigned char eventCode,
302 int lengthMs,
303 int attenuationDb,
304 bool playDtmfEvent);
305 int SetSendTelephoneEventPayloadType(unsigned char type);
306 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000307
kwiberg55b97fe2016-01-28 05:22:45 -0800308 // VoEAudioProcessingImpl
309 int UpdateRxVadDetection(AudioFrame& audioFrame);
310 int RegisterRxVadObserver(VoERxVadCallback& observer);
311 int DeRegisterRxVadObserver();
312 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000313#ifdef WEBRTC_VOICE_ENGINE_AGC
kwiberg55b97fe2016-01-28 05:22:45 -0800314 int SetRxAgcStatus(bool enable, AgcModes mode);
315 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
316 int SetRxAgcConfig(AgcConfig config);
317 int GetRxAgcConfig(AgcConfig& config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000318#endif
319#ifdef WEBRTC_VOICE_ENGINE_NR
kwiberg55b97fe2016-01-28 05:22:45 -0800320 int SetRxNsStatus(bool enable, NsModes mode);
321 int GetRxNsStatus(bool& enabled, NsModes& mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000322#endif
323
kwiberg55b97fe2016-01-28 05:22:45 -0800324 // VoERTP_RTCP
325 int SetLocalSSRC(unsigned int ssrc);
326 int GetLocalSSRC(unsigned int& ssrc);
327 int GetRemoteSSRC(unsigned int& ssrc);
328 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
329 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
330 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
331 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
332 void EnableSendTransportSequenceNumber(int id);
333 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100334
stefanbba9dec2016-02-01 04:39:55 -0800335 void RegisterSenderCongestionControlObjects(
336 RtpPacketSender* rtp_packet_sender,
337 TransportFeedbackObserver* transport_feedback_observer,
338 PacketRouter* packet_router);
339 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
340 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100341
kwiberg55b97fe2016-01-28 05:22:45 -0800342 void SetRTCPStatus(bool enable);
343 int GetRTCPStatus(bool& enabled);
344 int SetRTCP_CNAME(const char cName[256]);
345 int GetRemoteRTCP_CNAME(char cName[256]);
346 int GetRemoteRTCPData(unsigned int& NTPHigh,
347 unsigned int& NTPLow,
348 unsigned int& timestamp,
349 unsigned int& playoutTimestamp,
350 unsigned int* jitter,
351 unsigned short* fractionLost);
352 int SendApplicationDefinedRTCPPacket(unsigned char subType,
353 unsigned int name,
354 const char* data,
355 unsigned short dataLengthInBytes);
356 int GetRTPStatistics(unsigned int& averageJitterMs,
357 unsigned int& maxJitterMs,
358 unsigned int& discardedPackets);
359 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
360 int GetRTPStatistics(CallStatistics& stats);
361 int SetREDStatus(bool enable, int redPayloadtype);
362 int GetREDStatus(bool& enabled, int& redPayloadtype);
363 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 RtpAudioFeedback in the RTP/RTCP module
396 void OnPlayTelephoneEvent(uint8_t event,
397 uint16_t lengthMs,
398 uint8_t volume) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000399
kwiberg55b97fe2016-01-28 05:22:45 -0800400 // From Transport (called by the RTP/RTCP module)
401 bool SendRtp(const uint8_t* data,
402 size_t len,
403 const PacketOptions& packet_options) override;
404 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000405
kwiberg55b97fe2016-01-28 05:22:45 -0800406 // From MixerParticipant
407 int32_t GetAudioFrame(int32_t id, AudioFrame* audioFrame) override;
408 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000409
kwiberg55b97fe2016-01-28 05:22:45 -0800410 // From FileCallback
411 void PlayNotification(int32_t id, uint32_t durationMs) override;
412 void RecordNotification(int32_t id, uint32_t durationMs) override;
413 void PlayFileEnded(int32_t id) override;
414 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000415
kwiberg55b97fe2016-01-28 05:22:45 -0800416 uint32_t InstanceId() const { return _instanceId; }
417 int32_t ChannelId() const { return _channelId; }
418 bool Playing() const { return channel_state_.Get().playing; }
419 bool Sending() const { return channel_state_.Get().sending; }
420 bool Receiving() const { return channel_state_.Get().receiving; }
421 bool ExternalTransport() const {
422 rtc::CritScope cs(&_callbackCritSect);
423 return _externalTransport;
424 }
425 bool ExternalMixing() const { return _externalMixing; }
426 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
427 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
428 uint32_t Demultiplex(const AudioFrame& audioFrame);
429 // Demultiplex the data to the channel's |_audioFrame|. The difference
430 // between this method and the overloaded method above is that |audio_data|
431 // does not go through transmit_mixer and APM.
432 void Demultiplex(const int16_t* audio_data,
433 int sample_rate,
434 size_t number_of_frames,
435 size_t number_of_channels);
436 uint32_t PrepareEncodeAndSend(int mixingFrequency);
437 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000438
kwiberg55b97fe2016-01-28 05:22:45 -0800439 // Associate to a send channel.
440 // Used for obtaining RTT for a receive-only channel.
441 void set_associate_send_channel(const ChannelOwner& channel) {
442 assert(_channelId != channel.channel()->ChannelId());
443 rtc::CritScope lock(&assoc_send_channel_lock_);
444 associate_send_channel_ = channel;
445 }
Minyue2013aec2015-05-13 14:14:42 +0200446
kwiberg55b97fe2016-01-28 05:22:45 -0800447 // Disassociate a send channel if it was associated.
448 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200449
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);
solenberg3ecb5c82016-03-09 07:31:58 -0800464 int InsertInbandDtmfTone();
kwiberg55b97fe2016-01-28 05:22:45 -0800465 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
466 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
467 void UpdatePlayoutTimestamp(bool rtcp);
468 void UpdatePacketDelay(uint32_t timestamp, uint16_t sequenceNumber);
469 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000470
kwiberg55b97fe2016-01-28 05:22:45 -0800471 int SetRedPayloadType(int red_payload_type);
472 int SetSendRtpHeaderExtension(bool enable,
473 RTPExtensionType type,
474 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000475
kwiberg55b97fe2016-01-28 05:22:45 -0800476 int32_t GetPlayoutFrequency();
477 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000478
pbosd8de1152016-02-01 09:00:51 -0800479 rtc::CriticalSection _fileCritSect;
480 rtc::CriticalSection _callbackCritSect;
481 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800482 uint32_t _instanceId;
483 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000484
kwiberg55b97fe2016-01-28 05:22:45 -0800485 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000486
kwiberg55b97fe2016-01-28 05:22:45 -0800487 RtcEventLog* const event_log_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200488
kwibergb7f89d62016-02-17 10:04:18 -0800489 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
490 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
491 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
492 std::unique_ptr<StatisticsProxy> statistics_proxy_;
493 std::unique_ptr<RtpReceiver> rtp_receiver_;
kwiberg55b97fe2016-01-28 05:22:45 -0800494 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800495 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
496 std::unique_ptr<AudioCodingModule> audio_coding_;
497 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800498 AudioLevel _outputAudioLevel;
499 bool _externalTransport;
500 AudioFrame _audioFrame;
501 // Downsamples to the codec rate if necessary.
502 PushResampler<int16_t> input_resampler_;
503 FilePlayer* _inputFilePlayerPtr;
504 FilePlayer* _outputFilePlayerPtr;
505 FileRecorder* _outputFileRecorderPtr;
506 int _inputFilePlayerId;
507 int _outputFilePlayerId;
508 int _outputFileRecorderId;
509 bool _outputFileRecording;
solenberg3ecb5c82016-03-09 07:31:58 -0800510 DtmfInbandQueue _inbandDtmfQueue;
511 DtmfInband _inbandDtmfGenerator;
kwiberg55b97fe2016-01-28 05:22:45 -0800512 bool _outputExternalMedia;
513 VoEMediaProcess* _inputExternalMediaCallbackPtr;
514 VoEMediaProcess* _outputExternalMediaCallbackPtr;
515 uint32_t _timeStamp;
solenberg3ecb5c82016-03-09 07:31:58 -0800516 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000517
kwiberg55b97fe2016-01-28 05:22:45 -0800518 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000519
kwiberg55b97fe2016-01-28 05:22:45 -0800520 // Timestamp of the audio pulled from NetEq.
521 uint32_t jitter_buffer_playout_timestamp_;
522 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
523 uint32_t playout_timestamp_rtcp_;
524 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
525 uint32_t _numberOfDiscardedPackets;
526 uint16_t send_sequence_number_;
527 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000528
pbosd8de1152016-02-01 09:00:51 -0800529 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000530
kwibergb7f89d62016-02-17 10:04:18 -0800531 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800532 // The rtp timestamp of the first played out audio frame.
533 int64_t capture_start_rtp_time_stamp_;
534 // The capture ntp time (in local timebase) of the first played out audio
535 // frame.
536 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000537
kwiberg55b97fe2016-01-28 05:22:45 -0800538 // uses
539 Statistics* _engineStatisticsPtr;
540 OutputMixer* _outputMixerPtr;
541 TransmitMixer* _transmitMixerPtr;
542 ProcessThread* _moduleProcessThreadPtr;
543 AudioDeviceModule* _audioDeviceModulePtr;
544 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
545 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
546 Transport* _transportPtr; // WebRtc socket or external transport
547 RMSLevel rms_level_;
kwibergb7f89d62016-02-17 10:04:18 -0800548 std::unique_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800549 VoERxVadCallback* _rxVadObserverPtr;
550 int32_t _oldVadDecision;
551 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
552 // VoEBase
553 bool _externalMixing;
554 bool _mixFileWithMicrophone;
555 // VoEVolumeControl
556 bool _mute;
557 float _panLeft;
558 float _panRight;
559 float _outputGain;
solenberg3ecb5c82016-03-09 07:31:58 -0800560 // VoEDtmf
561 bool _playOutbandDtmfEvent;
562 bool _playInbandDtmfEvent;
kwiberg55b97fe2016-01-28 05:22:45 -0800563 // VoeRTP_RTCP
564 uint32_t _lastLocalTimeStamp;
565 int8_t _lastPayloadType;
566 bool _includeAudioLevelIndication;
567 // VoENetwork
568 AudioFrame::SpeechType _outputSpeechType;
569 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800570 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800571 uint32_t _average_jitter_buffer_delay_us GUARDED_BY(video_sync_lock_);
572 uint32_t _previousTimestamp;
573 uint16_t _recPacketDelayMs GUARDED_BY(video_sync_lock_);
574 // VoEAudioProcessing
575 bool _RxVadDetection;
576 bool _rxAgcIsEnabled;
577 bool _rxNsIsEnabled;
578 bool restored_packet_in_use_;
579 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800580 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
581 std::unique_ptr<NetworkPredictor> network_predictor_;
kwiberg55b97fe2016-01-28 05:22:45 -0800582 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800583 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800584 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100585
kwiberg55b97fe2016-01-28 05:22:45 -0800586 bool pacing_enabled_;
587 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800588 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
589 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
590 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000591};
592
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000593} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000594} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000595
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000596#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_