diff --git a/audio/audio_send_stream.cc b/audio/audio_send_stream.cc index d3ec157849..e12e24569d 100644 --- a/audio/audio_send_stream.cc +++ b/audio/audio_send_stream.cc @@ -796,8 +796,7 @@ void AudioSendStream::RemoveBitrateObserver() { void AudioSendStream::RegisterCngPayloadType(int payload_type, int clockrate_hz) { - rtp_rtcp_module_->RegisterAudioSendPayload(payload_type, "CN", clockrate_hz, - 1, 0); + channel_send_->RegisterCngPayloadType(payload_type, clockrate_hz); } } // namespace internal } // namespace webrtc diff --git a/audio/audio_send_stream_unittest.cc b/audio/audio_send_stream_unittest.cc index 1d4d5b76e9..df5ee30c40 100644 --- a/audio/audio_send_stream_unittest.cc +++ b/audio/audio_send_stream_unittest.cc @@ -450,6 +450,7 @@ TEST(AudioSendStreamTest, SendCodecCanApplyVad) { stolen_encoder = std::move(*encoder); return true; })); + EXPECT_CALL(*helper.channel_send(), RegisterCngPayloadType(105, 8000)); auto send_stream = helper.CreateAudioSendStream(); @@ -501,6 +502,8 @@ TEST(AudioSendStreamTest, DontRecreateEncoder) { EXPECT_CALL(*helper.channel_send(), SetEncoderForMock(_, _)) .WillOnce(Return()); + EXPECT_CALL(*helper.channel_send(), RegisterCngPayloadType(105, 8000)); + helper.config().send_codec_spec = AudioSendStream::Config::SendCodecSpec(9, kG722Format); helper.config().send_codec_spec->cng_payload_type = 105; diff --git a/audio/channel_send.cc b/audio/channel_send.cc index 705827dec0..196911aadd 100644 --- a/audio/channel_send.cc +++ b/audio/channel_send.cc @@ -129,6 +129,8 @@ class ChannelSend // Used by AudioSendStream. RtpRtcp* GetRtpRtcp() const override; + void RegisterCngPayloadType(int payload_type, int payload_frequency) override; + // DTMF. bool SendTelephoneEventOutband(int event, int duration_ms) override; void SetSendTelephoneEventPayloadType(int payload_type, @@ -236,6 +238,7 @@ class ChannelSend RtcEventLog* const event_log_; std::unique_ptr _rtpRtcpModule; + std::unique_ptr rtp_sender_audio_; std::unique_ptr audio_coding_; uint32_t _timeStamp RTC_GUARDED_BY(encoder_queue_); @@ -520,10 +523,10 @@ int32_t ChannelSend::SendRtpAudio(FrameType frameType, const RTPFragmentationHeader* fragmentation) { RTC_DCHECK_RUN_ON(encoder_queue_); if (_includeAudioLevelIndication) { - // Store current audio level in the RTP/RTCP module. + // Store current audio level in the RTP sender. // The level will be used in combination with voice-activity state // (frameType) to add an RTP header extension - _rtpRtcpModule->SetAudioLevel(rms_level_.Average()); + rtp_sender_audio_->SetAudioLevel(rms_level_.Average()); } // E2EE Custom Audio Frame Encryption (This is optional). @@ -559,14 +562,24 @@ int32_t ChannelSend::SendRtpAudio(FrameType frameType, // Push data from ACM to RTP/RTCP-module to deliver audio frame for // packetization. + if (!_rtpRtcpModule->OnSendingRtpFrame(timeStamp, + // Leaving the time when this frame was + // received from the capture device as + // undefined for voice for now. + -1, payloadType, + /*force_sender_report=*/false)) { + return false; + } + + // RTCPSender has it's own copy of the timestamp offset, added in + // RTCPSender::BuildSR, hence we must not add the in the offset for the above + // call. + // TODO(nisse): Delete RTCPSender:timestamp_offset_, and see if we can confine + // knowledge of the offset to a single place. + const uint32_t rtp_timestamp = timeStamp + _rtpRtcpModule->StartTimestamp(); // This call will trigger Transport::SendPacket() from the RTP/RTCP module. - if (!_rtpRtcpModule->SendOutgoingData((FrameType&)frameType, payloadType, - timeStamp, - // Leaving the time when this frame was - // received from the capture device as - // undefined for voice for now. - -1, payload.data(), payload.size(), - fragmentation, nullptr, nullptr)) { + if (!rtp_sender_audio_->SendAudio(frameType, payloadType, rtp_timestamp, + payload.data(), payload.size())) { RTC_DLOG(LS_ERROR) << "ChannelSend::SendData() failed to send data to RTP/RTCP module"; return -1; @@ -687,6 +700,7 @@ ChannelSend::ChannelSend(Clock* clock, configuration.clock = clock; configuration.audio = true; + configuration.clock = Clock::GetRealTimeClock(); configuration.outgoing_transport = rtp_transport; configuration.paced_sender = rtp_packet_sender_proxy_.get(); @@ -703,6 +717,9 @@ ChannelSend::ChannelSend(Clock* clock, _rtpRtcpModule = RtpRtcp::Create(configuration); _rtpRtcpModule->SetSendingMediaStatus(false); + rtp_sender_audio_ = absl::make_unique( + configuration.clock, _rtpRtcpModule->RtpSender()); + // We want to invoke the 'TargetRateObserver' and |OnOverheadChanged| // callbacks after the audio_coding_ is fully initialized. if (media_transport_) { @@ -797,11 +814,11 @@ void ChannelSend::SetEncoder(int payload_type, // 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. - _rtpRtcpModule->RegisterAudioSendPayload(payload_type, - "audio", - encoder->RtpTimestampRateHz(), - encoder->NumChannels(), - 0); + _rtpRtcpModule->RegisterSendPayloadFrequency(payload_type, + encoder->RtpTimestampRateHz()); + rtp_sender_audio_->RegisterAudioPayload("audio", payload_type, + encoder->RtpTimestampRateHz(), + encoder->NumChannels(), 0); if (media_transport_) { rtc::CritScope cs(&media_transport_lock_); @@ -926,21 +943,29 @@ bool ChannelSend::SendTelephoneEventOutband(int event, int duration_ms) { if (!sending_) { return false; } - if (_rtpRtcpModule->SendTelephoneEventOutband( + if (rtp_sender_audio_->SendTelephoneEvent( event, duration_ms, kTelephoneEventAttenuationdB) != 0) { - RTC_DLOG(LS_ERROR) << "SendTelephoneEventOutband() failed to send event"; + RTC_DLOG(LS_ERROR) << "SendTelephoneEvent() failed to send event"; return false; } return true; } +void ChannelSend::RegisterCngPayloadType(int payload_type, + int payload_frequency) { + _rtpRtcpModule->RegisterSendPayloadFrequency(payload_type, payload_frequency); + rtp_sender_audio_->RegisterAudioPayload("CN", payload_type, payload_frequency, + 1, 0); +} + void ChannelSend::SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency) { RTC_DCHECK_RUN_ON(&worker_thread_checker_); RTC_DCHECK_LE(0, payload_type); RTC_DCHECK_GE(127, payload_type); - _rtpRtcpModule->RegisterAudioSendPayload(payload_type, "telephone-event", - payload_frequency, 0, 0); + _rtpRtcpModule->RegisterSendPayloadFrequency(payload_type, payload_frequency); + rtp_sender_audio_->RegisterAudioPayload("telephone-event", payload_type, + payload_frequency, 0, 0); } void ChannelSend::SetLocalSSRC(uint32_t ssrc) { diff --git a/audio/channel_send.h b/audio/channel_send.h index 7149bbde09..0957035451 100644 --- a/audio/channel_send.h +++ b/audio/channel_send.h @@ -20,6 +20,7 @@ #include "api/crypto/crypto_options.h" #include "api/media_transport_interface.h" #include "modules/rtp_rtcp/include/rtp_rtcp.h" +#include "modules/rtp_rtcp/source/rtp_sender_audio.h" #include "rtc_base/function_view.h" #include "rtc_base/task_queue.h" @@ -81,6 +82,8 @@ class ChannelSendInterface { virtual void ResetSenderCongestionControlObjects() = 0; virtual std::vector GetRemoteRTCPReportBlocks() const = 0; virtual ANAStats GetANAStatistics() const = 0; + virtual void RegisterCngPayloadType(int payload_type, + int payload_frequency) = 0; virtual void SetSendTelephoneEventPayloadType(int payload_type, int payload_frequency) = 0; virtual bool SendTelephoneEventOutband(int event, int duration_ms) = 0; diff --git a/audio/mock_voe_channel_proxy.h b/audio/mock_voe_channel_proxy.h index 1b2f96eb20..cf2fe8874a 100644 --- a/audio/mock_voe_channel_proxy.h +++ b/audio/mock_voe_channel_proxy.h @@ -95,6 +95,8 @@ class MockChannelSend : public voe::ChannelSendInterface { MOCK_CONST_METHOD0(GetRTCPStatistics, CallSendStatistics()); MOCK_CONST_METHOD0(GetRemoteRTCPReportBlocks, std::vector()); MOCK_CONST_METHOD0(GetANAStatistics, ANAStats()); + MOCK_METHOD2(RegisterCngPayloadType, + void(int payload_type, int payload_frequency)); MOCK_METHOD2(SetSendTelephoneEventPayloadType, void(int payload_type, int payload_frequency)); MOCK_METHOD2(SendTelephoneEventOutband, bool(int event, int duration_ms)); diff --git a/modules/rtp_rtcp/include/rtp_rtcp.h b/modules/rtp_rtcp/include/rtp_rtcp.h index 8e1f98bbb4..34ccfeb02a 100644 --- a/modules/rtp_rtcp/include/rtp_rtcp.h +++ b/modules/rtp_rtcp/include/rtp_rtcp.h @@ -146,11 +146,6 @@ class RtpRtcp : public Module, public RtcpFeedbackSenderInterface { // FEC/ULP/RED overhead (when FEC is enabled). virtual size_t MaxRtpPacketSize() const = 0; - virtual void RegisterAudioSendPayload(int payload_type, - absl::string_view payload_name, - int frequency, - int channels, - int rate) = 0; virtual void RegisterSendPayloadFrequency(int payload_type, int payload_frequency) = 0; @@ -257,27 +252,6 @@ class RtpRtcp : public Module, public RtcpFeedbackSenderInterface { virtual RTPSender* RtpSender() = 0; virtual const RTPSender* RtpSender() const = 0; - // Used by the codec module to deliver a video or audio frame for - // packetization. - // |frame_type| - type of frame to send - // |payload_type| - payload type of frame to send - // |timestamp| - timestamp of frame to send - // |payload_data| - payload buffer of frame to send - // |payload_size| - size of payload buffer to send - // |fragmentation| - fragmentation offset data for fragmented frames such - // as layers or RED - // |transport_frame_id_out| - set to RTP timestamp. - // Returns true on success. - virtual bool SendOutgoingData(FrameType frame_type, - int8_t payload_type, - uint32_t timestamp, - int64_t capture_time_ms, - const uint8_t* payload_data, - size_t payload_size, - const RTPFragmentationHeader* fragmentation, - const RTPVideoHeader* rtp_video_header, - uint32_t* transport_frame_id_out) = 0; - // Record that a frame is about to be sent. Returns true on success, and false // if the module isn't ready to send. virtual bool OnSendingRtpFrame(uint32_t timestamp, @@ -431,23 +405,6 @@ class RtpRtcp : public Module, public RtcpFeedbackSenderInterface { virtual void SetVideoBitrateAllocation( const VideoBitrateAllocation& bitrate) = 0; - // ************************************************************************** - // Audio - // ************************************************************************** - - // Sends a TelephoneEvent tone using RFC 2833 (4733). - // Returns -1 on failure else 0. - virtual int32_t SendTelephoneEventOutband(uint8_t key, - uint16_t time_ms, - uint8_t level) = 0; - - // Store the audio level in dBov for header-extension-for-audio-level- - // indication. - // This API shall be called before transmision of an RTP packet to ensure - // that the |level| part of the extended RTP header is updated. - // return -1 on failure else 0. - virtual int32_t SetAudioLevel(uint8_t level_dbov) = 0; - // ************************************************************************** // Video // ************************************************************************** diff --git a/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h b/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h index 7d4f0f1d3c..668d52707d 100644 --- a/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h +++ b/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h @@ -37,12 +37,6 @@ class MockRtpRtcp : public RtpRtcp { MOCK_METHOD1(SetRemoteSSRC, void(uint32_t ssrc)); MOCK_METHOD1(SetMaxRtpPacketSize, void(size_t size)); MOCK_CONST_METHOD0(MaxRtpPacketSize, size_t()); - MOCK_METHOD5(RegisterAudioSendPayload, - void(int payload_type, - absl::string_view payload_name, - int frequency, - int channels, - int rate)); MOCK_METHOD2(RegisterSendPayloadFrequency, void(int payload_type, int frequency)); MOCK_METHOD1(DeRegisterSendPayload, int32_t(int8_t payload_type)); @@ -87,16 +81,6 @@ class MockRtpRtcp : public RtpRtcp { uint32_t* nack_rate)); MOCK_CONST_METHOD1(EstimatedReceiveBandwidth, int(uint32_t* available_bandwidth)); - MOCK_METHOD9(SendOutgoingData, - bool(FrameType frame_type, - int8_t payload_type, - uint32_t timestamp, - int64_t capture_time_ms, - const uint8_t* payload_data, - size_t payload_size, - const RTPFragmentationHeader* fragmentation, - const RTPVideoHeader* rtp_video_header, - uint32_t* frame_id_out)); MOCK_METHOD4(OnSendingRtpFrame, bool(uint32_t, int64_t, int, bool)); MOCK_METHOD5(TimeToSendPacket, bool(uint32_t ssrc, @@ -162,9 +146,6 @@ class MockRtpRtcp : public RtpRtcp { MOCK_METHOD1(RegisterRtcpStatisticsCallback, void(RtcpStatisticsCallback*)); MOCK_METHOD0(GetRtcpStatisticsCallback, RtcpStatisticsCallback*()); MOCK_METHOD1(SendFeedbackPacket, bool(const rtcp::TransportFeedback& packet)); - MOCK_METHOD3(SendTelephoneEventOutband, - int32_t(uint8_t key, uint16_t time_ms, uint8_t level)); - MOCK_METHOD1(SetAudioLevel, int32_t(uint8_t level_dbov)); MOCK_METHOD1(SetTargetSendBitrate, void(uint32_t bitrate_bps)); MOCK_METHOD1(SetKeyFrameRequestMethod, int32_t(KeyFrameRequestMethod method)); MOCK_METHOD0(RequestKeyFrame, int32_t()); diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl.cc index 4e0600222d..6d1c9e2ba5 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl.cc +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl.cc @@ -116,9 +116,7 @@ ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration) configuration.extmap_allow_mixed, configuration.field_trials ? *configuration.field_trials : default_trials)); - if (configuration.audio) { - audio_ = absl::make_unique(clock_, rtp_sender_.get()); - } + // Make sure rtcp sender use same timestamp offset as rtp sender. rtcp_sender_.SetTimestampOffset(rtp_sender_->TimestampOffset()); @@ -270,17 +268,6 @@ void ModuleRtpRtcpImpl::IncomingRtcpPacket(const uint8_t* rtcp_packet, rtcp_receiver_.IncomingPacket(rtcp_packet, length); } -void ModuleRtpRtcpImpl::RegisterAudioSendPayload(int payload_type, - absl::string_view payload_name, - int frequency, - int channels, - int rate) { - RTC_DCHECK(audio_); - rtcp_sender_.SetRtpClockRate(payload_type, frequency); - RTC_CHECK_EQ(0, audio_->RegisterAudioPayload(payload_name, payload_type, - frequency, channels, rate)); -} - void ModuleRtpRtcpImpl::RegisterSendPayloadFrequency(int payload_type, int payload_frequency) { rtcp_sender_.SetRtpClockRate(payload_type, payload_frequency); @@ -425,30 +412,6 @@ void ModuleRtpRtcpImpl::SetAsPartOfAllocation(bool part_of_allocation) { rtp_sender_->SetAsPartOfAllocation(part_of_allocation); } -bool ModuleRtpRtcpImpl::SendOutgoingData( - FrameType frame_type, - int8_t payload_type, - uint32_t time_stamp, - int64_t capture_time_ms, - const uint8_t* payload_data, - size_t payload_size, - const RTPFragmentationHeader* fragmentation, - const RTPVideoHeader* rtp_video_header, - uint32_t* transport_frame_id_out) { - OnSendingRtpFrame(time_stamp, capture_time_ms, payload_type, - kVideoFrameKey == frame_type); - - const uint32_t rtp_timestamp = time_stamp + rtp_sender_->TimestampOffset(); - if (transport_frame_id_out) - *transport_frame_id_out = rtp_timestamp; - - RTC_DCHECK(audio_); - RTC_DCHECK(fragmentation == nullptr); - - return audio_->SendAudio(frame_type, payload_type, rtp_timestamp, - payload_data, payload_size); -} - bool ModuleRtpRtcpImpl::OnSendingRtpFrame(uint32_t timestamp, int64_t capture_time_ms, int payload_type, @@ -787,17 +750,6 @@ bool ModuleRtpRtcpImpl::SendFeedbackPacket( return rtcp_sender_.SendFeedbackPacket(packet); } -// Send a TelephoneEvent tone using RFC 2833 (4733). -int32_t ModuleRtpRtcpImpl::SendTelephoneEventOutband(const uint8_t key, - const uint16_t time_ms, - const uint8_t level) { - return audio_ ? audio_->SendTelephoneEvent(key, time_ms, level) : -1; -} - -int32_t ModuleRtpRtcpImpl::SetAudioLevel(const uint8_t level_d_bov) { - return audio_ ? audio_->SetAudioLevel(level_d_bov) : -1; -} - int32_t ModuleRtpRtcpImpl::SetKeyFrameRequestMethod( const KeyFrameRequestMethod method) { key_frame_req_method_ = method; diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl.h b/modules/rtp_rtcp/source/rtp_rtcp_impl.h index 20eb179a9a..4b1c9279fe 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl.h +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl.h @@ -32,8 +32,6 @@ #include "modules/rtp_rtcp/source/rtcp_receiver.h" #include "modules/rtp_rtcp/source/rtcp_sender.h" #include "modules/rtp_rtcp/source/rtp_sender.h" -#include "modules/rtp_rtcp/source/rtp_sender_audio.h" -#include "modules/rtp_rtcp/source/rtp_sender_video.h" #include "rtc_base/critical_section.h" #include "rtc_base/gtest_prod_util.h" @@ -64,12 +62,6 @@ class ModuleRtpRtcpImpl : public RtpRtcp, public RTCPReceiver::ModuleRtpRtcp { void SetRemoteSSRC(uint32_t ssrc) override; // Sender part. - - void RegisterAudioSendPayload(int payload_type, - absl::string_view payload_name, - int frequency, - int channels, - int rate) override; void RegisterSendPayloadFrequency(int payload_type, int payload_frequency) override; @@ -137,18 +129,6 @@ class ModuleRtpRtcpImpl : public RtpRtcp, public RTCPReceiver::ModuleRtpRtcp { void SetAsPartOfAllocation(bool part_of_allocation) override; - // Used by the codec module to deliver a video or audio frame for - // packetization. - bool SendOutgoingData(FrameType frame_type, - int8_t payload_type, - uint32_t time_stamp, - int64_t capture_time_ms, - const uint8_t* payload_data, - size_t payload_size, - const RTPFragmentationHeader* fragmentation, - const RTPVideoHeader* rtp_video_header, - uint32_t* transport_frame_id_out) override; - bool OnSendingRtpFrame(uint32_t timestamp, int64_t capture_time_ms, int payload_type, @@ -270,17 +250,6 @@ class ModuleRtpRtcpImpl : public RtpRtcp, public RTCPReceiver::ModuleRtpRtcp { bool RtcpXrRrtrStatus() const override; - // Audio part. - - // Send a TelephoneEvent tone using RFC 2833 (4733). - int32_t SendTelephoneEventOutband(uint8_t key, - uint16_t time_ms, - uint8_t level) override; - - // Store the audio level in d_bov for header-extension-for-audio-level- - // indication. - int32_t SetAudioLevel(uint8_t level_d_bov) override; - // Video part. // Set method for requesting a new key frame. @@ -346,7 +315,6 @@ class ModuleRtpRtcpImpl : public RtpRtcp, public RTCPReceiver::ModuleRtpRtcp { bool TimeToSendFullNackList(int64_t now) const; std::unique_ptr rtp_sender_; - std::unique_ptr audio_; RTCPSender rtcp_sender_; RTCPReceiver rtcp_receiver_; diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc index da541a5098..98067b2b93 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc @@ -22,6 +22,7 @@ #include "modules/rtp_rtcp/source/rtcp_packet/nack.h" #include "modules/rtp_rtcp/source/rtp_packet_received.h" #include "modules/rtp_rtcp/source/rtp_rtcp_impl.h" +#include "modules/rtp_rtcp/source/rtp_sender_video.h" #include "rtc_base/rate_limiter.h" #include "test/gmock.h" #include "test/gtest.h" diff --git a/modules/rtp_rtcp/source/rtp_sender_audio.cc b/modules/rtp_rtcp/source/rtp_sender_audio.cc index 56d0884e75..c049530a96 100644 --- a/modules/rtp_rtcp/source/rtp_sender_audio.cc +++ b/modules/rtp_rtcp/source/rtp_sender_audio.cc @@ -47,7 +47,9 @@ const char* FrameTypeToString(FrameType frame_type) { } // namespace RTPSenderAudio::RTPSenderAudio(Clock* clock, RTPSender* rtp_sender) - : clock_(clock), rtp_sender_(rtp_sender) {} + : clock_(clock), rtp_sender_(rtp_sender) { + RTC_DCHECK(clock_); +} RTPSenderAudio::~RTPSenderAudio() {}