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 AV1_COMMON_LOOPFILTER_THREAD_H_
13 #define AV1_COMMON_LOOPFILTER_THREAD_H_
14 #include "./aom_config.h"
15 #include "av1/common/av1_loopfilter.h"
16 #include "aom_util/aom_thread.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 struct AV1Common;
23 struct FRAME_COUNTS;
24 
25 // Loopfilter row synchronization
26 typedef struct AV1LfSyncData {
27 #if CONFIG_MULTITHREAD
28   pthread_mutex_t *mutex_;
29   pthread_cond_t *cond_;
30 #endif
31   // Allocate memory to store the loop-filtered superblock index in each row.
32   int *cur_sb_col;
33   // The optimal sync_range for different resolution and platform should be
34   // determined by testing. Currently, it is chosen to be a power-of-2 number.
35   int sync_range;
36   int rows;
37 
38   // Row-based parallel loopfilter data
39   LFWorkerData *lfdata;
40   int num_workers;
41 } AV1LfSync;
42 
43 // Allocate memory for loopfilter row synchronization.
44 void av1_loop_filter_alloc(AV1LfSync *lf_sync, struct AV1Common *cm, int rows,
45                            int width, int num_workers);
46 
47 // Deallocate loopfilter synchronization related mutex and data.
48 void av1_loop_filter_dealloc(AV1LfSync *lf_sync);
49 
50 // Multi-threaded loopfilter that uses the tile threads.
51 void av1_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm,
52                               struct macroblockd_plane *planes,
53                               int frame_filter_level,
54 #if CONFIG_LOOPFILTER_LEVEL
55                               int frame_filter_level_r,
56 #endif
57                               int y_only, int partial_frame, AVxWorker *workers,
58                               int num_workers, AV1LfSync *lf_sync);
59 
60 void av1_accumulate_frame_counts(struct FRAME_COUNTS *acc_counts,
61                                  struct FRAME_COUNTS *counts);
62 
63 #ifdef __cplusplus
64 }  // extern "C"
65 #endif
66 
67 #endif  // AV1_COMMON_LOOPFILTER_THREAD_H_
68