Merge "remove mmx variance functions"
[aom.git] / test / superframe_test.cc
blob90aa75b41e750bb5ba5ed4bd50c7a1fa1c171cb0
1 /*
2 * Copyright (c) 2012 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.
9 */
10 #include <climits>
11 #include "third_party/googletest/src/include/gtest/gtest.h"
12 #include "test/codec_factory.h"
13 #include "test/encode_test_driver.h"
14 #include "test/i420_video_source.h"
15 #include "test/util.h"
17 namespace {
19 const int kTestMode = 0;
20 const int kSuperframeSyntax = 1;
22 typedef std::tr1::tuple<libvpx_test::TestMode,int> SuperframeTestParam;
24 class SuperframeTest : public ::libvpx_test::EncoderTest,
25 public ::libvpx_test::CodecTestWithParam<SuperframeTestParam> {
26 protected:
27 SuperframeTest() : EncoderTest(GET_PARAM(0)), modified_buf_(NULL),
28 last_sf_pts_(0) {}
29 virtual ~SuperframeTest() {}
31 virtual void SetUp() {
32 InitializeConfig();
33 const SuperframeTestParam input = GET_PARAM(1);
34 const libvpx_test::TestMode mode = std::tr1::get<kTestMode>(input);
35 const int syntax = std::tr1::get<kSuperframeSyntax>(input);
36 SetMode(mode);
37 sf_count_ = 0;
38 sf_count_max_ = INT_MAX;
39 is_vp10_style_superframe_ = syntax;
42 virtual void TearDown() {
43 delete[] modified_buf_;
46 virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
47 libvpx_test::Encoder *encoder) {
48 if (video->frame() == 1) {
49 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
53 virtual const vpx_codec_cx_pkt_t * MutateEncoderOutputHook(
54 const vpx_codec_cx_pkt_t *pkt) {
55 if (pkt->kind != VPX_CODEC_CX_FRAME_PKT)
56 return pkt;
58 const uint8_t *buffer = reinterpret_cast<uint8_t*>(pkt->data.frame.buf);
59 const uint8_t marker = buffer[pkt->data.frame.sz - 1];
60 const int frames = (marker & 0x7) + 1;
61 const int mag = ((marker >> 3) & 3) + 1;
62 const unsigned int index_sz =
63 2 + mag * (frames - is_vp10_style_superframe_);
64 if ((marker & 0xe0) == 0xc0 &&
65 pkt->data.frame.sz >= index_sz &&
66 buffer[pkt->data.frame.sz - index_sz] == marker) {
67 // frame is a superframe. strip off the index.
68 if (modified_buf_)
69 delete[] modified_buf_;
70 modified_buf_ = new uint8_t[pkt->data.frame.sz - index_sz];
71 memcpy(modified_buf_, pkt->data.frame.buf,
72 pkt->data.frame.sz - index_sz);
73 modified_pkt_ = *pkt;
74 modified_pkt_.data.frame.buf = modified_buf_;
75 modified_pkt_.data.frame.sz -= index_sz;
77 sf_count_++;
78 last_sf_pts_ = pkt->data.frame.pts;
79 return &modified_pkt_;
82 // Make sure we do a few frames after the last SF
83 abort_ |= sf_count_ > sf_count_max_ &&
84 pkt->data.frame.pts - last_sf_pts_ >= 5;
85 return pkt;
88 int is_vp10_style_superframe_;
89 int sf_count_;
90 int sf_count_max_;
91 vpx_codec_cx_pkt_t modified_pkt_;
92 uint8_t *modified_buf_;
93 vpx_codec_pts_t last_sf_pts_;
96 TEST_P(SuperframeTest, TestSuperframeIndexIsOptional) {
97 sf_count_max_ = 0; // early exit on successful test.
98 cfg_.g_lag_in_frames = 25;
100 ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
101 30, 1, 0, 40);
102 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
103 EXPECT_EQ(sf_count_, 1);
106 VP9_INSTANTIATE_TEST_CASE(SuperframeTest, ::testing::Combine(
107 ::testing::Values(::libvpx_test::kTwoPassGood),
108 ::testing::Values(0)));
110 VP10_INSTANTIATE_TEST_CASE(SuperframeTest, ::testing::Combine(
111 ::testing::Values(::libvpx_test::kTwoPassGood),
112 ::testing::Values(CONFIG_MISC_FIXES)));
113 } // namespace