OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 <memory> | 11 #include <memory> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "webrtc/base/buffer.h" | 14 #include "webrtc/base/buffer.h" |
15 #include "webrtc/base/rate_limiter.h" | 15 #include "webrtc/base/rate_limiter.h" |
16 #include "webrtc/call/mock/mock_rtc_event_log.h" | 16 #include "webrtc/call/mock/mock_rtc_event_log.h" |
17 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" | 17 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" |
18 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 18 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
19 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 19 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
21 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h" | 21 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h" |
22 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | 22 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
23 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" | 23 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
24 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | |
24 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" | 25 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" |
25 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" | 26 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" |
26 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" | 27 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" |
27 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 28 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
28 #include "webrtc/system_wrappers/include/stl_util.h" | 29 #include "webrtc/system_wrappers/include/stl_util.h" |
29 #include "webrtc/test/gmock.h" | 30 #include "webrtc/test/gmock.h" |
30 #include "webrtc/test/gtest.h" | 31 #include "webrtc/test/gtest.h" |
31 #include "webrtc/test/mock_transport.h" | 32 #include "webrtc/test/mock_transport.h" |
32 #include "webrtc/typedefs.h" | 33 #include "webrtc/typedefs.h" |
33 | 34 |
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1417 EXPECT_EQ(kNumPackets * 2, transport_.packets_sent_); | 1418 EXPECT_EQ(kNumPackets * 2, transport_.packets_sent_); |
1418 | 1419 |
1419 // Must be at least 5ms in between retransmission attempts. | 1420 // Must be at least 5ms in between retransmission attempts. |
1420 fake_clock_.AdvanceTimeMilliseconds(5); | 1421 fake_clock_.AdvanceTimeMilliseconds(5); |
1421 | 1422 |
1422 // Resending should not work, bandwidth exceeded. | 1423 // Resending should not work, bandwidth exceeded. |
1423 rtp_sender_->OnReceivedNack(sequence_numbers, 0); | 1424 rtp_sender_->OnReceivedNack(sequence_numbers, 0); |
1424 EXPECT_EQ(kNumPackets * 2, transport_.packets_sent_); | 1425 EXPECT_EQ(kNumPackets * 2, transport_.packets_sent_); |
1425 } | 1426 } |
1426 | 1427 |
1427 // Verify that all packets of a frame have CVO byte set. | 1428 TEST_F(RtpSenderVideoTest, KeyFrameHasCVO) { |
1428 TEST_F(RtpSenderVideoTest, SendVideoWithCVO) { | |
1429 uint8_t kFrame[kMaxPacketLength]; | 1429 uint8_t kFrame[kMaxPacketLength]; |
1430 RTPVideoHeader hdr = {0}; | |
1431 hdr.rotation = kVideoRotation_90; | |
1432 | |
1433 EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension( | 1430 EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension( |
1434 kRtpExtensionVideoRotation, kVideoRotationExtensionId)); | 1431 kRtpExtensionVideoRotation, kVideoRotationExtensionId)); |
1435 EXPECT_EQ( | |
1436 RtpUtility::Word32Align(kRtpOneByteHeaderLength + kVideoRotationLength), | |
1437 rtp_sender_->RtpHeaderExtensionLength()); | |
1438 | 1432 |
1433 RTPVideoHeader hdr = {0}; | |
1434 hdr.rotation = kVideoRotation_0; | |
1439 rtp_sender_video_->SendVideo(kRtpVideoGeneric, kVideoFrameKey, kPayload, | 1435 rtp_sender_video_->SendVideo(kRtpVideoGeneric, kVideoFrameKey, kPayload, |
1440 kTimestamp, 0, kFrame, sizeof(kFrame), nullptr, | 1436 kTimestamp, 0, kFrame, sizeof(kFrame), nullptr, |
1441 &hdr); | 1437 &hdr); |
1442 | 1438 |
1443 RtpHeaderExtensionMap map; | 1439 RtpHeaderExtensionMap map; |
1444 map.Register(kRtpExtensionVideoRotation, kVideoRotationExtensionId); | 1440 map.Register(kRtpExtensionVideoRotation, kVideoRotationExtensionId); |
1441 const auto& last_raw_packet = *transport_.sent_packets_.back(); | |
1442 RtpPacketReceived last_parsed_packet(&map); | |
1443 last_parsed_packet.Parse(last_raw_packet.data(), last_raw_packet.size()); | |
1444 VideoRotation rotation; | |
1445 EXPECT_TRUE(last_parsed_packet.GetExtension<VideoOrientation>(&rotation)); | |
1446 EXPECT_EQ(kVideoRotation_0, rotation); | |
1447 } | |
1445 | 1448 |
1446 // Verify that this packet does have CVO byte. | 1449 TEST_F(RtpSenderVideoTest, DeltaFrameHasCVOWhenChanged) { |
1447 VerifyCVOPacket( | 1450 uint8_t kFrame[kMaxPacketLength]; |
1448 reinterpret_cast<uint8_t*>(transport_.sent_packets_[0]->data()), | 1451 EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension( |
1449 transport_.sent_packets_[0]->size(), true, &map, kSeqNum, hdr.rotation); | 1452 kRtpExtensionVideoRotation, kVideoRotationExtensionId)); |
1450 | 1453 |
1451 // Verify that this packet does have CVO byte. | 1454 RTPVideoHeader hdr = {0}; |
1452 VerifyCVOPacket( | 1455 hdr.rotation = kVideoRotation_90; |
1453 reinterpret_cast<uint8_t*>(transport_.sent_packets_[1]->data()), | 1456 EXPECT_TRUE(rtp_sender_video_->SendVideo(kRtpVideoGeneric, kVideoFrameKey, |
1454 transport_.sent_packets_[1]->size(), true, &map, kSeqNum + 1, | 1457 kPayload, kTimestamp, 0, kFrame, |
1455 hdr.rotation); | 1458 sizeof(kFrame), nullptr, &hdr)); |
1459 | |
1460 hdr.rotation = kVideoRotation_0; | |
1461 EXPECT_TRUE(rtp_sender_video_->SendVideo(kRtpVideoGeneric, kVideoFrameDelta, | |
1462 kPayload, kTimestamp + 1, 0, kFrame, | |
1463 sizeof(kFrame), nullptr, &hdr)); | |
1464 | |
1465 RtpHeaderExtensionMap map; | |
1466 map.Register(kRtpExtensionVideoRotation, kVideoRotationExtensionId); | |
1467 const auto& last_raw_packet = *transport_.sent_packets_.back(); | |
1468 RtpPacketReceived last_parsed_packet(&map); | |
1469 last_parsed_packet.Parse(last_raw_packet.data(), last_raw_packet.size()); | |
1470 VideoRotation rotation; | |
1471 EXPECT_TRUE(last_parsed_packet.GetExtension<VideoOrientation>(&rotation)); | |
1472 EXPECT_EQ(kVideoRotation_0, rotation); | |
1473 } | |
1474 | |
1475 TEST_F(RtpSenderVideoTest, DeltaFrameHasCVOWhenNonZero) { | |
1476 uint8_t kFrame[kMaxPacketLength]; | |
1477 EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension( | |
1478 kRtpExtensionVideoRotation, kVideoRotationExtensionId)); | |
1479 | |
1480 RTPVideoHeader hdr = {0}; | |
1481 hdr.rotation = kVideoRotation_90; | |
1482 EXPECT_TRUE(rtp_sender_video_->SendVideo(kRtpVideoGeneric, kVideoFrameKey, | |
1483 kPayload, kTimestamp, 0, kFrame, | |
1484 sizeof(kFrame), nullptr, &hdr)); | |
1485 | |
1486 EXPECT_TRUE(rtp_sender_video_->SendVideo(kRtpVideoGeneric, kVideoFrameDelta, | |
1487 kPayload, kTimestamp + 1, 0, kFrame, | |
1488 sizeof(kFrame), nullptr, &hdr)); | |
1489 | |
1490 RtpHeaderExtensionMap map; | |
1491 map.Register(kRtpExtensionVideoRotation, kVideoRotationExtensionId); | |
1492 const auto& last_raw_packet = *transport_.sent_packets_.back(); | |
1493 RtpPacketReceived last_parsed_packet(&map); | |
1494 last_parsed_packet.Parse(last_raw_packet.data(), last_raw_packet.size()); | |
1495 VideoRotation rotation; | |
1496 EXPECT_TRUE(last_parsed_packet.GetExtension<VideoOrientation>(&rotation)); | |
1497 EXPECT_EQ(kVideoRotation_90, rotation); | |
sprang_webrtc
2016/10/25 13:39:02
There seems to be a bunch of code duplication betw
| |
1456 } | 1498 } |
1457 | 1499 |
1458 // Make sure rotation is parsed correctly when the Camera (C) and Flip (F) bits | 1500 // Make sure rotation is parsed correctly when the Camera (C) and Flip (F) bits |
1459 // are set in the CVO byte. | 1501 // are set in the CVO byte. |
1460 TEST_F(RtpSenderVideoTest, SendVideoWithCameraAndFlipCVO) { | 1502 TEST_F(RtpSenderVideoTest, SendVideoWithCameraAndFlipCVO) { |
1461 // Test extracting rotation when Camera (C) and Flip (F) bits are zero. | 1503 // Test extracting rotation when Camera (C) and Flip (F) bits are zero. |
1462 EXPECT_EQ(kVideoRotation_0, ConvertCVOByteToVideoRotation(0)); | 1504 EXPECT_EQ(kVideoRotation_0, ConvertCVOByteToVideoRotation(0)); |
1463 EXPECT_EQ(kVideoRotation_90, ConvertCVOByteToVideoRotation(1)); | 1505 EXPECT_EQ(kVideoRotation_90, ConvertCVOByteToVideoRotation(1)); |
1464 EXPECT_EQ(kVideoRotation_180, ConvertCVOByteToVideoRotation(2)); | 1506 EXPECT_EQ(kVideoRotation_180, ConvertCVOByteToVideoRotation(2)); |
1465 EXPECT_EQ(kVideoRotation_270, ConvertCVOByteToVideoRotation(3)); | 1507 EXPECT_EQ(kVideoRotation_270, ConvertCVOByteToVideoRotation(3)); |
1466 // Test extracting rotation when Camera (C) and Flip (F) bits are set. | 1508 // Test extracting rotation when Camera (C) and Flip (F) bits are set. |
1467 const int flip_bit = 1 << 2; | 1509 const int flip_bit = 1 << 2; |
1468 const int camera_bit = 1 << 3; | 1510 const int camera_bit = 1 << 3; |
1469 EXPECT_EQ(kVideoRotation_0, | 1511 EXPECT_EQ(kVideoRotation_0, |
1470 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 0)); | 1512 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 0)); |
1471 EXPECT_EQ(kVideoRotation_90, | 1513 EXPECT_EQ(kVideoRotation_90, |
1472 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 1)); | 1514 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 1)); |
1473 EXPECT_EQ(kVideoRotation_180, | 1515 EXPECT_EQ(kVideoRotation_180, |
1474 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 2)); | 1516 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 2)); |
1475 EXPECT_EQ(kVideoRotation_270, | 1517 EXPECT_EQ(kVideoRotation_270, |
1476 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 3)); | 1518 ConvertCVOByteToVideoRotation(flip_bit | camera_bit | 3)); |
1477 } | 1519 } |
1478 | 1520 |
1479 } // namespace webrtc | 1521 } // namespace webrtc |
OLD | NEW |