blob: fa5c35d6dbab09b0ed5d4187cfd9f4f42b45c138 [file] [log] [blame]
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +00001/*
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
kwiberg27f982b2016-03-01 11:52:33 -080011#include <memory>
12
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010013#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000014#include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
kjellander02b3d272016-04-20 05:05:54 -070015#include "webrtc/modules/video_coding/include/video_codec_interface.h"
kwibergac9f8762016-09-30 22:29:43 -070016#include "webrtc/test/gmock.h"
17#include "webrtc/test/gtest.h"
Peter Boström7623ce42015-12-09 12:13:30 +010018#include "webrtc/video/payload_router.h"
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000019
20using ::testing::_;
21using ::testing::AnyNumber;
22using ::testing::NiceMock;
23using ::testing::Return;
24
25namespace webrtc {
26
Per83d09102016-04-15 14:59:13 +020027TEST(PayloadRouterTest, SendOnOneModule) {
perkjbc75d972016-05-02 06:31:25 -070028 NiceMock<MockRtpRtcp> rtp;
Peter Boström404686a2016-02-11 23:37:26 +010029 std::vector<RtpRtcp*> modules(1, &rtp);
perkjbc75d972016-05-02 06:31:25 -070030 std::vector<VideoStream> streams(1);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000031
kjellander02b3d272016-04-20 05:05:54 -070032 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.org02270cd2015-02-06 13:10:19 +000042
kjellander02b3d272016-04-20 05:05:54 -070043 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
44 encoded_image._timeStamp,
45 encoded_image.capture_time_ms_, &payload,
Sergey Ulanov525df3f2016-08-02 17:46:41 -070046 encoded_image._length, nullptr, _, _))
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000047 .Times(0);
sergeyuc6812502016-11-03 11:06:38 -070048 EXPECT_NE(
49 EncodedImageCallback::Result::OK,
50 payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000051
Per83d09102016-04-15 14:59:13 +020052 payload_router.set_active(true);
kjellander02b3d272016-04-20 05:05:54 -070053 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
54 encoded_image._timeStamp,
55 encoded_image.capture_time_ms_, &payload,
Sergey Ulanov525df3f2016-08-02 17:46:41 -070056 encoded_image._length, nullptr, _, _))
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000057 .Times(1);
sergeyuc6812502016-11-03 11:06:38 -070058 EXPECT_EQ(
59 EncodedImageCallback::Result::OK,
60 payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000061
Per83d09102016-04-15 14:59:13 +020062 payload_router.set_active(false);
kjellander02b3d272016-04-20 05:05:54 -070063 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
64 encoded_image._timeStamp,
65 encoded_image.capture_time_ms_, &payload,
Sergey Ulanov525df3f2016-08-02 17:46:41 -070066 encoded_image._length, nullptr, _, _))
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000067 .Times(0);
sergeyuc6812502016-11-03 11:06:38 -070068 EXPECT_NE(
69 EncodedImageCallback::Result::OK,
70 payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000071
Per83d09102016-04-15 14:59:13 +020072 payload_router.set_active(true);
kjellander02b3d272016-04-20 05:05:54 -070073 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
74 encoded_image._timeStamp,
75 encoded_image.capture_time_ms_, &payload,
Sergey Ulanov525df3f2016-08-02 17:46:41 -070076 encoded_image._length, nullptr, _, _))
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000077 .Times(1);
sergeyuc6812502016-11-03 11:06:38 -070078 EXPECT_EQ(
79 EncodedImageCallback::Result::OK,
80 payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000081}
82
Per83d09102016-04-15 14:59:13 +020083TEST(PayloadRouterTest, SendSimulcast) {
perkjbc75d972016-05-02 06:31:25 -070084 NiceMock<MockRtpRtcp> rtp_1;
85 NiceMock<MockRtpRtcp> rtp_2;
Peter Boström404686a2016-02-11 23:37:26 +010086 std::vector<RtpRtcp*> modules;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000087 modules.push_back(&rtp_1);
88 modules.push_back(&rtp_2);
perkjbc75d972016-05-02 06:31:25 -070089 std::vector<VideoStream> streams(2);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000090
kjellander02b3d272016-04-20 05:05:54 -070091 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.org02270cd2015-02-06 13:10:19 +0000101
kjellander02b3d272016-04-20 05:05:54 -0700102 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.org02270cd2015-02-06 13:10:19 +0000106
Per83d09102016-04-15 14:59:13 +0200107 payload_router.set_active(true);
kjellander02b3d272016-04-20 05:05:54 -0700108 EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, payload_type,
109 encoded_image._timeStamp,
110 encoded_image.capture_time_ms_, &payload,
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700111 encoded_image._length, nullptr, _, _))
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000112 .Times(1);
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700113 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _)).Times(0);
sergeyuc6812502016-11-03 11:06:38 -0700114 EXPECT_EQ(EncodedImageCallback::Result::OK,
115 payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr)
116 .error);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000117
kjellander02b3d272016-04-20 05:05:54 -0700118 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 Ulanov525df3f2016-08-02 17:46:41 -0700126 encoded_image._length, nullptr, _, _))
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000127 .Times(1);
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700128 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _))
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000129 .Times(0);
sergeyuc6812502016-11-03 11:06:38 -0700130 EXPECT_EQ(EncodedImageCallback::Result::OK,
131 payload_router.OnEncodedImage(encoded_image, &codec_info_2, nullptr)
132 .error);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000133
mflodman@webrtc.org50e28162015-02-23 07:45:11 +0000134 // Inactive.
Per83d09102016-04-15 14:59:13 +0200135 payload_router.set_active(false);
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700136 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _))
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000137 .Times(0);
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700138 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _))
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000139 .Times(0);
sergeyuc6812502016-11-03 11:06:38 -0700140 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.org02270cd2015-02-06 13:10:19 +0000146}
147
Per83d09102016-04-15 14:59:13 +0200148TEST(PayloadRouterTest, MaxPayloadLength) {
mflodman@webrtc.orga4ef2ce2015-02-12 09:54:18 +0000149 // 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;
perkjbc75d972016-05-02 06:31:25 -0700152 NiceMock<MockRtpRtcp> rtp_1;
153 NiceMock<MockRtpRtcp> rtp_2;
Peter Boström404686a2016-02-11 23:37:26 +0100154 std::vector<RtpRtcp*> modules;
mflodman@webrtc.orga4ef2ce2015-02-12 09:54:18 +0000155 modules.push_back(&rtp_1);
156 modules.push_back(&rtp_2);
kjellander02b3d272016-04-20 05:05:54 -0700157 PayloadRouter payload_router(modules, 42);
Per83d09102016-04-15 14:59:13 +0200158
159 EXPECT_EQ(kDefaultMaxLength, PayloadRouter::DefaultMaxPayloadLength());
perkjbc75d972016-05-02 06:31:25 -0700160 std::vector<VideoStream> streams(2);
mflodman@webrtc.orga4ef2ce2015-02-12 09:54:18 +0000161
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));
Per83d09102016-04-15 14:59:13 +0200169 EXPECT_EQ(kDefaultMaxLength, payload_router.MaxPayloadLength());
mflodman@webrtc.orga4ef2ce2015-02-12 09:54:18 +0000170
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));
Per83d09102016-04-15 14:59:13 +0200179 EXPECT_EQ(kTestMinPayloadLength, payload_router.MaxPayloadLength());
mflodman@webrtc.orga4ef2ce2015-02-12 09:54:18 +0000180}
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000181} // namespace webrtc