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