blob: 2aacf3b55503cd06e3b0cedd8013a1fefb49e0f4 [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
niklase@google.com470e71d2011-07-07 08:21:25 +000014#include "audio_coding_module.h"
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000015#include "audio_conference_mixer_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016#include "common_types.h"
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000017#include "dtmf_inband.h"
18#include "dtmf_inband_queue.h"
19#include "file_player.h"
20#include "file_recorder.h"
21#include "level_indicator.h"
22#include "resampler.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023#include "rtp_rtcp.h"
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000024#include "scoped_ptr.h"
25#include "shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000026#include "voe_audio_processing.h"
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000027#include "voe_network.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000028#include "voice_engine_defines.h"
29
30#ifndef WEBRTC_EXTERNAL_TRANSPORT
31#include "udp_transport.h"
32#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000033#ifdef WEBRTC_SRTP
34#include "SrtpModule.h"
35#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000036#ifdef WEBRTC_DTMF_DETECTION
37#include "voe_dtmf.h" // TelephoneEventDetectionMethods, TelephoneEventObserver
38#endif
39
40namespace webrtc
41{
42class CriticalSectionWrapper;
43class ProcessThread;
44class AudioDeviceModule;
45class RtpRtcp;
46class FileWrapper;
47class RtpDump;
48class VoiceEngineObserver;
49class VoEMediaProcess;
50class VoERTPObserver;
51class VoERTCPObserver;
52
53struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000054struct ReportBlock;
55struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
57namespace voe
58{
59class Statistics;
60class TransmitMixer;
61class OutputMixer;
62
63
64class Channel:
65 public RtpData,
66 public RtpFeedback,
67 public RtcpFeedback,
68#ifndef WEBRTC_EXTERNAL_TRANSPORT
69 public UdpTransportData, // receiving packet from sockets
70#endif
71 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
76#ifdef WEBRTC_DTMF_DETECTION
77 public AudioCodingFeedback, // inband Dtmf detection in the ACM
78#endif
79 public MixerParticipant // supplies output mixer with audio frames
80{
81public:
82 enum {KNumSocketThreads = 1};
83 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +000084public:
85 virtual ~Channel();
86 static WebRtc_Word32 CreateChannel(Channel*& channel,
87 const WebRtc_Word32 channelId,
88 const WebRtc_UWord32 instanceId);
89 Channel(const WebRtc_Word32 channelId, const WebRtc_UWord32 instanceId);
90 WebRtc_Word32 Init();
91 WebRtc_Word32 SetEngineInformation(
92 Statistics& engineStatistics,
93 OutputMixer& outputMixer,
94 TransmitMixer& transmitMixer,
95 ProcessThread& moduleProcessThread,
96 AudioDeviceModule& audioDeviceModule,
97 VoiceEngineObserver* voiceEngineObserver,
98 CriticalSectionWrapper* callbackCritSect);
99 WebRtc_Word32 UpdateLocalTimeStamp();
100
101public:
102 // API methods
103
104 // VoEBase
105 WebRtc_Word32 StartPlayout();
106 WebRtc_Word32 StopPlayout();
107 WebRtc_Word32 StartSend();
108 WebRtc_Word32 StopSend();
109 WebRtc_Word32 StartReceiving();
110 WebRtc_Word32 StopReceiving();
111
112#ifndef WEBRTC_EXTERNAL_TRANSPORT
113 WebRtc_Word32 SetLocalReceiver(const WebRtc_UWord16 rtpPort,
114 const WebRtc_UWord16 rtcpPort,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000115 const char ipAddr[64],
116 const char multicastIpAddr[64]);
niklase@google.com470e71d2011-07-07 08:21:25 +0000117 WebRtc_Word32 GetLocalReceiver(int& port, int& RTCPport, char ipAddr[]);
118 WebRtc_Word32 SetSendDestination(const WebRtc_UWord16 rtpPort,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000119 const char ipAddr[64],
niklase@google.com470e71d2011-07-07 08:21:25 +0000120 const int sourcePort,
121 const WebRtc_UWord16 rtcpPort);
122 WebRtc_Word32 GetSendDestination(int& port, char ipAddr[64],
123 int& sourcePort, int& RTCPport);
124#endif
125 WebRtc_Word32 SetNetEQPlayoutMode(NetEqModes mode);
126 WebRtc_Word32 GetNetEQPlayoutMode(NetEqModes& mode);
127 WebRtc_Word32 SetNetEQBGNMode(NetEqBgnModes mode);
128 WebRtc_Word32 GetNetEQBGNMode(NetEqBgnModes& mode);
129 WebRtc_Word32 SetOnHoldStatus(bool enable, OnHoldModes mode);
130 WebRtc_Word32 GetOnHoldStatus(bool& enabled, OnHoldModes& mode);
131 WebRtc_Word32 RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
132 WebRtc_Word32 DeRegisterVoiceEngineObserver();
133
134 // VoECodec
135 WebRtc_Word32 GetSendCodec(CodecInst& codec);
136 WebRtc_Word32 GetRecCodec(CodecInst& codec);
137 WebRtc_Word32 SetSendCodec(const CodecInst& codec);
138 WebRtc_Word32 SetVADStatus(bool enableVAD, ACMVADMode mode,
139 bool disableDTX);
140 WebRtc_Word32 GetVADStatus(bool& enabledVAD, ACMVADMode& mode,
141 bool& disabledDTX);
142 WebRtc_Word32 SetRecPayloadType(const CodecInst& codec);
143 WebRtc_Word32 GetRecPayloadType(CodecInst& codec);
144 WebRtc_Word32 SetAMREncFormat(AmrMode mode);
145 WebRtc_Word32 SetAMRDecFormat(AmrMode mode);
146 WebRtc_Word32 SetAMRWbEncFormat(AmrMode mode);
147 WebRtc_Word32 SetAMRWbDecFormat(AmrMode mode);
148 WebRtc_Word32 SetSendCNPayloadType(int type, PayloadFrequencies frequency);
149 WebRtc_Word32 SetISACInitTargetRate(int rateBps, bool useFixedFrameSize);
150 WebRtc_Word32 SetISACMaxRate(int rateBps);
151 WebRtc_Word32 SetISACMaxPayloadSize(int sizeBytes);
152
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000153 // VoE dual-streaming.
154 int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);
155 void RemoveSecondarySendCodec();
156 int GetSecondarySendCodec(CodecInst* codec);
157
niklase@google.com470e71d2011-07-07 08:21:25 +0000158 // VoENetwork
159 WebRtc_Word32 RegisterExternalTransport(Transport& transport);
160 WebRtc_Word32 DeRegisterExternalTransport();
161 WebRtc_Word32 ReceivedRTPPacket(const WebRtc_Word8* data,
162 WebRtc_Word32 length);
163 WebRtc_Word32 ReceivedRTCPPacket(const WebRtc_Word8* data,
164 WebRtc_Word32 length);
165#ifndef WEBRTC_EXTERNAL_TRANSPORT
166 WebRtc_Word32 GetSourceInfo(int& rtpPort, int& rtcpPort, char ipAddr[64]);
167 WebRtc_Word32 EnableIPv6();
168 bool IPv6IsEnabled() const;
169 WebRtc_Word32 SetSourceFilter(int rtpPort, int rtcpPort,
170 const char ipAddr[64]);
171 WebRtc_Word32 GetSourceFilter(int& rtpPort, int& rtcpPort, char ipAddr[64]);
172 WebRtc_Word32 SetSendTOS(int DSCP, int priority, bool useSetSockopt);
173 WebRtc_Word32 GetSendTOS(int &DSCP, int& priority, bool &useSetSockopt);
174#if defined(_WIN32)
175 WebRtc_Word32 SetSendGQoS(bool enable, int serviceType, int overrideDSCP);
176 WebRtc_Word32 GetSendGQoS(bool &enabled, int &serviceType,
177 int &overrideDSCP);
178#endif
179#endif
180 WebRtc_Word32 SetPacketTimeoutNotification(bool enable, int timeoutSeconds);
181 WebRtc_Word32 GetPacketTimeoutNotification(bool& enabled,
182 int& timeoutSeconds);
183 WebRtc_Word32 RegisterDeadOrAliveObserver(VoEConnectionObserver& observer);
184 WebRtc_Word32 DeRegisterDeadOrAliveObserver();
185 WebRtc_Word32 SetPeriodicDeadOrAliveStatus(bool enable,
186 int sampleTimeSeconds);
187 WebRtc_Word32 GetPeriodicDeadOrAliveStatus(bool& enabled,
188 int& sampleTimeSeconds);
189 WebRtc_Word32 SendUDPPacket(const void* data, unsigned int length,
190 int& transmittedBytes, bool useRtcpSocket);
191
192 // VoEFile
193 int StartPlayingFileLocally(const char* fileName, const bool loop,
194 const FileFormats format,
195 const int startPosition,
196 const float volumeScaling,
197 const int stopPosition,
198 const CodecInst* codecInst);
199 int StartPlayingFileLocally(InStream* stream, const FileFormats format,
200 const int startPosition,
201 const float volumeScaling,
202 const int stopPosition,
203 const CodecInst* codecInst);
204 int StopPlayingFileLocally();
205 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000206 int RegisterFilePlayingToMixer();
niklase@google.com470e71d2011-07-07 08:21:25 +0000207 int ScaleLocalFilePlayout(const float scale);
208 int GetLocalPlayoutPosition(int& positionMs);
209 int StartPlayingFileAsMicrophone(const char* fileName, const bool loop,
210 const FileFormats format,
211 const int startPosition,
212 const float volumeScaling,
213 const int stopPosition,
214 const CodecInst* codecInst);
215 int StartPlayingFileAsMicrophone(InStream* stream,
216 const FileFormats format,
217 const int startPosition,
218 const float volumeScaling,
219 const int stopPosition,
220 const CodecInst* codecInst);
221 int StopPlayingFileAsMicrophone();
222 int IsPlayingFileAsMicrophone() const;
223 int ScaleFileAsMicrophonePlayout(const float scale);
224 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
225 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
226 int StopRecordingPlayout();
227
228 void SetMixWithMicStatus(bool mix);
229
230 // VoEExternalMediaProcessing
231 int RegisterExternalMediaProcessing(ProcessingTypes type,
232 VoEMediaProcess& processObject);
233 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
234
235 // VoEVolumeControl
236 int GetSpeechOutputLevel(WebRtc_UWord32& level) const;
237 int GetSpeechOutputLevelFullRange(WebRtc_UWord32& level) const;
238 int SetMute(const bool enable);
239 bool Mute() const;
240 int SetOutputVolumePan(float left, float right);
241 int GetOutputVolumePan(float& left, float& right) const;
242 int SetChannelOutputVolumeScaling(float scaling);
243 int GetChannelOutputVolumeScaling(float& scaling) const;
244
245 // VoECallReport
246 void ResetDeadOrAliveCounters();
247 int ResetRTCPStatistics();
248 int GetRoundTripTimeSummary(StatVal& delaysMs) const;
249 int GetDeadOrAliveCounters(int& countDead, int& countAlive) const;
250
251 // VoENetEqStats
252 int GetNetworkStatistics(NetworkStatistics& stats);
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
254 // VoEVideoSync
255 int GetDelayEstimate(int& delayMs) const;
256 int SetMinimumPlayoutDelay(int delayMs);
257 int GetPlayoutTimestamp(unsigned int& timestamp);
258 int SetInitTimestamp(unsigned int timestamp);
259 int SetInitSequenceNumber(short sequenceNumber);
260
261 // VoEVideoSyncExtended
262 int GetRtpRtcp(RtpRtcp* &rtpRtcpModule) const;
263
264 // VoEEncryption
265#ifdef WEBRTC_SRTP
266 int EnableSRTPSend(
267 CipherTypes cipherType,
268 int cipherKeyLength,
269 AuthenticationTypes authType,
270 int authKeyLength,
271 int authTagLength,
272 SecurityLevels level,
273 const unsigned char key[kVoiceEngineMaxSrtpKeyLength],
274 bool useForRTCP);
275 int DisableSRTPSend();
276 int EnableSRTPReceive(
277 CipherTypes cipherType,
278 int cipherKeyLength,
279 AuthenticationTypes authType,
280 int authKeyLength,
281 int authTagLength,
282 SecurityLevels level,
283 const unsigned char key[kVoiceEngineMaxSrtpKeyLength],
284 bool useForRTCP);
285 int DisableSRTPReceive();
286#endif
287 int RegisterExternalEncryption(Encryption& encryption);
288 int DeRegisterExternalEncryption();
289
290 // VoEDtmf
291 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
292 int attenuationDb, bool playDtmfEvent);
293 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
294 int attenuationDb, bool playDtmfEvent);
295 int SetDtmfPlayoutStatus(bool enable);
296 bool DtmfPlayoutStatus() const;
297 int SetSendTelephoneEventPayloadType(unsigned char type);
298 int GetSendTelephoneEventPayloadType(unsigned char& type);
299#ifdef WEBRTC_DTMF_DETECTION
300 int RegisterTelephoneEventDetection(
301 TelephoneEventDetectionMethods detectionMethod,
302 VoETelephoneEventObserver& observer);
303 int DeRegisterTelephoneEventDetection();
304 int GetTelephoneEventDetectionStatus(
305 bool& enabled,
306 TelephoneEventDetectionMethods& detectionMethod);
307#endif
308
309 // VoEAudioProcessingImpl
310 int UpdateRxVadDetection(AudioFrame& audioFrame);
311 int RegisterRxVadObserver(VoERxVadCallback &observer);
312 int DeRegisterRxVadObserver();
313 int VoiceActivityIndicator(int &activity);
314#ifdef WEBRTC_VOICE_ENGINE_AGC
315 int SetRxAgcStatus(const bool enable, const AgcModes mode);
316 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
317 int SetRxAgcConfig(const AgcConfig config);
318 int GetRxAgcConfig(AgcConfig& config);
319#endif
320#ifdef WEBRTC_VOICE_ENGINE_NR
321 int SetRxNsStatus(const bool enable, const NsModes mode);
322 int GetRxNsStatus(bool& enabled, NsModes& mode);
323#endif
324
325 // VoERTP_RTCP
326 int RegisterRTPObserver(VoERTPObserver& observer);
327 int DeRegisterRTPObserver();
328 int RegisterRTCPObserver(VoERTCPObserver& observer);
329 int DeRegisterRTCPObserver();
330 int SetLocalSSRC(unsigned int ssrc);
331 int GetLocalSSRC(unsigned int& ssrc);
332 int GetRemoteSSRC(unsigned int& ssrc);
333 int GetRemoteCSRCs(unsigned int arrCSRC[15]);
334 int SetRTPAudioLevelIndicationStatus(bool enable, unsigned char ID);
335 int GetRTPAudioLevelIndicationStatus(bool& enable, unsigned char& ID);
336 int SetRTCPStatus(bool enable);
337 int GetRTCPStatus(bool& enabled);
338 int SetRTCP_CNAME(const char cName[256]);
339 int GetRTCP_CNAME(char cName[256]);
340 int GetRemoteRTCP_CNAME(char cName[256]);
341 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
342 unsigned int& timestamp,
343 unsigned int& playoutTimestamp, unsigned int* jitter,
344 unsigned short* fractionLost);
345 int SendApplicationDefinedRTCPPacket(const unsigned char subType,
346 unsigned int name, const char* data,
347 unsigned short dataLengthInBytes);
348 int GetRTPStatistics(unsigned int& averageJitterMs,
349 unsigned int& maxJitterMs,
350 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000351 int GetRemoteRTCPSenderInfo(SenderInfo* sender_info);
352 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 int GetRTPStatistics(CallStatistics& stats);
354 int SetFECStatus(bool enable, int redPayloadtype);
355 int GetFECStatus(bool& enabled, int& redPayloadtype);
niklase@google.com470e71d2011-07-07 08:21:25 +0000356 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
357 int StopRTPDump(RTPDirections direction);
358 bool RTPDumpIsActive(RTPDirections direction);
359 int InsertExtraRTPPacket(unsigned char payloadType, bool markerBit,
360 const char* payloadData,
361 unsigned short payloadSize);
362
363public:
364 // From AudioPacketizationCallback in the ACM
365 WebRtc_Word32 SendData(FrameType frameType,
366 WebRtc_UWord8 payloadType,
367 WebRtc_UWord32 timeStamp,
368 const WebRtc_UWord8* payloadData,
369 WebRtc_UWord16 payloadSize,
370 const RTPFragmentationHeader* fragmentation);
371 // From ACMVADCallback in the ACM
372 WebRtc_Word32 InFrameType(WebRtc_Word16 frameType);
373
374#ifdef WEBRTC_DTMF_DETECTION
375public: // From AudioCodingFeedback in the ACM
376 int IncomingDtmf(const WebRtc_UWord8 digitDtmf, const bool end);
377#endif
378
379public:
380 WebRtc_Word32 OnRxVadDetected(const int vadDecision);
381
382public:
383 // From RtpData in the RTP/RTCP module
384 WebRtc_Word32 OnReceivedPayloadData(const WebRtc_UWord8* payloadData,
385 const WebRtc_UWord16 payloadSize,
386 const WebRtcRTPHeader* rtpHeader);
387
388public:
389 // From RtpFeedback in the RTP/RTCP module
390 WebRtc_Word32 OnInitializeDecoder(
391 const WebRtc_Word32 id,
392 const WebRtc_Word8 payloadType,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000393 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
xians@google.com0b0665a2011-08-08 08:18:44 +0000394 const int frequency,
niklase@google.com470e71d2011-07-07 08:21:25 +0000395 const WebRtc_UWord8 channels,
396 const WebRtc_UWord32 rate);
397
398 void OnPacketTimeout(const WebRtc_Word32 id);
399
400 void OnReceivedPacket(const WebRtc_Word32 id,
401 const RtpRtcpPacketType packetType);
402
403 void OnPeriodicDeadOrAlive(const WebRtc_Word32 id,
404 const RTPAliveType alive);
405
406 void OnIncomingSSRCChanged(const WebRtc_Word32 id,
407 const WebRtc_UWord32 SSRC);
408
409 void OnIncomingCSRCChanged(const WebRtc_Word32 id,
410 const WebRtc_UWord32 CSRC, const bool added);
411
412public:
413 // From RtcpFeedback in the RTP/RTCP module
niklase@google.com470e71d2011-07-07 08:21:25 +0000414 void OnApplicationDataReceived(const WebRtc_Word32 id,
415 const WebRtc_UWord8 subType,
416 const WebRtc_UWord32 name,
417 const WebRtc_UWord16 length,
418 const WebRtc_UWord8* data);
419
niklase@google.com470e71d2011-07-07 08:21:25 +0000420public:
421 // From RtpAudioFeedback in the RTP/RTCP module
422 void OnReceivedTelephoneEvent(const WebRtc_Word32 id,
423 const WebRtc_UWord8 event,
424 const bool endOfEvent);
425
426 void OnPlayTelephoneEvent(const WebRtc_Word32 id,
427 const WebRtc_UWord8 event,
428 const WebRtc_UWord16 lengthMs,
429 const WebRtc_UWord8 volume);
430
431public:
432 // From UdpTransportData in the Socket Transport module
433 void IncomingRTPPacket(const WebRtc_Word8* incomingRtpPacket,
434 const WebRtc_Word32 rtpPacketLength,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000435 const char* fromIP,
niklase@google.com470e71d2011-07-07 08:21:25 +0000436 const WebRtc_UWord16 fromPort);
437
438 void IncomingRTCPPacket(const WebRtc_Word8* incomingRtcpPacket,
439 const WebRtc_Word32 rtcpPacketLength,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000440 const char* fromIP,
niklase@google.com470e71d2011-07-07 08:21:25 +0000441 const WebRtc_UWord16 fromPort);
442
443public:
444 // From Transport (called by the RTP/RTCP module)
445 int SendPacket(int /*channel*/, const void *data, int len);
446 int SendRTCPPacket(int /*channel*/, const void *data, int len);
447
448public:
449 // From MixerParticipant
450 WebRtc_Word32 GetAudioFrame(const WebRtc_Word32 id,
451 AudioFrame& audioFrame);
452 WebRtc_Word32 NeededFrequency(const WebRtc_Word32 id);
453
454public:
455 // From MonitorObserver
456 void OnPeriodicProcess();
457
458public:
459 // From FileCallback
460 void PlayNotification(const WebRtc_Word32 id,
461 const WebRtc_UWord32 durationMs);
462 void RecordNotification(const WebRtc_Word32 id,
463 const WebRtc_UWord32 durationMs);
464 void PlayFileEnded(const WebRtc_Word32 id);
465 void RecordFileEnded(const WebRtc_Word32 id);
466
467public:
468 WebRtc_UWord32 InstanceId() const
469 {
470 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000471 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000472 WebRtc_Word32 ChannelId() const
473 {
474 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000475 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000476 bool Playing() const
477 {
478 return _playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000479 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000480 bool Sending() const
481 {
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000482 // A lock is needed because |_sending| is accessed by both
483 // TransmitMixer::PrepareDemux() and StartSend()/StopSend(), which
484 // are called by different threads.
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +0000485 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000486 return _sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000487 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000488 bool Receiving() const
489 {
490 return _receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000491 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000492 bool ExternalTransport() const
493 {
494 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000495 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000496 bool OutputIsOnHold() const
497 {
498 return _outputIsOnHold;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000499 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000500 bool InputIsOnHold() const
501 {
502 return _inputIsOnHold;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000503 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000504 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000505 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000506 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000507 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000508 WebRtc_Word8 OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000509 {
510 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000511 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000512#ifndef WEBRTC_EXTERNAL_TRANSPORT
513 bool SendSocketsInitialized() const
514 {
515 return _socketTransportModule.SendSocketsInitialized();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000516 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000517 bool ReceiveSocketsInitialized() const
518 {
519 return _socketTransportModule.ReceiveSocketsInitialized();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000520 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000521#endif
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000522 WebRtc_UWord32 Demultiplex(const AudioFrame& audioFrame);
xians@google.com0b0665a2011-08-08 08:18:44 +0000523 WebRtc_UWord32 PrepareEncodeAndSend(int mixingFrequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000524 WebRtc_UWord32 EncodeAndSend();
525
526private:
527 int InsertInbandDtmfTone();
528 WebRtc_Word32
xians@google.com0b0665a2011-08-08 08:18:44 +0000529 MixOrReplaceAudioWithFile(const int mixingFrequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000530 WebRtc_Word32 MixAudioWithFile(AudioFrame& audioFrame,
xians@google.com0b0665a2011-08-08 08:18:44 +0000531 const int mixingFrequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000532 WebRtc_Word32 GetPlayoutTimeStamp(WebRtc_UWord32& playoutTimestamp);
533 void UpdateDeadOrAliveCounters(bool alive);
534 WebRtc_Word32 SendPacketRaw(const void *data, int len, bool RTCP);
535 WebRtc_Word32 UpdatePacketDelay(const WebRtc_UWord32 timestamp,
536 const WebRtc_UWord16 sequenceNumber);
537 void RegisterReceiveCodecsToRTPModule();
538 int ApmProcessRx(AudioFrame& audioFrame);
539
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000540 int SetRedPayloadType(int red_payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000541private:
542 CriticalSectionWrapper& _fileCritSect;
543 CriticalSectionWrapper& _callbackCritSect;
niklase@google.com470e71d2011-07-07 08:21:25 +0000544 WebRtc_UWord32 _instanceId;
545 WebRtc_Word32 _channelId;
546
547private:
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000548 scoped_ptr<RtpRtcp> _rtpRtcpModule;
niklase@google.com470e71d2011-07-07 08:21:25 +0000549 AudioCodingModule& _audioCodingModule;
550#ifndef WEBRTC_EXTERNAL_TRANSPORT
perkj@webrtc.org68f21682011-11-30 18:11:23 +0000551 WebRtc_UWord8 _numSocketThreads;
niklase@google.com470e71d2011-07-07 08:21:25 +0000552 UdpTransport& _socketTransportModule;
553#endif
554#ifdef WEBRTC_SRTP
555 SrtpModule& _srtpModule;
556#endif
557 RtpDump& _rtpDumpIn;
558 RtpDump& _rtpDumpOut;
559private:
560 AudioLevel _outputAudioLevel;
561 bool _externalTransport;
562 AudioFrame _audioFrame;
563 WebRtc_UWord8 _audioLevel_dBov;
564 FilePlayer* _inputFilePlayerPtr;
565 FilePlayer* _outputFilePlayerPtr;
566 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000567 int _inputFilePlayerId;
568 int _outputFilePlayerId;
569 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000570 bool _inputFilePlaying;
571 bool _outputFilePlaying;
572 bool _outputFileRecording;
573 DtmfInbandQueue _inbandDtmfQueue;
574 DtmfInband _inbandDtmfGenerator;
niklase@google.com470e71d2011-07-07 08:21:25 +0000575 bool _inputExternalMedia;
xians@google.com22963ab2011-08-03 12:40:23 +0000576 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000577 VoEMediaProcess* _inputExternalMediaCallbackPtr;
578 VoEMediaProcess* _outputExternalMediaCallbackPtr;
579 WebRtc_UWord8* _encryptionRTPBufferPtr;
580 WebRtc_UWord8* _decryptionRTPBufferPtr;
581 WebRtc_UWord8* _encryptionRTCPBufferPtr;
582 WebRtc_UWord8* _decryptionRTCPBufferPtr;
583 WebRtc_UWord32 _timeStamp;
584 WebRtc_UWord8 _sendTelephoneEventPayloadType;
585 WebRtc_UWord32 _playoutTimeStampRTP;
586 WebRtc_UWord32 _playoutTimeStampRTCP;
587 WebRtc_UWord32 _numberOfDiscardedPackets;
588private:
589 // uses
590 Statistics* _engineStatisticsPtr;
591 OutputMixer* _outputMixerPtr;
592 TransmitMixer* _transmitMixerPtr;
593 ProcessThread* _moduleProcessThreadPtr;
594 AudioDeviceModule* _audioDeviceModulePtr;
595 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
596 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
597 Transport* _transportPtr; // WebRtc socket or external transport
598 Encryption* _encryptionPtr; // WebRtc SRTP or external encryption
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000599 scoped_ptr<AudioProcessing> _rtpAudioProc;
niklase@google.com470e71d2011-07-07 08:21:25 +0000600 AudioProcessing* _rxAudioProcessingModulePtr; // far end AudioProcessing
601#ifdef WEBRTC_DTMF_DETECTION
602 VoETelephoneEventObserver* _telephoneEventDetectionPtr;
603#endif
604 VoERxVadCallback* _rxVadObserverPtr;
605 WebRtc_Word32 _oldVadDecision;
606 WebRtc_Word32 _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
607 VoERTPObserver* _rtpObserverPtr;
608 VoERTCPObserver* _rtcpObserverPtr;
609private:
610 // VoEBase
611 bool _outputIsOnHold;
612 bool _externalPlayout;
613 bool _inputIsOnHold;
614 bool _playing;
615 bool _sending;
616 bool _receiving;
617 bool _mixFileWithMicrophone;
618 bool _rtpObserver;
619 bool _rtcpObserver;
620 // VoEVolumeControl
621 bool _mute;
622 float _panLeft;
623 float _panRight;
624 float _outputGain;
625 // VoEEncryption
626 bool _encrypting;
627 bool _decrypting;
628 // VoEDtmf
629 bool _playOutbandDtmfEvent;
630 bool _playInbandDtmfEvent;
631 bool _inbandTelephoneEventDetection;
632 bool _outOfBandTelephoneEventDetecion;
633 // VoeRTP_RTCP
634 WebRtc_UWord8 _extraPayloadType;
635 bool _insertExtraRTPPacket;
636 bool _extraMarkerBit;
637 WebRtc_UWord32 _lastLocalTimeStamp;
638 WebRtc_Word8 _lastPayloadType;
639 bool _includeAudioLevelIndication;
640 // VoENetwork
641 bool _rtpPacketTimedOut;
642 bool _rtpPacketTimeOutIsEnabled;
643 WebRtc_UWord32 _rtpTimeOutSeconds;
644 bool _connectionObserver;
645 VoEConnectionObserver* _connectionObserverPtr;
646 WebRtc_UWord32 _countAliveDetections;
647 WebRtc_UWord32 _countDeadDetections;
648 AudioFrame::SpeechType _outputSpeechType;
649 // VoEVideoSync
650 WebRtc_UWord32 _averageDelayMs;
651 WebRtc_UWord16 _previousSequenceNumber;
652 WebRtc_UWord32 _previousTimestamp;
653 WebRtc_UWord16 _recPacketDelayMs;
654 // VoEAudioProcessing
655 bool _RxVadDetection;
656 bool _rxApmIsEnabled;
657 bool _rxAgcIsEnabled;
658 bool _rxNsIsEnabled;
659};
660
661} // namespace voe
662
663} // namespace webrtc
664
665#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H