Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(745)

Side by Side Diff: talk/media/webrtc/webrtcvideoengine2_unittest.cc

Issue 1345473002: Reset frame timestamp epoch for new capturers. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: uint32 cast Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/media/webrtc/webrtcvideoengine2.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2004 Google Inc. 3 * Copyright 2004 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 EXPECT_TRUE( 433 EXPECT_TRUE(
434 channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); 434 channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc)));
435 435
436 FakeVideoCapturer capturer; 436 FakeVideoCapturer capturer;
437 EXPECT_TRUE(channel->SetCapturer(kSsrc, &capturer)); 437 EXPECT_TRUE(channel->SetCapturer(kSsrc, &capturer));
438 capturer.Start(cricket::VideoFormat(1280, 720, 438 capturer.Start(cricket::VideoFormat(1280, 720,
439 cricket::VideoFormat::FpsToInterval(60), 439 cricket::VideoFormat::FpsToInterval(60),
440 cricket::FOURCC_I420)); 440 cricket::FOURCC_I420));
441 channel->SetSend(true); 441 channel->SetSend(true);
442 442
443 FakeCall* call = factory.GetCall(); 443 FakeVideoSendStream* stream = factory.GetCall()->GetVideoSendStreams()[0];
444 std::vector<FakeVideoSendStream*> streams = call->GetVideoSendStreams();
445 FakeVideoSendStream* stream = streams[0];
446 444
447 int64_t timestamp;
448 int64_t last_timestamp;
449 445
450 EXPECT_TRUE(capturer.CaptureFrame()); 446 EXPECT_TRUE(capturer.CaptureFrame());
451 last_timestamp = stream->GetLastTimestamp(); 447 int64_t last_timestamp = stream->GetLastTimestamp();
452 for (int i = 0; i < 10; i++) { 448 for (int i = 0; i < 10; i++) {
453 EXPECT_TRUE(capturer.CaptureFrame()); 449 EXPECT_TRUE(capturer.CaptureFrame());
454 timestamp = stream->GetLastTimestamp(); 450 int64_t timestamp = stream->GetLastTimestamp();
455 int64_t interval = timestamp - last_timestamp; 451 int64_t interval = timestamp - last_timestamp;
456 452
457 // Precision changes from nanosecond to millisecond. 453 // Precision changes from nanosecond to millisecond.
458 // Allow error to be no more than 1. 454 // Allow error to be no more than 1.
459 EXPECT_NEAR(cricket::VideoFormat::FpsToInterval(60) / 1E6, interval, 1); 455 EXPECT_NEAR(cricket::VideoFormat::FpsToInterval(60) / 1E6, interval, 1);
460 456
461 last_timestamp = timestamp; 457 last_timestamp = timestamp;
462 } 458 }
463 459
464 capturer.Start(cricket::VideoFormat(1280, 720, 460 capturer.Start(cricket::VideoFormat(1280, 720,
465 cricket::VideoFormat::FpsToInterval(30), 461 cricket::VideoFormat::FpsToInterval(30),
466 cricket::FOURCC_I420)); 462 cricket::FOURCC_I420));
467 463
468 EXPECT_TRUE(capturer.CaptureFrame()); 464 EXPECT_TRUE(capturer.CaptureFrame());
469 last_timestamp = stream->GetLastTimestamp(); 465 last_timestamp = stream->GetLastTimestamp();
470 for (int i = 0; i < 10; i++) { 466 for (int i = 0; i < 10; i++) {
471 EXPECT_TRUE(capturer.CaptureFrame()); 467 EXPECT_TRUE(capturer.CaptureFrame());
472 timestamp = stream->GetLastTimestamp(); 468 int64_t timestamp = stream->GetLastTimestamp();
473 int64_t interval = timestamp - last_timestamp; 469 int64_t interval = timestamp - last_timestamp;
474 470
475 // Precision changes from nanosecond to millisecond. 471 // Precision changes from nanosecond to millisecond.
476 // Allow error to be no more than 1. 472 // Allow error to be no more than 1.
477 EXPECT_NEAR(cricket::VideoFormat::FpsToInterval(30) / 1E6, interval, 1); 473 EXPECT_NEAR(cricket::VideoFormat::FpsToInterval(30) / 1E6, interval, 1);
478 474
479 last_timestamp = timestamp; 475 last_timestamp = timestamp;
480 } 476 }
481 477
482 // Remove stream previously added to free the external encoder instance. 478 // Remove stream previously added to free the external encoder instance.
483 EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); 479 EXPECT_TRUE(channel->RemoveSendStream(kSsrc));
484 } 480 }
485 481
482 TEST_F(WebRtcVideoEngine2Test,
483 ProducesIncreasingTimestampsWithResetInputSources) {
484 cricket::FakeWebRtcVideoEncoderFactory encoder_factory;
485 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
486 std::vector<cricket::VideoCodec> codecs;
487 codecs.push_back(kVp8Codec);
488
489 FakeCallFactory factory;
490 engine_.SetCallFactory(&factory);
491 rtc::scoped_ptr<VideoMediaChannel> channel(
492 SetUpForExternalEncoderFactory(&encoder_factory, codecs));
493
494 EXPECT_TRUE(
495 channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc)));
496 channel->SetSend(true);
497 FakeVideoSendStream* stream = factory.GetCall()->GetVideoSendStreams()[0];
498
499 FakeVideoCapturer capturer1;
500 EXPECT_TRUE(channel->SetCapturer(kSsrc, &capturer1));
501
502 cricket::CapturedFrame frame;
503 frame.width = 1280;
504 frame.height = 720;
505 frame.fourcc = cricket::FOURCC_I420;
506 frame.data_size = static_cast<uint32>(
507 cricket::VideoFrame::SizeOf(frame.width, frame.height));
508 rtc::scoped_ptr<char[]> data(new char[frame.data_size]);
509 frame.data = data.get();
510 memset(frame.data, 1, frame.data_size);
511 frame.elapsed_time = 0;
512 const int kInitialTimestamp = 123456;
513 frame.time_stamp = kInitialTimestamp;
514
515 // Deliver initial frame.
516 capturer1.SignalCapturedFrame(&frame);
517 // Deliver next frame 1 second later.
518 frame.time_stamp += rtc::kNumNanosecsPerSec;
519 rtc::Thread::Current()->SleepMs(1000);
pthatcher1 2015/09/17 05:00:31 If you have to do a real sleep, can you at least m
pbos-webrtc 2015/09/17 06:36:20 It's a bit longer due to incoming frames being sta
520 capturer1.SignalCapturedFrame(&frame);
521
522 int64_t capturer1_last_timestamp = stream->GetLastTimestamp();
523 // Reset input source, should still be continuous even though input-frame
524 // timestamp is less than before.
525 FakeVideoCapturer capturer2;
526 EXPECT_TRUE(channel->SetCapturer(kSsrc, &capturer2));
527
528 rtc::Thread::Current()->SleepMs(1);
529 // Deliver with a timestamp (10 seconds) before the previous initial one,
530 // these should not be related at all anymore and it should still work fine.
531 frame.time_stamp = kInitialTimestamp - 10000;
532 capturer2.SignalCapturedFrame(&frame);
533
534 // New timestamp should be at least 1ms in the future and not old.
535 EXPECT_GT(stream->GetLastTimestamp(), capturer1_last_timestamp);
536
537 EXPECT_TRUE(channel->RemoveSendStream(kSsrc));
538 }
539
486 VideoMediaChannel* WebRtcVideoEngine2Test::SetUpForExternalEncoderFactory( 540 VideoMediaChannel* WebRtcVideoEngine2Test::SetUpForExternalEncoderFactory(
487 cricket::WebRtcVideoEncoderFactory* encoder_factory, 541 cricket::WebRtcVideoEncoderFactory* encoder_factory,
488 const std::vector<VideoCodec>& codecs) { 542 const std::vector<VideoCodec>& codecs) {
489 engine_.SetExternalEncoderFactory(encoder_factory); 543 engine_.SetExternalEncoderFactory(encoder_factory);
490 engine_.Init(); 544 engine_.Init();
491 545
492 VideoMediaChannel* channel = 546 VideoMediaChannel* channel =
493 engine_.CreateChannel(cricket::VideoOptions(), NULL); 547 engine_.CreateChannel(cricket::VideoOptions(), NULL);
494 EXPECT_TRUE(channel->SetSendCodecs(codecs)); 548 EXPECT_TRUE(channel->SetSendCodecs(codecs));
495 549
(...skipping 2694 matching lines...) Expand 10 before | Expand all | Expand 10 after
3190 // Ensures that the correct settings are applied to the codec when two temporal 3244 // Ensures that the correct settings are applied to the codec when two temporal
3191 // layer screencasting is enabled, and that the correct simulcast settings are 3245 // layer screencasting is enabled, and that the correct simulcast settings are
3192 // reapplied when disabling screencasting. 3246 // reapplied when disabling screencasting.
3193 TEST_F(WebRtcVideoChannel2SimulcastTest, 3247 TEST_F(WebRtcVideoChannel2SimulcastTest,
3194 DISABLED_TwoTemporalLayerScreencastSettings) { 3248 DISABLED_TwoTemporalLayerScreencastSettings) {
3195 // TODO(pbos): Implement. 3249 // TODO(pbos): Implement.
3196 FAIL() << "Not implemented."; 3250 FAIL() << "Not implemented.";
3197 } 3251 }
3198 3252
3199 } // namespace cricket 3253 } // namespace cricket
OLDNEW
« no previous file with comments | « talk/media/webrtc/webrtcvideoengine2.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698