Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | */ |
| 11 | |
| 12 | #include "media/engine/encoder_simulcast_proxy.h" |
| 13 | #include <string> |
| 14 | |
Erik Språng | 9e79e6b | 2019-04-25 16:01:03 +0200 | [diff] [blame] | 15 | #include "api/test/mock_video_encoder.h" |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 16 | #include "api/test/mock_video_encoder_factory.h" |
| 17 | #include "api/video_codecs/vp8_temporal_layers.h" |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 18 | #include "modules/video_coding/include/video_codec_interface.h" |
| 19 | #include "test/gmock.h" |
| 20 | #include "test/gtest.h" |
| 21 | #include "test/video_codec_settings.h" |
| 22 | |
| 23 | namespace webrtc { |
| 24 | namespace testing { |
| 25 | |
| 26 | using ::testing::_; |
| 27 | using ::testing::NiceMock; |
| 28 | using ::testing::Return; |
| 29 | |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 30 | TEST(EncoderSimulcastProxy, ChoosesCorrectImplementation) { |
| 31 | const std::string kImplementationName = "Fake"; |
| 32 | const std::string kSimulcastAdaptedImplementationName = |
| 33 | "SimulcastEncoderAdapter (Fake, Fake, Fake)"; |
| 34 | VideoCodec codec_settings; |
| 35 | webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings); |
| 36 | codec_settings.simulcastStream[0] = {test::kTestWidth, |
| 37 | test::kTestHeight, |
| 38 | test::kTestFrameRate, |
| 39 | 2, |
| 40 | 2000, |
| 41 | 1000, |
| 42 | 1000, |
| 43 | 56}; |
| 44 | codec_settings.simulcastStream[1] = {test::kTestWidth, |
| 45 | test::kTestHeight, |
| 46 | test::kTestFrameRate, |
| 47 | 2, |
| 48 | 3000, |
| 49 | 1000, |
| 50 | 1000, |
| 51 | 56}; |
| 52 | codec_settings.simulcastStream[2] = {test::kTestWidth, |
| 53 | test::kTestHeight, |
| 54 | test::kTestFrameRate, |
| 55 | 2, |
| 56 | 5000, |
| 57 | 1000, |
| 58 | 1000, |
| 59 | 56}; |
| 60 | codec_settings.numberOfSimulcastStreams = 3; |
| 61 | |
Erik Språng | 9e79e6b | 2019-04-25 16:01:03 +0200 | [diff] [blame] | 62 | NiceMock<MockVideoEncoder>* mock_encoder = new NiceMock<MockVideoEncoder>(); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 63 | NiceMock<MockVideoEncoderFactory> simulcast_factory; |
| 64 | |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 65 | EXPECT_CALL(*mock_encoder, InitEncode(_, _, _)) |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 66 | .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); |
| 67 | VideoEncoder::EncoderInfo encoder_info; |
| 68 | encoder_info.implementation_name = kImplementationName; |
| 69 | EXPECT_CALL(*mock_encoder, GetEncoderInfo()) |
| 70 | .WillRepeatedly(Return(encoder_info)); |
| 71 | |
| 72 | EXPECT_CALL(simulcast_factory, CreateVideoEncoderProxy(_)) |
| 73 | .Times(1) |
| 74 | .WillOnce(Return(mock_encoder)); |
| 75 | |
| 76 | EncoderSimulcastProxy simulcast_enabled_proxy(&simulcast_factory, |
| 77 | SdpVideoFormat("VP8")); |
| 78 | EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 79 | simulcast_enabled_proxy.InitEncode(&codec_settings, 4, 1200)); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 80 | EXPECT_EQ(kImplementationName, |
| 81 | simulcast_enabled_proxy.GetEncoderInfo().implementation_name); |
| 82 | |
Erik Språng | 9e79e6b | 2019-04-25 16:01:03 +0200 | [diff] [blame] | 83 | NiceMock<MockVideoEncoder>* mock_encoder1 = new NiceMock<MockVideoEncoder>(); |
| 84 | NiceMock<MockVideoEncoder>* mock_encoder2 = new NiceMock<MockVideoEncoder>(); |
| 85 | NiceMock<MockVideoEncoder>* mock_encoder3 = new NiceMock<MockVideoEncoder>(); |
| 86 | NiceMock<MockVideoEncoder>* mock_encoder4 = new NiceMock<MockVideoEncoder>(); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 87 | NiceMock<MockVideoEncoderFactory> nonsimulcast_factory; |
| 88 | |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 89 | EXPECT_CALL(*mock_encoder1, InitEncode(_, _, _)) |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 90 | .WillOnce( |
| 91 | Return(WEBRTC_VIDEO_CODEC_ERR_SIMULCAST_PARAMETERS_NOT_SUPPORTED)); |
| 92 | EXPECT_CALL(*mock_encoder1, GetEncoderInfo()) |
| 93 | .WillRepeatedly(Return(encoder_info)); |
| 94 | |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 95 | EXPECT_CALL(*mock_encoder2, InitEncode(_, _, _)) |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 96 | .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); |
| 97 | EXPECT_CALL(*mock_encoder2, GetEncoderInfo()) |
| 98 | .WillRepeatedly(Return(encoder_info)); |
| 99 | |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 100 | EXPECT_CALL(*mock_encoder3, InitEncode(_, _, _)) |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 101 | .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); |
| 102 | EXPECT_CALL(*mock_encoder3, GetEncoderInfo()) |
| 103 | .WillRepeatedly(Return(encoder_info)); |
| 104 | |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 105 | EXPECT_CALL(*mock_encoder4, InitEncode(_, _, _)) |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 106 | .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); |
| 107 | EXPECT_CALL(*mock_encoder4, GetEncoderInfo()) |
| 108 | .WillRepeatedly(Return(encoder_info)); |
| 109 | |
| 110 | EXPECT_CALL(nonsimulcast_factory, CreateVideoEncoderProxy(_)) |
| 111 | .Times(4) |
| 112 | .WillOnce(Return(mock_encoder1)) |
| 113 | .WillOnce(Return(mock_encoder2)) |
| 114 | .WillOnce(Return(mock_encoder3)) |
| 115 | .WillOnce(Return(mock_encoder4)); |
| 116 | |
| 117 | EncoderSimulcastProxy simulcast_disabled_proxy(&nonsimulcast_factory, |
| 118 | SdpVideoFormat("VP8")); |
| 119 | EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 120 | simulcast_disabled_proxy.InitEncode(&codec_settings, 4, 1200)); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 121 | EXPECT_EQ(kSimulcastAdaptedImplementationName, |
| 122 | simulcast_disabled_proxy.GetEncoderInfo().implementation_name); |
| 123 | |
| 124 | // Cleanup. |
| 125 | simulcast_enabled_proxy.Release(); |
| 126 | simulcast_disabled_proxy.Release(); |
| 127 | } |
| 128 | |
| 129 | TEST(EncoderSimulcastProxy, ForwardsTrustedSetting) { |
Erik Språng | 9e79e6b | 2019-04-25 16:01:03 +0200 | [diff] [blame] | 130 | NiceMock<MockVideoEncoder>* mock_encoder = new NiceMock<MockVideoEncoder>(); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 131 | NiceMock<MockVideoEncoderFactory> simulcast_factory; |
| 132 | |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 133 | EXPECT_CALL(*mock_encoder, InitEncode(_, _, _)) |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 134 | .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); |
| 135 | |
| 136 | EXPECT_CALL(simulcast_factory, CreateVideoEncoderProxy(_)) |
| 137 | .Times(1) |
| 138 | .WillOnce(Return(mock_encoder)); |
| 139 | |
| 140 | EncoderSimulcastProxy simulcast_enabled_proxy(&simulcast_factory, |
| 141 | SdpVideoFormat("VP8")); |
| 142 | VideoCodec codec_settings; |
| 143 | webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings); |
| 144 | EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 145 | simulcast_enabled_proxy.InitEncode(&codec_settings, 4, 1200)); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 146 | |
| 147 | VideoEncoder::EncoderInfo info; |
| 148 | info.has_trusted_rate_controller = true; |
| 149 | EXPECT_CALL(*mock_encoder, GetEncoderInfo()).WillRepeatedly(Return(info)); |
| 150 | |
| 151 | EXPECT_TRUE( |
| 152 | simulcast_enabled_proxy.GetEncoderInfo().has_trusted_rate_controller); |
| 153 | } |
| 154 | |
| 155 | TEST(EncoderSimulcastProxy, ForwardsHardwareAccelerated) { |
Erik Språng | 9e79e6b | 2019-04-25 16:01:03 +0200 | [diff] [blame] | 156 | NiceMock<MockVideoEncoder>* mock_encoder = new NiceMock<MockVideoEncoder>(); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 157 | NiceMock<MockVideoEncoderFactory> simulcast_factory; |
| 158 | |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 159 | EXPECT_CALL(*mock_encoder, InitEncode(_, _, _)) |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 160 | .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); |
| 161 | |
| 162 | EXPECT_CALL(simulcast_factory, CreateVideoEncoderProxy(_)) |
| 163 | .Times(1) |
| 164 | .WillOnce(Return(mock_encoder)); |
| 165 | |
| 166 | EncoderSimulcastProxy simulcast_enabled_proxy(&simulcast_factory, |
| 167 | SdpVideoFormat("VP8")); |
| 168 | VideoCodec codec_settings; |
| 169 | webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings); |
| 170 | EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 171 | simulcast_enabled_proxy.InitEncode(&codec_settings, 4, 1200)); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 172 | |
| 173 | VideoEncoder::EncoderInfo info; |
| 174 | |
| 175 | info.is_hardware_accelerated = false; |
| 176 | EXPECT_CALL(*mock_encoder, GetEncoderInfo()).WillOnce(Return(info)); |
| 177 | EXPECT_FALSE( |
| 178 | simulcast_enabled_proxy.GetEncoderInfo().is_hardware_accelerated); |
| 179 | |
| 180 | info.is_hardware_accelerated = true; |
| 181 | EXPECT_CALL(*mock_encoder, GetEncoderInfo()).WillOnce(Return(info)); |
| 182 | EXPECT_TRUE(simulcast_enabled_proxy.GetEncoderInfo().is_hardware_accelerated); |
| 183 | } |
| 184 | |
| 185 | TEST(EncoderSimulcastProxy, ForwardsInternalSource) { |
Erik Språng | 9e79e6b | 2019-04-25 16:01:03 +0200 | [diff] [blame] | 186 | NiceMock<MockVideoEncoder>* mock_encoder = new NiceMock<MockVideoEncoder>(); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 187 | NiceMock<MockVideoEncoderFactory> simulcast_factory; |
| 188 | |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 189 | EXPECT_CALL(*mock_encoder, InitEncode(_, _, _)) |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 190 | .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK)); |
| 191 | |
| 192 | EXPECT_CALL(simulcast_factory, CreateVideoEncoderProxy(_)) |
| 193 | .Times(1) |
| 194 | .WillOnce(Return(mock_encoder)); |
| 195 | |
| 196 | EncoderSimulcastProxy simulcast_enabled_proxy(&simulcast_factory, |
| 197 | SdpVideoFormat("VP8")); |
| 198 | VideoCodec codec_settings; |
| 199 | webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings); |
| 200 | EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
Philip Eliasson | 49d661a | 2019-06-11 11:55:47 +0000 | [diff] [blame] | 201 | simulcast_enabled_proxy.InitEncode(&codec_settings, 4, 1200)); |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 202 | |
| 203 | VideoEncoder::EncoderInfo info; |
| 204 | |
| 205 | info.has_internal_source = false; |
| 206 | EXPECT_CALL(*mock_encoder, GetEncoderInfo()).WillOnce(Return(info)); |
| 207 | EXPECT_FALSE(simulcast_enabled_proxy.GetEncoderInfo().has_internal_source); |
| 208 | |
| 209 | info.has_internal_source = true; |
| 210 | EXPECT_CALL(*mock_encoder, GetEncoderInfo()).WillOnce(Return(info)); |
| 211 | EXPECT_TRUE(simulcast_enabled_proxy.GetEncoderInfo().has_internal_source); |
| 212 | } |
| 213 | |
| 214 | } // namespace testing |
| 215 | } // namespace webrtc |