xref: /aosp_15_r20/external/libaom/av1/encoder/external_partition.c (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
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 
av1_ext_part_create(aom_ext_part_funcs_t funcs,aom_ext_part_config_t config,ExtPartController * ext_part_controller)16 aom_codec_err_t av1_ext_part_create(aom_ext_part_funcs_t funcs,
17                                     aom_ext_part_config_t config,
18                                     ExtPartController *ext_part_controller) {
19   if (ext_part_controller == NULL) {
20     return AOM_CODEC_INVALID_PARAM;
21   }
22   ext_part_controller->funcs = funcs;
23   ext_part_controller->config = config;
24   const aom_ext_part_status_t status = ext_part_controller->funcs.create_model(
25       ext_part_controller->funcs.priv, &ext_part_controller->config,
26       &ext_part_controller->model);
27   if (status == AOM_EXT_PART_ERROR) {
28     return AOM_CODEC_ERROR;
29   } else if (status == AOM_EXT_PART_TEST) {
30     ext_part_controller->test_mode = 1;
31     ext_part_controller->ready = 0;
32     return AOM_CODEC_OK;
33   }
34   assert(status == AOM_EXT_PART_OK);
35   ext_part_controller->ready = 1;
36   return AOM_CODEC_OK;
37 }
38 
ext_part_init(ExtPartController * ext_part_controller)39 static aom_codec_err_t ext_part_init(ExtPartController *ext_part_controller) {
40   if (ext_part_controller == NULL) {
41     return AOM_CODEC_INVALID_PARAM;
42   }
43   av1_zero(ext_part_controller);
44   return AOM_CODEC_OK;
45 }
46 
av1_ext_part_delete(ExtPartController * ext_part_controller)47 aom_codec_err_t av1_ext_part_delete(ExtPartController *ext_part_controller) {
48   if (ext_part_controller == NULL) {
49     return AOM_CODEC_INVALID_PARAM;
50   }
51   if (ext_part_controller->ready) {
52     const aom_ext_part_status_t status =
53         ext_part_controller->funcs.delete_model(ext_part_controller->model);
54     if (status != AOM_EXT_PART_OK) {
55       return AOM_CODEC_ERROR;
56     }
57   }
58   return ext_part_init(ext_part_controller);
59 }
60 
av1_ext_part_get_partition_decision(ExtPartController * ext_part_controller,aom_partition_decision_t * decision)61 bool av1_ext_part_get_partition_decision(ExtPartController *ext_part_controller,
62                                          aom_partition_decision_t *decision) {
63   assert(ext_part_controller != NULL);
64   assert(ext_part_controller->ready);
65   assert(decision != NULL);
66   const aom_ext_part_status_t status =
67       ext_part_controller->funcs.get_partition_decision(
68           ext_part_controller->model, decision);
69   if (status != AOM_EXT_PART_OK) return false;
70   return true;
71 }
72 
av1_ext_part_send_features(ExtPartController * ext_part_controller,const aom_partition_features_t * features)73 bool av1_ext_part_send_features(ExtPartController *ext_part_controller,
74                                 const aom_partition_features_t *features) {
75   assert(ext_part_controller != NULL);
76   assert(ext_part_controller->ready);
77   assert(features != NULL);
78   const aom_ext_part_status_t status = ext_part_controller->funcs.send_features(
79       ext_part_controller->model, features);
80   if (status != AOM_EXT_PART_OK) return false;
81   return true;
82 }
83 
84 #if CONFIG_PARTITION_SEARCH_ORDER
av1_ext_part_send_partition_stats(ExtPartController * ext_part_controller,const aom_partition_stats_t * stats)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 
av1_get_ext_part_decision_mode(const ExtPartController * ext_part_controller)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
102