blob: d3b1b93645bf79a93a0d9769e6a6499010266eee [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
Stefan Holmerb86d4e42015-12-07 10:26:18 +010014#include "webrtc/base/criticalsection.h"
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000015#include "webrtc/base/scoped_ptr.h"
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000016#include "webrtc/common_audio/resampler/include/push_resampler.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000017#include "webrtc/common_types.h"
kjellander3e6db232015-11-26 04:44:54 -080018#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010019#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
andrew@webrtc.org382c0c22014-05-05 18:22:21 +000020#include "webrtc/modules/audio_processing/rms_level.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010021#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
22#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
23#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
24#include "webrtc/modules/utility/include/file_player.h"
25#include "webrtc/modules/utility/include/file_recorder.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000026#include "webrtc/voice_engine/dtmf_inband.h"
27#include "webrtc/voice_engine/dtmf_inband_queue.h"
28#include "webrtc/voice_engine/include/voe_audio_processing.h"
29#include "webrtc/voice_engine/include/voe_network.h"
30#include "webrtc/voice_engine/level_indicator.h"
minyue@webrtc.org74aaf292014-07-16 21:28:26 +000031#include "webrtc/voice_engine/network_predictor.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000032#include "webrtc/voice_engine/shared_data.h"
33#include "webrtc/voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000034
niklase@google.com470e71d2011-07-07 08:21:25 +000035#ifdef WEBRTC_DTMF_DETECTION
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000036// TelephoneEventDetectionMethods, TelephoneEventObserver
37#include "webrtc/voice_engine/include/voe_dtmf.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000038#endif
39
wu@webrtc.org94454b72014-06-05 20:34:08 +000040namespace rtc {
41
42class TimestampWrapAroundHandler;
43}
44
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000045namespace webrtc {
46
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000047class AudioDeviceModule;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000048class Config;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049class CriticalSectionWrapper;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000050class FileWrapper;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010051class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000052class ProcessThread;
53class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000054class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070055class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000056class RTPPayloadRegistry;
57class RtpReceiver;
58class RTPReceiverAudio;
59class RtpRtcp;
60class TelephoneEventHandler;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000061class VoEMediaProcess;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000062class VoERTPObserver;
63class VoiceEngineObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
65struct CallStatistics;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000066struct ReportBlock;
67struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000068
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000069namespace voe {
70
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000071class OutputMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010072class RtpPacketSenderProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000073class Statistics;
sprang@webrtc.org54ae4ff2013-12-19 13:26:02 +000074class StatisticsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010075class TransportFeedbackProxy;
niklase@google.com470e71d2011-07-07 08:21:25 +000076class TransmitMixer;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010077class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000078class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000079
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000080// Helper class to simplify locking scheme for members that are accessed from
81// multiple threads.
82// Example: a member can be set on thread T1 and read by an internal audio
83// thread T2. Accessing the member via this class ensures that we are
84// safe and also avoid TSan v2 warnings.
85class ChannelState {
86 public:
87 struct State {
88 State() : rx_apm_is_enabled(false),
89 input_external_media(false),
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000090 output_file_playing(false),
91 input_file_playing(false),
92 playing(false),
93 sending(false),
94 receiving(false) {}
95
96 bool rx_apm_is_enabled;
97 bool input_external_media;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000098 bool output_file_playing;
99 bool input_file_playing;
100 bool playing;
101 bool sending;
102 bool receiving;
103 };
104
105 ChannelState() : lock_(CriticalSectionWrapper::CreateCriticalSection()) {
106 }
107 virtual ~ChannelState() {}
108
109 void Reset() {
110 CriticalSectionScoped lock(lock_.get());
111 state_ = State();
112 }
113
114 State Get() const {
115 CriticalSectionScoped lock(lock_.get());
116 return state_;
117 }
118
119 void SetRxApmIsEnabled(bool enable) {
120 CriticalSectionScoped lock(lock_.get());
121 state_.rx_apm_is_enabled = enable;
122 }
123
124 void SetInputExternalMedia(bool enable) {
125 CriticalSectionScoped lock(lock_.get());
126 state_.input_external_media = enable;
127 }
128
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000129 void SetOutputFilePlaying(bool enable) {
130 CriticalSectionScoped lock(lock_.get());
131 state_.output_file_playing = enable;
132 }
133
134 void SetInputFilePlaying(bool enable) {
135 CriticalSectionScoped lock(lock_.get());
136 state_.input_file_playing = enable;
137 }
138
139 void SetPlaying(bool enable) {
140 CriticalSectionScoped lock(lock_.get());
141 state_.playing = enable;
142 }
143
144 void SetSending(bool enable) {
145 CriticalSectionScoped lock(lock_.get());
146 state_.sending = enable;
147 }
148
149 void SetReceiving(bool enable) {
150 CriticalSectionScoped lock(lock_.get());
151 state_.receiving = enable;
152 }
153
154private:
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000155 rtc::scoped_ptr<CriticalSectionWrapper> lock_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000156 State state_;
157};
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
159class Channel:
160 public RtpData,
161 public RtpFeedback,
niklase@google.com470e71d2011-07-07 08:21:25 +0000162 public FileCallback, // receiving notification from file player & recorder
163 public Transport,
164 public RtpAudioFeedback,
165 public AudioPacketizationCallback, // receive encoded packets from the ACM
166 public ACMVADCallback, // receive voice activity from the ACM
niklase@google.com470e71d2011-07-07 08:21:25 +0000167 public MixerParticipant // supplies output mixer with audio frames
168{
169public:
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000170 friend class VoERtcpObserver;
171
niklase@google.com470e71d2011-07-07 08:21:25 +0000172 enum {KNumSocketThreads = 1};
173 enum {KNumberOfSocketBuffers = 8};
niklase@google.com470e71d2011-07-07 08:21:25 +0000174 virtual ~Channel();
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000175 static int32_t CreateChannel(Channel*& channel,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000176 int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000177 uint32_t instanceId,
ivocb04965c2015-09-09 00:09:43 -0700178 RtcEventLog* const event_log,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000179 const Config& config);
ivocb04965c2015-09-09 00:09:43 -0700180 Channel(int32_t channelId,
181 uint32_t instanceId,
182 RtcEventLog* const event_log,
183 const Config& config);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000184 int32_t Init();
185 int32_t SetEngineInformation(
niklase@google.com470e71d2011-07-07 08:21:25 +0000186 Statistics& engineStatistics,
187 OutputMixer& outputMixer,
188 TransmitMixer& transmitMixer,
189 ProcessThread& moduleProcessThread,
190 AudioDeviceModule& audioDeviceModule,
191 VoiceEngineObserver* voiceEngineObserver,
192 CriticalSectionWrapper* callbackCritSect);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000193 int32_t UpdateLocalTimeStamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
niklase@google.com470e71d2011-07-07 08:21:25 +0000195 // API methods
196
197 // VoEBase
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000198 int32_t StartPlayout();
199 int32_t StopPlayout();
200 int32_t StartSend();
201 int32_t StopSend();
202 int32_t StartReceiving();
203 int32_t StopReceiving();
niklase@google.com470e71d2011-07-07 08:21:25 +0000204
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000205 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
206 int32_t DeRegisterVoiceEngineObserver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
208 // VoECodec
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000209 int32_t GetSendCodec(CodecInst& codec);
210 int32_t GetRecCodec(CodecInst& codec);
211 int32_t SetSendCodec(const CodecInst& codec);
Ivo Creusenadf89b72015-04-29 16:03:33 +0200212 void SetBitRate(int bitrate_bps);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000213 int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX);
214 int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX);
215 int32_t SetRecPayloadType(const CodecInst& codec);
216 int32_t GetRecPayloadType(CodecInst& codec);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000217 int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
minyue@webrtc.orgadee8f92014-09-03 12:28:06 +0000218 int SetOpusMaxPlaybackRate(int frequency_hz);
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000219 int SetOpusDtx(bool enable_dtx);
niklase@google.com470e71d2011-07-07 08:21:25 +0000220
221 // VoENetwork
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000222 int32_t RegisterExternalTransport(Transport& transport);
223 int32_t DeRegisterExternalTransport();
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000224 int32_t ReceivedRTPPacket(const int8_t* data, size_t length,
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000225 const PacketTime& packet_time);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000226 int32_t ReceivedRTCPPacket(const int8_t* data, size_t length);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000227
niklase@google.com470e71d2011-07-07 08:21:25 +0000228 // VoEFile
pbos@webrtc.org92135212013-05-14 08:31:39 +0000229 int StartPlayingFileLocally(const char* fileName, bool loop,
230 FileFormats format,
231 int startPosition,
232 float volumeScaling,
233 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000234 const CodecInst* codecInst);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000235 int StartPlayingFileLocally(InStream* stream, FileFormats format,
236 int startPosition,
237 float volumeScaling,
238 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000239 const CodecInst* codecInst);
240 int StopPlayingFileLocally();
241 int IsPlayingFileLocally() const;
braveyao@webrtc.orgab129902012-06-04 03:26:39 +0000242 int RegisterFilePlayingToMixer();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000243 int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
244 FileFormats format,
245 int startPosition,
246 float volumeScaling,
247 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000248 const CodecInst* codecInst);
249 int StartPlayingFileAsMicrophone(InStream* stream,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000250 FileFormats format,
251 int startPosition,
252 float volumeScaling,
253 int stopPosition,
niklase@google.com470e71d2011-07-07 08:21:25 +0000254 const CodecInst* codecInst);
255 int StopPlayingFileAsMicrophone();
256 int IsPlayingFileAsMicrophone() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000257 int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
258 int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
259 int StopRecordingPlayout();
260
261 void SetMixWithMicStatus(bool mix);
262
263 // VoEExternalMediaProcessing
264 int RegisterExternalMediaProcessing(ProcessingTypes type,
265 VoEMediaProcess& processObject);
266 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000267 int SetExternalMixing(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000268
269 // VoEVolumeControl
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000270 int GetSpeechOutputLevel(uint32_t& level) const;
271 int GetSpeechOutputLevelFullRange(uint32_t& level) const;
pbos@webrtc.org92135212013-05-14 08:31:39 +0000272 int SetMute(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000273 bool Mute() const;
274 int SetOutputVolumePan(float left, float right);
275 int GetOutputVolumePan(float& left, float& right) const;
276 int SetChannelOutputVolumeScaling(float scaling);
277 int GetChannelOutputVolumeScaling(float& scaling) const;
278
niklase@google.com470e71d2011-07-07 08:21:25 +0000279 // VoENetEqStats
280 int GetNetworkStatistics(NetworkStatistics& stats);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000281 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000282
283 // VoEVideoSync
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000284 bool GetDelayEstimate(int* jitter_buffer_delay_ms,
285 int* playout_buffer_delay_ms) const;
solenberg358057b2015-11-27 10:46:42 -0800286 uint32_t GetDelayEstimate() const;
deadbeef74375882015-08-13 12:09:10 -0700287 int LeastRequiredDelayMs() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000288 int SetMinimumPlayoutDelay(int delayMs);
289 int GetPlayoutTimestamp(unsigned int& timestamp);
290 int SetInitTimestamp(unsigned int timestamp);
291 int SetInitSequenceNumber(short sequenceNumber);
292
293 // VoEVideoSyncExtended
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000294 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000295
niklase@google.com470e71d2011-07-07 08:21:25 +0000296 // VoEDtmf
297 int SendTelephoneEventOutband(unsigned char eventCode, int lengthMs,
298 int attenuationDb, bool playDtmfEvent);
299 int SendTelephoneEventInband(unsigned char eventCode, int lengthMs,
300 int attenuationDb, bool playDtmfEvent);
niklase@google.com470e71d2011-07-07 08:21:25 +0000301 int SetSendTelephoneEventPayloadType(unsigned char type);
302 int GetSendTelephoneEventPayloadType(unsigned char& type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000303
304 // VoEAudioProcessingImpl
305 int UpdateRxVadDetection(AudioFrame& audioFrame);
306 int RegisterRxVadObserver(VoERxVadCallback &observer);
307 int DeRegisterRxVadObserver();
308 int VoiceActivityIndicator(int &activity);
309#ifdef WEBRTC_VOICE_ENGINE_AGC
pbos@webrtc.org92135212013-05-14 08:31:39 +0000310 int SetRxAgcStatus(bool enable, AgcModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000311 int GetRxAgcStatus(bool& enabled, AgcModes& mode);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000312 int SetRxAgcConfig(AgcConfig config);
niklase@google.com470e71d2011-07-07 08:21:25 +0000313 int GetRxAgcConfig(AgcConfig& config);
314#endif
315#ifdef WEBRTC_VOICE_ENGINE_NR
pbos@webrtc.org92135212013-05-14 08:31:39 +0000316 int SetRxNsStatus(bool enable, NsModes mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000317 int GetRxNsStatus(bool& enabled, NsModes& mode);
318#endif
319
320 // VoERTP_RTCP
niklase@google.com470e71d2011-07-07 08:21:25 +0000321 int SetLocalSSRC(unsigned int ssrc);
322 int GetLocalSSRC(unsigned int& ssrc);
323 int GetRemoteSSRC(unsigned int& ssrc);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000324 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.org93fd25c2014-04-24 20:33:08 +0000325 int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000326 int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id);
327 int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100328 void EnableSendTransportSequenceNumber(int id);
329
330 void SetCongestionControlObjects(
331 RtpPacketSender* rtp_packet_sender,
332 TransportFeedbackObserver* transport_feedback_observer,
333 PacketRouter* packet_router);
334
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000335 void SetRTCPStatus(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000336 int GetRTCPStatus(bool& enabled);
337 int SetRTCP_CNAME(const char cName[256]);
niklase@google.com470e71d2011-07-07 08:21:25 +0000338 int GetRemoteRTCP_CNAME(char cName[256]);
339 int GetRemoteRTCPData(unsigned int& NTPHigh, unsigned int& NTPLow,
340 unsigned int& timestamp,
341 unsigned int& playoutTimestamp, unsigned int* jitter,
342 unsigned short* fractionLost);
pbos@webrtc.org92135212013-05-14 08:31:39 +0000343 int SendApplicationDefinedRTCPPacket(unsigned char subType,
niklase@google.com470e71d2011-07-07 08:21:25 +0000344 unsigned int name, const char* data,
345 unsigned short dataLengthInBytes);
346 int GetRTPStatistics(unsigned int& averageJitterMs,
347 unsigned int& maxJitterMs,
348 unsigned int& discardedPackets);
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +0000349 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000350 int GetRTPStatistics(CallStatistics& stats);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000351 int SetREDStatus(bool enable, int redPayloadtype);
352 int GetREDStatus(bool& enabled, int& redPayloadtype);
353 int SetCodecFECStatus(bool enable);
354 bool GetCodecFECStatus();
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +0000355 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000356
niklase@google.com470e71d2011-07-07 08:21:25 +0000357 // From AudioPacketizationCallback in the ACM
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000358 int32_t SendData(FrameType frameType,
359 uint8_t payloadType,
360 uint32_t timeStamp,
361 const uint8_t* payloadData,
362 size_t payloadSize,
363 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000364
niklase@google.com470e71d2011-07-07 08:21:25 +0000365 // From ACMVADCallback in the ACM
henrik.lundin@webrtc.orge9217b42015-03-06 07:50:34 +0000366 int32_t InFrameType(FrameType frame_type) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000367
pbos@webrtc.org92135212013-05-14 08:31:39 +0000368 int32_t OnRxVadDetected(int vadDecision);
niklase@google.com470e71d2011-07-07 08:21:25 +0000369
niklase@google.com470e71d2011-07-07 08:21:25 +0000370 // From RtpData in the RTP/RTCP module
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000371 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
372 size_t payloadSize,
373 const WebRtcRTPHeader* rtpHeader) override;
374 bool OnRecoveredPacket(const uint8_t* packet,
375 size_t packet_length) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000376
niklase@google.com470e71d2011-07-07 08:21:25 +0000377 // From RtpFeedback in the RTP/RTCP module
Peter Boströmac547a62015-09-17 23:03:57 +0200378 int32_t OnInitializeDecoder(int8_t payloadType,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000379 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
380 int frequency,
381 uint8_t channels,
382 uint32_t rate) override;
Peter Boströmac547a62015-09-17 23:03:57 +0200383 void OnIncomingSSRCChanged(uint32_t ssrc) override;
384 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000385
niklase@google.com470e71d2011-07-07 08:21:25 +0000386 // From RtpAudioFeedback in the RTP/RTCP module
Peter Boströmac547a62015-09-17 23:03:57 +0200387 void OnPlayTelephoneEvent(uint8_t event,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000388 uint16_t lengthMs,
389 uint8_t volume) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000390
niklase@google.com470e71d2011-07-07 08:21:25 +0000391 // From Transport (called by the RTP/RTCP module)
stefan1d8a5062015-10-02 03:39:33 -0700392 bool SendRtp(const uint8_t* data,
393 size_t len,
394 const PacketOptions& packet_options) override;
pbos2d566682015-09-28 09:59:31 -0700395 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000396
niklase@google.com470e71d2011-07-07 08:21:25 +0000397 // From MixerParticipant
minyuel0f4b3732015-08-31 16:04:32 +0200398 int32_t GetAudioFrame(int32_t id, AudioFrame* audioFrame) override;
399 int32_t NeededFrequency(int32_t id) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000400
niklase@google.com470e71d2011-07-07 08:21:25 +0000401 // From FileCallback
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000402 void PlayNotification(int32_t id, uint32_t durationMs) override;
403 void RecordNotification(int32_t id, uint32_t durationMs) override;
404 void PlayFileEnded(int32_t id) override;
405 void RecordFileEnded(int32_t id) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000406
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000407 uint32_t InstanceId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000408 {
409 return _instanceId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000410 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000411 int32_t ChannelId() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000412 {
413 return _channelId;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000414 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000415 bool Playing() const
416 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000417 return channel_state_.Get().playing;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000418 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000419 bool Sending() const
420 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000421 return channel_state_.Get().sending;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000422 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000423 bool Receiving() const
424 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000425 return channel_state_.Get().receiving;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000426 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000427 bool ExternalTransport() const
428 {
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000429 CriticalSectionScoped cs(&_callbackCritSect);
niklase@google.com470e71d2011-07-07 08:21:25 +0000430 return _externalTransport;
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000431 }
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000432 bool ExternalMixing() const
433 {
434 return _externalMixing;
435 }
andrew@webrtc.orgf81f9f82011-08-19 22:56:22 +0000436 RtpRtcp* RtpRtcpModulePtr() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000437 {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000438 return _rtpRtcpModule.get();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000439 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000440 int8_t OutputEnergyLevel() const
niklase@google.com470e71d2011-07-07 08:21:25 +0000441 {
442 return _outputAudioLevel.Level();
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000443 }
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000444 uint32_t Demultiplex(const AudioFrame& audioFrame);
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000445 // Demultiplex the data to the channel's |_audioFrame|. The difference
446 // between this method and the overloaded method above is that |audio_data|
447 // does not go through transmit_mixer and APM.
448 void Demultiplex(const int16_t* audio_data,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000449 int sample_rate,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700450 size_t number_of_frames,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000451 int number_of_channels);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000452 uint32_t PrepareEncodeAndSend(int mixingFrequency);
453 uint32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000454
Minyue2013aec2015-05-13 14:14:42 +0200455 // Associate to a send channel.
456 // Used for obtaining RTT for a receive-only channel.
457 void set_associate_send_channel(const ChannelOwner& channel) {
458 assert(_channelId != channel.channel()->ChannelId());
459 CriticalSectionScoped lock(assoc_send_channel_lock_.get());
460 associate_send_channel_ = channel;
461 }
462
463 // Disassociate a send channel if it was associated.
464 void DisassociateSendChannel(int channel_id);
465
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000466protected:
467 void OnIncomingFractionLoss(int fraction_lost);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000468
niklase@google.com470e71d2011-07-07 08:21:25 +0000469private:
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000470 bool ReceivePacket(const uint8_t* packet, size_t packet_length,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000471 const RTPHeader& header, bool in_order);
minyue@webrtc.org456f0142015-01-23 11:58:42 +0000472 bool HandleRtxPacket(const uint8_t* packet,
473 size_t packet_length,
474 const RTPHeader& header);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000475 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000476 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
andrew@webrtc.orgda710442013-06-07 01:43:12 +0000477 int ResendPackets(const uint16_t* sequence_numbers, int length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000478 int InsertInbandDtmfTone();
pbos@webrtc.org92135212013-05-14 08:31:39 +0000479 int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
480 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
deadbeef74375882015-08-13 12:09:10 -0700481 void UpdatePlayoutTimestamp(bool rtcp);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000482 void UpdatePacketDelay(uint32_t timestamp,
483 uint16_t sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +0000484 void RegisterReceiveCodecsToRTPModule();
niklase@google.com470e71d2011-07-07 08:21:25 +0000485
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000486 int SetRedPayloadType(int red_payload_type);
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000487 int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type,
488 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000489
wu@webrtc.org94454b72014-06-05 20:34:08 +0000490 int32_t GetPlayoutFrequency();
Minyue2013aec2015-05-13 14:14:42 +0200491 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000492
niklase@google.com470e71d2011-07-07 08:21:25 +0000493 CriticalSectionWrapper& _fileCritSect;
494 CriticalSectionWrapper& _callbackCritSect;
wu@webrtc.org63420662013-10-17 18:28:55 +0000495 CriticalSectionWrapper& volume_settings_critsect_;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000496 uint32_t _instanceId;
497 int32_t _channelId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000498
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000499 ChannelState channel_state_;
500
Ivo Creusenae856f22015-09-17 16:30:16 +0200501 RtcEventLog* const event_log_;
502
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000503 rtc::scoped_ptr<RtpHeaderParser> rtp_header_parser_;
504 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
505 rtc::scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
506 rtc::scoped_ptr<StatisticsProxy> statistics_proxy_;
507 rtc::scoped_ptr<RtpReceiver> rtp_receiver_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000508 TelephoneEventHandler* telephone_event_handler_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000509 rtc::scoped_ptr<RtpRtcp> _rtpRtcpModule;
510 rtc::scoped_ptr<AudioCodingModule> audio_coding_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000511 AudioLevel _outputAudioLevel;
512 bool _externalTransport;
513 AudioFrame _audioFrame;
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +0000514 // Downsamples to the codec rate if necessary.
515 PushResampler<int16_t> input_resampler_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000516 FilePlayer* _inputFilePlayerPtr;
517 FilePlayer* _outputFilePlayerPtr;
518 FileRecorder* _outputFileRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000519 int _inputFilePlayerId;
520 int _outputFilePlayerId;
521 int _outputFileRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000522 bool _outputFileRecording;
523 DtmfInbandQueue _inbandDtmfQueue;
524 DtmfInband _inbandDtmfGenerator;
xians@google.com22963ab2011-08-03 12:40:23 +0000525 bool _outputExternalMedia;
niklase@google.com470e71d2011-07-07 08:21:25 +0000526 VoEMediaProcess* _inputExternalMediaCallbackPtr;
527 VoEMediaProcess* _outputExternalMediaCallbackPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000528 uint32_t _timeStamp;
529 uint8_t _sendTelephoneEventPayloadType;
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000530
stefan@webrtc.org8e24d872014-09-02 18:58:24 +0000531 RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000532
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000533 // Timestamp of the audio pulled from NetEq.
534 uint32_t jitter_buffer_playout_timestamp_;
deadbeef74375882015-08-13 12:09:10 -0700535 uint32_t playout_timestamp_rtp_ GUARDED_BY(video_sync_lock_);
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000536 uint32_t playout_timestamp_rtcp_;
deadbeef74375882015-08-13 12:09:10 -0700537 uint32_t playout_delay_ms_ GUARDED_BY(video_sync_lock_);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000538 uint32_t _numberOfDiscardedPackets;
xians@webrtc.org09e8c472013-07-31 16:30:19 +0000539 uint16_t send_sequence_number_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000540 uint8_t restored_packet_[kVoiceEngineMaxIpPacketSizeBytes];
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000541
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000542 rtc::scoped_ptr<CriticalSectionWrapper> ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000543
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000544 rtc::scoped_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000545 // The rtp timestamp of the first played out audio frame.
wu@webrtc.org94454b72014-06-05 20:34:08 +0000546 int64_t capture_start_rtp_time_stamp_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000547 // The capture ntp time (in local timebase) of the first played out audio
548 // frame.
stefan@webrtc.org8e24d872014-09-02 18:58:24 +0000549 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000550
niklase@google.com470e71d2011-07-07 08:21:25 +0000551 // uses
552 Statistics* _engineStatisticsPtr;
553 OutputMixer* _outputMixerPtr;
554 TransmitMixer* _transmitMixerPtr;
555 ProcessThread* _moduleProcessThreadPtr;
556 AudioDeviceModule* _audioDeviceModulePtr;
557 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
558 CriticalSectionWrapper* _callbackCritSectPtr; // owned by base
559 Transport* _transportPtr; // WebRtc socket or external transport
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000560 RMSLevel rms_level_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000561 rtc::scoped_ptr<AudioProcessing> rx_audioproc_; // far end AudioProcessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000562 VoERxVadCallback* _rxVadObserverPtr;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000563 int32_t _oldVadDecision;
564 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000565 // VoEBase
roosa@google.com1b60ceb2012-12-12 23:00:29 +0000566 bool _externalMixing;
niklase@google.com470e71d2011-07-07 08:21:25 +0000567 bool _mixFileWithMicrophone;
niklase@google.com470e71d2011-07-07 08:21:25 +0000568 // VoEVolumeControl
569 bool _mute;
570 float _panLeft;
571 float _panRight;
572 float _outputGain;
niklase@google.com470e71d2011-07-07 08:21:25 +0000573 // VoEDtmf
574 bool _playOutbandDtmfEvent;
575 bool _playInbandDtmfEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000576 // VoeRTP_RTCP
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000577 uint32_t _lastLocalTimeStamp;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000578 int8_t _lastPayloadType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000579 bool _includeAudioLevelIndication;
580 // VoENetwork
niklase@google.com470e71d2011-07-07 08:21:25 +0000581 AudioFrame::SpeechType _outputSpeechType;
582 // VoEVideoSync
deadbeef74375882015-08-13 12:09:10 -0700583 rtc::scoped_ptr<CriticalSectionWrapper> video_sync_lock_;
584 uint32_t _average_jitter_buffer_delay_us GUARDED_BY(video_sync_lock_);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000585 uint32_t _previousTimestamp;
deadbeef74375882015-08-13 12:09:10 -0700586 uint16_t _recPacketDelayMs GUARDED_BY(video_sync_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000587 // VoEAudioProcessing
588 bool _RxVadDetection;
niklase@google.com470e71d2011-07-07 08:21:25 +0000589 bool _rxAgcIsEnabled;
590 bool _rxNsIsEnabled;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000591 bool restored_packet_in_use_;
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000592 // RtcpBandwidthObserver
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000593 rtc::scoped_ptr<VoERtcpObserver> rtcp_observer_;
594 rtc::scoped_ptr<NetworkPredictor> network_predictor_;
Minyue2013aec2015-05-13 14:14:42 +0200595 // An associated send channel.
596 rtc::scoped_ptr<CriticalSectionWrapper> assoc_send_channel_lock_;
597 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100598
599 bool pacing_enabled_;
600 PacketRouter* packet_router_ = nullptr;
601 rtc::scoped_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
602 rtc::scoped_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
603 rtc::scoped_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000604};
605
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000606} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000607} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000608
andrew@webrtc.org382c0c22014-05-05 18:22:21 +0000609#endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_