diff options
author | hubbe <hubbe@chromium.org> | 2014-11-21 16:05:59 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-22 00:06:29 +0000 |
commit | 9d51ce79eddc3ccf343248d4f34924de227ad3d5 (patch) | |
tree | 58e1f03e7473a3b02b8a7ab57c73c9018696adb6 /media | |
parent | b5236ab8c10dcc804067398c01bb34605513e71b (diff) | |
download | chromium_src-9d51ce79eddc3ccf343248d4f34924de227ad3d5.zip chromium_src-9d51ce79eddc3ccf343248d4f34924de227ad3d5.tar.gz chromium_src-9d51ce79eddc3ccf343248d4f34924de227ad3d5.tar.bz2 |
Cast: Clean up RtpReceiverStatistics handling.
This is in preparation for making a cast_streaming receiver.
The transport interface will need the stats to be a POD, not an interface.
Review URL: https://codereview.chromium.org/743093003
Cr-Commit-Position: refs/heads/master@{#305325}
Diffstat (limited to 'media')
-rw-r--r-- | media/cast/net/rtcp/rtcp.cc | 15 | ||||
-rw-r--r-- | media/cast/net/rtcp/rtcp.h | 14 | ||||
-rw-r--r-- | media/cast/net/rtcp/rtcp_unittest.cc | 23 | ||||
-rw-r--r-- | media/cast/net/rtp/receiver_stats.cc | 26 | ||||
-rw-r--r-- | media/cast/net/rtp/receiver_stats.h | 8 | ||||
-rw-r--r-- | media/cast/net/rtp/receiver_stats_unittest.cc | 82 | ||||
-rw-r--r-- | media/cast/receiver/frame_receiver.cc | 3 |
7 files changed, 63 insertions, 108 deletions
diff --git a/media/cast/net/rtcp/rtcp.cc b/media/cast/net/rtcp/rtcp.cc index 77be988..4e42ed0 100644 --- a/media/cast/net/rtcp/rtcp.cc +++ b/media/cast/net/rtcp/rtcp.cc @@ -53,6 +53,12 @@ std::pair<uint64, uint64> GetReceiverEventKey( } // namespace +RtpReceiverStatistics::RtpReceiverStatistics() : + fraction_lost(0), + cumulative_lost(0), + extended_high_sequence_number(0), + jitter(0) { +} Rtcp::Rtcp(const RtcpCastMessageCallback& cast_callback, const RtcpRttCallback& rtt_callback, @@ -209,10 +215,11 @@ void Rtcp::SendRtcpFromRtpReceiver( if (rtp_receiver_statistics) { report_block.remote_ssrc = 0; // Not needed to set send side. report_block.media_ssrc = remote_ssrc_; // SSRC of the RTP packet sender. - rtp_receiver_statistics->GetStatistics( - &report_block.fraction_lost, &report_block.cumulative_lost, - &report_block.extended_high_sequence_number, &report_block.jitter); - + report_block.fraction_lost = rtp_receiver_statistics->fraction_lost; + report_block.cumulative_lost = rtp_receiver_statistics->cumulative_lost; + report_block.extended_high_sequence_number = + rtp_receiver_statistics->extended_high_sequence_number; + report_block.jitter = rtp_receiver_statistics->jitter; report_block.last_sr = last_report_truncated_ntp_; if (!time_last_report_received_.is_null()) { uint32 delay_seconds = 0; diff --git a/media/cast/net/rtcp/rtcp.h b/media/cast/net/rtcp/rtcp.h index 6b32084..d1cfa48 100644 --- a/media/cast/net/rtcp/rtcp.h +++ b/media/cast/net/rtcp/rtcp.h @@ -38,14 +38,12 @@ typedef std::pair<uint32, base::TimeTicks> RtcpSendTimePair; typedef std::map<uint32, base::TimeTicks> RtcpSendTimeMap; typedef std::queue<RtcpSendTimePair> RtcpSendTimeQueue; -class RtpReceiverStatistics { - public: - virtual void GetStatistics(uint8* fraction_lost, - uint32* cumulative_lost, // 24 bits valid. - uint32* extended_high_sequence_number, - uint32* jitter) = 0; - - virtual ~RtpReceiverStatistics() {} +struct RtpReceiverStatistics { + RtpReceiverStatistics(); + uint8 fraction_lost; + uint32 cumulative_lost; // 24 bits valid. + uint32 extended_high_sequence_number; + uint32 jitter; }; // TODO(hclam): This should be renamed to RtcpSession. diff --git a/media/cast/net/rtcp/rtcp_unittest.cc b/media/cast/net/rtcp/rtcp_unittest.cc index 707cd95..e0c9f0a 100644 --- a/media/cast/net/rtcp/rtcp_unittest.cc +++ b/media/cast/net/rtcp/rtcp_unittest.cc @@ -55,25 +55,6 @@ class FakeRtcpTransport : public PacedPacketSender { DISALLOW_COPY_AND_ASSIGN(FakeRtcpTransport); }; -class FakeReceiverStats : public RtpReceiverStatistics { - public: - FakeReceiverStats() {} - ~FakeReceiverStats() override {} - - void GetStatistics(uint8* fraction_lost, - uint32* cumulative_lost, - uint32* extended_high_sequence_number, - uint32* jitter) override { - *fraction_lost = 0; - *cumulative_lost = 0; - *extended_high_sequence_number = 0; - *jitter = 0; - } - - private: - DISALLOW_COPY_AND_ASSIGN(FakeReceiverStats); -}; - class MockFrameSender { public: MockFrameSender() {} @@ -128,7 +109,6 @@ class RtcpTest : public ::testing::Test { MockFrameSender mock_frame_sender_; Rtcp rtcp_for_sender_; Rtcp rtcp_for_receiver_; - FakeReceiverStats stats_; DISALLOW_COPY_AND_ASSIGN(RtcpTest); }; @@ -198,8 +178,9 @@ TEST_F(RtcpTest, RoundTripTimesDeterminedFromReportPingPong) { #endif // Receiver --> Sender + RtpReceiverStatistics stats; rtcp_for_receiver_.SendRtcpFromRtpReceiver( - NULL, base::TimeDelta(), NULL, &stats_); + NULL, base::TimeDelta(), NULL, &stats); expected_rtt_according_to_sender = one_way_trip_time * 2; EXPECT_EQ(expected_rtt_according_to_sender, rtcp_for_sender_.current_round_trip_time()); diff --git a/media/cast/net/rtp/receiver_stats.cc b/media/cast/net/rtp/receiver_stats.cc index 416cdd8..2dbdbcb 100644 --- a/media/cast/net/rtp/receiver_stats.cc +++ b/media/cast/net/rtp/receiver_stats.cc @@ -22,15 +22,11 @@ ReceiverStats::ReceiverStats(base::TickClock* clock) interval_number_packets_(0), interval_wrap_count_(0) {} -ReceiverStats::~ReceiverStats() {} - -void ReceiverStats::GetStatistics(uint8* fraction_lost, - uint32* cumulative_lost, - uint32* extended_high_sequence_number, - uint32* jitter) { +RtpReceiverStatistics ReceiverStats::GetStatistics() { + RtpReceiverStatistics ret; // Compute losses. if (interval_number_packets_ == 0) { - *fraction_lost = 0; + ret.fraction_lost = 0; } else { int diff = 0; if (interval_wrap_count_ == 0) { @@ -42,36 +38,38 @@ void ReceiverStats::GetStatistics(uint8* fraction_lost, } if (diff < 1) { - *fraction_lost = 0; + ret.fraction_lost = 0; } else { float tmp_ratio = (1 - static_cast<float>(interval_number_packets_) / abs(diff)); - *fraction_lost = static_cast<uint8>(256 * tmp_ratio); + ret.fraction_lost = static_cast<uint8>(256 * tmp_ratio); } } int expected_packets_num = max_sequence_number_ - min_sequence_number_ + 1; if (total_number_packets_ == 0) { - *cumulative_lost = 0; + ret.cumulative_lost = 0; } else if (sequence_number_cycles_ == 0) { - *cumulative_lost = expected_packets_num - total_number_packets_; + ret.cumulative_lost = expected_packets_num - total_number_packets_; } else { - *cumulative_lost = + ret.cumulative_lost = kMaxSequenceNumber * (sequence_number_cycles_ - 1) + (expected_packets_num - total_number_packets_ + kMaxSequenceNumber); } // Extended high sequence number consists of the highest seq number and the // number of cycles (wrap). - *extended_high_sequence_number = + ret.extended_high_sequence_number = (sequence_number_cycles_ << 16) + max_sequence_number_; - *jitter = static_cast<uint32>(std::abs(jitter_.InMillisecondsRoundedUp())); + ret.jitter = static_cast<uint32>(std::abs(jitter_.InMillisecondsRoundedUp())); // Reset interval values. interval_min_sequence_number_ = 0; interval_number_packets_ = 0; interval_wrap_count_ = 0; + + return ret; } void ReceiverStats::UpdateStatistics(const RtpCastHeader& header) { diff --git a/media/cast/net/rtp/receiver_stats.h b/media/cast/net/rtp/receiver_stats.h index d428403..9cdda97 100644 --- a/media/cast/net/rtp/receiver_stats.h +++ b/media/cast/net/rtp/receiver_stats.h @@ -13,15 +13,11 @@ namespace media { namespace cast { -class ReceiverStats : public RtpReceiverStatistics { +class ReceiverStats { public: explicit ReceiverStats(base::TickClock* clock); - ~ReceiverStats() override; - void GetStatistics(uint8* fraction_lost, - uint32* cumulative_lost, // 24 bits valid. - uint32* extended_high_sequence_number, - uint32* jitter) override; + RtpReceiverStatistics GetStatistics(); void UpdateStatistics(const RtpCastHeader& header); private: diff --git a/media/cast/net/rtp/receiver_stats_unittest.cc b/media/cast/net/rtp/receiver_stats_unittest.cc index 7bb3dd1..4bde4a3 100644 --- a/media/cast/net/rtp/receiver_stats_unittest.cc +++ b/media/cast/net/rtp/receiver_stats_unittest.cc @@ -20,11 +20,7 @@ static const uint32 kStdTimeIncrementMs = 33; class ReceiverStatsTest : public ::testing::Test { protected: ReceiverStatsTest() - : stats_(&testing_clock_), - fraction_lost_(0), - cumulative_lost_(0), - extended_high_sequence_number_(0), - jitter_(0) { + : stats_(&testing_clock_) { testing_clock_.Advance( base::TimeDelta::FromMilliseconds(kStartMillisecond)); start_time_ = testing_clock_.NowTicks(); @@ -45,10 +41,6 @@ class ReceiverStatsTest : public ::testing::Test { ReceiverStats stats_; RtpCastHeader rtp_header_; - uint8 fraction_lost_; - uint32 cumulative_lost_; - uint32 extended_high_sequence_number_; - uint32 jitter_; base::SimpleTestTickClock testing_clock_; base::TimeTicks start_time_; base::TimeDelta delta_increments_; @@ -57,14 +49,11 @@ class ReceiverStatsTest : public ::testing::Test { }; TEST_F(ReceiverStatsTest, ResetState) { - stats_.GetStatistics(&fraction_lost_, - &cumulative_lost_, - &extended_high_sequence_number_, - &jitter_); - EXPECT_EQ(0u, fraction_lost_); - EXPECT_EQ(0u, cumulative_lost_); - EXPECT_EQ(0u, extended_high_sequence_number_); - EXPECT_EQ(0u, jitter_); + RtpReceiverStatistics s = stats_.GetStatistics(); + EXPECT_EQ(0u, s.fraction_lost); + EXPECT_EQ(0u, s.cumulative_lost); + EXPECT_EQ(0u, s.extended_high_sequence_number); + EXPECT_EQ(0u, s.jitter); } TEST_F(ReceiverStatsTest, LossCount) { @@ -77,15 +66,12 @@ TEST_F(ReceiverStatsTest, LossCount) { ++rtp_header_.sequence_number; testing_clock_.Advance(delta_increments_); } - stats_.GetStatistics(&fraction_lost_, - &cumulative_lost_, - &extended_high_sequence_number_, - &jitter_); - EXPECT_EQ(63u, fraction_lost_); - EXPECT_EQ(74u, cumulative_lost_); + RtpReceiverStatistics s = stats_.GetStatistics(); + EXPECT_EQ(63u, s.fraction_lost); + EXPECT_EQ(74u, s.cumulative_lost); // Build extended sequence number. const uint32 extended_seq_num = rtp_header_.sequence_number - 1; - EXPECT_EQ(extended_seq_num, extended_high_sequence_number_); + EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number); } TEST_F(ReceiverStatsTest, NoLossWrap) { @@ -98,15 +84,12 @@ TEST_F(ReceiverStatsTest, NoLossWrap) { ++rtp_header_.sequence_number; testing_clock_.Advance(delta_increments_); } - stats_.GetStatistics(&fraction_lost_, - &cumulative_lost_, - &extended_high_sequence_number_, - &jitter_); - EXPECT_EQ(0u, fraction_lost_); - EXPECT_EQ(0u, cumulative_lost_); + RtpReceiverStatistics s = stats_.GetStatistics(); + EXPECT_EQ(0u, s.fraction_lost); + EXPECT_EQ(0u, s.cumulative_lost); // Build extended sequence number (one wrap cycle). const uint32 extended_seq_num = (1 << 16) + rtp_header_.sequence_number - 1; - EXPECT_EQ(extended_seq_num, extended_high_sequence_number_); + EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number); } TEST_F(ReceiverStatsTest, LossCountWrap) { @@ -121,15 +104,12 @@ TEST_F(ReceiverStatsTest, LossCountWrap) { ++rtp_header_.sequence_number; testing_clock_.Advance(delta_increments_); } - stats_.GetStatistics(&fraction_lost_, - &cumulative_lost_, - &extended_high_sequence_number_, - &jitter_); - EXPECT_EQ(63u, fraction_lost_); - EXPECT_EQ(74u, cumulative_lost_); + RtpReceiverStatistics s = stats_.GetStatistics(); + EXPECT_EQ(63u, s.fraction_lost); + EXPECT_EQ(74u, s.cumulative_lost); // Build extended sequence number (one wrap cycle). const uint32 extended_seq_num = (1 << 16) + rtp_header_.sequence_number - 1; - EXPECT_EQ(extended_seq_num, extended_high_sequence_number_); + EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number); } TEST_F(ReceiverStatsTest, BasicJitter) { @@ -139,16 +119,13 @@ TEST_F(ReceiverStatsTest, BasicJitter) { rtp_header_.rtp_timestamp += 33 * 90; testing_clock_.Advance(delta_increments_); } - stats_.GetStatistics(&fraction_lost_, - &cumulative_lost_, - &extended_high_sequence_number_, - &jitter_); - EXPECT_FALSE(fraction_lost_); - EXPECT_FALSE(cumulative_lost_); + RtpReceiverStatistics s = stats_.GetStatistics(); + EXPECT_FALSE(s.fraction_lost); + EXPECT_FALSE(s.cumulative_lost); // Build extended sequence number (one wrap cycle). const uint32 extended_seq_num = rtp_header_.sequence_number - 1; - EXPECT_EQ(extended_seq_num, extended_high_sequence_number_); - EXPECT_EQ(ExpectedJitter(kStdTimeIncrementMs, 300), jitter_); + EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number); + EXPECT_EQ(ExpectedJitter(kStdTimeIncrementMs, 300), s.jitter); } TEST_F(ReceiverStatsTest, NonTrivialJitter) { @@ -161,17 +138,14 @@ TEST_F(ReceiverStatsTest, NonTrivialJitter) { base::TimeDelta::FromMilliseconds(kAdditionalIncrement); testing_clock_.Advance(delta_increments_ + additional_delta); } - stats_.GetStatistics(&fraction_lost_, - &cumulative_lost_, - &extended_high_sequence_number_, - &jitter_); - EXPECT_FALSE(fraction_lost_); - EXPECT_FALSE(cumulative_lost_); + RtpReceiverStatistics s = stats_.GetStatistics(); + EXPECT_FALSE(s.fraction_lost); + EXPECT_FALSE(s.cumulative_lost); // Build extended sequence number (one wrap cycle). const uint32 extended_seq_num = rtp_header_.sequence_number - 1; - EXPECT_EQ(extended_seq_num, extended_high_sequence_number_); + EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number); EXPECT_EQ(ExpectedJitter(kStdTimeIncrementMs + kAdditionalIncrement, 300), - jitter_); + s.jitter); } } // namespace cast diff --git a/media/cast/receiver/frame_receiver.cc b/media/cast/receiver/frame_receiver.cc index 095e611..561e19f 100644 --- a/media/cast/receiver/frame_receiver.cc +++ b/media/cast/receiver/frame_receiver.cc @@ -336,7 +336,8 @@ void FrameReceiver::ScheduleNextRtcpReport() { void FrameReceiver::SendNextRtcpReport() { DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); - rtcp_.SendRtcpFromRtpReceiver(NULL, base::TimeDelta(), NULL, &stats_); + RtpReceiverStatistics stats = stats_.GetStatistics(); + rtcp_.SendRtcpFromRtpReceiver(NULL, base::TimeDelta(), NULL, &stats); ScheduleNextRtcpReport(); } |