blob: 2626df969b1456d9525408ac7f13cb40152b5bee [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"
kjellander3e6db232015-11-26 04:44:54 -080021#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010022#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000023#include "webrtc/modules/audio_processing/rms_level.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010024#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
25#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
26#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
27#include "webrtc/modules/utility/include/file_player.h"
28#include "webrtc/modules/utility/include/file_recorder.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000029#include "webrtc/voice_engine/include/voe_audio_processing.h"
30#include "webrtc/voice_engine/include/voe_network.h"
31#include "webrtc/voice_engine/level_indicator.h"
minyue@webrtc.org74aaf292014-07-16 21:28:26 +000032#include "webrtc/voice_engine/network_predictor.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000033#include "webrtc/voice_engine/shared_data.h"
34#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000035
wu@webrtc.org94454b72014-06-05 20:34:08 +000036namespace rtc {
37
38class TimestampWrapAroundHandler;
39}
40
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000041namespace webrtc {
42
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000043class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000044class Config;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000045class FileWrapper;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010046class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000047class ProcessThread;
48class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000049class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070050class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000051class RTPPayloadRegistry;
52class RtpReceiver;
53class RTPReceiverAudio;
54class RtpRtcp;
55class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000056class VoEMediaProcess;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000057class VoERTPObserver;
58class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000059
60struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000061struct ReportBlock;
62struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000063
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000064namespace voe {
65
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000066class OutputMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010067class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000068class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000069class StatisticsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010070class TransportFeedbackProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000071class TransmitMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010072class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000073class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000074
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:
kwiberg55b97fe2016-01-28 05:22:45 -080082 struct State {
83 State()
84 : rx_apm_is_enabled(false),
85 input_external_media(false),
86 output_file_playing(false),
87 input_file_playing(false),
88 playing(false),
89 sending(false),
90 receiving(false) {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000091
kwiberg55b97fe2016-01-28 05:22:45 -080092 bool rx_apm_is_enabled;
93 bool input_external_media;
94 bool output_file_playing;
95 bool input_file_playing;
96 bool playing;
97 bool sending;
98 bool receiving;
99 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000100
kwiberg55b97fe2016-01-28 05:22:45 -0800101 ChannelState() {}
102 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000103
kwiberg55b97fe2016-01-28 05:22:45 -0800104 void Reset() {
105 rtc::CritScope lock(&lock_);
106 state_ = State();
107 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000108
kwiberg55b97fe2016-01-28 05:22:45 -0800109 State Get() const {
110 rtc::CritScope lock(&lock_);
111 return state_;
112 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000113
kwiberg55b97fe2016-01-28 05:22:45 -0800114 void SetRxApmIsEnabled(bool enable) {
115 rtc::CritScope lock(&lock_);
116 state_.rx_apm_is_enabled = enable;
117 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000118
kwiberg55b97fe2016-01-28 05:22:45 -0800119 void SetInputExternalMedia(bool enable) {
120 rtc::CritScope lock(&lock_);
121 state_.input_external_media = enable;
122 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000123
kwiberg55b97fe2016-01-28 05:22:45 -0800124 void SetOutputFilePlaying(bool enable) {
125 rtc::CritScope lock(&lock_);
126 state_.output_file_playing = enable;
127 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000128
kwiberg55b97fe2016-01-28 05:22:45 -0800129 void SetInputFilePlaying(bool enable) {
130 rtc::CritScope lock(&lock_);
131 state_.input_file_playing = enable;
132 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000133
kwiberg55b97fe2016-01-28 05:22:45 -0800134 void SetPlaying(bool enable) {
135 rtc::CritScope lock(&lock_);
136 state_.playing = enable;
137 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000138
kwiberg55b97fe2016-01-28 05:22:45 -0800139 void SetSending(bool enable) {
140 rtc::CritScope lock(&lock_);
141 state_.sending = enable;
142 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000143
kwiberg55b97fe2016-01-28 05:22:45 -0800144 void SetReceiving(bool enable) {
145 rtc::CritScope lock(&lock_);
146 state_.receiving = enable;
147 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000148
kwiberg55b97fe2016-01-28 05:22:45 -0800149 private:
pbosd8de1152016-02-01 09:00:51 -0800150 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800151 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000152};
niklase@google.com470e71d2011-07-07 08:21:25 +0000153
kwiberg55b97fe2016-01-28 05:22:45 -0800154class Channel
155 : public RtpData,
156 public RtpFeedback,
157 public FileCallback, // receiving notification from file player &
158 // recorder
159 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800160 public AudioPacketizationCallback, // receive encoded packets from the
161 // ACM
162 public ACMVADCallback, // receive voice activity from the ACM
163 public MixerParticipant // supplies output mixer with audio frames
niklase@google.com470e71d2011-07-07 08:21:25 +0000164{
kwiberg55b97fe2016-01-28 05:22:45 -0800165 public:
166 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000167
kwiberg55b97fe2016-01-28 05:22:45 -0800168 enum { KNumSocketThreads = 1 };
169 enum { KNumberOfSocketBuffers = 8 };
170 virtual ~Channel();
171 static int32_t CreateChannel(Channel*& channel,
172 int32_t channelId,
173 uint32_t instanceId,
174 RtcEventLog* const event_log,
175 const Config& config);
176 Channel(int32_t channelId,
177 uint32_t instanceId,
178 RtcEventLog* const event_log,
179 const Config& config);
180 int32_t Init();
181 int32_t SetEngineInformation(Statistics& engineStatistics,
182 OutputMixer& outputMixer,
183 TransmitMixer& transmitMixer,
184 ProcessThread& moduleProcessThread,
185 AudioDeviceModule& audioDeviceModule,
186 VoiceEngineObserver* voiceEngineObserver,
187 rtc::CriticalSection* callbackCritSect);
188 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
kwibergb7f89d62016-02-17 10:04:18 -0800190 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100191
kwiberg55b97fe2016-01-28 05:22:45 -0800192 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
kwiberg55b97fe2016-01-28 05:22:45 -0800194 // VoEBase
195 int32_t StartPlayout();
196 int32_t StopPlayout();
197 int32_t StartSend();
198 int32_t StopSend();
199 int32_t StartReceiving();
200 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
kwiberg55b97fe2016-01-28 05:22:45 -0800202 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
203 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000204
kwiberg55b97fe2016-01-28 05:22:45 -0800205 // VoECodec
206 int32_t GetSendCodec(CodecInst& codec);
207 int32_t GetRecCodec(CodecInst& codec);
208 int32_t SetSendCodec(const CodecInst& codec);
209 void SetBitRate(int bitrate_bps);
210 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
211 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
212 int32_t SetRecPayloadType(const CodecInst& codec);
213 int32_t GetRecPayloadType(CodecInst& codec);
214 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
215 int SetOpusMaxPlaybackRate(int frequency_hz);
216 int SetOpusDtx(bool enable_dtx);
niklase@google.com470e71d2011-07-07 08:21:25 +0000217
kwiberg55b97fe2016-01-28 05:22:45 -0800218 // VoENetwork
219 int32_t RegisterExternalTransport(Transport& transport);
220 int32_t DeRegisterExternalTransport();
221 int32_t ReceivedRTPPacket(const int8_t* data,
222 size_t length,
223 const PacketTime& packet_time);
224 int32_t ReceivedRTCPPacket(const int8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000225
kwiberg55b97fe2016-01-28 05:22:45 -0800226 // VoEFile
227 int StartPlayingFileLocally(const char* fileName,
228 bool loop,
229 FileFormats format,
230 int startPosition,
231 float volumeScaling,
232 int stopPosition,
233 const CodecInst* codecInst);
234 int StartPlayingFileLocally(InStream* stream,
235 FileFormats format,
236 int startPosition,
237 float volumeScaling,
238 int stopPosition,
239 const CodecInst* codecInst);
240 int StopPlayingFileLocally();
241 int IsPlayingFileLocally() const;
242 int RegisterFilePlayingToMixer();
243 int StartPlayingFileAsMicrophone(const char* fileName,
244 bool loop,
245 FileFormats format,
246 int startPosition,
247 float volumeScaling,
248 int stopPosition,
249 const CodecInst* codecInst);
250 int StartPlayingFileAsMicrophone(InStream* stream,
251 FileFormats format,
252 int startPosition,
253 float volumeScaling,
254 int stopPosition,
255 const CodecInst* codecInst);
256 int StopPlayingFileAsMicrophone();
257 int IsPlayingFileAsMicrophone() const;
258 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
259 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
260 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000261
kwiberg55b97fe2016-01-28 05:22:45 -0800262 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000263
kwiberg55b97fe2016-01-28 05:22:45 -0800264 // VoEExternalMediaProcessing
265 int RegisterExternalMediaProcessing(ProcessingTypes type,
266 VoEMediaProcess& processObject);
267 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
268 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
kwiberg55b97fe2016-01-28 05:22:45 -0800270 // VoEVolumeControl
271 int GetSpeechOutputLevel(uint32_t& level) const;
272 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
solenberg1c2af8e2016-03-24 10:36:00 -0700273 int SetInputMute(bool enable);
274 bool InputMute() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800275 int SetOutputVolumePan(float left, float right);
276 int GetOutputVolumePan(float& left, float& right) const;
277 int SetChannelOutputVolumeScaling(float scaling);
278 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000279
kwiberg55b97fe2016-01-28 05:22:45 -0800280 // VoENetEqStats
281 int GetNetworkStatistics(NetworkStatistics& stats);
282 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000283
kwiberg55b97fe2016-01-28 05:22:45 -0800284 // VoEVideoSync
285 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
286 int* playout_buffer_delay_ms) const;
287 uint32_t GetDelayEstimate() const;
288 int LeastRequiredDelayMs() const;
289 int SetMinimumPlayoutDelay(int delayMs);
290 int GetPlayoutTimestamp(unsigned int& timestamp);
291 int SetInitTimestamp(unsigned int timestamp);
292 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000293
kwiberg55b97fe2016-01-28 05:22:45 -0800294 // VoEVideoSyncExtended
295 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000296
solenberg31642aa2016-03-14 08:00:37 -0700297 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800298 int SendTelephoneEventOutband(int event, int duration_ms);
solenberg31642aa2016-03-14 08:00:37 -0700299 int SetSendTelephoneEventPayloadType(int payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000300
kwiberg55b97fe2016-01-28 05:22:45 -0800301 // VoEAudioProcessingImpl
302 int UpdateRxVadDetection(AudioFrame& audioFrame);
303 int RegisterRxVadObserver(VoERxVadCallback& observer);
304 int DeRegisterRxVadObserver();
305 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000306#ifdef WEBRTC_VOICE_ENGINE_AGC
kwiberg55b97fe2016-01-28 05:22:45 -0800307 int SetRxAgcStatus(bool enable, AgcModes mode);
308 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
309 int SetRxAgcConfig(AgcConfig config);
310 int GetRxAgcConfig(AgcConfig& config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000311#endif
312#ifdef WEBRTC_VOICE_ENGINE_NR
kwiberg55b97fe2016-01-28 05:22:45 -0800313 int SetRxNsStatus(bool enable, NsModes mode);
314 int GetRxNsStatus(bool& enabled, NsModes& mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000315#endif
316
kwiberg55b97fe2016-01-28 05:22:45 -0800317 // VoERTP_RTCP
318 int SetLocalSSRC(unsigned int ssrc);
319 int GetLocalSSRC(unsigned int& ssrc);
320 int GetRemoteSSRC(unsigned int& ssrc);
321 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
322 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
323 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
324 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
325 void EnableSendTransportSequenceNumber(int id);
326 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100327
stefanbba9dec2016-02-01 04:39:55 -0800328 void RegisterSenderCongestionControlObjects(
329 RtpPacketSender* rtp_packet_sender,
330 TransportFeedbackObserver* transport_feedback_observer,
331 PacketRouter* packet_router);
332 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
333 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100334
kwiberg55b97fe2016-01-28 05:22:45 -0800335 void SetRTCPStatus(bool enable);
336 int GetRTCPStatus(bool& enabled);
337 int SetRTCP_CNAME(const char cName[256]);
338 int GetRemoteRTCP_CNAME(char cName[256]);
339 int GetRemoteRTCPData(unsigned int& NTPHigh,
340 unsigned int& NTPLow,
341 unsigned int& timestamp,
342 unsigned int& playoutTimestamp,
343 unsigned int* jitter,
344 unsigned short* fractionLost);
345 int SendApplicationDefinedRTCPPacket(unsigned char subType,
346 unsigned int name,
347 const char* data,
348 unsigned short dataLengthInBytes);
349 int GetRTPStatistics(unsigned int& averageJitterMs,
350 unsigned int& maxJitterMs,
351 unsigned int& discardedPackets);
352 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
353 int GetRTPStatistics(CallStatistics& stats);
354 int SetREDStatus(bool enable, int redPayloadtype);
355 int GetREDStatus(bool& enabled, int& redPayloadtype);
356 int SetCodecFECStatus(bool enable);
357 bool GetCodecFECStatus();
358 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000359
kwiberg55b97fe2016-01-28 05:22:45 -0800360 // From AudioPacketizationCallback in the ACM
361 int32_t SendData(FrameType frameType,
362 uint8_t payloadType,
363 uint32_t timeStamp,
364 const uint8_t* payloadData,
365 size_t payloadSize,
366 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000367
kwiberg55b97fe2016-01-28 05:22:45 -0800368 // From ACMVADCallback in the ACM
369 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000370
kwiberg55b97fe2016-01-28 05:22:45 -0800371 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000372
kwiberg55b97fe2016-01-28 05:22:45 -0800373 // From RtpData in the RTP/RTCP module
374 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
375 size_t payloadSize,
376 const WebRtcRTPHeader* rtpHeader) override;
377 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000378
kwiberg55b97fe2016-01-28 05:22:45 -0800379 // From RtpFeedback in the RTP/RTCP module
380 int32_t OnInitializeDecoder(int8_t payloadType,
381 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
382 int frequency,
383 size_t channels,
384 uint32_t rate) override;
385 void OnIncomingSSRCChanged(uint32_t ssrc) override;
386 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000387
kwiberg55b97fe2016-01-28 05:22:45 -0800388 // From Transport (called by the RTP/RTCP module)
389 bool SendRtp(const uint8_t* data,
390 size_t len,
391 const PacketOptions& packet_options) override;
392 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000393
kwiberg55b97fe2016-01-28 05:22:45 -0800394 // From MixerParticipant
395 int32_t GetAudioFrame(int32_t id, AudioFrame* audioFrame) override;
396 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000397
kwiberg55b97fe2016-01-28 05:22:45 -0800398 // From FileCallback
399 void PlayNotification(int32_t id, uint32_t durationMs) override;
400 void RecordNotification(int32_t id, uint32_t durationMs) override;
401 void PlayFileEnded(int32_t id) override;
402 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000403
kwiberg55b97fe2016-01-28 05:22:45 -0800404 uint32_t InstanceId() const { return _instanceId; }
405 int32_t ChannelId() const { return _channelId; }
406 bool Playing() const { return channel_state_.Get().playing; }
407 bool Sending() const { return channel_state_.Get().sending; }
408 bool Receiving() const { return channel_state_.Get().receiving; }
409 bool ExternalTransport() const {
410 rtc::CritScope cs(&_callbackCritSect);
411 return _externalTransport;
412 }
413 bool ExternalMixing() const { return _externalMixing; }
414 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
415 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
416 uint32_t Demultiplex(const AudioFrame& audioFrame);
417 // Demultiplex the data to the channel's |_audioFrame|. The difference
418 // between this method and the overloaded method above is that |audio_data|
419 // does not go through transmit_mixer and APM.
420 void Demultiplex(const int16_t* audio_data,
421 int sample_rate,
422 size_t number_of_frames,
423 size_t number_of_channels);
424 uint32_t PrepareEncodeAndSend(int mixingFrequency);
425 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000426
kwiberg55b97fe2016-01-28 05:22:45 -0800427 // Associate to a send channel.
428 // Used for obtaining RTT for a receive-only channel.
429 void set_associate_send_channel(const ChannelOwner& channel) {
430 assert(_channelId != channel.channel()->ChannelId());
431 rtc::CritScope lock(&assoc_send_channel_lock_);
432 associate_send_channel_ = channel;
433 }
Minyue2013aec2015-05-13 14:14:42 +0200434
kwiberg55b97fe2016-01-28 05:22:45 -0800435 // Disassociate a send channel if it was associated.
436 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200437
kwiberg55b97fe2016-01-28 05:22:45 -0800438 protected:
439 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000440
kwiberg55b97fe2016-01-28 05:22:45 -0800441 private:
442 bool ReceivePacket(const uint8_t* packet,
443 size_t packet_length,
444 const RTPHeader& header,
445 bool in_order);
446 bool HandleRtxPacket(const uint8_t* packet,
447 size_t packet_length,
448 const RTPHeader& header);
449 bool IsPacketInOrder(const RTPHeader& header) const;
450 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
451 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800452 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
453 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
454 void UpdatePlayoutTimestamp(bool rtcp);
455 void UpdatePacketDelay(uint32_t timestamp, uint16_t sequenceNumber);
456 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000457
kwiberg55b97fe2016-01-28 05:22:45 -0800458 int SetRedPayloadType(int red_payload_type);
459 int SetSendRtpHeaderExtension(bool enable,
460 RTPExtensionType type,
461 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000462
kwiberg55b97fe2016-01-28 05:22:45 -0800463 int32_t GetPlayoutFrequency();
464 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000465
pbosd8de1152016-02-01 09:00:51 -0800466 rtc::CriticalSection _fileCritSect;
467 rtc::CriticalSection _callbackCritSect;
468 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800469 uint32_t _instanceId;
470 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000471
kwiberg55b97fe2016-01-28 05:22:45 -0800472 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000473
kwiberg55b97fe2016-01-28 05:22:45 -0800474 RtcEventLog* const event_log_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200475
kwibergb7f89d62016-02-17 10:04:18 -0800476 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
477 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
478 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
479 std::unique_ptr<StatisticsProxy> statistics_proxy_;
480 std::unique_ptr<RtpReceiver> rtp_receiver_;
kwiberg55b97fe2016-01-28 05:22:45 -0800481 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800482 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
483 std::unique_ptr<AudioCodingModule> audio_coding_;
484 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800485 AudioLevel _outputAudioLevel;
486 bool _externalTransport;
487 AudioFrame _audioFrame;
488 // Downsamples to the codec rate if necessary.
489 PushResampler<int16_t> input_resampler_;
490 FilePlayer* _inputFilePlayerPtr;
491 FilePlayer* _outputFilePlayerPtr;
492 FileRecorder* _outputFileRecorderPtr;
493 int _inputFilePlayerId;
494 int _outputFilePlayerId;
495 int _outputFileRecorderId;
496 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800497 bool _outputExternalMedia;
498 VoEMediaProcess* _inputExternalMediaCallbackPtr;
499 VoEMediaProcess* _outputExternalMediaCallbackPtr;
500 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000501
kwiberg55b97fe2016-01-28 05:22:45 -0800502 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000503
kwiberg55b97fe2016-01-28 05:22:45 -0800504 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700505 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
kwiberg55b97fe2016-01-28 05:22:45 -0800506 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
507 uint32_t playout_timestamp_rtcp_;
508 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
509 uint32_t _numberOfDiscardedPackets;
510 uint16_t send_sequence_number_;
511 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000512
pbosd8de1152016-02-01 09:00:51 -0800513 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000514
kwibergb7f89d62016-02-17 10:04:18 -0800515 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800516 // The rtp timestamp of the first played out audio frame.
517 int64_t capture_start_rtp_time_stamp_;
518 // The capture ntp time (in local timebase) of the first played out audio
519 // frame.
520 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000521
kwiberg55b97fe2016-01-28 05:22:45 -0800522 // uses
523 Statistics* _engineStatisticsPtr;
524 OutputMixer* _outputMixerPtr;
525 TransmitMixer* _transmitMixerPtr;
526 ProcessThread* _moduleProcessThreadPtr;
527 AudioDeviceModule* _audioDeviceModulePtr;
528 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
529 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
530 Transport* _transportPtr; // WebRtc socket or external transport
531 RMSLevel rms_level_;
kwibergb7f89d62016-02-17 10:04:18 -0800532 std::unique_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800533 VoERxVadCallback* _rxVadObserverPtr;
534 int32_t _oldVadDecision;
535 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
536 // VoEBase
537 bool _externalMixing;
538 bool _mixFileWithMicrophone;
539 // VoEVolumeControl
solenberg1c2af8e2016-03-24 10:36:00 -0700540 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
541 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
542 float _panLeft GUARDED_BY(volume_settings_critsect_);
543 float _panRight GUARDED_BY(volume_settings_critsect_);
544 float _outputGain GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800545 // VoeRTP_RTCP
546 uint32_t _lastLocalTimeStamp;
547 int8_t _lastPayloadType;
548 bool _includeAudioLevelIndication;
549 // VoENetwork
550 AudioFrame::SpeechType _outputSpeechType;
551 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800552 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800553 uint32_t _average_jitter_buffer_delay_us GUARDED_BY(video_sync_lock_);
554 uint32_t _previousTimestamp;
555 uint16_t _recPacketDelayMs GUARDED_BY(video_sync_lock_);
556 // VoEAudioProcessing
557 bool _RxVadDetection;
558 bool _rxAgcIsEnabled;
559 bool _rxNsIsEnabled;
560 bool restored_packet_in_use_;
561 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800562 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
563 std::unique_ptr<NetworkPredictor> network_predictor_;
kwiberg55b97fe2016-01-28 05:22:45 -0800564 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800565 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800566 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100567
kwiberg55b97fe2016-01-28 05:22:45 -0800568 bool pacing_enabled_;
569 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800570 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
571 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
572 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000573};
574
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000575} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000576} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000577
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000578#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_