blob: c3c06a0b322698bd4849ecd36278e1e7d7dbcac7 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
henrika@webrtc.org2919e952012-01-31 08:45:03 +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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "voice_engine/channel.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
Henrik Lundin64dad832015-05-11 12:44:23 +020013#include <algorithm>
Bjorn Terelius440216f2017-09-29 21:01:42 +020014#include <map>
15#include <string>
Tommif888bb52015-12-12 01:37:01 +010016#include <utility>
Bjorn Terelius440216f2017-09-29 21:01:42 +020017#include <vector>
Henrik Lundin64dad832015-05-11 12:44:23 +020018
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/array_view.h"
20#include "audio/utility/audio_frame_operations.h"
21#include "call/rtp_transport_controller_send_interface.h"
22#include "logging/rtc_event_log/rtc_event_log.h"
Elad Alon4a87e1c2017-10-03 16:11:34 +020023// TODO(eladalon): Remove events/* after removing the deprecated functions.
24#include "logging/rtc_event_log/events/rtc_event_audio_network_adaptation.h"
25#include "logging/rtc_event_log/events/rtc_event_audio_playout.h"
26#include "logging/rtc_event_log/events/rtc_event_audio_receive_stream_config.h"
27#include "logging/rtc_event_log/events/rtc_event_audio_send_stream_config.h"
28#include "logging/rtc_event_log/events/rtc_event_bwe_update_delay_based.h"
29#include "logging/rtc_event_log/events/rtc_event_bwe_update_loss_based.h"
30#include "logging/rtc_event_log/events/rtc_event_logging_started.h"
31#include "logging/rtc_event_log/events/rtc_event_logging_stopped.h"
32#include "logging/rtc_event_log/events/rtc_event_probe_cluster_created.h"
33#include "logging/rtc_event_log/events/rtc_event_probe_result_failure.h"
34#include "logging/rtc_event_log/events/rtc_event_probe_result_success.h"
35#include "logging/rtc_event_log/events/rtc_event_rtcp_packet_incoming.h"
36#include "logging/rtc_event_log/events/rtc_event_rtcp_packet_outgoing.h"
37#include "logging/rtc_event_log/events/rtc_event_rtp_packet_incoming.h"
38#include "logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.h"
39#include "logging/rtc_event_log/events/rtc_event_video_receive_stream_config.h"
40#include "logging/rtc_event_log/events/rtc_event_video_send_stream_config.h"
41#include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020042#include "modules/audio_coding/codecs/audio_format_conversion.h"
43#include "modules/audio_device/include/audio_device.h"
44#include "modules/audio_processing/include/audio_processing.h"
45#include "modules/include/module_common_types.h"
46#include "modules/pacing/packet_router.h"
47#include "modules/rtp_rtcp/include/receive_statistics.h"
48#include "modules/rtp_rtcp/include/rtp_payload_registry.h"
49#include "modules/rtp_rtcp/include/rtp_receiver.h"
50#include "modules/rtp_rtcp/source/rtp_packet_received.h"
51#include "modules/rtp_rtcp/source/rtp_receiver_strategy.h"
52#include "modules/utility/include/process_thread.h"
53#include "rtc_base/checks.h"
54#include "rtc_base/criticalsection.h"
55#include "rtc_base/format_macros.h"
56#include "rtc_base/location.h"
57#include "rtc_base/logging.h"
Elad Alon4a87e1c2017-10-03 16:11:34 +020058#include "rtc_base/ptr_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020059#include "rtc_base/rate_limiter.h"
60#include "rtc_base/task_queue.h"
61#include "rtc_base/thread_checker.h"
62#include "rtc_base/timeutils.h"
63#include "system_wrappers/include/field_trial.h"
henrika45802172017-09-28 09:39:34 +020064#include "system_wrappers/include/metrics.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020065#include "voice_engine/utility.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000066
andrew@webrtc.org50419b02012-11-14 19:07:54 +000067namespace webrtc {
68namespace voe {
niklase@google.com470e71d2011-07-07 08:21:25 +000069
kwibergc8d071e2016-04-06 12:22:38 -070070namespace {
71
zsteine76bd3a2017-07-14 12:17:49 -070072constexpr double kAudioSampleDurationSeconds = 0.01;
Erik Språng737336d2016-07-29 12:59:36 +020073constexpr int64_t kMaxRetransmissionWindowMs = 1000;
74constexpr int64_t kMinRetransmissionWindowMs = 30;
75
kwibergc8d071e2016-04-06 12:22:38 -070076} // namespace
77
solenberg8842c3e2016-03-11 03:06:41 -080078const int kTelephoneEventAttenuationdB = 10;
79
ivoc14d5dbe2016-07-04 07:06:55 -070080class RtcEventLogProxy final : public webrtc::RtcEventLog {
81 public:
82 RtcEventLogProxy() : event_log_(nullptr) {}
83
Elad Alon83ccca12017-10-04 13:18:26 +020084 bool StartLogging(std::unique_ptr<RtcEventLogOutput> output) override {
85 RTC_NOTREACHED();
86 return false;
87 }
88
ivoc14d5dbe2016-07-04 07:06:55 -070089 bool StartLogging(const std::string& file_name,
90 int64_t max_size_bytes) override {
91 RTC_NOTREACHED();
92 return false;
93 }
94
95 bool StartLogging(rtc::PlatformFile log_file,
96 int64_t max_size_bytes) override {
97 RTC_NOTREACHED();
98 return false;
99 }
100
101 void StopLogging() override { RTC_NOTREACHED(); }
102
Elad Alon4a87e1c2017-10-03 16:11:34 +0200103 void Log(std::unique_ptr<RtcEvent> event) override {
104 rtc::CritScope lock(&crit_);
105 if (event_log_) {
106 event_log_->Log(std::move(event));
107 }
108 }
109
ivoc14d5dbe2016-07-04 07:06:55 -0700110 void LogVideoReceiveStreamConfig(
perkj09e71da2017-05-22 03:26:49 -0700111 const webrtc::rtclog::StreamConfig&) override {
112 RTC_NOTREACHED();
ivoc14d5dbe2016-07-04 07:06:55 -0700113 }
114
perkjc0876aa2017-05-22 04:08:28 -0700115 void LogVideoSendStreamConfig(const webrtc::rtclog::StreamConfig&) override {
116 RTC_NOTREACHED();
ivoc14d5dbe2016-07-04 07:06:55 -0700117 }
118
ivoce0928d82016-10-10 05:12:51 -0700119 void LogAudioReceiveStreamConfig(
perkjac8f52d2017-05-22 09:36:28 -0700120 const webrtc::rtclog::StreamConfig& config) override {
ivoce0928d82016-10-10 05:12:51 -0700121 rtc::CritScope lock(&crit_);
122 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200123 event_log_->Log(rtc::MakeUnique<RtcEventAudioReceiveStreamConfig>(
124 rtc::MakeUnique<webrtc::rtclog::StreamConfig>(config)));
ivoce0928d82016-10-10 05:12:51 -0700125 }
126 }
127
128 void LogAudioSendStreamConfig(
perkjf4726992017-05-22 10:12:26 -0700129 const webrtc::rtclog::StreamConfig& config) override {
ivoce0928d82016-10-10 05:12:51 -0700130 rtc::CritScope lock(&crit_);
131 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200132 event_log_->Log(rtc::MakeUnique<RtcEventAudioSendStreamConfig>(
133 rtc::MakeUnique<webrtc::rtclog::StreamConfig>(config)));
ivoce0928d82016-10-10 05:12:51 -0700134 }
135 }
136
Bjorn Terelius440216f2017-09-29 21:01:42 +0200137 void LogIncomingRtpHeader(const RtpPacketReceived& packet) override {
ivoc14d5dbe2016-07-04 07:06:55 -0700138 rtc::CritScope lock(&crit_);
139 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200140 event_log_->Log(rtc::MakeUnique<RtcEventRtpPacketIncoming>(packet));
ivoc14d5dbe2016-07-04 07:06:55 -0700141 }
142 }
143
Bjorn Terelius440216f2017-09-29 21:01:42 +0200144 void LogOutgoingRtpHeader(const RtpPacketToSend& packet,
145 int probe_cluster_id) override {
ivoc14d5dbe2016-07-04 07:06:55 -0700146 rtc::CritScope lock(&crit_);
147 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200148 event_log_->Log(
149 rtc::MakeUnique<RtcEventRtpPacketOutgoing>(packet, probe_cluster_id));
Bjorn Terelius440216f2017-09-29 21:01:42 +0200150 }
151 }
152
153 void LogIncomingRtcpPacket(rtc::ArrayView<const uint8_t> packet) override {
154 rtc::CritScope lock(&crit_);
155 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200156 event_log_->Log(rtc::MakeUnique<RtcEventRtcpPacketIncoming>(packet));
Bjorn Terelius440216f2017-09-29 21:01:42 +0200157 }
158 }
159
160 void LogOutgoingRtcpPacket(rtc::ArrayView<const uint8_t> packet) override {
161 rtc::CritScope lock(&crit_);
162 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200163 event_log_->Log(rtc::MakeUnique<RtcEventRtcpPacketOutgoing>(packet));
ivoc14d5dbe2016-07-04 07:06:55 -0700164 }
165 }
166
167 void LogAudioPlayout(uint32_t ssrc) override {
168 rtc::CritScope lock(&crit_);
169 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200170 event_log_->Log(rtc::MakeUnique<RtcEventAudioPlayout>(ssrc));
ivoc14d5dbe2016-07-04 07:06:55 -0700171 }
172 }
173
terelius424e6cf2017-02-20 05:14:41 -0800174 void LogLossBasedBweUpdate(int32_t bitrate_bps,
ivoc14d5dbe2016-07-04 07:06:55 -0700175 uint8_t fraction_loss,
176 int32_t total_packets) override {
177 rtc::CritScope lock(&crit_);
178 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200179 event_log_->Log(rtc::MakeUnique<RtcEventBweUpdateLossBased>(
180 bitrate_bps, fraction_loss, total_packets));
ivoc14d5dbe2016-07-04 07:06:55 -0700181 }
182 }
183
terelius424e6cf2017-02-20 05:14:41 -0800184 void LogDelayBasedBweUpdate(int32_t bitrate_bps,
terelius0baf55d2017-02-17 03:38:28 -0800185 BandwidthUsage detector_state) override {
186 rtc::CritScope lock(&crit_);
187 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200188 event_log_->Log(rtc::MakeUnique<RtcEventBweUpdateDelayBased>(
189 bitrate_bps, detector_state));
terelius0baf55d2017-02-17 03:38:28 -0800190 }
191 }
192
minyue4b7c9522017-01-24 04:54:59 -0800193 void LogAudioNetworkAdaptation(
michaeltcde46b72017-04-06 05:59:10 -0700194 const AudioEncoderRuntimeConfig& config) override {
minyue4b7c9522017-01-24 04:54:59 -0800195 rtc::CritScope lock(&crit_);
196 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200197 event_log_->Log(rtc::MakeUnique<RtcEventAudioNetworkAdaptation>(
198 rtc::MakeUnique<AudioEncoderRuntimeConfig>(config)));
minyue4b7c9522017-01-24 04:54:59 -0800199 }
200 }
201
philipel32d00102017-02-27 02:18:46 -0800202 void LogProbeClusterCreated(int id,
203 int bitrate_bps,
204 int min_probes,
205 int min_bytes) override {
206 rtc::CritScope lock(&crit_);
207 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200208 event_log_->Log(rtc::MakeUnique<RtcEventProbeClusterCreated>(
209 id, bitrate_bps, min_probes, min_bytes));
philipel32d00102017-02-27 02:18:46 -0800210 }
211 };
212
213 void LogProbeResultSuccess(int id, int bitrate_bps) override {
214 rtc::CritScope lock(&crit_);
215 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200216 event_log_->Log(
217 rtc::MakeUnique<RtcEventProbeResultSuccess>(id, bitrate_bps));
philipel32d00102017-02-27 02:18:46 -0800218 }
219 };
220
221 void LogProbeResultFailure(int id,
222 ProbeFailureReason failure_reason) override {
223 rtc::CritScope lock(&crit_);
224 if (event_log_) {
Elad Alon4a87e1c2017-10-03 16:11:34 +0200225 event_log_->Log(
226 rtc::MakeUnique<RtcEventProbeResultFailure>(id, failure_reason));
philipel32d00102017-02-27 02:18:46 -0800227 }
228 };
229
ivoc14d5dbe2016-07-04 07:06:55 -0700230 void SetEventLog(RtcEventLog* event_log) {
231 rtc::CritScope lock(&crit_);
232 event_log_ = event_log;
233 }
234
235 private:
236 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -0700237 RtcEventLog* event_log_ RTC_GUARDED_BY(crit_);
ivoc14d5dbe2016-07-04 07:06:55 -0700238 RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogProxy);
239};
240
michaelt9332b7d2016-11-30 07:51:13 -0800241class RtcpRttStatsProxy final : public RtcpRttStats {
242 public:
243 RtcpRttStatsProxy() : rtcp_rtt_stats_(nullptr) {}
244
245 void OnRttUpdate(int64_t rtt) override {
246 rtc::CritScope lock(&crit_);
247 if (rtcp_rtt_stats_)
248 rtcp_rtt_stats_->OnRttUpdate(rtt);
249 }
250
251 int64_t LastProcessedRtt() const override {
252 rtc::CritScope lock(&crit_);
253 if (!rtcp_rtt_stats_)
254 return 0;
255 return rtcp_rtt_stats_->LastProcessedRtt();
256 }
257
258 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats) {
259 rtc::CritScope lock(&crit_);
260 rtcp_rtt_stats_ = rtcp_rtt_stats;
261 }
262
263 private:
264 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -0700265 RtcpRttStats* rtcp_rtt_stats_ RTC_GUARDED_BY(crit_);
michaelt9332b7d2016-11-30 07:51:13 -0800266 RTC_DISALLOW_COPY_AND_ASSIGN(RtcpRttStatsProxy);
267};
268
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100269class TransportFeedbackProxy : public TransportFeedbackObserver {
270 public:
271 TransportFeedbackProxy() : feedback_observer_(nullptr) {
272 pacer_thread_.DetachFromThread();
273 network_thread_.DetachFromThread();
274 }
275
276 void SetTransportFeedbackObserver(
277 TransportFeedbackObserver* feedback_observer) {
278 RTC_DCHECK(thread_checker_.CalledOnValidThread());
279 rtc::CritScope lock(&crit_);
280 feedback_observer_ = feedback_observer;
281 }
282
283 // Implements TransportFeedbackObserver.
elad.alond12a8e12017-03-23 11:04:48 -0700284 void AddPacket(uint32_t ssrc,
285 uint16_t sequence_number,
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100286 size_t length,
philipel8aadd502017-02-23 02:56:13 -0800287 const PacedPacketInfo& pacing_info) override {
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100288 RTC_DCHECK(pacer_thread_.CalledOnValidThread());
289 rtc::CritScope lock(&crit_);
290 if (feedback_observer_)
elad.alond12a8e12017-03-23 11:04:48 -0700291 feedback_observer_->AddPacket(ssrc, sequence_number, length, pacing_info);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100292 }
philipel8aadd502017-02-23 02:56:13 -0800293
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100294 void OnTransportFeedback(const rtcp::TransportFeedback& feedback) override {
295 RTC_DCHECK(network_thread_.CalledOnValidThread());
296 rtc::CritScope lock(&crit_);
michaelt9960bb12016-10-18 09:40:34 -0700297 if (feedback_observer_)
298 feedback_observer_->OnTransportFeedback(feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +0200299 }
elad.alonf9490002017-03-06 05:32:21 -0800300 std::vector<PacketFeedback> GetTransportFeedbackVector() const override {
Stefan Holmer60e43462016-09-07 09:58:20 +0200301 RTC_NOTREACHED();
elad.alonf9490002017-03-06 05:32:21 -0800302 return std::vector<PacketFeedback>();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100303 }
304
305 private:
306 rtc::CriticalSection crit_;
307 rtc::ThreadChecker thread_checker_;
308 rtc::ThreadChecker pacer_thread_;
309 rtc::ThreadChecker network_thread_;
danilchapa37de392017-09-09 04:17:22 -0700310 TransportFeedbackObserver* feedback_observer_ RTC_GUARDED_BY(&crit_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100311};
312
313class TransportSequenceNumberProxy : public TransportSequenceNumberAllocator {
314 public:
315 TransportSequenceNumberProxy() : seq_num_allocator_(nullptr) {
316 pacer_thread_.DetachFromThread();
317 }
318
319 void SetSequenceNumberAllocator(
320 TransportSequenceNumberAllocator* seq_num_allocator) {
321 RTC_DCHECK(thread_checker_.CalledOnValidThread());
322 rtc::CritScope lock(&crit_);
323 seq_num_allocator_ = seq_num_allocator;
324 }
325
326 // Implements TransportSequenceNumberAllocator.
327 uint16_t AllocateSequenceNumber() override {
328 RTC_DCHECK(pacer_thread_.CalledOnValidThread());
329 rtc::CritScope lock(&crit_);
330 if (!seq_num_allocator_)
331 return 0;
332 return seq_num_allocator_->AllocateSequenceNumber();
333 }
334
335 private:
336 rtc::CriticalSection crit_;
337 rtc::ThreadChecker thread_checker_;
338 rtc::ThreadChecker pacer_thread_;
danilchapa37de392017-09-09 04:17:22 -0700339 TransportSequenceNumberAllocator* seq_num_allocator_ RTC_GUARDED_BY(&crit_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100340};
341
342class RtpPacketSenderProxy : public RtpPacketSender {
343 public:
kwiberg55b97fe2016-01-28 05:22:45 -0800344 RtpPacketSenderProxy() : rtp_packet_sender_(nullptr) {}
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100345
346 void SetPacketSender(RtpPacketSender* rtp_packet_sender) {
347 RTC_DCHECK(thread_checker_.CalledOnValidThread());
348 rtc::CritScope lock(&crit_);
349 rtp_packet_sender_ = rtp_packet_sender;
350 }
351
352 // Implements RtpPacketSender.
353 void InsertPacket(Priority priority,
354 uint32_t ssrc,
355 uint16_t sequence_number,
356 int64_t capture_time_ms,
357 size_t bytes,
358 bool retransmission) override {
359 rtc::CritScope lock(&crit_);
360 if (rtp_packet_sender_) {
361 rtp_packet_sender_->InsertPacket(priority, ssrc, sequence_number,
362 capture_time_ms, bytes, retransmission);
363 }
364 }
365
366 private:
367 rtc::ThreadChecker thread_checker_;
368 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -0700369 RtpPacketSender* rtp_packet_sender_ RTC_GUARDED_BY(&crit_);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100370};
371
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000372class VoERtcpObserver : public RtcpBandwidthObserver {
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000373 public:
stefan7de8d642017-02-07 07:14:08 -0800374 explicit VoERtcpObserver(Channel* owner)
375 : owner_(owner), bandwidth_observer_(nullptr) {}
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000376 virtual ~VoERtcpObserver() {}
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000377
stefan7de8d642017-02-07 07:14:08 -0800378 void SetBandwidthObserver(RtcpBandwidthObserver* bandwidth_observer) {
379 rtc::CritScope lock(&crit_);
380 bandwidth_observer_ = bandwidth_observer;
381 }
382
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000383 void OnReceivedEstimatedBitrate(uint32_t bitrate) override {
stefan7de8d642017-02-07 07:14:08 -0800384 rtc::CritScope lock(&crit_);
385 if (bandwidth_observer_) {
386 bandwidth_observer_->OnReceivedEstimatedBitrate(bitrate);
387 }
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000388 }
389
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000390 void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks,
391 int64_t rtt,
392 int64_t now_ms) override {
stefan7de8d642017-02-07 07:14:08 -0800393 {
394 rtc::CritScope lock(&crit_);
395 if (bandwidth_observer_) {
396 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, rtt,
397 now_ms);
398 }
399 }
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000400 // TODO(mflodman): Do we need to aggregate reports here or can we jut send
401 // what we get? I.e. do we ever get multiple reports bundled into one RTCP
402 // report for VoiceEngine?
403 if (report_blocks.empty())
404 return;
405
406 int fraction_lost_aggregate = 0;
407 int total_number_of_packets = 0;
408
409 // If receiving multiple report blocks, calculate the weighted average based
410 // on the number of packets a report refers to.
411 for (ReportBlockList::const_iterator block_it = report_blocks.begin();
412 block_it != report_blocks.end(); ++block_it) {
413 // Find the previous extended high sequence number for this remote SSRC,
414 // to calculate the number of RTP packets this report refers to. Ignore if
415 // we haven't seen this SSRC before.
416 std::map<uint32_t, uint32_t>::iterator seq_num_it =
srte3e69e5c2017-08-09 06:13:45 -0700417 extended_max_sequence_number_.find(block_it->source_ssrc);
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000418 int number_of_packets = 0;
419 if (seq_num_it != extended_max_sequence_number_.end()) {
srte3e69e5c2017-08-09 06:13:45 -0700420 number_of_packets =
421 block_it->extended_highest_sequence_number - seq_num_it->second;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000422 }
srte3e69e5c2017-08-09 06:13:45 -0700423 fraction_lost_aggregate += number_of_packets * block_it->fraction_lost;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000424 total_number_of_packets += number_of_packets;
425
srte3e69e5c2017-08-09 06:13:45 -0700426 extended_max_sequence_number_[block_it->source_ssrc] =
427 block_it->extended_highest_sequence_number;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000428 }
429 int weighted_fraction_lost = 0;
430 if (total_number_of_packets > 0) {
kwiberg55b97fe2016-01-28 05:22:45 -0800431 weighted_fraction_lost =
432 (fraction_lost_aggregate + total_number_of_packets / 2) /
433 total_number_of_packets;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000434 }
elad.alond12a8e12017-03-23 11:04:48 -0700435 owner_->OnUplinkPacketLossRate(weighted_fraction_lost / 255.0f);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000436 }
437
438 private:
439 Channel* owner_;
mflodman@webrtc.org0a7d4ee2015-02-17 12:57:14 +0000440 // Maps remote side ssrc to extended highest sequence number received.
441 std::map<uint32_t, uint32_t> extended_max_sequence_number_;
stefan7de8d642017-02-07 07:14:08 -0800442 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -0700443 RtcpBandwidthObserver* bandwidth_observer_ RTC_GUARDED_BY(crit_);
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +0000444};
445
henrikaec6fbd22017-03-31 05:43:36 -0700446class Channel::ProcessAndEncodeAudioTask : public rtc::QueuedTask {
447 public:
448 ProcessAndEncodeAudioTask(std::unique_ptr<AudioFrame> audio_frame,
449 Channel* channel)
450 : audio_frame_(std::move(audio_frame)), channel_(channel) {
451 RTC_DCHECK(channel_);
452 }
453
454 private:
455 bool Run() override {
456 RTC_DCHECK_RUN_ON(channel_->encoder_queue_);
457 channel_->ProcessAndEncodeAudioOnTaskQueue(audio_frame_.get());
458 return true;
459 }
460
461 std::unique_ptr<AudioFrame> audio_frame_;
462 Channel* const channel_;
463};
464
kwiberg55b97fe2016-01-28 05:22:45 -0800465int32_t Channel::SendData(FrameType frameType,
466 uint8_t payloadType,
467 uint32_t timeStamp,
468 const uint8_t* payloadData,
469 size_t payloadSize,
470 const RTPFragmentationHeader* fragmentation) {
henrikaec6fbd22017-03-31 05:43:36 -0700471 RTC_DCHECK_RUN_ON(encoder_queue_);
kwiberg55b97fe2016-01-28 05:22:45 -0800472 if (_includeAudioLevelIndication) {
473 // Store current audio level in the RTP/RTCP module.
474 // The level will be used in combination with voice-activity state
475 // (frameType) to add an RTP header extension
henrik.lundin50499422016-11-29 04:26:24 -0800476 _rtpRtcpModule->SetAudioLevel(rms_level_.Average());
kwiberg55b97fe2016-01-28 05:22:45 -0800477 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000478
kwiberg55b97fe2016-01-28 05:22:45 -0800479 // Push data from ACM to RTP/RTCP-module to deliver audio frame for
480 // packetization.
481 // This call will trigger Transport::SendPacket() from the RTP/RTCP module.
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700482 if (!_rtpRtcpModule->SendOutgoingData(
kwiberg55b97fe2016-01-28 05:22:45 -0800483 (FrameType&)frameType, payloadType, timeStamp,
484 // Leaving the time when this frame was
485 // received from the capture device as
486 // undefined for voice for now.
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700487 -1, payloadData, payloadSize, fragmentation, nullptr, nullptr)) {
solenberg1c239d42017-09-29 06:00:28 -0700488 LOG(LS_ERROR) <<
489 "Channel::SendData() failed to send data to RTP/RTCP module";
kwiberg55b97fe2016-01-28 05:22:45 -0800490 return -1;
491 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000492
kwiberg55b97fe2016-01-28 05:22:45 -0800493 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000494}
495
stefan1d8a5062015-10-02 03:39:33 -0700496bool Channel::SendRtp(const uint8_t* data,
497 size_t len,
498 const PacketOptions& options) {
kwiberg55b97fe2016-01-28 05:22:45 -0800499 rtc::CritScope cs(&_callbackCritSect);
wu@webrtc.orgfb648da2013-10-18 21:10:51 +0000500
kwiberg55b97fe2016-01-28 05:22:45 -0800501 if (_transportPtr == NULL) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +0200502 LOG(LS_ERROR) << "Channel::SendPacket() failed to send RTP packet due to"
503 << " invalid transport object";
kwiberg55b97fe2016-01-28 05:22:45 -0800504 return false;
505 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000506
kwiberg55b97fe2016-01-28 05:22:45 -0800507 uint8_t* bufferToSendPtr = (uint8_t*)data;
508 size_t bufferLength = len;
niklase@google.com470e71d2011-07-07 08:21:25 +0000509
kwiberg55b97fe2016-01-28 05:22:45 -0800510 if (!_transportPtr->SendRtp(bufferToSendPtr, bufferLength, options)) {
solenberg1c239d42017-09-29 06:00:28 -0700511 LOG(LS_ERROR) << "Channel::SendPacket() RTP transmission failed";
kwiberg55b97fe2016-01-28 05:22:45 -0800512 return false;
513 }
514 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000515}
516
kwiberg55b97fe2016-01-28 05:22:45 -0800517bool Channel::SendRtcp(const uint8_t* data, size_t len) {
kwiberg55b97fe2016-01-28 05:22:45 -0800518 rtc::CritScope cs(&_callbackCritSect);
519 if (_transportPtr == NULL) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +0200520 LOG(LS_ERROR) << "Channel::SendRtcp() failed to send RTCP packet due to"
521 << " invalid transport object";
kwiberg55b97fe2016-01-28 05:22:45 -0800522 return false;
523 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000524
kwiberg55b97fe2016-01-28 05:22:45 -0800525 uint8_t* bufferToSendPtr = (uint8_t*)data;
526 size_t bufferLength = len;
niklase@google.com470e71d2011-07-07 08:21:25 +0000527
kwiberg55b97fe2016-01-28 05:22:45 -0800528 int n = _transportPtr->SendRtcp(bufferToSendPtr, bufferLength);
529 if (n < 0) {
solenberg1c239d42017-09-29 06:00:28 -0700530 LOG(LS_ERROR) << "Channel::SendRtcp() transmission failed";
kwiberg55b97fe2016-01-28 05:22:45 -0800531 return false;
532 }
533 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000534}
535
kwiberg55b97fe2016-01-28 05:22:45 -0800536void Channel::OnIncomingSSRCChanged(uint32_t ssrc) {
kwiberg55b97fe2016-01-28 05:22:45 -0800537 // Update ssrc so that NTP for AV sync can be updated.
538 _rtpRtcpModule->SetRemoteSSRC(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000539}
540
Peter Boströmac547a62015-09-17 23:03:57 +0200541void Channel::OnIncomingCSRCChanged(uint32_t CSRC, bool added) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +0200542 // TODO(saza): remove.
niklase@google.com470e71d2011-07-07 08:21:25 +0000543}
544
Karl Wibergc62f6c72017-10-04 12:38:53 +0200545int32_t Channel::OnInitializeDecoder(int payload_type,
546 const SdpAudioFormat& audio_format,
547 uint32_t rate) {
548 if (!audio_coding_->RegisterReceiveCodec(payload_type, audio_format)) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +0200549 LOG(LS_WARNING) << "Channel::OnInitializeDecoder() invalid codec (pt="
Karl Wibergc62f6c72017-10-04 12:38:53 +0200550 << payload_type << ", " << audio_format << ") received -1";
kwiberg55b97fe2016-01-28 05:22:45 -0800551 return -1;
552 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000553
kwiberg55b97fe2016-01-28 05:22:45 -0800554 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000555}
556
kwiberg55b97fe2016-01-28 05:22:45 -0800557int32_t Channel::OnReceivedPayloadData(const uint8_t* payloadData,
558 size_t payloadSize,
559 const WebRtcRTPHeader* rtpHeader) {
kwiberg55b97fe2016-01-28 05:22:45 -0800560 if (!channel_state_.Get().playing) {
561 // Avoid inserting into NetEQ when we are not playing. Count the
562 // packet as discarded.
niklase@google.com470e71d2011-07-07 08:21:25 +0000563 return 0;
kwiberg55b97fe2016-01-28 05:22:45 -0800564 }
565
566 // Push the incoming payload (parsed and ready for decoding) into the ACM
567 if (audio_coding_->IncomingPacket(payloadData, payloadSize, *rtpHeader) !=
568 0) {
solenberg1c239d42017-09-29 06:00:28 -0700569 LOG(LS_ERROR) <<
570 "Channel::OnReceivedPayloadData() unable to push data to the ACM";
kwiberg55b97fe2016-01-28 05:22:45 -0800571 return -1;
572 }
573
kwiberg55b97fe2016-01-28 05:22:45 -0800574 int64_t round_trip_time = 0;
575 _rtpRtcpModule->RTT(rtp_receiver_->SSRC(), &round_trip_time, NULL, NULL,
576 NULL);
577
578 std::vector<uint16_t> nack_list = audio_coding_->GetNackList(round_trip_time);
579 if (!nack_list.empty()) {
580 // Can't use nack_list.data() since it's not supported by all
581 // compilers.
582 ResendPackets(&(nack_list[0]), static_cast<int>(nack_list.size()));
583 }
584 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000585}
586
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000587bool Channel::OnRecoveredPacket(const uint8_t* rtp_packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000588 size_t rtp_packet_length) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000589 RTPHeader header;
590 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +0200591 LOG(LS_WARNING) << "IncomingPacket invalid RTP header";
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000592 return false;
593 }
594 header.payload_type_frequency =
595 rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType);
596 if (header.payload_type_frequency < 0)
597 return false;
598 return ReceivePacket(rtp_packet, rtp_packet_length, header, false);
599}
600
solenberg2397b9a2017-09-22 06:48:10 -0700601AudioMixer::Source::AudioFrameInfo Channel::GetAudioFrameWithInfo(
602 int sample_rate_hz,
603 AudioFrame* audio_frame) {
604 audio_frame->sample_rate_hz_ = sample_rate_hz;
605
ivoc14d5dbe2016-07-04 07:06:55 -0700606 unsigned int ssrc;
nisse7d59f6b2017-02-21 03:40:24 -0800607 RTC_CHECK_EQ(GetRemoteSSRC(ssrc), 0);
Elad Alon4a87e1c2017-10-03 16:11:34 +0200608 event_log_proxy_->Log(rtc::MakeUnique<RtcEventAudioPlayout>(ssrc));
kwiberg55b97fe2016-01-28 05:22:45 -0800609 // Get 10ms raw PCM data from the ACM (mixer limits output frequency)
henrik.lundind4ccb002016-05-17 12:21:55 -0700610 bool muted;
solenberg2397b9a2017-09-22 06:48:10 -0700611 if (audio_coding_->PlayoutData10Ms(audio_frame->sample_rate_hz_, audio_frame,
henrik.lundind4ccb002016-05-17 12:21:55 -0700612 &muted) == -1) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +0200613 LOG(LS_ERROR) << "Channel::GetAudioFrame() PlayoutData10Ms() failed!";
kwiberg55b97fe2016-01-28 05:22:45 -0800614 // In all likelihood, the audio in this frame is garbage. We return an
615 // error so that the audio mixer module doesn't add it to the mix. As
616 // a result, it won't be played out and the actions skipped here are
617 // irrelevant.
solenberg2397b9a2017-09-22 06:48:10 -0700618 return AudioMixer::Source::AudioFrameInfo::kError;
kwiberg55b97fe2016-01-28 05:22:45 -0800619 }
henrik.lundina89ab962016-05-18 08:52:45 -0700620
621 if (muted) {
622 // TODO(henrik.lundin): We should be able to do better than this. But we
623 // will have to go through all the cases below where the audio samples may
624 // be used, and handle the muted case in some way.
solenberg2397b9a2017-09-22 06:48:10 -0700625 AudioFrameOperations::Mute(audio_frame);
henrik.lundina89ab962016-05-18 08:52:45 -0700626 }
kwiberg55b97fe2016-01-28 05:22:45 -0800627
kwiberg55b97fe2016-01-28 05:22:45 -0800628 // Store speech type for dead-or-alive detection
solenberg2397b9a2017-09-22 06:48:10 -0700629 _outputSpeechType = audio_frame->speech_type_;
kwiberg55b97fe2016-01-28 05:22:45 -0800630
kwiberg55b97fe2016-01-28 05:22:45 -0800631 {
632 // Pass the audio buffers to an optional sink callback, before applying
633 // scaling/panning, as that applies to the mix operation.
634 // External recipients of the audio (e.g. via AudioTrack), will do their
635 // own mixing/dynamic processing.
636 rtc::CritScope cs(&_callbackCritSect);
637 if (audio_sink_) {
638 AudioSinkInterface::Data data(
solenberg2397b9a2017-09-22 06:48:10 -0700639 audio_frame->data(), audio_frame->samples_per_channel_,
640 audio_frame->sample_rate_hz_, audio_frame->num_channels_,
641 audio_frame->timestamp_);
kwiberg55b97fe2016-01-28 05:22:45 -0800642 audio_sink_->OnData(data);
643 }
644 }
645
646 float output_gain = 1.0f;
kwiberg55b97fe2016-01-28 05:22:45 -0800647 {
648 rtc::CritScope cs(&volume_settings_critsect_);
649 output_gain = _outputGain;
kwiberg55b97fe2016-01-28 05:22:45 -0800650 }
651
652 // Output volume scaling
653 if (output_gain < 0.99f || output_gain > 1.01f) {
solenberg8d73f8c2017-03-08 01:52:20 -0800654 // TODO(solenberg): Combine with mute state - this can cause clicks!
solenberg2397b9a2017-09-22 06:48:10 -0700655 AudioFrameOperations::ScaleWithSat(output_gain, audio_frame);
kwiberg55b97fe2016-01-28 05:22:45 -0800656 }
657
kwiberg55b97fe2016-01-28 05:22:45 -0800658 // Measure audio level (0-9)
henrik.lundina89ab962016-05-18 08:52:45 -0700659 // TODO(henrik.lundin) Use the |muted| information here too.
zstein3c451862017-07-20 09:57:42 -0700660 // TODO(deadbeef): Use RmsLevel for |_outputAudioLevel| (see
zsteine76bd3a2017-07-14 12:17:49 -0700661 // https://crbug.com/webrtc/7517).
solenberg2397b9a2017-09-22 06:48:10 -0700662 _outputAudioLevel.ComputeLevel(*audio_frame, kAudioSampleDurationSeconds);
kwiberg55b97fe2016-01-28 05:22:45 -0800663
solenberg2397b9a2017-09-22 06:48:10 -0700664 if (capture_start_rtp_time_stamp_ < 0 && audio_frame->timestamp_ != 0) {
kwiberg55b97fe2016-01-28 05:22:45 -0800665 // The first frame with a valid rtp timestamp.
solenberg2397b9a2017-09-22 06:48:10 -0700666 capture_start_rtp_time_stamp_ = audio_frame->timestamp_;
kwiberg55b97fe2016-01-28 05:22:45 -0800667 }
668
669 if (capture_start_rtp_time_stamp_ >= 0) {
solenberg2397b9a2017-09-22 06:48:10 -0700670 // audio_frame.timestamp_ should be valid from now on.
kwiberg55b97fe2016-01-28 05:22:45 -0800671
672 // Compute elapsed time.
673 int64_t unwrap_timestamp =
solenberg2397b9a2017-09-22 06:48:10 -0700674 rtp_ts_wraparound_handler_->Unwrap(audio_frame->timestamp_);
675 audio_frame->elapsed_time_ms_ =
kwiberg55b97fe2016-01-28 05:22:45 -0800676 (unwrap_timestamp - capture_start_rtp_time_stamp_) /
ossue280cde2016-10-12 11:04:10 -0700677 (GetRtpTimestampRateHz() / 1000);
kwiberg55b97fe2016-01-28 05:22:45 -0800678
niklase@google.com470e71d2011-07-07 08:21:25 +0000679 {
kwiberg55b97fe2016-01-28 05:22:45 -0800680 rtc::CritScope lock(&ts_stats_lock_);
681 // Compute ntp time.
solenberg2397b9a2017-09-22 06:48:10 -0700682 audio_frame->ntp_time_ms_ =
683 ntp_estimator_.Estimate(audio_frame->timestamp_);
kwiberg55b97fe2016-01-28 05:22:45 -0800684 // |ntp_time_ms_| won't be valid until at least 2 RTCP SRs are received.
solenberg2397b9a2017-09-22 06:48:10 -0700685 if (audio_frame->ntp_time_ms_ > 0) {
kwiberg55b97fe2016-01-28 05:22:45 -0800686 // Compute |capture_start_ntp_time_ms_| so that
687 // |capture_start_ntp_time_ms_| + |elapsed_time_ms_| == |ntp_time_ms_|
688 capture_start_ntp_time_ms_ =
solenberg2397b9a2017-09-22 06:48:10 -0700689 audio_frame->ntp_time_ms_ - audio_frame->elapsed_time_ms_;
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000690 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000691 }
kwiberg55b97fe2016-01-28 05:22:45 -0800692 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000693
solenberg2397b9a2017-09-22 06:48:10 -0700694 return muted ? AudioMixer::Source::AudioFrameInfo::kMuted
695 : AudioMixer::Source::AudioFrameInfo::kNormal;
niklase@google.com470e71d2011-07-07 08:21:25 +0000696}
697
solenberg2397b9a2017-09-22 06:48:10 -0700698int Channel::PreferredSampleRate() const {
kwiberg55b97fe2016-01-28 05:22:45 -0800699 // Return the bigger of playout and receive frequency in the ACM.
solenberg2397b9a2017-09-22 06:48:10 -0700700 return std::max(audio_coding_->ReceiveFrequency(),
701 audio_coding_->PlayoutFrequency());
niklase@google.com470e71d2011-07-07 08:21:25 +0000702}
703
henrikaec6fbd22017-03-31 05:43:36 -0700704int32_t Channel::CreateChannel(Channel*& channel,
705 int32_t channelId,
706 uint32_t instanceId,
707 const VoEBase::ChannelConfig& config) {
solenberg88499ec2016-09-07 07:34:41 -0700708 channel = new Channel(channelId, instanceId, config);
kwiberg55b97fe2016-01-28 05:22:45 -0800709 if (channel == NULL) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +0200710 LOG(LS_ERROR) << "unable to allocate memory for new channel";
kwiberg55b97fe2016-01-28 05:22:45 -0800711 return -1;
712 }
713 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000714}
715
pbos@webrtc.org92135212013-05-14 08:31:39 +0000716Channel::Channel(int32_t channelId,
minyue@webrtc.orge509f942013-09-12 17:03:00 +0000717 uint32_t instanceId,
solenberg88499ec2016-09-07 07:34:41 -0700718 const VoEBase::ChannelConfig& config)
tommi31fc21f2016-01-21 10:37:37 -0800719 : _instanceId(instanceId),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100720 _channelId(channelId),
ivoc14d5dbe2016-07-04 07:06:55 -0700721 event_log_proxy_(new RtcEventLogProxy()),
michaelt9332b7d2016-11-30 07:51:13 -0800722 rtcp_rtt_stats_proxy_(new RtcpRttStatsProxy()),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100723 rtp_header_parser_(RtpHeaderParser::Create()),
magjedf3feeff2016-11-25 06:40:25 -0800724 rtp_payload_registry_(new RTPPayloadRegistry()),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100725 rtp_receive_statistics_(
726 ReceiveStatistics::Create(Clock::GetRealTimeClock())),
727 rtp_receiver_(
728 RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100729 this,
730 this,
731 rtp_payload_registry_.get())),
danilchap799a9d02016-09-22 03:36:27 -0700732 telephone_event_handler_(rtp_receiver_->GetTelephoneEventHandler()),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100733 _outputAudioLevel(),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100734 _timeStamp(0), // This is just an offset, RTP module will add it's own
735 // random offset
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100736 ntp_estimator_(Clock::GetRealTimeClock()),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100737 playout_timestamp_rtp_(0),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100738 playout_delay_ms_(0),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100739 send_sequence_number_(0),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100740 rtp_ts_wraparound_handler_(new rtc::TimestampWrapAroundHandler()),
741 capture_start_rtp_time_stamp_(-1),
742 capture_start_ntp_time_ms_(-1),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100743 _moduleProcessThreadPtr(NULL),
744 _audioDeviceModulePtr(NULL),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100745 _transportPtr(NULL),
solenberg1c2af8e2016-03-24 10:36:00 -0700746 input_mute_(false),
747 previous_frame_muted_(false),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100748 _outputGain(1.0f),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100749 _includeAudioLevelIndication(false),
nisse284542b2017-01-10 08:58:32 -0800750 transport_overhead_per_packet_(0),
751 rtp_overhead_per_packet_(0),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100752 _outputSpeechType(AudioFrame::kNormalSpeech),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100753 rtcp_observer_(new VoERtcpObserver(this)),
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100754 associate_send_channel_(ChannelOwner(nullptr)),
solenberg88499ec2016-09-07 07:34:41 -0700755 pacing_enabled_(config.enable_voice_pacing),
stefanbba9dec2016-02-01 04:39:55 -0800756 feedback_observer_proxy_(new TransportFeedbackProxy()),
757 seq_num_allocator_proxy_(new TransportSequenceNumberProxy()),
ossu29b1a8d2016-06-13 07:34:51 -0700758 rtp_packet_sender_proxy_(new RtpPacketSenderProxy()),
Erik Språng737336d2016-07-29 12:59:36 +0200759 retransmission_rate_limiter_(new RateLimiter(Clock::GetRealTimeClock(),
760 kMaxRetransmissionWindowMs)),
elad.alond12a8e12017-03-23 11:04:48 -0700761 decoder_factory_(config.acm_config.decoder_factory),
elad.alon28770482017-03-28 05:03:55 -0700762 use_twcc_plr_for_ana_(
763 webrtc::field_trial::FindFullName("UseTwccPlrForAna") == "Enabled") {
solenberg88499ec2016-09-07 07:34:41 -0700764 AudioCodingModule::Config acm_config(config.acm_config);
henrik.lundina89ab962016-05-18 08:52:45 -0700765 acm_config.neteq_config.enable_muted_state = true;
kwiberg55b97fe2016-01-28 05:22:45 -0800766 audio_coding_.reset(AudioCodingModule::Create(acm_config));
Henrik Lundin64dad832015-05-11 12:44:23 +0200767
kwiberg55b97fe2016-01-28 05:22:45 -0800768 _outputAudioLevel.Clear();
niklase@google.com470e71d2011-07-07 08:21:25 +0000769
kwiberg55b97fe2016-01-28 05:22:45 -0800770 RtpRtcp::Configuration configuration;
771 configuration.audio = true;
772 configuration.outgoing_transport = this;
michaeltbf65be52016-12-15 06:24:49 -0800773 configuration.overhead_observer = this;
kwiberg55b97fe2016-01-28 05:22:45 -0800774 configuration.receive_statistics = rtp_receive_statistics_.get();
775 configuration.bandwidth_callback = rtcp_observer_.get();
stefanbba9dec2016-02-01 04:39:55 -0800776 if (pacing_enabled_) {
777 configuration.paced_sender = rtp_packet_sender_proxy_.get();
778 configuration.transport_sequence_number_allocator =
779 seq_num_allocator_proxy_.get();
780 configuration.transport_feedback_callback = feedback_observer_proxy_.get();
781 }
ivoc14d5dbe2016-07-04 07:06:55 -0700782 configuration.event_log = &(*event_log_proxy_);
michaelt9332b7d2016-11-30 07:51:13 -0800783 configuration.rtt_stats = &(*rtcp_rtt_stats_proxy_);
Erik Språng737336d2016-07-29 12:59:36 +0200784 configuration.retransmission_rate_limiter =
785 retransmission_rate_limiter_.get();
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000786
kwiberg55b97fe2016-01-28 05:22:45 -0800787 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration));
Peter Boström3dd5d1d2016-02-25 16:56:48 +0100788 _rtpRtcpModule->SetSendingMediaStatus(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000789}
790
kwiberg55b97fe2016-01-28 05:22:45 -0800791Channel::~Channel() {
tommi0a2391f2017-03-21 02:31:51 -0700792 RTC_DCHECK(!channel_state_.Get().sending);
793 RTC_DCHECK(!channel_state_.Get().playing);
niklase@google.com470e71d2011-07-07 08:21:25 +0000794}
795
kwiberg55b97fe2016-01-28 05:22:45 -0800796int32_t Channel::Init() {
tommi0a2391f2017-03-21 02:31:51 -0700797 RTC_DCHECK(construction_thread_.CalledOnValidThread());
niklase@google.com470e71d2011-07-07 08:21:25 +0000798
kwiberg55b97fe2016-01-28 05:22:45 -0800799 channel_state_.Reset();
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000800
kwiberg55b97fe2016-01-28 05:22:45 -0800801 // --- Initial sanity
niklase@google.com470e71d2011-07-07 08:21:25 +0000802
solenberg1c239d42017-09-29 06:00:28 -0700803 if (_moduleProcessThreadPtr == NULL) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +0200804 LOG(LS_ERROR) << "Channel::Init() must call SetEngineInformation() first";
kwiberg55b97fe2016-01-28 05:22:45 -0800805 return -1;
806 }
807
808 // --- Add modules to process thread (for periodic schedulation)
809
tommidea489f2017-03-03 03:20:24 -0800810 _moduleProcessThreadPtr->RegisterModule(_rtpRtcpModule.get(), RTC_FROM_HERE);
kwiberg55b97fe2016-01-28 05:22:45 -0800811
812 // --- ACM initialization
813
814 if (audio_coding_->InitializeReceiver() == -1) {
solenberg1c239d42017-09-29 06:00:28 -0700815 LOG(LS_ERROR) << "Channel::Init() unable to initialize the ACM - 1";
kwiberg55b97fe2016-01-28 05:22:45 -0800816 return -1;
817 }
818
819 // --- RTP/RTCP module initialization
820
821 // Ensure that RTCP is enabled by default for the created channel.
822 // Note that, the module will keep generating RTCP until it is explicitly
823 // disabled by the user.
824 // After StopListen (when no sockets exists), RTCP packets will no longer
825 // be transmitted since the Transport object will then be invalid.
danilchap799a9d02016-09-22 03:36:27 -0700826 telephone_event_handler_->SetTelephoneEventForwardToDecoder(true);
kwiberg55b97fe2016-01-28 05:22:45 -0800827 // RTCP is enabled by default.
828 _rtpRtcpModule->SetRTCPStatus(RtcpMode::kCompound);
829 // --- Register all permanent callbacks
solenbergfe7dd6d2017-03-11 08:10:43 -0800830 if (audio_coding_->RegisterTransportCallback(this) == -1) {
solenberg1c239d42017-09-29 06:00:28 -0700831 LOG(LS_ERROR) << "Channel::Init() callbacks not registered";
kwiberg55b97fe2016-01-28 05:22:45 -0800832 return -1;
833 }
834
kwiberg1c07c702017-03-27 07:15:49 -0700835 return 0;
836}
837
tommi0a2391f2017-03-21 02:31:51 -0700838void Channel::Terminate() {
839 RTC_DCHECK(construction_thread_.CalledOnValidThread());
840 // Must be called on the same thread as Init().
tommi0a2391f2017-03-21 02:31:51 -0700841 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(NULL);
842
843 StopSend();
844 StopPlayout();
845
tommi0a2391f2017-03-21 02:31:51 -0700846 // The order to safely shutdown modules in a channel is:
847 // 1. De-register callbacks in modules
848 // 2. De-register modules in process thread
849 // 3. Destroy modules
850 if (audio_coding_->RegisterTransportCallback(NULL) == -1) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +0200851 LOG(LS_WARNING) << "Terminate() failed to de-register transport callback"
852 << " (Audio coding module)";
tommi0a2391f2017-03-21 02:31:51 -0700853 }
854
tommi0a2391f2017-03-21 02:31:51 -0700855 // De-register modules in process thread
856 if (_moduleProcessThreadPtr)
857 _moduleProcessThreadPtr->DeRegisterModule(_rtpRtcpModule.get());
858
859 // End of modules shutdown
860}
861
solenberg1c239d42017-09-29 06:00:28 -0700862int32_t Channel::SetEngineInformation(ProcessThread& moduleProcessThread,
kwiberg55b97fe2016-01-28 05:22:45 -0800863 AudioDeviceModule& audioDeviceModule,
henrikaec6fbd22017-03-31 05:43:36 -0700864 rtc::TaskQueue* encoder_queue) {
865 RTC_DCHECK(encoder_queue);
866 RTC_DCHECK(!encoder_queue_);
kwiberg55b97fe2016-01-28 05:22:45 -0800867 _moduleProcessThreadPtr = &moduleProcessThread;
868 _audioDeviceModulePtr = &audioDeviceModule;
henrikaec6fbd22017-03-31 05:43:36 -0700869 encoder_queue_ = encoder_queue;
kwiberg55b97fe2016-01-28 05:22:45 -0800870 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000871}
872
kwibergb7f89d62016-02-17 10:04:18 -0800873void Channel::SetSink(std::unique_ptr<AudioSinkInterface> sink) {
tommi31fc21f2016-01-21 10:37:37 -0800874 rtc::CritScope cs(&_callbackCritSect);
deadbeef2d110be2016-01-13 12:00:26 -0800875 audio_sink_ = std::move(sink);
Tommif888bb52015-12-12 01:37:01 +0100876}
877
ossu29b1a8d2016-06-13 07:34:51 -0700878const rtc::scoped_refptr<AudioDecoderFactory>&
879Channel::GetAudioDecoderFactory() const {
880 return decoder_factory_;
881}
882
kwiberg55b97fe2016-01-28 05:22:45 -0800883int32_t Channel::StartPlayout() {
kwiberg55b97fe2016-01-28 05:22:45 -0800884 if (channel_state_.Get().playing) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000885 return 0;
kwiberg55b97fe2016-01-28 05:22:45 -0800886 }
887
kwiberg55b97fe2016-01-28 05:22:45 -0800888 channel_state_.SetPlaying(true);
kwiberg55b97fe2016-01-28 05:22:45 -0800889
890 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000891}
892
kwiberg55b97fe2016-01-28 05:22:45 -0800893int32_t Channel::StopPlayout() {
kwiberg55b97fe2016-01-28 05:22:45 -0800894 if (!channel_state_.Get().playing) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000895 return 0;
kwiberg55b97fe2016-01-28 05:22:45 -0800896 }
897
kwiberg55b97fe2016-01-28 05:22:45 -0800898 channel_state_.SetPlaying(false);
899 _outputAudioLevel.Clear();
900
901 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000902}
903
kwiberg55b97fe2016-01-28 05:22:45 -0800904int32_t Channel::StartSend() {
kwiberg55b97fe2016-01-28 05:22:45 -0800905 if (channel_state_.Get().sending) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000906 return 0;
kwiberg55b97fe2016-01-28 05:22:45 -0800907 }
908 channel_state_.SetSending(true);
henrika4515fa02017-05-03 08:30:15 -0700909 {
910 // It is now OK to start posting tasks to the encoder task queue.
911 rtc::CritScope cs(&encoder_queue_lock_);
912 encoder_queue_is_active_ = true;
913 }
solenberg08b19df2017-02-15 00:42:31 -0800914 // Resume the previous sequence number which was reset by StopSend(). This
915 // needs to be done before |sending| is set to true on the RTP/RTCP module.
916 if (send_sequence_number_) {
917 _rtpRtcpModule->SetSequenceNumber(send_sequence_number_);
918 }
Peter Boström3dd5d1d2016-02-25 16:56:48 +0100919 _rtpRtcpModule->SetSendingMediaStatus(true);
kwiberg55b97fe2016-01-28 05:22:45 -0800920 if (_rtpRtcpModule->SetSendingStatus(true) != 0) {
solenberg1c239d42017-09-29 06:00:28 -0700921 LOG(LS_ERROR) << "StartSend() RTP/RTCP failed to start sending";
Peter Boström3dd5d1d2016-02-25 16:56:48 +0100922 _rtpRtcpModule->SetSendingMediaStatus(false);
kwiberg55b97fe2016-01-28 05:22:45 -0800923 rtc::CritScope cs(&_callbackCritSect);
henrika@webrtc.org944cbeb2014-03-18 10:32:33 +0000924 channel_state_.SetSending(false);
kwiberg55b97fe2016-01-28 05:22:45 -0800925 return -1;
926 }
xians@webrtc.orge07247a2011-11-28 16:31:28 +0000927
kwiberg55b97fe2016-01-28 05:22:45 -0800928 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000929}
930
henrikaec6fbd22017-03-31 05:43:36 -0700931void Channel::StopSend() {
kwiberg55b97fe2016-01-28 05:22:45 -0800932 if (!channel_state_.Get().sending) {
henrikaec6fbd22017-03-31 05:43:36 -0700933 return;
kwiberg55b97fe2016-01-28 05:22:45 -0800934 }
935 channel_state_.SetSending(false);
936
henrikaec6fbd22017-03-31 05:43:36 -0700937 // Post a task to the encoder thread which sets an event when the task is
938 // executed. We know that no more encoding tasks will be added to the task
939 // queue for this channel since sending is now deactivated. It means that,
940 // if we wait for the event to bet set, we know that no more pending tasks
941 // exists and it is therfore guaranteed that the task queue will never try
942 // to acccess and invalid channel object.
943 RTC_DCHECK(encoder_queue_);
henrika4515fa02017-05-03 08:30:15 -0700944
henrikaec6fbd22017-03-31 05:43:36 -0700945 rtc::Event flush(false, false);
henrika4515fa02017-05-03 08:30:15 -0700946 {
947 // Clear |encoder_queue_is_active_| under lock to prevent any other tasks
948 // than this final "flush task" to be posted on the queue.
949 rtc::CritScope cs(&encoder_queue_lock_);
950 encoder_queue_is_active_ = false;
951 encoder_queue_->PostTask([&flush]() { flush.Set(); });
952 }
henrikaec6fbd22017-03-31 05:43:36 -0700953 flush.Wait(rtc::Event::kForever);
954
kwiberg55b97fe2016-01-28 05:22:45 -0800955 // Store the sequence number to be able to pick up the same sequence for
956 // the next StartSend(). This is needed for restarting device, otherwise
957 // it might cause libSRTP to complain about packets being replayed.
958 // TODO(xians): Remove this workaround after RtpRtcpModule's refactoring
959 // CL is landed. See issue
960 // https://code.google.com/p/webrtc/issues/detail?id=2111 .
961 send_sequence_number_ = _rtpRtcpModule->SequenceNumber();
962
963 // Reset sending SSRC and sequence number and triggers direct transmission
964 // of RTCP BYE
965 if (_rtpRtcpModule->SetSendingStatus(false) == -1) {
solenberg1c239d42017-09-29 06:00:28 -0700966 LOG(LS_ERROR) << "StartSend() RTP/RTCP failed to stop sending";
kwiberg55b97fe2016-01-28 05:22:45 -0800967 }
Peter Boström3dd5d1d2016-02-25 16:56:48 +0100968 _rtpRtcpModule->SetSendingMediaStatus(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000969}
970
ossu1ffbd6c2017-04-06 12:05:04 -0700971bool Channel::SetEncoder(int payload_type,
972 std::unique_ptr<AudioEncoder> encoder) {
973 RTC_DCHECK_GE(payload_type, 0);
974 RTC_DCHECK_LE(payload_type, 127);
ossu76d29f92017-06-09 07:30:13 -0700975 // TODO(ossu): Make CodecInsts up, for now: one for the RTP/RTCP module and
976 // one for for us to keep track of sample rate and number of channels, etc.
977
978 // The RTP/RTCP module needs to know the RTP timestamp rate (i.e. clockrate)
979 // as well as some other things, so we collect this info and send it along.
980 CodecInst rtp_codec;
981 rtp_codec.pltype = payload_type;
982 strncpy(rtp_codec.plname, "audio", sizeof(rtp_codec.plname));
983 rtp_codec.plname[sizeof(rtp_codec.plname) - 1] = 0;
ossu1ffbd6c2017-04-06 12:05:04 -0700984 // Seems unclear if it should be clock rate or sample rate. CodecInst
985 // supposedly carries the sample rate, but only clock rate seems sensible to
986 // send to the RTP/RTCP module.
ossu76d29f92017-06-09 07:30:13 -0700987 rtp_codec.plfreq = encoder->RtpTimestampRateHz();
988 rtp_codec.pacsize = rtc::CheckedDivExact(
989 static_cast<int>(encoder->Max10MsFramesInAPacket() * rtp_codec.plfreq),
990 100);
991 rtp_codec.channels = encoder->NumChannels();
992 rtp_codec.rate = 0;
ossu1ffbd6c2017-04-06 12:05:04 -0700993
ossu76d29f92017-06-09 07:30:13 -0700994 // For audio encoding we need, instead, the actual sample rate of the codec.
995 // The rest of the information should be the same.
996 CodecInst send_codec = rtp_codec;
997 send_codec.plfreq = encoder->SampleRateHz();
998 cached_send_codec_.emplace(send_codec);
999
1000 if (_rtpRtcpModule->RegisterSendPayload(rtp_codec) != 0) {
ossu1ffbd6c2017-04-06 12:05:04 -07001001 _rtpRtcpModule->DeRegisterSendPayload(payload_type);
ossu76d29f92017-06-09 07:30:13 -07001002 if (_rtpRtcpModule->RegisterSendPayload(rtp_codec) != 0) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +02001003 LOG(LS_ERROR)
1004 << "SetEncoder() failed to register codec to RTP/RTCP module";
ossu1ffbd6c2017-04-06 12:05:04 -07001005 return false;
1006 }
1007 }
1008
1009 audio_coding_->SetEncoder(std::move(encoder));
ossu20a4b3f2017-04-27 02:08:52 -07001010 codec_manager_.UnsetCodecInst();
ossu1ffbd6c2017-04-06 12:05:04 -07001011 return true;
1012}
1013
ossu20a4b3f2017-04-27 02:08:52 -07001014void Channel::ModifyEncoder(
1015 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) {
1016 audio_coding_->ModifyEncoder(modifier);
1017}
1018
kwiberg55b97fe2016-01-28 05:22:45 -08001019int32_t Channel::GetSendCodec(CodecInst& codec) {
ossu76d29f92017-06-09 07:30:13 -07001020 if (cached_send_codec_) {
1021 codec = *cached_send_codec_;
1022 return 0;
1023 } else {
ossu20a4b3f2017-04-27 02:08:52 -07001024 const CodecInst* send_codec = codec_manager_.GetCodecInst();
1025 if (send_codec) {
1026 codec = *send_codec;
1027 return 0;
1028 }
1029 }
kwiberg1fd4a4a2015-11-03 11:20:50 -08001030 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001031}
1032
kwiberg55b97fe2016-01-28 05:22:45 -08001033int32_t Channel::GetRecCodec(CodecInst& codec) {
1034 return (audio_coding_->ReceiveCodec(&codec));
niklase@google.com470e71d2011-07-07 08:21:25 +00001035}
1036
kwiberg55b97fe2016-01-28 05:22:45 -08001037int32_t Channel::SetSendCodec(const CodecInst& codec) {
kwibergc8d071e2016-04-06 12:22:38 -07001038 if (!codec_manager_.RegisterEncoder(codec) ||
1039 !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +02001040 LOG(LS_ERROR) << "SetSendCodec() failed to register codec to ACM";
kwiberg55b97fe2016-01-28 05:22:45 -08001041 return -1;
1042 }
1043
1044 if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) {
1045 _rtpRtcpModule->DeRegisterSendPayload(codec.pltype);
1046 if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +02001047 LOG(LS_ERROR)
1048 << "SetSendCodec() failed to register codec to RTP/RTCP module";
kwiberg55b97fe2016-01-28 05:22:45 -08001049 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001050 }
kwiberg55b97fe2016-01-28 05:22:45 -08001051 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001052
ossu76d29f92017-06-09 07:30:13 -07001053 cached_send_codec_.reset();
1054
kwiberg55b97fe2016-01-28 05:22:45 -08001055 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001056}
1057
minyue78b4d562016-11-30 04:47:39 -08001058void Channel::SetBitRate(int bitrate_bps, int64_t probing_interval_ms) {
minyue7e304322016-10-12 05:00:55 -07001059 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
michaelt2fedf9c2016-11-28 02:34:18 -08001060 if (*encoder) {
1061 (*encoder)->OnReceivedUplinkBandwidth(
michaelt566d8202017-01-12 10:17:38 -08001062 bitrate_bps, rtc::Optional<int64_t>(probing_interval_ms));
michaelt2fedf9c2016-11-28 02:34:18 -08001063 }
1064 });
michaelt566d8202017-01-12 10:17:38 -08001065 retransmission_rate_limiter_->SetMaxRate(bitrate_bps);
Ivo Creusenadf89b72015-04-29 16:03:33 +02001066}
1067
elad.alond12a8e12017-03-23 11:04:48 -07001068void Channel::OnTwccBasedUplinkPacketLossRate(float packet_loss_rate) {
1069 if (!use_twcc_plr_for_ana_)
1070 return;
minyue7e304322016-10-12 05:00:55 -07001071 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
elad.alond12a8e12017-03-23 11:04:48 -07001072 if (*encoder) {
1073 (*encoder)->OnReceivedUplinkPacketLossFraction(packet_loss_rate);
1074 }
1075 });
1076}
1077
elad.alondadb4dc2017-03-23 15:29:50 -07001078void Channel::OnRecoverableUplinkPacketLossRate(
1079 float recoverable_packet_loss_rate) {
1080 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
1081 if (*encoder) {
1082 (*encoder)->OnReceivedUplinkRecoverablePacketLossFraction(
1083 recoverable_packet_loss_rate);
1084 }
1085 });
1086}
1087
elad.alond12a8e12017-03-23 11:04:48 -07001088void Channel::OnUplinkPacketLossRate(float packet_loss_rate) {
1089 if (use_twcc_plr_for_ana_)
1090 return;
1091 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
1092 if (*encoder) {
1093 (*encoder)->OnReceivedUplinkPacketLossFraction(packet_loss_rate);
1094 }
minyue7e304322016-10-12 05:00:55 -07001095 });
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +00001096}
1097
kwiberg1c07c702017-03-27 07:15:49 -07001098void Channel::SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs) {
1099 rtp_payload_registry_->SetAudioReceivePayloads(codecs);
1100 audio_coding_->SetReceiveCodecs(codecs);
1101}
1102
minyue7e304322016-10-12 05:00:55 -07001103bool Channel::EnableAudioNetworkAdaptor(const std::string& config_string) {
1104 bool success = false;
1105 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
1106 if (*encoder) {
michaelt92aef172017-04-18 00:11:48 -07001107 success = (*encoder)->EnableAudioNetworkAdaptor(config_string,
1108 event_log_proxy_.get());
minyue7e304322016-10-12 05:00:55 -07001109 }
1110 });
1111 return success;
1112}
1113
1114void Channel::DisableAudioNetworkAdaptor() {
1115 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
1116 if (*encoder)
1117 (*encoder)->DisableAudioNetworkAdaptor();
1118 });
1119}
1120
1121void Channel::SetReceiverFrameLengthRange(int min_frame_length_ms,
1122 int max_frame_length_ms) {
1123 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
1124 if (*encoder) {
1125 (*encoder)->SetReceiverFrameLengthRange(min_frame_length_ms,
1126 max_frame_length_ms);
1127 }
1128 });
1129}
1130
solenberg1c239d42017-09-29 06:00:28 -07001131void Channel::RegisterTransport(Transport* transport) {
kwiberg55b97fe2016-01-28 05:22:45 -08001132 rtc::CritScope cs(&_callbackCritSect);
mflodman3d7db262016-04-29 00:57:13 -07001133 _transportPtr = transport;
niklase@google.com470e71d2011-07-07 08:21:25 +00001134}
1135
nisse657bab22017-02-21 06:28:10 -08001136void Channel::OnRtpPacket(const RtpPacketReceived& packet) {
nisse657bab22017-02-21 06:28:10 -08001137 RTPHeader header;
1138 packet.GetHeader(&header);
solenberg946d8862017-09-21 04:02:53 -07001139
1140 // Store playout timestamp for the received RTP packet
1141 UpdatePlayoutTimestamp(false);
1142
1143 header.payload_type_frequency =
1144 rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType);
1145 if (header.payload_type_frequency >= 0) {
1146 bool in_order = IsPacketInOrder(header);
1147 rtp_receive_statistics_->IncomingPacket(
1148 header, packet.size(), IsPacketRetransmitted(header, in_order));
1149 rtp_payload_registry_->SetIncomingPayloadType(header);
1150
1151 ReceivePacket(packet.data(), packet.size(), header, in_order);
1152 }
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +00001153}
1154
1155bool Channel::ReceivePacket(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +00001156 size_t packet_length,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +00001157 const RTPHeader& header,
1158 bool in_order) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +00001159 const uint8_t* payload = packet + header.headerLength;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +00001160 assert(packet_length >= header.headerLength);
1161 size_t payload_length = packet_length - header.headerLength;
Karl Wiberg73b60b82017-09-21 15:00:58 +02001162 const auto pl =
1163 rtp_payload_registry_->PayloadTypeToPayload(header.payloadType);
1164 if (!pl) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +00001165 return false;
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001166 }
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +00001167 return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
Karl Wiberg73b60b82017-09-21 15:00:58 +02001168 pl->typeSpecific, in_order);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +00001169}
1170
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +00001171bool Channel::IsPacketInOrder(const RTPHeader& header) const {
1172 StreamStatistician* statistician =
1173 rtp_receive_statistics_->GetStatistician(header.ssrc);
1174 if (!statistician)
1175 return false;
1176 return statistician->IsPacketInOrder(header.sequenceNumber);
niklase@google.com470e71d2011-07-07 08:21:25 +00001177}
1178
stefan@webrtc.org48df3812013-11-08 15:18:52 +00001179bool Channel::IsPacketRetransmitted(const RTPHeader& header,
1180 bool in_order) const {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +00001181 StreamStatistician* statistician =
1182 rtp_receive_statistics_->GetStatistician(header.ssrc);
1183 if (!statistician)
1184 return false;
1185 // Check if this is a retransmission.
pkasting@chromium.org16825b12015-01-12 21:51:21 +00001186 int64_t min_rtt = 0;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +00001187 _rtpRtcpModule->RTT(rtp_receiver_->SSRC(), NULL, NULL, &min_rtt, NULL);
kwiberg55b97fe2016-01-28 05:22:45 -08001188 return !in_order && statistician->IsRetransmitOfOldPacket(header, min_rtt);
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001189}
1190
mflodman3d7db262016-04-29 00:57:13 -07001191int32_t Channel::ReceivedRTCPPacket(const uint8_t* data, size_t length) {
pwestin@webrtc.org0c459572013-04-03 15:43:57 +00001192 // Store playout timestamp for the received RTCP packet
pwestin@webrtc.org1de01352013-04-11 20:23:35 +00001193 UpdatePlayoutTimestamp(true);
pwestin@webrtc.org0c459572013-04-03 15:43:57 +00001194
pwestin@webrtc.org0c459572013-04-03 15:43:57 +00001195 // Deliver RTCP packet to RTP/RTCP module for parsing
nisse479d3d72017-09-13 07:53:37 -07001196 _rtpRtcpModule->IncomingRtcpPacket(data, length);
wu@webrtc.org82c4b852014-05-20 22:55:01 +00001197
Minyue2013aec2015-05-13 14:14:42 +02001198 int64_t rtt = GetRTT(true);
1199 if (rtt == 0) {
1200 // Waiting for valid RTT.
1201 return 0;
1202 }
Erik Språng737336d2016-07-29 12:59:36 +02001203
1204 int64_t nack_window_ms = rtt;
1205 if (nack_window_ms < kMinRetransmissionWindowMs) {
1206 nack_window_ms = kMinRetransmissionWindowMs;
1207 } else if (nack_window_ms > kMaxRetransmissionWindowMs) {
1208 nack_window_ms = kMaxRetransmissionWindowMs;
1209 }
1210 retransmission_rate_limiter_->SetWindowSize(nack_window_ms);
1211
minyue7e304322016-10-12 05:00:55 -07001212 // Invoke audio encoders OnReceivedRtt().
1213 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
1214 if (*encoder)
1215 (*encoder)->OnReceivedRtt(rtt);
1216 });
1217
Minyue2013aec2015-05-13 14:14:42 +02001218 uint32_t ntp_secs = 0;
1219 uint32_t ntp_frac = 0;
1220 uint32_t rtp_timestamp = 0;
kwiberg55b97fe2016-01-28 05:22:45 -08001221 if (0 !=
1222 _rtpRtcpModule->RemoteNTP(&ntp_secs, &ntp_frac, NULL, NULL,
1223 &rtp_timestamp)) {
Minyue2013aec2015-05-13 14:14:42 +02001224 // Waiting for RTCP.
1225 return 0;
1226 }
1227
stefan@webrtc.org8e24d872014-09-02 18:58:24 +00001228 {
tommi31fc21f2016-01-21 10:37:37 -08001229 rtc::CritScope lock(&ts_stats_lock_);
minyue@webrtc.org2c0cdbc2014-10-09 10:52:43 +00001230 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
stefan@webrtc.org8e24d872014-09-02 18:58:24 +00001231 }
pwestin@webrtc.org0c459572013-04-03 15:43:57 +00001232 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001233}
1234
solenberg8d73f8c2017-03-08 01:52:20 -08001235int Channel::GetSpeechOutputLevel() const {
1236 return _outputAudioLevel.Level();
niklase@google.com470e71d2011-07-07 08:21:25 +00001237}
1238
solenberg8d73f8c2017-03-08 01:52:20 -08001239int Channel::GetSpeechOutputLevelFullRange() const {
1240 return _outputAudioLevel.LevelFullRange();
kwiberg55b97fe2016-01-28 05:22:45 -08001241}
1242
zsteine76bd3a2017-07-14 12:17:49 -07001243double Channel::GetTotalOutputEnergy() const {
zstein3c451862017-07-20 09:57:42 -07001244 return _outputAudioLevel.TotalEnergy();
zsteine76bd3a2017-07-14 12:17:49 -07001245}
1246
1247double Channel::GetTotalOutputDuration() const {
zstein3c451862017-07-20 09:57:42 -07001248 return _outputAudioLevel.TotalDuration();
zsteine76bd3a2017-07-14 12:17:49 -07001249}
1250
solenberg8d73f8c2017-03-08 01:52:20 -08001251void Channel::SetInputMute(bool enable) {
kwiberg55b97fe2016-01-28 05:22:45 -08001252 rtc::CritScope cs(&volume_settings_critsect_);
solenberg1c2af8e2016-03-24 10:36:00 -07001253 input_mute_ = enable;
niklase@google.com470e71d2011-07-07 08:21:25 +00001254}
1255
solenberg1c2af8e2016-03-24 10:36:00 -07001256bool Channel::InputMute() const {
kwiberg55b97fe2016-01-28 05:22:45 -08001257 rtc::CritScope cs(&volume_settings_critsect_);
solenberg1c2af8e2016-03-24 10:36:00 -07001258 return input_mute_;
niklase@google.com470e71d2011-07-07 08:21:25 +00001259}
1260
solenberg8d73f8c2017-03-08 01:52:20 -08001261void Channel::SetChannelOutputVolumeScaling(float scaling) {
kwiberg55b97fe2016-01-28 05:22:45 -08001262 rtc::CritScope cs(&volume_settings_critsect_);
kwiberg55b97fe2016-01-28 05:22:45 -08001263 _outputGain = scaling;
niklase@google.com470e71d2011-07-07 08:21:25 +00001264}
1265
solenberg8842c3e2016-03-11 03:06:41 -08001266int Channel::SendTelephoneEventOutband(int event, int duration_ms) {
solenberg8842c3e2016-03-11 03:06:41 -08001267 RTC_DCHECK_LE(0, event);
1268 RTC_DCHECK_GE(255, event);
1269 RTC_DCHECK_LE(0, duration_ms);
1270 RTC_DCHECK_GE(65535, duration_ms);
kwiberg55b97fe2016-01-28 05:22:45 -08001271 if (!Sending()) {
1272 return -1;
1273 }
solenberg8842c3e2016-03-11 03:06:41 -08001274 if (_rtpRtcpModule->SendTelephoneEventOutband(
1275 event, duration_ms, kTelephoneEventAttenuationdB) != 0) {
solenberg1c239d42017-09-29 06:00:28 -07001276 LOG(LS_ERROR) << "SendTelephoneEventOutband() failed to send event";
kwiberg55b97fe2016-01-28 05:22:45 -08001277 return -1;
1278 }
1279 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001280}
1281
solenbergffbbcac2016-11-17 05:25:37 -08001282int Channel::SetSendTelephoneEventPayloadType(int payload_type,
1283 int payload_frequency) {
solenberg31642aa2016-03-14 08:00:37 -07001284 RTC_DCHECK_LE(0, payload_type);
1285 RTC_DCHECK_GE(127, payload_type);
1286 CodecInst codec = {0};
solenberg31642aa2016-03-14 08:00:37 -07001287 codec.pltype = payload_type;
solenbergffbbcac2016-11-17 05:25:37 -08001288 codec.plfreq = payload_frequency;
kwiberg55b97fe2016-01-28 05:22:45 -08001289 memcpy(codec.plname, "telephone-event", 16);
1290 if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) {
1291 _rtpRtcpModule->DeRegisterSendPayload(codec.pltype);
1292 if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) {
solenberg1c239d42017-09-29 06:00:28 -07001293 LOG(LS_ERROR) << "SetSendTelephoneEventPayloadType() failed to register "
1294 "send payload type";
kwiberg55b97fe2016-01-28 05:22:45 -08001295 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001296 }
kwiberg55b97fe2016-01-28 05:22:45 -08001297 }
kwiberg55b97fe2016-01-28 05:22:45 -08001298 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001299}
1300
kwiberg55b97fe2016-01-28 05:22:45 -08001301int Channel::SetLocalSSRC(unsigned int ssrc) {
kwiberg55b97fe2016-01-28 05:22:45 -08001302 if (channel_state_.Get().sending) {
solenberg1c239d42017-09-29 06:00:28 -07001303 LOG(LS_ERROR) << "SetLocalSSRC() already sending";
kwiberg55b97fe2016-01-28 05:22:45 -08001304 return -1;
1305 }
1306 _rtpRtcpModule->SetSSRC(ssrc);
1307 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001308}
1309
kwiberg55b97fe2016-01-28 05:22:45 -08001310int Channel::GetRemoteSSRC(unsigned int& ssrc) {
1311 ssrc = rtp_receiver_->SSRC();
1312 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001313}
1314
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +00001315int Channel::SetSendAudioLevelIndicationStatus(bool enable, unsigned char id) {
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +00001316 _includeAudioLevelIndication = enable;
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +00001317 return SetSendRtpHeaderExtension(enable, kRtpExtensionAudioLevel, id);
niklase@google.com470e71d2011-07-07 08:21:25 +00001318}
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +00001319
wu@webrtc.org93fd25c2014-04-24 20:33:08 +00001320int Channel::SetReceiveAudioLevelIndicationStatus(bool enable,
1321 unsigned char id) {
kwiberg55b97fe2016-01-28 05:22:45 -08001322 rtp_header_parser_->DeregisterRtpHeaderExtension(kRtpExtensionAudioLevel);
1323 if (enable &&
1324 !rtp_header_parser_->RegisterRtpHeaderExtension(kRtpExtensionAudioLevel,
1325 id)) {
wu@webrtc.org93fd25c2014-04-24 20:33:08 +00001326 return -1;
1327 }
1328 return 0;
1329}
1330
Stefan Holmerb86d4e42015-12-07 10:26:18 +01001331void Channel::EnableSendTransportSequenceNumber(int id) {
1332 int ret =
1333 SetSendRtpHeaderExtension(true, kRtpExtensionTransportSequenceNumber, id);
1334 RTC_DCHECK_EQ(0, ret);
1335}
1336
stefan3313ec92016-01-21 06:32:43 -08001337void Channel::EnableReceiveTransportSequenceNumber(int id) {
1338 rtp_header_parser_->DeregisterRtpHeaderExtension(
1339 kRtpExtensionTransportSequenceNumber);
1340 bool ret = rtp_header_parser_->RegisterRtpHeaderExtension(
1341 kRtpExtensionTransportSequenceNumber, id);
1342 RTC_DCHECK(ret);
1343}
1344
stefanbba9dec2016-02-01 04:39:55 -08001345void Channel::RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -07001346 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -08001347 RtcpBandwidthObserver* bandwidth_observer) {
nisseb8f9a322017-03-27 05:36:15 -07001348 RtpPacketSender* rtp_packet_sender = transport->packet_sender();
1349 TransportFeedbackObserver* transport_feedback_observer =
1350 transport->transport_feedback_observer();
1351 PacketRouter* packet_router = transport->packet_router();
1352
stefanbba9dec2016-02-01 04:39:55 -08001353 RTC_DCHECK(rtp_packet_sender);
1354 RTC_DCHECK(transport_feedback_observer);
kwibergee89e782017-08-09 17:22:01 -07001355 RTC_DCHECK(packet_router);
1356 RTC_DCHECK(!packet_router_);
stefan7de8d642017-02-07 07:14:08 -08001357 rtcp_observer_->SetBandwidthObserver(bandwidth_observer);
stefanbba9dec2016-02-01 04:39:55 -08001358 feedback_observer_proxy_->SetTransportFeedbackObserver(
1359 transport_feedback_observer);
1360 seq_num_allocator_proxy_->SetSequenceNumberAllocator(packet_router);
1361 rtp_packet_sender_proxy_->SetPacketSender(rtp_packet_sender);
1362 _rtpRtcpModule->SetStorePacketsStatus(true, 600);
eladalon822ff2b2017-08-01 06:30:28 -07001363 constexpr bool remb_candidate = false;
1364 packet_router->AddSendRtpModule(_rtpRtcpModule.get(), remb_candidate);
Stefan Holmerb86d4e42015-12-07 10:26:18 +01001365 packet_router_ = packet_router;
1366}
1367
stefanbba9dec2016-02-01 04:39:55 -08001368void Channel::RegisterReceiverCongestionControlObjects(
1369 PacketRouter* packet_router) {
kwibergee89e782017-08-09 17:22:01 -07001370 RTC_DCHECK(packet_router);
1371 RTC_DCHECK(!packet_router_);
eladalon822ff2b2017-08-01 06:30:28 -07001372 constexpr bool remb_candidate = false;
1373 packet_router->AddReceiveRtpModule(_rtpRtcpModule.get(), remb_candidate);
stefanbba9dec2016-02-01 04:39:55 -08001374 packet_router_ = packet_router;
1375}
1376
nissefdbfdc92017-03-31 05:44:52 -07001377void Channel::ResetSenderCongestionControlObjects() {
stefanbba9dec2016-02-01 04:39:55 -08001378 RTC_DCHECK(packet_router_);
1379 _rtpRtcpModule->SetStorePacketsStatus(false, 600);
stefan7de8d642017-02-07 07:14:08 -08001380 rtcp_observer_->SetBandwidthObserver(nullptr);
stefanbba9dec2016-02-01 04:39:55 -08001381 feedback_observer_proxy_->SetTransportFeedbackObserver(nullptr);
1382 seq_num_allocator_proxy_->SetSequenceNumberAllocator(nullptr);
nissefdbfdc92017-03-31 05:44:52 -07001383 packet_router_->RemoveSendRtpModule(_rtpRtcpModule.get());
stefanbba9dec2016-02-01 04:39:55 -08001384 packet_router_ = nullptr;
1385 rtp_packet_sender_proxy_->SetPacketSender(nullptr);
1386}
1387
nissefdbfdc92017-03-31 05:44:52 -07001388void Channel::ResetReceiverCongestionControlObjects() {
1389 RTC_DCHECK(packet_router_);
1390 packet_router_->RemoveReceiveRtpModule(_rtpRtcpModule.get());
1391 packet_router_ = nullptr;
1392}
1393
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +00001394void Channel::SetRTCPStatus(bool enable) {
pbosda903ea2015-10-02 02:36:56 -07001395 _rtpRtcpModule->SetRTCPStatus(enable ? RtcpMode::kCompound : RtcpMode::kOff);
niklase@google.com470e71d2011-07-07 08:21:25 +00001396}
1397
kwiberg55b97fe2016-01-28 05:22:45 -08001398int Channel::SetRTCP_CNAME(const char cName[256]) {
kwiberg55b97fe2016-01-28 05:22:45 -08001399 if (_rtpRtcpModule->SetCNAME(cName) != 0) {
solenberg1c239d42017-09-29 06:00:28 -07001400 LOG(LS_ERROR) << "SetRTCP_CNAME() failed to set RTCP CNAME";
kwiberg55b97fe2016-01-28 05:22:45 -08001401 return -1;
1402 }
1403 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001404}
1405
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +00001406int Channel::GetRemoteRTCPReportBlocks(
1407 std::vector<ReportBlock>* report_blocks) {
1408 if (report_blocks == NULL) {
solenberg1c239d42017-09-29 06:00:28 -07001409 LOG(LS_ERROR) << "GetRemoteRTCPReportBlock()s invalid report_blocks.";
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +00001410 return -1;
1411 }
1412
1413 // Get the report blocks from the latest received RTCP Sender or Receiver
1414 // Report. Each element in the vector contains the sender's SSRC and a
1415 // report block according to RFC 3550.
1416 std::vector<RTCPReportBlock> rtcp_report_blocks;
1417 if (_rtpRtcpModule->RemoteRTCPStat(&rtcp_report_blocks) != 0) {
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +00001418 return -1;
1419 }
1420
1421 if (rtcp_report_blocks.empty())
1422 return 0;
1423
1424 std::vector<RTCPReportBlock>::const_iterator it = rtcp_report_blocks.begin();
1425 for (; it != rtcp_report_blocks.end(); ++it) {
1426 ReportBlock report_block;
srte3e69e5c2017-08-09 06:13:45 -07001427 report_block.sender_SSRC = it->sender_ssrc;
1428 report_block.source_SSRC = it->source_ssrc;
1429 report_block.fraction_lost = it->fraction_lost;
1430 report_block.cumulative_num_packets_lost = it->packets_lost;
1431 report_block.extended_highest_sequence_number =
1432 it->extended_highest_sequence_number;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +00001433 report_block.interarrival_jitter = it->jitter;
srte3e69e5c2017-08-09 06:13:45 -07001434 report_block.last_SR_timestamp = it->last_sender_report_timestamp;
1435 report_block.delay_since_last_SR = it->delay_since_last_sender_report;
henrika@webrtc.org8a2fc882012-08-22 08:53:55 +00001436 report_blocks->push_back(report_block);
1437 }
1438 return 0;
1439}
1440
kwiberg55b97fe2016-01-28 05:22:45 -08001441int Channel::GetRTPStatistics(CallStatistics& stats) {
1442 // --- RtcpStatistics
niklase@google.com470e71d2011-07-07 08:21:25 +00001443
kwiberg55b97fe2016-01-28 05:22:45 -08001444 // The jitter statistics is updated for each received RTP packet and is
1445 // based on received packets.
1446 RtcpStatistics statistics;
1447 StreamStatistician* statistician =
1448 rtp_receive_statistics_->GetStatistician(rtp_receiver_->SSRC());
Peter Boström59013bc2016-02-12 11:35:08 +01001449 if (statistician) {
1450 statistician->GetStatistics(&statistics,
1451 _rtpRtcpModule->RTCP() == RtcpMode::kOff);
kwiberg55b97fe2016-01-28 05:22:45 -08001452 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001453
kwiberg55b97fe2016-01-28 05:22:45 -08001454 stats.fractionLost = statistics.fraction_lost;
srte186d9c32017-08-04 05:03:53 -07001455 stats.cumulativeLost = statistics.packets_lost;
1456 stats.extendedMax = statistics.extended_highest_sequence_number;
kwiberg55b97fe2016-01-28 05:22:45 -08001457 stats.jitterSamples = statistics.jitter;
niklase@google.com470e71d2011-07-07 08:21:25 +00001458
kwiberg55b97fe2016-01-28 05:22:45 -08001459 // --- RTT
1460 stats.rttMs = GetRTT(true);
niklase@google.com470e71d2011-07-07 08:21:25 +00001461
kwiberg55b97fe2016-01-28 05:22:45 -08001462 // --- Data counters
niklase@google.com470e71d2011-07-07 08:21:25 +00001463
kwiberg55b97fe2016-01-28 05:22:45 -08001464 size_t bytesSent(0);
1465 uint32_t packetsSent(0);
1466 size_t bytesReceived(0);
1467 uint32_t packetsReceived(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001468
kwiberg55b97fe2016-01-28 05:22:45 -08001469 if (statistician) {
1470 statistician->GetDataCounters(&bytesReceived, &packetsReceived);
1471 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001472
kwiberg55b97fe2016-01-28 05:22:45 -08001473 if (_rtpRtcpModule->DataCountersRTP(&bytesSent, &packetsSent) != 0) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +02001474 LOG(LS_WARNING) << "GetRTPStatistics() failed to retrieve RTP datacounters"
1475 << " => output will not be complete";
kwiberg55b97fe2016-01-28 05:22:45 -08001476 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001477
kwiberg55b97fe2016-01-28 05:22:45 -08001478 stats.bytesSent = bytesSent;
1479 stats.packetsSent = packetsSent;
1480 stats.bytesReceived = bytesReceived;
1481 stats.packetsReceived = packetsReceived;
niklase@google.com470e71d2011-07-07 08:21:25 +00001482
kwiberg55b97fe2016-01-28 05:22:45 -08001483 // --- Timestamps
1484 {
1485 rtc::CritScope lock(&ts_stats_lock_);
1486 stats.capture_start_ntp_time_ms_ = capture_start_ntp_time_ms_;
1487 }
1488 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001489}
1490
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +00001491void Channel::SetNACKStatus(bool enable, int maxNumberOfPackets) {
1492 // None of these functions can fail.
Stefan Holmerb86d4e42015-12-07 10:26:18 +01001493 // If pacing is enabled we always store packets.
1494 if (!pacing_enabled_)
1495 _rtpRtcpModule->SetStorePacketsStatus(enable, maxNumberOfPackets);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +00001496 rtp_receive_statistics_->SetMaxReorderingThreshold(maxNumberOfPackets);
pwestin@webrtc.orgd30859e2013-06-06 21:09:01 +00001497 if (enable)
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +00001498 audio_coding_->EnableNack(maxNumberOfPackets);
pwestin@webrtc.orgd30859e2013-06-06 21:09:01 +00001499 else
andrew@webrtc.orgeb524d92013-09-23 23:02:24 +00001500 audio_coding_->DisableNack();
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +00001501}
1502
pwestin@webrtc.orgd30859e2013-06-06 21:09:01 +00001503// Called when we are missing one or more packets.
1504int Channel::ResendPackets(const uint16_t* sequence_numbers, int length) {
pwestin@webrtc.orgdb249952013-06-05 15:33:20 +00001505 return _rtpRtcpModule->SendNACK(sequence_numbers, length);
1506}
1507
henrikaec6fbd22017-03-31 05:43:36 -07001508void Channel::ProcessAndEncodeAudio(const AudioFrame& audio_input) {
henrika4515fa02017-05-03 08:30:15 -07001509 // Avoid posting any new tasks if sending was already stopped in StopSend().
1510 rtc::CritScope cs(&encoder_queue_lock_);
1511 if (!encoder_queue_is_active_) {
1512 return;
1513 }
henrikaec6fbd22017-03-31 05:43:36 -07001514 std::unique_ptr<AudioFrame> audio_frame(new AudioFrame());
1515 // TODO(henrika): try to avoid copying by moving ownership of audio frame
1516 // either into pool of frames or into the task itself.
1517 audio_frame->CopyFrom(audio_input);
henrika45802172017-09-28 09:39:34 +02001518 // Profile time between when the audio frame is added to the task queue and
1519 // when the task is actually executed.
1520 audio_frame->UpdateProfileTimeStamp();
henrikaec6fbd22017-03-31 05:43:36 -07001521 encoder_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(
1522 new ProcessAndEncodeAudioTask(std::move(audio_frame), this)));
niklase@google.com470e71d2011-07-07 08:21:25 +00001523}
1524
henrikaec6fbd22017-03-31 05:43:36 -07001525void Channel::ProcessAndEncodeAudio(const int16_t* audio_data,
1526 int sample_rate,
1527 size_t number_of_frames,
1528 size_t number_of_channels) {
henrika4515fa02017-05-03 08:30:15 -07001529 // Avoid posting as new task if sending was already stopped in StopSend().
1530 rtc::CritScope cs(&encoder_queue_lock_);
1531 if (!encoder_queue_is_active_) {
1532 return;
1533 }
xians@webrtc.org2f84afa2013-07-31 16:23:37 +00001534 CodecInst codec;
ossu950c1c92017-07-11 08:19:31 -07001535 const int result = GetSendCodec(codec);
henrikaec6fbd22017-03-31 05:43:36 -07001536 std::unique_ptr<AudioFrame> audio_frame(new AudioFrame());
ossu950c1c92017-07-11 08:19:31 -07001537 // TODO(ossu): Investigate how this could happen. b/62909493
1538 if (result == 0) {
1539 audio_frame->sample_rate_hz_ = std::min(codec.plfreq, sample_rate);
1540 audio_frame->num_channels_ = std::min(number_of_channels, codec.channels);
1541 } else {
1542 audio_frame->sample_rate_hz_ = sample_rate;
1543 audio_frame->num_channels_ = number_of_channels;
1544 LOG(LS_WARNING) << "Unable to get send codec for channel " << ChannelId();
1545 RTC_NOTREACHED();
1546 }
Alejandro Luebscdfe20b2015-09-23 12:49:12 -07001547 RemixAndResample(audio_data, number_of_frames, number_of_channels,
henrikaec6fbd22017-03-31 05:43:36 -07001548 sample_rate, &input_resampler_, audio_frame.get());
1549 encoder_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(
1550 new ProcessAndEncodeAudioTask(std::move(audio_frame), this)));
xians@webrtc.org2f84afa2013-07-31 16:23:37 +00001551}
1552
henrikaec6fbd22017-03-31 05:43:36 -07001553void Channel::ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input) {
1554 RTC_DCHECK_RUN_ON(encoder_queue_);
1555 RTC_DCHECK_GT(audio_input->samples_per_channel_, 0);
1556 RTC_DCHECK_LE(audio_input->num_channels_, 2);
kwiberg55b97fe2016-01-28 05:22:45 -08001557
henrika45802172017-09-28 09:39:34 +02001558 // Measure time between when the audio frame is added to the task queue and
1559 // when the task is actually executed. Goal is to keep track of unwanted
1560 // extra latency added by the task queue.
1561 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Audio.EncodingTaskQueueLatencyMs",
1562 audio_input->ElapsedProfileTimeMs());
1563
henrikaec6fbd22017-03-31 05:43:36 -07001564 bool is_muted = InputMute();
1565 AudioFrameOperations::Mute(audio_input, previous_frame_muted_, is_muted);
kwiberg55b97fe2016-01-28 05:22:45 -08001566
kwiberg55b97fe2016-01-28 05:22:45 -08001567 if (_includeAudioLevelIndication) {
1568 size_t length =
henrikaec6fbd22017-03-31 05:43:36 -07001569 audio_input->samples_per_channel_ * audio_input->num_channels_;
yujo36b1a5f2017-06-12 12:45:32 -07001570 RTC_CHECK_LE(length, AudioFrame::kMaxDataSizeBytes);
solenberg1c2af8e2016-03-24 10:36:00 -07001571 if (is_muted && previous_frame_muted_) {
henrik.lundin50499422016-11-29 04:26:24 -08001572 rms_level_.AnalyzeMuted(length);
kwiberg55b97fe2016-01-28 05:22:45 -08001573 } else {
henrik.lundin50499422016-11-29 04:26:24 -08001574 rms_level_.Analyze(
yujo36b1a5f2017-06-12 12:45:32 -07001575 rtc::ArrayView<const int16_t>(audio_input->data(), length));
niklase@google.com470e71d2011-07-07 08:21:25 +00001576 }
kwiberg55b97fe2016-01-28 05:22:45 -08001577 }
solenberg1c2af8e2016-03-24 10:36:00 -07001578 previous_frame_muted_ = is_muted;
niklase@google.com470e71d2011-07-07 08:21:25 +00001579
henrikaec6fbd22017-03-31 05:43:36 -07001580 // Add 10ms of raw (PCM) audio data to the encoder @ 32kHz.
niklase@google.com470e71d2011-07-07 08:21:25 +00001581
kwiberg55b97fe2016-01-28 05:22:45 -08001582 // The ACM resamples internally.
henrikaec6fbd22017-03-31 05:43:36 -07001583 audio_input->timestamp_ = _timeStamp;
kwiberg55b97fe2016-01-28 05:22:45 -08001584 // This call will trigger AudioPacketizationCallback::SendData if encoding
1585 // is done and payload is ready for packetization and transmission.
1586 // Otherwise, it will return without invoking the callback.
henrikaec6fbd22017-03-31 05:43:36 -07001587 if (audio_coding_->Add10MsData(*audio_input) < 0) {
1588 LOG(LS_ERROR) << "ACM::Add10MsData() failed for channel " << _channelId;
1589 return;
kwiberg55b97fe2016-01-28 05:22:45 -08001590 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001591
henrikaec6fbd22017-03-31 05:43:36 -07001592 _timeStamp += static_cast<uint32_t>(audio_input->samples_per_channel_);
niklase@google.com470e71d2011-07-07 08:21:25 +00001593}
1594
solenberg7602aab2016-11-14 11:30:07 -08001595void Channel::set_associate_send_channel(const ChannelOwner& channel) {
1596 RTC_DCHECK(!channel.channel() ||
1597 channel.channel()->ChannelId() != _channelId);
1598 rtc::CritScope lock(&assoc_send_channel_lock_);
1599 associate_send_channel_ = channel;
1600}
1601
Minyue2013aec2015-05-13 14:14:42 +02001602void Channel::DisassociateSendChannel(int channel_id) {
tommi31fc21f2016-01-21 10:37:37 -08001603 rtc::CritScope lock(&assoc_send_channel_lock_);
Minyue2013aec2015-05-13 14:14:42 +02001604 Channel* channel = associate_send_channel_.channel();
1605 if (channel && channel->ChannelId() == channel_id) {
1606 // If this channel is associated with a send channel of the specified
1607 // Channel ID, disassociate with it.
1608 ChannelOwner ref(NULL);
1609 associate_send_channel_ = ref;
1610 }
1611}
1612
ivoc14d5dbe2016-07-04 07:06:55 -07001613void Channel::SetRtcEventLog(RtcEventLog* event_log) {
1614 event_log_proxy_->SetEventLog(event_log);
1615}
1616
michaelt9332b7d2016-11-30 07:51:13 -08001617void Channel::SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats) {
1618 rtcp_rtt_stats_proxy_->SetRtcpRttStats(rtcp_rtt_stats);
1619}
1620
nisse284542b2017-01-10 08:58:32 -08001621void Channel::UpdateOverheadForEncoder() {
hbos3fd31fe2017-02-28 05:43:16 -08001622 size_t overhead_per_packet =
1623 transport_overhead_per_packet_ + rtp_overhead_per_packet_;
nisse284542b2017-01-10 08:58:32 -08001624 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
1625 if (*encoder) {
hbos3fd31fe2017-02-28 05:43:16 -08001626 (*encoder)->OnReceivedOverhead(overhead_per_packet);
nisse284542b2017-01-10 08:58:32 -08001627 }
1628 });
1629}
1630
1631void Channel::SetTransportOverhead(size_t transport_overhead_per_packet) {
hbos3fd31fe2017-02-28 05:43:16 -08001632 rtc::CritScope cs(&overhead_per_packet_lock_);
nisse284542b2017-01-10 08:58:32 -08001633 transport_overhead_per_packet_ = transport_overhead_per_packet;
1634 UpdateOverheadForEncoder();
michaelt79e05882016-11-08 02:50:09 -08001635}
1636
hbos3fd31fe2017-02-28 05:43:16 -08001637// TODO(solenberg): Make AudioSendStream an OverheadObserver instead.
michaeltbf65be52016-12-15 06:24:49 -08001638void Channel::OnOverheadChanged(size_t overhead_bytes_per_packet) {
hbos3fd31fe2017-02-28 05:43:16 -08001639 rtc::CritScope cs(&overhead_per_packet_lock_);
nisse284542b2017-01-10 08:58:32 -08001640 rtp_overhead_per_packet_ = overhead_bytes_per_packet;
1641 UpdateOverheadForEncoder();
michaeltbf65be52016-12-15 06:24:49 -08001642}
1643
kwiberg55b97fe2016-01-28 05:22:45 -08001644int Channel::GetNetworkStatistics(NetworkStatistics& stats) {
1645 return audio_coding_->GetNetworkStatistics(&stats);
niklase@google.com470e71d2011-07-07 08:21:25 +00001646}
1647
wu@webrtc.org24301a62013-12-13 19:17:43 +00001648void Channel::GetDecodingCallStatistics(AudioDecodingCallStats* stats) const {
1649 audio_coding_->GetDecodingCallStatistics(stats);
1650}
1651
ivoce1198e02017-09-08 08:13:19 -07001652ANAStats Channel::GetANAStatistics() const {
1653 return audio_coding_->GetANAStats();
1654}
1655
solenberg358057b2015-11-27 10:46:42 -08001656uint32_t Channel::GetDelayEstimate() const {
solenberg08b19df2017-02-15 00:42:31 -08001657 rtc::CritScope lock(&video_sync_lock_);
1658 return audio_coding_->FilteredCurrentDelayMs() + playout_delay_ms_;
deadbeef74375882015-08-13 12:09:10 -07001659}
1660
kwiberg55b97fe2016-01-28 05:22:45 -08001661int Channel::SetMinimumPlayoutDelay(int delayMs) {
kwiberg55b97fe2016-01-28 05:22:45 -08001662 if ((delayMs < kVoiceEngineMinMinPlayoutDelayMs) ||
1663 (delayMs > kVoiceEngineMaxMinPlayoutDelayMs)) {
solenberg1c239d42017-09-29 06:00:28 -07001664 LOG(LS_ERROR) << "SetMinimumPlayoutDelay() invalid min delay";
kwiberg55b97fe2016-01-28 05:22:45 -08001665 return -1;
1666 }
1667 if (audio_coding_->SetMinimumPlayoutDelay(delayMs) != 0) {
solenberg1c239d42017-09-29 06:00:28 -07001668 LOG(LS_ERROR) << "SetMinimumPlayoutDelay() failed to set min playout delay";
kwiberg55b97fe2016-01-28 05:22:45 -08001669 return -1;
1670 }
1671 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001672}
1673
pwestin@webrtc.org1de01352013-04-11 20:23:35 +00001674int Channel::GetPlayoutTimestamp(unsigned int& timestamp) {
deadbeef74375882015-08-13 12:09:10 -07001675 uint32_t playout_timestamp_rtp = 0;
1676 {
tommi31fc21f2016-01-21 10:37:37 -08001677 rtc::CritScope lock(&video_sync_lock_);
deadbeef74375882015-08-13 12:09:10 -07001678 playout_timestamp_rtp = playout_timestamp_rtp_;
1679 }
kwiberg55b97fe2016-01-28 05:22:45 -08001680 if (playout_timestamp_rtp == 0) {
solenberg1c239d42017-09-29 06:00:28 -07001681 LOG(LS_ERROR) << "GetPlayoutTimestamp() failed to retrieve timestamp";
pwestin@webrtc.org1de01352013-04-11 20:23:35 +00001682 return -1;
1683 }
deadbeef74375882015-08-13 12:09:10 -07001684 timestamp = playout_timestamp_rtp;
pwestin@webrtc.org1de01352013-04-11 20:23:35 +00001685 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001686}
1687
kwiberg55b97fe2016-01-28 05:22:45 -08001688int Channel::GetRtpRtcp(RtpRtcp** rtpRtcpModule,
1689 RtpReceiver** rtp_receiver) const {
1690 *rtpRtcpModule = _rtpRtcpModule.get();
1691 *rtp_receiver = rtp_receiver_.get();
1692 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001693}
1694
deadbeef74375882015-08-13 12:09:10 -07001695void Channel::UpdatePlayoutTimestamp(bool rtcp) {
henrik.lundin96bd5022016-04-06 04:13:56 -07001696 jitter_buffer_playout_timestamp_ = audio_coding_->PlayoutTimestamp();
deadbeef74375882015-08-13 12:09:10 -07001697
henrik.lundin96bd5022016-04-06 04:13:56 -07001698 if (!jitter_buffer_playout_timestamp_) {
1699 // This can happen if this channel has not received any RTP packets. In
1700 // this case, NetEq is not capable of computing a playout timestamp.
deadbeef74375882015-08-13 12:09:10 -07001701 return;
1702 }
1703
1704 uint16_t delay_ms = 0;
1705 if (_audioDeviceModulePtr->PlayoutDelay(&delay_ms) == -1) {
Sam Zackrissonecc51e92017-10-02 14:32:33 +02001706 LOG(LS_WARNING) << "Channel::UpdatePlayoutTimestamp() failed to read"
1707 << " playout delay from the ADM";
deadbeef74375882015-08-13 12:09:10 -07001708 return;
1709 }
1710
henrik.lundin96bd5022016-04-06 04:13:56 -07001711 RTC_DCHECK(jitter_buffer_playout_timestamp_);
1712 uint32_t playout_timestamp = *jitter_buffer_playout_timestamp_;
deadbeef74375882015-08-13 12:09:10 -07001713
1714 // Remove the playout delay.
ossue280cde2016-10-12 11:04:10 -07001715 playout_timestamp -= (delay_ms * (GetRtpTimestampRateHz() / 1000));
deadbeef74375882015-08-13 12:09:10 -07001716
deadbeef74375882015-08-13 12:09:10 -07001717 {
tommi31fc21f2016-01-21 10:37:37 -08001718 rtc::CritScope lock(&video_sync_lock_);
solenberg81d93f32017-02-14 03:44:57 -08001719 if (!rtcp) {
henrik.lundin96bd5022016-04-06 04:13:56 -07001720 playout_timestamp_rtp_ = playout_timestamp;
deadbeef74375882015-08-13 12:09:10 -07001721 }
1722 playout_delay_ms_ = delay_ms;
1723 }
1724}
1725
kwiberg55b97fe2016-01-28 05:22:45 -08001726void Channel::RegisterReceiveCodecsToRTPModule() {
Karl Wibergc62f6c72017-10-04 12:38:53 +02001727 // TODO(kwiberg): Iterate over the factory's supported codecs instead?
1728 const int nSupportedCodecs = AudioCodingModule::NumberOfCodecs();
kwiberg55b97fe2016-01-28 05:22:45 -08001729 for (int idx = 0; idx < nSupportedCodecs; idx++) {
Karl Wibergc62f6c72017-10-04 12:38:53 +02001730 CodecInst codec;
1731 if (audio_coding_->Codec(idx, &codec) == -1) {
1732 LOG(LS_WARNING) << "Unable to register codec #" << idx
1733 << " for RTP/RTCP receiver.";
1734 continue;
1735 }
1736 const SdpAudioFormat format = CodecInstToSdp(codec);
1737 if (!decoder_factory_->IsSupportedDecoder(format) ||
1738 rtp_receiver_->RegisterReceivePayload(codec.pltype, format) == -1) {
1739 LOG(LS_WARNING) << "Unable to register " << format
1740 << " for RTP/RTCP receiver.";
niklase@google.com470e71d2011-07-07 08:21:25 +00001741 }
kwiberg55b97fe2016-01-28 05:22:45 -08001742 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001743}
1744
kwiberg55b97fe2016-01-28 05:22:45 -08001745int Channel::SetSendRtpHeaderExtension(bool enable,
1746 RTPExtensionType type,
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +00001747 unsigned char id) {
1748 int error = 0;
1749 _rtpRtcpModule->DeregisterSendRtpHeaderExtension(type);
1750 if (enable) {
1751 error = _rtpRtcpModule->RegisterSendRtpHeaderExtension(type, id);
1752 }
1753 return error;
1754}
minyue@webrtc.orgc1a40a72014-05-28 09:52:06 +00001755
ossue280cde2016-10-12 11:04:10 -07001756int Channel::GetRtpTimestampRateHz() const {
1757 const auto format = audio_coding_->ReceiveFormat();
1758 // Default to the playout frequency if we've not gotten any packets yet.
1759 // TODO(ossu): Zero clockrate can only happen if we've added an external
1760 // decoder for a format we don't support internally. Remove once that way of
1761 // adding decoders is gone!
1762 return (format && format->clockrate_hz != 0)
1763 ? format->clockrate_hz
1764 : audio_coding_->PlayoutFrequency();
wu@webrtc.org94454b72014-06-05 20:34:08 +00001765}
1766
Minyue2013aec2015-05-13 14:14:42 +02001767int64_t Channel::GetRTT(bool allow_associate_channel) const {
pbosda903ea2015-10-02 02:36:56 -07001768 RtcpMode method = _rtpRtcpModule->RTCP();
1769 if (method == RtcpMode::kOff) {
minyue@webrtc.org2b58a442014-09-11 07:51:53 +00001770 return 0;
1771 }
1772 std::vector<RTCPReportBlock> report_blocks;
1773 _rtpRtcpModule->RemoteRTCPStat(&report_blocks);
Minyue2013aec2015-05-13 14:14:42 +02001774
1775 int64_t rtt = 0;
minyue@webrtc.org2b58a442014-09-11 07:51:53 +00001776 if (report_blocks.empty()) {
Minyue2013aec2015-05-13 14:14:42 +02001777 if (allow_associate_channel) {
tommi31fc21f2016-01-21 10:37:37 -08001778 rtc::CritScope lock(&assoc_send_channel_lock_);
Minyue2013aec2015-05-13 14:14:42 +02001779 Channel* channel = associate_send_channel_.channel();
1780 // Tries to get RTT from an associated channel. This is important for
1781 // receive-only channels.
1782 if (channel) {
1783 // To prevent infinite recursion and deadlock, calling GetRTT of
1784 // associate channel should always use "false" for argument:
1785 // |allow_associate_channel|.
1786 rtt = channel->GetRTT(false);
1787 }
1788 }
1789 return rtt;
minyue@webrtc.org2b58a442014-09-11 07:51:53 +00001790 }
1791
1792 uint32_t remoteSSRC = rtp_receiver_->SSRC();
1793 std::vector<RTCPReportBlock>::const_iterator it = report_blocks.begin();
1794 for (; it != report_blocks.end(); ++it) {
srte3e69e5c2017-08-09 06:13:45 -07001795 if (it->sender_ssrc == remoteSSRC)
minyue@webrtc.org2b58a442014-09-11 07:51:53 +00001796 break;
1797 }
1798 if (it == report_blocks.end()) {
1799 // We have not received packets with SSRC matching the report blocks.
1800 // To calculate RTT we try with the SSRC of the first report block.
1801 // This is very important for send-only channels where we don't know
1802 // the SSRC of the other end.
srte3e69e5c2017-08-09 06:13:45 -07001803 remoteSSRC = report_blocks[0].sender_ssrc;
minyue@webrtc.org2b58a442014-09-11 07:51:53 +00001804 }
Minyue2013aec2015-05-13 14:14:42 +02001805
pkasting@chromium.org16825b12015-01-12 21:51:21 +00001806 int64_t avg_rtt = 0;
kwiberg55b97fe2016-01-28 05:22:45 -08001807 int64_t max_rtt = 0;
pkasting@chromium.org16825b12015-01-12 21:51:21 +00001808 int64_t min_rtt = 0;
kwiberg55b97fe2016-01-28 05:22:45 -08001809 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) !=
1810 0) {
minyue@webrtc.org2b58a442014-09-11 07:51:53 +00001811 return 0;
1812 }
pkasting@chromium.org16825b12015-01-12 21:51:21 +00001813 return rtt;
minyue@webrtc.org2b58a442014-09-11 07:51:53 +00001814}
1815
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +00001816} // namespace voe
1817} // namespace webrtc