1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #include <assert.h>
13 #include <stddef.h>
14 #include <string.h>
15
16 #include "config/aom_scale_rtcd.h"
17
18 #include "aom/aom_integer.h"
19 #include "aom_util/aom_pthread.h"
20 #include "av1/common/av1_common_int.h"
21 #include "av1/common/cdef.h"
22 #include "av1/common/cdef_block.h"
23 #include "av1/common/common.h"
24 #include "av1/common/common_data.h"
25 #include "av1/common/enums.h"
26 #include "av1/common/reconinter.h"
27 #include "av1/common/thread_common.h"
28
is_8x8_block_skip(MB_MODE_INFO ** grid,int mi_row,int mi_col,int mi_stride)29 static int is_8x8_block_skip(MB_MODE_INFO **grid, int mi_row, int mi_col,
30 int mi_stride) {
31 MB_MODE_INFO **mbmi = grid + mi_row * mi_stride + mi_col;
32 for (int r = 0; r < mi_size_high[BLOCK_8X8]; ++r, mbmi += mi_stride) {
33 for (int c = 0; c < mi_size_wide[BLOCK_8X8]; ++c) {
34 if (!mbmi[c]->skip_txfm) return 0;
35 }
36 }
37
38 return 1;
39 }
40
av1_cdef_compute_sb_list(const CommonModeInfoParams * const mi_params,int mi_row,int mi_col,cdef_list * dlist,BLOCK_SIZE bs)41 int av1_cdef_compute_sb_list(const CommonModeInfoParams *const mi_params,
42 int mi_row, int mi_col, cdef_list *dlist,
43 BLOCK_SIZE bs) {
44 MB_MODE_INFO **grid = mi_params->mi_grid_base;
45 int maxc = mi_params->mi_cols - mi_col;
46 int maxr = mi_params->mi_rows - mi_row;
47
48 if (bs == BLOCK_128X128 || bs == BLOCK_128X64)
49 maxc = AOMMIN(maxc, MI_SIZE_128X128);
50 else
51 maxc = AOMMIN(maxc, MI_SIZE_64X64);
52 if (bs == BLOCK_128X128 || bs == BLOCK_64X128)
53 maxr = AOMMIN(maxr, MI_SIZE_128X128);
54 else
55 maxr = AOMMIN(maxr, MI_SIZE_64X64);
56
57 const int r_step = 2; // mi_size_high[BLOCK_8X8]
58 const int c_step = 2; // mi_size_wide[BLOCK_8X8]
59 const int r_shift = 1;
60 const int c_shift = 1;
61 int count = 0;
62 for (int r = 0; r < maxr; r += r_step) {
63 for (int c = 0; c < maxc; c += c_step) {
64 if (!is_8x8_block_skip(grid, mi_row + r, mi_col + c,
65 mi_params->mi_stride)) {
66 dlist[count].by = r >> r_shift;
67 dlist[count].bx = c >> c_shift;
68 count++;
69 }
70 }
71 }
72 return count;
73 }
74
cdef_copy_rect8_8bit_to_16bit_c(uint16_t * dst,int dstride,const uint8_t * src,int sstride,int width,int height)75 void cdef_copy_rect8_8bit_to_16bit_c(uint16_t *dst, int dstride,
76 const uint8_t *src, int sstride, int width,
77 int height) {
78 for (int i = 0; i < height; i++) {
79 for (int j = 0; j < width; j++) {
80 dst[i * dstride + j] = src[i * sstride + j];
81 }
82 }
83 }
84
cdef_copy_rect8_16bit_to_16bit_c(uint16_t * dst,int dstride,const uint16_t * src,int sstride,int width,int height)85 void cdef_copy_rect8_16bit_to_16bit_c(uint16_t *dst, int dstride,
86 const uint16_t *src, int sstride,
87 int width, int height) {
88 for (int i = 0; i < height; i++) {
89 for (int j = 0; j < width; j++) {
90 dst[i * dstride + j] = src[i * sstride + j];
91 }
92 }
93 }
94
av1_cdef_copy_sb8_16_lowbd(uint16_t * const dst,int dstride,const uint8_t * src,int src_voffset,int src_hoffset,int sstride,int vsize,int hsize)95 void av1_cdef_copy_sb8_16_lowbd(uint16_t *const dst, int dstride,
96 const uint8_t *src, int src_voffset,
97 int src_hoffset, int sstride, int vsize,
98 int hsize) {
99 const uint8_t *base = &src[src_voffset * (ptrdiff_t)sstride + src_hoffset];
100 cdef_copy_rect8_8bit_to_16bit(dst, dstride, base, sstride, hsize, vsize);
101 }
102
av1_cdef_copy_sb8_16_highbd(uint16_t * const dst,int dstride,const uint8_t * src,int src_voffset,int src_hoffset,int sstride,int vsize,int hsize)103 void av1_cdef_copy_sb8_16_highbd(uint16_t *const dst, int dstride,
104 const uint8_t *src, int src_voffset,
105 int src_hoffset, int sstride, int vsize,
106 int hsize) {
107 const uint16_t *base =
108 &CONVERT_TO_SHORTPTR(src)[src_voffset * (ptrdiff_t)sstride + src_hoffset];
109 cdef_copy_rect8_16bit_to_16bit(dst, dstride, base, sstride, hsize, vsize);
110 }
111
av1_cdef_copy_sb8_16(const AV1_COMMON * const cm,uint16_t * const dst,int dstride,const uint8_t * src,int src_voffset,int src_hoffset,int sstride,int vsize,int hsize)112 void av1_cdef_copy_sb8_16(const AV1_COMMON *const cm, uint16_t *const dst,
113 int dstride, const uint8_t *src, int src_voffset,
114 int src_hoffset, int sstride, int vsize, int hsize) {
115 if (cm->seq_params->use_highbitdepth) {
116 av1_cdef_copy_sb8_16_highbd(dst, dstride, src, src_voffset, src_hoffset,
117 sstride, vsize, hsize);
118 } else {
119 av1_cdef_copy_sb8_16_lowbd(dst, dstride, src, src_voffset, src_hoffset,
120 sstride, vsize, hsize);
121 }
122 }
123
copy_rect(uint16_t * dst,int dstride,const uint16_t * src,int sstride,int v,int h)124 static INLINE void copy_rect(uint16_t *dst, int dstride, const uint16_t *src,
125 int sstride, int v, int h) {
126 for (int i = 0; i < v; i++) {
127 for (int j = 0; j < h; j++) {
128 dst[i * dstride + j] = src[i * sstride + j];
129 }
130 }
131 }
132
133 // Prepares intermediate input buffer for CDEF.
134 // Inputs:
135 // cm: Pointer to common structure.
136 // fb_info: Pointer to the CDEF block-level parameter structure.
137 // colbuf: Left column buffer for CDEF.
138 // cdef_left: Left block is filtered or not.
139 // fbc, fbr: col and row index of a block.
140 // plane: plane index Y/CB/CR.
141 // Returns:
142 // Nothing will be returned.
cdef_prepare_fb(const AV1_COMMON * const cm,CdefBlockInfo * fb_info,uint16_t ** const colbuf,const int cdef_left,int fbc,int fbr,int plane)143 static void cdef_prepare_fb(const AV1_COMMON *const cm, CdefBlockInfo *fb_info,
144 uint16_t **const colbuf, const int cdef_left,
145 int fbc, int fbr, int plane) {
146 const CommonModeInfoParams *const mi_params = &cm->mi_params;
147 uint16_t *src = fb_info->src;
148 const int luma_stride =
149 ALIGN_POWER_OF_TWO(mi_params->mi_cols << MI_SIZE_LOG2, 4);
150 const int nvfb = (mi_params->mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
151 const int nhfb = (mi_params->mi_cols + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
152 int cstart = 0;
153 if (!cdef_left) cstart = -CDEF_HBORDER;
154 int rend, cend;
155 const int nhb =
156 AOMMIN(MI_SIZE_64X64, mi_params->mi_cols - MI_SIZE_64X64 * fbc);
157 const int nvb =
158 AOMMIN(MI_SIZE_64X64, mi_params->mi_rows - MI_SIZE_64X64 * fbr);
159 const int hsize = nhb << fb_info->mi_wide_l2;
160 const int vsize = nvb << fb_info->mi_high_l2;
161 const uint16_t *top_linebuf = fb_info->top_linebuf[plane];
162 const uint16_t *bot_linebuf = fb_info->bot_linebuf[plane];
163 const int bot_offset = (vsize + CDEF_VBORDER) * CDEF_BSTRIDE;
164 const int stride =
165 luma_stride >> (plane == AOM_PLANE_Y ? 0 : cm->seq_params->subsampling_x);
166
167 if (fbc == nhfb - 1)
168 cend = hsize;
169 else
170 cend = hsize + CDEF_HBORDER;
171
172 if (fbr == nvfb - 1)
173 rend = vsize;
174 else
175 rend = vsize + CDEF_VBORDER;
176
177 /* Copy in the pixels we need from the current superblock for
178 deringing.*/
179 av1_cdef_copy_sb8_16(
180 cm, &src[CDEF_VBORDER * CDEF_BSTRIDE + CDEF_HBORDER + cstart],
181 CDEF_BSTRIDE, fb_info->dst, fb_info->roffset, fb_info->coffset + cstart,
182 fb_info->dst_stride, vsize, cend - cstart);
183
184 /* Copy in the pixels we need for the current superblock from bottom buffer.*/
185 if (fbr < nvfb - 1) {
186 copy_rect(&src[bot_offset + CDEF_HBORDER], CDEF_BSTRIDE,
187 &bot_linebuf[fb_info->coffset], stride, CDEF_VBORDER, hsize);
188 } else {
189 fill_rect(&src[bot_offset + CDEF_HBORDER], CDEF_BSTRIDE, CDEF_VBORDER,
190 hsize, CDEF_VERY_LARGE);
191 }
192 if (fbr < nvfb - 1 && fbc > 0) {
193 copy_rect(&src[bot_offset], CDEF_BSTRIDE,
194 &bot_linebuf[fb_info->coffset - CDEF_HBORDER], stride,
195 CDEF_VBORDER, CDEF_HBORDER);
196 } else {
197 fill_rect(&src[bot_offset], CDEF_BSTRIDE, CDEF_VBORDER, CDEF_HBORDER,
198 CDEF_VERY_LARGE);
199 }
200 if (fbr < nvfb - 1 && fbc < nhfb - 1) {
201 copy_rect(&src[bot_offset + hsize + CDEF_HBORDER], CDEF_BSTRIDE,
202 &bot_linebuf[fb_info->coffset + hsize], stride, CDEF_VBORDER,
203 CDEF_HBORDER);
204 } else {
205 fill_rect(&src[bot_offset + hsize + CDEF_HBORDER], CDEF_BSTRIDE,
206 CDEF_VBORDER, CDEF_HBORDER, CDEF_VERY_LARGE);
207 }
208
209 /* Copy in the pixels we need from the current superblock from top buffer.*/
210 if (fbr > 0) {
211 copy_rect(&src[CDEF_HBORDER], CDEF_BSTRIDE, &top_linebuf[fb_info->coffset],
212 stride, CDEF_VBORDER, hsize);
213 } else {
214 fill_rect(&src[CDEF_HBORDER], CDEF_BSTRIDE, CDEF_VBORDER, hsize,
215 CDEF_VERY_LARGE);
216 }
217 if (fbr > 0 && fbc > 0) {
218 copy_rect(src, CDEF_BSTRIDE, &top_linebuf[fb_info->coffset - CDEF_HBORDER],
219 stride, CDEF_VBORDER, CDEF_HBORDER);
220 } else {
221 fill_rect(src, CDEF_BSTRIDE, CDEF_VBORDER, CDEF_HBORDER, CDEF_VERY_LARGE);
222 }
223 if (fbr > 0 && fbc < nhfb - 1) {
224 copy_rect(&src[hsize + CDEF_HBORDER], CDEF_BSTRIDE,
225 &top_linebuf[fb_info->coffset + hsize], stride, CDEF_VBORDER,
226 CDEF_HBORDER);
227 } else {
228 fill_rect(&src[hsize + CDEF_HBORDER], CDEF_BSTRIDE, CDEF_VBORDER,
229 CDEF_HBORDER, CDEF_VERY_LARGE);
230 }
231 if (cdef_left) {
232 /* If we deringed the superblock on the left then we need to copy in
233 saved pixels. */
234 copy_rect(src, CDEF_BSTRIDE, colbuf[plane], CDEF_HBORDER,
235 rend + CDEF_VBORDER, CDEF_HBORDER);
236 }
237 /* Saving pixels in case we need to dering the superblock on the
238 right. */
239 copy_rect(colbuf[plane], CDEF_HBORDER, src + hsize, CDEF_BSTRIDE,
240 rend + CDEF_VBORDER, CDEF_HBORDER);
241
242 if (fb_info->frame_boundary[LEFT]) {
243 fill_rect(src, CDEF_BSTRIDE, vsize + 2 * CDEF_VBORDER, CDEF_HBORDER,
244 CDEF_VERY_LARGE);
245 }
246 if (fb_info->frame_boundary[RIGHT]) {
247 fill_rect(&src[hsize + CDEF_HBORDER], CDEF_BSTRIDE,
248 vsize + 2 * CDEF_VBORDER, CDEF_HBORDER, CDEF_VERY_LARGE);
249 }
250 }
251
cdef_filter_fb(CdefBlockInfo * const fb_info,int plane,uint8_t use_highbitdepth)252 static INLINE void cdef_filter_fb(CdefBlockInfo *const fb_info, int plane,
253 uint8_t use_highbitdepth) {
254 ptrdiff_t offset =
255 (ptrdiff_t)fb_info->dst_stride * fb_info->roffset + fb_info->coffset;
256 if (use_highbitdepth) {
257 av1_cdef_filter_fb(
258 NULL, CONVERT_TO_SHORTPTR(fb_info->dst + offset), fb_info->dst_stride,
259 &fb_info->src[CDEF_VBORDER * CDEF_BSTRIDE + CDEF_HBORDER],
260 fb_info->xdec, fb_info->ydec, fb_info->dir, NULL, fb_info->var, plane,
261 fb_info->dlist, fb_info->cdef_count, fb_info->level,
262 fb_info->sec_strength, fb_info->damping, fb_info->coeff_shift);
263 } else {
264 av1_cdef_filter_fb(
265 fb_info->dst + offset, NULL, fb_info->dst_stride,
266 &fb_info->src[CDEF_VBORDER * CDEF_BSTRIDE + CDEF_HBORDER],
267 fb_info->xdec, fb_info->ydec, fb_info->dir, NULL, fb_info->var, plane,
268 fb_info->dlist, fb_info->cdef_count, fb_info->level,
269 fb_info->sec_strength, fb_info->damping, fb_info->coeff_shift);
270 }
271 }
272
273 // Initializes block-level parameters for CDEF.
cdef_init_fb_col(const MACROBLOCKD * const xd,CdefBlockInfo * const fb_info,int * level,int * sec_strength,int fbc,int fbr,int plane)274 static INLINE void cdef_init_fb_col(const MACROBLOCKD *const xd,
275 CdefBlockInfo *const fb_info, int *level,
276 int *sec_strength, int fbc, int fbr,
277 int plane) {
278 const PLANE_TYPE plane_type = get_plane_type(plane);
279 fb_info->level = level[plane_type];
280 fb_info->sec_strength = sec_strength[plane_type];
281 fb_info->dst = xd->plane[plane].dst.buf;
282 fb_info->dst_stride = xd->plane[plane].dst.stride;
283
284 fb_info->xdec = xd->plane[plane].subsampling_x;
285 fb_info->ydec = xd->plane[plane].subsampling_y;
286 fb_info->mi_wide_l2 = MI_SIZE_LOG2 - xd->plane[plane].subsampling_x;
287 fb_info->mi_high_l2 = MI_SIZE_LOG2 - xd->plane[plane].subsampling_y;
288 fb_info->roffset = MI_SIZE_64X64 * fbr << fb_info->mi_high_l2;
289 fb_info->coffset = MI_SIZE_64X64 * fbc << fb_info->mi_wide_l2;
290 }
291
cdef_fb_col(const AV1_COMMON * const cm,const MACROBLOCKD * const xd,CdefBlockInfo * const fb_info,uint16_t ** const colbuf,int * cdef_left,int fbc,int fbr)292 static void cdef_fb_col(const AV1_COMMON *const cm, const MACROBLOCKD *const xd,
293 CdefBlockInfo *const fb_info, uint16_t **const colbuf,
294 int *cdef_left, int fbc, int fbr) {
295 const CommonModeInfoParams *const mi_params = &cm->mi_params;
296 const int mbmi_cdef_strength =
297 mi_params
298 ->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride +
299 MI_SIZE_64X64 * fbc]
300 ->cdef_strength;
301 const int num_planes = av1_num_planes(cm);
302 int is_zero_level[PLANE_TYPES] = { 1, 1 };
303 int level[PLANE_TYPES] = { 0 };
304 int sec_strength[PLANE_TYPES] = { 0 };
305 const CdefInfo *const cdef_info = &cm->cdef_info;
306
307 if (mi_params->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride +
308 MI_SIZE_64X64 * fbc] == NULL ||
309 mbmi_cdef_strength == -1) {
310 av1_zero_array(cdef_left, num_planes);
311 return;
312 }
313
314 // Compute level and secondary strength for planes
315 level[PLANE_TYPE_Y] =
316 cdef_info->cdef_strengths[mbmi_cdef_strength] / CDEF_SEC_STRENGTHS;
317 sec_strength[PLANE_TYPE_Y] =
318 cdef_info->cdef_strengths[mbmi_cdef_strength] % CDEF_SEC_STRENGTHS;
319 sec_strength[PLANE_TYPE_Y] += sec_strength[PLANE_TYPE_Y] == 3;
320 is_zero_level[PLANE_TYPE_Y] =
321 (level[PLANE_TYPE_Y] == 0) && (sec_strength[PLANE_TYPE_Y] == 0);
322
323 if (num_planes > 1) {
324 level[PLANE_TYPE_UV] =
325 cdef_info->cdef_uv_strengths[mbmi_cdef_strength] / CDEF_SEC_STRENGTHS;
326 sec_strength[PLANE_TYPE_UV] =
327 cdef_info->cdef_uv_strengths[mbmi_cdef_strength] % CDEF_SEC_STRENGTHS;
328 sec_strength[PLANE_TYPE_UV] += sec_strength[PLANE_TYPE_UV] == 3;
329 is_zero_level[PLANE_TYPE_UV] =
330 (level[PLANE_TYPE_UV] == 0) && (sec_strength[PLANE_TYPE_UV] == 0);
331 }
332
333 if (is_zero_level[PLANE_TYPE_Y] && is_zero_level[PLANE_TYPE_UV]) {
334 av1_zero_array(cdef_left, num_planes);
335 return;
336 }
337
338 fb_info->cdef_count = av1_cdef_compute_sb_list(mi_params, fbr * MI_SIZE_64X64,
339 fbc * MI_SIZE_64X64,
340 fb_info->dlist, BLOCK_64X64);
341 if (!fb_info->cdef_count) {
342 av1_zero_array(cdef_left, num_planes);
343 return;
344 }
345
346 for (int plane = 0; plane < num_planes; plane++) {
347 // Do not skip cdef filtering for luma plane as filter direction is
348 // computed based on luma.
349 if (plane && is_zero_level[get_plane_type(plane)]) {
350 cdef_left[plane] = 0;
351 continue;
352 }
353 cdef_init_fb_col(xd, fb_info, level, sec_strength, fbc, fbr, plane);
354 cdef_prepare_fb(cm, fb_info, colbuf, cdef_left[plane], fbc, fbr, plane);
355 cdef_filter_fb(fb_info, plane, cm->seq_params->use_highbitdepth);
356 cdef_left[plane] = 1;
357 }
358 }
359
360 // Initializes row-level parameters for CDEF frame.
av1_cdef_init_fb_row(const AV1_COMMON * const cm,const MACROBLOCKD * const xd,CdefBlockInfo * const fb_info,uint16_t ** const linebuf,uint16_t * const src,struct AV1CdefSyncData * const cdef_sync,int fbr)361 void av1_cdef_init_fb_row(const AV1_COMMON *const cm,
362 const MACROBLOCKD *const xd,
363 CdefBlockInfo *const fb_info,
364 uint16_t **const linebuf, uint16_t *const src,
365 struct AV1CdefSyncData *const cdef_sync, int fbr) {
366 (void)cdef_sync;
367 const int num_planes = av1_num_planes(cm);
368 const int nvfb = (cm->mi_params.mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
369 const int luma_stride =
370 ALIGN_POWER_OF_TWO(cm->mi_params.mi_cols << MI_SIZE_LOG2, 4);
371 const bool ping_pong = fbr & 1;
372 // for the current filter block, it's top left corner mi structure (mi_tl)
373 // is first accessed to check whether the top and left boundaries are
374 // frame boundaries. Then bottom-left and top-right mi structures are
375 // accessed to check whether the bottom and right boundaries
376 // (respectively) are frame boundaries.
377 //
378 // Note that we can't just check the bottom-right mi structure - eg. if
379 // we're at the right-hand edge of the frame but not the bottom, then
380 // the bottom-right mi is NULL but the bottom-left is not.
381 fb_info->frame_boundary[TOP] = (MI_SIZE_64X64 * fbr == 0) ? 1 : 0;
382 if (fbr != nvfb - 1)
383 fb_info->frame_boundary[BOTTOM] =
384 (MI_SIZE_64X64 * (fbr + 1) == cm->mi_params.mi_rows) ? 1 : 0;
385 else
386 fb_info->frame_boundary[BOTTOM] = 1;
387
388 fb_info->src = src;
389 fb_info->damping = cm->cdef_info.cdef_damping;
390 fb_info->coeff_shift = AOMMAX(cm->seq_params->bit_depth - 8, 0);
391 av1_zero(fb_info->dir);
392 av1_zero(fb_info->var);
393
394 for (int plane = 0; plane < num_planes; plane++) {
395 const int mi_high_l2 = MI_SIZE_LOG2 - xd->plane[plane].subsampling_y;
396 const int offset = MI_SIZE_64X64 * (fbr + 1) << mi_high_l2;
397 const int stride = luma_stride >> xd->plane[plane].subsampling_x;
398 // here ping-pong buffers are maintained for top linebuf
399 // to avoid linebuf over-write by consecutive row.
400 uint16_t *const top_linebuf =
401 &linebuf[plane][ping_pong * CDEF_VBORDER * stride];
402 fb_info->bot_linebuf[plane] = &linebuf[plane][(CDEF_VBORDER << 1) * stride];
403
404 if (fbr != nvfb - 1) // top line buffer copy
405 av1_cdef_copy_sb8_16(cm, top_linebuf, stride, xd->plane[plane].dst.buf,
406 offset - CDEF_VBORDER, 0,
407 xd->plane[plane].dst.stride, CDEF_VBORDER, stride);
408 fb_info->top_linebuf[plane] =
409 &linebuf[plane][(!ping_pong) * CDEF_VBORDER * stride];
410
411 if (fbr != nvfb - 1) // bottom line buffer copy
412 av1_cdef_copy_sb8_16(cm, fb_info->bot_linebuf[plane], stride,
413 xd->plane[plane].dst.buf, offset, 0,
414 xd->plane[plane].dst.stride, CDEF_VBORDER, stride);
415 }
416 }
417
av1_cdef_fb_row(const AV1_COMMON * const cm,MACROBLOCKD * xd,uint16_t ** const linebuf,uint16_t ** const colbuf,uint16_t * const src,int fbr,cdef_init_fb_row_t cdef_init_fb_row_fn,struct AV1CdefSyncData * const cdef_sync,struct aom_internal_error_info * error_info)418 void av1_cdef_fb_row(const AV1_COMMON *const cm, MACROBLOCKD *xd,
419 uint16_t **const linebuf, uint16_t **const colbuf,
420 uint16_t *const src, int fbr,
421 cdef_init_fb_row_t cdef_init_fb_row_fn,
422 struct AV1CdefSyncData *const cdef_sync,
423 struct aom_internal_error_info *error_info) {
424 // TODO(aomedia:3276): Pass error_info to the low-level functions as required
425 // in future to handle error propagation.
426 (void)error_info;
427 CdefBlockInfo fb_info;
428 int cdef_left[MAX_MB_PLANE] = { 1, 1, 1 };
429 const int nhfb = (cm->mi_params.mi_cols + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
430
431 cdef_init_fb_row_fn(cm, xd, &fb_info, linebuf, src, cdef_sync, fbr);
432 #if CONFIG_MULTITHREAD
433 if (cdef_sync && cm->cdef_info.allocated_num_workers > 1) {
434 pthread_mutex_lock(cdef_sync->mutex_);
435 const bool cdef_mt_exit = cdef_sync->cdef_mt_exit;
436 pthread_mutex_unlock(cdef_sync->mutex_);
437 // Exit in case any worker has encountered an error.
438 if (cdef_mt_exit) return;
439 }
440 #endif
441 for (int fbc = 0; fbc < nhfb; fbc++) {
442 fb_info.frame_boundary[LEFT] = (MI_SIZE_64X64 * fbc == 0) ? 1 : 0;
443 if (fbc != nhfb - 1)
444 fb_info.frame_boundary[RIGHT] =
445 (MI_SIZE_64X64 * (fbc + 1) == cm->mi_params.mi_cols) ? 1 : 0;
446 else
447 fb_info.frame_boundary[RIGHT] = 1;
448 cdef_fb_col(cm, xd, &fb_info, colbuf, &cdef_left[0], fbc, fbr);
449 }
450 }
451
452 // Perform CDEF on input frame.
453 // Inputs:
454 // frame: Pointer to input frame buffer.
455 // cm: Pointer to common structure.
456 // xd: Pointer to common current coding block structure.
457 // Returns:
458 // Nothing will be returned.
av1_cdef_frame(YV12_BUFFER_CONFIG * frame,AV1_COMMON * const cm,MACROBLOCKD * xd,cdef_init_fb_row_t cdef_init_fb_row_fn)459 void av1_cdef_frame(YV12_BUFFER_CONFIG *frame, AV1_COMMON *const cm,
460 MACROBLOCKD *xd, cdef_init_fb_row_t cdef_init_fb_row_fn) {
461 const int num_planes = av1_num_planes(cm);
462 const int nvfb = (cm->mi_params.mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
463
464 av1_setup_dst_planes(xd->plane, cm->seq_params->sb_size, frame, 0, 0, 0,
465 num_planes);
466
467 for (int fbr = 0; fbr < nvfb; fbr++)
468 av1_cdef_fb_row(cm, xd, cm->cdef_info.linebuf, cm->cdef_info.colbuf,
469 cm->cdef_info.srcbuf, fbr, cdef_init_fb_row_fn, NULL,
470 xd->error_info);
471 }
472