Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/test/gtest.h" | 11 #include "webrtc/test/gtest.h" |
| 12 #include "webrtc/test/gmock.h" | 12 #include "webrtc/test/gmock.h" |
| 13 | 13 |
| 14 #include "webrtc/common_video/h264/h264_common.h" | 14 #include "webrtc/common_video/h264/h264_common.h" |
| 15 #include "webrtc/media/base/mediaconstants.h" | 15 #include "webrtc/media/base/mediaconstants.h" |
| 16 #include "webrtc/modules/pacing/packet_router.h" | 16 #include "webrtc/modules/pacing/packet_router.h" |
| 17 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | |
| 17 #include "webrtc/modules/utility/include/process_thread.h" | 18 #include "webrtc/modules/utility/include/process_thread.h" |
| 18 #include "webrtc/modules/video_coding/frame_object.h" | 19 #include "webrtc/modules/video_coding/frame_object.h" |
| 19 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 20 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
| 20 #include "webrtc/modules/video_coding/packet.h" | 21 #include "webrtc/modules/video_coding/packet.h" |
| 21 #include "webrtc/modules/video_coding/rtp_frame_reference_finder.h" | 22 #include "webrtc/modules/video_coding/rtp_frame_reference_finder.h" |
| 22 #include "webrtc/modules/video_coding/timing.h" | 23 #include "webrtc/modules/video_coding/timing.h" |
| 23 #include "webrtc/rtc_base/bytebuffer.h" | 24 #include "webrtc/rtc_base/bytebuffer.h" |
| 24 #include "webrtc/rtc_base/logging.h" | 25 #include "webrtc/rtc_base/logging.h" |
| 26 #include "webrtc/rtc_base/ptr_util.h" | |
| 25 #include "webrtc/system_wrappers/include/clock.h" | 27 #include "webrtc/system_wrappers/include/clock.h" |
| 26 #include "webrtc/system_wrappers/include/field_trial_default.h" | 28 #include "webrtc/system_wrappers/include/field_trial_default.h" |
| 27 #include "webrtc/test/field_trial.h" | 29 #include "webrtc/test/field_trial.h" |
| 28 #include "webrtc/video/rtp_video_stream_receiver.h" | 30 #include "webrtc/video/rtp_video_stream_receiver.h" |
| 29 | 31 |
| 30 using testing::_; | 32 using testing::_; |
| 31 | 33 |
| 32 namespace webrtc { | 34 namespace webrtc { |
| 33 | 35 |
| 34 namespace { | 36 namespace { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 } | 88 } |
| 87 DoOnCompleteFrame(frame.get()); | 89 DoOnCompleteFrame(frame.get()); |
| 88 } | 90 } |
| 89 void AppendExpectedBitstream(const uint8_t data[], size_t size_in_bytes) { | 91 void AppendExpectedBitstream(const uint8_t data[], size_t size_in_bytes) { |
| 90 // TODO(Johan): Let rtc::ByteBuffer handle uint8_t* instead of char*. | 92 // TODO(Johan): Let rtc::ByteBuffer handle uint8_t* instead of char*. |
| 91 buffer_.WriteBytes(reinterpret_cast<const char*>(data), size_in_bytes); | 93 buffer_.WriteBytes(reinterpret_cast<const char*>(data), size_in_bytes); |
| 92 } | 94 } |
| 93 rtc::ByteBufferWriter buffer_; | 95 rtc::ByteBufferWriter buffer_; |
| 94 }; | 96 }; |
| 95 | 97 |
| 98 class MockRtpPacketSink : public RtpPacketSinkInterface { | |
| 99 public: | |
| 100 MOCK_METHOD1(OnRtpPacket, void(const RtpPacketReceived&)); | |
| 101 }; | |
| 102 | |
| 103 std::unique_ptr<RtpPacketReceived> CreateRtpPacketReceived( | |
| 104 uint32_t ssrc, | |
| 105 uint16_t sequence_number) { | |
| 106 auto packet = rtc::MakeUnique<RtpPacketReceived>(); | |
| 107 packet->SetSsrc(ssrc); | |
| 108 packet->SetSequenceNumber(sequence_number); | |
| 109 return packet; | |
| 110 } | |
| 111 | |
| 112 MATCHER_P(SamePacketAs, other, "") { | |
| 113 return arg.Ssrc() == other.Ssrc() && | |
| 114 arg.SequenceNumber() == other.SequenceNumber(); | |
| 115 } | |
| 116 | |
| 96 } // namespace | 117 } // namespace |
| 97 | 118 |
| 98 class RtpVideoStreamReceiverTest : public testing::Test { | 119 class RtpVideoStreamReceiverTest : public testing::Test { |
| 99 public: | 120 public: |
| 100 RtpVideoStreamReceiverTest() | 121 RtpVideoStreamReceiverTest() |
| 101 : config_(CreateConfig()), | 122 : config_(CreateConfig()), |
| 102 timing_(Clock::GetRealTimeClock()), | 123 timing_(Clock::GetRealTimeClock()), |
| 103 process_thread_(ProcessThread::Create("TestThread")) {} | 124 process_thread_(ProcessThread::Create("TestThread")) {} |
| 104 | 125 |
| 105 void SetUp() { | 126 void SetUp() { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 rtp_header.header.markerBit = 1; | 358 rtp_header.header.markerBit = 1; |
| 338 rtp_header.type.Video.is_first_packet_in_frame = true; | 359 rtp_header.type.Video.is_first_packet_in_frame = true; |
| 339 rtp_header.frameType = kVideoFrameDelta; | 360 rtp_header.frameType = kVideoFrameDelta; |
| 340 rtp_header.type.Video.codec = kRtpVideoGeneric; | 361 rtp_header.type.Video.codec = kRtpVideoGeneric; |
| 341 | 362 |
| 342 EXPECT_CALL(mock_key_frame_request_sender_, RequestKeyFrame()); | 363 EXPECT_CALL(mock_key_frame_request_sender_, RequestKeyFrame()); |
| 343 rtp_video_stream_receiver_->OnReceivedPayloadData(data.data(), data.size(), | 364 rtp_video_stream_receiver_->OnReceivedPayloadData(data.data(), data.size(), |
| 344 &rtp_header); | 365 &rtp_header); |
| 345 } | 366 } |
| 346 | 367 |
| 368 TEST_F(RtpVideoStreamReceiverTest, SecondarySinksGetRtpNotifications) { | |
| 369 rtp_video_stream_receiver_->StartReceive(); | |
| 370 | |
| 371 MockRtpPacketSink secondary_sink_1; | |
| 372 MockRtpPacketSink secondary_sink_2; | |
| 373 | |
| 374 rtp_video_stream_receiver_->AddSecondarySink(&secondary_sink_1); | |
| 375 rtp_video_stream_receiver_->AddSecondarySink(&secondary_sink_2); | |
| 376 | |
| 377 constexpr uint32_t ssrc = 111; | |
| 378 constexpr size_t sequence_number = 222; | |
| 379 auto rtp_packet = CreateRtpPacketReceived(ssrc, sequence_number); | |
| 380 EXPECT_CALL(secondary_sink_1, OnRtpPacket(SamePacketAs(*rtp_packet))); | |
| 381 EXPECT_CALL(secondary_sink_2, OnRtpPacket(SamePacketAs(*rtp_packet))); | |
| 382 | |
| 383 rtp_video_stream_receiver_->OnRtpPacket(*rtp_packet); | |
| 384 | |
| 385 // Test tear-down. | |
| 386 rtp_video_stream_receiver_->StopReceive(); | |
| 387 rtp_video_stream_receiver_->RemoveSecondarySink(&secondary_sink_1); | |
| 388 rtp_video_stream_receiver_->RemoveSecondarySink(&secondary_sink_2); | |
| 389 } | |
| 390 | |
| 391 TEST_F(RtpVideoStreamReceiverTest, RemovedSecondarySinksGetNoRtpNotifications) { | |
| 392 rtp_video_stream_receiver_->StartReceive(); | |
| 393 | |
| 394 MockRtpPacketSink secondary_sink; | |
| 395 | |
| 396 rtp_video_stream_receiver_->AddSecondarySink(&secondary_sink); | |
| 397 rtp_video_stream_receiver_->RemoveSecondarySink(&secondary_sink); | |
| 398 | |
| 399 constexpr uint32_t ssrc = 111; | |
| 400 constexpr size_t sequence_number = 222; | |
| 401 auto rtp_packet = CreateRtpPacketReceived(ssrc, sequence_number); | |
| 402 | |
| 403 EXPECT_CALL(secondary_sink, OnRtpPacket(SamePacketAs(*rtp_packet))).Times(0); | |
| 404 | |
| 405 rtp_video_stream_receiver_->OnRtpPacket(*rtp_packet); | |
| 406 | |
| 407 // Test tear-down. | |
| 408 rtp_video_stream_receiver_->StopReceive(); | |
| 409 } | |
| 410 | |
| 411 TEST_F(RtpVideoStreamReceiverTest, | |
| 412 OnlyRemovedSecondarySinksExcludedFromNotifications) { | |
| 413 rtp_video_stream_receiver_->StartReceive(); | |
| 414 | |
| 415 MockRtpPacketSink kept_secondary_sink; | |
| 416 MockRtpPacketSink removed_secondary_sink; | |
| 417 | |
| 418 rtp_video_stream_receiver_->AddSecondarySink(&kept_secondary_sink); | |
| 419 rtp_video_stream_receiver_->AddSecondarySink(&removed_secondary_sink); | |
| 420 rtp_video_stream_receiver_->RemoveSecondarySink(&removed_secondary_sink); | |
| 421 | |
| 422 constexpr uint32_t ssrc = 111; | |
| 423 constexpr size_t sequence_number = 222; | |
| 424 auto rtp_packet = CreateRtpPacketReceived(ssrc, sequence_number); | |
| 425 EXPECT_CALL(kept_secondary_sink, OnRtpPacket(SamePacketAs(*rtp_packet))); | |
| 426 | |
| 427 rtp_video_stream_receiver_->OnRtpPacket(*rtp_packet); | |
| 428 | |
| 429 // Test tear-down. | |
| 430 rtp_video_stream_receiver_->StopReceive(); | |
| 431 rtp_video_stream_receiver_->RemoveSecondarySink(&kept_secondary_sink); | |
| 432 } | |
| 433 | |
| 434 // TODO(eladalon): !!! Discuss - do we want to allow secondaries to be | |
|
eladalon
2017/07/24 14:19:00
Danil, your thoughts?
danilchap
2017/07/24 15:02:07
I do not have strong opinion here.
Probably not: s
eladalon
2017/07/24 15:53:55
Acknowledged.
| |
| 435 // notified of packets before the primary got StartReceive() called? | |
| 436 // Add an appropriate test. | |
| 437 | |
| 438 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | |
| 439 TEST_F(RtpVideoStreamReceiverTest, RepeatedSecondarySinkDisallowed) { | |
| 440 MockRtpPacketSink secondary_sink; | |
| 441 | |
| 442 rtp_video_stream_receiver_->AddSecondarySink(&secondary_sink); | |
| 443 EXPECT_DEATH(rtp_video_stream_receiver_->AddSecondarySink(&secondary_sink), | |
| 444 ""); | |
| 445 | |
| 446 // Test tear-down. | |
| 447 rtp_video_stream_receiver_->RemoveSecondarySink(&secondary_sink); | |
| 448 } | |
| 449 #endif | |
| 450 | |
| 347 } // namespace webrtc | 451 } // namespace webrtc |
| OLD | NEW |