Line data Source code
1 : /*
2 : * Copyright(c) 2019 Intel Corporation
3 : * SPDX - License - Identifier: BSD - 2 - Clause - Patent
4 : */
5 :
6 : #include <stdlib.h>
7 : #include <string.h>
8 :
9 : #include "EbPictureBufferDesc.h"
10 : #include "EbReferenceObject.h"
11 :
12 0 : void InitializeSamplesNeighboringReferencePicture16Bit(
13 : EbByte reconSamplesBufferPtr,
14 : uint16_t stride,
15 : uint16_t reconWidth,
16 : uint16_t reconHeight,
17 : uint16_t left_padding,
18 : uint16_t top_padding) {
19 : uint16_t *reconSamplesPtr;
20 : uint16_t sampleCount;
21 :
22 : // 1. Zero out the top row
23 0 : reconSamplesPtr = (uint16_t*)reconSamplesBufferPtr + (top_padding - 1) * stride + left_padding - 1;
24 0 : EB_MEMSET((uint8_t*)reconSamplesPtr, 0, sizeof(uint16_t)*(1 + reconWidth + 1));
25 :
26 : // 2. Zero out the bottom row
27 0 : reconSamplesPtr = (uint16_t*)reconSamplesBufferPtr + (top_padding + reconHeight) * stride + left_padding - 1;
28 0 : EB_MEMSET((uint8_t*)reconSamplesPtr, 0, sizeof(uint16_t)*(1 + reconWidth + 1));
29 :
30 : // 3. Zero out the left column
31 0 : reconSamplesPtr = (uint16_t*)reconSamplesBufferPtr + top_padding * stride + left_padding - 1;
32 0 : for (sampleCount = 0; sampleCount < reconHeight; sampleCount++)
33 0 : reconSamplesPtr[sampleCount * stride] = 0;
34 : // 4. Zero out the right column
35 0 : reconSamplesPtr = (uint16_t*)reconSamplesBufferPtr + top_padding * stride + left_padding + reconWidth;
36 0 : for (sampleCount = 0; sampleCount < reconHeight; sampleCount++)
37 0 : reconSamplesPtr[sampleCount * stride] = 0;
38 0 : }
39 :
40 342 : void InitializeSamplesNeighboringReferencePicture8Bit(
41 : EbByte reconSamplesBufferPtr,
42 : uint16_t stride,
43 : uint16_t reconWidth,
44 : uint16_t reconHeight,
45 : uint16_t left_padding,
46 : uint16_t top_padding) {
47 : uint8_t *reconSamplesPtr;
48 : uint16_t sampleCount;
49 :
50 : // 1. Zero out the top row
51 342 : reconSamplesPtr = reconSamplesBufferPtr + (top_padding - 1) * stride + left_padding - 1;
52 342 : EB_MEMSET(reconSamplesPtr, 0, sizeof(uint8_t)*(1 + reconWidth + 1));
53 :
54 : // 2. Zero out the bottom row
55 342 : reconSamplesPtr = reconSamplesBufferPtr + (top_padding + reconHeight) * stride + left_padding - 1;
56 342 : EB_MEMSET(reconSamplesPtr, 0, sizeof(uint8_t)*(1 + reconWidth + 1));
57 :
58 : // 3. Zero out the left column
59 342 : reconSamplesPtr = reconSamplesBufferPtr + top_padding * stride + left_padding - 1;
60 82422 : for (sampleCount = 0; sampleCount < reconHeight; sampleCount++)
61 82080 : reconSamplesPtr[sampleCount * stride] = 0;
62 : // 4. Zero out the right column
63 342 : reconSamplesPtr = reconSamplesBufferPtr + top_padding * stride + left_padding + reconWidth;
64 82422 : for (sampleCount = 0; sampleCount < reconHeight; sampleCount++)
65 82080 : reconSamplesPtr[sampleCount * stride] = 0;
66 342 : }
67 :
68 114 : void InitializeSamplesNeighboringReferencePicture(
69 : EbReferenceObject *referenceObject,
70 : EbPictureBufferDescInitData *pictureBufferDescInitDataPtr,
71 : EbBitDepthEnum bit_depth) {
72 114 : if (bit_depth == EB_10BIT) {
73 0 : InitializeSamplesNeighboringReferencePicture16Bit(
74 0 : referenceObject->reference_picture16bit->buffer_y,
75 0 : referenceObject->reference_picture16bit->stride_y,
76 0 : referenceObject->reference_picture16bit->width,
77 0 : referenceObject->reference_picture16bit->height,
78 0 : pictureBufferDescInitDataPtr->left_padding,
79 0 : pictureBufferDescInitDataPtr->top_padding);
80 :
81 0 : InitializeSamplesNeighboringReferencePicture16Bit(
82 0 : referenceObject->reference_picture16bit->buffer_cb,
83 0 : referenceObject->reference_picture16bit->stride_cb,
84 0 : referenceObject->reference_picture16bit->width >> 1,
85 0 : referenceObject->reference_picture16bit->height >> 1,
86 0 : pictureBufferDescInitDataPtr->left_padding >> 1,
87 0 : pictureBufferDescInitDataPtr->top_padding >> 1);
88 :
89 0 : InitializeSamplesNeighboringReferencePicture16Bit(
90 0 : referenceObject->reference_picture16bit->buffer_cr,
91 0 : referenceObject->reference_picture16bit->stride_cr,
92 0 : referenceObject->reference_picture16bit->width >> 1,
93 0 : referenceObject->reference_picture16bit->height >> 1,
94 0 : pictureBufferDescInitDataPtr->left_padding >> 1,
95 0 : pictureBufferDescInitDataPtr->top_padding >> 1);
96 : }
97 : else {
98 114 : InitializeSamplesNeighboringReferencePicture8Bit(
99 114 : referenceObject->reference_picture->buffer_y,
100 114 : referenceObject->reference_picture->stride_y,
101 114 : referenceObject->reference_picture->width,
102 114 : referenceObject->reference_picture->height,
103 114 : pictureBufferDescInitDataPtr->left_padding,
104 114 : pictureBufferDescInitDataPtr->top_padding);
105 :
106 114 : InitializeSamplesNeighboringReferencePicture8Bit(
107 114 : referenceObject->reference_picture->buffer_cb,
108 114 : referenceObject->reference_picture->stride_cb,
109 114 : referenceObject->reference_picture->width >> 1,
110 114 : referenceObject->reference_picture->height >> 1,
111 114 : pictureBufferDescInitDataPtr->left_padding >> 1,
112 114 : pictureBufferDescInitDataPtr->top_padding >> 1);
113 :
114 114 : InitializeSamplesNeighboringReferencePicture8Bit(
115 114 : referenceObject->reference_picture->buffer_cr,
116 114 : referenceObject->reference_picture->stride_cr,
117 114 : referenceObject->reference_picture->width >> 1,
118 114 : referenceObject->reference_picture->height >> 1,
119 114 : pictureBufferDescInitDataPtr->left_padding >> 1,
120 114 : pictureBufferDescInitDataPtr->top_padding >> 1);
121 : }
122 114 : }
123 :
124 114 : static void eb_reference_object_dctor(EbPtr p)
125 : {
126 114 : EbReferenceObject *obj = (EbReferenceObject*)p;
127 114 : EB_DELETE(obj->reference_picture16bit);
128 114 : EB_DELETE(obj->reference_picture);
129 114 : EB_FREE_ALIGNED_ARRAY(obj->mvs);
130 : #if TWO_PASS
131 114 : EB_DESTROY_MUTEX(obj->referenced_area_mutex);
132 : #endif
133 114 : }
134 :
135 :
136 : /*****************************************
137 : * eb_picture_buffer_desc_ctor
138 : * Initializes the Buffer Descriptor's
139 : * values that are fixed for the life of
140 : * the descriptor.
141 : *****************************************/
142 114 : EbErrorType eb_reference_object_ctor(
143 : EbReferenceObject *referenceObject,
144 : EbPtr object_init_data_ptr)
145 : {
146 :
147 114 : EbPictureBufferDescInitData *pictureBufferDescInitDataPtr = (EbPictureBufferDescInitData*)object_init_data_ptr;
148 114 : EbPictureBufferDescInitData pictureBufferDescInitData16BitPtr = *pictureBufferDescInitDataPtr;
149 :
150 114 : referenceObject->dctor = eb_reference_object_dctor;
151 : //TODO:12bit
152 114 : if (pictureBufferDescInitData16BitPtr.bit_depth == EB_10BIT) {
153 : // Hsan: set split_mode to 0 to construct the packed reference buffer (used @ EP)
154 0 : pictureBufferDescInitData16BitPtr.split_mode = EB_FALSE;
155 0 : EB_NEW(
156 : referenceObject->reference_picture16bit,
157 : eb_picture_buffer_desc_ctor,
158 : (EbPtr)&pictureBufferDescInitData16BitPtr);
159 :
160 0 : InitializeSamplesNeighboringReferencePicture(
161 : referenceObject,
162 : &pictureBufferDescInitData16BitPtr,
163 : pictureBufferDescInitData16BitPtr.bit_depth);
164 :
165 : // Hsan: set split_mode to 1 to construct the unpacked reference buffer (used @ MD)
166 0 : pictureBufferDescInitData16BitPtr.split_mode = EB_TRUE;
167 0 : EB_NEW(
168 : referenceObject->reference_picture,
169 : eb_picture_buffer_desc_ctor,
170 : (EbPtr)&pictureBufferDescInitData16BitPtr);
171 : }
172 : else {
173 : // Hsan: set split_mode to 0 to as 8BIT input
174 114 : pictureBufferDescInitDataPtr->split_mode = EB_FALSE;
175 114 : EB_NEW(
176 : referenceObject->reference_picture,
177 : eb_picture_buffer_desc_ctor,
178 : (EbPtr)pictureBufferDescInitDataPtr);
179 :
180 114 : InitializeSamplesNeighboringReferencePicture(
181 : referenceObject,
182 : pictureBufferDescInitDataPtr,
183 : pictureBufferDescInitData16BitPtr.bit_depth);
184 : }
185 114 : if (pictureBufferDescInitDataPtr->mfmv)
186 : {
187 : //MFMV map is 8x8 based.
188 57 : uint32_t mi_rows = referenceObject->reference_picture->height >> MI_SIZE_LOG2;
189 57 : uint32_t mi_cols = referenceObject->reference_picture->width >> MI_SIZE_LOG2;
190 57 : const int mem_size = ((mi_rows + 1) >> 1) * ((mi_cols + 1) >> 1);
191 57 : EB_CALLOC_ALIGNED_ARRAY(referenceObject->mvs, mem_size);
192 : }
193 114 : memset(&referenceObject->film_grain_params, 0, sizeof(referenceObject->film_grain_params));
194 : #if TWO_PASS
195 114 : EB_CREATE_MUTEX(referenceObject->referenced_area_mutex);
196 : #endif
197 114 : return EB_ErrorNone;
198 : }
199 :
200 114 : EbErrorType eb_reference_object_creator(
201 : EbPtr *object_dbl_ptr,
202 : EbPtr object_init_data_ptr)
203 : {
204 : EbReferenceObject* obj;
205 :
206 114 : *object_dbl_ptr = NULL;
207 114 : EB_NEW(obj, eb_reference_object_ctor, object_init_data_ptr);
208 114 : *object_dbl_ptr = obj;
209 :
210 114 : return EB_ErrorNone;
211 : }
212 :
213 114 : static void eb_pa_reference_object_dctor(EbPtr p)
214 : {
215 114 : EbPaReferenceObject* obj = (EbPaReferenceObject*)p;
216 114 : EB_DELETE(obj->input_padded_picture_ptr);
217 114 : EB_DELETE(obj->quarter_decimated_picture_ptr);
218 114 : EB_DELETE(obj->sixteenth_decimated_picture_ptr);
219 114 : EB_DELETE(obj->quarter_filtered_picture_ptr);
220 114 : EB_DELETE(obj->sixteenth_filtered_picture_ptr);
221 114 : }
222 :
223 : /*****************************************
224 : * eb_pa_reference_object_ctor
225 : * Initializes the Buffer Descriptor's
226 : * values that are fixed for the life of
227 : * the descriptor.
228 : *****************************************/
229 114 : EbErrorType eb_pa_reference_object_ctor(
230 : EbPaReferenceObject *paReferenceObject,
231 : EbPtr object_init_data_ptr)
232 : {
233 114 : EbPictureBufferDescInitData *pictureBufferDescInitDataPtr = (EbPictureBufferDescInitData*)object_init_data_ptr;
234 :
235 114 : paReferenceObject->dctor = eb_pa_reference_object_dctor;
236 :
237 : // Reference picture constructor
238 114 : EB_NEW(
239 : paReferenceObject->input_padded_picture_ptr,
240 : eb_picture_buffer_desc_ctor,
241 : (EbPtr)pictureBufferDescInitDataPtr);
242 : // Quarter Decim reference picture constructor
243 114 : EB_NEW(
244 : paReferenceObject->quarter_decimated_picture_ptr,
245 : eb_picture_buffer_desc_ctor,
246 : (EbPtr)(pictureBufferDescInitDataPtr + 1));
247 114 : EB_NEW(
248 : paReferenceObject->sixteenth_decimated_picture_ptr,
249 : eb_picture_buffer_desc_ctor,
250 : (EbPtr)(pictureBufferDescInitDataPtr + 2));
251 : // Quarter Filtered reference picture constructor
252 114 : if ((pictureBufferDescInitDataPtr + 1)->down_sampled_filtered) {
253 57 : EB_NEW(
254 : paReferenceObject->quarter_filtered_picture_ptr,
255 : eb_picture_buffer_desc_ctor,
256 : (EbPtr)(pictureBufferDescInitDataPtr + 1));
257 : }
258 : // Sixteenth Filtered reference picture constructor
259 114 : if ((pictureBufferDescInitDataPtr + 2)->down_sampled_filtered) {
260 57 : EB_NEW(
261 : paReferenceObject->sixteenth_filtered_picture_ptr,
262 : eb_picture_buffer_desc_ctor,
263 : (EbPtr)(pictureBufferDescInitDataPtr + 2));
264 : }
265 :
266 114 : return EB_ErrorNone;
267 : }
268 :
269 114 : EbErrorType eb_pa_reference_object_creator(
270 : EbPtr *object_dbl_ptr,
271 : EbPtr object_init_data_ptr)
272 : {
273 : EbPaReferenceObject* obj;
274 :
275 114 : *object_dbl_ptr = NULL;
276 114 : EB_NEW(obj, eb_pa_reference_object_ctor, object_init_data_ptr);
277 114 : *object_dbl_ptr = obj;
278 :
279 114 : return EB_ErrorNone;
280 : }
|