mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 11 | #include <memory> |
| 12 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 13 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 15 | #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 16 | #include "webrtc/test/gmock.h" |
| 17 | #include "webrtc/test/gtest.h" |
Peter Boström | 7623ce4 | 2015-12-09 12:13:30 +0100 | [diff] [blame] | 18 | #include "webrtc/video/payload_router.h" |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 19 | |
| 20 | using ::testing::_; |
| 21 | using ::testing::AnyNumber; |
| 22 | using ::testing::NiceMock; |
| 23 | using ::testing::Return; |
| 24 | |
| 25 | namespace webrtc { |
| 26 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 27 | TEST(PayloadRouterTest, SendOnOneModule) { |
perkj | bc75d97 | 2016-05-02 06:31:25 -0700 | [diff] [blame] | 28 | NiceMock<MockRtpRtcp> rtp; |
Peter Boström | 404686a | 2016-02-11 23:37:26 +0100 | [diff] [blame] | 29 | std::vector<RtpRtcp*> modules(1, &rtp); |
perkj | bc75d97 | 2016-05-02 06:31:25 -0700 | [diff] [blame] | 30 | std::vector<VideoStream> streams(1); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 31 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 32 | uint8_t payload = 'a'; |
| 33 | int8_t payload_type = 96; |
| 34 | EncodedImage encoded_image; |
| 35 | encoded_image._timeStamp = 1; |
| 36 | encoded_image.capture_time_ms_ = 2; |
| 37 | encoded_image._frameType = kVideoFrameKey; |
| 38 | encoded_image._buffer = &payload; |
| 39 | encoded_image._length = 1; |
| 40 | |
| 41 | PayloadRouter payload_router(modules, payload_type); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 42 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 43 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, |
| 44 | encoded_image._timeStamp, |
| 45 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 46 | encoded_image._length, nullptr, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 47 | .Times(0); |
sergeyu | c681250 | 2016-11-03 11:06:38 -0700 | [diff] [blame] | 48 | EXPECT_NE( |
| 49 | EncodedImageCallback::Result::OK, |
| 50 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 51 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 52 | payload_router.set_active(true); |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 53 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, |
| 54 | encoded_image._timeStamp, |
| 55 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 56 | encoded_image._length, nullptr, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 57 | .Times(1); |
sergeyu | c681250 | 2016-11-03 11:06:38 -0700 | [diff] [blame] | 58 | EXPECT_EQ( |
| 59 | EncodedImageCallback::Result::OK, |
| 60 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 61 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 62 | payload_router.set_active(false); |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 63 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, |
| 64 | encoded_image._timeStamp, |
| 65 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 66 | encoded_image._length, nullptr, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 67 | .Times(0); |
sergeyu | c681250 | 2016-11-03 11:06:38 -0700 | [diff] [blame] | 68 | EXPECT_NE( |
| 69 | EncodedImageCallback::Result::OK, |
| 70 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 71 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 72 | payload_router.set_active(true); |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 73 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, |
| 74 | encoded_image._timeStamp, |
| 75 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 76 | encoded_image._length, nullptr, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 77 | .Times(1); |
sergeyu | c681250 | 2016-11-03 11:06:38 -0700 | [diff] [blame] | 78 | EXPECT_EQ( |
| 79 | EncodedImageCallback::Result::OK, |
| 80 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 83 | TEST(PayloadRouterTest, SendSimulcast) { |
perkj | bc75d97 | 2016-05-02 06:31:25 -0700 | [diff] [blame] | 84 | NiceMock<MockRtpRtcp> rtp_1; |
| 85 | NiceMock<MockRtpRtcp> rtp_2; |
Peter Boström | 404686a | 2016-02-11 23:37:26 +0100 | [diff] [blame] | 86 | std::vector<RtpRtcp*> modules; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 87 | modules.push_back(&rtp_1); |
| 88 | modules.push_back(&rtp_2); |
perkj | bc75d97 | 2016-05-02 06:31:25 -0700 | [diff] [blame] | 89 | std::vector<VideoStream> streams(2); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 90 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 91 | int8_t payload_type = 96; |
| 92 | uint8_t payload = 'a'; |
| 93 | EncodedImage encoded_image; |
| 94 | encoded_image._timeStamp = 1; |
| 95 | encoded_image.capture_time_ms_ = 2; |
| 96 | encoded_image._frameType = kVideoFrameKey; |
| 97 | encoded_image._buffer = &payload; |
| 98 | encoded_image._length = 1; |
| 99 | |
| 100 | PayloadRouter payload_router(modules, payload_type); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 101 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 102 | CodecSpecificInfo codec_info_1; |
| 103 | memset(&codec_info_1, 0, sizeof(CodecSpecificInfo)); |
| 104 | codec_info_1.codecType = kVideoCodecVP8; |
| 105 | codec_info_1.codecSpecific.VP8.simulcastIdx = 0; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 106 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 107 | payload_router.set_active(true); |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 108 | EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, payload_type, |
| 109 | encoded_image._timeStamp, |
| 110 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 111 | encoded_image._length, nullptr, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 112 | .Times(1); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 113 | EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _)).Times(0); |
sergeyu | c681250 | 2016-11-03 11:06:38 -0700 | [diff] [blame] | 114 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 115 | payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr) |
| 116 | .error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 117 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 118 | CodecSpecificInfo codec_info_2; |
| 119 | memset(&codec_info_2, 0, sizeof(CodecSpecificInfo)); |
| 120 | codec_info_2.codecType = kVideoCodecVP8; |
| 121 | codec_info_2.codecSpecific.VP8.simulcastIdx = 1; |
| 122 | |
| 123 | EXPECT_CALL(rtp_2, SendOutgoingData(encoded_image._frameType, payload_type, |
| 124 | encoded_image._timeStamp, |
| 125 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 126 | encoded_image._length, nullptr, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 127 | .Times(1); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 128 | EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 129 | .Times(0); |
sergeyu | c681250 | 2016-11-03 11:06:38 -0700 | [diff] [blame] | 130 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 131 | payload_router.OnEncodedImage(encoded_image, &codec_info_2, nullptr) |
| 132 | .error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 133 | |
mflodman@webrtc.org | 50e2816 | 2015-02-23 07:45:11 +0000 | [diff] [blame] | 134 | // Inactive. |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 135 | payload_router.set_active(false); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 136 | EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 137 | .Times(0); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 138 | EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 139 | .Times(0); |
sergeyu | c681250 | 2016-11-03 11:06:38 -0700 | [diff] [blame] | 140 | EXPECT_NE(EncodedImageCallback::Result::OK, |
| 141 | payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr) |
| 142 | .error); |
| 143 | EXPECT_NE(EncodedImageCallback::Result::OK, |
| 144 | payload_router.OnEncodedImage(encoded_image, &codec_info_2, nullptr) |
| 145 | .error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 148 | TEST(PayloadRouterTest, MaxPayloadLength) { |
mflodman@webrtc.org | a4ef2ce | 2015-02-12 09:54:18 +0000 | [diff] [blame] | 149 | // Without any limitations from the modules, verify we get the max payload |
| 150 | // length for IP/UDP/SRTP with a MTU of 150 bytes. |
| 151 | const size_t kDefaultMaxLength = 1500 - 20 - 8 - 12 - 4; |
perkj | bc75d97 | 2016-05-02 06:31:25 -0700 | [diff] [blame] | 152 | NiceMock<MockRtpRtcp> rtp_1; |
| 153 | NiceMock<MockRtpRtcp> rtp_2; |
Peter Boström | 404686a | 2016-02-11 23:37:26 +0100 | [diff] [blame] | 154 | std::vector<RtpRtcp*> modules; |
mflodman@webrtc.org | a4ef2ce | 2015-02-12 09:54:18 +0000 | [diff] [blame] | 155 | modules.push_back(&rtp_1); |
| 156 | modules.push_back(&rtp_2); |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 157 | PayloadRouter payload_router(modules, 42); |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 158 | |
| 159 | EXPECT_EQ(kDefaultMaxLength, PayloadRouter::DefaultMaxPayloadLength()); |
perkj | bc75d97 | 2016-05-02 06:31:25 -0700 | [diff] [blame] | 160 | std::vector<VideoStream> streams(2); |
mflodman@webrtc.org | a4ef2ce | 2015-02-12 09:54:18 +0000 | [diff] [blame] | 161 | |
| 162 | // Modules return a higher length than the default value. |
| 163 | EXPECT_CALL(rtp_1, MaxDataPayloadLength()) |
| 164 | .Times(1) |
| 165 | .WillOnce(Return(kDefaultMaxLength + 10)); |
| 166 | EXPECT_CALL(rtp_2, MaxDataPayloadLength()) |
| 167 | .Times(1) |
| 168 | .WillOnce(Return(kDefaultMaxLength + 10)); |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 169 | EXPECT_EQ(kDefaultMaxLength, payload_router.MaxPayloadLength()); |
mflodman@webrtc.org | a4ef2ce | 2015-02-12 09:54:18 +0000 | [diff] [blame] | 170 | |
| 171 | // The modules return a value lower than default. |
| 172 | const size_t kTestMinPayloadLength = 1001; |
| 173 | EXPECT_CALL(rtp_1, MaxDataPayloadLength()) |
| 174 | .Times(1) |
| 175 | .WillOnce(Return(kTestMinPayloadLength + 10)); |
| 176 | EXPECT_CALL(rtp_2, MaxDataPayloadLength()) |
| 177 | .Times(1) |
| 178 | .WillOnce(Return(kTestMinPayloadLength)); |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 179 | EXPECT_EQ(kTestMinPayloadLength, payload_router.MaxPayloadLength()); |
mflodman@webrtc.org | a4ef2ce | 2015-02-12 09:54:18 +0000 | [diff] [blame] | 180 | } |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 181 | } // namespace webrtc |