OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include "third_party/googletest/src/include/gtest/gtest.h" | 12 #include "third_party/googletest/src/include/gtest/gtest.h" |
13 #include "test/codec_factory.h" | 13 #include "test/codec_factory.h" |
14 #include "test/decode_test_driver.h" | 14 #include "test/decode_test_driver.h" |
15 #include "test/i420_video_source.h" | 15 #include "test/i420_video_source.h" |
| 16 |
| 17 #include "vp9/decoder/vp9_decoder.h" |
| 18 |
16 #include "vpx/svc_context.h" | 19 #include "vpx/svc_context.h" |
17 #include "vpx/vp8cx.h" | 20 #include "vpx/vp8cx.h" |
18 #include "vpx/vpx_encoder.h" | 21 #include "vpx/vpx_encoder.h" |
19 | 22 |
20 namespace { | 23 namespace { |
21 | 24 |
22 using libvpx_test::CodecFactory; | 25 using libvpx_test::CodecFactory; |
23 using libvpx_test::Decoder; | 26 using libvpx_test::Decoder; |
| 27 using libvpx_test::DxDataIterator; |
24 using libvpx_test::VP9CodecFactory; | 28 using libvpx_test::VP9CodecFactory; |
25 | 29 |
26 class SvcTest : public ::testing::Test { | 30 class SvcTest : public ::testing::Test { |
27 protected: | 31 protected: |
28 static const uint32_t kWidth = 352; | 32 static const uint32_t kWidth = 352; |
29 static const uint32_t kHeight = 288; | 33 static const uint32_t kHeight = 288; |
30 | 34 |
31 SvcTest() | 35 SvcTest() |
32 : codec_iface_(0), | 36 : codec_iface_(0), |
33 test_file_name_("hantro_collage_w352h288.yuv"), | 37 test_file_name_("hantro_collage_w352h288.yuv"), |
(...skipping 21 matching lines...) Expand all Loading... |
55 codec_enc_.g_timebase.den = 60; | 59 codec_enc_.g_timebase.den = 60; |
56 codec_enc_.kf_min_dist = 100; | 60 codec_enc_.kf_min_dist = 100; |
57 codec_enc_.kf_max_dist = 100; | 61 codec_enc_.kf_max_dist = 100; |
58 | 62 |
59 vpx_codec_dec_cfg_t dec_cfg = {0}; | 63 vpx_codec_dec_cfg_t dec_cfg = {0}; |
60 VP9CodecFactory codec_factory; | 64 VP9CodecFactory codec_factory; |
61 decoder_ = codec_factory.CreateDecoder(dec_cfg, 0); | 65 decoder_ = codec_factory.CreateDecoder(dec_cfg, 0); |
62 } | 66 } |
63 | 67 |
64 virtual void TearDown() { | 68 virtual void TearDown() { |
| 69 ReleaseEncoder(); |
| 70 delete(decoder_); |
| 71 } |
| 72 |
| 73 void InitializeEncoder() { |
| 74 const vpx_codec_err_t res = |
| 75 vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
| 76 EXPECT_EQ(VPX_CODEC_OK, res); |
| 77 codec_initialized_ = true; |
| 78 } |
| 79 |
| 80 void ReleaseEncoder() { |
65 vpx_svc_release(&svc_); | 81 vpx_svc_release(&svc_); |
66 delete(decoder_); | |
67 if (codec_initialized_) vpx_codec_destroy(&codec_); | 82 if (codec_initialized_) vpx_codec_destroy(&codec_); |
| 83 codec_initialized_ = false; |
| 84 } |
| 85 |
| 86 void Pass1EncodeNFrames(const int n, const int layers, |
| 87 std::string *const stats_buf) { |
| 88 vpx_codec_err_t res; |
| 89 size_t stats_size = 0; |
| 90 const char *stats_data = NULL; |
| 91 |
| 92 ASSERT_GT(n, 0); |
| 93 ASSERT_GT(layers, 0); |
| 94 svc_.spatial_layers = layers; |
| 95 codec_enc_.g_pass = VPX_RC_FIRST_PASS; |
| 96 InitializeEncoder(); |
| 97 |
| 98 libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight, |
| 99 codec_enc_.g_timebase.den, |
| 100 codec_enc_.g_timebase.num, 0, 30); |
| 101 video.Begin(); |
| 102 |
| 103 for (int i = 0; i < n; ++i) { |
| 104 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
| 105 video.duration(), VPX_DL_GOOD_QUALITY); |
| 106 ASSERT_EQ(VPX_CODEC_OK, res); |
| 107 stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); |
| 108 EXPECT_GT(stats_size, 0U); |
| 109 stats_data = vpx_svc_get_rc_stats_buffer(&svc_); |
| 110 ASSERT_TRUE(stats_data != NULL); |
| 111 stats_buf->append(stats_data, stats_size); |
| 112 video.Next(); |
| 113 } |
| 114 |
| 115 // Flush encoder and test EOS packet |
| 116 res = vpx_svc_encode(&svc_, &codec_, NULL, video.pts(), |
| 117 video.duration(), VPX_DL_GOOD_QUALITY); |
| 118 stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); |
| 119 EXPECT_GT(stats_size, 0U); |
| 120 stats_data = vpx_svc_get_rc_stats_buffer(&svc_); |
| 121 ASSERT_TRUE(stats_data != NULL); |
| 122 stats_buf->append(stats_data, stats_size); |
| 123 |
| 124 ReleaseEncoder(); |
| 125 } |
| 126 |
| 127 void StoreFrames(const size_t max_frame_received, |
| 128 struct vpx_fixed_buf *const outputs, |
| 129 size_t *const frame_received) { |
| 130 size_t frame_size; |
| 131 while ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) { |
| 132 ASSERT_LT(*frame_received, max_frame_received); |
| 133 |
| 134 if (*frame_received == 0) { |
| 135 EXPECT_EQ(1, vpx_svc_is_keyframe(&svc_)); |
| 136 } |
| 137 |
| 138 outputs[*frame_received].buf = malloc(frame_size); |
| 139 ASSERT_TRUE(outputs[*frame_received].buf != NULL); |
| 140 memcpy(outputs[*frame_received].buf, vpx_svc_get_buffer(&svc_), |
| 141 frame_size); |
| 142 outputs[*frame_received].sz = frame_size; |
| 143 ++(*frame_received); |
| 144 } |
| 145 } |
| 146 |
| 147 void Pass2EncodeNFrames(std::string *const stats_buf, |
| 148 const int n, const int layers, |
| 149 struct vpx_fixed_buf *const outputs) { |
| 150 vpx_codec_err_t res; |
| 151 size_t frame_received = 0; |
| 152 |
| 153 ASSERT_TRUE(outputs != NULL); |
| 154 ASSERT_GT(n, 0); |
| 155 ASSERT_GT(layers, 0); |
| 156 svc_.spatial_layers = layers; |
| 157 codec_enc_.rc_target_bitrate = 500; |
| 158 if (codec_enc_.g_pass == VPX_RC_LAST_PASS) { |
| 159 ASSERT_TRUE(stats_buf != NULL); |
| 160 ASSERT_GT(stats_buf->size(), 0U); |
| 161 codec_enc_.rc_twopass_stats_in.buf = &(*stats_buf)[0]; |
| 162 codec_enc_.rc_twopass_stats_in.sz = stats_buf->size(); |
| 163 } |
| 164 InitializeEncoder(); |
| 165 |
| 166 libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight, |
| 167 codec_enc_.g_timebase.den, |
| 168 codec_enc_.g_timebase.num, 0, 30); |
| 169 video.Begin(); |
| 170 |
| 171 for (int i = 0; i < n; ++i) { |
| 172 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), |
| 173 video.duration(), VPX_DL_GOOD_QUALITY); |
| 174 ASSERT_EQ(VPX_CODEC_OK, res); |
| 175 StoreFrames(n, outputs, &frame_received); |
| 176 video.Next(); |
| 177 } |
| 178 |
| 179 // Flush Encoder |
| 180 res = vpx_svc_encode(&svc_, &codec_, NULL, 0, |
| 181 video.duration(), VPX_DL_GOOD_QUALITY); |
| 182 EXPECT_EQ(VPX_CODEC_OK, res); |
| 183 StoreFrames(n, outputs, &frame_received); |
| 184 |
| 185 EXPECT_EQ(frame_received, (size_t)n); |
| 186 |
| 187 ReleaseEncoder(); |
| 188 } |
| 189 |
| 190 void DecodeNFrames(const struct vpx_fixed_buf *const inputs, const int n) { |
| 191 int decoded_frames = 0; |
| 192 int received_frames = 0; |
| 193 |
| 194 ASSERT_TRUE(inputs != NULL); |
| 195 ASSERT_GT(n, 0); |
| 196 |
| 197 for (int i = 0; i < n; ++i) { |
| 198 ASSERT_TRUE(inputs[i].buf != NULL); |
| 199 ASSERT_GT(inputs[i].sz, 0U); |
| 200 const vpx_codec_err_t res_dec = |
| 201 decoder_->DecodeFrame(static_cast<const uint8_t *>(inputs[i].buf), |
| 202 inputs[i].sz); |
| 203 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); |
| 204 ++decoded_frames; |
| 205 |
| 206 DxDataIterator dec_iter = decoder_->GetDxData(); |
| 207 while (dec_iter.Next()) { |
| 208 ++received_frames; |
| 209 } |
| 210 } |
| 211 EXPECT_EQ(decoded_frames, n); |
| 212 EXPECT_EQ(received_frames, n); |
| 213 } |
| 214 |
| 215 void DropEnhancementLayers(struct vpx_fixed_buf *const inputs, |
| 216 const int num_super_frames, |
| 217 const int remained_layers) { |
| 218 ASSERT_TRUE(inputs != NULL); |
| 219 ASSERT_GT(num_super_frames, 0); |
| 220 ASSERT_GT(remained_layers, 0); |
| 221 |
| 222 for (int i = 0; i < num_super_frames; ++i) { |
| 223 uint32_t frame_sizes[8] = {0}; |
| 224 int frame_count = 0; |
| 225 int frames_found = 0; |
| 226 int frame; |
| 227 ASSERT_TRUE(inputs[i].buf != NULL); |
| 228 ASSERT_GT(inputs[i].sz, 0U); |
| 229 |
| 230 vpx_codec_err_t res = |
| 231 vp9_parse_superframe_index(static_cast<const uint8_t*>(inputs[i].buf), |
| 232 inputs[i].sz, frame_sizes, &frame_count, |
| 233 NULL, NULL); |
| 234 ASSERT_EQ(VPX_CODEC_OK, res); |
| 235 |
| 236 uint8_t *frame_data = static_cast<uint8_t *>(inputs[i].buf); |
| 237 uint8_t *frame_start = frame_data; |
| 238 for (frame = 0; frame < frame_count; ++frame) { |
| 239 // Looking for a visible frame |
| 240 if (frame_data[0] & 0x02) { |
| 241 ++frames_found; |
| 242 if (frames_found == remained_layers) |
| 243 break; |
| 244 } |
| 245 frame_data += frame_sizes[frame]; |
| 246 } |
| 247 ASSERT_LT(frame, frame_count); |
| 248 if (frame == frame_count - 1) |
| 249 continue; |
| 250 |
| 251 frame_data += frame_sizes[frame]; |
| 252 uint8_t marker = |
| 253 static_cast<const uint8_t *>(inputs[i].buf)[inputs[i].sz - 1]; |
| 254 const uint32_t mag = ((marker >> 3) & 0x3) + 1; |
| 255 const size_t index_sz = 2 + mag * frame_count; |
| 256 const size_t new_index_sz = 2 + mag * (frame + 1); |
| 257 marker &= 0x0f8; |
| 258 marker |= frame; |
| 259 frame_data[0] = marker; |
| 260 memcpy(frame_data + 1, frame_start + inputs[i].sz - index_sz + 1, |
| 261 new_index_sz - 2); |
| 262 frame_data[new_index_sz - 1] = marker; |
| 263 inputs[i].sz = frame_data - frame_start + new_index_sz; |
| 264 } |
| 265 } |
| 266 |
| 267 void FreeBitstreamBuffers(struct vpx_fixed_buf *const inputs, const int n) { |
| 268 ASSERT_TRUE(inputs != NULL); |
| 269 ASSERT_GT(n, 0); |
| 270 |
| 271 for (int i = 0; i < n; ++i) { |
| 272 free(inputs[i].buf); |
| 273 inputs[i].buf = NULL; |
| 274 inputs[i].sz = 0; |
| 275 } |
68 } | 276 } |
69 | 277 |
70 SvcContext svc_; | 278 SvcContext svc_; |
71 vpx_codec_ctx_t codec_; | 279 vpx_codec_ctx_t codec_; |
72 struct vpx_codec_enc_cfg codec_enc_; | 280 struct vpx_codec_enc_cfg codec_enc_; |
73 vpx_codec_iface_t *codec_iface_; | 281 vpx_codec_iface_t *codec_iface_; |
74 std::string test_file_name_; | 282 std::string test_file_name_; |
75 bool codec_initialized_; | 283 bool codec_initialized_; |
76 Decoder *decoder_; | 284 Decoder *decoder_; |
77 }; | 285 }; |
78 | 286 |
79 TEST_F(SvcTest, SvcInit) { | 287 TEST_F(SvcTest, SvcInit) { |
80 // test missing parameters | 288 // test missing parameters |
81 vpx_codec_err_t res = vpx_svc_init(NULL, &codec_, codec_iface_, &codec_enc_); | 289 vpx_codec_err_t res = vpx_svc_init(NULL, &codec_, codec_iface_, &codec_enc_); |
82 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 290 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
83 res = vpx_svc_init(&svc_, NULL, codec_iface_, &codec_enc_); | 291 res = vpx_svc_init(&svc_, NULL, codec_iface_, &codec_enc_); |
84 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 292 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
85 res = vpx_svc_init(&svc_, &codec_, NULL, &codec_enc_); | 293 res = vpx_svc_init(&svc_, &codec_, NULL, &codec_enc_); |
86 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 294 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
87 | 295 |
88 res = vpx_svc_init(&svc_, &codec_, codec_iface_, NULL); | 296 res = vpx_svc_init(&svc_, &codec_, codec_iface_, NULL); |
89 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 297 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
90 | 298 |
91 svc_.spatial_layers = 6; // too many layers | 299 svc_.spatial_layers = 6; // too many layers |
92 res = vpx_svc_init(&svc_, &codec_, codec_iface_, &codec_enc_); | 300 res = vpx_svc_init(&svc_, &codec_, codec_iface_, &codec_enc_); |
93 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 301 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
94 | 302 |
95 svc_.spatial_layers = 0; // use default layers | 303 svc_.spatial_layers = 0; // use default layers |
96 res = vpx_svc_init(&svc_, &codec_, codec_iface_, &codec_enc_); | 304 InitializeEncoder(); |
97 EXPECT_EQ(VPX_CODEC_OK, res); | |
98 codec_initialized_ = true; | |
99 EXPECT_EQ(VPX_SS_DEFAULT_LAYERS, svc_.spatial_layers); | 305 EXPECT_EQ(VPX_SS_DEFAULT_LAYERS, svc_.spatial_layers); |
100 } | 306 } |
101 | 307 |
102 TEST_F(SvcTest, InitTwoLayers) { | 308 TEST_F(SvcTest, InitTwoLayers) { |
103 svc_.spatial_layers = 2; | 309 svc_.spatial_layers = 2; |
104 vpx_svc_set_scale_factors(&svc_, "4/16,16*16"); // invalid scale values | 310 vpx_svc_set_scale_factors(&svc_, "4/16,16*16"); // invalid scale values |
105 vpx_codec_err_t res = vpx_svc_init(&svc_, &codec_, codec_iface_, &codec_enc_); | 311 vpx_codec_err_t res = vpx_svc_init(&svc_, &codec_, codec_iface_, &codec_enc_); |
106 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 312 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
107 | 313 |
108 vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); // valid scale values | 314 vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); // valid scale values |
109 res = vpx_svc_init(&svc_, &codec_, codec_iface_, &codec_enc_); | 315 InitializeEncoder(); |
110 EXPECT_EQ(VPX_CODEC_OK, res); | |
111 codec_initialized_ = true; | |
112 } | 316 } |
113 | 317 |
114 TEST_F(SvcTest, InvalidOptions) { | 318 TEST_F(SvcTest, InvalidOptions) { |
115 vpx_codec_err_t res = vpx_svc_set_options(&svc_, NULL); | 319 vpx_codec_err_t res = vpx_svc_set_options(&svc_, NULL); |
116 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 320 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
117 | 321 |
118 res = vpx_svc_set_options(&svc_, "not-an-option=1"); | 322 res = vpx_svc_set_options(&svc_, "not-an-option=1"); |
119 EXPECT_EQ(VPX_CODEC_OK, res); | 323 EXPECT_EQ(VPX_CODEC_OK, res); |
120 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 324 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
121 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 325 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
122 } | 326 } |
123 | 327 |
124 TEST_F(SvcTest, SetLayersOption) { | 328 TEST_F(SvcTest, SetLayersOption) { |
125 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "layers=3"); | 329 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "layers=3"); |
126 EXPECT_EQ(VPX_CODEC_OK, res); | 330 EXPECT_EQ(VPX_CODEC_OK, res); |
127 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 331 InitializeEncoder(); |
128 EXPECT_EQ(VPX_CODEC_OK, res); | |
129 codec_initialized_ = true; | |
130 EXPECT_EQ(3, svc_.spatial_layers); | 332 EXPECT_EQ(3, svc_.spatial_layers); |
131 } | 333 } |
132 | 334 |
133 TEST_F(SvcTest, SetMultipleOptions) { | 335 TEST_F(SvcTest, SetMultipleOptions) { |
134 vpx_codec_err_t res = | 336 vpx_codec_err_t res = |
135 vpx_svc_set_options(&svc_, "layers=2 scale-factors=1/3,2/3"); | 337 vpx_svc_set_options(&svc_, "layers=2 scale-factors=1/3,2/3"); |
136 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | |
137 EXPECT_EQ(VPX_CODEC_OK, res); | 338 EXPECT_EQ(VPX_CODEC_OK, res); |
138 codec_initialized_ = true; | 339 InitializeEncoder(); |
139 EXPECT_EQ(2, svc_.spatial_layers); | 340 EXPECT_EQ(2, svc_.spatial_layers); |
140 } | 341 } |
141 | 342 |
142 TEST_F(SvcTest, SetScaleFactorsOption) { | 343 TEST_F(SvcTest, SetScaleFactorsOption) { |
143 svc_.spatial_layers = 2; | 344 svc_.spatial_layers = 2; |
144 vpx_codec_err_t res = | 345 vpx_codec_err_t res = |
145 vpx_svc_set_options(&svc_, "scale-factors=not-scale-factors"); | 346 vpx_svc_set_options(&svc_, "scale-factors=not-scale-factors"); |
146 EXPECT_EQ(VPX_CODEC_OK, res); | 347 EXPECT_EQ(VPX_CODEC_OK, res); |
147 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 348 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
148 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 349 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
149 | 350 |
150 res = vpx_svc_set_options(&svc_, "scale-factors=1/3,2/3"); | 351 res = vpx_svc_set_options(&svc_, "scale-factors=1/3,2/3"); |
151 EXPECT_EQ(VPX_CODEC_OK, res); | 352 EXPECT_EQ(VPX_CODEC_OK, res); |
152 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 353 InitializeEncoder(); |
153 EXPECT_EQ(VPX_CODEC_OK, res); | |
154 codec_initialized_ = true; | |
155 } | 354 } |
156 | 355 |
157 TEST_F(SvcTest, SetQuantizersOption) { | 356 TEST_F(SvcTest, SetQuantizersOption) { |
158 svc_.spatial_layers = 2; | 357 svc_.spatial_layers = 2; |
159 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "quantizers=not-quantizers"); | 358 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "quantizers=not-quantizers"); |
160 EXPECT_EQ(VPX_CODEC_OK, res); | 359 EXPECT_EQ(VPX_CODEC_OK, res); |
161 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 360 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
162 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 361 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
163 | 362 |
164 vpx_svc_set_options(&svc_, "quantizers=40,45"); | 363 vpx_svc_set_options(&svc_, "quantizers=40,45"); |
165 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 364 InitializeEncoder(); |
166 EXPECT_EQ(VPX_CODEC_OK, res); | |
167 codec_initialized_ = true; | |
168 } | 365 } |
169 | 366 |
170 TEST_F(SvcTest, SetAutoAltRefOption) { | 367 TEST_F(SvcTest, SetAutoAltRefOption) { |
171 svc_.spatial_layers = 5; | 368 svc_.spatial_layers = 5; |
172 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "auto-alt-refs=none"); | 369 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "auto-alt-refs=none"); |
173 EXPECT_EQ(VPX_CODEC_OK, res); | 370 EXPECT_EQ(VPX_CODEC_OK, res); |
174 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 371 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
175 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 372 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
176 | 373 |
177 res = vpx_svc_set_options(&svc_, "auto-alt-refs=1,1,1,1,0"); | 374 res = vpx_svc_set_options(&svc_, "auto-alt-refs=1,1,1,1,0"); |
178 EXPECT_EQ(VPX_CODEC_OK, res); | 375 EXPECT_EQ(VPX_CODEC_OK, res); |
179 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 376 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
180 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 377 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
181 | 378 |
182 vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0"); | 379 vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0"); |
183 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 380 InitializeEncoder(); |
184 EXPECT_EQ(VPX_CODEC_OK, res); | |
185 codec_initialized_ = true; | |
186 } | 381 } |
187 | 382 |
188 TEST_F(SvcTest, SetQuantizers) { | 383 TEST_F(SvcTest, SetQuantizers) { |
189 vpx_codec_err_t res = vpx_svc_set_quantizers(NULL, "40,30"); | 384 vpx_codec_err_t res = vpx_svc_set_quantizers(NULL, "40,30"); |
190 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 385 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
191 | 386 |
192 res = vpx_svc_set_quantizers(&svc_, NULL); | 387 res = vpx_svc_set_quantizers(&svc_, NULL); |
193 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 388 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
194 | 389 |
195 svc_.spatial_layers = 2; | 390 svc_.spatial_layers = 2; |
196 res = vpx_svc_set_quantizers(&svc_, "40"); | 391 res = vpx_svc_set_quantizers(&svc_, "40"); |
197 EXPECT_EQ(VPX_CODEC_OK, res); | 392 EXPECT_EQ(VPX_CODEC_OK, res); |
198 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 393 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
199 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 394 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
200 | 395 |
201 res = vpx_svc_set_quantizers(&svc_, "40,30"); | 396 res = vpx_svc_set_quantizers(&svc_, "40,30"); |
202 EXPECT_EQ(VPX_CODEC_OK, res); | 397 EXPECT_EQ(VPX_CODEC_OK, res); |
203 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 398 InitializeEncoder(); |
204 EXPECT_EQ(VPX_CODEC_OK, res); | |
205 codec_initialized_ = true; | |
206 } | 399 } |
207 | 400 |
208 TEST_F(SvcTest, SetScaleFactors) { | 401 TEST_F(SvcTest, SetScaleFactors) { |
209 vpx_codec_err_t res = vpx_svc_set_scale_factors(NULL, "4/16,16/16"); | 402 vpx_codec_err_t res = vpx_svc_set_scale_factors(NULL, "4/16,16/16"); |
210 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 403 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
211 | 404 |
212 res = vpx_svc_set_scale_factors(&svc_, NULL); | 405 res = vpx_svc_set_scale_factors(&svc_, NULL); |
213 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 406 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
214 | 407 |
215 svc_.spatial_layers = 2; | 408 svc_.spatial_layers = 2; |
216 res = vpx_svc_set_scale_factors(&svc_, "4/16"); | 409 res = vpx_svc_set_scale_factors(&svc_, "4/16"); |
217 EXPECT_EQ(VPX_CODEC_OK, res); | 410 EXPECT_EQ(VPX_CODEC_OK, res); |
218 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 411 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); |
219 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 412 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
220 | 413 |
221 res = vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); | 414 res = vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); |
222 EXPECT_EQ(VPX_CODEC_OK, res); | 415 EXPECT_EQ(VPX_CODEC_OK, res); |
223 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 416 InitializeEncoder(); |
224 EXPECT_EQ(VPX_CODEC_OK, res); | |
225 codec_initialized_ = true; | |
226 } | 417 } |
227 | 418 |
228 // Test that decoder can handle an SVC frame as the first frame in a sequence. | 419 // Test that decoder can handle an SVC frame as the first frame in a sequence. |
229 TEST_F(SvcTest, FirstFrameHasLayers) { | 420 TEST_F(SvcTest, OnePassEncodeOneFrame) { |
230 svc_.spatial_layers = 2; | 421 codec_enc_.g_pass = VPX_RC_ONE_PASS; |
231 vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); | 422 vpx_fixed_buf output = {0}; |
232 vpx_svc_set_quantizers(&svc_, "40,30"); | 423 Pass2EncodeNFrames(NULL, 1, 2, &output); |
233 | 424 DecodeNFrames(&output, 1); |
234 vpx_codec_err_t res = | 425 FreeBitstreamBuffers(&output, 1); |
235 vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | |
236 EXPECT_EQ(VPX_CODEC_OK, res); | |
237 codec_initialized_ = true; | |
238 | |
239 libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight, | |
240 codec_enc_.g_timebase.den, | |
241 codec_enc_.g_timebase.num, 0, 30); | |
242 video.Begin(); | |
243 | |
244 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | |
245 video.duration(), VPX_DL_GOOD_QUALITY); | |
246 EXPECT_EQ(VPX_CODEC_OK, res); | |
247 | |
248 if (vpx_svc_get_frame_size(&svc_) == 0) { | |
249 // Flush encoder | |
250 res = vpx_svc_encode(&svc_, &codec_, NULL, 0, | |
251 video.duration(), VPX_DL_GOOD_QUALITY); | |
252 EXPECT_EQ(VPX_CODEC_OK, res); | |
253 } | |
254 | |
255 int frame_size = vpx_svc_get_frame_size(&svc_); | |
256 EXPECT_GT(frame_size, 0); | |
257 const vpx_codec_err_t res_dec = decoder_->DecodeFrame( | |
258 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size); | |
259 | |
260 // this test fails with a decoder error | |
261 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); | |
262 } | 426 } |
263 | 427 |
264 TEST_F(SvcTest, EncodeThreeFrames) { | 428 TEST_F(SvcTest, OnePassEncodeThreeFrames) { |
265 svc_.spatial_layers = 2; | 429 codec_enc_.g_pass = VPX_RC_ONE_PASS; |
266 vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); | 430 vpx_fixed_buf outputs[3]; |
267 vpx_svc_set_quantizers(&svc_, "40,30"); | 431 memset(&outputs[0], 0, sizeof(outputs)); |
268 int decoded_frames = 0; | 432 Pass2EncodeNFrames(NULL, 3, 2, &outputs[0]); |
269 vpx_codec_err_t res_dec; | 433 DecodeNFrames(&outputs[0], 3); |
270 int frame_size; | 434 FreeBitstreamBuffers(&outputs[0], 3); |
271 | |
272 vpx_codec_err_t res = | |
273 vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | |
274 ASSERT_EQ(VPX_CODEC_OK, res); | |
275 codec_initialized_ = true; | |
276 | |
277 libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight, | |
278 codec_enc_.g_timebase.den, | |
279 codec_enc_.g_timebase.num, 0, 30); | |
280 // FRAME 0 | |
281 video.Begin(); | |
282 // This frame is a keyframe. | |
283 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | |
284 video.duration(), VPX_DL_GOOD_QUALITY); | |
285 | |
286 if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) { | |
287 EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_)); | |
288 res_dec = decoder_->DecodeFrame( | |
289 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size); | |
290 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); | |
291 ++decoded_frames; | |
292 } | |
293 | |
294 // FRAME 1 | |
295 video.Next(); | |
296 // This is a P-frame. | |
297 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | |
298 video.duration(), VPX_DL_GOOD_QUALITY); | |
299 ASSERT_EQ(VPX_CODEC_OK, res); | |
300 | |
301 if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) { | |
302 EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_)); | |
303 res_dec = decoder_->DecodeFrame( | |
304 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size); | |
305 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); | |
306 ++decoded_frames; | |
307 } | |
308 | |
309 // FRAME 2 | |
310 video.Next(); | |
311 // This is a P-frame. | |
312 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | |
313 video.duration(), VPX_DL_GOOD_QUALITY); | |
314 ASSERT_EQ(VPX_CODEC_OK, res); | |
315 | |
316 if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) { | |
317 EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_)); | |
318 res_dec = decoder_->DecodeFrame( | |
319 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size); | |
320 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); | |
321 ++decoded_frames; | |
322 } | |
323 | |
324 // Flush encoder | |
325 res = vpx_svc_encode(&svc_, &codec_, NULL, 0, | |
326 video.duration(), VPX_DL_GOOD_QUALITY); | |
327 EXPECT_EQ(VPX_CODEC_OK, res); | |
328 | |
329 while ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) { | |
330 EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_)); | |
331 res_dec = decoder_->DecodeFrame( | |
332 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size); | |
333 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); | |
334 ++decoded_frames; | |
335 } | |
336 | |
337 EXPECT_EQ(decoded_frames, 3); | |
338 } | 435 } |
339 | 436 |
340 TEST_F(SvcTest, GetLayerResolution) { | 437 TEST_F(SvcTest, GetLayerResolution) { |
341 svc_.spatial_layers = 2; | 438 svc_.spatial_layers = 2; |
342 vpx_svc_set_scale_factors(&svc_, "4/16,8/16"); | 439 vpx_svc_set_scale_factors(&svc_, "4/16,8/16"); |
343 vpx_svc_set_quantizers(&svc_, "40,30"); | 440 vpx_svc_set_quantizers(&svc_, "40,30"); |
344 | 441 |
345 vpx_codec_err_t res = | 442 InitializeEncoder(); |
346 vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | |
347 EXPECT_EQ(VPX_CODEC_OK, res); | |
348 codec_initialized_ = true; | |
349 | 443 |
350 // ensure that requested layer is a valid layer | 444 // ensure that requested layer is a valid layer |
351 uint32_t layer_width, layer_height; | 445 uint32_t layer_width, layer_height; |
352 res = vpx_svc_get_layer_resolution(&svc_, svc_.spatial_layers, | 446 vpx_codec_err_t res = vpx_svc_get_layer_resolution(&svc_, svc_.spatial_layers, |
353 &layer_width, &layer_height); | 447 &layer_width, &layer_height); |
354 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 448 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
355 | 449 |
356 res = vpx_svc_get_layer_resolution(NULL, 0, &layer_width, &layer_height); | 450 res = vpx_svc_get_layer_resolution(NULL, 0, &layer_width, &layer_height); |
357 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 451 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
358 | 452 |
359 res = vpx_svc_get_layer_resolution(&svc_, 0, NULL, &layer_height); | 453 res = vpx_svc_get_layer_resolution(&svc_, 0, NULL, &layer_height); |
360 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 454 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
361 | 455 |
362 res = vpx_svc_get_layer_resolution(&svc_, 0, &layer_width, NULL); | 456 res = vpx_svc_get_layer_resolution(&svc_, 0, &layer_width, NULL); |
363 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); | 457 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res); |
364 | 458 |
365 res = vpx_svc_get_layer_resolution(&svc_, 0, &layer_width, &layer_height); | 459 res = vpx_svc_get_layer_resolution(&svc_, 0, &layer_width, &layer_height); |
366 EXPECT_EQ(VPX_CODEC_OK, res); | 460 EXPECT_EQ(VPX_CODEC_OK, res); |
367 EXPECT_EQ(kWidth * 4 / 16, layer_width); | 461 EXPECT_EQ(kWidth * 4 / 16, layer_width); |
368 EXPECT_EQ(kHeight * 4 / 16, layer_height); | 462 EXPECT_EQ(kHeight * 4 / 16, layer_height); |
369 | 463 |
370 res = vpx_svc_get_layer_resolution(&svc_, 1, &layer_width, &layer_height); | 464 res = vpx_svc_get_layer_resolution(&svc_, 1, &layer_width, &layer_height); |
371 EXPECT_EQ(VPX_CODEC_OK, res); | 465 EXPECT_EQ(VPX_CODEC_OK, res); |
372 EXPECT_EQ(kWidth * 8 / 16, layer_width); | 466 EXPECT_EQ(kWidth * 8 / 16, layer_width); |
373 EXPECT_EQ(kHeight * 8 / 16, layer_height); | 467 EXPECT_EQ(kHeight * 8 / 16, layer_height); |
374 } | 468 } |
375 | 469 |
376 TEST_F(SvcTest, TwoPassEncode) { | 470 TEST_F(SvcTest, TwoPassEncode10Frames) { |
377 // First pass encode | 471 // First pass encode |
378 std::string stats_buf; | 472 std::string stats_buf; |
379 svc_.spatial_layers = 2; | 473 Pass1EncodeNFrames(10, 2, &stats_buf); |
380 codec_enc_.g_pass = VPX_RC_FIRST_PASS; | |
381 vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); | |
382 vpx_svc_set_quantizers(&svc_, "40,30"); | |
383 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1"); | |
384 | |
385 vpx_codec_err_t res = | |
386 vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | |
387 ASSERT_EQ(VPX_CODEC_OK, res); | |
388 codec_initialized_ = true; | |
389 | |
390 libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight, | |
391 codec_enc_.g_timebase.den, | |
392 codec_enc_.g_timebase.num, 0, 30); | |
393 // FRAME 0 | |
394 video.Begin(); | |
395 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | |
396 video.duration(), VPX_DL_GOOD_QUALITY); | |
397 ASSERT_EQ(VPX_CODEC_OK, res); | |
398 size_t stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); | |
399 EXPECT_GT(stats_size, 0U); | |
400 const char *stats_data = vpx_svc_get_rc_stats_buffer(&svc_); | |
401 ASSERT_TRUE(stats_data != NULL); | |
402 stats_buf.append(stats_data, stats_size); | |
403 | |
404 // FRAME 1 | |
405 video.Next(); | |
406 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | |
407 video.duration(), VPX_DL_GOOD_QUALITY); | |
408 stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); | |
409 EXPECT_GT(stats_size, 0U); | |
410 stats_data = vpx_svc_get_rc_stats_buffer(&svc_); | |
411 ASSERT_TRUE(stats_data != NULL); | |
412 stats_buf.append(stats_data, stats_size); | |
413 | |
414 // Flush encoder and test EOS packet | |
415 res = vpx_svc_encode(&svc_, &codec_, NULL, video.pts(), | |
416 video.duration(), VPX_DL_GOOD_QUALITY); | |
417 stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_); | |
418 EXPECT_GT(stats_size, 0U); | |
419 stats_data = vpx_svc_get_rc_stats_buffer(&svc_); | |
420 ASSERT_TRUE(stats_data != NULL); | |
421 stats_buf.append(stats_data, stats_size); | |
422 | |
423 // Tear down encoder | |
424 vpx_svc_release(&svc_); | |
425 vpx_codec_destroy(&codec_); | |
426 | 474 |
427 // Second pass encode | 475 // Second pass encode |
428 int decoded_frames = 0; | |
429 vpx_codec_err_t res_dec; | |
430 int frame_size; | |
431 codec_enc_.g_pass = VPX_RC_LAST_PASS; | 476 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
432 vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); | 477 vpx_fixed_buf outputs[10]; |
433 vpx_svc_set_quantizers(&svc_, "40,30"); | 478 memset(&outputs[0], 0, sizeof(outputs)); |
| 479 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]); |
| 480 DecodeNFrames(&outputs[0], 10); |
| 481 FreeBitstreamBuffers(&outputs[0], 10); |
| 482 } |
| 483 |
| 484 TEST_F(SvcTest, TwoPassEncode20FramesWithAltRef) { |
| 485 // First pass encode |
| 486 std::string stats_buf; |
| 487 Pass1EncodeNFrames(20, 2, &stats_buf); |
| 488 |
| 489 // Second pass encode |
| 490 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
434 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1"); | 491 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1"); |
435 codec_enc_.rc_twopass_stats_in.buf = &stats_buf[0]; | 492 vpx_fixed_buf outputs[20]; |
436 codec_enc_.rc_twopass_stats_in.sz = stats_buf.size(); | 493 memset(&outputs[0], 0, sizeof(outputs)); |
| 494 Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]); |
| 495 DecodeNFrames(&outputs[0], 20); |
| 496 FreeBitstreamBuffers(&outputs[0], 20); |
| 497 } |
437 | 498 |
438 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_); | 499 TEST_F(SvcTest, TwoPassEncode2LayersDecodeBaseLayerOnly) { |
439 ASSERT_EQ(VPX_CODEC_OK, res); | 500 // First pass encode |
440 codec_initialized_ = true; | 501 std::string stats_buf; |
| 502 Pass1EncodeNFrames(10, 2, &stats_buf); |
441 | 503 |
442 // FRAME 0 | 504 // Second pass encode |
443 video.Begin(); | 505 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
444 // This frame is a keyframe. | 506 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1"); |
445 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | 507 vpx_fixed_buf outputs[10]; |
446 video.duration(), VPX_DL_GOOD_QUALITY); | 508 memset(&outputs[0], 0, sizeof(outputs)); |
447 ASSERT_EQ(VPX_CODEC_OK, res); | 509 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]); |
| 510 DropEnhancementLayers(&outputs[0], 10, 1); |
| 511 DecodeNFrames(&outputs[0], 10); |
| 512 FreeBitstreamBuffers(&outputs[0], 10); |
| 513 } |
448 | 514 |
449 if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) { | 515 TEST_F(SvcTest, TwoPassEncode5LayersDecode54321Layers) { |
450 EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_)); | 516 // First pass encode |
451 res_dec = decoder_->DecodeFrame( | 517 std::string stats_buf; |
452 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size); | 518 Pass1EncodeNFrames(10, 5, &stats_buf); |
453 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); | |
454 ++decoded_frames; | |
455 } | |
456 | 519 |
457 // FRAME 1 | 520 // Second pass encode |
458 video.Next(); | 521 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
459 // This is a P-frame. | 522 vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0"); |
460 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | 523 vpx_fixed_buf outputs[10]; |
461 video.duration(), VPX_DL_GOOD_QUALITY); | 524 memset(&outputs[0], 0, sizeof(outputs)); |
462 ASSERT_EQ(VPX_CODEC_OK, res); | 525 Pass2EncodeNFrames(&stats_buf, 10, 5, &outputs[0]); |
463 | 526 |
464 if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) { | 527 DecodeNFrames(&outputs[0], 10); |
465 EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_)); | 528 DropEnhancementLayers(&outputs[0], 10, 4); |
466 res_dec = decoder_->DecodeFrame( | 529 DecodeNFrames(&outputs[0], 10); |
467 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size); | 530 DropEnhancementLayers(&outputs[0], 10, 3); |
468 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); | 531 DecodeNFrames(&outputs[0], 10); |
469 ++decoded_frames; | 532 DropEnhancementLayers(&outputs[0], 10, 2); |
470 } | 533 DecodeNFrames(&outputs[0], 10); |
| 534 DropEnhancementLayers(&outputs[0], 10, 1); |
| 535 DecodeNFrames(&outputs[0], 10); |
471 | 536 |
472 // FRAME 2 | 537 FreeBitstreamBuffers(&outputs[0], 10); |
473 video.Next(); | 538 } |
474 // This is a P-frame. | |
475 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(), | |
476 video.duration(), VPX_DL_GOOD_QUALITY); | |
477 ASSERT_EQ(VPX_CODEC_OK, res); | |
478 | 539 |
479 if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) { | 540 TEST_F(SvcTest, TwoPassEncode2SNRLayers) { |
480 EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_)); | 541 // First pass encode |
481 res_dec = decoder_->DecodeFrame( | 542 std::string stats_buf; |
482 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size); | 543 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1"); |
483 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); | 544 Pass1EncodeNFrames(20, 2, &stats_buf); |
484 ++decoded_frames; | |
485 } | |
486 | 545 |
487 // Flush encoder | 546 // Second pass encode |
488 res = vpx_svc_encode(&svc_, &codec_, NULL, 0, | 547 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
489 video.duration(), VPX_DL_GOOD_QUALITY); | 548 vpx_svc_set_options(&svc_, |
490 EXPECT_EQ(VPX_CODEC_OK, res); | 549 "auto-alt-refs=1,1 scale-factors=1/1,1/1"); |
| 550 vpx_fixed_buf outputs[20]; |
| 551 memset(&outputs[0], 0, sizeof(outputs)); |
| 552 Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]); |
| 553 DecodeNFrames(&outputs[0], 20); |
| 554 FreeBitstreamBuffers(&outputs[0], 20); |
| 555 } |
491 | 556 |
492 while ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) { | 557 TEST_F(SvcTest, TwoPassEncode3SNRLayersDecode321Layers) { |
493 EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_)); | 558 // First pass encode |
494 res_dec = decoder_->DecodeFrame( | 559 std::string stats_buf; |
495 static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size); | 560 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1,1/1"); |
496 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError(); | 561 Pass1EncodeNFrames(20, 3, &stats_buf); |
497 ++decoded_frames; | |
498 } | |
499 | 562 |
500 EXPECT_EQ(decoded_frames, 3); | 563 // Second pass encode |
| 564 codec_enc_.g_pass = VPX_RC_LAST_PASS; |
| 565 vpx_svc_set_options(&svc_, |
| 566 "auto-alt-refs=1,1,1 scale-factors=1/1,1/1,1/1"); |
| 567 vpx_fixed_buf outputs[20]; |
| 568 memset(&outputs[0], 0, sizeof(outputs)); |
| 569 Pass2EncodeNFrames(&stats_buf, 20, 3, &outputs[0]); |
| 570 DecodeNFrames(&outputs[0], 20); |
| 571 DropEnhancementLayers(&outputs[0], 20, 2); |
| 572 DecodeNFrames(&outputs[0], 20); |
| 573 DropEnhancementLayers(&outputs[0], 20, 1); |
| 574 DecodeNFrames(&outputs[0], 20); |
| 575 |
| 576 FreeBitstreamBuffers(&outputs[0], 20); |
501 } | 577 } |
502 | 578 |
503 } // namespace | 579 } // namespace |
OLD | NEW |