blob: c512c0838458751b16a072745943715e2051e784 [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
aleloiaed581a2016-10-20 06:32:39 -070016#include "webrtc/api/audio/audio_mixer.h"
kjellandera69d9732016-08-31 07:33:05 -070017#include "webrtc/api/call/audio_sink.h"
Stefan Holmerb86d4e42015-12-07 10:26:18 +010018#include "webrtc/base/criticalsection.h"
henrik.lundin96bd5022016-04-06 04:13:56 -070019#include "webrtc/base/optional.h"
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000020#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000021#include "webrtc/common_types.h"
kwibergc8d071e2016-04-06 12:22:38 -070022#include "webrtc/modules/audio_coding/acm2/codec_manager.h"
23#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
kjellander3e6db232015-11-26 04:44:54 -080024#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010025#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000026#include "webrtc/modules/audio_processing/rms_level.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010027#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
28#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
29#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
kwiberg97744472017-01-10 01:12:51 -080030#include "webrtc/voice_engine/file_player.h"
31#include "webrtc/voice_engine/file_recorder.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000032#include "webrtc/voice_engine/include/voe_audio_processing.h"
solenberg88499ec2016-09-07 07:34:41 -070033#include "webrtc/voice_engine/include/voe_base.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000034#include "webrtc/voice_engine/include/voe_network.h"
35#include "webrtc/voice_engine/level_indicator.h"
36#include "webrtc/voice_engine/shared_data.h"
37#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000038
wu@webrtc.org94454b72014-06-05 20:34:08 +000039namespace rtc {
wu@webrtc.org94454b72014-06-05 20:34:08 +000040class TimestampWrapAroundHandler;
41}
42
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000043namespace webrtc {
44
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000045class AudioDeviceModule;
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;
michaelt9332b7d2016-11-30 07:51:13 -080070class RtcpRttStatsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010071class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000072class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000073class StatisticsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010074class TransportFeedbackProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000075class TransmitMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010076class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000077class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000078
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000079// Helper class to simplify locking scheme for members that are accessed from
80// multiple threads.
81// Example: a member can be set on thread T1 and read by an internal audio
82// thread T2. Accessing the member via this class ensures that we are
83// safe and also avoid TSan v2 warnings.
84class ChannelState {
85 public:
kwiberg55b97fe2016-01-28 05:22:45 -080086 struct State {
solenberg11ace152016-09-15 04:29:13 -070087 bool input_external_media = false;
88 bool output_file_playing = false;
89 bool input_file_playing = false;
90 bool playing = false;
91 bool sending = false;
kwiberg55b97fe2016-01-28 05:22:45 -080092 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000093
kwiberg55b97fe2016-01-28 05:22:45 -080094 ChannelState() {}
95 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000096
kwiberg55b97fe2016-01-28 05:22:45 -080097 void Reset() {
98 rtc::CritScope lock(&lock_);
99 state_ = State();
100 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000101
kwiberg55b97fe2016-01-28 05:22:45 -0800102 State Get() const {
103 rtc::CritScope lock(&lock_);
104 return state_;
105 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000106
kwiberg55b97fe2016-01-28 05:22:45 -0800107 void SetInputExternalMedia(bool enable) {
108 rtc::CritScope lock(&lock_);
109 state_.input_external_media = enable;
110 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000111
kwiberg55b97fe2016-01-28 05:22:45 -0800112 void SetOutputFilePlaying(bool enable) {
113 rtc::CritScope lock(&lock_);
114 state_.output_file_playing = enable;
115 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000116
kwiberg55b97fe2016-01-28 05:22:45 -0800117 void SetInputFilePlaying(bool enable) {
118 rtc::CritScope lock(&lock_);
119 state_.input_file_playing = enable;
120 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000121
kwiberg55b97fe2016-01-28 05:22:45 -0800122 void SetPlaying(bool enable) {
123 rtc::CritScope lock(&lock_);
124 state_.playing = enable;
125 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000126
kwiberg55b97fe2016-01-28 05:22:45 -0800127 void SetSending(bool enable) {
128 rtc::CritScope lock(&lock_);
129 state_.sending = enable;
130 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000131
kwiberg55b97fe2016-01-28 05:22:45 -0800132 private:
pbosd8de1152016-02-01 09:00:51 -0800133 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800134 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000135};
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
kwiberg55b97fe2016-01-28 05:22:45 -0800137class Channel
138 : public RtpData,
139 public RtpFeedback,
140 public FileCallback, // receiving notification from file player &
141 // recorder
142 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800143 public AudioPacketizationCallback, // receive encoded packets from the
144 // ACM
145 public ACMVADCallback, // receive voice activity from the ACM
michaeltbf65be52016-12-15 06:24:49 -0800146 public MixerParticipant, // supplies output mixer with audio frames
147 public OverheadObserver {
kwiberg55b97fe2016-01-28 05:22:45 -0800148 public:
149 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000150
kwiberg55b97fe2016-01-28 05:22:45 -0800151 enum { KNumSocketThreads = 1 };
152 enum { KNumberOfSocketBuffers = 8 };
153 virtual ~Channel();
ossu5f7cfa52016-05-30 08:11:28 -0700154 static int32_t CreateChannel(
155 Channel*& channel,
156 int32_t channelId,
157 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700158 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800159 Channel(int32_t channelId,
160 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700161 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800162 int32_t Init();
163 int32_t SetEngineInformation(Statistics& engineStatistics,
164 OutputMixer& outputMixer,
165 TransmitMixer& transmitMixer,
166 ProcessThread& moduleProcessThread,
167 AudioDeviceModule& audioDeviceModule,
168 VoiceEngineObserver* voiceEngineObserver,
169 rtc::CriticalSection* callbackCritSect);
170 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000171
kwibergb7f89d62016-02-17 10:04:18 -0800172 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100173
ossu29b1a8d2016-06-13 07:34:51 -0700174 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
175 // passed into AudioReceiveStream is the same as the one set when creating the
176 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
177 // go.
178 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
179
kwiberg55b97fe2016-01-28 05:22:45 -0800180 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
kwiberg55b97fe2016-01-28 05:22:45 -0800182 // VoEBase
183 int32_t StartPlayout();
184 int32_t StopPlayout();
185 int32_t StartSend();
186 int32_t StopSend();
solenberge566ac72016-10-31 12:52:33 -0700187 void ResetDiscardedPacketCount();
kwiberg55b97fe2016-01-28 05:22:45 -0800188 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
189 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000190
kwiberg55b97fe2016-01-28 05:22:45 -0800191 // VoECodec
192 int32_t GetSendCodec(CodecInst& codec);
193 int32_t GetRecCodec(CodecInst& codec);
194 int32_t SetSendCodec(const CodecInst& codec);
minyue78b4d562016-11-30 04:47:39 -0800195 void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
kwiberg55b97fe2016-01-28 05:22:45 -0800196 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
197 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
198 int32_t SetRecPayloadType(const CodecInst& codec);
kwibergd32bf752017-01-19 07:03:59 -0800199 int32_t SetRecPayloadType(int payload_type, const SdpAudioFormat& format);
kwiberg55b97fe2016-01-28 05:22:45 -0800200 int32_t GetRecPayloadType(CodecInst& codec);
201 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
202 int SetOpusMaxPlaybackRate(int frequency_hz);
203 int SetOpusDtx(bool enable_dtx);
ivoc85228d62016-07-27 04:53:47 -0700204 int GetOpusDtx(bool* enabled);
minyue7e304322016-10-12 05:00:55 -0700205 bool EnableAudioNetworkAdaptor(const std::string& config_string);
206 void DisableAudioNetworkAdaptor();
207 void SetReceiverFrameLengthRange(int min_frame_length_ms,
208 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000209
kwiberg55b97fe2016-01-28 05:22:45 -0800210 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700211 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800212 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700213 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800214 size_t length,
215 const PacketTime& packet_time);
mflodman3d7db262016-04-29 00:57:13 -0700216 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000217
kwiberg55b97fe2016-01-28 05:22:45 -0800218 // VoEFile
219 int StartPlayingFileLocally(const char* fileName,
220 bool loop,
221 FileFormats format,
222 int startPosition,
223 float volumeScaling,
224 int stopPosition,
225 const CodecInst* codecInst);
226 int StartPlayingFileLocally(InStream* stream,
227 FileFormats format,
228 int startPosition,
229 float volumeScaling,
230 int stopPosition,
231 const CodecInst* codecInst);
232 int StopPlayingFileLocally();
233 int IsPlayingFileLocally() const;
234 int RegisterFilePlayingToMixer();
235 int StartPlayingFileAsMicrophone(const char* fileName,
236 bool loop,
237 FileFormats format,
238 int startPosition,
239 float volumeScaling,
240 int stopPosition,
241 const CodecInst* codecInst);
242 int StartPlayingFileAsMicrophone(InStream* stream,
243 FileFormats format,
244 int startPosition,
245 float volumeScaling,
246 int stopPosition,
247 const CodecInst* codecInst);
248 int StopPlayingFileAsMicrophone();
249 int IsPlayingFileAsMicrophone() const;
250 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
251 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
252 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
kwiberg55b97fe2016-01-28 05:22:45 -0800254 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000255
kwiberg55b97fe2016-01-28 05:22:45 -0800256 // VoEExternalMediaProcessing
257 int RegisterExternalMediaProcessing(ProcessingTypes type,
258 VoEMediaProcess& processObject);
259 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
260 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000261
kwiberg55b97fe2016-01-28 05:22:45 -0800262 // VoEVolumeControl
263 int GetSpeechOutputLevel(uint32_t& level) const;
264 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
solenberg1c2af8e2016-03-24 10:36:00 -0700265 int SetInputMute(bool enable);
266 bool InputMute() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800267 int SetOutputVolumePan(float left, float right);
268 int GetOutputVolumePan(float& left, float& right) const;
269 int SetChannelOutputVolumeScaling(float scaling);
270 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000271
kwiberg55b97fe2016-01-28 05:22:45 -0800272 // VoENetEqStats
273 int GetNetworkStatistics(NetworkStatistics& stats);
274 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000275
kwiberg55b97fe2016-01-28 05:22:45 -0800276 // VoEVideoSync
277 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
278 int* playout_buffer_delay_ms) const;
279 uint32_t GetDelayEstimate() const;
280 int LeastRequiredDelayMs() const;
281 int SetMinimumPlayoutDelay(int delayMs);
282 int GetPlayoutTimestamp(unsigned int& timestamp);
283 int SetInitTimestamp(unsigned int timestamp);
284 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000285
kwiberg55b97fe2016-01-28 05:22:45 -0800286 // VoEVideoSyncExtended
287 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000288
solenberg31642aa2016-03-14 08:00:37 -0700289 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800290 int SendTelephoneEventOutband(int event, int duration_ms);
solenbergffbbcac2016-11-17 05:25:37 -0800291 int SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000292
kwiberg55b97fe2016-01-28 05:22:45 -0800293 // VoEAudioProcessingImpl
kwiberg55b97fe2016-01-28 05:22:45 -0800294 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000295
kwiberg55b97fe2016-01-28 05:22:45 -0800296 // VoERTP_RTCP
297 int SetLocalSSRC(unsigned int ssrc);
298 int GetLocalSSRC(unsigned int& ssrc);
299 int GetRemoteSSRC(unsigned int& ssrc);
300 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
301 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
302 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
303 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
304 void EnableSendTransportSequenceNumber(int id);
305 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100306
stefan7de8d642017-02-07 07:14:08 -0800307 void RegisterSenderCongestionControlObjects(
308 RtpPacketSender* rtp_packet_sender,
309 TransportFeedbackObserver* transport_feedback_observer,
310 PacketRouter* packet_router,
311 RtcpBandwidthObserver* bandwidth_observer);
312 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
313 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100314
kwiberg55b97fe2016-01-28 05:22:45 -0800315 void SetRTCPStatus(bool enable);
316 int GetRTCPStatus(bool& enabled);
317 int SetRTCP_CNAME(const char cName[256]);
318 int GetRemoteRTCP_CNAME(char cName[256]);
319 int GetRemoteRTCPData(unsigned int& NTPHigh,
320 unsigned int& NTPLow,
321 unsigned int& timestamp,
322 unsigned int& playoutTimestamp,
323 unsigned int* jitter,
324 unsigned short* fractionLost);
325 int SendApplicationDefinedRTCPPacket(unsigned char subType,
326 unsigned int name,
327 const char* data,
328 unsigned short dataLengthInBytes);
329 int GetRTPStatistics(unsigned int& averageJitterMs,
330 unsigned int& maxJitterMs,
331 unsigned int& discardedPackets);
332 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
333 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800334 int SetCodecFECStatus(bool enable);
335 bool GetCodecFECStatus();
336 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000337
kwiberg55b97fe2016-01-28 05:22:45 -0800338 // From AudioPacketizationCallback in the ACM
339 int32_t SendData(FrameType frameType,
340 uint8_t payloadType,
341 uint32_t timeStamp,
342 const uint8_t* payloadData,
343 size_t payloadSize,
344 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000345
kwiberg55b97fe2016-01-28 05:22:45 -0800346 // From ACMVADCallback in the ACM
347 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000348
kwiberg55b97fe2016-01-28 05:22:45 -0800349 // From RtpData in the RTP/RTCP module
350 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
351 size_t payloadSize,
352 const WebRtcRTPHeader* rtpHeader) override;
353 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000354
kwiberg55b97fe2016-01-28 05:22:45 -0800355 // From RtpFeedback in the RTP/RTCP module
356 int32_t OnInitializeDecoder(int8_t payloadType,
357 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
358 int frequency,
359 size_t channels,
360 uint32_t rate) override;
361 void OnIncomingSSRCChanged(uint32_t ssrc) override;
362 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000363
kwiberg55b97fe2016-01-28 05:22:45 -0800364 // From Transport (called by the RTP/RTCP module)
365 bool SendRtp(const uint8_t* data,
366 size_t len,
367 const PacketOptions& packet_options) override;
368 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000369
kwiberg55b97fe2016-01-28 05:22:45 -0800370 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700371 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
372 int32_t id,
373 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800374 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000375
aleloiaed581a2016-10-20 06:32:39 -0700376 // From AudioMixer::Source.
aleloi6c278492016-10-20 14:24:39 -0700377 AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
378 int sample_rate_hz,
379 AudioFrame* audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700380
kwiberg55b97fe2016-01-28 05:22:45 -0800381 // From FileCallback
382 void PlayNotification(int32_t id, uint32_t durationMs) override;
383 void RecordNotification(int32_t id, uint32_t durationMs) override;
384 void PlayFileEnded(int32_t id) override;
385 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000386
kwiberg55b97fe2016-01-28 05:22:45 -0800387 uint32_t InstanceId() const { return _instanceId; }
388 int32_t ChannelId() const { return _channelId; }
389 bool Playing() const { return channel_state_.Get().playing; }
390 bool Sending() const { return channel_state_.Get().sending; }
kwiberg55b97fe2016-01-28 05:22:45 -0800391 bool ExternalTransport() const {
392 rtc::CritScope cs(&_callbackCritSect);
393 return _externalTransport;
394 }
395 bool ExternalMixing() const { return _externalMixing; }
396 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
397 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
398 uint32_t Demultiplex(const AudioFrame& audioFrame);
399 // Demultiplex the data to the channel's |_audioFrame|. The difference
400 // between this method and the overloaded method above is that |audio_data|
401 // does not go through transmit_mixer and APM.
402 void Demultiplex(const int16_t* audio_data,
403 int sample_rate,
404 size_t number_of_frames,
405 size_t number_of_channels);
406 uint32_t PrepareEncodeAndSend(int mixingFrequency);
407 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000408
kwiberg55b97fe2016-01-28 05:22:45 -0800409 // Associate to a send channel.
410 // Used for obtaining RTT for a receive-only channel.
solenberg7602aab2016-11-14 11:30:07 -0800411 void set_associate_send_channel(const ChannelOwner& channel);
kwiberg55b97fe2016-01-28 05:22:45 -0800412 // Disassociate a send channel if it was associated.
413 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200414
ivoc14d5dbe2016-07-04 07:06:55 -0700415 // Set a RtcEventLog logging object.
416 void SetRtcEventLog(RtcEventLog* event_log);
417
michaelt9332b7d2016-11-30 07:51:13 -0800418 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
nisse284542b2017-01-10 08:58:32 -0800419 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800420
michaeltbf65be52016-12-15 06:24:49 -0800421 // From OverheadObserver in the RTP/RTCP module
422 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
423
kwiberg55b97fe2016-01-28 05:22:45 -0800424 protected:
425 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000426
kwiberg55b97fe2016-01-28 05:22:45 -0800427 private:
428 bool ReceivePacket(const uint8_t* packet,
429 size_t packet_length,
430 const RTPHeader& header,
431 bool in_order);
432 bool HandleRtxPacket(const uint8_t* packet,
433 size_t packet_length,
434 const RTPHeader& header);
435 bool IsPacketInOrder(const RTPHeader& header) const;
436 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
437 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800438 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
439 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
440 void UpdatePlayoutTimestamp(bool rtcp);
kwiberg55b97fe2016-01-28 05:22:45 -0800441 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000442
kwiberg55b97fe2016-01-28 05:22:45 -0800443 int SetSendRtpHeaderExtension(bool enable,
444 RTPExtensionType type,
445 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000446
nisse284542b2017-01-10 08:58:32 -0800447 void UpdateOverheadForEncoder();
448
ossue280cde2016-10-12 11:04:10 -0700449 int GetRtpTimestampRateHz() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800450 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000451
pbosd8de1152016-02-01 09:00:51 -0800452 rtc::CriticalSection _fileCritSect;
453 rtc::CriticalSection _callbackCritSect;
454 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800455 uint32_t _instanceId;
456 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000457
kwiberg55b97fe2016-01-28 05:22:45 -0800458 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000459
ivoc14d5dbe2016-07-04 07:06:55 -0700460 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
michaelt9332b7d2016-11-30 07:51:13 -0800461 std::unique_ptr<voe::RtcpRttStatsProxy> rtcp_rtt_stats_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200462
kwibergb7f89d62016-02-17 10:04:18 -0800463 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
464 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
465 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
466 std::unique_ptr<StatisticsProxy> statistics_proxy_;
467 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700468 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800469 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
470 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700471 acm2::CodecManager codec_manager_;
472 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800473 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800474 AudioLevel _outputAudioLevel;
475 bool _externalTransport;
476 AudioFrame _audioFrame;
477 // Downsamples to the codec rate if necessary.
478 PushResampler<int16_t> input_resampler_;
kwiberg5a25d952016-08-17 07:31:12 -0700479 std::unique_ptr<FilePlayer> input_file_player_;
480 std::unique_ptr<FilePlayer> output_file_player_;
481 std::unique_ptr<FileRecorder> output_file_recorder_;
kwiberg55b97fe2016-01-28 05:22:45 -0800482 int _inputFilePlayerId;
483 int _outputFilePlayerId;
484 int _outputFileRecorderId;
485 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800486 bool _outputExternalMedia;
487 VoEMediaProcess* _inputExternalMediaCallbackPtr;
488 VoEMediaProcess* _outputExternalMediaCallbackPtr;
489 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000490
kwiberg55b97fe2016-01-28 05:22:45 -0800491 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000492
kwiberg55b97fe2016-01-28 05:22:45 -0800493 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700494 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
kwiberg55b97fe2016-01-28 05:22:45 -0800495 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
496 uint32_t playout_timestamp_rtcp_;
497 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
498 uint32_t _numberOfDiscardedPackets;
499 uint16_t send_sequence_number_;
500 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000501
pbosd8de1152016-02-01 09:00:51 -0800502 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000503
kwibergb7f89d62016-02-17 10:04:18 -0800504 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800505 // The rtp timestamp of the first played out audio frame.
506 int64_t capture_start_rtp_time_stamp_;
507 // The capture ntp time (in local timebase) of the first played out audio
508 // frame.
509 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000510
kwiberg55b97fe2016-01-28 05:22:45 -0800511 // uses
512 Statistics* _engineStatisticsPtr;
513 OutputMixer* _outputMixerPtr;
514 TransmitMixer* _transmitMixerPtr;
515 ProcessThread* _moduleProcessThreadPtr;
516 AudioDeviceModule* _audioDeviceModulePtr;
517 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
518 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
519 Transport* _transportPtr; // WebRtc socket or external transport
henrik.lundin50499422016-11-29 04:26:24 -0800520 RmsLevel rms_level_;
kwiberg55b97fe2016-01-28 05:22:45 -0800521 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
522 // VoEBase
523 bool _externalMixing;
524 bool _mixFileWithMicrophone;
525 // VoEVolumeControl
solenberg1c2af8e2016-03-24 10:36:00 -0700526 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
527 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
528 float _panLeft GUARDED_BY(volume_settings_critsect_);
529 float _panRight GUARDED_BY(volume_settings_critsect_);
530 float _outputGain GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800531 // VoeRTP_RTCP
532 uint32_t _lastLocalTimeStamp;
533 int8_t _lastPayloadType;
534 bool _includeAudioLevelIndication;
nisse284542b2017-01-10 08:58:32 -0800535 size_t transport_overhead_per_packet_;
536 size_t rtp_overhead_per_packet_;
kwiberg55b97fe2016-01-28 05:22:45 -0800537 // VoENetwork
538 AudioFrame::SpeechType _outputSpeechType;
539 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800540 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800541 // VoEAudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800542 bool restored_packet_in_use_;
543 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800544 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800545 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800546 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800547 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100548
kwiberg55b97fe2016-01-28 05:22:45 -0800549 bool pacing_enabled_;
550 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800551 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
552 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
553 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200554 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700555
556 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
557 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000558};
559
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000560} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000561} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000562
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000563#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_