blob: f2d48d8aadd2ec42e05e6964b4be4813b202c4d0 [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
kjellandera69d9732016-08-31 07:33:05 -070016#include "webrtc/api/call/audio_sink.h"
Stefan Holmerb86d4e42015-12-07 10:26:18 +010017#include "webrtc/base/criticalsection.h"
henrik.lundin96bd5022016-04-06 04:13:56 -070018#include "webrtc/base/optional.h"
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000019#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000020#include "webrtc/common_types.h"
kwibergc8d071e2016-04-06 12:22:38 -070021#include "webrtc/modules/audio_coding/acm2/codec_manager.h"
22#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
kjellander3e6db232015-11-26 04:44:54 -080023#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010024#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000025#include "webrtc/modules/audio_processing/rms_level.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010026#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
27#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
28#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
kwiberg9d7eb132016-08-16 04:08:30 -070029#include "webrtc/modules/utility/include/file_player.h"
30#include "webrtc/modules/utility/include/file_recorder.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000031#include "webrtc/voice_engine/include/voe_audio_processing.h"
solenberg88499ec2016-09-07 07:34:41 -070032#include "webrtc/voice_engine/include/voe_base.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000033#include "webrtc/voice_engine/include/voe_network.h"
34#include "webrtc/voice_engine/level_indicator.h"
minyue@webrtc.org74aaf292014-07-16 21:28:26 +000035#include "webrtc/voice_engine/network_predictor.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000036#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;
michaelte0729c52016-10-11 00:29:27 -070070class 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;
92 bool receiving = false;
kwiberg55b97fe2016-01-28 05:22:45 -080093 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000094
kwiberg55b97fe2016-01-28 05:22:45 -080095 ChannelState() {}
96 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000097
kwiberg55b97fe2016-01-28 05:22:45 -080098 void Reset() {
99 rtc::CritScope lock(&lock_);
100 state_ = State();
101 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000102
kwiberg55b97fe2016-01-28 05:22:45 -0800103 State Get() const {
104 rtc::CritScope lock(&lock_);
105 return state_;
106 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000107
kwiberg55b97fe2016-01-28 05:22:45 -0800108 void SetInputExternalMedia(bool enable) {
109 rtc::CritScope lock(&lock_);
110 state_.input_external_media = enable;
111 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000112
kwiberg55b97fe2016-01-28 05:22:45 -0800113 void SetOutputFilePlaying(bool enable) {
114 rtc::CritScope lock(&lock_);
115 state_.output_file_playing = enable;
116 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000117
kwiberg55b97fe2016-01-28 05:22:45 -0800118 void SetInputFilePlaying(bool enable) {
119 rtc::CritScope lock(&lock_);
120 state_.input_file_playing = enable;
121 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000122
kwiberg55b97fe2016-01-28 05:22:45 -0800123 void SetPlaying(bool enable) {
124 rtc::CritScope lock(&lock_);
125 state_.playing = enable;
126 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000127
kwiberg55b97fe2016-01-28 05:22:45 -0800128 void SetSending(bool enable) {
129 rtc::CritScope lock(&lock_);
130 state_.sending = enable;
131 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000132
kwiberg55b97fe2016-01-28 05:22:45 -0800133 void SetReceiving(bool enable) {
134 rtc::CritScope lock(&lock_);
135 state_.receiving = enable;
136 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000137
kwiberg55b97fe2016-01-28 05:22:45 -0800138 private:
pbosd8de1152016-02-01 09:00:51 -0800139 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800140 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000141};
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
kwiberg55b97fe2016-01-28 05:22:45 -0800143class Channel
144 : public RtpData,
145 public RtpFeedback,
146 public FileCallback, // receiving notification from file player &
147 // recorder
148 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800149 public AudioPacketizationCallback, // receive encoded packets from the
150 // ACM
151 public ACMVADCallback, // receive voice activity from the ACM
152 public MixerParticipant // supplies output mixer with audio frames
niklase@google.com470e71d2011-07-07 08:21:25 +0000153{
kwiberg55b97fe2016-01-28 05:22:45 -0800154 public:
155 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000156
kwiberg55b97fe2016-01-28 05:22:45 -0800157 enum { KNumSocketThreads = 1 };
158 enum { KNumberOfSocketBuffers = 8 };
159 virtual ~Channel();
ossu5f7cfa52016-05-30 08:11:28 -0700160 static int32_t CreateChannel(
161 Channel*& channel,
162 int32_t channelId,
163 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700164 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800165 Channel(int32_t channelId,
166 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700167 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800168 int32_t Init();
169 int32_t SetEngineInformation(Statistics& engineStatistics,
170 OutputMixer& outputMixer,
171 TransmitMixer& transmitMixer,
172 ProcessThread& moduleProcessThread,
173 AudioDeviceModule& audioDeviceModule,
174 VoiceEngineObserver* voiceEngineObserver,
175 rtc::CriticalSection* callbackCritSect);
176 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000177
kwibergb7f89d62016-02-17 10:04:18 -0800178 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100179
ossu29b1a8d2016-06-13 07:34:51 -0700180 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
181 // passed into AudioReceiveStream is the same as the one set when creating the
182 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
183 // go.
184 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
185
kwiberg55b97fe2016-01-28 05:22:45 -0800186 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000187
kwiberg55b97fe2016-01-28 05:22:45 -0800188 // VoEBase
189 int32_t StartPlayout();
190 int32_t StopPlayout();
191 int32_t StartSend();
192 int32_t StopSend();
193 int32_t StartReceiving();
194 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000195
kwiberg55b97fe2016-01-28 05:22:45 -0800196 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
197 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000198
kwiberg55b97fe2016-01-28 05:22:45 -0800199 // VoECodec
200 int32_t GetSendCodec(CodecInst& codec);
201 int32_t GetRecCodec(CodecInst& codec);
202 int32_t SetSendCodec(const CodecInst& codec);
203 void SetBitRate(int bitrate_bps);
204 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
205 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
206 int32_t SetRecPayloadType(const CodecInst& codec);
207 int32_t GetRecPayloadType(CodecInst& codec);
208 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
209 int SetOpusMaxPlaybackRate(int frequency_hz);
210 int SetOpusDtx(bool enable_dtx);
ivoc85228d62016-07-27 04:53:47 -0700211 int GetOpusDtx(bool* enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
kwiberg55b97fe2016-01-28 05:22:45 -0800213 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700214 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800215 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700216 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800217 size_t length,
218 const PacketTime& packet_time);
mflodman3d7db262016-04-29 00:57:13 -0700219 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000220
kwiberg55b97fe2016-01-28 05:22:45 -0800221 // VoEFile
222 int StartPlayingFileLocally(const char* fileName,
223 bool loop,
224 FileFormats format,
225 int startPosition,
226 float volumeScaling,
227 int stopPosition,
228 const CodecInst* codecInst);
229 int StartPlayingFileLocally(InStream* stream,
230 FileFormats format,
231 int startPosition,
232 float volumeScaling,
233 int stopPosition,
234 const CodecInst* codecInst);
235 int StopPlayingFileLocally();
236 int IsPlayingFileLocally() const;
237 int RegisterFilePlayingToMixer();
238 int StartPlayingFileAsMicrophone(const char* fileName,
239 bool loop,
240 FileFormats format,
241 int startPosition,
242 float volumeScaling,
243 int stopPosition,
244 const CodecInst* codecInst);
245 int StartPlayingFileAsMicrophone(InStream* stream,
246 FileFormats format,
247 int startPosition,
248 float volumeScaling,
249 int stopPosition,
250 const CodecInst* codecInst);
251 int StopPlayingFileAsMicrophone();
252 int IsPlayingFileAsMicrophone() const;
253 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
254 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
255 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000256
kwiberg55b97fe2016-01-28 05:22:45 -0800257 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
kwiberg55b97fe2016-01-28 05:22:45 -0800259 // VoEExternalMediaProcessing
260 int RegisterExternalMediaProcessing(ProcessingTypes type,
261 VoEMediaProcess& processObject);
262 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
263 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000264
kwiberg55b97fe2016-01-28 05:22:45 -0800265 // VoEVolumeControl
266 int GetSpeechOutputLevel(uint32_t& level) const;
267 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
solenberg1c2af8e2016-03-24 10:36:00 -0700268 int SetInputMute(bool enable);
269 bool InputMute() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800270 int SetOutputVolumePan(float left, float right);
271 int GetOutputVolumePan(float& left, float& right) const;
272 int SetChannelOutputVolumeScaling(float scaling);
273 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000274
kwiberg55b97fe2016-01-28 05:22:45 -0800275 // VoENetEqStats
276 int GetNetworkStatistics(NetworkStatistics& stats);
277 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000278
kwiberg55b97fe2016-01-28 05:22:45 -0800279 // VoEVideoSync
280 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
281 int* playout_buffer_delay_ms) const;
282 uint32_t GetDelayEstimate() const;
283 int LeastRequiredDelayMs() const;
284 int SetMinimumPlayoutDelay(int delayMs);
285 int GetPlayoutTimestamp(unsigned int& timestamp);
286 int SetInitTimestamp(unsigned int timestamp);
287 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000288
kwiberg55b97fe2016-01-28 05:22:45 -0800289 // VoEVideoSyncExtended
290 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000291
solenberg31642aa2016-03-14 08:00:37 -0700292 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800293 int SendTelephoneEventOutband(int event, int duration_ms);
solenberg31642aa2016-03-14 08:00:37 -0700294 int SetSendTelephoneEventPayloadType(int payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000295
kwiberg55b97fe2016-01-28 05:22:45 -0800296 // VoEAudioProcessingImpl
kwiberg55b97fe2016-01-28 05:22:45 -0800297 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000298
kwiberg55b97fe2016-01-28 05:22:45 -0800299 // VoERTP_RTCP
300 int SetLocalSSRC(unsigned int ssrc);
301 int GetLocalSSRC(unsigned int& ssrc);
302 int GetRemoteSSRC(unsigned int& ssrc);
303 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
304 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
305 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
306 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
307 void EnableSendTransportSequenceNumber(int id);
308 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100309
stefanbba9dec2016-02-01 04:39:55 -0800310 void RegisterSenderCongestionControlObjects(
311 RtpPacketSender* rtp_packet_sender,
312 TransportFeedbackObserver* transport_feedback_observer,
313 PacketRouter* packet_router);
314 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
315 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100316
kwiberg55b97fe2016-01-28 05:22:45 -0800317 void SetRTCPStatus(bool enable);
318 int GetRTCPStatus(bool& enabled);
319 int SetRTCP_CNAME(const char cName[256]);
320 int GetRemoteRTCP_CNAME(char cName[256]);
321 int GetRemoteRTCPData(unsigned int& NTPHigh,
322 unsigned int& NTPLow,
323 unsigned int& timestamp,
324 unsigned int& playoutTimestamp,
325 unsigned int* jitter,
326 unsigned short* fractionLost);
327 int SendApplicationDefinedRTCPPacket(unsigned char subType,
328 unsigned int name,
329 const char* data,
330 unsigned short dataLengthInBytes);
331 int GetRTPStatistics(unsigned int& averageJitterMs,
332 unsigned int& maxJitterMs,
333 unsigned int& discardedPackets);
334 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
335 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800336 int SetCodecFECStatus(bool enable);
337 bool GetCodecFECStatus();
338 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000339
kwiberg55b97fe2016-01-28 05:22:45 -0800340 // From AudioPacketizationCallback in the ACM
341 int32_t SendData(FrameType frameType,
342 uint8_t payloadType,
343 uint32_t timeStamp,
344 const uint8_t* payloadData,
345 size_t payloadSize,
346 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000347
kwiberg55b97fe2016-01-28 05:22:45 -0800348 // From ACMVADCallback in the ACM
349 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000350
kwiberg55b97fe2016-01-28 05:22:45 -0800351 // From RtpData in the RTP/RTCP module
352 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
353 size_t payloadSize,
354 const WebRtcRTPHeader* rtpHeader) override;
355 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000356
kwiberg55b97fe2016-01-28 05:22:45 -0800357 // From RtpFeedback in the RTP/RTCP module
358 int32_t OnInitializeDecoder(int8_t payloadType,
359 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
360 int frequency,
361 size_t channels,
362 uint32_t rate) override;
363 void OnIncomingSSRCChanged(uint32_t ssrc) override;
364 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000365
kwiberg55b97fe2016-01-28 05:22:45 -0800366 // From Transport (called by the RTP/RTCP module)
367 bool SendRtp(const uint8_t* data,
368 size_t len,
369 const PacketOptions& packet_options) override;
370 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000371
kwiberg55b97fe2016-01-28 05:22:45 -0800372 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700373 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
374 int32_t id,
375 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800376 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000377
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; }
388 bool Receiving() const { return channel_state_.Get().receiving; }
389 bool ExternalTransport() const {
390 rtc::CritScope cs(&_callbackCritSect);
391 return _externalTransport;
392 }
393 bool ExternalMixing() const { return _externalMixing; }
394 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
395 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
396 uint32_t Demultiplex(const AudioFrame& audioFrame);
397 // Demultiplex the data to the channel's |_audioFrame|. The difference
398 // between this method and the overloaded method above is that |audio_data|
399 // does not go through transmit_mixer and APM.
400 void Demultiplex(const int16_t* audio_data,
401 int sample_rate,
402 size_t number_of_frames,
403 size_t number_of_channels);
404 uint32_t PrepareEncodeAndSend(int mixingFrequency);
405 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000406
kwiberg55b97fe2016-01-28 05:22:45 -0800407 // Associate to a send channel.
408 // Used for obtaining RTT for a receive-only channel.
409 void set_associate_send_channel(const ChannelOwner& channel) {
410 assert(_channelId != channel.channel()->ChannelId());
411 rtc::CritScope lock(&assoc_send_channel_lock_);
412 associate_send_channel_ = channel;
413 }
Minyue2013aec2015-05-13 14:14:42 +0200414
kwiberg55b97fe2016-01-28 05:22:45 -0800415 // Disassociate a send channel if it was associated.
416 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200417
ivoc14d5dbe2016-07-04 07:06:55 -0700418 // Set a RtcEventLog logging object.
419 void SetRtcEventLog(RtcEventLog* event_log);
420
michaelte0729c52016-10-11 00:29:27 -0700421 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
422
kwiberg55b97fe2016-01-28 05:22:45 -0800423 protected:
424 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000425
kwiberg55b97fe2016-01-28 05:22:45 -0800426 private:
427 bool ReceivePacket(const uint8_t* packet,
428 size_t packet_length,
429 const RTPHeader& header,
430 bool in_order);
431 bool HandleRtxPacket(const uint8_t* packet,
432 size_t packet_length,
433 const RTPHeader& header);
434 bool IsPacketInOrder(const RTPHeader& header) const;
435 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
436 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800437 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
438 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
439 void UpdatePlayoutTimestamp(bool rtcp);
kwiberg55b97fe2016-01-28 05:22:45 -0800440 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000441
kwiberg55b97fe2016-01-28 05:22:45 -0800442 int SetSendRtpHeaderExtension(bool enable,
443 RTPExtensionType type,
444 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000445
henrik.lundinb3e30012016-08-31 14:09:51 -0700446 int32_t GetPlayoutFrequency() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800447 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000448
pbosd8de1152016-02-01 09:00:51 -0800449 rtc::CriticalSection _fileCritSect;
450 rtc::CriticalSection _callbackCritSect;
451 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800452 uint32_t _instanceId;
453 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000454
kwiberg55b97fe2016-01-28 05:22:45 -0800455 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000456
ivoc14d5dbe2016-07-04 07:06:55 -0700457 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
michaelte0729c52016-10-11 00:29:27 -0700458 std::unique_ptr<voe::RtcpRttStatsProxy> rtcp_rtt_stats_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200459
kwibergb7f89d62016-02-17 10:04:18 -0800460 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
461 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
462 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
463 std::unique_ptr<StatisticsProxy> statistics_proxy_;
464 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700465 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800466 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
467 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700468 acm2::CodecManager codec_manager_;
469 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800470 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800471 AudioLevel _outputAudioLevel;
472 bool _externalTransport;
473 AudioFrame _audioFrame;
474 // Downsamples to the codec rate if necessary.
475 PushResampler<int16_t> input_resampler_;
kwiberg5a25d952016-08-17 07:31:12 -0700476 std::unique_ptr<FilePlayer> input_file_player_;
477 std::unique_ptr<FilePlayer> output_file_player_;
478 std::unique_ptr<FileRecorder> output_file_recorder_;
kwiberg55b97fe2016-01-28 05:22:45 -0800479 int _inputFilePlayerId;
480 int _outputFilePlayerId;
481 int _outputFileRecorderId;
482 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800483 bool _outputExternalMedia;
484 VoEMediaProcess* _inputExternalMediaCallbackPtr;
485 VoEMediaProcess* _outputExternalMediaCallbackPtr;
486 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000487
kwiberg55b97fe2016-01-28 05:22:45 -0800488 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000489
kwiberg55b97fe2016-01-28 05:22:45 -0800490 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700491 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
kwiberg55b97fe2016-01-28 05:22:45 -0800492 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
493 uint32_t playout_timestamp_rtcp_;
494 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
495 uint32_t _numberOfDiscardedPackets;
496 uint16_t send_sequence_number_;
497 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000498
pbosd8de1152016-02-01 09:00:51 -0800499 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000500
kwibergb7f89d62016-02-17 10:04:18 -0800501 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800502 // The rtp timestamp of the first played out audio frame.
503 int64_t capture_start_rtp_time_stamp_;
504 // The capture ntp time (in local timebase) of the first played out audio
505 // frame.
506 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000507
kwiberg55b97fe2016-01-28 05:22:45 -0800508 // uses
509 Statistics* _engineStatisticsPtr;
510 OutputMixer* _outputMixerPtr;
511 TransmitMixer* _transmitMixerPtr;
512 ProcessThread* _moduleProcessThreadPtr;
513 AudioDeviceModule* _audioDeviceModulePtr;
514 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
515 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
516 Transport* _transportPtr; // WebRtc socket or external transport
517 RMSLevel rms_level_;
kwiberg55b97fe2016-01-28 05:22:45 -0800518 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
519 // VoEBase
520 bool _externalMixing;
521 bool _mixFileWithMicrophone;
522 // VoEVolumeControl
solenberg1c2af8e2016-03-24 10:36:00 -0700523 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
524 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
525 float _panLeft GUARDED_BY(volume_settings_critsect_);
526 float _panRight GUARDED_BY(volume_settings_critsect_);
527 float _outputGain GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800528 // VoeRTP_RTCP
529 uint32_t _lastLocalTimeStamp;
530 int8_t _lastPayloadType;
531 bool _includeAudioLevelIndication;
532 // VoENetwork
533 AudioFrame::SpeechType _outputSpeechType;
534 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800535 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800536 // VoEAudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800537 bool restored_packet_in_use_;
538 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800539 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
540 std::unique_ptr<NetworkPredictor> network_predictor_;
kwiberg55b97fe2016-01-28 05:22:45 -0800541 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800542 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800543 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100544
kwiberg55b97fe2016-01-28 05:22:45 -0800545 bool pacing_enabled_;
546 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800547 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
548 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
549 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200550 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700551
552 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
553 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000554};
555
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000556} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000557} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000558
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000559#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_