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
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "call/video_config.h"
|
|
|
|
|
#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"
|
|
|
|
|
#include "video/payload_router.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;
|
2018-01-18 10:39:54 -08:00
|
|
|
const uint32_t kSsrc3 = 34567;
|
2017-10-06 10:04:04 +02:00
|
|
|
const int16_t kPictureId = 123;
|
|
|
|
|
const int16_t kTl0PicIdx = 20;
|
|
|
|
|
const uint8_t kTemporalIdx = 1;
|
|
|
|
|
const int16_t kInitialPictureId1 = 222;
|
|
|
|
|
const int16_t kInitialPictureId2 = 44;
|
|
|
|
|
} // 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));
|
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));
|
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;
|
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);
|
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;
|
|
|
|
|
|
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(_, _, _, _, _, _, _, _, _))
|
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-12-01 06:34:11 -08:00
|
|
|
payload_router.SetActive(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-12-01 06:34:11 -08:00
|
|
|
TEST(PayloadRouterTest, SimulcastTargetBitrate) {
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp_1;
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp_2;
|
2017-10-06 10:04:04 +02:00
|
|
|
std::vector<RtpRtcp*> modules = {&rtp_1, &rtp_2};
|
|
|
|
|
|
|
|
|
|
PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {});
|
2016-12-01 06:34:11 -08:00
|
|
|
payload_router.SetActive(true);
|
|
|
|
|
|
|
|
|
|
BitrateAllocation bitrate;
|
|
|
|
|
bitrate.SetBitrate(0, 0, 10000);
|
|
|
|
|
bitrate.SetBitrate(0, 1, 20000);
|
|
|
|
|
bitrate.SetBitrate(1, 0, 40000);
|
|
|
|
|
bitrate.SetBitrate(1, 1, 80000);
|
|
|
|
|
|
|
|
|
|
BitrateAllocation layer0_bitrate;
|
|
|
|
|
layer0_bitrate.SetBitrate(0, 0, 10000);
|
|
|
|
|
layer0_bitrate.SetBitrate(0, 1, 20000);
|
|
|
|
|
|
|
|
|
|
BitrateAllocation layer1_bitrate;
|
|
|
|
|
layer1_bitrate.SetBitrate(0, 0, 40000);
|
|
|
|
|
layer1_bitrate.SetBitrate(0, 1, 80000);
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp_1, SetVideoBitrateAllocation(layer0_bitrate)).Times(1);
|
|
|
|
|
EXPECT_CALL(rtp_2, SetVideoBitrateAllocation(layer1_bitrate)).Times(1);
|
|
|
|
|
|
|
|
|
|
payload_router.OnBitrateAllocationUpdated(bitrate);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 10:39:54 -08:00
|
|
|
// If the middle of three streams is inactive the first and last streams should
|
|
|
|
|
// be asked to send the TargetBitrate message.
|
2017-06-22 05:40:25 -07:00
|
|
|
TEST(PayloadRouterTest, SimulcastTargetBitrateWithInactiveStream) {
|
2018-01-18 10:39:54 -08:00
|
|
|
// Set up three active rtp modules.
|
2017-06-22 05:40:25 -07:00
|
|
|
NiceMock<MockRtpRtcp> rtp_1;
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp_2;
|
2018-01-18 10:39:54 -08:00
|
|
|
NiceMock<MockRtpRtcp> rtp_3;
|
|
|
|
|
std::vector<RtpRtcp*> modules = {&rtp_1, &rtp_2, &rtp_3};
|
|
|
|
|
PayloadRouter payload_router(modules, {kSsrc1, kSsrc2, kSsrc3}, kPayloadType,
|
|
|
|
|
{});
|
2017-06-22 05:40:25 -07:00
|
|
|
payload_router.SetActive(true);
|
|
|
|
|
|
2018-01-18 10:39:54 -08:00
|
|
|
// Create bitrate allocation with bitrate only for the first and third stream.
|
2017-06-22 05:40:25 -07:00
|
|
|
BitrateAllocation bitrate;
|
|
|
|
|
bitrate.SetBitrate(0, 0, 10000);
|
|
|
|
|
bitrate.SetBitrate(0, 1, 20000);
|
2018-01-18 10:39:54 -08:00
|
|
|
bitrate.SetBitrate(2, 0, 40000);
|
|
|
|
|
bitrate.SetBitrate(2, 1, 80000);
|
|
|
|
|
|
|
|
|
|
BitrateAllocation layer0_bitrate;
|
|
|
|
|
layer0_bitrate.SetBitrate(0, 0, 10000);
|
|
|
|
|
layer0_bitrate.SetBitrate(0, 1, 20000);
|
2017-06-22 05:40:25 -07:00
|
|
|
|
2018-01-18 10:39:54 -08:00
|
|
|
BitrateAllocation layer2_bitrate;
|
|
|
|
|
layer2_bitrate.SetBitrate(0, 0, 40000);
|
|
|
|
|
layer2_bitrate.SetBitrate(0, 1, 80000);
|
|
|
|
|
|
|
|
|
|
// Expect the first and third rtp module to be asked to send a TargetBitrate
|
2017-06-22 05:40:25 -07:00
|
|
|
// message. (No target bitrate with 0bps sent from the second one.)
|
2018-01-18 10:39:54 -08:00
|
|
|
EXPECT_CALL(rtp_1, SetVideoBitrateAllocation(layer0_bitrate)).Times(1);
|
2017-06-22 05:40:25 -07:00
|
|
|
EXPECT_CALL(rtp_2, SetVideoBitrateAllocation(_)).Times(0);
|
2018-01-18 10:39:54 -08:00
|
|
|
EXPECT_CALL(rtp_3, SetVideoBitrateAllocation(layer2_bitrate)).Times(1);
|
2017-06-22 05:40:25 -07:00
|
|
|
|
|
|
|
|
payload_router.OnBitrateAllocationUpdated(bitrate);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 06:34:11 -08:00
|
|
|
TEST(PayloadRouterTest, SvcTargetBitrate) {
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp_1;
|
2017-10-06 10:04:04 +02:00
|
|
|
std::vector<RtpRtcp*> modules = {&rtp_1};
|
|
|
|
|
PayloadRouter payload_router(modules, {kSsrc1}, kPayloadType, {});
|
2016-12-01 06:34:11 -08:00
|
|
|
payload_router.SetActive(true);
|
|
|
|
|
|
|
|
|
|
BitrateAllocation bitrate;
|
|
|
|
|
bitrate.SetBitrate(0, 0, 10000);
|
|
|
|
|
bitrate.SetBitrate(0, 1, 20000);
|
|
|
|
|
bitrate.SetBitrate(1, 0, 40000);
|
|
|
|
|
bitrate.SetBitrate(1, 1, 80000);
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp_1, SetVideoBitrateAllocation(bitrate)).Times(1);
|
|
|
|
|
|
|
|
|
|
payload_router.OnBitrateAllocationUpdated(bitrate);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-06 10:04:04 +02:00
|
|
|
TEST(PayloadRouterTest, InfoMappedToRtpVideoHeader_Vp8) {
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp1;
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp2;
|
|
|
|
|
std::vector<RtpRtcp*> modules = {&rtp1, &rtp2};
|
|
|
|
|
PayloadRouter payload_router(modules, {kSsrc1, kSsrc2}, kPayloadType, {});
|
|
|
|
|
payload_router.SetActive(true);
|
|
|
|
|
|
|
|
|
|
EncodedImage encoded_image;
|
|
|
|
|
encoded_image.rotation_ = kVideoRotation_90;
|
|
|
|
|
encoded_image.content_type_ = VideoContentType::SCREENSHARE;
|
|
|
|
|
|
|
|
|
|
CodecSpecificInfo codec_info;
|
|
|
|
|
memset(&codec_info, 0, sizeof(CodecSpecificInfo));
|
|
|
|
|
codec_info.codecType = kVideoCodecVP8;
|
|
|
|
|
codec_info.codecSpecific.VP8.simulcastIdx = 1;
|
|
|
|
|
codec_info.codecSpecific.VP8.pictureId = kPictureId;
|
|
|
|
|
codec_info.codecSpecific.VP8.temporalIdx = kTemporalIdx;
|
|
|
|
|
codec_info.codecSpecific.VP8.tl0PicIdx = kTl0PicIdx;
|
|
|
|
|
codec_info.codecSpecific.VP8.keyIdx = kNoKeyIdx;
|
|
|
|
|
codec_info.codecSpecific.VP8.layerSync = true;
|
|
|
|
|
codec_info.codecSpecific.VP8.nonReference = true;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp2, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _))
|
|
|
|
|
.WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused,
|
|
|
|
|
Unused, const RTPVideoHeader* header, Unused) {
|
|
|
|
|
EXPECT_EQ(kVideoRotation_90, header->rotation);
|
|
|
|
|
EXPECT_EQ(VideoContentType::SCREENSHARE, header->content_type);
|
|
|
|
|
EXPECT_EQ(1, header->simulcastIdx);
|
|
|
|
|
EXPECT_EQ(kRtpVideoVp8, header->codec);
|
|
|
|
|
EXPECT_EQ(kPictureId, header->codecHeader.VP8.pictureId);
|
|
|
|
|
EXPECT_EQ(kTemporalIdx, header->codecHeader.VP8.temporalIdx);
|
|
|
|
|
EXPECT_EQ(kTl0PicIdx, header->codecHeader.VP8.tl0PicIdx);
|
|
|
|
|
EXPECT_EQ(kNoKeyIdx, header->codecHeader.VP8.keyIdx);
|
|
|
|
|
EXPECT_TRUE(header->codecHeader.VP8.layerSync);
|
|
|
|
|
EXPECT_TRUE(header->codecHeader.VP8.nonReference);
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
|
EncodedImageCallback::Result::OK,
|
|
|
|
|
payload_router.OnEncodedImage(encoded_image, &codec_info, nullptr).error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(PayloadRouterTest, InfoMappedToRtpVideoHeader_H264) {
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp1;
|
|
|
|
|
std::vector<RtpRtcp*> modules = {&rtp1};
|
|
|
|
|
PayloadRouter payload_router(modules, {kSsrc1}, kPayloadType, {});
|
|
|
|
|
payload_router.SetActive(true);
|
|
|
|
|
|
|
|
|
|
EncodedImage encoded_image;
|
|
|
|
|
CodecSpecificInfo codec_info;
|
|
|
|
|
memset(&codec_info, 0, sizeof(CodecSpecificInfo));
|
|
|
|
|
codec_info.codecType = kVideoCodecH264;
|
|
|
|
|
codec_info.codecSpecific.H264.packetization_mode =
|
|
|
|
|
H264PacketizationMode::SingleNalUnit;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp1, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _))
|
|
|
|
|
.WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused,
|
|
|
|
|
Unused, const RTPVideoHeader* header, Unused) {
|
|
|
|
|
EXPECT_EQ(0, header->simulcastIdx);
|
|
|
|
|
EXPECT_EQ(kRtpVideoH264, header->codec);
|
|
|
|
|
EXPECT_EQ(H264PacketizationMode::SingleNalUnit,
|
|
|
|
|
header->codecHeader.H264.packetization_mode);
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
|
EncodedImageCallback::Result::OK,
|
|
|
|
|
payload_router.OnEncodedImage(encoded_image, &codec_info, nullptr).error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
RtpPayloadState state2;
|
|
|
|
|
state2.picture_id = kInitialPictureId2;
|
|
|
|
|
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);
|
|
|
|
|
EXPECT_EQ(kInitialPictureId2, initial_states[kSsrc2].picture_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PayloadRouterTest : public ::testing::Test {
|
|
|
|
|
public:
|
|
|
|
|
explicit PayloadRouterTest(const std::string& field_trials)
|
|
|
|
|
: override_field_trials_(field_trials) {}
|
|
|
|
|
virtual ~PayloadRouterTest() {}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void SetUp() { memset(&codec_info_, 0, sizeof(CodecSpecificInfo)); }
|
|
|
|
|
|
|
|
|
|
test::ScopedFieldTrials override_field_trials_;
|
|
|
|
|
EncodedImage image_;
|
|
|
|
|
CodecSpecificInfo codec_info_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TestWithForcedFallbackDisabled : public PayloadRouterTest {
|
|
|
|
|
public:
|
|
|
|
|
TestWithForcedFallbackDisabled()
|
2017-11-13 10:16:47 +01:00
|
|
|
: PayloadRouterTest("WebRTC-VP8-Forced-Fallback-Encoder-v2/Disabled/") {}
|
2017-10-06 10:04:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TestWithForcedFallbackEnabled : public PayloadRouterTest {
|
|
|
|
|
public:
|
|
|
|
|
TestWithForcedFallbackEnabled()
|
|
|
|
|
: PayloadRouterTest(
|
2017-11-13 10:16:47 +01:00
|
|
|
"WebRTC-VP8-Forced-Fallback-Encoder-v2/Enabled-1,2,3/") {}
|
2017-10-06 10:04:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(TestWithForcedFallbackDisabled, PictureIdIsNotChangedForVp8) {
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp;
|
|
|
|
|
std::vector<RtpRtcp*> modules = {&rtp};
|
|
|
|
|
PayloadRouter router(modules, {kSsrc1}, kPayloadType, {});
|
|
|
|
|
router.SetActive(true);
|
|
|
|
|
|
|
|
|
|
codec_info_.codecType = kVideoCodecVP8;
|
|
|
|
|
codec_info_.codecSpecific.VP8.pictureId = kPictureId;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _))
|
|
|
|
|
.WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused,
|
|
|
|
|
Unused, const RTPVideoHeader* header, Unused) {
|
|
|
|
|
EXPECT_EQ(kRtpVideoVp8, header->codec);
|
|
|
|
|
EXPECT_EQ(kPictureId, header->codecHeader.VP8.pictureId);
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(EncodedImageCallback::Result::OK,
|
|
|
|
|
router.OnEncodedImage(image_, &codec_info_, nullptr).error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TestWithForcedFallbackEnabled, PictureIdIsSetForVp8) {
|
|
|
|
|
RtpPayloadState state1;
|
|
|
|
|
state1.picture_id = kInitialPictureId1;
|
|
|
|
|
RtpPayloadState state2;
|
|
|
|
|
state2.picture_id = kInitialPictureId2;
|
|
|
|
|
std::map<uint32_t, RtpPayloadState> states = {{kSsrc1, state1},
|
|
|
|
|
{kSsrc2, state2}};
|
|
|
|
|
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp1;
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp2;
|
|
|
|
|
std::vector<RtpRtcp*> modules = {&rtp1, &rtp2};
|
|
|
|
|
PayloadRouter router(modules, {kSsrc1, kSsrc2}, kPayloadType, states);
|
|
|
|
|
router.SetActive(true);
|
|
|
|
|
|
|
|
|
|
// OnEncodedImage, simulcastIdx: 0.
|
|
|
|
|
codec_info_.codecType = kVideoCodecVP8;
|
|
|
|
|
codec_info_.codecSpecific.VP8.pictureId = kPictureId;
|
|
|
|
|
codec_info_.codecSpecific.VP8.simulcastIdx = 0;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp1, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _))
|
|
|
|
|
.WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused,
|
|
|
|
|
Unused, const RTPVideoHeader* header, Unused) {
|
|
|
|
|
EXPECT_EQ(kRtpVideoVp8, header->codec);
|
|
|
|
|
EXPECT_EQ(kInitialPictureId1, header->codecHeader.VP8.pictureId);
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(EncodedImageCallback::Result::OK,
|
|
|
|
|
router.OnEncodedImage(image_, &codec_info_, nullptr).error);
|
|
|
|
|
|
|
|
|
|
// OnEncodedImage, simulcastIdx: 1.
|
|
|
|
|
codec_info_.codecSpecific.VP8.pictureId = kPictureId;
|
|
|
|
|
codec_info_.codecSpecific.VP8.simulcastIdx = 1;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp2, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _))
|
|
|
|
|
.WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused,
|
|
|
|
|
Unused, const RTPVideoHeader* header, Unused) {
|
|
|
|
|
EXPECT_EQ(kRtpVideoVp8, header->codec);
|
|
|
|
|
EXPECT_EQ(kInitialPictureId2, header->codecHeader.VP8.pictureId);
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(EncodedImageCallback::Result::OK,
|
|
|
|
|
router.OnEncodedImage(image_, &codec_info_, nullptr).error);
|
|
|
|
|
|
|
|
|
|
// State should hold next picture id to use.
|
|
|
|
|
states = router.GetRtpPayloadStates();
|
|
|
|
|
EXPECT_EQ(2u, states.size());
|
|
|
|
|
EXPECT_EQ(kInitialPictureId1 + 1, states[kSsrc1].picture_id);
|
|
|
|
|
EXPECT_EQ(kInitialPictureId2 + 1, states[kSsrc2].picture_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TestWithForcedFallbackEnabled, PictureIdWraps) {
|
|
|
|
|
RtpPayloadState state1;
|
|
|
|
|
state1.picture_id = kMaxTwoBytePictureId;
|
|
|
|
|
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp;
|
|
|
|
|
std::vector<RtpRtcp*> modules = {&rtp};
|
|
|
|
|
PayloadRouter router(modules, {kSsrc1}, kPayloadType, {{kSsrc1, state1}});
|
|
|
|
|
router.SetActive(true);
|
|
|
|
|
|
|
|
|
|
codec_info_.codecType = kVideoCodecVP8;
|
|
|
|
|
codec_info_.codecSpecific.VP8.pictureId = kPictureId;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _))
|
|
|
|
|
.WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused,
|
|
|
|
|
Unused, const RTPVideoHeader* header, Unused) {
|
|
|
|
|
EXPECT_EQ(kRtpVideoVp8, header->codec);
|
|
|
|
|
EXPECT_EQ(kMaxTwoBytePictureId, header->codecHeader.VP8.pictureId);
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(EncodedImageCallback::Result::OK,
|
|
|
|
|
router.OnEncodedImage(image_, &codec_info_, nullptr).error);
|
|
|
|
|
|
|
|
|
|
// State should hold next picture id to use.
|
|
|
|
|
std::map<uint32_t, RtpPayloadState> states = router.GetRtpPayloadStates();
|
|
|
|
|
EXPECT_EQ(1u, states.size());
|
|
|
|
|
EXPECT_EQ(0, states[kSsrc1].picture_id); // Wrapped.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TestWithForcedFallbackEnabled, PictureIdIsNotSetIfNoPictureId) {
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp;
|
|
|
|
|
std::vector<RtpRtcp*> modules = {&rtp};
|
|
|
|
|
PayloadRouter router(modules, {kSsrc1}, kPayloadType, {});
|
|
|
|
|
router.SetActive(true);
|
|
|
|
|
|
|
|
|
|
codec_info_.codecType = kVideoCodecVP8;
|
|
|
|
|
codec_info_.codecSpecific.VP8.pictureId = kNoPictureId;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _))
|
|
|
|
|
.WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused,
|
|
|
|
|
Unused, const RTPVideoHeader* header, Unused) {
|
|
|
|
|
EXPECT_EQ(kRtpVideoVp8, header->codec);
|
|
|
|
|
EXPECT_EQ(kNoPictureId, header->codecHeader.VP8.pictureId);
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(EncodedImageCallback::Result::OK,
|
|
|
|
|
router.OnEncodedImage(image_, &codec_info_, nullptr).error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TestWithForcedFallbackEnabled, PictureIdIsNotSetForVp9) {
|
|
|
|
|
NiceMock<MockRtpRtcp> rtp;
|
|
|
|
|
std::vector<RtpRtcp*> modules = {&rtp};
|
|
|
|
|
PayloadRouter router(modules, {kSsrc1}, kPayloadType, {});
|
|
|
|
|
router.SetActive(true);
|
|
|
|
|
|
|
|
|
|
codec_info_.codecType = kVideoCodecVP9;
|
|
|
|
|
codec_info_.codecSpecific.VP9.picture_id = kPictureId;
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(rtp, SendOutgoingData(_, _, _, _, _, _, nullptr, _, _))
|
|
|
|
|
.WillOnce(Invoke([](Unused, Unused, Unused, Unused, Unused, Unused,
|
|
|
|
|
Unused, const RTPVideoHeader* header, Unused) {
|
|
|
|
|
EXPECT_EQ(kRtpVideoVp9, header->codec);
|
|
|
|
|
EXPECT_EQ(kPictureId, header->codecHeader.VP9.picture_id);
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(EncodedImageCallback::Result::OK,
|
|
|
|
|
router.OnEncodedImage(image_, &codec_info_, nullptr).error);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 13:10:19 +00:00
|
|
|
} // namespace webrtc
|