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