Coverage Report

Created: 2025-10-10 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavif/ext/aom/av1/encoder/external_partition.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2021, 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
#include <string.h>
13
14
#include "av1/common/common.h"
15
#include "av1/encoder/external_partition.h"
16
#include "config/aom_config.h"
17
18
aom_codec_err_t av1_ext_part_create(aom_ext_part_funcs_t funcs,
19
                                    aom_ext_part_config_t config,
20
0
                                    ExtPartController *ext_part_controller) {
21
0
  if (ext_part_controller == NULL) {
22
0
    return AOM_CODEC_INVALID_PARAM;
23
0
  }
24
0
  ext_part_controller->funcs = funcs;
25
0
  ext_part_controller->config = config;
26
0
  const aom_ext_part_status_t status = ext_part_controller->funcs.create_model(
27
0
      ext_part_controller->funcs.priv, &ext_part_controller->config,
28
0
      &ext_part_controller->model);
29
0
  if (status == AOM_EXT_PART_ERROR) {
30
0
    return AOM_CODEC_ERROR;
31
0
  } else if (status == AOM_EXT_PART_TEST) {
32
0
    ext_part_controller->test_mode = 1;
33
0
    ext_part_controller->ready = 0;
34
0
    return AOM_CODEC_OK;
35
0
  }
36
0
  assert(status == AOM_EXT_PART_OK);
37
0
  ext_part_controller->ready = 1;
38
0
  return AOM_CODEC_OK;
39
0
}
40
41
75.1k
static aom_codec_err_t ext_part_init(ExtPartController *ext_part_controller) {
42
75.1k
  if (ext_part_controller == NULL) {
43
0
    return AOM_CODEC_INVALID_PARAM;
44
0
  }
45
75.1k
  memset(ext_part_controller, 0, sizeof(*ext_part_controller));
46
75.1k
  return AOM_CODEC_OK;
47
75.1k
}
48
49
75.1k
aom_codec_err_t av1_ext_part_delete(ExtPartController *ext_part_controller) {
50
75.1k
  if (ext_part_controller == NULL) {
51
0
    return AOM_CODEC_INVALID_PARAM;
52
0
  }
53
75.1k
  if (ext_part_controller->ready) {
54
0
    const aom_ext_part_status_t status =
55
0
        ext_part_controller->funcs.delete_model(ext_part_controller->model);
56
0
    if (status != AOM_EXT_PART_OK) {
57
0
      return AOM_CODEC_ERROR;
58
0
    }
59
0
  }
60
75.1k
  return ext_part_init(ext_part_controller);
61
75.1k
}
62
63
bool av1_ext_part_get_partition_decision(ExtPartController *ext_part_controller,
64
0
                                         aom_partition_decision_t *decision) {
65
0
  assert(ext_part_controller != NULL);
66
0
  assert(ext_part_controller->ready);
67
0
  assert(decision != NULL);
68
0
  const aom_ext_part_status_t status =
69
0
      ext_part_controller->funcs.get_partition_decision(
70
0
          ext_part_controller->model, decision);
71
0
  if (status != AOM_EXT_PART_OK) return false;
72
0
  return true;
73
0
}
74
75
bool av1_ext_part_send_features(ExtPartController *ext_part_controller,
76
0
                                const aom_partition_features_t *features) {
77
0
  assert(ext_part_controller != NULL);
78
0
  assert(ext_part_controller->ready);
79
0
  assert(features != NULL);
80
0
  const aom_ext_part_status_t status = ext_part_controller->funcs.send_features(
81
0
      ext_part_controller->model, features);
82
0
  if (status != AOM_EXT_PART_OK) return false;
83
0
  return true;
84
0
}
85
86
#if CONFIG_PARTITION_SEARCH_ORDER
87
bool av1_ext_part_send_partition_stats(ExtPartController *ext_part_controller,
88
                                       const aom_partition_stats_t *stats) {
89
  assert(ext_part_controller != NULL);
90
  assert(ext_part_controller->ready);
91
  assert(stats != NULL);
92
  const aom_ext_part_status_t status =
93
      ext_part_controller->funcs.send_partition_stats(
94
          ext_part_controller->model, stats);
95
  if (status != AOM_EXT_PART_OK) return false;
96
  return true;
97
}
98
99
aom_ext_part_decision_mode_t av1_get_ext_part_decision_mode(
100
    const ExtPartController *ext_part_controller) {
101
  return ext_part_controller->funcs.decision_mode;
102
}
103
#endif  // CONFIG_PARTITION_SEARCH_ORDER