blob: f1f6ba256779dd692380043b3022eec5d372f4e0 [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"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000028#include "webrtc/voice_engine/include/voe_audio_processing.h"
29#include "webrtc/voice_engine/include/voe_network.h"
30#include "webrtc/voice_engine/level_indicator.h"
minyue@webrtc.org74aaf292014-07-16 21:28:26 +000031#include "webrtc/voice_engine/network_predictor.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000032#include "webrtc/voice_engine/shared_data.h"
33#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000034
wu@webrtc.org94454b72014-06-05 20:34:08 +000035namespace rtc {
36
37class TimestampWrapAroundHandler;
38}
39
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000040namespace webrtc {
41
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000042class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000043class Config;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000044class FileWrapper;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010045class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000046class ProcessThread;
47class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000048class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070049class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000050class RTPPayloadRegistry;
51class RtpReceiver;
52class RTPReceiverAudio;
53class RtpRtcp;
54class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000055class VoEMediaProcess;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000056class VoERTPObserver;
57class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
59struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000060struct ReportBlock;
61struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000063namespace voe {
64
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000065class OutputMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010066class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000067class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000068class StatisticsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010069class TransportFeedbackProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000070class TransmitMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010071class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000072class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000073
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000074// Helper class to simplify locking scheme for members that are accessed from
75// multiple threads.
76// Example: a member can be set on thread T1 and read by an internal audio
77// thread T2. Accessing the member via this class ensures that we are
78// safe and also avoid TSan v2 warnings.
79class ChannelState {
80 public:
kwiberg55b97fe2016-01-28 05:22:45 -080081 struct State {
82 State()
83 : rx_apm_is_enabled(false),
84 input_external_media(false),
85 output_file_playing(false),
86 input_file_playing(false),
87 playing(false),
88 sending(false),
89 receiving(false) {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000090
kwiberg55b97fe2016-01-28 05:22:45 -080091 bool rx_apm_is_enabled;
92 bool input_external_media;
93 bool output_file_playing;
94 bool input_file_playing;
95 bool playing;
96 bool sending;
97 bool receiving;
98 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000099
kwiberg55b97fe2016-01-28 05:22:45 -0800100 ChannelState() {}
101 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000102
kwiberg55b97fe2016-01-28 05:22:45 -0800103 void Reset() {
104 rtc::CritScope lock(&lock_);
105 state_ = State();
106 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000107
kwiberg55b97fe2016-01-28 05:22:45 -0800108 State Get() const {
109 rtc::CritScope lock(&lock_);
110 return state_;
111 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000112
kwiberg55b97fe2016-01-28 05:22:45 -0800113 void SetRxApmIsEnabled(bool enable) {
114 rtc::CritScope lock(&lock_);
115 state_.rx_apm_is_enabled = enable;
116 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000117
kwiberg55b97fe2016-01-28 05:22:45 -0800118 void SetInputExternalMedia(bool enable) {
119 rtc::CritScope lock(&lock_);
120 state_.input_external_media = enable;
121 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000122
kwiberg55b97fe2016-01-28 05:22:45 -0800123 void SetOutputFilePlaying(bool enable) {
124 rtc::CritScope lock(&lock_);
125 state_.output_file_playing = enable;
126 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000127
kwiberg55b97fe2016-01-28 05:22:45 -0800128 void SetInputFilePlaying(bool enable) {
129 rtc::CritScope lock(&lock_);
130 state_.input_file_playing = enable;
131 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000132
kwiberg55b97fe2016-01-28 05:22:45 -0800133 void SetPlaying(bool enable) {
134 rtc::CritScope lock(&lock_);
135 state_.playing = enable;
136 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000137
kwiberg55b97fe2016-01-28 05:22:45 -0800138 void SetSending(bool enable) {
139 rtc::CritScope lock(&lock_);
140 state_.sending = enable;
141 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000142
kwiberg55b97fe2016-01-28 05:22:45 -0800143 void SetReceiving(bool enable) {
144 rtc::CritScope lock(&lock_);
145 state_.receiving = enable;
146 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000147
kwiberg55b97fe2016-01-28 05:22:45 -0800148 private:
pbosd8de1152016-02-01 09:00:51 -0800149 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800150 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000151};
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
kwiberg55b97fe2016-01-28 05:22:45 -0800153class Channel
154 : public RtpData,
155 public RtpFeedback,
156 public FileCallback, // receiving notification from file player &
157 // recorder
158 public Transport,
159 public RtpAudioFeedback,
160 public AudioPacketizationCallback, // receive encoded packets from the
161 // ACM
162 public ACMVADCallback, // receive voice activity from the ACM
163 public MixerParticipant // supplies output mixer with audio frames
niklase@google.com470e71d2011-07-07 08:21:25 +0000164{
kwiberg55b97fe2016-01-28 05:22:45 -0800165 public:
166 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000167
kwiberg55b97fe2016-01-28 05:22:45 -0800168 enum { KNumSocketThreads = 1 };
169 enum { KNumberOfSocketBuffers = 8 };
170 virtual ~Channel();
171 static int32_t CreateChannel(Channel*& channel,
172 int32_t channelId,
173 uint32_t instanceId,
174 RtcEventLog* const event_log,
175 const Config& config);
176 Channel(int32_t channelId,
177 uint32_t instanceId,
178 RtcEventLog* const event_log,
179 const Config& config);
180 int32_t Init();
181 int32_t SetEngineInformation(Statistics& engineStatistics,
182 OutputMixer& outputMixer,
183 TransmitMixer& transmitMixer,
184 ProcessThread& moduleProcessThread,
185 AudioDeviceModule& audioDeviceModule,
186 VoiceEngineObserver* voiceEngineObserver,
187 rtc::CriticalSection* callbackCritSect);
188 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
kwibergb7f89d62016-02-17 10:04:18 -0800190 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100191
kwiberg55b97fe2016-01-28 05:22:45 -0800192 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
kwiberg55b97fe2016-01-28 05:22:45 -0800194 // VoEBase
195 int32_t StartPlayout();
196 int32_t StopPlayout();
197 int32_t StartSend();
198 int32_t StopSend();
199 int32_t StartReceiving();
200 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
kwiberg55b97fe2016-01-28 05:22:45 -0800202 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
203 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000204
kwiberg55b97fe2016-01-28 05:22:45 -0800205 // VoECodec
206 int32_t GetSendCodec(CodecInst& codec);
207 int32_t GetRecCodec(CodecInst& codec);
208 int32_t SetSendCodec(const CodecInst& codec);
209 void SetBitRate(int bitrate_bps);
210 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
211 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
212 int32_t SetRecPayloadType(const CodecInst& codec);
213 int32_t GetRecPayloadType(CodecInst& codec);
214 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
215 int SetOpusMaxPlaybackRate(int frequency_hz);
216 int SetOpusDtx(bool enable_dtx);
niklase@google.com470e71d2011-07-07 08:21:25 +0000217
kwiberg55b97fe2016-01-28 05:22:45 -0800218 // VoENetwork
219 int32_t RegisterExternalTransport(Transport& transport);
220 int32_t DeRegisterExternalTransport();
221 int32_t ReceivedRTPPacket(const int8_t* data,
222 size_t length,
223 const PacketTime& packet_time);
224 int32_t ReceivedRTCPPacket(const int8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000225
kwiberg55b97fe2016-01-28 05:22:45 -0800226 // VoEFile
227 int StartPlayingFileLocally(const char* fileName,
228 bool loop,
229 FileFormats format,
230 int startPosition,
231 float volumeScaling,
232 int stopPosition,
233 const CodecInst* codecInst);
234 int StartPlayingFileLocally(InStream* stream,
235 FileFormats format,
236 int startPosition,
237 float volumeScaling,
238 int stopPosition,
239 const CodecInst* codecInst);
240 int StopPlayingFileLocally();
241 int IsPlayingFileLocally() const;
242 int RegisterFilePlayingToMixer();
243 int StartPlayingFileAsMicrophone(const char* fileName,
244 bool loop,
245 FileFormats format,
246 int startPosition,
247 float volumeScaling,
248 int stopPosition,
249 const CodecInst* codecInst);
250 int StartPlayingFileAsMicrophone(InStream* stream,
251 FileFormats format,
252 int startPosition,
253 float volumeScaling,
254 int stopPosition,
255 const CodecInst* codecInst);
256 int StopPlayingFileAsMicrophone();
257 int IsPlayingFileAsMicrophone() const;
258 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
259 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
260 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000261
kwiberg55b97fe2016-01-28 05:22:45 -0800262 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000263
kwiberg55b97fe2016-01-28 05:22:45 -0800264 // VoEExternalMediaProcessing
265 int RegisterExternalMediaProcessing(ProcessingTypes type,
266 VoEMediaProcess& processObject);
267 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
268 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
kwiberg55b97fe2016-01-28 05:22:45 -0800270 // VoEVolumeControl
271 int GetSpeechOutputLevel(uint32_t& level) const;
272 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
273 int SetMute(bool enable);
274 bool Mute() const;
275 int SetOutputVolumePan(float left, float right);
276 int GetOutputVolumePan(float& left, float& right) const;
277 int SetChannelOutputVolumeScaling(float scaling);
278 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000279
kwiberg55b97fe2016-01-28 05:22:45 -0800280 // VoENetEqStats
281 int GetNetworkStatistics(NetworkStatistics& stats);
282 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000283
kwiberg55b97fe2016-01-28 05:22:45 -0800284 // VoEVideoSync
285 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
286 int* playout_buffer_delay_ms) const;
287 uint32_t GetDelayEstimate() const;
288 int LeastRequiredDelayMs() const;
289 int SetMinimumPlayoutDelay(int delayMs);
290 int GetPlayoutTimestamp(unsigned int& timestamp);
291 int SetInitTimestamp(unsigned int timestamp);
292 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000293
kwiberg55b97fe2016-01-28 05:22:45 -0800294 // VoEVideoSyncExtended
295 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000296
solenberg3ecb5c82016-03-09 07:31:58 -0800297 // VoEDtmf
solenberg8842c3e2016-03-11 03:06:41 -0800298 int SendTelephoneEventOutband(int event, int duration_ms);
solenberg3ecb5c82016-03-09 07:31:58 -0800299 int SetSendTelephoneEventPayloadType(unsigned char type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000300
kwiberg55b97fe2016-01-28 05:22:45 -0800301 // VoEAudioProcessingImpl
302 int UpdateRxVadDetection(AudioFrame& audioFrame);
303 int RegisterRxVadObserver(VoERxVadCallback& observer);
304 int DeRegisterRxVadObserver();
305 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000306#ifdef WEBRTC_VOICE_ENGINE_AGC
kwiberg55b97fe2016-01-28 05:22:45 -0800307 int SetRxAgcStatus(bool enable, AgcModes mode);
308 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
309 int SetRxAgcConfig(AgcConfig config);
310 int GetRxAgcConfig(AgcConfig& config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000311#endif
312#ifdef WEBRTC_VOICE_ENGINE_NR
kwiberg55b97fe2016-01-28 05:22:45 -0800313 int SetRxNsStatus(bool enable, NsModes mode);
314 int GetRxNsStatus(bool& enabled, NsModes& mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000315#endif
316
kwiberg55b97fe2016-01-28 05:22:45 -0800317 // VoERTP_RTCP
318 int SetLocalSSRC(unsigned int ssrc);
319 int GetLocalSSRC(unsigned int& ssrc);
320 int GetRemoteSSRC(unsigned int& ssrc);
321 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
322 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
323 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
324 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
325 void EnableSendTransportSequenceNumber(int id);
326 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100327
stefanbba9dec2016-02-01 04:39:55 -0800328 void RegisterSenderCongestionControlObjects(
329 RtpPacketSender* rtp_packet_sender,
330 TransportFeedbackObserver* transport_feedback_observer,
331 PacketRouter* packet_router);
332 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
333 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100334
kwiberg55b97fe2016-01-28 05:22:45 -0800335 void SetRTCPStatus(bool enable);
336 int GetRTCPStatus(bool& enabled);
337 int SetRTCP_CNAME(const char cName[256]);
338 int GetRemoteRTCP_CNAME(char cName[256]);
339 int GetRemoteRTCPData(unsigned int& NTPHigh,
340 unsigned int& NTPLow,
341 unsigned int& timestamp,
342 unsigned int& playoutTimestamp,
343 unsigned int* jitter,
344 unsigned short* fractionLost);
345 int SendApplicationDefinedRTCPPacket(unsigned char subType,
346 unsigned int name,
347 const char* data,
348 unsigned short dataLengthInBytes);
349 int GetRTPStatistics(unsigned int& averageJitterMs,
350 unsigned int& maxJitterMs,
351 unsigned int& discardedPackets);
352 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
353 int GetRTPStatistics(CallStatistics& stats);
354 int SetREDStatus(bool enable, int redPayloadtype);
355 int GetREDStatus(bool& enabled, int& redPayloadtype);
356 int SetCodecFECStatus(bool enable);
357 bool GetCodecFECStatus();
358 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000359
kwiberg55b97fe2016-01-28 05:22:45 -0800360 // From AudioPacketizationCallback in the ACM
361 int32_t SendData(FrameType frameType,
362 uint8_t payloadType,
363 uint32_t timeStamp,
364 const uint8_t* payloadData,
365 size_t payloadSize,
366 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000367
kwiberg55b97fe2016-01-28 05:22:45 -0800368 // From ACMVADCallback in the ACM
369 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000370
kwiberg55b97fe2016-01-28 05:22:45 -0800371 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000372
kwiberg55b97fe2016-01-28 05:22:45 -0800373 // From RtpData in the RTP/RTCP module
374 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
375 size_t payloadSize,
376 const WebRtcRTPHeader* rtpHeader) override;
377 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000378
kwiberg55b97fe2016-01-28 05:22:45 -0800379 // From RtpFeedback in the RTP/RTCP module
380 int32_t OnInitializeDecoder(int8_t payloadType,
381 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
382 int frequency,
383 size_t channels,
384 uint32_t rate) override;
385 void OnIncomingSSRCChanged(uint32_t ssrc) override;
386 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000387
kwiberg55b97fe2016-01-28 05:22:45 -0800388 // From RtpAudioFeedback in the RTP/RTCP module
389 void OnPlayTelephoneEvent(uint8_t event,
390 uint16_t lengthMs,
391 uint8_t volume) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000392
kwiberg55b97fe2016-01-28 05:22:45 -0800393 // From Transport (called by the RTP/RTCP module)
394 bool SendRtp(const uint8_t* data,
395 size_t len,
396 const PacketOptions& packet_options) override;
397 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000398
kwiberg55b97fe2016-01-28 05:22:45 -0800399 // From MixerParticipant
400 int32_t GetAudioFrame(int32_t id, AudioFrame* audioFrame) override;
401 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000402
kwiberg55b97fe2016-01-28 05:22:45 -0800403 // From FileCallback
404 void PlayNotification(int32_t id, uint32_t durationMs) override;
405 void RecordNotification(int32_t id, uint32_t durationMs) override;
406 void PlayFileEnded(int32_t id) override;
407 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000408
kwiberg55b97fe2016-01-28 05:22:45 -0800409 uint32_t InstanceId() const { return _instanceId; }
410 int32_t ChannelId() const { return _channelId; }
411 bool Playing() const { return channel_state_.Get().playing; }
412 bool Sending() const { return channel_state_.Get().sending; }
413 bool Receiving() const { return channel_state_.Get().receiving; }
414 bool ExternalTransport() const {
415 rtc::CritScope cs(&_callbackCritSect);
416 return _externalTransport;
417 }
418 bool ExternalMixing() const { return _externalMixing; }
419 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
420 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
421 uint32_t Demultiplex(const AudioFrame& audioFrame);
422 // Demultiplex the data to the channel's |_audioFrame|. The difference
423 // between this method and the overloaded method above is that |audio_data|
424 // does not go through transmit_mixer and APM.
425 void Demultiplex(const int16_t* audio_data,
426 int sample_rate,
427 size_t number_of_frames,
428 size_t number_of_channels);
429 uint32_t PrepareEncodeAndSend(int mixingFrequency);
430 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000431
kwiberg55b97fe2016-01-28 05:22:45 -0800432 // Associate to a send channel.
433 // Used for obtaining RTT for a receive-only channel.
434 void set_associate_send_channel(const ChannelOwner& channel) {
435 assert(_channelId != channel.channel()->ChannelId());
436 rtc::CritScope lock(&assoc_send_channel_lock_);
437 associate_send_channel_ = channel;
438 }
Minyue2013aec2015-05-13 14:14:42 +0200439
kwiberg55b97fe2016-01-28 05:22:45 -0800440 // Disassociate a send channel if it was associated.
441 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200442
kwiberg55b97fe2016-01-28 05:22:45 -0800443 protected:
444 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000445
kwiberg55b97fe2016-01-28 05:22:45 -0800446 private:
447 bool ReceivePacket(const uint8_t* packet,
448 size_t packet_length,
449 const RTPHeader& header,
450 bool in_order);
451 bool HandleRtxPacket(const uint8_t* packet,
452 size_t packet_length,
453 const RTPHeader& header);
454 bool IsPacketInOrder(const RTPHeader& header) const;
455 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
456 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800457 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
458 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
459 void UpdatePlayoutTimestamp(bool rtcp);
460 void UpdatePacketDelay(uint32_t timestamp, uint16_t sequenceNumber);
461 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000462
kwiberg55b97fe2016-01-28 05:22:45 -0800463 int SetRedPayloadType(int red_payload_type);
464 int SetSendRtpHeaderExtension(bool enable,
465 RTPExtensionType type,
466 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000467
kwiberg55b97fe2016-01-28 05:22:45 -0800468 int32_t GetPlayoutFrequency();
469 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000470
pbosd8de1152016-02-01 09:00:51 -0800471 rtc::CriticalSection _fileCritSect;
472 rtc::CriticalSection _callbackCritSect;
473 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800474 uint32_t _instanceId;
475 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000476
kwiberg55b97fe2016-01-28 05:22:45 -0800477 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000478
kwiberg55b97fe2016-01-28 05:22:45 -0800479 RtcEventLog* const event_log_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200480
kwibergb7f89d62016-02-17 10:04:18 -0800481 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
482 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
483 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
484 std::unique_ptr<StatisticsProxy> statistics_proxy_;
485 std::unique_ptr<RtpReceiver> rtp_receiver_;
kwiberg55b97fe2016-01-28 05:22:45 -0800486 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800487 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
488 std::unique_ptr<AudioCodingModule> audio_coding_;
489 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800490 AudioLevel _outputAudioLevel;
491 bool _externalTransport;
492 AudioFrame _audioFrame;
493 // Downsamples to the codec rate if necessary.
494 PushResampler<int16_t> input_resampler_;
495 FilePlayer* _inputFilePlayerPtr;
496 FilePlayer* _outputFilePlayerPtr;
497 FileRecorder* _outputFileRecorderPtr;
498 int _inputFilePlayerId;
499 int _outputFilePlayerId;
500 int _outputFileRecorderId;
501 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800502 bool _outputExternalMedia;
503 VoEMediaProcess* _inputExternalMediaCallbackPtr;
504 VoEMediaProcess* _outputExternalMediaCallbackPtr;
505 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000506
kwiberg55b97fe2016-01-28 05:22:45 -0800507 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000508
kwiberg55b97fe2016-01-28 05:22:45 -0800509 // Timestamp of the audio pulled from NetEq.
510 uint32_t jitter_buffer_playout_timestamp_;
511 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
512 uint32_t playout_timestamp_rtcp_;
513 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
514 uint32_t _numberOfDiscardedPackets;
515 uint16_t send_sequence_number_;
516 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000517
pbosd8de1152016-02-01 09:00:51 -0800518 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000519
kwibergb7f89d62016-02-17 10:04:18 -0800520 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800521 // The rtp timestamp of the first played out audio frame.
522 int64_t capture_start_rtp_time_stamp_;
523 // The capture ntp time (in local timebase) of the first played out audio
524 // frame.
525 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000526
kwiberg55b97fe2016-01-28 05:22:45 -0800527 // uses
528 Statistics* _engineStatisticsPtr;
529 OutputMixer* _outputMixerPtr;
530 TransmitMixer* _transmitMixerPtr;
531 ProcessThread* _moduleProcessThreadPtr;
532 AudioDeviceModule* _audioDeviceModulePtr;
533 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
534 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
535 Transport* _transportPtr; // WebRtc socket or external transport
536 RMSLevel rms_level_;
kwibergb7f89d62016-02-17 10:04:18 -0800537 std::unique_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800538 VoERxVadCallback* _rxVadObserverPtr;
539 int32_t _oldVadDecision;
540 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
541 // VoEBase
542 bool _externalMixing;
543 bool _mixFileWithMicrophone;
544 // VoEVolumeControl
545 bool _mute;
546 float _panLeft;
547 float _panRight;
548 float _outputGain;
solenberg3ecb5c82016-03-09 07:31:58 -0800549 // VoEDtmf
550 bool _playOutbandDtmfEvent;
kwiberg55b97fe2016-01-28 05:22:45 -0800551 // VoeRTP_RTCP
552 uint32_t _lastLocalTimeStamp;
553 int8_t _lastPayloadType;
554 bool _includeAudioLevelIndication;
555 // VoENetwork
556 AudioFrame::SpeechType _outputSpeechType;
557 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800558 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800559 uint32_t _average_jitter_buffer_delay_us GUARDED_BY(video_sync_lock_);
560 uint32_t _previousTimestamp;
561 uint16_t _recPacketDelayMs GUARDED_BY(video_sync_lock_);
562 // VoEAudioProcessing
563 bool _RxVadDetection;
564 bool _rxAgcIsEnabled;
565 bool _rxNsIsEnabled;
566 bool restored_packet_in_use_;
567 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800568 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
569 std::unique_ptr<NetworkPredictor> network_predictor_;
kwiberg55b97fe2016-01-28 05:22:45 -0800570 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800571 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800572 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100573
kwiberg55b97fe2016-01-28 05:22:45 -0800574 bool pacing_enabled_;
575 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800576 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
577 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
578 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000579};
580
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000581} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000582} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000583
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000584#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_