2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-31 08:45:03 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-01-17 11:18:31 +01:00
|
|
|
#include "audio/channel.h"
|
2013-02-12 21:42:18 +00:00
|
|
|
|
2015-05-11 12:44:23 +02:00
|
|
|
#include <algorithm>
|
2017-09-29 21:01:42 +02:00
|
|
|
#include <map>
|
2017-10-05 12:47:06 +00:00
|
|
|
#include <memory>
|
2017-09-29 21:01:42 +02:00
|
|
|
#include <string>
|
2015-12-12 01:37:01 +01:00
|
|
|
#include <utility>
|
2017-09-29 21:01:42 +02:00
|
|
|
#include <vector>
|
2015-05-11 12:44:23 +02:00
|
|
|
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
#include "absl/memory/memory.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/array_view.h"
|
|
|
|
|
#include "audio/utility/audio_frame_operations.h"
|
|
|
|
|
#include "call/rtp_transport_controller_send_interface.h"
|
2017-10-03 16:11:34 +02:00
|
|
|
#include "logging/rtc_event_log/events/rtc_event_audio_playout.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "logging/rtc_event_log/rtc_event_log.h"
|
2017-10-03 16:11:34 +02:00
|
|
|
#include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor_config.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/codecs/audio_format_conversion.h"
|
|
|
|
|
#include "modules/audio_device/include/audio_device.h"
|
|
|
|
|
#include "modules/audio_processing/include/audio_processing.h"
|
|
|
|
|
#include "modules/pacing/packet_router.h"
|
|
|
|
|
#include "modules/rtp_rtcp/include/receive_statistics.h"
|
|
|
|
|
#include "modules/rtp_rtcp/include/rtp_payload_registry.h"
|
|
|
|
|
#include "modules/rtp_rtcp/include/rtp_receiver.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/rtp_receiver_strategy.h"
|
|
|
|
|
#include "modules/utility/include/process_thread.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/criticalsection.h"
|
|
|
|
|
#include "rtc_base/format_macros.h"
|
|
|
|
|
#include "rtc_base/location.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
|
|
|
|
#include "rtc_base/rate_limiter.h"
|
|
|
|
|
#include "rtc_base/task_queue.h"
|
|
|
|
|
#include "rtc_base/thread_checker.h"
|
|
|
|
|
#include "rtc_base/timeutils.h"
|
|
|
|
|
#include "system_wrappers/include/field_trial.h"
|
2017-09-28 09:39:34 +02:00
|
|
|
#include "system_wrappers/include/metrics.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-11-14 19:07:54 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace voe {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-04-06 12:22:38 -07:00
|
|
|
namespace {
|
|
|
|
|
|
2017-07-14 12:17:49 -07:00
|
|
|
constexpr double kAudioSampleDurationSeconds = 0.01;
|
2016-07-29 12:59:36 +02:00
|
|
|
constexpr int64_t kMaxRetransmissionWindowMs = 1000;
|
|
|
|
|
constexpr int64_t kMinRetransmissionWindowMs = 30;
|
|
|
|
|
|
2017-11-23 20:22:55 +01:00
|
|
|
// Video Sync.
|
|
|
|
|
constexpr int kVoiceEngineMinMinPlayoutDelayMs = 0;
|
|
|
|
|
constexpr int kVoiceEngineMaxMinPlayoutDelayMs = 10000;
|
|
|
|
|
|
2016-04-06 12:22:38 -07:00
|
|
|
} // namespace
|
|
|
|
|
|
2016-03-11 03:06:41 -08:00
|
|
|
const int kTelephoneEventAttenuationdB = 10;
|
|
|
|
|
|
2016-07-04 07:06:55 -07:00
|
|
|
class RtcEventLogProxy final : public webrtc::RtcEventLog {
|
|
|
|
|
public:
|
|
|
|
|
RtcEventLogProxy() : event_log_(nullptr) {}
|
|
|
|
|
|
2017-11-20 17:38:14 +01:00
|
|
|
bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
|
|
|
|
|
int64_t output_period_ms) override {
|
2017-10-04 13:18:26 +02:00
|
|
|
RTC_NOTREACHED();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-04 07:06:55 -07:00
|
|
|
void StopLogging() override { RTC_NOTREACHED(); }
|
|
|
|
|
|
2017-10-03 16:11:34 +02:00
|
|
|
void Log(std::unique_ptr<RtcEvent> event) override {
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
if (event_log_) {
|
|
|
|
|
event_log_->Log(std::move(event));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-04 07:06:55 -07:00
|
|
|
void SetEventLog(RtcEventLog* event_log) {
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
event_log_ = event_log;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
rtc::CriticalSection crit_;
|
2017-09-09 04:17:22 -07:00
|
|
|
RtcEventLog* event_log_ RTC_GUARDED_BY(crit_);
|
2016-07-04 07:06:55 -07:00
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogProxy);
|
|
|
|
|
};
|
|
|
|
|
|
2015-12-07 10:26:18 +01:00
|
|
|
class TransportFeedbackProxy : public TransportFeedbackObserver {
|
|
|
|
|
public:
|
|
|
|
|
TransportFeedbackProxy() : feedback_observer_(nullptr) {
|
|
|
|
|
pacer_thread_.DetachFromThread();
|
|
|
|
|
network_thread_.DetachFromThread();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetTransportFeedbackObserver(
|
|
|
|
|
TransportFeedbackObserver* feedback_observer) {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
feedback_observer_ = feedback_observer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Implements TransportFeedbackObserver.
|
2017-03-23 11:04:48 -07:00
|
|
|
void AddPacket(uint32_t ssrc,
|
|
|
|
|
uint16_t sequence_number,
|
2015-12-07 10:26:18 +01:00
|
|
|
size_t length,
|
2017-02-23 02:56:13 -08:00
|
|
|
const PacedPacketInfo& pacing_info) override {
|
2015-12-07 10:26:18 +01:00
|
|
|
RTC_DCHECK(pacer_thread_.CalledOnValidThread());
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
if (feedback_observer_)
|
2017-03-23 11:04:48 -07:00
|
|
|
feedback_observer_->AddPacket(ssrc, sequence_number, length, pacing_info);
|
2015-12-07 10:26:18 +01:00
|
|
|
}
|
2017-02-23 02:56:13 -08:00
|
|
|
|
2015-12-07 10:26:18 +01:00
|
|
|
void OnTransportFeedback(const rtcp::TransportFeedback& feedback) override {
|
|
|
|
|
RTC_DCHECK(network_thread_.CalledOnValidThread());
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
2016-10-18 09:40:34 -07:00
|
|
|
if (feedback_observer_)
|
|
|
|
|
feedback_observer_->OnTransportFeedback(feedback);
|
2016-09-07 09:58:20 +02:00
|
|
|
}
|
2015-12-07 10:26:18 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
rtc::CriticalSection crit_;
|
|
|
|
|
rtc::ThreadChecker thread_checker_;
|
|
|
|
|
rtc::ThreadChecker pacer_thread_;
|
|
|
|
|
rtc::ThreadChecker network_thread_;
|
2017-09-09 04:17:22 -07:00
|
|
|
TransportFeedbackObserver* feedback_observer_ RTC_GUARDED_BY(&crit_);
|
2015-12-07 10:26:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TransportSequenceNumberProxy : public TransportSequenceNumberAllocator {
|
|
|
|
|
public:
|
|
|
|
|
TransportSequenceNumberProxy() : seq_num_allocator_(nullptr) {
|
|
|
|
|
pacer_thread_.DetachFromThread();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetSequenceNumberAllocator(
|
|
|
|
|
TransportSequenceNumberAllocator* seq_num_allocator) {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
seq_num_allocator_ = seq_num_allocator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Implements TransportSequenceNumberAllocator.
|
|
|
|
|
uint16_t AllocateSequenceNumber() override {
|
|
|
|
|
RTC_DCHECK(pacer_thread_.CalledOnValidThread());
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
if (!seq_num_allocator_)
|
|
|
|
|
return 0;
|
|
|
|
|
return seq_num_allocator_->AllocateSequenceNumber();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
rtc::CriticalSection crit_;
|
|
|
|
|
rtc::ThreadChecker thread_checker_;
|
|
|
|
|
rtc::ThreadChecker pacer_thread_;
|
2017-09-09 04:17:22 -07:00
|
|
|
TransportSequenceNumberAllocator* seq_num_allocator_ RTC_GUARDED_BY(&crit_);
|
2015-12-07 10:26:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RtpPacketSenderProxy : public RtpPacketSender {
|
|
|
|
|
public:
|
2016-01-28 05:22:45 -08:00
|
|
|
RtpPacketSenderProxy() : rtp_packet_sender_(nullptr) {}
|
2015-12-07 10:26:18 +01:00
|
|
|
|
|
|
|
|
void SetPacketSender(RtpPacketSender* rtp_packet_sender) {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
rtp_packet_sender_ = rtp_packet_sender;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Implements RtpPacketSender.
|
|
|
|
|
void InsertPacket(Priority priority,
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
uint16_t sequence_number,
|
|
|
|
|
int64_t capture_time_ms,
|
|
|
|
|
size_t bytes,
|
|
|
|
|
bool retransmission) override {
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
if (rtp_packet_sender_) {
|
|
|
|
|
rtp_packet_sender_->InsertPacket(priority, ssrc, sequence_number,
|
|
|
|
|
capture_time_ms, bytes, retransmission);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-20 10:37:47 +02:00
|
|
|
void SetAccountForAudioPackets(bool account_for_audio) override {
|
|
|
|
|
RTC_NOTREACHED();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-07 10:26:18 +01:00
|
|
|
private:
|
|
|
|
|
rtc::ThreadChecker thread_checker_;
|
|
|
|
|
rtc::CriticalSection crit_;
|
2017-09-09 04:17:22 -07:00
|
|
|
RtpPacketSender* rtp_packet_sender_ RTC_GUARDED_BY(&crit_);
|
2015-12-07 10:26:18 +01:00
|
|
|
};
|
|
|
|
|
|
2015-02-17 12:57:14 +00:00
|
|
|
class VoERtcpObserver : public RtcpBandwidthObserver {
|
2014-05-28 09:52:06 +00:00
|
|
|
public:
|
2017-02-07 07:14:08 -08:00
|
|
|
explicit VoERtcpObserver(Channel* owner)
|
|
|
|
|
: owner_(owner), bandwidth_observer_(nullptr) {}
|
2015-02-17 12:57:14 +00:00
|
|
|
virtual ~VoERtcpObserver() {}
|
|
|
|
|
|
2017-02-07 07:14:08 -08:00
|
|
|
void SetBandwidthObserver(RtcpBandwidthObserver* bandwidth_observer) {
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
bandwidth_observer_ = bandwidth_observer;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 12:57:14 +00:00
|
|
|
void OnReceivedEstimatedBitrate(uint32_t bitrate) override {
|
2017-02-07 07:14:08 -08:00
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
if (bandwidth_observer_) {
|
|
|
|
|
bandwidth_observer_->OnReceivedEstimatedBitrate(bitrate);
|
|
|
|
|
}
|
2015-02-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks,
|
|
|
|
|
int64_t rtt,
|
|
|
|
|
int64_t now_ms) override {
|
2017-02-07 07:14:08 -08:00
|
|
|
{
|
|
|
|
|
rtc::CritScope lock(&crit_);
|
|
|
|
|
if (bandwidth_observer_) {
|
|
|
|
|
bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, rtt,
|
|
|
|
|
now_ms);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-17 12:57:14 +00:00
|
|
|
// TODO(mflodman): Do we need to aggregate reports here or can we jut send
|
|
|
|
|
// what we get? I.e. do we ever get multiple reports bundled into one RTCP
|
|
|
|
|
// report for VoiceEngine?
|
|
|
|
|
if (report_blocks.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int fraction_lost_aggregate = 0;
|
|
|
|
|
int total_number_of_packets = 0;
|
|
|
|
|
|
|
|
|
|
// If receiving multiple report blocks, calculate the weighted average based
|
|
|
|
|
// on the number of packets a report refers to.
|
|
|
|
|
for (ReportBlockList::const_iterator block_it = report_blocks.begin();
|
|
|
|
|
block_it != report_blocks.end(); ++block_it) {
|
|
|
|
|
// Find the previous extended high sequence number for this remote SSRC,
|
|
|
|
|
// to calculate the number of RTP packets this report refers to. Ignore if
|
|
|
|
|
// we haven't seen this SSRC before.
|
|
|
|
|
std::map<uint32_t, uint32_t>::iterator seq_num_it =
|
2017-08-09 06:13:45 -07:00
|
|
|
extended_max_sequence_number_.find(block_it->source_ssrc);
|
2015-02-17 12:57:14 +00:00
|
|
|
int number_of_packets = 0;
|
|
|
|
|
if (seq_num_it != extended_max_sequence_number_.end()) {
|
2017-08-09 06:13:45 -07:00
|
|
|
number_of_packets =
|
|
|
|
|
block_it->extended_highest_sequence_number - seq_num_it->second;
|
2015-02-17 12:57:14 +00:00
|
|
|
}
|
2017-08-09 06:13:45 -07:00
|
|
|
fraction_lost_aggregate += number_of_packets * block_it->fraction_lost;
|
2015-02-17 12:57:14 +00:00
|
|
|
total_number_of_packets += number_of_packets;
|
|
|
|
|
|
2017-08-09 06:13:45 -07:00
|
|
|
extended_max_sequence_number_[block_it->source_ssrc] =
|
|
|
|
|
block_it->extended_highest_sequence_number;
|
2015-02-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
int weighted_fraction_lost = 0;
|
|
|
|
|
if (total_number_of_packets > 0) {
|
2016-01-28 05:22:45 -08:00
|
|
|
weighted_fraction_lost =
|
|
|
|
|
(fraction_lost_aggregate + total_number_of_packets / 2) /
|
|
|
|
|
total_number_of_packets;
|
2015-02-17 12:57:14 +00:00
|
|
|
}
|
2017-03-23 11:04:48 -07:00
|
|
|
owner_->OnUplinkPacketLossRate(weighted_fraction_lost / 255.0f);
|
2014-05-28 09:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Channel* owner_;
|
2015-02-17 12:57:14 +00:00
|
|
|
// Maps remote side ssrc to extended highest sequence number received.
|
|
|
|
|
std::map<uint32_t, uint32_t> extended_max_sequence_number_;
|
2017-02-07 07:14:08 -08:00
|
|
|
rtc::CriticalSection crit_;
|
2017-09-09 04:17:22 -07:00
|
|
|
RtcpBandwidthObserver* bandwidth_observer_ RTC_GUARDED_BY(crit_);
|
2014-05-28 09:52:06 +00:00
|
|
|
};
|
|
|
|
|
|
2017-03-31 05:43:36 -07:00
|
|
|
class Channel::ProcessAndEncodeAudioTask : public rtc::QueuedTask {
|
|
|
|
|
public:
|
|
|
|
|
ProcessAndEncodeAudioTask(std::unique_ptr<AudioFrame> audio_frame,
|
|
|
|
|
Channel* channel)
|
|
|
|
|
: audio_frame_(std::move(audio_frame)), channel_(channel) {
|
|
|
|
|
RTC_DCHECK(channel_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool Run() override {
|
|
|
|
|
RTC_DCHECK_RUN_ON(channel_->encoder_queue_);
|
|
|
|
|
channel_->ProcessAndEncodeAudioOnTaskQueue(audio_frame_.get());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<AudioFrame> audio_frame_;
|
|
|
|
|
Channel* const channel_;
|
|
|
|
|
};
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int32_t Channel::SendData(FrameType frameType,
|
|
|
|
|
uint8_t payloadType,
|
|
|
|
|
uint32_t timeStamp,
|
|
|
|
|
const uint8_t* payloadData,
|
|
|
|
|
size_t payloadSize,
|
|
|
|
|
const RTPFragmentationHeader* fragmentation) {
|
2017-03-31 05:43:36 -07:00
|
|
|
RTC_DCHECK_RUN_ON(encoder_queue_);
|
2016-01-28 05:22:45 -08:00
|
|
|
if (_includeAudioLevelIndication) {
|
|
|
|
|
// Store current audio level in the RTP/RTCP module.
|
|
|
|
|
// The level will be used in combination with voice-activity state
|
|
|
|
|
// (frameType) to add an RTP header extension
|
2016-11-29 04:26:24 -08:00
|
|
|
_rtpRtcpModule->SetAudioLevel(rms_level_.Average());
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// Push data from ACM to RTP/RTCP-module to deliver audio frame for
|
|
|
|
|
// packetization.
|
|
|
|
|
// This call will trigger Transport::SendPacket() from the RTP/RTCP module.
|
2016-08-02 17:46:41 -07:00
|
|
|
if (!_rtpRtcpModule->SendOutgoingData(
|
2016-01-28 05:22:45 -08:00
|
|
|
(FrameType&)frameType, payloadType, timeStamp,
|
|
|
|
|
// Leaving the time when this frame was
|
|
|
|
|
// received from the capture device as
|
|
|
|
|
// undefined for voice for now.
|
2016-08-02 17:46:41 -07:00
|
|
|
-1, payloadData, payloadSize, fragmentation, nullptr, nullptr)) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR)
|
2017-11-09 11:09:25 +01:00
|
|
|
<< "Channel::SendData() failed to send data to RTP/RTCP module";
|
2016-01-28 05:22:45 -08:00
|
|
|
return -1;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-02 03:39:33 -07:00
|
|
|
bool Channel::SendRtp(const uint8_t* data,
|
|
|
|
|
size_t len,
|
|
|
|
|
const PacketOptions& options) {
|
2016-01-28 05:22:45 -08:00
|
|
|
rtc::CritScope cs(&_callbackCritSect);
|
2013-10-18 21:10:51 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
if (_transportPtr == NULL) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR)
|
2017-11-09 11:09:25 +01:00
|
|
|
<< "Channel::SendPacket() failed to send RTP packet due to"
|
|
|
|
|
<< " invalid transport object";
|
2016-01-28 05:22:45 -08:00
|
|
|
return false;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-01-17 11:18:31 +01:00
|
|
|
if (!_transportPtr->SendRtp(data, len, options)) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "Channel::SendPacket() RTP transmission failed";
|
2016-01-28 05:22:45 -08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
bool Channel::SendRtcp(const uint8_t* data, size_t len) {
|
|
|
|
|
rtc::CritScope cs(&_callbackCritSect);
|
|
|
|
|
if (_transportPtr == NULL) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR)
|
|
|
|
|
<< "Channel::SendRtcp() failed to send RTCP packet due to"
|
|
|
|
|
<< " invalid transport object";
|
2016-01-28 05:22:45 -08:00
|
|
|
return false;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-01-17 11:18:31 +01:00
|
|
|
int n = _transportPtr->SendRtcp(data, len);
|
2016-01-28 05:22:45 -08:00
|
|
|
if (n < 0) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "Channel::SendRtcp() transmission failed";
|
2016-01-28 05:22:45 -08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int32_t Channel::OnReceivedPayloadData(const uint8_t* payloadData,
|
|
|
|
|
size_t payloadSize,
|
|
|
|
|
const WebRtcRTPHeader* rtpHeader) {
|
|
|
|
|
if (!channel_state_.Get().playing) {
|
|
|
|
|
// Avoid inserting into NetEQ when we are not playing. Count the
|
|
|
|
|
// packet as discarded.
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// Push the incoming payload (parsed and ready for decoding) into the ACM
|
|
|
|
|
if (audio_coding_->IncomingPacket(payloadData, payloadSize, *rtpHeader) !=
|
|
|
|
|
0) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR)
|
2017-11-09 11:09:25 +01:00
|
|
|
<< "Channel::OnReceivedPayloadData() unable to push data to the ACM";
|
2016-01-28 05:22:45 -08:00
|
|
|
return -1;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int64_t round_trip_time = 0;
|
|
|
|
|
_rtpRtcpModule->RTT(rtp_receiver_->SSRC(), &round_trip_time, NULL, NULL,
|
|
|
|
|
NULL);
|
2013-08-15 23:38:54 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
std::vector<uint16_t> nack_list = audio_coding_->GetNackList(round_trip_time);
|
|
|
|
|
if (!nack_list.empty()) {
|
|
|
|
|
// Can't use nack_list.data() since it's not supported by all
|
|
|
|
|
// compilers.
|
|
|
|
|
ResendPackets(&(nack_list[0]), static_cast<int>(nack_list.size()));
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2017-09-22 06:48:10 -07:00
|
|
|
AudioMixer::Source::AudioFrameInfo Channel::GetAudioFrameWithInfo(
|
|
|
|
|
int sample_rate_hz,
|
|
|
|
|
AudioFrame* audio_frame) {
|
|
|
|
|
audio_frame->sample_rate_hz_ = sample_rate_hz;
|
|
|
|
|
|
2016-07-04 07:06:55 -07:00
|
|
|
unsigned int ssrc;
|
Reland of Delete class SSRCDatabase, and its global ssrc registry. (patchset #1 id:1 of https://codereview.webrtc.org/2700413002/ )
Reason for revert:
Intend to fix perf problem and reland.
Original issue's description:
> Revert of Delete class SSRCDatabase, and its global ssrc registry. (patchset #20 id:370001 of https://codereview.webrtc.org/2644303002/ )
>
> Reason for revert:
> Breaks webrtc_perf_tests reliably:
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/1780
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus4%29/builds/178
>
> We're actively working on getting a quick version of webrtc_perf_tests up on the trybots again to prevent breakages like this: https://bugs.chromium.org/p/webrtc/issues/detail?id=7101
>
> Original issue's description:
> > Delete class SSRCDatabase, and its global ssrc registry,
> > and the method RTPSender::GenerateNewSSRC.
> >
> > It's now mandatory for higher layers to call SetSSRC, RTPSender
> > no longer allocates any ssrc by default.
> >
> > BUG=webrtc:4306,webrtc:6887
> >
> > Review-Url: https://codereview.webrtc.org/2644303002
> > Cr-Commit-Position: refs/heads/master@{#16670}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/b78d4d13835f628e722a57abae2bf06ba3655921
>
> TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,nisse@webrtc.org
> NOTRY=True
> BUG=webrtc:4306,webrtc:6887
>
> Review-Url: https://codereview.webrtc.org/2700413002
> Cr-Commit-Position: refs/heads/master@{#16693}
> Committed: https://chromium.googlesource.com/external/webrtc/+/b5848ecbf5f7b310108546ec6b858fe93452f58e
TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,kjellander@webrtc.org,kjellander@google.com
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:4306,webrtc:6887
Review-Url: https://codereview.webrtc.org/2702203002
Cr-Commit-Position: refs/heads/master@{#16737}
2017-02-21 03:40:24 -08:00
|
|
|
RTC_CHECK_EQ(GetRemoteSSRC(ssrc), 0);
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
event_log_proxy_->Log(absl::make_unique<RtcEventAudioPlayout>(ssrc));
|
2016-01-28 05:22:45 -08:00
|
|
|
// Get 10ms raw PCM data from the ACM (mixer limits output frequency)
|
2016-05-17 12:21:55 -07:00
|
|
|
bool muted;
|
2017-09-22 06:48:10 -07:00
|
|
|
if (audio_coding_->PlayoutData10Ms(audio_frame->sample_rate_hz_, audio_frame,
|
2016-05-17 12:21:55 -07:00
|
|
|
&muted) == -1) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "Channel::GetAudioFrame() PlayoutData10Ms() failed!";
|
2016-01-28 05:22:45 -08:00
|
|
|
// In all likelihood, the audio in this frame is garbage. We return an
|
|
|
|
|
// error so that the audio mixer module doesn't add it to the mix. As
|
|
|
|
|
// a result, it won't be played out and the actions skipped here are
|
|
|
|
|
// irrelevant.
|
2017-09-22 06:48:10 -07:00
|
|
|
return AudioMixer::Source::AudioFrameInfo::kError;
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
2016-05-18 08:52:45 -07:00
|
|
|
|
|
|
|
|
if (muted) {
|
|
|
|
|
// TODO(henrik.lundin): We should be able to do better than this. But we
|
|
|
|
|
// will have to go through all the cases below where the audio samples may
|
|
|
|
|
// be used, and handle the muted case in some way.
|
2017-09-22 06:48:10 -07:00
|
|
|
AudioFrameOperations::Mute(audio_frame);
|
2016-05-18 08:52:45 -07:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
{
|
|
|
|
|
// Pass the audio buffers to an optional sink callback, before applying
|
|
|
|
|
// scaling/panning, as that applies to the mix operation.
|
|
|
|
|
// External recipients of the audio (e.g. via AudioTrack), will do their
|
|
|
|
|
// own mixing/dynamic processing.
|
|
|
|
|
rtc::CritScope cs(&_callbackCritSect);
|
|
|
|
|
if (audio_sink_) {
|
|
|
|
|
AudioSinkInterface::Data data(
|
2017-09-22 06:48:10 -07:00
|
|
|
audio_frame->data(), audio_frame->samples_per_channel_,
|
|
|
|
|
audio_frame->sample_rate_hz_, audio_frame->num_channels_,
|
|
|
|
|
audio_frame->timestamp_);
|
2016-01-28 05:22:45 -08:00
|
|
|
audio_sink_->OnData(data);
|
2015-12-12 01:37:01 +01:00
|
|
|
}
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
2015-12-12 01:37:01 +01:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
float output_gain = 1.0f;
|
|
|
|
|
{
|
|
|
|
|
rtc::CritScope cs(&volume_settings_critsect_);
|
|
|
|
|
output_gain = _outputGain;
|
|
|
|
|
}
|
2013-10-17 18:28:55 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// Output volume scaling
|
|
|
|
|
if (output_gain < 0.99f || output_gain > 1.01f) {
|
2017-03-08 01:52:20 -08:00
|
|
|
// TODO(solenberg): Combine with mute state - this can cause clicks!
|
2017-09-22 06:48:10 -07:00
|
|
|
AudioFrameOperations::ScaleWithSat(output_gain, audio_frame);
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// Measure audio level (0-9)
|
2016-05-18 08:52:45 -07:00
|
|
|
// TODO(henrik.lundin) Use the |muted| information here too.
|
2017-07-20 09:57:42 -07:00
|
|
|
// TODO(deadbeef): Use RmsLevel for |_outputAudioLevel| (see
|
2017-07-14 12:17:49 -07:00
|
|
|
// https://crbug.com/webrtc/7517).
|
2017-09-22 06:48:10 -07:00
|
|
|
_outputAudioLevel.ComputeLevel(*audio_frame, kAudioSampleDurationSeconds);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-09-22 06:48:10 -07:00
|
|
|
if (capture_start_rtp_time_stamp_ < 0 && audio_frame->timestamp_ != 0) {
|
2016-01-28 05:22:45 -08:00
|
|
|
// The first frame with a valid rtp timestamp.
|
2017-09-22 06:48:10 -07:00
|
|
|
capture_start_rtp_time_stamp_ = audio_frame->timestamp_;
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
2014-06-05 20:34:08 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
if (capture_start_rtp_time_stamp_ >= 0) {
|
2017-09-22 06:48:10 -07:00
|
|
|
// audio_frame.timestamp_ should be valid from now on.
|
2016-01-28 05:22:45 -08:00
|
|
|
|
|
|
|
|
// Compute elapsed time.
|
|
|
|
|
int64_t unwrap_timestamp =
|
2017-09-22 06:48:10 -07:00
|
|
|
rtp_ts_wraparound_handler_->Unwrap(audio_frame->timestamp_);
|
|
|
|
|
audio_frame->elapsed_time_ms_ =
|
2016-01-28 05:22:45 -08:00
|
|
|
(unwrap_timestamp - capture_start_rtp_time_stamp_) /
|
2016-10-12 11:04:10 -07:00
|
|
|
(GetRtpTimestampRateHz() / 1000);
|
2016-01-28 05:22:45 -08:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
rtc::CritScope lock(&ts_stats_lock_);
|
|
|
|
|
// Compute ntp time.
|
2017-09-22 06:48:10 -07:00
|
|
|
audio_frame->ntp_time_ms_ =
|
|
|
|
|
ntp_estimator_.Estimate(audio_frame->timestamp_);
|
2016-01-28 05:22:45 -08:00
|
|
|
// |ntp_time_ms_| won't be valid until at least 2 RTCP SRs are received.
|
2017-09-22 06:48:10 -07:00
|
|
|
if (audio_frame->ntp_time_ms_ > 0) {
|
2016-01-28 05:22:45 -08:00
|
|
|
// Compute |capture_start_ntp_time_ms_| so that
|
|
|
|
|
// |capture_start_ntp_time_ms_| + |elapsed_time_ms_| == |ntp_time_ms_|
|
|
|
|
|
capture_start_ntp_time_ms_ =
|
2017-09-22 06:48:10 -07:00
|
|
|
audio_frame->ntp_time_ms_ - audio_frame->elapsed_time_ms_;
|
2014-05-19 17:39:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
2014-05-19 17:39:11 +00:00
|
|
|
|
2017-11-02 15:01:56 +01:00
|
|
|
{
|
2017-11-29 09:14:04 +01:00
|
|
|
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.TargetJitterBufferDelayMs",
|
|
|
|
|
audio_coding_->TargetDelayMs());
|
2017-11-02 15:01:56 +01:00
|
|
|
const int jitter_buffer_delay = audio_coding_->FilteredCurrentDelayMs();
|
|
|
|
|
rtc::CritScope lock(&video_sync_lock_);
|
|
|
|
|
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverDelayEstimateMs",
|
|
|
|
|
jitter_buffer_delay + playout_delay_ms_);
|
|
|
|
|
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverJitterBufferDelayMs",
|
|
|
|
|
jitter_buffer_delay);
|
|
|
|
|
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverDeviceDelayMs",
|
|
|
|
|
playout_delay_ms_);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-22 06:48:10 -07:00
|
|
|
return muted ? AudioMixer::Source::AudioFrameInfo::kMuted
|
|
|
|
|
: AudioMixer::Source::AudioFrameInfo::kNormal;
|
2016-10-20 06:32:39 -07:00
|
|
|
}
|
|
|
|
|
|
2017-09-22 06:48:10 -07:00
|
|
|
int Channel::PreferredSampleRate() const {
|
2016-01-28 05:22:45 -08:00
|
|
|
// Return the bigger of playout and receive frequency in the ACM.
|
2017-09-22 06:48:10 -07:00
|
|
|
return std::max(audio_coding_->ReceiveFrequency(),
|
|
|
|
|
audio_coding_->PlayoutFrequency());
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-11 13:52:30 +01:00
|
|
|
Channel::Channel(rtc::TaskQueue* encoder_queue,
|
|
|
|
|
ProcessThread* module_process_thread,
|
2018-03-26 13:28:26 +02:00
|
|
|
AudioDeviceModule* audio_device_module,
|
|
|
|
|
RtcpRttStats* rtcp_rtt_stats)
|
2018-01-11 13:52:30 +01:00
|
|
|
: Channel(module_process_thread,
|
|
|
|
|
audio_device_module,
|
2018-03-26 13:28:26 +02:00
|
|
|
rtcp_rtt_stats,
|
2018-01-11 13:52:30 +01:00
|
|
|
0,
|
|
|
|
|
false,
|
2018-03-20 19:18:55 +01:00
|
|
|
rtc::scoped_refptr<AudioDecoderFactory>(),
|
2018-06-15 12:28:07 +02:00
|
|
|
absl::nullopt) {
|
2018-01-11 13:52:30 +01:00
|
|
|
RTC_DCHECK(encoder_queue);
|
|
|
|
|
encoder_queue_ = encoder_queue;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-11 13:52:30 +01:00
|
|
|
Channel::Channel(ProcessThread* module_process_thread,
|
|
|
|
|
AudioDeviceModule* audio_device_module,
|
2018-03-26 13:28:26 +02:00
|
|
|
RtcpRttStats* rtcp_rtt_stats,
|
2018-01-11 13:52:30 +01:00
|
|
|
size_t jitter_buffer_max_packets,
|
|
|
|
|
bool jitter_buffer_fast_playout,
|
2018-03-20 19:18:55 +01:00
|
|
|
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
|
2018-06-15 12:28:07 +02:00
|
|
|
absl::optional<AudioCodecPairId> codec_pair_id)
|
2018-01-11 13:52:30 +01:00
|
|
|
: event_log_proxy_(new RtcEventLogProxy()),
|
2016-11-25 06:40:25 -08:00
|
|
|
rtp_payload_registry_(new RTPPayloadRegistry()),
|
2015-12-07 10:26:18 +01:00
|
|
|
rtp_receive_statistics_(
|
|
|
|
|
ReceiveStatistics::Create(Clock::GetRealTimeClock())),
|
|
|
|
|
rtp_receiver_(
|
|
|
|
|
RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(),
|
|
|
|
|
this,
|
|
|
|
|
rtp_payload_registry_.get())),
|
|
|
|
|
_outputAudioLevel(),
|
|
|
|
|
_timeStamp(0), // This is just an offset, RTP module will add it's own
|
|
|
|
|
// random offset
|
|
|
|
|
ntp_estimator_(Clock::GetRealTimeClock()),
|
|
|
|
|
playout_timestamp_rtp_(0),
|
|
|
|
|
playout_delay_ms_(0),
|
|
|
|
|
send_sequence_number_(0),
|
|
|
|
|
rtp_ts_wraparound_handler_(new rtc::TimestampWrapAroundHandler()),
|
|
|
|
|
capture_start_rtp_time_stamp_(-1),
|
|
|
|
|
capture_start_ntp_time_ms_(-1),
|
2018-01-11 13:52:30 +01:00
|
|
|
_moduleProcessThreadPtr(module_process_thread),
|
|
|
|
|
_audioDeviceModulePtr(audio_device_module),
|
2015-12-07 10:26:18 +01:00
|
|
|
_transportPtr(NULL),
|
2016-03-24 10:36:00 -07:00
|
|
|
input_mute_(false),
|
|
|
|
|
previous_frame_muted_(false),
|
2015-12-07 10:26:18 +01:00
|
|
|
_outputGain(1.0f),
|
|
|
|
|
_includeAudioLevelIndication(false),
|
2017-01-10 08:58:32 -08:00
|
|
|
transport_overhead_per_packet_(0),
|
|
|
|
|
rtp_overhead_per_packet_(0),
|
2015-12-07 10:26:18 +01:00
|
|
|
rtcp_observer_(new VoERtcpObserver(this)),
|
2018-01-11 13:52:30 +01:00
|
|
|
associated_send_channel_(nullptr),
|
2016-02-01 04:39:55 -08:00
|
|
|
feedback_observer_proxy_(new TransportFeedbackProxy()),
|
|
|
|
|
seq_num_allocator_proxy_(new TransportSequenceNumberProxy()),
|
2016-06-13 07:34:51 -07:00
|
|
|
rtp_packet_sender_proxy_(new RtpPacketSenderProxy()),
|
2016-07-29 12:59:36 +02:00
|
|
|
retransmission_rate_limiter_(new RateLimiter(Clock::GetRealTimeClock(),
|
|
|
|
|
kMaxRetransmissionWindowMs)),
|
2017-03-28 05:03:55 -07:00
|
|
|
use_twcc_plr_for_ana_(
|
|
|
|
|
webrtc::field_trial::FindFullName("UseTwccPlrForAna") == "Enabled") {
|
2018-01-11 13:52:30 +01:00
|
|
|
RTC_DCHECK(module_process_thread);
|
|
|
|
|
RTC_DCHECK(audio_device_module);
|
|
|
|
|
AudioCodingModule::Config acm_config;
|
|
|
|
|
acm_config.decoder_factory = decoder_factory;
|
2018-03-20 19:18:55 +01:00
|
|
|
acm_config.neteq_config.codec_pair_id = codec_pair_id;
|
2018-01-11 13:52:30 +01:00
|
|
|
acm_config.neteq_config.max_packets_in_buffer = jitter_buffer_max_packets;
|
|
|
|
|
acm_config.neteq_config.enable_fast_accelerate = jitter_buffer_fast_playout;
|
2016-05-18 08:52:45 -07:00
|
|
|
acm_config.neteq_config.enable_muted_state = true;
|
2016-01-28 05:22:45 -08:00
|
|
|
audio_coding_.reset(AudioCodingModule::Create(acm_config));
|
|
|
|
|
|
|
|
|
|
_outputAudioLevel.Clear();
|
|
|
|
|
|
|
|
|
|
RtpRtcp::Configuration configuration;
|
|
|
|
|
configuration.audio = true;
|
|
|
|
|
configuration.outgoing_transport = this;
|
2016-12-15 06:24:49 -08:00
|
|
|
configuration.overhead_observer = this;
|
2016-01-28 05:22:45 -08:00
|
|
|
configuration.receive_statistics = rtp_receive_statistics_.get();
|
|
|
|
|
configuration.bandwidth_callback = rtcp_observer_.get();
|
2016-02-01 04:39:55 -08:00
|
|
|
if (pacing_enabled_) {
|
|
|
|
|
configuration.paced_sender = rtp_packet_sender_proxy_.get();
|
|
|
|
|
configuration.transport_sequence_number_allocator =
|
|
|
|
|
seq_num_allocator_proxy_.get();
|
|
|
|
|
configuration.transport_feedback_callback = feedback_observer_proxy_.get();
|
|
|
|
|
}
|
2016-07-04 07:06:55 -07:00
|
|
|
configuration.event_log = &(*event_log_proxy_);
|
2018-03-26 13:28:26 +02:00
|
|
|
configuration.rtt_stats = rtcp_rtt_stats;
|
2016-07-29 12:59:36 +02:00
|
|
|
configuration.retransmission_rate_limiter =
|
|
|
|
|
retransmission_rate_limiter_.get();
|
2016-01-28 05:22:45 -08:00
|
|
|
|
|
|
|
|
_rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration));
|
2016-02-25 16:56:48 +01:00
|
|
|
_rtpRtcpModule->SetSendingMediaStatus(false);
|
2018-01-11 13:52:30 +01:00
|
|
|
|
|
|
|
|
Init();
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Channel::~Channel() {
|
2018-01-11 13:52:30 +01:00
|
|
|
Terminate();
|
2017-03-21 02:31:51 -07:00
|
|
|
RTC_DCHECK(!channel_state_.Get().sending);
|
|
|
|
|
RTC_DCHECK(!channel_state_.Get().playing);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-11 13:52:30 +01:00
|
|
|
void Channel::Init() {
|
2016-01-28 05:22:45 -08:00
|
|
|
channel_state_.Reset();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// --- Add modules to process thread (for periodic schedulation)
|
2017-03-03 03:20:24 -08:00
|
|
|
_moduleProcessThreadPtr->RegisterModule(_rtpRtcpModule.get(), RTC_FROM_HERE);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// --- ACM initialization
|
2018-01-11 13:52:30 +01:00
|
|
|
int error = audio_coding_->InitializeReceiver();
|
|
|
|
|
RTC_DCHECK_EQ(0, error);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// --- RTP/RTCP module initialization
|
|
|
|
|
|
|
|
|
|
// Ensure that RTCP is enabled by default for the created channel.
|
|
|
|
|
// Note that, the module will keep generating RTCP until it is explicitly
|
|
|
|
|
// disabled by the user.
|
|
|
|
|
// After StopListen (when no sockets exists), RTCP packets will no longer
|
|
|
|
|
// be transmitted since the Transport object will then be invalid.
|
|
|
|
|
// RTCP is enabled by default.
|
|
|
|
|
_rtpRtcpModule->SetRTCPStatus(RtcpMode::kCompound);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-01-11 13:52:30 +01:00
|
|
|
// --- Register all permanent callbacks
|
|
|
|
|
error = audio_coding_->RegisterTransportCallback(this);
|
|
|
|
|
RTC_DCHECK_EQ(0, error);
|
2017-03-27 07:15:49 -07:00
|
|
|
}
|
|
|
|
|
|
2017-03-21 02:31:51 -07:00
|
|
|
void Channel::Terminate() {
|
|
|
|
|
RTC_DCHECK(construction_thread_.CalledOnValidThread());
|
|
|
|
|
// Must be called on the same thread as Init().
|
|
|
|
|
rtp_receive_statistics_->RegisterRtcpStatisticsCallback(NULL);
|
|
|
|
|
|
|
|
|
|
StopSend();
|
|
|
|
|
StopPlayout();
|
|
|
|
|
|
|
|
|
|
// The order to safely shutdown modules in a channel is:
|
|
|
|
|
// 1. De-register callbacks in modules
|
|
|
|
|
// 2. De-register modules in process thread
|
|
|
|
|
// 3. Destroy modules
|
2018-01-11 13:52:30 +01:00
|
|
|
int error = audio_coding_->RegisterTransportCallback(NULL);
|
|
|
|
|
RTC_DCHECK_EQ(0, error);
|
2017-03-21 02:31:51 -07:00
|
|
|
|
|
|
|
|
// De-register modules in process thread
|
|
|
|
|
if (_moduleProcessThreadPtr)
|
|
|
|
|
_moduleProcessThreadPtr->DeRegisterModule(_rtpRtcpModule.get());
|
|
|
|
|
|
|
|
|
|
// End of modules shutdown
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 13:52:30 +01:00
|
|
|
void Channel::SetSink(AudioSinkInterface* sink) {
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope cs(&_callbackCritSect);
|
2018-01-11 13:52:30 +01:00
|
|
|
audio_sink_ = sink;
|
2016-06-13 07:34:51 -07:00
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int32_t Channel::StartPlayout() {
|
|
|
|
|
if (channel_state_.Get().playing) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2012-12-12 23:00:29 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
channel_state_.SetPlaying(true);
|
2012-06-04 03:26:39 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int32_t Channel::StopPlayout() {
|
|
|
|
|
if (!channel_state_.Get().playing) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2012-12-12 23:00:29 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
channel_state_.SetPlaying(false);
|
|
|
|
|
_outputAudioLevel.Clear();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int32_t Channel::StartSend() {
|
|
|
|
|
if (channel_state_.Get().sending) {
|
2011-07-07 08:21:25 +00:00
|
|
|
return 0;
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
|
|
|
|
channel_state_.SetSending(true);
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
|
2017-02-15 00:42:31 -08:00
|
|
|
// Resume the previous sequence number which was reset by StopSend(). This
|
|
|
|
|
// needs to be done before |sending| is set to true on the RTP/RTCP module.
|
|
|
|
|
if (send_sequence_number_) {
|
|
|
|
|
_rtpRtcpModule->SetSequenceNumber(send_sequence_number_);
|
|
|
|
|
}
|
2016-02-25 16:56:48 +01:00
|
|
|
_rtpRtcpModule->SetSendingMediaStatus(true);
|
2016-01-28 05:22:45 -08:00
|
|
|
if (_rtpRtcpModule->SetSendingStatus(true) != 0) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "StartSend() RTP/RTCP failed to start sending";
|
2016-02-25 16:56:48 +01:00
|
|
|
_rtpRtcpModule->SetSendingMediaStatus(false);
|
2016-01-28 05:22:45 -08:00
|
|
|
rtc::CritScope cs(&_callbackCritSect);
|
2014-03-18 10:32:33 +00:00
|
|
|
channel_state_.SetSending(false);
|
2016-01-28 05:22:45 -08:00
|
|
|
return -1;
|
|
|
|
|
}
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
{
|
|
|
|
|
// It is now OK to start posting tasks to the encoder task queue.
|
|
|
|
|
rtc::CritScope cs(&encoder_queue_lock_);
|
|
|
|
|
encoder_queue_is_active_ = true;
|
|
|
|
|
}
|
2016-01-28 05:22:45 -08:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-31 05:43:36 -07:00
|
|
|
void Channel::StopSend() {
|
2016-01-28 05:22:45 -08:00
|
|
|
if (!channel_state_.Get().sending) {
|
2017-03-31 05:43:36 -07:00
|
|
|
return;
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
|
|
|
|
channel_state_.SetSending(false);
|
|
|
|
|
|
2017-03-31 05:43:36 -07:00
|
|
|
// Post a task to the encoder thread which sets an event when the task is
|
|
|
|
|
// executed. We know that no more encoding tasks will be added to the task
|
|
|
|
|
// queue for this channel since sending is now deactivated. It means that,
|
|
|
|
|
// if we wait for the event to bet set, we know that no more pending tasks
|
|
|
|
|
// exists and it is therfore guaranteed that the task queue will never try
|
|
|
|
|
// to acccess and invalid channel object.
|
|
|
|
|
RTC_DCHECK(encoder_queue_);
|
2017-05-03 08:30:15 -07:00
|
|
|
|
2017-03-31 05:43:36 -07:00
|
|
|
rtc::Event flush(false, false);
|
2017-05-03 08:30:15 -07:00
|
|
|
{
|
|
|
|
|
// Clear |encoder_queue_is_active_| under lock to prevent any other tasks
|
|
|
|
|
// than this final "flush task" to be posted on the queue.
|
|
|
|
|
rtc::CritScope cs(&encoder_queue_lock_);
|
|
|
|
|
encoder_queue_is_active_ = false;
|
|
|
|
|
encoder_queue_->PostTask([&flush]() { flush.Set(); });
|
|
|
|
|
}
|
2017-03-31 05:43:36 -07:00
|
|
|
flush.Wait(rtc::Event::kForever);
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// Store the sequence number to be able to pick up the same sequence for
|
|
|
|
|
// the next StartSend(). This is needed for restarting device, otherwise
|
|
|
|
|
// it might cause libSRTP to complain about packets being replayed.
|
|
|
|
|
// TODO(xians): Remove this workaround after RtpRtcpModule's refactoring
|
|
|
|
|
// CL is landed. See issue
|
|
|
|
|
// https://code.google.com/p/webrtc/issues/detail?id=2111 .
|
|
|
|
|
send_sequence_number_ = _rtpRtcpModule->SequenceNumber();
|
|
|
|
|
|
|
|
|
|
// Reset sending SSRC and sequence number and triggers direct transmission
|
|
|
|
|
// of RTCP BYE
|
|
|
|
|
if (_rtpRtcpModule->SetSendingStatus(false) == -1) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "StartSend() RTP/RTCP failed to stop sending";
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
2016-02-25 16:56:48 +01:00
|
|
|
_rtpRtcpModule->SetSendingMediaStatus(false);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2017-04-06 12:05:04 -07:00
|
|
|
bool Channel::SetEncoder(int payload_type,
|
|
|
|
|
std::unique_ptr<AudioEncoder> encoder) {
|
|
|
|
|
RTC_DCHECK_GE(payload_type, 0);
|
|
|
|
|
RTC_DCHECK_LE(payload_type, 127);
|
2017-06-09 07:30:13 -07:00
|
|
|
// TODO(ossu): Make CodecInsts up, for now: one for the RTP/RTCP module and
|
|
|
|
|
// one for for us to keep track of sample rate and number of channels, etc.
|
|
|
|
|
|
|
|
|
|
// The RTP/RTCP module needs to know the RTP timestamp rate (i.e. clockrate)
|
|
|
|
|
// as well as some other things, so we collect this info and send it along.
|
|
|
|
|
CodecInst rtp_codec;
|
|
|
|
|
rtp_codec.pltype = payload_type;
|
|
|
|
|
strncpy(rtp_codec.plname, "audio", sizeof(rtp_codec.plname));
|
|
|
|
|
rtp_codec.plname[sizeof(rtp_codec.plname) - 1] = 0;
|
2017-04-06 12:05:04 -07:00
|
|
|
// Seems unclear if it should be clock rate or sample rate. CodecInst
|
|
|
|
|
// supposedly carries the sample rate, but only clock rate seems sensible to
|
|
|
|
|
// send to the RTP/RTCP module.
|
2017-06-09 07:30:13 -07:00
|
|
|
rtp_codec.plfreq = encoder->RtpTimestampRateHz();
|
|
|
|
|
rtp_codec.pacsize = rtc::CheckedDivExact(
|
|
|
|
|
static_cast<int>(encoder->Max10MsFramesInAPacket() * rtp_codec.plfreq),
|
|
|
|
|
100);
|
|
|
|
|
rtp_codec.channels = encoder->NumChannels();
|
|
|
|
|
rtp_codec.rate = 0;
|
|
|
|
|
|
|
|
|
|
if (_rtpRtcpModule->RegisterSendPayload(rtp_codec) != 0) {
|
2017-04-06 12:05:04 -07:00
|
|
|
_rtpRtcpModule->DeRegisterSendPayload(payload_type);
|
2017-06-09 07:30:13 -07:00
|
|
|
if (_rtpRtcpModule->RegisterSendPayload(rtp_codec) != 0) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR)
|
2017-10-02 14:32:33 +02:00
|
|
|
<< "SetEncoder() failed to register codec to RTP/RTCP module";
|
2017-04-06 12:05:04 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
audio_coding_->SetEncoder(std::move(encoder));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 02:08:52 -07:00
|
|
|
void Channel::ModifyEncoder(
|
|
|
|
|
rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) {
|
|
|
|
|
audio_coding_->ModifyEncoder(modifier);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int32_t Channel::GetRecCodec(CodecInst& codec) {
|
|
|
|
|
return (audio_coding_->ReceiveCodec(&codec));
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-30 04:47:39 -08:00
|
|
|
void Channel::SetBitRate(int bitrate_bps, int64_t probing_interval_ms) {
|
2016-11-28 02:34:18 -08:00
|
|
|
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
|
|
|
|
|
if (*encoder) {
|
2017-11-16 10:57:11 +01:00
|
|
|
(*encoder)->OnReceivedUplinkBandwidth(bitrate_bps, probing_interval_ms);
|
2016-11-28 02:34:18 -08:00
|
|
|
}
|
|
|
|
|
});
|
2017-01-12 10:17:38 -08:00
|
|
|
retransmission_rate_limiter_->SetMaxRate(bitrate_bps);
|
2015-04-29 16:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
2017-03-23 11:04:48 -07:00
|
|
|
void Channel::OnTwccBasedUplinkPacketLossRate(float packet_loss_rate) {
|
|
|
|
|
if (!use_twcc_plr_for_ana_)
|
|
|
|
|
return;
|
2016-10-12 05:00:55 -07:00
|
|
|
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
|
2017-03-23 11:04:48 -07:00
|
|
|
if (*encoder) {
|
|
|
|
|
(*encoder)->OnReceivedUplinkPacketLossFraction(packet_loss_rate);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 15:29:50 -07:00
|
|
|
void Channel::OnRecoverableUplinkPacketLossRate(
|
|
|
|
|
float recoverable_packet_loss_rate) {
|
|
|
|
|
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
|
|
|
|
|
if (*encoder) {
|
|
|
|
|
(*encoder)->OnReceivedUplinkRecoverablePacketLossFraction(
|
|
|
|
|
recoverable_packet_loss_rate);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 11:04:48 -07:00
|
|
|
void Channel::OnUplinkPacketLossRate(float packet_loss_rate) {
|
|
|
|
|
if (use_twcc_plr_for_ana_)
|
|
|
|
|
return;
|
|
|
|
|
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
|
|
|
|
|
if (*encoder) {
|
|
|
|
|
(*encoder)->OnReceivedUplinkPacketLossFraction(packet_loss_rate);
|
|
|
|
|
}
|
2016-10-12 05:00:55 -07:00
|
|
|
});
|
2014-05-28 09:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-27 07:15:49 -07:00
|
|
|
void Channel::SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs) {
|
|
|
|
|
rtp_payload_registry_->SetAudioReceivePayloads(codecs);
|
|
|
|
|
audio_coding_->SetReceiveCodecs(codecs);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-12 05:00:55 -07:00
|
|
|
bool Channel::EnableAudioNetworkAdaptor(const std::string& config_string) {
|
|
|
|
|
bool success = false;
|
|
|
|
|
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
|
|
|
|
|
if (*encoder) {
|
2017-04-18 00:11:48 -07:00
|
|
|
success = (*encoder)->EnableAudioNetworkAdaptor(config_string,
|
|
|
|
|
event_log_proxy_.get());
|
2016-10-12 05:00:55 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Channel::DisableAudioNetworkAdaptor() {
|
|
|
|
|
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
|
|
|
|
|
if (*encoder)
|
|
|
|
|
(*encoder)->DisableAudioNetworkAdaptor();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Channel::SetReceiverFrameLengthRange(int min_frame_length_ms,
|
|
|
|
|
int max_frame_length_ms) {
|
|
|
|
|
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
|
|
|
|
|
if (*encoder) {
|
|
|
|
|
(*encoder)->SetReceiverFrameLengthRange(min_frame_length_ms,
|
|
|
|
|
max_frame_length_ms);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 06:00:28 -07:00
|
|
|
void Channel::RegisterTransport(Transport* transport) {
|
2016-01-28 05:22:45 -08:00
|
|
|
rtc::CritScope cs(&_callbackCritSect);
|
2016-04-29 00:57:13 -07:00
|
|
|
_transportPtr = transport;
|
2013-03-13 23:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 06:28:10 -08:00
|
|
|
void Channel::OnRtpPacket(const RtpPacketReceived& packet) {
|
|
|
|
|
RTPHeader header;
|
|
|
|
|
packet.GetHeader(&header);
|
2017-09-21 04:02:53 -07:00
|
|
|
|
|
|
|
|
// Store playout timestamp for the received RTP packet
|
|
|
|
|
UpdatePlayoutTimestamp(false);
|
|
|
|
|
|
|
|
|
|
header.payload_type_frequency =
|
|
|
|
|
rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType);
|
|
|
|
|
if (header.payload_type_frequency >= 0) {
|
2018-06-25 16:58:54 +02:00
|
|
|
rtp_receive_statistics_->IncomingPacket(header, packet.size(),
|
|
|
|
|
IsPacketRetransmitted(header));
|
2017-09-21 04:02:53 -07:00
|
|
|
|
2017-10-05 08:39:15 +02:00
|
|
|
ReceivePacket(packet.data(), packet.size(), header);
|
2017-09-21 04:02:53 -07:00
|
|
|
}
|
2013-09-06 13:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Channel::ReceivePacket(const uint8_t* packet,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t packet_length,
|
2017-10-05 08:39:15 +02:00
|
|
|
const RTPHeader& header) {
|
2013-09-06 13:40:11 +00:00
|
|
|
const uint8_t* payload = packet + header.headerLength;
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
assert(packet_length >= header.headerLength);
|
|
|
|
|
size_t payload_length = packet_length - header.headerLength;
|
2017-09-21 15:00:58 +02:00
|
|
|
const auto pl =
|
|
|
|
|
rtp_payload_registry_->PayloadTypeToPayload(header.payloadType);
|
|
|
|
|
if (!pl) {
|
2013-09-06 13:40:11 +00:00
|
|
|
return false;
|
2013-08-15 23:38:54 +00:00
|
|
|
}
|
2013-09-06 13:40:11 +00:00
|
|
|
return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
|
2017-10-05 08:39:15 +02:00
|
|
|
pl->typeSpecific);
|
2013-09-06 13:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-25 16:58:54 +02:00
|
|
|
bool Channel::IsPacketRetransmitted(const RTPHeader& header) const {
|
2013-09-06 13:40:11 +00:00
|
|
|
StreamStatistician* statistician =
|
|
|
|
|
rtp_receive_statistics_->GetStatistician(header.ssrc);
|
|
|
|
|
if (!statistician)
|
|
|
|
|
return false;
|
|
|
|
|
// Check if this is a retransmission.
|
2018-06-25 16:58:54 +02:00
|
|
|
return statistician->IsRetransmitOfOldPacket(header);
|
2013-08-15 23:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-29 00:57:13 -07:00
|
|
|
int32_t Channel::ReceivedRTCPPacket(const uint8_t* data, size_t length) {
|
2013-04-03 15:43:57 +00:00
|
|
|
// Store playout timestamp for the received RTCP packet
|
2013-04-11 20:23:35 +00:00
|
|
|
UpdatePlayoutTimestamp(true);
|
2013-04-03 15:43:57 +00:00
|
|
|
|
|
|
|
|
// Deliver RTCP packet to RTP/RTCP module for parsing
|
2017-09-13 07:53:37 -07:00
|
|
|
_rtpRtcpModule->IncomingRtcpPacket(data, length);
|
2014-05-20 22:55:01 +00:00
|
|
|
|
2015-05-13 14:14:42 +02:00
|
|
|
int64_t rtt = GetRTT(true);
|
|
|
|
|
if (rtt == 0) {
|
|
|
|
|
// Waiting for valid RTT.
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-07-29 12:59:36 +02:00
|
|
|
|
|
|
|
|
int64_t nack_window_ms = rtt;
|
|
|
|
|
if (nack_window_ms < kMinRetransmissionWindowMs) {
|
|
|
|
|
nack_window_ms = kMinRetransmissionWindowMs;
|
|
|
|
|
} else if (nack_window_ms > kMaxRetransmissionWindowMs) {
|
|
|
|
|
nack_window_ms = kMaxRetransmissionWindowMs;
|
|
|
|
|
}
|
|
|
|
|
retransmission_rate_limiter_->SetWindowSize(nack_window_ms);
|
|
|
|
|
|
2016-10-12 05:00:55 -07:00
|
|
|
// Invoke audio encoders OnReceivedRtt().
|
|
|
|
|
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
|
|
|
|
|
if (*encoder)
|
|
|
|
|
(*encoder)->OnReceivedRtt(rtt);
|
|
|
|
|
});
|
|
|
|
|
|
2015-05-13 14:14:42 +02:00
|
|
|
uint32_t ntp_secs = 0;
|
|
|
|
|
uint32_t ntp_frac = 0;
|
|
|
|
|
uint32_t rtp_timestamp = 0;
|
2016-01-28 05:22:45 -08:00
|
|
|
if (0 != _rtpRtcpModule->RemoteNTP(&ntp_secs, &ntp_frac, NULL, NULL,
|
|
|
|
|
&rtp_timestamp)) {
|
2015-05-13 14:14:42 +02:00
|
|
|
// Waiting for RTCP.
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-02 18:58:24 +00:00
|
|
|
{
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope lock(&ts_stats_lock_);
|
2014-10-09 10:52:43 +00:00
|
|
|
ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
|
2014-09-02 18:58:24 +00:00
|
|
|
}
|
2013-04-03 15:43:57 +00:00
|
|
|
return 0;
|
2013-03-13 23:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-08 01:52:20 -08:00
|
|
|
int Channel::GetSpeechOutputLevelFullRange() const {
|
|
|
|
|
return _outputAudioLevel.LevelFullRange();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-14 12:17:49 -07:00
|
|
|
double Channel::GetTotalOutputEnergy() const {
|
2017-07-20 09:57:42 -07:00
|
|
|
return _outputAudioLevel.TotalEnergy();
|
2017-07-14 12:17:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double Channel::GetTotalOutputDuration() const {
|
2017-07-20 09:57:42 -07:00
|
|
|
return _outputAudioLevel.TotalDuration();
|
2017-07-14 12:17:49 -07:00
|
|
|
}
|
|
|
|
|
|
2017-03-08 01:52:20 -08:00
|
|
|
void Channel::SetInputMute(bool enable) {
|
2016-01-28 05:22:45 -08:00
|
|
|
rtc::CritScope cs(&volume_settings_critsect_);
|
2016-03-24 10:36:00 -07:00
|
|
|
input_mute_ = enable;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-24 10:36:00 -07:00
|
|
|
bool Channel::InputMute() const {
|
2016-01-28 05:22:45 -08:00
|
|
|
rtc::CritScope cs(&volume_settings_critsect_);
|
2016-03-24 10:36:00 -07:00
|
|
|
return input_mute_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-08 01:52:20 -08:00
|
|
|
void Channel::SetChannelOutputVolumeScaling(float scaling) {
|
2016-01-28 05:22:45 -08:00
|
|
|
rtc::CritScope cs(&volume_settings_critsect_);
|
|
|
|
|
_outputGain = scaling;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 03:06:41 -08:00
|
|
|
int Channel::SendTelephoneEventOutband(int event, int duration_ms) {
|
|
|
|
|
RTC_DCHECK_LE(0, event);
|
|
|
|
|
RTC_DCHECK_GE(255, event);
|
|
|
|
|
RTC_DCHECK_LE(0, duration_ms);
|
|
|
|
|
RTC_DCHECK_GE(65535, duration_ms);
|
2016-01-28 05:22:45 -08:00
|
|
|
if (!Sending()) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2016-03-11 03:06:41 -08:00
|
|
|
if (_rtpRtcpModule->SendTelephoneEventOutband(
|
|
|
|
|
event, duration_ms, kTelephoneEventAttenuationdB) != 0) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "SendTelephoneEventOutband() failed to send event";
|
2016-01-28 05:22:45 -08:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-17 05:25:37 -08:00
|
|
|
int Channel::SetSendTelephoneEventPayloadType(int payload_type,
|
|
|
|
|
int payload_frequency) {
|
2016-03-14 08:00:37 -07:00
|
|
|
RTC_DCHECK_LE(0, payload_type);
|
|
|
|
|
RTC_DCHECK_GE(127, payload_type);
|
|
|
|
|
CodecInst codec = {0};
|
|
|
|
|
codec.pltype = payload_type;
|
2016-11-17 05:25:37 -08:00
|
|
|
codec.plfreq = payload_frequency;
|
2016-01-28 05:22:45 -08:00
|
|
|
memcpy(codec.plname, "telephone-event", 16);
|
|
|
|
|
if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) {
|
|
|
|
|
_rtpRtcpModule->DeRegisterSendPayload(codec.pltype);
|
|
|
|
|
if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR)
|
2017-11-09 11:09:25 +01:00
|
|
|
<< "SetSendTelephoneEventPayloadType() failed to register "
|
|
|
|
|
"send payload type";
|
2016-01-28 05:22:45 -08:00
|
|
|
return -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int Channel::SetLocalSSRC(unsigned int ssrc) {
|
|
|
|
|
if (channel_state_.Get().sending) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "SetLocalSSRC() already sending";
|
2016-01-28 05:22:45 -08:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
_rtpRtcpModule->SetSSRC(ssrc);
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-25 13:41:10 +02:00
|
|
|
void Channel::SetRemoteSSRC(uint32_t ssrc) {
|
|
|
|
|
// Update ssrc so that NTP for AV sync can be updated.
|
|
|
|
|
_rtpRtcpModule->SetRemoteSSRC(ssrc);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-26 10:24:32 -07:00
|
|
|
void Channel::SetMid(const std::string& mid, int extension_id) {
|
|
|
|
|
int ret = SetSendRtpHeaderExtension(true, kRtpExtensionMid, extension_id);
|
|
|
|
|
RTC_DCHECK_EQ(0, ret);
|
|
|
|
|
_rtpRtcpModule->SetMid(mid);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int Channel::GetRemoteSSRC(unsigned int& ssrc) {
|
|
|
|
|
ssrc = rtp_receiver_->SSRC();
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-06 23:49:08 +00:00
|
|
|
int Channel::SetSendAudioLevelIndicationStatus(bool enable, unsigned char id) {
|
2013-09-18 22:37:32 +00:00
|
|
|
_includeAudioLevelIndication = enable;
|
2014-03-06 23:49:08 +00:00
|
|
|
return SetSendRtpHeaderExtension(enable, kRtpExtensionAudioLevel, id);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-09-18 22:37:32 +00:00
|
|
|
|
2015-12-07 10:26:18 +01:00
|
|
|
void Channel::EnableSendTransportSequenceNumber(int id) {
|
|
|
|
|
int ret =
|
|
|
|
|
SetSendRtpHeaderExtension(true, kRtpExtensionTransportSequenceNumber, id);
|
|
|
|
|
RTC_DCHECK_EQ(0, ret);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 04:39:55 -08:00
|
|
|
void Channel::RegisterSenderCongestionControlObjects(
|
2017-03-27 05:36:15 -07:00
|
|
|
RtpTransportControllerSendInterface* transport,
|
2017-02-07 07:14:08 -08:00
|
|
|
RtcpBandwidthObserver* bandwidth_observer) {
|
2017-03-27 05:36:15 -07:00
|
|
|
RtpPacketSender* rtp_packet_sender = transport->packet_sender();
|
|
|
|
|
TransportFeedbackObserver* transport_feedback_observer =
|
|
|
|
|
transport->transport_feedback_observer();
|
|
|
|
|
PacketRouter* packet_router = transport->packet_router();
|
|
|
|
|
|
2016-02-01 04:39:55 -08:00
|
|
|
RTC_DCHECK(rtp_packet_sender);
|
|
|
|
|
RTC_DCHECK(transport_feedback_observer);
|
2017-08-09 17:22:01 -07:00
|
|
|
RTC_DCHECK(packet_router);
|
|
|
|
|
RTC_DCHECK(!packet_router_);
|
2017-02-07 07:14:08 -08:00
|
|
|
rtcp_observer_->SetBandwidthObserver(bandwidth_observer);
|
2016-02-01 04:39:55 -08:00
|
|
|
feedback_observer_proxy_->SetTransportFeedbackObserver(
|
|
|
|
|
transport_feedback_observer);
|
|
|
|
|
seq_num_allocator_proxy_->SetSequenceNumberAllocator(packet_router);
|
|
|
|
|
rtp_packet_sender_proxy_->SetPacketSender(rtp_packet_sender);
|
|
|
|
|
_rtpRtcpModule->SetStorePacketsStatus(true, 600);
|
2017-08-01 06:30:28 -07:00
|
|
|
constexpr bool remb_candidate = false;
|
|
|
|
|
packet_router->AddSendRtpModule(_rtpRtcpModule.get(), remb_candidate);
|
2015-12-07 10:26:18 +01:00
|
|
|
packet_router_ = packet_router;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 04:39:55 -08:00
|
|
|
void Channel::RegisterReceiverCongestionControlObjects(
|
|
|
|
|
PacketRouter* packet_router) {
|
2017-08-09 17:22:01 -07:00
|
|
|
RTC_DCHECK(packet_router);
|
|
|
|
|
RTC_DCHECK(!packet_router_);
|
2017-08-01 06:30:28 -07:00
|
|
|
constexpr bool remb_candidate = false;
|
|
|
|
|
packet_router->AddReceiveRtpModule(_rtpRtcpModule.get(), remb_candidate);
|
2016-02-01 04:39:55 -08:00
|
|
|
packet_router_ = packet_router;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 05:44:52 -07:00
|
|
|
void Channel::ResetSenderCongestionControlObjects() {
|
2016-02-01 04:39:55 -08:00
|
|
|
RTC_DCHECK(packet_router_);
|
|
|
|
|
_rtpRtcpModule->SetStorePacketsStatus(false, 600);
|
2017-02-07 07:14:08 -08:00
|
|
|
rtcp_observer_->SetBandwidthObserver(nullptr);
|
2016-02-01 04:39:55 -08:00
|
|
|
feedback_observer_proxy_->SetTransportFeedbackObserver(nullptr);
|
|
|
|
|
seq_num_allocator_proxy_->SetSequenceNumberAllocator(nullptr);
|
2017-03-31 05:44:52 -07:00
|
|
|
packet_router_->RemoveSendRtpModule(_rtpRtcpModule.get());
|
2016-02-01 04:39:55 -08:00
|
|
|
packet_router_ = nullptr;
|
|
|
|
|
rtp_packet_sender_proxy_->SetPacketSender(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 05:44:52 -07:00
|
|
|
void Channel::ResetReceiverCongestionControlObjects() {
|
|
|
|
|
RTC_DCHECK(packet_router_);
|
|
|
|
|
packet_router_->RemoveReceiveRtpModule(_rtpRtcpModule.get());
|
|
|
|
|
packet_router_ = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
void Channel::SetRTCPStatus(bool enable) {
|
2015-10-02 02:36:56 -07:00
|
|
|
_rtpRtcpModule->SetRTCPStatus(enable ? RtcpMode::kCompound : RtcpMode::kOff);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int Channel::SetRTCP_CNAME(const char cName[256]) {
|
|
|
|
|
if (_rtpRtcpModule->SetCNAME(cName) != 0) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "SetRTCP_CNAME() failed to set RTCP CNAME";
|
2016-01-28 05:22:45 -08:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-22 08:53:55 +00:00
|
|
|
int Channel::GetRemoteRTCPReportBlocks(
|
|
|
|
|
std::vector<ReportBlock>* report_blocks) {
|
|
|
|
|
if (report_blocks == NULL) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "GetRemoteRTCPReportBlock()s invalid report_blocks.";
|
2012-08-22 08:53:55 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the report blocks from the latest received RTCP Sender or Receiver
|
|
|
|
|
// Report. Each element in the vector contains the sender's SSRC and a
|
|
|
|
|
// report block according to RFC 3550.
|
|
|
|
|
std::vector<RTCPReportBlock> rtcp_report_blocks;
|
|
|
|
|
if (_rtpRtcpModule->RemoteRTCPStat(&rtcp_report_blocks) != 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rtcp_report_blocks.empty())
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
std::vector<RTCPReportBlock>::const_iterator it = rtcp_report_blocks.begin();
|
|
|
|
|
for (; it != rtcp_report_blocks.end(); ++it) {
|
|
|
|
|
ReportBlock report_block;
|
2017-08-09 06:13:45 -07:00
|
|
|
report_block.sender_SSRC = it->sender_ssrc;
|
|
|
|
|
report_block.source_SSRC = it->source_ssrc;
|
|
|
|
|
report_block.fraction_lost = it->fraction_lost;
|
|
|
|
|
report_block.cumulative_num_packets_lost = it->packets_lost;
|
|
|
|
|
report_block.extended_highest_sequence_number =
|
|
|
|
|
it->extended_highest_sequence_number;
|
2012-08-22 08:53:55 +00:00
|
|
|
report_block.interarrival_jitter = it->jitter;
|
2017-08-09 06:13:45 -07:00
|
|
|
report_block.last_SR_timestamp = it->last_sender_report_timestamp;
|
|
|
|
|
report_block.delay_since_last_SR = it->delay_since_last_sender_report;
|
2012-08-22 08:53:55 +00:00
|
|
|
report_blocks->push_back(report_block);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int Channel::GetRTPStatistics(CallStatistics& stats) {
|
|
|
|
|
// --- RtcpStatistics
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-06-25 15:50:26 -07:00
|
|
|
// Jitter, cumulative loss, and extended max sequence number is updated for
|
|
|
|
|
// each received RTP packet.
|
2016-01-28 05:22:45 -08:00
|
|
|
RtcpStatistics statistics;
|
|
|
|
|
StreamStatistician* statistician =
|
|
|
|
|
rtp_receive_statistics_->GetStatistician(rtp_receiver_->SSRC());
|
2016-02-12 11:35:08 +01:00
|
|
|
if (statistician) {
|
2018-06-25 15:50:26 -07:00
|
|
|
// Recompute |fraction_lost| only if RTCP is off. If it's on, then
|
|
|
|
|
// |fraction_lost| should only be recomputed when an RTCP SR or RR is sent.
|
|
|
|
|
bool update_fraction_lost = _rtpRtcpModule->RTCP() == RtcpMode::kOff;
|
|
|
|
|
statistician->GetStatistics(&statistics, update_fraction_lost);
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
stats.fractionLost = statistics.fraction_lost;
|
2017-08-04 05:03:53 -07:00
|
|
|
stats.cumulativeLost = statistics.packets_lost;
|
|
|
|
|
stats.extendedMax = statistics.extended_highest_sequence_number;
|
2016-01-28 05:22:45 -08:00
|
|
|
stats.jitterSamples = statistics.jitter;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// --- RTT
|
|
|
|
|
stats.rttMs = GetRTT(true);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// --- Data counters
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
size_t bytesSent(0);
|
|
|
|
|
uint32_t packetsSent(0);
|
|
|
|
|
size_t bytesReceived(0);
|
|
|
|
|
uint32_t packetsReceived(0);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
if (statistician) {
|
|
|
|
|
statistician->GetDataCounters(&bytesReceived, &packetsReceived);
|
|
|
|
|
}
|
2013-08-15 23:38:54 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
if (_rtpRtcpModule->DataCountersRTP(&bytesSent, &packetsSent) != 0) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_WARNING)
|
2017-11-09 11:09:25 +01:00
|
|
|
<< "GetRTPStatistics() failed to retrieve RTP datacounters"
|
|
|
|
|
<< " => output will not be complete";
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
stats.bytesSent = bytesSent;
|
|
|
|
|
stats.packetsSent = packetsSent;
|
|
|
|
|
stats.bytesReceived = bytesReceived;
|
|
|
|
|
stats.packetsReceived = packetsReceived;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// --- Timestamps
|
|
|
|
|
{
|
|
|
|
|
rtc::CritScope lock(&ts_stats_lock_);
|
|
|
|
|
stats.capture_start_ntp_time_ms_ = capture_start_ntp_time_ms_;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-06-05 15:33:20 +00:00
|
|
|
void Channel::SetNACKStatus(bool enable, int maxNumberOfPackets) {
|
|
|
|
|
// None of these functions can fail.
|
2015-12-07 10:26:18 +01:00
|
|
|
// If pacing is enabled we always store packets.
|
|
|
|
|
if (!pacing_enabled_)
|
|
|
|
|
_rtpRtcpModule->SetStorePacketsStatus(enable, maxNumberOfPackets);
|
2013-09-06 13:40:11 +00:00
|
|
|
rtp_receive_statistics_->SetMaxReorderingThreshold(maxNumberOfPackets);
|
2013-06-06 21:09:01 +00:00
|
|
|
if (enable)
|
2013-09-23 23:02:24 +00:00
|
|
|
audio_coding_->EnableNack(maxNumberOfPackets);
|
2013-06-06 21:09:01 +00:00
|
|
|
else
|
2013-09-23 23:02:24 +00:00
|
|
|
audio_coding_->DisableNack();
|
2013-06-05 15:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
2013-06-06 21:09:01 +00:00
|
|
|
// Called when we are missing one or more packets.
|
|
|
|
|
int Channel::ResendPackets(const uint16_t* sequence_numbers, int length) {
|
2013-06-05 15:33:20 +00:00
|
|
|
return _rtpRtcpModule->SendNACK(sequence_numbers, length);
|
|
|
|
|
}
|
|
|
|
|
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
void Channel::ProcessAndEncodeAudio(std::unique_ptr<AudioFrame> audio_frame) {
|
2017-05-03 08:30:15 -07:00
|
|
|
// Avoid posting any new tasks if sending was already stopped in StopSend().
|
|
|
|
|
rtc::CritScope cs(&encoder_queue_lock_);
|
|
|
|
|
if (!encoder_queue_is_active_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-09-28 09:39:34 +02:00
|
|
|
// Profile time between when the audio frame is added to the task queue and
|
|
|
|
|
// when the task is actually executed.
|
|
|
|
|
audio_frame->UpdateProfileTimeStamp();
|
2017-03-31 05:43:36 -07:00
|
|
|
encoder_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(
|
|
|
|
|
new ProcessAndEncodeAudioTask(std::move(audio_frame), this)));
|
2013-07-31 16:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-31 05:43:36 -07:00
|
|
|
void Channel::ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input) {
|
|
|
|
|
RTC_DCHECK_RUN_ON(encoder_queue_);
|
|
|
|
|
RTC_DCHECK_GT(audio_input->samples_per_channel_, 0);
|
|
|
|
|
RTC_DCHECK_LE(audio_input->num_channels_, 2);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-09-28 09:39:34 +02:00
|
|
|
// Measure time between when the audio frame is added to the task queue and
|
|
|
|
|
// when the task is actually executed. Goal is to keep track of unwanted
|
|
|
|
|
// extra latency added by the task queue.
|
|
|
|
|
RTC_HISTOGRAM_COUNTS_10000("WebRTC.Audio.EncodingTaskQueueLatencyMs",
|
|
|
|
|
audio_input->ElapsedProfileTimeMs());
|
|
|
|
|
|
2017-03-31 05:43:36 -07:00
|
|
|
bool is_muted = InputMute();
|
|
|
|
|
AudioFrameOperations::Mute(audio_input, previous_frame_muted_, is_muted);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
if (_includeAudioLevelIndication) {
|
|
|
|
|
size_t length =
|
2017-03-31 05:43:36 -07:00
|
|
|
audio_input->samples_per_channel_ * audio_input->num_channels_;
|
2017-06-12 12:45:32 -07:00
|
|
|
RTC_CHECK_LE(length, AudioFrame::kMaxDataSizeBytes);
|
2016-03-24 10:36:00 -07:00
|
|
|
if (is_muted && previous_frame_muted_) {
|
2016-11-29 04:26:24 -08:00
|
|
|
rms_level_.AnalyzeMuted(length);
|
2016-01-28 05:22:45 -08:00
|
|
|
} else {
|
2016-11-29 04:26:24 -08:00
|
|
|
rms_level_.Analyze(
|
2017-06-12 12:45:32 -07:00
|
|
|
rtc::ArrayView<const int16_t>(audio_input->data(), length));
|
2011-11-15 16:57:56 +00:00
|
|
|
}
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
2016-03-24 10:36:00 -07:00
|
|
|
previous_frame_muted_ = is_muted;
|
2011-11-15 16:57:56 +00:00
|
|
|
|
2017-03-31 05:43:36 -07:00
|
|
|
// Add 10ms of raw (PCM) audio data to the encoder @ 32kHz.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
// The ACM resamples internally.
|
2017-03-31 05:43:36 -07:00
|
|
|
audio_input->timestamp_ = _timeStamp;
|
2016-01-28 05:22:45 -08:00
|
|
|
// This call will trigger AudioPacketizationCallback::SendData if encoding
|
|
|
|
|
// is done and payload is ready for packetization and transmission.
|
|
|
|
|
// Otherwise, it will return without invoking the callback.
|
2017-03-31 05:43:36 -07:00
|
|
|
if (audio_coding_->Add10MsData(*audio_input) < 0) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "ACM::Add10MsData() failed.";
|
2017-03-31 05:43:36 -07:00
|
|
|
return;
|
2016-01-28 05:22:45 -08:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-03-31 05:43:36 -07:00
|
|
|
_timeStamp += static_cast<uint32_t>(audio_input->samples_per_channel_);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-11 13:52:30 +01:00
|
|
|
void Channel::SetAssociatedSendChannel(Channel* channel) {
|
|
|
|
|
RTC_DCHECK_NE(this, channel);
|
2016-11-14 11:30:07 -08:00
|
|
|
rtc::CritScope lock(&assoc_send_channel_lock_);
|
2018-01-11 13:52:30 +01:00
|
|
|
associated_send_channel_ = channel;
|
2015-05-13 14:14:42 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-04 07:06:55 -07:00
|
|
|
void Channel::SetRtcEventLog(RtcEventLog* event_log) {
|
|
|
|
|
event_log_proxy_->SetEventLog(event_log);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-10 08:58:32 -08:00
|
|
|
void Channel::UpdateOverheadForEncoder() {
|
2017-02-28 05:43:16 -08:00
|
|
|
size_t overhead_per_packet =
|
|
|
|
|
transport_overhead_per_packet_ + rtp_overhead_per_packet_;
|
2016-12-15 06:24:49 -08:00
|
|
|
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
|
|
|
|
|
if (*encoder) {
|
2017-02-28 05:43:16 -08:00
|
|
|
(*encoder)->OnReceivedOverhead(overhead_per_packet);
|
2016-12-15 06:24:49 -08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-10 08:58:32 -08:00
|
|
|
void Channel::SetTransportOverhead(size_t transport_overhead_per_packet) {
|
2017-02-28 05:43:16 -08:00
|
|
|
rtc::CritScope cs(&overhead_per_packet_lock_);
|
2017-01-10 08:58:32 -08:00
|
|
|
transport_overhead_per_packet_ = transport_overhead_per_packet;
|
|
|
|
|
UpdateOverheadForEncoder();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 05:43:16 -08:00
|
|
|
// TODO(solenberg): Make AudioSendStream an OverheadObserver instead.
|
2017-01-10 08:58:32 -08:00
|
|
|
void Channel::OnOverheadChanged(size_t overhead_bytes_per_packet) {
|
2017-02-28 05:43:16 -08:00
|
|
|
rtc::CritScope cs(&overhead_per_packet_lock_);
|
2017-01-10 08:58:32 -08:00
|
|
|
rtp_overhead_per_packet_ = overhead_bytes_per_packet;
|
|
|
|
|
UpdateOverheadForEncoder();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int Channel::GetNetworkStatistics(NetworkStatistics& stats) {
|
|
|
|
|
return audio_coding_->GetNetworkStatistics(&stats);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-13 19:17:43 +00:00
|
|
|
void Channel::GetDecodingCallStatistics(AudioDecodingCallStats* stats) const {
|
|
|
|
|
audio_coding_->GetDecodingCallStatistics(stats);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-08 08:13:19 -07:00
|
|
|
ANAStats Channel::GetANAStatistics() const {
|
|
|
|
|
return audio_coding_->GetANAStats();
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 10:46:42 -08:00
|
|
|
uint32_t Channel::GetDelayEstimate() const {
|
2017-02-15 00:42:31 -08:00
|
|
|
rtc::CritScope lock(&video_sync_lock_);
|
|
|
|
|
return audio_coding_->FilteredCurrentDelayMs() + playout_delay_ms_;
|
2015-08-13 12:09:10 -07:00
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int Channel::SetMinimumPlayoutDelay(int delayMs) {
|
|
|
|
|
if ((delayMs < kVoiceEngineMinMinPlayoutDelayMs) ||
|
|
|
|
|
(delayMs > kVoiceEngineMaxMinPlayoutDelayMs)) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "SetMinimumPlayoutDelay() invalid min delay";
|
2016-01-28 05:22:45 -08:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (audio_coding_->SetMinimumPlayoutDelay(delayMs) != 0) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR)
|
2017-11-09 11:09:25 +01:00
|
|
|
<< "SetMinimumPlayoutDelay() failed to set min playout delay";
|
2016-01-28 05:22:45 -08:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-11 20:23:35 +00:00
|
|
|
int Channel::GetPlayoutTimestamp(unsigned int& timestamp) {
|
2015-08-13 12:09:10 -07:00
|
|
|
uint32_t playout_timestamp_rtp = 0;
|
|
|
|
|
{
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope lock(&video_sync_lock_);
|
2015-08-13 12:09:10 -07:00
|
|
|
playout_timestamp_rtp = playout_timestamp_rtp_;
|
|
|
|
|
}
|
2016-01-28 05:22:45 -08:00
|
|
|
if (playout_timestamp_rtp == 0) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "GetPlayoutTimestamp() failed to retrieve timestamp";
|
2013-04-11 20:23:35 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2015-08-13 12:09:10 -07:00
|
|
|
timestamp = playout_timestamp_rtp;
|
2013-04-11 20:23:35 +00:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-08 10:49:16 +02:00
|
|
|
RtpRtcp* Channel::GetRtpRtcp() const {
|
|
|
|
|
return _rtpRtcpModule.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
absl::optional<Syncable::Info> Channel::GetSyncInfo() const {
|
|
|
|
|
Syncable::Info info;
|
|
|
|
|
if (!rtp_receiver_->GetLatestTimestamps(
|
|
|
|
|
&info.latest_received_capture_timestamp,
|
|
|
|
|
&info.latest_receive_time_ms)) {
|
|
|
|
|
return absl::nullopt;
|
|
|
|
|
}
|
|
|
|
|
if (_rtpRtcpModule->RemoteNTP(&info.capture_time_ntp_secs,
|
|
|
|
|
&info.capture_time_ntp_frac, nullptr, nullptr,
|
|
|
|
|
&info.capture_time_source_clock) != 0) {
|
|
|
|
|
return absl::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-08-13 12:09:10 -07:00
|
|
|
void Channel::UpdatePlayoutTimestamp(bool rtcp) {
|
2016-04-06 04:13:56 -07:00
|
|
|
jitter_buffer_playout_timestamp_ = audio_coding_->PlayoutTimestamp();
|
2015-08-13 12:09:10 -07:00
|
|
|
|
2016-04-06 04:13:56 -07:00
|
|
|
if (!jitter_buffer_playout_timestamp_) {
|
|
|
|
|
// This can happen if this channel has not received any RTP packets. In
|
|
|
|
|
// this case, NetEq is not capable of computing a playout timestamp.
|
2015-08-13 12:09:10 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t delay_ms = 0;
|
|
|
|
|
if (_audioDeviceModulePtr->PlayoutDelay(&delay_ms) == -1) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_WARNING) << "Channel::UpdatePlayoutTimestamp() failed to read"
|
|
|
|
|
<< " playout delay from the ADM";
|
2015-08-13 12:09:10 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-06 04:13:56 -07:00
|
|
|
RTC_DCHECK(jitter_buffer_playout_timestamp_);
|
|
|
|
|
uint32_t playout_timestamp = *jitter_buffer_playout_timestamp_;
|
2015-08-13 12:09:10 -07:00
|
|
|
|
|
|
|
|
// Remove the playout delay.
|
2016-10-12 11:04:10 -07:00
|
|
|
playout_timestamp -= (delay_ms * (GetRtpTimestampRateHz() / 1000));
|
2015-08-13 12:09:10 -07:00
|
|
|
|
|
|
|
|
{
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope lock(&video_sync_lock_);
|
2017-02-14 03:44:57 -08:00
|
|
|
if (!rtcp) {
|
2016-04-06 04:13:56 -07:00
|
|
|
playout_timestamp_rtp_ = playout_timestamp;
|
2015-08-13 12:09:10 -07:00
|
|
|
}
|
|
|
|
|
playout_delay_ms_ = delay_ms;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 05:22:45 -08:00
|
|
|
int Channel::SetSendRtpHeaderExtension(bool enable,
|
|
|
|
|
RTPExtensionType type,
|
2014-03-06 23:49:08 +00:00
|
|
|
unsigned char id) {
|
|
|
|
|
int error = 0;
|
|
|
|
|
_rtpRtcpModule->DeregisterSendRtpHeaderExtension(type);
|
|
|
|
|
if (enable) {
|
|
|
|
|
error = _rtpRtcpModule->RegisterSendRtpHeaderExtension(type, id);
|
|
|
|
|
}
|
|
|
|
|
return error;
|
|
|
|
|
}
|
2014-05-28 09:52:06 +00:00
|
|
|
|
2016-10-12 11:04:10 -07:00
|
|
|
int Channel::GetRtpTimestampRateHz() const {
|
|
|
|
|
const auto format = audio_coding_->ReceiveFormat();
|
|
|
|
|
// Default to the playout frequency if we've not gotten any packets yet.
|
|
|
|
|
// TODO(ossu): Zero clockrate can only happen if we've added an external
|
|
|
|
|
// decoder for a format we don't support internally. Remove once that way of
|
|
|
|
|
// adding decoders is gone!
|
|
|
|
|
return (format && format->clockrate_hz != 0)
|
|
|
|
|
? format->clockrate_hz
|
|
|
|
|
: audio_coding_->PlayoutFrequency();
|
2014-06-05 20:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-13 14:14:42 +02:00
|
|
|
int64_t Channel::GetRTT(bool allow_associate_channel) const {
|
2015-10-02 02:36:56 -07:00
|
|
|
RtcpMode method = _rtpRtcpModule->RTCP();
|
|
|
|
|
if (method == RtcpMode::kOff) {
|
2014-09-11 07:51:53 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
std::vector<RTCPReportBlock> report_blocks;
|
|
|
|
|
_rtpRtcpModule->RemoteRTCPStat(&report_blocks);
|
2015-05-13 14:14:42 +02:00
|
|
|
|
|
|
|
|
int64_t rtt = 0;
|
2014-09-11 07:51:53 +00:00
|
|
|
if (report_blocks.empty()) {
|
2015-05-13 14:14:42 +02:00
|
|
|
if (allow_associate_channel) {
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope lock(&assoc_send_channel_lock_);
|
2015-05-13 14:14:42 +02:00
|
|
|
// Tries to get RTT from an associated channel. This is important for
|
|
|
|
|
// receive-only channels.
|
2018-01-11 13:52:30 +01:00
|
|
|
if (associated_send_channel_) {
|
2015-05-13 14:14:42 +02:00
|
|
|
// To prevent infinite recursion and deadlock, calling GetRTT of
|
|
|
|
|
// associate channel should always use "false" for argument:
|
|
|
|
|
// |allow_associate_channel|.
|
2018-01-11 13:52:30 +01:00
|
|
|
rtt = associated_send_channel_->GetRTT(false);
|
2015-05-13 14:14:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rtt;
|
2014-09-11 07:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t remoteSSRC = rtp_receiver_->SSRC();
|
|
|
|
|
std::vector<RTCPReportBlock>::const_iterator it = report_blocks.begin();
|
|
|
|
|
for (; it != report_blocks.end(); ++it) {
|
2017-08-09 06:13:45 -07:00
|
|
|
if (it->sender_ssrc == remoteSSRC)
|
2014-09-11 07:51:53 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (it == report_blocks.end()) {
|
|
|
|
|
// We have not received packets with SSRC matching the report blocks.
|
|
|
|
|
// To calculate RTT we try with the SSRC of the first report block.
|
|
|
|
|
// This is very important for send-only channels where we don't know
|
|
|
|
|
// the SSRC of the other end.
|
2017-08-09 06:13:45 -07:00
|
|
|
remoteSSRC = report_blocks[0].sender_ssrc;
|
2014-09-11 07:51:53 +00:00
|
|
|
}
|
2015-05-13 14:14:42 +02:00
|
|
|
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t avg_rtt = 0;
|
2016-01-28 05:22:45 -08:00
|
|
|
int64_t max_rtt = 0;
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t min_rtt = 0;
|
2016-01-28 05:22:45 -08:00
|
|
|
if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) !=
|
|
|
|
|
0) {
|
2014-09-11 07:51:53 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2015-01-12 21:51:21 +00:00
|
|
|
return rtt;
|
2014-09-11 07:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace voe
|
|
|
|
|
} // namespace webrtc
|