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 kOtherPayloadType = 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. |
38 0x56, 0x57, // Orig seqno. | 39 0x56, 0x57, // Orig seqno. |
39 // Payload. | 40 // Payload. |
40 0xee, | 41 0xee, |
41 }; | 42 }; |
42 | 43 |
43 constexpr uint8_t kRtxPacketWithCVO[] = { | 44 constexpr uint8_t kRtxPacketWithCVO[] = { |
44 0x90, // Version 2, X set. | 45 0x90, // Version 2, X set. |
45 98, // Payload type. | 46 98, // Payload type. |
46 0x12, 0x34, // Seqno. | 47 0x12, 0x34, // Seqno. |
47 0x11, 0x11, 0x11, 0x11, // Timestamp. | 48 0x11, 0x11, 0x11, 0x11, // Timestamp. |
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(int payload_type = kRtxPayloadType) { |
58 std::map<int, int> m; | 59 std::map<int, int> m; |
59 m[kRtxPayloadType] = kMediaPayloadType; | 60 m[payload_type] = kMediaPayloadType; |
60 return m; | 61 return m; |
61 } | 62 } |
62 | 63 |
63 template <typename T> | 64 template <typename T> |
64 rtc::ArrayView<T> Truncate(rtc::ArrayView<T> a, size_t drop) { | 65 rtc::ArrayView<T> Truncate(rtc::ArrayView<T> a, size_t drop) { |
65 return a.subview(0, a.size() - drop); | 66 return a.subview(0, a.size() - drop); |
66 } | 67 } |
67 | 68 |
68 } // namespace | 69 } // namespace |
69 | 70 |
70 TEST(RtxReceiveStreamTest, RestoresPacketPayload) { | 71 TEST(RtxReceiveStreamTest, RestoresPacketPayload) { |
71 StrictMock<MockRtpPacketSink> media_sink; | 72 StrictMock<MockRtpPacketSink> media_sink; |
72 RtxReceiveStream rtx_sink(&media_sink, PayloadTypeMapping(), kMediaSSRC); | 73 RtxReceiveStream rtx_sink(&media_sink, PayloadTypeMapping(), kMediaSSRC); |
73 RtpPacketReceived rtx_packet; | 74 RtpPacketReceived rtx_packet; |
74 EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket))); | 75 EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket))); |
75 | 76 |
76 EXPECT_CALL(media_sink, OnRtpPacket(_)).WillOnce(testing::Invoke( | 77 EXPECT_CALL(media_sink, OnRtpPacket(_)).WillOnce(testing::Invoke( |
77 [](const RtpPacketReceived& packet) { | 78 [](const RtpPacketReceived& packet) { |
78 EXPECT_EQ(packet.SequenceNumber(), kMediaSeqno); | 79 EXPECT_EQ(packet.SequenceNumber(), kMediaSeqno); |
79 EXPECT_EQ(packet.Ssrc(), kMediaSSRC); | 80 EXPECT_EQ(packet.Ssrc(), kMediaSSRC); |
80 EXPECT_EQ(packet.PayloadType(), kMediaPayloadType); | 81 EXPECT_EQ(packet.PayloadType(), kMediaPayloadType); |
81 EXPECT_THAT(packet.payload(), testing::ElementsAre(0xee)); | 82 EXPECT_THAT(packet.payload(), testing::ElementsAre(0xee)); |
82 })); | 83 })); |
83 | 84 |
84 rtx_sink.OnRtpPacket(rtx_packet); | 85 rtx_sink.OnRtpPacket(rtx_packet); |
85 } | 86 } |
86 | 87 |
87 TEST(RtxReceiveStreamTest, IgnoresUnknownPayloadType) { | 88 TEST(RtxReceiveStreamTest, IgnoresUnknownPayloadType) { |
88 StrictMock<MockRtpPacketSink> media_sink; | 89 StrictMock<MockRtpPacketSink> media_sink; |
89 RtxReceiveStream rtx_sink(&media_sink, std::map<int, int>(), kMediaSSRC); | 90 RtxReceiveStream rtx_sink(&media_sink, PayloadTypeMapping(kOtherPayloadType), |
danilchap
2017/08/29 13:33:06
suggestion:
{{kUnknownPayloadType, kMediaPayloadTy
nisse-webrtc
2017/08/29 13:51:35
If I change to a map initializer here, should I do
| |
91 kMediaSSRC); | |
90 RtpPacketReceived rtx_packet; | 92 RtpPacketReceived rtx_packet; |
91 EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket))); | 93 EXPECT_TRUE(rtx_packet.Parse(rtc::ArrayView<const uint8_t>(kRtxPacket))); |
92 rtx_sink.OnRtpPacket(rtx_packet); | 94 rtx_sink.OnRtpPacket(rtx_packet); |
93 } | 95 } |
94 | 96 |
95 TEST(RtxReceiveStreamTest, IgnoresTruncatedPacket) { | 97 TEST(RtxReceiveStreamTest, IgnoresTruncatedPacket) { |
96 StrictMock<MockRtpPacketSink> media_sink; | 98 StrictMock<MockRtpPacketSink> media_sink; |
97 RtxReceiveStream rtx_sink(&media_sink, PayloadTypeMapping(), kMediaSSRC); | 99 RtxReceiveStream rtx_sink(&media_sink, PayloadTypeMapping(), kMediaSSRC); |
98 RtpPacketReceived rtx_packet; | 100 RtpPacketReceived rtx_packet; |
99 EXPECT_TRUE( | 101 EXPECT_TRUE( |
(...skipping 22 matching lines...) Expand all Loading... | |
122 EXPECT_THAT(packet.payload(), testing::ElementsAre(0xee)); | 124 EXPECT_THAT(packet.payload(), testing::ElementsAre(0xee)); |
123 VideoRotation rotation = kVideoRotation_0; | 125 VideoRotation rotation = kVideoRotation_0; |
124 EXPECT_TRUE(packet.GetExtension<VideoOrientation>(&rotation)); | 126 EXPECT_TRUE(packet.GetExtension<VideoOrientation>(&rotation)); |
125 EXPECT_EQ(rotation, kVideoRotation_90); | 127 EXPECT_EQ(rotation, kVideoRotation_90); |
126 })); | 128 })); |
127 | 129 |
128 rtx_sink.OnRtpPacket(rtx_packet); | 130 rtx_sink.OnRtpPacket(rtx_packet); |
129 } | 131 } |
130 | 132 |
131 } // namespace webrtc | 133 } // namespace webrtc |
OLD | NEW |