| Index: media/cast/logging/logging_unittest.cc
|
| diff --git a/media/cast/logging/logging_unittest.cc b/media/cast/logging/logging_unittest.cc
|
| index 75915de293c0d4823292cdeb0ddee1fcc086f5fa..b7bed1751ab6d1b66e5dcc34b1fcc1550af5dbed 100644
|
| --- a/media/cast/logging/logging_unittest.cc
|
| +++ b/media/cast/logging/logging_unittest.cc
|
| @@ -42,6 +42,8 @@ class TestLogging : public ::testing::Test {
|
| scoped_refptr<test::FakeTaskRunner> task_runner_;
|
| scoped_ptr<LoggingImpl> logging_;
|
| base::SimpleTestTickClock testing_clock_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestLogging);
|
| };
|
|
|
| TEST_F(TestLogging, BasicFrameLogging) {
|
| @@ -49,31 +51,35 @@ TEST_F(TestLogging, BasicFrameLogging) {
|
| base::TimeDelta time_interval = testing_clock_.NowTicks() - start_time;
|
| uint32 rtp_timestamp = 0;
|
| uint32 frame_id = 0;
|
| + base::TimeTicks now;
|
| do {
|
| - logging_->InsertFrameEvent(testing_clock_.NowTicks(),
|
| - kAudioFrameCaptured, rtp_timestamp, frame_id);
|
| + now = testing_clock_.NowTicks();
|
| + logging_->InsertFrameEvent(now, kAudioFrameCaptured, rtp_timestamp,
|
| + frame_id);
|
| testing_clock_.Advance(
|
| base::TimeDelta::FromMilliseconds(kFrameIntervalMs));
|
| rtp_timestamp += kFrameIntervalMs * 90;
|
| ++frame_id;
|
| - time_interval = testing_clock_.NowTicks() - start_time;
|
| + time_interval = now - start_time;
|
| } while (time_interval.InSeconds() < kIntervalTime1S);
|
| + base::TimeTicks end_time = now;
|
| // Get logging data.
|
| FrameRawMap frame_map = logging_->GetFrameRawData();
|
| // Size of map should be equal to the number of frames logged.
|
| EXPECT_EQ(frame_id, frame_map.size());
|
| // Verify stats.
|
| - const FrameStatsMap* frame_stats =
|
| - logging_->GetFrameStatsData(testing_clock_.NowTicks());
|
| + FrameStatsMap frame_stats = logging_->GetFrameStatsData();
|
| // Size of stats equals the number of events.
|
| - EXPECT_EQ(1u, frame_stats->size());
|
| - FrameStatsMap::const_iterator it = frame_stats->find(kAudioFrameCaptured);
|
| - EXPECT_TRUE(it != frame_stats->end());
|
| - EXPECT_NEAR(30.3, it->second->framerate_fps, 0.1);
|
| - EXPECT_EQ(0, it->second->bitrate_kbps);
|
| - EXPECT_EQ(0, it->second->max_delay_ms);
|
| - EXPECT_EQ(0, it->second->min_delay_ms);
|
| - EXPECT_EQ(0, it->second->avg_delay_ms);
|
| + EXPECT_EQ(1u, frame_stats.size());
|
| + FrameStatsMap::const_iterator it = frame_stats.find(kAudioFrameCaptured);
|
| + EXPECT_TRUE(it != frame_stats.end());
|
| + EXPECT_EQ(0, it->second.max_delay.InMilliseconds());
|
| + EXPECT_EQ(0, it->second.min_delay.InMilliseconds());
|
| + EXPECT_EQ(start_time, it->second.first_event_time);
|
| + EXPECT_EQ(end_time, it->second.last_event_time);
|
| + EXPECT_EQ(0u, it->second.sum_size);
|
| + // Number of events is equal to the number of frames.
|
| + EXPECT_EQ(static_cast<int>(frame_id), it->second.event_counter);
|
| }
|
|
|
| TEST_F(TestLogging, FrameLoggingWithSize) {
|
| @@ -84,9 +90,11 @@ TEST_F(TestLogging, FrameLoggingWithSize) {
|
| base::TimeDelta time_interval = testing_clock_.NowTicks() - start_time;
|
| uint32 rtp_timestamp = 0;
|
| uint32 frame_id = 0;
|
| + size_t sum_size = 0;
|
| do {
|
| int size = kBaseFrameSizeBytes +
|
| base::RandInt(-kRandomSizeInterval, kRandomSizeInterval);
|
| + sum_size += static_cast<size_t>(size);
|
| logging_->InsertFrameEventWithSize(testing_clock_.NowTicks(),
|
| kAudioFrameCaptured, rtp_timestamp, frame_id, size);
|
| testing_clock_.Advance(
|
| @@ -100,18 +108,15 @@ TEST_F(TestLogging, FrameLoggingWithSize) {
|
| // Size of map should be equal to the number of frames logged.
|
| EXPECT_EQ(frame_id, frame_map.size());
|
| // Verify stats.
|
| - const FrameStatsMap* frame_stats =
|
| - logging_->GetFrameStatsData(testing_clock_.NowTicks());
|
| + FrameStatsMap frame_stats = logging_->GetFrameStatsData();
|
| // Size of stats equals the number of events.
|
| - EXPECT_EQ(1u, frame_stats->size());
|
| - FrameStatsMap::const_iterator it = frame_stats->find(kAudioFrameCaptured);
|
| - EXPECT_TRUE(it != frame_stats->end());
|
| - EXPECT_NEAR(30.3, it->second->framerate_fps, 0.1);
|
| - EXPECT_NEAR(8 * kBaseFrameSizeBytes / (kFrameIntervalMs * 1000),
|
| - it->second->bitrate_kbps, kRandomSizeInterval);
|
| - EXPECT_EQ(0, it->second->max_delay_ms);
|
| - EXPECT_EQ(0, it->second->min_delay_ms);
|
| - EXPECT_EQ(0, it->second->avg_delay_ms);
|
| + EXPECT_EQ(1u, frame_stats.size());
|
| + FrameStatsMap::const_iterator it = frame_stats.find(kAudioFrameCaptured);
|
| + EXPECT_TRUE(it != frame_stats.end());
|
| + EXPECT_EQ(0, it->second.max_delay.InMilliseconds());
|
| + EXPECT_EQ(0, it->second.min_delay.InMilliseconds());
|
| + EXPECT_EQ(0, it->second.sum_delay.InMilliseconds());
|
| + EXPECT_EQ(sum_size, it->second.sum_size);
|
| }
|
|
|
| TEST_F(TestLogging, FrameLoggingWithDelay) {
|
| @@ -139,18 +144,15 @@ TEST_F(TestLogging, FrameLoggingWithDelay) {
|
| // Size of map should be equal to the number of frames logged.
|
| EXPECT_EQ(frame_id, frame_map.size());
|
| // Verify stats.
|
| - const FrameStatsMap* frame_stats =
|
| - logging_->GetFrameStatsData(testing_clock_.NowTicks());
|
| + FrameStatsMap frame_stats = logging_->GetFrameStatsData();
|
| // Size of stats equals the number of events.
|
| - EXPECT_EQ(1u, frame_stats->size());
|
| - FrameStatsMap::const_iterator it = frame_stats->find(kAudioFrameCaptured);
|
| - EXPECT_TRUE(it != frame_stats->end());
|
| - EXPECT_NEAR(30.3, it->second->framerate_fps, 0.1);
|
| - EXPECT_EQ(0, it->second->bitrate_kbps);
|
| - EXPECT_GE(kPlayoutDelayMs + kRandomSizeInterval, it->second->max_delay_ms);
|
| - EXPECT_LE(kPlayoutDelayMs - kRandomSizeInterval, it->second->min_delay_ms);
|
| - EXPECT_NEAR(kPlayoutDelayMs, it->second->avg_delay_ms,
|
| - 0.2 * kRandomSizeInterval);
|
| + EXPECT_EQ(1u, frame_stats.size());
|
| + FrameStatsMap::const_iterator it = frame_stats.find(kAudioFrameCaptured);
|
| + EXPECT_TRUE(it != frame_stats.end());
|
| + EXPECT_GE(kPlayoutDelayMs + kRandomSizeInterval,
|
| + it->second.max_delay.InMilliseconds());
|
| + EXPECT_LE(kPlayoutDelayMs - kRandomSizeInterval,
|
| + it->second.min_delay.InMilliseconds());
|
| }
|
|
|
| TEST_F(TestLogging, MultipleEventFrameLogging) {
|
| @@ -210,37 +212,54 @@ TEST_F(TestLogging, PacketLogging) {
|
| // Size of map should be equal to the number of frames logged.
|
| EXPECT_EQ(frame_id, raw_map.size());
|
| // Verify stats.
|
| - const PacketStatsMap* stats_map =
|
| - logging_->GetPacketStatsData(testing_clock_.NowTicks());
|
| + PacketStatsMap stats_map = logging_->GetPacketStatsData();
|
| // Size of stats equals the number of events.
|
| - EXPECT_EQ(1u, stats_map->size());
|
| - PacketStatsMap::const_iterator it = stats_map->find(kPacketSentToPacer);
|
| - EXPECT_TRUE(it != stats_map->end());
|
| - // We only store the bitrate as a packet statistic.
|
| - EXPECT_NEAR(8 * kNumPacketsPerFrame * kBaseSize / (kFrameIntervalMs * 1000),
|
| - it->second, kSizeInterval);
|
| + EXPECT_EQ(1u, stats_map.size());
|
| + PacketStatsMap::const_iterator it = stats_map.find(kPacketSentToPacer);
|
| + EXPECT_TRUE(it != stats_map.end());
|
| }
|
|
|
| TEST_F(TestLogging, GenericLogging) {
|
| // Insert multiple generic types.
|
| - const size_t kNumRuns = 1000;
|
| + const size_t kNumRuns = 20;//1000;
|
| const int kBaseValue = 20;
|
| + int sum_value_rtt = 0;
|
| + int sum_value_pl = 0;
|
| + int sum_value_jitter = 0;
|
| + uint64 sumsq_value_rtt = 0;
|
| + uint64 sumsq_value_pl = 0;
|
| + uint64 sumsq_value_jitter = 0;
|
| + int min_value, max_value;
|
| for (size_t i = 0; i < kNumRuns; ++i) {
|
| int value = kBaseValue + base::RandInt(-5, 5);
|
| + sum_value_rtt += value;
|
| + sumsq_value_rtt += value * value;
|
| logging_->InsertGenericEvent(testing_clock_.NowTicks(), kRttMs, value);
|
| if (i % 2) {
|
| logging_->InsertGenericEvent(testing_clock_.NowTicks(), kPacketLoss,
|
| value);
|
| + sum_value_pl += value;
|
| + sumsq_value_pl += value * value;
|
| }
|
| if (!(i % 4)) {
|
| logging_->InsertGenericEvent(testing_clock_.NowTicks(), kJitterMs, value);
|
| + sum_value_jitter += value;
|
| + sumsq_value_jitter += value * value;
|
| + }
|
| + if (i == 0) {
|
| + min_value = value;
|
| + max_value = value;
|
| + } else if (min_value > value) {
|
| + min_value = value;
|
| + } else if (max_value < value) {
|
| + max_value = value;
|
| }
|
| }
|
| GenericRawMap raw_map = logging_->GetGenericRawData();
|
| - const GenericStatsMap* stats_map = logging_->GetGenericStatsData();
|
| + GenericStatsMap stats_map = logging_->GetGenericStatsData();
|
| // Size of generic map = number of different events.
|
| EXPECT_EQ(3u, raw_map.size());
|
| - EXPECT_EQ(3u, stats_map->size());
|
| + EXPECT_EQ(3u, stats_map.size());
|
| // Raw events - size of internal map = number of calls.
|
| GenericRawMap::iterator rit = raw_map.find(kRttMs);
|
| EXPECT_EQ(kNumRuns, rit->second.value.size());
|
| @@ -251,13 +270,21 @@ TEST_F(TestLogging, GenericLogging) {
|
| rit = raw_map.find(kJitterMs);
|
| EXPECT_EQ(kNumRuns / 4, rit->second.value.size());
|
| EXPECT_EQ(kNumRuns / 4, rit->second.timestamp.size());
|
| - // Stats - one value per event.
|
| - GenericStatsMap::const_iterator sit = stats_map->find(kRttMs);
|
| - EXPECT_NEAR(kBaseValue, sit->second, 2.5);
|
| - sit = stats_map->find(kPacketLoss);
|
| - EXPECT_NEAR(kBaseValue, sit->second, 2.5);
|
| - sit = stats_map->find(kJitterMs);
|
| - EXPECT_NEAR(kBaseValue, sit->second, 2.5);
|
| + // Stats - one value per all events.
|
| + GenericStatsMap::const_iterator sit = stats_map.find(kRttMs);
|
| + EXPECT_EQ(sum_value_rtt, sit->second.sum);
|
| + EXPECT_EQ(sumsq_value_rtt, sit->second.sum_squared);
|
| + EXPECT_LE(min_value, sit->second.min);
|
| + EXPECT_GE(max_value, sit->second.max);
|
| + sit = stats_map.find(kPacketLoss);
|
| + EXPECT_EQ(sum_value_pl, sit->second.sum);
|
| + EXPECT_EQ(sumsq_value_pl, sit->second.sum_squared);
|
| + EXPECT_LE(min_value, sit->second.min);
|
| + EXPECT_GE(max_value, sit->second.max);
|
| + sit = stats_map.find(kJitterMs);
|
| + EXPECT_EQ(sumsq_value_jitter, sit->second.sum_squared);
|
| + EXPECT_LE(min_value, sit->second.min);
|
| + EXPECT_GE(max_value, sit->second.max);
|
| }
|
|
|
| TEST_F(TestLogging, RtcpMultipleEventFrameLogging) {
|
| @@ -291,10 +318,10 @@ TEST_F(TestLogging, RtcpMultipleEventFrameLogging) {
|
| EXPECT_EQ(frame_id, frame_map.size());
|
| // Multiple events captured per frame.
|
|
|
| - AudioRtcpRawMap audio_rtcp = logging_->GetAudioRtcpRawData();
|
| + AudioRtcpRawMap audio_rtcp = logging_->GetAndResetAudioRtcpRawData();
|
| EXPECT_EQ(0u, audio_rtcp.size());
|
|
|
| - VideoRtcpRawMap video_rtcp = logging_->GetVideoRtcpRawData();
|
| + VideoRtcpRawMap video_rtcp = logging_->GetAndResetVideoRtcpRawData();
|
| EXPECT_EQ((frame_id + 1) / 2, video_rtcp.size());
|
| }
|
|
|
|
|