blob: 3c49d9bd2975c79091ff9dacaf4444998102d030 [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"
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +000019#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000020#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000021#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
22#include "webrtc/modules/utility/interface/file_player.h"
23#include "webrtc/modules/utility/interface/file_recorder.h"
24#include "webrtc/system_wrappers/interface/scoped_ptr.h"
25#include "webrtc/voice_engine/dtmf_inband.h"
26#include "webrtc/voice_engine/dtmf_inband_queue.h"
27#include "webrtc/voice_engine/include/voe_audio_processing.h"
28#include "webrtc/voice_engine/include/voe_network.h"
29#include "webrtc/voice_engine/level_indicator.h"
30#include "webrtc/voice_engine/shared_data.h"
31#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000032
niklase@google.com470e71d2011-07-07 08:21:25 +000033#ifdef WEBRTC_DTMF_DETECTION
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000034// TelephoneEventDetectionMethods, TelephoneEventObserver
35#include "webrtc/voice_engine/include/voe_dtmf.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000036#endif
37
wu@webrtc.org94454b72014-06-05 20:34:08 +000038namespace rtc {
39
40class TimestampWrapAroundHandler;
41}
42
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000043namespace webrtc {
44
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000045class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000046class Config;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000047class CriticalSectionWrapper;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000048class FileWrapper;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049class ProcessThread;
50class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000051class RemoteNtpTimeEstimator;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000052class RtpDump;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000053class RTPPayloadRegistry;
54class RtpReceiver;
55class RTPReceiverAudio;
56class RtpRtcp;
57class TelephoneEventHandler;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +000058class ViENetwork;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000059class VoEMediaProcess;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000060class VoERTCPObserver;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000061class VoERTPObserver;
62class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000063
64struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000065struct ReportBlock;
66struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000067
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000068namespace voe {
69
niklase@google.com470e71d2011-07-07 08:21:25 +000070class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000071class StatisticsProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000072class TransmitMixer;
73class OutputMixer;
74
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000075// Helper class to simplify locking scheme for members that are accessed from
76// multiple threads.
77// Example: a member can be set on thread T1 and read by an internal audio
78// thread T2. Accessing the member via this class ensures that we are
79// safe and also avoid TSan v2 warnings.
80class ChannelState {
81 public:
82 struct State {
83 State() : rx_apm_is_enabled(false),
84 input_external_media(false),
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000085 output_file_playing(false),
86 input_file_playing(false),
87 playing(false),
88 sending(false),
89 receiving(false) {}
90
91 bool rx_apm_is_enabled;
92 bool input_external_media;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000093 bool output_file_playing;
94 bool input_file_playing;
95 bool playing;
96 bool sending;
97 bool receiving;
98 };
99
100 ChannelState() : lock_(CriticalSectionWrapper::CreateCriticalSection()) {
101 }
102 virtual ~ChannelState() {}
103
104 void Reset() {
105 CriticalSectionScoped lock(lock_.get());
106 state_ = State();
107 }
108
109 State Get() const {
110 CriticalSectionScoped lock(lock_.get());
111 return state_;
112 }
113
114 void SetRxApmIsEnabled(bool enable) {
115 CriticalSectionScoped lock(lock_.get());
116 state_.rx_apm_is_enabled = enable;
117 }
118
119 void SetInputExternalMedia(bool enable) {
120 CriticalSectionScoped lock(lock_.get());
121 state_.input_external_media = enable;
122 }
123
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000124 void SetOutputFilePlaying(bool enable) {
125 CriticalSectionScoped lock(lock_.get());
126 state_.output_file_playing = enable;
127 }
128
129 void SetInputFilePlaying(bool enable) {
130 CriticalSectionScoped lock(lock_.get());
131 state_.input_file_playing = enable;
132 }
133
134 void SetPlaying(bool enable) {
135 CriticalSectionScoped lock(lock_.get());
136 state_.playing = enable;
137 }
138
139 void SetSending(bool enable) {
140 CriticalSectionScoped lock(lock_.get());
141 state_.sending = enable;
142 }
143
144 void SetReceiving(bool enable) {
145 CriticalSectionScoped lock(lock_.get());
146 state_.receiving = enable;
147 }
148
149private:
150 scoped_ptr<CriticalSectionWrapper> lock_;
151 State state_;
152};
niklase@google.com470e71d2011-07-07 08:21:25 +0000153
154class Channel:
155 public RtpData,
156 public RtpFeedback,
157 public RtcpFeedback,
niklase@google.com470e71d2011-07-07 08:21:25 +0000158 public FileCallback, // receiving notification from file player & recorder
159 public Transport,
160 public RtpAudioFeedback,
161 public AudioPacketizationCallback, // receive encoded packets from the ACM
162 public ACMVADCallback, // receive voice activity from the ACM
niklase@google.com470e71d2011-07-07 08:21:25 +0000163 public MixerParticipant // supplies output mixer with audio frames
164{
165public:
166 enum {KNumSocketThreads = 1};
167 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +0000168 virtual ~Channel();
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000169 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000170 int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000171 uint32_t instanceId,
172 const Config& config);
173 Channel(int32_t channelId, uint32_t instanceId, const Config& config);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000174 int32_t Init();
175 int32_t SetEngineInformation(
niklase@google.com470e71d2011-07-07 08:21:25 +0000176 Statistics& engineStatistics,
177 OutputMixer& outputMixer,
178 TransmitMixer& transmitMixer,
179 ProcessThread& moduleProcessThread,
180 AudioDeviceModule& audioDeviceModule,
181 VoiceEngineObserver* voiceEngineObserver,
182 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000183 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000184
niklase@google.com470e71d2011-07-07 08:21:25 +0000185 // API methods
186
187 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000188 int32_t StartPlayout();
189 int32_t StopPlayout();
190 int32_t StartSend();
191 int32_t StopSend();
192 int32_t StartReceiving();
193 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000195 int32_t SetNetEQPlayoutMode(NetEqModes mode);
196 int32_t GetNetEQPlayoutMode(NetEqModes& mode);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000197 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
198 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000199
200 // VoECodec
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000201 int32_t GetSendCodec(CodecInst& codec);
202 int32_t GetRecCodec(CodecInst& codec);
203 int32_t SetSendCodec(const CodecInst& codec);
204 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
205 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
206 int32_t SetRecPayloadType(const CodecInst& codec);
207 int32_t GetRecPayloadType(CodecInst& codec);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000208 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000209
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000210 // VoE dual-streaming.
211 int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);
212 void RemoveSecondarySendCodec();
213 int GetSecondarySendCodec(CodecInst* codec);
214
niklase@google.com470e71d2011-07-07 08:21:25 +0000215 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000216 int32_t RegisterExternalTransport(Transport& transport);
217 int32_t DeRegisterExternalTransport();
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000218 int32_t ReceivedRTPPacket(const int8_t* data, int32_t length,
219 const PacketTime& packet_time);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000220 int32_t ReceivedRTCPPacket(const int8_t* data, int32_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000221
niklase@google.com470e71d2011-07-07 08:21:25 +0000222 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000223 int StartPlayingFileLocally(const char* fileName, bool loop,
224 FileFormats format,
225 int startPosition,
226 float volumeScaling,
227 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000228 const CodecInst* codecInst);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000229 int StartPlayingFileLocally(InStream* stream, FileFormats format,
230 int startPosition,
231 float volumeScaling,
232 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000233 const CodecInst* codecInst);
234 int StopPlayingFileLocally();
235 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000236 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000237 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
238 FileFormats format,
239 int startPosition,
240 float volumeScaling,
241 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000242 const CodecInst* codecInst);
243 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000244 FileFormats format,
245 int startPosition,
246 float volumeScaling,
247 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000248 const CodecInst* codecInst);
249 int StopPlayingFileAsMicrophone();
250 int IsPlayingFileAsMicrophone() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000251 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
252 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
253 int StopRecordingPlayout();
254
255 void SetMixWithMicStatus(bool mix);
256
257 // VoEExternalMediaProcessing
258 int RegisterExternalMediaProcessing(ProcessingTypes type,
259 VoEMediaProcess& processObject);
260 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000261 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000262
263 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000264 int GetSpeechOutputLevel(uint32_t& level) const;
265 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000266 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000267 bool Mute() const;
268 int SetOutputVolumePan(float left, float right);
269 int GetOutputVolumePan(float& left, float& right) const;
270 int SetChannelOutputVolumeScaling(float scaling);
271 int GetChannelOutputVolumeScaling(float& scaling) const;
272
niklase@google.com470e71d2011-07-07 08:21:25 +0000273 // VoENetEqStats
274 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000275 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000276
277 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000278 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
279 int* playout_buffer_delay_ms) const;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000280 int least_required_delay_ms() const { return least_required_delay_ms_; }
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000281 int SetInitialPlayoutDelay(int delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000282 int SetMinimumPlayoutDelay(int delayMs);
283 int GetPlayoutTimestamp(unsigned int& timestamp);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000284 void UpdatePlayoutTimestamp(bool rtcp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000285 int SetInitTimestamp(unsigned int timestamp);
286 int SetInitSequenceNumber(short sequenceNumber);
287
288 // VoEVideoSyncExtended
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000289 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000290
niklase@google.com470e71d2011-07-07 08:21:25 +0000291 // VoEDtmf
292 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
293 int attenuationDb, bool playDtmfEvent);
294 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
295 int attenuationDb, bool playDtmfEvent);
296 int SetDtmfPlayoutStatus(bool enable);
297 bool DtmfPlayoutStatus() const;
298 int SetSendTelephoneEventPayloadType(unsigned char type);
299 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000300
301 // VoEAudioProcessingImpl
302 int UpdateRxVadDetection(AudioFrame& audioFrame);
303 int RegisterRxVadObserver(VoERxVadCallback &observer);
304 int DeRegisterRxVadObserver();
305 int VoiceActivityIndicator(int &activity);
306#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000307 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000308 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000309 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000310 int GetRxAgcConfig(AgcConfig& config);
311#endif
312#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000313 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000314 int GetRxNsStatus(bool& enabled, NsModes& mode);
315#endif
316
317 // VoERTP_RTCP
niklase@google.com470e71d2011-07-07 08:21:25 +0000318 int RegisterRTCPObserver(VoERTCPObserver& observer);
319 int DeRegisterRTCPObserver();
320 int SetLocalSSRC(unsigned int ssrc);
321 int GetLocalSSRC(unsigned int& ssrc);
322 int GetRemoteSSRC(unsigned int& ssrc);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000323 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.org93fd25c2014-04-24 20:33:08 +0000324 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000325 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
326 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000327 int SetRTCPStatus(bool enable);
328 int GetRTCPStatus(bool& enabled);
329 int SetRTCP_CNAME(const char cName[256]);
330 int GetRTCP_CNAME(char cName[256]);
331 int GetRemoteRTCP_CNAME(char cName[256]);
332 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
333 unsigned int& timestamp,
334 unsigned int& playoutTimestamp, unsigned int* jitter,
335 unsigned short* fractionLost);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000336 int SendApplicationDefinedRTCPPacket(unsigned char subType,
niklase@google.com470e71d2011-07-07 08:21:25 +0000337 unsigned int name, const char* data,
338 unsigned short dataLengthInBytes);
339 int GetRTPStatistics(unsigned int& averageJitterMs,
340 unsigned int& maxJitterMs,
341 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000342 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000343 int GetRTPStatistics(CallStatistics& stats);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000344 int SetREDStatus(bool enable, int redPayloadtype);
345 int GetREDStatus(bool& enabled, int& redPayloadtype);
346 int SetCodecFECStatus(bool enable);
347 bool GetCodecFECStatus();
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000348 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000349 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
350 int StopRTPDump(RTPDirections direction);
351 bool RTPDumpIsActive(RTPDirections direction);
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000352 // Takes ownership of the ViENetwork.
353 void SetVideoEngineBWETarget(ViENetwork* vie_network, int video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000354
niklase@google.com470e71d2011-07-07 08:21:25 +0000355 // From AudioPacketizationCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000356 int32_t SendData(FrameType frameType,
357 uint8_t payloadType,
358 uint32_t timeStamp,
359 const uint8_t* payloadData,
360 uint16_t payloadSize,
361 const RTPFragmentationHeader* fragmentation);
niklase@google.com470e71d2011-07-07 08:21:25 +0000362 // From ACMVADCallback in the ACM
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000363 int32_t InFrameType(int16_t frameType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000364
pbos@webrtc.org92135212013-05-14 08:31:39 +0000365 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000366
niklase@google.com470e71d2011-07-07 08:21:25 +0000367 // From RtpData in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000368 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000369 uint16_t payloadSize,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000370 const WebRtcRTPHeader* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +0000371
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000372 bool OnRecoveredPacket(const uint8_t* packet, int packet_length);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000373
niklase@google.com470e71d2011-07-07 08:21:25 +0000374 // From RtpFeedback in the RTP/RTCP module
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000375 int32_t OnInitializeDecoder(
pbos@webrtc.org92135212013-05-14 08:31:39 +0000376 int32_t id,
377 int8_t payloadType,
leozwang@webrtc.org813e4b02012-03-01 18:34:25 +0000378 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org92135212013-05-14 08:31:39 +0000379 int frequency,
380 uint8_t channels,
381 uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000382
pbos@webrtc.org92135212013-05-14 08:31:39 +0000383 void OnPacketTimeout(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000384
pbos@webrtc.org92135212013-05-14 08:31:39 +0000385 void OnReceivedPacket(int32_t id, RtpRtcpPacketType packetType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000386
pbos@webrtc.org92135212013-05-14 08:31:39 +0000387 void OnPeriodicDeadOrAlive(int32_t id,
388 RTPAliveType alive);
niklase@google.com470e71d2011-07-07 08:21:25 +0000389
pbos@webrtc.org92135212013-05-14 08:31:39 +0000390 void OnIncomingSSRCChanged(int32_t id,
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000391 uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000392
pbos@webrtc.org92135212013-05-14 08:31:39 +0000393 void OnIncomingCSRCChanged(int32_t id,
394 uint32_t CSRC, bool added);
niklase@google.com470e71d2011-07-07 08:21:25 +0000395
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000396 void ResetStatistics(uint32_t ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000397
niklase@google.com470e71d2011-07-07 08:21:25 +0000398 // From RtcpFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000399 void OnApplicationDataReceived(int32_t id,
400 uint8_t subType,
401 uint32_t name,
402 uint16_t length,
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000403 const uint8_t* data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000404
niklase@google.com470e71d2011-07-07 08:21:25 +0000405 // From RtpAudioFeedback in the RTP/RTCP module
pbos@webrtc.org92135212013-05-14 08:31:39 +0000406 void OnReceivedTelephoneEvent(int32_t id,
407 uint8_t event,
408 bool endOfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000409
pbos@webrtc.org92135212013-05-14 08:31:39 +0000410 void OnPlayTelephoneEvent(int32_t id,
411 uint8_t event,
412 uint16_t lengthMs,
413 uint8_t volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000414
niklase@google.com470e71d2011-07-07 08:21:25 +0000415 // From Transport (called by the RTP/RTCP module)
416 int SendPacket(int /*channel*/, const void *data, int len);
417 int SendRTCPPacket(int /*channel*/, const void *data, int len);
418
niklase@google.com470e71d2011-07-07 08:21:25 +0000419 // From MixerParticipant
pbos@webrtc.org92135212013-05-14 08:31:39 +0000420 int32_t GetAudioFrame(int32_t id, AudioFrame& audioFrame);
421 int32_t NeededFrequency(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000422
niklase@google.com470e71d2011-07-07 08:21:25 +0000423 // From MonitorObserver
424 void OnPeriodicProcess();
425
niklase@google.com470e71d2011-07-07 08:21:25 +0000426 // From FileCallback
pbos@webrtc.org92135212013-05-14 08:31:39 +0000427 void PlayNotification(int32_t id,
428 uint32_t durationMs);
429 void RecordNotification(int32_t id,
430 uint32_t durationMs);
431 void PlayFileEnded(int32_t id);
432 void RecordFileEnded(int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000433
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000434 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000435 {
436 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000437 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000438 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000439 {
440 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000441 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000442 bool Playing() const
443 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000444 return channel_state_.Get().playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000445 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000446 bool Sending() const
447 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000448 return channel_state_.Get().sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000449 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000450 bool Receiving() const
451 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000452 return channel_state_.Get().receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000453 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000454 bool ExternalTransport() const
455 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000456 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000457 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000458 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000459 bool ExternalMixing() const
460 {
461 return _externalMixing;
462 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000463 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000464 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000465 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000466 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000467 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000468 {
469 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000470 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000471 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000472 // Demultiplex the data to the channel's |_audioFrame|. The difference
473 // between this method and the overloaded method above is that |audio_data|
474 // does not go through transmit_mixer and APM.
475 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000476 int sample_rate,
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000477 int number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000478 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000479 uint32_t PrepareEncodeAndSend(int mixingFrequency);
480 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000481
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000482 // From BitrateObserver (called by the RTP/RTCP module).
483 void OnNetworkChanged(const uint32_t bitrate_bps,
484 const uint8_t fraction_lost, // 0 - 255.
485 const uint32_t rtt);
486
niklase@google.com470e71d2011-07-07 08:21:25 +0000487private:
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000488 bool ReceivePacket(const uint8_t* packet, int packet_length,
489 const RTPHeader& header, bool in_order);
490 bool HandleEncapsulation(const uint8_t* packet,
491 int packet_length,
492 const RTPHeader& header);
493 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000494 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000495 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000496 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000497 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
498 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000499 int32_t SendPacketRaw(const void *data, int len, bool RTCP);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000500 void UpdatePacketDelay(uint32_t timestamp,
501 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000502 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000503
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000504 int SetRedPayloadType(int red_payload_type);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000505 int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type,
506 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000507
wu@webrtc.org94454b72014-06-05 20:34:08 +0000508 int32_t GetPlayoutFrequency();
509
niklase@google.com470e71d2011-07-07 08:21:25 +0000510 CriticalSectionWrapper& _fileCritSect;
511 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.org63420662013-10-17 18:28:55 +0000512 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000513 uint32_t _instanceId;
514 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000515
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000516 ChannelState channel_state_;
517
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000518 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000519 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
520 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +0000521 scoped_ptr<StatisticsProxy> statistics_proxy_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000522 scoped_ptr<RtpReceiver> rtp_receiver_;
523 TelephoneEventHandler* telephone_event_handler_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000524 scoped_ptr<RtpRtcp> _rtpRtcpModule;
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000525 scoped_ptr<AudioCodingModule> audio_coding_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000526 RtpDump& _rtpDumpIn;
527 RtpDump& _rtpDumpOut;
niklase@google.com470e71d2011-07-07 08:21:25 +0000528 AudioLevel _outputAudioLevel;
529 bool _externalTransport;
530 AudioFrame _audioFrame;
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +0000531 scoped_ptr<int16_t[]> mono_recording_audio_;
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +0000532 // Downsamples to the codec rate if necessary.
533 PushResampler<int16_t> input_resampler_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000534 uint8_t _audioLevel_dBov;
niklase@google.com470e71d2011-07-07 08:21:25 +0000535 FilePlayer* _inputFilePlayerPtr;
536 FilePlayer* _outputFilePlayerPtr;
537 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000538 int _inputFilePlayerId;
539 int _outputFilePlayerId;
540 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000541 bool _outputFileRecording;
542 DtmfInbandQueue _inbandDtmfQueue;
543 DtmfInband _inbandDtmfGenerator;
xians@google.com22963ab2011-08-03 12:40:23 +0000544 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000545 VoEMediaProcess* _inputExternalMediaCallbackPtr;
546 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000547 uint32_t _timeStamp;
548 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000549
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000550 scoped_ptr<RemoteNtpTimeEstimator> ntp_estimator_;
551
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000552 // Timestamp of the audio pulled from NetEq.
553 uint32_t jitter_buffer_playout_timestamp_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000554 uint32_t playout_timestamp_rtp_;
555 uint32_t playout_timestamp_rtcp_;
556 uint32_t playout_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000557 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000558 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000559 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000560
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000561 scoped_ptr<CriticalSectionWrapper> ts_stats_lock_;
562
wu@webrtc.org94454b72014-06-05 20:34:08 +0000563 scoped_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000564 // The rtp timestamp of the first played out audio frame.
wu@webrtc.org94454b72014-06-05 20:34:08 +0000565 int64_t capture_start_rtp_time_stamp_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000566 // The capture ntp time (in local timebase) of the first played out audio
567 // frame.
568 int64_t capture_start_ntp_time_ms_;
569
niklase@google.com470e71d2011-07-07 08:21:25 +0000570 // uses
571 Statistics* _engineStatisticsPtr;
572 OutputMixer* _outputMixerPtr;
573 TransmitMixer* _transmitMixerPtr;
574 ProcessThread* _moduleProcessThreadPtr;
575 AudioDeviceModule* _audioDeviceModulePtr;
576 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
577 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
578 Transport* _transportPtr; // WebRtc socket or external transport
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000579 RMSLevel rms_level_;
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +0000580 scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000581 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000582 int32_t _oldVadDecision;
583 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000584 VoERTCPObserver* _rtcpObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000585 // VoEBase
niklase@google.com470e71d2011-07-07 08:21:25 +0000586 bool _externalPlayout;
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000587 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000588 bool _mixFileWithMicrophone;
niklase@google.com470e71d2011-07-07 08:21:25 +0000589 bool _rtcpObserver;
590 // VoEVolumeControl
591 bool _mute;
592 float _panLeft;
593 float _panRight;
594 float _outputGain;
niklase@google.com470e71d2011-07-07 08:21:25 +0000595 // VoEDtmf
596 bool _playOutbandDtmfEvent;
597 bool _playInbandDtmfEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000598 // VoeRTP_RTCP
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000599 uint32_t _lastLocalTimeStamp;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000600 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000601 bool _includeAudioLevelIndication;
602 // VoENetwork
603 bool _rtpPacketTimedOut;
604 bool _rtpPacketTimeOutIsEnabled;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000605 uint32_t _rtpTimeOutSeconds;
niklase@google.com470e71d2011-07-07 08:21:25 +0000606 bool _connectionObserver;
607 VoEConnectionObserver* _connectionObserverPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000608 AudioFrame::SpeechType _outputSpeechType;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000609 ViENetwork* vie_network_;
610 int video_channel_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000611 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000612 uint32_t _average_jitter_buffer_delay_us;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000613 int least_required_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000614 uint32_t _previousTimestamp;
615 uint16_t _recPacketDelayMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000616 // VoEAudioProcessing
617 bool _RxVadDetection;
niklase@google.com470e71d2011-07-07 08:21:25 +0000618 bool _rxAgcIsEnabled;
619 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000620 bool restored_packet_in_use_;
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000621 // RtcpBandwidthObserver
622 scoped_ptr<BitrateController> bitrate_controller_;
623 scoped_ptr<RtcpBandwidthObserver> rtcp_bandwidth_observer_;
624 scoped_ptr<BitrateObserver> send_bitrate_observer_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000625};
626
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000627} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000628} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000629
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000630#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_