| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
| 6 | 6 |
| 7 #include "base/rand_util.h" | 7 #include "base/rand_util.h" |
| 8 #include "base/test/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
| 9 #include "base/time/tick_clock.h" | 9 #include "base/time/tick_clock.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "media/cast/logging/logging_impl.h" | 11 #include "media/cast/logging/logging_impl.h" |
| 12 #include "media/cast/test/fake_task_runner.h" | 12 #include "media/cast/test/fake_task_runner.h" |
| 13 | 13 |
| 14 namespace media { | 14 namespace media { |
| 15 namespace cast { | 15 namespace cast { |
| 16 | 16 |
| 17 // Insert frame duration- one second. | 17 // Insert frame duration- one second. |
| 18 const int64 kIntervalTime1S = 1; | 18 const int64 kIntervalTime1S = 1; |
| 19 // Test frame rate goal - 30fps. | 19 // Test frame rate goal - 30fps. |
| 20 const int kFrameIntervalMs = 33; | 20 const int kFrameIntervalMs = 33; |
| 21 | 21 |
| 22 static const int64 kStartMillisecond = GG_INT64_C(12345678900000); | 22 static const int64 kStartMillisecond = GG_INT64_C(12345678900000); |
| 23 | 23 |
| 24 class TestLogging : public ::testing::Test { | 24 class TestLogging : public ::testing::Test { |
| 25 protected: | 25 protected: |
| 26 TestLogging() { | 26 TestLogging() : config_(false) { |
| 27 // Enable all logging types. | 27 // Enable all logging types. |
| 28 config_.enable_raw_data_collection = true; | 28 config_.enable_raw_data_collection = true; |
| 29 config_.enable_stats_data_collection = true; | 29 config_.enable_stats_data_collection = true; |
| 30 config_.enable_uma_stats = true; | 30 config_.enable_uma_stats = true; |
| 31 config_.enable_tracing = true; | 31 config_.enable_tracing = true; |
| 32 | 32 |
| 33 testing_clock_.Advance( | 33 testing_clock_.Advance( |
| 34 base::TimeDelta::FromMilliseconds(kStartMillisecond)); | 34 base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
| 35 task_runner_ = new test::FakeTaskRunner(&testing_clock_); | 35 task_runner_ = new test::FakeTaskRunner(&testing_clock_); |
| 36 logging_.reset(new LoggingImpl(task_runner_, config_)); | 36 logging_.reset(new LoggingImpl(task_runner_, config_)); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 EXPECT_EQ(kNumRuns / 4, rit->second.timestamp.size()); | 253 EXPECT_EQ(kNumRuns / 4, rit->second.timestamp.size()); |
| 254 // Stats - one value per event. | 254 // Stats - one value per event. |
| 255 GenericStatsMap::const_iterator sit = stats_map->find(kRttMs); | 255 GenericStatsMap::const_iterator sit = stats_map->find(kRttMs); |
| 256 EXPECT_NEAR(kBaseValue, sit->second, 2.5); | 256 EXPECT_NEAR(kBaseValue, sit->second, 2.5); |
| 257 sit = stats_map->find(kPacketLoss); | 257 sit = stats_map->find(kPacketLoss); |
| 258 EXPECT_NEAR(kBaseValue, sit->second, 2.5); | 258 EXPECT_NEAR(kBaseValue, sit->second, 2.5); |
| 259 sit = stats_map->find(kJitterMs); | 259 sit = stats_map->find(kJitterMs); |
| 260 EXPECT_NEAR(kBaseValue, sit->second, 2.5); | 260 EXPECT_NEAR(kBaseValue, sit->second, 2.5); |
| 261 } | 261 } |
| 262 | 262 |
| 263 TEST_F(TestLogging, RtcpMultipleEventFrameLogging) { |
| 264 base::TimeTicks start_time = testing_clock_.NowTicks(); |
| 265 base::TimeDelta time_interval = testing_clock_.NowTicks() - start_time; |
| 266 uint32 rtp_timestamp = 0; |
| 267 uint32 frame_id = 0; |
| 268 do { |
| 269 logging_->InsertFrameEvent(testing_clock_.NowTicks(), kAudioFrameCaptured, |
| 270 rtp_timestamp, frame_id); |
| 271 if (frame_id % 2) { |
| 272 logging_->InsertFrameEventWithSize(testing_clock_.NowTicks(), |
| 273 kAudioFrameEncoded, rtp_timestamp, frame_id, 1500); |
| 274 } else if (frame_id % 3) { |
| 275 logging_->InsertFrameEvent(testing_clock_.NowTicks(), kVideoFrameDecoded, |
| 276 rtp_timestamp, frame_id); |
| 277 } else { |
| 278 logging_->InsertFrameEventWithDelay(testing_clock_.NowTicks(), |
| 279 kVideoRenderDelay, rtp_timestamp, frame_id, |
| 280 base::TimeDelta::FromMilliseconds(20)); |
| 281 } |
| 282 testing_clock_.Advance( |
| 283 base::TimeDelta::FromMilliseconds(kFrameIntervalMs)); |
| 284 rtp_timestamp += kFrameIntervalMs * 90; |
| 285 ++frame_id; |
| 286 time_interval = testing_clock_.NowTicks() - start_time; |
| 287 } while (time_interval.InSeconds() < kIntervalTime1S); |
| 288 // Get logging data. |
| 289 FrameRawMap frame_map = logging_->GetFrameRawData(); |
| 290 // Size of map should be equal to the number of frames logged. |
| 291 EXPECT_EQ(frame_id, frame_map.size()); |
| 292 // Multiple events captured per frame. |
| 293 |
| 294 AudioRtcpRawMap audio_rtcp = logging_->GetAudioRtcpRawData(); |
| 295 EXPECT_EQ(0u, audio_rtcp.size()); |
| 296 |
| 297 VideoRtcpRawMap video_rtcp = logging_->GetVideoRtcpRawData(); |
| 298 EXPECT_EQ((frame_id + 1) / 2, video_rtcp.size()); |
| 299 } |
| 300 |
| 263 } // namespace cast | 301 } // namespace cast |
| 264 } // namespace media | 302 } // namespace media |
| OLD | NEW |