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> |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 12 | #include <string> |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "call/video_config.h" |
| 15 | #include "modules/rtp_rtcp/include/rtp_rtcp.h" |
| 16 | #include "modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
| 17 | #include "modules/video_coding/include/video_codec_interface.h" |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 18 | #include "test/field_trial.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "test/gmock.h" |
| 20 | #include "test/gtest.h" |
| 21 | #include "video/payload_router.h" |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 22 | |
| 23 | using ::testing::_; |
| 24 | using ::testing::AnyNumber; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 25 | using ::testing::Invoke; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 26 | using ::testing::NiceMock; |
| 27 | using ::testing::Return; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 28 | using ::testing::Unused; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 31 | namespace { |
| 32 | const int8_t kPayloadType = 96; |
| 33 | const uint32_t kSsrc1 = 12345; |
| 34 | const uint32_t kSsrc2 = 23456; |
| 35 | const int16_t kPictureId = 123; |
| 36 | const int16_t kTl0PicIdx = 20; |
| 37 | const uint8_t kTemporalIdx = 1; |
| 38 | const int16_t kInitialPictureId1 = 222; |
| 39 | const int16_t kInitialPictureId2 = 44; |
| 40 | } // namespace |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 41 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 42 | TEST(PayloadRouterTest, SendOnOneModule) { |
perkj | bc75d97 | 2016-05-02 06:31:25 -0700 | [diff] [blame] | 43 | NiceMock<MockRtpRtcp> rtp; |
Peter Boström | 404686a | 2016-02-11 23:37:26 +0100 | [diff] [blame] | 44 | std::vector<RtpRtcp*> modules(1, &rtp); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 45 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 46 | uint8_t payload = 'a'; |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 47 | EncodedImage encoded_image; |
| 48 | encoded_image._timeStamp = 1; |
| 49 | encoded_image.capture_time_ms_ = 2; |
| 50 | encoded_image._frameType = kVideoFrameKey; |
| 51 | encoded_image._buffer = &payload; |
| 52 | encoded_image._length = 1; |
| 53 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 54 | PayloadRouter payload_router(modules, {kSsrc1}, kPayloadType, {}); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 55 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 56 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 57 | encoded_image._timeStamp, |
| 58 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 59 | encoded_image._length, nullptr, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 60 | .Times(0); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 61 | EXPECT_NE( |
| 62 | EncodedImageCallback::Result::OK, |
| 63 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 64 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 65 | payload_router.SetActive(true); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 66 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 67 | encoded_image._timeStamp, |
| 68 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 69 | encoded_image._length, nullptr, _, _)) |
sergeyu | 7b9feee | 2016-11-17 16:16:14 -0800 | [diff] [blame] | 70 | .Times(1) |
| 71 | .WillOnce(Return(true)); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 72 | EXPECT_EQ( |
| 73 | EncodedImageCallback::Result::OK, |
| 74 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 75 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 76 | payload_router.SetActive(false); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 77 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 78 | encoded_image._timeStamp, |
| 79 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 80 | encoded_image._length, nullptr, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 81 | .Times(0); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 82 | EXPECT_NE( |
| 83 | EncodedImageCallback::Result::OK, |
| 84 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 85 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 86 | payload_router.SetActive(true); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 87 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 88 | encoded_image._timeStamp, |
| 89 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 90 | encoded_image._length, nullptr, _, _)) |
sergeyu | 7b9feee | 2016-11-17 16:16:14 -0800 | [diff] [blame] | 91 | .Times(1) |
| 92 | .WillOnce(Return(true)); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 93 | EXPECT_EQ( |
| 94 | EncodedImageCallback::Result::OK, |
| 95 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 98 | TEST(PayloadRouterTest, SendSimulcast) { |
perkj | bc75d97 | 2016-05-02 06:31:25 -0700 | [diff] [blame] | 99 | NiceMock<MockRtpRtcp> rtp_1; |
| 100 | NiceMock<MockRtpRtcp> rtp_2; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 101 | std::vector<RtpRtcp*> modules = {&rtp_1, &rtp_2}; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 102 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 103 | uint8_t payload = 'a'; |
| 104 | EncodedImage encoded_image; |
| 105 | encoded_image._timeStamp = 1; |
| 106 | encoded_image.capture_time_ms_ = 2; |
| 107 | encoded_image._frameType = kVideoFrameKey; |
| 108 | encoded_image._buffer = &payload; |
| 109 | encoded_image._length = 1; |
| 110 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 111 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {}); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 112 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 113 | CodecSpecificInfo codec_info_1; |
| 114 | memset(&codec_info_1, 0, sizeof(CodecSpecificInfo)); |
| 115 | codec_info_1.codecType = kVideoCodecVP8; |
| 116 | codec_info_1.codecSpecific.VP8.simulcastIdx = 0; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 117 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 118 | payload_router.SetActive(true); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 119 | EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 120 | encoded_image._timeStamp, |
| 121 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 122 | encoded_image._length, nullptr, _, _)) |
sergeyu | 7b9feee | 2016-11-17 16:16:14 -0800 | [diff] [blame] | 123 | .Times(1) |
| 124 | .WillOnce(Return(true)); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 125 | EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _)).Times(0); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 126 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 127 | payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr) |
| 128 | .error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 129 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 130 | CodecSpecificInfo codec_info_2; |
| 131 | memset(&codec_info_2, 0, sizeof(CodecSpecificInfo)); |
| 132 | codec_info_2.codecType = kVideoCodecVP8; |
| 133 | codec_info_2.codecSpecific.VP8.simulcastIdx = 1; |
| 134 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 135 | EXPECT_CALL(rtp_2, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 136 | encoded_image._timeStamp, |
| 137 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 138 | encoded_image._length, nullptr, _, _)) |
sergeyu | 7b9feee | 2016-11-17 16:16:14 -0800 | [diff] [blame] | 139 | .Times(1) |
| 140 | .WillOnce(Return(true)); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 141 | EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 142 | .Times(0); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 143 | EXPECT_EQ(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 | |
mflodman@webrtc.org | 50e2816 | 2015-02-23 07:45:11 +0000 | [diff] [blame] | 147 | // Inactive. |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 148 | payload_router.SetActive(false); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 149 | EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 150 | .Times(0); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 151 | EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 152 | .Times(0); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 153 | EXPECT_NE(EncodedImageCallback::Result::OK, |
| 154 | payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr) |
| 155 | .error); |
| 156 | EXPECT_NE(EncodedImageCallback::Result::OK, |
| 157 | payload_router.OnEncodedImage(encoded_image, &codec_info_2, nullptr) |
| 158 | .error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 159 | } |
| 160 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 161 | TEST(PayloadRouterTest, SimulcastTargetBitrate) { |
| 162 | NiceMock<MockRtpRtcp> rtp_1; |
| 163 | NiceMock<MockRtpRtcp> rtp_2; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 164 | std::vector<RtpRtcp*> modules = {&rtp_1, &rtp_2}; |
| 165 | |
| 166 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {}); |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 167 | payload_router.SetActive(true); |
| 168 | |
| 169 | BitrateAllocation bitrate; |
| 170 | bitrate.SetBitrate(0, 0, 10000); |
| 171 | bitrate.SetBitrate(0, 1, 20000); |
| 172 | bitrate.SetBitrate(1, 0, 40000); |
| 173 | bitrate.SetBitrate(1, 1, 80000); |
| 174 | |
| 175 | BitrateAllocation layer0_bitrate; |
| 176 | layer0_bitrate.SetBitrate(0, 0, 10000); |
| 177 | layer0_bitrate.SetBitrate(0, 1, 20000); |
| 178 | |
| 179 | BitrateAllocation layer1_bitrate; |
| 180 | layer1_bitrate.SetBitrate(0, 0, 40000); |
| 181 | layer1_bitrate.SetBitrate(0, 1, 80000); |
| 182 | |
| 183 | EXPECT_CALL(rtp_1, SetVideoBitrateAllocation(layer0_bitrate)).Times(1); |
| 184 | EXPECT_CALL(rtp_2, SetVideoBitrateAllocation(layer1_bitrate)).Times(1); |
| 185 | |
| 186 | payload_router.OnBitrateAllocationUpdated(bitrate); |
| 187 | } |
| 188 | |
sprang | d0fc37a | 2017-06-22 05:40:25 -0700 | [diff] [blame] | 189 | TEST(PayloadRouterTest, SimulcastTargetBitrateWithInactiveStream) { |
| 190 | // Set up two active rtp modules. |
| 191 | NiceMock<MockRtpRtcp> rtp_1; |
| 192 | NiceMock<MockRtpRtcp> rtp_2; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 193 | std::vector<RtpRtcp*> modules = {&rtp_1, &rtp_2}; |
| 194 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {}); |
sprang | d0fc37a | 2017-06-22 05:40:25 -0700 | [diff] [blame] | 195 | payload_router.SetActive(true); |
| 196 | |
| 197 | // Create bitrate allocation with bitrate only for the first stream. |
| 198 | BitrateAllocation bitrate; |
| 199 | bitrate.SetBitrate(0, 0, 10000); |
| 200 | bitrate.SetBitrate(0, 1, 20000); |
| 201 | |
| 202 | // Expect only the first rtp module to be asked to send a TargetBitrate |
| 203 | // message. (No target bitrate with 0bps sent from the second one.) |
| 204 | EXPECT_CALL(rtp_1, SetVideoBitrateAllocation(bitrate)).Times(1); |
| 205 | EXPECT_CALL(rtp_2, SetVideoBitrateAllocation(_)).Times(0); |
| 206 | |
| 207 | payload_router.OnBitrateAllocationUpdated(bitrate); |
| 208 | } |
| 209 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 210 | TEST(PayloadRouterTest, SvcTargetBitrate) { |
| 211 | NiceMock<MockRtpRtcp> rtp_1; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 212 | std::vector<RtpRtcp*> modules = {&rtp_1}; |
| 213 | PayloadRouter payload_router(modules, {kSsrc1}, kPayloadType, {}); |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 214 | payload_router.SetActive(true); |
| 215 | |
| 216 | BitrateAllocation bitrate; |
| 217 | bitrate.SetBitrate(0, 0, 10000); |
| 218 | bitrate.SetBitrate(0, 1, 20000); |
| 219 | bitrate.SetBitrate(1, 0, 40000); |
| 220 | bitrate.SetBitrate(1, 1, 80000); |
| 221 | |
| 222 | EXPECT_CALL(rtp_1, SetVideoBitrateAllocation(bitrate)).Times(1); |
| 223 | |
| 224 | payload_router.OnBitrateAllocationUpdated(bitrate); |
| 225 | } |
| 226 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 227 | TEST(PayloadRouterTest, InfoMappedToRtpVideoHeader_Vp8) { |
| 228 | NiceMock<MockRtpRtcp> rtp1; |
| 229 | NiceMock<MockRtpRtcp> rtp2; |
| 230 | std::vector<RtpRtcp*> modules = {&rtp1, &rtp2}; |
| 231 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {}); |
| 232 | payload_router.SetActive(true); |
| 233 | |
| 234 | EncodedImage encoded_image; |
| 235 | encoded_image.rotation_ = kVideoRotation_90; |
| 236 | encoded_image.content_type_ = VideoContentType::SCREENSHARE; |
| 237 | |
| 238 | CodecSpecificInfo codec_info; |
| 239 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 240 | codec_info.codecType = kVideoCodecVP8; |
| 241 | codec_info.codecSpecific.VP8.simulcastIdx = 1; |
| 242 | codec_info.codecSpecific.VP8.pictureId = kPictureId; |
| 243 | codec_info.codecSpecific.VP8.temporalIdx = kTemporalIdx; |
| 244 | codec_info.codecSpecific.VP8.tl0PicIdx = kTl0PicIdx; |
| 245 | codec_info.codecSpecific.VP8.keyIdx = kNoKeyIdx; |
| 246 | codec_info.codecSpecific.VP8.layerSync = true; |
| 247 | codec_info.codecSpecific.VP8.nonReference = true; |
| 248 | |
| 249 | EXPECT_CALL(rtp2, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 250 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 251 | Unused, const RTPVideoHeader* header, Unused) { |
| 252 | EXPECT_EQ(kVideoRotation_90, header->rotation); |
| 253 | EXPECT_EQ(VideoContentType::SCREENSHARE, header->content_type); |
| 254 | EXPECT_EQ(1, header->simulcastIdx); |
| 255 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
| 256 | EXPECT_EQ(kPictureId, header->codecHeader.VP8.pictureId); |
| 257 | EXPECT_EQ(kTemporalIdx, header->codecHeader.VP8.temporalIdx); |
| 258 | EXPECT_EQ(kTl0PicIdx, header->codecHeader.VP8.tl0PicIdx); |
| 259 | EXPECT_EQ(kNoKeyIdx, header->codecHeader.VP8.keyIdx); |
| 260 | EXPECT_TRUE(header->codecHeader.VP8.layerSync); |
| 261 | EXPECT_TRUE(header->codecHeader.VP8.nonReference); |
| 262 | return true; |
| 263 | })); |
| 264 | |
| 265 | EXPECT_EQ( |
| 266 | EncodedImageCallback::Result::OK, |
| 267 | payload_router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
| 268 | } |
| 269 | |
| 270 | TEST(PayloadRouterTest, InfoMappedToRtpVideoHeader_H264) { |
| 271 | NiceMock<MockRtpRtcp> rtp1; |
| 272 | std::vector<RtpRtcp*> modules = {&rtp1}; |
| 273 | PayloadRouter payload_router(modules, {kSsrc1}, kPayloadType, {}); |
| 274 | payload_router.SetActive(true); |
| 275 | |
| 276 | EncodedImage encoded_image; |
| 277 | CodecSpecificInfo codec_info; |
| 278 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 279 | codec_info.codecType = kVideoCodecH264; |
| 280 | codec_info.codecSpecific.H264.packetization_mode = |
| 281 | H264PacketizationMode::SingleNalUnit; |
| 282 | |
| 283 | EXPECT_CALL(rtp1, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 284 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 285 | Unused, const RTPVideoHeader* header, Unused) { |
| 286 | EXPECT_EQ(0, header->simulcastIdx); |
| 287 | EXPECT_EQ(kRtpVideoH264, header->codec); |
| 288 | EXPECT_EQ(H264PacketizationMode::SingleNalUnit, |
| 289 | header->codecHeader.H264.packetization_mode); |
| 290 | return true; |
| 291 | })); |
| 292 | |
| 293 | EXPECT_EQ( |
| 294 | EncodedImageCallback::Result::OK, |
| 295 | payload_router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
| 296 | } |
| 297 | |
| 298 | TEST(PayloadRouterTest, CreateWithNoPreviousStates) { |
| 299 | NiceMock<MockRtpRtcp> rtp1; |
| 300 | NiceMock<MockRtpRtcp> rtp2; |
| 301 | std::vector<RtpRtcp*> modules = {&rtp1, &rtp2}; |
| 302 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {}); |
| 303 | payload_router.SetActive(true); |
| 304 | |
| 305 | std::map<uint32_t, RtpPayloadState> initial_states = |
| 306 | payload_router.GetRtpPayloadStates(); |
| 307 | EXPECT_EQ(2u, initial_states.size()); |
| 308 | EXPECT_NE(initial_states.find(kSsrc1), initial_states.end()); |
| 309 | EXPECT_NE(initial_states.find(kSsrc2), initial_states.end()); |
| 310 | } |
| 311 | |
| 312 | TEST(PayloadRouterTest, CreateWithPreviousStates) { |
| 313 | RtpPayloadState state1; |
| 314 | state1.picture_id = kInitialPictureId1; |
| 315 | RtpPayloadState state2; |
| 316 | state2.picture_id = kInitialPictureId2; |
| 317 | std::map<uint32_t, RtpPayloadState> states = {{kSsrc1, state1}, |
| 318 | {kSsrc2, state2}}; |
| 319 | |
| 320 | NiceMock<MockRtpRtcp> rtp1; |
| 321 | NiceMock<MockRtpRtcp> rtp2; |
| 322 | std::vector<RtpRtcp*> modules = {&rtp1, &rtp2}; |
| 323 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, states); |
| 324 | payload_router.SetActive(true); |
| 325 | |
| 326 | std::map<uint32_t, RtpPayloadState> initial_states = |
| 327 | payload_router.GetRtpPayloadStates(); |
| 328 | EXPECT_EQ(2u, initial_states.size()); |
| 329 | EXPECT_EQ(kInitialPictureId1, initial_states[kSsrc1].picture_id); |
| 330 | EXPECT_EQ(kInitialPictureId2, initial_states[kSsrc2].picture_id); |
| 331 | } |
| 332 | |
| 333 | class PayloadRouterTest : public ::testing::Test { |
| 334 | public: |
| 335 | explicit PayloadRouterTest(const std::string& field_trials) |
| 336 | : override_field_trials_(field_trials) {} |
| 337 | virtual ~PayloadRouterTest() {} |
| 338 | |
| 339 | protected: |
| 340 | virtual void SetUp() { memset(&codec_info_, 0, sizeof(CodecSpecificInfo)); } |
| 341 | |
| 342 | test::ScopedFieldTrials override_field_trials_; |
| 343 | EncodedImage image_; |
| 344 | CodecSpecificInfo codec_info_; |
| 345 | }; |
| 346 | |
| 347 | class TestWithForcedFallbackDisabled : public PayloadRouterTest { |
| 348 | public: |
| 349 | TestWithForcedFallbackDisabled() |
| 350 | : PayloadRouterTest("WebRTC-VP8-Forced-Fallback-Encoder/Disabled/") {} |
| 351 | }; |
| 352 | |
| 353 | class TestWithForcedFallbackEnabled : public PayloadRouterTest { |
| 354 | public: |
| 355 | TestWithForcedFallbackEnabled() |
| 356 | : PayloadRouterTest( |
| 357 | "WebRTC-VP8-Forced-Fallback-Encoder/Enabled-1,2,3,4/") {} |
| 358 | }; |
| 359 | |
| 360 | TEST_F(TestWithForcedFallbackDisabled, PictureIdIsNotChangedForVp8) { |
| 361 | NiceMock<MockRtpRtcp> rtp; |
| 362 | std::vector<RtpRtcp*> modules = {&rtp}; |
| 363 | PayloadRouter router(modules, {kSsrc1}, kPayloadType, {}); |
| 364 | router.SetActive(true); |
| 365 | |
| 366 | codec_info_.codecType = kVideoCodecVP8; |
| 367 | codec_info_.codecSpecific.VP8.pictureId = kPictureId; |
| 368 | |
| 369 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 370 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 371 | Unused, const RTPVideoHeader* header, Unused) { |
| 372 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
| 373 | EXPECT_EQ(kPictureId, header->codecHeader.VP8.pictureId); |
| 374 | return true; |
| 375 | })); |
| 376 | |
| 377 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 378 | router.OnEncodedImage(image_, &codec_info_, nullptr).error); |
| 379 | } |
| 380 | |
| 381 | TEST_F(TestWithForcedFallbackEnabled, PictureIdIsSetForVp8) { |
| 382 | RtpPayloadState state1; |
| 383 | state1.picture_id = kInitialPictureId1; |
| 384 | RtpPayloadState state2; |
| 385 | state2.picture_id = kInitialPictureId2; |
| 386 | std::map<uint32_t, RtpPayloadState> states = {{kSsrc1, state1}, |
| 387 | {kSsrc2, state2}}; |
| 388 | |
| 389 | NiceMock<MockRtpRtcp> rtp1; |
| 390 | NiceMock<MockRtpRtcp> rtp2; |
| 391 | std::vector<RtpRtcp*> modules = {&rtp1, &rtp2}; |
| 392 | PayloadRouter router(modules, {kSsrc1, kSsrc2}, kPayloadType, states); |
| 393 | router.SetActive(true); |
| 394 | |
| 395 | // OnEncodedImage, simulcastIdx: 0. |
| 396 | codec_info_.codecType = kVideoCodecVP8; |
| 397 | codec_info_.codecSpecific.VP8.pictureId = kPictureId; |
| 398 | codec_info_.codecSpecific.VP8.simulcastIdx = 0; |
| 399 | |
| 400 | EXPECT_CALL(rtp1, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 401 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 402 | Unused, const RTPVideoHeader* header, Unused) { |
| 403 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
| 404 | EXPECT_EQ(kInitialPictureId1, header->codecHeader.VP8.pictureId); |
| 405 | return true; |
| 406 | })); |
| 407 | |
| 408 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 409 | router.OnEncodedImage(image_, &codec_info_, nullptr).error); |
| 410 | |
| 411 | // OnEncodedImage, simulcastIdx: 1. |
| 412 | codec_info_.codecSpecific.VP8.pictureId = kPictureId; |
| 413 | codec_info_.codecSpecific.VP8.simulcastIdx = 1; |
| 414 | |
| 415 | EXPECT_CALL(rtp2, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 416 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 417 | Unused, const RTPVideoHeader* header, Unused) { |
| 418 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
| 419 | EXPECT_EQ(kInitialPictureId2, header->codecHeader.VP8.pictureId); |
| 420 | return true; |
| 421 | })); |
| 422 | |
| 423 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 424 | router.OnEncodedImage(image_, &codec_info_, nullptr).error); |
| 425 | |
| 426 | // State should hold next picture id to use. |
| 427 | states = router.GetRtpPayloadStates(); |
| 428 | EXPECT_EQ(2u, states.size()); |
| 429 | EXPECT_EQ(kInitialPictureId1 + 1, states[kSsrc1].picture_id); |
| 430 | EXPECT_EQ(kInitialPictureId2 + 1, states[kSsrc2].picture_id); |
| 431 | } |
| 432 | |
| 433 | TEST_F(TestWithForcedFallbackEnabled, PictureIdWraps) { |
| 434 | RtpPayloadState state1; |
| 435 | state1.picture_id = kMaxTwoBytePictureId; |
| 436 | |
| 437 | NiceMock<MockRtpRtcp> rtp; |
| 438 | std::vector<RtpRtcp*> modules = {&rtp}; |
| 439 | PayloadRouter router(modules, {kSsrc1}, kPayloadType, {{kSsrc1, state1}}); |
| 440 | router.SetActive(true); |
| 441 | |
| 442 | codec_info_.codecType = kVideoCodecVP8; |
| 443 | codec_info_.codecSpecific.VP8.pictureId = kPictureId; |
| 444 | |
| 445 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 446 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 447 | Unused, const RTPVideoHeader* header, Unused) { |
| 448 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
| 449 | EXPECT_EQ(kMaxTwoBytePictureId, header->codecHeader.VP8.pictureId); |
| 450 | return true; |
| 451 | })); |
| 452 | |
| 453 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 454 | router.OnEncodedImage(image_, &codec_info_, nullptr).error); |
| 455 | |
| 456 | // State should hold next picture id to use. |
| 457 | std::map<uint32_t, RtpPayloadState> states = router.GetRtpPayloadStates(); |
| 458 | EXPECT_EQ(1u, states.size()); |
| 459 | EXPECT_EQ(0, states[kSsrc1].picture_id); // Wrapped. |
| 460 | } |
| 461 | |
| 462 | TEST_F(TestWithForcedFallbackEnabled, PictureIdIsNotSetIfNoPictureId) { |
| 463 | NiceMock<MockRtpRtcp> rtp; |
| 464 | std::vector<RtpRtcp*> modules = {&rtp}; |
| 465 | PayloadRouter router(modules, {kSsrc1}, kPayloadType, {}); |
| 466 | router.SetActive(true); |
| 467 | |
| 468 | codec_info_.codecType = kVideoCodecVP8; |
| 469 | codec_info_.codecSpecific.VP8.pictureId = kNoPictureId; |
| 470 | |
| 471 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 472 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 473 | Unused, const RTPVideoHeader* header, Unused) { |
| 474 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
| 475 | EXPECT_EQ(kNoPictureId, header->codecHeader.VP8.pictureId); |
| 476 | return true; |
| 477 | })); |
| 478 | |
| 479 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 480 | router.OnEncodedImage(image_, &codec_info_, nullptr).error); |
| 481 | } |
| 482 | |
| 483 | TEST_F(TestWithForcedFallbackEnabled, PictureIdIsNotSetForVp9) { |
| 484 | NiceMock<MockRtpRtcp> rtp; |
| 485 | std::vector<RtpRtcp*> modules = {&rtp}; |
| 486 | PayloadRouter router(modules, {kSsrc1}, kPayloadType, {}); |
| 487 | router.SetActive(true); |
| 488 | |
| 489 | codec_info_.codecType = kVideoCodecVP9; |
| 490 | codec_info_.codecSpecific.VP9.picture_id = kPictureId; |
| 491 | |
| 492 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 493 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 494 | Unused, const RTPVideoHeader* header, Unused) { |
| 495 | EXPECT_EQ(kRtpVideoVp9, header->codec); |
| 496 | EXPECT_EQ(kPictureId, header->codecHeader.VP9.picture_id); |
| 497 | return true; |
| 498 | })); |
| 499 | |
| 500 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 501 | router.OnEncodedImage(image_, &codec_info_, nullptr).error); |
| 502 | } |
| 503 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 504 | } // namespace webrtc |