blob: 4d9146eb1b7d48152d295d6cc7432ed4c3d2e83a [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
36namespace 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
59namespace voe
60{
61class 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 +000080public:
81 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
98public:
99 // API methods
100
101 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000102 int32_t StartPlayout();
103 int32_t StopPlayout();
104 int32_t StartSend();
105 int32_t StopSend();
106 int32_t StartReceiving();
107 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000109 int32_t SetNetEQPlayoutMode(NetEqModes mode);
110 int32_t GetNetEQPlayoutMode(NetEqModes& mode);
111 int32_t SetOnHoldStatus(bool enable, OnHoldModes mode);
112 int32_t GetOnHoldStatus(bool& enabled, OnHoldModes& mode);
113 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
114 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
116 // VoECodec
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000117 int32_t GetSendCodec(CodecInst& codec);
118 int32_t GetRecCodec(CodecInst& codec);
119 int32_t SetSendCodec(const CodecInst& codec);
120 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
121 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
122 int32_t SetRecPayloadType(const CodecInst& codec);
123 int32_t GetRecPayloadType(CodecInst& codec);
124 int32_t SetAMREncFormat(AmrMode mode);
125 int32_t SetAMRDecFormat(AmrMode mode);
126 int32_t SetAMRWbEncFormat(AmrMode mode);
127 int32_t SetAMRWbDecFormat(AmrMode mode);
128 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
129 int32_t SetISACInitTargetRate(int rateBps, bool useFixedFrameSize);
130 int32_t SetISACMaxRate(int rateBps);
131 int32_t SetISACMaxPayloadSize(int sizeBytes);
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000133 // VoE dual-streaming.
134 int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);
135 void RemoveSecondarySendCodec();
136 int GetSecondarySendCodec(CodecInst* codec);
137
niklase@google.com470e71d2011-07-07 08:21:25 +0000138 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000139 int32_t RegisterExternalTransport(Transport& transport);
140 int32_t DeRegisterExternalTransport();
141 int32_t ReceivedRTPPacket(const int8_t* data, int32_t length);
142 int32_t ReceivedRTCPPacket(const int8_t* data, int32_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000143
niklase@google.com470e71d2011-07-07 08:21:25 +0000144 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000145 int StartPlayingFileLocally(const char* fileName, bool loop,
146 FileFormats format,
147 int startPosition,
148 float volumeScaling,
149 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000150 const CodecInst* codecInst);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000151 int StartPlayingFileLocally(InStream* stream, FileFormats format,
152 int startPosition,
153 float volumeScaling,
154 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000155 const CodecInst* codecInst);
156 int StopPlayingFileLocally();
157 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000158 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000159 int ScaleLocalFilePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000160 int GetLocalPlayoutPosition(int& positionMs);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000161 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
162 FileFormats format,
163 int startPosition,
164 float volumeScaling,
165 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000166 const CodecInst* codecInst);
167 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000168 FileFormats format,
169 int startPosition,
170 float volumeScaling,
171 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000172 const CodecInst* codecInst);
173 int StopPlayingFileAsMicrophone();
174 int IsPlayingFileAsMicrophone() const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000175 int ScaleFileAsMicrophonePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000176 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
177 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
178 int StopRecordingPlayout();
179
180 void SetMixWithMicStatus(bool mix);
181
182 // VoEExternalMediaProcessing
183 int RegisterExternalMediaProcessing(ProcessingTypes type,
184 VoEMediaProcess& processObject);
185 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000186 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000187
188 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000189 int GetSpeechOutputLevel(uint32_t& level) const;
190 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000191 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000192 bool Mute() const;
193 int SetOutputVolumePan(float left, float right);
194 int GetOutputVolumePan(float& left, float& right) const;
195 int SetChannelOutputVolumeScaling(float scaling);
196 int GetChannelOutputVolumeScaling(float& scaling) const;
197
198 // VoECallReport
199 void ResetDeadOrAliveCounters();
200 int ResetRTCPStatistics();
201 int GetRoundTripTimeSummary(StatVal& delaysMs) const;
202 int GetDeadOrAliveCounters(int& countDead, int& countAlive) const;
203
204 // VoENetEqStats
205 int GetNetworkStatistics(NetworkStatistics& stats);
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
221 // VoEEncryption
niklase@google.com470e71d2011-07-07 08:21:25 +0000222 int RegisterExternalEncryption(Encryption& encryption);
223 int DeRegisterExternalEncryption();
224
225 // VoEDtmf
226 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
227 int attenuationDb, bool playDtmfEvent);
228 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
229 int attenuationDb, bool playDtmfEvent);
230 int SetDtmfPlayoutStatus(bool enable);
231 bool DtmfPlayoutStatus() const;
232 int SetSendTelephoneEventPayloadType(unsigned char type);
233 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000234
235 // VoEAudioProcessingImpl
236 int UpdateRxVadDetection(AudioFrame& audioFrame);
237 int RegisterRxVadObserver(VoERxVadCallback &observer);
238 int DeRegisterRxVadObserver();
239 int VoiceActivityIndicator(int &activity);
240#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000241 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000242 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000243 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000244 int GetRxAgcConfig(AgcConfig& config);
245#endif
246#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000247 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000248 int GetRxNsStatus(bool& enabled, NsModes& mode);
249#endif
250
251 // VoERTP_RTCP
252 int RegisterRTPObserver(VoERTPObserver& observer);
253 int DeRegisterRTPObserver();
254 int RegisterRTCPObserver(VoERTCPObserver& observer);
255 int DeRegisterRTCPObserver();
256 int SetLocalSSRC(unsigned int ssrc);
257 int GetLocalSSRC(unsigned int& ssrc);
258 int GetRemoteSSRC(unsigned int& ssrc);
259 int GetRemoteCSRCs(unsigned int arrCSRC[15]);
260 int SetRTPAudioLevelIndicationStatus(bool enable, unsigned char ID);
261 int GetRTPAudioLevelIndicationStatus(bool& enable, unsigned char& ID);
262 int SetRTCPStatus(bool enable);
263 int GetRTCPStatus(bool& enabled);
264 int SetRTCP_CNAME(const char cName[256]);
265 int GetRTCP_CNAME(char cName[256]);
266 int GetRemoteRTCP_CNAME(char cName[256]);
267 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
268 unsigned int& timestamp,
269 unsigned int& playoutTimestamp, unsigned int* jitter,
270 unsigned short* fractionLost);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000271 int SendApplicationDefinedRTCPPacket(unsigned char subType,
niklase@google.com470e71d2011-07-07 08:21:25 +0000272 unsigned int name, const char* data,
273 unsigned short dataLengthInBytes);
274 int GetRTPStatistics(unsigned int& averageJitterMs,
275 unsigned int& maxJitterMs,
276 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000277 int GetRemoteRTCPSenderInfo(SenderInfo* sender_info);
278 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000279 int GetRTPStatistics(CallStatistics& stats);
280 int SetFECStatus(bool enable, int redPayloadtype);
281 int GetFECStatus(bool& enabled, int& redPayloadtype);
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000282 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000283 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
284 int StopRTPDump(RTPDirections direction);
285 bool RTPDumpIsActive(RTPDirections direction);
286 int InsertExtraRTPPacket(unsigned char payloadType, bool markerBit,
287 const char* payloadData,
288 unsigned short payloadSize);
roosa@google.com0870f022012-12-12 21:31:41 +0000289 uint32_t LastRemoteTimeStamp() { return _lastRemoteTimeStamp; }
niklase@google.com470e71d2011-07-07 08:21:25 +0000290
291public:
292 // From AudioPacketizationCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000293 int32_t SendData(FrameType frameType,
294 uint8_t payloadType,
295 uint32_t timeStamp,
296 const uint8_t* payloadData,
297 uint16_t payloadSize,
298 const RTPFragmentationHeader* fragmentation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000299 // From ACMVADCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000300 int32_t InFrameType(int16_t frameType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000301
niklase@google.com470e71d2011-07-07 08:21:25 +0000302public:
pbos@webrtc.org92135212013-05-14 08:31:39 +0000303 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000304
305public:
306 // From RtpData in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000307 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000308 uint16_t payloadSize,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000309 const WebRtcRTPHeader* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +0000310
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000311 bool OnRecoveredPacket(const uint8_t* packet, int packet_length);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000312
niklase@google.com470e71d2011-07-07 08:21:25 +0000313public:
314 // From RtpFeedback in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000315 int32_t OnInitializeDecoder(
pbos@webrtc.org92135212013-05-14 08:31:39 +0000316 int32_t id,
317 int8_t payloadType,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000318 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org92135212013-05-14 08:31:39 +0000319 int frequency,
320 uint8_t channels,
321 uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000322
pbos@webrtc.org92135212013-05-14 08:31:39 +0000323 void OnPacketTimeout(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000324
pbos@webrtc.org92135212013-05-14 08:31:39 +0000325 void OnReceivedPacket(int32_t id, RtpRtcpPacketType packetType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000326
pbos@webrtc.org92135212013-05-14 08:31:39 +0000327 void OnPeriodicDeadOrAlive(int32_t id,
328 RTPAliveType alive);
niklase@google.com470e71d2011-07-07 08:21:25 +0000329
pbos@webrtc.org92135212013-05-14 08:31:39 +0000330 void OnIncomingSSRCChanged(int32_t id,
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000331 uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000332
pbos@webrtc.org92135212013-05-14 08:31:39 +0000333 void OnIncomingCSRCChanged(int32_t id,
334 uint32_t CSRC, bool added);
niklase@google.com470e71d2011-07-07 08:21:25 +0000335
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000336 void ResetStatistics(uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000337
niklase@google.com470e71d2011-07-07 08:21:25 +0000338public:
339 // From RtcpFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000340 void OnApplicationDataReceived(int32_t id,
341 uint8_t subType,
342 uint32_t name,
343 uint16_t length,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000344 const uint8_t* data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000345
niklase@google.com470e71d2011-07-07 08:21:25 +0000346public:
347 // From RtpAudioFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000348 void OnReceivedTelephoneEvent(int32_t id,
349 uint8_t event,
350 bool endOfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000351
pbos@webrtc.org92135212013-05-14 08:31:39 +0000352 void OnPlayTelephoneEvent(int32_t id,
353 uint8_t event,
354 uint16_t lengthMs,
355 uint8_t volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000356
357public:
niklase@google.com470e71d2011-07-07 08:21:25 +0000358 // From Transport (called by the RTP/RTCP module)
359 int SendPacket(int /*channel*/, const void *data, int len);
360 int SendRTCPPacket(int /*channel*/, const void *data, int len);
361
362public:
363 // From MixerParticipant
pbos@webrtc.org92135212013-05-14 08:31:39 +0000364 int32_t GetAudioFrame(int32_t id, AudioFrame& audioFrame);
365 int32_t NeededFrequency(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000366
367public:
368 // From MonitorObserver
369 void OnPeriodicProcess();
370
371public:
372 // From FileCallback
pbos@webrtc.org92135212013-05-14 08:31:39 +0000373 void PlayNotification(int32_t id,
374 uint32_t durationMs);
375 void RecordNotification(int32_t id,
376 uint32_t durationMs);
377 void PlayFileEnded(int32_t id);
378 void RecordFileEnded(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000379
380public:
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000381 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000382 {
383 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000384 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000385 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000386 {
387 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000388 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000389 bool Playing() const
390 {
391 return _playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000392 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000393 bool Sending() const
394 {
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000395 // A lock is needed because |_sending| is accessed by both
396 // TransmitMixer::PrepareDemux() and StartSend()/StopSend(), which
397 // are called by different threads.
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +0000398 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000399 return _sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000400 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000401 bool Receiving() const
402 {
403 return _receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000404 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000405 bool ExternalTransport() const
406 {
407 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000408 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000409 bool ExternalMixing() const
410 {
411 return _externalMixing;
412 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000413 bool OutputIsOnHold() const
414 {
415 return _outputIsOnHold;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000416 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000417 bool InputIsOnHold() const
418 {
419 return _inputIsOnHold;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000420 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000421 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000422 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000423 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000424 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000425 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000426 {
427 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000428 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000429 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000430 // Demultiplex the data to the channel's |_audioFrame|. The difference
431 // between this method and the overloaded method above is that |audio_data|
432 // does not go through transmit_mixer and APM.
433 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000434 int sample_rate,
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000435 int number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000436 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000437 uint32_t PrepareEncodeAndSend(int mixingFrequency);
438 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000439
440private:
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000441 bool ReceivePacket(const uint8_t* packet, int packet_length,
442 const RTPHeader& header, bool in_order);
443 bool HandleEncapsulation(const uint8_t* packet,
444 int packet_length,
445 const RTPHeader& header);
446 bool IsPacketInOrder(const RTPHeader& header) const;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000447 bool IsPacketRetransmitted(const RTPHeader& header) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000448 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000449 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000450 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
451 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000452 void UpdateDeadOrAliveCounters(bool alive);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000453 int32_t SendPacketRaw(const void *data, int len, bool RTCP);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000454 void UpdatePacketDelay(uint32_t timestamp,
455 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000456 void RegisterReceiveCodecsToRTPModule();
457 int ApmProcessRx(AudioFrame& audioFrame);
458
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000459 int SetRedPayloadType(int red_payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000460private:
461 CriticalSectionWrapper& _fileCritSect;
462 CriticalSectionWrapper& _callbackCritSect;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000463 uint32_t _instanceId;
464 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000465
466private:
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000467 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000468 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
469 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
470 scoped_ptr<RtpReceiver> rtp_receiver_;
471 TelephoneEventHandler* telephone_event_handler_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000472 scoped_ptr<RtpRtcp> _rtpRtcpModule;
niklase@google.com470e71d2011-07-07 08:21:25 +0000473 AudioCodingModule& _audioCodingModule;
niklase@google.com470e71d2011-07-07 08:21:25 +0000474 RtpDump& _rtpDumpIn;
475 RtpDump& _rtpDumpOut;
476private:
477 AudioLevel _outputAudioLevel;
478 bool _externalTransport;
479 AudioFrame _audioFrame;
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000480 scoped_array<int16_t> mono_recording_audio_;
481 // Resampler is used when input data is stereo while codec is mono.
482 PushResampler input_resampler_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000483 uint8_t _audioLevel_dBov;
niklase@google.com470e71d2011-07-07 08:21:25 +0000484 FilePlayer* _inputFilePlayerPtr;
485 FilePlayer* _outputFilePlayerPtr;
486 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000487 int _inputFilePlayerId;
488 int _outputFilePlayerId;
489 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000490 bool _inputFilePlaying;
491 bool _outputFilePlaying;
492 bool _outputFileRecording;
493 DtmfInbandQueue _inbandDtmfQueue;
494 DtmfInband _inbandDtmfGenerator;
niklase@google.com470e71d2011-07-07 08:21:25 +0000495 bool _inputExternalMedia;
xians@google.com22963ab2011-08-03 12:40:23 +0000496 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000497 VoEMediaProcess* _inputExternalMediaCallbackPtr;
498 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000499 uint8_t* _encryptionRTPBufferPtr;
500 uint8_t* _decryptionRTPBufferPtr;
501 uint8_t* _encryptionRTCPBufferPtr;
502 uint8_t* _decryptionRTCPBufferPtr;
503 uint32_t _timeStamp;
504 uint8_t _sendTelephoneEventPayloadType;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000505 uint32_t playout_timestamp_rtp_;
506 uint32_t playout_timestamp_rtcp_;
507 uint32_t playout_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000508 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000509 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000510 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000511
512 private:
niklase@google.com470e71d2011-07-07 08:21:25 +0000513 // uses
514 Statistics* _engineStatisticsPtr;
515 OutputMixer* _outputMixerPtr;
516 TransmitMixer* _transmitMixerPtr;
517 ProcessThread* _moduleProcessThreadPtr;
518 AudioDeviceModule* _audioDeviceModulePtr;
519 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
520 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
521 Transport* _transportPtr; // WebRtc socket or external transport
522 Encryption* _encryptionPtr; // WebRtc SRTP or external encryption
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000523 scoped_ptr<AudioProcessing> _rtpAudioProc;
niklase@google.com470e71d2011-07-07 08:21:25 +0000524 AudioProcessing* _rxAudioProcessingModulePtr; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000525 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000526 int32_t _oldVadDecision;
527 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000528 VoERTPObserver* _rtpObserverPtr;
529 VoERTCPObserver* _rtcpObserverPtr;
530private:
531 // VoEBase
532 bool _outputIsOnHold;
533 bool _externalPlayout;
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000534 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000535 bool _inputIsOnHold;
536 bool _playing;
537 bool _sending;
538 bool _receiving;
539 bool _mixFileWithMicrophone;
540 bool _rtpObserver;
541 bool _rtcpObserver;
542 // VoEVolumeControl
543 bool _mute;
544 float _panLeft;
545 float _panRight;
546 float _outputGain;
547 // VoEEncryption
548 bool _encrypting;
549 bool _decrypting;
550 // VoEDtmf
551 bool _playOutbandDtmfEvent;
552 bool _playInbandDtmfEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000553 // VoeRTP_RTCP
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000554 uint8_t _extraPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000555 bool _insertExtraRTPPacket;
556 bool _extraMarkerBit;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000557 uint32_t _lastLocalTimeStamp;
roosa@google.com0870f022012-12-12 21:31:41 +0000558 uint32_t _lastRemoteTimeStamp;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000559 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000560 bool _includeAudioLevelIndication;
561 // VoENetwork
562 bool _rtpPacketTimedOut;
563 bool _rtpPacketTimeOutIsEnabled;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000564 uint32_t _rtpTimeOutSeconds;
niklase@google.com470e71d2011-07-07 08:21:25 +0000565 bool _connectionObserver;
566 VoEConnectionObserver* _connectionObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000567 uint32_t _countAliveDetections;
568 uint32_t _countDeadDetections;
niklase@google.com470e71d2011-07-07 08:21:25 +0000569 AudioFrame::SpeechType _outputSpeechType;
570 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000571 uint32_t _average_jitter_buffer_delay_us;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000572 int least_required_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000573 uint32_t _previousTimestamp;
574 uint16_t _recPacketDelayMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000575 // VoEAudioProcessing
576 bool _RxVadDetection;
577 bool _rxApmIsEnabled;
578 bool _rxAgcIsEnabled;
579 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000580 bool restored_packet_in_use_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000581};
582
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000583} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +0000584
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000585} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000586
587#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H