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_, "max-quantizers=nothing");
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_, "min-quantizers=nothing");
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 res = vpx_svc_set_options(&svc_, "max-quantizers=40");
466 EXPECT_EQ(VPX_CODEC_OK, res);
467 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
468 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
470 res = vpx_svc_set_options(&svc_, "min-quantizers=40");
471 EXPECT_EQ(VPX_CODEC_OK, res);
472 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
473 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
475 res = vpx_svc_set_options(&svc_, "max-quantizers=30,30 min-quantizers=40,40");
476 EXPECT_EQ(VPX_CODEC_OK, res);
477 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
478 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
480 res = vpx_svc_set_options(&svc_, "max-quantizers=40,40 min-quantizers=30,30");
484 TEST_F(SvcTest, SetAutoAltRefOption) {
485 svc_.spatial_layers = 5;
486 vpx_codec_err_t res = vpx_svc_set_options(&svc_, "auto-alt-refs=none");
487 EXPECT_EQ(VPX_CODEC_OK, res);
488 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
489 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
491 res = vpx_svc_set_options(&svc_, "auto-alt-refs=1,1,1,1,0");
492 EXPECT_EQ(VPX_CODEC_OK, res);
493 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
494 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
496 vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0");
500 // Test that decoder can handle an SVC frame as the first frame in a sequence.
501 TEST_F(SvcTest, OnePassEncodeOneFrame) {
502 codec_enc_.g_pass = VPX_RC_ONE_PASS;
503 vpx_fixed_buf output = {0};
504 Pass2EncodeNFrames(NULL, 1, 2, &output);
505 DecodeNFrames(&output, 1);
506 FreeBitstreamBuffers(&output, 1);
509 TEST_F(SvcTest, OnePassEncodeThreeFrames) {
510 codec_enc_.g_pass = VPX_RC_ONE_PASS;
511 vpx_fixed_buf outputs[3];
512 memset(&outputs[0], 0, sizeof(outputs));
513 Pass2EncodeNFrames(NULL, 3, 2, &outputs[0]);
514 DecodeNFrames(&outputs[0], 3);
515 FreeBitstreamBuffers(&outputs[0], 3);
518 TEST_F(SvcTest, TwoPassEncode10Frames) {
520 std::string stats_buf;
521 Pass1EncodeNFrames(10, 2, &stats_buf);
523 // Second pass encode
524 codec_enc_.g_pass = VPX_RC_LAST_PASS;
525 vpx_fixed_buf outputs[10];
526 memset(&outputs[0], 0, sizeof(outputs));
527 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
528 DecodeNFrames(&outputs[0], 10);
529 FreeBitstreamBuffers(&outputs[0], 10);
532 TEST_F(SvcTest, TwoPassEncode20FramesWithAltRef) {
534 std::string stats_buf;
535 Pass1EncodeNFrames(20, 2, &stats_buf);
537 // Second pass encode
538 codec_enc_.g_pass = VPX_RC_LAST_PASS;
539 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1");
540 vpx_fixed_buf outputs[20];
541 memset(&outputs[0], 0, sizeof(outputs));
542 Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]);
543 DecodeNFrames(&outputs[0], 20);
544 FreeBitstreamBuffers(&outputs[0], 20);
547 TEST_F(SvcTest, TwoPassEncode2SpatialLayersDecodeBaseLayerOnly) {
549 std::string stats_buf;
550 Pass1EncodeNFrames(10, 2, &stats_buf);
552 // Second pass encode
553 codec_enc_.g_pass = VPX_RC_LAST_PASS;
554 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1");
555 vpx_fixed_buf outputs[10];
556 memset(&outputs[0], 0, sizeof(outputs));
557 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
558 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, false);
559 DecodeNFrames(&outputs[0], 10);
560 FreeBitstreamBuffers(&outputs[0], 10);
563 TEST_F(SvcTest, TwoPassEncode5SpatialLayersDecode54321Layers) {
565 std::string stats_buf;
566 Pass1EncodeNFrames(10, 5, &stats_buf);
568 // Second pass encode
569 codec_enc_.g_pass = VPX_RC_LAST_PASS;
570 vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0");
571 vpx_fixed_buf outputs[10];
572 memset(&outputs[0], 0, sizeof(outputs));
573 Pass2EncodeNFrames(&stats_buf, 10, 5, &outputs[0]);
575 DecodeNFrames(&outputs[0], 10);
576 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 4, false);
577 DecodeNFrames(&outputs[0], 10);
578 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 3, false);
579 DecodeNFrames(&outputs[0], 10);
580 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 2, false);
581 DecodeNFrames(&outputs[0], 10);
582 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, false);
583 DecodeNFrames(&outputs[0], 10);
585 FreeBitstreamBuffers(&outputs[0], 10);
588 TEST_F(SvcTest, TwoPassEncode2SNRLayers) {
590 std::string stats_buf;
591 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1");
592 Pass1EncodeNFrames(20, 2, &stats_buf);
594 // Second pass encode
595 codec_enc_.g_pass = VPX_RC_LAST_PASS;
596 vpx_svc_set_options(&svc_,
597 "auto-alt-refs=1,1 scale-factors=1/1,1/1");
598 vpx_fixed_buf outputs[20];
599 memset(&outputs[0], 0, sizeof(outputs));
600 Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]);
601 DecodeNFrames(&outputs[0], 20);
602 FreeBitstreamBuffers(&outputs[0], 20);
605 TEST_F(SvcTest, TwoPassEncode3SNRLayersDecode321Layers) {
607 std::string stats_buf;
608 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1,1/1");
609 Pass1EncodeNFrames(20, 3, &stats_buf);
611 // Second pass encode
612 codec_enc_.g_pass = VPX_RC_LAST_PASS;
613 vpx_svc_set_options(&svc_,
614 "auto-alt-refs=1,1,1 scale-factors=1/1,1/1,1/1");
615 vpx_fixed_buf outputs[20];
616 memset(&outputs[0], 0, sizeof(outputs));
617 Pass2EncodeNFrames(&stats_buf, 20, 3, &outputs[0]);
618 DecodeNFrames(&outputs[0], 20);
619 DropLayersAndMakeItVP9Comaptible(&outputs[0], 20, 2, false);
620 DecodeNFrames(&outputs[0], 20);
621 DropLayersAndMakeItVP9Comaptible(&outputs[0], 20, 1, false);
622 DecodeNFrames(&outputs[0], 20);
624 FreeBitstreamBuffers(&outputs[0], 20);
627 TEST_F(SvcTest, SetMultipleFrameContextsOption) {
628 svc_.spatial_layers = 5;
629 vpx_codec_err_t res =
630 vpx_svc_set_options(&svc_, "multi-frame-contexts=1");
631 EXPECT_EQ(VPX_CODEC_OK, res);
632 res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
633 EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
635 svc_.spatial_layers = 2;
636 res = vpx_svc_set_options(&svc_, "multi-frame-contexts=1");
640 TEST_F(SvcTest, TwoPassEncode2SpatialLayersWithMultipleFrameContexts) {
642 std::string stats_buf;
643 Pass1EncodeNFrames(10, 2, &stats_buf);
645 // Second pass encode
646 codec_enc_.g_pass = VPX_RC_LAST_PASS;
647 codec_enc_.g_error_resilient = 0;
648 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 multi-frame-contexts=1");
649 vpx_fixed_buf outputs[10];
650 memset(&outputs[0], 0, sizeof(outputs));
651 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
652 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 2, true);
653 DecodeNFrames(&outputs[0], 10);
654 FreeBitstreamBuffers(&outputs[0], 10);
658 TwoPassEncode2SpatialLayersWithMultipleFrameContextsDecodeBaselayer) {
660 std::string stats_buf;
661 Pass1EncodeNFrames(10, 2, &stats_buf);
663 // Second pass encode
664 codec_enc_.g_pass = VPX_RC_LAST_PASS;
665 codec_enc_.g_error_resilient = 0;
666 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 multi-frame-contexts=1");
667 vpx_fixed_buf outputs[10];
668 memset(&outputs[0], 0, sizeof(outputs));
669 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
670 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, true);
671 DecodeNFrames(&outputs[0], 10);
672 FreeBitstreamBuffers(&outputs[0], 10);
675 TEST_F(SvcTest, TwoPassEncode2SNRLayersWithMultipleFrameContexts) {
677 std::string stats_buf;
678 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1");
679 Pass1EncodeNFrames(10, 2, &stats_buf);
681 // Second pass encode
682 codec_enc_.g_pass = VPX_RC_LAST_PASS;
683 codec_enc_.g_error_resilient = 0;
684 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1 scale-factors=1/1,1/1 "
685 "multi-frame-contexts=1");
686 vpx_fixed_buf outputs[10];
687 memset(&outputs[0], 0, sizeof(outputs));
688 Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
689 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 2, true);
690 DecodeNFrames(&outputs[0], 10);
691 FreeBitstreamBuffers(&outputs[0], 10);
695 TwoPassEncode3SNRLayersWithMultipleFrameContextsDecode321Layer) {
697 std::string stats_buf;
698 vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1,1/1");
699 Pass1EncodeNFrames(10, 3, &stats_buf);
701 // Second pass encode
702 codec_enc_.g_pass = VPX_RC_LAST_PASS;
703 codec_enc_.g_error_resilient = 0;
704 vpx_svc_set_options(&svc_, "auto-alt-refs=1,1,1 scale-factors=1/1,1/1,1/1 "
705 "multi-frame-contexts=1");
706 vpx_fixed_buf outputs[10];
707 memset(&outputs[0], 0, sizeof(outputs));
708 Pass2EncodeNFrames(&stats_buf, 10, 3, &outputs[0]);
710 vpx_fixed_buf outputs_new[10];
711 for (int i = 0; i < 10; ++i) {
712 outputs_new[i].buf = malloc(outputs[i].sz + 16);
713 ASSERT_TRUE(outputs_new[i].buf != NULL);
714 memcpy(outputs_new[i].buf, outputs[i].buf, outputs[i].sz);
715 outputs_new[i].sz = outputs[i].sz;
717 DropLayersAndMakeItVP9Comaptible(&outputs_new[0], 10, 3, true);
718 DecodeNFrames(&outputs_new[0], 10);
720 for (int i = 0; i < 10; ++i) {
721 memcpy(outputs_new[i].buf, outputs[i].buf, outputs[i].sz);
722 outputs_new[i].sz = outputs[i].sz;
724 DropLayersAndMakeItVP9Comaptible(&outputs_new[0], 10, 2, true);
725 DecodeNFrames(&outputs_new[0], 10);
727 for (int i = 0; i < 10; ++i) {
728 memcpy(outputs_new[i].buf, outputs[i].buf, outputs[i].sz);
729 outputs_new[i].sz = outputs[i].sz;
731 DropLayersAndMakeItVP9Comaptible(&outputs_new[0], 10, 1, true);
732 DecodeNFrames(&outputs_new[0], 10);
734 FreeBitstreamBuffers(&outputs[0], 10);
735 FreeBitstreamBuffers(&outputs_new[0], 10);
738 TEST_F(SvcTest, TwoPassEncode2TemporalLayers) {
740 std::string stats_buf;
741 vpx_svc_set_options(&svc_, "scale-factors=1/1");
742 svc_.temporal_layers = 2;
743 Pass1EncodeNFrames(10, 1, &stats_buf);
745 // Second pass encode
746 codec_enc_.g_pass = VPX_RC_LAST_PASS;
747 svc_.temporal_layers = 2;
748 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1");
749 vpx_fixed_buf outputs[10];
750 memset(&outputs[0], 0, sizeof(outputs));
751 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
752 DecodeNFrames(&outputs[0], 10);
753 FreeBitstreamBuffers(&outputs[0], 10);
756 TEST_F(SvcTest, TwoPassEncode2TemporalLayersWithMultipleFrameContexts) {
758 std::string stats_buf;
759 vpx_svc_set_options(&svc_, "scale-factors=1/1");
760 svc_.temporal_layers = 2;
761 Pass1EncodeNFrames(10, 1, &stats_buf);
763 // Second pass encode
764 codec_enc_.g_pass = VPX_RC_LAST_PASS;
765 svc_.temporal_layers = 2;
766 codec_enc_.g_error_resilient = 0;
767 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1 "
768 "multi-frame-contexts=1");
769 vpx_fixed_buf outputs[10];
770 memset(&outputs[0], 0, sizeof(outputs));
771 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
772 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, true);
773 DecodeNFrames(&outputs[0], 10);
774 FreeBitstreamBuffers(&outputs[0], 10);
777 TEST_F(SvcTest, TwoPassEncode2TemporalLayersDecodeBaseLayer) {
779 std::string stats_buf;
780 vpx_svc_set_options(&svc_, "scale-factors=1/1");
781 svc_.temporal_layers = 2;
782 Pass1EncodeNFrames(10, 1, &stats_buf);
784 // Second pass encode
785 codec_enc_.g_pass = VPX_RC_LAST_PASS;
786 svc_.temporal_layers = 2;
787 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1");
788 vpx_fixed_buf outputs[10];
789 memset(&outputs[0], 0, sizeof(outputs));
790 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
792 vpx_fixed_buf base_layer[5];
793 for (int i = 0; i < 5; ++i)
794 base_layer[i] = outputs[i * 2];
796 DecodeNFrames(&base_layer[0], 5);
797 FreeBitstreamBuffers(&outputs[0], 10);
801 TwoPassEncode2TemporalLayersWithMultipleFrameContextsDecodeBaseLayer) {
803 std::string stats_buf;
804 vpx_svc_set_options(&svc_, "scale-factors=1/1");
805 svc_.temporal_layers = 2;
806 Pass1EncodeNFrames(10, 1, &stats_buf);
808 // Second pass encode
809 codec_enc_.g_pass = VPX_RC_LAST_PASS;
810 svc_.temporal_layers = 2;
811 codec_enc_.g_error_resilient = 0;
812 vpx_svc_set_options(&svc_, "auto-alt-refs=1 scale-factors=1/1 "
813 "multi-frame-contexts=1");
814 vpx_fixed_buf outputs[10];
815 memset(&outputs[0], 0, sizeof(outputs));
816 Pass2EncodeNFrames(&stats_buf, 10, 1, &outputs[0]);
817 DropLayersAndMakeItVP9Comaptible(&outputs[0], 10, 1, true);
819 vpx_fixed_buf base_layer[5];
820 for (int i = 0; i < 5; ++i)
821 base_layer[i] = outputs[i * 2];
823 DecodeNFrames(&base_layer[0], 5);
824 FreeBitstreamBuffers(&outputs[0], 10);