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