Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/frontends/va/picture_mpeg12.c
4561 views
1
/**************************************************************************
2
*
3
* Copyright 2014 Advanced Micro Devices, Inc.
4
* All Rights Reserved.
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the
8
* "Software"), to deal in the Software without restriction, including
9
* without limitation the rights to use, copy, modify, merge, publish,
10
* distribute, sub license, and/or sell copies of the Software, and to
11
* permit persons to whom the Software is furnished to do so, subject to
12
* the following conditions:
13
*
14
* The above copyright notice and this permission notice (including the
15
* next paragraph) shall be included in all copies or substantial portions
16
* of the Software.
17
*
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21
* IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
*
26
**************************************************************************/
27
28
#include "va_private.h"
29
30
const int reverse_inverse_zscan[] =
31
{
32
/* Reverse inverse z scan pattern */
33
0, 2, 3, 9, 10, 20, 21, 35,
34
1, 4, 8, 11, 19, 22, 34, 36,
35
5, 7, 12, 18, 23, 33, 37, 48,
36
6, 13, 17, 24, 32, 38, 47, 49,
37
14, 16, 25, 31, 39, 46, 50, 57,
38
15, 26, 30, 40, 45, 51, 56, 58,
39
27, 29, 41, 44, 52, 55, 59, 62,
40
28, 42, 43, 53, 54, 60, 61, 63,
41
};
42
43
void vlVaHandlePictureParameterBufferMPEG12(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)
44
{
45
VAPictureParameterBufferMPEG2 *mpeg2 = buf->data;
46
47
assert(buf->size >= sizeof(VAPictureParameterBufferMPEG2) && buf->num_elements == 1);
48
context->desc.mpeg12.num_slices = 0;
49
/*horizontal_size;*/
50
/*vertical_size;*/
51
vlVaGetReferenceFrame(drv, mpeg2->forward_reference_picture, &context->desc.mpeg12.ref[0]);
52
vlVaGetReferenceFrame(drv, mpeg2->backward_reference_picture, &context->desc.mpeg12.ref[1]);
53
context->desc.mpeg12.picture_coding_type = mpeg2->picture_coding_type;
54
context->desc.mpeg12.f_code[0][0] = ((mpeg2->f_code >> 12) & 0xf) - 1;
55
context->desc.mpeg12.f_code[0][1] = ((mpeg2->f_code >> 8) & 0xf) - 1;
56
context->desc.mpeg12.f_code[1][0] = ((mpeg2->f_code >> 4) & 0xf) - 1;
57
context->desc.mpeg12.f_code[1][1] = (mpeg2->f_code & 0xf) - 1;
58
context->desc.mpeg12.intra_dc_precision =
59
mpeg2->picture_coding_extension.bits.intra_dc_precision;
60
context->desc.mpeg12.picture_structure =
61
mpeg2->picture_coding_extension.bits.picture_structure;
62
context->desc.mpeg12.top_field_first =
63
mpeg2->picture_coding_extension.bits.top_field_first;
64
context->desc.mpeg12.frame_pred_frame_dct =
65
mpeg2->picture_coding_extension.bits.frame_pred_frame_dct;
66
context->desc.mpeg12.concealment_motion_vectors =
67
mpeg2->picture_coding_extension.bits.concealment_motion_vectors;
68
context->desc.mpeg12.q_scale_type =
69
mpeg2->picture_coding_extension.bits.q_scale_type;
70
context->desc.mpeg12.intra_vlc_format =
71
mpeg2->picture_coding_extension.bits.intra_vlc_format;
72
context->desc.mpeg12.alternate_scan =
73
mpeg2->picture_coding_extension.bits.alternate_scan;
74
/*repeat_first_field*/
75
/*progressive_frame*/
76
/*is_first_field*/
77
}
78
79
void vlVaHandleIQMatrixBufferMPEG12(vlVaContext *context, vlVaBuffer *buf)
80
{
81
VAIQMatrixBufferMPEG2 *mpeg2 = buf->data;
82
static uint8_t temp_intra_matrix[64];
83
static uint8_t temp_nonintra_matrix[64];
84
85
assert(buf->size >= sizeof(VAIQMatrixBufferMPEG2) && buf->num_elements == 1);
86
if (mpeg2->load_intra_quantiser_matrix) {
87
/* The quantiser matrix that VAAPI provides has been applied
88
with inverse z-scan. However, what we expect in MPEG2
89
picture description is the original order. Therefore,
90
we need to reverse it back to its original order.
91
*/
92
for (int i = 0; i < 64; i++)
93
temp_intra_matrix[i] =
94
mpeg2->intra_quantiser_matrix[reverse_inverse_zscan[i]];
95
context->desc.mpeg12.intra_matrix = temp_intra_matrix;
96
} else
97
context->desc.mpeg12.intra_matrix = NULL;
98
99
if (mpeg2->load_non_intra_quantiser_matrix) {
100
for (int i = 0; i < 64; i++)
101
temp_nonintra_matrix[i] =
102
mpeg2->non_intra_quantiser_matrix[reverse_inverse_zscan[i]];
103
context->desc.mpeg12.non_intra_matrix = temp_nonintra_matrix;
104
} else
105
context->desc.mpeg12.non_intra_matrix = NULL;
106
}
107
108
void vlVaHandleSliceParameterBufferMPEG12(vlVaContext *context, vlVaBuffer *buf)
109
{
110
assert(buf->size >= sizeof(VASliceParameterBufferMPEG2));
111
context->desc.mpeg12.num_slices += buf->num_elements;
112
}
113
114