• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef AOM_AV1_COMMON_THREAD_COMMON_H_
13 #define AOM_AV1_COMMON_THREAD_COMMON_H_
14 
15 #include "config/aom_config.h"
16 
17 #include "av1/common/av1_loopfilter.h"
18 #include "av1/common/cdef.h"
19 #include "aom_util/aom_thread.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 struct AV1Common;
26 
27 typedef struct AV1LfMTInfo {
28   int mi_row;
29   int plane;
30   int dir;
31   int is_realtime;
32 } AV1LfMTInfo;
33 
34 // Loopfilter row synchronization
35 typedef struct AV1LfSyncData {
36 #if CONFIG_MULTITHREAD
37   pthread_mutex_t *mutex_[MAX_MB_PLANE];
38   pthread_cond_t *cond_[MAX_MB_PLANE];
39 #endif
40   // Allocate memory to store the loop-filtered superblock index in each row.
41   int *cur_sb_col[MAX_MB_PLANE];
42   // The optimal sync_range for different resolution and platform should be
43   // determined by testing. Currently, it is chosen to be a power-of-2 number.
44   int sync_range;
45   int rows;
46 
47   // Row-based parallel loopfilter data
48   LFWorkerData *lfdata;
49   int num_workers;
50 
51 #if CONFIG_MULTITHREAD
52   pthread_mutex_t *job_mutex;
53 #endif
54   AV1LfMTInfo *job_queue;
55   int jobs_enqueued;
56   int jobs_dequeued;
57 } AV1LfSync;
58 
59 typedef struct AV1LrMTInfo {
60   int v_start;
61   int v_end;
62   int lr_unit_row;
63   int plane;
64   int sync_mode;
65   int v_copy_start;
66   int v_copy_end;
67 } AV1LrMTInfo;
68 
69 typedef struct LoopRestorationWorkerData {
70   int32_t *rst_tmpbuf;
71   void *rlbs;
72   void *lr_ctxt;
73 } LRWorkerData;
74 
75 // Looprestoration row synchronization
76 typedef struct AV1LrSyncData {
77 #if CONFIG_MULTITHREAD
78   pthread_mutex_t *mutex_[MAX_MB_PLANE];
79   pthread_cond_t *cond_[MAX_MB_PLANE];
80 #endif
81   // Allocate memory to store the loop-restoration block index in each row.
82   int *cur_sb_col[MAX_MB_PLANE];
83   // The optimal sync_range for different resolution and platform should be
84   // determined by testing. Currently, it is chosen to be a power-of-2 number.
85   int sync_range;
86   int rows;
87   int num_planes;
88 
89   int num_workers;
90 
91 #if CONFIG_MULTITHREAD
92   pthread_mutex_t *job_mutex;
93 #endif
94   // Row-based parallel loopfilter data
95   LRWorkerData *lrworkerdata;
96 
97   AV1LrMTInfo *job_queue;
98   int jobs_enqueued;
99   int jobs_dequeued;
100 } AV1LrSync;
101 
102 typedef struct AV1CdefWorker {
103   AV1_COMMON *cm;
104   MACROBLOCKD *xd;
105   uint16_t *colbuf[MAX_MB_PLANE];
106   uint16_t *srcbuf;
107   uint16_t *linebuf[MAX_MB_PLANE];
108   cdef_init_fb_row_t cdef_init_fb_row_fn;
109 } AV1CdefWorkerData;
110 
111 typedef struct AV1CdefRowSync {
112 #if CONFIG_MULTITHREAD
113   pthread_mutex_t *row_mutex_;
114   pthread_cond_t *row_cond_;
115 #endif  // CONFIG_MULTITHREAD
116   int is_row_done;
117 } AV1CdefRowSync;
118 
119 // Data related to CDEF search multi-thread synchronization.
120 typedef struct AV1CdefSyncData {
121 #if CONFIG_MULTITHREAD
122   // Mutex lock used while dispatching jobs.
123   pthread_mutex_t *mutex_;
124 #endif  // CONFIG_MULTITHREAD
125   // Data related to CDEF row mt sync information
126   AV1CdefRowSync *cdef_row_mt;
127   // Flag to indicate all blocks are processed and end of frame is reached
128   int end_of_frame;
129   // Row index in units of 64x64 block
130   int fbr;
131   // Column index in units of 64x64 block
132   int fbc;
133 } AV1CdefSync;
134 
135 void av1_cdef_frame_mt(AV1_COMMON *const cm, MACROBLOCKD *const xd,
136                        AV1CdefWorkerData *const cdef_worker,
137                        AVxWorker *const workers, AV1CdefSync *const cdef_sync,
138                        int num_workers, cdef_init_fb_row_t cdef_init_fb_row_fn);
139 void av1_cdef_init_fb_row_mt(const AV1_COMMON *const cm,
140                              const MACROBLOCKD *const xd,
141                              CdefBlockInfo *const fb_info,
142                              uint16_t **const linebuf, uint16_t *const src,
143                              struct AV1CdefSyncData *const cdef_sync, int fbr);
144 void av1_cdef_copy_sb8_16(const AV1_COMMON *const cm, uint16_t *const dst,
145                           int dstride, const uint8_t *src, int src_voffset,
146                           int src_hoffset, int sstride, int vsize, int hsize);
147 void av1_alloc_cdef_sync(AV1_COMMON *const cm, AV1CdefSync *cdef_sync,
148                          int num_workers);
149 void av1_free_cdef_sync(AV1CdefSync *cdef_sync);
150 
151 // Deallocate loopfilter synchronization related mutex and data.
152 void av1_loop_filter_dealloc(AV1LfSync *lf_sync);
153 void av1_loop_filter_alloc(AV1LfSync *lf_sync, AV1_COMMON *cm, int rows,
154                            int width, int num_workers);
155 
156 void av1_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm,
157                               struct macroblockd *xd, int plane_start,
158                               int plane_end, int partial_frame,
159                               AVxWorker *workers, int num_workers,
160                               AV1LfSync *lf_sync, int is_realtime);
161 
162 #if !CONFIG_REALTIME_ONLY
163 void av1_loop_restoration_filter_frame_mt(YV12_BUFFER_CONFIG *frame,
164                                           struct AV1Common *cm,
165                                           int optimized_lr, AVxWorker *workers,
166                                           int num_workers, AV1LrSync *lr_sync,
167                                           void *lr_ctxt);
168 void av1_loop_restoration_dealloc(AV1LrSync *lr_sync, int num_workers);
169 void av1_loop_restoration_alloc(AV1LrSync *lr_sync, AV1_COMMON *cm,
170                                 int num_workers, int num_rows_lr,
171                                 int num_planes, int width);
172 #endif
173 
174 #ifdef __cplusplus
175 }  // extern "C"
176 #endif
177 
178 #endif  // AOM_AV1_COMMON_THREAD_COMMON_H_
179