summaryrefslogtreecommitdiff
path: root/test/i965_streamable.h
blob: 4969c141317394d9a1f35a348eb8ea3574766523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/*
 * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef I965_STREAMABLE_H
#define I965_STREAMABLE_H

#include <array>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <va/va.h>

namespace std {
    template <typename T, const size_t S> inline std::ostream&
    operator<<(std::ostream& os, const std::array<T, S>& a)
    {
        os << "{";
        for (const auto& s : a) {
            if (&s != &a[0])
                os << ",";
            os << s;
        }
        return os << "}";
    }

    template <const size_t S> inline std::ostream&
    operator<<(std::ostream& os, const std::array<uint8_t, S>& a)
    {
        os << "{" << std::hex;
        for (const auto& s : a) {
            if (&s != &a[0])
                os << ",";
            os << "0x" << std::setfill('0') << std::setw(2) << unsigned(s);
        }
        return os << std::dec << "}";
    }
}// namespace std

template <typename T>
const std::string toString(const T& t)
{
    std::ostringstream os;
    os << t;
    return os.str();
}

inline std::ostream&
operator<<(std::ostream& os, const VAEncPictureParameterBufferJPEG& b)
{
    os  << "VAEncPictureParameterBufferJPEG (" << &b << ")" << std::endl
        << "  .reconstructed_picture    = " << b.reconstructed_picture
        << std::endl

        << "  .picture_width            = " << b.picture_width
        << std::endl

        << "  .picture_height           = " << b.picture_height
        << std::endl

        << "  .coded_buf                = " << b.coded_buf
        << std::endl

        << "  .pic_flags.value          = "
        << std::hex << std::setw(8) << std::setfill('0') << b.pic_flags.value
        << std::dec
        << std::endl

        << "  ...profile                = " << b.pic_flags.bits.profile
        << " (0 - Baseline, 1 - Extended, 2 - Lossless, 3 - Hierarchical)"
        << std::endl

        << "  ...progressive            = " << b.pic_flags.bits.progressive
        << " (0 - sequential, 1 - extended, 2 - progressive)"
        << std::endl

        << "  ...huffman                = " << b.pic_flags.bits.huffman
        << " (0 - arithmetic, 1 - huffman)"
        << std::endl

        << "  ...interleaved            = " << b.pic_flags.bits.interleaved
        << " (0 - non interleaved, 1 - interleaved)"
        << std::endl

        << "  ...differential           = " << b.pic_flags.bits.differential
        << " (0 - non differential, 1 - differential)"
        << std::endl

        << "  .sample_bit_depth         = " << (unsigned)b.sample_bit_depth
        << std::endl

        << "  .num_scan                 = " << (unsigned)b.num_scan
        << std::endl

        << "  .num_components           = " << (unsigned)b.num_components
        << std::endl

        << "  .component_id             = "
        << (unsigned)b.component_id[0] << ","
        << (unsigned)b.component_id[1] << ","
        << (unsigned)b.component_id[2] << ","
        << (unsigned)b.component_id[3] << ","
        << std::endl

        << "  .quantiser_table_selector = "
        << (unsigned)b.quantiser_table_selector[0] << ","
        << (unsigned)b.quantiser_table_selector[1] << ","
        << (unsigned)b.quantiser_table_selector[2] << ","
        << (unsigned)b.quantiser_table_selector[3] << ","
        << std::endl

        << "  .quality                  = " << (unsigned)b.quality
        << std::endl
    ;
    return os;
}

inline std::ostream&
operator<<(std::ostream& os, const VAEncPictureParameterBufferJPEG* b)
{
    os << *b;
    return os;
}

inline std::ostream&
operator<<(std::ostream& os, const VAQMatrixBufferJPEG& b)
{
      os << "VAQMatrixBufferJPEG (" << &b << ")" << std::endl;

      os << "  .load_lum_quantiser_matrix     = " << b.load_lum_quantiser_matrix
          << std::endl
      ;

      if (b.load_lum_quantiser_matrix)
      {
          os << "  .lum_quantiser_matrix          = ";
          for (size_t i(0); i < sizeof(b.lum_quantiser_matrix); ++i) {
              os << std::hex << std::setw(2) << std::setfill('0')
                  << (unsigned)b.lum_quantiser_matrix[i] << ",";
              if (((i+1) % 12) == 0)
                  os << std::endl << "                                   ";
          }
          os << std::dec << std::endl;
      }

      os << "  .load_chroma_quantiser_matrix  = " << b.load_chroma_quantiser_matrix
          << std::endl
      ;

      if (b.load_lum_quantiser_matrix)
      {
          os << "  .chroma_quantiser_matrix       = ";
          for (size_t i(0); i < sizeof(b.chroma_quantiser_matrix); ++i) {
              os << std::hex << std::setw(2) << std::setfill('0')
                  << (unsigned)b.chroma_quantiser_matrix[i] << ",";
              if (((i+1) % 12) == 0)
                  os << std::endl << "                                   ";
          }
          os << std::dec << std::endl;
      }

      return os;
}

inline std::ostream&
operator<<(std::ostream& os, const VAQMatrixBufferJPEG* b)
{
    os << *b;
    return os;
}

inline std::ostream&
operator<<(std::ostream& os, const VAHuffmanTableBufferJPEGBaseline& b)
{
    os << "VAHuffmanTableBufferJPEGBaseline (" << &b << ")" << std::endl;

    os  << "  .load_huffman_table            = "
        << (unsigned)b.load_huffman_table[0] << ","
        << (unsigned)b.load_huffman_table[1] << ","
        << std::endl
    ;

    for (size_t i(0); i < 2; ++i) {
        unsigned sum(0);
        os << "  .huffman_table[" << i << "].num_dc_codes = ";
        for (size_t j(0); j < sizeof(b.huffman_table[i].num_dc_codes); ++j) {
            if (j and (j % 12) == 0)
                os << std::endl << "                                   ";
            os << std::hex << std::setfill('0') << std::setw(2)
                << (unsigned)b.huffman_table[i].num_dc_codes[j] << ","
                << std::dec
            ;
            sum += b.huffman_table[i].num_dc_codes[j];
        }
        os << " (sum = " << sum << ")" << std::endl;

        os << "  .huffman_table[" << i << "].dc_values    = ";
        for (size_t j(0); j < sizeof(b.huffman_table[i].dc_values); ++j) {
            if (j and (j % 12) == 0)
                os << std::endl << "                                   ";
            os << std::hex << std::setfill('0') << std::setw(2)
                << (unsigned)b.huffman_table[i].dc_values[j] << ","
                << std::dec
            ;
        }
        os << std::endl;

        sum = 0;
        os << "  .huffman_table[" << i << "].num_ac_codes = ";
        for (size_t j(0); j < sizeof(b.huffman_table[i].num_ac_codes); ++j) {
            if (j and (j % 12) == 0)
                os << std::endl << "                                   ";
            os << std::hex << std::setfill('0') << std::setw(2)
                << (unsigned)b.huffman_table[i].num_ac_codes[j] << ","
                << std::dec
            ;
            sum += b.huffman_table[i].num_ac_codes[j];
        }
        os << " (sum = " << sum << ")" << std::endl;

        os << "  .huffman_table[" << i << "].ac_values    = ";
        for (size_t j(0); j < sizeof(b.huffman_table[i].ac_values); ++j) {
            if (j and (j % 12) == 0)
                os << std::endl << "                                   ";
            os << std::hex << std::setfill('0') << std::setw(2)
                << (unsigned)b.huffman_table[i].ac_values[j] << ","
                << std::dec
            ;
        }
        os << std::endl;
    }
    return os;
}

inline std::ostream&
operator<<(std::ostream& os, const VAHuffmanTableBufferJPEGBaseline* b)
{
    os << *b;
    return os;
}

inline std::ostream&
operator<<(std::ostream& os, const VAEncSliceParameterBufferJPEG& b)
{
    os  << "VAEncSliceParameterBufferJPEG (" << &b << ")" << std::endl
        << "  .restart_interval     = " << b.restart_interval
        << std::endl

        << "  .num_components       = " << b.num_components
        << std::endl
    ;

    for (size_t i(0); i < 4; ++i) {
        os  << "  .components[" << i << "]" << std::endl
            << "    .component_selector = "
            << (unsigned)b.components[i].component_selector
            << std::endl

            << "    .dc_table_selector  = "
            << (unsigned)b.components[i].dc_table_selector
            << std::endl

            << "    .ac_table_selector  = "
            << (unsigned)b.components[i].ac_table_selector
            << std::endl
        ;
    }

    return os;
}

inline std::ostream&
operator<<(std::ostream& os, const VAEncSliceParameterBufferJPEG* b)
{
    os << *b;
    return os;
}

inline std::ostream&
operator<<(std::ostream& os, const VAEncPackedHeaderParameterBuffer& b)
{
    os  << "VAEncPackedHeaderParameterBuffer (" << &b << ")" << std::endl
        << "  .type                = " << b.type
        << std::endl
        << "  .bit_length          = " << b.bit_length
        << std::endl
        << "  .has_emulation_bytes = " << (unsigned)b.has_emulation_bytes
        << std::endl
    ;

    return os;
}

inline std::ostream&
operator<<(std::ostream& os, const VAEncPackedHeaderParameterBuffer* b)
{
    os << *b;
    return os;
}

inline std::ostream&
operator<<(std::ostream& os, const VAImage& image)
{
    os << "VAImage (" << &image << ")"
        << std::dec << std::endl
        << "  id       : " << image.image_id
        << std::endl
        << "  fourcc   : "
        << std::string(reinterpret_cast<const char*>(&image.format.fourcc), 4)
        << std::endl
        << "  size     : " << image.width << "x" << image.height
        << std::endl
        << "  planes   : " << image.num_planes
        << std::endl
        << "  offsets  : "
        << "{"
        << image.offsets[0] << ","
        << image.offsets[1] << ","
        << image.offsets[2]
        << "}"
        << std::endl
        << "  pitches  : "
        << "{"
        << image.pitches[0] << ","
        << image.pitches[1] << ","
        << image.pitches[2]
        << "}"
        << std::endl
        << "  bpp      : " << image.format.bits_per_pixel
        << std::endl
        << "  depth    : " << image.format.depth
        << std::endl
        << "  byteorder: " << image.format.byte_order
        << std::endl
        << "  rgba mask: "
        << "{"
        << image.format.red_mask << ","
        << image.format.green_mask << ","
        << image.format.blue_mask << ","
        << image.format.alpha_mask
        << "}"
        << std::endl
        << "  buffer id: " << image.buf
        << std::endl
        << "  data size: " << image.data_size
    ;
    return os;
}

inline std::ostream&
operator<<(std::ostream& os, const VAProfile& profile)
{
    switch(profile) {
    case VAProfileNone:
        return os << "VAProfileNone";
    case VAProfileMPEG2Simple:
        return os << "VAProfileMPEG2Simple";
    case VAProfileMPEG2Main:
        return os << "VAProfileMPEG2Main";
    case VAProfileMPEG4Simple:
        return os << "VAProfileMPEG4Simple";
    case VAProfileMPEG4AdvancedSimple:
        return os << "VAProfileMPEG4AdvancedSimple";
    case VAProfileMPEG4Main:
        return os << "VAProfileMPEG4Main";
    case VAProfileVC1Simple:
        return os << "VAProfileVC1Simple";
    case VAProfileVC1Main:
        return os << "VAProfileVC1Main";
    case VAProfileVC1Advanced:
        return os << "VAProfileVC1Advanced";
    case VAProfileH263Baseline:
        return os << "VAProfileH263Baseline";
    case VAProfileJPEGBaseline:
        return os << "VAProfileJPEGBaseline";
    case VAProfileVP8Version0_3:
        return os << "VAProfileVP8Version0_3";
    case VAProfileHEVCMain:
        return os << "VAProfileHEVCMain";
    case VAProfileHEVCMain10:
        return os << "VAProfileHEVCMain10";
    case VAProfileVP9Profile0:
        return os << "VAProfileVP9Profile0";
    case VAProfileVP9Profile1:
        return os << "VAProfileVP9Profile1";
    case VAProfileVP9Profile2:
        return os << "VAProfileVP9Profile2";
    case VAProfileVP9Profile3:
        return os << "VAProfileVP9Profile3";
    case VAProfileH264Baseline:
        return os << "VAProfileH264Baseline";
    case VAProfileH264ConstrainedBaseline:
        return os << "VAProfileH264ConstrainedBaseline";
    case VAProfileH264High:
        return os << "VAProfileH264High";
    case VAProfileH264Main:
        return os << "VAProfileH264Main";
    case VAProfileH264MultiviewHigh:
        return os << "VAProfileH264MultiviewHigh";
    case VAProfileH264StereoHigh:
        return os << "VAProfileH264StereoHigh";
    default:
        return os << "Unknown VAProfile: " << static_cast<int>(profile);
    }
}

inline std::ostream&
operator<<(std::ostream& os, const VAEntrypoint& entrypoint)
{
    switch(entrypoint) {
    case VAEntrypointVLD:
        return os << "VAEntrypointVLD";
    case VAEntrypointIZZ:
        return os << "VAEntrypointIZZ";
    case VAEntrypointIDCT:
        return os << "VAEntrypointIDCT";
    case VAEntrypointMoComp:
        return os << "VAEntrypointMoComp";
    case VAEntrypointDeblocking:
        return os << "VAEntrypointDeblocking";
    case VAEntrypointVideoProc:
        return os << "VAEntrypointVideoProc";
    case VAEntrypointEncSlice:
        return os << "VAEntrypointEncSlice";
    case VAEntrypointEncSliceLP:
        return os << "VAEntrypointEncSliceLP";
    case VAEntrypointEncPicture:
        return os << "VAEntrypointEncPicture";
    default:
        return os << "Unknown VAEntrypoint: " << static_cast<int>(entrypoint);
    }
}

#endif // I965_STREAMABLE_H