2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
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.
12 #include "third_party/googletest/src/include/gtest/gtest.h"
13 #include "test/codec_factory.h"
14 #include "test/decode_test_driver.h"
15 #include "test/i420_video_source.h"
17 #include "vp9/decoder/vp9_decoder.h"
19 #include "vpx/svc_context.h"
20 #include "vpx/vp8cx.h"
21 #include "vpx/vpx_encoder.h"
25 using libvpx_test::CodecFactory;
26 using libvpx_test::Decoder;
27 using libvpx_test::DxDataIterator;
28 using libvpx_test::VP9CodecFactory;
30 class SvcTest : public ::testing::Test {
32 static const uint32_t kWidth = 352;
33 static const uint32_t kHeight = 288;
37 test_file_name_("hantro_collage_w352h288.yuv"),
38 codec_initialized_(false),
40 memset(&svc_, 0, sizeof(svc_));
41 memset(&codec_, 0, sizeof(codec_));
42 memset(&codec_enc_, 0, sizeof(codec_enc_));
47 virtual void SetUp() {
48 svc_.log_level = SVC_LOG_DEBUG;
51 codec_iface_ = vpx_codec_vp9_cx();
52 const vpx_codec_err_t res =
53 vpx_codec_enc_config_default(codec_iface_, &codec_enc_, 0);
54 EXPECT_EQ(VPX_CODEC_OK, res);
56 codec_enc_.g_w = kWidth;
57 codec_enc_.g_h = kHeight;
58 codec_enc_.g_timebase.num = 1;
59 codec_enc_.g_timebase.den = 60;
60 codec_enc_.kf_min_dist = 100;
61 codec_enc_.kf_max_dist = 100;
63 vpx_codec_dec_cfg_t dec_cfg = vpx_codec_dec_cfg_t();
64 VP9CodecFactory codec_factory;
65 decoder_ = codec_factory.CreateDecoder(dec_cfg, 0);
68 virtual void TearDown() {
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 vpx_codec_control(&codec_, VP8E_SET_CPUUSED, 4); // Make the test faster
78 codec_initialized_ = true;
81 void ReleaseEncoder() {
82 vpx_svc_release(&svc_);
83 if (codec_initialized_) vpx_codec_destroy(&codec_);
84 codec_initialized_ = false;
87 void GetStatsData(std::string *const stats_buf) {
88 vpx_codec_iter_t iter = NULL;
89 const vpx_codec_cx_pkt_t *cx_pkt;
91 while ((cx_pkt = vpx_codec_get_cx_data(&codec_, &iter)) != NULL) {
92 if (cx_pkt->kind == VPX_CODEC_STATS_PKT) {
93 EXPECT_GT(cx_pkt->data.twopass_stats.sz, 0U);
94 ASSERT_TRUE(cx_pkt->data.twopass_stats.buf != NULL);
95 stats_buf->append(static_cast<char*>(cx_pkt->data.twopass_stats.buf),
96 cx_pkt->data.twopass_stats.sz);
101 void Pass1EncodeNFrames(const int n, const int layers,
102 std::string *const stats_buf) {
106 ASSERT_GT(layers, 0);
107 svc_.spatial_layers = layers;
108 codec_enc_.g_pass = VPX_RC_FIRST_PASS;
111 libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight,
112 codec_enc_.g_timebase.den,
113 codec_enc_.g_timebase.num, 0, 30);
116 for (int i = 0; i < n; ++i) {
117 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
118 video.duration(), VPX_DL_GOOD_QUALITY);
119 ASSERT_EQ(VPX_CODEC_OK, res);
120 GetStatsData(stats_buf);
124 // Flush encoder and test EOS packet.
125 res = vpx_svc_encode(&svc_, &codec_, NULL, video.pts(),
126 video.duration(), VPX_DL_GOOD_QUALITY);
127 ASSERT_EQ(VPX_CODEC_OK, res);
128 GetStatsData(stats_buf);
133 void StoreFrames(const size_t max_frame_received,
134 struct vpx_fixed_buf *const outputs,
135 size_t *const frame_received) {
136 vpx_codec_iter_t iter = NULL;
137 const vpx_codec_cx_pkt_t *cx_pkt;
139 while ((cx_pkt = vpx_codec_get_cx_data(&codec_, &iter)) != NULL) {
140 if (cx_pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
141 const size_t frame_size = cx_pkt->data.frame.sz;
143 EXPECT_GT(frame_size, 0U);
144 ASSERT_TRUE(cx_pkt->data.frame.buf != NULL);
145 ASSERT_LT(*frame_received, max_frame_received);
147 if (*frame_received == 0)
148 EXPECT_EQ(1, !!(cx_pkt->data.frame.flags & VPX_FRAME_IS_KEY));
150 outputs[*frame_received].buf = malloc(frame_size + 16);
151 ASSERT_TRUE(outputs[*frame_received].buf != NULL);
152 memcpy(outputs[*frame_received].buf, cx_pkt->data.frame.buf,
154 outputs[*frame_received].sz = frame_size;
160 void Pass2EncodeNFrames(std::string *const stats_buf,
161 const int n, const int layers,
162 struct vpx_fixed_buf *const outputs) {
164 size_t frame_received = 0;
166 ASSERT_TRUE(outputs != NULL);
168 ASSERT_GT(layers, 0);
169 svc_.spatial_layers = layers;
170 codec_enc_.rc_target_bitrate = 500;
171 if (codec_enc_.g_pass == VPX_RC_LAST_PASS) {
172 ASSERT_TRUE(stats_buf != NULL);
173 ASSERT_GT(stats_buf->size(), 0U);
174 codec_enc_.rc_twopass_stats_in.buf = &(*stats_buf)[0];
175 codec_enc_.rc_twopass_stats_in.sz = stats_buf->size();
179 libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight,
180 codec_enc_.g_timebase.den,
181 codec_enc_.g_timebase.num, 0, 30);
184 for (int i = 0; i < n; ++i) {
185 res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
186 video.duration(), VPX_DL_GOOD_QUALITY);
187 ASSERT_EQ(VPX_CODEC_OK, res);
188 StoreFrames(n, outputs, &frame_received);
193 res = vpx_svc_encode(&svc_, &codec_, NULL, 0,
194 video.duration(), VPX_DL_GOOD_QUALITY);
195 EXPECT_EQ(VPX_CODEC_OK, res);
196 StoreFrames(n, outputs, &frame_received);
198 EXPECT_EQ(frame_received, static_cast<size_t>(n));
203 void DecodeNFrames(const struct vpx_fixed_buf *const inputs, const int n) {
204 int decoded_frames = 0;
205 int received_frames = 0;
207 ASSERT_TRUE(inputs != NULL);
210 for (int i = 0; i < n; ++i) {
211 ASSERT_TRUE(inputs[i].buf != NULL);
212 ASSERT_GT(inputs[i].sz, 0U);
213 const vpx_codec_err_t res_dec =
214 decoder_->DecodeFrame(static_cast<const uint8_t *>(inputs[i].buf),
216 ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError();
219 DxDataIterator dec_iter = decoder_->GetDxData();
220 while (dec_iter.Next() != NULL) {
224 EXPECT_EQ(decoded_frames, n);
225 EXPECT_EQ(received_frames, n);
228 void DropEnhancementLayers(struct vpx_fixed_buf *const inputs,
229 const int num_super_frames,
230 const int remained_spatial_layers) {
231 ASSERT_TRUE(inputs != NULL);
232 ASSERT_GT(num_super_frames, 0);
233 ASSERT_GT(remained_spatial_layers, 0);
235 for (int i = 0; i < num_super_frames; ++i) {
236 uint32_t frame_sizes[8] = {0};
238 int frames_found = 0;
240 ASSERT_TRUE(inputs[i].buf != NULL);
241 ASSERT_GT(inputs[i].sz, 0U);
243 vpx_codec_err_t res =
244 vp9_parse_superframe_index(static_cast<const uint8_t*>(inputs[i].buf),
245 inputs[i].sz, frame_sizes, &frame_count,
247 ASSERT_EQ(VPX_CODEC_OK, res);
249 if (frame_count == 0) {
250 // There's no super frame but only a single frame.
251 ASSERT_EQ(1, remained_spatial_layers);
253 // Found a super frame.
254 uint8_t *frame_data = static_cast<uint8_t*>(inputs[i].buf);
255 uint8_t *frame_start = frame_data;
256 for (frame = 0; frame < frame_count; ++frame) {
257 // Looking for a visible frame.
258 if (frame_data[0] & 0x02) {
260 if (frames_found == remained_spatial_layers)
263 frame_data += frame_sizes[frame];
265 ASSERT_LT(frame, frame_count) << "Couldn't find a visible frame. "
266 << "remained_spatial_layers: " << remained_spatial_layers
267 << " super_frame: " << i;
268 if (frame == frame_count - 1)
271 frame_data += frame_sizes[frame];
273 // We need to add one more frame for multiple frame contexts.
275 static_cast<const uint8_t*>(inputs[i].buf)[inputs[i].sz - 1];
276 const uint32_t mag = ((marker >> 3) & 0x3) + 1;
277 const size_t index_sz = 2 + mag * frame_count;
278 const size_t new_index_sz = 2 + mag * (frame + 1);
282 // Copy existing frame sizes.
283 memmove(frame_data + 1, frame_start + inputs[i].sz - index_sz + 1,
286 frame_data[0] = marker;
287 frame_data += (mag * (frame + 1) + 1);
289 *frame_data++ = marker;
290 inputs[i].sz = frame_data - frame_start;
295 void FreeBitstreamBuffers(struct vpx_fixed_buf *const inputs, const int n) {
296 ASSERT_TRUE(inputs != NULL);
299 for (int i = 0; i < n; ++i) {
301 inputs[i].buf = NULL;
307 vpx_codec_ctx_t codec_;
308 struct vpx_codec_enc_cfg codec_enc_;
309 vpx_codec_iface_t *codec_iface_;
310 std::string test_file_name_;
311 bool codec_initialized_;
315 TEST_F(SvcTest, SvcInit) {
316 // test missing parameters
317 vpx_codec_err_t res = vpx_svc_init(NULL, &codec_, codec_iface_, &codec_enc_);
318 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
319 res = vpx_svc_init(&svc_, NULL, codec_iface_, &codec_enc_);
320 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
321 res = vpx_svc_init(&svc_, &codec_, NULL, &codec_enc_);
322 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
324 res = vpx_svc_init(&svc_, &codec_, codec_iface_, NULL);
325 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
327 svc_.spatial_layers = 6; // too many layers
328 res = vpx_svc_init(&svc_, &codec_, codec_iface_, &codec_enc_);
329 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
331 svc_.spatial_layers = 0; // use default layers
333 EXPECT_EQ(VPX_SS_DEFAULT_LAYERS, svc_.spatial_layers);
336 TEST_F(SvcTest, InitTwoLayers) {
337 svc_.spatial_layers = 2;
341 TEST_F(SvcTest, InvalidOptions) {
342 vpx_codec_err_t res = vpx_svc_set_options(&svc_, NULL);
343 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
345 res = vpx_svc_set_options(&svc_, "not-an-option=1");
346 EXPECT_EQ(VPX_CODEC_OK, res);
347 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
348 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
351 TEST_F(SvcTest, SetLayersOption) {
352 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "spatial-layers=3");
353 EXPECT_EQ(VPX_CODEC_OK, res);
355 EXPECT_EQ(3, svc_.spatial_layers);
358 TEST_F(SvcTest, SetMultipleOptions) {
359 vpx_codec_err_t res =
360 vpx_svc_set_options(&svc_, "spatial-layers=2 scale-factors=1/3,2/3");
361 EXPECT_EQ(VPX_CODEC_OK, res);
363 EXPECT_EQ(2, svc_.spatial_layers);
366 TEST_F(SvcTest, SetScaleFactorsOption) {
367 svc_.spatial_layers = 2;
368 vpx_codec_err_t res =
369 vpx_svc_set_options(&svc_, "scale-factors=not-scale-factors");
370 EXPECT_EQ(VPX_CODEC_OK, res);
371 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
372 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
374 res = vpx_svc_set_options(&svc_, "scale-factors=1/3, 3*3");
375 EXPECT_EQ(VPX_CODEC_OK, res);
376 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
377 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
379 res = vpx_svc_set_options(&svc_, "scale-factors=1/3");
380 EXPECT_EQ(VPX_CODEC_OK, res);
381 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
382 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
384 res = vpx_svc_set_options(&svc_, "scale-factors=1/3,2/3");
385 EXPECT_EQ(VPX_CODEC_OK, res);
389 TEST_F(SvcTest, SetQuantizersOption) {
390 svc_.spatial_layers = 2;
391 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "max-quantizers=nothing");
392 EXPECT_EQ(VPX_CODEC_OK, res);
393 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
394 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
396 res = vpx_svc_set_options(&svc_, "min-quantizers=nothing");
397 EXPECT_EQ(VPX_CODEC_OK, res);
398 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
399 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
401 res = vpx_svc_set_options(&svc_, "max-quantizers=40");
402 EXPECT_EQ(VPX_CODEC_OK, res);
403 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
404 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
406 res = vpx_svc_set_options(&svc_, "min-quantizers=40");
407 EXPECT_EQ(VPX_CODEC_OK, res);
408 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
409 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
411 res = vpx_svc_set_options(&svc_, "max-quantizers=30,30 min-quantizers=40,40");
412 EXPECT_EQ(VPX_CODEC_OK, res);
413 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
414 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
416 res = vpx_svc_set_options(&svc_, "max-quantizers=40,40 min-quantizers=30,30");
420 TEST_F(SvcTest, SetAutoAltRefOption) {
421 svc_.spatial_layers = 5;
422 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "auto-alt-refs=none");
423 EXPECT_EQ(VPX_CODEC_OK, res);
424 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
425 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
427 res = vpx_svc_set_options(&svc_, "auto-alt-refs=1,1,1,1,0");
428 EXPECT_EQ(VPX_CODEC_OK, res);
429 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
430 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
432 vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0");
436 // Test that decoder can handle an SVC frame as the first frame in a sequence.
437 TEST_F(SvcTest, OnePassEncodeOneFrame) {
438 codec_enc_.g_pass = VPX_RC_ONE_PASS;
439 vpx_fixed_buf output = {0};
440 Pass2EncodeNFrames(NULL, 1, 2, &output);
441 DecodeNFrames(&output, 1);
442 FreeBitstreamBuffers(&output, 1);
445 TEST_F(SvcTest, OnePassEncodeThreeFrames) {
446 codec_enc_.g_pass = VPX_RC_ONE_PASS;
447 vpx_fixed_buf outputs[3];
448 memset(&outputs[0], 0, sizeof(outputs));
449 Pass2EncodeNFrames(NULL, 3, 2, &outputs[0]);
450 DecodeNFrames(&outputs[0], 3);
451 FreeBitstreamBuffers(&outputs[0], 3);
454 TEST_F(SvcTest, TwoPassEncode10Frames) {
456 std::string stats_buf;
457 Pass1EncodeNFrames(10, 2, &stats_buf);
459 // Second pass encode
460 codec_enc_.g_pass = VPX_RC_LAST_PASS;
461 vpx_fixed_buf outputs[10];
462 memset(&outputs[0], 0, sizeof(outputs));
463 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
464 DecodeNFrames(&outputs[0], 10);
465 FreeBitstreamBuffers(&outputs[0], 10);
468 TEST_F(SvcTest, TwoPassEncode20FramesWithAltRef) {
470 std::string stats_buf;
471 Pass1EncodeNFrames(20, 2, &stats_buf);
473 // Second pass encode
474 codec_enc_.g_pass = VPX_RC_LAST_PASS;
475 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1");
476 vpx_fixed_buf outputs[20];
477 memset(&outputs[0], 0, sizeof(outputs));
478 Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]);
479 DecodeNFrames(&outputs[0], 20);
480 FreeBitstreamBuffers(&outputs[0], 20);
483 TEST_F(SvcTest, TwoPassEncode2SpatialLayersDecodeBaseLayerOnly) {
485 std::string stats_buf;
486 Pass1EncodeNFrames(10, 2, &stats_buf);
488 // Second pass encode
489 codec_enc_.g_pass = VPX_RC_LAST_PASS;
490 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1");
491 vpx_fixed_buf outputs[10];
492 memset(&outputs[0], 0, sizeof(outputs));
493 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
494 DropEnhancementLayers(&outputs[0], 10, 1);
495 DecodeNFrames(&outputs[0], 10);
496 FreeBitstreamBuffers(&outputs[0], 10);
499 TEST_F(SvcTest, TwoPassEncode5SpatialLayersDecode54321Layers) {
501 std::string stats_buf;
502 Pass1EncodeNFrames(10, 5, &stats_buf);
504 // Second pass encode
505 codec_enc_.g_pass = VPX_RC_LAST_PASS;
506 vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0");
507 vpx_fixed_buf outputs[10];
508 memset(&outputs[0], 0, sizeof(outputs));
509 Pass2EncodeNFrames(&stats_buf, 10, 5, &outputs[0]);
511 DecodeNFrames(&outputs[0], 10);
512 DropEnhancementLayers(&outputs[0], 10, 4);
513 DecodeNFrames(&outputs[0], 10);
514 DropEnhancementLayers(&outputs[0], 10, 3);
515 DecodeNFrames(&outputs[0], 10);
516 DropEnhancementLayers(&outputs[0], 10, 2);
517 DecodeNFrames(&outputs[0], 10);
518 DropEnhancementLayers(&outputs[0], 10, 1);
519 DecodeNFrames(&outputs[0], 10);
521 FreeBitstreamBuffers(&outputs[0], 10);
524 TEST_F(SvcTest, TwoPassEncode2SNRLayers) {
526 std::string stats_buf;
527 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1");
528 Pass1EncodeNFrames(20, 2, &stats_buf);
530 // Second pass encode
531 codec_enc_.g_pass = VPX_RC_LAST_PASS;
532 vpx_svc_set_options(&svc_,
533 "auto-alt-refs=1,1 scale-factors=1/1,1/1");
534 vpx_fixed_buf outputs[20];
535 memset(&outputs[0], 0, sizeof(outputs));
536 Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]);
537 DecodeNFrames(&outputs[0], 20);
538 FreeBitstreamBuffers(&outputs[0], 20);
541 TEST_F(SvcTest, TwoPassEncode3SNRLayersDecode321Layers) {
543 std::string stats_buf;
544 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1,1/1");
545 Pass1EncodeNFrames(20, 3, &stats_buf);
547 // Second pass encode
548 codec_enc_.g_pass = VPX_RC_LAST_PASS;
549 vpx_svc_set_options(&svc_,
550 "auto-alt-refs=1,1,1 scale-factors=1/1,1/1,1/1");
551 vpx_fixed_buf outputs[20];
552 memset(&outputs[0], 0, sizeof(outputs));
553 Pass2EncodeNFrames(&stats_buf, 20, 3, &outputs[0]);
554 DecodeNFrames(&outputs[0], 20);
555 DropEnhancementLayers(&outputs[0], 20, 2);
556 DecodeNFrames(&outputs[0], 20);
557 DropEnhancementLayers(&outputs[0], 20, 1);
558 DecodeNFrames(&outputs[0], 20);
560 FreeBitstreamBuffers(&outputs[0], 20);
563 TEST_F(SvcTest, SetMultipleFrameContextsOption) {
564 svc_.spatial_layers = 5;
565 vpx_codec_err_t res =
566 vpx_svc_set_options(&svc_, "multi-frame-contexts=1");
567 EXPECT_EQ(VPX_CODEC_OK, res);
568 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
569 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
571 svc_.spatial_layers = 2;
572 res = vpx_svc_set_options(&svc_, "multi-frame-contexts=1");
576 TEST_F(SvcTest, TwoPassEncode2SpatialLayersWithMultipleFrameContexts) {
578 std::string stats_buf;
579 Pass1EncodeNFrames(10, 2, &stats_buf);
581 // Second pass encode
582 codec_enc_.g_pass = VPX_RC_LAST_PASS;
583 codec_enc_.g_error_resilient = 0;
584 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 multi-frame-contexts=1");
585 vpx_fixed_buf outputs[10];
586 memset(&outputs[0], 0, sizeof(outputs));
587 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
588 DecodeNFrames(&outputs[0], 10);
589 FreeBitstreamBuffers(&outputs[0], 10);
593 TwoPassEncode2SpatialLayersWithMultipleFrameContextsDecodeBaselayer) {
595 std::string stats_buf;
596 Pass1EncodeNFrames(10, 2, &stats_buf);
598 // Second pass encode
599 codec_enc_.g_pass = VPX_RC_LAST_PASS;
600 codec_enc_.g_error_resilient = 0;
601 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 multi-frame-contexts=1");
602 vpx_fixed_buf outputs[10];
603 memset(&outputs[0], 0, sizeof(outputs));
604 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
605 DropEnhancementLayers(&outputs[0], 10, 1);
606 DecodeNFrames(&outputs[0], 10);
607 FreeBitstreamBuffers(&outputs[0], 10);
610 TEST_F(SvcTest, TwoPassEncode2SNRLayersWithMultipleFrameContexts) {
612 std::string stats_buf;
613 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1");
614 Pass1EncodeNFrames(10, 2, &stats_buf);
616 // Second pass encode
617 codec_enc_.g_pass = VPX_RC_LAST_PASS;
618 codec_enc_.g_error_resilient = 0;
619 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 scale-factors=1/1,1/1 "
620 "multi-frame-contexts=1");
621 vpx_fixed_buf outputs[10];
622 memset(&outputs[0], 0, sizeof(outputs));
623 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
624 DecodeNFrames(&outputs[0], 10);
625 FreeBitstreamBuffers(&outputs[0], 10);
629 TwoPassEncode3SNRLayersWithMultipleFrameContextsDecode321Layer) {
631 std::string stats_buf;
632 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1,1/1");
633 Pass1EncodeNFrames(10, 3, &stats_buf);
635 // Second pass encode
636 codec_enc_.g_pass = VPX_RC_LAST_PASS;
637 codec_enc_.g_error_resilient = 0;
638 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1,1 scale-factors=1/1,1/1,1/1 "
639 "multi-frame-contexts=1");
640 vpx_fixed_buf outputs[10];
641 memset(&outputs[0], 0, sizeof(outputs));
642 Pass2EncodeNFrames(&stats_buf, 10, 3, &outputs[0]);
644 DecodeNFrames(&outputs[0], 10);
645 DropEnhancementLayers(&outputs[0], 10, 2);
646 DecodeNFrames(&outputs[0], 10);
647 DropEnhancementLayers(&outputs[0], 10, 1);
648 DecodeNFrames(&outputs[0], 10);
650 FreeBitstreamBuffers(&outputs[0], 10);
653 TEST_F(SvcTest, TwoPassEncode2TemporalLayers) {
655 std::string stats_buf;
656 vpx_svc_set_options(&svc_, "scale-factors=1/1");
657 svc_.temporal_layers = 2;
658 Pass1EncodeNFrames(10, 1, &stats_buf);
660 // Second pass encode
661 codec_enc_.g_pass = VPX_RC_LAST_PASS;
662 svc_.temporal_layers = 2;
663 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1");
664 vpx_fixed_buf outputs[10];
665 memset(&outputs[0], 0, sizeof(outputs));
666 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
667 DecodeNFrames(&outputs[0], 10);
668 FreeBitstreamBuffers(&outputs[0], 10);
671 TEST_F(SvcTest, TwoPassEncode2TemporalLayersWithMultipleFrameContexts) {
673 std::string stats_buf;
674 vpx_svc_set_options(&svc_, "scale-factors=1/1");
675 svc_.temporal_layers = 2;
676 Pass1EncodeNFrames(10, 1, &stats_buf);
678 // Second pass encode
679 codec_enc_.g_pass = VPX_RC_LAST_PASS;
680 svc_.temporal_layers = 2;
681 codec_enc_.g_error_resilient = 0;
682 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1 "
683 "multi-frame-contexts=1");
684 vpx_fixed_buf outputs[10];
685 memset(&outputs[0], 0, sizeof(outputs));
686 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
687 DecodeNFrames(&outputs[0], 10);
688 FreeBitstreamBuffers(&outputs[0], 10);
691 TEST_F(SvcTest, TwoPassEncode2TemporalLayersDecodeBaseLayer) {
693 std::string stats_buf;
694 vpx_svc_set_options(&svc_, "scale-factors=1/1");
695 svc_.temporal_layers = 2;
696 Pass1EncodeNFrames(10, 1, &stats_buf);
698 // Second pass encode
699 codec_enc_.g_pass = VPX_RC_LAST_PASS;
700 svc_.temporal_layers = 2;
701 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1");
702 vpx_fixed_buf outputs[10];
703 memset(&outputs[0], 0, sizeof(outputs));
704 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
706 vpx_fixed_buf base_layer[5];
707 for (int i = 0; i < 5; ++i)
708 base_layer[i] = outputs[i * 2];
710 DecodeNFrames(&base_layer[0], 5);
711 FreeBitstreamBuffers(&outputs[0], 10);
715 TwoPassEncode2TemporalLayersWithMultipleFrameContextsDecodeBaseLayer) {
717 std::string stats_buf;
718 vpx_svc_set_options(&svc_, "scale-factors=1/1");
719 svc_.temporal_layers = 2;
720 Pass1EncodeNFrames(10, 1, &stats_buf);
722 // Second pass encode
723 codec_enc_.g_pass = VPX_RC_LAST_PASS;
724 svc_.temporal_layers = 2;
725 codec_enc_.g_error_resilient = 0;
726 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1 "
727 "multi-frame-contexts=1");
728 vpx_fixed_buf outputs[10];
729 memset(&outputs[0], 0, sizeof(outputs));
730 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
732 vpx_fixed_buf base_layer[5];
733 for (int i = 0; i < 5; ++i)
734 base_layer[i] = outputs[i * 2];
736 DecodeNFrames(&base_layer[0], 5);
737 FreeBitstreamBuffers(&outputs[0], 10);