2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
12 #include "./warnings.h"
19 #include "aom/aom_encoder.h"
21 #include "./tools_common.h"
24 static const char quantizer_warning_string
[] =
25 "Bad quantizer values. Quantizer values should not be equal, and should "
26 "differ by at least 8.";
28 struct WarningListNode
{
29 const char *warning_string
;
30 struct WarningListNode
*next_warning
;
34 struct WarningListNode
*warning_node
;
37 static void add_warning(const char *warning_string
,
38 struct WarningList
*warning_list
) {
39 struct WarningListNode
**node
= &warning_list
->warning_node
;
41 struct WarningListNode
*new_node
= malloc(sizeof(*new_node
));
42 if (new_node
== NULL
) {
43 fatal("Unable to allocate warning node.");
46 new_node
->warning_string
= warning_string
;
47 new_node
->next_warning
= NULL
;
49 while (*node
!= NULL
) node
= &(*node
)->next_warning
;
54 static void free_warning_list(struct WarningList
*warning_list
) {
55 while (warning_list
->warning_node
!= NULL
) {
56 struct WarningListNode
*const node
= warning_list
->warning_node
;
57 warning_list
->warning_node
= node
->next_warning
;
62 static int continue_prompt(int num_warnings
) {
65 "%d encoder configuration warning(s). Continue? (y to continue) ",
71 static void check_quantizer(int min_q
, int max_q
,
72 struct WarningList
*warning_list
) {
73 const int lossless
= min_q
== 0 && max_q
== 0;
74 if (!lossless
&& (min_q
== max_q
|| abs(max_q
- min_q
) < 8))
75 add_warning(quantizer_warning_string
, warning_list
);
78 void check_encoder_config(int disable_prompt
,
79 const struct AvxEncoderConfig
*global_config
,
80 const struct aom_codec_enc_cfg
*stream_config
) {
82 struct WarningListNode
*warning
= NULL
;
83 struct WarningList warning_list
= { 0 };
85 check_quantizer(stream_config
->rc_min_quantizer
,
86 stream_config
->rc_max_quantizer
, &warning_list
);
87 /* Count and print warnings. */
88 for (warning
= warning_list
.warning_node
; warning
!= NULL
;
89 warning
= warning
->next_warning
, ++num_warnings
) {
90 warn(warning
->warning_string
);
93 free_warning_list(&warning_list
);
96 if (!disable_prompt
&& !continue_prompt(num_warnings
)) exit(EXIT_FAILURE
);