blob: 14bfc2bba0dd35dc979ca5b09b2e014aedd078cf [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
Tommif888bb52015-12-12 01:37:01 +010014#include "webrtc/audio/audio_sink.h"
Stefan Holmerb86d4e42015-12-07 10:26:18 +010015#include "webrtc/base/criticalsection.h"
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000016#include "webrtc/base/scoped_ptr.h"
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000017#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000018#include "webrtc/common_types.h"
kjellander3e6db232015-11-26 04:44:54 -080019#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010020#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000021#include "webrtc/modules/audio_processing/rms_level.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010022#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
23#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
24#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
25#include "webrtc/modules/utility/include/file_player.h"
26#include "webrtc/modules/utility/include/file_recorder.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000027#include "webrtc/voice_engine/dtmf_inband.h"
28#include "webrtc/voice_engine/dtmf_inband_queue.h"
29#include "webrtc/voice_engine/include/voe_audio_processing.h"
30#include "webrtc/voice_engine/include/voe_network.h"
31#include "webrtc/voice_engine/level_indicator.h"
minyue@webrtc.org74aaf292014-07-16 21:28:26 +000032#include "webrtc/voice_engine/network_predictor.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000033#include "webrtc/voice_engine/shared_data.h"
34#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000035
niklase@google.com470e71d2011-07-07 08:21:25 +000036#ifdef WEBRTC_DTMF_DETECTION
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000037// TelephoneEventDetectionMethods, TelephoneEventObserver
38#include "webrtc/voice_engine/include/voe_dtmf.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000039#endif
40
wu@webrtc.org94454b72014-06-05 20:34:08 +000041namespace rtc {
42
43class TimestampWrapAroundHandler;
44}
45
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000046namespace webrtc {
47
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000048class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000049class Config;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000050class FileWrapper;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010051class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000052class ProcessThread;
53class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000054class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070055class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000056class RTPPayloadRegistry;
57class RtpReceiver;
58class RTPReceiverAudio;
59class RtpRtcp;
60class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000061class VoEMediaProcess;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000062class VoERTPObserver;
63class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
65struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000066struct ReportBlock;
67struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000068
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000069namespace voe {
70
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000071class OutputMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010072class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000073class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000074class StatisticsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010075class TransportFeedbackProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000076class TransmitMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010077class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000078class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000079
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000080// Helper class to simplify locking scheme for members that are accessed from
81// multiple threads.
82// Example: a member can be set on thread T1 and read by an internal audio
83// thread T2. Accessing the member via this class ensures that we are
84// safe and also avoid TSan v2 warnings.
85class ChannelState {
86 public:
kwiberg55b97fe2016-01-28 05:22:45 -080087 struct State {
88 State()
89 : rx_apm_is_enabled(false),
90 input_external_media(false),
91 output_file_playing(false),
92 input_file_playing(false),
93 playing(false),
94 sending(false),
95 receiving(false) {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000096
kwiberg55b97fe2016-01-28 05:22:45 -080097 bool rx_apm_is_enabled;
98 bool input_external_media;
99 bool output_file_playing;
100 bool input_file_playing;
101 bool playing;
102 bool sending;
103 bool receiving;
104 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000105
kwiberg55b97fe2016-01-28 05:22:45 -0800106 ChannelState() {}
107 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000108
kwiberg55b97fe2016-01-28 05:22:45 -0800109 void Reset() {
110 rtc::CritScope lock(&lock_);
111 state_ = State();
112 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000113
kwiberg55b97fe2016-01-28 05:22:45 -0800114 State Get() const {
115 rtc::CritScope lock(&lock_);
116 return state_;
117 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000118
kwiberg55b97fe2016-01-28 05:22:45 -0800119 void SetRxApmIsEnabled(bool enable) {
120 rtc::CritScope lock(&lock_);
121 state_.rx_apm_is_enabled = enable;
122 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000123
kwiberg55b97fe2016-01-28 05:22:45 -0800124 void SetInputExternalMedia(bool enable) {
125 rtc::CritScope lock(&lock_);
126 state_.input_external_media = enable;
127 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000128
kwiberg55b97fe2016-01-28 05:22:45 -0800129 void SetOutputFilePlaying(bool enable) {
130 rtc::CritScope lock(&lock_);
131 state_.output_file_playing = enable;
132 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000133
kwiberg55b97fe2016-01-28 05:22:45 -0800134 void SetInputFilePlaying(bool enable) {
135 rtc::CritScope lock(&lock_);
136 state_.input_file_playing = enable;
137 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000138
kwiberg55b97fe2016-01-28 05:22:45 -0800139 void SetPlaying(bool enable) {
140 rtc::CritScope lock(&lock_);
141 state_.playing = enable;
142 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000143
kwiberg55b97fe2016-01-28 05:22:45 -0800144 void SetSending(bool enable) {
145 rtc::CritScope lock(&lock_);
146 state_.sending = enable;
147 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000148
kwiberg55b97fe2016-01-28 05:22:45 -0800149 void SetReceiving(bool enable) {
150 rtc::CritScope lock(&lock_);
151 state_.receiving = enable;
152 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000153
kwiberg55b97fe2016-01-28 05:22:45 -0800154 private:
155 mutable rtc::CriticalSection lock_;
156 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000157};
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
kwiberg55b97fe2016-01-28 05:22:45 -0800159class Channel
160 : public RtpData,
161 public RtpFeedback,
162 public FileCallback, // receiving notification from file player &
163 // recorder
164 public Transport,
165 public RtpAudioFeedback,
166 public AudioPacketizationCallback, // receive encoded packets from the
167 // ACM
168 public ACMVADCallback, // receive voice activity from the ACM
169 public MixerParticipant // supplies output mixer with audio frames
niklase@google.com470e71d2011-07-07 08:21:25 +0000170{
kwiberg55b97fe2016-01-28 05:22:45 -0800171 public:
172 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000173
kwiberg55b97fe2016-01-28 05:22:45 -0800174 enum { KNumSocketThreads = 1 };
175 enum { KNumberOfSocketBuffers = 8 };
176 virtual ~Channel();
177 static int32_t CreateChannel(Channel*& channel,
178 int32_t channelId,
179 uint32_t instanceId,
180 RtcEventLog* const event_log,
181 const Config& config);
182 Channel(int32_t channelId,
183 uint32_t instanceId,
184 RtcEventLog* const event_log,
185 const Config& config);
186 int32_t Init();
187 int32_t SetEngineInformation(Statistics& engineStatistics,
188 OutputMixer& outputMixer,
189 TransmitMixer& transmitMixer,
190 ProcessThread& moduleProcessThread,
191 AudioDeviceModule& audioDeviceModule,
192 VoiceEngineObserver* voiceEngineObserver,
193 rtc::CriticalSection* callbackCritSect);
194 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000195
kwiberg55b97fe2016-01-28 05:22:45 -0800196 void SetSink(rtc::scoped_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100197
kwiberg55b97fe2016-01-28 05:22:45 -0800198 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000199
kwiberg55b97fe2016-01-28 05:22:45 -0800200 // VoEBase
201 int32_t StartPlayout();
202 int32_t StopPlayout();
203 int32_t StartSend();
204 int32_t StopSend();
205 int32_t StartReceiving();
206 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
kwiberg55b97fe2016-01-28 05:22:45 -0800208 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
209 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
kwiberg55b97fe2016-01-28 05:22:45 -0800211 // VoECodec
212 int32_t GetSendCodec(CodecInst& codec);
213 int32_t GetRecCodec(CodecInst& codec);
214 int32_t SetSendCodec(const CodecInst& codec);
215 void SetBitRate(int bitrate_bps);
216 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
217 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
218 int32_t SetRecPayloadType(const CodecInst& codec);
219 int32_t GetRecPayloadType(CodecInst& codec);
220 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
221 int SetOpusMaxPlaybackRate(int frequency_hz);
222 int SetOpusDtx(bool enable_dtx);
niklase@google.com470e71d2011-07-07 08:21:25 +0000223
kwiberg55b97fe2016-01-28 05:22:45 -0800224 // VoENetwork
225 int32_t RegisterExternalTransport(Transport& transport);
226 int32_t DeRegisterExternalTransport();
227 int32_t ReceivedRTPPacket(const int8_t* data,
228 size_t length,
229 const PacketTime& packet_time);
230 int32_t ReceivedRTCPPacket(const int8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000231
kwiberg55b97fe2016-01-28 05:22:45 -0800232 // VoEFile
233 int StartPlayingFileLocally(const char* fileName,
234 bool loop,
235 FileFormats format,
236 int startPosition,
237 float volumeScaling,
238 int stopPosition,
239 const CodecInst* codecInst);
240 int StartPlayingFileLocally(InStream* stream,
241 FileFormats format,
242 int startPosition,
243 float volumeScaling,
244 int stopPosition,
245 const CodecInst* codecInst);
246 int StopPlayingFileLocally();
247 int IsPlayingFileLocally() const;
248 int RegisterFilePlayingToMixer();
249 int StartPlayingFileAsMicrophone(const char* fileName,
250 bool loop,
251 FileFormats format,
252 int startPosition,
253 float volumeScaling,
254 int stopPosition,
255 const CodecInst* codecInst);
256 int StartPlayingFileAsMicrophone(InStream* stream,
257 FileFormats format,
258 int startPosition,
259 float volumeScaling,
260 int stopPosition,
261 const CodecInst* codecInst);
262 int StopPlayingFileAsMicrophone();
263 int IsPlayingFileAsMicrophone() const;
264 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
265 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
266 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000267
kwiberg55b97fe2016-01-28 05:22:45 -0800268 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
kwiberg55b97fe2016-01-28 05:22:45 -0800270 // VoEExternalMediaProcessing
271 int RegisterExternalMediaProcessing(ProcessingTypes type,
272 VoEMediaProcess& processObject);
273 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
274 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000275
kwiberg55b97fe2016-01-28 05:22:45 -0800276 // VoEVolumeControl
277 int GetSpeechOutputLevel(uint32_t& level) const;
278 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
279 int SetMute(bool enable);
280 bool Mute() const;
281 int SetOutputVolumePan(float left, float right);
282 int GetOutputVolumePan(float& left, float& right) const;
283 int SetChannelOutputVolumeScaling(float scaling);
284 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000285
kwiberg55b97fe2016-01-28 05:22:45 -0800286 // VoENetEqStats
287 int GetNetworkStatistics(NetworkStatistics& stats);
288 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000289
kwiberg55b97fe2016-01-28 05:22:45 -0800290 // VoEVideoSync
291 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
292 int* playout_buffer_delay_ms) const;
293 uint32_t GetDelayEstimate() const;
294 int LeastRequiredDelayMs() const;
295 int SetMinimumPlayoutDelay(int delayMs);
296 int GetPlayoutTimestamp(unsigned int& timestamp);
297 int SetInitTimestamp(unsigned int timestamp);
298 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000299
kwiberg55b97fe2016-01-28 05:22:45 -0800300 // VoEVideoSyncExtended
301 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000302
kwiberg55b97fe2016-01-28 05:22:45 -0800303 // VoEDtmf
304 int SendTelephoneEventOutband(unsigned char eventCode,
305 int lengthMs,
306 int attenuationDb,
307 bool playDtmfEvent);
308 int SendTelephoneEventInband(unsigned char eventCode,
309 int lengthMs,
310 int attenuationDb,
311 bool playDtmfEvent);
312 int SetSendTelephoneEventPayloadType(unsigned char type);
313 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000314
kwiberg55b97fe2016-01-28 05:22:45 -0800315 // VoEAudioProcessingImpl
316 int UpdateRxVadDetection(AudioFrame& audioFrame);
317 int RegisterRxVadObserver(VoERxVadCallback& observer);
318 int DeRegisterRxVadObserver();
319 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000320#ifdef WEBRTC_VOICE_ENGINE_AGC
kwiberg55b97fe2016-01-28 05:22:45 -0800321 int SetRxAgcStatus(bool enable, AgcModes mode);
322 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
323 int SetRxAgcConfig(AgcConfig config);
324 int GetRxAgcConfig(AgcConfig& config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000325#endif
326#ifdef WEBRTC_VOICE_ENGINE_NR
kwiberg55b97fe2016-01-28 05:22:45 -0800327 int SetRxNsStatus(bool enable, NsModes mode);
328 int GetRxNsStatus(bool& enabled, NsModes& mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000329#endif
330
kwiberg55b97fe2016-01-28 05:22:45 -0800331 // VoERTP_RTCP
332 int SetLocalSSRC(unsigned int ssrc);
333 int GetLocalSSRC(unsigned int& ssrc);
334 int GetRemoteSSRC(unsigned int& ssrc);
335 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
336 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
337 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
338 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
339 void EnableSendTransportSequenceNumber(int id);
340 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100341
kwiberg55b97fe2016-01-28 05:22:45 -0800342 void SetCongestionControlObjects(
343 RtpPacketSender* rtp_packet_sender,
344 TransportFeedbackObserver* transport_feedback_observer,
345 PacketRouter* packet_router);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100346
kwiberg55b97fe2016-01-28 05:22:45 -0800347 void SetRTCPStatus(bool enable);
348 int GetRTCPStatus(bool& enabled);
349 int SetRTCP_CNAME(const char cName[256]);
350 int GetRemoteRTCP_CNAME(char cName[256]);
351 int GetRemoteRTCPData(unsigned int& NTPHigh,
352 unsigned int& NTPLow,
353 unsigned int& timestamp,
354 unsigned int& playoutTimestamp,
355 unsigned int* jitter,
356 unsigned short* fractionLost);
357 int SendApplicationDefinedRTCPPacket(unsigned char subType,
358 unsigned int name,
359 const char* data,
360 unsigned short dataLengthInBytes);
361 int GetRTPStatistics(unsigned int& averageJitterMs,
362 unsigned int& maxJitterMs,
363 unsigned int& discardedPackets);
364 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
365 int GetRTPStatistics(CallStatistics& stats);
366 int SetREDStatus(bool enable, int redPayloadtype);
367 int GetREDStatus(bool& enabled, int& redPayloadtype);
368 int SetCodecFECStatus(bool enable);
369 bool GetCodecFECStatus();
370 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000371
kwiberg55b97fe2016-01-28 05:22:45 -0800372 // From AudioPacketizationCallback in the ACM
373 int32_t SendData(FrameType frameType,
374 uint8_t payloadType,
375 uint32_t timeStamp,
376 const uint8_t* payloadData,
377 size_t payloadSize,
378 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000379
kwiberg55b97fe2016-01-28 05:22:45 -0800380 // From ACMVADCallback in the ACM
381 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000382
kwiberg55b97fe2016-01-28 05:22:45 -0800383 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000384
kwiberg55b97fe2016-01-28 05:22:45 -0800385 // From RtpData in the RTP/RTCP module
386 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
387 size_t payloadSize,
388 const WebRtcRTPHeader* rtpHeader) override;
389 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000390
kwiberg55b97fe2016-01-28 05:22:45 -0800391 // From RtpFeedback in the RTP/RTCP module
392 int32_t OnInitializeDecoder(int8_t payloadType,
393 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
394 int frequency,
395 size_t channels,
396 uint32_t rate) override;
397 void OnIncomingSSRCChanged(uint32_t ssrc) override;
398 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000399
kwiberg55b97fe2016-01-28 05:22:45 -0800400 // From RtpAudioFeedback in the RTP/RTCP module
401 void OnPlayTelephoneEvent(uint8_t event,
402 uint16_t lengthMs,
403 uint8_t volume) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000404
kwiberg55b97fe2016-01-28 05:22:45 -0800405 // From Transport (called by the RTP/RTCP module)
406 bool SendRtp(const uint8_t* data,
407 size_t len,
408 const PacketOptions& packet_options) override;
409 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000410
kwiberg55b97fe2016-01-28 05:22:45 -0800411 // From MixerParticipant
412 int32_t GetAudioFrame(int32_t id, AudioFrame* audioFrame) override;
413 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000414
kwiberg55b97fe2016-01-28 05:22:45 -0800415 // From FileCallback
416 void PlayNotification(int32_t id, uint32_t durationMs) override;
417 void RecordNotification(int32_t id, uint32_t durationMs) override;
418 void PlayFileEnded(int32_t id) override;
419 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000420
kwiberg55b97fe2016-01-28 05:22:45 -0800421 uint32_t InstanceId() const { return _instanceId; }
422 int32_t ChannelId() const { return _channelId; }
423 bool Playing() const { return channel_state_.Get().playing; }
424 bool Sending() const { return channel_state_.Get().sending; }
425 bool Receiving() const { return channel_state_.Get().receiving; }
426 bool ExternalTransport() const {
427 rtc::CritScope cs(&_callbackCritSect);
428 return _externalTransport;
429 }
430 bool ExternalMixing() const { return _externalMixing; }
431 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
432 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
433 uint32_t Demultiplex(const AudioFrame& audioFrame);
434 // Demultiplex the data to the channel's |_audioFrame|. The difference
435 // between this method and the overloaded method above is that |audio_data|
436 // does not go through transmit_mixer and APM.
437 void Demultiplex(const int16_t* audio_data,
438 int sample_rate,
439 size_t number_of_frames,
440 size_t number_of_channels);
441 uint32_t PrepareEncodeAndSend(int mixingFrequency);
442 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000443
kwiberg55b97fe2016-01-28 05:22:45 -0800444 // Associate to a send channel.
445 // Used for obtaining RTT for a receive-only channel.
446 void set_associate_send_channel(const ChannelOwner& channel) {
447 assert(_channelId != channel.channel()->ChannelId());
448 rtc::CritScope lock(&assoc_send_channel_lock_);
449 associate_send_channel_ = channel;
450 }
Minyue2013aec2015-05-13 14:14:42 +0200451
kwiberg55b97fe2016-01-28 05:22:45 -0800452 // Disassociate a send channel if it was associated.
453 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200454
kwiberg55b97fe2016-01-28 05:22:45 -0800455 protected:
456 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000457
kwiberg55b97fe2016-01-28 05:22:45 -0800458 private:
459 bool ReceivePacket(const uint8_t* packet,
460 size_t packet_length,
461 const RTPHeader& header,
462 bool in_order);
463 bool HandleRtxPacket(const uint8_t* packet,
464 size_t packet_length,
465 const RTPHeader& header);
466 bool IsPacketInOrder(const RTPHeader& header) const;
467 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
468 int ResendPackets(const uint16_t* sequence_numbers, int length);
469 int InsertInbandDtmfTone();
470 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
471 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
472 void UpdatePlayoutTimestamp(bool rtcp);
473 void UpdatePacketDelay(uint32_t timestamp, uint16_t sequenceNumber);
474 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000475
kwiberg55b97fe2016-01-28 05:22:45 -0800476 int SetRedPayloadType(int red_payload_type);
477 int SetSendRtpHeaderExtension(bool enable,
478 RTPExtensionType type,
479 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000480
kwiberg55b97fe2016-01-28 05:22:45 -0800481 int32_t GetPlayoutFrequency();
482 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000483
kwiberg55b97fe2016-01-28 05:22:45 -0800484 mutable rtc::CriticalSection _fileCritSect;
485 mutable rtc::CriticalSection _callbackCritSect;
486 mutable rtc::CriticalSection volume_settings_critsect_;
487 uint32_t _instanceId;
488 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000489
kwiberg55b97fe2016-01-28 05:22:45 -0800490 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000491
kwiberg55b97fe2016-01-28 05:22:45 -0800492 RtcEventLog* const event_log_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200493
kwiberg55b97fe2016-01-28 05:22:45 -0800494 rtc::scoped_ptr<RtpHeaderParser> rtp_header_parser_;
495 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
496 rtc::scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
497 rtc::scoped_ptr<StatisticsProxy> statistics_proxy_;
498 rtc::scoped_ptr<RtpReceiver> rtp_receiver_;
499 TelephoneEventHandler* telephone_event_handler_;
500 rtc::scoped_ptr<RtpRtcp> _rtpRtcpModule;
501 rtc::scoped_ptr<AudioCodingModule> audio_coding_;
502 rtc::scoped_ptr<AudioSinkInterface> audio_sink_;
503 AudioLevel _outputAudioLevel;
504 bool _externalTransport;
505 AudioFrame _audioFrame;
506 // Downsamples to the codec rate if necessary.
507 PushResampler<int16_t> input_resampler_;
508 FilePlayer* _inputFilePlayerPtr;
509 FilePlayer* _outputFilePlayerPtr;
510 FileRecorder* _outputFileRecorderPtr;
511 int _inputFilePlayerId;
512 int _outputFilePlayerId;
513 int _outputFileRecorderId;
514 bool _outputFileRecording;
515 DtmfInbandQueue _inbandDtmfQueue;
516 DtmfInband _inbandDtmfGenerator;
517 bool _outputExternalMedia;
518 VoEMediaProcess* _inputExternalMediaCallbackPtr;
519 VoEMediaProcess* _outputExternalMediaCallbackPtr;
520 uint32_t _timeStamp;
521 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000522
kwiberg55b97fe2016-01-28 05:22:45 -0800523 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000524
kwiberg55b97fe2016-01-28 05:22:45 -0800525 // Timestamp of the audio pulled from NetEq.
526 uint32_t jitter_buffer_playout_timestamp_;
527 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
528 uint32_t playout_timestamp_rtcp_;
529 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
530 uint32_t _numberOfDiscardedPackets;
531 uint16_t send_sequence_number_;
532 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000533
kwiberg55b97fe2016-01-28 05:22:45 -0800534 mutable rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000535
kwiberg55b97fe2016-01-28 05:22:45 -0800536 rtc::scoped_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
537 // The rtp timestamp of the first played out audio frame.
538 int64_t capture_start_rtp_time_stamp_;
539 // The capture ntp time (in local timebase) of the first played out audio
540 // frame.
541 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000542
kwiberg55b97fe2016-01-28 05:22:45 -0800543 // uses
544 Statistics* _engineStatisticsPtr;
545 OutputMixer* _outputMixerPtr;
546 TransmitMixer* _transmitMixerPtr;
547 ProcessThread* _moduleProcessThreadPtr;
548 AudioDeviceModule* _audioDeviceModulePtr;
549 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
550 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
551 Transport* _transportPtr; // WebRtc socket or external transport
552 RMSLevel rms_level_;
553 rtc::scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
554 VoERxVadCallback* _rxVadObserverPtr;
555 int32_t _oldVadDecision;
556 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
557 // VoEBase
558 bool _externalMixing;
559 bool _mixFileWithMicrophone;
560 // VoEVolumeControl
561 bool _mute;
562 float _panLeft;
563 float _panRight;
564 float _outputGain;
565 // VoEDtmf
566 bool _playOutbandDtmfEvent;
567 bool _playInbandDtmfEvent;
568 // VoeRTP_RTCP
569 uint32_t _lastLocalTimeStamp;
570 int8_t _lastPayloadType;
571 bool _includeAudioLevelIndication;
572 // VoENetwork
573 AudioFrame::SpeechType _outputSpeechType;
574 // VoEVideoSync
575 mutable rtc::CriticalSection video_sync_lock_;
576 uint32_t _average_jitter_buffer_delay_us GUARDED_BY(video_sync_lock_);
577 uint32_t _previousTimestamp;
578 uint16_t _recPacketDelayMs GUARDED_BY(video_sync_lock_);
579 // VoEAudioProcessing
580 bool _RxVadDetection;
581 bool _rxAgcIsEnabled;
582 bool _rxNsIsEnabled;
583 bool restored_packet_in_use_;
584 // RtcpBandwidthObserver
585 rtc::scoped_ptr<VoERtcpObserver> rtcp_observer_;
586 rtc::scoped_ptr<NetworkPredictor> network_predictor_;
587 // An associated send channel.
588 mutable rtc::CriticalSection assoc_send_channel_lock_;
589 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100590
kwiberg55b97fe2016-01-28 05:22:45 -0800591 bool pacing_enabled_;
592 PacketRouter* packet_router_ = nullptr;
593 rtc::scoped_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
594 rtc::scoped_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
595 rtc::scoped_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000596};
597
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000598} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000599} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000600
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000601#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_