OSDN Git Service

68335d4545a4df7a39b6a81c64b6d5ae673b473a
[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         if (IS_GEN9(i965->intel.device_info))
65             is_gen9 = true;
66
67         struct object_context const *obj_context = CONTEXT(context);
68         if (not obj_context) return NULL;
69
70         return reinterpret_cast<struct intel_encoder_context const *>(
71             obj_context->hw_context);
72     }
73
74     VAProfile       profile;
75     VAEntrypoint    entrypoint;
76     VAConfigID      config = VA_INVALID_ID;
77     VAContextID     context = VA_INVALID_ID;
78     bool            is_gen9 = false;
79 };
80
81 TEST_P(AVCEContextTest, RateControl)
82 {
83     if (not IsSupported(profile, entrypoint)) {
84         RecordProperty("skipped", true);
85         std::cout << "[  SKIPPED ] " << getFullTestName()
86             << " is unsupported on this hardware" << std::endl;
87         return;
88     }
89
90     static const std::vector<unsigned> rateControls = {
91         VA_RC_NONE, VA_RC_CBR, VA_RC_VBR, VA_RC_VCM, VA_RC_CQP,
92         VA_RC_VBR_CONSTRAINED, VA_RC_MB,
93     };
94
95     for (auto rc : rateControls) {
96         ConfigAttribs attribs(1, {type:VAConfigAttribRateControl, value:rc});
97         config = createConfig(profile, entrypoint, attribs);
98         context = createContext(config, 1, 1);
99         if (HasFailure()) continue;
100
101         struct intel_encoder_context const *hw_context(*this);
102         EXPECT_PTR(hw_context);
103         if (HasFailure()) continue;
104
105         EXPECT_EQ(rc, hw_context->rate_control_mode);
106
107         destroyContext(context);
108         destroyConfig(config);
109         context = VA_INVALID_ID;
110         config = VA_INVALID_ID;
111     }
112 }
113
114 TEST_P(AVCEContextTest, Codec)
115 {
116     if (not IsSupported(profile, entrypoint)) {
117         RecordProperty("skipped", true);
118         std::cout << "[  SKIPPED ] " << getFullTestName()
119             << " is unsupported on this hardware" << std::endl;
120         return;
121     }
122
123     static const std::map<VAProfile, int> codecs = {
124         {VAProfileH264ConstrainedBaseline, CODEC_H264},
125         {VAProfileH264Main, CODEC_H264},
126         {VAProfileH264High, CODEC_H264},
127         {VAProfileH264MultiviewHigh, CODEC_H264_MVC},
128         {VAProfileH264StereoHigh, CODEC_H264_MVC},
129     };
130
131     ASSERT_NO_FAILURE(
132         config = createConfig(profile, entrypoint);
133         context = createContext(config, 1, 1);
134     );
135
136     struct intel_encoder_context const *hw_context(*this);
137     ASSERT_PTR(hw_context);
138
139     EXPECT_EQ(codecs.at(profile), hw_context->codec);
140 }
141
142 TEST_P(AVCEContextTest, LowPowerMode)
143 {
144     if (not IsSupported(profile, entrypoint)) {
145         RecordProperty("skipped", true);
146         std::cout << "[  SKIPPED ] " << getFullTestName()
147             << " is unsupported on this hardware" << std::endl;
148         return;
149     }
150
151     ASSERT_NO_FAILURE(
152         config = createConfig(profile, entrypoint);
153         context = createContext(config, 1, 1);
154     );
155
156     struct intel_encoder_context const *hw_context(*this);
157     ASSERT_PTR(hw_context);
158
159     EXPECT_EQ(
160         (entrypoint == VAEntrypointEncSliceLP ? 1u : 0u),
161         hw_context->low_power_mode
162     );
163 }
164
165 TEST_P(AVCEContextTest, ROINotSpecified)
166 {
167     if (not IsSupported(profile, entrypoint)) {
168         RecordProperty("skipped", true);
169         std::cout << "[  SKIPPED ] " << getFullTestName()
170             << " is unsupported on this hardware" << std::endl;
171         return;
172     }
173
174     // The lack of the VAConfigAttribEncROI config attribute
175     // will disable it.
176     ASSERT_NO_FAILURE(
177         config = createConfig(profile, entrypoint);
178         context = createContext(config, 1, 1);
179     );
180
181     struct intel_encoder_context const *hw_context(*this);
182     ASSERT_PTR(hw_context);
183
184     EXPECT_EQ(0u, hw_context->context_roi);
185 }
186
187 TEST_P(AVCEContextTest, ROISpecified)
188 {
189     if (not IsSupported(profile, entrypoint)) {
190         RecordProperty("skipped", true);
191         std::cout << "[  SKIPPED ] " << getFullTestName()
192             << " is unsupported on this hardware" << std::endl;
193         return;
194     }
195
196     static const std::map<VAProfile, unsigned> roiSupport = {
197         {VAProfileH264ConstrainedBaseline, 1}, {VAProfileH264Main, 1},
198         {VAProfileH264High, 1}, {VAProfileH264MultiviewHigh, 0},
199         {VAProfileH264StereoHigh, 0},
200     };
201
202     // The presence of the VAConfigAttribEncROI config attribute
203     // will enable it for supported profile
204     ConfigAttribs attribs(1, {type:VAConfigAttribEncROI});
205     ASSERT_NO_FAILURE(
206         config = createConfig(profile, entrypoint, attribs);
207         context = createContext(config, 1, 1);
208     );
209
210     struct intel_encoder_context const *hw_context(*this);
211     ASSERT_PTR(hw_context);
212
213     EXPECT_EQ(roiSupport.at(profile), hw_context->context_roi);
214 }
215
216 TEST_P(AVCEContextTest, QualityRange)
217 {
218     if (not IsSupported(profile, entrypoint)) {
219         RecordProperty("skipped", true);
220         std::cout << "[  SKIPPED ] " << getFullTestName()
221             << " is unsupported on this hardware" << std::endl;
222         return;
223     }
224
225     ASSERT_NO_FAILURE(
226         config = createConfig(profile, entrypoint);
227         context = createContext(config, 1, 1);
228     );
229
230     struct intel_encoder_context const *hw_context(*this);
231     ASSERT_PTR(hw_context);
232
233     std::map<VAProfile, unsigned> qranges;
234     if(is_gen9) {
235         qranges = {
236             {VAProfileH264ConstrainedBaseline, entrypoint == VAEntrypointEncSliceLP
237                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE_AVC},
238             {VAProfileH264Main, entrypoint == VAEntrypointEncSliceLP
239                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE_AVC},
240             {VAProfileH264High, entrypoint == VAEntrypointEncSliceLP
241                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE_AVC},
242             {VAProfileH264MultiviewHigh, ENCODER_QUALITY_RANGE_AVC},
243             {VAProfileH264StereoHigh, ENCODER_QUALITY_RANGE_AVC},
244         };
245     }else {
246         qranges = {
247             {VAProfileH264ConstrainedBaseline, entrypoint == VAEntrypointEncSliceLP
248                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE},
249             {VAProfileH264Main, entrypoint == VAEntrypointEncSliceLP
250                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE},
251             {VAProfileH264High, entrypoint == VAEntrypointEncSliceLP
252                 ? ENCODER_LP_QUALITY_RANGE : ENCODER_QUALITY_RANGE},
253             {VAProfileH264MultiviewHigh, 1u},
254             {VAProfileH264StereoHigh, 1u},
255         };
256     }
257
258     EXPECT_EQ(qranges.at(profile), hw_context->quality_range);
259 }
260
261 INSTANTIATE_TEST_CASE_P(
262     AVCEncode, AVCEContextTest, ::testing::Values(
263         std::make_tuple(VAProfileH264ConstrainedBaseline, VAEntrypointEncSlice),
264         std::make_tuple(VAProfileH264ConstrainedBaseline, VAEntrypointEncSliceLP),
265         std::make_tuple(VAProfileH264Main, VAEntrypointEncSlice),
266         std::make_tuple(VAProfileH264Main, VAEntrypointEncSliceLP),
267         std::make_tuple(VAProfileH264High, VAEntrypointEncSlice),
268         std::make_tuple(VAProfileH264High, VAEntrypointEncSliceLP),
269         std::make_tuple(VAProfileH264MultiviewHigh, VAEntrypointEncSlice),
270         std::make_tuple(VAProfileH264StereoHigh, VAEntrypointEncSlice)
271     )
272 );
273
274 } // namespace Encode
275 } // namespace AVC