OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 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/call/rtx_receive_stream.h" | 11 #include "webrtc/call/rtx_receive_stream.h" |
12 #include "webrtc/call/test/mock_rtp_packet_sink_interface.h" | 12 #include "webrtc/call/test/mock_rtp_packet_sink_interface.h" |
13 #include "webrtc/modules/rtp_rtcp/include/rtp_header_extension_map.h" | 13 #include "webrtc/modules/rtp_rtcp/include/rtp_header_extension_map.h" |
14 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" | 14 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
15 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | 15 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
16 #include "webrtc/test/gmock.h" | 16 #include "webrtc/test/gmock.h" |
17 #include "webrtc/test/gtest.h" | 17 #include "webrtc/test/gtest.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 using ::testing::_; | 23 using ::testing::_; |
24 using ::testing::StrictMock; | 24 using ::testing::StrictMock; |
25 | 25 |
26 constexpr int kMediaPayloadType = 100; | 26 constexpr int kMediaPayloadType = 100; |
27 constexpr int kRtxPayloadType = 98; | 27 constexpr int kRtxPayloadType = 98; |
| 28 constexpr int kUnknownPayloadType = 90; |
28 constexpr uint32_t kMediaSSRC = 0x3333333; | 29 constexpr uint32_t kMediaSSRC = 0x3333333; |
29 constexpr uint16_t kMediaSeqno = 0x5657; | 30 constexpr uint16_t kMediaSeqno = 0x5657; |
30 | 31 |
31 constexpr uint8_t kRtxPacket[] = { | 32 constexpr uint8_t kRtxPacket[] = { |
32 0x80, // Version 2. | 33 0x80, // Version 2. |
33 98, // Payload type. | 34 98, // Payload type. |
34 0x12, 0x34, // Seqno. | 35 0x12, 0x34, // Seqno. |
35 0x11, 0x11, 0x11, 0x11, // Timestamp. | 36 0x11, 0x11, 0x11, 0x11, // Timestamp. |
36 0x22, 0x22, 0x22, 0x22, // SSRC. | 37 0x22, 0x22, 0x22, 0x22, // SSRC. |
37 // RTX header. | 38 // RTX header. |
(...skipping 10 matching lines...) Expand all Loading... |
48 0x22, 0x22, 0x22, 0x22, // SSRC. | 49 0x22, 0x22, 0x22, 0x22, // SSRC. |
49 0xbe, 0xde, 0x00, 0x01, // Extension header. | 50 0xbe, 0xde, 0x00, 0x01, // Extension header. |
50 0x30, 0x01, 0x00, 0x00, // 90 degree rotation. | 51 0x30, 0x01, 0x00, 0x00, // 90 degree rotation. |
51 // RTX header. | 52 // RTX header. |
52 0x56, 0x57, // Orig seqno. | 53 0x56, 0x57, // Orig seqno. |
53 // Payload. | 54 // Payload. |
54 0xee, | 55 0xee, |
55 }; | 56 }; |
56 | 57 |
57 std::map<int, int> PayloadTypeMapping() { | 58 std::map<int, int> PayloadTypeMapping() { |
58 std::map<int, int> m; | 59 const std::map<int, int> m = {{kRtxPayloadType, kMediaPayloadType}}; |
59 m[kRtxPayloadType] = kMediaPayloadType; | |
60 return m; | 60 return m; |
61 } | 61 } |
62 | 62 |
63 template <typename T> | 63 template <typename T> |
64 rtc::ArrayView<T> Truncate(rtc::ArrayView<T> a, size_t drop) { | 64 rtc::ArrayView<T> Truncate(rtc::ArrayView<T> a, size_t drop) { |
65 return a.subview(0, a.size() - drop); | 65 return a.subview(0, a.size() - drop); |
66 } | 66 } |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 TEST(RtxReceiveStreamTest, RestoresPacketPayload) { | 70 TEST(RtxReceiveStreamTest, RestoresPacketPayload) { |
71 StrictMock<MockRtpPacketSink> media_sink; | 71 StrictMock<MockRtpPacketSink> media_sink; |
72 RtxReceiveStream rtx_sink(&media_sink, PayloadTypeMapping(), kMediaSSRC); | 72 RtxReceiveStream rtx_sink(&media_sink, PayloadTypeMapping(), kMediaSSRC); |
73 RtpPacketReceived rtx_packet; | 73 RtpPacketReceived rtx_packet; |
74 EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket))); | 74 EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket))); |
75 | 75 |
76 EXPECT_CALL(media_sink, OnRtpPacket(_)).WillOnce(testing::Invoke( | 76 EXPECT_CALL(media_sink, OnRtpPacket(_)).WillOnce(testing::Invoke( |
77 [](const RtpPacketReceived& packet) { | 77 [](const RtpPacketReceived& packet) { |
78 EXPECT_EQ(packet.SequenceNumber(), kMediaSeqno); | 78 EXPECT_EQ(packet.SequenceNumber(), kMediaSeqno); |
79 EXPECT_EQ(packet.Ssrc(), kMediaSSRC); | 79 EXPECT_EQ(packet.Ssrc(), kMediaSSRC); |
80 EXPECT_EQ(packet.PayloadType(), kMediaPayloadType); | 80 EXPECT_EQ(packet.PayloadType(), kMediaPayloadType); |
81 EXPECT_THAT(packet.payload(), testing::ElementsAre(0xee)); | 81 EXPECT_THAT(packet.payload(), testing::ElementsAre(0xee)); |
82 })); | 82 })); |
83 | 83 |
84 rtx_sink.OnRtpPacket(rtx_packet); | 84 rtx_sink.OnRtpPacket(rtx_packet); |
85 } | 85 } |
86 | 86 |
| 87 TEST(RtxReceiveStreamTest, SetsRecoveredFlag) { |
| 88 StrictMock<MockRtpPacketSink> media_sink; |
| 89 RtxReceiveStream rtx_sink(&media_sink, PayloadTypeMapping(), kMediaSSRC); |
| 90 RtpPacketReceived rtx_packet; |
| 91 EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket))); |
| 92 EXPECT_FALSE(rtx_packet.recovered()); |
| 93 EXPECT_CALL(media_sink, OnRtpPacket(_)) |
| 94 .WillOnce(testing::Invoke([](const RtpPacketReceived& packet) { |
| 95 EXPECT_TRUE(packet.recovered()); |
| 96 })); |
| 97 |
| 98 rtx_sink.OnRtpPacket(rtx_packet); |
| 99 } |
| 100 |
87 TEST(RtxReceiveStreamTest, IgnoresUnknownPayloadType) { | 101 TEST(RtxReceiveStreamTest, IgnoresUnknownPayloadType) { |
88 StrictMock<MockRtpPacketSink> media_sink; | 102 StrictMock<MockRtpPacketSink> media_sink; |
89 RtxReceiveStream rtx_sink(&media_sink, std::map<int, int>(), kMediaSSRC); | 103 const std::map<int, int> payload_type_mapping = { |
| 104 {kUnknownPayloadType, kMediaPayloadType}}; |
| 105 |
| 106 RtxReceiveStream rtx_sink(&media_sink, payload_type_mapping, kMediaSSRC); |
90 RtpPacketReceived rtx_packet; | 107 RtpPacketReceived rtx_packet; |
91 EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket))); | 108 EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket))); |
92 rtx_sink.OnRtpPacket(rtx_packet); | 109 rtx_sink.OnRtpPacket(rtx_packet); |
93 } | 110 } |
94 | 111 |
95 TEST(RtxReceiveStreamTest, IgnoresTruncatedPacket) { | 112 TEST(RtxReceiveStreamTest, IgnoresTruncatedPacket) { |
96 StrictMock<MockRtpPacketSink> media_sink; | 113 StrictMock<MockRtpPacketSink> media_sink; |
97 RtxReceiveStream rtx_sink(&media_sink, PayloadTypeMapping(), kMediaSSRC); | 114 RtxReceiveStream rtx_sink(&media_sink, PayloadTypeMapping(), kMediaSSRC); |
98 RtpPacketReceived rtx_packet; | 115 RtpPacketReceived rtx_packet; |
99 EXPECT_TRUE( | 116 EXPECT_TRUE( |
(...skipping 22 matching lines...) Expand all Loading... |
122 EXPECT_THAT(packet.payload(), testing::ElementsAre(0xee)); | 139 EXPECT_THAT(packet.payload(), testing::ElementsAre(0xee)); |
123 VideoRotation rotation = kVideoRotation_0; | 140 VideoRotation rotation = kVideoRotation_0; |
124 EXPECT_TRUE(packet.GetExtension<VideoOrientation>(&rotation)); | 141 EXPECT_TRUE(packet.GetExtension<VideoOrientation>(&rotation)); |
125 EXPECT_EQ(rotation, kVideoRotation_90); | 142 EXPECT_EQ(rotation, kVideoRotation_90); |
126 })); | 143 })); |
127 | 144 |
128 rtx_sink.OnRtpPacket(rtx_packet); | 145 rtx_sink.OnRtpPacket(rtx_packet); |
129 } | 146 } |
130 | 147 |
131 } // namespace webrtc | 148 } // namespace webrtc |
OLD | NEW |