blob: 68211a605aafea0e5831a8982dc169077922ee3f [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"
kwiberge7edea92016-06-22 16:29:55 -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 {
39
40class TimestampWrapAroundHandler;
41}
42
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000043namespace webrtc {
44
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000045class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000046class Config;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000047class FileWrapper;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010048class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049class ProcessThread;
50class 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();
174 static int32_t CreateChannel(Channel*& channel,
175 int32_t channelId,
176 uint32_t instanceId,
kwiberg55b97fe2016-01-28 05:22:45 -0800177 const Config& config);
ossu5f7cfa52016-05-30 08:11:28 -0700178 static int32_t CreateChannel(
179 Channel*& channel,
180 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 Channel(int32_t channelId,
185 uint32_t instanceId,
ossu5f7cfa52016-05-30 08:11:28 -0700186 const Config& config,
187 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory);
kwiberg55b97fe2016-01-28 05:22:45 -0800188 int32_t Init();
189 int32_t SetEngineInformation(Statistics& engineStatistics,
190 OutputMixer& outputMixer,
191 TransmitMixer& transmitMixer,
192 ProcessThread& moduleProcessThread,
193 AudioDeviceModule& audioDeviceModule,
194 VoiceEngineObserver* voiceEngineObserver,
195 rtc::CriticalSection* callbackCritSect);
196 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000197
kwibergb7f89d62016-02-17 10:04:18 -0800198 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100199
ossu29b1a8d2016-06-13 07:34:51 -0700200 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
201 // passed into AudioReceiveStream is the same as the one set when creating the
202 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
203 // go.
204 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
205
kwiberg55b97fe2016-01-28 05:22:45 -0800206 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
kwiberg55b97fe2016-01-28 05:22:45 -0800208 // VoEBase
209 int32_t StartPlayout();
210 int32_t StopPlayout();
211 int32_t StartSend();
212 int32_t StopSend();
213 int32_t StartReceiving();
214 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000215
kwiberg55b97fe2016-01-28 05:22:45 -0800216 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
217 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000218
kwiberg55b97fe2016-01-28 05:22:45 -0800219 // VoECodec
220 int32_t GetSendCodec(CodecInst& codec);
221 int32_t GetRecCodec(CodecInst& codec);
222 int32_t SetSendCodec(const CodecInst& codec);
223 void SetBitRate(int bitrate_bps);
224 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
225 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
226 int32_t SetRecPayloadType(const CodecInst& codec);
227 int32_t GetRecPayloadType(CodecInst& codec);
228 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
229 int SetOpusMaxPlaybackRate(int frequency_hz);
230 int SetOpusDtx(bool enable_dtx);
niklase@google.com470e71d2011-07-07 08:21:25 +0000231
kwiberg55b97fe2016-01-28 05:22:45 -0800232 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700233 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800234 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700235 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800236 size_t length,
237 const PacketTime& packet_time);
mflodman3d7db262016-04-29 00:57:13 -0700238 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000239
kwiberg55b97fe2016-01-28 05:22:45 -0800240 // VoEFile
241 int StartPlayingFileLocally(const char* fileName,
242 bool loop,
243 FileFormats format,
244 int startPosition,
245 float volumeScaling,
246 int stopPosition,
247 const CodecInst* codecInst);
248 int StartPlayingFileLocally(InStream* stream,
249 FileFormats format,
250 int startPosition,
251 float volumeScaling,
252 int stopPosition,
253 const CodecInst* codecInst);
254 int StopPlayingFileLocally();
255 int IsPlayingFileLocally() const;
256 int RegisterFilePlayingToMixer();
257 int StartPlayingFileAsMicrophone(const char* fileName,
258 bool loop,
259 FileFormats format,
260 int startPosition,
261 float volumeScaling,
262 int stopPosition,
263 const CodecInst* codecInst);
264 int StartPlayingFileAsMicrophone(InStream* stream,
265 FileFormats format,
266 int startPosition,
267 float volumeScaling,
268 int stopPosition,
269 const CodecInst* codecInst);
270 int StopPlayingFileAsMicrophone();
271 int IsPlayingFileAsMicrophone() const;
272 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
273 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
274 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000275
kwiberg55b97fe2016-01-28 05:22:45 -0800276 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000277
kwiberg55b97fe2016-01-28 05:22:45 -0800278 // VoEExternalMediaProcessing
279 int RegisterExternalMediaProcessing(ProcessingTypes type,
280 VoEMediaProcess& processObject);
281 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
282 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000283
kwiberg55b97fe2016-01-28 05:22:45 -0800284 // VoEVolumeControl
285 int GetSpeechOutputLevel(uint32_t& level) const;
286 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
solenberg1c2af8e2016-03-24 10:36:00 -0700287 int SetInputMute(bool enable);
288 bool InputMute() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800289 int SetOutputVolumePan(float left, float right);
290 int GetOutputVolumePan(float& left, float& right) const;
291 int SetChannelOutputVolumeScaling(float scaling);
292 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000293
kwiberg55b97fe2016-01-28 05:22:45 -0800294 // VoENetEqStats
295 int GetNetworkStatistics(NetworkStatistics& stats);
296 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000297
kwiberg55b97fe2016-01-28 05:22:45 -0800298 // VoEVideoSync
299 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
300 int* playout_buffer_delay_ms) const;
301 uint32_t GetDelayEstimate() const;
302 int LeastRequiredDelayMs() const;
303 int SetMinimumPlayoutDelay(int delayMs);
304 int GetPlayoutTimestamp(unsigned int& timestamp);
305 int SetInitTimestamp(unsigned int timestamp);
306 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000307
kwiberg55b97fe2016-01-28 05:22:45 -0800308 // VoEVideoSyncExtended
309 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000310
solenberg31642aa2016-03-14 08:00:37 -0700311 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800312 int SendTelephoneEventOutband(int event, int duration_ms);
solenberg31642aa2016-03-14 08:00:37 -0700313 int SetSendTelephoneEventPayloadType(int payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000314
kwiberg55b97fe2016-01-28 05:22:45 -0800315 // VoEAudioProcessingImpl
316 int UpdateRxVadDetection(AudioFrame& audioFrame);
317 int RegisterRxVadObserver(VoERxVadCallback& observer);
318 int DeRegisterRxVadObserver();
319 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000320#ifdef WEBRTC_VOICE_ENGINE_AGC
kwiberg55b97fe2016-01-28 05:22:45 -0800321 int SetRxAgcStatus(bool enable, AgcModes mode);
322 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
323 int SetRxAgcConfig(AgcConfig config);
324 int GetRxAgcConfig(AgcConfig& config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000325#endif
326#ifdef WEBRTC_VOICE_ENGINE_NR
kwiberg55b97fe2016-01-28 05:22:45 -0800327 int SetRxNsStatus(bool enable, NsModes mode);
328 int GetRxNsStatus(bool& enabled, NsModes& mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000329#endif
330
kwiberg55b97fe2016-01-28 05:22:45 -0800331 // VoERTP_RTCP
332 int SetLocalSSRC(unsigned int ssrc);
333 int GetLocalSSRC(unsigned int& ssrc);
334 int GetRemoteSSRC(unsigned int& ssrc);
335 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
336 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
337 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
338 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
339 void EnableSendTransportSequenceNumber(int id);
340 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100341
stefanbba9dec2016-02-01 04:39:55 -0800342 void RegisterSenderCongestionControlObjects(
343 RtpPacketSender* rtp_packet_sender,
344 TransportFeedbackObserver* transport_feedback_observer,
345 PacketRouter* packet_router);
346 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
347 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100348
kwiberg55b97fe2016-01-28 05:22:45 -0800349 void SetRTCPStatus(bool enable);
350 int GetRTCPStatus(bool& enabled);
351 int SetRTCP_CNAME(const char cName[256]);
352 int GetRemoteRTCP_CNAME(char cName[256]);
353 int GetRemoteRTCPData(unsigned int& NTPHigh,
354 unsigned int& NTPLow,
355 unsigned int& timestamp,
356 unsigned int& playoutTimestamp,
357 unsigned int* jitter,
358 unsigned short* fractionLost);
359 int SendApplicationDefinedRTCPPacket(unsigned char subType,
360 unsigned int name,
361 const char* data,
362 unsigned short dataLengthInBytes);
363 int GetRTPStatistics(unsigned int& averageJitterMs,
364 unsigned int& maxJitterMs,
365 unsigned int& discardedPackets);
366 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
367 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800368 int SetCodecFECStatus(bool enable);
369 bool GetCodecFECStatus();
370 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000371
kwiberg55b97fe2016-01-28 05:22:45 -0800372 // From AudioPacketizationCallback in the ACM
373 int32_t SendData(FrameType frameType,
374 uint8_t payloadType,
375 uint32_t timeStamp,
376 const uint8_t* payloadData,
377 size_t payloadSize,
378 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000379
kwiberg55b97fe2016-01-28 05:22:45 -0800380 // From ACMVADCallback in the ACM
381 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000382
kwiberg55b97fe2016-01-28 05:22:45 -0800383 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000384
kwiberg55b97fe2016-01-28 05:22:45 -0800385 // From RtpData in the RTP/RTCP module
386 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
387 size_t payloadSize,
388 const WebRtcRTPHeader* rtpHeader) override;
389 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000390
kwiberg55b97fe2016-01-28 05:22:45 -0800391 // From RtpFeedback in the RTP/RTCP module
392 int32_t OnInitializeDecoder(int8_t payloadType,
393 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
394 int frequency,
395 size_t channels,
396 uint32_t rate) override;
397 void OnIncomingSSRCChanged(uint32_t ssrc) override;
398 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000399
kwiberg55b97fe2016-01-28 05:22:45 -0800400 // From Transport (called by the RTP/RTCP module)
401 bool SendRtp(const uint8_t* data,
402 size_t len,
403 const PacketOptions& packet_options) override;
404 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000405
kwiberg55b97fe2016-01-28 05:22:45 -0800406 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700407 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
408 int32_t id,
409 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800410 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000411
kwiberg55b97fe2016-01-28 05:22:45 -0800412 // From FileCallback
413 void PlayNotification(int32_t id, uint32_t durationMs) override;
414 void RecordNotification(int32_t id, uint32_t durationMs) override;
415 void PlayFileEnded(int32_t id) override;
416 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000417
kwiberg55b97fe2016-01-28 05:22:45 -0800418 uint32_t InstanceId() const { return _instanceId; }
419 int32_t ChannelId() const { return _channelId; }
420 bool Playing() const { return channel_state_.Get().playing; }
421 bool Sending() const { return channel_state_.Get().sending; }
422 bool Receiving() const { return channel_state_.Get().receiving; }
423 bool ExternalTransport() const {
424 rtc::CritScope cs(&_callbackCritSect);
425 return _externalTransport;
426 }
427 bool ExternalMixing() const { return _externalMixing; }
428 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
429 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
430 uint32_t Demultiplex(const AudioFrame& audioFrame);
431 // Demultiplex the data to the channel's |_audioFrame|. The difference
432 // between this method and the overloaded method above is that |audio_data|
433 // does not go through transmit_mixer and APM.
434 void Demultiplex(const int16_t* audio_data,
435 int sample_rate,
436 size_t number_of_frames,
437 size_t number_of_channels);
438 uint32_t PrepareEncodeAndSend(int mixingFrequency);
439 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000440
kwiberg55b97fe2016-01-28 05:22:45 -0800441 // Associate to a send channel.
442 // Used for obtaining RTT for a receive-only channel.
443 void set_associate_send_channel(const ChannelOwner& channel) {
444 assert(_channelId != channel.channel()->ChannelId());
445 rtc::CritScope lock(&assoc_send_channel_lock_);
446 associate_send_channel_ = channel;
447 }
Minyue2013aec2015-05-13 14:14:42 +0200448
kwiberg55b97fe2016-01-28 05:22:45 -0800449 // Disassociate a send channel if it was associated.
450 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200451
ivoc14d5dbe2016-07-04 07:06:55 -0700452 // Set a RtcEventLog logging object.
453 void SetRtcEventLog(RtcEventLog* event_log);
454
kwiberg55b97fe2016-01-28 05:22:45 -0800455 protected:
456 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000457
kwiberg55b97fe2016-01-28 05:22:45 -0800458 private:
459 bool ReceivePacket(const uint8_t* packet,
460 size_t packet_length,
461 const RTPHeader& header,
462 bool in_order);
463 bool HandleRtxPacket(const uint8_t* packet,
464 size_t packet_length,
465 const RTPHeader& header);
466 bool IsPacketInOrder(const RTPHeader& header) const;
467 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
468 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800469 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
470 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
471 void UpdatePlayoutTimestamp(bool rtcp);
472 void UpdatePacketDelay(uint32_t timestamp, uint16_t sequenceNumber);
473 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000474
kwiberg55b97fe2016-01-28 05:22:45 -0800475 int SetSendRtpHeaderExtension(bool enable,
476 RTPExtensionType type,
477 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000478
kwiberg55b97fe2016-01-28 05:22:45 -0800479 int32_t GetPlayoutFrequency();
480 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000481
pbosd8de1152016-02-01 09:00:51 -0800482 rtc::CriticalSection _fileCritSect;
483 rtc::CriticalSection _callbackCritSect;
484 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800485 uint32_t _instanceId;
486 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000487
kwiberg55b97fe2016-01-28 05:22:45 -0800488 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000489
ivoc14d5dbe2016-07-04 07:06:55 -0700490 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200491
kwibergb7f89d62016-02-17 10:04:18 -0800492 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
493 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
494 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
495 std::unique_ptr<StatisticsProxy> statistics_proxy_;
496 std::unique_ptr<RtpReceiver> rtp_receiver_;
kwiberg55b97fe2016-01-28 05:22:45 -0800497 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800498 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
499 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700500 acm2::CodecManager codec_manager_;
501 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800502 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800503 AudioLevel _outputAudioLevel;
504 bool _externalTransport;
505 AudioFrame _audioFrame;
506 // Downsamples to the codec rate if necessary.
507 PushResampler<int16_t> input_resampler_;
508 FilePlayer* _inputFilePlayerPtr;
509 FilePlayer* _outputFilePlayerPtr;
510 FileRecorder* _outputFileRecorderPtr;
511 int _inputFilePlayerId;
512 int _outputFilePlayerId;
513 int _outputFileRecorderId;
514 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800515 bool _outputExternalMedia;
516 VoEMediaProcess* _inputExternalMediaCallbackPtr;
517 VoEMediaProcess* _outputExternalMediaCallbackPtr;
518 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000519
kwiberg55b97fe2016-01-28 05:22:45 -0800520 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000521
kwiberg55b97fe2016-01-28 05:22:45 -0800522 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700523 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
kwiberg55b97fe2016-01-28 05:22:45 -0800524 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
525 uint32_t playout_timestamp_rtcp_;
526 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
527 uint32_t _numberOfDiscardedPackets;
528 uint16_t send_sequence_number_;
529 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000530
pbosd8de1152016-02-01 09:00:51 -0800531 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000532
kwibergb7f89d62016-02-17 10:04:18 -0800533 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800534 // The rtp timestamp of the first played out audio frame.
535 int64_t capture_start_rtp_time_stamp_;
536 // The capture ntp time (in local timebase) of the first played out audio
537 // frame.
538 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000539
kwiberg55b97fe2016-01-28 05:22:45 -0800540 // uses
541 Statistics* _engineStatisticsPtr;
542 OutputMixer* _outputMixerPtr;
543 TransmitMixer* _transmitMixerPtr;
544 ProcessThread* _moduleProcessThreadPtr;
545 AudioDeviceModule* _audioDeviceModulePtr;
546 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
547 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
548 Transport* _transportPtr; // WebRtc socket or external transport
549 RMSLevel rms_level_;
kwibergb7f89d62016-02-17 10:04:18 -0800550 std::unique_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800551 VoERxVadCallback* _rxVadObserverPtr;
552 int32_t _oldVadDecision;
553 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
554 // VoEBase
555 bool _externalMixing;
556 bool _mixFileWithMicrophone;
557 // VoEVolumeControl
solenberg1c2af8e2016-03-24 10:36:00 -0700558 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
559 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
560 float _panLeft GUARDED_BY(volume_settings_critsect_);
561 float _panRight GUARDED_BY(volume_settings_critsect_);
562 float _outputGain GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800563 // VoeRTP_RTCP
564 uint32_t _lastLocalTimeStamp;
565 int8_t _lastPayloadType;
566 bool _includeAudioLevelIndication;
567 // VoENetwork
568 AudioFrame::SpeechType _outputSpeechType;
569 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800570 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800571 uint32_t _average_jitter_buffer_delay_us GUARDED_BY(video_sync_lock_);
572 uint32_t _previousTimestamp;
573 uint16_t _recPacketDelayMs GUARDED_BY(video_sync_lock_);
574 // VoEAudioProcessing
575 bool _RxVadDetection;
576 bool _rxAgcIsEnabled;
577 bool _rxNsIsEnabled;
578 bool restored_packet_in_use_;
579 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800580 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
581 std::unique_ptr<NetworkPredictor> network_predictor_;
kwiberg55b97fe2016-01-28 05:22:45 -0800582 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800583 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800584 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100585
kwiberg55b97fe2016-01-28 05:22:45 -0800586 bool pacing_enabled_;
587 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800588 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
589 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
590 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
ossu29b1a8d2016-06-13 07:34:51 -0700591
592 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
593 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000594};
595
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000596} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000597} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000598
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000599#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_