blob: 6fc4f3404009af5c2211164bfd6f27934a28dc88 [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
kwibergb7f89d62016-02-17 10:04:18 -080014#include <memory>
15
kjellander@webrtc.org7ffeab52016-02-26 22:46:09 +010016#include "webrtc/audio_sink.h"
Stefan Holmerb86d4e42015-12-07 10:26:18 +010017#include "webrtc/base/criticalsection.h"
henrik.lundin96bd5022016-04-06 04:13:56 -070018#include "webrtc/base/optional.h"
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000019#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000020#include "webrtc/common_types.h"
kwibergc8d071e2016-04-06 12:22:38 -070021#include "webrtc/modules/audio_coding/acm2/codec_manager.h"
22#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
kjellander3e6db232015-11-26 04:44:54 -080023#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010024#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000025#include "webrtc/modules/audio_processing/rms_level.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010026#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
27#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
28#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
kwiberg9d7eb132016-08-16 04:08:30 -070029#include "webrtc/modules/utility/include/file_player.h"
30#include "webrtc/modules/utility/include/file_recorder.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000031#include "webrtc/voice_engine/include/voe_audio_processing.h"
32#include "webrtc/voice_engine/include/voe_network.h"
33#include "webrtc/voice_engine/level_indicator.h"
minyue@webrtc.org74aaf292014-07-16 21:28:26 +000034#include "webrtc/voice_engine/network_predictor.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000035#include "webrtc/voice_engine/shared_data.h"
36#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000037
wu@webrtc.org94454b72014-06-05 20:34:08 +000038namespace rtc {
wu@webrtc.org94454b72014-06-05 20:34:08 +000039class TimestampWrapAroundHandler;
40}
41
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000042namespace webrtc {
43
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000044class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000045class Config;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000046class FileWrapper;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010047class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000048class ProcessThread;
Erik Språng737336d2016-07-29 12:59:36 +020049class RateLimiter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000050class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000051class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070052class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000053class RTPPayloadRegistry;
54class RtpReceiver;
55class RTPReceiverAudio;
56class RtpRtcp;
57class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000058class VoEMediaProcess;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000059class VoERTPObserver;
60class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
62struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000063struct ReportBlock;
64struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000065
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000066namespace voe {
67
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000068class OutputMixer;
ivoc14d5dbe2016-07-04 07:06:55 -070069class RtcEventLogProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010070class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000071class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000072class StatisticsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010073class TransportFeedbackProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000074class TransmitMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010075class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000076class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000077
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000078// Helper class to simplify locking scheme for members that are accessed from
79// multiple threads.
80// Example: a member can be set on thread T1 and read by an internal audio
81// thread T2. Accessing the member via this class ensures that we are
82// safe and also avoid TSan v2 warnings.
83class ChannelState {
84 public:
kwiberg55b97fe2016-01-28 05:22:45 -080085 struct State {
86 State()
87 : rx_apm_is_enabled(false),
88 input_external_media(false),
89 output_file_playing(false),
90 input_file_playing(false),
91 playing(false),
92 sending(false),
93 receiving(false) {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000094
kwiberg55b97fe2016-01-28 05:22:45 -080095 bool rx_apm_is_enabled;
96 bool input_external_media;
97 bool output_file_playing;
98 bool input_file_playing;
99 bool playing;
100 bool sending;
101 bool receiving;
102 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000103
kwiberg55b97fe2016-01-28 05:22:45 -0800104 ChannelState() {}
105 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000106
kwiberg55b97fe2016-01-28 05:22:45 -0800107 void Reset() {
108 rtc::CritScope lock(&lock_);
109 state_ = State();
110 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000111
kwiberg55b97fe2016-01-28 05:22:45 -0800112 State Get() const {
113 rtc::CritScope lock(&lock_);
114 return state_;
115 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000116
kwiberg55b97fe2016-01-28 05:22:45 -0800117 void SetRxApmIsEnabled(bool enable) {
118 rtc::CritScope lock(&lock_);
119 state_.rx_apm_is_enabled = enable;
120 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000121
kwiberg55b97fe2016-01-28 05:22:45 -0800122 void SetInputExternalMedia(bool enable) {
123 rtc::CritScope lock(&lock_);
124 state_.input_external_media = enable;
125 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000126
kwiberg55b97fe2016-01-28 05:22:45 -0800127 void SetOutputFilePlaying(bool enable) {
128 rtc::CritScope lock(&lock_);
129 state_.output_file_playing = enable;
130 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000131
kwiberg55b97fe2016-01-28 05:22:45 -0800132 void SetInputFilePlaying(bool enable) {
133 rtc::CritScope lock(&lock_);
134 state_.input_file_playing = enable;
135 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000136
kwiberg55b97fe2016-01-28 05:22:45 -0800137 void SetPlaying(bool enable) {
138 rtc::CritScope lock(&lock_);
139 state_.playing = enable;
140 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000141
kwiberg55b97fe2016-01-28 05:22:45 -0800142 void SetSending(bool enable) {
143 rtc::CritScope lock(&lock_);
144 state_.sending = enable;
145 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000146
kwiberg55b97fe2016-01-28 05:22:45 -0800147 void SetReceiving(bool enable) {
148 rtc::CritScope lock(&lock_);
149 state_.receiving = enable;
150 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000151
kwiberg55b97fe2016-01-28 05:22:45 -0800152 private:
pbosd8de1152016-02-01 09:00:51 -0800153 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800154 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000155};
niklase@google.com470e71d2011-07-07 08:21:25 +0000156
kwiberg55b97fe2016-01-28 05:22:45 -0800157class Channel
158 : public RtpData,
159 public RtpFeedback,
160 public FileCallback, // receiving notification from file player &
161 // recorder
162 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800163 public AudioPacketizationCallback, // receive encoded packets from the
164 // ACM
165 public ACMVADCallback, // receive voice activity from the ACM
166 public MixerParticipant // supplies output mixer with audio frames
niklase@google.com470e71d2011-07-07 08:21:25 +0000167{
kwiberg55b97fe2016-01-28 05:22:45 -0800168 public:
169 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000170
kwiberg55b97fe2016-01-28 05:22:45 -0800171 enum { KNumSocketThreads = 1 };
172 enum { KNumberOfSocketBuffers = 8 };
173 virtual ~Channel();
ossu5f7cfa52016-05-30 08:11:28 -0700174 static int32_t CreateChannel(
175 Channel*& channel,
176 int32_t channelId,
177 uint32_t instanceId,
ossu5f7cfa52016-05-30 08:11:28 -0700178 const Config& config,
179 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory);
kwiberg55b97fe2016-01-28 05:22:45 -0800180 Channel(int32_t channelId,
181 uint32_t instanceId,
ossu5f7cfa52016-05-30 08:11:28 -0700182 const Config& config,
183 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory);
kwiberg55b97fe2016-01-28 05:22:45 -0800184 int32_t Init();
185 int32_t SetEngineInformation(Statistics& engineStatistics,
186 OutputMixer& outputMixer,
187 TransmitMixer& transmitMixer,
188 ProcessThread& moduleProcessThread,
189 AudioDeviceModule& audioDeviceModule,
190 VoiceEngineObserver* voiceEngineObserver,
191 rtc::CriticalSection* callbackCritSect);
192 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
kwibergb7f89d62016-02-17 10:04:18 -0800194 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100195
ossu29b1a8d2016-06-13 07:34:51 -0700196 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
197 // passed into AudioReceiveStream is the same as the one set when creating the
198 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
199 // go.
200 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
201
kwiberg55b97fe2016-01-28 05:22:45 -0800202 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000203
kwiberg55b97fe2016-01-28 05:22:45 -0800204 // VoEBase
205 int32_t StartPlayout();
206 int32_t StopPlayout();
207 int32_t StartSend();
208 int32_t StopSend();
209 int32_t StartReceiving();
210 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000211
kwiberg55b97fe2016-01-28 05:22:45 -0800212 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
213 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000214
kwiberg55b97fe2016-01-28 05:22:45 -0800215 // VoECodec
216 int32_t GetSendCodec(CodecInst& codec);
217 int32_t GetRecCodec(CodecInst& codec);
218 int32_t SetSendCodec(const CodecInst& codec);
219 void SetBitRate(int bitrate_bps);
220 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
221 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
222 int32_t SetRecPayloadType(const CodecInst& codec);
223 int32_t GetRecPayloadType(CodecInst& codec);
224 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
225 int SetOpusMaxPlaybackRate(int frequency_hz);
226 int SetOpusDtx(bool enable_dtx);
ivoc85228d62016-07-27 04:53:47 -0700227 int GetOpusDtx(bool* enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000228
kwiberg55b97fe2016-01-28 05:22:45 -0800229 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700230 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800231 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700232 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800233 size_t length,
234 const PacketTime& packet_time);
mflodman3d7db262016-04-29 00:57:13 -0700235 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000236
kwiberg55b97fe2016-01-28 05:22:45 -0800237 // VoEFile
238 int StartPlayingFileLocally(const char* fileName,
239 bool loop,
240 FileFormats format,
241 int startPosition,
242 float volumeScaling,
243 int stopPosition,
244 const CodecInst* codecInst);
245 int StartPlayingFileLocally(InStream* stream,
246 FileFormats format,
247 int startPosition,
248 float volumeScaling,
249 int stopPosition,
250 const CodecInst* codecInst);
251 int StopPlayingFileLocally();
252 int IsPlayingFileLocally() const;
253 int RegisterFilePlayingToMixer();
254 int StartPlayingFileAsMicrophone(const char* fileName,
255 bool loop,
256 FileFormats format,
257 int startPosition,
258 float volumeScaling,
259 int stopPosition,
260 const CodecInst* codecInst);
261 int StartPlayingFileAsMicrophone(InStream* stream,
262 FileFormats format,
263 int startPosition,
264 float volumeScaling,
265 int stopPosition,
266 const CodecInst* codecInst);
267 int StopPlayingFileAsMicrophone();
268 int IsPlayingFileAsMicrophone() const;
269 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
270 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
271 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000272
kwiberg55b97fe2016-01-28 05:22:45 -0800273 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000274
kwiberg55b97fe2016-01-28 05:22:45 -0800275 // VoEExternalMediaProcessing
276 int RegisterExternalMediaProcessing(ProcessingTypes type,
277 VoEMediaProcess& processObject);
278 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
279 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000280
kwiberg55b97fe2016-01-28 05:22:45 -0800281 // VoEVolumeControl
282 int GetSpeechOutputLevel(uint32_t& level) const;
283 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
solenberg1c2af8e2016-03-24 10:36:00 -0700284 int SetInputMute(bool enable);
285 bool InputMute() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800286 int SetOutputVolumePan(float left, float right);
287 int GetOutputVolumePan(float& left, float& right) const;
288 int SetChannelOutputVolumeScaling(float scaling);
289 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000290
kwiberg55b97fe2016-01-28 05:22:45 -0800291 // VoENetEqStats
292 int GetNetworkStatistics(NetworkStatistics& stats);
293 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000294
kwiberg55b97fe2016-01-28 05:22:45 -0800295 // VoEVideoSync
296 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
297 int* playout_buffer_delay_ms) const;
298 uint32_t GetDelayEstimate() const;
299 int LeastRequiredDelayMs() const;
300 int SetMinimumPlayoutDelay(int delayMs);
301 int GetPlayoutTimestamp(unsigned int& timestamp);
302 int SetInitTimestamp(unsigned int timestamp);
303 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000304
kwiberg55b97fe2016-01-28 05:22:45 -0800305 // VoEVideoSyncExtended
306 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000307
solenberg31642aa2016-03-14 08:00:37 -0700308 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800309 int SendTelephoneEventOutband(int event, int duration_ms);
solenberg31642aa2016-03-14 08:00:37 -0700310 int SetSendTelephoneEventPayloadType(int payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000311
kwiberg55b97fe2016-01-28 05:22:45 -0800312 // VoEAudioProcessingImpl
313 int UpdateRxVadDetection(AudioFrame& audioFrame);
314 int RegisterRxVadObserver(VoERxVadCallback& observer);
315 int DeRegisterRxVadObserver();
316 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000317#ifdef WEBRTC_VOICE_ENGINE_AGC
kwiberg55b97fe2016-01-28 05:22:45 -0800318 int SetRxAgcStatus(bool enable, AgcModes mode);
319 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
320 int SetRxAgcConfig(AgcConfig config);
321 int GetRxAgcConfig(AgcConfig& config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000322#endif
323#ifdef WEBRTC_VOICE_ENGINE_NR
kwiberg55b97fe2016-01-28 05:22:45 -0800324 int SetRxNsStatus(bool enable, NsModes mode);
325 int GetRxNsStatus(bool& enabled, NsModes& mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000326#endif
327
kwiberg55b97fe2016-01-28 05:22:45 -0800328 // VoERTP_RTCP
329 int SetLocalSSRC(unsigned int ssrc);
330 int GetLocalSSRC(unsigned int& ssrc);
331 int GetRemoteSSRC(unsigned int& ssrc);
332 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
333 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
334 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
335 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
336 void EnableSendTransportSequenceNumber(int id);
337 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100338
stefanbba9dec2016-02-01 04:39:55 -0800339 void RegisterSenderCongestionControlObjects(
340 RtpPacketSender* rtp_packet_sender,
341 TransportFeedbackObserver* transport_feedback_observer,
342 PacketRouter* packet_router);
343 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
344 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100345
kwiberg55b97fe2016-01-28 05:22:45 -0800346 void SetRTCPStatus(bool enable);
347 int GetRTCPStatus(bool& enabled);
348 int SetRTCP_CNAME(const char cName[256]);
349 int GetRemoteRTCP_CNAME(char cName[256]);
350 int GetRemoteRTCPData(unsigned int& NTPHigh,
351 unsigned int& NTPLow,
352 unsigned int& timestamp,
353 unsigned int& playoutTimestamp,
354 unsigned int* jitter,
355 unsigned short* fractionLost);
356 int SendApplicationDefinedRTCPPacket(unsigned char subType,
357 unsigned int name,
358 const char* data,
359 unsigned short dataLengthInBytes);
360 int GetRTPStatistics(unsigned int& averageJitterMs,
361 unsigned int& maxJitterMs,
362 unsigned int& discardedPackets);
363 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
364 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800365 int SetCodecFECStatus(bool enable);
366 bool GetCodecFECStatus();
367 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000368
kwiberg55b97fe2016-01-28 05:22:45 -0800369 // From AudioPacketizationCallback in the ACM
370 int32_t SendData(FrameType frameType,
371 uint8_t payloadType,
372 uint32_t timeStamp,
373 const uint8_t* payloadData,
374 size_t payloadSize,
375 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000376
kwiberg55b97fe2016-01-28 05:22:45 -0800377 // From ACMVADCallback in the ACM
378 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000379
kwiberg55b97fe2016-01-28 05:22:45 -0800380 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000381
kwiberg55b97fe2016-01-28 05:22:45 -0800382 // From RtpData in the RTP/RTCP module
383 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
384 size_t payloadSize,
385 const WebRtcRTPHeader* rtpHeader) override;
386 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000387
kwiberg55b97fe2016-01-28 05:22:45 -0800388 // From RtpFeedback in the RTP/RTCP module
389 int32_t OnInitializeDecoder(int8_t payloadType,
390 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
391 int frequency,
392 size_t channels,
393 uint32_t rate) override;
394 void OnIncomingSSRCChanged(uint32_t ssrc) override;
395 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000396
kwiberg55b97fe2016-01-28 05:22:45 -0800397 // From Transport (called by the RTP/RTCP module)
398 bool SendRtp(const uint8_t* data,
399 size_t len,
400 const PacketOptions& packet_options) override;
401 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000402
kwiberg55b97fe2016-01-28 05:22:45 -0800403 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700404 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
405 int32_t id,
406 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800407 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000408
kwiberg55b97fe2016-01-28 05:22:45 -0800409 // From FileCallback
410 void PlayNotification(int32_t id, uint32_t durationMs) override;
411 void RecordNotification(int32_t id, uint32_t durationMs) override;
412 void PlayFileEnded(int32_t id) override;
413 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000414
kwiberg55b97fe2016-01-28 05:22:45 -0800415 uint32_t InstanceId() const { return _instanceId; }
416 int32_t ChannelId() const { return _channelId; }
417 bool Playing() const { return channel_state_.Get().playing; }
418 bool Sending() const { return channel_state_.Get().sending; }
419 bool Receiving() const { return channel_state_.Get().receiving; }
420 bool ExternalTransport() const {
421 rtc::CritScope cs(&_callbackCritSect);
422 return _externalTransport;
423 }
424 bool ExternalMixing() const { return _externalMixing; }
425 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
426 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
427 uint32_t Demultiplex(const AudioFrame& audioFrame);
428 // Demultiplex the data to the channel's |_audioFrame|. The difference
429 // between this method and the overloaded method above is that |audio_data|
430 // does not go through transmit_mixer and APM.
431 void Demultiplex(const int16_t* audio_data,
432 int sample_rate,
433 size_t number_of_frames,
434 size_t number_of_channels);
435 uint32_t PrepareEncodeAndSend(int mixingFrequency);
436 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000437
kwiberg55b97fe2016-01-28 05:22:45 -0800438 // Associate to a send channel.
439 // Used for obtaining RTT for a receive-only channel.
440 void set_associate_send_channel(const ChannelOwner& channel) {
441 assert(_channelId != channel.channel()->ChannelId());
442 rtc::CritScope lock(&assoc_send_channel_lock_);
443 associate_send_channel_ = channel;
444 }
Minyue2013aec2015-05-13 14:14:42 +0200445
kwiberg55b97fe2016-01-28 05:22:45 -0800446 // Disassociate a send channel if it was associated.
447 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200448
ivoc14d5dbe2016-07-04 07:06:55 -0700449 // Set a RtcEventLog logging object.
450 void SetRtcEventLog(RtcEventLog* event_log);
451
kwiberg55b97fe2016-01-28 05:22:45 -0800452 protected:
453 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000454
kwiberg55b97fe2016-01-28 05:22:45 -0800455 private:
456 bool ReceivePacket(const uint8_t* packet,
457 size_t packet_length,
458 const RTPHeader& header,
459 bool in_order);
460 bool HandleRtxPacket(const uint8_t* packet,
461 size_t packet_length,
462 const RTPHeader& header);
463 bool IsPacketInOrder(const RTPHeader& header) const;
464 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
465 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800466 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
467 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
468 void UpdatePlayoutTimestamp(bool rtcp);
469 void UpdatePacketDelay(uint32_t timestamp, uint16_t sequenceNumber);
470 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000471
kwiberg55b97fe2016-01-28 05:22:45 -0800472 int SetSendRtpHeaderExtension(bool enable,
473 RTPExtensionType type,
474 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000475
kwiberg55b97fe2016-01-28 05:22:45 -0800476 int32_t GetPlayoutFrequency();
477 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000478
pbosd8de1152016-02-01 09:00:51 -0800479 rtc::CriticalSection _fileCritSect;
480 rtc::CriticalSection _callbackCritSect;
481 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800482 uint32_t _instanceId;
483 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000484
kwiberg55b97fe2016-01-28 05:22:45 -0800485 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000486
ivoc14d5dbe2016-07-04 07:06:55 -0700487 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200488
kwibergb7f89d62016-02-17 10:04:18 -0800489 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
490 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
491 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
492 std::unique_ptr<StatisticsProxy> statistics_proxy_;
493 std::unique_ptr<RtpReceiver> rtp_receiver_;
kwiberg55b97fe2016-01-28 05:22:45 -0800494 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800495 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
496 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700497 acm2::CodecManager codec_manager_;
498 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800499 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800500 AudioLevel _outputAudioLevel;
501 bool _externalTransport;
502 AudioFrame _audioFrame;
503 // Downsamples to the codec rate if necessary.
504 PushResampler<int16_t> input_resampler_;
kwiberg5a25d952016-08-17 07:31:12 -0700505 std::unique_ptr<FilePlayer> input_file_player_;
506 std::unique_ptr<FilePlayer> output_file_player_;
507 std::unique_ptr<FileRecorder> output_file_recorder_;
kwiberg55b97fe2016-01-28 05:22:45 -0800508 int _inputFilePlayerId;
509 int _outputFilePlayerId;
510 int _outputFileRecorderId;
511 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800512 bool _outputExternalMedia;
513 VoEMediaProcess* _inputExternalMediaCallbackPtr;
514 VoEMediaProcess* _outputExternalMediaCallbackPtr;
515 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000516
kwiberg55b97fe2016-01-28 05:22:45 -0800517 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000518
kwiberg55b97fe2016-01-28 05:22:45 -0800519 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700520 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
kwiberg55b97fe2016-01-28 05:22:45 -0800521 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
522 uint32_t playout_timestamp_rtcp_;
523 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
524 uint32_t _numberOfDiscardedPackets;
525 uint16_t send_sequence_number_;
526 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000527
pbosd8de1152016-02-01 09:00:51 -0800528 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000529
kwibergb7f89d62016-02-17 10:04:18 -0800530 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800531 // The rtp timestamp of the first played out audio frame.
532 int64_t capture_start_rtp_time_stamp_;
533 // The capture ntp time (in local timebase) of the first played out audio
534 // frame.
535 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000536
kwiberg55b97fe2016-01-28 05:22:45 -0800537 // uses
538 Statistics* _engineStatisticsPtr;
539 OutputMixer* _outputMixerPtr;
540 TransmitMixer* _transmitMixerPtr;
541 ProcessThread* _moduleProcessThreadPtr;
542 AudioDeviceModule* _audioDeviceModulePtr;
543 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
544 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
545 Transport* _transportPtr; // WebRtc socket or external transport
546 RMSLevel rms_level_;
kwibergb7f89d62016-02-17 10:04:18 -0800547 std::unique_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800548 VoERxVadCallback* _rxVadObserverPtr;
549 int32_t _oldVadDecision;
550 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
551 // VoEBase
552 bool _externalMixing;
553 bool _mixFileWithMicrophone;
554 // VoEVolumeControl
solenberg1c2af8e2016-03-24 10:36:00 -0700555 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
556 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
557 float _panLeft GUARDED_BY(volume_settings_critsect_);
558 float _panRight GUARDED_BY(volume_settings_critsect_);
559 float _outputGain GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800560 // VoeRTP_RTCP
561 uint32_t _lastLocalTimeStamp;
562 int8_t _lastPayloadType;
563 bool _includeAudioLevelIndication;
564 // VoENetwork
565 AudioFrame::SpeechType _outputSpeechType;
566 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800567 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800568 uint32_t _average_jitter_buffer_delay_us GUARDED_BY(video_sync_lock_);
569 uint32_t _previousTimestamp;
570 uint16_t _recPacketDelayMs GUARDED_BY(video_sync_lock_);
571 // VoEAudioProcessing
572 bool _RxVadDetection;
573 bool _rxAgcIsEnabled;
574 bool _rxNsIsEnabled;
575 bool restored_packet_in_use_;
576 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800577 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
578 std::unique_ptr<NetworkPredictor> network_predictor_;
kwiberg55b97fe2016-01-28 05:22:45 -0800579 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800580 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800581 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100582
kwiberg55b97fe2016-01-28 05:22:45 -0800583 bool pacing_enabled_;
584 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800585 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
586 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
587 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200588 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700589
590 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
591 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000592};
593
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000594} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000595} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000596
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000597#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_