blob: 75c4fd87cb96467aed48a6ba0c27202b4641dc84 [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
300 int SendTelephoneEventOutband(unsigned char eventCode,
301 int lengthMs,
302 int attenuationDb,
303 bool playDtmfEvent);
304 int SendTelephoneEventInband(unsigned char eventCode,
305 int lengthMs,
306 int attenuationDb,
307 bool playDtmfEvent);
308 int SetSendTelephoneEventPayloadType(unsigned char type);
309 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000310
kwiberg55b97fe2016-01-28 05:22:45 -0800311 // VoEAudioProcessingImpl
312 int UpdateRxVadDetection(AudioFrame& audioFrame);
313 int RegisterRxVadObserver(VoERxVadCallback& observer);
314 int DeRegisterRxVadObserver();
315 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000316#ifdef WEBRTC_VOICE_ENGINE_AGC
kwiberg55b97fe2016-01-28 05:22:45 -0800317 int SetRxAgcStatus(bool enable, AgcModes mode);
318 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
319 int SetRxAgcConfig(AgcConfig config);
320 int GetRxAgcConfig(AgcConfig& config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000321#endif
322#ifdef WEBRTC_VOICE_ENGINE_NR
kwiberg55b97fe2016-01-28 05:22:45 -0800323 int SetRxNsStatus(bool enable, NsModes mode);
324 int GetRxNsStatus(bool& enabled, NsModes& mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000325#endif
326
kwiberg55b97fe2016-01-28 05:22:45 -0800327 // VoERTP_RTCP
328 int SetLocalSSRC(unsigned int ssrc);
329 int GetLocalSSRC(unsigned int& ssrc);
330 int GetRemoteSSRC(unsigned int& ssrc);
331 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
332 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
333 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
334 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
335 void EnableSendTransportSequenceNumber(int id);
336 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100337
stefanbba9dec2016-02-01 04:39:55 -0800338 void RegisterSenderCongestionControlObjects(
339 RtpPacketSender* rtp_packet_sender,
340 TransportFeedbackObserver* transport_feedback_observer,
341 PacketRouter* packet_router);
342 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
343 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100344
kwiberg55b97fe2016-01-28 05:22:45 -0800345 void SetRTCPStatus(bool enable);
346 int GetRTCPStatus(bool& enabled);
347 int SetRTCP_CNAME(const char cName[256]);
348 int GetRemoteRTCP_CNAME(char cName[256]);
349 int GetRemoteRTCPData(unsigned int& NTPHigh,
350 unsigned int& NTPLow,
351 unsigned int& timestamp,
352 unsigned int& playoutTimestamp,
353 unsigned int* jitter,
354 unsigned short* fractionLost);
355 int SendApplicationDefinedRTCPPacket(unsigned char subType,
356 unsigned int name,
357 const char* data,
358 unsigned short dataLengthInBytes);
359 int GetRTPStatistics(unsigned int& averageJitterMs,
360 unsigned int& maxJitterMs,
361 unsigned int& discardedPackets);
362 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
363 int GetRTPStatistics(CallStatistics& stats);
364 int SetREDStatus(bool enable, int redPayloadtype);
365 int GetREDStatus(bool& enabled, int& redPayloadtype);
366 int SetCodecFECStatus(bool enable);
367 bool GetCodecFECStatus();
368 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000369
kwiberg55b97fe2016-01-28 05:22:45 -0800370 // From AudioPacketizationCallback in the ACM
371 int32_t SendData(FrameType frameType,
372 uint8_t payloadType,
373 uint32_t timeStamp,
374 const uint8_t* payloadData,
375 size_t payloadSize,
376 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000377
kwiberg55b97fe2016-01-28 05:22:45 -0800378 // From ACMVADCallback in the ACM
379 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000380
kwiberg55b97fe2016-01-28 05:22:45 -0800381 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000382
kwiberg55b97fe2016-01-28 05:22:45 -0800383 // From RtpData in the RTP/RTCP module
384 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
385 size_t payloadSize,
386 const WebRtcRTPHeader* rtpHeader) override;
387 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000388
kwiberg55b97fe2016-01-28 05:22:45 -0800389 // From RtpFeedback in the RTP/RTCP module
390 int32_t OnInitializeDecoder(int8_t payloadType,
391 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
392 int frequency,
393 size_t channels,
394 uint32_t rate) override;
395 void OnIncomingSSRCChanged(uint32_t ssrc) override;
396 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000397
kwiberg55b97fe2016-01-28 05:22:45 -0800398 // From RtpAudioFeedback in the RTP/RTCP module
399 void OnPlayTelephoneEvent(uint8_t event,
400 uint16_t lengthMs,
401 uint8_t volume) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000402
kwiberg55b97fe2016-01-28 05:22:45 -0800403 // From Transport (called by the RTP/RTCP module)
404 bool SendRtp(const uint8_t* data,
405 size_t len,
406 const PacketOptions& packet_options) override;
407 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000408
kwiberg55b97fe2016-01-28 05:22:45 -0800409 // From MixerParticipant
410 int32_t GetAudioFrame(int32_t id, AudioFrame* audioFrame) override;
411 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000412
kwiberg55b97fe2016-01-28 05:22:45 -0800413 // From FileCallback
414 void PlayNotification(int32_t id, uint32_t durationMs) override;
415 void RecordNotification(int32_t id, uint32_t durationMs) override;
416 void PlayFileEnded(int32_t id) override;
417 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000418
kwiberg55b97fe2016-01-28 05:22:45 -0800419 uint32_t InstanceId() const { return _instanceId; }
420 int32_t ChannelId() const { return _channelId; }
421 bool Playing() const { return channel_state_.Get().playing; }
422 bool Sending() const { return channel_state_.Get().sending; }
423 bool Receiving() const { return channel_state_.Get().receiving; }
424 bool ExternalTransport() const {
425 rtc::CritScope cs(&_callbackCritSect);
426 return _externalTransport;
427 }
428 bool ExternalMixing() const { return _externalMixing; }
429 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
430 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
431 uint32_t Demultiplex(const AudioFrame& audioFrame);
432 // Demultiplex the data to the channel's |_audioFrame|. The difference
433 // between this method and the overloaded method above is that |audio_data|
434 // does not go through transmit_mixer and APM.
435 void Demultiplex(const int16_t* audio_data,
436 int sample_rate,
437 size_t number_of_frames,
438 size_t number_of_channels);
439 uint32_t PrepareEncodeAndSend(int mixingFrequency);
440 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000441
kwiberg55b97fe2016-01-28 05:22:45 -0800442 // Associate to a send channel.
443 // Used for obtaining RTT for a receive-only channel.
444 void set_associate_send_channel(const ChannelOwner& channel) {
445 assert(_channelId != channel.channel()->ChannelId());
446 rtc::CritScope lock(&assoc_send_channel_lock_);
447 associate_send_channel_ = channel;
448 }
Minyue2013aec2015-05-13 14:14:42 +0200449
kwiberg55b97fe2016-01-28 05:22:45 -0800450 // Disassociate a send channel if it was associated.
451 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200452
kwiberg55b97fe2016-01-28 05:22:45 -0800453 protected:
454 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000455
kwiberg55b97fe2016-01-28 05:22:45 -0800456 private:
457 bool ReceivePacket(const uint8_t* packet,
458 size_t packet_length,
459 const RTPHeader& header,
460 bool in_order);
461 bool HandleRtxPacket(const uint8_t* packet,
462 size_t packet_length,
463 const RTPHeader& header);
464 bool IsPacketInOrder(const RTPHeader& header) const;
465 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
466 int ResendPackets(const uint16_t* sequence_numbers, int length);
solenberg3ecb5c82016-03-09 07:31:58 -0800467 int InsertInbandDtmfTone();
kwiberg55b97fe2016-01-28 05:22:45 -0800468 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
469 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
470 void UpdatePlayoutTimestamp(bool rtcp);
471 void UpdatePacketDelay(uint32_t timestamp, uint16_t sequenceNumber);
472 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000473
kwiberg55b97fe2016-01-28 05:22:45 -0800474 int SetRedPayloadType(int red_payload_type);
475 int SetSendRtpHeaderExtension(bool enable,
476 RTPExtensionType type,
477 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000478
kwiberg55b97fe2016-01-28 05:22:45 -0800479 int32_t GetPlayoutFrequency();
480 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000481
pbosd8de1152016-02-01 09:00:51 -0800482 rtc::CriticalSection _fileCritSect;
483 rtc::CriticalSection _callbackCritSect;
484 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800485 uint32_t _instanceId;
486 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000487
kwiberg55b97fe2016-01-28 05:22:45 -0800488 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000489
kwiberg55b97fe2016-01-28 05:22:45 -0800490 RtcEventLog* const event_log_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200491
kwibergb7f89d62016-02-17 10:04:18 -0800492 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
493 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
494 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
495 std::unique_ptr<StatisticsProxy> statistics_proxy_;
496 std::unique_ptr<RtpReceiver> rtp_receiver_;
kwiberg55b97fe2016-01-28 05:22:45 -0800497 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800498 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
499 std::unique_ptr<AudioCodingModule> audio_coding_;
500 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800501 AudioLevel _outputAudioLevel;
502 bool _externalTransport;
503 AudioFrame _audioFrame;
504 // Downsamples to the codec rate if necessary.
505 PushResampler<int16_t> input_resampler_;
506 FilePlayer* _inputFilePlayerPtr;
507 FilePlayer* _outputFilePlayerPtr;
508 FileRecorder* _outputFileRecorderPtr;
509 int _inputFilePlayerId;
510 int _outputFilePlayerId;
511 int _outputFileRecorderId;
512 bool _outputFileRecording;
solenberg3ecb5c82016-03-09 07:31:58 -0800513 DtmfInbandQueue _inbandDtmfQueue;
514 DtmfInband _inbandDtmfGenerator;
kwiberg55b97fe2016-01-28 05:22:45 -0800515 bool _outputExternalMedia;
516 VoEMediaProcess* _inputExternalMediaCallbackPtr;
517 VoEMediaProcess* _outputExternalMediaCallbackPtr;
518 uint32_t _timeStamp;
solenberg3ecb5c82016-03-09 07:31:58 -0800519 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000520
kwiberg55b97fe2016-01-28 05:22:45 -0800521 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000522
kwiberg55b97fe2016-01-28 05:22:45 -0800523 // Timestamp of the audio pulled from NetEq.
524 uint32_t jitter_buffer_playout_timestamp_;
525 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
526 uint32_t playout_timestamp_rtcp_;
527 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
528 uint32_t _numberOfDiscardedPackets;
529 uint16_t send_sequence_number_;
530 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000531
pbosd8de1152016-02-01 09:00:51 -0800532 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000533
kwibergb7f89d62016-02-17 10:04:18 -0800534 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800535 // The rtp timestamp of the first played out audio frame.
536 int64_t capture_start_rtp_time_stamp_;
537 // The capture ntp time (in local timebase) of the first played out audio
538 // frame.
539 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000540
kwiberg55b97fe2016-01-28 05:22:45 -0800541 // uses
542 Statistics* _engineStatisticsPtr;
543 OutputMixer* _outputMixerPtr;
544 TransmitMixer* _transmitMixerPtr;
545 ProcessThread* _moduleProcessThreadPtr;
546 AudioDeviceModule* _audioDeviceModulePtr;
547 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
548 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
549 Transport* _transportPtr; // WebRtc socket or external transport
550 RMSLevel rms_level_;
kwibergb7f89d62016-02-17 10:04:18 -0800551 std::unique_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800552 VoERxVadCallback* _rxVadObserverPtr;
553 int32_t _oldVadDecision;
554 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
555 // VoEBase
556 bool _externalMixing;
557 bool _mixFileWithMicrophone;
558 // VoEVolumeControl
559 bool _mute;
560 float _panLeft;
561 float _panRight;
562 float _outputGain;
solenberg3ecb5c82016-03-09 07:31:58 -0800563 // VoEDtmf
564 bool _playOutbandDtmfEvent;
565 bool _playInbandDtmfEvent;
kwiberg55b97fe2016-01-28 05:22:45 -0800566 // VoeRTP_RTCP
567 uint32_t _lastLocalTimeStamp;
568 int8_t _lastPayloadType;
569 bool _includeAudioLevelIndication;
570 // VoENetwork
571 AudioFrame::SpeechType _outputSpeechType;
572 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800573 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800574 uint32_t _average_jitter_buffer_delay_us GUARDED_BY(video_sync_lock_);
575 uint32_t _previousTimestamp;
576 uint16_t _recPacketDelayMs GUARDED_BY(video_sync_lock_);
577 // VoEAudioProcessing
578 bool _RxVadDetection;
579 bool _rxAgcIsEnabled;
580 bool _rxNsIsEnabled;
581 bool restored_packet_in_use_;
582 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800583 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
584 std::unique_ptr<NetworkPredictor> network_predictor_;
kwiberg55b97fe2016-01-28 05:22:45 -0800585 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800586 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800587 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100588
kwiberg55b97fe2016-01-28 05:22:45 -0800589 bool pacing_enabled_;
590 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800591 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
592 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
593 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000594};
595
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000596} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000597} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000598
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000599#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_