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