blob: 7575925d4ef5e94621f72fb0f2c9ca826527341d [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.";
27static const char lag_in_frames_with_realtime[] =
28 "Lag in frames is ignored when deadline is set to realtime.";
29
30struct WarningListNode {
31 const char *warning_string;
32 struct WarningListNode *next_warning;
33};
34
35struct WarningList {
36 struct WarningListNode *warning_node;
37};
38
39static void add_warning(const char *warning_string,
40 struct WarningList *warning_list) {
41 struct WarningListNode **node = &warning_list->warning_node;
42
43 struct WarningListNode *new_node = malloc(sizeof(*new_node));
44 if (new_node == NULL) {
45 fatal("Unable to allocate warning node.");
46 }
47
48 new_node->warning_string = warning_string;
49 new_node->next_warning = NULL;
50
clang-format6c4d83e2016-08-08 19:03:30 -070051 while (*node != NULL) node = &(*node)->next_warning;
Tom Finegan249366b2013-11-25 12:05:19 -080052
53 *node = new_node;
54}
55
56static void free_warning_list(struct WarningList *warning_list) {
Tom Finegan249366b2013-11-25 12:05:19 -080057 while (warning_list->warning_node != NULL) {
James Zernc04c3132014-02-08 13:10:27 -080058 struct WarningListNode *const node = warning_list->warning_node;
59 warning_list->warning_node = node->next_warning;
60 free(node);
Tom Finegan249366b2013-11-25 12:05:19 -080061 }
62}
63
64static int continue_prompt(int num_warnings) {
65 int c;
66 fprintf(stderr,
67 "%d encoder configuration warning(s). Continue? (y to continue) ",
68 num_warnings);
69 c = getchar();
70 return c == 'y';
71}
72
Tom Finegan249366b2013-11-25 12:05:19 -080073static void check_quantizer(int min_q, int max_q,
74 struct WarningList *warning_list) {
Yaowu Xu23417472013-12-05 13:52:47 -080075 const int lossless = min_q == 0 && max_q == 0;
76 if (!lossless && (min_q == max_q || abs(max_q - min_q) < 8))
Tom Finegan249366b2013-11-25 12:05:19 -080077 add_warning(quantizer_warning_string, warning_list);
78}
79
Tom Finegan150fbfc2014-01-14 18:04:35 -080080static void check_lag_in_frames_realtime_deadline(
clang-format6c4d83e2016-08-08 19:03:30 -070081 int lag_in_frames, int deadline, struct WarningList *warning_list) {
Yaowu Xuf883b422016-08-30 14:01:10 -070082 if (deadline == AOM_DL_REALTIME && lag_in_frames != 0)
Tom Finegan150fbfc2014-01-14 18:04:35 -080083 add_warning(lag_in_frames_with_realtime, warning_list);
84}
85
Tom Finegan249366b2013-11-25 12:05:19 -080086void check_encoder_config(int disable_prompt,
Yaowu Xuf883b422016-08-30 14:01:10 -070087 const struct AvxEncoderConfig *global_config,
88 const struct aom_codec_enc_cfg *stream_config) {
Tom Finegan249366b2013-11-25 12:05:19 -080089 int num_warnings = 0;
90 struct WarningListNode *warning = NULL;
clang-format6c4d83e2016-08-08 19:03:30 -070091 struct WarningList warning_list = { 0 };
Tom Finegan249366b2013-11-25 12:05:19 -080092
93 check_quantizer(stream_config->rc_min_quantizer,
clang-format6c4d83e2016-08-08 19:03:30 -070094 stream_config->rc_max_quantizer, &warning_list);
Tom Finegan150fbfc2014-01-14 18:04:35 -080095 check_lag_in_frames_realtime_deadline(stream_config->g_lag_in_frames,
clang-format6c4d83e2016-08-08 19:03:30 -070096 global_config->deadline, &warning_list);
Tom Finegan249366b2013-11-25 12:05:19 -080097 /* Count and print warnings. */
clang-format6c4d83e2016-08-08 19:03:30 -070098 for (warning = warning_list.warning_node; warning != NULL;
99 warning = warning->next_warning, ++num_warnings) {
Tom Finegan249366b2013-11-25 12:05:19 -0800100 warn(warning->warning_string);
101 }
102
103 free_warning_list(&warning_list);
104
105 if (num_warnings) {
clang-format6c4d83e2016-08-08 19:03:30 -0700106 if (!disable_prompt && !continue_prompt(num_warnings)) exit(EXIT_FAILURE);
Tom Finegan249366b2013-11-25 12:05:19 -0800107 }
108}