OSDN Git Service

Fix packed headers attribute test in vaCreateConfig()
[android-x86/hardware-intel-common-vaapi.git] / test / i965_streamable.h
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 #ifndef I965_STREAMABLE_H
26 #define I965_STREAMABLE_H
27
28 #include <array>
29 #include <iostream>
30 #include <iomanip>
31 #include <sstream>
32 #include <valarray>
33 #include <va/va.h>
34 #include <va/va_str.h>
35
36 namespace std {
37     template <typename T, const size_t S> inline std::ostream&
38     operator<<(std::ostream& os, const std::array<T, S>& a)
39     {
40         os << "{";
41         for (const auto& s : a) {
42             if (&s != &a[0])
43                 os << ",";
44             os << s;
45         }
46         return os << "}";
47     }
48
49     template <const size_t S> inline std::ostream&
50     operator<<(std::ostream& os, const std::array<uint8_t, S>& a)
51     {
52         os << "{" << std::hex;
53         for (const auto& s : a) {
54             if (&s != &a[0])
55                 os << ",";
56             os << "0x" << std::setfill('0') << std::setw(2) << unsigned(s);
57         }
58         return os << std::dec << "}";
59     }
60
61     template <typename T> inline std::ostream&
62     operator<<(std::ostream& os, const std::valarray<T>& a)
63     {
64         os << "{";
65         for (const auto& s : a) {
66             if (&s != &a[0])
67                 os << ",";
68             os << s;
69         }
70         return os << "}";
71     }
72
73     template <> inline std::ostream&
74     operator<<(std::ostream& os, const std::valarray<uint8_t>& a)
75     {
76         os << "{" << std::hex;
77         for (const auto& s : a) {
78             if (&s != &a[0])
79                 os << ",";
80             os << "0x" << std::setfill('0') << std::setw(2) << unsigned(s);
81         }
82         return os << std::dec << "}";
83     }
84 }// namespace std
85
86 template <typename T>
87 const std::string toString(const T& t)
88 {
89     std::ostringstream os;
90     os << t;
91     return os.str();
92 }
93
94 inline std::ostream&
95 operator<<(std::ostream& os, const VAEncPictureParameterBufferJPEG& b)
96 {
97     os  << "VAEncPictureParameterBufferJPEG (" << &b << ")" << std::endl
98         << "  .reconstructed_picture    = " << b.reconstructed_picture
99         << std::endl
100
101         << "  .picture_width            = " << b.picture_width
102         << std::endl
103
104         << "  .picture_height           = " << b.picture_height
105         << std::endl
106
107         << "  .coded_buf                = " << b.coded_buf
108         << std::endl
109
110         << "  .pic_flags.value          = "
111         << std::hex << std::setw(8) << std::setfill('0') << b.pic_flags.value
112         << std::dec
113         << std::endl
114
115         << "  ...profile                = " << b.pic_flags.bits.profile
116         << " (0 - Baseline, 1 - Extended, 2 - Lossless, 3 - Hierarchical)"
117         << std::endl
118
119         << "  ...progressive            = " << b.pic_flags.bits.progressive
120         << " (0 - sequential, 1 - extended, 2 - progressive)"
121         << std::endl
122
123         << "  ...huffman                = " << b.pic_flags.bits.huffman
124         << " (0 - arithmetic, 1 - huffman)"
125         << std::endl
126
127         << "  ...interleaved            = " << b.pic_flags.bits.interleaved
128         << " (0 - non interleaved, 1 - interleaved)"
129         << std::endl
130
131         << "  ...differential           = " << b.pic_flags.bits.differential
132         << " (0 - non differential, 1 - differential)"
133         << std::endl
134
135         << "  .sample_bit_depth         = " << (unsigned)b.sample_bit_depth
136         << std::endl
137
138         << "  .num_scan                 = " << (unsigned)b.num_scan
139         << std::endl
140
141         << "  .num_components           = " << (unsigned)b.num_components
142         << std::endl
143
144         << "  .component_id             = "
145         << (unsigned)b.component_id[0] << ","
146         << (unsigned)b.component_id[1] << ","
147         << (unsigned)b.component_id[2] << ","
148         << (unsigned)b.component_id[3] << ","
149         << std::endl
150
151         << "  .quantiser_table_selector = "
152         << (unsigned)b.quantiser_table_selector[0] << ","
153         << (unsigned)b.quantiser_table_selector[1] << ","
154         << (unsigned)b.quantiser_table_selector[2] << ","
155         << (unsigned)b.quantiser_table_selector[3] << ","
156         << std::endl
157
158         << "  .quality                  = " << (unsigned)b.quality
159         << std::endl
160     ;
161     return os;
162 }
163
164 inline std::ostream&
165 operator<<(std::ostream& os, const VAEncPictureParameterBufferJPEG* b)
166 {
167     os << *b;
168     return os;
169 }
170
171 inline std::ostream&
172 operator<<(std::ostream& os, const VAQMatrixBufferJPEG& b)
173 {
174       os << "VAQMatrixBufferJPEG (" << &b << ")" << std::endl;
175
176       os << "  .load_lum_quantiser_matrix     = " << b.load_lum_quantiser_matrix
177           << std::endl
178       ;
179
180       if (b.load_lum_quantiser_matrix)
181       {
182           os << "  .lum_quantiser_matrix          = ";
183           for (size_t i(0); i < sizeof(b.lum_quantiser_matrix); ++i) {
184               os << std::hex << std::setw(2) << std::setfill('0')
185                   << (unsigned)b.lum_quantiser_matrix[i] << ",";
186               if (((i+1) % 12) == 0)
187                   os << std::endl << "                                   ";
188           }
189           os << std::dec << std::endl;
190       }
191
192       os << "  .load_chroma_quantiser_matrix  = " << b.load_chroma_quantiser_matrix
193           << std::endl
194       ;
195
196       if (b.load_lum_quantiser_matrix)
197       {
198           os << "  .chroma_quantiser_matrix       = ";
199           for (size_t i(0); i < sizeof(b.chroma_quantiser_matrix); ++i) {
200               os << std::hex << std::setw(2) << std::setfill('0')
201                   << (unsigned)b.chroma_quantiser_matrix[i] << ",";
202               if (((i+1) % 12) == 0)
203                   os << std::endl << "                                   ";
204           }
205           os << std::dec << std::endl;
206       }
207
208       return os;
209 }
210
211 inline std::ostream&
212 operator<<(std::ostream& os, const VAQMatrixBufferJPEG* b)
213 {
214     os << *b;
215     return os;
216 }
217
218 inline std::ostream&
219 operator<<(std::ostream& os, const VAHuffmanTableBufferJPEGBaseline& b)
220 {
221     os << "VAHuffmanTableBufferJPEGBaseline (" << &b << ")" << std::endl;
222
223     os  << "  .load_huffman_table            = "
224         << (unsigned)b.load_huffman_table[0] << ","
225         << (unsigned)b.load_huffman_table[1] << ","
226         << std::endl
227     ;
228
229     for (size_t i(0); i < 2; ++i) {
230         unsigned sum(0);
231         os << "  .huffman_table[" << i << "].num_dc_codes = ";
232         for (size_t j(0); j < sizeof(b.huffman_table[i].num_dc_codes); ++j) {
233             if (j and (j % 12) == 0)
234                 os << std::endl << "                                   ";
235             os << std::hex << std::setfill('0') << std::setw(2)
236                 << (unsigned)b.huffman_table[i].num_dc_codes[j] << ","
237                 << std::dec
238             ;
239             sum += b.huffman_table[i].num_dc_codes[j];
240         }
241         os << " (sum = " << sum << ")" << std::endl;
242
243         os << "  .huffman_table[" << i << "].dc_values    = ";
244         for (size_t j(0); j < sizeof(b.huffman_table[i].dc_values); ++j) {
245             if (j and (j % 12) == 0)
246                 os << std::endl << "                                   ";
247             os << std::hex << std::setfill('0') << std::setw(2)
248                 << (unsigned)b.huffman_table[i].dc_values[j] << ","
249                 << std::dec
250             ;
251         }
252         os << std::endl;
253
254         sum = 0;
255         os << "  .huffman_table[" << i << "].num_ac_codes = ";
256         for (size_t j(0); j < sizeof(b.huffman_table[i].num_ac_codes); ++j) {
257             if (j and (j % 12) == 0)
258                 os << std::endl << "                                   ";
259             os << std::hex << std::setfill('0') << std::setw(2)
260                 << (unsigned)b.huffman_table[i].num_ac_codes[j] << ","
261                 << std::dec
262             ;
263             sum += b.huffman_table[i].num_ac_codes[j];
264         }
265         os << " (sum = " << sum << ")" << std::endl;
266
267         os << "  .huffman_table[" << i << "].ac_values    = ";
268         for (size_t j(0); j < sizeof(b.huffman_table[i].ac_values); ++j) {
269             if (j and (j % 12) == 0)
270                 os << std::endl << "                                   ";
271             os << std::hex << std::setfill('0') << std::setw(2)
272                 << (unsigned)b.huffman_table[i].ac_values[j] << ","
273                 << std::dec
274             ;
275         }
276         os << std::endl;
277     }
278     return os;
279 }
280
281 inline std::ostream&
282 operator<<(std::ostream& os, const VAHuffmanTableBufferJPEGBaseline* b)
283 {
284     os << *b;
285     return os;
286 }
287
288 inline std::ostream&
289 operator<<(std::ostream& os, const VAEncSliceParameterBufferJPEG& b)
290 {
291     os  << "VAEncSliceParameterBufferJPEG (" << &b << ")" << std::endl
292         << "  .restart_interval     = " << b.restart_interval
293         << std::endl
294
295         << "  .num_components       = " << b.num_components
296         << std::endl
297     ;
298
299     for (size_t i(0); i < 4; ++i) {
300         os  << "  .components[" << i << "]" << std::endl
301             << "    .component_selector = "
302             << (unsigned)b.components[i].component_selector
303             << std::endl
304
305             << "    .dc_table_selector  = "
306             << (unsigned)b.components[i].dc_table_selector
307             << std::endl
308
309             << "    .ac_table_selector  = "
310             << (unsigned)b.components[i].ac_table_selector
311             << std::endl
312         ;
313     }
314
315     return os;
316 }
317
318 inline std::ostream&
319 operator<<(std::ostream& os, const VAEncSliceParameterBufferJPEG* b)
320 {
321     os << *b;
322     return os;
323 }
324
325 inline std::ostream&
326 operator<<(std::ostream& os, const VAEncPackedHeaderParameterBuffer& b)
327 {
328     os  << "VAEncPackedHeaderParameterBuffer (" << &b << ")" << std::endl
329         << "  .type                = " << b.type
330         << std::endl
331         << "  .bit_length          = " << b.bit_length
332         << std::endl
333         << "  .has_emulation_bytes = " << (unsigned)b.has_emulation_bytes
334         << std::endl
335     ;
336
337     return os;
338 }
339
340 inline std::ostream&
341 operator<<(std::ostream& os, const VAEncPackedHeaderParameterBuffer* b)
342 {
343     os << *b;
344     return os;
345 }
346
347 inline std::ostream&
348 operator<<(std::ostream& os, const VAImage& image)
349 {
350     os << "VAImage (" << &image << ")"
351         << std::dec << std::endl
352         << "  id       : " << image.image_id
353         << std::endl
354         << "  fourcc   : "
355         << std::string(reinterpret_cast<const char*>(&image.format.fourcc), 4)
356         << std::endl
357         << "  size     : " << image.width << "x" << image.height
358         << std::endl
359         << "  planes   : " << image.num_planes
360         << std::endl
361         << "  offsets  : "
362         << "{"
363         << image.offsets[0] << ","
364         << image.offsets[1] << ","
365         << image.offsets[2]
366         << "}"
367         << std::endl
368         << "  pitches  : "
369         << "{"
370         << image.pitches[0] << ","
371         << image.pitches[1] << ","
372         << image.pitches[2]
373         << "}"
374         << std::endl
375         << "  bpp      : " << image.format.bits_per_pixel
376         << std::endl
377         << "  depth    : " << image.format.depth
378         << std::endl
379         << "  byteorder: " << image.format.byte_order
380         << std::endl
381         << "  rgba mask: "
382         << "{"
383         << image.format.red_mask << ","
384         << image.format.green_mask << ","
385         << image.format.blue_mask << ","
386         << image.format.alpha_mask
387         << "}"
388         << std::endl
389         << "  buffer id: " << image.buf
390         << std::endl
391         << "  data size: " << image.data_size
392     ;
393     return os;
394 }
395
396 inline std::ostream&
397 operator<<(std::ostream& os, const VAProfile& profile)
398 {
399     return os << vaProfileStr(profile);
400 }
401
402 inline std::ostream&
403 operator<<(std::ostream& os, const VAEntrypoint& entrypoint)
404 {
405     return os << vaEntrypointStr(entrypoint);
406 }
407
408 #endif // I965_STREAMABLE_H