blob: f8b04fdd18f58647019e71e4c856986b5ee963c0 [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;
62class TransmitMixer;
63class OutputMixer;
64
65
66class Channel:
67 public RtpData,
68 public RtpFeedback,
69 public RtcpFeedback,
niklase@google.com470e71d2011-07-07 08:21:25 +000070 public FileCallback, // receiving notification from file player & recorder
71 public Transport,
72 public RtpAudioFeedback,
73 public AudioPacketizationCallback, // receive encoded packets from the ACM
74 public ACMVADCallback, // receive voice activity from the ACM
niklase@google.com470e71d2011-07-07 08:21:25 +000075 public MixerParticipant // supplies output mixer with audio frames
76{
77public:
78 enum {KNumSocketThreads = 1};
79 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +000080 virtual ~Channel();
pbos@webrtc.org6141e132013-04-09 10:09:10 +000081 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +000082 int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +000083 uint32_t instanceId,
84 const Config& config);
85 Channel(int32_t channelId, uint32_t instanceId, const Config& config);
pbos@webrtc.org6141e132013-04-09 10:09:10 +000086 int32_t Init();
87 int32_t SetEngineInformation(
niklase@google.com470e71d2011-07-07 08:21:25 +000088 Statistics& engineStatistics,
89 OutputMixer& outputMixer,
90 TransmitMixer& transmitMixer,
91 ProcessThread& moduleProcessThread,
92 AudioDeviceModule& audioDeviceModule,
93 VoiceEngineObserver* voiceEngineObserver,
94 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org6141e132013-04-09 10:09:10 +000095 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +000096
niklase@google.com470e71d2011-07-07 08:21:25 +000097 // API methods
98
99 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000100 int32_t StartPlayout();
101 int32_t StopPlayout();
102 int32_t StartSend();
103 int32_t StopSend();
104 int32_t StartReceiving();
105 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000107 int32_t SetNetEQPlayoutMode(NetEqModes mode);
108 int32_t GetNetEQPlayoutMode(NetEqModes& mode);
109 int32_t SetOnHoldStatus(bool enable, OnHoldModes mode);
110 int32_t GetOnHoldStatus(bool& enabled, OnHoldModes& mode);
111 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
112 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
114 // VoECodec
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000115 int32_t GetSendCodec(CodecInst& codec);
116 int32_t GetRecCodec(CodecInst& codec);
117 int32_t SetSendCodec(const CodecInst& codec);
118 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
119 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
120 int32_t SetRecPayloadType(const CodecInst& codec);
121 int32_t GetRecPayloadType(CodecInst& codec);
122 int32_t SetAMREncFormat(AmrMode mode);
123 int32_t SetAMRDecFormat(AmrMode mode);
124 int32_t SetAMRWbEncFormat(AmrMode mode);
125 int32_t SetAMRWbDecFormat(AmrMode mode);
126 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
127 int32_t SetISACInitTargetRate(int rateBps, bool useFixedFrameSize);
128 int32_t SetISACMaxRate(int rateBps);
129 int32_t SetISACMaxPayloadSize(int sizeBytes);
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000131 // VoE dual-streaming.
132 int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);
133 void RemoveSecondarySendCodec();
134 int GetSecondarySendCodec(CodecInst* codec);
135
niklase@google.com470e71d2011-07-07 08:21:25 +0000136 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000137 int32_t RegisterExternalTransport(Transport& transport);
138 int32_t DeRegisterExternalTransport();
139 int32_t ReceivedRTPPacket(const int8_t* data, int32_t length);
140 int32_t ReceivedRTCPPacket(const int8_t* data, int32_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000141
niklase@google.com470e71d2011-07-07 08:21:25 +0000142 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000143 int StartPlayingFileLocally(const char* fileName, bool loop,
144 FileFormats format,
145 int startPosition,
146 float volumeScaling,
147 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000148 const CodecInst* codecInst);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000149 int StartPlayingFileLocally(InStream* stream, FileFormats format,
150 int startPosition,
151 float volumeScaling,
152 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000153 const CodecInst* codecInst);
154 int StopPlayingFileLocally();
155 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000156 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000157 int ScaleLocalFilePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000158 int GetLocalPlayoutPosition(int& positionMs);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000159 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
160 FileFormats format,
161 int startPosition,
162 float volumeScaling,
163 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000164 const CodecInst* codecInst);
165 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000166 FileFormats format,
167 int startPosition,
168 float volumeScaling,
169 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000170 const CodecInst* codecInst);
171 int StopPlayingFileAsMicrophone();
172 int IsPlayingFileAsMicrophone() const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000173 int ScaleFileAsMicrophonePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000174 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
175 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
176 int StopRecordingPlayout();
177
178 void SetMixWithMicStatus(bool mix);
179
180 // VoEExternalMediaProcessing
181 int RegisterExternalMediaProcessing(ProcessingTypes type,
182 VoEMediaProcess& processObject);
183 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000184 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000185
186 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000187 int GetSpeechOutputLevel(uint32_t& level) const;
188 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000189 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000190 bool Mute() const;
191 int SetOutputVolumePan(float left, float right);
192 int GetOutputVolumePan(float& left, float& right) const;
193 int SetChannelOutputVolumeScaling(float scaling);
194 int GetChannelOutputVolumeScaling(float& scaling) const;
195
196 // VoECallReport
197 void ResetDeadOrAliveCounters();
198 int ResetRTCPStatistics();
199 int GetRoundTripTimeSummary(StatVal& delaysMs) const;
200 int GetDeadOrAliveCounters(int& countDead, int& countAlive) const;
201
202 // VoENetEqStats
203 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000204 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000205
206 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000207 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
208 int* playout_buffer_delay_ms) const;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000209 int least_required_delay_ms() const { return least_required_delay_ms_; }
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000210 int SetInitialPlayoutDelay(int delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000211 int SetMinimumPlayoutDelay(int delayMs);
212 int GetPlayoutTimestamp(unsigned int& timestamp);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000213 void UpdatePlayoutTimestamp(bool rtcp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000214 int SetInitTimestamp(unsigned int timestamp);
215 int SetInitSequenceNumber(short sequenceNumber);
216
217 // VoEVideoSyncExtended
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000218 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000219
220 // VoEEncryption
niklase@google.com470e71d2011-07-07 08:21:25 +0000221 int RegisterExternalEncryption(Encryption& encryption);
222 int DeRegisterExternalEncryption();
223
224 // VoEDtmf
225 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
226 int attenuationDb, bool playDtmfEvent);
227 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
228 int attenuationDb, bool playDtmfEvent);
229 int SetDtmfPlayoutStatus(bool enable);
230 bool DtmfPlayoutStatus() const;
231 int SetSendTelephoneEventPayloadType(unsigned char type);
232 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000233
234 // VoEAudioProcessingImpl
235 int UpdateRxVadDetection(AudioFrame& audioFrame);
236 int RegisterRxVadObserver(VoERxVadCallback &observer);
237 int DeRegisterRxVadObserver();
238 int VoiceActivityIndicator(int &activity);
239#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000240 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000241 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000242 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000243 int GetRxAgcConfig(AgcConfig& config);
244#endif
245#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000246 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000247 int GetRxNsStatus(bool& enabled, NsModes& mode);
248#endif
249
250 // VoERTP_RTCP
251 int RegisterRTPObserver(VoERTPObserver& observer);
252 int DeRegisterRTPObserver();
253 int RegisterRTCPObserver(VoERTCPObserver& observer);
254 int DeRegisterRTCPObserver();
255 int SetLocalSSRC(unsigned int ssrc);
256 int GetLocalSSRC(unsigned int& ssrc);
257 int GetRemoteSSRC(unsigned int& ssrc);
258 int GetRemoteCSRCs(unsigned int arrCSRC[15]);
259 int SetRTPAudioLevelIndicationStatus(bool enable, unsigned char ID);
260 int GetRTPAudioLevelIndicationStatus(bool& enable, unsigned char& ID);
261 int SetRTCPStatus(bool enable);
262 int GetRTCPStatus(bool& enabled);
263 int SetRTCP_CNAME(const char cName[256]);
264 int GetRTCP_CNAME(char cName[256]);
265 int GetRemoteRTCP_CNAME(char cName[256]);
266 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
267 unsigned int& timestamp,
268 unsigned int& playoutTimestamp, unsigned int* jitter,
269 unsigned short* fractionLost);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000270 int SendApplicationDefinedRTCPPacket(unsigned char subType,
niklase@google.com470e71d2011-07-07 08:21:25 +0000271 unsigned int name, const char* data,
272 unsigned short dataLengthInBytes);
273 int GetRTPStatistics(unsigned int& averageJitterMs,
274 unsigned int& maxJitterMs,
275 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000276 int GetRemoteRTCPSenderInfo(SenderInfo* sender_info);
277 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000278 int GetRTPStatistics(CallStatistics& stats);
279 int SetFECStatus(bool enable, int redPayloadtype);
280 int GetFECStatus(bool& enabled, int& redPayloadtype);
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000281 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000282 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
283 int StopRTPDump(RTPDirections direction);
284 bool RTPDumpIsActive(RTPDirections direction);
285 int InsertExtraRTPPacket(unsigned char payloadType, bool markerBit,
286 const char* payloadData,
287 unsigned short payloadSize);
roosa@google.com0870f022012-12-12 21:31:41 +0000288 uint32_t LastRemoteTimeStamp() { return _lastRemoteTimeStamp; }
niklase@google.com470e71d2011-07-07 08:21:25 +0000289
niklase@google.com470e71d2011-07-07 08:21:25 +0000290 // From AudioPacketizationCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000291 int32_t SendData(FrameType frameType,
292 uint8_t payloadType,
293 uint32_t timeStamp,
294 const uint8_t* payloadData,
295 uint16_t payloadSize,
296 const RTPFragmentationHeader* fragmentation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000297 // From ACMVADCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000298 int32_t InFrameType(int16_t frameType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000299
pbos@webrtc.org92135212013-05-14 08:31:39 +0000300 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000301
niklase@google.com470e71d2011-07-07 08:21:25 +0000302 // From RtpData in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000303 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000304 uint16_t payloadSize,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000305 const WebRtcRTPHeader* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +0000306
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000307 bool OnRecoveredPacket(const uint8_t* packet, int packet_length);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000308
niklase@google.com470e71d2011-07-07 08:21:25 +0000309 // From RtpFeedback in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000310 int32_t OnInitializeDecoder(
pbos@webrtc.org92135212013-05-14 08:31:39 +0000311 int32_t id,
312 int8_t payloadType,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000313 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org92135212013-05-14 08:31:39 +0000314 int frequency,
315 uint8_t channels,
316 uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000317
pbos@webrtc.org92135212013-05-14 08:31:39 +0000318 void OnPacketTimeout(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000319
pbos@webrtc.org92135212013-05-14 08:31:39 +0000320 void OnReceivedPacket(int32_t id, RtpRtcpPacketType packetType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000321
pbos@webrtc.org92135212013-05-14 08:31:39 +0000322 void OnPeriodicDeadOrAlive(int32_t id,
323 RTPAliveType alive);
niklase@google.com470e71d2011-07-07 08:21:25 +0000324
pbos@webrtc.org92135212013-05-14 08:31:39 +0000325 void OnIncomingSSRCChanged(int32_t id,
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000326 uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000327
pbos@webrtc.org92135212013-05-14 08:31:39 +0000328 void OnIncomingCSRCChanged(int32_t id,
329 uint32_t CSRC, bool added);
niklase@google.com470e71d2011-07-07 08:21:25 +0000330
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000331 void ResetStatistics(uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000332
niklase@google.com470e71d2011-07-07 08:21:25 +0000333 // From RtcpFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000334 void OnApplicationDataReceived(int32_t id,
335 uint8_t subType,
336 uint32_t name,
337 uint16_t length,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000338 const uint8_t* data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000339
niklase@google.com470e71d2011-07-07 08:21:25 +0000340 // From RtpAudioFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000341 void OnReceivedTelephoneEvent(int32_t id,
342 uint8_t event,
343 bool endOfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000344
pbos@webrtc.org92135212013-05-14 08:31:39 +0000345 void OnPlayTelephoneEvent(int32_t id,
346 uint8_t event,
347 uint16_t lengthMs,
348 uint8_t volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000349
niklase@google.com470e71d2011-07-07 08:21:25 +0000350 // From Transport (called by the RTP/RTCP module)
351 int SendPacket(int /*channel*/, const void *data, int len);
352 int SendRTCPPacket(int /*channel*/, const void *data, int len);
353
niklase@google.com470e71d2011-07-07 08:21:25 +0000354 // From MixerParticipant
pbos@webrtc.org92135212013-05-14 08:31:39 +0000355 int32_t GetAudioFrame(int32_t id, AudioFrame& audioFrame);
356 int32_t NeededFrequency(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000357
niklase@google.com470e71d2011-07-07 08:21:25 +0000358 // From MonitorObserver
359 void OnPeriodicProcess();
360
niklase@google.com470e71d2011-07-07 08:21:25 +0000361 // From FileCallback
pbos@webrtc.org92135212013-05-14 08:31:39 +0000362 void PlayNotification(int32_t id,
363 uint32_t durationMs);
364 void RecordNotification(int32_t id,
365 uint32_t durationMs);
366 void PlayFileEnded(int32_t id);
367 void RecordFileEnded(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000368
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000369 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000370 {
371 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000372 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000373 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000374 {
375 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000376 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000377 bool Playing() const
378 {
379 return _playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000380 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000381 bool Sending() const
382 {
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000383 // A lock is needed because |_sending| is accessed by both
384 // TransmitMixer::PrepareDemux() and StartSend()/StopSend(), which
385 // are called by different threads.
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +0000386 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000387 return _sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000388 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000389 bool Receiving() const
390 {
391 return _receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000392 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000393 bool ExternalTransport() const
394 {
395 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000396 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000397 bool ExternalMixing() const
398 {
399 return _externalMixing;
400 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000401 bool OutputIsOnHold() const
402 {
403 return _outputIsOnHold;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000404 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000405 bool InputIsOnHold() const
406 {
407 return _inputIsOnHold;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000408 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000409 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000410 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000411 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000412 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000413 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000414 {
415 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000416 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000417 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000418 // Demultiplex the data to the channel's |_audioFrame|. The difference
419 // between this method and the overloaded method above is that |audio_data|
420 // does not go through transmit_mixer and APM.
421 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000422 int sample_rate,
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000423 int number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000424 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000425 uint32_t PrepareEncodeAndSend(int mixingFrequency);
426 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000427
428private:
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000429 bool ReceivePacket(const uint8_t* packet, int packet_length,
430 const RTPHeader& header, bool in_order);
431 bool HandleEncapsulation(const uint8_t* packet,
432 int packet_length,
433 const RTPHeader& header);
434 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000435 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000436 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000437 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000438 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
439 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000440 void UpdateDeadOrAliveCounters(bool alive);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000441 int32_t SendPacketRaw(const void *data, int len, bool RTCP);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000442 void UpdatePacketDelay(uint32_t timestamp,
443 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000444 void RegisterReceiveCodecsToRTPModule();
445 int ApmProcessRx(AudioFrame& audioFrame);
446
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000447 int SetRedPayloadType(int red_payload_type);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000448
niklase@google.com470e71d2011-07-07 08:21:25 +0000449 CriticalSectionWrapper& _fileCritSect;
450 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.org63420662013-10-17 18:28:55 +0000451 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000452 uint32_t _instanceId;
453 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000454
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000455 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000456 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
457 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
458 scoped_ptr<RtpReceiver> rtp_receiver_;
459 TelephoneEventHandler* telephone_event_handler_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000460 scoped_ptr<RtpRtcp> _rtpRtcpModule;
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000461 scoped_ptr<AudioCodingModule> audio_coding_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000462 RtpDump& _rtpDumpIn;
463 RtpDump& _rtpDumpOut;
niklase@google.com470e71d2011-07-07 08:21:25 +0000464 AudioLevel _outputAudioLevel;
465 bool _externalTransport;
466 AudioFrame _audioFrame;
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000467 scoped_array<int16_t> mono_recording_audio_;
468 // Resampler is used when input data is stereo while codec is mono.
469 PushResampler input_resampler_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000470 uint8_t _audioLevel_dBov;
niklase@google.com470e71d2011-07-07 08:21:25 +0000471 FilePlayer* _inputFilePlayerPtr;
472 FilePlayer* _outputFilePlayerPtr;
473 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000474 int _inputFilePlayerId;
475 int _outputFilePlayerId;
476 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000477 bool _inputFilePlaying;
478 bool _outputFilePlaying;
479 bool _outputFileRecording;
480 DtmfInbandQueue _inbandDtmfQueue;
481 DtmfInband _inbandDtmfGenerator;
niklase@google.com470e71d2011-07-07 08:21:25 +0000482 bool _inputExternalMedia;
xians@google.com22963ab2011-08-03 12:40:23 +0000483 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000484 VoEMediaProcess* _inputExternalMediaCallbackPtr;
485 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000486 uint8_t* _encryptionRTPBufferPtr;
487 uint8_t* _decryptionRTPBufferPtr;
488 uint8_t* _encryptionRTCPBufferPtr;
489 uint8_t* _decryptionRTCPBufferPtr;
490 uint32_t _timeStamp;
491 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000492
493 // Timestamp of the audio pulled from NetEq.
494 uint32_t jitter_buffer_playout_timestamp_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000495 uint32_t playout_timestamp_rtp_;
496 uint32_t playout_timestamp_rtcp_;
497 uint32_t playout_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000498 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000499 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000500 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000501
niklase@google.com470e71d2011-07-07 08:21:25 +0000502 // uses
503 Statistics* _engineStatisticsPtr;
504 OutputMixer* _outputMixerPtr;
505 TransmitMixer* _transmitMixerPtr;
506 ProcessThread* _moduleProcessThreadPtr;
507 AudioDeviceModule* _audioDeviceModulePtr;
508 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
509 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
510 Transport* _transportPtr; // WebRtc socket or external transport
511 Encryption* _encryptionPtr; // WebRtc SRTP or external encryption
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +0000512 scoped_ptr<AudioProcessing> rtp_audioproc_;
513 scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000514 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000515 int32_t _oldVadDecision;
516 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000517 VoERTPObserver* _rtpObserverPtr;
518 VoERTCPObserver* _rtcpObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000519 // VoEBase
520 bool _outputIsOnHold;
521 bool _externalPlayout;
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000522 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000523 bool _inputIsOnHold;
524 bool _playing;
525 bool _sending;
526 bool _receiving;
527 bool _mixFileWithMicrophone;
528 bool _rtpObserver;
529 bool _rtcpObserver;
530 // VoEVolumeControl
531 bool _mute;
532 float _panLeft;
533 float _panRight;
534 float _outputGain;
535 // VoEEncryption
536 bool _encrypting;
537 bool _decrypting;
538 // VoEDtmf
539 bool _playOutbandDtmfEvent;
540 bool _playInbandDtmfEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000541 // VoeRTP_RTCP
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000542 uint8_t _extraPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000543 bool _insertExtraRTPPacket;
544 bool _extraMarkerBit;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000545 uint32_t _lastLocalTimeStamp;
roosa@google.com0870f022012-12-12 21:31:41 +0000546 uint32_t _lastRemoteTimeStamp;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000547 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000548 bool _includeAudioLevelIndication;
549 // VoENetwork
550 bool _rtpPacketTimedOut;
551 bool _rtpPacketTimeOutIsEnabled;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000552 uint32_t _rtpTimeOutSeconds;
niklase@google.com470e71d2011-07-07 08:21:25 +0000553 bool _connectionObserver;
554 VoEConnectionObserver* _connectionObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000555 uint32_t _countAliveDetections;
556 uint32_t _countDeadDetections;
niklase@google.com470e71d2011-07-07 08:21:25 +0000557 AudioFrame::SpeechType _outputSpeechType;
558 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000559 uint32_t _average_jitter_buffer_delay_us;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000560 int least_required_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000561 uint32_t _previousTimestamp;
562 uint16_t _recPacketDelayMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000563 // VoEAudioProcessing
564 bool _RxVadDetection;
565 bool _rxApmIsEnabled;
566 bool _rxAgcIsEnabled;
567 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000568 bool restored_packet_in_use_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000569};
570
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000571} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000572} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000573
574#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H