blob: 954d6ea3dcfa066363d667bc7ca77c524522169d [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
11#ifndef WEBRTC_VOICE_ENGINE_CHANNEL_H
12#define WEBRTC_VOICE_ENGINE_CHANNEL_H
13
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"
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000018#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000019#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
20#include "webrtc/modules/utility/interface/file_player.h"
21#include "webrtc/modules/utility/interface/file_recorder.h"
22#include "webrtc/system_wrappers/interface/scoped_ptr.h"
23#include "webrtc/voice_engine/dtmf_inband.h"
24#include "webrtc/voice_engine/dtmf_inband_queue.h"
25#include "webrtc/voice_engine/include/voe_audio_processing.h"
26#include "webrtc/voice_engine/include/voe_network.h"
27#include "webrtc/voice_engine/level_indicator.h"
28#include "webrtc/voice_engine/shared_data.h"
29#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000030
niklase@google.com470e71d2011-07-07 08:21:25 +000031#ifdef WEBRTC_DTMF_DETECTION
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000032// TelephoneEventDetectionMethods, TelephoneEventObserver
33#include "webrtc/voice_engine/include/voe_dtmf.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000034#endif
35
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000036namespace webrtc {
37
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000038class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000039class Config;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000040class CriticalSectionWrapper;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000041class FileWrapper;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000042class ProcessThread;
43class ReceiveStatistics;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000044class RtpDump;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000045class RTPPayloadRegistry;
46class RtpReceiver;
47class RTPReceiverAudio;
48class RtpRtcp;
49class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000050class VoEMediaProcess;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000051class VoERTCPObserver;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000052class VoERTPObserver;
53class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000054
55struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000056struct ReportBlock;
57struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000059namespace voe {
60
niklase@google.com470e71d2011-07-07 08:21:25 +000061class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000062class StatisticsProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000063class TransmitMixer;
64class OutputMixer;
65
66
67class Channel:
68 public RtpData,
69 public RtpFeedback,
70 public RtcpFeedback,
niklase@google.com470e71d2011-07-07 08:21:25 +000071 public FileCallback, // receiving notification from file player & recorder
72 public Transport,
73 public RtpAudioFeedback,
74 public AudioPacketizationCallback, // receive encoded packets from the ACM
75 public ACMVADCallback, // receive voice activity from the ACM
niklase@google.com470e71d2011-07-07 08:21:25 +000076 public MixerParticipant // supplies output mixer with audio frames
77{
78public:
79 enum {KNumSocketThreads = 1};
80 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +000081 virtual ~Channel();
pbos@webrtc.org6141e132013-04-09 10:09:10 +000082 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +000083 int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +000084 uint32_t instanceId,
85 const Config& config);
86 Channel(int32_t channelId, uint32_t instanceId, const Config& config);
pbos@webrtc.org6141e132013-04-09 10:09:10 +000087 int32_t Init();
88 int32_t SetEngineInformation(
niklase@google.com470e71d2011-07-07 08:21:25 +000089 Statistics& engineStatistics,
90 OutputMixer& outputMixer,
91 TransmitMixer& transmitMixer,
92 ProcessThread& moduleProcessThread,
93 AudioDeviceModule& audioDeviceModule,
94 VoiceEngineObserver* voiceEngineObserver,
95 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org6141e132013-04-09 10:09:10 +000096 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +000097
niklase@google.com470e71d2011-07-07 08:21:25 +000098 // API methods
99
100 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000101 int32_t StartPlayout();
102 int32_t StopPlayout();
103 int32_t StartSend();
104 int32_t StopSend();
105 int32_t StartReceiving();
106 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000108 int32_t SetNetEQPlayoutMode(NetEqModes mode);
109 int32_t GetNetEQPlayoutMode(NetEqModes& mode);
110 int32_t SetOnHoldStatus(bool enable, OnHoldModes mode);
111 int32_t GetOnHoldStatus(bool& enabled, OnHoldModes& mode);
112 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
113 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
115 // VoECodec
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000116 int32_t GetSendCodec(CodecInst& codec);
117 int32_t GetRecCodec(CodecInst& codec);
118 int32_t SetSendCodec(const CodecInst& codec);
119 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
120 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
121 int32_t SetRecPayloadType(const CodecInst& codec);
122 int32_t GetRecPayloadType(CodecInst& codec);
123 int32_t SetAMREncFormat(AmrMode mode);
124 int32_t SetAMRDecFormat(AmrMode mode);
125 int32_t SetAMRWbEncFormat(AmrMode mode);
126 int32_t SetAMRWbDecFormat(AmrMode mode);
127 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
128 int32_t SetISACInitTargetRate(int rateBps, bool useFixedFrameSize);
129 int32_t SetISACMaxRate(int rateBps);
130 int32_t SetISACMaxPayloadSize(int sizeBytes);
niklase@google.com470e71d2011-07-07 08:21:25 +0000131
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000132 // VoE dual-streaming.
133 int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);
134 void RemoveSecondarySendCodec();
135 int GetSecondarySendCodec(CodecInst* codec);
136
niklase@google.com470e71d2011-07-07 08:21:25 +0000137 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000138 int32_t RegisterExternalTransport(Transport& transport);
139 int32_t DeRegisterExternalTransport();
140 int32_t ReceivedRTPPacket(const int8_t* data, int32_t length);
141 int32_t ReceivedRTCPPacket(const int8_t* data, int32_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000142
niklase@google.com470e71d2011-07-07 08:21:25 +0000143 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000144 int StartPlayingFileLocally(const char* fileName, bool loop,
145 FileFormats format,
146 int startPosition,
147 float volumeScaling,
148 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000149 const CodecInst* codecInst);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000150 int StartPlayingFileLocally(InStream* stream, FileFormats format,
151 int startPosition,
152 float volumeScaling,
153 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000154 const CodecInst* codecInst);
155 int StopPlayingFileLocally();
156 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000157 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000158 int ScaleLocalFilePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000159 int GetLocalPlayoutPosition(int& positionMs);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000160 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
161 FileFormats format,
162 int startPosition,
163 float volumeScaling,
164 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000165 const CodecInst* codecInst);
166 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000167 FileFormats format,
168 int startPosition,
169 float volumeScaling,
170 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000171 const CodecInst* codecInst);
172 int StopPlayingFileAsMicrophone();
173 int IsPlayingFileAsMicrophone() const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000174 int ScaleFileAsMicrophonePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000175 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
176 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
177 int StopRecordingPlayout();
178
179 void SetMixWithMicStatus(bool mix);
180
181 // VoEExternalMediaProcessing
182 int RegisterExternalMediaProcessing(ProcessingTypes type,
183 VoEMediaProcess& processObject);
184 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000185 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000186
187 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000188 int GetSpeechOutputLevel(uint32_t& level) const;
189 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000190 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000191 bool Mute() const;
192 int SetOutputVolumePan(float left, float right);
193 int GetOutputVolumePan(float& left, float& right) const;
194 int SetChannelOutputVolumeScaling(float scaling);
195 int GetChannelOutputVolumeScaling(float& scaling) const;
196
197 // VoECallReport
198 void ResetDeadOrAliveCounters();
199 int ResetRTCPStatistics();
200 int GetRoundTripTimeSummary(StatVal& delaysMs) const;
201 int GetDeadOrAliveCounters(int& countDead, int& countAlive) const;
202
203 // VoENetEqStats
204 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000205 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000206
207 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000208 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
209 int* playout_buffer_delay_ms) const;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000210 int least_required_delay_ms() const { return least_required_delay_ms_; }
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000211 int SetInitialPlayoutDelay(int delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000212 int SetMinimumPlayoutDelay(int delayMs);
213 int GetPlayoutTimestamp(unsigned int& timestamp);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000214 void UpdatePlayoutTimestamp(bool rtcp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000215 int SetInitTimestamp(unsigned int timestamp);
216 int SetInitSequenceNumber(short sequenceNumber);
217
218 // VoEVideoSyncExtended
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000219 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000220
niklase@google.com470e71d2011-07-07 08:21:25 +0000221 // VoEDtmf
222 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
223 int attenuationDb, bool playDtmfEvent);
224 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
225 int attenuationDb, bool playDtmfEvent);
226 int SetDtmfPlayoutStatus(bool enable);
227 bool DtmfPlayoutStatus() const;
228 int SetSendTelephoneEventPayloadType(unsigned char type);
229 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000230
231 // VoEAudioProcessingImpl
232 int UpdateRxVadDetection(AudioFrame& audioFrame);
233 int RegisterRxVadObserver(VoERxVadCallback &observer);
234 int DeRegisterRxVadObserver();
235 int VoiceActivityIndicator(int &activity);
236#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000237 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000238 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000239 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000240 int GetRxAgcConfig(AgcConfig& config);
241#endif
242#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000243 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000244 int GetRxNsStatus(bool& enabled, NsModes& mode);
245#endif
246
247 // VoERTP_RTCP
248 int RegisterRTPObserver(VoERTPObserver& observer);
249 int DeRegisterRTPObserver();
250 int RegisterRTCPObserver(VoERTCPObserver& observer);
251 int DeRegisterRTCPObserver();
252 int SetLocalSSRC(unsigned int ssrc);
253 int GetLocalSSRC(unsigned int& ssrc);
254 int GetRemoteSSRC(unsigned int& ssrc);
255 int GetRemoteCSRCs(unsigned int arrCSRC[15]);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000256 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
257 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
258 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000259 int SetRTCPStatus(bool enable);
260 int GetRTCPStatus(bool& enabled);
261 int SetRTCP_CNAME(const char cName[256]);
262 int GetRTCP_CNAME(char cName[256]);
263 int GetRemoteRTCP_CNAME(char cName[256]);
264 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
265 unsigned int& timestamp,
266 unsigned int& playoutTimestamp, unsigned int* jitter,
267 unsigned short* fractionLost);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000268 int SendApplicationDefinedRTCPPacket(unsigned char subType,
niklase@google.com470e71d2011-07-07 08:21:25 +0000269 unsigned int name, const char* data,
270 unsigned short dataLengthInBytes);
271 int GetRTPStatistics(unsigned int& averageJitterMs,
272 unsigned int& maxJitterMs,
273 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000274 int GetRemoteRTCPSenderInfo(SenderInfo* sender_info);
275 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000276 int GetRTPStatistics(CallStatistics& stats);
277 int SetFECStatus(bool enable, int redPayloadtype);
278 int GetFECStatus(bool& enabled, int& redPayloadtype);
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000279 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000280 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
281 int StopRTPDump(RTPDirections direction);
282 bool RTPDumpIsActive(RTPDirections direction);
roosa@google.com0870f022012-12-12 21:31:41 +0000283 uint32_t LastRemoteTimeStamp() { return _lastRemoteTimeStamp; }
niklase@google.com470e71d2011-07-07 08:21:25 +0000284
niklase@google.com470e71d2011-07-07 08:21:25 +0000285 // From AudioPacketizationCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000286 int32_t SendData(FrameType frameType,
287 uint8_t payloadType,
288 uint32_t timeStamp,
289 const uint8_t* payloadData,
290 uint16_t payloadSize,
291 const RTPFragmentationHeader* fragmentation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000292 // From ACMVADCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000293 int32_t InFrameType(int16_t frameType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000294
pbos@webrtc.org92135212013-05-14 08:31:39 +0000295 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000296
niklase@google.com470e71d2011-07-07 08:21:25 +0000297 // From RtpData in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000298 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000299 uint16_t payloadSize,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000300 const WebRtcRTPHeader* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +0000301
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000302 bool OnRecoveredPacket(const uint8_t* packet, int packet_length);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000303
niklase@google.com470e71d2011-07-07 08:21:25 +0000304 // From RtpFeedback in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000305 int32_t OnInitializeDecoder(
pbos@webrtc.org92135212013-05-14 08:31:39 +0000306 int32_t id,
307 int8_t payloadType,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000308 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org92135212013-05-14 08:31:39 +0000309 int frequency,
310 uint8_t channels,
311 uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000312
pbos@webrtc.org92135212013-05-14 08:31:39 +0000313 void OnPacketTimeout(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000314
pbos@webrtc.org92135212013-05-14 08:31:39 +0000315 void OnReceivedPacket(int32_t id, RtpRtcpPacketType packetType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000316
pbos@webrtc.org92135212013-05-14 08:31:39 +0000317 void OnPeriodicDeadOrAlive(int32_t id,
318 RTPAliveType alive);
niklase@google.com470e71d2011-07-07 08:21:25 +0000319
pbos@webrtc.org92135212013-05-14 08:31:39 +0000320 void OnIncomingSSRCChanged(int32_t id,
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000321 uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000322
pbos@webrtc.org92135212013-05-14 08:31:39 +0000323 void OnIncomingCSRCChanged(int32_t id,
324 uint32_t CSRC, bool added);
niklase@google.com470e71d2011-07-07 08:21:25 +0000325
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000326 void ResetStatistics(uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000327
niklase@google.com470e71d2011-07-07 08:21:25 +0000328 // From RtcpFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000329 void OnApplicationDataReceived(int32_t id,
330 uint8_t subType,
331 uint32_t name,
332 uint16_t length,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000333 const uint8_t* data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000334
niklase@google.com470e71d2011-07-07 08:21:25 +0000335 // From RtpAudioFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000336 void OnReceivedTelephoneEvent(int32_t id,
337 uint8_t event,
338 bool endOfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000339
pbos@webrtc.org92135212013-05-14 08:31:39 +0000340 void OnPlayTelephoneEvent(int32_t id,
341 uint8_t event,
342 uint16_t lengthMs,
343 uint8_t volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000344
niklase@google.com470e71d2011-07-07 08:21:25 +0000345 // From Transport (called by the RTP/RTCP module)
346 int SendPacket(int /*channel*/, const void *data, int len);
347 int SendRTCPPacket(int /*channel*/, const void *data, int len);
348
niklase@google.com470e71d2011-07-07 08:21:25 +0000349 // From MixerParticipant
pbos@webrtc.org92135212013-05-14 08:31:39 +0000350 int32_t GetAudioFrame(int32_t id, AudioFrame& audioFrame);
351 int32_t NeededFrequency(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000352
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 // From MonitorObserver
354 void OnPeriodicProcess();
355
niklase@google.com470e71d2011-07-07 08:21:25 +0000356 // From FileCallback
pbos@webrtc.org92135212013-05-14 08:31:39 +0000357 void PlayNotification(int32_t id,
358 uint32_t durationMs);
359 void RecordNotification(int32_t id,
360 uint32_t durationMs);
361 void PlayFileEnded(int32_t id);
362 void RecordFileEnded(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000363
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000364 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000365 {
366 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000367 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000368 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000369 {
370 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000371 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000372 bool Playing() const
373 {
374 return _playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000375 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000376 bool Sending() const
377 {
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000378 // A lock is needed because |_sending| is accessed by both
379 // TransmitMixer::PrepareDemux() and StartSend()/StopSend(), which
380 // are called by different threads.
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +0000381 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000382 return _sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000383 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000384 bool Receiving() const
385 {
386 return _receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000387 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000388 bool ExternalTransport() const
389 {
390 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000391 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000392 bool ExternalMixing() const
393 {
394 return _externalMixing;
395 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000396 bool OutputIsOnHold() const
397 {
398 return _outputIsOnHold;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000399 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000400 bool InputIsOnHold() const
401 {
402 return _inputIsOnHold;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000403 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000404 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000405 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000406 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000407 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000408 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000409 {
410 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000411 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000412 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000413 // Demultiplex the data to the channel's |_audioFrame|. The difference
414 // between this method and the overloaded method above is that |audio_data|
415 // does not go through transmit_mixer and APM.
416 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000417 int sample_rate,
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000418 int number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000419 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000420 uint32_t PrepareEncodeAndSend(int mixingFrequency);
421 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000422
423private:
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000424 bool ReceivePacket(const uint8_t* packet, int packet_length,
425 const RTPHeader& header, bool in_order);
426 bool HandleEncapsulation(const uint8_t* packet,
427 int packet_length,
428 const RTPHeader& header);
429 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000430 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000431 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000432 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000433 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
434 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000435 void UpdateDeadOrAliveCounters(bool alive);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000436 int32_t SendPacketRaw(const void *data, int len, bool RTCP);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000437 void UpdatePacketDelay(uint32_t timestamp,
438 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000439 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000440
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000441 int SetRedPayloadType(int red_payload_type);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000442 int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type,
443 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000444
niklase@google.com470e71d2011-07-07 08:21:25 +0000445 CriticalSectionWrapper& _fileCritSect;
446 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.org63420662013-10-17 18:28:55 +0000447 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000448 uint32_t _instanceId;
449 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000450
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000451 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000452 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
453 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +0000454 scoped_ptr<StatisticsProxy> statistics_proxy_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000455 scoped_ptr<RtpReceiver> rtp_receiver_;
456 TelephoneEventHandler* telephone_event_handler_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000457 scoped_ptr<RtpRtcp> _rtpRtcpModule;
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000458 scoped_ptr<AudioCodingModule> audio_coding_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000459 RtpDump& _rtpDumpIn;
460 RtpDump& _rtpDumpOut;
niklase@google.com470e71d2011-07-07 08:21:25 +0000461 AudioLevel _outputAudioLevel;
462 bool _externalTransport;
463 AudioFrame _audioFrame;
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000464 scoped_array<int16_t> mono_recording_audio_;
465 // Resampler is used when input data is stereo while codec is mono.
466 PushResampler input_resampler_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000467 uint8_t _audioLevel_dBov;
niklase@google.com470e71d2011-07-07 08:21:25 +0000468 FilePlayer* _inputFilePlayerPtr;
469 FilePlayer* _outputFilePlayerPtr;
470 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000471 int _inputFilePlayerId;
472 int _outputFilePlayerId;
473 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000474 bool _inputFilePlaying;
475 bool _outputFilePlaying;
476 bool _outputFileRecording;
477 DtmfInbandQueue _inbandDtmfQueue;
478 DtmfInband _inbandDtmfGenerator;
niklase@google.com470e71d2011-07-07 08:21:25 +0000479 bool _inputExternalMedia;
xians@google.com22963ab2011-08-03 12:40:23 +0000480 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000481 VoEMediaProcess* _inputExternalMediaCallbackPtr;
482 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000483 uint32_t _timeStamp;
484 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000485
486 // Timestamp of the audio pulled from NetEq.
487 uint32_t jitter_buffer_playout_timestamp_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000488 uint32_t playout_timestamp_rtp_;
489 uint32_t playout_timestamp_rtcp_;
490 uint32_t playout_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000491 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000492 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000493 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000494
niklase@google.com470e71d2011-07-07 08:21:25 +0000495 // uses
496 Statistics* _engineStatisticsPtr;
497 OutputMixer* _outputMixerPtr;
498 TransmitMixer* _transmitMixerPtr;
499 ProcessThread* _moduleProcessThreadPtr;
500 AudioDeviceModule* _audioDeviceModulePtr;
501 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
502 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
503 Transport* _transportPtr; // WebRtc socket or external transport
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +0000504 scoped_ptr<AudioProcessing> rtp_audioproc_;
505 scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000506 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000507 int32_t _oldVadDecision;
508 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000509 VoERTPObserver* _rtpObserverPtr;
510 VoERTCPObserver* _rtcpObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000511 // VoEBase
512 bool _outputIsOnHold;
513 bool _externalPlayout;
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000514 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000515 bool _inputIsOnHold;
516 bool _playing;
517 bool _sending;
518 bool _receiving;
519 bool _mixFileWithMicrophone;
520 bool _rtpObserver;
521 bool _rtcpObserver;
522 // VoEVolumeControl
523 bool _mute;
524 float _panLeft;
525 float _panRight;
526 float _outputGain;
niklase@google.com470e71d2011-07-07 08:21:25 +0000527 // VoEDtmf
528 bool _playOutbandDtmfEvent;
529 bool _playInbandDtmfEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000530 // VoeRTP_RTCP
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000531 uint32_t _lastLocalTimeStamp;
roosa@google.com0870f022012-12-12 21:31:41 +0000532 uint32_t _lastRemoteTimeStamp;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000533 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000534 bool _includeAudioLevelIndication;
535 // VoENetwork
536 bool _rtpPacketTimedOut;
537 bool _rtpPacketTimeOutIsEnabled;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000538 uint32_t _rtpTimeOutSeconds;
niklase@google.com470e71d2011-07-07 08:21:25 +0000539 bool _connectionObserver;
540 VoEConnectionObserver* _connectionObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000541 uint32_t _countAliveDetections;
542 uint32_t _countDeadDetections;
niklase@google.com470e71d2011-07-07 08:21:25 +0000543 AudioFrame::SpeechType _outputSpeechType;
544 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000545 uint32_t _average_jitter_buffer_delay_us;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000546 int least_required_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000547 uint32_t _previousTimestamp;
548 uint16_t _recPacketDelayMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000549 // VoEAudioProcessing
550 bool _RxVadDetection;
551 bool _rxApmIsEnabled;
552 bool _rxAgcIsEnabled;
553 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000554 bool restored_packet_in_use_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000555};
556
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000557} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000558} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000559
560#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H