blob: 9184b93e099bc3df8338212ec668fae55a8006ab [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;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000050class CriticalSectionWrapper;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000051class FileWrapper;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010052class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000053class ProcessThread;
54class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000055class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070056class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000057class RTPPayloadRegistry;
58class RtpReceiver;
59class RTPReceiverAudio;
60class RtpRtcp;
61class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000062class VoEMediaProcess;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000063class VoERTPObserver;
64class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000065
66struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000067struct ReportBlock;
68struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000069
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000070namespace voe {
71
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000072class OutputMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010073class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000074class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000075class StatisticsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010076class TransportFeedbackProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000077class TransmitMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010078class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000079class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000081// Helper class to simplify locking scheme for members that are accessed from
82// multiple threads.
83// Example: a member can be set on thread T1 and read by an internal audio
84// thread T2. Accessing the member via this class ensures that we are
85// safe and also avoid TSan v2 warnings.
86class ChannelState {
87 public:
88 struct State {
89 State() : rx_apm_is_enabled(false),
90 input_external_media(false),
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000091 output_file_playing(false),
92 input_file_playing(false),
93 playing(false),
94 sending(false),
95 receiving(false) {}
96
97 bool rx_apm_is_enabled;
98 bool input_external_media;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000099 bool output_file_playing;
100 bool input_file_playing;
101 bool playing;
102 bool sending;
103 bool receiving;
104 };
105
106 ChannelState() : lock_(CriticalSectionWrapper::CreateCriticalSection()) {
107 }
108 virtual ~ChannelState() {}
109
110 void Reset() {
111 CriticalSectionScoped lock(lock_.get());
112 state_ = State();
113 }
114
115 State Get() const {
116 CriticalSectionScoped lock(lock_.get());
117 return state_;
118 }
119
120 void SetRxApmIsEnabled(bool enable) {
121 CriticalSectionScoped lock(lock_.get());
122 state_.rx_apm_is_enabled = enable;
123 }
124
125 void SetInputExternalMedia(bool enable) {
126 CriticalSectionScoped lock(lock_.get());
127 state_.input_external_media = enable;
128 }
129
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000130 void SetOutputFilePlaying(bool enable) {
131 CriticalSectionScoped lock(lock_.get());
132 state_.output_file_playing = enable;
133 }
134
135 void SetInputFilePlaying(bool enable) {
136 CriticalSectionScoped lock(lock_.get());
137 state_.input_file_playing = enable;
138 }
139
140 void SetPlaying(bool enable) {
141 CriticalSectionScoped lock(lock_.get());
142 state_.playing = enable;
143 }
144
145 void SetSending(bool enable) {
146 CriticalSectionScoped lock(lock_.get());
147 state_.sending = enable;
148 }
149
150 void SetReceiving(bool enable) {
151 CriticalSectionScoped lock(lock_.get());
152 state_.receiving = enable;
153 }
154
155private:
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000156 rtc::scoped_ptr<CriticalSectionWrapper> lock_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000157 State state_;
158};
niklase@google.com470e71d2011-07-07 08:21:25 +0000159
160class Channel:
161 public RtpData,
162 public RtpFeedback,
niklase@google.com470e71d2011-07-07 08:21:25 +0000163 public FileCallback, // receiving notification from file player & recorder
164 public Transport,
165 public RtpAudioFeedback,
166 public AudioPacketizationCallback, // receive encoded packets from the ACM
167 public ACMVADCallback, // receive voice activity from the ACM
niklase@google.com470e71d2011-07-07 08:21:25 +0000168 public MixerParticipant // supplies output mixer with audio frames
169{
170public:
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000171 friend class VoERtcpObserver;
172
niklase@google.com470e71d2011-07-07 08:21:25 +0000173 enum {KNumSocketThreads = 1};
174 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +0000175 virtual ~Channel();
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000176 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000177 int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000178 uint32_t instanceId,
ivocb04965c2015-09-09 00:09:43 -0700179 RtcEventLog* const event_log,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000180 const Config& config);
ivocb04965c2015-09-09 00:09:43 -0700181 Channel(int32_t channelId,
182 uint32_t instanceId,
183 RtcEventLog* const event_log,
184 const Config& config);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000185 int32_t Init();
186 int32_t SetEngineInformation(
niklase@google.com470e71d2011-07-07 08:21:25 +0000187 Statistics& engineStatistics,
188 OutputMixer& outputMixer,
189 TransmitMixer& transmitMixer,
190 ProcessThread& moduleProcessThread,
191 AudioDeviceModule& audioDeviceModule,
192 VoiceEngineObserver* voiceEngineObserver,
193 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000194 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000195
Tommif888bb52015-12-12 01:37:01 +0100196 void SetSink(rtc::scoped_ptr<AudioSinkInterface> sink);
197
niklase@google.com470e71d2011-07-07 08:21:25 +0000198 // API methods
199
200 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000201 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
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000208 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
209 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
211 // VoECodec
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000212 int32_t GetSendCodec(CodecInst& codec);
213 int32_t GetRecCodec(CodecInst& codec);
214 int32_t SetSendCodec(const CodecInst& codec);
Ivo Creusenadf89b72015-04-29 16:03:33 +0200215 void SetBitRate(int bitrate_bps);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000216 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);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000220 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
minyue@webrtc.orgadee8f92014-09-03 12:28:06 +0000221 int SetOpusMaxPlaybackRate(int frequency_hz);
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000222 int SetOpusDtx(bool enable_dtx);
niklase@google.com470e71d2011-07-07 08:21:25 +0000223
224 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000225 int32_t RegisterExternalTransport(Transport& transport);
226 int32_t DeRegisterExternalTransport();
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000227 int32_t ReceivedRTPPacket(const int8_t* data, size_t length,
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000228 const PacketTime& packet_time);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000229 int32_t ReceivedRTCPPacket(const int8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000230
niklase@google.com470e71d2011-07-07 08:21:25 +0000231 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000232 int StartPlayingFileLocally(const char* fileName, bool loop,
233 FileFormats format,
234 int startPosition,
235 float volumeScaling,
236 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000237 const CodecInst* codecInst);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000238 int StartPlayingFileLocally(InStream* stream, FileFormats format,
239 int startPosition,
240 float volumeScaling,
241 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000242 const CodecInst* codecInst);
243 int StopPlayingFileLocally();
244 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000245 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000246 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
247 FileFormats format,
248 int startPosition,
249 float volumeScaling,
250 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000251 const CodecInst* codecInst);
252 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000253 FileFormats format,
254 int startPosition,
255 float volumeScaling,
256 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000257 const CodecInst* codecInst);
258 int StopPlayingFileAsMicrophone();
259 int IsPlayingFileAsMicrophone() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000260 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
261 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
262 int StopRecordingPlayout();
263
264 void SetMixWithMicStatus(bool mix);
265
266 // VoEExternalMediaProcessing
267 int RegisterExternalMediaProcessing(ProcessingTypes type,
268 VoEMediaProcess& processObject);
269 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000270 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000271
272 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000273 int GetSpeechOutputLevel(uint32_t& level) const;
274 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000275 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000276 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;
281
niklase@google.com470e71d2011-07-07 08:21:25 +0000282 // VoENetEqStats
283 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000284 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000285
286 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000287 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
288 int* playout_buffer_delay_ms) const;
solenberg358057b2015-11-27 10:46:42 -0800289 uint32_t GetDelayEstimate() const;
deadbeef74375882015-08-13 12:09:10 -0700290 int LeastRequiredDelayMs() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000291 int SetMinimumPlayoutDelay(int delayMs);
292 int GetPlayoutTimestamp(unsigned int& timestamp);
293 int SetInitTimestamp(unsigned int timestamp);
294 int SetInitSequenceNumber(short sequenceNumber);
295
296 // VoEVideoSyncExtended
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000297 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000298
niklase@google.com470e71d2011-07-07 08:21:25 +0000299 // VoEDtmf
300 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
301 int attenuationDb, bool playDtmfEvent);
302 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
303 int attenuationDb, bool playDtmfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000304 int SetSendTelephoneEventPayloadType(unsigned char type);
305 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000306
307 // VoEAudioProcessingImpl
308 int UpdateRxVadDetection(AudioFrame& audioFrame);
309 int RegisterRxVadObserver(VoERxVadCallback &observer);
310 int DeRegisterRxVadObserver();
311 int VoiceActivityIndicator(int &activity);
312#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000313 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000314 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000315 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000316 int GetRxAgcConfig(AgcConfig& config);
317#endif
318#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000319 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000320 int GetRxNsStatus(bool& enabled, NsModes& mode);
321#endif
322
323 // VoERTP_RTCP
niklase@google.com470e71d2011-07-07 08:21:25 +0000324 int SetLocalSSRC(unsigned int ssrc);
325 int GetLocalSSRC(unsigned int& ssrc);
326 int GetRemoteSSRC(unsigned int& ssrc);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000327 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.org93fd25c2014-04-24 20:33:08 +0000328 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000329 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
330 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100331 void EnableSendTransportSequenceNumber(int id);
332
333 void SetCongestionControlObjects(
334 RtpPacketSender* rtp_packet_sender,
335 TransportFeedbackObserver* transport_feedback_observer,
336 PacketRouter* packet_router);
337
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000338 void SetRTCPStatus(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000339 int GetRTCPStatus(bool& enabled);
340 int SetRTCP_CNAME(const char cName[256]);
niklase@google.com470e71d2011-07-07 08:21:25 +0000341 int GetRemoteRTCP_CNAME(char cName[256]);
342 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
343 unsigned int& timestamp,
344 unsigned int& playoutTimestamp, unsigned int* jitter,
345 unsigned short* fractionLost);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000346 int SendApplicationDefinedRTCPPacket(unsigned char subType,
niklase@google.com470e71d2011-07-07 08:21:25 +0000347 unsigned int name, const char* data,
348 unsigned short dataLengthInBytes);
349 int GetRTPStatistics(unsigned int& averageJitterMs,
350 unsigned int& maxJitterMs,
351 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000352 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 int GetRTPStatistics(CallStatistics& stats);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000354 int SetREDStatus(bool enable, int redPayloadtype);
355 int GetREDStatus(bool& enabled, int& redPayloadtype);
356 int SetCodecFECStatus(bool enable);
357 bool GetCodecFECStatus();
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000358 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000359
niklase@google.com470e71d2011-07-07 08:21:25 +0000360 // From AudioPacketizationCallback in the ACM
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000361 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
niklase@google.com470e71d2011-07-07 08:21:25 +0000368 // From ACMVADCallback in the ACM
henrik.lundin@webrtc.orge9217b42015-03-06 07:50:34 +0000369 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000370
pbos@webrtc.org92135212013-05-14 08:31:39 +0000371 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000372
niklase@google.com470e71d2011-07-07 08:21:25 +0000373 // From RtpData in the RTP/RTCP module
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000374 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
375 size_t payloadSize,
376 const WebRtcRTPHeader* rtpHeader) override;
377 bool OnRecoveredPacket(const uint8_t* packet,
378 size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000379
niklase@google.com470e71d2011-07-07 08:21:25 +0000380 // From RtpFeedback in the RTP/RTCP module
Peter Boströmac547a62015-09-17 23:03:57 +0200381 int32_t OnInitializeDecoder(int8_t payloadType,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000382 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
383 int frequency,
384 uint8_t channels,
385 uint32_t rate) override;
Peter Boströmac547a62015-09-17 23:03:57 +0200386 void OnIncomingSSRCChanged(uint32_t ssrc) override;
387 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000388
niklase@google.com470e71d2011-07-07 08:21:25 +0000389 // From RtpAudioFeedback in the RTP/RTCP module
Peter Boströmac547a62015-09-17 23:03:57 +0200390 void OnPlayTelephoneEvent(uint8_t event,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000391 uint16_t lengthMs,
392 uint8_t volume) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000393
niklase@google.com470e71d2011-07-07 08:21:25 +0000394 // From Transport (called by the RTP/RTCP module)
stefan1d8a5062015-10-02 03:39:33 -0700395 bool SendRtp(const uint8_t* data,
396 size_t len,
397 const PacketOptions& packet_options) override;
pbos2d566682015-09-28 09:59:31 -0700398 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000399
niklase@google.com470e71d2011-07-07 08:21:25 +0000400 // From MixerParticipant
minyuel0f4b3732015-08-31 16:04:32 +0200401 int32_t GetAudioFrame(int32_t id, AudioFrame* audioFrame) override;
402 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000403
niklase@google.com470e71d2011-07-07 08:21:25 +0000404 // From FileCallback
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000405 void PlayNotification(int32_t id, uint32_t durationMs) override;
406 void RecordNotification(int32_t id, uint32_t durationMs) override;
407 void PlayFileEnded(int32_t id) override;
408 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000409
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000410 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000411 {
412 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000413 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000414 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000415 {
416 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000417 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000418 bool Playing() const
419 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000420 return channel_state_.Get().playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000421 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000422 bool Sending() const
423 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000424 return channel_state_.Get().sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000425 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000426 bool Receiving() const
427 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000428 return channel_state_.Get().receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000429 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000430 bool ExternalTransport() const
431 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000432 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000433 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000434 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000435 bool ExternalMixing() const
436 {
437 return _externalMixing;
438 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000439 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000440 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000441 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000442 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000443 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000444 {
445 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000446 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000447 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000448 // Demultiplex the data to the channel's |_audioFrame|. The difference
449 // between this method and the overloaded method above is that |audio_data|
450 // does not go through transmit_mixer and APM.
451 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000452 int sample_rate,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700453 size_t number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000454 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000455 uint32_t PrepareEncodeAndSend(int mixingFrequency);
456 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000457
Minyue2013aec2015-05-13 14:14:42 +0200458 // Associate to a send channel.
459 // Used for obtaining RTT for a receive-only channel.
460 void set_associate_send_channel(const ChannelOwner& channel) {
461 assert(_channelId != channel.channel()->ChannelId());
462 CriticalSectionScoped lock(assoc_send_channel_lock_.get());
463 associate_send_channel_ = channel;
464 }
465
466 // Disassociate a send channel if it was associated.
467 void DisassociateSendChannel(int channel_id);
468
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000469protected:
470 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000471
niklase@google.com470e71d2011-07-07 08:21:25 +0000472private:
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000473 bool ReceivePacket(const uint8_t* packet, size_t packet_length,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000474 const RTPHeader& header, bool in_order);
minyue@webrtc.org456f0142015-01-23 11:58:42 +0000475 bool HandleRtxPacket(const uint8_t* packet,
476 size_t packet_length,
477 const RTPHeader& header);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000478 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000479 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000480 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000481 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000482 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
483 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
deadbeef74375882015-08-13 12:09:10 -0700484 void UpdatePlayoutTimestamp(bool rtcp);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000485 void UpdatePacketDelay(uint32_t timestamp,
486 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000487 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000488
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000489 int SetRedPayloadType(int red_payload_type);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000490 int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type,
491 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000492
wu@webrtc.org94454b72014-06-05 20:34:08 +0000493 int32_t GetPlayoutFrequency();
Minyue2013aec2015-05-13 14:14:42 +0200494 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000495
niklase@google.com470e71d2011-07-07 08:21:25 +0000496 CriticalSectionWrapper& _fileCritSect;
497 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.org63420662013-10-17 18:28:55 +0000498 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000499 uint32_t _instanceId;
500 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000501
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000502 ChannelState channel_state_;
503
Ivo Creusenae856f22015-09-17 16:30:16 +0200504 RtcEventLog* const event_log_;
505
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000506 rtc::scoped_ptr<RtpHeaderParser> rtp_header_parser_;
507 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
508 rtc::scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
509 rtc::scoped_ptr<StatisticsProxy> statistics_proxy_;
510 rtc::scoped_ptr<RtpReceiver> rtp_receiver_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000511 TelephoneEventHandler* telephone_event_handler_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000512 rtc::scoped_ptr<RtpRtcp> _rtpRtcpModule;
513 rtc::scoped_ptr<AudioCodingModule> audio_coding_;
Tommif888bb52015-12-12 01:37:01 +0100514 rtc::scoped_ptr<AudioSinkInterface> audio_sink_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000515 AudioLevel _outputAudioLevel;
516 bool _externalTransport;
517 AudioFrame _audioFrame;
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +0000518 // Downsamples to the codec rate if necessary.
519 PushResampler<int16_t> input_resampler_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000520 FilePlayer* _inputFilePlayerPtr;
521 FilePlayer* _outputFilePlayerPtr;
522 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000523 int _inputFilePlayerId;
524 int _outputFilePlayerId;
525 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000526 bool _outputFileRecording;
527 DtmfInbandQueue _inbandDtmfQueue;
528 DtmfInband _inbandDtmfGenerator;
xians@google.com22963ab2011-08-03 12:40:23 +0000529 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000530 VoEMediaProcess* _inputExternalMediaCallbackPtr;
531 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000532 uint32_t _timeStamp;
533 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000534
stefan@webrtc.org8e24d872014-09-02 18:58:24 +0000535 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000536
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000537 // Timestamp of the audio pulled from NetEq.
538 uint32_t jitter_buffer_playout_timestamp_;
deadbeef74375882015-08-13 12:09:10 -0700539 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000540 uint32_t playout_timestamp_rtcp_;
deadbeef74375882015-08-13 12:09:10 -0700541 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000542 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000543 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000544 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000545
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000546 rtc::scoped_ptr<CriticalSectionWrapper> ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000547
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000548 rtc::scoped_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000549 // The rtp timestamp of the first played out audio frame.
wu@webrtc.org94454b72014-06-05 20:34:08 +0000550 int64_t capture_start_rtp_time_stamp_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000551 // The capture ntp time (in local timebase) of the first played out audio
552 // frame.
stefan@webrtc.org8e24d872014-09-02 18:58:24 +0000553 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000554
niklase@google.com470e71d2011-07-07 08:21:25 +0000555 // uses
556 Statistics* _engineStatisticsPtr;
557 OutputMixer* _outputMixerPtr;
558 TransmitMixer* _transmitMixerPtr;
559 ProcessThread* _moduleProcessThreadPtr;
560 AudioDeviceModule* _audioDeviceModulePtr;
561 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
562 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
563 Transport* _transportPtr; // WebRtc socket or external transport
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000564 RMSLevel rms_level_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000565 rtc::scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000566 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000567 int32_t _oldVadDecision;
568 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000569 // VoEBase
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000570 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000571 bool _mixFileWithMicrophone;
niklase@google.com470e71d2011-07-07 08:21:25 +0000572 // VoEVolumeControl
573 bool _mute;
574 float _panLeft;
575 float _panRight;
576 float _outputGain;
niklase@google.com470e71d2011-07-07 08:21:25 +0000577 // VoEDtmf
578 bool _playOutbandDtmfEvent;
579 bool _playInbandDtmfEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000580 // VoeRTP_RTCP
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000581 uint32_t _lastLocalTimeStamp;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000582 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000583 bool _includeAudioLevelIndication;
584 // VoENetwork
niklase@google.com470e71d2011-07-07 08:21:25 +0000585 AudioFrame::SpeechType _outputSpeechType;
586 // VoEVideoSync
deadbeef74375882015-08-13 12:09:10 -0700587 rtc::scoped_ptr<CriticalSectionWrapper> video_sync_lock_;
588 uint32_t _average_jitter_buffer_delay_us GUARDED_BY(video_sync_lock_);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000589 uint32_t _previousTimestamp;
deadbeef74375882015-08-13 12:09:10 -0700590 uint16_t _recPacketDelayMs GUARDED_BY(video_sync_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000591 // VoEAudioProcessing
592 bool _RxVadDetection;
niklase@google.com470e71d2011-07-07 08:21:25 +0000593 bool _rxAgcIsEnabled;
594 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000595 bool restored_packet_in_use_;
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000596 // RtcpBandwidthObserver
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000597 rtc::scoped_ptr<VoERtcpObserver> rtcp_observer_;
598 rtc::scoped_ptr<NetworkPredictor> network_predictor_;
Minyue2013aec2015-05-13 14:14:42 +0200599 // An associated send channel.
600 rtc::scoped_ptr<CriticalSectionWrapper> assoc_send_channel_lock_;
601 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100602
603 bool pacing_enabled_;
604 PacketRouter* packet_router_ = nullptr;
605 rtc::scoped_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
606 rtc::scoped_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
607 rtc::scoped_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000608};
609
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000610} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000611} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000612
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000613#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_