blob: 55108b6cdb51181c2323cb55d3e39636cbff1361 [file] [log] [blame]
chiyotsaic666b1f2019-12-20 10:44:58 -08001/*
2 * Copyright (c) 2019, 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_MV_PREC_H_
13#define AOM_AV1_ENCODER_MV_PREC_H_
14
15#include "av1/encoder/encoder.h"
16#include "av1/encoder/speed_features.h"
17
18// Q threshold for high precision mv.
19#define HIGH_PRECISION_MV_QTHRESH 128
chiyotsai51bd6482019-12-20 10:49:34 -080020#if !CONFIG_REALTIME_ONLY
21void av1_collect_mv_stats(AV1_COMP *cpi, int current_q);
22
23static AOM_INLINE int av1_frame_allows_smart_mv(const AV1_COMP *cpi) {
Mufaddal Chakeraab20d372021-03-17 12:18:34 +053024 const int gf_group_index = cpi->gf_frame_index;
Mufaddal Chakera8ee04fa2021-03-17 13:33:18 +053025 const int gf_update_type = cpi->ppi->gf_group.update_type[gf_group_index];
chiyotsai51bd6482019-12-20 10:49:34 -080026 return !frame_is_intra_only(&cpi->common) &&
27 !(gf_update_type == INTNL_OVERLAY_UPDATE ||
28 gf_update_type == OVERLAY_UPDATE);
29}
30#endif // !CONFIG_REALTIME_ONLY
chiyotsaic666b1f2019-12-20 10:44:58 -080031
32static AOM_INLINE void av1_set_high_precision_mv(
33 AV1_COMP *cpi, int allow_high_precision_mv,
34 int cur_frame_force_integer_mv) {
Fyodor Kyslov648c6502021-02-02 18:41:10 -080035 MvCosts *const mv_costs = cpi->td.mb.mv_costs;
Jayasanker Jc1443052021-07-21 13:18:08 +053036 // Avoid accessing 'mv_costs' when it is not allocated.
37 if (mv_costs == NULL) return;
38
Urvang Joshib6409e92020-03-23 11:23:27 -070039 const int copy_hp = cpi->common.features.allow_high_precision_mv =
chiyotsai8b7cef82020-01-21 16:52:54 -080040 allow_high_precision_mv && !cur_frame_force_integer_mv;
chiyotsaic95e3642020-04-10 13:17:06 -070041
chiyotsai9a06d182020-05-01 17:12:12 -070042 mv_costs->nmv_cost[0] = &mv_costs->nmv_cost_alloc[0][MV_MAX];
43 mv_costs->nmv_cost[1] = &mv_costs->nmv_cost_alloc[1][MV_MAX];
44 mv_costs->nmv_cost_hp[0] = &mv_costs->nmv_cost_hp_alloc[0][MV_MAX];
45 mv_costs->nmv_cost_hp[1] = &mv_costs->nmv_cost_hp_alloc[1][MV_MAX];
46 mv_costs->mv_cost_stack =
47 copy_hp ? mv_costs->nmv_cost_hp : mv_costs->nmv_cost;
chiyotsaic666b1f2019-12-20 10:44:58 -080048}
49
50void av1_pick_and_set_high_precision_mv(AV1_COMP *cpi, int qindex);
51
52#endif // AOM_AV1_ENCODER_MV_PREC_H_