diff --git a/webrtc/modules/remote_bitrate_estimator/bwe_simulations.cc b/webrtc/modules/remote_bitrate_estimator/bwe_simulations.cc index 9d86ba31be..cb8d0db5c7 100644 --- a/webrtc/modules/remote_bitrate_estimator/bwe_simulations.cc +++ b/webrtc/modules/remote_bitrate_estimator/bwe_simulations.cc @@ -36,7 +36,7 @@ class BweSimulation : public BweTest, VerboseLogging(true); } - Random random_; + test::Random random_; private: RTC_DISALLOW_COPY_AND_ASSIGN(BweSimulation); diff --git a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc index 56a309c59d..522489e921 100644 --- a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc +++ b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc @@ -64,6 +64,15 @@ std::vector Keys(const std::map& map) { return keys; } +uint32_t ConvertMsTo24Bits(int64_t time_ms) { + uint32_t time_24_bits = + static_cast( + ((static_cast(time_ms) << kAbsSendTimeFraction) + 500) / + 1000) & + 0x00FFFFFF; + return time_24_bits; +} + bool RemoteBitrateEstimatorAbsSendTime::IsWithinClusterBounds( int send_delta_ms, const Cluster& cluster_aggregate) { @@ -219,12 +228,8 @@ bool RemoteBitrateEstimatorAbsSendTime::IsBitrateImproving( void RemoteBitrateEstimatorAbsSendTime::IncomingPacketFeedbackVector( const std::vector& packet_feedback_vector) { for (const auto& packet_info : packet_feedback_vector) { - // TODO(holmer): We should get rid of this conversion if possible as we may - // lose precision. - uint32_t send_time_32bits = (packet_info.send_time_ms) / kTimestampToMs; - uint32_t send_time_24bits = - send_time_32bits >> kAbsSendTimeInterArrivalUpshift; - IncomingPacketInfo(packet_info.arrival_time_ms, send_time_24bits, + IncomingPacketInfo(packet_info.arrival_time_ms, + ConvertMsTo24Bits(packet_info.send_time_ms), packet_info.payload_size, 0, packet_info.was_paced); } } diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc index 8dc8ca6e41..b21f115065 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc @@ -26,8 +26,9 @@ namespace webrtc { // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. -const size_t kMaxPaddingLength = 224; -const int kSendSideDelayWindowMs = 1000; +static const size_t kMaxPaddingLength = 224; +static const int kSendSideDelayWindowMs = 1000; +static const uint32_t kAbsSendTimeFraction = 18; namespace { @@ -45,6 +46,16 @@ const char* FrameTypeToString(FrameType frame_type) { return ""; } +// TODO(holmer): Merge this with the implementation in +// remote_bitrate_estimator_abs_send_time.cc. +uint32_t ConvertMsTo24Bits(int64_t time_ms) { + uint32_t time_24_bits = + static_cast( + ((static_cast(time_ms) << kAbsSendTimeFraction) + 500) / + 1000) & + 0x00FFFFFF; + return time_24_bits; +} } // namespace class BitrateAggregator { @@ -1596,7 +1607,7 @@ void RTPSender::UpdateAbsoluteSendTime(uint8_t* rtp_packet, // Update absolute send time field (convert ms to 24-bit unsigned with 18 bit // fractional part). ByteWriter::WriteBigEndian(rtp_packet + offset + 1, - ((now_ms << 18) / 1000) & 0x00ffffff); + ConvertMsTo24Bits(now_ms)); } uint16_t RTPSender::UpdateTransportSequenceNumber( diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc index e4ace67a48..9be888c92a 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc @@ -64,7 +64,7 @@ size_t GetPayloadDataLength(const RTPHeader& rtp_header, } uint64_t ConvertMsToAbsSendTime(int64_t time_ms) { - return 0x00fffffful & ((time_ms << 18) / 1000); + return (((time_ms << 18) + 500) / 1000) & 0x00ffffff; } class LoopbackTransportTest : public webrtc::Transport {