1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_AV1_COMMON_THREAD_COMMON_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AV1_COMMON_THREAD_COMMON_H_
14*77c1e3ccSAndroid Build Coastguard Worker
15*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
16*77c1e3ccSAndroid Build Coastguard Worker
17*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/av1_loopfilter.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/cdef.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "aom_util/aom_pthread.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "aom_util/aom_thread.h"
21*77c1e3ccSAndroid Build Coastguard Worker
22*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
23*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
24*77c1e3ccSAndroid Build Coastguard Worker #endif
25*77c1e3ccSAndroid Build Coastguard Worker
26*77c1e3ccSAndroid Build Coastguard Worker struct AV1Common;
27*77c1e3ccSAndroid Build Coastguard Worker
28*77c1e3ccSAndroid Build Coastguard Worker typedef struct AV1LfMTInfo {
29*77c1e3ccSAndroid Build Coastguard Worker int mi_row;
30*77c1e3ccSAndroid Build Coastguard Worker int plane;
31*77c1e3ccSAndroid Build Coastguard Worker int dir;
32*77c1e3ccSAndroid Build Coastguard Worker int lpf_opt_level;
33*77c1e3ccSAndroid Build Coastguard Worker } AV1LfMTInfo;
34*77c1e3ccSAndroid Build Coastguard Worker
35*77c1e3ccSAndroid Build Coastguard Worker // Loopfilter row synchronization
36*77c1e3ccSAndroid Build Coastguard Worker typedef struct AV1LfSyncData {
37*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_MULTITHREAD
38*77c1e3ccSAndroid Build Coastguard Worker pthread_mutex_t *mutex_[MAX_MB_PLANE];
39*77c1e3ccSAndroid Build Coastguard Worker pthread_cond_t *cond_[MAX_MB_PLANE];
40*77c1e3ccSAndroid Build Coastguard Worker #endif
41*77c1e3ccSAndroid Build Coastguard Worker // Allocate memory to store the loop-filtered superblock index in each row.
42*77c1e3ccSAndroid Build Coastguard Worker int *cur_sb_col[MAX_MB_PLANE];
43*77c1e3ccSAndroid Build Coastguard Worker // The optimal sync_range for different resolution and platform should be
44*77c1e3ccSAndroid Build Coastguard Worker // determined by testing. Currently, it is chosen to be a power-of-2 number.
45*77c1e3ccSAndroid Build Coastguard Worker int sync_range;
46*77c1e3ccSAndroid Build Coastguard Worker int rows;
47*77c1e3ccSAndroid Build Coastguard Worker
48*77c1e3ccSAndroid Build Coastguard Worker // Row-based parallel loopfilter data
49*77c1e3ccSAndroid Build Coastguard Worker LFWorkerData *lfdata;
50*77c1e3ccSAndroid Build Coastguard Worker int num_workers;
51*77c1e3ccSAndroid Build Coastguard Worker
52*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_MULTITHREAD
53*77c1e3ccSAndroid Build Coastguard Worker pthread_mutex_t *job_mutex;
54*77c1e3ccSAndroid Build Coastguard Worker #endif
55*77c1e3ccSAndroid Build Coastguard Worker AV1LfMTInfo *job_queue;
56*77c1e3ccSAndroid Build Coastguard Worker int jobs_enqueued;
57*77c1e3ccSAndroid Build Coastguard Worker int jobs_dequeued;
58*77c1e3ccSAndroid Build Coastguard Worker
59*77c1e3ccSAndroid Build Coastguard Worker // Initialized to false, set to true by the worker thread that encounters an
60*77c1e3ccSAndroid Build Coastguard Worker // error in order to abort the processing of other worker threads.
61*77c1e3ccSAndroid Build Coastguard Worker bool lf_mt_exit;
62*77c1e3ccSAndroid Build Coastguard Worker } AV1LfSync;
63*77c1e3ccSAndroid Build Coastguard Worker
64*77c1e3ccSAndroid Build Coastguard Worker typedef struct AV1LrMTInfo {
65*77c1e3ccSAndroid Build Coastguard Worker int v_start;
66*77c1e3ccSAndroid Build Coastguard Worker int v_end;
67*77c1e3ccSAndroid Build Coastguard Worker int lr_unit_row;
68*77c1e3ccSAndroid Build Coastguard Worker int plane;
69*77c1e3ccSAndroid Build Coastguard Worker int sync_mode;
70*77c1e3ccSAndroid Build Coastguard Worker int v_copy_start;
71*77c1e3ccSAndroid Build Coastguard Worker int v_copy_end;
72*77c1e3ccSAndroid Build Coastguard Worker } AV1LrMTInfo;
73*77c1e3ccSAndroid Build Coastguard Worker
74*77c1e3ccSAndroid Build Coastguard Worker typedef struct LoopRestorationWorkerData {
75*77c1e3ccSAndroid Build Coastguard Worker int32_t *rst_tmpbuf;
76*77c1e3ccSAndroid Build Coastguard Worker void *rlbs;
77*77c1e3ccSAndroid Build Coastguard Worker void *lr_ctxt;
78*77c1e3ccSAndroid Build Coastguard Worker int do_extend_border;
79*77c1e3ccSAndroid Build Coastguard Worker struct aom_internal_error_info error_info;
80*77c1e3ccSAndroid Build Coastguard Worker } LRWorkerData;
81*77c1e3ccSAndroid Build Coastguard Worker
82*77c1e3ccSAndroid Build Coastguard Worker // Looprestoration row synchronization
83*77c1e3ccSAndroid Build Coastguard Worker typedef struct AV1LrSyncData {
84*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_MULTITHREAD
85*77c1e3ccSAndroid Build Coastguard Worker pthread_mutex_t *mutex_[MAX_MB_PLANE];
86*77c1e3ccSAndroid Build Coastguard Worker pthread_cond_t *cond_[MAX_MB_PLANE];
87*77c1e3ccSAndroid Build Coastguard Worker #endif
88*77c1e3ccSAndroid Build Coastguard Worker // Allocate memory to store the loop-restoration block index in each row.
89*77c1e3ccSAndroid Build Coastguard Worker int *cur_sb_col[MAX_MB_PLANE];
90*77c1e3ccSAndroid Build Coastguard Worker // The optimal sync_range for different resolution and platform should be
91*77c1e3ccSAndroid Build Coastguard Worker // determined by testing. Currently, it is chosen to be a power-of-2 number.
92*77c1e3ccSAndroid Build Coastguard Worker int sync_range;
93*77c1e3ccSAndroid Build Coastguard Worker int rows;
94*77c1e3ccSAndroid Build Coastguard Worker int num_planes;
95*77c1e3ccSAndroid Build Coastguard Worker
96*77c1e3ccSAndroid Build Coastguard Worker int num_workers;
97*77c1e3ccSAndroid Build Coastguard Worker
98*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_MULTITHREAD
99*77c1e3ccSAndroid Build Coastguard Worker pthread_mutex_t *job_mutex;
100*77c1e3ccSAndroid Build Coastguard Worker #endif
101*77c1e3ccSAndroid Build Coastguard Worker // Row-based parallel loopfilter data
102*77c1e3ccSAndroid Build Coastguard Worker LRWorkerData *lrworkerdata;
103*77c1e3ccSAndroid Build Coastguard Worker
104*77c1e3ccSAndroid Build Coastguard Worker AV1LrMTInfo *job_queue;
105*77c1e3ccSAndroid Build Coastguard Worker int jobs_enqueued;
106*77c1e3ccSAndroid Build Coastguard Worker int jobs_dequeued;
107*77c1e3ccSAndroid Build Coastguard Worker // Initialized to false, set to true by the worker thread that encounters
108*77c1e3ccSAndroid Build Coastguard Worker // an error in order to abort the processing of other worker threads.
109*77c1e3ccSAndroid Build Coastguard Worker bool lr_mt_exit;
110*77c1e3ccSAndroid Build Coastguard Worker } AV1LrSync;
111*77c1e3ccSAndroid Build Coastguard Worker
112*77c1e3ccSAndroid Build Coastguard Worker typedef struct AV1CdefWorker {
113*77c1e3ccSAndroid Build Coastguard Worker AV1_COMMON *cm;
114*77c1e3ccSAndroid Build Coastguard Worker MACROBLOCKD *xd;
115*77c1e3ccSAndroid Build Coastguard Worker uint16_t *colbuf[MAX_MB_PLANE];
116*77c1e3ccSAndroid Build Coastguard Worker uint16_t *srcbuf;
117*77c1e3ccSAndroid Build Coastguard Worker uint16_t *linebuf[MAX_MB_PLANE];
118*77c1e3ccSAndroid Build Coastguard Worker cdef_init_fb_row_t cdef_init_fb_row_fn;
119*77c1e3ccSAndroid Build Coastguard Worker int do_extend_border;
120*77c1e3ccSAndroid Build Coastguard Worker struct aom_internal_error_info error_info;
121*77c1e3ccSAndroid Build Coastguard Worker } AV1CdefWorkerData;
122*77c1e3ccSAndroid Build Coastguard Worker
123*77c1e3ccSAndroid Build Coastguard Worker typedef struct AV1CdefRowSync {
124*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_MULTITHREAD
125*77c1e3ccSAndroid Build Coastguard Worker pthread_mutex_t *row_mutex_;
126*77c1e3ccSAndroid Build Coastguard Worker pthread_cond_t *row_cond_;
127*77c1e3ccSAndroid Build Coastguard Worker #endif // CONFIG_MULTITHREAD
128*77c1e3ccSAndroid Build Coastguard Worker int is_row_done;
129*77c1e3ccSAndroid Build Coastguard Worker } AV1CdefRowSync;
130*77c1e3ccSAndroid Build Coastguard Worker
131*77c1e3ccSAndroid Build Coastguard Worker // Data related to CDEF search multi-thread synchronization.
132*77c1e3ccSAndroid Build Coastguard Worker typedef struct AV1CdefSyncData {
133*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_MULTITHREAD
134*77c1e3ccSAndroid Build Coastguard Worker // Mutex lock used while dispatching jobs.
135*77c1e3ccSAndroid Build Coastguard Worker pthread_mutex_t *mutex_;
136*77c1e3ccSAndroid Build Coastguard Worker #endif // CONFIG_MULTITHREAD
137*77c1e3ccSAndroid Build Coastguard Worker // Data related to CDEF row mt sync information
138*77c1e3ccSAndroid Build Coastguard Worker AV1CdefRowSync *cdef_row_mt;
139*77c1e3ccSAndroid Build Coastguard Worker // Flag to indicate all blocks are processed and end of frame is reached
140*77c1e3ccSAndroid Build Coastguard Worker int end_of_frame;
141*77c1e3ccSAndroid Build Coastguard Worker // Row index in units of 64x64 block
142*77c1e3ccSAndroid Build Coastguard Worker int fbr;
143*77c1e3ccSAndroid Build Coastguard Worker // Column index in units of 64x64 block
144*77c1e3ccSAndroid Build Coastguard Worker int fbc;
145*77c1e3ccSAndroid Build Coastguard Worker // Initialized to false, set to true by the worker thread that encounters
146*77c1e3ccSAndroid Build Coastguard Worker // an error in order to abort the processing of other worker threads.
147*77c1e3ccSAndroid Build Coastguard Worker bool cdef_mt_exit;
148*77c1e3ccSAndroid Build Coastguard Worker } AV1CdefSync;
149*77c1e3ccSAndroid Build Coastguard Worker
150*77c1e3ccSAndroid Build Coastguard Worker void av1_cdef_frame_mt(AV1_COMMON *const cm, MACROBLOCKD *const xd,
151*77c1e3ccSAndroid Build Coastguard Worker AV1CdefWorkerData *const cdef_worker,
152*77c1e3ccSAndroid Build Coastguard Worker AVxWorker *const workers, AV1CdefSync *const cdef_sync,
153*77c1e3ccSAndroid Build Coastguard Worker int num_workers, cdef_init_fb_row_t cdef_init_fb_row_fn,
154*77c1e3ccSAndroid Build Coastguard Worker int do_extend_border);
155*77c1e3ccSAndroid Build Coastguard Worker void av1_cdef_init_fb_row_mt(const AV1_COMMON *const cm,
156*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *const xd,
157*77c1e3ccSAndroid Build Coastguard Worker CdefBlockInfo *const fb_info,
158*77c1e3ccSAndroid Build Coastguard Worker uint16_t **const linebuf, uint16_t *const src,
159*77c1e3ccSAndroid Build Coastguard Worker struct AV1CdefSyncData *const cdef_sync, int fbr);
160*77c1e3ccSAndroid Build Coastguard Worker void av1_cdef_copy_sb8_16(const AV1_COMMON *const cm, uint16_t *const dst,
161*77c1e3ccSAndroid Build Coastguard Worker int dstride, const uint8_t *src, int src_voffset,
162*77c1e3ccSAndroid Build Coastguard Worker int src_hoffset, int sstride, int vsize, int hsize);
163*77c1e3ccSAndroid Build Coastguard Worker void av1_cdef_copy_sb8_16_lowbd(uint16_t *const dst, int dstride,
164*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *src, int src_voffset,
165*77c1e3ccSAndroid Build Coastguard Worker int src_hoffset, int sstride, int vsize,
166*77c1e3ccSAndroid Build Coastguard Worker int hsize);
167*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
168*77c1e3ccSAndroid Build Coastguard Worker void av1_cdef_copy_sb8_16_highbd(uint16_t *const dst, int dstride,
169*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *src, int src_voffset,
170*77c1e3ccSAndroid Build Coastguard Worker int src_hoffset, int sstride, int vsize,
171*77c1e3ccSAndroid Build Coastguard Worker int hsize);
172*77c1e3ccSAndroid Build Coastguard Worker #endif // CONFIG_AV1_HIGHBITDEPTH
173*77c1e3ccSAndroid Build Coastguard Worker void av1_alloc_cdef_sync(AV1_COMMON *const cm, AV1CdefSync *cdef_sync,
174*77c1e3ccSAndroid Build Coastguard Worker int num_workers);
175*77c1e3ccSAndroid Build Coastguard Worker void av1_free_cdef_sync(AV1CdefSync *cdef_sync);
176*77c1e3ccSAndroid Build Coastguard Worker
177*77c1e3ccSAndroid Build Coastguard Worker // Deallocate loopfilter synchronization related mutex and data.
178*77c1e3ccSAndroid Build Coastguard Worker void av1_loop_filter_dealloc(AV1LfSync *lf_sync);
179*77c1e3ccSAndroid Build Coastguard Worker void av1_loop_filter_alloc(AV1LfSync *lf_sync, AV1_COMMON *cm, int rows,
180*77c1e3ccSAndroid Build Coastguard Worker int width, int num_workers);
181*77c1e3ccSAndroid Build Coastguard Worker
182*77c1e3ccSAndroid Build Coastguard Worker void av1_set_vert_loop_filter_done(AV1_COMMON *cm, AV1LfSync *lf_sync,
183*77c1e3ccSAndroid Build Coastguard Worker int num_mis_in_lpf_unit_height_log2);
184*77c1e3ccSAndroid Build Coastguard Worker
185*77c1e3ccSAndroid Build Coastguard Worker void av1_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm,
186*77c1e3ccSAndroid Build Coastguard Worker struct macroblockd *xd, int plane_start,
187*77c1e3ccSAndroid Build Coastguard Worker int plane_end, int partial_frame,
188*77c1e3ccSAndroid Build Coastguard Worker AVxWorker *workers, int num_workers,
189*77c1e3ccSAndroid Build Coastguard Worker AV1LfSync *lf_sync, int lpf_opt_level);
190*77c1e3ccSAndroid Build Coastguard Worker
191*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
192*77c1e3ccSAndroid Build Coastguard Worker void av1_loop_restoration_filter_frame_mt(YV12_BUFFER_CONFIG *frame,
193*77c1e3ccSAndroid Build Coastguard Worker struct AV1Common *cm,
194*77c1e3ccSAndroid Build Coastguard Worker int optimized_lr, AVxWorker *workers,
195*77c1e3ccSAndroid Build Coastguard Worker int num_workers, AV1LrSync *lr_sync,
196*77c1e3ccSAndroid Build Coastguard Worker void *lr_ctxt, int do_extend_border);
197*77c1e3ccSAndroid Build Coastguard Worker void av1_loop_restoration_dealloc(AV1LrSync *lr_sync);
198*77c1e3ccSAndroid Build Coastguard Worker void av1_loop_restoration_alloc(AV1LrSync *lr_sync, AV1_COMMON *cm,
199*77c1e3ccSAndroid Build Coastguard Worker int num_workers, int num_rows_lr,
200*77c1e3ccSAndroid Build Coastguard Worker int num_planes, int width);
201*77c1e3ccSAndroid Build Coastguard Worker #endif // !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
202*77c1e3ccSAndroid Build Coastguard Worker
203*77c1e3ccSAndroid Build Coastguard Worker int av1_get_intrabc_extra_top_right_sb_delay(const AV1_COMMON *cm);
204*77c1e3ccSAndroid Build Coastguard Worker
205*77c1e3ccSAndroid Build Coastguard Worker void av1_thread_loop_filter_rows(
206*77c1e3ccSAndroid Build Coastguard Worker const YV12_BUFFER_CONFIG *const frame_buffer, AV1_COMMON *const cm,
207*77c1e3ccSAndroid Build Coastguard Worker struct macroblockd_plane *planes, MACROBLOCKD *xd, int mi_row, int plane,
208*77c1e3ccSAndroid Build Coastguard Worker int dir, int lpf_opt_level, AV1LfSync *const lf_sync,
209*77c1e3ccSAndroid Build Coastguard Worker struct aom_internal_error_info *error_info,
210*77c1e3ccSAndroid Build Coastguard Worker AV1_DEBLOCKING_PARAMETERS *params_buf, TX_SIZE *tx_buf, int mib_size_log2);
211*77c1e3ccSAndroid Build Coastguard Worker
skip_loop_filter_plane(const int planes_to_lf[MAX_MB_PLANE],int plane,int lpf_opt_level)212*77c1e3ccSAndroid Build Coastguard Worker static AOM_FORCE_INLINE bool skip_loop_filter_plane(
213*77c1e3ccSAndroid Build Coastguard Worker const int planes_to_lf[MAX_MB_PLANE], int plane, int lpf_opt_level) {
214*77c1e3ccSAndroid Build Coastguard Worker // If LPF_PICK_METHOD is LPF_PICK_FROM_Q, we have the option to filter both
215*77c1e3ccSAndroid Build Coastguard Worker // chroma planes together
216*77c1e3ccSAndroid Build Coastguard Worker if (lpf_opt_level == 2) {
217*77c1e3ccSAndroid Build Coastguard Worker if (plane == AOM_PLANE_Y) {
218*77c1e3ccSAndroid Build Coastguard Worker return !planes_to_lf[plane];
219*77c1e3ccSAndroid Build Coastguard Worker }
220*77c1e3ccSAndroid Build Coastguard Worker if (plane == AOM_PLANE_U) {
221*77c1e3ccSAndroid Build Coastguard Worker // U and V are handled together
222*77c1e3ccSAndroid Build Coastguard Worker return !planes_to_lf[1] && !planes_to_lf[2];
223*77c1e3ccSAndroid Build Coastguard Worker }
224*77c1e3ccSAndroid Build Coastguard Worker assert(plane == AOM_PLANE_V);
225*77c1e3ccSAndroid Build Coastguard Worker if (plane == AOM_PLANE_V) {
226*77c1e3ccSAndroid Build Coastguard Worker // V is handled when u is filtered
227*77c1e3ccSAndroid Build Coastguard Worker return true;
228*77c1e3ccSAndroid Build Coastguard Worker }
229*77c1e3ccSAndroid Build Coastguard Worker }
230*77c1e3ccSAndroid Build Coastguard Worker
231*77c1e3ccSAndroid Build Coastguard Worker // Normal operation mode
232*77c1e3ccSAndroid Build Coastguard Worker return !planes_to_lf[plane];
233*77c1e3ccSAndroid Build Coastguard Worker }
234*77c1e3ccSAndroid Build Coastguard Worker
enqueue_lf_jobs(AV1LfSync * lf_sync,int start,int stop,const int planes_to_lf[MAX_MB_PLANE],int lpf_opt_level,int num_mis_in_lpf_unit_height)235*77c1e3ccSAndroid Build Coastguard Worker static inline void enqueue_lf_jobs(AV1LfSync *lf_sync, int start, int stop,
236*77c1e3ccSAndroid Build Coastguard Worker const int planes_to_lf[MAX_MB_PLANE],
237*77c1e3ccSAndroid Build Coastguard Worker int lpf_opt_level,
238*77c1e3ccSAndroid Build Coastguard Worker int num_mis_in_lpf_unit_height) {
239*77c1e3ccSAndroid Build Coastguard Worker int mi_row, plane, dir;
240*77c1e3ccSAndroid Build Coastguard Worker AV1LfMTInfo *lf_job_queue = lf_sync->job_queue;
241*77c1e3ccSAndroid Build Coastguard Worker lf_sync->jobs_enqueued = 0;
242*77c1e3ccSAndroid Build Coastguard Worker lf_sync->jobs_dequeued = 0;
243*77c1e3ccSAndroid Build Coastguard Worker
244*77c1e3ccSAndroid Build Coastguard Worker // Launch all vertical jobs first, as they are blocking the horizontal ones.
245*77c1e3ccSAndroid Build Coastguard Worker // Launch top row jobs for all planes first, in case the output can be
246*77c1e3ccSAndroid Build Coastguard Worker // partially reconstructed row by row.
247*77c1e3ccSAndroid Build Coastguard Worker for (dir = 0; dir < 2; ++dir) {
248*77c1e3ccSAndroid Build Coastguard Worker for (mi_row = start; mi_row < stop; mi_row += num_mis_in_lpf_unit_height) {
249*77c1e3ccSAndroid Build Coastguard Worker for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
250*77c1e3ccSAndroid Build Coastguard Worker if (skip_loop_filter_plane(planes_to_lf, plane, lpf_opt_level)) {
251*77c1e3ccSAndroid Build Coastguard Worker continue;
252*77c1e3ccSAndroid Build Coastguard Worker }
253*77c1e3ccSAndroid Build Coastguard Worker if (!planes_to_lf[plane]) continue;
254*77c1e3ccSAndroid Build Coastguard Worker lf_job_queue->mi_row = mi_row;
255*77c1e3ccSAndroid Build Coastguard Worker lf_job_queue->plane = plane;
256*77c1e3ccSAndroid Build Coastguard Worker lf_job_queue->dir = dir;
257*77c1e3ccSAndroid Build Coastguard Worker lf_job_queue->lpf_opt_level = lpf_opt_level;
258*77c1e3ccSAndroid Build Coastguard Worker lf_job_queue++;
259*77c1e3ccSAndroid Build Coastguard Worker lf_sync->jobs_enqueued++;
260*77c1e3ccSAndroid Build Coastguard Worker }
261*77c1e3ccSAndroid Build Coastguard Worker }
262*77c1e3ccSAndroid Build Coastguard Worker }
263*77c1e3ccSAndroid Build Coastguard Worker }
264*77c1e3ccSAndroid Build Coastguard Worker
loop_filter_frame_mt_init(AV1_COMMON * cm,int start_mi_row,int end_mi_row,const int planes_to_lf[MAX_MB_PLANE],int num_workers,AV1LfSync * lf_sync,int lpf_opt_level,int num_mis_in_lpf_unit_height_log2)265*77c1e3ccSAndroid Build Coastguard Worker static inline void loop_filter_frame_mt_init(
266*77c1e3ccSAndroid Build Coastguard Worker AV1_COMMON *cm, int start_mi_row, int end_mi_row,
267*77c1e3ccSAndroid Build Coastguard Worker const int planes_to_lf[MAX_MB_PLANE], int num_workers, AV1LfSync *lf_sync,
268*77c1e3ccSAndroid Build Coastguard Worker int lpf_opt_level, int num_mis_in_lpf_unit_height_log2) {
269*77c1e3ccSAndroid Build Coastguard Worker // Number of superblock rows
270*77c1e3ccSAndroid Build Coastguard Worker const int sb_rows =
271*77c1e3ccSAndroid Build Coastguard Worker CEIL_POWER_OF_TWO(cm->mi_params.mi_rows, num_mis_in_lpf_unit_height_log2);
272*77c1e3ccSAndroid Build Coastguard Worker
273*77c1e3ccSAndroid Build Coastguard Worker if (!lf_sync->sync_range || sb_rows != lf_sync->rows ||
274*77c1e3ccSAndroid Build Coastguard Worker num_workers > lf_sync->num_workers) {
275*77c1e3ccSAndroid Build Coastguard Worker av1_loop_filter_dealloc(lf_sync);
276*77c1e3ccSAndroid Build Coastguard Worker av1_loop_filter_alloc(lf_sync, cm, sb_rows, cm->width, num_workers);
277*77c1e3ccSAndroid Build Coastguard Worker }
278*77c1e3ccSAndroid Build Coastguard Worker lf_sync->lf_mt_exit = false;
279*77c1e3ccSAndroid Build Coastguard Worker
280*77c1e3ccSAndroid Build Coastguard Worker // Initialize cur_sb_col to -1 for all SB rows.
281*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < MAX_MB_PLANE; i++) {
282*77c1e3ccSAndroid Build Coastguard Worker memset(lf_sync->cur_sb_col[i], -1,
283*77c1e3ccSAndroid Build Coastguard Worker sizeof(*(lf_sync->cur_sb_col[i])) * sb_rows);
284*77c1e3ccSAndroid Build Coastguard Worker }
285*77c1e3ccSAndroid Build Coastguard Worker
286*77c1e3ccSAndroid Build Coastguard Worker enqueue_lf_jobs(lf_sync, start_mi_row, end_mi_row, planes_to_lf,
287*77c1e3ccSAndroid Build Coastguard Worker lpf_opt_level, (1 << num_mis_in_lpf_unit_height_log2));
288*77c1e3ccSAndroid Build Coastguard Worker }
289*77c1e3ccSAndroid Build Coastguard Worker
get_lf_job_info(AV1LfSync * lf_sync)290*77c1e3ccSAndroid Build Coastguard Worker static inline AV1LfMTInfo *get_lf_job_info(AV1LfSync *lf_sync) {
291*77c1e3ccSAndroid Build Coastguard Worker AV1LfMTInfo *cur_job_info = NULL;
292*77c1e3ccSAndroid Build Coastguard Worker
293*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_MULTITHREAD
294*77c1e3ccSAndroid Build Coastguard Worker pthread_mutex_lock(lf_sync->job_mutex);
295*77c1e3ccSAndroid Build Coastguard Worker
296*77c1e3ccSAndroid Build Coastguard Worker if (!lf_sync->lf_mt_exit && lf_sync->jobs_dequeued < lf_sync->jobs_enqueued) {
297*77c1e3ccSAndroid Build Coastguard Worker cur_job_info = lf_sync->job_queue + lf_sync->jobs_dequeued;
298*77c1e3ccSAndroid Build Coastguard Worker lf_sync->jobs_dequeued++;
299*77c1e3ccSAndroid Build Coastguard Worker }
300*77c1e3ccSAndroid Build Coastguard Worker
301*77c1e3ccSAndroid Build Coastguard Worker pthread_mutex_unlock(lf_sync->job_mutex);
302*77c1e3ccSAndroid Build Coastguard Worker #else
303*77c1e3ccSAndroid Build Coastguard Worker (void)lf_sync;
304*77c1e3ccSAndroid Build Coastguard Worker #endif
305*77c1e3ccSAndroid Build Coastguard Worker
306*77c1e3ccSAndroid Build Coastguard Worker return cur_job_info;
307*77c1e3ccSAndroid Build Coastguard Worker }
308*77c1e3ccSAndroid Build Coastguard Worker
loop_filter_data_reset(LFWorkerData * lf_data,YV12_BUFFER_CONFIG * frame_buffer,struct AV1Common * cm,MACROBLOCKD * xd)309*77c1e3ccSAndroid Build Coastguard Worker static inline void loop_filter_data_reset(LFWorkerData *lf_data,
310*77c1e3ccSAndroid Build Coastguard Worker YV12_BUFFER_CONFIG *frame_buffer,
311*77c1e3ccSAndroid Build Coastguard Worker struct AV1Common *cm,
312*77c1e3ccSAndroid Build Coastguard Worker MACROBLOCKD *xd) {
313*77c1e3ccSAndroid Build Coastguard Worker struct macroblockd_plane *pd = xd->plane;
314*77c1e3ccSAndroid Build Coastguard Worker lf_data->frame_buffer = frame_buffer;
315*77c1e3ccSAndroid Build Coastguard Worker lf_data->cm = cm;
316*77c1e3ccSAndroid Build Coastguard Worker lf_data->xd = xd;
317*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < MAX_MB_PLANE; i++) {
318*77c1e3ccSAndroid Build Coastguard Worker memcpy(&lf_data->planes[i].dst, &pd[i].dst, sizeof(lf_data->planes[i].dst));
319*77c1e3ccSAndroid Build Coastguard Worker lf_data->planes[i].subsampling_x = pd[i].subsampling_x;
320*77c1e3ccSAndroid Build Coastguard Worker lf_data->planes[i].subsampling_y = pd[i].subsampling_y;
321*77c1e3ccSAndroid Build Coastguard Worker }
322*77c1e3ccSAndroid Build Coastguard Worker }
323*77c1e3ccSAndroid Build Coastguard Worker
set_planes_to_loop_filter(const struct loopfilter * lf,int planes_to_lf[MAX_MB_PLANE],int plane_start,int plane_end)324*77c1e3ccSAndroid Build Coastguard Worker static inline void set_planes_to_loop_filter(const struct loopfilter *lf,
325*77c1e3ccSAndroid Build Coastguard Worker int planes_to_lf[MAX_MB_PLANE],
326*77c1e3ccSAndroid Build Coastguard Worker int plane_start, int plane_end) {
327*77c1e3ccSAndroid Build Coastguard Worker // For each luma and chroma plane, whether to filter it or not.
328*77c1e3ccSAndroid Build Coastguard Worker planes_to_lf[0] = (lf->filter_level[0] || lf->filter_level[1]) &&
329*77c1e3ccSAndroid Build Coastguard Worker plane_start <= 0 && 0 < plane_end;
330*77c1e3ccSAndroid Build Coastguard Worker planes_to_lf[1] = lf->filter_level_u && plane_start <= 1 && 1 < plane_end;
331*77c1e3ccSAndroid Build Coastguard Worker planes_to_lf[2] = lf->filter_level_v && plane_start <= 2 && 2 < plane_end;
332*77c1e3ccSAndroid Build Coastguard Worker }
333*77c1e3ccSAndroid Build Coastguard Worker
check_planes_to_loop_filter(const struct loopfilter * lf,int planes_to_lf[MAX_MB_PLANE],int plane_start,int plane_end)334*77c1e3ccSAndroid Build Coastguard Worker static inline int check_planes_to_loop_filter(const struct loopfilter *lf,
335*77c1e3ccSAndroid Build Coastguard Worker int planes_to_lf[MAX_MB_PLANE],
336*77c1e3ccSAndroid Build Coastguard Worker int plane_start, int plane_end) {
337*77c1e3ccSAndroid Build Coastguard Worker set_planes_to_loop_filter(lf, planes_to_lf, plane_start, plane_end);
338*77c1e3ccSAndroid Build Coastguard Worker // If the luma plane is purposely not filtered, neither are the chroma
339*77c1e3ccSAndroid Build Coastguard Worker // planes.
340*77c1e3ccSAndroid Build Coastguard Worker if (!planes_to_lf[0] && plane_start <= 0 && 0 < plane_end) return 0;
341*77c1e3ccSAndroid Build Coastguard Worker // Early exit.
342*77c1e3ccSAndroid Build Coastguard Worker if (!planes_to_lf[0] && !planes_to_lf[1] && !planes_to_lf[2]) return 0;
343*77c1e3ccSAndroid Build Coastguard Worker return 1;
344*77c1e3ccSAndroid Build Coastguard Worker }
345*77c1e3ccSAndroid Build Coastguard Worker
346*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
347*77c1e3ccSAndroid Build Coastguard Worker } // extern "C"
348*77c1e3ccSAndroid Build Coastguard Worker #endif
349*77c1e3ccSAndroid Build Coastguard Worker
350*77c1e3ccSAndroid Build Coastguard Worker #endif // AOM_AV1_COMMON_THREAD_COMMON_H_
351