OSDN Git Service

test: add some avce context tests
[android-x86/hardware-intel-common-vaapi.git] / test / i965_avce_context_test.cpp
1 /*
2  * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 #include "i965_avce_test_common.h"
26 #include "i965_streamable.h"
27 #include "i965_test_fixture.h"
28
29 #include <map>
30 #include <tuple>
31 #include <vector>
32
33 namespace AVC {
34 namespace Encode {
35
36 class AVCEContextTest
37     : public I965TestFixture
38     , public ::testing::WithParamInterface<
39         std::tuple<VAProfile, VAEntrypoint> >
40 {
41 protected:
42     void SetUp()
43     {
44         I965TestFixture::SetUp();
45         std::tie(profile, entrypoint) = GetParam();
46     }
47
48     void TearDown()
49     {
50         if (context != VA_INVALID_ID)
51             destroyContext(context);
52         if (config != VA_INVALID_ID)
53             destroyConfig(config);
54         I965TestFixture::TearDown();
55     }
56
57     operator struct intel_encoder_context const *()
58     {
59         if (config == VA_INVALID_ID) return NULL;
60
61         struct i965_driver_data *i965(*this);
62         if (not i965) return NULL;
63
64         struct object_context const *obj_context = CONTEXT(context);
65         if (not obj_context) return NULL;
66
67         return reinterpret_cast<struct intel_encoder_context const *>(
68             obj_context->hw_context);
69     }
70
71     VAProfile       profile;
72     VAEntrypoint    entrypoint;
73     VAConfigID      config = VA_INVALID_ID;
74     VAContextID     context = VA_INVALID_ID;
75 };
76
77 TEST_P(AVCEContextTest, RateControl)
78 {
79     if (not IsSupported(profile, entrypoint)) {
80         RecordProperty("skipped", true);
81         std::cout << "[  SKIPPED ] " << getFullTestName()
82             << " is unsupported on this hardware" << std::endl;
83         return;
84     }
85
86     static const std::vector<unsigned> rateControls = {
87         VA_RC_NONE, VA_RC_CBR, VA_RC_VBR, VA_RC_VCM, VA_RC_CQP,
88         VA_RC_VBR_CONSTRAINED, VA_RC_MB,
89     };
90
91     for (auto rc : rateControls) {
92         ConfigAttribs attribs(1, {type:VAConfigAttribRateControl, value:rc});
93         config = createConfig(profile, entrypoint, attribs);
94         context = createContext(config, 1, 1);
95         if (HasFailure()) continue;
96
97         struct intel_encoder_context const *hw_context(*this);
98         EXPECT_PTR(hw_context);
99         if (HasFailure()) continue;
100
101         EXPECT_EQ(rc, hw_context->rate_control_mode);
102
103         destroyContext(context);
104         destroyConfig(config);
105         context = VA_INVALID_ID;
106         config = VA_INVALID_ID;
107     }
108 }
109
110 TEST_P(AVCEContextTest, Codec)
111 {
112     if (not IsSupported(profile, entrypoint)) {
113         RecordProperty("skipped", true);
114         std::cout << "[  SKIPPED ] " << getFullTestName()
115             << " is unsupported on this hardware" << std::endl;
116         return;
117     }
118
119     static const std::map<VAProfile, int> codecs = {
120         {VAProfileH264ConstrainedBaseline, CODEC_H264},
121         {VAProfileH264Main, CODEC_H264},
122         {VAProfileH264High, CODEC_H264},
123         {VAProfileH264MultiviewHigh, CODEC_H264_MVC},
124         {VAProfileH264StereoHigh, CODEC_H264_MVC},
125     };
126
127     ASSERT_NO_FAILURE(
128         config = createConfig(profile, entrypoint);
129         context = createContext(config, 1, 1);
130     );
131
132     struct intel_encoder_context const *hw_context(*this);
133     ASSERT_PTR(hw_context);
134
135     EXPECT_EQ(codecs.at(profile), hw_context->codec);
136 }
137
138 TEST_P(AVCEContextTest, LowPowerMode)
139 {
140     if (not IsSupported(profile, entrypoint)) {
141         RecordProperty("skipped", true);
142         std::cout << "[  SKIPPED ] " << getFullTestName()
143             << " is unsupported on this hardware" << std::endl;
144         return;
145     }
146
147     ASSERT_NO_FAILURE(
148         config = createConfig(profile, entrypoint);
149         context = createContext(config, 1, 1);
150     );
151
152     struct intel_encoder_context const *hw_context(*this);
153     ASSERT_PTR(hw_context);
154
155     EXPECT_EQ(
156         (entrypoint == VAEntrypointEncSliceLP ? 1u : 0u),
157         hw_context->low_power_mode
158     );
159 }
160
161 TEST_P(AVCEContextTest, ROINotSpecified)
162 {
163     if (not IsSupported(profile, entrypoint)) {
164         RecordProperty("skipped", true);
165         std::cout << "[  SKIPPED ] " << getFullTestName()
166             << " is unsupported on this hardware" << std::endl;
167         return;
168     }
169
170     // The lack of the VAConfigAttribEncROI config attribute
171     // will disable it.
172     ASSERT_NO_FAILURE(
173         config = createConfig(profile, entrypoint);
174         context = createContext(config, 1, 1);
175     );
176
177     struct intel_encoder_context const *hw_context(*this);
178     ASSERT_PTR(hw_context);
179
180     EXPECT_EQ(0u, hw_context->context_roi);
181 }
182
183 TEST_P(AVCEContextTest, ROISpecified)
184 {
185     if (not IsSupported(profile, entrypoint)) {
186         RecordProperty("skipped", true);
187         std::cout << "[  SKIPPED ] " << getFullTestName()
188             << " is unsupported on this hardware" << std::endl;
189         return;
190     }
191
192     static const std::map<VAProfile, unsigned> roiSupport = {
193         {VAProfileH264ConstrainedBaseline, 1}, {VAProfileH264Main, 1},
194         {VAProfileH264High, 1}, {VAProfileH264MultiviewHigh, 0},
195         {VAProfileH264StereoHigh, 0},
196     };
197
198     // The presence of the VAConfigAttribEncROI config attribute
199     // will enable it for supported profile
200     ConfigAttribs attribs(1, {type:VAConfigAttribEncROI});
201     ASSERT_NO_FAILURE(
202         config = createConfig(profile, entrypoint, attribs);
203         context = createContext(config, 1, 1);
204     );
205
206     struct intel_encoder_context const *hw_context(*this);
207     ASSERT_PTR(hw_context);
208
209     EXPECT_EQ(roiSupport.at(profile), hw_context->context_roi);
210 }
211
212 TEST_P(AVCEContextTest, QualityRange)
213 {
214     if (not IsSupported(profile, entrypoint)) {
215         RecordProperty("skipped", true);
216         std::cout << "[  SKIPPED ] " << getFullTestName()
217             << " is unsupported on this hardware" << std::endl;
218         return;
219     }
220
221     const std::map<VAProfile, unsigned> qranges = {
222         {VAProfileH264ConstrainedBaseline, entrypoint == VAEntrypointEncSliceLP
223             ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE},
224         {VAProfileH264Main, entrypoint == VAEntrypointEncSliceLP
225             ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE},
226         {VAProfileH264High, entrypoint == VAEntrypointEncSliceLP
227             ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE},
228         {VAProfileH264MultiviewHigh, 1u},
229         {VAProfileH264StereoHigh, 1u},
230     };
231
232     ASSERT_NO_FAILURE(
233         config = createConfig(profile, entrypoint);
234         context = createContext(config, 1, 1);
235     );
236
237     struct intel_encoder_context const *hw_context(*this);
238     ASSERT_PTR(hw_context);
239
240     EXPECT_EQ(qranges.at(profile), hw_context->quality_range);
241 }
242
243 INSTANTIATE_TEST_CASE_P(
244     AVCEncode, AVCEContextTest, ::testing::Values(
245         std::make_tuple(VAProfileH264ConstrainedBaseline, VAEntrypointEncSlice),
246         std::make_tuple(VAProfileH264ConstrainedBaseline, VAEntrypointEncSliceLP),
247         std::make_tuple(VAProfileH264Main, VAEntrypointEncSlice),
248         std::make_tuple(VAProfileH264Main, VAEntrypointEncSliceLP),
249         std::make_tuple(VAProfileH264High, VAEntrypointEncSlice),
250         std::make_tuple(VAProfileH264High, VAEntrypointEncSliceLP),
251         std::make_tuple(VAProfileH264MultiviewHigh, VAEntrypointEncSlice),
252         std::make_tuple(VAProfileH264StereoHigh, VAEntrypointEncSlice)
253     )
254 );
255
256 } // namespace Encode
257 } // namespace AVC