2017-10-25 10:04:54 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 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.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "media/engine/vp8_encoder_simulcast_proxy.h"
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2017-11-17 14:44:55 +01:00
|
|
|
#include "api/test/mock_video_encoder_factory.h"
|
2017-10-25 10:04:54 +02:00
|
|
|
#include "media/engine/webrtcvideoencoderfactory.h"
|
|
|
|
|
#include "modules/video_coding/codecs/vp8/temporal_layers.h"
|
|
|
|
|
#include "modules/video_coding/include/video_codec_interface.h"
|
|
|
|
|
#include "test/gmock.h"
|
|
|
|
|
#include "test/gtest.h"
|
|
|
|
|
#include "test/video_codec_settings.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace testing {
|
|
|
|
|
|
|
|
|
|
using ::testing::Return;
|
|
|
|
|
using ::testing::_;
|
|
|
|
|
using ::testing::NiceMock;
|
|
|
|
|
|
|
|
|
|
class MockEncoder : public VideoEncoder {
|
|
|
|
|
public:
|
|
|
|
|
// TODO(nisse): Valid overrides commented out, because the gmock
|
|
|
|
|
// methods don't use any override declarations, and we want to avoid
|
|
|
|
|
// warnings from -Winconsistent-missing-override. See
|
|
|
|
|
// http://crbug.com/428099.
|
|
|
|
|
MockEncoder() {}
|
|
|
|
|
virtual ~MockEncoder() {}
|
|
|
|
|
|
|
|
|
|
MOCK_METHOD3(InitEncode,
|
|
|
|
|
int32_t(const VideoCodec* codec_settings,
|
|
|
|
|
int32_t number_of_cores,
|
|
|
|
|
size_t max_payload_size));
|
|
|
|
|
|
|
|
|
|
MOCK_METHOD1(RegisterEncodeCompleteCallback, int32_t(EncodedImageCallback*));
|
|
|
|
|
|
|
|
|
|
MOCK_METHOD0(Release, int32_t());
|
|
|
|
|
|
|
|
|
|
MOCK_METHOD3(
|
|
|
|
|
Encode,
|
|
|
|
|
int32_t(const VideoFrame& inputImage,
|
|
|
|
|
const CodecSpecificInfo* codecSpecificInfo,
|
|
|
|
|
const std::vector<FrameType>* frame_types) /* override */);
|
|
|
|
|
|
|
|
|
|
MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt));
|
|
|
|
|
|
|
|
|
|
MOCK_CONST_METHOD0(ImplementationName, const char*());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST(VP8EncoderSimulcastProxy, ChoosesCorrectImplementation) {
|
|
|
|
|
const std::string kImplementationName = "Fake";
|
|
|
|
|
const std::string kSimulcastAdaptedImplementationName =
|
|
|
|
|
"SimulcastEncoderAdapter (Fake, Fake, Fake)";
|
|
|
|
|
VideoCodec codec_settings;
|
|
|
|
|
webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings);
|
|
|
|
|
TemporalLayersFactory tl_factory;
|
|
|
|
|
codec_settings.VP8()->tl_factory = &tl_factory;
|
|
|
|
|
codec_settings.simulcastStream[0] = {
|
|
|
|
|
test::kTestWidth, test::kTestHeight, 2, 2000, 1000, 1000, 56};
|
|
|
|
|
codec_settings.simulcastStream[1] = {
|
|
|
|
|
test::kTestWidth, test::kTestHeight, 2, 3000, 1000, 1000, 56};
|
|
|
|
|
codec_settings.simulcastStream[2] = {
|
|
|
|
|
test::kTestWidth, test::kTestHeight, 2, 5000, 1000, 1000, 56};
|
|
|
|
|
codec_settings.numberOfSimulcastStreams = 3;
|
|
|
|
|
|
2017-11-17 14:44:55 +01:00
|
|
|
NiceMock<MockEncoder>* mock_encoder = new NiceMock<MockEncoder>();
|
|
|
|
|
NiceMock<MockVideoEncoderFactory> simulcast_factory;
|
2017-10-25 10:04:54 +02:00
|
|
|
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(*mock_encoder, InitEncode(_, _, _))
|
2017-10-25 10:04:54 +02:00
|
|
|
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(*mock_encoder, ImplementationName())
|
2017-10-25 10:04:54 +02:00
|
|
|
.WillRepeatedly(Return(kImplementationName.c_str()));
|
|
|
|
|
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(simulcast_factory, CreateVideoEncoderProxy(_))
|
2017-10-25 10:04:54 +02:00
|
|
|
.Times(1)
|
2017-11-17 14:44:55 +01:00
|
|
|
.WillOnce(Return(mock_encoder));
|
2017-10-25 10:04:54 +02:00
|
|
|
|
|
|
|
|
VP8EncoderSimulcastProxy simulcast_enabled_proxy(&simulcast_factory);
|
|
|
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
|
|
|
|
|
simulcast_enabled_proxy.InitEncode(&codec_settings, 4, 1200));
|
|
|
|
|
EXPECT_EQ(kImplementationName, simulcast_enabled_proxy.ImplementationName());
|
|
|
|
|
|
2017-11-17 14:44:55 +01:00
|
|
|
NiceMock<MockEncoder>* mock_encoder1 = new NiceMock<MockEncoder>();
|
|
|
|
|
NiceMock<MockEncoder>* mock_encoder2 = new NiceMock<MockEncoder>();
|
|
|
|
|
NiceMock<MockEncoder>* mock_encoder3 = new NiceMock<MockEncoder>();
|
|
|
|
|
NiceMock<MockEncoder>* mock_encoder4 = new NiceMock<MockEncoder>();
|
|
|
|
|
NiceMock<MockVideoEncoderFactory> nonsimulcast_factory;
|
2017-10-25 10:04:54 +02:00
|
|
|
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(*mock_encoder1, InitEncode(_, _, _))
|
2017-10-25 10:04:54 +02:00
|
|
|
.WillOnce(
|
|
|
|
|
Return(WEBRTC_VIDEO_CODEC_ERR_SIMULCAST_PARAMETERS_NOT_SUPPORTED));
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(*mock_encoder1, ImplementationName())
|
2017-10-25 10:04:54 +02:00
|
|
|
.WillRepeatedly(Return(kImplementationName.c_str()));
|
|
|
|
|
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(*mock_encoder2, InitEncode(_, _, _))
|
2017-10-25 10:04:54 +02:00
|
|
|
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(*mock_encoder2, ImplementationName())
|
2017-10-25 10:04:54 +02:00
|
|
|
.WillRepeatedly(Return(kImplementationName.c_str()));
|
|
|
|
|
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(*mock_encoder3, InitEncode(_, _, _))
|
2017-10-25 10:04:54 +02:00
|
|
|
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(*mock_encoder3, ImplementationName())
|
2017-10-25 10:04:54 +02:00
|
|
|
.WillRepeatedly(Return(kImplementationName.c_str()));
|
|
|
|
|
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(*mock_encoder4, InitEncode(_, _, _))
|
2017-10-25 10:04:54 +02:00
|
|
|
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(*mock_encoder4, ImplementationName())
|
2017-10-25 10:04:54 +02:00
|
|
|
.WillRepeatedly(Return(kImplementationName.c_str()));
|
|
|
|
|
|
2017-11-17 14:44:55 +01:00
|
|
|
EXPECT_CALL(nonsimulcast_factory, CreateVideoEncoderProxy(_))
|
2017-10-25 10:04:54 +02:00
|
|
|
.Times(4)
|
2017-11-17 14:44:55 +01:00
|
|
|
.WillOnce(Return(mock_encoder1))
|
|
|
|
|
.WillOnce(Return(mock_encoder2))
|
|
|
|
|
.WillOnce(Return(mock_encoder3))
|
|
|
|
|
.WillOnce(Return(mock_encoder4));
|
2017-10-25 10:04:54 +02:00
|
|
|
|
|
|
|
|
VP8EncoderSimulcastProxy simulcast_disabled_proxy(&nonsimulcast_factory);
|
|
|
|
|
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
|
|
|
|
|
simulcast_disabled_proxy.InitEncode(&codec_settings, 4, 1200));
|
|
|
|
|
EXPECT_EQ(kSimulcastAdaptedImplementationName,
|
|
|
|
|
simulcast_disabled_proxy.ImplementationName());
|
|
|
|
|
|
|
|
|
|
// Cleanup.
|
|
|
|
|
simulcast_enabled_proxy.Release();
|
|
|
|
|
simulcast_disabled_proxy.Release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace testing
|
|
|
|
|
} // namespace webrtc
|