Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2020, VideoLAN and dav1d authors |
3 | | * Copyright © 2020, Two Orioles, LLC |
4 | | * All rights reserved. |
5 | | * |
6 | | * Redistribution and use in source and binary forms, with or without |
7 | | * modification, are permitted provided that the following conditions are met: |
8 | | * |
9 | | * 1. Redistributions of source code must retain the above copyright notice, this |
10 | | * list of conditions and the following disclaimer. |
11 | | * |
12 | | * 2. Redistributions in binary form must reproduce the above copyright notice, |
13 | | * this list of conditions and the following disclaimer in the documentation |
14 | | * and/or other materials provided with the distribution. |
15 | | * |
16 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
20 | | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | | */ |
27 | | |
28 | | #ifndef DAV1D_SRC_REF_MVS_H |
29 | | #define DAV1D_SRC_REF_MVS_H |
30 | | |
31 | | #include <stdint.h> |
32 | | |
33 | | #include "dav1d/headers.h" |
34 | | |
35 | | #include "common/intops.h" |
36 | | |
37 | | #include "src/intra_edge.h" |
38 | | #include "src/tables.h" |
39 | | |
40 | 0 | #define INVALID_MV 0x80008000 |
41 | 0 | #define INVALID_REF2CUR (-32) |
42 | | |
43 | | PACKED(typedef struct refmvs_temporal_block { |
44 | | mv mv; |
45 | | uint8_t ref; |
46 | | }) refmvs_temporal_block; |
47 | | CHECK_SIZE(refmvs_temporal_block, 5); |
48 | | |
49 | | PACKED(typedef union refmvs_refpair { |
50 | | int8_t ref[2]; // [0] = 0: intra=1, [1] = -1: comp=0 |
51 | | uint16_t pair; |
52 | | }) ALIGN(refmvs_refpair, 2); |
53 | | CHECK_SIZE(refmvs_refpair, 2); |
54 | | |
55 | | typedef union refmvs_mvpair { |
56 | | mv mv[2]; |
57 | | uint64_t n; |
58 | | } refmvs_mvpair; |
59 | | CHECK_SIZE(refmvs_mvpair, 8); |
60 | | |
61 | | PACKED(typedef struct refmvs_block { |
62 | | refmvs_mvpair mv; |
63 | | refmvs_refpair ref; |
64 | | uint8_t bs, mf; // 1 = globalmv+affine, 2 = newmv |
65 | | }) ALIGN(refmvs_block, 4); |
66 | | CHECK_SIZE(refmvs_block, 12); |
67 | | |
68 | | typedef struct refmvs_frame { |
69 | | const Dav1dFrameHeader *frm_hdr; |
70 | | int iw4, ih4, iw8, ih8; |
71 | | int sbsz; |
72 | | int use_ref_frame_mvs; |
73 | | uint8_t sign_bias[7], mfmv_sign[7]; |
74 | | int8_t pocdiff[7]; |
75 | | uint8_t mfmv_ref[3]; |
76 | | int8_t mfmv_ref2cur[3]; |
77 | | uint8_t mfmv_ref2ref[3][7]; |
78 | | int n_mfmvs; |
79 | | |
80 | | int n_blocks; |
81 | | refmvs_temporal_block *rp; |
82 | | /*const*/ refmvs_temporal_block *const *rp_ref; |
83 | | refmvs_temporal_block *rp_proj; |
84 | | ptrdiff_t rp_stride; |
85 | | |
86 | | refmvs_block *r; // 35 x r_stride memory |
87 | | int n_tile_threads, n_frame_threads; |
88 | | } refmvs_frame; |
89 | | |
90 | | typedef struct refmvs_tile { |
91 | | const refmvs_frame *rf; |
92 | | refmvs_block *r[32 + 5]; |
93 | | refmvs_temporal_block *rp_proj; |
94 | | struct { |
95 | | int start, end; |
96 | | } tile_col, tile_row; |
97 | | } refmvs_tile; |
98 | | |
99 | | typedef struct refmvs_candidate { |
100 | | refmvs_mvpair mv; |
101 | | int weight; |
102 | | } refmvs_candidate; |
103 | | |
104 | | // initialize temporal MVs; this can be done in any configuration, e.g. one |
105 | | // tile/sbrow at a time, where col_{start,end}8 are the tile boundaries; or |
106 | | // it can just be for the whole frame's sbrow, where col_{start,end}8 are the |
107 | | // frame boundaries. row_{start,end}8 are the superblock row boundaries. |
108 | | #define decl_load_tmvs_fn(name) \ |
109 | | void (name)(const refmvs_frame *rf, int tile_row_idx, \ |
110 | | int col_start8, int col_end8, int row_start8, int row_end8) |
111 | | typedef decl_load_tmvs_fn(*load_tmvs_fn); |
112 | | |
113 | | #define decl_save_tmvs_fn(name) \ |
114 | | void (name)(refmvs_temporal_block *rp, const ptrdiff_t stride, \ |
115 | | refmvs_block *const *const rr, const uint8_t *const ref_sign, \ |
116 | | int col_end8, int row_end8, int col_start8, int row_start8) |
117 | | typedef decl_save_tmvs_fn(*save_tmvs_fn); |
118 | | |
119 | | #define decl_splat_mv_fn(name) \ |
120 | | void (name)(refmvs_block **rr, const refmvs_block *rmv, int bx4, int bw4, int bh4) |
121 | | typedef decl_splat_mv_fn(*splat_mv_fn); |
122 | | |
123 | | typedef struct Dav1dRefmvsDSPContext { |
124 | | load_tmvs_fn load_tmvs; |
125 | | save_tmvs_fn save_tmvs; |
126 | | splat_mv_fn splat_mv; |
127 | | } Dav1dRefmvsDSPContext; |
128 | | |
129 | | // call once per frame |
130 | | int dav1d_refmvs_init_frame(refmvs_frame *rf, |
131 | | const Dav1dSequenceHeader *seq_hdr, |
132 | | const Dav1dFrameHeader *frm_hdr, |
133 | | const uint8_t ref_poc[7], |
134 | | refmvs_temporal_block *rp, |
135 | | const uint8_t ref_ref_poc[7][7], |
136 | | /*const*/ refmvs_temporal_block *const rp_ref[7], |
137 | | int n_tile_threads, int n_frame_threads); |
138 | | |
139 | | // cache the current tile/sbrow (or frame/sbrow)'s projectable motion vectors |
140 | | // into buffers for use in future frame's temporal MV prediction |
141 | | static inline void dav1d_refmvs_save_tmvs(const Dav1dRefmvsDSPContext *const dsp, |
142 | | const refmvs_tile *const rt, |
143 | | const int col_start8, int col_end8, |
144 | | const int row_start8, int row_end8) |
145 | 0 | { |
146 | 0 | const refmvs_frame *const rf = rt->rf; |
147 | |
|
148 | 0 | assert(row_start8 >= 0); |
149 | 0 | assert((unsigned) (row_end8 - row_start8) <= 16U); |
150 | 0 | row_end8 = imin(row_end8, rf->ih8); |
151 | 0 | col_end8 = imin(col_end8, rf->iw8); |
152 | |
|
153 | 0 | const ptrdiff_t stride = rf->rp_stride; |
154 | 0 | const uint8_t *const ref_sign = rf->mfmv_sign; |
155 | 0 | refmvs_temporal_block *rp = &rf->rp[row_start8 * stride]; |
156 | |
|
157 | 0 | dsp->save_tmvs(rp, stride, rt->r + 6, ref_sign, |
158 | 0 | col_end8, row_end8, col_start8, row_start8); |
159 | 0 | } Unexecuted instantiation: lib.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: log.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: mem.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: obu.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: picture.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: refmvs.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: thread_task.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: cdf.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: decode.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: recon_tmpl.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: cdef_apply_tmpl.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: ipred_prepare_tmpl.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: lf_apply_tmpl.c:dav1d_refmvs_save_tmvs Unexecuted instantiation: lr_apply_tmpl.c:dav1d_refmvs_save_tmvs |
160 | | |
161 | | // initialize tile boundaries and refmvs_block pointers for one tile/sbrow |
162 | | void dav1d_refmvs_tile_sbrow_init(refmvs_tile *rt, const refmvs_frame *rf, |
163 | | int tile_col_start4, int tile_col_end4, |
164 | | int tile_row_start4, int tile_row_end4, |
165 | | int sby, int tile_row_idx, int pass); |
166 | | |
167 | | // call for each block |
168 | | void dav1d_refmvs_find(const refmvs_tile *rt, |
169 | | refmvs_candidate mvstack[8], int *cnt, |
170 | | int *ctx, const refmvs_refpair ref, enum BlockSize bs, |
171 | | enum EdgeFlags edge_flags, int by4, int bx4); |
172 | | |
173 | | void dav1d_refmvs_dsp_init(Dav1dRefmvsDSPContext *dsp); |
174 | | void dav1d_refmvs_dsp_init_arm(Dav1dRefmvsDSPContext *dsp); |
175 | | void dav1d_refmvs_dsp_init_loongarch(Dav1dRefmvsDSPContext *dsp); |
176 | | void dav1d_refmvs_dsp_init_x86(Dav1dRefmvsDSPContext *dsp); |
177 | | |
178 | | #endif /* DAV1D_SRC_REF_MVS_H */ |