blob: 16d5c6c18a3cc1acd3df4148d43ded6e44a734a3 [file] [log] [blame]
Tom Finegan249366b2013-11-25 12:05:19 -08001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Tom Finegan249366b2013-11-25 12:05:19 -08003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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.
Tom Finegan249366b2013-11-25 12:05:19 -080010 */
11
12#include "./warnings.h"
13
14#include <assert.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18
Yaowu Xuf883b422016-08-30 14:01:10 -070019#include "aom/aom_encoder.h"
Tom Finegan249366b2013-11-25 12:05:19 -080020
21#include "./tools_common.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070022#include "./aomenc.h"
Tom Finegan249366b2013-11-25 12:05:19 -080023
24static const char quantizer_warning_string[] =
25 "Bad quantizer values. Quantizer values should not be equal, and should "
26 "differ by at least 8.";
Tom Finegan249366b2013-11-25 12:05:19 -080027
28struct WarningListNode {
29 const char *warning_string;
30 struct WarningListNode *next_warning;
31};
32
33struct WarningList {
34 struct WarningListNode *warning_node;
35};
36
37static void add_warning(const char *warning_string,
38 struct WarningList *warning_list) {
39 struct WarningListNode **node = &warning_list->warning_node;
40
41 struct WarningListNode *new_node = malloc(sizeof(*new_node));
42 if (new_node == NULL) {
43 fatal("Unable to allocate warning node.");
44 }
45
46 new_node->warning_string = warning_string;
47 new_node->next_warning = NULL;
48
clang-format6c4d83e2016-08-08 19:03:30 -070049 while (*node != NULL) node = &(*node)->next_warning;
Tom Finegan249366b2013-11-25 12:05:19 -080050
51 *node = new_node;
52}
53
54static void free_warning_list(struct WarningList *warning_list) {
Tom Finegan249366b2013-11-25 12:05:19 -080055 while (warning_list->warning_node != NULL) {
James Zernc04c3132014-02-08 13:10:27 -080056 struct WarningListNode *const node = warning_list->warning_node;
57 warning_list->warning_node = node->next_warning;
58 free(node);
Tom Finegan249366b2013-11-25 12:05:19 -080059 }
60}
61
62static int continue_prompt(int num_warnings) {
63 int c;
64 fprintf(stderr,
65 "%d encoder configuration warning(s). Continue? (y to continue) ",
66 num_warnings);
67 c = getchar();
68 return c == 'y';
69}
70
Tom Finegan249366b2013-11-25 12:05:19 -080071static void check_quantizer(int min_q, int max_q,
72 struct WarningList *warning_list) {
Yaowu Xu23417472013-12-05 13:52:47 -080073 const int lossless = min_q == 0 && max_q == 0;
74 if (!lossless && (min_q == max_q || abs(max_q - min_q) < 8))
Tom Finegan249366b2013-11-25 12:05:19 -080075 add_warning(quantizer_warning_string, warning_list);
76}
77
78void check_encoder_config(int disable_prompt,
Yaowu Xuf883b422016-08-30 14:01:10 -070079 const struct AvxEncoderConfig *global_config,
80 const struct aom_codec_enc_cfg *stream_config) {
Tom Finegan249366b2013-11-25 12:05:19 -080081 int num_warnings = 0;
82 struct WarningListNode *warning = NULL;
clang-format6c4d83e2016-08-08 19:03:30 -070083 struct WarningList warning_list = { 0 };
Thomas Daede80826142017-03-20 15:44:24 -070084 (void)global_config;
Tom Finegan249366b2013-11-25 12:05:19 -080085 check_quantizer(stream_config->rc_min_quantizer,
clang-format6c4d83e2016-08-08 19:03:30 -070086 stream_config->rc_max_quantizer, &warning_list);
Tom Finegan249366b2013-11-25 12:05:19 -080087 /* Count and print warnings. */
clang-format6c4d83e2016-08-08 19:03:30 -070088 for (warning = warning_list.warning_node; warning != NULL;
89 warning = warning->next_warning, ++num_warnings) {
Tom Finegan249366b2013-11-25 12:05:19 -080090 warn(warning->warning_string);
91 }
92
93 free_warning_list(&warning_list);
94
95 if (num_warnings) {
clang-format6c4d83e2016-08-08 19:03:30 -070096 if (!disable_prompt && !continue_prompt(num_warnings)) exit(EXIT_FAILURE);
Tom Finegan249366b2013-11-25 12:05:19 -080097 }
98}