1 /*
2 * Copyright (c) 2022, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file codechal_oca_debug.cpp
24 //! \brief Defines the oca debug interface shared by codec only.
25 //! \details The debug interface dumps output from Media based on in input config file.
26 //!
27 #include "codechal_oca_debug.h"
28
CodechalOcaDumper()29 CodechalOcaDumper::CodechalOcaDumper()
30 {
31 }
32
~CodechalOcaDumper()33 CodechalOcaDumper::~CodechalOcaDumper()
34 {
35 MOS_DeleteArray(m_pOcaDecodeParam);
36 }
37
Delete(void * & p)38 void CodechalOcaDumper::Delete(void *&p)
39 {
40 CodechalOcaDumper *pOcaDumper = (CodechalOcaDumper *)p;
41 MOS_Delete(pOcaDumper);
42 p = nullptr;
43 }
44
AllocateBufferSize(uint32_t allocSize)45 void CodechalOcaDumper::AllocateBufferSize(uint32_t allocSize)
46 {
47 if (m_pOcaDecodeParam)
48 {
49 if (allocSize > ((CODECHAL_OCA_DECODE_HEADER*)m_pOcaDecodeParam)->Header.allocSize)
50 {
51 MOS_DeleteArray(m_pOcaDecodeParam);
52 }
53 else
54 {
55 // Reuse previous buffer.
56 allocSize = ((CODECHAL_OCA_DECODE_HEADER*)m_pOcaDecodeParam)->Header.allocSize;
57 }
58 }
59
60 if (nullptr == m_pOcaDecodeParam)
61 {
62 m_pOcaDecodeParam = (CODECHAL_OCA_DECODE_HEADER *)MOS_NewArray(char, allocSize);
63 }
64 }
65
SetAvcDecodeParam(PCODEC_AVC_PIC_PARAMS picParams,PCODEC_AVC_SLICE_PARAMS sliceParams,uint32_t numSlices)66 void CodechalOcaDumper::SetAvcDecodeParam(
67 PCODEC_AVC_PIC_PARAMS picParams,
68 PCODEC_AVC_SLICE_PARAMS sliceParams,
69 uint32_t numSlices)
70 {
71 uint32_t sliceNum = (numSlices > CODECHAL_OCA_DECODE_MAX_SLICE_NUM) ? CODECHAL_OCA_DECODE_MAX_SLICE_NUM : numSlices;
72
73 // OCA Buffer dumps header + pic parameter + slice parameter
74 uint32_t size = sizeof(CODECHAL_OCA_DECODE_HEADER) +
75 sizeof(CODECHAL_OCA_DECODE_AVC_PIC_PARAM) +
76 sliceNum * sizeof(CODECHAL_OCA_DECODE_AVC_SLICE_PARAM);
77 uint32_t allocSize = size;
78
79 AllocateBufferSize(allocSize);
80 if (nullptr == m_pOcaDecodeParam)
81 {
82 return;
83 }
84 memset(m_pOcaDecodeParam, 0, size);
85
86 m_pOcaDecodeParam->Header.size = size;
87 m_pOcaDecodeParam->Header.allocSize = allocSize;
88 m_pOcaDecodeParam->Component = COMPONENT_Decode;
89 m_pOcaDecodeParam->numSlices = sliceNum;
90
91 uint32_t offset = sizeof(CODECHAL_OCA_DECODE_HEADER);
92 CODECHAL_OCA_DECODE_AVC_PIC_PARAM* pPicParam = (CODECHAL_OCA_DECODE_AVC_PIC_PARAM *)((char*)m_pOcaDecodeParam + offset);
93
94 offset += sizeof(CODECHAL_OCA_DECODE_AVC_PIC_PARAM);
95 CODECHAL_OCA_DECODE_AVC_SLICE_PARAM* pSliceParam = (CODECHAL_OCA_DECODE_AVC_SLICE_PARAM *)((char*)m_pOcaDecodeParam + offset);
96
97 if (picParams)
98 {
99 pPicParam->picParams.params = *picParams;
100 pPicParam->picParams.bValid = true;
101 }
102
103 for(uint16_t i = 0; i < sliceNum; i++)
104 {
105 if (sliceParams)
106 {
107 pSliceParam[i].bValid = true;
108 pSliceParam[i].sliceParams.slice_data_size = sliceParams[i].slice_data_size;
109 pSliceParam[i].sliceParams.slice_data_offset = sliceParams[i].slice_data_offset;
110 pSliceParam[i].sliceParams.slice_data_bit_offset = sliceParams[i].slice_data_bit_offset;
111 pSliceParam[i].sliceParams.first_mb_in_slice = sliceParams[i].first_mb_in_slice;
112 pSliceParam[i].sliceParams.NumMbsForSlice = sliceParams[i].NumMbsForSlice;
113 pSliceParam[i].sliceParams.slice_type = sliceParams[i].slice_type;
114 pSliceParam[i].sliceParams.direct_spatial_mv_pred_flag = sliceParams[i].direct_spatial_mv_pred_flag;
115 pSliceParam[i].sliceParams.num_ref_idx_l0_active_minus1 = sliceParams[i].num_ref_idx_l0_active_minus1;
116 pSliceParam[i].sliceParams.num_ref_idx_l1_active_minus1 = sliceParams[i].num_ref_idx_l1_active_minus1;
117 pSliceParam[i].sliceParams.cabac_init_idc = sliceParams[i].cabac_init_idc;
118 pSliceParam[i].sliceParams.slice_qp_delta = sliceParams[i].slice_qp_delta;
119 pSliceParam[i].sliceParams.disable_deblocking_filter_idc = sliceParams[i].disable_deblocking_filter_idc;
120 pSliceParam[i].sliceParams.slice_alpha_c0_offset_div2 = sliceParams[i].slice_alpha_c0_offset_div2;
121 pSliceParam[i].sliceParams.slice_beta_offset_div2 = sliceParams[i].slice_beta_offset_div2;
122 pSliceParam[i].sliceParams.slice_id = sliceParams[i].slice_id;
123 pSliceParam[i].sliceParams.first_mb_in_next_slice = sliceParams[i].first_mb_in_next_slice;
124 }
125 }
126 }
127
SetHevcDecodeParam(PCODEC_HEVC_PIC_PARAMS picParams,PCODEC_HEVC_EXT_PIC_PARAMS extPicParams,PCODEC_HEVC_SCC_PIC_PARAMS sccPicParams,PCODEC_HEVC_SLICE_PARAMS sliceParams,PCODEC_HEVC_EXT_SLICE_PARAMS extSliceParams,uint32_t numSlices,bool shortFormatInUse)128 void CodechalOcaDumper::SetHevcDecodeParam(
129 PCODEC_HEVC_PIC_PARAMS picParams,
130 PCODEC_HEVC_EXT_PIC_PARAMS extPicParams,
131 PCODEC_HEVC_SCC_PIC_PARAMS sccPicParams,
132 PCODEC_HEVC_SLICE_PARAMS sliceParams,
133 PCODEC_HEVC_EXT_SLICE_PARAMS extSliceParams,
134 uint32_t numSlices,
135 bool shortFormatInUse)
136 {
137 uint32_t sliceNum = (numSlices > CODECHAL_OCA_DECODE_MAX_SLICE_NUM) ? CODECHAL_OCA_DECODE_MAX_SLICE_NUM : numSlices;
138
139 uint32_t size = sizeof(CODECHAL_OCA_DECODE_HEADER) +
140 sizeof(CODECHAL_OCA_DECODE_HEVC_PIC_PARAM) +
141 sliceNum * sizeof(CODECHAL_OCA_DECODE_HEVC_SLICE_PARAM);
142 uint32_t allocSize = size;
143
144 AllocateBufferSize(allocSize);
145 if (nullptr == m_pOcaDecodeParam)
146 {
147 return;
148 }
149 memset(m_pOcaDecodeParam, 0, size);
150
151 m_pOcaDecodeParam->Header.size = size;
152 m_pOcaDecodeParam->Header.allocSize = allocSize;
153 m_pOcaDecodeParam->Component = COMPONENT_Decode;
154 m_pOcaDecodeParam->numSlices = sliceNum;
155 m_pOcaDecodeParam->shortFormatInUse = shortFormatInUse;
156
157 uint32_t offset = sizeof(CODECHAL_OCA_DECODE_HEADER);
158 CODECHAL_OCA_DECODE_HEVC_PIC_PARAM* pPicParam = (CODECHAL_OCA_DECODE_HEVC_PIC_PARAM *)((char*)m_pOcaDecodeParam + offset);
159
160 offset += sizeof(CODECHAL_OCA_DECODE_HEVC_PIC_PARAM);
161 CODECHAL_OCA_DECODE_HEVC_SLICE_PARAM* pSliceParam = (CODECHAL_OCA_DECODE_HEVC_SLICE_PARAM *)((char*)m_pOcaDecodeParam + offset);
162
163 if (picParams)
164 {
165 pPicParam->picParams.params = *picParams;
166 pPicParam->picParams.bValid = true;
167 }
168
169 if (extPicParams)
170 {
171 pPicParam->extPicParams.params = *extPicParams;
172 pPicParam->extPicParams.bValid = true;
173 }
174
175 if (sccPicParams)
176 {
177 pPicParam->sccPicParams.params = *sccPicParams;
178 pPicParam->sccPicParams.bValid = true;
179 }
180
181 for(uint16_t i = 0; i < sliceNum; i++)
182 {
183 if (sliceParams)
184 {
185 pSliceParam[i].bValid = true;
186 pSliceParam[i].sliceParams.slice_data_size = sliceParams[i].slice_data_size;
187 pSliceParam[i].sliceParams.slice_data_offset = sliceParams[i].slice_data_offset;
188 pSliceParam[i].sliceParams.NumEmuPrevnBytesInSliceHdr = sliceParams[i].NumEmuPrevnBytesInSliceHdr;
189 pSliceParam[i].sliceParams.ByteOffsetToSliceData = sliceParams[i].ByteOffsetToSliceData;
190 pSliceParam[i].sliceParams.collocated_ref_idx = sliceParams[i].collocated_ref_idx;
191 pSliceParam[i].sliceParams.num_ref_idx_l0_active_minus1 = sliceParams[i].num_ref_idx_l0_active_minus1;
192 pSliceParam[i].sliceParams.num_ref_idx_l1_active_minus1 = sliceParams[i].num_ref_idx_l1_active_minus1;
193 pSliceParam[i].sliceParams.LongSliceFlags.LastSliceOfPic = sliceParams[i].LongSliceFlags.fields.LastSliceOfPic;
194 pSliceParam[i].sliceParams.LongSliceFlags.dependent_slice_segment_flag = sliceParams[i].LongSliceFlags.fields.dependent_slice_segment_flag;
195 pSliceParam[i].sliceParams.LongSliceFlags.slice_type = sliceParams[i].LongSliceFlags.fields.slice_type;
196 pSliceParam[i].sliceParams.LongSliceFlags.color_plane_id = sliceParams[i].LongSliceFlags.fields.color_plane_id;
197 pSliceParam[i].sliceParams.LongSliceFlags.slice_sao_luma_flag = sliceParams[i].LongSliceFlags.fields.slice_sao_luma_flag;
198 pSliceParam[i].sliceParams.LongSliceFlags.slice_sao_chroma_flag = sliceParams[i].LongSliceFlags.fields.slice_sao_chroma_flag;
199 pSliceParam[i].sliceParams.LongSliceFlags.mvd_l1_zero_flag = sliceParams[i].LongSliceFlags.fields.mvd_l1_zero_flag;
200 pSliceParam[i].sliceParams.LongSliceFlags.cabac_init_flag = sliceParams[i].LongSliceFlags.fields.cabac_init_flag;
201 pSliceParam[i].sliceParams.LongSliceFlags.slice_temporal_mvp_enabled_flag = sliceParams[i].LongSliceFlags.fields.slice_temporal_mvp_enabled_flag;
202 pSliceParam[i].sliceParams.LongSliceFlags.slice_deblocking_filter_disabled_flag = sliceParams[i].LongSliceFlags.fields.slice_deblocking_filter_disabled_flag;
203 pSliceParam[i].sliceParams.LongSliceFlags.collocated_from_l0_flag = sliceParams[i].LongSliceFlags.fields.collocated_from_l0_flag;
204 pSliceParam[i].sliceParams.LongSliceFlags.slice_loop_filter_across_slices_enabled_flag = sliceParams[i].LongSliceFlags.fields.slice_loop_filter_across_slices_enabled_flag;
205 }
206 }
207 }
208