blob: f3bc096622078f8b5fd11e2f353839d8e714b842 [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
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000066// Helper class to simplify locking scheme for members that are accessed from
67// multiple threads.
68// Example: a member can be set on thread T1 and read by an internal audio
69// thread T2. Accessing the member via this class ensures that we are
70// safe and also avoid TSan v2 warnings.
71class ChannelState {
72 public:
73 struct State {
74 State() : rx_apm_is_enabled(false),
75 input_external_media(false),
76 output_is_on_hold(false),
77 output_file_playing(false),
78 input_file_playing(false),
79 playing(false),
80 sending(false),
81 receiving(false) {}
82
83 bool rx_apm_is_enabled;
84 bool input_external_media;
85 bool output_is_on_hold;
86 bool output_file_playing;
87 bool input_file_playing;
88 bool playing;
89 bool sending;
90 bool receiving;
91 };
92
93 ChannelState() : lock_(CriticalSectionWrapper::CreateCriticalSection()) {
94 }
95 virtual ~ChannelState() {}
96
97 void Reset() {
98 CriticalSectionScoped lock(lock_.get());
99 state_ = State();
100 }
101
102 State Get() const {
103 CriticalSectionScoped lock(lock_.get());
104 return state_;
105 }
106
107 void SetRxApmIsEnabled(bool enable) {
108 CriticalSectionScoped lock(lock_.get());
109 state_.rx_apm_is_enabled = enable;
110 }
111
112 void SetInputExternalMedia(bool enable) {
113 CriticalSectionScoped lock(lock_.get());
114 state_.input_external_media = enable;
115 }
116
117 void SetOutputIsOnHold(bool enable) {
118 CriticalSectionScoped lock(lock_.get());
119 state_.output_is_on_hold = enable;
120 }
121
122 void SetOutputFilePlaying(bool enable) {
123 CriticalSectionScoped lock(lock_.get());
124 state_.output_file_playing = enable;
125 }
126
127 void SetInputFilePlaying(bool enable) {
128 CriticalSectionScoped lock(lock_.get());
129 state_.input_file_playing = enable;
130 }
131
132 void SetPlaying(bool enable) {
133 CriticalSectionScoped lock(lock_.get());
134 state_.playing = enable;
135 }
136
137 void SetSending(bool enable) {
138 CriticalSectionScoped lock(lock_.get());
139 state_.sending = enable;
140 }
141
142 void SetReceiving(bool enable) {
143 CriticalSectionScoped lock(lock_.get());
144 state_.receiving = enable;
145 }
146
147private:
148 scoped_ptr<CriticalSectionWrapper> lock_;
149 State state_;
150};
niklase@google.com470e71d2011-07-07 08:21:25 +0000151
152class Channel:
153 public RtpData,
154 public RtpFeedback,
155 public RtcpFeedback,
niklase@google.com470e71d2011-07-07 08:21:25 +0000156 public FileCallback, // receiving notification from file player & recorder
157 public Transport,
158 public RtpAudioFeedback,
159 public AudioPacketizationCallback, // receive encoded packets from the ACM
160 public ACMVADCallback, // receive voice activity from the ACM
niklase@google.com470e71d2011-07-07 08:21:25 +0000161 public MixerParticipant // supplies output mixer with audio frames
162{
163public:
164 enum {KNumSocketThreads = 1};
165 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +0000166 virtual ~Channel();
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000167 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000168 int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000169 uint32_t instanceId,
170 const Config& config);
171 Channel(int32_t channelId, uint32_t instanceId, const Config& config);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000172 int32_t Init();
173 int32_t SetEngineInformation(
niklase@google.com470e71d2011-07-07 08:21:25 +0000174 Statistics& engineStatistics,
175 OutputMixer& outputMixer,
176 TransmitMixer& transmitMixer,
177 ProcessThread& moduleProcessThread,
178 AudioDeviceModule& audioDeviceModule,
179 VoiceEngineObserver* voiceEngineObserver,
180 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000181 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000182
niklase@google.com470e71d2011-07-07 08:21:25 +0000183 // API methods
184
185 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000186 int32_t StartPlayout();
187 int32_t StopPlayout();
188 int32_t StartSend();
189 int32_t StopSend();
190 int32_t StartReceiving();
191 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000192
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000193 int32_t SetNetEQPlayoutMode(NetEqModes mode);
194 int32_t GetNetEQPlayoutMode(NetEqModes& mode);
195 int32_t SetOnHoldStatus(bool enable, OnHoldModes mode);
196 int32_t GetOnHoldStatus(bool& enabled, OnHoldModes& mode);
197 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
198 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000199
200 // VoECodec
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000201 int32_t GetSendCodec(CodecInst& codec);
202 int32_t GetRecCodec(CodecInst& codec);
203 int32_t SetSendCodec(const CodecInst& codec);
204 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
205 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
206 int32_t SetRecPayloadType(const CodecInst& codec);
207 int32_t GetRecPayloadType(CodecInst& codec);
208 int32_t SetAMREncFormat(AmrMode mode);
209 int32_t SetAMRDecFormat(AmrMode mode);
210 int32_t SetAMRWbEncFormat(AmrMode mode);
211 int32_t SetAMRWbDecFormat(AmrMode mode);
212 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
213 int32_t SetISACInitTargetRate(int rateBps, bool useFixedFrameSize);
214 int32_t SetISACMaxRate(int rateBps);
215 int32_t SetISACMaxPayloadSize(int sizeBytes);
niklase@google.com470e71d2011-07-07 08:21:25 +0000216
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000217 // VoE dual-streaming.
218 int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);
219 void RemoveSecondarySendCodec();
220 int GetSecondarySendCodec(CodecInst* codec);
221
niklase@google.com470e71d2011-07-07 08:21:25 +0000222 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000223 int32_t RegisterExternalTransport(Transport& transport);
224 int32_t DeRegisterExternalTransport();
225 int32_t ReceivedRTPPacket(const int8_t* data, int32_t length);
226 int32_t ReceivedRTCPPacket(const int8_t* data, int32_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000227
niklase@google.com470e71d2011-07-07 08:21:25 +0000228 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000229 int StartPlayingFileLocally(const char* fileName, bool loop,
230 FileFormats format,
231 int startPosition,
232 float volumeScaling,
233 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000234 const CodecInst* codecInst);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000235 int StartPlayingFileLocally(InStream* stream, FileFormats format,
236 int startPosition,
237 float volumeScaling,
238 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000239 const CodecInst* codecInst);
240 int StopPlayingFileLocally();
241 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000242 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000243 int ScaleLocalFilePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000244 int GetLocalPlayoutPosition(int& positionMs);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000245 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
246 FileFormats format,
247 int startPosition,
248 float volumeScaling,
249 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000250 const CodecInst* codecInst);
251 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000252 FileFormats format,
253 int startPosition,
254 float volumeScaling,
255 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000256 const CodecInst* codecInst);
257 int StopPlayingFileAsMicrophone();
258 int IsPlayingFileAsMicrophone() const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000259 int ScaleFileAsMicrophonePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000260 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
261 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
262 int StopRecordingPlayout();
263
264 void SetMixWithMicStatus(bool mix);
265
266 // VoEExternalMediaProcessing
267 int RegisterExternalMediaProcessing(ProcessingTypes type,
268 VoEMediaProcess& processObject);
269 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000270 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000271
272 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000273 int GetSpeechOutputLevel(uint32_t& level) const;
274 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000275 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000276 bool Mute() const;
277 int SetOutputVolumePan(float left, float right);
278 int GetOutputVolumePan(float& left, float& right) const;
279 int SetChannelOutputVolumeScaling(float scaling);
280 int GetChannelOutputVolumeScaling(float& scaling) const;
281
282 // VoECallReport
283 void ResetDeadOrAliveCounters();
284 int ResetRTCPStatistics();
285 int GetRoundTripTimeSummary(StatVal& delaysMs) const;
286 int GetDeadOrAliveCounters(int& countDead, int& countAlive) const;
287
288 // VoENetEqStats
289 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000290 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000291
292 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000293 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
294 int* playout_buffer_delay_ms) const;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000295 int least_required_delay_ms() const { return least_required_delay_ms_; }
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000296 int SetInitialPlayoutDelay(int delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000297 int SetMinimumPlayoutDelay(int delayMs);
298 int GetPlayoutTimestamp(unsigned int& timestamp);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000299 void UpdatePlayoutTimestamp(bool rtcp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000300 int SetInitTimestamp(unsigned int timestamp);
301 int SetInitSequenceNumber(short sequenceNumber);
302
303 // VoEVideoSyncExtended
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000304 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000305
niklase@google.com470e71d2011-07-07 08:21:25 +0000306 // VoEDtmf
307 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
308 int attenuationDb, bool playDtmfEvent);
309 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
310 int attenuationDb, bool playDtmfEvent);
311 int SetDtmfPlayoutStatus(bool enable);
312 bool DtmfPlayoutStatus() const;
313 int SetSendTelephoneEventPayloadType(unsigned char type);
314 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000315
316 // VoEAudioProcessingImpl
317 int UpdateRxVadDetection(AudioFrame& audioFrame);
318 int RegisterRxVadObserver(VoERxVadCallback &observer);
319 int DeRegisterRxVadObserver();
320 int VoiceActivityIndicator(int &activity);
321#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000322 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000323 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000324 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000325 int GetRxAgcConfig(AgcConfig& config);
326#endif
327#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000328 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000329 int GetRxNsStatus(bool& enabled, NsModes& mode);
330#endif
331
332 // VoERTP_RTCP
333 int RegisterRTPObserver(VoERTPObserver& observer);
334 int DeRegisterRTPObserver();
335 int RegisterRTCPObserver(VoERTCPObserver& observer);
336 int DeRegisterRTCPObserver();
337 int SetLocalSSRC(unsigned int ssrc);
338 int GetLocalSSRC(unsigned int& ssrc);
339 int GetRemoteSSRC(unsigned int& ssrc);
340 int GetRemoteCSRCs(unsigned int arrCSRC[15]);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000341 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
342 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
343 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000344 int SetRTCPStatus(bool enable);
345 int GetRTCPStatus(bool& enabled);
346 int SetRTCP_CNAME(const char cName[256]);
347 int GetRTCP_CNAME(char cName[256]);
348 int GetRemoteRTCP_CNAME(char cName[256]);
349 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
350 unsigned int& timestamp,
351 unsigned int& playoutTimestamp, unsigned int* jitter,
352 unsigned short* fractionLost);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000353 int SendApplicationDefinedRTCPPacket(unsigned char subType,
niklase@google.com470e71d2011-07-07 08:21:25 +0000354 unsigned int name, const char* data,
355 unsigned short dataLengthInBytes);
356 int GetRTPStatistics(unsigned int& averageJitterMs,
357 unsigned int& maxJitterMs,
358 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000359 int GetRemoteRTCPSenderInfo(SenderInfo* sender_info);
360 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000361 int GetRTPStatistics(CallStatistics& stats);
362 int SetFECStatus(bool enable, int redPayloadtype);
363 int GetFECStatus(bool& enabled, int& redPayloadtype);
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000364 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000365 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
366 int StopRTPDump(RTPDirections direction);
367 bool RTPDumpIsActive(RTPDirections direction);
roosa@google.com0870f022012-12-12 21:31:41 +0000368 uint32_t LastRemoteTimeStamp() { return _lastRemoteTimeStamp; }
niklase@google.com470e71d2011-07-07 08:21:25 +0000369
niklase@google.com470e71d2011-07-07 08:21:25 +0000370 // From AudioPacketizationCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000371 int32_t SendData(FrameType frameType,
372 uint8_t payloadType,
373 uint32_t timeStamp,
374 const uint8_t* payloadData,
375 uint16_t payloadSize,
376 const RTPFragmentationHeader* fragmentation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000377 // From ACMVADCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000378 int32_t InFrameType(int16_t frameType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000379
pbos@webrtc.org92135212013-05-14 08:31:39 +0000380 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000381
niklase@google.com470e71d2011-07-07 08:21:25 +0000382 // From RtpData in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000383 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000384 uint16_t payloadSize,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000385 const WebRtcRTPHeader* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +0000386
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000387 bool OnRecoveredPacket(const uint8_t* packet, int packet_length);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000388
niklase@google.com470e71d2011-07-07 08:21:25 +0000389 // From RtpFeedback in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000390 int32_t OnInitializeDecoder(
pbos@webrtc.org92135212013-05-14 08:31:39 +0000391 int32_t id,
392 int8_t payloadType,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000393 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org92135212013-05-14 08:31:39 +0000394 int frequency,
395 uint8_t channels,
396 uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000397
pbos@webrtc.org92135212013-05-14 08:31:39 +0000398 void OnPacketTimeout(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000399
pbos@webrtc.org92135212013-05-14 08:31:39 +0000400 void OnReceivedPacket(int32_t id, RtpRtcpPacketType packetType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000401
pbos@webrtc.org92135212013-05-14 08:31:39 +0000402 void OnPeriodicDeadOrAlive(int32_t id,
403 RTPAliveType alive);
niklase@google.com470e71d2011-07-07 08:21:25 +0000404
pbos@webrtc.org92135212013-05-14 08:31:39 +0000405 void OnIncomingSSRCChanged(int32_t id,
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000406 uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000407
pbos@webrtc.org92135212013-05-14 08:31:39 +0000408 void OnIncomingCSRCChanged(int32_t id,
409 uint32_t CSRC, bool added);
niklase@google.com470e71d2011-07-07 08:21:25 +0000410
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000411 void ResetStatistics(uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000412
niklase@google.com470e71d2011-07-07 08:21:25 +0000413 // From RtcpFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000414 void OnApplicationDataReceived(int32_t id,
415 uint8_t subType,
416 uint32_t name,
417 uint16_t length,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000418 const uint8_t* data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000419
niklase@google.com470e71d2011-07-07 08:21:25 +0000420 // From RtpAudioFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000421 void OnReceivedTelephoneEvent(int32_t id,
422 uint8_t event,
423 bool endOfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000424
pbos@webrtc.org92135212013-05-14 08:31:39 +0000425 void OnPlayTelephoneEvent(int32_t id,
426 uint8_t event,
427 uint16_t lengthMs,
428 uint8_t volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000429
niklase@google.com470e71d2011-07-07 08:21:25 +0000430 // From Transport (called by the RTP/RTCP module)
431 int SendPacket(int /*channel*/, const void *data, int len);
432 int SendRTCPPacket(int /*channel*/, const void *data, int len);
433
niklase@google.com470e71d2011-07-07 08:21:25 +0000434 // From MixerParticipant
pbos@webrtc.org92135212013-05-14 08:31:39 +0000435 int32_t GetAudioFrame(int32_t id, AudioFrame& audioFrame);
436 int32_t NeededFrequency(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000437
niklase@google.com470e71d2011-07-07 08:21:25 +0000438 // From MonitorObserver
439 void OnPeriodicProcess();
440
niklase@google.com470e71d2011-07-07 08:21:25 +0000441 // From FileCallback
pbos@webrtc.org92135212013-05-14 08:31:39 +0000442 void PlayNotification(int32_t id,
443 uint32_t durationMs);
444 void RecordNotification(int32_t id,
445 uint32_t durationMs);
446 void PlayFileEnded(int32_t id);
447 void RecordFileEnded(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000448
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000449 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000450 {
451 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000452 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000453 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000454 {
455 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000456 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000457 bool Playing() const
458 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000459 return channel_state_.Get().playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000460 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000461 bool Sending() const
462 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000463 return channel_state_.Get().sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000464 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000465 bool Receiving() const
466 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000467 return channel_state_.Get().receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000468 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000469 bool ExternalTransport() const
470 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000471 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000472 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000473 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000474 bool ExternalMixing() const
475 {
476 return _externalMixing;
477 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000478 bool InputIsOnHold() const
479 {
480 return _inputIsOnHold;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000481 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000482 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000483 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000484 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000485 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000486 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000487 {
488 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000489 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000490 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000491 // Demultiplex the data to the channel's |_audioFrame|. The difference
492 // between this method and the overloaded method above is that |audio_data|
493 // does not go through transmit_mixer and APM.
494 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000495 int sample_rate,
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000496 int number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000497 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000498 uint32_t PrepareEncodeAndSend(int mixingFrequency);
499 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000500
501private:
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000502 bool ReceivePacket(const uint8_t* packet, int packet_length,
503 const RTPHeader& header, bool in_order);
504 bool HandleEncapsulation(const uint8_t* packet,
505 int packet_length,
506 const RTPHeader& header);
507 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000508 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000509 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000510 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000511 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
512 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000513 void UpdateDeadOrAliveCounters(bool alive);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000514 int32_t SendPacketRaw(const void *data, int len, bool RTCP);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000515 void UpdatePacketDelay(uint32_t timestamp,
516 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000517 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000518
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000519 int SetRedPayloadType(int red_payload_type);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000520 int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type,
521 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000522
niklase@google.com470e71d2011-07-07 08:21:25 +0000523 CriticalSectionWrapper& _fileCritSect;
524 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.org63420662013-10-17 18:28:55 +0000525 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000526 uint32_t _instanceId;
527 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000528
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000529 ChannelState channel_state_;
530
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000531 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000532 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
533 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +0000534 scoped_ptr<StatisticsProxy> statistics_proxy_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000535 scoped_ptr<RtpReceiver> rtp_receiver_;
536 TelephoneEventHandler* telephone_event_handler_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000537 scoped_ptr<RtpRtcp> _rtpRtcpModule;
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000538 scoped_ptr<AudioCodingModule> audio_coding_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000539 RtpDump& _rtpDumpIn;
540 RtpDump& _rtpDumpOut;
niklase@google.com470e71d2011-07-07 08:21:25 +0000541 AudioLevel _outputAudioLevel;
542 bool _externalTransport;
543 AudioFrame _audioFrame;
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000544 scoped_array<int16_t> mono_recording_audio_;
545 // Resampler is used when input data is stereo while codec is mono.
546 PushResampler input_resampler_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000547 uint8_t _audioLevel_dBov;
niklase@google.com470e71d2011-07-07 08:21:25 +0000548 FilePlayer* _inputFilePlayerPtr;
549 FilePlayer* _outputFilePlayerPtr;
550 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000551 int _inputFilePlayerId;
552 int _outputFilePlayerId;
553 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000554 bool _outputFileRecording;
555 DtmfInbandQueue _inbandDtmfQueue;
556 DtmfInband _inbandDtmfGenerator;
xians@google.com22963ab2011-08-03 12:40:23 +0000557 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000558 VoEMediaProcess* _inputExternalMediaCallbackPtr;
559 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000560 uint32_t _timeStamp;
561 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000562
563 // Timestamp of the audio pulled from NetEq.
564 uint32_t jitter_buffer_playout_timestamp_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000565 uint32_t playout_timestamp_rtp_;
566 uint32_t playout_timestamp_rtcp_;
567 uint32_t playout_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000568 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000569 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000570 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000571
niklase@google.com470e71d2011-07-07 08:21:25 +0000572 // uses
573 Statistics* _engineStatisticsPtr;
574 OutputMixer* _outputMixerPtr;
575 TransmitMixer* _transmitMixerPtr;
576 ProcessThread* _moduleProcessThreadPtr;
577 AudioDeviceModule* _audioDeviceModulePtr;
578 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
579 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
580 Transport* _transportPtr; // WebRtc socket or external transport
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +0000581 scoped_ptr<AudioProcessing> rtp_audioproc_;
582 scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000583 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000584 int32_t _oldVadDecision;
585 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000586 VoERTPObserver* _rtpObserverPtr;
587 VoERTCPObserver* _rtcpObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000588 // VoEBase
niklase@google.com470e71d2011-07-07 08:21:25 +0000589 bool _externalPlayout;
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000590 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000591 bool _inputIsOnHold;
niklase@google.com470e71d2011-07-07 08:21:25 +0000592 bool _mixFileWithMicrophone;
593 bool _rtpObserver;
594 bool _rtcpObserver;
595 // VoEVolumeControl
596 bool _mute;
597 float _panLeft;
598 float _panRight;
599 float _outputGain;
niklase@google.com470e71d2011-07-07 08:21:25 +0000600 // VoEDtmf
601 bool _playOutbandDtmfEvent;
602 bool _playInbandDtmfEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000603 // VoeRTP_RTCP
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000604 uint32_t _lastLocalTimeStamp;
roosa@google.com0870f022012-12-12 21:31:41 +0000605 uint32_t _lastRemoteTimeStamp;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000606 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000607 bool _includeAudioLevelIndication;
608 // VoENetwork
609 bool _rtpPacketTimedOut;
610 bool _rtpPacketTimeOutIsEnabled;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000611 uint32_t _rtpTimeOutSeconds;
niklase@google.com470e71d2011-07-07 08:21:25 +0000612 bool _connectionObserver;
613 VoEConnectionObserver* _connectionObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000614 uint32_t _countAliveDetections;
615 uint32_t _countDeadDetections;
niklase@google.com470e71d2011-07-07 08:21:25 +0000616 AudioFrame::SpeechType _outputSpeechType;
617 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000618 uint32_t _average_jitter_buffer_delay_us;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000619 int least_required_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000620 uint32_t _previousTimestamp;
621 uint16_t _recPacketDelayMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000622 // VoEAudioProcessing
623 bool _RxVadDetection;
niklase@google.com470e71d2011-07-07 08:21:25 +0000624 bool _rxAgcIsEnabled;
625 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000626 bool restored_packet_in_use_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000627};
628
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000629} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000630} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000631
632#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H