blob: 03b19cc3a2656a720490f981a4c1f1cea2c5b030 [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;
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;
niklase@google.com470e71d2011-07-07 08:21:25 +000073class TransmitMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010074class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000075class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000076
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000077// Helper class to simplify locking scheme for members that are accessed from
78// multiple threads.
79// Example: a member can be set on thread T1 and read by an internal audio
80// thread T2. Accessing the member via this class ensures that we are
81// safe and also avoid TSan v2 warnings.
82class ChannelState {
83 public:
kwiberg55b97fe2016-01-28 05:22:45 -080084 struct State {
solenberg11ace152016-09-15 04:29:13 -070085 bool output_file_playing = false;
86 bool input_file_playing = false;
87 bool playing = false;
88 bool sending = false;
kwiberg55b97fe2016-01-28 05:22:45 -080089 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000090
kwiberg55b97fe2016-01-28 05:22:45 -080091 ChannelState() {}
92 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000093
kwiberg55b97fe2016-01-28 05:22:45 -080094 void Reset() {
95 rtc::CritScope lock(&lock_);
96 state_ = State();
97 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000098
kwiberg55b97fe2016-01-28 05:22:45 -080099 State Get() const {
100 rtc::CritScope lock(&lock_);
101 return state_;
102 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000103
kwiberg55b97fe2016-01-28 05:22:45 -0800104 void SetOutputFilePlaying(bool enable) {
105 rtc::CritScope lock(&lock_);
106 state_.output_file_playing = enable;
107 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000108
kwiberg55b97fe2016-01-28 05:22:45 -0800109 void SetInputFilePlaying(bool enable) {
110 rtc::CritScope lock(&lock_);
111 state_.input_file_playing = enable;
112 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000113
kwiberg55b97fe2016-01-28 05:22:45 -0800114 void SetPlaying(bool enable) {
115 rtc::CritScope lock(&lock_);
116 state_.playing = enable;
117 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000118
kwiberg55b97fe2016-01-28 05:22:45 -0800119 void SetSending(bool enable) {
120 rtc::CritScope lock(&lock_);
121 state_.sending = enable;
122 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000123
kwiberg55b97fe2016-01-28 05:22:45 -0800124 private:
pbosd8de1152016-02-01 09:00:51 -0800125 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800126 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000127};
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
kwiberg55b97fe2016-01-28 05:22:45 -0800129class Channel
130 : public RtpData,
131 public RtpFeedback,
132 public FileCallback, // receiving notification from file player &
133 // recorder
134 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800135 public AudioPacketizationCallback, // receive encoded packets from the
136 // ACM
137 public ACMVADCallback, // receive voice activity from the ACM
michaeltbf65be52016-12-15 06:24:49 -0800138 public MixerParticipant, // supplies output mixer with audio frames
139 public OverheadObserver {
kwiberg55b97fe2016-01-28 05:22:45 -0800140 public:
141 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000142
kwiberg55b97fe2016-01-28 05:22:45 -0800143 enum { KNumSocketThreads = 1 };
144 enum { KNumberOfSocketBuffers = 8 };
145 virtual ~Channel();
ossu5f7cfa52016-05-30 08:11:28 -0700146 static int32_t CreateChannel(
147 Channel*& channel,
148 int32_t channelId,
149 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700150 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800151 Channel(int32_t channelId,
152 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700153 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800154 int32_t Init();
155 int32_t SetEngineInformation(Statistics& engineStatistics,
156 OutputMixer& outputMixer,
157 TransmitMixer& transmitMixer,
158 ProcessThread& moduleProcessThread,
159 AudioDeviceModule& audioDeviceModule,
160 VoiceEngineObserver* voiceEngineObserver,
161 rtc::CriticalSection* callbackCritSect);
162 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000163
kwibergb7f89d62016-02-17 10:04:18 -0800164 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100165
ossu29b1a8d2016-06-13 07:34:51 -0700166 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
167 // passed into AudioReceiveStream is the same as the one set when creating the
168 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
169 // go.
170 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
171
kwiberg55b97fe2016-01-28 05:22:45 -0800172 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000173
kwiberg55b97fe2016-01-28 05:22:45 -0800174 // VoEBase
175 int32_t StartPlayout();
176 int32_t StopPlayout();
177 int32_t StartSend();
178 int32_t StopSend();
kwiberg55b97fe2016-01-28 05:22:45 -0800179 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
180 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
kwiberg55b97fe2016-01-28 05:22:45 -0800182 // VoECodec
183 int32_t GetSendCodec(CodecInst& codec);
184 int32_t GetRecCodec(CodecInst& codec);
185 int32_t SetSendCodec(const CodecInst& codec);
minyue78b4d562016-11-30 04:47:39 -0800186 void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
kwiberg55b97fe2016-01-28 05:22:45 -0800187 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
188 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
189 int32_t SetRecPayloadType(const CodecInst& codec);
kwibergd32bf752017-01-19 07:03:59 -0800190 int32_t SetRecPayloadType(int payload_type, const SdpAudioFormat& format);
kwiberg55b97fe2016-01-28 05:22:45 -0800191 int32_t GetRecPayloadType(CodecInst& codec);
192 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
193 int SetOpusMaxPlaybackRate(int frequency_hz);
194 int SetOpusDtx(bool enable_dtx);
ivoc85228d62016-07-27 04:53:47 -0700195 int GetOpusDtx(bool* enabled);
minyue7e304322016-10-12 05:00:55 -0700196 bool EnableAudioNetworkAdaptor(const std::string& config_string);
197 void DisableAudioNetworkAdaptor();
198 void SetReceiverFrameLengthRange(int min_frame_length_ms,
199 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000200
kwiberg55b97fe2016-01-28 05:22:45 -0800201 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700202 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800203 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700204 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800205 size_t length,
206 const PacketTime& packet_time);
mflodman3d7db262016-04-29 00:57:13 -0700207 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000208
kwiberg55b97fe2016-01-28 05:22:45 -0800209 // VoEFile
210 int StartPlayingFileLocally(const char* fileName,
211 bool loop,
212 FileFormats format,
213 int startPosition,
214 float volumeScaling,
215 int stopPosition,
216 const CodecInst* codecInst);
217 int StartPlayingFileLocally(InStream* stream,
218 FileFormats format,
219 int startPosition,
220 float volumeScaling,
221 int stopPosition,
222 const CodecInst* codecInst);
223 int StopPlayingFileLocally();
224 int IsPlayingFileLocally() const;
225 int RegisterFilePlayingToMixer();
226 int StartPlayingFileAsMicrophone(const char* fileName,
227 bool loop,
228 FileFormats format,
229 int startPosition,
230 float volumeScaling,
231 int stopPosition,
232 const CodecInst* codecInst);
233 int StartPlayingFileAsMicrophone(InStream* stream,
234 FileFormats format,
235 int startPosition,
236 float volumeScaling,
237 int stopPosition,
238 const CodecInst* codecInst);
239 int StopPlayingFileAsMicrophone();
240 int IsPlayingFileAsMicrophone() const;
241 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
242 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
243 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000244
kwiberg55b97fe2016-01-28 05:22:45 -0800245 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000246
kwiberg55b97fe2016-01-28 05:22:45 -0800247 // VoEVolumeControl
248 int GetSpeechOutputLevel(uint32_t& level) const;
249 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
solenberg1c2af8e2016-03-24 10:36:00 -0700250 int SetInputMute(bool enable);
251 bool InputMute() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800252 int SetOutputVolumePan(float left, float right);
253 int GetOutputVolumePan(float& left, float& right) const;
254 int SetChannelOutputVolumeScaling(float scaling);
255 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000256
kwiberg55b97fe2016-01-28 05:22:45 -0800257 // VoENetEqStats
258 int GetNetworkStatistics(NetworkStatistics& stats);
259 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000260
solenberg08b19df2017-02-15 00:42:31 -0800261 // Audio+Video Sync
kwiberg55b97fe2016-01-28 05:22:45 -0800262 uint32_t GetDelayEstimate() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800263 int SetMinimumPlayoutDelay(int delayMs);
264 int GetPlayoutTimestamp(unsigned int& timestamp);
kwiberg55b97fe2016-01-28 05:22:45 -0800265 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000266
solenberg31642aa2016-03-14 08:00:37 -0700267 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800268 int SendTelephoneEventOutband(int event, int duration_ms);
solenbergffbbcac2016-11-17 05:25:37 -0800269 int SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000270
kwiberg55b97fe2016-01-28 05:22:45 -0800271 // VoEAudioProcessingImpl
kwiberg55b97fe2016-01-28 05:22:45 -0800272 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000273
kwiberg55b97fe2016-01-28 05:22:45 -0800274 // VoERTP_RTCP
275 int SetLocalSSRC(unsigned int ssrc);
276 int GetLocalSSRC(unsigned int& ssrc);
277 int GetRemoteSSRC(unsigned int& ssrc);
278 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
279 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
kwiberg55b97fe2016-01-28 05:22:45 -0800280 void EnableSendTransportSequenceNumber(int id);
281 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100282
stefan7de8d642017-02-07 07:14:08 -0800283 void RegisterSenderCongestionControlObjects(
284 RtpPacketSender* rtp_packet_sender,
285 TransportFeedbackObserver* transport_feedback_observer,
286 PacketRouter* packet_router,
287 RtcpBandwidthObserver* bandwidth_observer);
288 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
289 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100290
kwiberg55b97fe2016-01-28 05:22:45 -0800291 void SetRTCPStatus(bool enable);
292 int GetRTCPStatus(bool& enabled);
293 int SetRTCP_CNAME(const char cName[256]);
294 int GetRemoteRTCP_CNAME(char cName[256]);
kwiberg55b97fe2016-01-28 05:22:45 -0800295 int SendApplicationDefinedRTCPPacket(unsigned char subType,
296 unsigned int name,
297 const char* data,
298 unsigned short dataLengthInBytes);
kwiberg55b97fe2016-01-28 05:22:45 -0800299 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
300 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800301 int SetCodecFECStatus(bool enable);
302 bool GetCodecFECStatus();
303 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000304
kwiberg55b97fe2016-01-28 05:22:45 -0800305 // From AudioPacketizationCallback in the ACM
306 int32_t SendData(FrameType frameType,
307 uint8_t payloadType,
308 uint32_t timeStamp,
309 const uint8_t* payloadData,
310 size_t payloadSize,
311 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000312
kwiberg55b97fe2016-01-28 05:22:45 -0800313 // From ACMVADCallback in the ACM
314 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000315
kwiberg55b97fe2016-01-28 05:22:45 -0800316 // From RtpData in the RTP/RTCP module
317 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
318 size_t payloadSize,
319 const WebRtcRTPHeader* rtpHeader) override;
320 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000321
kwiberg55b97fe2016-01-28 05:22:45 -0800322 // From RtpFeedback in the RTP/RTCP module
323 int32_t OnInitializeDecoder(int8_t payloadType,
324 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
325 int frequency,
326 size_t channels,
327 uint32_t rate) override;
328 void OnIncomingSSRCChanged(uint32_t ssrc) override;
329 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000330
kwiberg55b97fe2016-01-28 05:22:45 -0800331 // From Transport (called by the RTP/RTCP module)
332 bool SendRtp(const uint8_t* data,
333 size_t len,
334 const PacketOptions& packet_options) override;
335 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000336
kwiberg55b97fe2016-01-28 05:22:45 -0800337 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700338 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
339 int32_t id,
340 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800341 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000342
aleloiaed581a2016-10-20 06:32:39 -0700343 // From AudioMixer::Source.
aleloi6c278492016-10-20 14:24:39 -0700344 AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
345 int sample_rate_hz,
346 AudioFrame* audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700347
kwiberg55b97fe2016-01-28 05:22:45 -0800348 // From FileCallback
349 void PlayNotification(int32_t id, uint32_t durationMs) override;
350 void RecordNotification(int32_t id, uint32_t durationMs) override;
351 void PlayFileEnded(int32_t id) override;
352 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000353
kwiberg55b97fe2016-01-28 05:22:45 -0800354 uint32_t InstanceId() const { return _instanceId; }
355 int32_t ChannelId() const { return _channelId; }
356 bool Playing() const { return channel_state_.Get().playing; }
357 bool Sending() const { return channel_state_.Get().sending; }
kwiberg55b97fe2016-01-28 05:22:45 -0800358 bool ExternalTransport() const {
359 rtc::CritScope cs(&_callbackCritSect);
360 return _externalTransport;
361 }
kwiberg55b97fe2016-01-28 05:22:45 -0800362 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
363 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
364 uint32_t Demultiplex(const AudioFrame& audioFrame);
365 // Demultiplex the data to the channel's |_audioFrame|. The difference
366 // between this method and the overloaded method above is that |audio_data|
367 // does not go through transmit_mixer and APM.
368 void Demultiplex(const int16_t* audio_data,
369 int sample_rate,
370 size_t number_of_frames,
371 size_t number_of_channels);
372 uint32_t PrepareEncodeAndSend(int mixingFrequency);
373 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000374
kwiberg55b97fe2016-01-28 05:22:45 -0800375 // Associate to a send channel.
376 // Used for obtaining RTT for a receive-only channel.
solenberg7602aab2016-11-14 11:30:07 -0800377 void set_associate_send_channel(const ChannelOwner& channel);
kwiberg55b97fe2016-01-28 05:22:45 -0800378 // Disassociate a send channel if it was associated.
379 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200380
ivoc14d5dbe2016-07-04 07:06:55 -0700381 // Set a RtcEventLog logging object.
382 void SetRtcEventLog(RtcEventLog* event_log);
383
michaelt9332b7d2016-11-30 07:51:13 -0800384 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
nisse284542b2017-01-10 08:58:32 -0800385 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800386
michaeltbf65be52016-12-15 06:24:49 -0800387 // From OverheadObserver in the RTP/RTCP module
388 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
389
kwiberg55b97fe2016-01-28 05:22:45 -0800390 protected:
391 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000392
kwiberg55b97fe2016-01-28 05:22:45 -0800393 private:
394 bool ReceivePacket(const uint8_t* packet,
395 size_t packet_length,
396 const RTPHeader& header,
397 bool in_order);
398 bool HandleRtxPacket(const uint8_t* packet,
399 size_t packet_length,
400 const RTPHeader& header);
401 bool IsPacketInOrder(const RTPHeader& header) const;
402 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
403 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800404 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
405 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
406 void UpdatePlayoutTimestamp(bool rtcp);
kwiberg55b97fe2016-01-28 05:22:45 -0800407 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000408
kwiberg55b97fe2016-01-28 05:22:45 -0800409 int SetSendRtpHeaderExtension(bool enable,
410 RTPExtensionType type,
411 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000412
nisse284542b2017-01-10 08:58:32 -0800413 void UpdateOverheadForEncoder();
414
ossue280cde2016-10-12 11:04:10 -0700415 int GetRtpTimestampRateHz() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800416 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000417
pbosd8de1152016-02-01 09:00:51 -0800418 rtc::CriticalSection _fileCritSect;
419 rtc::CriticalSection _callbackCritSect;
420 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800421 uint32_t _instanceId;
422 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000423
kwiberg55b97fe2016-01-28 05:22:45 -0800424 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000425
ivoc14d5dbe2016-07-04 07:06:55 -0700426 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
michaelt9332b7d2016-11-30 07:51:13 -0800427 std::unique_ptr<voe::RtcpRttStatsProxy> rtcp_rtt_stats_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200428
kwibergb7f89d62016-02-17 10:04:18 -0800429 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
430 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
431 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
kwibergb7f89d62016-02-17 10:04:18 -0800432 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700433 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800434 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
435 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700436 acm2::CodecManager codec_manager_;
437 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800438 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800439 AudioLevel _outputAudioLevel;
440 bool _externalTransport;
441 AudioFrame _audioFrame;
442 // Downsamples to the codec rate if necessary.
443 PushResampler<int16_t> input_resampler_;
kwiberg5a25d952016-08-17 07:31:12 -0700444 std::unique_ptr<FilePlayer> input_file_player_;
445 std::unique_ptr<FilePlayer> output_file_player_;
446 std::unique_ptr<FileRecorder> output_file_recorder_;
kwiberg55b97fe2016-01-28 05:22:45 -0800447 int _inputFilePlayerId;
448 int _outputFilePlayerId;
449 int _outputFileRecorderId;
450 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800451 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000452
kwiberg55b97fe2016-01-28 05:22:45 -0800453 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000454
kwiberg55b97fe2016-01-28 05:22:45 -0800455 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700456 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
kwiberg55b97fe2016-01-28 05:22:45 -0800457 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800458 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800459 uint16_t send_sequence_number_;
460 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000461
pbosd8de1152016-02-01 09:00:51 -0800462 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000463
kwibergb7f89d62016-02-17 10:04:18 -0800464 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800465 // The rtp timestamp of the first played out audio frame.
466 int64_t capture_start_rtp_time_stamp_;
467 // The capture ntp time (in local timebase) of the first played out audio
468 // frame.
469 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000470
kwiberg55b97fe2016-01-28 05:22:45 -0800471 // uses
472 Statistics* _engineStatisticsPtr;
473 OutputMixer* _outputMixerPtr;
474 TransmitMixer* _transmitMixerPtr;
475 ProcessThread* _moduleProcessThreadPtr;
476 AudioDeviceModule* _audioDeviceModulePtr;
477 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
478 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
479 Transport* _transportPtr; // WebRtc socket or external transport
henrik.lundin50499422016-11-29 04:26:24 -0800480 RmsLevel rms_level_;
kwiberg55b97fe2016-01-28 05:22:45 -0800481 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
482 // VoEBase
kwiberg55b97fe2016-01-28 05:22:45 -0800483 bool _mixFileWithMicrophone;
484 // VoEVolumeControl
solenberg1c2af8e2016-03-24 10:36:00 -0700485 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
486 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
487 float _panLeft GUARDED_BY(volume_settings_critsect_);
488 float _panRight GUARDED_BY(volume_settings_critsect_);
489 float _outputGain GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800490 // VoeRTP_RTCP
491 uint32_t _lastLocalTimeStamp;
492 int8_t _lastPayloadType;
493 bool _includeAudioLevelIndication;
nisse284542b2017-01-10 08:58:32 -0800494 size_t transport_overhead_per_packet_;
495 size_t rtp_overhead_per_packet_;
kwiberg55b97fe2016-01-28 05:22:45 -0800496 // VoENetwork
497 AudioFrame::SpeechType _outputSpeechType;
498 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800499 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800500 // VoEAudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800501 bool restored_packet_in_use_;
502 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800503 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800504 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800505 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800506 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100507
kwiberg55b97fe2016-01-28 05:22:45 -0800508 bool pacing_enabled_;
509 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800510 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
511 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
512 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200513 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700514
515 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
516 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000517};
518
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000519} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000520} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000521
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000522#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_