blob: 94fa04fb5fb90098ac3cd242ee217230e13b7649 [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
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000014#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000015#include "webrtc/common_types.h"
16#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
17#include "webrtc/modules/audio_conference_mixer/interface/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000018#include "webrtc/modules/audio_processing/rms_level.h"
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +000019#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
stefan@webrtc.org8e24d872014-09-02 18:58:24 +000020#include "webrtc/modules/rtp_rtcp/interface/remote_ntp_time_estimator.h"
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000021#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000022#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
23#include "webrtc/modules/utility/interface/file_player.h"
24#include "webrtc/modules/utility/interface/file_recorder.h"
25#include "webrtc/system_wrappers/interface/scoped_ptr.h"
26#include "webrtc/voice_engine/dtmf_inband.h"
27#include "webrtc/voice_engine/dtmf_inband_queue.h"
28#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
niklase@google.com470e71d2011-07-07 08:21:25 +000035#ifdef WEBRTC_DTMF_DETECTION
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000036// TelephoneEventDetectionMethods, TelephoneEventObserver
37#include "webrtc/voice_engine/include/voe_dtmf.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000038#endif
39
wu@webrtc.org94454b72014-06-05 20:34:08 +000040namespace rtc {
41
42class TimestampWrapAroundHandler;
43}
44
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000045namespace webrtc {
46
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000047class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000048class Config;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049class CriticalSectionWrapper;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000050class FileWrapper;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000051class ProcessThread;
52class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000053class RemoteNtpTimeEstimator;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000054class RtpDump;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000055class RTPPayloadRegistry;
56class RtpReceiver;
57class RTPReceiverAudio;
58class RtpRtcp;
59class TelephoneEventHandler;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +000060class ViENetwork;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000061class VoEMediaProcess;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000062class VoERTCPObserver;
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
niklase@google.com470e71d2011-07-07 08:21:25 +000072class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000073class StatisticsProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000074class TransmitMixer;
75class OutputMixer;
76
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000077// Helper class to simplify locking scheme for members that are accessed from
78// multiple threads.
79// Example: a member can be set on thread T1 and read by an internal audio
80// thread T2. Accessing the member via this class ensures that we are
81// safe and also avoid TSan v2 warnings.
82class ChannelState {
83 public:
84 struct State {
85 State() : rx_apm_is_enabled(false),
86 input_external_media(false),
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000087 output_file_playing(false),
88 input_file_playing(false),
89 playing(false),
90 sending(false),
91 receiving(false) {}
92
93 bool rx_apm_is_enabled;
94 bool input_external_media;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000095 bool output_file_playing;
96 bool input_file_playing;
97 bool playing;
98 bool sending;
99 bool receiving;
100 };
101
102 ChannelState() : lock_(CriticalSectionWrapper::CreateCriticalSection()) {
103 }
104 virtual ~ChannelState() {}
105
106 void Reset() {
107 CriticalSectionScoped lock(lock_.get());
108 state_ = State();
109 }
110
111 State Get() const {
112 CriticalSectionScoped lock(lock_.get());
113 return state_;
114 }
115
116 void SetRxApmIsEnabled(bool enable) {
117 CriticalSectionScoped lock(lock_.get());
118 state_.rx_apm_is_enabled = enable;
119 }
120
121 void SetInputExternalMedia(bool enable) {
122 CriticalSectionScoped lock(lock_.get());
123 state_.input_external_media = enable;
124 }
125
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000126 void SetOutputFilePlaying(bool enable) {
127 CriticalSectionScoped lock(lock_.get());
128 state_.output_file_playing = enable;
129 }
130
131 void SetInputFilePlaying(bool enable) {
132 CriticalSectionScoped lock(lock_.get());
133 state_.input_file_playing = enable;
134 }
135
136 void SetPlaying(bool enable) {
137 CriticalSectionScoped lock(lock_.get());
138 state_.playing = enable;
139 }
140
141 void SetSending(bool enable) {
142 CriticalSectionScoped lock(lock_.get());
143 state_.sending = enable;
144 }
145
146 void SetReceiving(bool enable) {
147 CriticalSectionScoped lock(lock_.get());
148 state_.receiving = enable;
149 }
150
151private:
152 scoped_ptr<CriticalSectionWrapper> lock_;
153 State state_;
154};
niklase@google.com470e71d2011-07-07 08:21:25 +0000155
156class Channel:
157 public RtpData,
158 public RtpFeedback,
159 public RtcpFeedback,
niklase@google.com470e71d2011-07-07 08:21:25 +0000160 public FileCallback, // receiving notification from file player & recorder
161 public Transport,
162 public RtpAudioFeedback,
163 public AudioPacketizationCallback, // receive encoded packets from the ACM
164 public ACMVADCallback, // receive voice activity from the ACM
niklase@google.com470e71d2011-07-07 08:21:25 +0000165 public MixerParticipant // supplies output mixer with audio frames
166{
167public:
168 enum {KNumSocketThreads = 1};
169 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +0000170 virtual ~Channel();
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000171 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000172 int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000173 uint32_t instanceId,
174 const Config& config);
175 Channel(int32_t channelId, uint32_t instanceId, const Config& config);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000176 int32_t Init();
177 int32_t SetEngineInformation(
niklase@google.com470e71d2011-07-07 08:21:25 +0000178 Statistics& engineStatistics,
179 OutputMixer& outputMixer,
180 TransmitMixer& transmitMixer,
181 ProcessThread& moduleProcessThread,
182 AudioDeviceModule& audioDeviceModule,
183 VoiceEngineObserver* voiceEngineObserver,
184 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000185 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000186
niklase@google.com470e71d2011-07-07 08:21:25 +0000187 // API methods
188
189 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000190 int32_t StartPlayout();
191 int32_t StopPlayout();
192 int32_t StartSend();
193 int32_t StopSend();
194 int32_t StartReceiving();
195 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000197 int32_t SetNetEQPlayoutMode(NetEqModes mode);
198 int32_t GetNetEQPlayoutMode(NetEqModes& mode);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000199 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
200 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
202 // VoECodec
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000203 int32_t GetSendCodec(CodecInst& codec);
204 int32_t GetRecCodec(CodecInst& codec);
205 int32_t SetSendCodec(const CodecInst& codec);
206 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
207 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
208 int32_t SetRecPayloadType(const CodecInst& codec);
209 int32_t GetRecPayloadType(CodecInst& codec);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000210 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
minyue@webrtc.orgadee8f92014-09-03 12:28:06 +0000211 int SetOpusMaxPlaybackRate(int frequency_hz);
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000213 // VoE dual-streaming.
214 int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);
215 void RemoveSecondarySendCodec();
216 int GetSecondarySendCodec(CodecInst* codec);
217
niklase@google.com470e71d2011-07-07 08:21:25 +0000218 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000219 int32_t RegisterExternalTransport(Transport& transport);
220 int32_t DeRegisterExternalTransport();
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000221 int32_t ReceivedRTPPacket(const int8_t* data, int32_t length,
222 const PacketTime& packet_time);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000223 int32_t ReceivedRTCPPacket(const int8_t* data, int32_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000224
niklase@google.com470e71d2011-07-07 08:21:25 +0000225 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000226 int StartPlayingFileLocally(const char* fileName, bool loop,
227 FileFormats format,
228 int startPosition,
229 float volumeScaling,
230 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000231 const CodecInst* codecInst);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000232 int StartPlayingFileLocally(InStream* stream, FileFormats format,
233 int startPosition,
234 float volumeScaling,
235 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000236 const CodecInst* codecInst);
237 int StopPlayingFileLocally();
238 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000239 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000240 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
241 FileFormats format,
242 int startPosition,
243 float volumeScaling,
244 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000245 const CodecInst* codecInst);
246 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000247 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 StopPlayingFileAsMicrophone();
253 int IsPlayingFileAsMicrophone() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000254 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
255 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
256 int StopRecordingPlayout();
257
258 void SetMixWithMicStatus(bool mix);
259
260 // VoEExternalMediaProcessing
261 int RegisterExternalMediaProcessing(ProcessingTypes type,
262 VoEMediaProcess& processObject);
263 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000264 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000265
266 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000267 int GetSpeechOutputLevel(uint32_t& level) const;
268 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000269 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000270 bool Mute() const;
271 int SetOutputVolumePan(float left, float right);
272 int GetOutputVolumePan(float& left, float& right) const;
273 int SetChannelOutputVolumeScaling(float scaling);
274 int GetChannelOutputVolumeScaling(float& scaling) const;
275
niklase@google.com470e71d2011-07-07 08:21:25 +0000276 // VoENetEqStats
277 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000278 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000279
280 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000281 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
282 int* playout_buffer_delay_ms) const;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000283 int least_required_delay_ms() const { return least_required_delay_ms_; }
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000284 int SetInitialPlayoutDelay(int delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000285 int SetMinimumPlayoutDelay(int delayMs);
286 int GetPlayoutTimestamp(unsigned int& timestamp);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000287 void UpdatePlayoutTimestamp(bool rtcp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000288 int SetInitTimestamp(unsigned int timestamp);
289 int SetInitSequenceNumber(short sequenceNumber);
290
291 // VoEVideoSyncExtended
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000292 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000293
niklase@google.com470e71d2011-07-07 08:21:25 +0000294 // VoEDtmf
295 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
296 int attenuationDb, bool playDtmfEvent);
297 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
298 int attenuationDb, bool playDtmfEvent);
299 int SetDtmfPlayoutStatus(bool enable);
300 bool DtmfPlayoutStatus() const;
301 int SetSendTelephoneEventPayloadType(unsigned char type);
302 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000303
304 // VoEAudioProcessingImpl
305 int UpdateRxVadDetection(AudioFrame& audioFrame);
306 int RegisterRxVadObserver(VoERxVadCallback &observer);
307 int DeRegisterRxVadObserver();
308 int VoiceActivityIndicator(int &activity);
309#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000310 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000311 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000312 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000313 int GetRxAgcConfig(AgcConfig& config);
314#endif
315#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000316 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000317 int GetRxNsStatus(bool& enabled, NsModes& mode);
318#endif
319
320 // VoERTP_RTCP
niklase@google.com470e71d2011-07-07 08:21:25 +0000321 int RegisterRTCPObserver(VoERTCPObserver& observer);
322 int DeRegisterRTCPObserver();
323 int SetLocalSSRC(unsigned int ssrc);
324 int GetLocalSSRC(unsigned int& ssrc);
325 int GetRemoteSSRC(unsigned int& ssrc);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000326 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.org93fd25c2014-04-24 20:33:08 +0000327 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000328 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
329 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000330 int SetRTCPStatus(bool enable);
331 int GetRTCPStatus(bool& enabled);
332 int SetRTCP_CNAME(const char cName[256]);
niklase@google.com470e71d2011-07-07 08:21:25 +0000333 int GetRemoteRTCP_CNAME(char cName[256]);
334 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
335 unsigned int& timestamp,
336 unsigned int& playoutTimestamp, unsigned int* jitter,
337 unsigned short* fractionLost);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000338 int SendApplicationDefinedRTCPPacket(unsigned char subType,
niklase@google.com470e71d2011-07-07 08:21:25 +0000339 unsigned int name, const char* data,
340 unsigned short dataLengthInBytes);
341 int GetRTPStatistics(unsigned int& averageJitterMs,
342 unsigned int& maxJitterMs,
343 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000344 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000345 int GetRTPStatistics(CallStatistics& stats);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000346 int SetREDStatus(bool enable, int redPayloadtype);
347 int GetREDStatus(bool& enabled, int& redPayloadtype);
348 int SetCodecFECStatus(bool enable);
349 bool GetCodecFECStatus();
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000350 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000351 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
352 int StopRTPDump(RTPDirections direction);
353 bool RTPDumpIsActive(RTPDirections direction);
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000354 // Takes ownership of the ViENetwork.
355 void SetVideoEngineBWETarget(ViENetwork* vie_network, int video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000356
niklase@google.com470e71d2011-07-07 08:21:25 +0000357 // From AudioPacketizationCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000358 int32_t SendData(FrameType frameType,
359 uint8_t payloadType,
360 uint32_t timeStamp,
361 const uint8_t* payloadData,
362 uint16_t payloadSize,
363 const RTPFragmentationHeader* fragmentation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000364 // From ACMVADCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000365 int32_t InFrameType(int16_t frameType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000366
pbos@webrtc.org92135212013-05-14 08:31:39 +0000367 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000368
niklase@google.com470e71d2011-07-07 08:21:25 +0000369 // From RtpData in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000370 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000371 uint16_t payloadSize,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000372 const WebRtcRTPHeader* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +0000373
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000374 bool OnRecoveredPacket(const uint8_t* packet, int packet_length);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000375
niklase@google.com470e71d2011-07-07 08:21:25 +0000376 // From RtpFeedback in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000377 int32_t OnInitializeDecoder(
pbos@webrtc.org92135212013-05-14 08:31:39 +0000378 int32_t id,
379 int8_t payloadType,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000380 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org92135212013-05-14 08:31:39 +0000381 int frequency,
382 uint8_t channels,
383 uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000384
pbos@webrtc.org92135212013-05-14 08:31:39 +0000385 void OnPacketTimeout(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000386
pbos@webrtc.org92135212013-05-14 08:31:39 +0000387 void OnReceivedPacket(int32_t id, RtpRtcpPacketType packetType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000388
pbos@webrtc.org92135212013-05-14 08:31:39 +0000389 void OnPeriodicDeadOrAlive(int32_t id,
390 RTPAliveType alive);
niklase@google.com470e71d2011-07-07 08:21:25 +0000391
pbos@webrtc.org92135212013-05-14 08:31:39 +0000392 void OnIncomingSSRCChanged(int32_t id,
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000393 uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000394
pbos@webrtc.org92135212013-05-14 08:31:39 +0000395 void OnIncomingCSRCChanged(int32_t id,
396 uint32_t CSRC, bool added);
niklase@google.com470e71d2011-07-07 08:21:25 +0000397
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000398 void ResetStatistics(uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000399
niklase@google.com470e71d2011-07-07 08:21:25 +0000400 // From RtcpFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000401 void OnApplicationDataReceived(int32_t id,
402 uint8_t subType,
403 uint32_t name,
404 uint16_t length,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000405 const uint8_t* data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000406
niklase@google.com470e71d2011-07-07 08:21:25 +0000407 // From RtpAudioFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000408 void OnReceivedTelephoneEvent(int32_t id,
409 uint8_t event,
410 bool endOfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000411
pbos@webrtc.org92135212013-05-14 08:31:39 +0000412 void OnPlayTelephoneEvent(int32_t id,
413 uint8_t event,
414 uint16_t lengthMs,
415 uint8_t volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000416
niklase@google.com470e71d2011-07-07 08:21:25 +0000417 // From Transport (called by the RTP/RTCP module)
418 int SendPacket(int /*channel*/, const void *data, int len);
419 int SendRTCPPacket(int /*channel*/, const void *data, int len);
420
niklase@google.com470e71d2011-07-07 08:21:25 +0000421 // From MixerParticipant
pbos@webrtc.org92135212013-05-14 08:31:39 +0000422 int32_t GetAudioFrame(int32_t id, AudioFrame& audioFrame);
423 int32_t NeededFrequency(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000424
niklase@google.com470e71d2011-07-07 08:21:25 +0000425 // From MonitorObserver
426 void OnPeriodicProcess();
427
niklase@google.com470e71d2011-07-07 08:21:25 +0000428 // From FileCallback
pbos@webrtc.org92135212013-05-14 08:31:39 +0000429 void PlayNotification(int32_t id,
430 uint32_t durationMs);
431 void RecordNotification(int32_t id,
432 uint32_t durationMs);
433 void PlayFileEnded(int32_t id);
434 void RecordFileEnded(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000435
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000436 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000437 {
438 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000439 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000440 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000441 {
442 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000443 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000444 bool Playing() const
445 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000446 return channel_state_.Get().playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000447 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000448 bool Sending() const
449 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000450 return channel_state_.Get().sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000451 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000452 bool Receiving() const
453 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000454 return channel_state_.Get().receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000455 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000456 bool ExternalTransport() const
457 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000458 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000459 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000460 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000461 bool ExternalMixing() const
462 {
463 return _externalMixing;
464 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000465 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000466 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000467 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000468 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000469 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000470 {
471 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000472 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000473 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000474 // Demultiplex the data to the channel's |_audioFrame|. The difference
475 // between this method and the overloaded method above is that |audio_data|
476 // does not go through transmit_mixer and APM.
477 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000478 int sample_rate,
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000479 int number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000480 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000481 uint32_t PrepareEncodeAndSend(int mixingFrequency);
482 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000483
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000484 // From BitrateObserver (called by the RTP/RTCP module).
485 void OnNetworkChanged(const uint32_t bitrate_bps,
486 const uint8_t fraction_lost, // 0 - 255.
487 const uint32_t rtt);
488
niklase@google.com470e71d2011-07-07 08:21:25 +0000489private:
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000490 bool ReceivePacket(const uint8_t* packet, int packet_length,
491 const RTPHeader& header, bool in_order);
492 bool HandleEncapsulation(const uint8_t* packet,
493 int packet_length,
494 const RTPHeader& header);
495 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000496 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000497 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000498 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000499 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
500 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000501 int32_t SendPacketRaw(const void *data, int len, bool RTCP);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000502 void UpdatePacketDelay(uint32_t timestamp,
503 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000504 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000505
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000506 int SetRedPayloadType(int red_payload_type);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000507 int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type,
508 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000509
wu@webrtc.org94454b72014-06-05 20:34:08 +0000510 int32_t GetPlayoutFrequency();
511
niklase@google.com470e71d2011-07-07 08:21:25 +0000512 CriticalSectionWrapper& _fileCritSect;
513 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.org63420662013-10-17 18:28:55 +0000514 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000515 uint32_t _instanceId;
516 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000517
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000518 ChannelState channel_state_;
519
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000520 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000521 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
522 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +0000523 scoped_ptr<StatisticsProxy> statistics_proxy_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000524 scoped_ptr<RtpReceiver> rtp_receiver_;
525 TelephoneEventHandler* telephone_event_handler_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000526 scoped_ptr<RtpRtcp> _rtpRtcpModule;
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000527 scoped_ptr<AudioCodingModule> audio_coding_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000528 RtpDump& _rtpDumpIn;
529 RtpDump& _rtpDumpOut;
niklase@google.com470e71d2011-07-07 08:21:25 +0000530 AudioLevel _outputAudioLevel;
531 bool _externalTransport;
532 AudioFrame _audioFrame;
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +0000533 scoped_ptr<int16_t[]> mono_recording_audio_;
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +0000534 // Downsamples to the codec rate if necessary.
535 PushResampler<int16_t> input_resampler_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000536 uint8_t _audioLevel_dBov;
niklase@google.com470e71d2011-07-07 08:21:25 +0000537 FilePlayer* _inputFilePlayerPtr;
538 FilePlayer* _outputFilePlayerPtr;
539 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000540 int _inputFilePlayerId;
541 int _outputFilePlayerId;
542 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000543 bool _outputFileRecording;
544 DtmfInbandQueue _inbandDtmfQueue;
545 DtmfInband _inbandDtmfGenerator;
xians@google.com22963ab2011-08-03 12:40:23 +0000546 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000547 VoEMediaProcess* _inputExternalMediaCallbackPtr;
548 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000549 uint32_t _timeStamp;
550 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000551
stefan@webrtc.org8e24d872014-09-02 18:58:24 +0000552 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000553
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000554 // Timestamp of the audio pulled from NetEq.
555 uint32_t jitter_buffer_playout_timestamp_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000556 uint32_t playout_timestamp_rtp_;
557 uint32_t playout_timestamp_rtcp_;
558 uint32_t playout_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000559 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000560 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000561 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000562
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000563 scoped_ptr<CriticalSectionWrapper> ts_stats_lock_;
564
wu@webrtc.org94454b72014-06-05 20:34:08 +0000565 scoped_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000566 // The rtp timestamp of the first played out audio frame.
wu@webrtc.org94454b72014-06-05 20:34:08 +0000567 int64_t capture_start_rtp_time_stamp_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000568 // The capture ntp time (in local timebase) of the first played out audio
569 // frame.
stefan@webrtc.org8e24d872014-09-02 18:58:24 +0000570 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000571
niklase@google.com470e71d2011-07-07 08:21:25 +0000572 // uses
573 Statistics* _engineStatisticsPtr;
574 OutputMixer* _outputMixerPtr;
575 TransmitMixer* _transmitMixerPtr;
576 ProcessThread* _moduleProcessThreadPtr;
577 AudioDeviceModule* _audioDeviceModulePtr;
578 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
579 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
580 Transport* _transportPtr; // WebRtc socket or external transport
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000581 RMSLevel rms_level_;
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +0000582 scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000583 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000584 int32_t _oldVadDecision;
585 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000586 VoERTCPObserver* _rtcpObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000587 // VoEBase
niklase@google.com470e71d2011-07-07 08:21:25 +0000588 bool _externalPlayout;
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000589 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000590 bool _mixFileWithMicrophone;
niklase@google.com470e71d2011-07-07 08:21:25 +0000591 bool _rtcpObserver;
592 // VoEVolumeControl
593 bool _mute;
594 float _panLeft;
595 float _panRight;
596 float _outputGain;
niklase@google.com470e71d2011-07-07 08:21:25 +0000597 // VoEDtmf
598 bool _playOutbandDtmfEvent;
599 bool _playInbandDtmfEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000600 // VoeRTP_RTCP
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000601 uint32_t _lastLocalTimeStamp;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000602 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000603 bool _includeAudioLevelIndication;
604 // VoENetwork
605 bool _rtpPacketTimedOut;
606 bool _rtpPacketTimeOutIsEnabled;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000607 uint32_t _rtpTimeOutSeconds;
niklase@google.com470e71d2011-07-07 08:21:25 +0000608 bool _connectionObserver;
609 VoEConnectionObserver* _connectionObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000610 AudioFrame::SpeechType _outputSpeechType;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000611 ViENetwork* vie_network_;
612 int video_channel_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000613 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000614 uint32_t _average_jitter_buffer_delay_us;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000615 int least_required_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000616 uint32_t _previousTimestamp;
617 uint16_t _recPacketDelayMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000618 // VoEAudioProcessing
619 bool _RxVadDetection;
niklase@google.com470e71d2011-07-07 08:21:25 +0000620 bool _rxAgcIsEnabled;
621 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000622 bool restored_packet_in_use_;
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000623 // RtcpBandwidthObserver
624 scoped_ptr<BitrateController> bitrate_controller_;
625 scoped_ptr<RtcpBandwidthObserver> rtcp_bandwidth_observer_;
626 scoped_ptr<BitrateObserver> send_bitrate_observer_;
minyue@webrtc.org74aaf292014-07-16 21:28:26 +0000627 scoped_ptr<NetworkPredictor> network_predictor_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000628};
629
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000630} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000631} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000632
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000633#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_