Tweak ChannelSend interface, to make it closer to ChannelSendProxy

This is a preparation for deleting ChannelSendProxy. Signature is
changed on a couple of methods. Unused methods
EnableAudioNetworkAdaptor, DisableAudioNetworkAdaptor,
SetReceiverFrameLengthRange and RtpRtcpModulePtr are deleted. Some
methods are demoted to private: SendData, SendRtp, SendRtcp,
PreferredSampleRate, Sending, and OnOverheadChanged.

Bug: webrtc:9801
Change-Id: I982e72418a32e66fb5de410350b1bfebd9a3219c
Reviewed-on: https://webrtc-review.googlesource.com/c/110605
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25666}
This commit is contained in:
Niels Möller 2018-11-16 09:32:40 +01:00 committed by Commit Bot
parent 349ade3a4b
commit 2681523793
5 changed files with 89 additions and 156 deletions

View File

@ -33,6 +33,7 @@
#include "rtc_base/format_macros.h"
#include "rtc_base/location.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/rate_limiter.h"
#include "rtc_base/task_queue.h"
#include "rtc_base/thread_checker.h"
@ -557,10 +558,8 @@ void ChannelSend::Terminate() {
// End of modules shutdown
}
int32_t ChannelSend::StartSend() {
if (channel_state_.Get().sending) {
return 0;
}
void ChannelSend::StartSend() {
RTC_DCHECK(!channel_state_.Get().sending);
channel_state_.SetSending(true);
// Resume the previous sequence number which was reset by StopSend(). This
@ -569,19 +568,13 @@ int32_t ChannelSend::StartSend() {
_rtpRtcpModule->SetSequenceNumber(send_sequence_number_);
}
_rtpRtcpModule->SetSendingMediaStatus(true);
if (_rtpRtcpModule->SetSendingStatus(true) != 0) {
RTC_DLOG(LS_ERROR) << "StartSend() RTP/RTCP failed to start sending";
_rtpRtcpModule->SetSendingMediaStatus(false);
rtc::CritScope cs(&_callbackCritSect);
channel_state_.SetSending(false);
return -1;
}
int ret = _rtpRtcpModule->SetSendingStatus(true);
RTC_DCHECK_EQ(0, ret);
{
// It is now OK to start posting tasks to the encoder task queue.
rtc::CritScope cs(&encoder_queue_lock_);
encoder_queue_is_active_ = true;
}
return 0;
}
void ChannelSend::StopSend() {
@ -716,47 +709,20 @@ void ChannelSend::OnUplinkPacketLossRate(float packet_loss_rate) {
});
}
bool ChannelSend::EnableAudioNetworkAdaptor(const std::string& config_string) {
bool success = false;
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
if (*encoder) {
success =
(*encoder)->EnableAudioNetworkAdaptor(config_string, event_log_);
}
});
return success;
}
void ChannelSend::DisableAudioNetworkAdaptor() {
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
if (*encoder)
(*encoder)->DisableAudioNetworkAdaptor();
});
}
void ChannelSend::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);
}
});
}
void ChannelSend::RegisterTransport(Transport* transport) {
rtc::CritScope cs(&_callbackCritSect);
_transportPtr = transport;
}
int32_t ChannelSend::ReceivedRTCPPacket(const uint8_t* data, size_t length) {
// TODO(nisse): Delete always-true return value.
bool ChannelSend::ReceivedRTCPPacket(const uint8_t* data, size_t length) {
// Deliver RTCP packet to RTP/RTCP module for parsing
_rtpRtcpModule->IncomingRtcpPacket(data, length);
int64_t rtt = GetRTT();
if (rtt == 0) {
// Waiting for valid RTT.
return 0;
return true;
}
int64_t nack_window_ms = rtt;
@ -772,8 +738,7 @@ int32_t ChannelSend::ReceivedRTCPPacket(const uint8_t* data, size_t length) {
if (*encoder)
(*encoder)->OnReceivedRtt(rtt);
});
return 0;
return true;
}
void ChannelSend::SetInputMute(bool enable) {
@ -786,24 +751,24 @@ bool ChannelSend::InputMute() const {
return input_mute_;
}
int ChannelSend::SendTelephoneEventOutband(int event, int duration_ms) {
bool ChannelSend::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);
if (!Sending()) {
return -1;
return false;
}
if (_rtpRtcpModule->SendTelephoneEventOutband(
event, duration_ms, kTelephoneEventAttenuationdB) != 0) {
RTC_DLOG(LS_ERROR) << "SendTelephoneEventOutband() failed to send event";
return -1;
return false;
}
return 0;
return true;
}
int ChannelSend::SetSendTelephoneEventPayloadType(int payload_type,
int payload_frequency) {
bool ChannelSend::SetSendTelephoneEventPayloadType(int payload_type,
int payload_frequency) {
RTC_DCHECK_LE(0, payload_type);
RTC_DCHECK_GE(127, payload_type);
CodecInst codec = {0};
@ -816,23 +781,20 @@ int ChannelSend::SetSendTelephoneEventPayloadType(int payload_type,
RTC_DLOG(LS_ERROR)
<< "SetSendTelephoneEventPayloadType() failed to register "
"send payload type";
return -1;
return false;
}
}
return 0;
return true;
}
int ChannelSend::SetLocalSSRC(unsigned int ssrc) {
if (channel_state_.Get().sending) {
RTC_DLOG(LS_ERROR) << "SetLocalSSRC() already sending";
return -1;
}
void ChannelSend::SetLocalSSRC(unsigned int ssrc) {
RTC_DCHECK(!channel_state_.Get().sending);
if (media_transport_) {
rtc::CritScope cs(&media_transport_lock_);
media_transport_channel_id_ = ssrc;
}
_rtpRtcpModule->SetSSRC(ssrc);
return 0;
}
void ChannelSend::SetMid(const std::string& mid, int extension_id) {
@ -845,10 +807,10 @@ void ChannelSend::SetExtmapAllowMixed(bool extmap_allow_mixed) {
_rtpRtcpModule->SetExtmapAllowMixed(extmap_allow_mixed);
}
int ChannelSend::SetSendAudioLevelIndicationStatus(bool enable,
unsigned char id) {
void ChannelSend::SetSendAudioLevelIndicationStatus(bool enable, int id) {
_includeAudioLevelIndication = enable;
return SetSendRtpHeaderExtension(enable, kRtpExtensionAudioLevel, id);
int ret = SetSendRtpHeaderExtension(enable, kRtpExtensionAudioLevel, id);
RTC_DCHECK_EQ(0, ret);
}
void ChannelSend::EnableSendTransportSequenceNumber(int id) {
@ -895,31 +857,23 @@ void ChannelSend::SetRTCPStatus(bool enable) {
_rtpRtcpModule->SetRTCPStatus(enable ? RtcpMode::kCompound : RtcpMode::kOff);
}
int ChannelSend::SetRTCP_CNAME(const char cName[256]) {
if (_rtpRtcpModule->SetCNAME(cName) != 0) {
RTC_DLOG(LS_ERROR) << "SetRTCP_CNAME() failed to set RTCP CNAME";
return -1;
}
return 0;
void ChannelSend::SetRTCP_CNAME(absl::string_view c_name) {
// Note: SetCNAME() accepts a c string of length at most 255.
const std::string c_name_limited(c_name.substr(0, 255));
int ret = _rtpRtcpModule->SetCNAME(c_name_limited.c_str()) != 0;
RTC_DCHECK_EQ(0, ret) << "SetRTCP_CNAME() failed to set RTCP CNAME";
}
int ChannelSend::GetRemoteRTCPReportBlocks(
std::vector<ReportBlock>* report_blocks) {
if (report_blocks == NULL) {
RTC_DLOG(LS_ERROR) << "GetRemoteRTCPReportBlock()s invalid report_blocks.";
return -1;
}
std::vector<ReportBlock> ChannelSend::GetRemoteRTCPReportBlocks() const {
// 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;
int ret = _rtpRtcpModule->RemoteRTCPStat(&rtcp_report_blocks);
RTC_DCHECK_EQ(0, ret);
std::vector<ReportBlock> report_blocks;
std::vector<RTCPReportBlock>::const_iterator it = rtcp_report_blocks.begin();
for (; it != rtcp_report_blocks.end(); ++it) {
@ -933,19 +887,15 @@ int ChannelSend::GetRemoteRTCPReportBlocks(
report_block.interarrival_jitter = it->jitter;
report_block.last_SR_timestamp = it->last_sender_report_timestamp;
report_block.delay_since_last_SR = it->delay_since_last_sender_report;
report_blocks->push_back(report_block);
report_blocks.push_back(report_block);
}
return 0;
return report_blocks;
}
int ChannelSend::GetRTPStatistics(CallSendStatistics& stats) {
// --- RtcpStatistics
// --- RTT
CallSendStatistics ChannelSend::GetRTCPStatistics() const {
CallSendStatistics stats = {0};
stats.rttMs = GetRTT();
// --- Data counters
size_t bytesSent(0);
uint32_t packetsSent(0);
@ -958,7 +908,7 @@ int ChannelSend::GetRTPStatistics(CallSendStatistics& stats) {
stats.bytesSent = bytesSent;
stats.packetsSent = packetsSent;
return 0;
return stats;
}
void ChannelSend::SetNACKStatus(bool enable, int maxNumberOfPackets) {
@ -1063,11 +1013,14 @@ RtpRtcp* ChannelSend::GetRtpRtcp() const {
int ChannelSend::SetSendRtpHeaderExtension(bool enable,
RTPExtensionType type,
unsigned char id) {
int id) {
int error = 0;
_rtpRtcpModule->DeregisterSendRtpHeaderExtension(type);
if (enable) {
error = _rtpRtcpModule->RegisterSendRtpHeaderExtension(type, id);
// TODO(nisse): RtpRtcp::RegisterSendRtpHeaderExtension to take an int
// argument. Currently it wants an uint8_t.
error = _rtpRtcpModule->RegisterSendRtpHeaderExtension(
type, rtc::dchecked_cast<uint8_t>(id));
}
return error;
}

View File

@ -137,24 +137,17 @@ class ChannelSend
// API methods
// VoEBase
int32_t StartSend();
void StartSend();
void StopSend();
// Codecs
void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
int GetBitRate() const;
bool EnableAudioNetworkAdaptor(const std::string& config_string);
void DisableAudioNetworkAdaptor();
// TODO(nisse): Modifies decoder, but not used?
void SetReceiverFrameLengthRange(int min_frame_length_ms,
int max_frame_length_ms);
// Network
void RegisterTransport(Transport* transport);
// TODO(nisse, solenberg): Delete when VoENetwork is deleted.
int32_t ReceivedRTCPPacket(const uint8_t* data, size_t length);
bool ReceivedRTCPPacket(const uint8_t* data, size_t length);
// Muting, Volume and Level.
void SetInputMute(bool enable);
@ -166,15 +159,16 @@ class ChannelSend
RtpRtcp* GetRtpRtcp() const;
// DTMF.
int SendTelephoneEventOutband(int event, int duration_ms);
int SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency);
bool SendTelephoneEventOutband(int event, int duration_ms);
bool SetSendTelephoneEventPayloadType(int payload_type,
int payload_frequency);
// RTP+RTCP
int SetLocalSSRC(unsigned int ssrc);
void SetLocalSSRC(uint32_t ssrc);
void SetMid(const std::string& mid, int extension_id);
void SetExtmapAllowMixed(bool extmap_allow_mixed);
int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
void SetSendAudioLevelIndicationStatus(bool enable, int id);
void EnableSendTransportSequenceNumber(int id);
void RegisterSenderCongestionControlObjects(
@ -182,30 +176,11 @@ class ChannelSend
RtcpBandwidthObserver* bandwidth_observer);
void ResetSenderCongestionControlObjects();
void SetRTCPStatus(bool enable);
int SetRTCP_CNAME(const char cName[256]);
int GetRemoteRTCPReportBlocks(std::vector<ReportBlock>* report_blocks);
int GetRTPStatistics(CallSendStatistics& stats); // NOLINT
void SetRTCP_CNAME(absl::string_view c_name);
std::vector<ReportBlock> GetRemoteRTCPReportBlocks() const;
CallSendStatistics GetRTCPStatistics() const;
void SetNACKStatus(bool enable, int maxNumberOfPackets);
// From AudioPacketizationCallback in the ACM
int32_t SendData(FrameType frameType,
uint8_t payloadType,
uint32_t timeStamp,
const uint8_t* payloadData,
size_t payloadSize,
const RTPFragmentationHeader* fragmentation) override;
// From Transport (called by the RTP/RTCP module)
bool SendRtp(const uint8_t* data,
size_t len,
const PacketOptions& packet_options) override;
bool SendRtcp(const uint8_t* data, size_t len) override;
int PreferredSampleRate() const;
bool Sending() const { return channel_state_.Get().sending; }
RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
// ProcessAndEncodeAudio() posts a task on the shared encoder task queue,
// which in turn calls (on the queue) ProcessAndEncodeAudioOnTaskQueue() where
// the actual processing of the audio takes place. The processing mainly
@ -217,11 +192,9 @@ class ChannelSend
// packet.
void ProcessAndEncodeAudio(std::unique_ptr<AudioFrame> audio_frame);
public:
void SetTransportOverhead(size_t transport_overhead_per_packet);
// From OverheadObserver in the RTP/RTCP module
void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
// The existence of this function alongside OnUplinkPacketLossRate is
// a compromise. We want the encoder to be agnostic of the PLR source, but
// we also don't want it to receive conflicting information from TWCC and
@ -242,14 +215,33 @@ class ChannelSend
void Init();
void Terminate();
// From AudioPacketizationCallback in the ACM
int32_t SendData(FrameType frameType,
uint8_t payloadType,
uint32_t timeStamp,
const uint8_t* payloadData,
size_t payloadSize,
const RTPFragmentationHeader* fragmentation) override;
// From Transport (called by the RTP/RTCP module)
bool SendRtp(const uint8_t* data,
size_t len,
const PacketOptions& packet_options) override;
bool SendRtcp(const uint8_t* data, size_t len) override;
int PreferredSampleRate() const;
bool Sending() const { return channel_state_.Get().sending; }
// From OverheadObserver in the RTP/RTCP module
void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
void OnUplinkPacketLossRate(float packet_loss_rate);
bool InputMute() const;
int ResendPackets(const uint16_t* sequence_numbers, int length);
int SetSendRtpHeaderExtension(bool enable,
RTPExtensionType type,
unsigned char id);
int SetSendRtpHeaderExtension(bool enable, RTPExtensionType type, int id);
void UpdateOverheadForEncoder()
RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);

View File

@ -30,8 +30,7 @@ ChannelSendProxy::~ChannelSendProxy() {}
void ChannelSendProxy::SetLocalSSRC(uint32_t ssrc) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
int error = channel_->SetLocalSSRC(ssrc);
RTC_DCHECK_EQ(0, error);
return channel_->SetLocalSSRC(ssrc);
}
void ChannelSendProxy::SetNACKStatus(bool enable, int max_packets) {
@ -41,10 +40,7 @@ void ChannelSendProxy::SetNACKStatus(bool enable, int max_packets) {
CallSendStatistics ChannelSendProxy::GetRTCPStatistics() const {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
CallSendStatistics stats = {0};
int error = channel_->GetRTPStatistics(stats);
RTC_DCHECK_EQ(0, error);
return stats;
return channel_->GetRTCPStatistics();
}
void ChannelSendProxy::RegisterTransport(Transport* transport) {
@ -55,7 +51,7 @@ void ChannelSendProxy::RegisterTransport(Transport* transport) {
bool ChannelSendProxy::ReceivedRTCPPacket(const uint8_t* packet,
size_t length) {
// May be called on either worker thread or network thread.
return channel_->ReceivedRTCPPacket(packet, length) == 0;
return channel_->ReceivedRTCPPacket(packet, length);
}
bool ChannelSendProxy::SetEncoder(int payload_type,
@ -80,12 +76,9 @@ void ChannelSendProxy::SetMid(const std::string& mid, int extension_id) {
channel_->SetMid(mid, extension_id);
}
void ChannelSendProxy::SetRTCP_CNAME(const std::string& c_name) {
void ChannelSendProxy::SetRTCP_CNAME(absl::string_view c_name) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
// Note: VoERTP_RTCP::SetRTCP_CNAME() accepts a char[256] array.
std::string c_name_limited = c_name.substr(0, 255);
int error = channel_->SetRTCP_CNAME(c_name_limited.c_str());
RTC_DCHECK_EQ(0, error);
channel_->SetRTCP_CNAME(c_name);
}
void ChannelSendProxy::SetExtmapAllowMixed(bool extmap_allow_mixed) {
@ -95,8 +88,7 @@ void ChannelSendProxy::SetExtmapAllowMixed(bool extmap_allow_mixed) {
void ChannelSendProxy::SetSendAudioLevelIndicationStatus(bool enable, int id) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
int error = channel_->SetSendAudioLevelIndicationStatus(enable, id);
RTC_DCHECK_EQ(0, error);
channel_->SetSendAudioLevelIndicationStatus(enable, id);
}
void ChannelSendProxy::EnableSendTransportSequenceNumber(int id) {
@ -119,10 +111,7 @@ void ChannelSendProxy::ResetSenderCongestionControlObjects() {
std::vector<ReportBlock> ChannelSendProxy::GetRemoteRTCPReportBlocks() const {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
std::vector<webrtc::ReportBlock> blocks;
int error = channel_->GetRemoteRTCPReportBlocks(&blocks);
RTC_DCHECK_EQ(0, error);
return blocks;
return channel_->GetRemoteRTCPReportBlocks();
}
ANAStats ChannelSendProxy::GetANAStatistics() const {
@ -134,12 +123,12 @@ bool ChannelSendProxy::SetSendTelephoneEventPayloadType(int payload_type,
int payload_frequency) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel_->SetSendTelephoneEventPayloadType(payload_type,
payload_frequency) == 0;
payload_frequency);
}
bool ChannelSendProxy::SendTelephoneEventOutband(int event, int duration_ms) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel_->SendTelephoneEventOutband(event, duration_ms) == 0;
return channel_->SendTelephoneEventOutband(event, duration_ms);
}
void ChannelSendProxy::SetBitrate(int bitrate_bps,
@ -191,8 +180,7 @@ void ChannelSendProxy::OnRecoverableUplinkPacketLossRate(
void ChannelSendProxy::StartSend() {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
int error = channel_->StartSend();
RTC_DCHECK_EQ(0, error);
channel_->StartSend();
}
void ChannelSendProxy::StopSend() {

View File

@ -57,7 +57,7 @@ class ChannelSendProxy {
virtual void SetRTCPStatus(bool enable);
virtual void SetMid(const std::string& mid, int extension_id);
virtual void SetRTCP_CNAME(const std::string& c_name);
virtual void SetRTCP_CNAME(absl::string_view c_name);
virtual void SetExtmapAllowMixed(bool extmap_allow_mixed);
virtual void SetSendAudioLevelIndicationStatus(bool enable, int id);
virtual void EnableSendTransportSequenceNumber(int id);

View File

@ -74,7 +74,7 @@ class MockChannelSendProxy : public voe::ChannelSendProxy {
void(rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier));
MOCK_METHOD1(SetRTCPStatus, void(bool enable));
MOCK_METHOD1(SetLocalSSRC, void(uint32_t ssrc));
MOCK_METHOD1(SetRTCP_CNAME, void(const std::string& c_name));
MOCK_METHOD1(SetRTCP_CNAME, void(absl::string_view c_name));
MOCK_METHOD2(SetNACKStatus, void(bool enable, int max_packets));
MOCK_METHOD1(SetExtmapAllowMixed, void(bool extmap_allow_mixed));
MOCK_METHOD2(SetSendAudioLevelIndicationStatus, void(bool enable, int id));