blob: b490f4896aaa6f18bfcb45bdcf7bf88f605a54ed [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),
77 output_is_on_hold(false),
78 output_file_playing(false),
79 input_file_playing(false),
80 playing(false),
81 sending(false),
82 receiving(false) {}
83
84 bool rx_apm_is_enabled;
85 bool input_external_media;
86 bool output_is_on_hold;
87 bool output_file_playing;
88 bool input_file_playing;
89 bool playing;
90 bool sending;
91 bool receiving;
92 };
93
94 ChannelState() : lock_(CriticalSectionWrapper::CreateCriticalSection()) {
95 }
96 virtual ~ChannelState() {}
97
98 void Reset() {
99 CriticalSectionScoped lock(lock_.get());
100 state_ = State();
101 }
102
103 State Get() const {
104 CriticalSectionScoped lock(lock_.get());
105 return state_;
106 }
107
108 void SetRxApmIsEnabled(bool enable) {
109 CriticalSectionScoped lock(lock_.get());
110 state_.rx_apm_is_enabled = enable;
111 }
112
113 void SetInputExternalMedia(bool enable) {
114 CriticalSectionScoped lock(lock_.get());
115 state_.input_external_media = enable;
116 }
117
118 void SetOutputIsOnHold(bool enable) {
119 CriticalSectionScoped lock(lock_.get());
120 state_.output_is_on_hold = enable;
121 }
122
123 void SetOutputFilePlaying(bool enable) {
124 CriticalSectionScoped lock(lock_.get());
125 state_.output_file_playing = enable;
126 }
127
128 void SetInputFilePlaying(bool enable) {
129 CriticalSectionScoped lock(lock_.get());
130 state_.input_file_playing = enable;
131 }
132
133 void SetPlaying(bool enable) {
134 CriticalSectionScoped lock(lock_.get());
135 state_.playing = enable;
136 }
137
138 void SetSending(bool enable) {
139 CriticalSectionScoped lock(lock_.get());
140 state_.sending = enable;
141 }
142
143 void SetReceiving(bool enable) {
144 CriticalSectionScoped lock(lock_.get());
145 state_.receiving = enable;
146 }
147
148private:
149 scoped_ptr<CriticalSectionWrapper> lock_;
150 State state_;
151};
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
153class Channel:
154 public RtpData,
155 public RtpFeedback,
156 public RtcpFeedback,
niklase@google.com470e71d2011-07-07 08:21:25 +0000157 public FileCallback, // receiving notification from file player & recorder
158 public Transport,
159 public RtpAudioFeedback,
160 public AudioPacketizationCallback, // receive encoded packets from the ACM
161 public ACMVADCallback, // receive voice activity from the ACM
niklase@google.com470e71d2011-07-07 08:21:25 +0000162 public MixerParticipant // supplies output mixer with audio frames
163{
164public:
165 enum {KNumSocketThreads = 1};
166 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +0000167 virtual ~Channel();
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000168 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000169 int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000170 uint32_t instanceId,
171 const Config& config);
172 Channel(int32_t channelId, uint32_t instanceId, const Config& config);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000173 int32_t Init();
174 int32_t SetEngineInformation(
niklase@google.com470e71d2011-07-07 08:21:25 +0000175 Statistics& engineStatistics,
176 OutputMixer& outputMixer,
177 TransmitMixer& transmitMixer,
178 ProcessThread& moduleProcessThread,
179 AudioDeviceModule& audioDeviceModule,
180 VoiceEngineObserver* voiceEngineObserver,
181 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000182 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000183
niklase@google.com470e71d2011-07-07 08:21:25 +0000184 // API methods
185
186 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000187 int32_t StartPlayout();
188 int32_t StopPlayout();
189 int32_t StartSend();
190 int32_t StopSend();
191 int32_t StartReceiving();
192 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000194 int32_t SetNetEQPlayoutMode(NetEqModes mode);
195 int32_t GetNetEQPlayoutMode(NetEqModes& mode);
196 int32_t SetOnHoldStatus(bool enable, OnHoldModes mode);
197 int32_t GetOnHoldStatus(bool& enabled, OnHoldModes& mode);
198 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
199 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000200
201 // VoECodec
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000202 int32_t GetSendCodec(CodecInst& codec);
203 int32_t GetRecCodec(CodecInst& codec);
204 int32_t SetSendCodec(const CodecInst& codec);
205 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
206 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
207 int32_t SetRecPayloadType(const CodecInst& codec);
208 int32_t GetRecPayloadType(CodecInst& codec);
209 int32_t SetAMREncFormat(AmrMode mode);
210 int32_t SetAMRDecFormat(AmrMode mode);
211 int32_t SetAMRWbEncFormat(AmrMode mode);
212 int32_t SetAMRWbDecFormat(AmrMode mode);
213 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
214 int32_t SetISACInitTargetRate(int rateBps, bool useFixedFrameSize);
215 int32_t SetISACMaxRate(int rateBps);
216 int32_t SetISACMaxPayloadSize(int sizeBytes);
niklase@google.com470e71d2011-07-07 08:21:25 +0000217
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000218 // VoE dual-streaming.
219 int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);
220 void RemoveSecondarySendCodec();
221 int GetSecondarySendCodec(CodecInst* codec);
222
niklase@google.com470e71d2011-07-07 08:21:25 +0000223 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000224 int32_t RegisterExternalTransport(Transport& transport);
225 int32_t DeRegisterExternalTransport();
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000226 int32_t ReceivedRTPPacket(const int8_t* data, int32_t length,
227 const PacketTime& packet_time);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000228 int32_t ReceivedRTCPPacket(const int8_t* data, int32_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000229
niklase@google.com470e71d2011-07-07 08:21:25 +0000230 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000231 int StartPlayingFileLocally(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);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000237 int StartPlayingFileLocally(InStream* stream, FileFormats format,
238 int startPosition,
239 float volumeScaling,
240 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000241 const CodecInst* codecInst);
242 int StopPlayingFileLocally();
243 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000244 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000245 int ScaleLocalFilePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000246 int GetLocalPlayoutPosition(int& positionMs);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000247 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
248 FileFormats format,
249 int startPosition,
250 float volumeScaling,
251 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000252 const CodecInst* codecInst);
253 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000254 FileFormats format,
255 int startPosition,
256 float volumeScaling,
257 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000258 const CodecInst* codecInst);
259 int StopPlayingFileAsMicrophone();
260 int IsPlayingFileAsMicrophone() const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000261 int ScaleFileAsMicrophonePlayout(float scale);
niklase@google.com470e71d2011-07-07 08:21:25 +0000262 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
263 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
264 int StopRecordingPlayout();
265
266 void SetMixWithMicStatus(bool mix);
267
268 // VoEExternalMediaProcessing
269 int RegisterExternalMediaProcessing(ProcessingTypes type,
270 VoEMediaProcess& processObject);
271 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000272 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000273
274 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000275 int GetSpeechOutputLevel(uint32_t& level) const;
276 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000277 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000278 bool Mute() const;
279 int SetOutputVolumePan(float left, float right);
280 int GetOutputVolumePan(float& left, float& right) const;
281 int SetChannelOutputVolumeScaling(float scaling);
282 int GetChannelOutputVolumeScaling(float& scaling) const;
283
284 // VoECallReport
285 void ResetDeadOrAliveCounters();
286 int ResetRTCPStatistics();
287 int GetRoundTripTimeSummary(StatVal& delaysMs) const;
288 int GetDeadOrAliveCounters(int& countDead, int& countAlive) const;
289
290 // VoENetEqStats
291 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000292 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000293
294 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000295 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
296 int* playout_buffer_delay_ms) const;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000297 int least_required_delay_ms() const { return least_required_delay_ms_; }
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000298 int SetInitialPlayoutDelay(int delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000299 int SetMinimumPlayoutDelay(int delayMs);
300 int GetPlayoutTimestamp(unsigned int& timestamp);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000301 void UpdatePlayoutTimestamp(bool rtcp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000302 int SetInitTimestamp(unsigned int timestamp);
303 int SetInitSequenceNumber(short sequenceNumber);
304
305 // VoEVideoSyncExtended
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000306 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000307
niklase@google.com470e71d2011-07-07 08:21:25 +0000308 // VoEDtmf
309 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
310 int attenuationDb, bool playDtmfEvent);
311 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
312 int attenuationDb, bool playDtmfEvent);
313 int SetDtmfPlayoutStatus(bool enable);
314 bool DtmfPlayoutStatus() const;
315 int SetSendTelephoneEventPayloadType(unsigned char type);
316 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000317
318 // VoEAudioProcessingImpl
319 int UpdateRxVadDetection(AudioFrame& audioFrame);
320 int RegisterRxVadObserver(VoERxVadCallback &observer);
321 int DeRegisterRxVadObserver();
322 int VoiceActivityIndicator(int &activity);
323#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000324 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000325 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000326 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000327 int GetRxAgcConfig(AgcConfig& config);
328#endif
329#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000330 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000331 int GetRxNsStatus(bool& enabled, NsModes& mode);
332#endif
333
334 // VoERTP_RTCP
335 int RegisterRTPObserver(VoERTPObserver& observer);
336 int DeRegisterRTPObserver();
337 int RegisterRTCPObserver(VoERTCPObserver& observer);
338 int DeRegisterRTCPObserver();
339 int SetLocalSSRC(unsigned int ssrc);
340 int GetLocalSSRC(unsigned int& ssrc);
341 int GetRemoteSSRC(unsigned int& ssrc);
342 int GetRemoteCSRCs(unsigned int arrCSRC[15]);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000343 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
344 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
345 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000346 int SetRTCPStatus(bool enable);
347 int GetRTCPStatus(bool& enabled);
348 int SetRTCP_CNAME(const char cName[256]);
349 int GetRTCP_CNAME(char cName[256]);
350 int GetRemoteRTCP_CNAME(char cName[256]);
351 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
352 unsigned int& timestamp,
353 unsigned int& playoutTimestamp, unsigned int* jitter,
354 unsigned short* fractionLost);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000355 int SendApplicationDefinedRTCPPacket(unsigned char subType,
niklase@google.com470e71d2011-07-07 08:21:25 +0000356 unsigned int name, const char* data,
357 unsigned short dataLengthInBytes);
358 int GetRTPStatistics(unsigned int& averageJitterMs,
359 unsigned int& maxJitterMs,
360 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000361 int GetRemoteRTCPSenderInfo(SenderInfo* sender_info);
362 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000363 int GetRTPStatistics(CallStatistics& stats);
364 int SetFECStatus(bool enable, int redPayloadtype);
365 int GetFECStatus(bool& enabled, int& redPayloadtype);
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000366 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000367 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
368 int StopRTPDump(RTPDirections direction);
369 bool RTPDumpIsActive(RTPDirections direction);
roosa@google.com0870f022012-12-12 21:31:41 +0000370 uint32_t LastRemoteTimeStamp() { return _lastRemoteTimeStamp; }
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000371 // Takes ownership of the ViENetwork.
372 void SetVideoEngineBWETarget(ViENetwork* vie_network, int video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000373
niklase@google.com470e71d2011-07-07 08:21:25 +0000374 // From AudioPacketizationCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000375 int32_t SendData(FrameType frameType,
376 uint8_t payloadType,
377 uint32_t timeStamp,
378 const uint8_t* payloadData,
379 uint16_t payloadSize,
380 const RTPFragmentationHeader* fragmentation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000381 // From ACMVADCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000382 int32_t InFrameType(int16_t frameType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000383
pbos@webrtc.org92135212013-05-14 08:31:39 +0000384 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000385
niklase@google.com470e71d2011-07-07 08:21:25 +0000386 // From RtpData in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000387 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000388 uint16_t payloadSize,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000389 const WebRtcRTPHeader* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +0000390
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000391 bool OnRecoveredPacket(const uint8_t* packet, int packet_length);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000392
niklase@google.com470e71d2011-07-07 08:21:25 +0000393 // From RtpFeedback in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000394 int32_t OnInitializeDecoder(
pbos@webrtc.org92135212013-05-14 08:31:39 +0000395 int32_t id,
396 int8_t payloadType,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000397 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org92135212013-05-14 08:31:39 +0000398 int frequency,
399 uint8_t channels,
400 uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000401
pbos@webrtc.org92135212013-05-14 08:31:39 +0000402 void OnPacketTimeout(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000403
pbos@webrtc.org92135212013-05-14 08:31:39 +0000404 void OnReceivedPacket(int32_t id, RtpRtcpPacketType packetType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000405
pbos@webrtc.org92135212013-05-14 08:31:39 +0000406 void OnPeriodicDeadOrAlive(int32_t id,
407 RTPAliveType alive);
niklase@google.com470e71d2011-07-07 08:21:25 +0000408
pbos@webrtc.org92135212013-05-14 08:31:39 +0000409 void OnIncomingSSRCChanged(int32_t id,
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000410 uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000411
pbos@webrtc.org92135212013-05-14 08:31:39 +0000412 void OnIncomingCSRCChanged(int32_t id,
413 uint32_t CSRC, bool added);
niklase@google.com470e71d2011-07-07 08:21:25 +0000414
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000415 void ResetStatistics(uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000416
niklase@google.com470e71d2011-07-07 08:21:25 +0000417 // From RtcpFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000418 void OnApplicationDataReceived(int32_t id,
419 uint8_t subType,
420 uint32_t name,
421 uint16_t length,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000422 const uint8_t* data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000423
niklase@google.com470e71d2011-07-07 08:21:25 +0000424 // From RtpAudioFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000425 void OnReceivedTelephoneEvent(int32_t id,
426 uint8_t event,
427 bool endOfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000428
pbos@webrtc.org92135212013-05-14 08:31:39 +0000429 void OnPlayTelephoneEvent(int32_t id,
430 uint8_t event,
431 uint16_t lengthMs,
432 uint8_t volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000433
niklase@google.com470e71d2011-07-07 08:21:25 +0000434 // From Transport (called by the RTP/RTCP module)
435 int SendPacket(int /*channel*/, const void *data, int len);
436 int SendRTCPPacket(int /*channel*/, const void *data, int len);
437
niklase@google.com470e71d2011-07-07 08:21:25 +0000438 // From MixerParticipant
pbos@webrtc.org92135212013-05-14 08:31:39 +0000439 int32_t GetAudioFrame(int32_t id, AudioFrame& audioFrame);
440 int32_t NeededFrequency(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000441
niklase@google.com470e71d2011-07-07 08:21:25 +0000442 // From MonitorObserver
443 void OnPeriodicProcess();
444
niklase@google.com470e71d2011-07-07 08:21:25 +0000445 // From FileCallback
pbos@webrtc.org92135212013-05-14 08:31:39 +0000446 void PlayNotification(int32_t id,
447 uint32_t durationMs);
448 void RecordNotification(int32_t id,
449 uint32_t durationMs);
450 void PlayFileEnded(int32_t id);
451 void RecordFileEnded(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000452
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000453 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000454 {
455 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000456 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000457 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000458 {
459 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000460 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000461 bool Playing() const
462 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000463 return channel_state_.Get().playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000464 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000465 bool Sending() const
466 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000467 return channel_state_.Get().sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000468 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000469 bool Receiving() const
470 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000471 return channel_state_.Get().receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000472 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000473 bool ExternalTransport() const
474 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000475 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000476 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000477 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000478 bool ExternalMixing() const
479 {
480 return _externalMixing;
481 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000482 bool InputIsOnHold() const
483 {
484 return _inputIsOnHold;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000485 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000486 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000487 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000488 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000489 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000490 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000491 {
492 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000493 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000494 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000495 // Demultiplex the data to the channel's |_audioFrame|. The difference
496 // between this method and the overloaded method above is that |audio_data|
497 // does not go through transmit_mixer and APM.
498 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000499 int sample_rate,
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000500 int number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000501 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000502 uint32_t PrepareEncodeAndSend(int mixingFrequency);
503 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000504
505private:
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000506 bool ReceivePacket(const uint8_t* packet, int packet_length,
507 const RTPHeader& header, bool in_order);
508 bool HandleEncapsulation(const uint8_t* packet,
509 int packet_length,
510 const RTPHeader& header);
511 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000512 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000513 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000514 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000515 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
516 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000517 void UpdateDeadOrAliveCounters(bool alive);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000518 int32_t SendPacketRaw(const void *data, int len, bool RTCP);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000519 void UpdatePacketDelay(uint32_t timestamp,
520 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000521 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000522
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000523 int SetRedPayloadType(int red_payload_type);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000524 int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type,
525 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000526
niklase@google.com470e71d2011-07-07 08:21:25 +0000527 CriticalSectionWrapper& _fileCritSect;
528 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.org63420662013-10-17 18:28:55 +0000529 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000530 uint32_t _instanceId;
531 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000532
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000533 ChannelState channel_state_;
534
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000535 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000536 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
537 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +0000538 scoped_ptr<StatisticsProxy> statistics_proxy_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000539 scoped_ptr<RtpReceiver> rtp_receiver_;
540 TelephoneEventHandler* telephone_event_handler_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000541 scoped_ptr<RtpRtcp> _rtpRtcpModule;
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000542 scoped_ptr<AudioCodingModule> audio_coding_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000543 RtpDump& _rtpDumpIn;
544 RtpDump& _rtpDumpOut;
niklase@google.com470e71d2011-07-07 08:21:25 +0000545 AudioLevel _outputAudioLevel;
546 bool _externalTransport;
547 AudioFrame _audioFrame;
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +0000548 scoped_ptr<int16_t[]> mono_recording_audio_;
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000549 // Resampler is used when input data is stereo while codec is mono.
550 PushResampler input_resampler_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000551 uint8_t _audioLevel_dBov;
niklase@google.com470e71d2011-07-07 08:21:25 +0000552 FilePlayer* _inputFilePlayerPtr;
553 FilePlayer* _outputFilePlayerPtr;
554 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000555 int _inputFilePlayerId;
556 int _outputFilePlayerId;
557 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000558 bool _outputFileRecording;
559 DtmfInbandQueue _inbandDtmfQueue;
560 DtmfInband _inbandDtmfGenerator;
xians@google.com22963ab2011-08-03 12:40:23 +0000561 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000562 VoEMediaProcess* _inputExternalMediaCallbackPtr;
563 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000564 uint32_t _timeStamp;
565 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000566
567 // Timestamp of the audio pulled from NetEq.
568 uint32_t jitter_buffer_playout_timestamp_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000569 uint32_t playout_timestamp_rtp_;
570 uint32_t playout_timestamp_rtcp_;
571 uint32_t playout_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000572 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000573 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000574 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000575
niklase@google.com470e71d2011-07-07 08:21:25 +0000576 // uses
577 Statistics* _engineStatisticsPtr;
578 OutputMixer* _outputMixerPtr;
579 TransmitMixer* _transmitMixerPtr;
580 ProcessThread* _moduleProcessThreadPtr;
581 AudioDeviceModule* _audioDeviceModulePtr;
582 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
583 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
584 Transport* _transportPtr; // WebRtc socket or external transport
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +0000585 scoped_ptr<AudioProcessing> rtp_audioproc_;
586 scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000587 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000588 int32_t _oldVadDecision;
589 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000590 VoERTPObserver* _rtpObserverPtr;
591 VoERTCPObserver* _rtcpObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000592 // VoEBase
niklase@google.com470e71d2011-07-07 08:21:25 +0000593 bool _externalPlayout;
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000594 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000595 bool _inputIsOnHold;
niklase@google.com470e71d2011-07-07 08:21:25 +0000596 bool _mixFileWithMicrophone;
597 bool _rtpObserver;
598 bool _rtcpObserver;
599 // VoEVolumeControl
600 bool _mute;
601 float _panLeft;
602 float _panRight;
603 float _outputGain;
niklase@google.com470e71d2011-07-07 08:21:25 +0000604 // VoEDtmf
605 bool _playOutbandDtmfEvent;
606 bool _playInbandDtmfEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000607 // VoeRTP_RTCP
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000608 uint32_t _lastLocalTimeStamp;
roosa@google.com0870f022012-12-12 21:31:41 +0000609 uint32_t _lastRemoteTimeStamp;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000610 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000611 bool _includeAudioLevelIndication;
612 // VoENetwork
613 bool _rtpPacketTimedOut;
614 bool _rtpPacketTimeOutIsEnabled;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000615 uint32_t _rtpTimeOutSeconds;
niklase@google.com470e71d2011-07-07 08:21:25 +0000616 bool _connectionObserver;
617 VoEConnectionObserver* _connectionObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000618 uint32_t _countAliveDetections;
619 uint32_t _countDeadDetections;
niklase@google.com470e71d2011-07-07 08:21:25 +0000620 AudioFrame::SpeechType _outputSpeechType;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000621 ViENetwork* vie_network_;
622 int video_channel_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000623 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000624 uint32_t _average_jitter_buffer_delay_us;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000625 int least_required_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000626 uint32_t _previousTimestamp;
627 uint16_t _recPacketDelayMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000628 // VoEAudioProcessing
629 bool _RxVadDetection;
niklase@google.com470e71d2011-07-07 08:21:25 +0000630 bool _rxAgcIsEnabled;
631 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000632 bool restored_packet_in_use_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000633};
634
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000635} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000636} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000637
638#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H