blob: 9f789dfac332907ad4ec65c99ea8eb681c3faab0 [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
kjellander@webrtc.org7ffeab52016-02-26 22:46:09 +010016#include "webrtc/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"
29#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"
32#include "webrtc/voice_engine/include/voe_network.h"
33#include "webrtc/voice_engine/level_indicator.h"
minyue@webrtc.org74aaf292014-07-16 21:28:26 +000034#include "webrtc/voice_engine/network_predictor.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000035#include "webrtc/voice_engine/shared_data.h"
36#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000037
wu@webrtc.org94454b72014-06-05 20:34:08 +000038namespace rtc {
39
40class TimestampWrapAroundHandler;
41}
42
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000043namespace webrtc {
44
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000045class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000046class Config;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000047class FileWrapper;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010048class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049class ProcessThread;
50class 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;
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 {
85 State()
86 : rx_apm_is_enabled(false),
87 input_external_media(false),
88 output_file_playing(false),
89 input_file_playing(false),
90 playing(false),
91 sending(false),
92 receiving(false) {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000093
kwiberg55b97fe2016-01-28 05:22:45 -080094 bool rx_apm_is_enabled;
95 bool input_external_media;
96 bool output_file_playing;
97 bool input_file_playing;
98 bool playing;
99 bool sending;
100 bool receiving;
101 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000102
kwiberg55b97fe2016-01-28 05:22:45 -0800103 ChannelState() {}
104 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000105
kwiberg55b97fe2016-01-28 05:22:45 -0800106 void Reset() {
107 rtc::CritScope lock(&lock_);
108 state_ = State();
109 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000110
kwiberg55b97fe2016-01-28 05:22:45 -0800111 State Get() const {
112 rtc::CritScope lock(&lock_);
113 return state_;
114 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000115
kwiberg55b97fe2016-01-28 05:22:45 -0800116 void SetRxApmIsEnabled(bool enable) {
117 rtc::CritScope lock(&lock_);
118 state_.rx_apm_is_enabled = enable;
119 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000120
kwiberg55b97fe2016-01-28 05:22:45 -0800121 void SetInputExternalMedia(bool enable) {
122 rtc::CritScope lock(&lock_);
123 state_.input_external_media = enable;
124 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000125
kwiberg55b97fe2016-01-28 05:22:45 -0800126 void SetOutputFilePlaying(bool enable) {
127 rtc::CritScope lock(&lock_);
128 state_.output_file_playing = enable;
129 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000130
kwiberg55b97fe2016-01-28 05:22:45 -0800131 void SetInputFilePlaying(bool enable) {
132 rtc::CritScope lock(&lock_);
133 state_.input_file_playing = enable;
134 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000135
kwiberg55b97fe2016-01-28 05:22:45 -0800136 void SetPlaying(bool enable) {
137 rtc::CritScope lock(&lock_);
138 state_.playing = enable;
139 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000140
kwiberg55b97fe2016-01-28 05:22:45 -0800141 void SetSending(bool enable) {
142 rtc::CritScope lock(&lock_);
143 state_.sending = enable;
144 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000145
kwiberg55b97fe2016-01-28 05:22:45 -0800146 void SetReceiving(bool enable) {
147 rtc::CritScope lock(&lock_);
148 state_.receiving = enable;
149 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000150
kwiberg55b97fe2016-01-28 05:22:45 -0800151 private:
pbosd8de1152016-02-01 09:00:51 -0800152 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800153 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000154};
niklase@google.com470e71d2011-07-07 08:21:25 +0000155
kwiberg55b97fe2016-01-28 05:22:45 -0800156class Channel
157 : public RtpData,
158 public RtpFeedback,
159 public FileCallback, // receiving notification from file player &
160 // recorder
161 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800162 public AudioPacketizationCallback, // receive encoded packets from the
163 // ACM
164 public ACMVADCallback, // receive voice activity from the ACM
165 public MixerParticipant // supplies output mixer with audio frames
niklase@google.com470e71d2011-07-07 08:21:25 +0000166{
kwiberg55b97fe2016-01-28 05:22:45 -0800167 public:
168 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000169
kwiberg55b97fe2016-01-28 05:22:45 -0800170 enum { KNumSocketThreads = 1 };
171 enum { KNumberOfSocketBuffers = 8 };
172 virtual ~Channel();
173 static int32_t CreateChannel(Channel*& channel,
174 int32_t channelId,
175 uint32_t instanceId,
176 RtcEventLog* const event_log,
177 const Config& config);
ossu5f7cfa52016-05-30 08:11:28 -0700178 static int32_t CreateChannel(
179 Channel*& channel,
180 int32_t channelId,
181 uint32_t instanceId,
182 RtcEventLog* const event_log,
183 const Config& config,
184 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory);
kwiberg55b97fe2016-01-28 05:22:45 -0800185 Channel(int32_t channelId,
186 uint32_t instanceId,
187 RtcEventLog* const event_log,
ossu5f7cfa52016-05-30 08:11:28 -0700188 const Config& config,
189 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory);
kwiberg55b97fe2016-01-28 05:22:45 -0800190 int32_t Init();
191 int32_t SetEngineInformation(Statistics& engineStatistics,
192 OutputMixer& outputMixer,
193 TransmitMixer& transmitMixer,
194 ProcessThread& moduleProcessThread,
195 AudioDeviceModule& audioDeviceModule,
196 VoiceEngineObserver* voiceEngineObserver,
197 rtc::CriticalSection* callbackCritSect);
198 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000199
kwibergb7f89d62016-02-17 10:04:18 -0800200 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
Tommif888bb52015-12-12 01:37:01 +0100201
kwiberg55b97fe2016-01-28 05:22:45 -0800202 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000203
kwiberg55b97fe2016-01-28 05:22:45 -0800204 // VoEBase
205 int32_t StartPlayout();
206 int32_t StopPlayout();
207 int32_t StartSend();
208 int32_t StopSend();
209 int32_t StartReceiving();
210 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000211
kwiberg55b97fe2016-01-28 05:22:45 -0800212 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
213 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000214
kwiberg55b97fe2016-01-28 05:22:45 -0800215 // VoECodec
216 int32_t GetSendCodec(CodecInst& codec);
217 int32_t GetRecCodec(CodecInst& codec);
218 int32_t SetSendCodec(const CodecInst& codec);
219 void SetBitRate(int bitrate_bps);
220 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
221 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
222 int32_t SetRecPayloadType(const CodecInst& codec);
223 int32_t GetRecPayloadType(CodecInst& codec);
224 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
225 int SetOpusMaxPlaybackRate(int frequency_hz);
226 int SetOpusDtx(bool enable_dtx);
niklase@google.com470e71d2011-07-07 08:21:25 +0000227
kwiberg55b97fe2016-01-28 05:22:45 -0800228 // VoENetwork
mflodman3d7db262016-04-29 00:57:13 -0700229 int32_t RegisterExternalTransport(Transport* transport);
kwiberg55b97fe2016-01-28 05:22:45 -0800230 int32_t DeRegisterExternalTransport();
mflodman3d7db262016-04-29 00:57:13 -0700231 int32_t ReceivedRTPPacket(const uint8_t* received_packet,
kwiberg55b97fe2016-01-28 05:22:45 -0800232 size_t length,
233 const PacketTime& packet_time);
mflodman3d7db262016-04-29 00:57:13 -0700234 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000235
kwiberg55b97fe2016-01-28 05:22:45 -0800236 // VoEFile
237 int StartPlayingFileLocally(const char* fileName,
238 bool loop,
239 FileFormats format,
240 int startPosition,
241 float volumeScaling,
242 int stopPosition,
243 const CodecInst* codecInst);
244 int StartPlayingFileLocally(InStream* stream,
245 FileFormats format,
246 int startPosition,
247 float volumeScaling,
248 int stopPosition,
249 const CodecInst* codecInst);
250 int StopPlayingFileLocally();
251 int IsPlayingFileLocally() const;
252 int RegisterFilePlayingToMixer();
253 int StartPlayingFileAsMicrophone(const char* fileName,
254 bool loop,
255 FileFormats format,
256 int startPosition,
257 float volumeScaling,
258 int stopPosition,
259 const CodecInst* codecInst);
260 int StartPlayingFileAsMicrophone(InStream* stream,
261 FileFormats format,
262 int startPosition,
263 float volumeScaling,
264 int stopPosition,
265 const CodecInst* codecInst);
266 int StopPlayingFileAsMicrophone();
267 int IsPlayingFileAsMicrophone() const;
268 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
269 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
270 int StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000271
kwiberg55b97fe2016-01-28 05:22:45 -0800272 void SetMixWithMicStatus(bool mix);
niklase@google.com470e71d2011-07-07 08:21:25 +0000273
kwiberg55b97fe2016-01-28 05:22:45 -0800274 // VoEExternalMediaProcessing
275 int RegisterExternalMediaProcessing(ProcessingTypes type,
276 VoEMediaProcess& processObject);
277 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
278 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000279
kwiberg55b97fe2016-01-28 05:22:45 -0800280 // VoEVolumeControl
281 int GetSpeechOutputLevel(uint32_t& level) const;
282 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
solenberg1c2af8e2016-03-24 10:36:00 -0700283 int SetInputMute(bool enable);
284 bool InputMute() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800285 int SetOutputVolumePan(float left, float right);
286 int GetOutputVolumePan(float& left, float& right) const;
287 int SetChannelOutputVolumeScaling(float scaling);
288 int GetChannelOutputVolumeScaling(float& scaling) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000289
kwiberg55b97fe2016-01-28 05:22:45 -0800290 // VoENetEqStats
291 int GetNetworkStatistics(NetworkStatistics& stats);
292 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000293
kwiberg55b97fe2016-01-28 05:22:45 -0800294 // VoEVideoSync
295 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
296 int* playout_buffer_delay_ms) const;
297 uint32_t GetDelayEstimate() const;
298 int LeastRequiredDelayMs() const;
299 int SetMinimumPlayoutDelay(int delayMs);
300 int GetPlayoutTimestamp(unsigned int& timestamp);
301 int SetInitTimestamp(unsigned int timestamp);
302 int SetInitSequenceNumber(short sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000303
kwiberg55b97fe2016-01-28 05:22:45 -0800304 // VoEVideoSyncExtended
305 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000306
solenberg31642aa2016-03-14 08:00:37 -0700307 // DTMF
solenberg8842c3e2016-03-11 03:06:41 -0800308 int SendTelephoneEventOutband(int event, int duration_ms);
solenberg31642aa2016-03-14 08:00:37 -0700309 int SetSendTelephoneEventPayloadType(int payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000310
kwiberg55b97fe2016-01-28 05:22:45 -0800311 // VoEAudioProcessingImpl
312 int UpdateRxVadDetection(AudioFrame& audioFrame);
313 int RegisterRxVadObserver(VoERxVadCallback& observer);
314 int DeRegisterRxVadObserver();
315 int VoiceActivityIndicator(int& activity);
niklase@google.com470e71d2011-07-07 08:21:25 +0000316#ifdef WEBRTC_VOICE_ENGINE_AGC
kwiberg55b97fe2016-01-28 05:22:45 -0800317 int SetRxAgcStatus(bool enable, AgcModes mode);
318 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
319 int SetRxAgcConfig(AgcConfig config);
320 int GetRxAgcConfig(AgcConfig& config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000321#endif
322#ifdef WEBRTC_VOICE_ENGINE_NR
kwiberg55b97fe2016-01-28 05:22:45 -0800323 int SetRxNsStatus(bool enable, NsModes mode);
324 int GetRxNsStatus(bool& enabled, NsModes& mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000325#endif
326
kwiberg55b97fe2016-01-28 05:22:45 -0800327 // VoERTP_RTCP
328 int SetLocalSSRC(unsigned int ssrc);
329 int GetLocalSSRC(unsigned int& ssrc);
330 int GetRemoteSSRC(unsigned int& ssrc);
331 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
332 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
333 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
334 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
335 void EnableSendTransportSequenceNumber(int id);
336 void EnableReceiveTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100337
stefanbba9dec2016-02-01 04:39:55 -0800338 void RegisterSenderCongestionControlObjects(
339 RtpPacketSender* rtp_packet_sender,
340 TransportFeedbackObserver* transport_feedback_observer,
341 PacketRouter* packet_router);
342 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
343 void ResetCongestionControlObjects();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100344
kwiberg55b97fe2016-01-28 05:22:45 -0800345 void SetRTCPStatus(bool enable);
346 int GetRTCPStatus(bool& enabled);
347 int SetRTCP_CNAME(const char cName[256]);
348 int GetRemoteRTCP_CNAME(char cName[256]);
349 int GetRemoteRTCPData(unsigned int& NTPHigh,
350 unsigned int& NTPLow,
351 unsigned int& timestamp,
352 unsigned int& playoutTimestamp,
353 unsigned int* jitter,
354 unsigned short* fractionLost);
355 int SendApplicationDefinedRTCPPacket(unsigned char subType,
356 unsigned int name,
357 const char* data,
358 unsigned short dataLengthInBytes);
359 int GetRTPStatistics(unsigned int& averageJitterMs,
360 unsigned int& maxJitterMs,
361 unsigned int& discardedPackets);
362 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
363 int GetRTPStatistics(CallStatistics& stats);
364 int SetREDStatus(bool enable, int redPayloadtype);
365 int GetREDStatus(bool& enabled, int& redPayloadtype);
366 int SetCodecFECStatus(bool enable);
367 bool GetCodecFECStatus();
368 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000369
kwiberg55b97fe2016-01-28 05:22:45 -0800370 // From AudioPacketizationCallback in the ACM
371 int32_t SendData(FrameType frameType,
372 uint8_t payloadType,
373 uint32_t timeStamp,
374 const uint8_t* payloadData,
375 size_t payloadSize,
376 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000377
kwiberg55b97fe2016-01-28 05:22:45 -0800378 // From ACMVADCallback in the ACM
379 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000380
kwiberg55b97fe2016-01-28 05:22:45 -0800381 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000382
kwiberg55b97fe2016-01-28 05:22:45 -0800383 // From RtpData in the RTP/RTCP module
384 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
385 size_t payloadSize,
386 const WebRtcRTPHeader* rtpHeader) override;
387 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000388
kwiberg55b97fe2016-01-28 05:22:45 -0800389 // From RtpFeedback in the RTP/RTCP module
390 int32_t OnInitializeDecoder(int8_t payloadType,
391 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
392 int frequency,
393 size_t channels,
394 uint32_t rate) override;
395 void OnIncomingSSRCChanged(uint32_t ssrc) override;
396 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000397
kwiberg55b97fe2016-01-28 05:22:45 -0800398 // From Transport (called by the RTP/RTCP module)
399 bool SendRtp(const uint8_t* data,
400 size_t len,
401 const PacketOptions& packet_options) override;
402 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000403
kwiberg55b97fe2016-01-28 05:22:45 -0800404 // From MixerParticipant
henrik.lundin42dda502016-05-18 05:36:01 -0700405 MixerParticipant::AudioFrameInfo GetAudioFrameWithMuted(
406 int32_t id,
407 AudioFrame* audioFrame) override;
kwiberg55b97fe2016-01-28 05:22:45 -0800408 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000409
kwiberg55b97fe2016-01-28 05:22:45 -0800410 // From FileCallback
411 void PlayNotification(int32_t id, uint32_t durationMs) override;
412 void RecordNotification(int32_t id, uint32_t durationMs) override;
413 void PlayFileEnded(int32_t id) override;
414 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000415
kwiberg55b97fe2016-01-28 05:22:45 -0800416 uint32_t InstanceId() const { return _instanceId; }
417 int32_t ChannelId() const { return _channelId; }
418 bool Playing() const { return channel_state_.Get().playing; }
419 bool Sending() const { return channel_state_.Get().sending; }
420 bool Receiving() const { return channel_state_.Get().receiving; }
421 bool ExternalTransport() const {
422 rtc::CritScope cs(&_callbackCritSect);
423 return _externalTransport;
424 }
425 bool ExternalMixing() const { return _externalMixing; }
426 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
427 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
428 uint32_t Demultiplex(const AudioFrame& audioFrame);
429 // Demultiplex the data to the channel's |_audioFrame|. The difference
430 // between this method and the overloaded method above is that |audio_data|
431 // does not go through transmit_mixer and APM.
432 void Demultiplex(const int16_t* audio_data,
433 int sample_rate,
434 size_t number_of_frames,
435 size_t number_of_channels);
436 uint32_t PrepareEncodeAndSend(int mixingFrequency);
437 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000438
kwiberg55b97fe2016-01-28 05:22:45 -0800439 // Associate to a send channel.
440 // Used for obtaining RTT for a receive-only channel.
441 void set_associate_send_channel(const ChannelOwner& channel) {
442 assert(_channelId != channel.channel()->ChannelId());
443 rtc::CritScope lock(&assoc_send_channel_lock_);
444 associate_send_channel_ = channel;
445 }
Minyue2013aec2015-05-13 14:14:42 +0200446
kwiberg55b97fe2016-01-28 05:22:45 -0800447 // Disassociate a send channel if it was associated.
448 void DisassociateSendChannel(int channel_id);
Minyue2013aec2015-05-13 14:14:42 +0200449
kwiberg55b97fe2016-01-28 05:22:45 -0800450 protected:
451 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000452
kwiberg55b97fe2016-01-28 05:22:45 -0800453 private:
454 bool ReceivePacket(const uint8_t* packet,
455 size_t packet_length,
456 const RTPHeader& header,
457 bool in_order);
458 bool HandleRtxPacket(const uint8_t* packet,
459 size_t packet_length,
460 const RTPHeader& header);
461 bool IsPacketInOrder(const RTPHeader& header) const;
462 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
463 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800464 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
465 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
466 void UpdatePlayoutTimestamp(bool rtcp);
467 void UpdatePacketDelay(uint32_t timestamp, uint16_t sequenceNumber);
468 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000469
kwiberg55b97fe2016-01-28 05:22:45 -0800470 int SetRedPayloadType(int red_payload_type);
471 int SetSendRtpHeaderExtension(bool enable,
472 RTPExtensionType type,
473 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000474
kwiberg55b97fe2016-01-28 05:22:45 -0800475 int32_t GetPlayoutFrequency();
476 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000477
pbosd8de1152016-02-01 09:00:51 -0800478 rtc::CriticalSection _fileCritSect;
479 rtc::CriticalSection _callbackCritSect;
480 rtc::CriticalSection volume_settings_critsect_;
kwiberg55b97fe2016-01-28 05:22:45 -0800481 uint32_t _instanceId;
482 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000483
kwiberg55b97fe2016-01-28 05:22:45 -0800484 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000485
kwiberg55b97fe2016-01-28 05:22:45 -0800486 RtcEventLog* const event_log_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200487
kwibergb7f89d62016-02-17 10:04:18 -0800488 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
489 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
490 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
491 std::unique_ptr<StatisticsProxy> statistics_proxy_;
492 std::unique_ptr<RtpReceiver> rtp_receiver_;
kwiberg55b97fe2016-01-28 05:22:45 -0800493 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800494 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
495 std::unique_ptr<AudioCodingModule> audio_coding_;
kwibergc8d071e2016-04-06 12:22:38 -0700496 acm2::CodecManager codec_manager_;
497 acm2::RentACodec rent_a_codec_;
kwibergb7f89d62016-02-17 10:04:18 -0800498 std::unique_ptr<AudioSinkInterface> audio_sink_;
kwiberg55b97fe2016-01-28 05:22:45 -0800499 AudioLevel _outputAudioLevel;
500 bool _externalTransport;
501 AudioFrame _audioFrame;
502 // Downsamples to the codec rate if necessary.
503 PushResampler<int16_t> input_resampler_;
504 FilePlayer* _inputFilePlayerPtr;
505 FilePlayer* _outputFilePlayerPtr;
506 FileRecorder* _outputFileRecorderPtr;
507 int _inputFilePlayerId;
508 int _outputFilePlayerId;
509 int _outputFileRecorderId;
510 bool _outputFileRecording;
kwiberg55b97fe2016-01-28 05:22:45 -0800511 bool _outputExternalMedia;
512 VoEMediaProcess* _inputExternalMediaCallbackPtr;
513 VoEMediaProcess* _outputExternalMediaCallbackPtr;
514 uint32_t _timeStamp;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000515
kwiberg55b97fe2016-01-28 05:22:45 -0800516 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000517
kwiberg55b97fe2016-01-28 05:22:45 -0800518 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700519 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
kwiberg55b97fe2016-01-28 05:22:45 -0800520 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
521 uint32_t playout_timestamp_rtcp_;
522 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
523 uint32_t _numberOfDiscardedPackets;
524 uint16_t send_sequence_number_;
525 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000526
pbosd8de1152016-02-01 09:00:51 -0800527 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000528
kwibergb7f89d62016-02-17 10:04:18 -0800529 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800530 // The rtp timestamp of the first played out audio frame.
531 int64_t capture_start_rtp_time_stamp_;
532 // The capture ntp time (in local timebase) of the first played out audio
533 // frame.
534 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000535
kwiberg55b97fe2016-01-28 05:22:45 -0800536 // uses
537 Statistics* _engineStatisticsPtr;
538 OutputMixer* _outputMixerPtr;
539 TransmitMixer* _transmitMixerPtr;
540 ProcessThread* _moduleProcessThreadPtr;
541 AudioDeviceModule* _audioDeviceModulePtr;
542 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
543 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
544 Transport* _transportPtr; // WebRtc socket or external transport
545 RMSLevel rms_level_;
kwibergb7f89d62016-02-17 10:04:18 -0800546 std::unique_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
kwiberg55b97fe2016-01-28 05:22:45 -0800547 VoERxVadCallback* _rxVadObserverPtr;
548 int32_t _oldVadDecision;
549 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
550 // VoEBase
551 bool _externalMixing;
552 bool _mixFileWithMicrophone;
553 // VoEVolumeControl
solenberg1c2af8e2016-03-24 10:36:00 -0700554 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
555 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
556 float _panLeft GUARDED_BY(volume_settings_critsect_);
557 float _panRight GUARDED_BY(volume_settings_critsect_);
558 float _outputGain GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800559 // VoeRTP_RTCP
560 uint32_t _lastLocalTimeStamp;
561 int8_t _lastPayloadType;
562 bool _includeAudioLevelIndication;
563 // VoENetwork
564 AudioFrame::SpeechType _outputSpeechType;
565 // VoEVideoSync
pbosd8de1152016-02-01 09:00:51 -0800566 rtc::CriticalSection video_sync_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800567 uint32_t _average_jitter_buffer_delay_us GUARDED_BY(video_sync_lock_);
568 uint32_t _previousTimestamp;
569 uint16_t _recPacketDelayMs GUARDED_BY(video_sync_lock_);
570 // VoEAudioProcessing
571 bool _RxVadDetection;
572 bool _rxAgcIsEnabled;
573 bool _rxNsIsEnabled;
574 bool restored_packet_in_use_;
575 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800576 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
577 std::unique_ptr<NetworkPredictor> network_predictor_;
kwiberg55b97fe2016-01-28 05:22:45 -0800578 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800579 rtc::CriticalSection assoc_send_channel_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800580 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100581
kwiberg55b97fe2016-01-28 05:22:45 -0800582 bool pacing_enabled_;
583 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800584 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
585 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
586 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000587};
588
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000589} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000590} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000591
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000592#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_