diff --git a/audio/channel_send.cc b/audio/channel_send.cc index a4a4977441..09482a4fb5 100644 --- a/audio/channel_send.cc +++ b/audio/channel_send.cc @@ -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* encoder) { - if (*encoder) { - success = - (*encoder)->EnableAudioNetworkAdaptor(config_string, event_log_); - } - }); - return success; -} - -void ChannelSend::DisableAudioNetworkAdaptor() { - audio_coding_->ModifyEncoder([&](std::unique_ptr* encoder) { - if (*encoder) - (*encoder)->DisableAudioNetworkAdaptor(); - }); -} - -void ChannelSend::SetReceiverFrameLengthRange(int min_frame_length_ms, - int max_frame_length_ms) { - audio_coding_->ModifyEncoder([&](std::unique_ptr* 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* report_blocks) { - if (report_blocks == NULL) { - RTC_DLOG(LS_ERROR) << "GetRemoteRTCPReportBlock()s invalid report_blocks."; - return -1; - } - +std::vector 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 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 report_blocks; std::vector::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(id)); } return error; } diff --git a/audio/channel_send.h b/audio/channel_send.h index 6013d1e8c4..29b472a12a 100644 --- a/audio/channel_send.h +++ b/audio/channel_send.h @@ -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* report_blocks); - int GetRTPStatistics(CallSendStatistics& stats); // NOLINT + void SetRTCP_CNAME(absl::string_view c_name); + std::vector 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 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_); diff --git a/audio/channel_send_proxy.cc b/audio/channel_send_proxy.cc index 2d0bdd37b2..1fe87a00e8 100644 --- a/audio/channel_send_proxy.cc +++ b/audio/channel_send_proxy.cc @@ -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 ChannelSendProxy::GetRemoteRTCPReportBlocks() const { RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); - std::vector 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() { diff --git a/audio/channel_send_proxy.h b/audio/channel_send_proxy.h index 3146830351..e26ef54e9d 100644 --- a/audio/channel_send_proxy.h +++ b/audio/channel_send_proxy.h @@ -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); diff --git a/audio/mock_voe_channel_proxy.h b/audio/mock_voe_channel_proxy.h index 0571c8daba..2ded3a3f75 100644 --- a/audio/mock_voe_channel_proxy.h +++ b/audio/mock_voe_channel_proxy.h @@ -74,7 +74,7 @@ class MockChannelSendProxy : public voe::ChannelSendProxy { void(rtc::FunctionView*)> 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));