xref: /aosp_15_r20/external/libaom/av1/encoder/external_partition.c (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2021, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/common.h"
13*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/external_partition.h"
14*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
15*77c1e3ccSAndroid Build Coastguard Worker 
av1_ext_part_create(aom_ext_part_funcs_t funcs,aom_ext_part_config_t config,ExtPartController * ext_part_controller)16*77c1e3ccSAndroid Build Coastguard Worker aom_codec_err_t av1_ext_part_create(aom_ext_part_funcs_t funcs,
17*77c1e3ccSAndroid Build Coastguard Worker                                     aom_ext_part_config_t config,
18*77c1e3ccSAndroid Build Coastguard Worker                                     ExtPartController *ext_part_controller) {
19*77c1e3ccSAndroid Build Coastguard Worker   if (ext_part_controller == NULL) {
20*77c1e3ccSAndroid Build Coastguard Worker     return AOM_CODEC_INVALID_PARAM;
21*77c1e3ccSAndroid Build Coastguard Worker   }
22*77c1e3ccSAndroid Build Coastguard Worker   ext_part_controller->funcs = funcs;
23*77c1e3ccSAndroid Build Coastguard Worker   ext_part_controller->config = config;
24*77c1e3ccSAndroid Build Coastguard Worker   const aom_ext_part_status_t status = ext_part_controller->funcs.create_model(
25*77c1e3ccSAndroid Build Coastguard Worker       ext_part_controller->funcs.priv, &ext_part_controller->config,
26*77c1e3ccSAndroid Build Coastguard Worker       &ext_part_controller->model);
27*77c1e3ccSAndroid Build Coastguard Worker   if (status == AOM_EXT_PART_ERROR) {
28*77c1e3ccSAndroid Build Coastguard Worker     return AOM_CODEC_ERROR;
29*77c1e3ccSAndroid Build Coastguard Worker   } else if (status == AOM_EXT_PART_TEST) {
30*77c1e3ccSAndroid Build Coastguard Worker     ext_part_controller->test_mode = 1;
31*77c1e3ccSAndroid Build Coastguard Worker     ext_part_controller->ready = 0;
32*77c1e3ccSAndroid Build Coastguard Worker     return AOM_CODEC_OK;
33*77c1e3ccSAndroid Build Coastguard Worker   }
34*77c1e3ccSAndroid Build Coastguard Worker   assert(status == AOM_EXT_PART_OK);
35*77c1e3ccSAndroid Build Coastguard Worker   ext_part_controller->ready = 1;
36*77c1e3ccSAndroid Build Coastguard Worker   return AOM_CODEC_OK;
37*77c1e3ccSAndroid Build Coastguard Worker }
38*77c1e3ccSAndroid Build Coastguard Worker 
ext_part_init(ExtPartController * ext_part_controller)39*77c1e3ccSAndroid Build Coastguard Worker static aom_codec_err_t ext_part_init(ExtPartController *ext_part_controller) {
40*77c1e3ccSAndroid Build Coastguard Worker   if (ext_part_controller == NULL) {
41*77c1e3ccSAndroid Build Coastguard Worker     return AOM_CODEC_INVALID_PARAM;
42*77c1e3ccSAndroid Build Coastguard Worker   }
43*77c1e3ccSAndroid Build Coastguard Worker   av1_zero(ext_part_controller);
44*77c1e3ccSAndroid Build Coastguard Worker   return AOM_CODEC_OK;
45*77c1e3ccSAndroid Build Coastguard Worker }
46*77c1e3ccSAndroid Build Coastguard Worker 
av1_ext_part_delete(ExtPartController * ext_part_controller)47*77c1e3ccSAndroid Build Coastguard Worker aom_codec_err_t av1_ext_part_delete(ExtPartController *ext_part_controller) {
48*77c1e3ccSAndroid Build Coastguard Worker   if (ext_part_controller == NULL) {
49*77c1e3ccSAndroid Build Coastguard Worker     return AOM_CODEC_INVALID_PARAM;
50*77c1e3ccSAndroid Build Coastguard Worker   }
51*77c1e3ccSAndroid Build Coastguard Worker   if (ext_part_controller->ready) {
52*77c1e3ccSAndroid Build Coastguard Worker     const aom_ext_part_status_t status =
53*77c1e3ccSAndroid Build Coastguard Worker         ext_part_controller->funcs.delete_model(ext_part_controller->model);
54*77c1e3ccSAndroid Build Coastguard Worker     if (status != AOM_EXT_PART_OK) {
55*77c1e3ccSAndroid Build Coastguard Worker       return AOM_CODEC_ERROR;
56*77c1e3ccSAndroid Build Coastguard Worker     }
57*77c1e3ccSAndroid Build Coastguard Worker   }
58*77c1e3ccSAndroid Build Coastguard Worker   return ext_part_init(ext_part_controller);
59*77c1e3ccSAndroid Build Coastguard Worker }
60*77c1e3ccSAndroid Build Coastguard Worker 
av1_ext_part_get_partition_decision(ExtPartController * ext_part_controller,aom_partition_decision_t * decision)61*77c1e3ccSAndroid Build Coastguard Worker bool av1_ext_part_get_partition_decision(ExtPartController *ext_part_controller,
62*77c1e3ccSAndroid Build Coastguard Worker                                          aom_partition_decision_t *decision) {
63*77c1e3ccSAndroid Build Coastguard Worker   assert(ext_part_controller != NULL);
64*77c1e3ccSAndroid Build Coastguard Worker   assert(ext_part_controller->ready);
65*77c1e3ccSAndroid Build Coastguard Worker   assert(decision != NULL);
66*77c1e3ccSAndroid Build Coastguard Worker   const aom_ext_part_status_t status =
67*77c1e3ccSAndroid Build Coastguard Worker       ext_part_controller->funcs.get_partition_decision(
68*77c1e3ccSAndroid Build Coastguard Worker           ext_part_controller->model, decision);
69*77c1e3ccSAndroid Build Coastguard Worker   if (status != AOM_EXT_PART_OK) return false;
70*77c1e3ccSAndroid Build Coastguard Worker   return true;
71*77c1e3ccSAndroid Build Coastguard Worker }
72*77c1e3ccSAndroid Build Coastguard Worker 
av1_ext_part_send_features(ExtPartController * ext_part_controller,const aom_partition_features_t * features)73*77c1e3ccSAndroid Build Coastguard Worker bool av1_ext_part_send_features(ExtPartController *ext_part_controller,
74*77c1e3ccSAndroid Build Coastguard Worker                                 const aom_partition_features_t *features) {
75*77c1e3ccSAndroid Build Coastguard Worker   assert(ext_part_controller != NULL);
76*77c1e3ccSAndroid Build Coastguard Worker   assert(ext_part_controller->ready);
77*77c1e3ccSAndroid Build Coastguard Worker   assert(features != NULL);
78*77c1e3ccSAndroid Build Coastguard Worker   const aom_ext_part_status_t status = ext_part_controller->funcs.send_features(
79*77c1e3ccSAndroid Build Coastguard Worker       ext_part_controller->model, features);
80*77c1e3ccSAndroid Build Coastguard Worker   if (status != AOM_EXT_PART_OK) return false;
81*77c1e3ccSAndroid Build Coastguard Worker   return true;
82*77c1e3ccSAndroid Build Coastguard Worker }
83*77c1e3ccSAndroid Build Coastguard Worker 
84*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_PARTITION_SEARCH_ORDER
av1_ext_part_send_partition_stats(ExtPartController * ext_part_controller,const aom_partition_stats_t * stats)85*77c1e3ccSAndroid Build Coastguard Worker bool av1_ext_part_send_partition_stats(ExtPartController *ext_part_controller,
86*77c1e3ccSAndroid Build Coastguard Worker                                        const aom_partition_stats_t *stats) {
87*77c1e3ccSAndroid Build Coastguard Worker   assert(ext_part_controller != NULL);
88*77c1e3ccSAndroid Build Coastguard Worker   assert(ext_part_controller->ready);
89*77c1e3ccSAndroid Build Coastguard Worker   assert(stats != NULL);
90*77c1e3ccSAndroid Build Coastguard Worker   const aom_ext_part_status_t status =
91*77c1e3ccSAndroid Build Coastguard Worker       ext_part_controller->funcs.send_partition_stats(
92*77c1e3ccSAndroid Build Coastguard Worker           ext_part_controller->model, stats);
93*77c1e3ccSAndroid Build Coastguard Worker   if (status != AOM_EXT_PART_OK) return false;
94*77c1e3ccSAndroid Build Coastguard Worker   return true;
95*77c1e3ccSAndroid Build Coastguard Worker }
96*77c1e3ccSAndroid Build Coastguard Worker 
av1_get_ext_part_decision_mode(const ExtPartController * ext_part_controller)97*77c1e3ccSAndroid Build Coastguard Worker aom_ext_part_decision_mode_t av1_get_ext_part_decision_mode(
98*77c1e3ccSAndroid Build Coastguard Worker     const ExtPartController *ext_part_controller) {
99*77c1e3ccSAndroid Build Coastguard Worker   return ext_part_controller->funcs.decision_mode;
100*77c1e3ccSAndroid Build Coastguard Worker }
101*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_PARTITION_SEARCH_ORDER
102