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 DropLayersAndMakeItVP9Comaptible(struct vpx_fixed_buf *const inputs,
229 const int num_super_frames,
230 const int remained_spatial_layers,
231 const bool is_multiple_frame_contexts) {
232 ASSERT_TRUE(inputs != NULL);
233 ASSERT_GT(num_super_frames, 0);
234 ASSERT_GT(remained_spatial_layers, 0);
236 for (int i = 0; i < num_super_frames; ++i) {
237 uint32_t frame_sizes[8] = {0};
239 int frames_found = 0;
241 ASSERT_TRUE(inputs[i].buf != NULL);
242 ASSERT_GT(inputs[i].sz, 0U);
244 vpx_codec_err_t res =
245 vp9_parse_superframe_index(static_cast<const uint8_t*>(inputs[i].buf),
246 inputs[i].sz, frame_sizes, &frame_count,
248 ASSERT_EQ(VPX_CODEC_OK, res);
250 if (frame_count == 0) {
251 // There's no super frame but only a single frame.
252 ASSERT_EQ(1, remained_spatial_layers);
253 if (is_multiple_frame_contexts) {
254 // Make a new super frame.
255 uint8_t marker = 0xc1;
259 // Choose the magnitude.
260 for (mag = 0, mask = 0xff; mag < 4; ++mag) {
261 if (inputs[i].sz < mask)
267 int index_sz = 2 + (mag + 1) * 2;
269 inputs[i].buf = realloc(inputs[i].buf, inputs[i].sz + index_sz + 16);
270 ASSERT_TRUE(inputs[i].buf != NULL);
271 uint8_t *frame_data = static_cast<uint8_t*>(inputs[i].buf);
272 frame_data[0] &= ~2; // Set the show_frame flag to 0.
273 frame_data += inputs[i].sz;
274 // Add an one byte frame with show_existing_frame.
275 *frame_data++ = 0x88;
277 // Write the super frame index.
278 *frame_data++ = marker;
280 frame_sizes[0] = inputs[i].sz;
282 for (int j = 0; j < 2; ++j) {
283 unsigned int this_sz = frame_sizes[j];
284 for (int k = 0; k <= mag; k++) {
285 *frame_data++ = this_sz & 0xff;
289 *frame_data++ = marker;
290 inputs[i].sz += index_sz + 1;
293 // Found a super frame.
294 uint8_t *frame_data = static_cast<uint8_t*>(inputs[i].buf);
295 uint8_t *frame_start = frame_data;
296 for (frame = 0; frame < frame_count; ++frame) {
297 // Looking for a visible frame.
298 if (frame_data[0] & 0x02) {
300 if (frames_found == remained_spatial_layers)
303 frame_data += frame_sizes[frame];
305 ASSERT_LT(frame, frame_count) << "Couldn't find a visible frame. "
306 << "remained_spatial_layers: " << remained_spatial_layers
307 << " super_frame: " << i
308 << " is_multiple_frame_context: " << is_multiple_frame_contexts;
309 if (frame == frame_count - 1 && !is_multiple_frame_contexts)
312 frame_data += frame_sizes[frame];
314 // We need to add one more frame for multiple frame contexts.
315 if (is_multiple_frame_contexts)
318 static_cast<const uint8_t*>(inputs[i].buf)[inputs[i].sz - 1];
319 const uint32_t mag = ((marker >> 3) & 0x3) + 1;
320 const size_t index_sz = 2 + mag * frame_count;
321 const size_t new_index_sz = 2 + mag * (frame + 1);
325 // Copy existing frame sizes.
326 memmove(frame_data + (is_multiple_frame_contexts ? 2 : 1),
327 frame_start + inputs[i].sz - index_sz + 1, new_index_sz - 2);
328 if (is_multiple_frame_contexts) {
329 // Add a one byte frame with flag show_existing_frame.
330 *frame_data++ = 0x88 | (remained_spatial_layers - 1);
333 frame_data[0] = marker;
334 frame_data += (mag * (frame + 1) + 1);
336 if (is_multiple_frame_contexts) {
337 // Write the frame size for the one byte frame.
340 for (uint32_t j = 1; j < mag; ++j) {
345 *frame_data++ = marker;
346 inputs[i].sz = frame_data - frame_start;
348 if (is_multiple_frame_contexts) {
349 // Change the show frame flag to 0 for all frames.
350 for (int j = 0; j < frame; ++j) {
351 frame_start[0] &= ~2;
352 frame_start += frame_sizes[j];
359 void FreeBitstreamBuffers(struct vpx_fixed_buf *const inputs, const int n) {
360 ASSERT_TRUE(inputs != NULL);
363 for (int i = 0; i < n; ++i) {
365 inputs[i].buf = NULL;
371 vpx_codec_ctx_t codec_;
372 struct vpx_codec_enc_cfg codec_enc_;
373 vpx_codec_iface_t *codec_iface_;
374 std::string test_file_name_;
375 bool codec_initialized_;
379 TEST_F(SvcTest, SvcInit) {
380 // test missing parameters
381 vpx_codec_err_t res = vpx_svc_init(NULL, &codec_, codec_iface_, &codec_enc_);
382 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
383 res = vpx_svc_init(&svc_, NULL, codec_iface_, &codec_enc_);
384 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
385 res = vpx_svc_init(&svc_, &codec_, NULL, &codec_enc_);
386 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
388 res = vpx_svc_init(&svc_, &codec_, codec_iface_, NULL);
389 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
391 svc_.spatial_layers = 6; // too many layers
392 res = vpx_svc_init(&svc_, &codec_, codec_iface_, &codec_enc_);
393 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
395 svc_.spatial_layers = 0; // use default layers
397 EXPECT_EQ(VPX_SS_DEFAULT_LAYERS, svc_.spatial_layers);
400 TEST_F(SvcTest, InitTwoLayers) {
401 svc_.spatial_layers = 2;
405 TEST_F(SvcTest, InvalidOptions) {
406 vpx_codec_err_t res = vpx_svc_set_options(&svc_, NULL);
407 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
409 res = vpx_svc_set_options(&svc_, "not-an-option=1");
410 EXPECT_EQ(VPX_CODEC_OK, res);
411 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
412 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
415 TEST_F(SvcTest, SetLayersOption) {
416 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "spatial-layers=3");
417 EXPECT_EQ(VPX_CODEC_OK, res);
419 EXPECT_EQ(3, svc_.spatial_layers);
422 TEST_F(SvcTest, SetMultipleOptions) {
423 vpx_codec_err_t res =
424 vpx_svc_set_options(&svc_, "spatial-layers=2 scale-factors=1/3,2/3");
425 EXPECT_EQ(VPX_CODEC_OK, res);
427 EXPECT_EQ(2, svc_.spatial_layers);
430 TEST_F(SvcTest, SetScaleFactorsOption) {
431 svc_.spatial_layers = 2;
432 vpx_codec_err_t res =
433 vpx_svc_set_options(&svc_, "scale-factors=not-scale-factors");
434 EXPECT_EQ(VPX_CODEC_OK, res);
435 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
436 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
438 res = vpx_svc_set_options(&svc_, "scale-factors=1/3, 3*3");
439 EXPECT_EQ(VPX_CODEC_OK, res);
440 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
441 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
443 res = vpx_svc_set_options(&svc_, "scale-factors=1/3");
444 EXPECT_EQ(VPX_CODEC_OK, res);
445 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
446 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
448 res = vpx_svc_set_options(&svc_, "scale-factors=1/3,2/3");
449 EXPECT_EQ(VPX_CODEC_OK, res);
453 TEST_F(SvcTest, SetQuantizersOption) {
454 svc_.spatial_layers = 2;
455 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "quantizers=not-quantizers");
456 EXPECT_EQ(VPX_CODEC_OK, res);
457 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
458 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
460 res = vpx_svc_set_options(&svc_, "40");
461 EXPECT_EQ(VPX_CODEC_OK, res);
462 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
463 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
465 vpx_svc_set_options(&svc_, "quantizers=40,45");
469 TEST_F(SvcTest, SetAutoAltRefOption) {
470 svc_.spatial_layers = 5;
471 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "auto-alt-refs=none");
472 EXPECT_EQ(VPX_CODEC_OK, res);
473 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
474 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
476 res = vpx_svc_set_options(&svc_, "auto-alt-refs=1,1,1,1,0");
477 EXPECT_EQ(VPX_CODEC_OK, res);
478 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
479 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
481 vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0");
485 // Test that decoder can handle an SVC frame as the first frame in a sequence.
486 TEST_F(SvcTest, OnePassEncodeOneFrame) {
487 codec_enc_.g_pass = VPX_RC_ONE_PASS;
488 vpx_fixed_buf output = {0};
489 Pass2EncodeNFrames(NULL, 1, 2, &output);
490 DecodeNFrames(&output, 1);
491 FreeBitstreamBuffers(&output, 1);
494 TEST_F(SvcTest, OnePassEncodeThreeFrames) {
495 codec_enc_.g_pass = VPX_RC_ONE_PASS;
496 vpx_fixed_buf outputs[3];
497 memset(&outputs[0], 0, sizeof(outputs));
498 Pass2EncodeNFrames(NULL, 3, 2, &outputs[0]);
499 DecodeNFrames(&outputs[0], 3);
500 FreeBitstreamBuffers(&outputs[0], 3);
503 TEST_F(SvcTest, GetLayerResolution) {
504 svc_.spatial_layers = 2;
505 vpx_svc_set_options(&svc_, "scale-factors=4/16,8/16");
508 // ensure that requested layer is a valid layer
509 uint32_t layer_width, layer_height;
510 vpx_codec_err_t res = vpx_svc_get_layer_resolution(&svc_, svc_.spatial_layers,
511 &layer_width, &layer_height);
512 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
514 res = vpx_svc_get_layer_resolution(NULL, 0, &layer_width, &layer_height);
515 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
517 res = vpx_svc_get_layer_resolution(&svc_, 0, NULL, &layer_height);
518 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
520 res = vpx_svc_get_layer_resolution(&svc_, 0, &layer_width, NULL);
521 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
523 res = vpx_svc_get_layer_resolution(&svc_, 0, &layer_width, &layer_height);
524 EXPECT_EQ(VPX_CODEC_OK, res);
525 EXPECT_EQ(kWidth * 4 / 16, layer_width);
526 EXPECT_EQ(kHeight * 4 / 16, layer_height);
528 res = vpx_svc_get_layer_resolution(&svc_, 1, &layer_width, &layer_height);
529 EXPECT_EQ(VPX_CODEC_OK, res);
530 EXPECT_EQ(kWidth * 8 / 16, layer_width);
531 EXPECT_EQ(kHeight * 8 / 16, layer_height);
534 TEST_F(SvcTest, TwoPassEncode10Frames) {
536 std::string stats_buf;
537 Pass1EncodeNFrames(10, 2, &stats_buf);
539 // Second pass encode
540 codec_enc_.g_pass = VPX_RC_LAST_PASS;
541 vpx_fixed_buf outputs[10];
542 memset(&outputs[0], 0, sizeof(outputs));
543 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
544 DecodeNFrames(&outputs[0], 10);
545 FreeBitstreamBuffers(&outputs[0], 10);
548 TEST_F(SvcTest, TwoPassEncode20FramesWithAltRef) {
550 std::string stats_buf;
551 Pass1EncodeNFrames(20, 2, &stats_buf);
553 // Second pass encode
554 codec_enc_.g_pass = VPX_RC_LAST_PASS;
555 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1");
556 vpx_fixed_buf outputs[20];
557 memset(&outputs[0], 0, sizeof(outputs));
558 Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]);
559 DecodeNFrames(&outputs[0], 20);
560 FreeBitstreamBuffers(&outputs[0], 20);
563 TEST_F(SvcTest, TwoPassEncode2SpatialLayersDecodeBaseLayerOnly) {
565 std::string stats_buf;
566 Pass1EncodeNFrames(10, 2, &stats_buf);
568 // Second pass encode
569 codec_enc_.g_pass = VPX_RC_LAST_PASS;
570 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1");
571 vpx_fixed_buf outputs[10];
572 memset(&outputs[0], 0, sizeof(outputs));
573 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
574 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, false);
575 DecodeNFrames(&outputs[0], 10);
576 FreeBitstreamBuffers(&outputs[0], 10);
579 TEST_F(SvcTest, TwoPassEncode5SpatialLayersDecode54321Layers) {
581 std::string stats_buf;
582 Pass1EncodeNFrames(10, 5, &stats_buf);
584 // Second pass encode
585 codec_enc_.g_pass = VPX_RC_LAST_PASS;
586 vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0");
587 vpx_fixed_buf outputs[10];
588 memset(&outputs[0], 0, sizeof(outputs));
589 Pass2EncodeNFrames(&stats_buf, 10, 5, &outputs[0]);
591 DecodeNFrames(&outputs[0], 10);
592 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 4, false);
593 DecodeNFrames(&outputs[0], 10);
594 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 3, false);
595 DecodeNFrames(&outputs[0], 10);
596 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 2, false);
597 DecodeNFrames(&outputs[0], 10);
598 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, false);
599 DecodeNFrames(&outputs[0], 10);
601 FreeBitstreamBuffers(&outputs[0], 10);
604 TEST_F(SvcTest, TwoPassEncode2SNRLayers) {
606 std::string stats_buf;
607 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1");
608 Pass1EncodeNFrames(20, 2, &stats_buf);
610 // Second pass encode
611 codec_enc_.g_pass = VPX_RC_LAST_PASS;
612 vpx_svc_set_options(&svc_,
613 "auto-alt-refs=1,1 scale-factors=1/1,1/1");
614 vpx_fixed_buf outputs[20];
615 memset(&outputs[0], 0, sizeof(outputs));
616 Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]);
617 DecodeNFrames(&outputs[0], 20);
618 FreeBitstreamBuffers(&outputs[0], 20);
621 TEST_F(SvcTest, TwoPassEncode3SNRLayersDecode321Layers) {
623 std::string stats_buf;
624 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1,1/1");
625 Pass1EncodeNFrames(20, 3, &stats_buf);
627 // Second pass encode
628 codec_enc_.g_pass = VPX_RC_LAST_PASS;
629 vpx_svc_set_options(&svc_,
630 "auto-alt-refs=1,1,1 scale-factors=1/1,1/1,1/1");
631 vpx_fixed_buf outputs[20];
632 memset(&outputs[0], 0, sizeof(outputs));
633 Pass2EncodeNFrames(&stats_buf, 20, 3, &outputs[0]);
634 DecodeNFrames(&outputs[0], 20);
635 DropLayersAndMakeItVP9Comaptible(&outputs[0], 20, 2, false);
636 DecodeNFrames(&outputs[0], 20);
637 DropLayersAndMakeItVP9Comaptible(&outputs[0], 20, 1, false);
638 DecodeNFrames(&outputs[0], 20);
640 FreeBitstreamBuffers(&outputs[0], 20);
643 TEST_F(SvcTest, SetMultipleFrameContextsOption) {
644 svc_.spatial_layers = 5;
645 vpx_codec_err_t res =
646 vpx_svc_set_options(&svc_, "multi-frame-contexts=1");
647 EXPECT_EQ(VPX_CODEC_OK, res);
648 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
649 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
651 svc_.spatial_layers = 2;
652 res = vpx_svc_set_options(&svc_, "multi-frame-contexts=1");
656 TEST_F(SvcTest, TwoPassEncode2SpatialLayersWithMultipleFrameContexts) {
658 std::string stats_buf;
659 Pass1EncodeNFrames(10, 2, &stats_buf);
661 // Second pass encode
662 codec_enc_.g_pass = VPX_RC_LAST_PASS;
663 codec_enc_.g_error_resilient = 0;
664 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 multi-frame-contexts=1");
665 vpx_fixed_buf outputs[10];
666 memset(&outputs[0], 0, sizeof(outputs));
667 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
668 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 2, true);
669 DecodeNFrames(&outputs[0], 10);
670 FreeBitstreamBuffers(&outputs[0], 10);
674 TwoPassEncode2SpatialLayersWithMultipleFrameContextsDecodeBaselayer) {
676 std::string stats_buf;
677 Pass1EncodeNFrames(10, 2, &stats_buf);
679 // Second pass encode
680 codec_enc_.g_pass = VPX_RC_LAST_PASS;
681 codec_enc_.g_error_resilient = 0;
682 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 multi-frame-contexts=1");
683 vpx_fixed_buf outputs[10];
684 memset(&outputs[0], 0, sizeof(outputs));
685 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
686 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, true);
687 DecodeNFrames(&outputs[0], 10);
688 FreeBitstreamBuffers(&outputs[0], 10);
691 TEST_F(SvcTest, TwoPassEncode2SNRLayersWithMultipleFrameContexts) {
693 std::string stats_buf;
694 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1");
695 Pass1EncodeNFrames(10, 2, &stats_buf);
697 // Second pass encode
698 codec_enc_.g_pass = VPX_RC_LAST_PASS;
699 codec_enc_.g_error_resilient = 0;
700 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 scale-factors=1/1,1/1 "
701 "multi-frame-contexts=1");
702 vpx_fixed_buf outputs[10];
703 memset(&outputs[0], 0, sizeof(outputs));
704 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
705 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 2, true);
706 DecodeNFrames(&outputs[0], 10);
707 FreeBitstreamBuffers(&outputs[0], 10);
711 TwoPassEncode3SNRLayersWithMultipleFrameContextsDecode321Layer) {
713 std::string stats_buf;
714 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1,1/1");
715 Pass1EncodeNFrames(10, 3, &stats_buf);
717 // Second pass encode
718 codec_enc_.g_pass = VPX_RC_LAST_PASS;
719 codec_enc_.g_error_resilient = 0;
720 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1,1 scale-factors=1/1,1/1,1/1 "
721 "multi-frame-contexts=1");
722 vpx_fixed_buf outputs[10];
723 memset(&outputs[0], 0, sizeof(outputs));
724 Pass2EncodeNFrames(&stats_buf, 10, 3, &outputs[0]);
726 vpx_fixed_buf outputs_new[10];
727 for (int i = 0; i < 10; ++i) {
728 outputs_new[i].buf = malloc(outputs[i].sz + 16);
729 ASSERT_TRUE(outputs_new[i].buf != NULL);
730 memcpy(outputs_new[i].buf, outputs[i].buf, outputs[i].sz);
731 outputs_new[i].sz = outputs[i].sz;
733 DropLayersAndMakeItVP9Comaptible(&outputs_new[0], 10, 3, true);
734 DecodeNFrames(&outputs_new[0], 10);
736 for (int i = 0; i < 10; ++i) {
737 memcpy(outputs_new[i].buf, outputs[i].buf, outputs[i].sz);
738 outputs_new[i].sz = outputs[i].sz;
740 DropLayersAndMakeItVP9Comaptible(&outputs_new[0], 10, 2, true);
741 DecodeNFrames(&outputs_new[0], 10);
743 for (int i = 0; i < 10; ++i) {
744 memcpy(outputs_new[i].buf, outputs[i].buf, outputs[i].sz);
745 outputs_new[i].sz = outputs[i].sz;
747 DropLayersAndMakeItVP9Comaptible(&outputs_new[0], 10, 1, true);
748 DecodeNFrames(&outputs_new[0], 10);
750 FreeBitstreamBuffers(&outputs[0], 10);
751 FreeBitstreamBuffers(&outputs_new[0], 10);
754 TEST_F(SvcTest, TwoPassEncode2TemporalLayers) {
756 std::string stats_buf;
757 vpx_svc_set_options(&svc_, "scale-factors=1/1");
758 svc_.temporal_layers = 2;
759 Pass1EncodeNFrames(10, 1, &stats_buf);
761 // Second pass encode
762 codec_enc_.g_pass = VPX_RC_LAST_PASS;
763 svc_.temporal_layers = 2;
764 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1");
765 vpx_fixed_buf outputs[10];
766 memset(&outputs[0], 0, sizeof(outputs));
767 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
768 DecodeNFrames(&outputs[0], 10);
769 FreeBitstreamBuffers(&outputs[0], 10);
772 TEST_F(SvcTest, TwoPassEncode2TemporalLayersWithMultipleFrameContexts) {
774 std::string stats_buf;
775 vpx_svc_set_options(&svc_, "scale-factors=1/1");
776 svc_.temporal_layers = 2;
777 Pass1EncodeNFrames(10, 1, &stats_buf);
779 // Second pass encode
780 codec_enc_.g_pass = VPX_RC_LAST_PASS;
781 svc_.temporal_layers = 2;
782 codec_enc_.g_error_resilient = 0;
783 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1 "
784 "multi-frame-contexts=1");
785 vpx_fixed_buf outputs[10];
786 memset(&outputs[0], 0, sizeof(outputs));
787 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
788 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, true);
789 DecodeNFrames(&outputs[0], 10);
790 FreeBitstreamBuffers(&outputs[0], 10);
793 TEST_F(SvcTest, TwoPassEncode2TemporalLayersDecodeBaseLayer) {
795 std::string stats_buf;
796 vpx_svc_set_options(&svc_, "scale-factors=1/1");
797 svc_.temporal_layers = 2;
798 Pass1EncodeNFrames(10, 1, &stats_buf);
800 // Second pass encode
801 codec_enc_.g_pass = VPX_RC_LAST_PASS;
802 svc_.temporal_layers = 2;
803 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1");
804 vpx_fixed_buf outputs[10];
805 memset(&outputs[0], 0, sizeof(outputs));
806 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
808 vpx_fixed_buf base_layer[5];
809 for (int i = 0; i < 5; ++i)
810 base_layer[i] = outputs[i * 2];
812 DecodeNFrames(&base_layer[0], 5);
813 FreeBitstreamBuffers(&outputs[0], 10);
817 TwoPassEncode2TemporalLayersWithMultipleFrameContextsDecodeBaseLayer) {
819 std::string stats_buf;
820 vpx_svc_set_options(&svc_, "scale-factors=1/1");
821 svc_.temporal_layers = 2;
822 Pass1EncodeNFrames(10, 1, &stats_buf);
824 // Second pass encode
825 codec_enc_.g_pass = VPX_RC_LAST_PASS;
826 svc_.temporal_layers = 2;
827 codec_enc_.g_error_resilient = 0;
828 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1 "
829 "multi-frame-contexts=1");
830 vpx_fixed_buf outputs[10];
831 memset(&outputs[0], 0, sizeof(outputs));
832 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
833 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, true);
835 vpx_fixed_buf base_layer[5];
836 for (int i = 0; i < 5; ++i)
837 base_layer[i] = outputs[i * 2];
839 DecodeNFrames(&base_layer[0], 5);
840 FreeBitstreamBuffers(&outputs[0], 10);