blob: 31c44efccd12cf4038a755e9f096042d26e6cacc [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"
kwiberg9d7eb132016-08-16 04:08:30 -070030#include "webrtc/modules/utility/include/file_player.h"
31#include "webrtc/modules/utility/include/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;
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 {
solenberg11ace152016-09-15 04:29:13 -070086 bool input_external_media = false;
87 bool output_file_playing = false;
88 bool input_file_playing = false;
89 bool playing = false;
90 bool sending = false;
kwiberg55b97fe2016-01-28 05:22:45 -080091 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000092
kwiberg55b97fe2016-01-28 05:22:45 -080093 ChannelState() {}
94 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000095
kwiberg55b97fe2016-01-28 05:22:45 -080096 void Reset() {
97 rtc::CritScope lock(&lock_);
98 state_ = State();
99 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000100
kwiberg55b97fe2016-01-28 05:22:45 -0800101 State Get() const {
102 rtc::CritScope lock(&lock_);
103 return state_;
104 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000105
kwiberg55b97fe2016-01-28 05:22:45 -0800106 void SetInputExternalMedia(bool enable) {
107 rtc::CritScope lock(&lock_);
108 state_.input_external_media = enable;
109 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000110
kwiberg55b97fe2016-01-28 05:22:45 -0800111 void SetOutputFilePlaying(bool enable) {
112 rtc::CritScope lock(&lock_);
113 state_.output_file_playing = enable;
114 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000115
kwiberg55b97fe2016-01-28 05:22:45 -0800116 void SetInputFilePlaying(bool enable) {
117 rtc::CritScope lock(&lock_);
118 state_.input_file_playing = enable;
119 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000120
kwiberg55b97fe2016-01-28 05:22:45 -0800121 void SetPlaying(bool enable) {
122 rtc::CritScope lock(&lock_);
123 state_.playing = enable;
124 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000125
kwiberg55b97fe2016-01-28 05:22:45 -0800126 void SetSending(bool enable) {
127 rtc::CritScope lock(&lock_);
128 state_.sending = enable;
129 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000130
kwiberg55b97fe2016-01-28 05:22:45 -0800131 private:
pbosd8de1152016-02-01 09:00:51 -0800132 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800133 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000134};
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
kwiberg55b97fe2016-01-28 05:22:45 -0800136class Channel
137 : public RtpData,
138 public RtpFeedback,
139 public FileCallback, // receiving notification from file player &
140 // recorder
141 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800142 public AudioPacketizationCallback, // receive encoded packets from the
143 // ACM
144 public ACMVADCallback, // receive voice activity from the ACM
145 public MixerParticipant // supplies output mixer with audio frames
niklase@google.com470e71d2011-07-07 08:21:25 +0000146{
kwiberg55b97fe2016-01-28 05:22:45 -0800147 public:
148 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000149
kwiberg55b97fe2016-01-28 05:22:45 -0800150 enum { KNumSocketThreads = 1 };
151 enum { KNumberOfSocketBuffers = 8 };
152 virtual ~Channel();
ossu5f7cfa52016-05-30 08:11:28 -0700153 static int32_t CreateChannel(
154 Channel*& channel,
155 int32_t channelId,
156 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700157 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800158 Channel(int32_t channelId,
159 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700160 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800161 int32_t Init();
162 int32_t SetEngineInformation(Statistics& engineStatistics,
163 OutputMixer& outputMixer,
164 TransmitMixer& transmitMixer,
165 ProcessThread& moduleProcessThread,
166 AudioDeviceModule& audioDeviceModule,
167 VoiceEngineObserver* voiceEngineObserver,
168 rtc::CriticalSection* callbackCritSect);
169 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000170
kwibergb7f89d62016-02-17 10:04:18 -0800171 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100172
ossu29b1a8d2016-06-13 07:34:51 -0700173 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
174 // passed into AudioReceiveStream is the same as the one set when creating the
175 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
176 // go.
177 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
178
kwiberg55b97fe2016-01-28 05:22:45 -0800179 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000180
kwiberg55b97fe2016-01-28 05:22:45 -0800181 // VoEBase
182 int32_t StartPlayout();
183 int32_t StopPlayout();
184 int32_t StartSend();
185 int32_t StopSend();
solenberge566ac72016-10-31 12:52:33 -0700186 void ResetDiscardedPacketCount();
kwiberg55b97fe2016-01-28 05:22:45 -0800187 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
188 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
kwiberg55b97fe2016-01-28 05:22:45 -0800190 // VoECodec
191 int32_t GetSendCodec(CodecInst& codec);
192 int32_t GetRecCodec(CodecInst& codec);
193 int32_t SetSendCodec(const CodecInst& codec);
194 void SetBitRate(int bitrate_bps);
195 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
196 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
197 int32_t SetRecPayloadType(const CodecInst& codec);
198 int32_t GetRecPayloadType(CodecInst& codec);
199 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
200 int SetOpusMaxPlaybackRate(int frequency_hz);
201 int SetOpusDtx(bool enable_dtx);
ivoc85228d62016-07-27 04:53:47 -0700202 int GetOpusDtx(bool* enabled);
minyue7e304322016-10-12 05:00:55 -0700203 bool EnableAudioNetworkAdaptor(const std::string& config_string);
204 void DisableAudioNetworkAdaptor();
205 void SetReceiverFrameLengthRange(int min_frame_length_ms,
206 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
kwiberg55b97fe2016-01-28 05:22:45 -0800208 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700209 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800210 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700211 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800212 size_t length,
213 const PacketTime& packet_time);
mflodman3d7db262016-04-29 00:57:13 -0700214 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000215
kwiberg55b97fe2016-01-28 05:22:45 -0800216 // VoEFile
217 int StartPlayingFileLocally(const char* fileName,
218 bool loop,
219 FileFormats format,
220 int startPosition,
221 float volumeScaling,
222 int stopPosition,
223 const CodecInst* codecInst);
224 int StartPlayingFileLocally(InStream* stream,
225 FileFormats format,
226 int startPosition,
227 float volumeScaling,
228 int stopPosition,
229 const CodecInst* codecInst);
230 int StopPlayingFileLocally();
231 int IsPlayingFileLocally() const;
232 int RegisterFilePlayingToMixer();
233 int StartPlayingFileAsMicrophone(const char* fileName,
234 bool loop,
235 FileFormats format,
236 int startPosition,
237 float volumeScaling,
238 int stopPosition,
239 const CodecInst* codecInst);
240 int StartPlayingFileAsMicrophone(InStream* stream,
241 FileFormats format,
242 int startPosition,
243 float volumeScaling,
244 int stopPosition,
245 const CodecInst* codecInst);
246 int StopPlayingFileAsMicrophone();
247 int IsPlayingFileAsMicrophone() const;
248 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
249 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
250 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000251
kwiberg55b97fe2016-01-28 05:22:45 -0800252 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
kwiberg55b97fe2016-01-28 05:22:45 -0800254 // VoEExternalMediaProcessing
255 int RegisterExternalMediaProcessing(ProcessingTypes type,
256 VoEMediaProcess& processObject);
257 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
258 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000259
kwiberg55b97fe2016-01-28 05:22:45 -0800260 // VoEVolumeControl
261 int GetSpeechOutputLevel(uint32_t& level) const;
262 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
solenberg1c2af8e2016-03-24 10:36:00 -0700263 int SetInputMute(bool enable);
264 bool InputMute() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800265 int SetOutputVolumePan(float left, float right);
266 int GetOutputVolumePan(float& left, float& right) const;
267 int SetChannelOutputVolumeScaling(float scaling);
268 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
kwiberg55b97fe2016-01-28 05:22:45 -0800270 // VoENetEqStats
271 int GetNetworkStatistics(NetworkStatistics& stats);
272 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000273
kwiberg55b97fe2016-01-28 05:22:45 -0800274 // VoEVideoSync
275 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
276 int* playout_buffer_delay_ms) const;
277 uint32_t GetDelayEstimate() const;
278 int LeastRequiredDelayMs() const;
279 int SetMinimumPlayoutDelay(int delayMs);
280 int GetPlayoutTimestamp(unsigned int& timestamp);
281 int SetInitTimestamp(unsigned int timestamp);
282 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000283
kwiberg55b97fe2016-01-28 05:22:45 -0800284 // VoEVideoSyncExtended
285 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000286
solenberg31642aa2016-03-14 08:00:37 -0700287 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800288 int SendTelephoneEventOutband(int event, int duration_ms);
solenbergffbbcac2016-11-17 05:25:37 -0800289 int SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000290
kwiberg55b97fe2016-01-28 05:22:45 -0800291 // VoEAudioProcessingImpl
kwiberg55b97fe2016-01-28 05:22:45 -0800292 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000293
kwiberg55b97fe2016-01-28 05:22:45 -0800294 // VoERTP_RTCP
295 int SetLocalSSRC(unsigned int ssrc);
296 int GetLocalSSRC(unsigned int& ssrc);
297 int GetRemoteSSRC(unsigned int& ssrc);
298 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
299 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
300 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
301 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
302 void EnableSendTransportSequenceNumber(int id);
303 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100304
stefanbba9dec2016-02-01 04:39:55 -0800305 void RegisterSenderCongestionControlObjects(
306 RtpPacketSender* rtp_packet_sender,
307 TransportFeedbackObserver* transport_feedback_observer,
308 PacketRouter* packet_router);
309 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
310 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100311
kwiberg55b97fe2016-01-28 05:22:45 -0800312 void SetRTCPStatus(bool enable);
313 int GetRTCPStatus(bool& enabled);
314 int SetRTCP_CNAME(const char cName[256]);
315 int GetRemoteRTCP_CNAME(char cName[256]);
316 int GetRemoteRTCPData(unsigned int& NTPHigh,
317 unsigned int& NTPLow,
318 unsigned int& timestamp,
319 unsigned int& playoutTimestamp,
320 unsigned int* jitter,
321 unsigned short* fractionLost);
322 int SendApplicationDefinedRTCPPacket(unsigned char subType,
323 unsigned int name,
324 const char* data,
325 unsigned short dataLengthInBytes);
326 int GetRTPStatistics(unsigned int& averageJitterMs,
327 unsigned int& maxJitterMs,
328 unsigned int& discardedPackets);
329 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
330 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800331 int SetCodecFECStatus(bool enable);
332 bool GetCodecFECStatus();
333 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000334
kwiberg55b97fe2016-01-28 05:22:45 -0800335 // From AudioPacketizationCallback in the ACM
336 int32_t SendData(FrameType frameType,
337 uint8_t payloadType,
338 uint32_t timeStamp,
339 const uint8_t* payloadData,
340 size_t payloadSize,
341 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000342
kwiberg55b97fe2016-01-28 05:22:45 -0800343 // From ACMVADCallback in the ACM
344 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000345
kwiberg55b97fe2016-01-28 05:22:45 -0800346 // From RtpData in the RTP/RTCP module
347 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
348 size_t payloadSize,
349 const WebRtcRTPHeader* rtpHeader) override;
350 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000351
kwiberg55b97fe2016-01-28 05:22:45 -0800352 // From RtpFeedback in the RTP/RTCP module
353 int32_t OnInitializeDecoder(int8_t payloadType,
354 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
355 int frequency,
356 size_t channels,
357 uint32_t rate) override;
358 void OnIncomingSSRCChanged(uint32_t ssrc) override;
359 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000360
kwiberg55b97fe2016-01-28 05:22:45 -0800361 // From Transport (called by the RTP/RTCP module)
362 bool SendRtp(const uint8_t* data,
363 size_t len,
364 const PacketOptions& packet_options) override;
365 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000366
kwiberg55b97fe2016-01-28 05:22:45 -0800367 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700368 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
369 int32_t id,
370 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800371 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000372
aleloiaed581a2016-10-20 06:32:39 -0700373 // From AudioMixer::Source.
aleloi6c278492016-10-20 14:24:39 -0700374 AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
375 int sample_rate_hz,
376 AudioFrame* audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700377
kwiberg55b97fe2016-01-28 05:22:45 -0800378 // From FileCallback
379 void PlayNotification(int32_t id, uint32_t durationMs) override;
380 void RecordNotification(int32_t id, uint32_t durationMs) override;
381 void PlayFileEnded(int32_t id) override;
382 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000383
kwiberg55b97fe2016-01-28 05:22:45 -0800384 uint32_t InstanceId() const { return _instanceId; }
385 int32_t ChannelId() const { return _channelId; }
386 bool Playing() const { return channel_state_.Get().playing; }
387 bool Sending() const { return channel_state_.Get().sending; }
kwiberg55b97fe2016-01-28 05:22:45 -0800388 bool ExternalTransport() const {
389 rtc::CritScope cs(&_callbackCritSect);
390 return _externalTransport;
391 }
392 bool ExternalMixing() const { return _externalMixing; }
393 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
394 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
395 uint32_t Demultiplex(const AudioFrame& audioFrame);
396 // Demultiplex the data to the channel's |_audioFrame|. The difference
397 // between this method and the overloaded method above is that |audio_data|
398 // does not go through transmit_mixer and APM.
399 void Demultiplex(const int16_t* audio_data,
400 int sample_rate,
401 size_t number_of_frames,
402 size_t number_of_channels);
403 uint32_t PrepareEncodeAndSend(int mixingFrequency);
404 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000405
kwiberg55b97fe2016-01-28 05:22:45 -0800406 // Associate to a send channel.
407 // Used for obtaining RTT for a receive-only channel.
solenberg7602aab2016-11-14 11:30:07 -0800408 void set_associate_send_channel(const ChannelOwner& channel);
kwiberg55b97fe2016-01-28 05:22:45 -0800409 // Disassociate a send channel if it was associated.
410 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200411
ivoc14d5dbe2016-07-04 07:06:55 -0700412 // Set a RtcEventLog logging object.
413 void SetRtcEventLog(RtcEventLog* event_log);
414
michaelt79e05882016-11-08 02:50:09 -0800415 void SetTransportOverhead(int transport_overhead_per_packet);
416
kwiberg55b97fe2016-01-28 05:22:45 -0800417 protected:
418 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000419
kwiberg55b97fe2016-01-28 05:22:45 -0800420 private:
421 bool ReceivePacket(const uint8_t* packet,
422 size_t packet_length,
423 const RTPHeader& header,
424 bool in_order);
425 bool HandleRtxPacket(const uint8_t* packet,
426 size_t packet_length,
427 const RTPHeader& header);
428 bool IsPacketInOrder(const RTPHeader& header) const;
429 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
430 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800431 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
432 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
433 void UpdatePlayoutTimestamp(bool rtcp);
kwiberg55b97fe2016-01-28 05:22:45 -0800434 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000435
kwiberg55b97fe2016-01-28 05:22:45 -0800436 int SetSendRtpHeaderExtension(bool enable,
437 RTPExtensionType type,
438 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000439
ossue280cde2016-10-12 11:04:10 -0700440 int GetRtpTimestampRateHz() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800441 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000442
pbosd8de1152016-02-01 09:00:51 -0800443 rtc::CriticalSection _fileCritSect;
444 rtc::CriticalSection _callbackCritSect;
445 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800446 uint32_t _instanceId;
447 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000448
kwiberg55b97fe2016-01-28 05:22:45 -0800449 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000450
ivoc14d5dbe2016-07-04 07:06:55 -0700451 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200452
kwibergb7f89d62016-02-17 10:04:18 -0800453 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
454 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
455 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
456 std::unique_ptr<StatisticsProxy> statistics_proxy_;
457 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700458 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800459 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
460 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700461 acm2::CodecManager codec_manager_;
462 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800463 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800464 AudioLevel _outputAudioLevel;
465 bool _externalTransport;
466 AudioFrame _audioFrame;
467 // Downsamples to the codec rate if necessary.
468 PushResampler<int16_t> input_resampler_;
kwiberg5a25d952016-08-17 07:31:12 -0700469 std::unique_ptr<FilePlayer> input_file_player_;
470 std::unique_ptr<FilePlayer> output_file_player_;
471 std::unique_ptr<FileRecorder> output_file_recorder_;
kwiberg55b97fe2016-01-28 05:22:45 -0800472 int _inputFilePlayerId;
473 int _outputFilePlayerId;
474 int _outputFileRecorderId;
475 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800476 bool _outputExternalMedia;
477 VoEMediaProcess* _inputExternalMediaCallbackPtr;
478 VoEMediaProcess* _outputExternalMediaCallbackPtr;
479 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000480
kwiberg55b97fe2016-01-28 05:22:45 -0800481 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000482
kwiberg55b97fe2016-01-28 05:22:45 -0800483 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700484 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
kwiberg55b97fe2016-01-28 05:22:45 -0800485 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
486 uint32_t playout_timestamp_rtcp_;
487 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
488 uint32_t _numberOfDiscardedPackets;
489 uint16_t send_sequence_number_;
490 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000491
pbosd8de1152016-02-01 09:00:51 -0800492 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000493
kwibergb7f89d62016-02-17 10:04:18 -0800494 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800495 // The rtp timestamp of the first played out audio frame.
496 int64_t capture_start_rtp_time_stamp_;
497 // The capture ntp time (in local timebase) of the first played out audio
498 // frame.
499 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000500
kwiberg55b97fe2016-01-28 05:22:45 -0800501 // uses
502 Statistics* _engineStatisticsPtr;
503 OutputMixer* _outputMixerPtr;
504 TransmitMixer* _transmitMixerPtr;
505 ProcessThread* _moduleProcessThreadPtr;
506 AudioDeviceModule* _audioDeviceModulePtr;
507 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
508 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
509 Transport* _transportPtr; // WebRtc socket or external transport
510 RMSLevel rms_level_;
kwiberg55b97fe2016-01-28 05:22:45 -0800511 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
512 // VoEBase
513 bool _externalMixing;
514 bool _mixFileWithMicrophone;
515 // VoEVolumeControl
solenberg1c2af8e2016-03-24 10:36:00 -0700516 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
517 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
518 float _panLeft GUARDED_BY(volume_settings_critsect_);
519 float _panRight GUARDED_BY(volume_settings_critsect_);
520 float _outputGain GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800521 // VoeRTP_RTCP
522 uint32_t _lastLocalTimeStamp;
523 int8_t _lastPayloadType;
524 bool _includeAudioLevelIndication;
525 // VoENetwork
526 AudioFrame::SpeechType _outputSpeechType;
527 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800528 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800529 // VoEAudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800530 bool restored_packet_in_use_;
531 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800532 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800533 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800534 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800535 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100536
kwiberg55b97fe2016-01-28 05:22:45 -0800537 bool pacing_enabled_;
538 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800539 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
540 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
541 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200542 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700543
544 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
545 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000546};
547
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000548} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000549} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000550
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000551#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_