blob: d3d6d89ad9a3f7a88593acd780699a836fe372db [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
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000014#include "webrtc/base/scoped_ptr.h"
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000015#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000016#include "webrtc/common_types.h"
17#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
18#include "webrtc/modules/audio_conference_mixer/interface/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000019#include "webrtc/modules/audio_processing/rms_level.h"
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +000020#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
stefan@webrtc.org8e24d872014-09-02 18:58:24 +000021#include "webrtc/modules/rtp_rtcp/interface/remote_ntp_time_estimator.h"
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000022#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000023#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
24#include "webrtc/modules/utility/interface/file_player.h"
25#include "webrtc/modules/utility/interface/file_recorder.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000026#include "webrtc/voice_engine/dtmf_inband.h"
27#include "webrtc/voice_engine/dtmf_inband_queue.h"
28#include "webrtc/voice_engine/include/voe_audio_processing.h"
29#include "webrtc/voice_engine/include/voe_network.h"
30#include "webrtc/voice_engine/level_indicator.h"
minyue@webrtc.org74aaf292014-07-16 21:28:26 +000031#include "webrtc/voice_engine/network_predictor.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000032#include "webrtc/voice_engine/shared_data.h"
33#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000034
niklase@google.com470e71d2011-07-07 08:21:25 +000035#ifdef WEBRTC_DTMF_DETECTION
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000036// TelephoneEventDetectionMethods, TelephoneEventObserver
37#include "webrtc/voice_engine/include/voe_dtmf.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000038#endif
39
wu@webrtc.org94454b72014-06-05 20:34:08 +000040namespace rtc {
41
42class TimestampWrapAroundHandler;
43}
44
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000045namespace webrtc {
46
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000047class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000048class Config;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049class CriticalSectionWrapper;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000050class FileWrapper;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000051class ProcessThread;
52class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000053class RemoteNtpTimeEstimator;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000054class RtpDump;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000055class RTPPayloadRegistry;
56class RtpReceiver;
57class RTPReceiverAudio;
58class RtpRtcp;
59class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000060class VoEMediaProcess;
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
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000070class OutputMixer;
niklase@google.com470e71d2011-07-07 08:21:25 +000071class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000072class StatisticsProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000073class TransmitMixer;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000074class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000075
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000076// Helper class to simplify locking scheme for members that are accessed from
77// multiple threads.
78// Example: a member can be set on thread T1 and read by an internal audio
79// thread T2. Accessing the member via this class ensures that we are
80// safe and also avoid TSan v2 warnings.
81class ChannelState {
82 public:
83 struct State {
84 State() : rx_apm_is_enabled(false),
85 input_external_media(false),
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000086 output_file_playing(false),
87 input_file_playing(false),
88 playing(false),
89 sending(false),
90 receiving(false) {}
91
92 bool rx_apm_is_enabled;
93 bool input_external_media;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000094 bool output_file_playing;
95 bool input_file_playing;
96 bool playing;
97 bool sending;
98 bool receiving;
99 };
100
101 ChannelState() : lock_(CriticalSectionWrapper::CreateCriticalSection()) {
102 }
103 virtual ~ChannelState() {}
104
105 void Reset() {
106 CriticalSectionScoped lock(lock_.get());
107 state_ = State();
108 }
109
110 State Get() const {
111 CriticalSectionScoped lock(lock_.get());
112 return state_;
113 }
114
115 void SetRxApmIsEnabled(bool enable) {
116 CriticalSectionScoped lock(lock_.get());
117 state_.rx_apm_is_enabled = enable;
118 }
119
120 void SetInputExternalMedia(bool enable) {
121 CriticalSectionScoped lock(lock_.get());
122 state_.input_external_media = enable;
123 }
124
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000125 void SetOutputFilePlaying(bool enable) {
126 CriticalSectionScoped lock(lock_.get());
127 state_.output_file_playing = enable;
128 }
129
130 void SetInputFilePlaying(bool enable) {
131 CriticalSectionScoped lock(lock_.get());
132 state_.input_file_playing = enable;
133 }
134
135 void SetPlaying(bool enable) {
136 CriticalSectionScoped lock(lock_.get());
137 state_.playing = enable;
138 }
139
140 void SetSending(bool enable) {
141 CriticalSectionScoped lock(lock_.get());
142 state_.sending = enable;
143 }
144
145 void SetReceiving(bool enable) {
146 CriticalSectionScoped lock(lock_.get());
147 state_.receiving = enable;
148 }
149
150private:
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000151 rtc::scoped_ptr<CriticalSectionWrapper> lock_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000152 State state_;
153};
niklase@google.com470e71d2011-07-07 08:21:25 +0000154
155class Channel:
156 public RtpData,
157 public RtpFeedback,
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:
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000166 friend class VoERtcpObserver;
167
niklase@google.com470e71d2011-07-07 08:21:25 +0000168 enum {KNumSocketThreads = 1};
169 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +0000170 virtual ~Channel();
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000171 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000172 int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000173 uint32_t instanceId,
174 const Config& config);
175 Channel(int32_t channelId, uint32_t instanceId, const Config& config);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000176 int32_t Init();
177 int32_t SetEngineInformation(
niklase@google.com470e71d2011-07-07 08:21:25 +0000178 Statistics& engineStatistics,
179 OutputMixer& outputMixer,
180 TransmitMixer& transmitMixer,
181 ProcessThread& moduleProcessThread,
182 AudioDeviceModule& audioDeviceModule,
183 VoiceEngineObserver* voiceEngineObserver,
184 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000185 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000186
niklase@google.com470e71d2011-07-07 08:21:25 +0000187 // API methods
188
189 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000190 int32_t StartPlayout();
191 int32_t StopPlayout();
192 int32_t StartSend();
193 int32_t StopSend();
194 int32_t StartReceiving();
195 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
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);
Ivo Creusenadf89b72015-04-29 16:03:33 +0200204 void SetBitRate(int bitrate_bps);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000205 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
206 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
207 int32_t SetRecPayloadType(const CodecInst& codec);
208 int32_t GetRecPayloadType(CodecInst& codec);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000209 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
minyue@webrtc.orgadee8f92014-09-03 12:28:06 +0000210 int SetOpusMaxPlaybackRate(int frequency_hz);
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000211 int SetOpusDtx(bool enable_dtx);
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
213 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000214 int32_t RegisterExternalTransport(Transport& transport);
215 int32_t DeRegisterExternalTransport();
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000216 int32_t ReceivedRTPPacket(const int8_t* data, size_t length,
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000217 const PacketTime& packet_time);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000218 int32_t ReceivedRTCPPacket(const int8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000219
niklase@google.com470e71d2011-07-07 08:21:25 +0000220 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000221 int StartPlayingFileLocally(const char* fileName, bool loop,
222 FileFormats format,
223 int startPosition,
224 float volumeScaling,
225 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000226 const CodecInst* codecInst);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000227 int StartPlayingFileLocally(InStream* stream, FileFormats format,
228 int startPosition,
229 float volumeScaling,
230 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000231 const CodecInst* codecInst);
232 int StopPlayingFileLocally();
233 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000234 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000235 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
236 FileFormats format,
237 int startPosition,
238 float volumeScaling,
239 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000240 const CodecInst* codecInst);
241 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000242 FileFormats format,
243 int startPosition,
244 float volumeScaling,
245 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000246 const CodecInst* codecInst);
247 int StopPlayingFileAsMicrophone();
248 int IsPlayingFileAsMicrophone() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000249 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
250 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
251 int StopRecordingPlayout();
252
253 void SetMixWithMicStatus(bool mix);
254
255 // VoEExternalMediaProcessing
256 int RegisterExternalMediaProcessing(ProcessingTypes type,
257 VoEMediaProcess& processObject);
258 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000259 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000260
261 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000262 int GetSpeechOutputLevel(uint32_t& level) const;
263 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000264 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000265 bool Mute() const;
266 int SetOutputVolumePan(float left, float right);
267 int GetOutputVolumePan(float& left, float& right) const;
268 int SetChannelOutputVolumeScaling(float scaling);
269 int GetChannelOutputVolumeScaling(float& scaling) const;
270
niklase@google.com470e71d2011-07-07 08:21:25 +0000271 // VoENetEqStats
272 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000273 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000274
275 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000276 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
277 int* playout_buffer_delay_ms) const;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000278 int least_required_delay_ms() const { return least_required_delay_ms_; }
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000279 int SetInitialPlayoutDelay(int delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000280 int SetMinimumPlayoutDelay(int delayMs);
281 int GetPlayoutTimestamp(unsigned int& timestamp);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000282 void UpdatePlayoutTimestamp(bool rtcp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000283 int SetInitTimestamp(unsigned int timestamp);
284 int SetInitSequenceNumber(short sequenceNumber);
285
286 // VoEVideoSyncExtended
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000287 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000288
niklase@google.com470e71d2011-07-07 08:21:25 +0000289 // VoEDtmf
290 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
291 int attenuationDb, bool playDtmfEvent);
292 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
293 int attenuationDb, bool playDtmfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000294 int SetSendTelephoneEventPayloadType(unsigned char type);
295 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000296
297 // VoEAudioProcessingImpl
298 int UpdateRxVadDetection(AudioFrame& audioFrame);
299 int RegisterRxVadObserver(VoERxVadCallback &observer);
300 int DeRegisterRxVadObserver();
301 int VoiceActivityIndicator(int &activity);
302#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000303 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000304 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000305 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000306 int GetRxAgcConfig(AgcConfig& config);
307#endif
308#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000309 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000310 int GetRxNsStatus(bool& enabled, NsModes& mode);
311#endif
312
313 // VoERTP_RTCP
niklase@google.com470e71d2011-07-07 08:21:25 +0000314 int SetLocalSSRC(unsigned int ssrc);
315 int GetLocalSSRC(unsigned int& ssrc);
316 int GetRemoteSSRC(unsigned int& ssrc);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000317 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.org93fd25c2014-04-24 20:33:08 +0000318 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000319 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
320 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000321 void SetRTCPStatus(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000322 int GetRTCPStatus(bool& enabled);
323 int SetRTCP_CNAME(const char cName[256]);
niklase@google.com470e71d2011-07-07 08:21:25 +0000324 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);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000337 int SetREDStatus(bool enable, int redPayloadtype);
338 int GetREDStatus(bool& enabled, int& redPayloadtype);
339 int SetCodecFECStatus(bool enable);
340 bool GetCodecFECStatus();
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000341 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000342 int StartRTPDump(const char fileNameUTF8[1024], RTPDirections direction);
343 int StopRTPDump(RTPDirections direction);
344 bool RTPDumpIsActive(RTPDirections direction);
niklase@google.com470e71d2011-07-07 08:21:25 +0000345
niklase@google.com470e71d2011-07-07 08:21:25 +0000346 // From AudioPacketizationCallback in the ACM
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000347 int32_t SendData(FrameType frameType,
348 uint8_t payloadType,
349 uint32_t timeStamp,
350 const uint8_t* payloadData,
351 size_t payloadSize,
352 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000353
niklase@google.com470e71d2011-07-07 08:21:25 +0000354 // From ACMVADCallback in the ACM
henrik.lundin@webrtc.orge9217b42015-03-06 07:50:34 +0000355 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000356
pbos@webrtc.org92135212013-05-14 08:31:39 +0000357 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000358
niklase@google.com470e71d2011-07-07 08:21:25 +0000359 // From RtpData in the RTP/RTCP module
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000360 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
361 size_t payloadSize,
362 const WebRtcRTPHeader* rtpHeader) override;
363 bool OnRecoveredPacket(const uint8_t* packet,
364 size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000365
niklase@google.com470e71d2011-07-07 08:21:25 +0000366 // From RtpFeedback in the RTP/RTCP module
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000367 int32_t OnInitializeDecoder(int32_t id,
368 int8_t payloadType,
369 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
370 int frequency,
371 uint8_t channels,
372 uint32_t rate) override;
373 void OnIncomingSSRCChanged(int32_t id, uint32_t ssrc) override;
374 void OnIncomingCSRCChanged(int32_t id, uint32_t CSRC, bool added) override;
375 void ResetStatistics(uint32_t ssrc) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000376
niklase@google.com470e71d2011-07-07 08:21:25 +0000377 // From RtpAudioFeedback in the RTP/RTCP module
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000378 void OnPlayTelephoneEvent(int32_t id,
379 uint8_t event,
380 uint16_t lengthMs,
381 uint8_t volume) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000382
niklase@google.com470e71d2011-07-07 08:21:25 +0000383 // From Transport (called by the RTP/RTCP module)
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000384 int SendPacket(int /*channel*/, const void* data, size_t len) override;
385 int SendRTCPPacket(int /*channel*/, const void* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000386
niklase@google.com470e71d2011-07-07 08:21:25 +0000387 // From MixerParticipant
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000388 int32_t GetAudioFrame(int32_t id, AudioFrame& audioFrame) override;
389 int32_t NeededFrequency(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000390
niklase@google.com470e71d2011-07-07 08:21:25 +0000391 // From FileCallback
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000392 void PlayNotification(int32_t id, uint32_t durationMs) override;
393 void RecordNotification(int32_t id, uint32_t durationMs) override;
394 void PlayFileEnded(int32_t id) override;
395 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000396
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000397 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000398 {
399 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000400 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000401 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000402 {
403 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000404 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000405 bool Playing() const
406 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000407 return channel_state_.Get().playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000408 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000409 bool Sending() const
410 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000411 return channel_state_.Get().sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000412 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000413 bool Receiving() const
414 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000415 return channel_state_.Get().receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000416 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000417 bool ExternalTransport() const
418 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000419 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000420 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000421 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000422 bool ExternalMixing() const
423 {
424 return _externalMixing;
425 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000426 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000427 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000428 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000429 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000430 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000431 {
432 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000433 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000434 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000435 // Demultiplex the data to the channel's |_audioFrame|. The difference
436 // between this method and the overloaded method above is that |audio_data|
437 // does not go through transmit_mixer and APM.
438 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000439 int sample_rate,
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000440 int number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000441 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000442 uint32_t PrepareEncodeAndSend(int mixingFrequency);
443 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000444
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000445protected:
446 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000447
niklase@google.com470e71d2011-07-07 08:21:25 +0000448private:
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000449 bool ReceivePacket(const uint8_t* packet, size_t packet_length,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000450 const RTPHeader& header, bool in_order);
minyue@webrtc.org456f0142015-01-23 11:58:42 +0000451 bool HandleRtxPacket(const uint8_t* packet,
452 size_t packet_length,
453 const RTPHeader& header);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000454 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000455 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000456 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000457 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000458 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
459 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000460 int32_t SendPacketRaw(const void *data, size_t len, bool RTCP);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000461 void UpdatePacketDelay(uint32_t timestamp,
462 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000463 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000464
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000465 int SetRedPayloadType(int red_payload_type);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000466 int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type,
467 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000468
wu@webrtc.org94454b72014-06-05 20:34:08 +0000469 int32_t GetPlayoutFrequency();
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000470 int64_t GetRTT() const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000471
niklase@google.com470e71d2011-07-07 08:21:25 +0000472 CriticalSectionWrapper& _fileCritSect;
473 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.org63420662013-10-17 18:28:55 +0000474 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000475 uint32_t _instanceId;
476 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000477
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000478 ChannelState channel_state_;
479
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000480 rtc::scoped_ptr<RtpHeaderParser> rtp_header_parser_;
481 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
482 rtc::scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
483 rtc::scoped_ptr<StatisticsProxy> statistics_proxy_;
484 rtc::scoped_ptr<RtpReceiver> rtp_receiver_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000485 TelephoneEventHandler* telephone_event_handler_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000486 rtc::scoped_ptr<RtpRtcp> _rtpRtcpModule;
487 rtc::scoped_ptr<AudioCodingModule> audio_coding_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000488 RtpDump& _rtpDumpIn;
489 RtpDump& _rtpDumpOut;
niklase@google.com470e71d2011-07-07 08:21:25 +0000490 AudioLevel _outputAudioLevel;
491 bool _externalTransport;
492 AudioFrame _audioFrame;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000493 rtc::scoped_ptr<int16_t[]> mono_recording_audio_;
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +0000494 // Downsamples to the codec rate if necessary.
495 PushResampler<int16_t> input_resampler_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000496 FilePlayer* _inputFilePlayerPtr;
497 FilePlayer* _outputFilePlayerPtr;
498 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000499 int _inputFilePlayerId;
500 int _outputFilePlayerId;
501 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000502 bool _outputFileRecording;
503 DtmfInbandQueue _inbandDtmfQueue;
504 DtmfInband _inbandDtmfGenerator;
xians@google.com22963ab2011-08-03 12:40:23 +0000505 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000506 VoEMediaProcess* _inputExternalMediaCallbackPtr;
507 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000508 uint32_t _timeStamp;
509 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000510
stefan@webrtc.org8e24d872014-09-02 18:58:24 +0000511 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000512
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000513 // Timestamp of the audio pulled from NetEq.
514 uint32_t jitter_buffer_playout_timestamp_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000515 uint32_t playout_timestamp_rtp_;
516 uint32_t playout_timestamp_rtcp_;
517 uint32_t playout_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000518 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000519 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000520 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000521
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000522 rtc::scoped_ptr<CriticalSectionWrapper> ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000523
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000524 rtc::scoped_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000525 // The rtp timestamp of the first played out audio frame.
wu@webrtc.org94454b72014-06-05 20:34:08 +0000526 int64_t capture_start_rtp_time_stamp_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000527 // The capture ntp time (in local timebase) of the first played out audio
528 // frame.
stefan@webrtc.org8e24d872014-09-02 18:58:24 +0000529 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000530
niklase@google.com470e71d2011-07-07 08:21:25 +0000531 // uses
532 Statistics* _engineStatisticsPtr;
533 OutputMixer* _outputMixerPtr;
534 TransmitMixer* _transmitMixerPtr;
535 ProcessThread* _moduleProcessThreadPtr;
536 AudioDeviceModule* _audioDeviceModulePtr;
537 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
538 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
539 Transport* _transportPtr; // WebRtc socket or external transport
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000540 RMSLevel rms_level_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000541 rtc::scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000542 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000543 int32_t _oldVadDecision;
544 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000545 // VoEBase
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000546 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000547 bool _mixFileWithMicrophone;
niklase@google.com470e71d2011-07-07 08:21:25 +0000548 // VoEVolumeControl
549 bool _mute;
550 float _panLeft;
551 float _panRight;
552 float _outputGain;
niklase@google.com470e71d2011-07-07 08:21:25 +0000553 // VoEDtmf
554 bool _playOutbandDtmfEvent;
555 bool _playInbandDtmfEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000556 // VoeRTP_RTCP
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000557 uint32_t _lastLocalTimeStamp;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000558 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000559 bool _includeAudioLevelIndication;
560 // VoENetwork
niklase@google.com470e71d2011-07-07 08:21:25 +0000561 AudioFrame::SpeechType _outputSpeechType;
562 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000563 uint32_t _average_jitter_buffer_delay_us;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000564 int least_required_delay_ms_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000565 uint32_t _previousTimestamp;
566 uint16_t _recPacketDelayMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000567 // VoEAudioProcessing
568 bool _RxVadDetection;
niklase@google.com470e71d2011-07-07 08:21:25 +0000569 bool _rxAgcIsEnabled;
570 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000571 bool restored_packet_in_use_;
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000572 // RtcpBandwidthObserver
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000573 rtc::scoped_ptr<VoERtcpObserver> rtcp_observer_;
574 rtc::scoped_ptr<NetworkPredictor> network_predictor_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000575};
576
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000577} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000578} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000579
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000580#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_