blob: 7290ce8f09efa8ee57566f62047a78c1bca6cf21 [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
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010011#ifndef AUDIO_CHANNEL_H_
12#define AUDIO_CHANNEL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010014#include <map>
kwibergb7f89d62016-02-17 10:04:18 -080015#include <memory>
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010016#include <string>
17#include <vector>
kwibergb7f89d62016-02-17 10:04:18 -080018
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/audio/audio_mixer.h"
20#include "api/audio_codecs/audio_encoder.h"
21#include "api/call/audio_sink.h"
solenberg946d8862017-09-21 04:02:53 -070022#include "api/call/transport.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "api/optional.h"
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010024#include "audio/audio_level.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020025#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "modules/audio_coding/include/audio_coding_module.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "modules/audio_processing/rms_level.h"
28#include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
29#include "modules/rtp_rtcp/include/rtp_header_parser.h"
30#include "modules/rtp_rtcp/include/rtp_receiver.h"
31#include "modules/rtp_rtcp/include/rtp_rtcp.h"
32#include "rtc_base/criticalsection.h"
33#include "rtc_base/event.h"
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010034#include "rtc_base/task_queue.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "rtc_base/thread_checker.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000036
Niels Möllerf120cba2018-01-30 09:33:03 +010037// TODO(solenberg, nisse): This file contains a few NOLINT marks, to silence
38// warnings about use of unsigned short, and non-const reference arguments.
39// These need cleanup, in a separate cl.
40
wu@webrtc.org94454b72014-06-05 20:34:08 +000041namespace rtc {
wu@webrtc.org94454b72014-06-05 20:34:08 +000042class TimestampWrapAroundHandler;
43}
44
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000045namespace webrtc {
46
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000047class AudioDeviceModule;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010048class PacketRouter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049class ProcessThread;
Erik Språng737336d2016-07-29 12:59:36 +020050class RateLimiter;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000051class ReceiveStatistics;
wu@webrtc.org82c4b852014-05-20 22:55:01 +000052class RemoteNtpTimeEstimator;
ivocb04965c2015-09-09 00:09:43 -070053class RtcEventLog;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000054class RTPPayloadRegistry;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000055class RTPReceiverAudio;
nisse657bab22017-02-21 06:28:10 -080056class RtpPacketReceived;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000057class RtpRtcp;
nisseb8f9a322017-03-27 05:36:15 -070058class RtpTransportControllerSendInterface;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000059class TelephoneEventHandler;
niklase@google.com470e71d2011-07-07 08:21:25 +000060
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +000061struct SenderInfo;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
solenbergdd3abbb2017-09-18 07:05:30 -070063struct CallStatistics {
Niels Möllerf120cba2018-01-30 09:33:03 +010064 unsigned short fractionLost; // NOLINT
solenbergdd3abbb2017-09-18 07:05:30 -070065 unsigned int cumulativeLost;
66 unsigned int extendedMax;
67 unsigned int jitterSamples;
68 int64_t rttMs;
69 size_t bytesSent;
70 int packetsSent;
71 size_t bytesReceived;
72 int packetsReceived;
73 // The capture ntp time (in local timebase) of the first played out audio
74 // frame.
75 int64_t capture_start_ntp_time_ms_;
76};
77
78// See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details.
79struct ReportBlock {
80 uint32_t sender_SSRC; // SSRC of sender
81 uint32_t source_SSRC;
82 uint8_t fraction_lost;
83 uint32_t cumulative_num_packets_lost;
84 uint32_t extended_highest_sequence_number;
85 uint32_t interarrival_jitter;
86 uint32_t last_SR_timestamp;
87 uint32_t delay_since_last_SR;
88};
89
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +000090namespace voe {
91
ivoc14d5dbe2016-07-04 07:06:55 -070092class RtcEventLogProxy;
michaelt9332b7d2016-11-30 07:51:13 -080093class RtcpRttStatsProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010094class RtpPacketSenderProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010095class TransportFeedbackProxy;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010096class TransportSequenceNumberProxy;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +000097class VoERtcpObserver;
niklase@google.com470e71d2011-07-07 08:21:25 +000098
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +000099// Helper class to simplify locking scheme for members that are accessed from
100// multiple threads.
101// Example: a member can be set on thread T1 and read by an internal audio
102// thread T2. Accessing the member via this class ensures that we are
103// safe and also avoid TSan v2 warnings.
104class ChannelState {
105 public:
kwiberg55b97fe2016-01-28 05:22:45 -0800106 struct State {
solenberg11ace152016-09-15 04:29:13 -0700107 bool playing = false;
108 bool sending = false;
kwiberg55b97fe2016-01-28 05:22:45 -0800109 };
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000110
kwiberg55b97fe2016-01-28 05:22:45 -0800111 ChannelState() {}
112 virtual ~ChannelState() {}
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000113
kwiberg55b97fe2016-01-28 05:22:45 -0800114 void Reset() {
115 rtc::CritScope lock(&lock_);
116 state_ = State();
117 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000118
kwiberg55b97fe2016-01-28 05:22:45 -0800119 State Get() const {
120 rtc::CritScope lock(&lock_);
121 return state_;
122 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000123
kwiberg55b97fe2016-01-28 05:22:45 -0800124 void SetPlaying(bool enable) {
125 rtc::CritScope lock(&lock_);
126 state_.playing = enable;
127 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000128
kwiberg55b97fe2016-01-28 05:22:45 -0800129 void SetSending(bool enable) {
130 rtc::CritScope lock(&lock_);
131 state_.sending = enable;
132 }
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000133
kwiberg55b97fe2016-01-28 05:22:45 -0800134 private:
pbosd8de1152016-02-01 09:00:51 -0800135 rtc::CriticalSection lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800136 State state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000137};
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
kwiberg55b97fe2016-01-28 05:22:45 -0800139class Channel
140 : public RtpData,
141 public RtpFeedback,
kwiberg55b97fe2016-01-28 05:22:45 -0800142 public Transport,
kwiberg55b97fe2016-01-28 05:22:45 -0800143 public AudioPacketizationCallback, // receive encoded packets from the
144 // ACM
michaeltbf65be52016-12-15 06:24:49 -0800145 public OverheadObserver {
kwiberg55b97fe2016-01-28 05:22:45 -0800146 public:
147 friend class VoERtcpObserver;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000148
kwiberg55b97fe2016-01-28 05:22:45 -0800149 enum { KNumSocketThreads = 1 };
150 enum { KNumberOfSocketBuffers = 8 };
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100151 // Used for send streams.
152 Channel(rtc::TaskQueue* encoder_queue,
153 ProcessThread* module_process_thread,
154 AudioDeviceModule* audio_device_module);
155 // Used for receive streams.
156 Channel(ProcessThread* module_process_thread,
157 AudioDeviceModule* audio_device_module,
158 size_t jitter_buffer_max_packets,
159 bool jitter_buffer_fast_playout,
160 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory);
kwiberg55b97fe2016-01-28 05:22:45 -0800161 virtual ~Channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000162
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100163 void SetSink(AudioSinkInterface* sink);
ossu29b1a8d2016-06-13 07:34:51 -0700164
kwiberg1c07c702017-03-27 07:15:49 -0700165 void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
166
ossu1ffbd6c2017-04-06 12:05:04 -0700167 // Send using this encoder, with this payload type.
168 bool SetEncoder(int payload_type, std::unique_ptr<AudioEncoder> encoder);
ossu20a4b3f2017-04-27 02:08:52 -0700169 void ModifyEncoder(
170 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier);
ossu1ffbd6c2017-04-06 12:05:04 -0700171
kwiberg55b97fe2016-01-28 05:22:45 -0800172 // API methods
niklase@google.com470e71d2011-07-07 08:21:25 +0000173
kwiberg55b97fe2016-01-28 05:22:45 -0800174 // VoEBase
175 int32_t StartPlayout();
176 int32_t StopPlayout();
177 int32_t StartSend();
henrikaec6fbd22017-03-31 05:43:36 -0700178 void StopSend();
niklase@google.com470e71d2011-07-07 08:21:25 +0000179
solenberg6dc20382017-09-18 05:22:39 -0700180 // Codecs
Niels Möllerf120cba2018-01-30 09:33:03 +0100181 int32_t GetRecCodec(CodecInst& codec); // NOLINT
minyue78b4d562016-11-30 04:47:39 -0800182 void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
minyue7e304322016-10-12 05:00:55 -0700183 bool EnableAudioNetworkAdaptor(const std::string& config_string);
184 void DisableAudioNetworkAdaptor();
185 void SetReceiverFrameLengthRange(int min_frame_length_ms,
186 int max_frame_length_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000187
solenberg946d8862017-09-21 04:02:53 -0700188 // Network
solenberg1c239d42017-09-29 06:00:28 -0700189 void RegisterTransport(Transport* transport);
nisse657bab22017-02-21 06:28:10 -0800190 // TODO(nisse, solenberg): Delete when VoENetwork is deleted.
mflodman3d7db262016-04-29 00:57:13 -0700191 int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
nisse657bab22017-02-21 06:28:10 -0800192 void OnRtpPacket(const RtpPacketReceived& packet);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000193
solenberg8d73f8c2017-03-08 01:52:20 -0800194 // Muting, Volume and Level.
195 void SetInputMute(bool enable);
196 void SetChannelOutputVolumeScaling(float scaling);
solenberg8d73f8c2017-03-08 01:52:20 -0800197 int GetSpeechOutputLevelFullRange() const;
zsteine76bd3a2017-07-14 12:17:49 -0700198 // See description of "totalAudioEnergy" in the WebRTC stats spec:
199 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
200 double GetTotalOutputEnergy() const;
201 double GetTotalOutputDuration() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
solenbergc6192a92017-03-13 02:36:19 -0700203 // Stats.
Niels Möllerf120cba2018-01-30 09:33:03 +0100204 int GetNetworkStatistics(NetworkStatistics& stats); // NOLINT
kwiberg55b97fe2016-01-28 05:22:45 -0800205 void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const;
ivoce1198e02017-09-08 08:13:19 -0700206 ANAStats GetANAStatistics() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
solenbergc6192a92017-03-13 02:36:19 -0700208 // Audio+Video Sync.
kwiberg55b97fe2016-01-28 05:22:45 -0800209 uint32_t GetDelayEstimate() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800210 int SetMinimumPlayoutDelay(int delayMs);
Niels Möllerf120cba2018-01-30 09:33:03 +0100211 int GetPlayoutTimestamp(unsigned int& timestamp); // NOLINT
kwiberg55b97fe2016-01-28 05:22:45 -0800212 int GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000213
solenbergc6192a92017-03-13 02:36:19 -0700214 // DTMF.
solenberg8842c3e2016-03-11 03:06:41 -0800215 int SendTelephoneEventOutband(int event, int duration_ms);
solenbergffbbcac2016-11-17 05:25:37 -0800216 int SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000217
solenbergdd3abbb2017-09-18 07:05:30 -0700218 // RTP+RTCP
kwiberg55b97fe2016-01-28 05:22:45 -0800219 int SetLocalSSRC(unsigned int ssrc);
kwiberg55b97fe2016-01-28 05:22:45 -0800220 int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
kwiberg55b97fe2016-01-28 05:22:45 -0800221 void EnableSendTransportSequenceNumber(int id);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100222
stefan7de8d642017-02-07 07:14:08 -0800223 void RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -0700224 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -0800225 RtcpBandwidthObserver* bandwidth_observer);
226 void RegisterReceiverCongestionControlObjects(PacketRouter* packet_router);
nissefdbfdc92017-03-31 05:44:52 -0700227 void ResetSenderCongestionControlObjects();
228 void ResetReceiverCongestionControlObjects();
kwiberg55b97fe2016-01-28 05:22:45 -0800229 void SetRTCPStatus(bool enable);
kwiberg55b97fe2016-01-28 05:22:45 -0800230 int SetRTCP_CNAME(const char cName[256]);
kwiberg55b97fe2016-01-28 05:22:45 -0800231 int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
Niels Möllerf120cba2018-01-30 09:33:03 +0100232 int GetRTPStatistics(CallStatistics& stats); // NOLINT
kwiberg55b97fe2016-01-28 05:22:45 -0800233 void SetNACKStatus(bool enable, int maxNumberOfPackets);
niklase@google.com470e71d2011-07-07 08:21:25 +0000234
kwiberg55b97fe2016-01-28 05:22:45 -0800235 // From AudioPacketizationCallback in the ACM
236 int32_t SendData(FrameType frameType,
237 uint8_t payloadType,
238 uint32_t timeStamp,
239 const uint8_t* payloadData,
240 size_t payloadSize,
241 const RTPFragmentationHeader* fragmentation) override;
xians@webrtc.org3cefbc92014-10-10 09:42:53 +0000242
kwiberg55b97fe2016-01-28 05:22:45 -0800243 // From RtpData in the RTP/RTCP module
244 int32_t OnReceivedPayloadData(const uint8_t* payloadData,
245 size_t payloadSize,
246 const WebRtcRTPHeader* rtpHeader) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000247
kwiberg55b97fe2016-01-28 05:22:45 -0800248 // From RtpFeedback in the RTP/RTCP module
Karl Wibergc62f6c72017-10-04 12:38:53 +0200249 int32_t OnInitializeDecoder(int payload_type,
250 const SdpAudioFormat& audio_format,
kwiberg55b97fe2016-01-28 05:22:45 -0800251 uint32_t rate) override;
252 void OnIncomingSSRCChanged(uint32_t ssrc) override;
253 void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000254
kwiberg55b97fe2016-01-28 05:22:45 -0800255 // From Transport (called by the RTP/RTCP module)
256 bool SendRtp(const uint8_t* data,
257 size_t len,
258 const PacketOptions& packet_options) override;
259 bool SendRtcp(const uint8_t* data, size_t len) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000260
aleloiaed581a2016-10-20 06:32:39 -0700261 // From AudioMixer::Source.
aleloi6c278492016-10-20 14:24:39 -0700262 AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
263 int sample_rate_hz,
264 AudioFrame* audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700265
solenberg2397b9a2017-09-22 06:48:10 -0700266 int PreferredSampleRate() const;
267
kwiberg55b97fe2016-01-28 05:22:45 -0800268 bool Playing() const { return channel_state_.Get().playing; }
269 bool Sending() const { return channel_state_.Get().sending; }
kwiberg55b97fe2016-01-28 05:22:45 -0800270 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
henrikaec6fbd22017-03-31 05:43:36 -0700271
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100272 // ProcessAndEncodeAudio() posts a task on the shared encoder task queue,
273 // which in turn calls (on the queue) ProcessAndEncodeAudioOnTaskQueue() where
274 // the actual processing of the audio takes place. The processing mainly
275 // consists of encoding and preparing the result for sending by adding it to a
276 // send queue.
henrikaec6fbd22017-03-31 05:43:36 -0700277 // The main reason for using a task queue here is to release the native,
278 // OS-specific, audio capture thread as soon as possible to ensure that it
279 // can go back to sleep and be prepared to deliver an new captured audio
280 // packet.
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100281 void ProcessAndEncodeAudio(std::unique_ptr<AudioFrame> audio_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +0000282
kwiberg55b97fe2016-01-28 05:22:45 -0800283 // Associate to a send channel.
284 // Used for obtaining RTT for a receive-only channel.
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100285 void SetAssociatedSendChannel(Channel* channel);
Minyue2013aec2015-05-13 14:14:42 +0200286
ivoc14d5dbe2016-07-04 07:06:55 -0700287 // Set a RtcEventLog logging object.
288 void SetRtcEventLog(RtcEventLog* event_log);
289
michaelt9332b7d2016-11-30 07:51:13 -0800290 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
nisse284542b2017-01-10 08:58:32 -0800291 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800292
michaeltbf65be52016-12-15 06:24:49 -0800293 // From OverheadObserver in the RTP/RTCP module
294 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
295
elad.alond12a8e12017-03-23 11:04:48 -0700296 // The existence of this function alongside OnUplinkPacketLossRate is
297 // a compromise. We want the encoder to be agnostic of the PLR source, but
298 // we also don't want it to receive conflicting information from TWCC and
299 // from RTCP-XR.
300 void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000301
elad.alondadb4dc2017-03-23 15:29:50 -0700302 void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate);
303
hbos8d609f62017-04-10 07:39:05 -0700304 std::vector<RtpSource> GetSources() const {
305 return rtp_receiver_->GetSources();
306 }
307
kwiberg55b97fe2016-01-28 05:22:45 -0800308 private:
henrikaec6fbd22017-03-31 05:43:36 -0700309 class ProcessAndEncodeAudioTask;
elad.alond12a8e12017-03-23 11:04:48 -0700310
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100311 void Init();
312 void Terminate();
313
Niels Möllerf120cba2018-01-30 09:33:03 +0100314 int GetRemoteSSRC(unsigned int& ssrc); // NOLINT
henrikaec6fbd22017-03-31 05:43:36 -0700315 void OnUplinkPacketLossRate(float packet_loss_rate);
solenberg8d73f8c2017-03-08 01:52:20 -0800316 bool InputMute() const;
nisse30e89312017-05-29 08:16:37 -0700317
kwiberg55b97fe2016-01-28 05:22:45 -0800318 bool ReceivePacket(const uint8_t* packet,
319 size_t packet_length,
Niels Möller22ec9522017-10-05 08:39:15 +0200320 const RTPHeader& header);
kwiberg55b97fe2016-01-28 05:22:45 -0800321 bool IsPacketInOrder(const RTPHeader& header) const;
322 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
323 int ResendPackets(const uint16_t* sequence_numbers, int length);
kwiberg55b97fe2016-01-28 05:22:45 -0800324 void UpdatePlayoutTimestamp(bool rtcp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000325
kwiberg55b97fe2016-01-28 05:22:45 -0800326 int SetSendRtpHeaderExtension(bool enable,
327 RTPExtensionType type,
328 unsigned char id);
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +0000329
hbos3fd31fe2017-02-28 05:43:16 -0800330 void UpdateOverheadForEncoder()
danilchapa37de392017-09-09 04:17:22 -0700331 RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
nisse284542b2017-01-10 08:58:32 -0800332
ossue280cde2016-10-12 11:04:10 -0700333 int GetRtpTimestampRateHz() const;
kwiberg55b97fe2016-01-28 05:22:45 -0800334 int64_t GetRTT(bool allow_associate_channel) const;
wu@webrtc.org94454b72014-06-05 20:34:08 +0000335
henrikaec6fbd22017-03-31 05:43:36 -0700336 // Called on the encoder task queue when a new input audio frame is ready
337 // for encoding.
338 void ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input);
339
pbosd8de1152016-02-01 09:00:51 -0800340 rtc::CriticalSection _callbackCritSect;
341 rtc::CriticalSection volume_settings_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000342
kwiberg55b97fe2016-01-28 05:22:45 -0800343 ChannelState channel_state_;
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000344
ivoc14d5dbe2016-07-04 07:06:55 -0700345 std::unique_ptr<voe::RtcEventLogProxy> event_log_proxy_;
michaelt9332b7d2016-11-30 07:51:13 -0800346 std::unique_ptr<voe::RtcpRttStatsProxy> rtcp_rtt_stats_proxy_;
Ivo Creusenae856f22015-09-17 16:30:16 +0200347
kwibergb7f89d62016-02-17 10:04:18 -0800348 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
349 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
kwibergb7f89d62016-02-17 10:04:18 -0800350 std::unique_ptr<RtpReceiver> rtp_receiver_;
danilchap799a9d02016-09-22 03:36:27 -0700351 TelephoneEventHandler* telephone_event_handler_;
kwibergb7f89d62016-02-17 10:04:18 -0800352 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
353 std::unique_ptr<AudioCodingModule> audio_coding_;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100354 AudioSinkInterface* audio_sink_ = nullptr;
kwiberg55b97fe2016-01-28 05:22:45 -0800355 AudioLevel _outputAudioLevel;
danilchapa37de392017-09-09 04:17:22 -0700356 uint32_t _timeStamp RTC_ACCESS_ON(encoder_queue_);
turaj@webrtc.org167b6df2013-12-13 21:05:07 +0000357
danilchapa37de392017-09-09 04:17:22 -0700358 RemoteNtpTimeEstimator ntp_estimator_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.org82c4b852014-05-20 22:55:01 +0000359
kwiberg55b97fe2016-01-28 05:22:45 -0800360 // Timestamp of the audio pulled from NetEq.
henrik.lundin96bd5022016-04-06 04:13:56 -0700361 rtc::Optional<uint32_t> jitter_buffer_playout_timestamp_;
solenbergfe7dd6d2017-03-11 08:10:43 -0800362
363 rtc::CriticalSection video_sync_lock_;
danilchapa37de392017-09-09 04:17:22 -0700364 uint32_t playout_timestamp_rtp_ RTC_GUARDED_BY(video_sync_lock_);
365 uint32_t playout_delay_ms_ RTC_GUARDED_BY(video_sync_lock_);
kwiberg55b97fe2016-01-28 05:22:45 -0800366 uint16_t send_sequence_number_;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000367
pbosd8de1152016-02-01 09:00:51 -0800368 rtc::CriticalSection ts_stats_lock_;
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000369
kwibergb7f89d62016-02-17 10:04:18 -0800370 std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
kwiberg55b97fe2016-01-28 05:22:45 -0800371 // The rtp timestamp of the first played out audio frame.
372 int64_t capture_start_rtp_time_stamp_;
373 // The capture ntp time (in local timebase) of the first played out audio
374 // frame.
danilchapa37de392017-09-09 04:17:22 -0700375 int64_t capture_start_ntp_time_ms_ RTC_GUARDED_BY(ts_stats_lock_);
wu@webrtc.orgcb711f72014-05-19 17:39:11 +0000376
kwiberg55b97fe2016-01-28 05:22:45 -0800377 // uses
kwiberg55b97fe2016-01-28 05:22:45 -0800378 ProcessThread* _moduleProcessThreadPtr;
379 AudioDeviceModule* _audioDeviceModulePtr;
kwiberg55b97fe2016-01-28 05:22:45 -0800380 Transport* _transportPtr; // WebRtc socket or external transport
danilchapa37de392017-09-09 04:17:22 -0700381 RmsLevel rms_level_ RTC_ACCESS_ON(encoder_queue_);
382 bool input_mute_ RTC_GUARDED_BY(volume_settings_critsect_);
383 bool previous_frame_muted_ RTC_ACCESS_ON(encoder_queue_);
384 float _outputGain RTC_GUARDED_BY(volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -0800385 // VoeRTP_RTCP
henrikaec6fbd22017-03-31 05:43:36 -0700386 // TODO(henrika): can today be accessed on the main thread and on the
387 // task queue; hence potential race.
kwiberg55b97fe2016-01-28 05:22:45 -0800388 bool _includeAudioLevelIndication;
danilchapa37de392017-09-09 04:17:22 -0700389 size_t transport_overhead_per_packet_
390 RTC_GUARDED_BY(overhead_per_packet_lock_);
391 size_t rtp_overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_);
hbos3fd31fe2017-02-28 05:43:16 -0800392 rtc::CriticalSection overhead_per_packet_lock_;
kwiberg55b97fe2016-01-28 05:22:45 -0800393 // RtcpBandwidthObserver
kwibergb7f89d62016-02-17 10:04:18 -0800394 std::unique_ptr<VoERtcpObserver> rtcp_observer_;
kwiberg55b97fe2016-01-28 05:22:45 -0800395 // An associated send channel.
pbosd8de1152016-02-01 09:00:51 -0800396 rtc::CriticalSection assoc_send_channel_lock_;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100397 Channel* associated_send_channel_ RTC_GUARDED_BY(assoc_send_channel_lock_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100398
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100399 bool pacing_enabled_ = true;
kwiberg55b97fe2016-01-28 05:22:45 -0800400 PacketRouter* packet_router_ = nullptr;
kwibergb7f89d62016-02-17 10:04:18 -0800401 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
402 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
403 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
Erik Språng737336d2016-07-29 12:59:36 +0200404 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
ossu29b1a8d2016-06-13 07:34:51 -0700405
tommi0a2391f2017-03-21 02:31:51 -0700406 rtc::ThreadChecker construction_thread_;
elad.alond12a8e12017-03-23 11:04:48 -0700407
408 const bool use_twcc_plr_for_ana_;
henrikaec6fbd22017-03-31 05:43:36 -0700409
henrika4515fa02017-05-03 08:30:15 -0700410 rtc::CriticalSection encoder_queue_lock_;
danilchapa37de392017-09-09 04:17:22 -0700411 bool encoder_queue_is_active_ RTC_GUARDED_BY(encoder_queue_lock_) = false;
henrikaec6fbd22017-03-31 05:43:36 -0700412 rtc::TaskQueue* encoder_queue_ = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000413};
414
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000415} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000416} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000417
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +0100418#endif // AUDIO_CHANNEL_H_