| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 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 "media/cast/cast_environment.h" | 10 #include "media/cast/cast_environment.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 TEST_F(StatsEventSubscriberTest, Capture) { | 68 TEST_F(StatsEventSubscriberTest, Capture) { |
| 69 Init(VIDEO_EVENT); | 69 Init(VIDEO_EVENT); |
| 70 | 70 |
| 71 uint32 rtp_timestamp = 0; | 71 uint32 rtp_timestamp = 0; |
| 72 uint32 frame_id = 0; | 72 uint32 frame_id = 0; |
| 73 int num_frames = 10; | 73 int num_frames = 10; |
| 74 base::TimeTicks start_time = sender_clock_->NowTicks(); | 74 base::TimeTicks start_time = sender_clock_->NowTicks(); |
| 75 for (int i = 0; i < num_frames; i++) { | 75 for (int i = 0; i < num_frames; i++) { |
| 76 cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), | 76 cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), |
| 77 kVideoFrameCaptureBegin, | 77 FRAME_CAPTURE_BEGIN, |
| 78 VIDEO_EVENT, |
| 78 rtp_timestamp, | 79 rtp_timestamp, |
| 79 frame_id); | 80 frame_id); |
| 80 | 81 |
| 81 AdvanceClocks(base::TimeDelta::FromMicroseconds(34567)); | 82 AdvanceClocks(base::TimeDelta::FromMicroseconds(34567)); |
| 82 rtp_timestamp += 90; | 83 rtp_timestamp += 90; |
| 83 frame_id++; | 84 frame_id++; |
| 84 } | 85 } |
| 85 | 86 |
| 86 base::TimeTicks end_time = sender_clock_->NowTicks(); | 87 base::TimeTicks end_time = sender_clock_->NowTicks(); |
| 87 | 88 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 104 uint32 rtp_timestamp = 0; | 105 uint32 rtp_timestamp = 0; |
| 105 uint32 frame_id = 0; | 106 uint32 frame_id = 0; |
| 106 int num_frames = 10; | 107 int num_frames = 10; |
| 107 base::TimeTicks start_time = sender_clock_->NowTicks(); | 108 base::TimeTicks start_time = sender_clock_->NowTicks(); |
| 108 int total_size = 0; | 109 int total_size = 0; |
| 109 for (int i = 0; i < num_frames; i++) { | 110 for (int i = 0; i < num_frames; i++) { |
| 110 int size = 1000 + base::RandInt(-100, 100); | 111 int size = 1000 + base::RandInt(-100, 100); |
| 111 total_size += size; | 112 total_size += size; |
| 112 cast_environment_->Logging()->InsertEncodedFrameEvent( | 113 cast_environment_->Logging()->InsertEncodedFrameEvent( |
| 113 sender_clock_->NowTicks(), | 114 sender_clock_->NowTicks(), |
| 114 kVideoFrameEncoded, | 115 FRAME_ENCODED, VIDEO_EVENT, |
| 115 rtp_timestamp, | 116 rtp_timestamp, |
| 116 frame_id, | 117 frame_id, |
| 117 size, | 118 size, |
| 118 true, | 119 true, |
| 119 5678); | 120 5678); |
| 120 | 121 |
| 121 AdvanceClocks(base::TimeDelta::FromMicroseconds(35678)); | 122 AdvanceClocks(base::TimeDelta::FromMicroseconds(35678)); |
| 122 rtp_timestamp += 90; | 123 rtp_timestamp += 90; |
| 123 frame_id++; | 124 frame_id++; |
| 124 } | 125 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 146 | 147 |
| 147 TEST_F(StatsEventSubscriberTest, Decode) { | 148 TEST_F(StatsEventSubscriberTest, Decode) { |
| 148 Init(VIDEO_EVENT); | 149 Init(VIDEO_EVENT); |
| 149 | 150 |
| 150 uint32 rtp_timestamp = 0; | 151 uint32 rtp_timestamp = 0; |
| 151 uint32 frame_id = 0; | 152 uint32 frame_id = 0; |
| 152 int num_frames = 10; | 153 int num_frames = 10; |
| 153 base::TimeTicks start_time = sender_clock_->NowTicks(); | 154 base::TimeTicks start_time = sender_clock_->NowTicks(); |
| 154 for (int i = 0; i < num_frames; i++) { | 155 for (int i = 0; i < num_frames; i++) { |
| 155 cast_environment_->Logging()->InsertFrameEvent(receiver_clock_.NowTicks(), | 156 cast_environment_->Logging()->InsertFrameEvent(receiver_clock_.NowTicks(), |
| 156 kVideoFrameDecoded, | 157 FRAME_DECODED, VIDEO_EVENT, |
| 157 rtp_timestamp, | 158 rtp_timestamp, |
| 158 frame_id); | 159 frame_id); |
| 159 | 160 |
| 160 AdvanceClocks(base::TimeDelta::FromMicroseconds(36789)); | 161 AdvanceClocks(base::TimeDelta::FromMicroseconds(36789)); |
| 161 rtp_timestamp += 90; | 162 rtp_timestamp += 90; |
| 162 frame_id++; | 163 frame_id++; |
| 163 } | 164 } |
| 164 | 165 |
| 165 base::TimeTicks end_time = sender_clock_->NowTicks(); | 166 base::TimeTicks end_time = sender_clock_->NowTicks(); |
| 166 | 167 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 183 uint32 rtp_timestamp = 0; | 184 uint32 rtp_timestamp = 0; |
| 184 uint32 frame_id = 0; | 185 uint32 frame_id = 0; |
| 185 int num_frames = 10; | 186 int num_frames = 10; |
| 186 int total_delay_ms = 0; | 187 int total_delay_ms = 0; |
| 187 for (int i = 0; i < num_frames; i++) { | 188 for (int i = 0; i < num_frames; i++) { |
| 188 int delay_ms = base::RandInt(-50, 50); | 189 int delay_ms = base::RandInt(-50, 50); |
| 189 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(delay_ms); | 190 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(delay_ms); |
| 190 total_delay_ms += delay_ms; | 191 total_delay_ms += delay_ms; |
| 191 cast_environment_->Logging()->InsertFrameEventWithDelay( | 192 cast_environment_->Logging()->InsertFrameEventWithDelay( |
| 192 receiver_clock_.NowTicks(), | 193 receiver_clock_.NowTicks(), |
| 193 kVideoRenderDelay, | 194 FRAME_PLAYOUT, |
| 195 VIDEO_EVENT, |
| 194 rtp_timestamp, | 196 rtp_timestamp, |
| 195 frame_id, | 197 frame_id, |
| 196 delay); | 198 delay); |
| 197 | 199 |
| 198 AdvanceClocks(base::TimeDelta::FromMicroseconds(37890)); | 200 AdvanceClocks(base::TimeDelta::FromMicroseconds(37890)); |
| 199 rtp_timestamp += 90; | 201 rtp_timestamp += 90; |
| 200 frame_id++; | 202 frame_id++; |
| 201 } | 203 } |
| 202 | 204 |
| 203 StatsEventSubscriber::StatsMap stats_map; | 205 StatsEventSubscriber::StatsMap stats_map; |
| 204 subscriber_->GetStatsInternal(&stats_map); | 206 subscriber_->GetStatsInternal(&stats_map); |
| 205 | 207 |
| 206 StatsEventSubscriber::StatsMap::iterator it = | 208 StatsEventSubscriber::StatsMap::iterator it = |
| 207 stats_map.find(StatsEventSubscriber::AVG_PLAYOUT_DELAY_MS); | 209 stats_map.find(StatsEventSubscriber::AVG_PLAYOUT_DELAY_MS); |
| 208 ASSERT_NE(it, stats_map.end()); | 210 ASSERT_NE(it, stats_map.end()); |
| 209 | 211 |
| 210 EXPECT_DOUBLE_EQ( | 212 EXPECT_DOUBLE_EQ( |
| 211 it->second, static_cast<double>(total_delay_ms) / num_frames); | 213 it->second, static_cast<double>(total_delay_ms) / num_frames); |
| 212 } | 214 } |
| 213 | 215 |
| 214 TEST_F(StatsEventSubscriberTest, E2ELatency) { | 216 TEST_F(StatsEventSubscriberTest, E2ELatency) { |
| 215 Init(VIDEO_EVENT); | 217 Init(VIDEO_EVENT); |
| 216 | 218 |
| 217 uint32 rtp_timestamp = 0; | 219 uint32 rtp_timestamp = 0; |
| 218 uint32 frame_id = 0; | 220 uint32 frame_id = 0; |
| 219 int num_frames = 10; | 221 int num_frames = 10; |
| 220 base::TimeDelta total_latency; | 222 base::TimeDelta total_latency; |
| 221 for (int i = 0; i < num_frames; i++) { | 223 for (int i = 0; i < num_frames; i++) { |
| 222 cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), | 224 cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), |
| 223 kVideoFrameCaptureBegin, | 225 FRAME_CAPTURE_BEGIN, |
| 226 VIDEO_EVENT, |
| 224 rtp_timestamp, | 227 rtp_timestamp, |
| 225 frame_id); | 228 frame_id); |
| 226 | 229 |
| 227 int latency_micros = 100000 + base::RandInt(-5000, 50000); | 230 int latency_micros = 100000 + base::RandInt(-5000, 50000); |
| 228 base::TimeDelta latency = base::TimeDelta::FromMicroseconds(latency_micros); | 231 base::TimeDelta latency = base::TimeDelta::FromMicroseconds(latency_micros); |
| 229 AdvanceClocks(latency); | 232 AdvanceClocks(latency); |
| 230 | 233 |
| 231 int delay_micros = base::RandInt(-50000, 50000); | 234 int delay_micros = base::RandInt(-50000, 50000); |
| 232 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(delay_micros); | 235 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(delay_micros); |
| 233 total_latency += latency + delay; | 236 total_latency += latency + delay; |
| 234 | 237 |
| 235 cast_environment_->Logging()->InsertFrameEventWithDelay( | 238 cast_environment_->Logging()->InsertFrameEventWithDelay( |
| 236 receiver_clock_.NowTicks(), | 239 receiver_clock_.NowTicks(), |
| 237 kVideoRenderDelay, | 240 FRAME_PLAYOUT, |
| 241 VIDEO_EVENT, |
| 238 rtp_timestamp, | 242 rtp_timestamp, |
| 239 frame_id, | 243 frame_id, |
| 240 delay); | 244 delay); |
| 241 | 245 |
| 242 rtp_timestamp += 90; | 246 rtp_timestamp += 90; |
| 243 frame_id++; | 247 frame_id++; |
| 244 } | 248 } |
| 245 | 249 |
| 246 StatsEventSubscriber::StatsMap stats_map; | 250 StatsEventSubscriber::StatsMap stats_map; |
| 247 subscriber_->GetStatsInternal(&stats_map); | 251 subscriber_->GetStatsInternal(&stats_map); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 267 int num_packets_sent = 0; | 271 int num_packets_sent = 0; |
| 268 int num_packets_retransmitted = 0; | 272 int num_packets_retransmitted = 0; |
| 269 // Every 2nd packet will be retransmitted once. | 273 // Every 2nd packet will be retransmitted once. |
| 270 // Every 4th packet will be retransmitted twice. | 274 // Every 4th packet will be retransmitted twice. |
| 271 // Every 8th packet will be retransmitted 3 times. | 275 // Every 8th packet will be retransmitted 3 times. |
| 272 for (int i = 0; i < num_packets; i++) { | 276 for (int i = 0; i < num_packets; i++) { |
| 273 int size = 1000 + base::RandInt(-100, 100); | 277 int size = 1000 + base::RandInt(-100, 100); |
| 274 total_size += size; | 278 total_size += size; |
| 275 | 279 |
| 276 cast_environment_->Logging()->InsertPacketEvent(sender_clock_->NowTicks(), | 280 cast_environment_->Logging()->InsertPacketEvent(sender_clock_->NowTicks(), |
| 277 kVideoPacketSentToNetwork, | 281 PACKET_SENT_TO_NETWORK, |
| 282 VIDEO_EVENT, |
| 278 rtp_timestamp, | 283 rtp_timestamp, |
| 279 0, | 284 0, |
| 280 i, | 285 i, |
| 281 num_packets - 1, | 286 num_packets - 1, |
| 282 size); | 287 size); |
| 283 num_packets_sent++; | 288 num_packets_sent++; |
| 284 | 289 |
| 285 int latency_micros = 20000 + base::RandInt(-10000, 10000); | 290 int latency_micros = 20000 + base::RandInt(-10000, 10000); |
| 286 base::TimeDelta latency = base::TimeDelta::FromMicroseconds(latency_micros); | 291 base::TimeDelta latency = base::TimeDelta::FromMicroseconds(latency_micros); |
| 287 // Latency is only recorded for packets that aren't retransmitted. | 292 // Latency is only recorded for packets that aren't retransmitted. |
| 288 if (i % 2 != 0) { | 293 if (i % 2 != 0) { |
| 289 total_latency += latency; | 294 total_latency += latency; |
| 290 num_latency_recorded_packets++; | 295 num_latency_recorded_packets++; |
| 291 } | 296 } |
| 292 | 297 |
| 293 AdvanceClocks(latency); | 298 AdvanceClocks(latency); |
| 294 | 299 |
| 295 base::TimeTicks received_time = receiver_clock_.NowTicks(); | 300 base::TimeTicks received_time = receiver_clock_.NowTicks(); |
| 296 | 301 |
| 297 // Retransmission 1. | 302 // Retransmission 1. |
| 298 AdvanceClocks(base::TimeDelta::FromMicroseconds(12345)); | 303 AdvanceClocks(base::TimeDelta::FromMicroseconds(12345)); |
| 299 if (i % 2 == 0) { | 304 if (i % 2 == 0) { |
| 300 cast_environment_->Logging()->InsertPacketEvent( | 305 cast_environment_->Logging()->InsertPacketEvent( |
| 301 receiver_clock_.NowTicks(), | 306 receiver_clock_.NowTicks(), |
| 302 kVideoPacketRetransmitted, | 307 PACKET_RETRANSMITTED, |
| 308 VIDEO_EVENT, |
| 303 rtp_timestamp, | 309 rtp_timestamp, |
| 304 0, | 310 0, |
| 305 i, | 311 i, |
| 306 num_packets - 1, | 312 num_packets - 1, |
| 307 size); | 313 size); |
| 308 retransmit_total_size += size; | 314 retransmit_total_size += size; |
| 309 num_packets_sent++; | 315 num_packets_sent++; |
| 310 num_packets_retransmitted++; | 316 num_packets_retransmitted++; |
| 311 } | 317 } |
| 312 | 318 |
| 313 // Retransmission 2. | 319 // Retransmission 2. |
| 314 AdvanceClocks(base::TimeDelta::FromMicroseconds(13456)); | 320 AdvanceClocks(base::TimeDelta::FromMicroseconds(13456)); |
| 315 if (i % 4 == 0) { | 321 if (i % 4 == 0) { |
| 316 cast_environment_->Logging()->InsertPacketEvent( | 322 cast_environment_->Logging()->InsertPacketEvent( |
| 317 receiver_clock_.NowTicks(), | 323 receiver_clock_.NowTicks(), |
| 318 kVideoPacketRetransmitted, | 324 PACKET_RETRANSMITTED, |
| 325 VIDEO_EVENT, |
| 319 rtp_timestamp, | 326 rtp_timestamp, |
| 320 0, | 327 0, |
| 321 i, | 328 i, |
| 322 num_packets - 1, | 329 num_packets - 1, |
| 323 size); | 330 size); |
| 324 retransmit_total_size += size; | 331 retransmit_total_size += size; |
| 325 num_packets_sent++; | 332 num_packets_sent++; |
| 326 num_packets_retransmitted++; | 333 num_packets_retransmitted++; |
| 327 } | 334 } |
| 328 | 335 |
| 329 // Retransmission 3. | 336 // Retransmission 3. |
| 330 AdvanceClocks(base::TimeDelta::FromMicroseconds(14567)); | 337 AdvanceClocks(base::TimeDelta::FromMicroseconds(14567)); |
| 331 if (i % 8 == 0) { | 338 if (i % 8 == 0) { |
| 332 cast_environment_->Logging()->InsertPacketEvent( | 339 cast_environment_->Logging()->InsertPacketEvent( |
| 333 receiver_clock_.NowTicks(), | 340 receiver_clock_.NowTicks(), |
| 334 kVideoPacketRetransmitted, | 341 PACKET_RETRANSMITTED, |
| 342 VIDEO_EVENT, |
| 335 rtp_timestamp, | 343 rtp_timestamp, |
| 336 0, | 344 0, |
| 337 i, | 345 i, |
| 338 num_packets - 1, | 346 num_packets - 1, |
| 339 size); | 347 size); |
| 340 retransmit_total_size += size; | 348 retransmit_total_size += size; |
| 341 num_packets_sent++; | 349 num_packets_sent++; |
| 342 num_packets_retransmitted++; | 350 num_packets_retransmitted++; |
| 343 } | 351 } |
| 344 | 352 |
| 345 cast_environment_->Logging()->InsertPacketEvent(received_time, | 353 cast_environment_->Logging()->InsertPacketEvent(received_time, |
| 346 kVideoPacketReceived, | 354 PACKET_RECEIVED, |
| 355 VIDEO_EVENT, |
| 347 rtp_timestamp, | 356 rtp_timestamp, |
| 348 0, | 357 0, |
| 349 i, | 358 i, |
| 350 num_packets - 1, | 359 num_packets - 1, |
| 351 size); | 360 size); |
| 352 } | 361 } |
| 353 | 362 |
| 354 base::TimeTicks end_time = sender_clock_->NowTicks(); | 363 base::TimeTicks end_time = sender_clock_->NowTicks(); |
| 355 base::TimeDelta duration = end_time - start_time; | 364 base::TimeDelta duration = end_time - start_time; |
| 356 | 365 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 383 it = stats_map.find(StatsEventSubscriber::PACKET_LOSS_FRACTION); | 392 it = stats_map.find(StatsEventSubscriber::PACKET_LOSS_FRACTION); |
| 384 ASSERT_NE(it, stats_map.end()); | 393 ASSERT_NE(it, stats_map.end()); |
| 385 | 394 |
| 386 EXPECT_DOUBLE_EQ( | 395 EXPECT_DOUBLE_EQ( |
| 387 it->second, | 396 it->second, |
| 388 static_cast<double>(num_packets_retransmitted) / num_packets_sent); | 397 static_cast<double>(num_packets_retransmitted) / num_packets_sent); |
| 389 } | 398 } |
| 390 | 399 |
| 391 } // namespace cast | 400 } // namespace cast |
| 392 } // namespace media | 401 } // namespace media |
| OLD | NEW |