blob: 7b40ed282c78522a060d5ca4ce67404985bbfcf7 [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
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000011#ifndef WEBRTC_VOICE_ENGINE_CHANNEL_H_
12#define WEBRTC_VOICE_ENGINE_CHANNEL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
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"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000018#include "webrtc/modules/audio_processing/rms_level.h"
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000019#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000020#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
21#include "webrtc/modules/utility/interface/file_player.h"
22#include "webrtc/modules/utility/interface/file_recorder.h"
23#include "webrtc/system_wrappers/interface/scoped_ptr.h"
24#include "webrtc/voice_engine/dtmf_inband.h"
25#include "webrtc/voice_engine/dtmf_inband_queue.h"
26#include "webrtc/voice_engine/include/voe_audio_processing.h"
27#include "webrtc/voice_engine/include/voe_network.h"
28#include "webrtc/voice_engine/level_indicator.h"
29#include "webrtc/voice_engine/shared_data.h"
30#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000031
niklase@google.com470e71d2011-07-07 08:21:25 +000032#ifdef WEBRTC_DTMF_DETECTION
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000033// TelephoneEventDetectionMethods, TelephoneEventObserver
34#include "webrtc/voice_engine/include/voe_dtmf.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000035#endif
36
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000037namespace webrtc {
38
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000039class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000040class Config;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000041class CriticalSectionWrapper;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000042class FileWrapper;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000043class ProcessThread;
44class ReceiveStatistics;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000045class RtpDump;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000046class RTPPayloadRegistry;
47class RtpReceiver;
48class RTPReceiverAudio;
49class RtpRtcp;
50class TelephoneEventHandler;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +000051class ViENetwork;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000052class VoEMediaProcess;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000053class VoERTCPObserver;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000054class VoERTPObserver;
55class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
57struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000058struct ReportBlock;
59struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000060
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000061namespace voe {
62
niklase@google.com470e71d2011-07-07 08:21:25 +000063class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000064class StatisticsProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000065class TransmitMixer;
66class OutputMixer;
67
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000068// Helper class to simplify locking scheme for members that are accessed from
69// multiple threads.
70// Example: a member can be set on thread T1 and read by an internal audio
71// thread T2. Accessing the member via this class ensures that we are
72// safe and also avoid TSan v2 warnings.
73class ChannelState {
74 public:
75 struct State {
76 State() : rx_apm_is_enabled(false),
77 input_external_media(false),
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000078 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;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000086 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
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000117 void SetOutputFilePlaying(bool enable) {
118 CriticalSectionScoped lock(lock_.get());
119 state_.output_file_playing = enable;
120 }
121
122 void SetInputFilePlaying(bool enable) {
123 CriticalSectionScoped lock(lock_.get());
124 state_.input_file_playing = enable;
125 }
126
127 void SetPlaying(bool enable) {
128 CriticalSectionScoped lock(lock_.get());
129 state_.playing = enable;
130 }
131
132 void SetSending(bool enable) {
133 CriticalSectionScoped lock(lock_.get());
134 state_.sending = enable;
135 }
136
137 void SetReceiving(bool enable) {
138 CriticalSectionScoped lock(lock_.get());
139 state_.receiving = enable;
140 }
141
142private:
143 scoped_ptr<CriticalSectionWrapper> lock_;
144 State state_;
145};
niklase@google.com470e71d2011-07-07 08:21:25 +0000146
147class Channel:
148 public RtpData,
149 public RtpFeedback,
150 public RtcpFeedback,
niklase@google.com470e71d2011-07-07 08:21:25 +0000151 public FileCallback, // receiving notification from file player & recorder
152 public Transport,
153 public RtpAudioFeedback,
154 public AudioPacketizationCallback, // receive encoded packets from the ACM
155 public ACMVADCallback, // receive voice activity from the ACM
niklase@google.com470e71d2011-07-07 08:21:25 +0000156 public MixerParticipant // supplies output mixer with audio frames
157{
158public:
159 enum {KNumSocketThreads = 1};
160 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +0000161 virtual ~Channel();
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000162 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000163 int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000164 uint32_t instanceId,
165 const Config& config);
166 Channel(int32_t channelId, uint32_t instanceId, const Config& config);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000167 int32_t Init();
168 int32_t SetEngineInformation(
niklase@google.com470e71d2011-07-07 08:21:25 +0000169 Statistics& engineStatistics,
170 OutputMixer& outputMixer,
171 TransmitMixer& transmitMixer,
172 ProcessThread& moduleProcessThread,
173 AudioDeviceModule& audioDeviceModule,
174 VoiceEngineObserver* voiceEngineObserver,
175 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000176 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000177
niklase@google.com470e71d2011-07-07 08:21:25 +0000178 // API methods
179
180 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000181 int32_t StartPlayout();
182 int32_t StopPlayout();
183 int32_t StartSend();
184 int32_t StopSend();
185 int32_t StartReceiving();
186 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000187
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000188 int32_t SetNetEQPlayoutMode(NetEqModes mode);
189 int32_t GetNetEQPlayoutMode(NetEqModes& mode);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000190 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
191 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000192
193 // VoECodec
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000194 int32_t GetSendCodec(CodecInst& codec);
195 int32_t GetRecCodec(CodecInst& codec);
196 int32_t SetSendCodec(const CodecInst& codec);
197 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
198 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
199 int32_t SetRecPayloadType(const CodecInst& codec);
200 int32_t GetRecPayloadType(CodecInst& codec);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000201 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000203 // VoE dual-streaming.
204 int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);
205 void RemoveSecondarySendCodec();
206 int GetSecondarySendCodec(CodecInst* codec);
207
niklase@google.com470e71d2011-07-07 08:21:25 +0000208 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000209 int32_t RegisterExternalTransport(Transport& transport);
210 int32_t DeRegisterExternalTransport();
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000211 int32_t ReceivedRTPPacket(const int8_t* data, int32_t length,
212 const PacketTime& packet_time);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000213 int32_t ReceivedRTCPPacket(const int8_t* data, int32_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000214
niklase@google.com470e71d2011-07-07 08:21:25 +0000215 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000216 int StartPlayingFileLocally(const char* fileName, bool loop,
217 FileFormats format,
218 int startPosition,
219 float volumeScaling,
220 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000221 const CodecInst* codecInst);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000222 int StartPlayingFileLocally(InStream* stream, FileFormats format,
223 int startPosition,
224 float volumeScaling,
225 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000226 const CodecInst* codecInst);
227 int StopPlayingFileLocally();
228 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000229 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000230 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
231 FileFormats format,
232 int startPosition,
233 float volumeScaling,
234 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000235 const CodecInst* codecInst);
236 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000237 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 StopPlayingFileAsMicrophone();
243 int IsPlayingFileAsMicrophone() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000244 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
245 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
246 int StopRecordingPlayout();
247
248 void SetMixWithMicStatus(bool mix);
249
250 // VoEExternalMediaProcessing
251 int RegisterExternalMediaProcessing(ProcessingTypes type,
252 VoEMediaProcess& processObject);
253 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000254 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000255
256 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000257 int GetSpeechOutputLevel(uint32_t& level) const;
258 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000259 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000260 bool Mute() const;
261 int SetOutputVolumePan(float left, float right);
262 int GetOutputVolumePan(float& left, float& right) const;
263 int SetChannelOutputVolumeScaling(float scaling);
264 int GetChannelOutputVolumeScaling(float& scaling) const;
265
niklase@google.com470e71d2011-07-07 08:21:25 +0000266 // VoENetEqStats
267 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000268 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
270 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000271 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
272 int* playout_buffer_delay_ms) const;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000273 int least_required_delay_ms() const { return least_required_delay_ms_; }
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000274 int SetInitialPlayoutDelay(int delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000275 int SetMinimumPlayoutDelay(int delayMs);
276 int GetPlayoutTimestamp(unsigned int& timestamp);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000277 void UpdatePlayoutTimestamp(bool rtcp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000278 int SetInitTimestamp(unsigned int timestamp);
279 int SetInitSequenceNumber(short sequenceNumber);
280
281 // VoEVideoSyncExtended
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000282 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000283
niklase@google.com470e71d2011-07-07 08:21:25 +0000284 // VoEDtmf
285 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
286 int attenuationDb, bool playDtmfEvent);
287 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
288 int attenuationDb, bool playDtmfEvent);
289 int SetDtmfPlayoutStatus(bool enable);
290 bool DtmfPlayoutStatus() const;
291 int SetSendTelephoneEventPayloadType(unsigned char type);
292 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000293
294 // VoEAudioProcessingImpl
295 int UpdateRxVadDetection(AudioFrame& audioFrame);
296 int RegisterRxVadObserver(VoERxVadCallback &observer);
297 int DeRegisterRxVadObserver();
298 int VoiceActivityIndicator(int &activity);
299#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000300 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000301 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000302 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000303 int GetRxAgcConfig(AgcConfig& config);
304#endif
305#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000306 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000307 int GetRxNsStatus(bool& enabled, NsModes& mode);
308#endif
309
310 // VoERTP_RTCP
niklase@google.com470e71d2011-07-07 08:21:25 +0000311 int RegisterRTCPObserver(VoERTCPObserver& observer);
312 int DeRegisterRTCPObserver();
313 int SetLocalSSRC(unsigned int ssrc);
314 int GetLocalSSRC(unsigned int& ssrc);
315 int GetRemoteSSRC(unsigned int& ssrc);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000316 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.org93fd25c2014-04-24 20:33:08 +0000317 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000318 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
319 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000320 int SetRTCPStatus(bool enable);
321 int GetRTCPStatus(bool& enabled);
322 int SetRTCP_CNAME(const char cName[256]);
323 int GetRTCP_CNAME(char cName[256]);
324 int GetRemoteRTCP_CNAME(char cName[256]);
325 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
326 unsigned int& timestamp,
327 unsigned int& playoutTimestamp, unsigned int* jitter,
328 unsigned short* fractionLost);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000329 int SendApplicationDefinedRTCPPacket(unsigned char subType,
niklase@google.com470e71d2011-07-07 08:21:25 +0000330 unsigned int name, const char* data,
331 unsigned short dataLengthInBytes);
332 int GetRTPStatistics(unsigned int& averageJitterMs,
333 unsigned int& maxJitterMs,
334 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000335 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000336 int GetRTPStatistics(CallStatistics& stats);
337 int SetFECStatus(bool enable, int redPayloadtype);
338 int GetFECStatus(bool& enabled, int& redPayloadtype);
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000339 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000340 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
341 int StopRTPDump(RTPDirections direction);
342 bool RTPDumpIsActive(RTPDirections direction);
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000343 // Takes ownership of the ViENetwork.
344 void SetVideoEngineBWETarget(ViENetwork* vie_network, int video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000345
niklase@google.com470e71d2011-07-07 08:21:25 +0000346 // From AudioPacketizationCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000347 int32_t SendData(FrameType frameType,
348 uint8_t payloadType,
349 uint32_t timeStamp,
350 const uint8_t* payloadData,
351 uint16_t payloadSize,
352 const RTPFragmentationHeader* fragmentation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 // From ACMVADCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000354 int32_t InFrameType(int16_t frameType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000355
pbos@webrtc.org92135212013-05-14 08:31:39 +0000356 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000357
niklase@google.com470e71d2011-07-07 08:21:25 +0000358 // From RtpData in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000359 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000360 uint16_t payloadSize,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000361 const WebRtcRTPHeader* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +0000362
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000363 bool OnRecoveredPacket(const uint8_t* packet, int packet_length);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000364
niklase@google.com470e71d2011-07-07 08:21:25 +0000365 // From RtpFeedback in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000366 int32_t OnInitializeDecoder(
pbos@webrtc.org92135212013-05-14 08:31:39 +0000367 int32_t id,
368 int8_t payloadType,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000369 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org92135212013-05-14 08:31:39 +0000370 int frequency,
371 uint8_t channels,
372 uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000373
pbos@webrtc.org92135212013-05-14 08:31:39 +0000374 void OnPacketTimeout(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000375
pbos@webrtc.org92135212013-05-14 08:31:39 +0000376 void OnReceivedPacket(int32_t id, RtpRtcpPacketType packetType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000377
pbos@webrtc.org92135212013-05-14 08:31:39 +0000378 void OnPeriodicDeadOrAlive(int32_t id,
379 RTPAliveType alive);
niklase@google.com470e71d2011-07-07 08:21:25 +0000380
pbos@webrtc.org92135212013-05-14 08:31:39 +0000381 void OnIncomingSSRCChanged(int32_t id,
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000382 uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000383
pbos@webrtc.org92135212013-05-14 08:31:39 +0000384 void OnIncomingCSRCChanged(int32_t id,
385 uint32_t CSRC, bool added);
niklase@google.com470e71d2011-07-07 08:21:25 +0000386
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000387 void ResetStatistics(uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000388
niklase@google.com470e71d2011-07-07 08:21:25 +0000389 // From RtcpFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000390 void OnApplicationDataReceived(int32_t id,
391 uint8_t subType,
392 uint32_t name,
393 uint16_t length,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000394 const uint8_t* data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000395
niklase@google.com470e71d2011-07-07 08:21:25 +0000396 // From RtpAudioFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000397 void OnReceivedTelephoneEvent(int32_t id,
398 uint8_t event,
399 bool endOfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000400
pbos@webrtc.org92135212013-05-14 08:31:39 +0000401 void OnPlayTelephoneEvent(int32_t id,
402 uint8_t event,
403 uint16_t lengthMs,
404 uint8_t volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000405
niklase@google.com470e71d2011-07-07 08:21:25 +0000406 // From Transport (called by the RTP/RTCP module)
407 int SendPacket(int /*channel*/, const void *data, int len);
408 int SendRTCPPacket(int /*channel*/, const void *data, int len);
409
niklase@google.com470e71d2011-07-07 08:21:25 +0000410 // From MixerParticipant
pbos@webrtc.org92135212013-05-14 08:31:39 +0000411 int32_t GetAudioFrame(int32_t id, AudioFrame& audioFrame);
412 int32_t NeededFrequency(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000413
niklase@google.com470e71d2011-07-07 08:21:25 +0000414 // From MonitorObserver
415 void OnPeriodicProcess();
416
niklase@google.com470e71d2011-07-07 08:21:25 +0000417 // From FileCallback
pbos@webrtc.org92135212013-05-14 08:31:39 +0000418 void PlayNotification(int32_t id,
419 uint32_t durationMs);
420 void RecordNotification(int32_t id,
421 uint32_t durationMs);
422 void PlayFileEnded(int32_t id);
423 void RecordFileEnded(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000424
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000425 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000426 {
427 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000428 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000429 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000430 {
431 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000432 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000433 bool Playing() const
434 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000435 return channel_state_.Get().playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000436 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000437 bool Sending() const
438 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000439 return channel_state_.Get().sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000440 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000441 bool Receiving() const
442 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000443 return channel_state_.Get().receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000444 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000445 bool ExternalTransport() const
446 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000447 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000448 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000449 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000450 bool ExternalMixing() const
451 {
452 return _externalMixing;
453 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000454 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000455 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000456 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000457 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000458 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000459 {
460 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000461 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000462 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000463 // Demultiplex the data to the channel's |_audioFrame|. The difference
464 // between this method and the overloaded method above is that |audio_data|
465 // does not go through transmit_mixer and APM.
466 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000467 int sample_rate,
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000468 int number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000469 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000470 uint32_t PrepareEncodeAndSend(int mixingFrequency);
471 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000472
473private:
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000474 bool ReceivePacket(const uint8_t* packet, int packet_length,
475 const RTPHeader& header, bool in_order);
476 bool HandleEncapsulation(const uint8_t* packet,
477 int packet_length,
478 const RTPHeader& header);
479 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000480 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000481 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000482 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000483 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
484 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000485 int32_t SendPacketRaw(const void *data, int len, bool RTCP);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000486 void UpdatePacketDelay(uint32_t timestamp,
487 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000488 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000489
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000490 int SetRedPayloadType(int red_payload_type);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000491 int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type,
492 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000493
niklase@google.com470e71d2011-07-07 08:21:25 +0000494 CriticalSectionWrapper& _fileCritSect;
495 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.org63420662013-10-17 18:28:55 +0000496 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000497 uint32_t _instanceId;
498 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000499
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000500 ChannelState channel_state_;
501
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000502 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000503 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
504 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +0000505 scoped_ptr<StatisticsProxy> statistics_proxy_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000506 scoped_ptr<RtpReceiver> rtp_receiver_;
507 TelephoneEventHandler* telephone_event_handler_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000508 scoped_ptr<RtpRtcp> _rtpRtcpModule;
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000509 scoped_ptr<AudioCodingModule> audio_coding_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000510 RtpDump& _rtpDumpIn;
511 RtpDump& _rtpDumpOut;
niklase@google.com470e71d2011-07-07 08:21:25 +0000512 AudioLevel _outputAudioLevel;
513 bool _externalTransport;
514 AudioFrame _audioFrame;
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +0000515 scoped_ptr<int16_t[]> mono_recording_audio_;
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +0000516 // Downsamples to the codec rate if necessary.
517 PushResampler<int16_t> input_resampler_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000518 uint8_t _audioLevel_dBov;
niklase@google.com470e71d2011-07-07 08:21:25 +0000519 FilePlayer* _inputFilePlayerPtr;
520 FilePlayer* _outputFilePlayerPtr;
521 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000522 int _inputFilePlayerId;
523 int _outputFilePlayerId;
524 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000525 bool _outputFileRecording;
526 DtmfInbandQueue _inbandDtmfQueue;
527 DtmfInband _inbandDtmfGenerator;
xians@google.com22963ab2011-08-03 12:40:23 +0000528 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000529 VoEMediaProcess* _inputExternalMediaCallbackPtr;
530 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000531 uint32_t _timeStamp;
532 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000533
534 // Timestamp of the audio pulled from NetEq.
535 uint32_t jitter_buffer_playout_timestamp_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000536 uint32_t playout_timestamp_rtp_;
537 uint32_t playout_timestamp_rtcp_;
538 uint32_t playout_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000539 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000540 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000541 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000542
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000543 scoped_ptr<CriticalSectionWrapper> ts_stats_lock_;
544
545 bool first_frame_arrived_;
546 // The rtp timestamp of the first played out audio frame.
547 uint32_t capture_start_rtp_time_stamp_;
548 // The capture ntp time (in local timebase) of the first played out audio
549 // frame.
550 int64_t capture_start_ntp_time_ms_;
551
niklase@google.com470e71d2011-07-07 08:21:25 +0000552 // uses
553 Statistics* _engineStatisticsPtr;
554 OutputMixer* _outputMixerPtr;
555 TransmitMixer* _transmitMixerPtr;
556 ProcessThread* _moduleProcessThreadPtr;
557 AudioDeviceModule* _audioDeviceModulePtr;
558 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
559 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
560 Transport* _transportPtr; // WebRtc socket or external transport
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000561 RMSLevel rms_level_;
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +0000562 scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000563 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000564 int32_t _oldVadDecision;
565 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000566 VoERTCPObserver* _rtcpObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000567 // VoEBase
niklase@google.com470e71d2011-07-07 08:21:25 +0000568 bool _externalPlayout;
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000569 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000570 bool _mixFileWithMicrophone;
niklase@google.com470e71d2011-07-07 08:21:25 +0000571 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;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000582 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000583 bool _includeAudioLevelIndication;
584 // VoENetwork
585 bool _rtpPacketTimedOut;
586 bool _rtpPacketTimeOutIsEnabled;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000587 uint32_t _rtpTimeOutSeconds;
niklase@google.com470e71d2011-07-07 08:21:25 +0000588 bool _connectionObserver;
589 VoEConnectionObserver* _connectionObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000590 AudioFrame::SpeechType _outputSpeechType;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000591 ViENetwork* vie_network_;
592 int video_channel_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000593 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000594 uint32_t _average_jitter_buffer_delay_us;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000595 int least_required_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000596 uint32_t _previousTimestamp;
597 uint16_t _recPacketDelayMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000598 // VoEAudioProcessing
599 bool _RxVadDetection;
niklase@google.com470e71d2011-07-07 08:21:25 +0000600 bool _rxAgcIsEnabled;
601 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000602 bool restored_packet_in_use_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000603};
604
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000605} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000606} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000607
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000608#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_