blob: 8166f1c27558401dac13c117cb957a8fb1642409 [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;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +000050class ViENetwork;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000051class VoEMediaProcess;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000052class VoERTCPObserver;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000053class VoERTPObserver;
54class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
56struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000057struct ReportBlock;
58struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000059
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000060namespace voe {
61
niklase@google.com470e71d2011-07-07 08:21:25 +000062class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000063class StatisticsProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000064class TransmitMixer;
65class OutputMixer;
66
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000067// Helper class to simplify locking scheme for members that are accessed from
68// multiple threads.
69// Example: a member can be set on thread T1 and read by an internal audio
70// thread T2. Accessing the member via this class ensures that we are
71// safe and also avoid TSan v2 warnings.
72class ChannelState {
73 public:
74 struct State {
75 State() : rx_apm_is_enabled(false),
76 input_external_media(false),
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000077 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;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000085 bool output_file_playing;
86 bool input_file_playing;
87 bool playing;
88 bool sending;
89 bool receiving;
90 };
91
92 ChannelState() : lock_(CriticalSectionWrapper::CreateCriticalSection()) {
93 }
94 virtual ~ChannelState() {}
95
96 void Reset() {
97 CriticalSectionScoped lock(lock_.get());
98 state_ = State();
99 }
100
101 State Get() const {
102 CriticalSectionScoped lock(lock_.get());
103 return state_;
104 }
105
106 void SetRxApmIsEnabled(bool enable) {
107 CriticalSectionScoped lock(lock_.get());
108 state_.rx_apm_is_enabled = enable;
109 }
110
111 void SetInputExternalMedia(bool enable) {
112 CriticalSectionScoped lock(lock_.get());
113 state_.input_external_media = enable;
114 }
115
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000116 void SetOutputFilePlaying(bool enable) {
117 CriticalSectionScoped lock(lock_.get());
118 state_.output_file_playing = enable;
119 }
120
121 void SetInputFilePlaying(bool enable) {
122 CriticalSectionScoped lock(lock_.get());
123 state_.input_file_playing = enable;
124 }
125
126 void SetPlaying(bool enable) {
127 CriticalSectionScoped lock(lock_.get());
128 state_.playing = enable;
129 }
130
131 void SetSending(bool enable) {
132 CriticalSectionScoped lock(lock_.get());
133 state_.sending = enable;
134 }
135
136 void SetReceiving(bool enable) {
137 CriticalSectionScoped lock(lock_.get());
138 state_.receiving = enable;
139 }
140
141private:
142 scoped_ptr<CriticalSectionWrapper> lock_;
143 State state_;
144};
niklase@google.com470e71d2011-07-07 08:21:25 +0000145
146class Channel:
147 public RtpData,
148 public RtpFeedback,
149 public RtcpFeedback,
niklase@google.com470e71d2011-07-07 08:21:25 +0000150 public FileCallback, // receiving notification from file player & recorder
151 public Transport,
152 public RtpAudioFeedback,
153 public AudioPacketizationCallback, // receive encoded packets from the ACM
154 public ACMVADCallback, // receive voice activity from the ACM
niklase@google.com470e71d2011-07-07 08:21:25 +0000155 public MixerParticipant // supplies output mixer with audio frames
156{
157public:
158 enum {KNumSocketThreads = 1};
159 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +0000160 virtual ~Channel();
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000161 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000162 int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000163 uint32_t instanceId,
164 const Config& config);
165 Channel(int32_t channelId, uint32_t instanceId, const Config& config);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000166 int32_t Init();
167 int32_t SetEngineInformation(
niklase@google.com470e71d2011-07-07 08:21:25 +0000168 Statistics& engineStatistics,
169 OutputMixer& outputMixer,
170 TransmitMixer& transmitMixer,
171 ProcessThread& moduleProcessThread,
172 AudioDeviceModule& audioDeviceModule,
173 VoiceEngineObserver* voiceEngineObserver,
174 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000175 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000176
niklase@google.com470e71d2011-07-07 08:21:25 +0000177 // API methods
178
179 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000180 int32_t StartPlayout();
181 int32_t StopPlayout();
182 int32_t StartSend();
183 int32_t StopSend();
184 int32_t StartReceiving();
185 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000186
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000187 int32_t SetNetEQPlayoutMode(NetEqModes mode);
188 int32_t GetNetEQPlayoutMode(NetEqModes& mode);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000189 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
190 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000191
192 // VoECodec
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000193 int32_t GetSendCodec(CodecInst& codec);
194 int32_t GetRecCodec(CodecInst& codec);
195 int32_t SetSendCodec(const CodecInst& codec);
196 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
197 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
198 int32_t SetRecPayloadType(const CodecInst& codec);
199 int32_t GetRecPayloadType(CodecInst& codec);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000200 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000202 // VoE dual-streaming.
203 int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);
204 void RemoveSecondarySendCodec();
205 int GetSecondarySendCodec(CodecInst* codec);
206
niklase@google.com470e71d2011-07-07 08:21:25 +0000207 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000208 int32_t RegisterExternalTransport(Transport& transport);
209 int32_t DeRegisterExternalTransport();
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000210 int32_t ReceivedRTPPacket(const int8_t* data, int32_t length,
211 const PacketTime& packet_time);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000212 int32_t ReceivedRTCPPacket(const int8_t* data, int32_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000213
niklase@google.com470e71d2011-07-07 08:21:25 +0000214 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000215 int StartPlayingFileLocally(const char* fileName, bool loop,
216 FileFormats format,
217 int startPosition,
218 float volumeScaling,
219 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000220 const CodecInst* codecInst);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000221 int StartPlayingFileLocally(InStream* stream, FileFormats format,
222 int startPosition,
223 float volumeScaling,
224 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000225 const CodecInst* codecInst);
226 int StopPlayingFileLocally();
227 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000228 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000229 int ScaleLocalFilePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000230 int GetLocalPlayoutPosition(int& positionMs);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000231 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
232 FileFormats format,
233 int startPosition,
234 float volumeScaling,
235 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000236 const CodecInst* codecInst);
237 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000238 FileFormats format,
239 int startPosition,
240 float volumeScaling,
241 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000242 const CodecInst* codecInst);
243 int StopPlayingFileAsMicrophone();
244 int IsPlayingFileAsMicrophone() const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000245 int ScaleFileAsMicrophonePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000246 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
247 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
248 int StopRecordingPlayout();
249
250 void SetMixWithMicStatus(bool mix);
251
252 // VoEExternalMediaProcessing
253 int RegisterExternalMediaProcessing(ProcessingTypes type,
254 VoEMediaProcess& processObject);
255 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000256 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000257
258 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000259 int GetSpeechOutputLevel(uint32_t& level) const;
260 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000261 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000262 bool Mute() const;
263 int SetOutputVolumePan(float left, float right);
264 int GetOutputVolumePan(float& left, float& right) const;
265 int SetChannelOutputVolumeScaling(float scaling);
266 int GetChannelOutputVolumeScaling(float& scaling) const;
267
niklase@google.com470e71d2011-07-07 08:21:25 +0000268 // VoENetEqStats
269 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000270 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000271
272 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000273 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
274 int* playout_buffer_delay_ms) const;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000275 int least_required_delay_ms() const { return least_required_delay_ms_; }
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000276 int SetInitialPlayoutDelay(int delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000277 int SetMinimumPlayoutDelay(int delayMs);
278 int GetPlayoutTimestamp(unsigned int& timestamp);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000279 void UpdatePlayoutTimestamp(bool rtcp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000280 int SetInitTimestamp(unsigned int timestamp);
281 int SetInitSequenceNumber(short sequenceNumber);
282
283 // VoEVideoSyncExtended
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000284 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000285
niklase@google.com470e71d2011-07-07 08:21:25 +0000286 // VoEDtmf
287 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
288 int attenuationDb, bool playDtmfEvent);
289 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
290 int attenuationDb, bool playDtmfEvent);
291 int SetDtmfPlayoutStatus(bool enable);
292 bool DtmfPlayoutStatus() const;
293 int SetSendTelephoneEventPayloadType(unsigned char type);
294 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000295
296 // VoEAudioProcessingImpl
297 int UpdateRxVadDetection(AudioFrame& audioFrame);
298 int RegisterRxVadObserver(VoERxVadCallback &observer);
299 int DeRegisterRxVadObserver();
300 int VoiceActivityIndicator(int &activity);
301#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000302 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000303 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000304 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000305 int GetRxAgcConfig(AgcConfig& config);
306#endif
307#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000308 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000309 int GetRxNsStatus(bool& enabled, NsModes& mode);
310#endif
311
312 // VoERTP_RTCP
313 int RegisterRTPObserver(VoERTPObserver& observer);
314 int DeRegisterRTPObserver();
315 int RegisterRTCPObserver(VoERTCPObserver& observer);
316 int DeRegisterRTCPObserver();
317 int SetLocalSSRC(unsigned int ssrc);
318 int GetLocalSSRC(unsigned int& ssrc);
319 int GetRemoteSSRC(unsigned int& ssrc);
320 int GetRemoteCSRCs(unsigned int arrCSRC[15]);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000321 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.org93fd25c2014-04-24 20:33:08 +0000322 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000323 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
324 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000325 int SetRTCPStatus(bool enable);
326 int GetRTCPStatus(bool& enabled);
327 int SetRTCP_CNAME(const char cName[256]);
328 int GetRTCP_CNAME(char cName[256]);
329 int GetRemoteRTCP_CNAME(char cName[256]);
330 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
331 unsigned int& timestamp,
332 unsigned int& playoutTimestamp, unsigned int* jitter,
333 unsigned short* fractionLost);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000334 int SendApplicationDefinedRTCPPacket(unsigned char subType,
niklase@google.com470e71d2011-07-07 08:21:25 +0000335 unsigned int name, const char* data,
336 unsigned short dataLengthInBytes);
337 int GetRTPStatistics(unsigned int& averageJitterMs,
338 unsigned int& maxJitterMs,
339 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000340 int GetRemoteRTCPSenderInfo(SenderInfo* sender_info);
341 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000342 int GetRTPStatistics(CallStatistics& stats);
343 int SetFECStatus(bool enable, int redPayloadtype);
344 int GetFECStatus(bool& enabled, int& redPayloadtype);
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000345 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000346 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
347 int StopRTPDump(RTPDirections direction);
348 bool RTPDumpIsActive(RTPDirections direction);
roosa@google.com0870f022012-12-12 21:31:41 +0000349 uint32_t LastRemoteTimeStamp() { return _lastRemoteTimeStamp; }
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000350 // Takes ownership of the ViENetwork.
351 void SetVideoEngineBWETarget(ViENetwork* vie_network, int video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000352
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 // From AudioPacketizationCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000354 int32_t SendData(FrameType frameType,
355 uint8_t payloadType,
356 uint32_t timeStamp,
357 const uint8_t* payloadData,
358 uint16_t payloadSize,
359 const RTPFragmentationHeader* fragmentation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000360 // From ACMVADCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000361 int32_t InFrameType(int16_t frameType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000362
pbos@webrtc.org92135212013-05-14 08:31:39 +0000363 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000364
niklase@google.com470e71d2011-07-07 08:21:25 +0000365 // From RtpData in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000366 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000367 uint16_t payloadSize,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000368 const WebRtcRTPHeader* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +0000369
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000370 bool OnRecoveredPacket(const uint8_t* packet, int packet_length);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000371
niklase@google.com470e71d2011-07-07 08:21:25 +0000372 // From RtpFeedback in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000373 int32_t OnInitializeDecoder(
pbos@webrtc.org92135212013-05-14 08:31:39 +0000374 int32_t id,
375 int8_t payloadType,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000376 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org92135212013-05-14 08:31:39 +0000377 int frequency,
378 uint8_t channels,
379 uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000380
pbos@webrtc.org92135212013-05-14 08:31:39 +0000381 void OnPacketTimeout(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000382
pbos@webrtc.org92135212013-05-14 08:31:39 +0000383 void OnReceivedPacket(int32_t id, RtpRtcpPacketType packetType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000384
pbos@webrtc.org92135212013-05-14 08:31:39 +0000385 void OnPeriodicDeadOrAlive(int32_t id,
386 RTPAliveType alive);
niklase@google.com470e71d2011-07-07 08:21:25 +0000387
pbos@webrtc.org92135212013-05-14 08:31:39 +0000388 void OnIncomingSSRCChanged(int32_t id,
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000389 uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000390
pbos@webrtc.org92135212013-05-14 08:31:39 +0000391 void OnIncomingCSRCChanged(int32_t id,
392 uint32_t CSRC, bool added);
niklase@google.com470e71d2011-07-07 08:21:25 +0000393
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000394 void ResetStatistics(uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000395
niklase@google.com470e71d2011-07-07 08:21:25 +0000396 // From RtcpFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000397 void OnApplicationDataReceived(int32_t id,
398 uint8_t subType,
399 uint32_t name,
400 uint16_t length,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000401 const uint8_t* data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000402
niklase@google.com470e71d2011-07-07 08:21:25 +0000403 // From RtpAudioFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000404 void OnReceivedTelephoneEvent(int32_t id,
405 uint8_t event,
406 bool endOfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000407
pbos@webrtc.org92135212013-05-14 08:31:39 +0000408 void OnPlayTelephoneEvent(int32_t id,
409 uint8_t event,
410 uint16_t lengthMs,
411 uint8_t volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000412
niklase@google.com470e71d2011-07-07 08:21:25 +0000413 // From Transport (called by the RTP/RTCP module)
414 int SendPacket(int /*channel*/, const void *data, int len);
415 int SendRTCPPacket(int /*channel*/, const void *data, int len);
416
niklase@google.com470e71d2011-07-07 08:21:25 +0000417 // From MixerParticipant
pbos@webrtc.org92135212013-05-14 08:31:39 +0000418 int32_t GetAudioFrame(int32_t id, AudioFrame& audioFrame);
419 int32_t NeededFrequency(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000420
niklase@google.com470e71d2011-07-07 08:21:25 +0000421 // From MonitorObserver
422 void OnPeriodicProcess();
423
niklase@google.com470e71d2011-07-07 08:21:25 +0000424 // From FileCallback
pbos@webrtc.org92135212013-05-14 08:31:39 +0000425 void PlayNotification(int32_t id,
426 uint32_t durationMs);
427 void RecordNotification(int32_t id,
428 uint32_t durationMs);
429 void PlayFileEnded(int32_t id);
430 void RecordFileEnded(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000431
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000432 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000433 {
434 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000435 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000436 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000437 {
438 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000439 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000440 bool Playing() const
441 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000442 return channel_state_.Get().playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000443 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000444 bool Sending() const
445 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000446 return channel_state_.Get().sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000447 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000448 bool Receiving() const
449 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000450 return channel_state_.Get().receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000451 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000452 bool ExternalTransport() const
453 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000454 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000455 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000456 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000457 bool ExternalMixing() const
458 {
459 return _externalMixing;
460 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000461 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000462 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000463 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000464 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000465 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000466 {
467 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000468 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000469 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000470 // Demultiplex the data to the channel's |_audioFrame|. The difference
471 // between this method and the overloaded method above is that |audio_data|
472 // does not go through transmit_mixer and APM.
473 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000474 int sample_rate,
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000475 int number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000476 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000477 uint32_t PrepareEncodeAndSend(int mixingFrequency);
478 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000479
480private:
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000481 bool ReceivePacket(const uint8_t* packet, int packet_length,
482 const RTPHeader& header, bool in_order);
483 bool HandleEncapsulation(const uint8_t* packet,
484 int packet_length,
485 const RTPHeader& header);
486 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000487 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000488 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000489 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000490 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
491 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000492 int32_t SendPacketRaw(const void *data, int len, bool RTCP);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000493 void UpdatePacketDelay(uint32_t timestamp,
494 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000495 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000496
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000497 int SetRedPayloadType(int red_payload_type);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000498 int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type,
499 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000500
niklase@google.com470e71d2011-07-07 08:21:25 +0000501 CriticalSectionWrapper& _fileCritSect;
502 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.org63420662013-10-17 18:28:55 +0000503 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000504 uint32_t _instanceId;
505 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000506
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000507 ChannelState channel_state_;
508
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000509 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000510 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
511 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +0000512 scoped_ptr<StatisticsProxy> statistics_proxy_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000513 scoped_ptr<RtpReceiver> rtp_receiver_;
514 TelephoneEventHandler* telephone_event_handler_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000515 scoped_ptr<RtpRtcp> _rtpRtcpModule;
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000516 scoped_ptr<AudioCodingModule> audio_coding_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000517 RtpDump& _rtpDumpIn;
518 RtpDump& _rtpDumpOut;
niklase@google.com470e71d2011-07-07 08:21:25 +0000519 AudioLevel _outputAudioLevel;
520 bool _externalTransport;
521 AudioFrame _audioFrame;
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +0000522 scoped_ptr<int16_t[]> mono_recording_audio_;
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +0000523 // Downsamples to the codec rate if necessary.
524 PushResampler<int16_t> input_resampler_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000525 uint8_t _audioLevel_dBov;
niklase@google.com470e71d2011-07-07 08:21:25 +0000526 FilePlayer* _inputFilePlayerPtr;
527 FilePlayer* _outputFilePlayerPtr;
528 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000529 int _inputFilePlayerId;
530 int _outputFilePlayerId;
531 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000532 bool _outputFileRecording;
533 DtmfInbandQueue _inbandDtmfQueue;
534 DtmfInband _inbandDtmfGenerator;
xians@google.com22963ab2011-08-03 12:40:23 +0000535 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000536 VoEMediaProcess* _inputExternalMediaCallbackPtr;
537 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000538 uint32_t _timeStamp;
539 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000540
541 // Timestamp of the audio pulled from NetEq.
542 uint32_t jitter_buffer_playout_timestamp_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000543 uint32_t playout_timestamp_rtp_;
544 uint32_t playout_timestamp_rtcp_;
545 uint32_t playout_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000546 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000547 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000548 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000549
niklase@google.com470e71d2011-07-07 08:21:25 +0000550 // uses
551 Statistics* _engineStatisticsPtr;
552 OutputMixer* _outputMixerPtr;
553 TransmitMixer* _transmitMixerPtr;
554 ProcessThread* _moduleProcessThreadPtr;
555 AudioDeviceModule* _audioDeviceModulePtr;
556 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
557 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
558 Transport* _transportPtr; // WebRtc socket or external transport
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +0000559 scoped_ptr<AudioProcessing> rtp_audioproc_;
560 scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000561 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000562 int32_t _oldVadDecision;
563 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000564 VoERTPObserver* _rtpObserverPtr;
565 VoERTCPObserver* _rtcpObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000566 // VoEBase
niklase@google.com470e71d2011-07-07 08:21:25 +0000567 bool _externalPlayout;
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000568 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000569 bool _mixFileWithMicrophone;
570 bool _rtpObserver;
571 bool _rtcpObserver;
572 // VoEVolumeControl
573 bool _mute;
574 float _panLeft;
575 float _panRight;
576 float _outputGain;
niklase@google.com470e71d2011-07-07 08:21:25 +0000577 // VoEDtmf
578 bool _playOutbandDtmfEvent;
579 bool _playInbandDtmfEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000580 // VoeRTP_RTCP
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000581 uint32_t _lastLocalTimeStamp;
roosa@google.com0870f022012-12-12 21:31:41 +0000582 uint32_t _lastRemoteTimeStamp;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000583 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000584 bool _includeAudioLevelIndication;
585 // VoENetwork
586 bool _rtpPacketTimedOut;
587 bool _rtpPacketTimeOutIsEnabled;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000588 uint32_t _rtpTimeOutSeconds;
niklase@google.com470e71d2011-07-07 08:21:25 +0000589 bool _connectionObserver;
590 VoEConnectionObserver* _connectionObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000591 AudioFrame::SpeechType _outputSpeechType;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000592 ViENetwork* vie_network_;
593 int video_channel_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000594 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000595 uint32_t _average_jitter_buffer_delay_us;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000596 int least_required_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000597 uint32_t _previousTimestamp;
598 uint16_t _recPacketDelayMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000599 // VoEAudioProcessing
600 bool _RxVadDetection;
niklase@google.com470e71d2011-07-07 08:21:25 +0000601 bool _rxAgcIsEnabled;
602 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000603 bool restored_packet_in_use_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000604};
605
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000606} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000607} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000608
609#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H