Coverage Report

Created: 2026-08-31 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/svt-av1/Source/Lib/Codec/mcomp.h
Line
Count
Source
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_ENCODER_MCOMP_H_
13
#define AOM_AV1_ENCODER_MCOMP_H_
14
15
#include "mv.h"
16
#include "coding_unit.h"
17
#include "block_structures.h"
18
#include "av1_common.h"
19
#include "av1me.h"
20
#include "rd_cost.h"
21
22
#ifdef __cplusplus
23
extern "C" {
24
#endif
25
// =============================================================================
26
//  Cost functions
27
// =============================================================================
28
29
enum {
30
    MV_COST_ENTROPY, // Use the entropy rate of the mv as the cost
31
    MV_COST_OPT,
32
    MV_COST_NONE // Use 0 as as cost irrespective of the current mv
33
} UENUM1BYTE(MV_COST_TYPE);
34
35
typedef struct svt_mv_cost_param {
36
    // The reference mv used to compute the mv cost
37
    Mv           ref_mv;
38
    Mv           full_ref_mv;
39
    MV_COST_TYPE mv_cost_type;
40
    const int*   mvjcost;
41
    const int*   mvcost[2];
42
    int          error_per_bit;
43
    int          early_exit_th;
44
    // A multiplier used to convert rate to sad cost
45
    int sad_per_bit;
46
} svt_mv_cost_param;
47
48
// =============================================================================
49
//  Motion Search
50
// =============================================================================
51
typedef struct svt_buf_2d {
52
    uint8_t* buf;
53
    int      width;
54
    int      height;
55
    int      stride;
56
} svt_buf_2d;
57
58
typedef struct {
59
    // The reference buffer
60
    svt_buf_2d* ref;
61
62
    // The source and predictors/mask used by translational search
63
    svt_buf_2d* src;
64
} MSBuffers;
65
66
// =============================================================================
67
//  Subpixel Motion Search
68
// =============================================================================
69
typedef struct {
70
    const AomVarianceFnPtr* vfp;
71
72
    SUBPEL_SEARCH_TYPE subpel_search_type;
73
74
    // Source and reference buffers
75
    MSBuffers ms_buffers;
76
77
    int w, h;
78
    int32_t
79
        bias_fp; // Bias towards fpel at the MD subpel-search: apply a penalty to the cost of fractional positions during the subpel-search each time we check against a full-pel MV
80
} SUBPEL_SEARCH_VAR_PARAMS;
81
82
// This struct holds subpixel motion search parameters that should be constant
83
// during the search
84
typedef struct {
85
    // High level motion search settings
86
    int               allow_hp;
87
    SUBPEL_FORCE_STOP forced_stop;
88
    int               iters_per_step;
89
    int               pred_variance_th;
90
    uint8_t           abs_th_mult;
91
    int               round_dev_th;
92
    uint8_t           skip_diag_refinement;
93
    SUBPEL_STAGE      search_stage; //0: ME  1: PME
94
    uint8_t           list_idx;
95
    uint8_t           ref_idx;
96
    SubpelMvLimits    mv_limits;
97
    // For calculating mv cost
98
    svt_mv_cost_param mv_cost_params;
99
100
    // Distortion calculation params
101
    SUBPEL_SEARCH_VAR_PARAMS var_params;
102
} SUBPEL_MOTION_SEARCH_PARAMS;
103
104
typedef int(fractional_mv_step_fp)(void* ictx, MacroBlockD* xd, const struct AV1Common* const cm,
105
                                   SUBPEL_MOTION_SEARCH_PARAMS* ms_params, Mv start_mv, Mv* bestmv, BlockSize bsize);
106
extern fractional_mv_step_fp svt_av1_find_best_sub_pixel_tree;
107
extern fractional_mv_step_fp svt_av1_find_best_sub_pixel_tree_pruned;
108
109
static INLINE void svt_av1_set_subpel_mv_search_range(SubpelMvLimits* subpel_limits, const FullMvLimits* mv_limits,
110
0
                                                      const Mv ref_mv) {
111
0
    const int max_mv = GET_MV_SUBPEL(MAX_FULL_PEL_VAL);
112
0
    const int minc   = AOMMAX(GET_MV_SUBPEL(mv_limits->col_min), ref_mv.x - max_mv);
113
0
    const int maxc   = AOMMIN(GET_MV_SUBPEL(mv_limits->col_max), ref_mv.x + max_mv);
114
0
    const int minr   = AOMMAX(GET_MV_SUBPEL(mv_limits->row_min), ref_mv.y - max_mv);
115
0
    const int maxr   = AOMMIN(GET_MV_SUBPEL(mv_limits->row_max), ref_mv.y + max_mv);
116
117
0
    subpel_limits->col_min = AOMMAX(MV_LOW + 1, minc);
118
0
    subpel_limits->col_max = AOMMIN(MV_UPP - 1, maxc);
119
0
    subpel_limits->row_min = AOMMAX(MV_LOW + 1, minr);
120
0
    subpel_limits->row_max = AOMMIN(MV_UPP - 1, maxr);
121
0
}
Unexecuted instantiation: av1me.c:svt_av1_set_subpel_mv_search_range
Unexecuted instantiation: mode_decision.c:svt_av1_set_subpel_mv_search_range
Unexecuted instantiation: product_coding_loop.c:svt_av1_set_subpel_mv_search_range
Unexecuted instantiation: rd_cost.c:svt_av1_set_subpel_mv_search_range
Unexecuted instantiation: src_ops_process.c:svt_av1_set_subpel_mv_search_range
Unexecuted instantiation: mcomp.c:svt_av1_set_subpel_mv_search_range
122
123
0
static INLINE int svt_av1_is_subpelmv_in_range(const SubpelMvLimits* mv_limits, Mv mv) {
124
0
    return (mv.x >= mv_limits->col_min) && (mv.x <= mv_limits->col_max) && (mv.y >= mv_limits->row_min) &&
125
0
        (mv.y <= mv_limits->row_max);
126
0
}
Unexecuted instantiation: av1me.c:svt_av1_is_subpelmv_in_range
Unexecuted instantiation: mode_decision.c:svt_av1_is_subpelmv_in_range
Unexecuted instantiation: product_coding_loop.c:svt_av1_is_subpelmv_in_range
Unexecuted instantiation: rd_cost.c:svt_av1_is_subpelmv_in_range
Unexecuted instantiation: src_ops_process.c:svt_av1_is_subpelmv_in_range
Unexecuted instantiation: mcomp.c:svt_av1_is_subpelmv_in_range
127
128
// Returns the rate of encoding the current motion vector based on the
129
// joint_cost and comp_cost. joint_costs covers the cost of transmitting
130
// JOINT_MV, and comp_cost covers the cost of transmitting the actual motion
131
// vector.
132
0
static INLINE int svt_mv_cost(const Mv mv, const int* joint_cost, const int* const comp_cost[2]) {
133
    // The y-component (row component) of the MV is coded first, so the cost is in the 0th idx
134
0
    return joint_cost[svt_av1_get_mv_joint(mv)] + comp_cost[0][CLIP3(MV_LOW, MV_UPP, mv.y)] +
135
0
        comp_cost[1][CLIP3(MV_LOW, MV_UPP, mv.x)];
136
0
}
Unexecuted instantiation: av1me.c:svt_mv_cost
Unexecuted instantiation: mode_decision.c:svt_mv_cost
Unexecuted instantiation: product_coding_loop.c:svt_mv_cost
Unexecuted instantiation: rd_cost.c:svt_mv_cost
Unexecuted instantiation: src_ops_process.c:svt_mv_cost
Unexecuted instantiation: mcomp.c:svt_mv_cost
137
138
#define PIXEL_TRANSFORM_ERROR_SCALE 4
139
140
// Returns the cost of using the current mv during the motion search. This is
141
// used when var is used as the error metric.
142
static INLINE int svt_mv_err_cost(Mv mv, Mv ref_mv, const int* mvjcost, const int* const mvcost[2], int error_per_bit,
143
0
                                  MV_COST_TYPE mv_cost_type) {
144
0
    const Mv diff     = {{(int16_t)(mv.x - ref_mv.x), (int16_t)(mv.y - ref_mv.y)}};
145
0
    const Mv abs_diff = {{(int16_t)abs(diff.x), (int16_t)abs(diff.y)}};
146
147
0
    switch (mv_cost_type) {
148
0
    case MV_COST_ENTROPY:
149
0
        assert(mvcost);
150
0
        return (int)ROUND_POWER_OF_TWO_64(
151
0
            (int64_t)svt_mv_cost(diff, mvjcost, mvcost) * error_per_bit,
152
0
            RDDIV_BITS + AV1_PROB_COST_SHIFT - RD_EPB_SHIFT + PIXEL_TRANSFORM_ERROR_SCALE);
153
0
    case MV_COST_OPT: {
154
0
        return (int)ROUND_POWER_OF_TWO_64(
155
0
            (int64_t)((abs_diff.y + abs_diff.x) << 8) * error_per_bit,
156
0
            RDDIV_BITS + AV1_PROB_COST_SHIFT - RD_EPB_SHIFT + PIXEL_TRANSFORM_ERROR_SCALE);
157
0
    }
158
0
    case MV_COST_NONE:
159
0
        return 0;
160
0
    default:
161
0
        assert(0 && "Invalid rd_cost_type");
162
0
        return 0;
163
0
    }
164
0
}
Unexecuted instantiation: av1me.c:svt_mv_err_cost
Unexecuted instantiation: mode_decision.c:svt_mv_err_cost
Unexecuted instantiation: product_coding_loop.c:svt_mv_err_cost
Unexecuted instantiation: rd_cost.c:svt_mv_err_cost
Unexecuted instantiation: src_ops_process.c:svt_mv_err_cost
Unexecuted instantiation: mcomp.c:svt_mv_err_cost
165
166
0
static INLINE int svt_aom_fp_mv_err_cost(Mv mv, const svt_mv_cost_param* mv_cost_params) {
167
0
    return svt_mv_err_cost(mv,
168
0
                           mv_cost_params->ref_mv,
169
0
                           mv_cost_params->mvjcost,
170
0
                           mv_cost_params->mvcost,
171
0
                           mv_cost_params->error_per_bit,
172
0
                           mv_cost_params->mv_cost_type);
173
0
}
Unexecuted instantiation: av1me.c:svt_aom_fp_mv_err_cost
Unexecuted instantiation: mode_decision.c:svt_aom_fp_mv_err_cost
Unexecuted instantiation: product_coding_loop.c:svt_aom_fp_mv_err_cost
Unexecuted instantiation: rd_cost.c:svt_aom_fp_mv_err_cost
Unexecuted instantiation: src_ops_process.c:svt_aom_fp_mv_err_cost
Unexecuted instantiation: mcomp.c:svt_aom_fp_mv_err_cost
174
175
#ifdef __cplusplus
176
} // extern "C"
177
#endif
178
#endif // AOM_AV1_ENCODER_MCOMP_H_