Coverage Report

Created: 2026-05-16 06:41

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_L1_LOWRES, // Use the l1 norm of the mv as the cost (<480p)
32
    MV_COST_L1_MIDRES, // Use the l1 norm of the mv as the cost (>=480p)
33
    MV_COST_L1_HDRES, // Use the l1 norm of the mv as the cost (>=720p)
34
    MV_COST_OPT,
35
    MV_COST_NONE // Use 0 as as cost irrespective of the current mv
36
} UENUM1BYTE(MV_COST_TYPE);
37
38
typedef struct svt_mv_cost_param {
39
    // The reference mv used to compute the mv cost
40
    const Mv*    ref_mv;
41
    Mv           full_ref_mv;
42
    MV_COST_TYPE mv_cost_type;
43
    const int*   mvjcost;
44
    const int*   mvcost[2];
45
    int          error_per_bit;
46
    int          early_exit_th;
47
    // A multiplier used to convert rate to sad cost
48
    int sad_per_bit;
49
} svt_mv_cost_param;
50
51
// =============================================================================
52
//  Motion Search
53
// =============================================================================
54
typedef struct svt_buf_2d {
55
    uint8_t* buf;
56
    int      width;
57
    int      height;
58
    int      stride;
59
} svt_buf_2d;
60
61
typedef struct {
62
    // The reference buffer
63
    svt_buf_2d* ref;
64
65
    // The source and predictors/mask used by translational search
66
    svt_buf_2d* src;
67
} MSBuffers;
68
69
// =============================================================================
70
//  Subpixel Motion Search
71
// =============================================================================
72
typedef struct {
73
    const AomVarianceFnPtr* vfp;
74
75
    SUBPEL_SEARCH_TYPE subpel_search_type;
76
77
    // Source and reference buffers
78
    MSBuffers ms_buffers;
79
80
    int w, h;
81
    int32_t
82
        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
83
} SUBPEL_SEARCH_VAR_PARAMS;
84
85
// This struct holds subpixel motion search parameters that should be constant
86
// during the search
87
typedef struct {
88
    // High level motion search settings
89
    int               allow_hp;
90
    SUBPEL_FORCE_STOP forced_stop;
91
    int               iters_per_step;
92
    int               pred_variance_th;
93
    uint8_t           abs_th_mult;
94
    int               round_dev_th;
95
    uint8_t           skip_diag_refinement;
96
    SUBPEL_STAGE      search_stage; //0: ME  1: PME
97
    uint8_t           list_idx;
98
    uint8_t           ref_idx;
99
    SubpelMvLimits    mv_limits;
100
    // For calculating mv cost
101
    svt_mv_cost_param mv_cost_params;
102
103
    // Distortion calculation params
104
    SUBPEL_SEARCH_VAR_PARAMS var_params;
105
} SUBPEL_MOTION_SEARCH_PARAMS;
106
107
typedef int(fractional_mv_step_fp)(void* ictx, MacroBlockD* xd, const struct AV1Common* const cm,
108
                                   SUBPEL_MOTION_SEARCH_PARAMS* ms_params, Mv start_mv, Mv* bestmv, int* distortion,
109
                                   unsigned int* sse1, int qp, BlockSize bsize, uint8_t is_intra_bordered);
110
extern fractional_mv_step_fp svt_av1_find_best_sub_pixel_tree;
111
extern fractional_mv_step_fp svt_av1_find_best_sub_pixel_tree_pruned;
112
113
int svt_aom_fp_mv_err_cost(const Mv* mv, const svt_mv_cost_param* mv_cost_params);
114
115
static INLINE void svt_av1_set_subpel_mv_search_range(SubpelMvLimits* subpel_limits, const FullMvLimits* mv_limits,
116
0
                                                      const Mv* ref_mv) {
117
0
    const int max_mv = GET_MV_SUBPEL(MAX_FULL_PEL_VAL);
118
0
    const int minc   = AOMMAX(GET_MV_SUBPEL(mv_limits->col_min), ref_mv->x - max_mv);
119
0
    const int maxc   = AOMMIN(GET_MV_SUBPEL(mv_limits->col_max), ref_mv->x + max_mv);
120
0
    const int minr   = AOMMAX(GET_MV_SUBPEL(mv_limits->row_min), ref_mv->y - max_mv);
121
0
    const int maxr   = AOMMIN(GET_MV_SUBPEL(mv_limits->row_max), ref_mv->y + max_mv);
122
123
0
    subpel_limits->col_min = AOMMAX(MV_LOW + 1, minc);
124
0
    subpel_limits->col_max = AOMMIN(MV_UPP - 1, maxc);
125
0
    subpel_limits->row_min = AOMMAX(MV_LOW + 1, minr);
126
0
    subpel_limits->row_max = AOMMIN(MV_UPP - 1, maxr);
127
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: src_ops_process.c:svt_av1_set_subpel_mv_search_range
Unexecuted instantiation: mcomp.c:svt_av1_set_subpel_mv_search_range
128
129
0
static INLINE int svt_av1_is_subpelmv_in_range(const SubpelMvLimits* mv_limits, Mv mv) {
130
0
    return (mv.x >= mv_limits->col_min) && (mv.x <= mv_limits->col_max) && (mv.y >= mv_limits->row_min) &&
131
0
        (mv.y <= mv_limits->row_max);
132
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: src_ops_process.c:svt_av1_is_subpelmv_in_range
Unexecuted instantiation: mcomp.c:svt_av1_is_subpelmv_in_range
133
134
// Returns the rate of encoding the current motion vector based on the
135
// joint_cost and comp_cost. joint_costs covers the cost of transmitting
136
// JOINT_MV, and comp_cost covers the cost of transmitting the actual motion
137
// vector.
138
0
static INLINE int svt_mv_cost(const Mv* mv, const int* joint_cost, const int* const comp_cost[2]) {
139
    // The y-component (row component) of the MV is coded first, so the cost is in the 0th idx
140
0
    return joint_cost[svt_av1_get_mv_joint(mv)] + comp_cost[0][CLIP3(MV_LOW, MV_UPP, mv->y)] +
141
0
        comp_cost[1][CLIP3(MV_LOW, MV_UPP, mv->x)];
142
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: src_ops_process.c:svt_mv_cost
Unexecuted instantiation: mcomp.c:svt_mv_cost
143
144
#ifdef __cplusplus
145
} // extern "C"
146
#endif
147
#endif // AOM_AV1_ENCODER_MCOMP_H_