blob: 3377be0ee486fdc6be3fceba8c39b55290e99ac0 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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.org44f12392013-07-31 16:23:37 +000014#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.orgead8a5b2013-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.org6696fba2013-05-29 12:12:51 +000018#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
turaj@webrtc.orgead8a5b2013-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"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000030
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000031#ifdef WEBRTC_DTMF_DETECTION
pbos@webrtc.org471ae722013-05-21 13:52:32 +000032// TelephoneEventDetectionMethods, TelephoneEventObserver
33#include "webrtc/voice_engine/include/voe_dtmf.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000034#endif
35
andrew@webrtc.org510ee1b2013-09-23 23:02:24 +000036namespace webrtc {
37
tnakamura@webrtc.org0ba496b2013-07-16 19:25:04 +000038class AudioDeviceModule;
minyue@webrtc.org4489c512013-09-12 17:03:00 +000039class Config;
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +000040class CriticalSectionWrapper;
tnakamura@webrtc.org0ba496b2013-07-16 19:25:04 +000041class FileWrapper;
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +000042class ProcessThread;
43class ReceiveStatistics;
tnakamura@webrtc.org0ba496b2013-07-16 19:25:04 +000044class RtpDump;
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +000045class RTPPayloadRegistry;
46class RtpReceiver;
47class RTPReceiverAudio;
48class RtpRtcp;
49class TelephoneEventHandler;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25 +000050class ViENetwork;
tnakamura@webrtc.org0ba496b2013-07-16 19:25:04 +000051class VoEMediaProcess;
tnakamura@webrtc.org0ba496b2013-07-16 19:25:04 +000052class VoERTCPObserver;
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +000053class VoERTPObserver;
54class VoiceEngineObserver;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000055
56struct CallStatistics;
57struct ReportBlock;
58struct SenderInfo;
59
andrew@webrtc.org510ee1b2013-09-23 23:02:24 +000060namespace voe {
61
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000062class Statistics;
sprang@webrtc.org4f1f5fa2013-12-19 13:26:02 +000063class StatisticsProxy;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000064class TransmitMixer;
65class OutputMixer;
66
henrika@webrtc.orgdf08c5d2014-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.orgdf08c5d2014-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.orgdf08c5d2014-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.orgdf08c5d2014-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};
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000145
146class Channel:
147 public RtpData,
148 public RtpFeedback,
149 public RtcpFeedback,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +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
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000155 public MixerParticipant // supplies output mixer with audio frames
156{
157public:
158 enum {KNumSocketThreads = 1};
159 enum {KNumberOfSocketBuffers = 8};
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000160 virtual ~Channel();
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000161 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000162 int32_t channelId,
minyue@webrtc.org4489c512013-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.org54f03bc2013-04-09 10:09:10 +0000166 int32_t Init();
167 int32_t SetEngineInformation(
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000168 Statistics& engineStatistics,
169 OutputMixer& outputMixer,
170 TransmitMixer& transmitMixer,
171 ProcessThread& moduleProcessThread,
172 AudioDeviceModule& audioDeviceModule,
173 VoiceEngineObserver* voiceEngineObserver,
174 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000175 int32_t UpdateLocalTimeStamp();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000176
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000177 // API methods
178
179 // VoEBase
pbos@webrtc.org54f03bc2013-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();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000186
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000187 int32_t SetNetEQPlayoutMode(NetEqModes mode);
188 int32_t GetNetEQPlayoutMode(NetEqModes& mode);
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000189 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
190 int32_t DeRegisterVoiceEngineObserver();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000191
192 // VoECodec
pbos@webrtc.org54f03bc2013-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.org54f03bc2013-04-09 10:09:10 +0000200 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000201
turaj@webrtc.org7db52902012-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
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000207 // VoENetwork
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000208 int32_t RegisterExternalTransport(Transport& transport);
209 int32_t DeRegisterExternalTransport();
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25 +0000210 int32_t ReceivedRTPPacket(const int8_t* data, int32_t length,
211 const PacketTime& packet_time);
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000212 int32_t ReceivedRTCPPacket(const int8_t* data, int32_t length);
pwestin@webrtc.org912b7f72013-03-13 23:20:57 +0000213
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000214 // VoEFile
pbos@webrtc.orgca7a9a22013-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,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000220 const CodecInst* codecInst);
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000221 int StartPlayingFileLocally(InStream* stream, FileFormats format,
222 int startPosition,
223 float volumeScaling,
224 int stopPosition,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000225 const CodecInst* codecInst);
226 int StopPlayingFileLocally();
227 int IsPlayingFileLocally() const;
228 int RegisterFilePlayingToMixer();
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000229 int ScaleLocalFilePlayout(float scale);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000230 int GetLocalPlayoutPosition(int& positionMs);
pbos@webrtc.orgca7a9a22013-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,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000236 const CodecInst* codecInst);
237 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000238 FileFormats format,
239 int startPosition,
240 float volumeScaling,
241 int stopPosition,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000242 const CodecInst* codecInst);
243 int StopPlayingFileAsMicrophone();
244 int IsPlayingFileAsMicrophone() const;
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000245 int ScaleFileAsMicrophonePlayout(float scale);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +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.comb9e3afc2012-12-12 23:00:29 +0000256 int SetExternalMixing(bool enabled);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000257
258 // VoEVolumeControl
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000259 int GetSpeechOutputLevel(uint32_t& level) const;
260 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000261 int SetMute(bool enable);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +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
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000268 // VoENetEqStats
269 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org79d6daf2013-12-13 19:17:43 +0000270 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000271
272 // VoEVideoSync
pwestin@webrtc.orgf2724972013-04-11 20:23:35 +0000273 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
274 int* playout_buffer_delay_ms) const;
turaj@webrtc.orgd5577342013-05-22 20:39:43 +0000275 int least_required_delay_ms() const { return least_required_delay_ms_; }
turaj@webrtc.orgead8a5b2013-02-12 21:42:18 +0000276 int SetInitialPlayoutDelay(int delay_ms);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000277 int SetMinimumPlayoutDelay(int delayMs);
278 int GetPlayoutTimestamp(unsigned int& timestamp);
pwestin@webrtc.orgf2724972013-04-11 20:23:35 +0000279 void UpdatePlayoutTimestamp(bool rtcp);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000280 int SetInitTimestamp(unsigned int timestamp);
281 int SetInitSequenceNumber(short sequenceNumber);
282
283 // VoEVideoSyncExtended
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000284 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000285
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +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);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +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.orgca7a9a22013-05-14 08:31:39 +0000302 int SetRxAgcStatus(bool enable, AgcModes mode);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000303 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000304 int SetRxAgcConfig(AgcConfig config);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000305 int GetRxAgcConfig(AgcConfig& config);
306#endif
307#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000308 int SetRxNsStatus(bool enable, NsModes mode);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +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.org9a823222014-03-06 23:49:08 +0000321 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
322 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
323 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000324 int SetRTCPStatus(bool enable);
325 int GetRTCPStatus(bool& enabled);
326 int SetRTCP_CNAME(const char cName[256]);
327 int GetRTCP_CNAME(char cName[256]);
328 int GetRemoteRTCP_CNAME(char cName[256]);
329 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
330 unsigned int& timestamp,
331 unsigned int& playoutTimestamp, unsigned int* jitter,
332 unsigned short* fractionLost);
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000333 int SendApplicationDefinedRTCPPacket(unsigned char subType,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000334 unsigned int name, const char* data,
335 unsigned short dataLengthInBytes);
336 int GetRTPStatistics(unsigned int& averageJitterMs,
337 unsigned int& maxJitterMs,
338 unsigned int& discardedPackets);
339 int GetRemoteRTCPSenderInfo(SenderInfo* sender_info);
340 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
341 int GetRTPStatistics(CallStatistics& stats);
342 int SetFECStatus(bool enable, int redPayloadtype);
343 int GetFECStatus(bool& enabled, int& redPayloadtype);
pwestin@webrtc.orgb8171ff2013-06-05 15:33:20 +0000344 void SetNACKStatus(bool enable, int maxNumberOfPackets);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000345 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
346 int StopRTPDump(RTPDirections direction);
347 bool RTPDumpIsActive(RTPDirections direction);
roosa@google.comca771492012-12-12 21:31:41 +0000348 uint32_t LastRemoteTimeStamp() { return _lastRemoteTimeStamp; }
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25 +0000349 // Takes ownership of the ViENetwork.
350 void SetVideoEngineBWETarget(ViENetwork* vie_network, int video_channel);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000351
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000352 // From AudioPacketizationCallback in the ACM
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000353 int32_t SendData(FrameType frameType,
354 uint8_t payloadType,
355 uint32_t timeStamp,
356 const uint8_t* payloadData,
357 uint16_t payloadSize,
358 const RTPFragmentationHeader* fragmentation);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000359 // From ACMVADCallback in the ACM
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000360 int32_t InFrameType(int16_t frameType);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000361
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000362 int32_t OnRxVadDetected(int vadDecision);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000363
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000364 // From RtpData in the RTP/RTCP module
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000365 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000366 uint16_t payloadSize,
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000367 const WebRtcRTPHeader* rtpHeader);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000368
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000369 bool OnRecoveredPacket(const uint8_t* packet, int packet_length);
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000370
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000371 // From RtpFeedback in the RTP/RTCP module
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000372 int32_t OnInitializeDecoder(
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000373 int32_t id,
374 int8_t payloadType,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000375 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000376 int frequency,
377 uint8_t channels,
378 uint32_t rate);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000379
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000380 void OnPacketTimeout(int32_t id);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000381
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000382 void OnReceivedPacket(int32_t id, RtpRtcpPacketType packetType);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000383
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000384 void OnPeriodicDeadOrAlive(int32_t id,
385 RTPAliveType alive);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000386
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000387 void OnIncomingSSRCChanged(int32_t id,
stefan@webrtc.orga20e2d42013-08-21 20:58:21 +0000388 uint32_t ssrc);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000389
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000390 void OnIncomingCSRCChanged(int32_t id,
391 uint32_t CSRC, bool added);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000392
stefan@webrtc.orga20e2d42013-08-21 20:58:21 +0000393 void ResetStatistics(uint32_t ssrc);
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000394
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000395 // From RtcpFeedback in the RTP/RTCP module
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000396 void OnApplicationDataReceived(int32_t id,
397 uint8_t subType,
398 uint32_t name,
399 uint16_t length,
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000400 const uint8_t* data);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000401
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000402 // From RtpAudioFeedback in the RTP/RTCP module
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000403 void OnReceivedTelephoneEvent(int32_t id,
404 uint8_t event,
405 bool endOfEvent);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000406
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000407 void OnPlayTelephoneEvent(int32_t id,
408 uint8_t event,
409 uint16_t lengthMs,
410 uint8_t volume);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000411
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000412 // From Transport (called by the RTP/RTCP module)
413 int SendPacket(int /*channel*/, const void *data, int len);
414 int SendRTCPPacket(int /*channel*/, const void *data, int len);
415
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000416 // From MixerParticipant
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000417 int32_t GetAudioFrame(int32_t id, AudioFrame& audioFrame);
418 int32_t NeededFrequency(int32_t id);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000419
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000420 // From MonitorObserver
421 void OnPeriodicProcess();
422
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000423 // From FileCallback
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000424 void PlayNotification(int32_t id,
425 uint32_t durationMs);
426 void RecordNotification(int32_t id,
427 uint32_t durationMs);
428 void PlayFileEnded(int32_t id);
429 void RecordFileEnded(int32_t id);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000430
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000431 uint32_t InstanceId() const
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000432 {
433 return _instanceId;
434 }
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000435 int32_t ChannelId() const
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000436 {
437 return _channelId;
438 }
439 bool Playing() const
440 {
henrika@webrtc.orgdf08c5d2014-03-18 10:32:33 +0000441 return channel_state_.Get().playing;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000442 }
443 bool Sending() const
444 {
henrika@webrtc.orgdf08c5d2014-03-18 10:32:33 +0000445 return channel_state_.Get().sending;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000446 }
447 bool Receiving() const
448 {
henrika@webrtc.orgdf08c5d2014-03-18 10:32:33 +0000449 return channel_state_.Get().receiving;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000450 }
451 bool ExternalTransport() const
452 {
henrika@webrtc.orgdf08c5d2014-03-18 10:32:33 +0000453 CriticalSectionScoped cs(&_callbackCritSect);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000454 return _externalTransport;
455 }
roosa@google.comb9e3afc2012-12-12 23:00:29 +0000456 bool ExternalMixing() const
457 {
458 return _externalMixing;
459 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000460 RtpRtcp* RtpRtcpModulePtr() const
461 {
462 return _rtpRtcpModule.get();
463 }
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000464 int8_t OutputEnergyLevel() const
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000465 {
466 return _outputAudioLevel.Level();
467 }
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000468 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org44f12392013-07-31 16:23:37 +0000469 // Demultiplex the data to the channel's |_audioFrame|. The difference
470 // between this method and the overloaded method above is that |audio_data|
471 // does not go through transmit_mixer and APM.
472 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org0e6fa8c2013-07-31 16:27:42 +0000473 int sample_rate,
xians@webrtc.org44f12392013-07-31 16:23:37 +0000474 int number_of_frames,
xians@webrtc.org0e6fa8c2013-07-31 16:27:42 +0000475 int number_of_channels);
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000476 uint32_t PrepareEncodeAndSend(int mixingFrequency);
477 uint32_t EncodeAndSend();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000478
479private:
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000480 bool ReceivePacket(const uint8_t* packet, int packet_length,
481 const RTPHeader& header, bool in_order);
482 bool HandleEncapsulation(const uint8_t* packet,
483 int packet_length,
484 const RTPHeader& header);
485 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org7e97e4c2013-11-08 15:18:52 +0000486 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.org9aeef322013-06-07 01:43:12 +0000487 int ResendPackets(const uint16_t* sequence_numbers, int length);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000488 int InsertInbandDtmfTone();
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000489 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
490 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000491 int32_t SendPacketRaw(const void *data, int len, bool RTCP);
pwestin@webrtc.orgf2724972013-04-11 20:23:35 +0000492 void UpdatePacketDelay(uint32_t timestamp,
493 uint16_t sequenceNumber);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000494 void RegisterReceiveCodecsToRTPModule();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000495
turaj@webrtc.org7db52902012-12-11 02:15:12 +0000496 int SetRedPayloadType(int red_payload_type);
wu@webrtc.org9a823222014-03-06 23:49:08 +0000497 int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type,
498 unsigned char id);
andrew@webrtc.org510ee1b2013-09-23 23:02:24 +0000499
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000500 CriticalSectionWrapper& _fileCritSect;
501 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.orgf7651ef2013-10-17 18:28:55 +0000502 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000503 uint32_t _instanceId;
504 int32_t _channelId;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000505
henrika@webrtc.orgdf08c5d2014-03-18 10:32:33 +0000506 ChannelState channel_state_;
507
stefan@webrtc.org6696fba2013-05-29 12:12:51 +0000508 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000509 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
510 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
sprang@webrtc.org4f1f5fa2013-12-19 13:26:02 +0000511 scoped_ptr<StatisticsProxy> statistics_proxy_;
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000512 scoped_ptr<RtpReceiver> rtp_receiver_;
513 TelephoneEventHandler* telephone_event_handler_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000514 scoped_ptr<RtpRtcp> _rtpRtcpModule;
andrew@webrtc.org510ee1b2013-09-23 23:02:24 +0000515 scoped_ptr<AudioCodingModule> audio_coding_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000516 RtpDump& _rtpDumpIn;
517 RtpDump& _rtpDumpOut;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000518 AudioLevel _outputAudioLevel;
519 bool _externalTransport;
520 AudioFrame _audioFrame;
andrew@webrtc.orgf7c73b52014-04-03 21:56:01 +0000521 scoped_ptr<int16_t[]> mono_recording_audio_;
xians@webrtc.org44f12392013-07-31 16:23:37 +0000522 // Resampler is used when input data is stereo while codec is mono.
523 PushResampler input_resampler_;
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000524 uint8_t _audioLevel_dBov;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000525 FilePlayer* _inputFilePlayerPtr;
526 FilePlayer* _outputFilePlayerPtr;
527 FileRecorder* _outputFileRecorderPtr;
528 int _inputFilePlayerId;
529 int _outputFilePlayerId;
530 int _outputFileRecorderId;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000531 bool _outputFileRecording;
532 DtmfInbandQueue _inbandDtmfQueue;
533 DtmfInband _inbandDtmfGenerator;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000534 bool _outputExternalMedia;
535 VoEMediaProcess* _inputExternalMediaCallbackPtr;
536 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000537 uint32_t _timeStamp;
538 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.orgf1b92fd2013-12-13 21:05:07 +0000539
540 // Timestamp of the audio pulled from NetEq.
541 uint32_t jitter_buffer_playout_timestamp_;
pwestin@webrtc.orgf2724972013-04-11 20:23:35 +0000542 uint32_t playout_timestamp_rtp_;
543 uint32_t playout_timestamp_rtcp_;
544 uint32_t playout_delay_ms_;
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000545 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org5ce87232013-07-31 16:30:19 +0000546 uint16_t send_sequence_number_;
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000547 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.orgf2724972013-04-11 20:23:35 +0000548
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000549 // uses
550 Statistics* _engineStatisticsPtr;
551 OutputMixer* _outputMixerPtr;
552 TransmitMixer* _transmitMixerPtr;
553 ProcessThread* _moduleProcessThreadPtr;
554 AudioDeviceModule* _audioDeviceModulePtr;
555 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
556 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
557 Transport* _transportPtr; // WebRtc socket or external transport
andrew@webrtc.org80142aa2013-09-18 22:37:32 +0000558 scoped_ptr<AudioProcessing> rtp_audioproc_;
559 scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000560 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000561 int32_t _oldVadDecision;
562 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000563 VoERTPObserver* _rtpObserverPtr;
564 VoERTCPObserver* _rtcpObserverPtr;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000565 // VoEBase
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000566 bool _externalPlayout;
roosa@google.comb9e3afc2012-12-12 23:00:29 +0000567 bool _externalMixing;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000568 bool _mixFileWithMicrophone;
569 bool _rtpObserver;
570 bool _rtcpObserver;
571 // VoEVolumeControl
572 bool _mute;
573 float _panLeft;
574 float _panRight;
575 float _outputGain;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000576 // VoEDtmf
577 bool _playOutbandDtmfEvent;
578 bool _playInbandDtmfEvent;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000579 // VoeRTP_RTCP
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000580 uint32_t _lastLocalTimeStamp;
roosa@google.comca771492012-12-12 21:31:41 +0000581 uint32_t _lastRemoteTimeStamp;
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000582 int8_t _lastPayloadType;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000583 bool _includeAudioLevelIndication;
584 // VoENetwork
585 bool _rtpPacketTimedOut;
586 bool _rtpPacketTimeOutIsEnabled;
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000587 uint32_t _rtpTimeOutSeconds;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000588 bool _connectionObserver;
589 VoEConnectionObserver* _connectionObserverPtr;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000590 AudioFrame::SpeechType _outputSpeechType;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25 +0000591 ViENetwork* vie_network_;
592 int video_channel_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000593 // VoEVideoSync
pwestin@webrtc.orgf2724972013-04-11 20:23:35 +0000594 uint32_t _average_jitter_buffer_delay_us;
turaj@webrtc.orgd5577342013-05-22 20:39:43 +0000595 int least_required_delay_ms_;
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000596 uint32_t _previousTimestamp;
597 uint16_t _recPacketDelayMs;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000598 // VoEAudioProcessing
599 bool _RxVadDetection;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000600 bool _rxAgcIsEnabled;
601 bool _rxNsIsEnabled;
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000602 bool restored_packet_in_use_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000603};
604
pbos@webrtc.org3b89e102013-07-03 15:12:26 +0000605} // namespace voe
pbos@webrtc.org3b89e102013-07-03 15:12:26 +0000606} // namespace webrtc
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000607
608#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H