blob: 9835b207579862225aa5d22d11bda07441984428 [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"
henrik.lundin92a7a182017-03-07 01:58:55 -080030#include "webrtc/voice_engine/audio_level.h"
kwiberg97744472017-01-10 01:12:51 -080031#include "webrtc/voice_engine/file_player.h"
32#include "webrtc/voice_engine/file_recorder.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"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000035#include "webrtc/voice_engine/shared_data.h"
36#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000037
wu@webrtc.org94454b72014-06-05 20:34:08 +000038namespace rtc {
wu@webrtc.org94454b72014-06-05 20:34:08 +000039class TimestampWrapAroundHandler;
40}
41
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000042namespace webrtc {
43
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000044class AudioDeviceModule;
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;
Erik Språng737336d2016-07-29 12:59:36 +020048class RateLimiter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000050class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070051class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000052class RTPPayloadRegistry;
53class RtpReceiver;
54class RTPReceiverAudio;
nisse657bab22017-02-21 06:28:10 -080055class RtpPacketReceived;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000056class RtpRtcp;
57class TelephoneEventHandler;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000058class VoERTPObserver;
59class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000060
61struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000062struct ReportBlock;
63struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000065namespace voe {
66
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000067class OutputMixer;
ivoc14d5dbe2016-07-04 07:06:55 -070068class RtcEventLogProxy;
michaelt9332b7d2016-11-30 07:51:13 -080069class RtcpRttStatsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010070class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000071class Statistics;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010072class TransportFeedbackProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010073class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000074class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000075
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000076// Helper class to simplify locking scheme for members that are accessed from
77// multiple threads.
78// Example: a member can be set on thread T1 and read by an internal audio
79// thread T2. Accessing the member via this class ensures that we are
80// safe and also avoid TSan v2 warnings.
81class ChannelState {
82 public:
kwiberg55b97fe2016-01-28 05:22:45 -080083 struct State {
solenberg11ace152016-09-15 04:29:13 -070084 bool output_file_playing = false;
85 bool input_file_playing = false;
86 bool playing = false;
87 bool sending = false;
kwiberg55b97fe2016-01-28 05:22:45 -080088 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000089
kwiberg55b97fe2016-01-28 05:22:45 -080090 ChannelState() {}
91 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000092
kwiberg55b97fe2016-01-28 05:22:45 -080093 void Reset() {
94 rtc::CritScope lock(&lock_);
95 state_ = State();
96 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000097
kwiberg55b97fe2016-01-28 05:22:45 -080098 State Get() const {
99 rtc::CritScope lock(&lock_);
100 return state_;
101 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000102
kwiberg55b97fe2016-01-28 05:22:45 -0800103 void SetOutputFilePlaying(bool enable) {
104 rtc::CritScope lock(&lock_);
105 state_.output_file_playing = enable;
106 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000107
kwiberg55b97fe2016-01-28 05:22:45 -0800108 void SetInputFilePlaying(bool enable) {
109 rtc::CritScope lock(&lock_);
110 state_.input_file_playing = enable;
111 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000112
kwiberg55b97fe2016-01-28 05:22:45 -0800113 void SetPlaying(bool enable) {
114 rtc::CritScope lock(&lock_);
115 state_.playing = enable;
116 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000117
kwiberg55b97fe2016-01-28 05:22:45 -0800118 void SetSending(bool enable) {
119 rtc::CritScope lock(&lock_);
120 state_.sending = enable;
121 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000122
kwiberg55b97fe2016-01-28 05:22:45 -0800123 private:
pbosd8de1152016-02-01 09:00:51 -0800124 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800125 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000126};
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
kwiberg55b97fe2016-01-28 05:22:45 -0800128class Channel
129 : public RtpData,
130 public RtpFeedback,
131 public FileCallback, // receiving notification from file player &
132 // recorder
133 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800134 public AudioPacketizationCallback, // receive encoded packets from the
135 // ACM
michaeltbf65be52016-12-15 06:24:49 -0800136 public MixerParticipant, // supplies output mixer with audio frames
137 public OverheadObserver {
kwiberg55b97fe2016-01-28 05:22:45 -0800138 public:
139 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000140
kwiberg55b97fe2016-01-28 05:22:45 -0800141 enum { KNumSocketThreads = 1 };
142 enum { KNumberOfSocketBuffers = 8 };
143 virtual ~Channel();
ossu5f7cfa52016-05-30 08:11:28 -0700144 static int32_t CreateChannel(
145 Channel*& channel,
146 int32_t channelId,
147 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700148 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800149 Channel(int32_t channelId,
150 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700151 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800152 int32_t Init();
153 int32_t SetEngineInformation(Statistics& engineStatistics,
154 OutputMixer& outputMixer,
kwiberg55b97fe2016-01-28 05:22:45 -0800155 ProcessThread& moduleProcessThread,
156 AudioDeviceModule& audioDeviceModule,
157 VoiceEngineObserver* voiceEngineObserver,
158 rtc::CriticalSection* callbackCritSect);
159 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000160
kwibergb7f89d62016-02-17 10:04:18 -0800161 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100162
ossu29b1a8d2016-06-13 07:34:51 -0700163 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
164 // passed into AudioReceiveStream is the same as the one set when creating the
165 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
166 // go.
167 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
168
kwiberg55b97fe2016-01-28 05:22:45 -0800169 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000170
kwiberg55b97fe2016-01-28 05:22:45 -0800171 // VoEBase
172 int32_t StartPlayout();
173 int32_t StopPlayout();
174 int32_t StartSend();
175 int32_t StopSend();
kwiberg55b97fe2016-01-28 05:22:45 -0800176 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
177 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000178
kwiberg55b97fe2016-01-28 05:22:45 -0800179 // VoECodec
180 int32_t GetSendCodec(CodecInst& codec);
181 int32_t GetRecCodec(CodecInst& codec);
182 int32_t SetSendCodec(const CodecInst& codec);
minyue78b4d562016-11-30 04:47:39 -0800183 void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
kwiberg55b97fe2016-01-28 05:22:45 -0800184 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
185 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
186 int32_t SetRecPayloadType(const CodecInst& codec);
kwibergd32bf752017-01-19 07:03:59 -0800187 int32_t SetRecPayloadType(int payload_type, const SdpAudioFormat& format);
kwiberg55b97fe2016-01-28 05:22:45 -0800188 int32_t GetRecPayloadType(CodecInst& codec);
189 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
190 int SetOpusMaxPlaybackRate(int frequency_hz);
191 int SetOpusDtx(bool enable_dtx);
ivoc85228d62016-07-27 04:53:47 -0700192 int GetOpusDtx(bool* enabled);
minyue7e304322016-10-12 05:00:55 -0700193 bool EnableAudioNetworkAdaptor(const std::string& config_string);
194 void DisableAudioNetworkAdaptor();
195 void SetReceiverFrameLengthRange(int min_frame_length_ms,
196 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000197
kwiberg55b97fe2016-01-28 05:22:45 -0800198 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700199 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800200 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700201 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800202 size_t length,
203 const PacketTime& packet_time);
nisse657bab22017-02-21 06:28:10 -0800204 // TODO(nisse, solenberg): Delete when VoENetwork is deleted.
mflodman3d7db262016-04-29 00:57:13 -0700205 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
nisse657bab22017-02-21 06:28:10 -0800206 void OnRtpPacket(const RtpPacketReceived& packet);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000207
kwiberg55b97fe2016-01-28 05:22:45 -0800208 // VoEFile
209 int StartPlayingFileLocally(const char* fileName,
210 bool loop,
211 FileFormats format,
212 int startPosition,
213 float volumeScaling,
214 int stopPosition,
215 const CodecInst* codecInst);
216 int StartPlayingFileLocally(InStream* stream,
217 FileFormats format,
218 int startPosition,
219 float volumeScaling,
220 int stopPosition,
221 const CodecInst* codecInst);
222 int StopPlayingFileLocally();
223 int IsPlayingFileLocally() const;
224 int RegisterFilePlayingToMixer();
225 int StartPlayingFileAsMicrophone(const char* fileName,
226 bool loop,
227 FileFormats format,
228 int startPosition,
229 float volumeScaling,
230 int stopPosition,
231 const CodecInst* codecInst);
232 int StartPlayingFileAsMicrophone(InStream* stream,
233 FileFormats format,
234 int startPosition,
235 float volumeScaling,
236 int stopPosition,
237 const CodecInst* codecInst);
238 int StopPlayingFileAsMicrophone();
239 int IsPlayingFileAsMicrophone() const;
240 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
241 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
242 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000243
kwiberg55b97fe2016-01-28 05:22:45 -0800244 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000245
solenberg8d73f8c2017-03-08 01:52:20 -0800246 // Muting, Volume and Level.
247 void SetInputMute(bool enable);
248 void SetChannelOutputVolumeScaling(float scaling);
249 int GetSpeechOutputLevel() const;
250 int GetSpeechOutputLevelFullRange() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000251
kwiberg55b97fe2016-01-28 05:22:45 -0800252 // VoENetEqStats
253 int GetNetworkStatistics(NetworkStatistics& stats);
254 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000255
solenberg08b19df2017-02-15 00:42:31 -0800256 // Audio+Video Sync
kwiberg55b97fe2016-01-28 05:22:45 -0800257 uint32_t GetDelayEstimate() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800258 int SetMinimumPlayoutDelay(int delayMs);
259 int GetPlayoutTimestamp(unsigned int& timestamp);
kwiberg55b97fe2016-01-28 05:22:45 -0800260 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000261
solenberg31642aa2016-03-14 08:00:37 -0700262 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800263 int SendTelephoneEventOutband(int event, int duration_ms);
solenbergffbbcac2016-11-17 05:25:37 -0800264 int SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000265
kwiberg55b97fe2016-01-28 05:22:45 -0800266 // VoERTP_RTCP
267 int SetLocalSSRC(unsigned int ssrc);
268 int GetLocalSSRC(unsigned int& ssrc);
269 int GetRemoteSSRC(unsigned int& ssrc);
270 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
271 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
kwiberg55b97fe2016-01-28 05:22:45 -0800272 void EnableSendTransportSequenceNumber(int id);
273 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100274
stefan7de8d642017-02-07 07:14:08 -0800275 void RegisterSenderCongestionControlObjects(
276 RtpPacketSender* rtp_packet_sender,
277 TransportFeedbackObserver* transport_feedback_observer,
278 PacketRouter* packet_router,
279 RtcpBandwidthObserver* bandwidth_observer);
280 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
281 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100282
kwiberg55b97fe2016-01-28 05:22:45 -0800283 void SetRTCPStatus(bool enable);
284 int GetRTCPStatus(bool& enabled);
285 int SetRTCP_CNAME(const char cName[256]);
286 int GetRemoteRTCP_CNAME(char cName[256]);
kwiberg55b97fe2016-01-28 05:22:45 -0800287 int SendApplicationDefinedRTCPPacket(unsigned char subType,
288 unsigned int name,
289 const char* data,
290 unsigned short dataLengthInBytes);
kwiberg55b97fe2016-01-28 05:22:45 -0800291 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
292 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800293 int SetCodecFECStatus(bool enable);
294 bool GetCodecFECStatus();
295 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000296
kwiberg55b97fe2016-01-28 05:22:45 -0800297 // From AudioPacketizationCallback in the ACM
298 int32_t SendData(FrameType frameType,
299 uint8_t payloadType,
300 uint32_t timeStamp,
301 const uint8_t* payloadData,
302 size_t payloadSize,
303 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000304
kwiberg55b97fe2016-01-28 05:22:45 -0800305 // From RtpData in the RTP/RTCP module
306 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
307 size_t payloadSize,
308 const WebRtcRTPHeader* rtpHeader) override;
309 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000310
kwiberg55b97fe2016-01-28 05:22:45 -0800311 // From RtpFeedback in the RTP/RTCP module
312 int32_t OnInitializeDecoder(int8_t payloadType,
313 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
314 int frequency,
315 size_t channels,
316 uint32_t rate) override;
317 void OnIncomingSSRCChanged(uint32_t ssrc) override;
318 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000319
kwiberg55b97fe2016-01-28 05:22:45 -0800320 // From Transport (called by the RTP/RTCP module)
321 bool SendRtp(const uint8_t* data,
322 size_t len,
323 const PacketOptions& packet_options) override;
324 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000325
kwiberg55b97fe2016-01-28 05:22:45 -0800326 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700327 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
328 int32_t id,
329 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800330 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000331
aleloiaed581a2016-10-20 06:32:39 -0700332 // From AudioMixer::Source.
aleloi6c278492016-10-20 14:24:39 -0700333 AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
334 int sample_rate_hz,
335 AudioFrame* audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700336
kwiberg55b97fe2016-01-28 05:22:45 -0800337 // From FileCallback
338 void PlayNotification(int32_t id, uint32_t durationMs) override;
339 void RecordNotification(int32_t id, uint32_t durationMs) override;
340 void PlayFileEnded(int32_t id) override;
341 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000342
kwiberg55b97fe2016-01-28 05:22:45 -0800343 uint32_t InstanceId() const { return _instanceId; }
344 int32_t ChannelId() const { return _channelId; }
345 bool Playing() const { return channel_state_.Get().playing; }
346 bool Sending() const { return channel_state_.Get().sending; }
kwiberg55b97fe2016-01-28 05:22:45 -0800347 bool ExternalTransport() const {
348 rtc::CritScope cs(&_callbackCritSect);
349 return _externalTransport;
350 }
kwiberg55b97fe2016-01-28 05:22:45 -0800351 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
352 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
353 uint32_t Demultiplex(const AudioFrame& audioFrame);
354 // Demultiplex the data to the channel's |_audioFrame|. The difference
355 // between this method and the overloaded method above is that |audio_data|
356 // does not go through transmit_mixer and APM.
357 void Demultiplex(const int16_t* audio_data,
358 int sample_rate,
359 size_t number_of_frames,
360 size_t number_of_channels);
361 uint32_t PrepareEncodeAndSend(int mixingFrequency);
362 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000363
kwiberg55b97fe2016-01-28 05:22:45 -0800364 // Associate to a send channel.
365 // Used for obtaining RTT for a receive-only channel.
solenberg7602aab2016-11-14 11:30:07 -0800366 void set_associate_send_channel(const ChannelOwner& channel);
kwiberg55b97fe2016-01-28 05:22:45 -0800367 // Disassociate a send channel if it was associated.
368 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200369
ivoc14d5dbe2016-07-04 07:06:55 -0700370 // Set a RtcEventLog logging object.
371 void SetRtcEventLog(RtcEventLog* event_log);
372
michaelt9332b7d2016-11-30 07:51:13 -0800373 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
nisse284542b2017-01-10 08:58:32 -0800374 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800375
michaeltbf65be52016-12-15 06:24:49 -0800376 // From OverheadObserver in the RTP/RTCP module
377 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
378
kwiberg55b97fe2016-01-28 05:22:45 -0800379 protected:
380 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000381
kwiberg55b97fe2016-01-28 05:22:45 -0800382 private:
solenberg8d73f8c2017-03-08 01:52:20 -0800383 bool InputMute() const;
nisse657bab22017-02-21 06:28:10 -0800384 bool OnRtpPacketWithHeader(const uint8_t* received_packet,
385 size_t length,
386 RTPHeader *header);
kwiberg55b97fe2016-01-28 05:22:45 -0800387 bool ReceivePacket(const uint8_t* packet,
388 size_t packet_length,
389 const RTPHeader& header,
390 bool in_order);
391 bool HandleRtxPacket(const uint8_t* packet,
392 size_t packet_length,
393 const RTPHeader& header);
394 bool IsPacketInOrder(const RTPHeader& header) const;
395 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
396 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800397 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
398 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
399 void UpdatePlayoutTimestamp(bool rtcp);
kwiberg55b97fe2016-01-28 05:22:45 -0800400 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000401
kwiberg55b97fe2016-01-28 05:22:45 -0800402 int SetSendRtpHeaderExtension(bool enable,
403 RTPExtensionType type,
404 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000405
hbos3fd31fe2017-02-28 05:43:16 -0800406 void UpdateOverheadForEncoder()
407 EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
nisse284542b2017-01-10 08:58:32 -0800408
ossue280cde2016-10-12 11:04:10 -0700409 int GetRtpTimestampRateHz() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800410 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000411
pbosd8de1152016-02-01 09:00:51 -0800412 rtc::CriticalSection _fileCritSect;
413 rtc::CriticalSection _callbackCritSect;
414 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800415 uint32_t _instanceId;
416 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000417
kwiberg55b97fe2016-01-28 05:22:45 -0800418 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000419
ivoc14d5dbe2016-07-04 07:06:55 -0700420 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
michaelt9332b7d2016-11-30 07:51:13 -0800421 std::unique_ptr<voe::RtcpRttStatsProxy> rtcp_rtt_stats_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200422
kwibergb7f89d62016-02-17 10:04:18 -0800423 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
424 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
425 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
kwibergb7f89d62016-02-17 10:04:18 -0800426 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700427 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800428 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
429 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700430 acm2::CodecManager codec_manager_;
431 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800432 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800433 AudioLevel _outputAudioLevel;
434 bool _externalTransport;
435 AudioFrame _audioFrame;
436 // Downsamples to the codec rate if necessary.
437 PushResampler<int16_t> input_resampler_;
kwiberg5a25d952016-08-17 07:31:12 -0700438 std::unique_ptr<FilePlayer> input_file_player_;
439 std::unique_ptr<FilePlayer> output_file_player_;
440 std::unique_ptr<FileRecorder> output_file_recorder_;
kwiberg55b97fe2016-01-28 05:22:45 -0800441 int _inputFilePlayerId;
442 int _outputFilePlayerId;
443 int _outputFileRecorderId;
444 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800445 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000446
kwiberg55b97fe2016-01-28 05:22:45 -0800447 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000448
kwiberg55b97fe2016-01-28 05:22:45 -0800449 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700450 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
solenbergfe7dd6d2017-03-11 08:10:43 -0800451
452 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800453 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800454 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800455 uint16_t send_sequence_number_;
456 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000457
pbosd8de1152016-02-01 09:00:51 -0800458 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000459
kwibergb7f89d62016-02-17 10:04:18 -0800460 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800461 // The rtp timestamp of the first played out audio frame.
462 int64_t capture_start_rtp_time_stamp_;
463 // The capture ntp time (in local timebase) of the first played out audio
464 // frame.
465 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000466
kwiberg55b97fe2016-01-28 05:22:45 -0800467 // uses
468 Statistics* _engineStatisticsPtr;
469 OutputMixer* _outputMixerPtr;
kwiberg55b97fe2016-01-28 05:22:45 -0800470 ProcessThread* _moduleProcessThreadPtr;
471 AudioDeviceModule* _audioDeviceModulePtr;
472 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
473 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
474 Transport* _transportPtr; // WebRtc socket or external transport
henrik.lundin50499422016-11-29 04:26:24 -0800475 RmsLevel rms_level_;
solenberg1c2af8e2016-03-24 10:36:00 -0700476 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
477 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
solenberg1c2af8e2016-03-24 10:36:00 -0700478 float _outputGain GUARDED_BY(volume_settings_critsect_);
solenberg8d73f8c2017-03-08 01:52:20 -0800479 // VoEBase
480 bool _mixFileWithMicrophone;
kwiberg55b97fe2016-01-28 05:22:45 -0800481 // VoeRTP_RTCP
482 uint32_t _lastLocalTimeStamp;
483 int8_t _lastPayloadType;
484 bool _includeAudioLevelIndication;
hbos3fd31fe2017-02-28 05:43:16 -0800485 size_t transport_overhead_per_packet_ GUARDED_BY(overhead_per_packet_lock_);
486 size_t rtp_overhead_per_packet_ GUARDED_BY(overhead_per_packet_lock_);
487 rtc::CriticalSection overhead_per_packet_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800488 // VoENetwork
489 AudioFrame::SpeechType _outputSpeechType;
solenbergfe7dd6d2017-03-11 08:10:43 -0800490 // DTX.
kwiberg55b97fe2016-01-28 05:22:45 -0800491 bool restored_packet_in_use_;
492 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800493 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800494 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800495 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800496 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100497
kwiberg55b97fe2016-01-28 05:22:45 -0800498 bool pacing_enabled_;
499 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800500 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
501 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
502 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200503 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700504
505 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
506 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000507};
508
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000509} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000510} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000511
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000512#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_