OSDN Git Service

test: check whether MVC encoding is support
[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
35 namespace std {
36     template <typename T, const size_t S> inline std::ostream&
37     operator<<(std::ostream& os, const std::array<T, S>& a)
38     {
39         os << "{";
40         for (const auto& s : a) {
41             if (&s != &a[0])
42                 os << ",";
43             os << s;
44         }
45         return os << "}";
46     }
47
48     template <const size_t S> inline std::ostream&
49     operator<<(std::ostream& os, const std::array<uint8_t, S>& a)
50     {
51         os << "{" << std::hex;
52         for (const auto& s : a) {
53             if (&s != &a[0])
54                 os << ",";
55             os << "0x" << std::setfill('0') << std::setw(2) << unsigned(s);
56         }
57         return os << std::dec << "}";
58     }
59
60     template <typename T> inline std::ostream&
61     operator<<(std::ostream& os, const std::valarray<T>& a)
62     {
63         os << "{";
64         for (const auto& s : a) {
65             if (&s != &a[0])
66                 os << ",";
67             os << s;
68         }
69         return os << "}";
70     }
71
72     template <> inline std::ostream&
73     operator<<(std::ostream& os, const std::valarray<uint8_t>& a)
74     {
75         os << "{" << std::hex;
76         for (const auto& s : a) {
77             if (&s != &a[0])
78                 os << ",";
79             os << "0x" << std::setfill('0') << std::setw(2) << unsigned(s);
80         }
81         return os << std::dec << "}";
82     }
83 }// namespace std
84
85 template <typename T>
86 const std::string toString(const T& t)
87 {
88     std::ostringstream os;
89     os << t;
90     return os.str();
91 }
92
93 inline std::ostream&
94 operator<<(std::ostream& os, const VAEncPictureParameterBufferJPEG& b)
95 {
96     os  << "VAEncPictureParameterBufferJPEG (" << &b << ")" << std::endl
97         << "  .reconstructed_picture    = " << b.reconstructed_picture
98         << std::endl
99
100         << "  .picture_width            = " << b.picture_width
101         << std::endl
102
103         << "  .picture_height           = " << b.picture_height
104         << std::endl
105
106         << "  .coded_buf                = " << b.coded_buf
107         << std::endl
108
109         << "  .pic_flags.value          = "
110         << std::hex << std::setw(8) << std::setfill('0') << b.pic_flags.value
111         << std::dec
112         << std::endl
113
114         << "  ...profile                = " << b.pic_flags.bits.profile
115         << " (0 - Baseline, 1 - Extended, 2 - Lossless, 3 - Hierarchical)"
116         << std::endl
117
118         << "  ...progressive            = " << b.pic_flags.bits.progressive
119         << " (0 - sequential, 1 - extended, 2 - progressive)"
120         << std::endl
121
122         << "  ...huffman                = " << b.pic_flags.bits.huffman
123         << " (0 - arithmetic, 1 - huffman)"
124         << std::endl
125
126         << "  ...interleaved            = " << b.pic_flags.bits.interleaved
127         << " (0 - non interleaved, 1 - interleaved)"
128         << std::endl
129
130         << "  ...differential           = " << b.pic_flags.bits.differential
131         << " (0 - non differential, 1 - differential)"
132         << std::endl
133
134         << "  .sample_bit_depth         = " << (unsigned)b.sample_bit_depth
135         << std::endl
136
137         << "  .num_scan                 = " << (unsigned)b.num_scan
138         << std::endl
139
140         << "  .num_components           = " << (unsigned)b.num_components
141         << std::endl
142
143         << "  .component_id             = "
144         << (unsigned)b.component_id[0] << ","
145         << (unsigned)b.component_id[1] << ","
146         << (unsigned)b.component_id[2] << ","
147         << (unsigned)b.component_id[3] << ","
148         << std::endl
149
150         << "  .quantiser_table_selector = "
151         << (unsigned)b.quantiser_table_selector[0] << ","
152         << (unsigned)b.quantiser_table_selector[1] << ","
153         << (unsigned)b.quantiser_table_selector[2] << ","
154         << (unsigned)b.quantiser_table_selector[3] << ","
155         << std::endl
156
157         << "  .quality                  = " << (unsigned)b.quality
158         << std::endl
159     ;
160     return os;
161 }
162
163 inline std::ostream&
164 operator<<(std::ostream& os, const VAEncPictureParameterBufferJPEG* b)
165 {
166     os << *b;
167     return os;
168 }
169
170 inline std::ostream&
171 operator<<(std::ostream& os, const VAQMatrixBufferJPEG& b)
172 {
173       os << "VAQMatrixBufferJPEG (" << &b << ")" << std::endl;
174
175       os << "  .load_lum_quantiser_matrix     = " << b.load_lum_quantiser_matrix
176           << std::endl
177       ;
178
179       if (b.load_lum_quantiser_matrix)
180       {
181           os << "  .lum_quantiser_matrix          = ";
182           for (size_t i(0); i < sizeof(b.lum_quantiser_matrix); ++i) {
183               os << std::hex << std::setw(2) << std::setfill('0')
184                   << (unsigned)b.lum_quantiser_matrix[i] << ",";
185               if (((i+1) % 12) == 0)
186                   os << std::endl << "                                   ";
187           }
188           os << std::dec << std::endl;
189       }
190
191       os << "  .load_chroma_quantiser_matrix  = " << b.load_chroma_quantiser_matrix
192           << std::endl
193       ;
194
195       if (b.load_lum_quantiser_matrix)
196       {
197           os << "  .chroma_quantiser_matrix       = ";
198           for (size_t i(0); i < sizeof(b.chroma_quantiser_matrix); ++i) {
199               os << std::hex << std::setw(2) << std::setfill('0')
200                   << (unsigned)b.chroma_quantiser_matrix[i] << ",";
201               if (((i+1) % 12) == 0)
202                   os << std::endl << "                                   ";
203           }
204           os << std::dec << std::endl;
205       }
206
207       return os;
208 }
209
210 inline std::ostream&
211 operator<<(std::ostream& os, const VAQMatrixBufferJPEG* b)
212 {
213     os << *b;
214     return os;
215 }
216
217 inline std::ostream&
218 operator<<(std::ostream& os, const VAHuffmanTableBufferJPEGBaseline& b)
219 {
220     os << "VAHuffmanTableBufferJPEGBaseline (" << &b << ")" << std::endl;
221
222     os  << "  .load_huffman_table            = "
223         << (unsigned)b.load_huffman_table[0] << ","
224         << (unsigned)b.load_huffman_table[1] << ","
225         << std::endl
226     ;
227
228     for (size_t i(0); i < 2; ++i) {
229         unsigned sum(0);
230         os << "  .huffman_table[" << i << "].num_dc_codes = ";
231         for (size_t j(0); j < sizeof(b.huffman_table[i].num_dc_codes); ++j) {
232             if (j and (j % 12) == 0)
233                 os << std::endl << "                                   ";
234             os << std::hex << std::setfill('0') << std::setw(2)
235                 << (unsigned)b.huffman_table[i].num_dc_codes[j] << ","
236                 << std::dec
237             ;
238             sum += b.huffman_table[i].num_dc_codes[j];
239         }
240         os << " (sum = " << sum << ")" << std::endl;
241
242         os << "  .huffman_table[" << i << "].dc_values    = ";
243         for (size_t j(0); j < sizeof(b.huffman_table[i].dc_values); ++j) {
244             if (j and (j % 12) == 0)
245                 os << std::endl << "                                   ";
246             os << std::hex << std::setfill('0') << std::setw(2)
247                 << (unsigned)b.huffman_table[i].dc_values[j] << ","
248                 << std::dec
249             ;
250         }
251         os << std::endl;
252
253         sum = 0;
254         os << "  .huffman_table[" << i << "].num_ac_codes = ";
255         for (size_t j(0); j < sizeof(b.huffman_table[i].num_ac_codes); ++j) {
256             if (j and (j % 12) == 0)
257                 os << std::endl << "                                   ";
258             os << std::hex << std::setfill('0') << std::setw(2)
259                 << (unsigned)b.huffman_table[i].num_ac_codes[j] << ","
260                 << std::dec
261             ;
262             sum += b.huffman_table[i].num_ac_codes[j];
263         }
264         os << " (sum = " << sum << ")" << std::endl;
265
266         os << "  .huffman_table[" << i << "].ac_values    = ";
267         for (size_t j(0); j < sizeof(b.huffman_table[i].ac_values); ++j) {
268             if (j and (j % 12) == 0)
269                 os << std::endl << "                                   ";
270             os << std::hex << std::setfill('0') << std::setw(2)
271                 << (unsigned)b.huffman_table[i].ac_values[j] << ","
272                 << std::dec
273             ;
274         }
275         os << std::endl;
276     }
277     return os;
278 }
279
280 inline std::ostream&
281 operator<<(std::ostream& os, const VAHuffmanTableBufferJPEGBaseline* b)
282 {
283     os << *b;
284     return os;
285 }
286
287 inline std::ostream&
288 operator<<(std::ostream& os, const VAEncSliceParameterBufferJPEG& b)
289 {
290     os  << "VAEncSliceParameterBufferJPEG (" << &b << ")" << std::endl
291         << "  .restart_interval     = " << b.restart_interval
292         << std::endl
293
294         << "  .num_components       = " << b.num_components
295         << std::endl
296     ;
297
298     for (size_t i(0); i < 4; ++i) {
299         os  << "  .components[" << i << "]" << std::endl
300             << "    .component_selector = "
301             << (unsigned)b.components[i].component_selector
302             << std::endl
303
304             << "    .dc_table_selector  = "
305             << (unsigned)b.components[i].dc_table_selector
306             << std::endl
307
308             << "    .ac_table_selector  = "
309             << (unsigned)b.components[i].ac_table_selector
310             << std::endl
311         ;
312     }
313
314     return os;
315 }
316
317 inline std::ostream&
318 operator<<(std::ostream& os, const VAEncSliceParameterBufferJPEG* b)
319 {
320     os << *b;
321     return os;
322 }
323
324 inline std::ostream&
325 operator<<(std::ostream& os, const VAEncPackedHeaderParameterBuffer& b)
326 {
327     os  << "VAEncPackedHeaderParameterBuffer (" << &b << ")" << std::endl
328         << "  .type                = " << b.type
329         << std::endl
330         << "  .bit_length          = " << b.bit_length
331         << std::endl
332         << "  .has_emulation_bytes = " << (unsigned)b.has_emulation_bytes
333         << std::endl
334     ;
335
336     return os;
337 }
338
339 inline std::ostream&
340 operator<<(std::ostream& os, const VAEncPackedHeaderParameterBuffer* b)
341 {
342     os << *b;
343     return os;
344 }
345
346 inline std::ostream&
347 operator<<(std::ostream& os, const VAImage& image)
348 {
349     os << "VAImage (" << &image << ")"
350         << std::dec << std::endl
351         << "  id       : " << image.image_id
352         << std::endl
353         << "  fourcc   : "
354         << std::string(reinterpret_cast<const char*>(&image.format.fourcc), 4)
355         << std::endl
356         << "  size     : " << image.width << "x" << image.height
357         << std::endl
358         << "  planes   : " << image.num_planes
359         << std::endl
360         << "  offsets  : "
361         << "{"
362         << image.offsets[0] << ","
363         << image.offsets[1] << ","
364         << image.offsets[2]
365         << "}"
366         << std::endl
367         << "  pitches  : "
368         << "{"
369         << image.pitches[0] << ","
370         << image.pitches[1] << ","
371         << image.pitches[2]
372         << "}"
373         << std::endl
374         << "  bpp      : " << image.format.bits_per_pixel
375         << std::endl
376         << "  depth    : " << image.format.depth
377         << std::endl
378         << "  byteorder: " << image.format.byte_order
379         << std::endl
380         << "  rgba mask: "
381         << "{"
382         << image.format.red_mask << ","
383         << image.format.green_mask << ","
384         << image.format.blue_mask << ","
385         << image.format.alpha_mask
386         << "}"
387         << std::endl
388         << "  buffer id: " << image.buf
389         << std::endl
390         << "  data size: " << image.data_size
391     ;
392     return os;
393 }
394
395 inline std::ostream&
396 operator<<(std::ostream& os, const VAProfile& profile)
397 {
398     switch(profile) {
399     case VAProfileNone:
400         return os << "VAProfileNone";
401     case VAProfileMPEG2Simple:
402         return os << "VAProfileMPEG2Simple";
403     case VAProfileMPEG2Main:
404         return os << "VAProfileMPEG2Main";
405     case VAProfileMPEG4Simple:
406         return os << "VAProfileMPEG4Simple";
407     case VAProfileMPEG4AdvancedSimple:
408         return os << "VAProfileMPEG4AdvancedSimple";
409     case VAProfileMPEG4Main:
410         return os << "VAProfileMPEG4Main";
411     case VAProfileVC1Simple:
412         return os << "VAProfileVC1Simple";
413     case VAProfileVC1Main:
414         return os << "VAProfileVC1Main";
415     case VAProfileVC1Advanced:
416         return os << "VAProfileVC1Advanced";
417     case VAProfileH263Baseline:
418         return os << "VAProfileH263Baseline";
419     case VAProfileJPEGBaseline:
420         return os << "VAProfileJPEGBaseline";
421     case VAProfileVP8Version0_3:
422         return os << "VAProfileVP8Version0_3";
423     case VAProfileHEVCMain:
424         return os << "VAProfileHEVCMain";
425     case VAProfileHEVCMain10:
426         return os << "VAProfileHEVCMain10";
427     case VAProfileVP9Profile0:
428         return os << "VAProfileVP9Profile0";
429     case VAProfileVP9Profile1:
430         return os << "VAProfileVP9Profile1";
431     case VAProfileVP9Profile2:
432         return os << "VAProfileVP9Profile2";
433     case VAProfileVP9Profile3:
434         return os << "VAProfileVP9Profile3";
435     case VAProfileH264Baseline:
436         return os << "VAProfileH264Baseline";
437     case VAProfileH264ConstrainedBaseline:
438         return os << "VAProfileH264ConstrainedBaseline";
439     case VAProfileH264High:
440         return os << "VAProfileH264High";
441     case VAProfileH264Main:
442         return os << "VAProfileH264Main";
443     case VAProfileH264MultiviewHigh:
444         return os << "VAProfileH264MultiviewHigh";
445     case VAProfileH264StereoHigh:
446         return os << "VAProfileH264StereoHigh";
447     default:
448         return os << "Unknown VAProfile: " << static_cast<int>(profile);
449     }
450 }
451
452 inline std::ostream&
453 operator<<(std::ostream& os, const VAEntrypoint& entrypoint)
454 {
455     switch(entrypoint) {
456     case VAEntrypointVLD:
457         return os << "VAEntrypointVLD";
458     case VAEntrypointIZZ:
459         return os << "VAEntrypointIZZ";
460     case VAEntrypointIDCT:
461         return os << "VAEntrypointIDCT";
462     case VAEntrypointMoComp:
463         return os << "VAEntrypointMoComp";
464     case VAEntrypointDeblocking:
465         return os << "VAEntrypointDeblocking";
466     case VAEntrypointVideoProc:
467         return os << "VAEntrypointVideoProc";
468     case VAEntrypointEncSlice:
469         return os << "VAEntrypointEncSlice";
470     case VAEntrypointEncSliceLP:
471         return os << "VAEntrypointEncSliceLP";
472     case VAEntrypointEncPicture:
473         return os << "VAEntrypointEncPicture";
474     default:
475         return os << "Unknown VAEntrypoint: " << static_cast<int>(entrypoint);
476     }
477 }
478
479 #endif // I965_STREAMABLE_H