sprang | 429600d | 2017-01-26 06:12:26 -0800 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/video_coding/include/video_codec_initializer.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 12 | |
| 13 | #include <stddef.h> |
| 14 | #include <stdint.h> |
| 15 | #include <memory> |
| 16 | |
| 17 | #include "absl/types/optional.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 18 | #include "api/scoped_refptr.h" |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 19 | #include "api/video/builtin_video_bitrate_allocator_factory.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 20 | #include "api/video/video_bitrate_allocation.h" |
| 21 | #include "api/video/video_bitrate_allocator.h" |
| 22 | #include "api/video/video_bitrate_allocator_factory.h" |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 23 | #include "api/video_codecs/video_encoder.h" |
Erik Språng | 4529fbc | 2018-10-12 10:30:31 +0200 | [diff] [blame] | 24 | #include "api/video_codecs/vp8_temporal_layers.h" |
Elad Alon | cde8ab2 | 2019-03-20 11:56:20 +0100 | [diff] [blame] | 25 | #include "api/video_codecs/vp8_temporal_layers_factory.h" |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 26 | #include "modules/video_coding/codecs/vp9/include/vp9_globals.h" |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 27 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "rtc_base/ref_counted_object.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "test/gtest.h" |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 30 | |
| 31 | namespace webrtc { |
| 32 | |
| 33 | namespace { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 34 | static const int kDefaultWidth = 1280; |
| 35 | static const int kDefaultHeight = 720; |
| 36 | static const int kDefaultFrameRate = 30; |
| 37 | static const uint32_t kDefaultMinBitrateBps = 60000; |
| 38 | static const uint32_t kDefaultTargetBitrateBps = 2000000; |
| 39 | static const uint32_t kDefaultMaxBitrateBps = 2000000; |
| 40 | static const uint32_t kDefaultMinTransmitBitrateBps = 400000; |
| 41 | static const int kDefaultMaxQp = 48; |
Erik Språng | 5e898d6 | 2018-07-06 16:32:20 +0200 | [diff] [blame] | 42 | static const uint32_t kScreenshareTl0BitrateBps = 200000; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 43 | static const uint32_t kScreenshareCodecTargetBitrateBps = 200000; |
| 44 | static const uint32_t kScreenshareDefaultFramerate = 5; |
| 45 | // Bitrates for the temporal layers of the higher screenshare simulcast stream. |
| 46 | static const uint32_t kHighScreenshareTl0Bps = 800000; |
| 47 | static const uint32_t kHighScreenshareTl1Bps = 1200000; |
| 48 | } // namespace |
| 49 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 50 | // TODO(sprang): Extend coverage to handle the rest of the codec initializer. |
| 51 | class VideoCodecInitializerTest : public ::testing::Test { |
| 52 | public: |
Niels Möller | f133856 | 2018-04-26 09:51:47 +0200 | [diff] [blame] | 53 | VideoCodecInitializerTest() {} |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 54 | virtual ~VideoCodecInitializerTest() {} |
| 55 | |
| 56 | protected: |
| 57 | void SetUpFor(VideoCodecType type, |
| 58 | int num_spatial_streams, |
| 59 | int num_temporal_streams, |
| 60 | bool screenshare) { |
| 61 | config_ = VideoEncoderConfig(); |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 62 | config_.codec_type = type; |
| 63 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 64 | if (screenshare) { |
| 65 | config_.min_transmit_bitrate_bps = kDefaultMinTransmitBitrateBps; |
| 66 | config_.content_type = VideoEncoderConfig::ContentType::kScreen; |
| 67 | } |
| 68 | |
| 69 | if (type == VideoCodecType::kVideoCodecVP8) { |
| 70 | config_.number_of_streams = num_spatial_streams; |
| 71 | VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings(); |
| 72 | vp8_settings.numberOfTemporalLayers = num_temporal_streams; |
| 73 | config_.encoder_specific_settings = new rtc::RefCountedObject< |
| 74 | webrtc::VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings); |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 75 | } else if (type == VideoCodecType::kVideoCodecVP9) { |
| 76 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
| 77 | vp9_settings.numberOfSpatialLayers = num_spatial_streams; |
| 78 | vp9_settings.numberOfTemporalLayers = num_temporal_streams; |
| 79 | config_.encoder_specific_settings = new rtc::RefCountedObject< |
| 80 | webrtc::VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
| 81 | } else if (type != VideoCodecType::kVideoCodecMultiplex) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 82 | ADD_FAILURE() << "Unexpected codec type: " << type; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | bool InitializeCodec() { |
| 87 | codec_out_ = VideoCodec(); |
Elad Alon | cde8ab2 | 2019-03-20 11:56:20 +0100 | [diff] [blame] | 88 | frame_buffer_controller_.reset(); |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 89 | if (!VideoCodecInitializer::SetupCodec(config_, streams_, &codec_out_)) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 90 | return false; |
| 91 | } |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 92 | bitrate_allocator_ = CreateBuiltinVideoBitrateAllocatorFactory() |
| 93 | ->CreateVideoBitrateAllocator(codec_out_); |
| 94 | RTC_CHECK(bitrate_allocator_); |
Emircan Uysaler | d7ae3c3 | 2018-01-25 13:01:09 -0800 | [diff] [blame] | 95 | if (codec_out_.codecType == VideoCodecType::kVideoCodecMultiplex) |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 96 | return true; |
Erik Språng | 82fad3d | 2018-03-21 09:57:23 +0100 | [diff] [blame] | 97 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 98 | // Make sure temporal layers instances have been created. |
| 99 | if (codec_out_.codecType == VideoCodecType::kVideoCodecVP8) { |
Elad Alon | cde8ab2 | 2019-03-20 11:56:20 +0100 | [diff] [blame] | 100 | Vp8TemporalLayersFactory factory; |
| 101 | frame_buffer_controller_ = factory.Create(codec_out_); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 102 | } |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | VideoStream DefaultStream() { |
| 107 | VideoStream stream; |
| 108 | stream.width = kDefaultWidth; |
| 109 | stream.height = kDefaultHeight; |
| 110 | stream.max_framerate = kDefaultFrameRate; |
| 111 | stream.min_bitrate_bps = kDefaultMinBitrateBps; |
| 112 | stream.target_bitrate_bps = kDefaultTargetBitrateBps; |
| 113 | stream.max_bitrate_bps = kDefaultMaxBitrateBps; |
| 114 | stream.max_qp = kDefaultMaxQp; |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 115 | stream.num_temporal_layers = 1; |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 116 | stream.active = true; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 117 | return stream; |
| 118 | } |
| 119 | |
| 120 | VideoStream DefaultScreenshareStream() { |
| 121 | VideoStream stream = DefaultStream(); |
| 122 | stream.min_bitrate_bps = 30000; |
| 123 | stream.target_bitrate_bps = kScreenshareTl0BitrateBps; |
| 124 | stream.max_bitrate_bps = 1000000; |
| 125 | stream.max_framerate = kScreenshareDefaultFramerate; |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 126 | stream.num_temporal_layers = 2; |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 127 | stream.active = true; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 128 | return stream; |
| 129 | } |
| 130 | |
| 131 | // Input settings. |
| 132 | VideoEncoderConfig config_; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 133 | std::vector<VideoStream> streams_; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 134 | |
| 135 | // Output. |
| 136 | VideoCodec codec_out_; |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 137 | std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; |
Elad Alon | cde8ab2 | 2019-03-20 11:56:20 +0100 | [diff] [blame] | 138 | std::unique_ptr<Vp8FrameBufferController> frame_buffer_controller_; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | TEST_F(VideoCodecInitializerTest, SingleStreamVp8Screenshare) { |
| 142 | SetUpFor(VideoCodecType::kVideoCodecVP8, 1, 1, true); |
| 143 | streams_.push_back(DefaultStream()); |
| 144 | EXPECT_TRUE(InitializeCodec()); |
| 145 | |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 146 | VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation( |
| 147 | kDefaultTargetBitrateBps, kDefaultFrameRate); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 148 | EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams); |
| 149 | EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers); |
| 150 | EXPECT_EQ(kDefaultTargetBitrateBps, bitrate_allocation.get_sum_bps()); |
| 151 | } |
| 152 | |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 153 | TEST_F(VideoCodecInitializerTest, SingleStreamVp8ScreenshareInactive) { |
| 154 | SetUpFor(VideoCodecType::kVideoCodecVP8, 1, 1, true); |
| 155 | VideoStream inactive_stream = DefaultStream(); |
| 156 | inactive_stream.active = false; |
| 157 | streams_.push_back(inactive_stream); |
| 158 | EXPECT_TRUE(InitializeCodec()); |
| 159 | |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 160 | VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation( |
| 161 | kDefaultTargetBitrateBps, kDefaultFrameRate); |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 162 | EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams); |
| 163 | EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers); |
| 164 | EXPECT_EQ(0U, bitrate_allocation.get_sum_bps()); |
| 165 | } |
| 166 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 167 | TEST_F(VideoCodecInitializerTest, TemporalLayeredVp8Screenshare) { |
| 168 | SetUpFor(VideoCodecType::kVideoCodecVP8, 1, 2, true); |
| 169 | streams_.push_back(DefaultScreenshareStream()); |
| 170 | EXPECT_TRUE(InitializeCodec()); |
| 171 | |
| 172 | EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams); |
| 173 | EXPECT_EQ(2u, codec_out_.VP8()->numberOfTemporalLayers); |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 174 | VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation( |
| 175 | kScreenshareCodecTargetBitrateBps, kScreenshareDefaultFramerate); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 176 | EXPECT_EQ(kScreenshareCodecTargetBitrateBps, |
| 177 | bitrate_allocation.get_sum_bps()); |
| 178 | EXPECT_EQ(kScreenshareTl0BitrateBps, bitrate_allocation.GetBitrate(0, 0)); |
| 179 | } |
| 180 | |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 181 | TEST_F(VideoCodecInitializerTest, SimulcastVp8Screenshare) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 182 | SetUpFor(VideoCodecType::kVideoCodecVP8, 2, 1, true); |
| 183 | streams_.push_back(DefaultScreenshareStream()); |
| 184 | VideoStream video_stream = DefaultStream(); |
| 185 | video_stream.max_framerate = kScreenshareDefaultFramerate; |
| 186 | streams_.push_back(video_stream); |
| 187 | EXPECT_TRUE(InitializeCodec()); |
| 188 | |
| 189 | EXPECT_EQ(2u, codec_out_.numberOfSimulcastStreams); |
| 190 | EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers); |
| 191 | const uint32_t max_bitrate_bps = |
| 192 | streams_[0].target_bitrate_bps + streams_[1].max_bitrate_bps; |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 193 | VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation( |
| 194 | max_bitrate_bps, kScreenshareDefaultFramerate); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 195 | EXPECT_EQ(max_bitrate_bps, bitrate_allocation.get_sum_bps()); |
| 196 | EXPECT_EQ(static_cast<uint32_t>(streams_[0].target_bitrate_bps), |
| 197 | bitrate_allocation.GetSpatialLayerSum(0)); |
| 198 | EXPECT_EQ(static_cast<uint32_t>(streams_[1].max_bitrate_bps), |
| 199 | bitrate_allocation.GetSpatialLayerSum(1)); |
| 200 | } |
| 201 | |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 202 | // Tests that when a video stream is inactive, then the bitrate allocation will |
| 203 | // be 0 for that stream. |
| 204 | TEST_F(VideoCodecInitializerTest, SimulcastVp8ScreenshareInactive) { |
| 205 | SetUpFor(VideoCodecType::kVideoCodecVP8, 2, 1, true); |
| 206 | streams_.push_back(DefaultScreenshareStream()); |
| 207 | VideoStream inactive_video_stream = DefaultStream(); |
| 208 | inactive_video_stream.active = false; |
| 209 | inactive_video_stream.max_framerate = kScreenshareDefaultFramerate; |
| 210 | streams_.push_back(inactive_video_stream); |
| 211 | EXPECT_TRUE(InitializeCodec()); |
| 212 | |
| 213 | EXPECT_EQ(2u, codec_out_.numberOfSimulcastStreams); |
| 214 | EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers); |
| 215 | const uint32_t target_bitrate = |
| 216 | streams_[0].target_bitrate_bps + streams_[1].target_bitrate_bps; |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 217 | VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation( |
| 218 | target_bitrate, kScreenshareDefaultFramerate); |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 219 | EXPECT_EQ(static_cast<uint32_t>(streams_[0].max_bitrate_bps), |
| 220 | bitrate_allocation.get_sum_bps()); |
| 221 | EXPECT_EQ(static_cast<uint32_t>(streams_[0].max_bitrate_bps), |
| 222 | bitrate_allocation.GetSpatialLayerSum(0)); |
| 223 | EXPECT_EQ(0U, bitrate_allocation.GetSpatialLayerSum(1)); |
| 224 | } |
| 225 | |
| 226 | TEST_F(VideoCodecInitializerTest, HighFpsSimulcastVp8Screenshare) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 227 | // Two simulcast streams, the lower one using legacy settings (two temporal |
| 228 | // streams, 5fps), the higher one using 3 temporal streams and 30fps. |
| 229 | SetUpFor(VideoCodecType::kVideoCodecVP8, 2, 3, true); |
| 230 | streams_.push_back(DefaultScreenshareStream()); |
| 231 | VideoStream video_stream = DefaultStream(); |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 232 | video_stream.num_temporal_layers = 3; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 233 | streams_.push_back(video_stream); |
| 234 | EXPECT_TRUE(InitializeCodec()); |
| 235 | |
| 236 | EXPECT_EQ(2u, codec_out_.numberOfSimulcastStreams); |
| 237 | EXPECT_EQ(3u, codec_out_.VP8()->numberOfTemporalLayers); |
| 238 | const uint32_t max_bitrate_bps = |
| 239 | streams_[0].target_bitrate_bps + streams_[1].max_bitrate_bps; |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 240 | VideoBitrateAllocation bitrate_allocation = |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 241 | bitrate_allocator_->GetAllocation(max_bitrate_bps, kDefaultFrameRate); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 242 | EXPECT_EQ(max_bitrate_bps, bitrate_allocation.get_sum_bps()); |
| 243 | EXPECT_EQ(static_cast<uint32_t>(streams_[0].target_bitrate_bps), |
| 244 | bitrate_allocation.GetSpatialLayerSum(0)); |
| 245 | EXPECT_EQ(static_cast<uint32_t>(streams_[1].max_bitrate_bps), |
| 246 | bitrate_allocation.GetSpatialLayerSum(1)); |
| 247 | EXPECT_EQ(kHighScreenshareTl0Bps, bitrate_allocation.GetBitrate(1, 0)); |
| 248 | EXPECT_EQ(kHighScreenshareTl1Bps - kHighScreenshareTl0Bps, |
| 249 | bitrate_allocation.GetBitrate(1, 1)); |
| 250 | } |
| 251 | |
Emircan Uysaler | d7ae3c3 | 2018-01-25 13:01:09 -0800 | [diff] [blame] | 252 | TEST_F(VideoCodecInitializerTest, SingleStreamMultiplexCodec) { |
| 253 | SetUpFor(VideoCodecType::kVideoCodecMultiplex, 1, 1, true); |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 254 | streams_.push_back(DefaultStream()); |
| 255 | EXPECT_TRUE(InitializeCodec()); |
| 256 | } |
| 257 | |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 258 | TEST_F(VideoCodecInitializerTest, Vp9SvcDefaultLayering) { |
| 259 | SetUpFor(VideoCodecType::kVideoCodecVP9, 3, 3, false); |
| 260 | VideoStream stream = DefaultStream(); |
| 261 | stream.num_temporal_layers = 3; |
| 262 | streams_.push_back(stream); |
| 263 | |
| 264 | EXPECT_TRUE(InitializeCodec()); |
| 265 | EXPECT_EQ(codec_out_.VP9()->numberOfSpatialLayers, 3u); |
| 266 | EXPECT_EQ(codec_out_.VP9()->numberOfTemporalLayers, 3u); |
| 267 | } |
| 268 | |
| 269 | TEST_F(VideoCodecInitializerTest, Vp9SvcAdjustedLayering) { |
| 270 | SetUpFor(VideoCodecType::kVideoCodecVP9, 3, 3, false); |
| 271 | VideoStream stream = DefaultStream(); |
| 272 | stream.num_temporal_layers = 3; |
| 273 | // Set resolution which is only enough to produce 2 spatial layers. |
| 274 | stream.width = kMinVp9SpatialLayerWidth * 2; |
| 275 | stream.height = kMinVp9SpatialLayerHeight * 2; |
| 276 | |
| 277 | streams_.push_back(stream); |
| 278 | |
| 279 | EXPECT_TRUE(InitializeCodec()); |
| 280 | EXPECT_EQ(codec_out_.VP9()->numberOfSpatialLayers, 2u); |
| 281 | } |
| 282 | |
Sergey Silkin | fafeac3 | 2018-04-13 16:36:39 +0200 | [diff] [blame] | 283 | TEST_F(VideoCodecInitializerTest, |
| 284 | Vp9SingleSpatialLayerMaxBitrateIsEqualToCodecMaxBitrate) { |
| 285 | SetUpFor(VideoCodecType::kVideoCodecVP9, 1, 3, false); |
| 286 | VideoStream stream = DefaultStream(); |
| 287 | stream.num_temporal_layers = 3; |
| 288 | streams_.push_back(stream); |
| 289 | |
| 290 | EXPECT_TRUE(InitializeCodec()); |
| 291 | EXPECT_EQ(codec_out_.spatialLayers[0].maxBitrate, |
| 292 | kDefaultMaxBitrateBps / 1000); |
| 293 | } |
| 294 | |
Sergey Silkin | 3312092 | 2018-11-28 13:32:13 +0100 | [diff] [blame] | 295 | TEST_F(VideoCodecInitializerTest, |
Ilya Nikolaevskiy | 9ef5e05 | 2019-03-05 10:08:35 +0100 | [diff] [blame] | 296 | Vp9SingleSpatialLayerTargetBitrateIsEqualToCodecMaxBitrate) { |
| 297 | SetUpFor(VideoCodecType::kVideoCodecVP9, 1, 1, true); |
| 298 | VideoStream stream = DefaultStream(); |
| 299 | stream.num_temporal_layers = 1; |
| 300 | streams_.push_back(stream); |
| 301 | |
| 302 | EXPECT_TRUE(InitializeCodec()); |
| 303 | EXPECT_EQ(codec_out_.spatialLayers[0].targetBitrate, |
| 304 | kDefaultMaxBitrateBps / 1000); |
| 305 | } |
| 306 | |
| 307 | TEST_F(VideoCodecInitializerTest, |
Sergey Silkin | 3312092 | 2018-11-28 13:32:13 +0100 | [diff] [blame] | 308 | Vp9KeepBitrateLimitsIfNumberOfSpatialLayersIsReducedToOne) { |
| 309 | // Request 3 spatial layers for 320x180 input. Actual number of layers will be |
| 310 | // reduced to 1 due to low input resolution but SVC bitrate limits should be |
| 311 | // applied. |
| 312 | SetUpFor(VideoCodecType::kVideoCodecVP9, 3, 3, false); |
| 313 | VideoStream stream = DefaultStream(); |
| 314 | stream.width = 320; |
| 315 | stream.height = 180; |
| 316 | stream.num_temporal_layers = 3; |
| 317 | streams_.push_back(stream); |
| 318 | |
| 319 | EXPECT_TRUE(InitializeCodec()); |
| 320 | EXPECT_LT(codec_out_.spatialLayers[0].maxBitrate, |
| 321 | kDefaultMaxBitrateBps / 1000); |
| 322 | } |
| 323 | |
Sergey Silkin | 8b9b5f9 | 2018-12-10 09:28:53 +0100 | [diff] [blame] | 324 | TEST_F(VideoCodecInitializerTest, Vp9DeactivateLayers) { |
| 325 | SetUpFor(VideoCodecType::kVideoCodecVP9, 3, 1, false); |
| 326 | VideoStream stream = DefaultStream(); |
| 327 | streams_.push_back(stream); |
| 328 | |
| 329 | config_.simulcast_layers.resize(3); |
| 330 | |
| 331 | // Activate all layers. |
| 332 | config_.simulcast_layers[0].active = true; |
| 333 | config_.simulcast_layers[1].active = true; |
| 334 | config_.simulcast_layers[2].active = true; |
| 335 | EXPECT_TRUE(InitializeCodec()); |
| 336 | EXPECT_TRUE(codec_out_.spatialLayers[0].active); |
| 337 | EXPECT_TRUE(codec_out_.spatialLayers[1].active); |
| 338 | EXPECT_TRUE(codec_out_.spatialLayers[2].active); |
| 339 | |
| 340 | // Deactivate top layer. |
| 341 | config_.simulcast_layers[0].active = false; |
| 342 | EXPECT_TRUE(InitializeCodec()); |
| 343 | EXPECT_TRUE(codec_out_.spatialLayers[0].active); |
| 344 | EXPECT_TRUE(codec_out_.spatialLayers[1].active); |
| 345 | EXPECT_FALSE(codec_out_.spatialLayers[2].active); |
| 346 | |
| 347 | // Deactivate middle layer. |
| 348 | config_.simulcast_layers[0].active = true; |
| 349 | config_.simulcast_layers[1].active = false; |
| 350 | EXPECT_TRUE(InitializeCodec()); |
| 351 | EXPECT_TRUE(codec_out_.spatialLayers[0].active); |
| 352 | EXPECT_FALSE(codec_out_.spatialLayers[1].active); |
| 353 | EXPECT_TRUE(codec_out_.spatialLayers[2].active); |
| 354 | } |
| 355 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 356 | } // namespace webrtc |