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; |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 35 | const uint32_t kSsrc3 = 34567; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 36 | const int16_t kPictureId = 123; |
| 37 | const int16_t kTl0PicIdx = 20; |
| 38 | const uint8_t kTemporalIdx = 1; |
| 39 | const int16_t kInitialPictureId1 = 222; |
| 40 | const int16_t kInitialPictureId2 = 44; |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 41 | const int16_t kInitialTl0PicIdx1 = 99; |
| 42 | const int16_t kInitialTl0PicIdx2 = 199; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 43 | } // namespace |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 44 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 45 | TEST(PayloadRouterTest, SendOnOneModule) { |
perkj | bc75d97 | 2016-05-02 06:31:25 -0700 | [diff] [blame] | 46 | NiceMock<MockRtpRtcp> rtp; |
Peter Boström | 404686a | 2016-02-11 23:37:26 +0100 | [diff] [blame] | 47 | std::vector<RtpRtcp*> modules(1, &rtp); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 48 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 49 | uint8_t payload = 'a'; |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 50 | EncodedImage encoded_image; |
| 51 | encoded_image._timeStamp = 1; |
| 52 | encoded_image.capture_time_ms_ = 2; |
| 53 | encoded_image._frameType = kVideoFrameKey; |
| 54 | encoded_image._buffer = &payload; |
| 55 | encoded_image._length = 1; |
| 56 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 57 | PayloadRouter payload_router(modules, {kSsrc1}, kPayloadType, {}); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 58 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 59 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 60 | encoded_image._timeStamp, |
| 61 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 62 | encoded_image._length, nullptr, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 63 | .Times(0); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 64 | EXPECT_NE( |
| 65 | EncodedImageCallback::Result::OK, |
| 66 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 67 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 68 | payload_router.SetActive(true); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 69 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 70 | encoded_image._timeStamp, |
| 71 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 72 | encoded_image._length, nullptr, _, _)) |
sergeyu | 7b9feee | 2016-11-17 16:16:14 -0800 | [diff] [blame] | 73 | .Times(1) |
| 74 | .WillOnce(Return(true)); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 75 | EXPECT_CALL(rtp, Sending()).WillOnce(Return(true)); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 76 | EXPECT_EQ( |
| 77 | EncodedImageCallback::Result::OK, |
| 78 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 79 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 80 | payload_router.SetActive(false); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 81 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 82 | encoded_image._timeStamp, |
| 83 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 84 | encoded_image._length, nullptr, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 85 | .Times(0); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 86 | EXPECT_NE( |
| 87 | EncodedImageCallback::Result::OK, |
| 88 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 89 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 90 | payload_router.SetActive(true); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 91 | EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 92 | encoded_image._timeStamp, |
| 93 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 94 | encoded_image._length, nullptr, _, _)) |
sergeyu | 7b9feee | 2016-11-17 16:16:14 -0800 | [diff] [blame] | 95 | .Times(1) |
| 96 | .WillOnce(Return(true)); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 97 | EXPECT_CALL(rtp, Sending()).WillOnce(Return(true)); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 98 | EXPECT_EQ( |
| 99 | EncodedImageCallback::Result::OK, |
| 100 | payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 103 | TEST(PayloadRouterTest, SendSimulcastSetActive) { |
perkj | bc75d97 | 2016-05-02 06:31:25 -0700 | [diff] [blame] | 104 | NiceMock<MockRtpRtcp> rtp_1; |
| 105 | NiceMock<MockRtpRtcp> rtp_2; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 106 | std::vector<RtpRtcp*> modules = {&rtp_1, &rtp_2}; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 107 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 108 | uint8_t payload = 'a'; |
| 109 | EncodedImage encoded_image; |
| 110 | encoded_image._timeStamp = 1; |
| 111 | encoded_image.capture_time_ms_ = 2; |
| 112 | encoded_image._frameType = kVideoFrameKey; |
| 113 | encoded_image._buffer = &payload; |
| 114 | encoded_image._length = 1; |
| 115 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 116 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {}); |
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_1; |
| 119 | memset(&codec_info_1, 0, sizeof(CodecSpecificInfo)); |
| 120 | codec_info_1.codecType = kVideoCodecVP8; |
| 121 | codec_info_1.codecSpecific.VP8.simulcastIdx = 0; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 122 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 123 | payload_router.SetActive(true); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 124 | EXPECT_CALL(rtp_1, Sending()).WillOnce(Return(true)); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 125 | EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 126 | encoded_image._timeStamp, |
| 127 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 128 | encoded_image._length, nullptr, _, _)) |
sergeyu | 7b9feee | 2016-11-17 16:16:14 -0800 | [diff] [blame] | 129 | .Times(1) |
| 130 | .WillOnce(Return(true)); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 131 | EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _)).Times(0); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 132 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 133 | payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr) |
| 134 | .error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 135 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 136 | CodecSpecificInfo codec_info_2; |
| 137 | memset(&codec_info_2, 0, sizeof(CodecSpecificInfo)); |
| 138 | codec_info_2.codecType = kVideoCodecVP8; |
| 139 | codec_info_2.codecSpecific.VP8.simulcastIdx = 1; |
| 140 | |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 141 | EXPECT_CALL(rtp_2, Sending()).WillOnce(Return(true)); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 142 | EXPECT_CALL(rtp_2, SendOutgoingData(encoded_image._frameType, kPayloadType, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 143 | encoded_image._timeStamp, |
| 144 | encoded_image.capture_time_ms_, &payload, |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 145 | encoded_image._length, nullptr, _, _)) |
sergeyu | 7b9feee | 2016-11-17 16:16:14 -0800 | [diff] [blame] | 146 | .Times(1) |
| 147 | .WillOnce(Return(true)); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 148 | EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 149 | .Times(0); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 150 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 151 | payload_router.OnEncodedImage(encoded_image, &codec_info_2, nullptr) |
| 152 | .error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 153 | |
mflodman@webrtc.org | 50e2816 | 2015-02-23 07:45:11 +0000 | [diff] [blame] | 154 | // Inactive. |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 155 | payload_router.SetActive(false); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 156 | EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 157 | .Times(0); |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 158 | EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _)) |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 159 | .Times(0); |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 160 | EXPECT_NE(EncodedImageCallback::Result::OK, |
| 161 | payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr) |
| 162 | .error); |
| 163 | EXPECT_NE(EncodedImageCallback::Result::OK, |
| 164 | payload_router.OnEncodedImage(encoded_image, &codec_info_2, nullptr) |
| 165 | .error); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 168 | // Tests how setting individual rtp modules to active affects the overall |
| 169 | // behavior of the payload router. First sets one module to active and checks |
| 170 | // that outgoing data can be sent on this module, and checks that no data can be |
| 171 | // sent if both modules are inactive. |
| 172 | TEST(PayloadRouterTest, SendSimulcastSetActiveModules) { |
| 173 | NiceMock<MockRtpRtcp> rtp_1; |
| 174 | NiceMock<MockRtpRtcp> rtp_2; |
| 175 | std::vector<RtpRtcp*> modules = {&rtp_1, &rtp_2}; |
| 176 | |
| 177 | uint8_t payload = 'a'; |
| 178 | EncodedImage encoded_image; |
| 179 | encoded_image._timeStamp = 1; |
| 180 | encoded_image.capture_time_ms_ = 2; |
| 181 | encoded_image._frameType = kVideoFrameKey; |
| 182 | encoded_image._buffer = &payload; |
| 183 | encoded_image._length = 1; |
| 184 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {}); |
| 185 | CodecSpecificInfo codec_info_1; |
| 186 | memset(&codec_info_1, 0, sizeof(CodecSpecificInfo)); |
| 187 | codec_info_1.codecType = kVideoCodecVP8; |
| 188 | codec_info_1.codecSpecific.VP8.simulcastIdx = 0; |
| 189 | CodecSpecificInfo codec_info_2; |
| 190 | memset(&codec_info_2, 0, sizeof(CodecSpecificInfo)); |
| 191 | codec_info_2.codecType = kVideoCodecVP8; |
| 192 | codec_info_2.codecSpecific.VP8.simulcastIdx = 1; |
| 193 | |
| 194 | // Only setting one stream to active will still set the payload router to |
| 195 | // active and allow sending data on the active stream. |
| 196 | std::vector<bool> active_modules({true, false}); |
| 197 | payload_router.SetActiveModules(active_modules); |
| 198 | |
| 199 | EXPECT_CALL(rtp_1, Sending()).WillOnce(Return(true)); |
| 200 | EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, kPayloadType, |
| 201 | encoded_image._timeStamp, |
| 202 | encoded_image.capture_time_ms_, &payload, |
| 203 | encoded_image._length, nullptr, _, _)) |
| 204 | .Times(1) |
| 205 | .WillOnce(Return(true)); |
| 206 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 207 | payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr) |
| 208 | .error); |
| 209 | |
| 210 | // Setting both streams to inactive will turn the payload router to inactive. |
| 211 | active_modules = {false, false}; |
| 212 | payload_router.SetActiveModules(active_modules); |
| 213 | // An incoming encoded image will not ask the module to send outgoing data |
| 214 | // because the payload router is inactive. |
| 215 | EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _)).Times(0); |
| 216 | EXPECT_CALL(rtp_1, Sending()).Times(0); |
| 217 | EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _)).Times(0); |
| 218 | EXPECT_CALL(rtp_2, Sending()).Times(0); |
| 219 | EXPECT_NE(EncodedImageCallback::Result::OK, |
| 220 | payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr) |
| 221 | .error); |
| 222 | EXPECT_NE(EncodedImageCallback::Result::OK, |
| 223 | payload_router.OnEncodedImage(encoded_image, &codec_info_2, nullptr) |
| 224 | .error); |
| 225 | } |
| 226 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 227 | TEST(PayloadRouterTest, SimulcastTargetBitrate) { |
| 228 | NiceMock<MockRtpRtcp> rtp_1; |
| 229 | NiceMock<MockRtpRtcp> rtp_2; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 230 | std::vector<RtpRtcp*> modules = {&rtp_1, &rtp_2}; |
| 231 | |
| 232 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {}); |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 233 | payload_router.SetActive(true); |
| 234 | |
| 235 | BitrateAllocation bitrate; |
| 236 | bitrate.SetBitrate(0, 0, 10000); |
| 237 | bitrate.SetBitrate(0, 1, 20000); |
| 238 | bitrate.SetBitrate(1, 0, 40000); |
| 239 | bitrate.SetBitrate(1, 1, 80000); |
| 240 | |
| 241 | BitrateAllocation layer0_bitrate; |
| 242 | layer0_bitrate.SetBitrate(0, 0, 10000); |
| 243 | layer0_bitrate.SetBitrate(0, 1, 20000); |
| 244 | |
| 245 | BitrateAllocation layer1_bitrate; |
| 246 | layer1_bitrate.SetBitrate(0, 0, 40000); |
| 247 | layer1_bitrate.SetBitrate(0, 1, 80000); |
| 248 | |
| 249 | EXPECT_CALL(rtp_1, SetVideoBitrateAllocation(layer0_bitrate)).Times(1); |
| 250 | EXPECT_CALL(rtp_2, SetVideoBitrateAllocation(layer1_bitrate)).Times(1); |
| 251 | |
| 252 | payload_router.OnBitrateAllocationUpdated(bitrate); |
| 253 | } |
| 254 | |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 255 | // If the middle of three streams is inactive the first and last streams should |
| 256 | // be asked to send the TargetBitrate message. |
sprang | d0fc37a | 2017-06-22 05:40:25 -0700 | [diff] [blame] | 257 | TEST(PayloadRouterTest, SimulcastTargetBitrateWithInactiveStream) { |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 258 | // Set up three active rtp modules. |
sprang | d0fc37a | 2017-06-22 05:40:25 -0700 | [diff] [blame] | 259 | NiceMock<MockRtpRtcp> rtp_1; |
| 260 | NiceMock<MockRtpRtcp> rtp_2; |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 261 | NiceMock<MockRtpRtcp> rtp_3; |
| 262 | std::vector<RtpRtcp*> modules = {&rtp_1, &rtp_2, &rtp_3}; |
| 263 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2, kSsrc3}, kPayloadType, |
| 264 | {}); |
sprang | d0fc37a | 2017-06-22 05:40:25 -0700 | [diff] [blame] | 265 | payload_router.SetActive(true); |
| 266 | |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 267 | // Create bitrate allocation with bitrate only for the first and third stream. |
sprang | d0fc37a | 2017-06-22 05:40:25 -0700 | [diff] [blame] | 268 | BitrateAllocation bitrate; |
| 269 | bitrate.SetBitrate(0, 0, 10000); |
| 270 | bitrate.SetBitrate(0, 1, 20000); |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 271 | bitrate.SetBitrate(2, 0, 40000); |
| 272 | bitrate.SetBitrate(2, 1, 80000); |
sprang | d0fc37a | 2017-06-22 05:40:25 -0700 | [diff] [blame] | 273 | |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 274 | BitrateAllocation layer0_bitrate; |
| 275 | layer0_bitrate.SetBitrate(0, 0, 10000); |
| 276 | layer0_bitrate.SetBitrate(0, 1, 20000); |
| 277 | |
| 278 | BitrateAllocation layer2_bitrate; |
| 279 | layer2_bitrate.SetBitrate(0, 0, 40000); |
| 280 | layer2_bitrate.SetBitrate(0, 1, 80000); |
| 281 | |
| 282 | // Expect the first and third rtp module to be asked to send a TargetBitrate |
sprang | d0fc37a | 2017-06-22 05:40:25 -0700 | [diff] [blame] | 283 | // message. (No target bitrate with 0bps sent from the second one.) |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 284 | EXPECT_CALL(rtp_1, SetVideoBitrateAllocation(layer0_bitrate)).Times(1); |
sprang | d0fc37a | 2017-06-22 05:40:25 -0700 | [diff] [blame] | 285 | EXPECT_CALL(rtp_2, SetVideoBitrateAllocation(_)).Times(0); |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 286 | EXPECT_CALL(rtp_3, SetVideoBitrateAllocation(layer2_bitrate)).Times(1); |
sprang | d0fc37a | 2017-06-22 05:40:25 -0700 | [diff] [blame] | 287 | |
| 288 | payload_router.OnBitrateAllocationUpdated(bitrate); |
| 289 | } |
| 290 | |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 291 | TEST(PayloadRouterTest, SvcTargetBitrate) { |
| 292 | NiceMock<MockRtpRtcp> rtp_1; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 293 | std::vector<RtpRtcp*> modules = {&rtp_1}; |
| 294 | PayloadRouter payload_router(modules, {kSsrc1}, kPayloadType, {}); |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 295 | payload_router.SetActive(true); |
| 296 | |
| 297 | BitrateAllocation bitrate; |
| 298 | bitrate.SetBitrate(0, 0, 10000); |
| 299 | bitrate.SetBitrate(0, 1, 20000); |
| 300 | bitrate.SetBitrate(1, 0, 40000); |
| 301 | bitrate.SetBitrate(1, 1, 80000); |
| 302 | |
| 303 | EXPECT_CALL(rtp_1, SetVideoBitrateAllocation(bitrate)).Times(1); |
| 304 | |
| 305 | payload_router.OnBitrateAllocationUpdated(bitrate); |
| 306 | } |
| 307 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 308 | TEST(PayloadRouterTest, InfoMappedToRtpVideoHeader_Vp8) { |
| 309 | NiceMock<MockRtpRtcp> rtp1; |
| 310 | NiceMock<MockRtpRtcp> rtp2; |
| 311 | std::vector<RtpRtcp*> modules = {&rtp1, &rtp2}; |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 312 | RtpPayloadState state2; |
| 313 | state2.picture_id = kPictureId; |
| 314 | state2.tl0_pic_idx = kTl0PicIdx; |
| 315 | std::map<uint32_t, RtpPayloadState> states = {{kSsrc2, state2}}; |
| 316 | |
| 317 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, states); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 318 | payload_router.SetActive(true); |
| 319 | |
| 320 | EncodedImage encoded_image; |
| 321 | encoded_image.rotation_ = kVideoRotation_90; |
| 322 | encoded_image.content_type_ = VideoContentType::SCREENSHARE; |
| 323 | |
| 324 | CodecSpecificInfo codec_info; |
| 325 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 326 | codec_info.codecType = kVideoCodecVP8; |
| 327 | codec_info.codecSpecific.VP8.simulcastIdx = 1; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 328 | codec_info.codecSpecific.VP8.temporalIdx = kTemporalIdx; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 329 | codec_info.codecSpecific.VP8.keyIdx = kNoKeyIdx; |
| 330 | codec_info.codecSpecific.VP8.layerSync = true; |
| 331 | codec_info.codecSpecific.VP8.nonReference = true; |
| 332 | |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 333 | EXPECT_CALL(rtp2, Sending()).WillOnce(Return(true)); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 334 | EXPECT_CALL(rtp2, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 335 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 336 | Unused, const RTPVideoHeader* header, Unused) { |
| 337 | EXPECT_EQ(kVideoRotation_90, header->rotation); |
| 338 | EXPECT_EQ(VideoContentType::SCREENSHARE, header->content_type); |
| 339 | EXPECT_EQ(1, header->simulcastIdx); |
| 340 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 341 | EXPECT_EQ(kPictureId + 1, header->codecHeader.VP8.pictureId); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 342 | EXPECT_EQ(kTemporalIdx, header->codecHeader.VP8.temporalIdx); |
| 343 | EXPECT_EQ(kTl0PicIdx, header->codecHeader.VP8.tl0PicIdx); |
| 344 | EXPECT_EQ(kNoKeyIdx, header->codecHeader.VP8.keyIdx); |
| 345 | EXPECT_TRUE(header->codecHeader.VP8.layerSync); |
| 346 | EXPECT_TRUE(header->codecHeader.VP8.nonReference); |
| 347 | return true; |
| 348 | })); |
| 349 | |
| 350 | EXPECT_EQ( |
| 351 | EncodedImageCallback::Result::OK, |
| 352 | payload_router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
| 353 | } |
| 354 | |
Sergey Silkin | 2a1f183 | 2018-04-04 11:45:41 +0200 | [diff] [blame] | 355 | TEST(PayloadRouterTest, InfoMappedToRtpVideoHeader_Vp9) { |
| 356 | RtpPayloadState state; |
| 357 | state.picture_id = kPictureId; |
| 358 | state.tl0_pic_idx = kTl0PicIdx; |
| 359 | std::map<uint32_t, RtpPayloadState> states = {{kSsrc1, state}}; |
| 360 | |
| 361 | NiceMock<MockRtpRtcp> rtp; |
| 362 | std::vector<RtpRtcp*> modules = {&rtp}; |
| 363 | PayloadRouter router(modules, {kSsrc1}, kPayloadType, states); |
| 364 | router.SetActive(true); |
| 365 | |
| 366 | EncodedImage encoded_image; |
| 367 | encoded_image.rotation_ = kVideoRotation_90; |
| 368 | encoded_image.content_type_ = VideoContentType::SCREENSHARE; |
| 369 | |
| 370 | CodecSpecificInfo codec_info; |
| 371 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 372 | codec_info.codecType = kVideoCodecVP9; |
| 373 | codec_info.codecSpecific.VP9.num_spatial_layers = 3; |
| 374 | codec_info.codecSpecific.VP9.first_frame_in_picture = true; |
| 375 | codec_info.codecSpecific.VP9.spatial_idx = 0; |
| 376 | codec_info.codecSpecific.VP9.temporal_idx = 2; |
| 377 | codec_info.codecSpecific.VP9.end_of_superframe = false; |
| 378 | |
| 379 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 380 | .WillOnce( |
| 381 | Invoke([&codec_info](Unused, Unused, Unused, Unused, Unused, Unused, |
| 382 | Unused, const RTPVideoHeader* header, Unused) { |
| 383 | EXPECT_EQ(kVideoRotation_90, header->rotation); |
| 384 | EXPECT_EQ(VideoContentType::SCREENSHARE, header->content_type); |
| 385 | EXPECT_EQ(kRtpVideoVp9, header->codec); |
| 386 | EXPECT_EQ(kPictureId + 1, header->codecHeader.VP9.picture_id); |
| 387 | EXPECT_EQ(kTl0PicIdx, header->codecHeader.VP9.tl0_pic_idx); |
| 388 | EXPECT_EQ(header->codecHeader.VP9.temporal_idx, |
| 389 | codec_info.codecSpecific.VP9.temporal_idx); |
| 390 | EXPECT_EQ(header->codecHeader.VP9.spatial_idx, |
| 391 | codec_info.codecSpecific.VP9.spatial_idx); |
| 392 | EXPECT_EQ(header->codecHeader.VP9.num_spatial_layers, |
| 393 | codec_info.codecSpecific.VP9.num_spatial_layers); |
| 394 | EXPECT_EQ(header->codecHeader.VP9.end_of_superframe, |
| 395 | codec_info.codecSpecific.VP9.end_of_superframe); |
| 396 | return true; |
| 397 | })); |
| 398 | EXPECT_CALL(rtp, Sending()).WillOnce(Return(true)); |
| 399 | |
| 400 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 401 | router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
| 402 | |
| 403 | // Next spatial layer. |
| 404 | codec_info.codecSpecific.VP9.first_frame_in_picture = false; |
| 405 | codec_info.codecSpecific.VP9.spatial_idx += 1; |
| 406 | codec_info.codecSpecific.VP9.end_of_superframe = true; |
| 407 | |
| 408 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 409 | .WillOnce( |
| 410 | Invoke([&codec_info](Unused, Unused, Unused, Unused, Unused, Unused, |
| 411 | Unused, const RTPVideoHeader* header, Unused) { |
| 412 | EXPECT_EQ(kVideoRotation_90, header->rotation); |
| 413 | EXPECT_EQ(VideoContentType::SCREENSHARE, header->content_type); |
| 414 | EXPECT_EQ(kRtpVideoVp9, header->codec); |
| 415 | EXPECT_EQ(kPictureId + 1, header->codecHeader.VP9.picture_id); |
| 416 | EXPECT_EQ(kTl0PicIdx, header->codecHeader.VP9.tl0_pic_idx); |
| 417 | EXPECT_EQ(header->codecHeader.VP9.temporal_idx, |
| 418 | codec_info.codecSpecific.VP9.temporal_idx); |
| 419 | EXPECT_EQ(header->codecHeader.VP9.spatial_idx, |
| 420 | codec_info.codecSpecific.VP9.spatial_idx); |
| 421 | EXPECT_EQ(header->codecHeader.VP9.num_spatial_layers, |
| 422 | codec_info.codecSpecific.VP9.num_spatial_layers); |
| 423 | EXPECT_EQ(header->codecHeader.VP9.end_of_superframe, |
| 424 | codec_info.codecSpecific.VP9.end_of_superframe); |
| 425 | return true; |
| 426 | })); |
| 427 | EXPECT_CALL(rtp, Sending()).WillOnce(Return(true)); |
| 428 | |
| 429 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 430 | router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
| 431 | } |
| 432 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 433 | TEST(PayloadRouterTest, InfoMappedToRtpVideoHeader_H264) { |
| 434 | NiceMock<MockRtpRtcp> rtp1; |
| 435 | std::vector<RtpRtcp*> modules = {&rtp1}; |
| 436 | PayloadRouter payload_router(modules, {kSsrc1}, kPayloadType, {}); |
| 437 | payload_router.SetActive(true); |
| 438 | |
| 439 | EncodedImage encoded_image; |
| 440 | CodecSpecificInfo codec_info; |
| 441 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 442 | codec_info.codecType = kVideoCodecH264; |
| 443 | codec_info.codecSpecific.H264.packetization_mode = |
| 444 | H264PacketizationMode::SingleNalUnit; |
| 445 | |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 446 | EXPECT_CALL(rtp1, Sending()).WillOnce(Return(true)); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 447 | EXPECT_CALL(rtp1, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 448 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 449 | Unused, const RTPVideoHeader* header, Unused) { |
| 450 | EXPECT_EQ(0, header->simulcastIdx); |
| 451 | EXPECT_EQ(kRtpVideoH264, header->codec); |
| 452 | EXPECT_EQ(H264PacketizationMode::SingleNalUnit, |
| 453 | header->codecHeader.H264.packetization_mode); |
| 454 | return true; |
| 455 | })); |
| 456 | |
| 457 | EXPECT_EQ( |
| 458 | EncodedImageCallback::Result::OK, |
| 459 | payload_router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
| 460 | } |
| 461 | |
| 462 | TEST(PayloadRouterTest, CreateWithNoPreviousStates) { |
| 463 | NiceMock<MockRtpRtcp> rtp1; |
| 464 | NiceMock<MockRtpRtcp> rtp2; |
| 465 | std::vector<RtpRtcp*> modules = {&rtp1, &rtp2}; |
| 466 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {}); |
| 467 | payload_router.SetActive(true); |
| 468 | |
| 469 | std::map<uint32_t, RtpPayloadState> initial_states = |
| 470 | payload_router.GetRtpPayloadStates(); |
| 471 | EXPECT_EQ(2u, initial_states.size()); |
| 472 | EXPECT_NE(initial_states.find(kSsrc1), initial_states.end()); |
| 473 | EXPECT_NE(initial_states.find(kSsrc2), initial_states.end()); |
| 474 | } |
| 475 | |
| 476 | TEST(PayloadRouterTest, CreateWithPreviousStates) { |
| 477 | RtpPayloadState state1; |
| 478 | state1.picture_id = kInitialPictureId1; |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 479 | state1.tl0_pic_idx = kInitialTl0PicIdx1; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 480 | RtpPayloadState state2; |
| 481 | state2.picture_id = kInitialPictureId2; |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 482 | state2.tl0_pic_idx = kInitialTl0PicIdx2; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 483 | std::map<uint32_t, RtpPayloadState> states = {{kSsrc1, state1}, |
| 484 | {kSsrc2, state2}}; |
| 485 | |
| 486 | NiceMock<MockRtpRtcp> rtp1; |
| 487 | NiceMock<MockRtpRtcp> rtp2; |
| 488 | std::vector<RtpRtcp*> modules = {&rtp1, &rtp2}; |
| 489 | PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, states); |
| 490 | payload_router.SetActive(true); |
| 491 | |
| 492 | std::map<uint32_t, RtpPayloadState> initial_states = |
| 493 | payload_router.GetRtpPayloadStates(); |
| 494 | EXPECT_EQ(2u, initial_states.size()); |
| 495 | EXPECT_EQ(kInitialPictureId1, initial_states[kSsrc1].picture_id); |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 496 | EXPECT_EQ(kInitialTl0PicIdx1, initial_states[kSsrc1].tl0_pic_idx); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 497 | EXPECT_EQ(kInitialPictureId2, initial_states[kSsrc2].picture_id); |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 498 | EXPECT_EQ(kInitialTl0PicIdx2, initial_states[kSsrc2].tl0_pic_idx); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 499 | } |
| 500 | |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 501 | TEST(PayloadRouterTest, PictureIdIsSetForVp8) { |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 502 | RtpPayloadState state1; |
| 503 | state1.picture_id = kInitialPictureId1; |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 504 | state1.tl0_pic_idx = kInitialTl0PicIdx1; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 505 | RtpPayloadState state2; |
| 506 | state2.picture_id = kInitialPictureId2; |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 507 | state2.tl0_pic_idx = kInitialTl0PicIdx2; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 508 | std::map<uint32_t, RtpPayloadState> states = {{kSsrc1, state1}, |
| 509 | {kSsrc2, state2}}; |
| 510 | |
| 511 | NiceMock<MockRtpRtcp> rtp1; |
| 512 | NiceMock<MockRtpRtcp> rtp2; |
| 513 | std::vector<RtpRtcp*> modules = {&rtp1, &rtp2}; |
| 514 | PayloadRouter router(modules, {kSsrc1, kSsrc2}, kPayloadType, states); |
| 515 | router.SetActive(true); |
| 516 | |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 517 | EncodedImage encoded_image; |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 518 | // Modules are sending for this test. |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 519 | // OnEncodedImage, simulcastIdx: 0. |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 520 | CodecSpecificInfo codec_info; |
| 521 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 522 | codec_info.codecType = kVideoCodecVP8; |
| 523 | codec_info.codecSpecific.VP8.simulcastIdx = 0; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 524 | |
| 525 | EXPECT_CALL(rtp1, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 526 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 527 | Unused, const RTPVideoHeader* header, Unused) { |
| 528 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 529 | EXPECT_EQ(kInitialPictureId1 + 1, header->codecHeader.VP8.pictureId); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 530 | return true; |
| 531 | })); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 532 | EXPECT_CALL(rtp1, Sending()).WillOnce(Return(true)); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 533 | |
| 534 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 535 | router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 536 | |
| 537 | // OnEncodedImage, simulcastIdx: 1. |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 538 | codec_info.codecSpecific.VP8.simulcastIdx = 1; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 539 | |
| 540 | EXPECT_CALL(rtp2, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 541 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 542 | Unused, const RTPVideoHeader* header, Unused) { |
| 543 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 544 | EXPECT_EQ(kInitialPictureId2 + 1, header->codecHeader.VP8.pictureId); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 545 | return true; |
| 546 | })); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 547 | EXPECT_CALL(rtp2, Sending()).WillOnce(Return(true)); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 548 | |
| 549 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 550 | router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 551 | |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 552 | // State should hold latest used picture id and tl0_pic_idx. |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 553 | states = router.GetRtpPayloadStates(); |
| 554 | EXPECT_EQ(2u, states.size()); |
| 555 | EXPECT_EQ(kInitialPictureId1 + 1, states[kSsrc1].picture_id); |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 556 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, states[kSsrc1].tl0_pic_idx); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 557 | EXPECT_EQ(kInitialPictureId2 + 1, states[kSsrc2].picture_id); |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 558 | EXPECT_EQ(kInitialTl0PicIdx2 + 1, states[kSsrc2].tl0_pic_idx); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 559 | } |
| 560 | |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 561 | TEST(PayloadRouterTest, PictureIdWraps) { |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 562 | RtpPayloadState state1; |
| 563 | state1.picture_id = kMaxTwoBytePictureId; |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 564 | state1.tl0_pic_idx = kInitialTl0PicIdx1; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 565 | |
| 566 | NiceMock<MockRtpRtcp> rtp; |
| 567 | std::vector<RtpRtcp*> modules = {&rtp}; |
| 568 | PayloadRouter router(modules, {kSsrc1}, kPayloadType, {{kSsrc1, state1}}); |
| 569 | router.SetActive(true); |
| 570 | |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 571 | EncodedImage encoded_image; |
| 572 | CodecSpecificInfo codec_info; |
| 573 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 574 | codec_info.codecType = kVideoCodecVP8; |
| 575 | codec_info.codecSpecific.VP8.temporalIdx = kNoTemporalIdx; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 576 | |
| 577 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 578 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 579 | Unused, const RTPVideoHeader* header, Unused) { |
| 580 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 581 | EXPECT_EQ(0, header->codecHeader.VP8.pictureId); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 582 | return true; |
| 583 | })); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 584 | EXPECT_CALL(rtp, Sending()).WillOnce(Return(true)); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 585 | |
| 586 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 587 | router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 588 | |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 589 | // State should hold latest used picture id and tl0_pic_idx. |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 590 | std::map<uint32_t, RtpPayloadState> states = router.GetRtpPayloadStates(); |
| 591 | EXPECT_EQ(1u, states.size()); |
| 592 | EXPECT_EQ(0, states[kSsrc1].picture_id); // Wrapped. |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 593 | EXPECT_EQ(kInitialTl0PicIdx1, states[kSsrc1].tl0_pic_idx); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 594 | } |
| 595 | |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 596 | TEST(PayloadRouterTest, Tl0PicIdxUpdatedForVp8) { |
| 597 | RtpPayloadState state; |
| 598 | state.picture_id = kInitialPictureId1; |
| 599 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 600 | std::map<uint32_t, RtpPayloadState> states = {{kSsrc1, state}}; |
| 601 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 602 | NiceMock<MockRtpRtcp> rtp; |
| 603 | std::vector<RtpRtcp*> modules = {&rtp}; |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 604 | PayloadRouter router(modules, {kSsrc1}, kPayloadType, states); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 605 | router.SetActive(true); |
| 606 | |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 607 | EncodedImage encoded_image; |
| 608 | // Modules are sending for this test. |
| 609 | // OnEncodedImage, temporalIdx: 1. |
| 610 | CodecSpecificInfo codec_info; |
| 611 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 612 | codec_info.codecType = kVideoCodecVP8; |
| 613 | codec_info.codecSpecific.VP8.temporalIdx = 1; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 614 | |
| 615 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 616 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 617 | Unused, const RTPVideoHeader* header, Unused) { |
| 618 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 619 | EXPECT_EQ(kInitialPictureId1 + 1, header->codecHeader.VP8.pictureId); |
| 620 | EXPECT_EQ(kInitialTl0PicIdx1, header->codecHeader.VP8.tl0PicIdx); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 621 | return true; |
| 622 | })); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 623 | EXPECT_CALL(rtp, Sending()).WillOnce(Return(true)); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 624 | |
| 625 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 626 | router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
| 627 | |
| 628 | // OnEncodedImage, temporalIdx: 0. |
| 629 | codec_info.codecSpecific.VP8.temporalIdx = 0; |
| 630 | |
| 631 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 632 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 633 | Unused, const RTPVideoHeader* header, Unused) { |
| 634 | EXPECT_EQ(kRtpVideoVp8, header->codec); |
| 635 | EXPECT_EQ(kInitialPictureId1 + 2, header->codecHeader.VP8.pictureId); |
| 636 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, header->codecHeader.VP8.tl0PicIdx); |
| 637 | return true; |
| 638 | })); |
| 639 | EXPECT_CALL(rtp, Sending()).WillOnce(Return(true)); |
| 640 | |
| 641 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 642 | router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
| 643 | |
| 644 | // State should hold latest used picture id and tl0_pic_idx. |
| 645 | states = router.GetRtpPayloadStates(); |
| 646 | EXPECT_EQ(1u, states.size()); |
| 647 | EXPECT_EQ(kInitialPictureId1 + 2, states[kSsrc1].picture_id); |
| 648 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, states[kSsrc1].tl0_pic_idx); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 649 | } |
| 650 | |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 651 | TEST(PayloadRouterTest, Tl0PicIdxUpdatedForVp9) { |
| 652 | RtpPayloadState state; |
| 653 | state.picture_id = kInitialPictureId1; |
| 654 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 655 | std::map<uint32_t, RtpPayloadState> states = {{kSsrc1, state}}; |
| 656 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 657 | NiceMock<MockRtpRtcp> rtp; |
| 658 | std::vector<RtpRtcp*> modules = {&rtp}; |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 659 | PayloadRouter router(modules, {kSsrc1}, kPayloadType, states); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 660 | router.SetActive(true); |
| 661 | |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 662 | EncodedImage encoded_image; |
| 663 | // Modules are sending for this test. |
| 664 | // OnEncodedImage, temporalIdx: 1. |
| 665 | CodecSpecificInfo codec_info; |
| 666 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 667 | codec_info.codecType = kVideoCodecVP9; |
| 668 | codec_info.codecSpecific.VP9.temporal_idx = 1; |
| 669 | codec_info.codecSpecific.VP9.first_frame_in_picture = true; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 670 | |
| 671 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 672 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 673 | Unused, const RTPVideoHeader* header, Unused) { |
| 674 | EXPECT_EQ(kRtpVideoVp9, header->codec); |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 675 | EXPECT_EQ(kInitialPictureId1 + 1, header->codecHeader.VP9.picture_id); |
| 676 | EXPECT_EQ(kInitialTl0PicIdx1, header->codecHeader.VP9.tl0_pic_idx); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 677 | return true; |
| 678 | })); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 679 | EXPECT_CALL(rtp, Sending()).WillOnce(Return(true)); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 680 | |
| 681 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
Niels Möller | bb894ff | 2018-03-15 12:28:53 +0100 | [diff] [blame] | 682 | router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
| 683 | |
| 684 | // OnEncodedImage, temporalIdx: 0. |
| 685 | codec_info.codecSpecific.VP9.temporal_idx = 0; |
| 686 | |
| 687 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 688 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 689 | Unused, const RTPVideoHeader* header, Unused) { |
| 690 | EXPECT_EQ(kRtpVideoVp9, header->codec); |
| 691 | EXPECT_EQ(kInitialPictureId1 + 2, header->codecHeader.VP9.picture_id); |
| 692 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, header->codecHeader.VP9.tl0_pic_idx); |
| 693 | return true; |
| 694 | })); |
| 695 | EXPECT_CALL(rtp, Sending()).WillOnce(Return(true)); |
| 696 | |
| 697 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 698 | router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
| 699 | |
| 700 | // OnEncodedImage, first_frame_in_picture = false |
| 701 | codec_info.codecSpecific.VP9.first_frame_in_picture = false; |
| 702 | |
| 703 | EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _)) |
| 704 | .WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused, |
| 705 | Unused, const RTPVideoHeader* header, Unused) { |
| 706 | EXPECT_EQ(kRtpVideoVp9, header->codec); |
| 707 | EXPECT_EQ(kInitialPictureId1 + 2, header->codecHeader.VP9.picture_id); |
| 708 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, header->codecHeader.VP9.tl0_pic_idx); |
| 709 | return true; |
| 710 | })); |
| 711 | EXPECT_CALL(rtp, Sending()).WillOnce(Return(true)); |
| 712 | |
| 713 | EXPECT_EQ(EncodedImageCallback::Result::OK, |
| 714 | router.OnEncodedImage(encoded_image, &codec_info, nullptr).error); |
| 715 | |
| 716 | // State should hold latest used picture id and tl0_pic_idx. |
| 717 | states = router.GetRtpPayloadStates(); |
| 718 | EXPECT_EQ(1u, states.size()); |
| 719 | EXPECT_EQ(kInitialPictureId1 + 2, states[kSsrc1].picture_id); |
| 720 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, states[kSsrc1].tl0_pic_idx); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 721 | } |
| 722 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 723 | } // namespace webrtc |