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>
|
2017-10-06 10:04:04 +02:00
|
|
|
#include <string>
|
2016-03-01 11:52:33 -08:00
|
|
|
|
2018-07-11 17:11:31 +02:00
|
|
|
#include "call/payload_router.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/include/rtp_rtcp.h"
|
|
|
|
|
#include "modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
|
|
|
|
|
#include "modules/video_coding/include/video_codec_interface.h"
|
2017-10-06 10:04:04 +02:00
|
|
|
#include "test/field_trial.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "test/gmock.h"
|
|
|
|
|
#include "test/gtest.h"
|
2015-02-06 13:10:19 +00:00
|
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
|
using ::testing::AnyNumber;
|
2017-10-06 10:04:04 +02:00
|
|
|
using ::testing::Invoke;
|
2015-02-06 13:10:19 +00:00
|
|
|
using ::testing::NiceMock;
|
|
|
|
|
using ::testing::Return;
|
2017-10-06 10:04:04 +02:00
|
|
|
using ::testing::Unused;
|
2015-02-06 13:10:19 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2017-10-06 10:04:04 +02:00
|
|
|
namespace {
|
|
|
|
|
const int8_t kPayloadType = 96;
|
|
|
|
|
const uint32_t kSsrc1 = 12345;
|
|
|
|
|
const uint32_t kSsrc2 = 23456;
|
|
|
|
|
const int16_t kInitialPictureId1 = 222;
|
|
|
|
|
const int16_t kInitialPictureId2 = 44;
|
2018-03-15 12:28:53 +01:00
|
|
|
const int16_t kInitialTl0PicIdx1 = 99;
|
|
|
|
|
const int16_t kInitialTl0PicIdx2 = 199;
|
2017-10-06 10:04:04 +02:00
|
|
|
} // namespace
|
2015-02-06 13:10:19 +00:00
|
|
|
|
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);
|
2015-02-06 13:10:19 +00:00
|
|
|
|
|
|
|
|
uint8_t payload = 'a';
|
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;
|
|
|
|
|
|
2017-10-06 10:04:04 +02:00
|
|
|
PayloadRouter payload_router(modules, {kSsrc1}, kPayloadType, {});
|
2015-02-06 13:10:19 +00:00
|
|
|
|
2017-10-06 10:04:04 +02:00
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType,
|
2016-04-20 05:05:54 -07:00
|
|
|
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-12-01 06:34:11 -08:00
|
|
|
payload_router.SetActive(true);
|
2017-10-06 10:04:04 +02:00
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType,
|
2016-04-20 05:05:54 -07:00
|
|
|
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));
|
2018-02-02 08:46:16 -08:00
|
|
|
EXPECT_CALL(rtp, Sending()).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-12-01 06:34:11 -08:00
|
|
|
payload_router.SetActive(false);
|
2017-10-06 10:04:04 +02:00
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType,
|
2016-04-20 05:05:54 -07:00
|
|
|
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-12-01 06:34:11 -08:00
|
|
|
payload_router.SetActive(true);
|
2017-10-06 10:04:04 +02:00
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, kPayloadType,
|
2016-04-20 05:05:54 -07:00
|
|
|
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));
|
2018-02-02 08:46:16 -08:00
|
|
|
EXPECT_CALL(rtp, Sending()).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
|
|
|
}
|
|
|
|
|
|
2018-02-02 08:46:16 -08:00
|
|
|
TEST(PayloadRouterTest, SendSimulcastSetActive) {
|
2016-05-02 06:31:25 -07:00
|
|
|
NiceMock<MockRtpRtcp> rtp_1;
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp_2;
|
2017-10-06 10:04:04 +02:00
|
|
|
std::vector<RtpRtcp*> modules = {&rtp_1, &rtp_2};
|
2015-02-06 13:10:19 +00:00
|
|
|
|
2016-04-20 05:05:54 -07:00
|
|
|
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;
|
|
|
|
|
|
2017-10-06 10:04:04 +02:00
|
|
|
PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {});
|
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-12-01 06:34:11 -08:00
|
|
|
payload_router.SetActive(true);
|
2018-02-02 08:46:16 -08:00
|
|
|
EXPECT_CALL(rtp_1, Sending()).WillOnce(Return(true));
|
2017-10-06 10:04:04 +02:00
|
|
|
EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, kPayloadType,
|
2016-04-20 05:05:54 -07:00
|
|
|
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;
|
|
|
|
|
|
2018-02-02 08:46:16 -08:00
|
|
|
EXPECT_CALL(rtp_2, Sending()).WillOnce(Return(true));
|
2017-10-06 10:04:04 +02:00
|
|
|
EXPECT_CALL(rtp_2, SendOutgoingData(encoded_image._frameType, kPayloadType,
|
2016-04-20 05:05:54 -07:00
|
|
|
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(_, _, _, _, _, _, _, _, _)).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-12-01 06:34:11 -08:00
|
|
|
payload_router.SetActive(false);
|
2016-08-02 17:46:41 -07:00
|
|
|
EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _)).Times(0);
|
|
|
|
|
EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _)).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
|
|
|
}
|
|
|
|
|
|
2018-02-02 08:46:16 -08:00
|
|
|
// Tests how setting individual rtp modules to active affects the overall
|
|
|
|
|
// behavior of the payload router. First sets one module to active and checks
|
|
|
|
|
// that outgoing data can be sent on this module, and checks that no data can be
|
|
|
|
|
// sent if both modules are inactive.
|
|
|
|
|
TEST(PayloadRouterTest, SendSimulcastSetActiveModules) {
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp_1;
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp_2;
|
|
|
|
|
std::vector<RtpRtcp*> modules = {&rtp_1, &rtp_2};
|
|
|
|
|
|
|
|
|
|
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, {kSsrc1, kSsrc2}, kPayloadType, {});
|
|
|
|
|
CodecSpecificInfo codec_info_1;
|
|
|
|
|
memset(&codec_info_1, 0, sizeof(CodecSpecificInfo));
|
|
|
|
|
codec_info_1.codecType = kVideoCodecVP8;
|
|
|
|
|
codec_info_1.codecSpecific.VP8.simulcastIdx = 0;
|
|
|
|
|
CodecSpecificInfo codec_info_2;
|
|
|
|
|
memset(&codec_info_2, 0, sizeof(CodecSpecificInfo));
|
|
|
|
|
codec_info_2.codecType = kVideoCodecVP8;
|
|
|
|
|
codec_info_2.codecSpecific.VP8.simulcastIdx = 1;
|
|
|
|
|
|
|
|
|
|
// Only setting one stream to active will still set the payload router to
|
|
|
|
|
// active and allow sending data on the active stream.
|
|
|
|
|
std::vector<bool> active_modules({true, false});
|
|
|
|
|
payload_router.SetActiveModules(active_modules);
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp_1, Sending()).WillOnce(Return(true));
|
|
|
|
|
EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, kPayloadType,
|
|
|
|
|
encoded_image._timeStamp,
|
|
|
|
|
encoded_image.capture_time_ms_, &payload,
|
|
|
|
|
encoded_image._length, nullptr, _, _))
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce(Return(true));
|
|
|
|
|
EXPECT_EQ(EncodedImageCallback::Result::OK,
|
|
|
|
|
payload_router.OnEncodedImage(encoded_image, &codec_info_1, nullptr)
|
|
|
|
|
.error);
|
|
|
|
|
|
|
|
|
|
// Setting both streams to inactive will turn the payload router to inactive.
|
|
|
|
|
active_modules = {false, false};
|
|
|
|
|
payload_router.SetActiveModules(active_modules);
|
|
|
|
|
// An incoming encoded image will not ask the module to send outgoing data
|
|
|
|
|
// because the payload router is inactive.
|
|
|
|
|
EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _, _)).Times(0);
|
|
|
|
|
EXPECT_CALL(rtp_1, Sending()).Times(0);
|
|
|
|
|
EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _, _)).Times(0);
|
|
|
|
|
EXPECT_CALL(rtp_2, Sending()).Times(0);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-06 10:04:04 +02:00
|
|
|
TEST(PayloadRouterTest, CreateWithNoPreviousStates) {
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp1;
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp2;
|
|
|
|
|
std::vector<RtpRtcp*> modules = {&rtp1, &rtp2};
|
|
|
|
|
PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {});
|
|
|
|
|
payload_router.SetActive(true);
|
|
|
|
|
|
|
|
|
|
std::map<uint32_t, RtpPayloadState> initial_states =
|
|
|
|
|
payload_router.GetRtpPayloadStates();
|
|
|
|
|
EXPECT_EQ(2u, initial_states.size());
|
|
|
|
|
EXPECT_NE(initial_states.find(kSsrc1), initial_states.end());
|
|
|
|
|
EXPECT_NE(initial_states.find(kSsrc2), initial_states.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(PayloadRouterTest, CreateWithPreviousStates) {
|
|
|
|
|
RtpPayloadState state1;
|
|
|
|
|
state1.picture_id = kInitialPictureId1;
|
2018-03-15 12:28:53 +01:00
|
|
|
state1.tl0_pic_idx = kInitialTl0PicIdx1;
|
2017-10-06 10:04:04 +02:00
|
|
|
RtpPayloadState state2;
|
|
|
|
|
state2.picture_id = kInitialPictureId2;
|
2018-03-15 12:28:53 +01:00
|
|
|
state2.tl0_pic_idx = kInitialTl0PicIdx2;
|
2017-10-06 10:04:04 +02:00
|
|
|
std::map<uint32_t, RtpPayloadState> states = {{kSsrc1, state1},
|
|
|
|
|
{kSsrc2, state2}};
|
|
|
|
|
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp1;
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp2;
|
|
|
|
|
std::vector<RtpRtcp*> modules = {&rtp1, &rtp2};
|
|
|
|
|
PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, states);
|
|
|
|
|
payload_router.SetActive(true);
|
|
|
|
|
|
|
|
|
|
std::map<uint32_t, RtpPayloadState> initial_states =
|
|
|
|
|
payload_router.GetRtpPayloadStates();
|
|
|
|
|
EXPECT_EQ(2u, initial_states.size());
|
|
|
|
|
EXPECT_EQ(kInitialPictureId1, initial_states[kSsrc1].picture_id);
|
2018-03-15 12:28:53 +01:00
|
|
|
EXPECT_EQ(kInitialTl0PicIdx1, initial_states[kSsrc1].tl0_pic_idx);
|
2017-10-06 10:04:04 +02:00
|
|
|
EXPECT_EQ(kInitialPictureId2, initial_states[kSsrc2].picture_id);
|
2018-03-15 12:28:53 +01:00
|
|
|
EXPECT_EQ(kInitialTl0PicIdx2, initial_states[kSsrc2].tl0_pic_idx);
|
2017-10-06 10:04:04 +02:00
|
|
|
}
|
2015-02-06 13:10:19 +00:00
|
|
|
} // namespace webrtc
|