Coverage Report

Created: 2025-06-22 08:04

/src/aom/av1/encoder/motion_search_facade.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2020, 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_MOTION_SEARCH_H_
13
#define AOM_AV1_ENCODER_MOTION_SEARCH_H_
14
15
#include "av1/encoder/encoder.h"
16
17
#ifdef __cplusplus
18
extern "C" {
19
#endif
20
21
0
#define NUM_JOINT_ME_REFINE_ITER 2
22
0
#define REDUCED_JOINT_ME_REFINE_ITER 1
23
// TODO(any): rename this struct to something else. There is already another
24
// struct called inter_modes_info, which makes this terribly confusing.
25
typedef struct {
26
  int drl_cost;
27
  int_mv full_search_mv;
28
  int full_mv_rate;
29
  int full_mv_bestsme;
30
  int skip;
31
} inter_mode_info;
32
33
struct HandleInterModeArgs;
34
void av1_single_motion_search(const AV1_COMP *const cpi, MACROBLOCK *x,
35
                              BLOCK_SIZE bsize, int ref_idx, int *rate_mv,
36
                              int search_range, inter_mode_info *mode_info,
37
                              int_mv *best_mv,
38
                              struct HandleInterModeArgs *const args);
39
40
int av1_joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
41
                            BLOCK_SIZE bsize, int_mv *cur_mv,
42
                            const uint8_t *mask, int mask_stride, int *rate_mv,
43
                            int allow_second_mv, int joint_me_num_refine_iter);
44
45
int av1_interinter_compound_motion_search(const AV1_COMP *const cpi,
46
                                          MACROBLOCK *x,
47
                                          const int_mv *const cur_mv,
48
                                          const BLOCK_SIZE bsize,
49
                                          const PREDICTION_MODE this_mode);
50
51
int av1_compound_single_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
52
                                      BLOCK_SIZE bsize, MV *this_mv,
53
                                      const uint8_t *second_pred,
54
                                      const uint8_t *mask, int mask_stride,
55
                                      int *rate_mv, int ref_idx);
56
57
// Performs a motion search in SIMPLE_TRANSLATION mode using reference frame
58
// ref and calculates the sse and var of the residue. Note that this sets the
59
// offset of mbmi, so we will need to reset it after calling this function.
60
int_mv av1_simple_motion_search_sse_var(struct AV1_COMP *cpi, MACROBLOCK *x,
61
                                        int mi_row, int mi_col,
62
                                        BLOCK_SIZE bsize, int ref,
63
                                        const FULLPEL_MV start_mv,
64
                                        int num_planes, int use_subpixel,
65
                                        unsigned int *sse, unsigned int *var);
66
67
static inline const search_site_config *av1_get_search_site_config(
68
0
    const AV1_COMP *cpi, MACROBLOCK *x, SEARCH_METHODS search_method) {
69
0
  const int ref_stride = x->e_mbd.plane[0].pre[0].stride;
70
71
  // AV1_COMP::mv_search_params.search_site_config is a compressor level cache
72
  // that's shared by multiple threads. In most cases where all frames have the
73
  // same resolution, the cache contains the search site config that we need.
74
0
  const MotionVectorSearchParams *mv_search_params = &cpi->mv_search_params;
75
0
  if (ref_stride == mv_search_params->search_site_cfg[SS_CFG_SRC]->stride) {
76
0
    return mv_search_params->search_site_cfg[SS_CFG_SRC];
77
0
  } else if (ref_stride ==
78
0
             mv_search_params->search_site_cfg[SS_CFG_LOOKAHEAD]->stride) {
79
0
    return mv_search_params->search_site_cfg[SS_CFG_LOOKAHEAD];
80
0
  }
81
82
  // If the cache does not contain the correct stride, then we will need to rely
83
  // on the thread level config MACROBLOCK::search_site_cfg_buf. If even the
84
  // thread level config doesn't match, then we need to update it.
85
0
  search_method = search_method_lookup[search_method];
86
0
  assert(search_method_lookup[search_method] == search_method &&
87
0
         "The search_method_lookup table should be idempotent.");
88
0
  if (ref_stride != x->search_site_cfg_buf[search_method].stride) {
89
0
    av1_refresh_search_site_config(x->search_site_cfg_buf, search_method,
90
0
                                   ref_stride);
91
0
  }
92
93
0
  return x->search_site_cfg_buf;
94
0
}
Unexecuted instantiation: encodeframe.c:av1_get_search_site_config
Unexecuted instantiation: partition_search.c:av1_get_search_site_config
Unexecuted instantiation: partition_strategy.c:av1_get_search_site_config
Unexecuted instantiation: rdopt.c:av1_get_search_site_config
Unexecuted instantiation: nonrd_pickmode.c:av1_get_search_site_config
Unexecuted instantiation: temporal_filter.c:av1_get_search_site_config
Unexecuted instantiation: tpl_model.c:av1_get_search_site_config
Unexecuted instantiation: compound_type.c:av1_get_search_site_config
Unexecuted instantiation: motion_search_facade.c:av1_get_search_site_config
95
96
static inline SEARCH_METHODS av1_get_faster_search_method(
97
0
    SEARCH_METHODS search_method) {
98
  // Note on search method's accuracy:
99
  //  1. NSTEP
100
  //  2. DIAMOND
101
  //  3. BIGDIA \approx SQUARE
102
  //  4. HEX.
103
  //  5. FAST_HEX \approx FAST_DIAMOND
104
0
  switch (search_method) {
105
0
    case NSTEP: return DIAMOND;
106
0
    case NSTEP_8PT: return DIAMOND;
107
0
    case DIAMOND: return BIGDIA;
108
0
    case CLAMPED_DIAMOND: return BIGDIA;
109
0
    case BIGDIA: return HEX;
110
0
    case SQUARE: return HEX;
111
0
    case HEX: return FAST_HEX;
112
0
    case FAST_HEX: return FAST_HEX;
113
0
    case FAST_DIAMOND: return VFAST_DIAMOND;
114
0
    case FAST_BIGDIA: return FAST_BIGDIA;
115
0
    case VFAST_DIAMOND: return VFAST_DIAMOND;
116
0
    default: assert(0 && "Invalid search method!"); return DIAMOND;
117
0
  }
118
0
}
Unexecuted instantiation: encodeframe.c:av1_get_faster_search_method
Unexecuted instantiation: partition_search.c:av1_get_faster_search_method
Unexecuted instantiation: partition_strategy.c:av1_get_faster_search_method
Unexecuted instantiation: rdopt.c:av1_get_faster_search_method
Unexecuted instantiation: nonrd_pickmode.c:av1_get_faster_search_method
Unexecuted instantiation: temporal_filter.c:av1_get_faster_search_method
Unexecuted instantiation: tpl_model.c:av1_get_faster_search_method
Unexecuted instantiation: compound_type.c:av1_get_faster_search_method
Unexecuted instantiation: motion_search_facade.c:av1_get_faster_search_method
119
120
static inline SEARCH_METHODS av1_get_default_mv_search_method(
121
0
    const MACROBLOCK *x, const MV_SPEED_FEATURES *mv_sf, BLOCK_SIZE bsize) {
122
0
  SEARCH_METHODS search_method = mv_sf->search_method;
123
0
  const int sf_blk_search_method = mv_sf->use_bsize_dependent_search_method;
124
0
  const int min_dim = AOMMIN(block_size_wide[bsize], block_size_high[bsize]);
125
0
  const int qband = x->qindex >> (QINDEX_BITS - 2);
126
0
  const bool use_faster_search_method =
127
0
      (sf_blk_search_method == 1 && min_dim >= 32) ||
128
0
      (sf_blk_search_method >= 2 && min_dim >= 16 &&
129
0
       x->content_state_sb.source_sad_nonrd <= kMedSad && qband < 3);
130
131
0
  if (use_faster_search_method) {
132
0
    search_method = av1_get_faster_search_method(search_method);
133
0
  }
134
0
  return search_method;
135
0
}
Unexecuted instantiation: encodeframe.c:av1_get_default_mv_search_method
Unexecuted instantiation: partition_search.c:av1_get_default_mv_search_method
Unexecuted instantiation: partition_strategy.c:av1_get_default_mv_search_method
Unexecuted instantiation: rdopt.c:av1_get_default_mv_search_method
Unexecuted instantiation: nonrd_pickmode.c:av1_get_default_mv_search_method
Unexecuted instantiation: temporal_filter.c:av1_get_default_mv_search_method
Unexecuted instantiation: tpl_model.c:av1_get_default_mv_search_method
Unexecuted instantiation: compound_type.c:av1_get_default_mv_search_method
Unexecuted instantiation: motion_search_facade.c:av1_get_default_mv_search_method
136
137
#ifdef __cplusplus
138
}  // extern "C"
139
#endif
140
141
#endif  // AOM_AV1_ENCODER_MOTION_SEARCH_H_