Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: webrtc/modules/video_coding/video_codec_initializer_unittest.cc

Issue 2641133002: Reland of Add experimental simulcast screen content mode (Closed)
Patch Set: Missing file Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 #include "webrtc/common_video/include/video_bitrate_allocator.h"
12 #include "webrtc/common_types.h"
13 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
14 #include "webrtc/modules/video_coding/include/video_codec_initializer.h"
15 #include "webrtc/test/gtest.h"
16 #include "webrtc/video_encoder.h"
17
18 namespace webrtc {
19
20 namespace {
21 static const char* kVp8PayloadName = "VP8";
22 static const int kVp8PayloadType = 100;
23 static const int kDefaultWidth = 1280;
24 static const int kDefaultHeight = 720;
25 static const int kDefaultFrameRate = 30;
26 static const uint32_t kDefaultMinBitrateBps = 60000;
27 static const uint32_t kDefaultTargetBitrateBps = 2000000;
28 static const uint32_t kDefaultMaxBitrateBps = 2000000;
29 static const uint32_t kDefaultMinTransmitBitrateBps = 400000;
30 static const int kDefaultMaxQp = 48;
31 static const uint32_t kScreenshareTl0BitrateBps = 100000;
32 static const uint32_t kScreenshareCodecTargetBitrateBps = 200000;
33 static const uint32_t kScreenshareDefaultFramerate = 5;
34 // Bitrates for the temporal layers of the higher screenshare simulcast stream.
35 static const uint32_t kHighScreenshareTl0Bps = 800000;
36 static const uint32_t kHighScreenshareTl1Bps = 1200000;
37 } // namespace
38
39 /*
40 * static bool SetupCodec(
41 const VideoEncoderConfig& config,
42 const VideoSendStream::Config::EncoderSettings settings,
43 const std::vector<VideoStream>& streams,
44 bool nack_enabled,
45 VideoCodec* codec,
46 std::unique_ptr<VideoBitrateAllocator>* bitrate_allocator);
47
48 // Create a bitrate allocator for the specified codec. |tl_factory| is
49 // optional, if it is populated, ownership of that instance will be
50 // transferred to the VideoBitrateAllocator instance.
51 static std::unique_ptr<VideoBitrateAllocator> CreateBitrateAllocator(
52 const VideoCodec& codec,
53 std::unique_ptr<TemporalLayersFactory> tl_factory);
54 */
55
56 // TODO(sprang): Extend coverage to handle the rest of the codec initializer.
57 class VideoCodecInitializerTest : public ::testing::Test {
58 public:
59 VideoCodecInitializerTest() : nack_enabled_(false) {}
60 virtual ~VideoCodecInitializerTest() {}
61
62 protected:
63 void SetUpFor(VideoCodecType type,
64 int num_spatial_streams,
65 int num_temporal_streams,
66 bool screenshare) {
67 config_ = VideoEncoderConfig();
68 if (screenshare) {
69 config_.min_transmit_bitrate_bps = kDefaultMinTransmitBitrateBps;
70 config_.content_type = VideoEncoderConfig::ContentType::kScreen;
71 }
72
73 if (type == VideoCodecType::kVideoCodecVP8) {
74 config_.number_of_streams = num_spatial_streams;
75 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
76 vp8_settings.numberOfTemporalLayers = num_temporal_streams;
77 config_.encoder_specific_settings = new rtc::RefCountedObject<
78 webrtc::VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
79 settings_.payload_name = kVp8PayloadName;
80 settings_.payload_type = kVp8PayloadType;
81 } else {
82 ADD_FAILURE() << "Unexpected codec type: " << type;
83 }
84 }
85
86 bool InitializeCodec() {
87 codec_out_ = VideoCodec();
88 bitrate_allocator_out_.reset();
89 if (!VideoCodecInitializer::SetupCodec(config_, settings_, streams_,
90 nack_enabled_, &codec_out_,
91 &bitrate_allocator_out_)) {
92 return false;
93 }
94
95 // Make sure temporal layers instances have been created (owned by the
96 // bitrate_allocator_out_ instance, so no need to capture ptr).
97 if (codec_out_.codecType == VideoCodecType::kVideoCodecVP8) {
98 if (!codec_out_.VP8()->tl_factory)
99 return false;
100
101 for (int i = 0; i < codec_out_.numberOfSimulcastStreams; ++i) {
102 codec_out_.VP8()->tl_factory->Create(
103 i, streams_[i].temporal_layer_thresholds_bps.size() + 1, 0);
104 }
105 }
106 return true;
107 }
108
109 VideoStream DefaultStream() {
110 VideoStream stream;
111 stream.width = kDefaultWidth;
112 stream.height = kDefaultHeight;
113 stream.max_framerate = kDefaultFrameRate;
114 stream.min_bitrate_bps = kDefaultMinBitrateBps;
115 stream.target_bitrate_bps = kDefaultTargetBitrateBps;
116 stream.max_bitrate_bps = kDefaultMaxBitrateBps;
117 stream.max_qp = kDefaultMaxQp;
118 return stream;
119 }
120
121 VideoStream DefaultScreenshareStream() {
122 VideoStream stream = DefaultStream();
123 stream.min_bitrate_bps = 30000;
124 stream.target_bitrate_bps = kScreenshareTl0BitrateBps;
125 stream.max_bitrate_bps = 1000000;
126 stream.max_framerate = kScreenshareDefaultFramerate;
127 stream.temporal_layer_thresholds_bps.push_back(kScreenshareTl0BitrateBps);
128 return stream;
129 }
130
131 // Input settings.
132 VideoEncoderConfig config_;
133 VideoSendStream::Config::EncoderSettings settings_;
134 std::vector<VideoStream> streams_;
135 bool nack_enabled_;
136
137 // Output.
138 VideoCodec codec_out_;
139 std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_out_;
140 };
141
142 TEST_F(VideoCodecInitializerTest, SingleStreamVp8Screenshare) {
143 SetUpFor(VideoCodecType::kVideoCodecVP8, 1, 1, true);
144 streams_.push_back(DefaultStream());
145 EXPECT_TRUE(InitializeCodec());
146
147 BitrateAllocation bitrate_allocation = bitrate_allocator_out_->GetAllocation(
148 kDefaultTargetBitrateBps, kDefaultFrameRate);
149 EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams);
150 EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers);
151 EXPECT_EQ(kDefaultTargetBitrateBps, bitrate_allocation.get_sum_bps());
152 }
153
154 TEST_F(VideoCodecInitializerTest, TemporalLayeredVp8Screenshare) {
155 SetUpFor(VideoCodecType::kVideoCodecVP8, 1, 2, true);
156 streams_.push_back(DefaultScreenshareStream());
157 EXPECT_TRUE(InitializeCodec());
158
159 EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams);
160 EXPECT_EQ(2u, codec_out_.VP8()->numberOfTemporalLayers);
161 BitrateAllocation bitrate_allocation = bitrate_allocator_out_->GetAllocation(
162 kScreenshareCodecTargetBitrateBps, kScreenshareDefaultFramerate);
163 EXPECT_EQ(kScreenshareCodecTargetBitrateBps,
164 bitrate_allocation.get_sum_bps());
165 EXPECT_EQ(kScreenshareTl0BitrateBps, bitrate_allocation.GetBitrate(0, 0));
166 }
167
168 TEST_F(VideoCodecInitializerTest, SimlucastVp8Screenshare) {
169 SetUpFor(VideoCodecType::kVideoCodecVP8, 2, 1, true);
170 streams_.push_back(DefaultScreenshareStream());
171 VideoStream video_stream = DefaultStream();
172 video_stream.max_framerate = kScreenshareDefaultFramerate;
173 streams_.push_back(video_stream);
174 EXPECT_TRUE(InitializeCodec());
175
176 EXPECT_EQ(2u, codec_out_.numberOfSimulcastStreams);
177 EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers);
178 const uint32_t max_bitrate_bps =
179 streams_[0].target_bitrate_bps + streams_[1].max_bitrate_bps;
180 BitrateAllocation bitrate_allocation = bitrate_allocator_out_->GetAllocation(
181 max_bitrate_bps, kScreenshareDefaultFramerate);
182 EXPECT_EQ(max_bitrate_bps, bitrate_allocation.get_sum_bps());
183 EXPECT_EQ(static_cast<uint32_t>(streams_[0].target_bitrate_bps),
184 bitrate_allocation.GetSpatialLayerSum(0));
185 EXPECT_EQ(static_cast<uint32_t>(streams_[1].max_bitrate_bps),
186 bitrate_allocation.GetSpatialLayerSum(1));
187 }
188
189 TEST_F(VideoCodecInitializerTest, HighFpsSimlucastVp8Screenshare) {
190 // Two simulcast streams, the lower one using legacy settings (two temporal
191 // streams, 5fps), the higher one using 3 temporal streams and 30fps.
192 SetUpFor(VideoCodecType::kVideoCodecVP8, 2, 3, true);
193 streams_.push_back(DefaultScreenshareStream());
194 VideoStream video_stream = DefaultStream();
195 video_stream.temporal_layer_thresholds_bps.push_back(kHighScreenshareTl0Bps);
196 video_stream.temporal_layer_thresholds_bps.push_back(kHighScreenshareTl1Bps);
197 streams_.push_back(video_stream);
198 EXPECT_TRUE(InitializeCodec());
199
200 EXPECT_EQ(2u, codec_out_.numberOfSimulcastStreams);
201 EXPECT_EQ(3u, codec_out_.VP8()->numberOfTemporalLayers);
202 const uint32_t max_bitrate_bps =
203 streams_[0].target_bitrate_bps + streams_[1].max_bitrate_bps;
204 BitrateAllocation bitrate_allocation =
205 bitrate_allocator_out_->GetAllocation(max_bitrate_bps, kDefaultFrameRate);
206 EXPECT_EQ(max_bitrate_bps, bitrate_allocation.get_sum_bps());
207 EXPECT_EQ(static_cast<uint32_t>(streams_[0].target_bitrate_bps),
208 bitrate_allocation.GetSpatialLayerSum(0));
209 EXPECT_EQ(static_cast<uint32_t>(streams_[1].max_bitrate_bps),
210 bitrate_allocation.GetSpatialLayerSum(1));
211 EXPECT_EQ(kHighScreenshareTl0Bps, bitrate_allocation.GetBitrate(1, 0));
212 EXPECT_EQ(kHighScreenshareTl1Bps - kHighScreenshareTl0Bps,
213 bitrate_allocation.GetBitrate(1, 1));
214 }
215
216 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698