2015-02-06 13:10:19 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-03-01 11:52:33 -08:00
|
|
|
#include <memory>
|
|
|
|
|
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
|
2015-02-06 13:10:19 +00:00
|
|
|
#include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
|
2016-04-20 05:05:54 -07:00
|
|
|
#include "webrtc/modules/video_coding/include/video_codec_interface.h"
|
2016-09-30 22:29:43 -07:00
|
|
|
#include "webrtc/test/gmock.h"
|
|
|
|
|
#include "webrtc/test/gtest.h"
|
2015-12-09 12:13:30 +01:00
|
|
|
#include "webrtc/video/payload_router.h"
|
2015-02-06 13:10:19 +00:00
|
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
|
using ::testing::AnyNumber;
|
|
|
|
|
using ::testing::NiceMock;
|
|
|
|
|
using ::testing::Return;
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2016-04-15 14:59:13 +02:00
|
|
|
TEST(PayloadRouterTest, SendOnOneModule) {
|
2016-05-02 06:31:25 -07:00
|
|
|
NiceMock<MockRtpRtcp> rtp;
|
2016-02-11 23:37:26 +01:00
|
|
|
std::vector<RtpRtcp*> modules(1, &rtp);
|
2016-05-02 06:31:25 -07:00
|
|
|
std::vector<VideoStream> streams(1);
|
2015-02-06 13:10:19 +00:00
|
|
|
|
|
|
|
|
uint8_t payload = 'a';
|
|
|
|
|
int8_t payload_type = 96;
|
2016-04-20 05:05:54 -07:00
|
|
|
EncodedImage encoded_image;
|
|
|
|
|
encoded_image._timeStamp = 1;
|
|
|
|
|
encoded_image.capture_time_ms_ = 2;
|
|
|
|
|
encoded_image._frameType = kVideoFrameKey;
|
|
|
|
|
encoded_image._buffer = &payload;
|
|
|
|
|
encoded_image._length = 1;
|
|
|
|
|
|
|
|
|
|
PayloadRouter payload_router(modules, payload_type);
|
2015-02-06 13:10:19 +00:00
|
|
|
|
2016-04-20 05:05:54 -07:00
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
|
|
|
|
|
encoded_image._timeStamp,
|
|
|
|
|
encoded_image.capture_time_ms_, &payload,
|
2016-08-02 17:46:41 -07:00
|
|
|
encoded_image._length, nullptr, _, _))
|
2015-02-06 13:10:19 +00:00
|
|
|
.Times(0);
|
2016-11-04 11:39:29 -07:00
|
|
|
EXPECT_NE(
|
|
|
|
|
EncodedImageCallback::Result::OK,
|
|
|
|
|
payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error);
|
2015-02-06 13:10:19 +00:00
|
|
|
|
2016-04-15 14:59:13 +02:00
|
|
|
payload_router.set_active(true);
|
2016-04-20 05:05:54 -07:00
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
|
|
|
|
|
encoded_image._timeStamp,
|
|
|
|
|
encoded_image.capture_time_ms_, &payload,
|
2016-08-02 17:46:41 -07:00
|
|
|
encoded_image._length, nullptr, _, _))
|
2016-11-17 16:16:14 -08:00
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(true));
|
2016-11-04 11:39:29 -07:00
|
|
|
EXPECT_EQ(
|
|
|
|
|
EncodedImageCallback::Result::OK,
|
|
|
|
|
payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error);
|
2015-02-06 13:10:19 +00:00
|
|
|
|
2016-04-15 14:59:13 +02:00
|
|
|
payload_router.set_active(false);
|
2016-04-20 05:05:54 -07:00
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
|
|
|
|
|
encoded_image._timeStamp,
|
|
|
|
|
encoded_image.capture_time_ms_, &payload,
|
2016-08-02 17:46:41 -07:00
|
|
|
encoded_image._length, nullptr, _, _))
|
2015-02-06 13:10:19 +00:00
|
|
|
.Times(0);
|
2016-11-04 11:39:29 -07:00
|
|
|
EXPECT_NE(
|
|
|
|
|
EncodedImageCallback::Result::OK,
|
|
|
|
|
payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error);
|
2015-02-06 13:10:19 +00:00
|
|
|
|
2016-04-15 14:59:13 +02:00
|
|
|
payload_router.set_active(true);
|
2016-04-20 05:05:54 -07:00
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
|
|
|
|
|
encoded_image._timeStamp,
|
|
|
|
|
encoded_image.capture_time_ms_, &payload,
|
2016-08-02 17:46:41 -07:00
|
|
|
encoded_image._length, nullptr, _, _))
|
2016-11-17 16:16:14 -08:00
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(true));
|
2016-11-04 11:39:29 -07:00
|
|
|
EXPECT_EQ(
|
|
|
|
|
EncodedImageCallback::Result::OK,
|
|
|
|
|
payload_router.OnEncodedImage(encoded_image, nullptr, nullptr).error);
|
2015-02-06 13:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-15 14:59:13 +02:00
|
|
|
TEST(PayloadRouterTest, SendSimulcast) {
|
2016-05-02 06:31:25 -07:00
|
|
|
NiceMock<MockRtpRtcp> rtp_1;
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp_2;
|
2016-02-11 23:37:26 +01:00
|
|
|
std::vector<RtpRtcp*> modules;
|
2015-02-06 13:10:19 +00:00
|
|
|
modules.push_back(&rtp_1);
|
|
|
|
|
modules.push_back(&rtp_2);
|
2016-05-02 06:31:25 -07:00
|
|
|
std::vector<VideoStream> streams(2);
|
2015-02-06 13:10:19 +00:00
|
|
|
|
2016-04-20 05:05:54 -07:00
|
|
|
int8_t payload_type = 96;
|
|
|
|
|
uint8_t payload = 'a';
|
|
|
|
|
EncodedImage encoded_image;
|
|
|
|
|
encoded_image._timeStamp = 1;
|
|
|
|
|
encoded_image.capture_time_ms_ = 2;
|
|
|
|
|
encoded_image._frameType = kVideoFrameKey;
|
|
|
|
|
encoded_image._buffer = &payload;
|
|
|
|
|
encoded_image._length = 1;
|
|
|
|
|
|
|
|
|
|
PayloadRouter payload_router(modules, payload_type);
|
2015-02-06 13:10:19 +00:00
|
|
|
|
2016-04-20 05:05:54 -07:00
|
|
|
CodecSpecificInfo codec_info_1;
|
|
|
|
|
memset(&codec_info_1, 0, sizeof(CodecSpecificInfo));
|
|
|
|
|
codec_info_1.codecType = kVideoCodecVP8;
|
|
|
|
|
codec_info_1.codecSpecific.VP8.simulcastIdx = 0;
|
2015-02-06 13:10:19 +00:00
|
|
|
|
2016-04-15 14:59:13 +02:00
|
|
|
payload_router.set_active(true);
|
2016-04-20 05:05:54 -07:00
|
|
|
EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, payload_type,
|
|
|
|
|
encoded_image._timeStamp,
|
|
|
|
|
encoded_image.capture_time_ms_, &payload,
|
2016-08-02 17:46:41 -07:00
|
|
|
encoded_image._length, nullptr, _, _))
|
2016-11-17 16:16:14 -08:00
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(true));
|
2016-08-02 17:46:41 -07:00
|
|
|
EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _)).Times(0);
|
2016-11-04 11:39:29 -07:00
|
|
|
EXPECT_EQ(EncodedImageCallback::Result::OK,
|
|
|
|
|
payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr)
|
|
|
|
|
.error);
|
2016-04-20 05:05:54 -07:00
|
|
|
|
|
|
|
|
CodecSpecificInfo codec_info_2;
|
|
|
|
|
memset(&codec_info_2, 0, sizeof(CodecSpecificInfo));
|
|
|
|
|
codec_info_2.codecType = kVideoCodecVP8;
|
|
|
|
|
codec_info_2.codecSpecific.VP8.simulcastIdx = 1;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp_2, SendOutgoingData(encoded_image._frameType, payload_type,
|
|
|
|
|
encoded_image._timeStamp,
|
|
|
|
|
encoded_image.capture_time_ms_, &payload,
|
2016-08-02 17:46:41 -07:00
|
|
|
encoded_image._length, nullptr, _, _))
|
2016-11-17 16:16:14 -08:00
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(true));
|
2016-08-02 17:46:41 -07:00
|
|
|
EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _))
|
2015-02-06 13:10:19 +00:00
|
|
|
.Times(0);
|
2016-11-04 11:39:29 -07:00
|
|
|
EXPECT_EQ(EncodedImageCallback::Result::OK,
|
|
|
|
|
payload_router.OnEncodedImage(encoded_image, &codec_info_2, nullptr)
|
|
|
|
|
.error);
|
2015-02-06 13:10:19 +00:00
|
|
|
|
2015-02-23 07:45:11 +00:00
|
|
|
// Inactive.
|
2016-04-15 14:59:13 +02:00
|
|
|
payload_router.set_active(false);
|
2016-08-02 17:46:41 -07:00
|
|
|
EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _))
|
2015-02-06 13:10:19 +00:00
|
|
|
.Times(0);
|
2016-08-02 17:46:41 -07:00
|
|
|
EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _))
|
2015-02-06 13:10:19 +00:00
|
|
|
.Times(0);
|
2016-11-04 11:39:29 -07:00
|
|
|
EXPECT_NE(EncodedImageCallback::Result::OK,
|
|
|
|
|
payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr)
|
|
|
|
|
.error);
|
|
|
|
|
EXPECT_NE(EncodedImageCallback::Result::OK,
|
|
|
|
|
payload_router.OnEncodedImage(encoded_image, &codec_info_2, nullptr)
|
|
|
|
|
.error);
|
2015-02-06 13:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-15 14:59:13 +02:00
|
|
|
TEST(PayloadRouterTest, MaxPayloadLength) {
|
2015-02-12 09:54:18 +00:00
|
|
|
// Without any limitations from the modules, verify we get the max payload
|
|
|
|
|
// length for IP/UDP/SRTP with a MTU of 150 bytes.
|
|
|
|
|
const size_t kDefaultMaxLength = 1500 - 20 - 8 - 12 - 4;
|
2016-05-02 06:31:25 -07:00
|
|
|
NiceMock<MockRtpRtcp> rtp_1;
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp_2;
|
2016-02-11 23:37:26 +01:00
|
|
|
std::vector<RtpRtcp*> modules;
|
2015-02-12 09:54:18 +00:00
|
|
|
modules.push_back(&rtp_1);
|
|
|
|
|
modules.push_back(&rtp_2);
|
2016-04-20 05:05:54 -07:00
|
|
|
PayloadRouter payload_router(modules, 42);
|
2016-04-15 14:59:13 +02:00
|
|
|
|
|
|
|
|
EXPECT_EQ(kDefaultMaxLength, PayloadRouter::DefaultMaxPayloadLength());
|
2016-05-02 06:31:25 -07:00
|
|
|
std::vector<VideoStream> streams(2);
|
2015-02-12 09:54:18 +00:00
|
|
|
|
|
|
|
|
// Modules return a higher length than the default value.
|
|
|
|
|
EXPECT_CALL(rtp_1, MaxDataPayloadLength())
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(kDefaultMaxLength + 10));
|
|
|
|
|
EXPECT_CALL(rtp_2, MaxDataPayloadLength())
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(kDefaultMaxLength + 10));
|
2016-04-15 14:59:13 +02:00
|
|
|
EXPECT_EQ(kDefaultMaxLength, payload_router.MaxPayloadLength());
|
2015-02-12 09:54:18 +00:00
|
|
|
|
|
|
|
|
// The modules return a value lower than default.
|
|
|
|
|
const size_t kTestMinPayloadLength = 1001;
|
|
|
|
|
EXPECT_CALL(rtp_1, MaxDataPayloadLength())
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(kTestMinPayloadLength + 10));
|
|
|
|
|
EXPECT_CALL(rtp_2, MaxDataPayloadLength())
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(kTestMinPayloadLength));
|
2016-04-15 14:59:13 +02:00
|
|
|
EXPECT_EQ(kTestMinPayloadLength, payload_router.MaxPayloadLength());
|
2015-02-12 09:54:18 +00:00
|
|
|
}
|
2015-02-06 13:10:19 +00:00
|
|
|
} // namespace webrtc
|