blob: b0725867aa1cc54d975c4ed69c3a46cacb380d4e [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"
35#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;
55class RtpRtcp;
56class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000057class VoEMediaProcess;
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;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010069class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000070class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000071class StatisticsProxy;
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 input_external_media = false;
86 bool output_file_playing = false;
87 bool input_file_playing = false;
88 bool playing = false;
89 bool sending = false;
90 bool receiving = 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 void SetReceiving(bool enable) {
132 rtc::CritScope lock(&lock_);
133 state_.receiving = enable;
134 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000135
kwiberg55b97fe2016-01-28 05:22:45 -0800136 private:
pbosd8de1152016-02-01 09:00:51 -0800137 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800138 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000139};
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
kwiberg55b97fe2016-01-28 05:22:45 -0800141class Channel
142 : public RtpData,
143 public RtpFeedback,
144 public FileCallback, // receiving notification from file player &
145 // recorder
146 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800147 public AudioPacketizationCallback, // receive encoded packets from the
148 // ACM
149 public ACMVADCallback, // receive voice activity from the ACM
150 public MixerParticipant // supplies output mixer with audio frames
niklase@google.com470e71d2011-07-07 08:21:25 +0000151{
kwiberg55b97fe2016-01-28 05:22:45 -0800152 public:
153 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000154
kwiberg55b97fe2016-01-28 05:22:45 -0800155 enum { KNumSocketThreads = 1 };
156 enum { KNumberOfSocketBuffers = 8 };
157 virtual ~Channel();
ossu5f7cfa52016-05-30 08:11:28 -0700158 static int32_t CreateChannel(
159 Channel*& channel,
160 int32_t channelId,
161 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700162 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800163 Channel(int32_t channelId,
164 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700165 const VoEBase::ChannelConfig& config);
kwiberg55b97fe2016-01-28 05:22:45 -0800166 int32_t Init();
167 int32_t SetEngineInformation(Statistics& engineStatistics,
168 OutputMixer& outputMixer,
169 TransmitMixer& transmitMixer,
170 ProcessThread& moduleProcessThread,
171 AudioDeviceModule& audioDeviceModule,
172 VoiceEngineObserver* voiceEngineObserver,
173 rtc::CriticalSection* callbackCritSect);
174 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000175
kwibergb7f89d62016-02-17 10:04:18 -0800176 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100177
ossu29b1a8d2016-06-13 07:34:51 -0700178 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
179 // passed into AudioReceiveStream is the same as the one set when creating the
180 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
181 // go.
182 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
183
kwiberg55b97fe2016-01-28 05:22:45 -0800184 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000185
kwiberg55b97fe2016-01-28 05:22:45 -0800186 // VoEBase
187 int32_t StartPlayout();
188 int32_t StopPlayout();
189 int32_t StartSend();
190 int32_t StopSend();
191 int32_t StartReceiving();
192 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
kwiberg55b97fe2016-01-28 05:22:45 -0800194 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
195 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
kwiberg55b97fe2016-01-28 05:22:45 -0800197 // VoECodec
198 int32_t GetSendCodec(CodecInst& codec);
199 int32_t GetRecCodec(CodecInst& codec);
200 int32_t SetSendCodec(const CodecInst& codec);
201 void SetBitRate(int bitrate_bps);
202 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
203 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
204 int32_t SetRecPayloadType(const CodecInst& codec);
205 int32_t GetRecPayloadType(CodecInst& codec);
206 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
207 int SetOpusMaxPlaybackRate(int frequency_hz);
208 int SetOpusDtx(bool enable_dtx);
ivoc85228d62016-07-27 04:53:47 -0700209 int GetOpusDtx(bool* enabled);
minyue7e304322016-10-12 05:00:55 -0700210 bool EnableAudioNetworkAdaptor(const std::string& config_string);
211 void DisableAudioNetworkAdaptor();
212 void SetReceiverFrameLengthRange(int min_frame_length_ms,
213 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000214
kwiberg55b97fe2016-01-28 05:22:45 -0800215 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700216 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800217 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700218 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800219 size_t length,
220 const PacketTime& packet_time);
mflodman3d7db262016-04-29 00:57:13 -0700221 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000222
kwiberg55b97fe2016-01-28 05:22:45 -0800223 // VoEFile
224 int StartPlayingFileLocally(const char* fileName,
225 bool loop,
226 FileFormats format,
227 int startPosition,
228 float volumeScaling,
229 int stopPosition,
230 const CodecInst* codecInst);
231 int StartPlayingFileLocally(InStream* stream,
232 FileFormats format,
233 int startPosition,
234 float volumeScaling,
235 int stopPosition,
236 const CodecInst* codecInst);
237 int StopPlayingFileLocally();
238 int IsPlayingFileLocally() const;
239 int RegisterFilePlayingToMixer();
240 int StartPlayingFileAsMicrophone(const char* fileName,
241 bool loop,
242 FileFormats format,
243 int startPosition,
244 float volumeScaling,
245 int stopPosition,
246 const CodecInst* codecInst);
247 int StartPlayingFileAsMicrophone(InStream* stream,
248 FileFormats format,
249 int startPosition,
250 float volumeScaling,
251 int stopPosition,
252 const CodecInst* codecInst);
253 int StopPlayingFileAsMicrophone();
254 int IsPlayingFileAsMicrophone() const;
255 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
256 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
257 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
kwiberg55b97fe2016-01-28 05:22:45 -0800259 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000260
kwiberg55b97fe2016-01-28 05:22:45 -0800261 // VoEExternalMediaProcessing
262 int RegisterExternalMediaProcessing(ProcessingTypes type,
263 VoEMediaProcess& processObject);
264 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
265 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000266
kwiberg55b97fe2016-01-28 05:22:45 -0800267 // VoEVolumeControl
268 int GetSpeechOutputLevel(uint32_t& level) const;
269 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
solenberg1c2af8e2016-03-24 10:36:00 -0700270 int SetInputMute(bool enable);
271 bool InputMute() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800272 int SetOutputVolumePan(float left, float right);
273 int GetOutputVolumePan(float& left, float& right) const;
274 int SetChannelOutputVolumeScaling(float scaling);
275 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000276
kwiberg55b97fe2016-01-28 05:22:45 -0800277 // VoENetEqStats
278 int GetNetworkStatistics(NetworkStatistics& stats);
279 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000280
kwiberg55b97fe2016-01-28 05:22:45 -0800281 // VoEVideoSync
282 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
283 int* playout_buffer_delay_ms) const;
284 uint32_t GetDelayEstimate() const;
285 int LeastRequiredDelayMs() const;
286 int SetMinimumPlayoutDelay(int delayMs);
287 int GetPlayoutTimestamp(unsigned int& timestamp);
288 int SetInitTimestamp(unsigned int timestamp);
289 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000290
kwiberg55b97fe2016-01-28 05:22:45 -0800291 // VoEVideoSyncExtended
292 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000293
solenberg31642aa2016-03-14 08:00:37 -0700294 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800295 int SendTelephoneEventOutband(int event, int duration_ms);
solenberg31642aa2016-03-14 08:00:37 -0700296 int SetSendTelephoneEventPayloadType(int payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000297
kwiberg55b97fe2016-01-28 05:22:45 -0800298 // VoEAudioProcessingImpl
kwiberg55b97fe2016-01-28 05:22:45 -0800299 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000300
kwiberg55b97fe2016-01-28 05:22:45 -0800301 // VoERTP_RTCP
302 int SetLocalSSRC(unsigned int ssrc);
303 int GetLocalSSRC(unsigned int& ssrc);
304 int GetRemoteSSRC(unsigned int& ssrc);
305 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
306 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
307 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
308 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
309 void EnableSendTransportSequenceNumber(int id);
310 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100311
stefanbba9dec2016-02-01 04:39:55 -0800312 void RegisterSenderCongestionControlObjects(
313 RtpPacketSender* rtp_packet_sender,
314 TransportFeedbackObserver* transport_feedback_observer,
315 PacketRouter* packet_router);
316 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
317 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100318
kwiberg55b97fe2016-01-28 05:22:45 -0800319 void SetRTCPStatus(bool enable);
320 int GetRTCPStatus(bool& enabled);
321 int SetRTCP_CNAME(const char cName[256]);
322 int GetRemoteRTCP_CNAME(char cName[256]);
323 int GetRemoteRTCPData(unsigned int& NTPHigh,
324 unsigned int& NTPLow,
325 unsigned int& timestamp,
326 unsigned int& playoutTimestamp,
327 unsigned int* jitter,
328 unsigned short* fractionLost);
329 int SendApplicationDefinedRTCPPacket(unsigned char subType,
330 unsigned int name,
331 const char* data,
332 unsigned short dataLengthInBytes);
333 int GetRTPStatistics(unsigned int& averageJitterMs,
334 unsigned int& maxJitterMs,
335 unsigned int& discardedPackets);
336 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
337 int GetRTPStatistics(CallStatistics& stats);
kwiberg55b97fe2016-01-28 05:22:45 -0800338 int SetCodecFECStatus(bool enable);
339 bool GetCodecFECStatus();
340 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000341
kwiberg55b97fe2016-01-28 05:22:45 -0800342 // From AudioPacketizationCallback in the ACM
343 int32_t SendData(FrameType frameType,
344 uint8_t payloadType,
345 uint32_t timeStamp,
346 const uint8_t* payloadData,
347 size_t payloadSize,
348 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000349
kwiberg55b97fe2016-01-28 05:22:45 -0800350 // From ACMVADCallback in the ACM
351 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000352
kwiberg55b97fe2016-01-28 05:22:45 -0800353 // From RtpData in the RTP/RTCP module
354 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
355 size_t payloadSize,
356 const WebRtcRTPHeader* rtpHeader) override;
357 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000358
kwiberg55b97fe2016-01-28 05:22:45 -0800359 // From RtpFeedback in the RTP/RTCP module
360 int32_t OnInitializeDecoder(int8_t payloadType,
361 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
362 int frequency,
363 size_t channels,
364 uint32_t rate) override;
365 void OnIncomingSSRCChanged(uint32_t ssrc) override;
366 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000367
kwiberg55b97fe2016-01-28 05:22:45 -0800368 // From Transport (called by the RTP/RTCP module)
369 bool SendRtp(const uint8_t* data,
370 size_t len,
371 const PacketOptions& packet_options) override;
372 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000373
kwiberg55b97fe2016-01-28 05:22:45 -0800374 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700375 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
376 int32_t id,
377 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800378 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000379
kwiberg55b97fe2016-01-28 05:22:45 -0800380 // From FileCallback
381 void PlayNotification(int32_t id, uint32_t durationMs) override;
382 void RecordNotification(int32_t id, uint32_t durationMs) override;
383 void PlayFileEnded(int32_t id) override;
384 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000385
kwiberg55b97fe2016-01-28 05:22:45 -0800386 uint32_t InstanceId() const { return _instanceId; }
387 int32_t ChannelId() const { return _channelId; }
388 bool Playing() const { return channel_state_.Get().playing; }
389 bool Sending() const { return channel_state_.Get().sending; }
390 bool Receiving() const { return channel_state_.Get().receiving; }
391 bool ExternalTransport() const {
392 rtc::CritScope cs(&_callbackCritSect);
393 return _externalTransport;
394 }
395 bool ExternalMixing() const { return _externalMixing; }
396 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
397 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
398 uint32_t Demultiplex(const AudioFrame& audioFrame);
399 // Demultiplex the data to the channel's |_audioFrame|. The difference
400 // between this method and the overloaded method above is that |audio_data|
401 // does not go through transmit_mixer and APM.
402 void Demultiplex(const int16_t* audio_data,
403 int sample_rate,
404 size_t number_of_frames,
405 size_t number_of_channels);
406 uint32_t PrepareEncodeAndSend(int mixingFrequency);
407 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000408
kwiberg55b97fe2016-01-28 05:22:45 -0800409 // Associate to a send channel.
410 // Used for obtaining RTT for a receive-only channel.
411 void set_associate_send_channel(const ChannelOwner& channel) {
412 assert(_channelId != channel.channel()->ChannelId());
413 rtc::CritScope lock(&assoc_send_channel_lock_);
414 associate_send_channel_ = channel;
415 }
Minyue2013aec2015-05-13 14:14:42 +0200416
kwiberg55b97fe2016-01-28 05:22:45 -0800417 // Disassociate a send channel if it was associated.
418 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200419
ivoc14d5dbe2016-07-04 07:06:55 -0700420 // Set a RtcEventLog logging object.
421 void SetRtcEventLog(RtcEventLog* event_log);
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
ossue280cde2016-10-12 11:04:10 -0700446 int GetRtpTimestampRateHz() 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_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200458
kwibergb7f89d62016-02-17 10:04:18 -0800459 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
460 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
461 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
462 std::unique_ptr<StatisticsProxy> statistics_proxy_;
463 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700464 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800465 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
466 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700467 acm2::CodecManager codec_manager_;
468 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800469 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800470 AudioLevel _outputAudioLevel;
471 bool _externalTransport;
472 AudioFrame _audioFrame;
473 // Downsamples to the codec rate if necessary.
474 PushResampler<int16_t> input_resampler_;
kwiberg5a25d952016-08-17 07:31:12 -0700475 std::unique_ptr<FilePlayer> input_file_player_;
476 std::unique_ptr<FilePlayer> output_file_player_;
477 std::unique_ptr<FileRecorder> output_file_recorder_;
kwiberg55b97fe2016-01-28 05:22:45 -0800478 int _inputFilePlayerId;
479 int _outputFilePlayerId;
480 int _outputFileRecorderId;
481 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800482 bool _outputExternalMedia;
483 VoEMediaProcess* _inputExternalMediaCallbackPtr;
484 VoEMediaProcess* _outputExternalMediaCallbackPtr;
485 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000486
kwiberg55b97fe2016-01-28 05:22:45 -0800487 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000488
kwiberg55b97fe2016-01-28 05:22:45 -0800489 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700490 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
kwiberg55b97fe2016-01-28 05:22:45 -0800491 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
492 uint32_t playout_timestamp_rtcp_;
493 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
494 uint32_t _numberOfDiscardedPackets;
495 uint16_t send_sequence_number_;
496 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000497
pbosd8de1152016-02-01 09:00:51 -0800498 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000499
kwibergb7f89d62016-02-17 10:04:18 -0800500 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800501 // The rtp timestamp of the first played out audio frame.
502 int64_t capture_start_rtp_time_stamp_;
503 // The capture ntp time (in local timebase) of the first played out audio
504 // frame.
505 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000506
kwiberg55b97fe2016-01-28 05:22:45 -0800507 // uses
508 Statistics* _engineStatisticsPtr;
509 OutputMixer* _outputMixerPtr;
510 TransmitMixer* _transmitMixerPtr;
511 ProcessThread* _moduleProcessThreadPtr;
512 AudioDeviceModule* _audioDeviceModulePtr;
513 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
514 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
515 Transport* _transportPtr; // WebRtc socket or external transport
516 RMSLevel rms_level_;
kwiberg55b97fe2016-01-28 05:22:45 -0800517 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
518 // VoEBase
519 bool _externalMixing;
520 bool _mixFileWithMicrophone;
521 // VoEVolumeControl
solenberg1c2af8e2016-03-24 10:36:00 -0700522 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
523 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
524 float _panLeft GUARDED_BY(volume_settings_critsect_);
525 float _panRight GUARDED_BY(volume_settings_critsect_);
526 float _outputGain GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800527 // VoeRTP_RTCP
528 uint32_t _lastLocalTimeStamp;
529 int8_t _lastPayloadType;
530 bool _includeAudioLevelIndication;
531 // VoENetwork
532 AudioFrame::SpeechType _outputSpeechType;
533 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800534 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800535 // VoEAudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800536 bool restored_packet_in_use_;
537 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800538 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800539 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800540 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800541 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100542
kwiberg55b97fe2016-01-28 05:22:45 -0800543 bool pacing_enabled_;
544 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800545 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
546 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
547 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200548 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700549
550 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
551 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000552};
553
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000554} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000555} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000556
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000557#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_