diff --git a/src/modules/rtp_rtcp/interface/rtp_rtcp.h b/src/modules/rtp_rtcp/interface/rtp_rtcp.h index 0a26da3d8..d8d493f11 100644 --- a/src/modules/rtp_rtcp/interface/rtp_rtcp.h +++ b/src/modules/rtp_rtcp/interface/rtp_rtcp.h @@ -566,6 +566,12 @@ public: WebRtc_UWord32* fecRate, WebRtc_UWord32* nackRate) const = 0; + /* + * Get the send-side estimate of the available bandwidth. + */ + virtual int EstimatedBandwidth( + WebRtc_UWord32* available_bandwidth) const = 0; + /* * Used by the codec module to deliver a video or audio frame for packetization * diff --git a/src/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h b/src/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h index d11328be3..f8e42e37b 100644 --- a/src/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h +++ b/src/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * 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. + */ + #include "../testing/gmock/include/gmock/gmock.h" #include "modules/interface/module.h" @@ -132,6 +142,8 @@ class MockRtpRtcp : public RtpRtcp { bool()); MOCK_CONST_METHOD4(BitrateSent, void(WebRtc_UWord32* totalRate, WebRtc_UWord32* videoRate, WebRtc_UWord32* fecRate, WebRtc_UWord32* nackRate)); + MOCK_CONST_METHOD1(EstimatedBandwidth, + int(WebRtc_UWord32* available_bandwidth)); MOCK_METHOD7(SendOutgoingData, WebRtc_Word32(const FrameType frameType, const WebRtc_Word8 payloadType, const WebRtc_UWord32 timeStamp, const WebRtc_UWord8* payloadData, const WebRtc_UWord32 payloadSize, const RTPFragmentationHeader* fragmentation, const RTPVideoHeader* rtpVideoHdr)); MOCK_METHOD1(RegisterIncomingRTCPCallback, diff --git a/src/modules/rtp_rtcp/source/bandwidth_management.cc b/src/modules/rtp_rtcp/source/bandwidth_management.cc index 8851fdba3..a14a2ef6f 100644 --- a/src/modules/rtp_rtcp/source/bandwidth_management.cc +++ b/src/modules/rtp_rtcp/source/bandwidth_management.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * 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 @@ -182,6 +182,19 @@ WebRtc_Word32 BandwidthManagement::UpdatePacketLoss( return 0; } +WebRtc_Word32 BandwidthManagement::AvailableBandwidth( + WebRtc_UWord32* bandwidthKbit) const { + CriticalSectionScoped cs(_critsect); + if (_bitRate == 0) { + return -1; + } + if (!bandwidthKbit) { + return -1; + } + *bandwidthKbit = _bitRate; + return 0; +} + /* Calculate the rate that TCP-Friendly Rate Control (TFRC) would apply. * The formula in RFC 3448, Section 3.1, is used. */ diff --git a/src/modules/rtp_rtcp/source/bandwidth_management.h b/src/modules/rtp_rtcp/source/bandwidth_management.h index 10f821bd9..2516b866d 100644 --- a/src/modules/rtp_rtcp/source/bandwidth_management.h +++ b/src/modules/rtp_rtcp/source/bandwidth_management.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * 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 @@ -41,7 +41,9 @@ public: WebRtc_UWord32* newBitrate, WebRtc_Word64 nowMS); - WebRtc_Word32 AvailableBandwidth(WebRtc_UWord16* bandwidthKbit) const; + // If no bandwidth estimate is available or if |bandwidthKbit| is NULL, + // -1 is returned. + WebRtc_Word32 AvailableBandwidth(WebRtc_UWord32* bandwidthKbit) const; void SetSendBitrate(const WebRtc_UWord32 startBitrate, const WebRtc_UWord16 minBitrateKbit, diff --git a/src/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/src/modules/rtp_rtcp/source/rtp_rtcp_impl.cc index f10d675a0..a42860903 100644 --- a/src/modules/rtp_rtcp/source/rtp_rtcp_impl.cc +++ b/src/modules/rtp_rtcp/source/rtp_rtcp_impl.cc @@ -2501,6 +2501,11 @@ void ModuleRtpRtcpImpl::BitrateSent(WebRtc_UWord32* totalRate, *nackRate = _rtpSender.NackOverheadRate(); } +int ModuleRtpRtcpImpl::EstimatedBandwidth( + WebRtc_UWord32* available_bandwidth) const { + return _bandwidthManagement.AvailableBandwidth(available_bandwidth); +} + // for lip sync void ModuleRtpRtcpImpl::OnReceivedNTP() { // don't do anything if we are the audio module diff --git a/src/modules/rtp_rtcp/source/rtp_rtcp_impl.h b/src/modules/rtp_rtcp/source/rtp_rtcp_impl.h index 2d9d625fb..0802a9d39 100644 --- a/src/modules/rtp_rtcp/source/rtp_rtcp_impl.h +++ b/src/modules/rtp_rtcp/source/rtp_rtcp_impl.h @@ -491,6 +491,8 @@ public: WebRtc_UWord32* fecRate, WebRtc_UWord32* nackRate) const; + virtual int EstimatedBandwidth(WebRtc_UWord32* available_bandwidth) const; + virtual void SetRemoteSSRC(const WebRtc_UWord32 SSRC); virtual WebRtc_UWord32 SendTimeOfSendReport(const WebRtc_UWord32 sendReport); diff --git a/src/video_engine/include/vie_rtp_rtcp.h b/src/video_engine/include/vie_rtp_rtcp.h index 298031d91..5a6a4de05 100644 --- a/src/video_engine/include/vie_rtp_rtcp.h +++ b/src/video_engine/include/vie_rtp_rtcp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * 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 @@ -242,6 +242,12 @@ class WEBRTC_DLLEXPORT ViERTP_RTCP { unsigned int& fec_bitrate_sent, unsigned int& nackBitrateSent) const = 0; + // This function gets the send-side estimated bandwidth available for video, + // including overhead, in bits/s. + virtual int GetEstimatedBandwidth( + const int video_channel, + unsigned int* estimated_bandwidth) const = 0; + // This function enables or disables an RTP keep-alive mechanism which can // be used to maintain an existing Network Address Translator (NAT) mapping // while regular RTP is no longer transmitted. diff --git a/src/video_engine/test/auto_test/source/vie_autotest_rtp_rtcp.cc b/src/video_engine/test/auto_test/source/vie_autotest_rtp_rtcp.cc index 0599972ca..7a543c9f0 100644 --- a/src/video_engine/test/auto_test/source/vie_autotest_rtp_rtcp.cc +++ b/src/video_engine/test/auto_test/source/vie_autotest_rtp_rtcp.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * 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 @@ -221,6 +221,11 @@ void ViEAutoTest::ViERtpRtcpStandardTest() EXPECT_GT(recJitter, 0u); EXPECT_GT(recRttMs, 0); + unsigned int estimated_bandwidth = 0; + EXPECT_EQ(0, ViE.rtp_rtcp->GetEstimatedBandwidth(tbChannel.videoChannel, + &estimated_bandwidth)); + EXPECT_GT(estimated_bandwidth, 0u); + // Check that rec stats extended max is greater than what we've sent. EXPECT_GE(recExtendedMax, sentExtendedMax); EXPECT_EQ(0, ViE.base->StopSend(tbChannel.videoChannel)); diff --git a/src/video_engine/vie_encoder.cc b/src/video_engine/vie_encoder.cc index 8c2e610b0..c80b5be74 100644 --- a/src/video_engine/vie_encoder.cc +++ b/src/video_engine/vie_encoder.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * 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 @@ -560,6 +560,13 @@ WebRtc_Word32 ViEEncoder::SendCodecStatistics( return 0; } +WebRtc_Word32 ViEEncoder::EstimatedBandwidth( + WebRtc_UWord32* available_bandwidth) const { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + return default_rtp_rtcp_.EstimatedBandwidth(available_bandwidth); +} + WebRtc_Word32 ViEEncoder::UpdateProtectionMethod() { bool fec_enabled = false; WebRtc_UWord8 dummy_ptype_red = 0; diff --git a/src/video_engine/vie_encoder.h b/src/video_engine/vie_encoder.h index 6734759b0..9afdaac6e 100644 --- a/src/video_engine/vie_encoder.h +++ b/src/video_engine/vie_encoder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * 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 @@ -88,6 +88,7 @@ class ViEEncoder WebRtc_Word32 SendKeyFrame(); WebRtc_Word32 SendCodecStatistics(WebRtc_UWord32& num_key_frames, WebRtc_UWord32& num_delta_frames); + WebRtc_Word32 EstimatedBandwidth(WebRtc_UWord32* available_bandwidth) const; // Loss protection. WebRtc_Word32 UpdateProtectionMethod(); diff --git a/src/video_engine/vie_rtp_rtcp_impl.cc b/src/video_engine/vie_rtp_rtcp_impl.cc index 93aea8a14..1d2dd9a40 100644 --- a/src/video_engine/vie_rtp_rtcp_impl.cc +++ b/src/video_engine/vie_rtp_rtcp_impl.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * 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 @@ -733,6 +733,26 @@ int ViERTP_RTCPImpl::GetBandwidthUsage(const int video_channel, return 0; } +int ViERTP_RTCPImpl::GetEstimatedBandwidth( + const int video_channel, + unsigned int* estimated_bandwidth) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, + ViEId(shared_data_->instance_id(), video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); + ViEEncoder* vie_encoder = cs.Encoder(video_channel); + if (!vie_encoder) { + WEBRTC_TRACE(kTraceError, kTraceVideo, + ViEId(shared_data_->instance_id(), video_channel), + "%s: Could not get encoder for channel %d", __FUNCTION__, + video_channel); + shared_data_->SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + return vie_encoder->EstimatedBandwidth( + static_cast(estimated_bandwidth)); +} + int ViERTP_RTCPImpl::SetRTPKeepAliveStatus( const int video_channel, bool enable, diff --git a/src/video_engine/vie_rtp_rtcp_impl.h b/src/video_engine/vie_rtp_rtcp_impl.h index 9b4f0d82d..89ea16c48 100644 --- a/src/video_engine/vie_rtp_rtcp_impl.h +++ b/src/video_engine/vie_rtp_rtcp_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * 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 @@ -87,9 +87,13 @@ class ViERTP_RTCPImpl unsigned int& video_bitrate_sent, unsigned int& fec_bitrate_sent, unsigned int& nackBitrateSent) const; - virtual int SetRTPKeepAliveStatus(const int video_channel, - bool enable, - const char unknown_payload_type, + virtual int GetEstimatedBandwidth( + const int video_channel, + unsigned int* estimated_bandwidth) const; + virtual int SetRTPKeepAliveStatus( + const int video_channel, + bool enable, + const char unknown_payload_type, const unsigned int delta_transmit_time_seconds); virtual int GetRTPKeepAliveStatus( const int video_channel,