Refactor voe::Channel to not use RtpReceiver.
Analogous to https://webrtc-review.googlesource.com/c/src/+/92398, for RtpVideoStreamReceiver. Bug: webrtc:7135 Change-Id: I0639f9982da2ed80edbcf900cf14f8ae982ef80c Reviewed-on: https://webrtc-review.googlesource.com/93820 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Oskar Sundbom <ossu@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24309}
This commit is contained in:
parent
4eb4b05556
commit
30b4839d10
@ -20,7 +20,6 @@
|
||||
#include "audio/conversion.h"
|
||||
#include "call/rtp_stream_receiver_controller_interface.h"
|
||||
#include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
|
||||
#include "modules/rtp_rtcp/include/rtp_receiver.h"
|
||||
#include "modules/rtp_rtcp/include/rtp_rtcp.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
@ -73,9 +72,9 @@ std::unique_ptr<voe::ChannelProxy> CreateChannelAndProxy(
|
||||
static_cast<internal::AudioState*>(audio_state);
|
||||
return absl::make_unique<voe::ChannelProxy>(absl::make_unique<voe::Channel>(
|
||||
module_process_thread, internal_audio_state->audio_device_module(),
|
||||
nullptr /* RtcpRttStats */, event_log, config.jitter_buffer_max_packets,
|
||||
config.jitter_buffer_fast_accelerate, config.decoder_factory,
|
||||
config.codec_pair_id));
|
||||
nullptr /* RtcpRttStats */, event_log, config.rtp.remote_ssrc,
|
||||
config.jitter_buffer_max_packets, config.jitter_buffer_fast_accelerate,
|
||||
config.decoder_factory, config.codec_pair_id));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -345,9 +344,7 @@ void AudioReceiveStream::ConfigureStream(AudioReceiveStream* stream,
|
||||
channel_proxy->SetLocalSSRC(new_config.rtp.local_ssrc);
|
||||
}
|
||||
|
||||
if (first_time) {
|
||||
channel_proxy->SetRemoteSSRC(new_config.rtp.remote_ssrc);
|
||||
} else {
|
||||
if (!first_time) {
|
||||
// Remote ssrc can't be changed mid-stream.
|
||||
RTC_DCHECK_EQ(old_config.rtp.remote_ssrc, new_config.rtp.remote_ssrc);
|
||||
}
|
||||
|
||||
@ -83,7 +83,6 @@ struct ConfigHelper {
|
||||
|
||||
channel_proxy_ = new testing::StrictMock<MockVoEChannelProxy>();
|
||||
EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kLocalSsrc)).Times(1);
|
||||
EXPECT_CALL(*channel_proxy_, SetRemoteSSRC(kRemoteSsrc)).Times(1);
|
||||
EXPECT_CALL(*channel_proxy_, SetNACKStatus(true, 15)).Times(1);
|
||||
EXPECT_CALL(*channel_proxy_,
|
||||
RegisterReceiverCongestionControlObjects(&packet_router_))
|
||||
|
||||
102
audio/channel.cc
102
audio/channel.cc
@ -30,7 +30,6 @@
|
||||
#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"
|
||||
@ -344,8 +343,7 @@ int32_t Channel::OnReceivedPayloadData(const uint8_t* payloadData,
|
||||
}
|
||||
|
||||
int64_t round_trip_time = 0;
|
||||
_rtpRtcpModule->RTT(rtp_receiver_->SSRC(), &round_trip_time, NULL, NULL,
|
||||
NULL);
|
||||
_rtpRtcpModule->RTT(remote_ssrc_, &round_trip_time, NULL, NULL, NULL);
|
||||
|
||||
std::vector<uint16_t> nack_list = audio_coding_->GetNackList(round_trip_time);
|
||||
if (!nack_list.empty()) {
|
||||
@ -479,6 +477,7 @@ Channel::Channel(rtc::TaskQueue* encoder_queue,
|
||||
rtcp_rtt_stats,
|
||||
rtc_event_log,
|
||||
0,
|
||||
0,
|
||||
false,
|
||||
rtc::scoped_refptr<AudioDecoderFactory>(),
|
||||
absl::nullopt) {
|
||||
@ -490,6 +489,7 @@ Channel::Channel(ProcessThread* module_process_thread,
|
||||
AudioDeviceModule* audio_device_module,
|
||||
RtcpRttStats* rtcp_rtt_stats,
|
||||
RtcEventLog* rtc_event_log,
|
||||
uint32_t remote_ssrc,
|
||||
size_t jitter_buffer_max_packets,
|
||||
bool jitter_buffer_fast_playout,
|
||||
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
|
||||
@ -498,10 +498,7 @@ Channel::Channel(ProcessThread* module_process_thread,
|
||||
rtp_payload_registry_(new RTPPayloadRegistry()),
|
||||
rtp_receive_statistics_(
|
||||
ReceiveStatistics::Create(Clock::GetRealTimeClock())),
|
||||
rtp_receiver_(
|
||||
RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(),
|
||||
this,
|
||||
rtp_payload_registry_.get())),
|
||||
remote_ssrc_(remote_ssrc),
|
||||
_outputAudioLevel(),
|
||||
_timeStamp(0), // This is just an offset, RTP module will add it's own
|
||||
// random offset
|
||||
@ -561,7 +558,7 @@ Channel::Channel(ProcessThread* module_process_thread,
|
||||
|
||||
_rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration));
|
||||
_rtpRtcpModule->SetSendingMediaStatus(false);
|
||||
|
||||
_rtpRtcpModule->SetRemoteSSRC(remote_ssrc_);
|
||||
Init();
|
||||
}
|
||||
|
||||
@ -785,6 +782,22 @@ void Channel::OnRecoverableUplinkPacketLossRate(
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<webrtc::RtpSource> Channel::GetSources() const {
|
||||
int64_t now_ms = rtc::TimeMillis();
|
||||
std::vector<RtpSource> sources;
|
||||
{
|
||||
rtc::CritScope cs(&rtp_sources_lock_);
|
||||
sources = contributing_sources_.GetSources(now_ms);
|
||||
if (last_received_rtp_system_time_ms_ >=
|
||||
now_ms - ContributingSources::kHistoryMs) {
|
||||
sources.emplace_back(*last_received_rtp_system_time_ms_, remote_ssrc_,
|
||||
RtpSourceType::SSRC);
|
||||
sources.back().set_audio_level(last_received_rtp_audio_level_);
|
||||
}
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
void Channel::OnUplinkPacketLossRate(float packet_loss_rate) {
|
||||
if (use_twcc_plr_for_ana_)
|
||||
return;
|
||||
@ -833,7 +846,24 @@ void Channel::RegisterTransport(Transport* transport) {
|
||||
_transportPtr = transport;
|
||||
}
|
||||
|
||||
// TODO(nisse): Move receive logic up to AudioReceiveStream.
|
||||
void Channel::OnRtpPacket(const RtpPacketReceived& packet) {
|
||||
int64_t now_ms = rtc::TimeMillis();
|
||||
uint8_t audio_level;
|
||||
bool voice_activity;
|
||||
bool has_audio_level =
|
||||
packet.GetExtension<::webrtc::AudioLevel>(&voice_activity, &audio_level);
|
||||
|
||||
{
|
||||
rtc::CritScope cs(&rtp_sources_lock_);
|
||||
last_received_rtp_timestamp_ = packet.Timestamp();
|
||||
last_received_rtp_system_time_ms_ = now_ms;
|
||||
if (has_audio_level)
|
||||
last_received_rtp_audio_level_ = audio_level;
|
||||
std::vector<uint32_t> csrcs = packet.Csrcs();
|
||||
contributing_sources_.Update(now_ms, csrcs);
|
||||
}
|
||||
|
||||
RTPHeader header;
|
||||
packet.GetHeader(&header);
|
||||
|
||||
@ -861,8 +891,16 @@ bool Channel::ReceivePacket(const uint8_t* packet,
|
||||
if (!pl) {
|
||||
return false;
|
||||
}
|
||||
return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
|
||||
pl->typeSpecific);
|
||||
WebRtcRTPHeader webrtc_rtp_header = {};
|
||||
webrtc_rtp_header.header = header;
|
||||
|
||||
const size_t payload_data_length = payload_length - header.paddingLength;
|
||||
if (payload_data_length == 0) {
|
||||
webrtc_rtp_header.frameType = kEmptyFrame;
|
||||
return OnReceivedPayloadData(nullptr, 0, &webrtc_rtp_header);
|
||||
}
|
||||
return OnReceivedPayloadData(payload, payload_data_length,
|
||||
&webrtc_rtp_header);
|
||||
}
|
||||
|
||||
bool Channel::IsPacketRetransmitted(const RTPHeader& header) const {
|
||||
@ -989,19 +1027,15 @@ int Channel::SetLocalSSRC(unsigned int ssrc) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Channel::SetRemoteSSRC(uint32_t ssrc) {
|
||||
// Update ssrc so that NTP for AV sync can be updated.
|
||||
_rtpRtcpModule->SetRemoteSSRC(ssrc);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// TODO(nisse): Pass ssrc in return value instead.
|
||||
int Channel::GetRemoteSSRC(unsigned int& ssrc) {
|
||||
ssrc = rtp_receiver_->SSRC();
|
||||
ssrc = remote_ssrc_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1119,7 +1153,7 @@ int Channel::GetRTPStatistics(CallStatistics& stats) {
|
||||
// each received RTP packet.
|
||||
RtcpStatistics statistics;
|
||||
StreamStatistician* statistician =
|
||||
rtp_receive_statistics_->GetStatistician(rtp_receiver_->SSRC());
|
||||
rtp_receive_statistics_->GetStatistician(remote_ssrc_);
|
||||
if (statistician) {
|
||||
// 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.
|
||||
@ -1317,17 +1351,19 @@ RtpRtcp* Channel::GetRtpRtcp() const {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
{
|
||||
rtc::CritScope cs(&rtp_sources_lock_);
|
||||
if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_ms_) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
info.latest_received_capture_timestamp = *last_received_rtp_timestamp_;
|
||||
info.latest_receive_time_ms = *last_received_rtp_system_time_ms_;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@ -1408,25 +1444,23 @@ int64_t Channel::GetRTT(bool allow_associate_channel) const {
|
||||
return rtt;
|
||||
}
|
||||
|
||||
uint32_t remoteSSRC = rtp_receiver_->SSRC();
|
||||
std::vector<RTCPReportBlock>::const_iterator it = report_blocks.begin();
|
||||
for (; it != report_blocks.end(); ++it) {
|
||||
if (it->sender_ssrc == remoteSSRC)
|
||||
if (it->sender_ssrc == remote_ssrc_)
|
||||
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.
|
||||
remoteSSRC = report_blocks[0].sender_ssrc;
|
||||
}
|
||||
|
||||
// If we have not received packets with SSRC matching the report blocks, use
|
||||
// the SSRC of the first report block for calculating the RTT. This is very
|
||||
// important for send-only channels where we don't know the SSRC of the other
|
||||
// end.
|
||||
uint32_t ssrc =
|
||||
(it == report_blocks.end()) ? report_blocks[0].sender_ssrc : remote_ssrc_;
|
||||
|
||||
int64_t avg_rtt = 0;
|
||||
int64_t max_rtt = 0;
|
||||
int64_t min_rtt = 0;
|
||||
if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) !=
|
||||
0) {
|
||||
if (_rtpRtcpModule->RTT(ssrc, &rtt, &avg_rtt, &min_rtt, &max_rtt) != 0) {
|
||||
return 0;
|
||||
}
|
||||
return rtt;
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#include "api/audio_codecs/audio_encoder.h"
|
||||
#include "api/call/audio_sink.h"
|
||||
#include "api/call/transport.h"
|
||||
#include "api/rtpreceiverinterface.h"
|
||||
#include "audio/audio_level.h"
|
||||
#include "call/syncable.h"
|
||||
#include "common_types.h" // NOLINT(build/include)
|
||||
@ -28,8 +29,8 @@
|
||||
#include "modules/audio_processing/rms_level.h"
|
||||
#include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
|
||||
#include "modules/rtp_rtcp/include/rtp_header_parser.h"
|
||||
#include "modules/rtp_rtcp/include/rtp_receiver.h"
|
||||
#include "modules/rtp_rtcp/include/rtp_rtcp.h"
|
||||
#include "modules/rtp_rtcp/source/contributing_sources.h"
|
||||
#include "rtc_base/criticalsection.h"
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
@ -156,6 +157,7 @@ class Channel
|
||||
AudioDeviceModule* audio_device_module,
|
||||
RtcpRttStats* rtcp_rtt_stats,
|
||||
RtcEventLog* rtc_event_log,
|
||||
uint32_t remote_ssrc,
|
||||
size_t jitter_buffer_max_packets,
|
||||
bool jitter_buffer_fast_playout,
|
||||
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
|
||||
@ -223,7 +225,6 @@ class Channel
|
||||
|
||||
// RTP+RTCP
|
||||
int SetLocalSSRC(unsigned int ssrc);
|
||||
void SetRemoteSSRC(uint32_t ssrc);
|
||||
|
||||
void SetMid(const std::string& mid, int extension_id);
|
||||
int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
|
||||
@ -299,9 +300,7 @@ class Channel
|
||||
|
||||
void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate);
|
||||
|
||||
std::vector<RtpSource> GetSources() const {
|
||||
return rtp_receiver_->GetSources();
|
||||
}
|
||||
std::vector<RtpSource> GetSources() const;
|
||||
|
||||
private:
|
||||
class ProcessAndEncodeAudioTask;
|
||||
@ -343,8 +342,20 @@ class Channel
|
||||
|
||||
std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
|
||||
std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
|
||||
std::unique_ptr<RtpReceiver> rtp_receiver_;
|
||||
std::unique_ptr<RtpRtcp> _rtpRtcpModule;
|
||||
const uint32_t remote_ssrc_;
|
||||
|
||||
// Info for GetSources and GetSyncInfo is updated on network or worker thread,
|
||||
// queried on the worker thread.
|
||||
rtc::CriticalSection rtp_sources_lock_;
|
||||
ContributingSources contributing_sources_ RTC_GUARDED_BY(&rtp_sources_lock_);
|
||||
absl::optional<uint32_t> last_received_rtp_timestamp_
|
||||
RTC_GUARDED_BY(&rtp_sources_lock_);
|
||||
absl::optional<int64_t> last_received_rtp_system_time_ms_
|
||||
RTC_GUARDED_BY(&rtp_sources_lock_);
|
||||
absl::optional<uint8_t> last_received_rtp_audio_level_
|
||||
RTC_GUARDED_BY(&rtp_sources_lock_);
|
||||
|
||||
std::unique_ptr<AudioCodingModule> audio_coding_;
|
||||
AudioSinkInterface* audio_sink_ = nullptr;
|
||||
AudioLevel _outputAudioLevel;
|
||||
|
||||
@ -53,11 +53,6 @@ void ChannelProxy::SetLocalSSRC(uint32_t ssrc) {
|
||||
RTC_DCHECK_EQ(0, error);
|
||||
}
|
||||
|
||||
void ChannelProxy::SetRemoteSSRC(uint32_t ssrc) {
|
||||
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
|
||||
channel_->SetRemoteSSRC(ssrc);
|
||||
}
|
||||
|
||||
void ChannelProxy::SetMid(const std::string& mid, int extension_id) {
|
||||
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
|
||||
channel_->SetMid(mid, extension_id);
|
||||
|
||||
@ -34,7 +34,6 @@ class RtcpBandwidthObserver;
|
||||
class RtcpRttStats;
|
||||
class RtpPacketSender;
|
||||
class RtpPacketReceived;
|
||||
class RtpReceiver;
|
||||
class RtpRtcp;
|
||||
class RtpTransportControllerSendInterface;
|
||||
class Transport;
|
||||
@ -62,7 +61,6 @@ class ChannelProxy : public RtpPacketSinkInterface {
|
||||
|
||||
virtual void SetRTCPStatus(bool enable);
|
||||
virtual void SetLocalSSRC(uint32_t ssrc);
|
||||
virtual void SetRemoteSSRC(uint32_t ssrc);
|
||||
virtual void SetMid(const std::string& mid, int extension_id);
|
||||
virtual void SetRTCP_CNAME(const std::string& c_name);
|
||||
virtual void SetNACKStatus(bool enable, int max_packets);
|
||||
|
||||
@ -37,7 +37,6 @@ class MockVoEChannelProxy : public voe::ChannelProxy {
|
||||
void(rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier));
|
||||
MOCK_METHOD1(SetRTCPStatus, void(bool enable));
|
||||
MOCK_METHOD1(SetLocalSSRC, void(uint32_t ssrc));
|
||||
MOCK_METHOD1(SetRemoteSSRC, void(uint32_t ssrc));
|
||||
MOCK_METHOD1(SetRTCP_CNAME, void(const std::string& c_name));
|
||||
MOCK_METHOD2(SetNACKStatus, void(bool enable, int max_packets));
|
||||
MOCK_METHOD2(SetSendAudioLevelIndicationStatus, void(bool enable, int id));
|
||||
|
||||
@ -14,15 +14,13 @@ namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
// Set by the spec, see
|
||||
// https://www.w3.org/TR/webrtc/#dom-rtcrtpreceiver-getcontributingsources
|
||||
constexpr int64_t kHistoryMs = 10 * rtc::kNumMillisecsPerSec;
|
||||
|
||||
// Allow some stale records to accumulate before cleaning.
|
||||
constexpr int64_t kPruningIntervalMs = 15 * rtc::kNumMillisecsPerSec;
|
||||
|
||||
} // namespace
|
||||
|
||||
constexpr int64_t ContributingSources::kHistoryMs;
|
||||
|
||||
ContributingSources::ContributingSources() = default;
|
||||
ContributingSources::~ContributingSources() = default;
|
||||
|
||||
|
||||
@ -24,6 +24,10 @@ namespace webrtc {
|
||||
|
||||
class ContributingSources {
|
||||
public:
|
||||
// Set by the spec, see
|
||||
// https://www.w3.org/TR/webrtc/#dom-rtcrtpreceiver-getcontributingsources
|
||||
static constexpr int64_t kHistoryMs = 10 * rtc::kNumMillisecsPerSec;
|
||||
|
||||
ContributingSources();
|
||||
~ContributingSources();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user