summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--media/cast/congestion_control/congestion_control.cc3
-rw-r--r--media/cast/congestion_control/congestion_control.h4
-rw-r--r--media/cast/rtcp/rtcp.cc27
-rw-r--r--media/cast/rtcp/rtcp.h4
-rw-r--r--media/cast/rtcp/rtcp_receiver_unittest.cc9
-rw-r--r--media/cast/rtcp/rtcp_sender.cc10
-rw-r--r--media/cast/rtcp/rtcp_sender.h4
-rw-r--r--media/cast/rtcp/rtcp_sender_unittest.cc3
-rw-r--r--media/cast/rtcp/test_rtcp_packet_builder.cc4
-rw-r--r--media/cast/rtcp/test_rtcp_packet_builder.h4
10 files changed, 40 insertions, 32 deletions
diff --git a/media/cast/congestion_control/congestion_control.cc b/media/cast/congestion_control/congestion_control.cc
index d24e0ac..d0d08b3 100644
--- a/media/cast/congestion_control/congestion_control.cc
+++ b/media/cast/congestion_control/congestion_control.cc
@@ -59,8 +59,7 @@ CongestionControl::CongestionControl(base::TickClock* clock,
CongestionControl::~CongestionControl() {}
void CongestionControl::UpdateRtt(base::TimeDelta rtt) {
- rtt_ = base::TimeDelta::FromSecondsD(
- (rtt_.InSecondsF() * 7 + rtt.InSecondsF()) / 8);
+ rtt_ = (7 * rtt_ + rtt) / 8;
}
// Calculate how much "dead air" there is between two frames.
diff --git a/media/cast/congestion_control/congestion_control.h b/media/cast/congestion_control/congestion_control.h
index 54622ab..1c8a9d5 100644
--- a/media/cast/congestion_control/congestion_control.h
+++ b/media/cast/congestion_control/congestion_control.h
@@ -54,7 +54,7 @@ class CongestionControl {
// Get the FrameStats for a given |frame_id|.
// Note: Older FrameStats will be removed automatically.
FrameStats* GetFrameStats(uint32 frame_id);
- // Calculata safe bitrate. This is based on how much we've been
+ // Calculate a safe bitrate. This is based on how much we've been
// sending in the past.
double CalculateSafeBitrate();
@@ -63,7 +63,7 @@ class CongestionControl {
base::TimeTicks EstimatedAckTime(uint32 frame_id, double bitrate);
// Calculate when we start sending the data for a given frame.
// This is done by calculating when we were done sending the previous
- // frame, but obvoiusly can't be less than |sent_time| (if known).
+ // frame, but obviously can't be less than |sent_time| (if known).
base::TimeTicks EstimatedSendingTime(uint32 frame_id, double bitrate);
base::TickClock* const clock_; // Not owned by this class.
diff --git a/media/cast/rtcp/rtcp.cc b/media/cast/rtcp/rtcp.cc
index 480b2ac..ddf7fec 100644
--- a/media/cast/rtcp/rtcp.cc
+++ b/media/cast/rtcp/rtcp.cc
@@ -15,11 +15,13 @@
#include "media/cast/rtcp/rtcp_utility.h"
#include "media/cast/transport/cast_transport_defines.h"
+using base::TimeDelta;
+
namespace media {
namespace cast {
-static const int kMaxRttMs = 10000; // 10 seconds.
-static const int kMaxDelay = 2000;
+static const int32 kMaxRttMs = 10000; // 10 seconds.
+static const int32 kMaxDelayMs = 2000; // 2 seconds.
class LocalRtcpRttFeedback : public RtcpRttFeedback {
public:
@@ -98,7 +100,7 @@ Rtcp::Rtcp(scoped_refptr<CastEnvironment> cast_environment,
local_clock_ahead_by_(ClockDriftSmoother::GetDefaultTimeConstant()),
lip_sync_rtp_timestamp_(0),
lip_sync_ntp_timestamp_(0),
- min_rtt_(base::TimeDelta::FromMilliseconds(kMaxRttMs)),
+ min_rtt_(TimeDelta::FromMilliseconds(kMaxRttMs)),
number_of_rtt_in_avg_(0) {
rtcp_receiver_.reset(new RtcpReceiver(cast_environment, sender_feedback,
receiver_feedback_.get(),
@@ -201,7 +203,7 @@ void Rtcp::SendRtcpFromRtpReceiver(
&rrtr,
cast_message,
rtcp_events,
- target_delay_ms_);
+ target_delay_);
}
void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time,
@@ -302,8 +304,8 @@ void Rtcp::SetCastReceiverEventHistorySize(size_t size) {
}
void Rtcp::SetTargetDelay(base::TimeDelta target_delay) {
- DCHECK(target_delay.InMilliseconds() < kMaxDelay);
- target_delay_ms_ = static_cast<uint16>(target_delay.InMilliseconds());
+ DCHECK(target_delay < TimeDelta::FromMilliseconds(kMaxDelayMs));
+ target_delay_ = target_delay;
}
void Rtcp::OnReceivedDelaySinceLastReport(uint32 receivers_ssrc,
@@ -331,7 +333,7 @@ void Rtcp::SaveLastSentNtpTime(const base::TimeTicks& now,
last_reports_sent_map_[last_report] = now;
last_reports_sent_queue_.push(std::make_pair(last_report, now));
- base::TimeTicks timeout = now - base::TimeDelta::FromMilliseconds(kMaxRttMs);
+ base::TimeTicks timeout = now - TimeDelta::FromMilliseconds(kMaxRttMs);
// Cleanup old statistics older than |timeout|.
while (!last_reports_sent_queue_.empty()) {
@@ -358,11 +360,12 @@ void Rtcp::UpdateRtt(const base::TimeDelta& sender_delay,
// TODO(miu): Replace "average for all time" with an EWMA, or suitable
// "average over recent past" mechanism.
if (number_of_rtt_in_avg_ != 0) {
- const double ac = static_cast<double>(number_of_rtt_in_avg_);
- avg_rtt_ms_ = ((ac / (ac + 1.0)) * avg_rtt_ms_) +
- ((1.0 / (ac + 1.0)) * rtt.InMillisecondsF());
+ // Integer math equivalent of (ac/(ac+1.0))*avg_rtt_ + (1.0/(ac+1.0))*rtt).
+ // (TimeDelta only supports math with other TimeDeltas and int64s.)
+ avg_rtt_ = (avg_rtt_ * number_of_rtt_in_avg_ + rtt) /
+ (number_of_rtt_in_avg_ + 1);
} else {
- avg_rtt_ms_ = rtt.InMillisecondsF();
+ avg_rtt_ = rtt;
}
number_of_rtt_in_avg_++;
}
@@ -377,7 +380,7 @@ bool Rtcp::Rtt(base::TimeDelta* rtt, base::TimeDelta* avg_rtt,
if (number_of_rtt_in_avg_ == 0) return false;
*rtt = rtt_;
- *avg_rtt = base::TimeDelta::FromMillisecondsD(avg_rtt_ms_);
+ *avg_rtt = avg_rtt_;
*min_rtt = min_rtt_;
*max_rtt = max_rtt_;
return true;
diff --git a/media/cast/rtcp/rtcp.h b/media/cast/rtcp/rtcp.h
index 9d0184f..e7cdb6c 100644
--- a/media/cast/rtcp/rtcp.h
+++ b/media/cast/rtcp/rtcp.h
@@ -194,8 +194,8 @@ class Rtcp {
base::TimeDelta min_rtt_;
base::TimeDelta max_rtt_;
int number_of_rtt_in_avg_;
- double avg_rtt_ms_;
- uint16 target_delay_ms_;
+ base::TimeDelta avg_rtt_;
+ base::TimeDelta target_delay_;
DISALLOW_COPY_AND_ASSIGN(Rtcp);
};
diff --git a/media/cast/rtcp/rtcp_receiver_unittest.cc b/media/cast/rtcp/rtcp_receiver_unittest.cc
index 51026d1..485c3ee 100644
--- a/media/cast/rtcp/rtcp_receiver_unittest.cc
+++ b/media/cast/rtcp/rtcp_receiver_unittest.cc
@@ -22,7 +22,8 @@ using testing::_;
static const uint32 kSenderSsrc = 0x10203;
static const uint32 kSourceSsrc = 0x40506;
static const uint32 kUnknownSsrc = 0xDEAD;
-static const uint16 kTargetDelayMs = 100;
+static const base::TimeDelta kTargetDelay =
+ base::TimeDelta::FromMilliseconds(100);
static const std::string kCName("test@10.1.1.1");
namespace {
@@ -374,7 +375,7 @@ TEST_F(RtcpReceiverTest, InjectReceiverReportPacketWithCastFeedback) {
TestRtcpPacketBuilder p1;
p1.AddRr(kSenderSsrc, 1);
p1.AddRb(kUnknownSsrc);
- p1.AddCast(kSenderSsrc, kUnknownSsrc, kTargetDelayMs);
+ p1.AddCast(kSenderSsrc, kUnknownSsrc, kTargetDelay);
// Expected to be ignored since the source ssrc does not match our
// local ssrc.
@@ -391,7 +392,7 @@ TEST_F(RtcpReceiverTest, InjectReceiverReportPacketWithCastFeedback) {
TestRtcpPacketBuilder p2;
p2.AddRr(kSenderSsrc, 1);
p2.AddRb(kSourceSsrc);
- p2.AddCast(kSenderSsrc, kSourceSsrc, kTargetDelayMs);
+ p2.AddCast(kSenderSsrc, kSourceSsrc, kTargetDelay);
// Expected to be pass through since the sender ssrc match our local ssrc.
InjectRtcpPacket(p2.Data(), p2.Length());
@@ -415,7 +416,7 @@ TEST_F(RtcpReceiverTest, InjectReceiverReportPacketWithCastVerification) {
TestRtcpPacketBuilder p;
p.AddRr(kSenderSsrc, 1);
p.AddRb(kSourceSsrc);
- p.AddCast(kSenderSsrc, kSourceSsrc, kTargetDelayMs);
+ p.AddCast(kSenderSsrc, kSourceSsrc, kTargetDelay);
// Expected to be pass through since the sender ssrc match our local ssrc.
RtcpParser rtcp_parser(p.Data(), p.Length());
diff --git a/media/cast/rtcp/rtcp_sender.cc b/media/cast/rtcp/rtcp_sender.cc
index bf7d30c..4bed377 100644
--- a/media/cast/rtcp/rtcp_sender.cc
+++ b/media/cast/rtcp/rtcp_sender.cc
@@ -166,7 +166,7 @@ void RtcpSender::SendRtcpFromRtpReceiver(
const RtcpReceiverReferenceTimeReport* rrtr,
const RtcpCastMessage* cast_message,
const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events,
- uint16 target_delay_ms) {
+ base::TimeDelta target_delay) {
if (packet_type_flags & transport::kRtcpSr ||
packet_type_flags & transport::kRtcpDlrr ||
packet_type_flags & transport::kRtcpSenderLog) {
@@ -197,7 +197,7 @@ void RtcpSender::SendRtcpFromRtpReceiver(
}
if (packet_type_flags & transport::kRtcpCast) {
DCHECK(cast_message) << "Invalid argument";
- BuildCast(cast_message, target_delay_ms, &packet->data);
+ BuildCast(cast_message, target_delay, &packet->data);
}
if (packet_type_flags & transport::kRtcpReceiverLog) {
DCHECK(rtcp_events) << "Invalid argument";
@@ -529,7 +529,7 @@ void RtcpSender::BuildRrtr(const RtcpReceiverReferenceTimeReport* rrtr,
}
void RtcpSender::BuildCast(const RtcpCastMessage* cast,
- uint16 target_delay_ms,
+ base::TimeDelta target_delay,
Packet* packet) const {
size_t start_size = packet->size();
DCHECK_LT(start_size + 20, kMaxIpPacketSize) << "Not enough buffer space";
@@ -552,7 +552,9 @@ void RtcpSender::BuildCast(const RtcpCastMessage* cast,
big_endian_writer.WriteU8(static_cast<uint8>(cast->ack_frame_id_));
size_t cast_loss_field_pos = start_size + 17; // Save loss field position.
big_endian_writer.WriteU8(0); // Overwritten with number_of_loss_fields.
- big_endian_writer.WriteU16(target_delay_ms);
+ DCHECK_LE(target_delay.InMilliseconds(),
+ std::numeric_limits<uint16_t>::max());
+ big_endian_writer.WriteU16(target_delay.InMilliseconds());
size_t number_of_loss_fields = 0;
size_t max_number_of_loss_fields = std::min<size_t>(
diff --git a/media/cast/rtcp/rtcp_sender.h b/media/cast/rtcp/rtcp_sender.h
index f09a4fb..bec05c1 100644
--- a/media/cast/rtcp/rtcp_sender.h
+++ b/media/cast/rtcp/rtcp_sender.h
@@ -56,7 +56,7 @@ class RtcpSender {
const RtcpReceiverReferenceTimeReport* rrtr,
const RtcpCastMessage* cast_message,
const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events,
- uint16 target_delay_ms);
+ base::TimeDelta target_delay);
private:
void BuildRR(const transport::RtcpReportBlock* report_block,
@@ -81,7 +81,7 @@ class RtcpSender {
Packet* packet) const;
void BuildCast(const RtcpCastMessage* cast_message,
- uint16 target_delay_ms,
+ base::TimeDelta target_delay,
Packet* packet) const;
void BuildReceiverLog(
diff --git a/media/cast/rtcp/rtcp_sender_unittest.cc b/media/cast/rtcp/rtcp_sender_unittest.cc
index 0b0c7d3..49534f6 100644
--- a/media/cast/rtcp/rtcp_sender_unittest.cc
+++ b/media/cast/rtcp/rtcp_sender_unittest.cc
@@ -21,7 +21,8 @@ namespace cast {
namespace {
static const uint32 kSendingSsrc = 0x12345678;
static const uint32 kMediaSsrc = 0x87654321;
-static const int16 kDefaultDelay = 100;
+static const base::TimeDelta kDefaultDelay =
+ base::TimeDelta::FromMilliseconds(100);
static const std::string kCName("test@10.1.1.1");
transport::RtcpReportBlock GetReportBlock() {
diff --git a/media/cast/rtcp/test_rtcp_packet_builder.cc b/media/cast/rtcp/test_rtcp_packet_builder.cc
index 8d0809d..5bfebf6 100644
--- a/media/cast/rtcp/test_rtcp_packet_builder.cc
+++ b/media/cast/rtcp/test_rtcp_packet_builder.cc
@@ -191,7 +191,7 @@ void TestRtcpPacketBuilder::AddRemb(uint32 sender_ssrc, uint32 media_ssrc) {
void TestRtcpPacketBuilder::AddCast(uint32 sender_ssrc,
uint32 media_ssrc,
- uint16 target_delay_ms) {
+ base::TimeDelta target_delay) {
AddRtcpHeader(206, 15);
big_endian_writer_.WriteU32(sender_ssrc);
big_endian_writer_.WriteU32(media_ssrc);
@@ -201,7 +201,7 @@ void TestRtcpPacketBuilder::AddCast(uint32 sender_ssrc,
big_endian_writer_.WriteU8('T');
big_endian_writer_.WriteU8(kAckFrameId);
big_endian_writer_.WriteU8(3); // Loss fields.
- big_endian_writer_.WriteU16(target_delay_ms);
+ big_endian_writer_.WriteU16(target_delay.InMilliseconds());
big_endian_writer_.WriteU8(kLostFrameId);
big_endian_writer_.WriteU16(kRtcpCastAllPacketsLost);
big_endian_writer_.WriteU8(0); // Lost packet id mask.
diff --git a/media/cast/rtcp/test_rtcp_packet_builder.h b/media/cast/rtcp/test_rtcp_packet_builder.h
index d426667..679085c 100644
--- a/media/cast/rtcp/test_rtcp_packet_builder.h
+++ b/media/cast/rtcp/test_rtcp_packet_builder.h
@@ -79,7 +79,9 @@ class TestRtcpPacketBuilder {
void AddPli(uint32 sender_ssrc, uint32 media_ssrc);
void AddRpsi(uint32 sender_ssrc, uint32 media_ssrc);
void AddRemb(uint32 sender_ssrc, uint32 media_ssrc);
- void AddCast(uint32 sender_ssrc, uint32 media_ssrc, uint16 target_delay_ms);
+ void AddCast(uint32 sender_ssrc,
+ uint32 media_ssrc,
+ base::TimeDelta target_delay);
void AddReceiverLog(uint32 sender_ssrc);
void AddReceiverFrameLog(uint32 rtp_timestamp,
int num_events,