blob: 07a0f789da8f22c907658f8e0ca838f8c7d975e5 [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"
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000018#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000019#include "webrtc/common_types.h"
kjellander3e6db232015-11-26 04:44:54 -080020#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010021#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000022#include "webrtc/modules/audio_processing/rms_level.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010023#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
24#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
25#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
26#include "webrtc/modules/utility/include/file_player.h"
27#include "webrtc/modules/utility/include/file_recorder.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000028#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
wu@webrtc.org94454b72014-06-05 20:34:08 +000035namespace rtc {
36
37class TimestampWrapAroundHandler;
38}
39
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000040namespace webrtc {
41
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000042class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000043class Config;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000044class FileWrapper;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010045class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000046class ProcessThread;
47class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000048class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070049class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000050class RTPPayloadRegistry;
51class RtpReceiver;
52class RTPReceiverAudio;
53class RtpRtcp;
54class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000055class VoEMediaProcess;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000056class VoERTPObserver;
57class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
59struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000060struct ReportBlock;
61struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000063namespace voe {
64
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000065class OutputMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010066class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000067class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000068class StatisticsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010069class TransportFeedbackProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000070class TransmitMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010071class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000072class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000073
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000074// Helper class to simplify locking scheme for members that are accessed from
75// multiple threads.
76// Example: a member can be set on thread T1 and read by an internal audio
77// thread T2. Accessing the member via this class ensures that we are
78// safe and also avoid TSan v2 warnings.
79class ChannelState {
80 public:
kwiberg55b97fe2016-01-28 05:22:45 -080081 struct State {
82 State()
83 : rx_apm_is_enabled(false),
84 input_external_media(false),
85 output_file_playing(false),
86 input_file_playing(false),
87 playing(false),
88 sending(false),
89 receiving(false) {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000090
kwiberg55b97fe2016-01-28 05:22:45 -080091 bool rx_apm_is_enabled;
92 bool input_external_media;
93 bool output_file_playing;
94 bool input_file_playing;
95 bool playing;
96 bool sending;
97 bool receiving;
98 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000099
kwiberg55b97fe2016-01-28 05:22:45 -0800100 ChannelState() {}
101 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000102
kwiberg55b97fe2016-01-28 05:22:45 -0800103 void Reset() {
104 rtc::CritScope lock(&lock_);
105 state_ = State();
106 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000107
kwiberg55b97fe2016-01-28 05:22:45 -0800108 State Get() const {
109 rtc::CritScope lock(&lock_);
110 return state_;
111 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000112
kwiberg55b97fe2016-01-28 05:22:45 -0800113 void SetRxApmIsEnabled(bool enable) {
114 rtc::CritScope lock(&lock_);
115 state_.rx_apm_is_enabled = enable;
116 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000117
kwiberg55b97fe2016-01-28 05:22:45 -0800118 void SetInputExternalMedia(bool enable) {
119 rtc::CritScope lock(&lock_);
120 state_.input_external_media = enable;
121 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000122
kwiberg55b97fe2016-01-28 05:22:45 -0800123 void SetOutputFilePlaying(bool enable) {
124 rtc::CritScope lock(&lock_);
125 state_.output_file_playing = enable;
126 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000127
kwiberg55b97fe2016-01-28 05:22:45 -0800128 void SetInputFilePlaying(bool enable) {
129 rtc::CritScope lock(&lock_);
130 state_.input_file_playing = enable;
131 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000132
kwiberg55b97fe2016-01-28 05:22:45 -0800133 void SetPlaying(bool enable) {
134 rtc::CritScope lock(&lock_);
135 state_.playing = enable;
136 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000137
kwiberg55b97fe2016-01-28 05:22:45 -0800138 void SetSending(bool enable) {
139 rtc::CritScope lock(&lock_);
140 state_.sending = enable;
141 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000142
kwiberg55b97fe2016-01-28 05:22:45 -0800143 void SetReceiving(bool enable) {
144 rtc::CritScope lock(&lock_);
145 state_.receiving = enable;
146 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000147
kwiberg55b97fe2016-01-28 05:22:45 -0800148 private:
pbosd8de1152016-02-01 09:00:51 -0800149 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800150 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000151};
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
kwiberg55b97fe2016-01-28 05:22:45 -0800153class Channel
154 : public RtpData,
155 public RtpFeedback,
156 public FileCallback, // receiving notification from file player &
157 // recorder
158 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800159 public AudioPacketizationCallback, // receive encoded packets from the
160 // ACM
161 public ACMVADCallback, // receive voice activity from the ACM
162 public MixerParticipant // supplies output mixer with audio frames
niklase@google.com470e71d2011-07-07 08:21:25 +0000163{
kwiberg55b97fe2016-01-28 05:22:45 -0800164 public:
165 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000166
kwiberg55b97fe2016-01-28 05:22:45 -0800167 enum { KNumSocketThreads = 1 };
168 enum { KNumberOfSocketBuffers = 8 };
169 virtual ~Channel();
170 static int32_t CreateChannel(Channel*& channel,
171 int32_t channelId,
172 uint32_t instanceId,
173 RtcEventLog* const event_log,
174 const Config& config);
175 Channel(int32_t channelId,
176 uint32_t instanceId,
177 RtcEventLog* const event_log,
178 const Config& config);
179 int32_t Init();
180 int32_t SetEngineInformation(Statistics& engineStatistics,
181 OutputMixer& outputMixer,
182 TransmitMixer& transmitMixer,
183 ProcessThread& moduleProcessThread,
184 AudioDeviceModule& audioDeviceModule,
185 VoiceEngineObserver* voiceEngineObserver,
186 rtc::CriticalSection* callbackCritSect);
187 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000188
kwibergb7f89d62016-02-17 10:04:18 -0800189 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100190
kwiberg55b97fe2016-01-28 05:22:45 -0800191 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000192
kwiberg55b97fe2016-01-28 05:22:45 -0800193 // VoEBase
194 int32_t StartPlayout();
195 int32_t StopPlayout();
196 int32_t StartSend();
197 int32_t StopSend();
198 int32_t StartReceiving();
199 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000200
kwiberg55b97fe2016-01-28 05:22:45 -0800201 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
202 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000203
kwiberg55b97fe2016-01-28 05:22:45 -0800204 // VoECodec
205 int32_t GetSendCodec(CodecInst& codec);
206 int32_t GetRecCodec(CodecInst& codec);
207 int32_t SetSendCodec(const CodecInst& codec);
208 void SetBitRate(int bitrate_bps);
209 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
210 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
211 int32_t SetRecPayloadType(const CodecInst& codec);
212 int32_t GetRecPayloadType(CodecInst& codec);
213 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
214 int SetOpusMaxPlaybackRate(int frequency_hz);
215 int SetOpusDtx(bool enable_dtx);
niklase@google.com470e71d2011-07-07 08:21:25 +0000216
kwiberg55b97fe2016-01-28 05:22:45 -0800217 // VoENetwork
218 int32_t RegisterExternalTransport(Transport& transport);
219 int32_t DeRegisterExternalTransport();
220 int32_t ReceivedRTPPacket(const int8_t* data,
221 size_t length,
222 const PacketTime& packet_time);
223 int32_t ReceivedRTCPPacket(const int8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000224
kwiberg55b97fe2016-01-28 05:22:45 -0800225 // VoEFile
226 int StartPlayingFileLocally(const char* fileName,
227 bool loop,
228 FileFormats format,
229 int startPosition,
230 float volumeScaling,
231 int stopPosition,
232 const CodecInst* codecInst);
233 int StartPlayingFileLocally(InStream* stream,
234 FileFormats format,
235 int startPosition,
236 float volumeScaling,
237 int stopPosition,
238 const CodecInst* codecInst);
239 int StopPlayingFileLocally();
240 int IsPlayingFileLocally() const;
241 int RegisterFilePlayingToMixer();
242 int StartPlayingFileAsMicrophone(const char* fileName,
243 bool loop,
244 FileFormats format,
245 int startPosition,
246 float volumeScaling,
247 int stopPosition,
248 const CodecInst* codecInst);
249 int StartPlayingFileAsMicrophone(InStream* stream,
250 FileFormats format,
251 int startPosition,
252 float volumeScaling,
253 int stopPosition,
254 const CodecInst* codecInst);
255 int StopPlayingFileAsMicrophone();
256 int IsPlayingFileAsMicrophone() const;
257 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
258 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
259 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000260
kwiberg55b97fe2016-01-28 05:22:45 -0800261 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000262
kwiberg55b97fe2016-01-28 05:22:45 -0800263 // VoEExternalMediaProcessing
264 int RegisterExternalMediaProcessing(ProcessingTypes type,
265 VoEMediaProcess& processObject);
266 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
267 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000268
kwiberg55b97fe2016-01-28 05:22:45 -0800269 // VoEVolumeControl
270 int GetSpeechOutputLevel(uint32_t& level) const;
271 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
solenberg1c2af8e2016-03-24 10:36:00 -0700272 int SetInputMute(bool enable);
273 bool InputMute() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800274 int SetOutputVolumePan(float left, float right);
275 int GetOutputVolumePan(float& left, float& right) const;
276 int SetChannelOutputVolumeScaling(float scaling);
277 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000278
kwiberg55b97fe2016-01-28 05:22:45 -0800279 // VoENetEqStats
280 int GetNetworkStatistics(NetworkStatistics& stats);
281 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000282
kwiberg55b97fe2016-01-28 05:22:45 -0800283 // VoEVideoSync
284 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
285 int* playout_buffer_delay_ms) const;
286 uint32_t GetDelayEstimate() const;
287 int LeastRequiredDelayMs() const;
288 int SetMinimumPlayoutDelay(int delayMs);
289 int GetPlayoutTimestamp(unsigned int& timestamp);
290 int SetInitTimestamp(unsigned int timestamp);
291 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000292
kwiberg55b97fe2016-01-28 05:22:45 -0800293 // VoEVideoSyncExtended
294 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000295
solenberg31642aa2016-03-14 08:00:37 -0700296 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800297 int SendTelephoneEventOutband(int event, int duration_ms);
solenberg31642aa2016-03-14 08:00:37 -0700298 int SetSendTelephoneEventPayloadType(int payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000299
kwiberg55b97fe2016-01-28 05:22:45 -0800300 // VoEAudioProcessingImpl
301 int UpdateRxVadDetection(AudioFrame& audioFrame);
302 int RegisterRxVadObserver(VoERxVadCallback& observer);
303 int DeRegisterRxVadObserver();
304 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000305#ifdef WEBRTC_VOICE_ENGINE_AGC
kwiberg55b97fe2016-01-28 05:22:45 -0800306 int SetRxAgcStatus(bool enable, AgcModes mode);
307 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
308 int SetRxAgcConfig(AgcConfig config);
309 int GetRxAgcConfig(AgcConfig& config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000310#endif
311#ifdef WEBRTC_VOICE_ENGINE_NR
kwiberg55b97fe2016-01-28 05:22:45 -0800312 int SetRxNsStatus(bool enable, NsModes mode);
313 int GetRxNsStatus(bool& enabled, NsModes& mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000314#endif
315
kwiberg55b97fe2016-01-28 05:22:45 -0800316 // VoERTP_RTCP
317 int SetLocalSSRC(unsigned int ssrc);
318 int GetLocalSSRC(unsigned int& ssrc);
319 int GetRemoteSSRC(unsigned int& ssrc);
320 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
321 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
322 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
323 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
324 void EnableSendTransportSequenceNumber(int id);
325 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100326
stefanbba9dec2016-02-01 04:39:55 -0800327 void RegisterSenderCongestionControlObjects(
328 RtpPacketSender* rtp_packet_sender,
329 TransportFeedbackObserver* transport_feedback_observer,
330 PacketRouter* packet_router);
331 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
332 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100333
kwiberg55b97fe2016-01-28 05:22:45 -0800334 void SetRTCPStatus(bool enable);
335 int GetRTCPStatus(bool& enabled);
336 int SetRTCP_CNAME(const char cName[256]);
337 int GetRemoteRTCP_CNAME(char cName[256]);
338 int GetRemoteRTCPData(unsigned int& NTPHigh,
339 unsigned int& NTPLow,
340 unsigned int& timestamp,
341 unsigned int& playoutTimestamp,
342 unsigned int* jitter,
343 unsigned short* fractionLost);
344 int SendApplicationDefinedRTCPPacket(unsigned char subType,
345 unsigned int name,
346 const char* data,
347 unsigned short dataLengthInBytes);
348 int GetRTPStatistics(unsigned int& averageJitterMs,
349 unsigned int& maxJitterMs,
350 unsigned int& discardedPackets);
351 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
352 int GetRTPStatistics(CallStatistics& stats);
353 int SetREDStatus(bool enable, int redPayloadtype);
354 int GetREDStatus(bool& enabled, int& redPayloadtype);
355 int SetCodecFECStatus(bool enable);
356 bool GetCodecFECStatus();
357 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000358
kwiberg55b97fe2016-01-28 05:22:45 -0800359 // From AudioPacketizationCallback in the ACM
360 int32_t SendData(FrameType frameType,
361 uint8_t payloadType,
362 uint32_t timeStamp,
363 const uint8_t* payloadData,
364 size_t payloadSize,
365 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000366
kwiberg55b97fe2016-01-28 05:22:45 -0800367 // From ACMVADCallback in the ACM
368 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000369
kwiberg55b97fe2016-01-28 05:22:45 -0800370 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000371
kwiberg55b97fe2016-01-28 05:22:45 -0800372 // From RtpData in the RTP/RTCP module
373 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
374 size_t payloadSize,
375 const WebRtcRTPHeader* rtpHeader) override;
376 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000377
kwiberg55b97fe2016-01-28 05:22:45 -0800378 // From RtpFeedback in the RTP/RTCP module
379 int32_t OnInitializeDecoder(int8_t payloadType,
380 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
381 int frequency,
382 size_t channels,
383 uint32_t rate) override;
384 void OnIncomingSSRCChanged(uint32_t ssrc) override;
385 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000386
kwiberg55b97fe2016-01-28 05:22:45 -0800387 // From Transport (called by the RTP/RTCP module)
388 bool SendRtp(const uint8_t* data,
389 size_t len,
390 const PacketOptions& packet_options) override;
391 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000392
kwiberg55b97fe2016-01-28 05:22:45 -0800393 // From MixerParticipant
394 int32_t GetAudioFrame(int32_t id, AudioFrame* audioFrame) override;
395 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000396
kwiberg55b97fe2016-01-28 05:22:45 -0800397 // From FileCallback
398 void PlayNotification(int32_t id, uint32_t durationMs) override;
399 void RecordNotification(int32_t id, uint32_t durationMs) override;
400 void PlayFileEnded(int32_t id) override;
401 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000402
kwiberg55b97fe2016-01-28 05:22:45 -0800403 uint32_t InstanceId() const { return _instanceId; }
404 int32_t ChannelId() const { return _channelId; }
405 bool Playing() const { return channel_state_.Get().playing; }
406 bool Sending() const { return channel_state_.Get().sending; }
407 bool Receiving() const { return channel_state_.Get().receiving; }
408 bool ExternalTransport() const {
409 rtc::CritScope cs(&_callbackCritSect);
410 return _externalTransport;
411 }
412 bool ExternalMixing() const { return _externalMixing; }
413 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
414 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
415 uint32_t Demultiplex(const AudioFrame& audioFrame);
416 // Demultiplex the data to the channel's |_audioFrame|. The difference
417 // between this method and the overloaded method above is that |audio_data|
418 // does not go through transmit_mixer and APM.
419 void Demultiplex(const int16_t* audio_data,
420 int sample_rate,
421 size_t number_of_frames,
422 size_t number_of_channels);
423 uint32_t PrepareEncodeAndSend(int mixingFrequency);
424 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000425
kwiberg55b97fe2016-01-28 05:22:45 -0800426 // Associate to a send channel.
427 // Used for obtaining RTT for a receive-only channel.
428 void set_associate_send_channel(const ChannelOwner& channel) {
429 assert(_channelId != channel.channel()->ChannelId());
430 rtc::CritScope lock(&assoc_send_channel_lock_);
431 associate_send_channel_ = channel;
432 }
Minyue2013aec2015-05-13 14:14:42 +0200433
kwiberg55b97fe2016-01-28 05:22:45 -0800434 // Disassociate a send channel if it was associated.
435 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200436
kwiberg55b97fe2016-01-28 05:22:45 -0800437 protected:
438 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000439
kwiberg55b97fe2016-01-28 05:22:45 -0800440 private:
441 bool ReceivePacket(const uint8_t* packet,
442 size_t packet_length,
443 const RTPHeader& header,
444 bool in_order);
445 bool HandleRtxPacket(const uint8_t* packet,
446 size_t packet_length,
447 const RTPHeader& header);
448 bool IsPacketInOrder(const RTPHeader& header) const;
449 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
450 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800451 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
452 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
453 void UpdatePlayoutTimestamp(bool rtcp);
454 void UpdatePacketDelay(uint32_t timestamp, uint16_t sequenceNumber);
455 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000456
kwiberg55b97fe2016-01-28 05:22:45 -0800457 int SetRedPayloadType(int red_payload_type);
458 int SetSendRtpHeaderExtension(bool enable,
459 RTPExtensionType type,
460 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000461
kwiberg55b97fe2016-01-28 05:22:45 -0800462 int32_t GetPlayoutFrequency();
463 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000464
pbosd8de1152016-02-01 09:00:51 -0800465 rtc::CriticalSection _fileCritSect;
466 rtc::CriticalSection _callbackCritSect;
467 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800468 uint32_t _instanceId;
469 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000470
kwiberg55b97fe2016-01-28 05:22:45 -0800471 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000472
kwiberg55b97fe2016-01-28 05:22:45 -0800473 RtcEventLog* const event_log_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200474
kwibergb7f89d62016-02-17 10:04:18 -0800475 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
476 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
477 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
478 std::unique_ptr<StatisticsProxy> statistics_proxy_;
479 std::unique_ptr<RtpReceiver> rtp_receiver_;
kwiberg55b97fe2016-01-28 05:22:45 -0800480 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800481 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
482 std::unique_ptr<AudioCodingModule> audio_coding_;
483 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800484 AudioLevel _outputAudioLevel;
485 bool _externalTransport;
486 AudioFrame _audioFrame;
487 // Downsamples to the codec rate if necessary.
488 PushResampler<int16_t> input_resampler_;
489 FilePlayer* _inputFilePlayerPtr;
490 FilePlayer* _outputFilePlayerPtr;
491 FileRecorder* _outputFileRecorderPtr;
492 int _inputFilePlayerId;
493 int _outputFilePlayerId;
494 int _outputFileRecorderId;
495 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800496 bool _outputExternalMedia;
497 VoEMediaProcess* _inputExternalMediaCallbackPtr;
498 VoEMediaProcess* _outputExternalMediaCallbackPtr;
499 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000500
kwiberg55b97fe2016-01-28 05:22:45 -0800501 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000502
kwiberg55b97fe2016-01-28 05:22:45 -0800503 // Timestamp of the audio pulled from NetEq.
504 uint32_t jitter_buffer_playout_timestamp_;
505 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
506 uint32_t playout_timestamp_rtcp_;
507 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
508 uint32_t _numberOfDiscardedPackets;
509 uint16_t send_sequence_number_;
510 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000511
pbosd8de1152016-02-01 09:00:51 -0800512 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000513
kwibergb7f89d62016-02-17 10:04:18 -0800514 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800515 // The rtp timestamp of the first played out audio frame.
516 int64_t capture_start_rtp_time_stamp_;
517 // The capture ntp time (in local timebase) of the first played out audio
518 // frame.
519 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000520
kwiberg55b97fe2016-01-28 05:22:45 -0800521 // uses
522 Statistics* _engineStatisticsPtr;
523 OutputMixer* _outputMixerPtr;
524 TransmitMixer* _transmitMixerPtr;
525 ProcessThread* _moduleProcessThreadPtr;
526 AudioDeviceModule* _audioDeviceModulePtr;
527 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
528 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
529 Transport* _transportPtr; // WebRtc socket or external transport
530 RMSLevel rms_level_;
kwibergb7f89d62016-02-17 10:04:18 -0800531 std::unique_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800532 VoERxVadCallback* _rxVadObserverPtr;
533 int32_t _oldVadDecision;
534 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
535 // VoEBase
536 bool _externalMixing;
537 bool _mixFileWithMicrophone;
538 // VoEVolumeControl
solenberg1c2af8e2016-03-24 10:36:00 -0700539 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
540 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
541 float _panLeft GUARDED_BY(volume_settings_critsect_);
542 float _panRight GUARDED_BY(volume_settings_critsect_);
543 float _outputGain GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800544 // VoeRTP_RTCP
545 uint32_t _lastLocalTimeStamp;
546 int8_t _lastPayloadType;
547 bool _includeAudioLevelIndication;
548 // VoENetwork
549 AudioFrame::SpeechType _outputSpeechType;
550 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800551 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800552 uint32_t _average_jitter_buffer_delay_us GUARDED_BY(video_sync_lock_);
553 uint32_t _previousTimestamp;
554 uint16_t _recPacketDelayMs GUARDED_BY(video_sync_lock_);
555 // VoEAudioProcessing
556 bool _RxVadDetection;
557 bool _rxAgcIsEnabled;
558 bool _rxNsIsEnabled;
559 bool restored_packet_in_use_;
560 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800561 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
562 std::unique_ptr<NetworkPredictor> network_predictor_;
kwiberg55b97fe2016-01-28 05:22:45 -0800563 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800564 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800565 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100566
kwiberg55b97fe2016-01-28 05:22:45 -0800567 bool pacing_enabled_;
568 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800569 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
570 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
571 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000572};
573
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000574} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000575} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000576
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000577#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_