blob: a9690d487133059b6ead31c6d8f93163a3f61648 [file] [log] [blame]
Tom Finegan249366b2013-11-25 12:05:19 -08001/*
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "./warnings.h"
12
13#include <assert.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17
Yaowu Xuf883b422016-08-30 14:01:10 -070018#include "aom/aom_encoder.h"
Tom Finegan249366b2013-11-25 12:05:19 -080019
20#include "./tools_common.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070021#include "./aomenc.h"
Tom Finegan249366b2013-11-25 12:05:19 -080022
23static const char quantizer_warning_string[] =
24 "Bad quantizer values. Quantizer values should not be equal, and should "
25 "differ by at least 8.";
26static const char lag_in_frames_with_realtime[] =
27 "Lag in frames is ignored when deadline is set to realtime.";
28
29struct WarningListNode {
30 const char *warning_string;
31 struct WarningListNode *next_warning;
32};
33
34struct WarningList {
35 struct WarningListNode *warning_node;
36};
37
38static void add_warning(const char *warning_string,
39 struct WarningList *warning_list) {
40 struct WarningListNode **node = &warning_list->warning_node;
41
42 struct WarningListNode *new_node = malloc(sizeof(*new_node));
43 if (new_node == NULL) {
44 fatal("Unable to allocate warning node.");
45 }
46
47 new_node->warning_string = warning_string;
48 new_node->next_warning = NULL;
49
clang-format6c4d83e2016-08-08 19:03:30 -070050 while (*node != NULL) node = &(*node)->next_warning;
Tom Finegan249366b2013-11-25 12:05:19 -080051
52 *node = new_node;
53}
54
55static void free_warning_list(struct WarningList *warning_list) {
Tom Finegan249366b2013-11-25 12:05:19 -080056 while (warning_list->warning_node != NULL) {
James Zernc04c3132014-02-08 13:10:27 -080057 struct WarningListNode *const node = warning_list->warning_node;
58 warning_list->warning_node = node->next_warning;
59 free(node);
Tom Finegan249366b2013-11-25 12:05:19 -080060 }
61}
62
63static int continue_prompt(int num_warnings) {
64 int c;
65 fprintf(stderr,
66 "%d encoder configuration warning(s). Continue? (y to continue) ",
67 num_warnings);
68 c = getchar();
69 return c == 'y';
70}
71
Tom Finegan249366b2013-11-25 12:05:19 -080072static void check_quantizer(int min_q, int max_q,
73 struct WarningList *warning_list) {
Yaowu Xu23417472013-12-05 13:52:47 -080074 const int lossless = min_q == 0 && max_q == 0;
75 if (!lossless && (min_q == max_q || abs(max_q - min_q) < 8))
Tom Finegan249366b2013-11-25 12:05:19 -080076 add_warning(quantizer_warning_string, warning_list);
77}
78
Tom Finegan150fbfc2014-01-14 18:04:35 -080079static void check_lag_in_frames_realtime_deadline(
clang-format6c4d83e2016-08-08 19:03:30 -070080 int lag_in_frames, int deadline, struct WarningList *warning_list) {
Yaowu Xuf883b422016-08-30 14:01:10 -070081 if (deadline == AOM_DL_REALTIME && lag_in_frames != 0)
Tom Finegan150fbfc2014-01-14 18:04:35 -080082 add_warning(lag_in_frames_with_realtime, warning_list);
83}
84
Tom Finegan249366b2013-11-25 12:05:19 -080085void check_encoder_config(int disable_prompt,
Yaowu Xuf883b422016-08-30 14:01:10 -070086 const struct AvxEncoderConfig *global_config,
87 const struct aom_codec_enc_cfg *stream_config) {
Tom Finegan249366b2013-11-25 12:05:19 -080088 int num_warnings = 0;
89 struct WarningListNode *warning = NULL;
clang-format6c4d83e2016-08-08 19:03:30 -070090 struct WarningList warning_list = { 0 };
Tom Finegan249366b2013-11-25 12:05:19 -080091
92 check_quantizer(stream_config->rc_min_quantizer,
clang-format6c4d83e2016-08-08 19:03:30 -070093 stream_config->rc_max_quantizer, &warning_list);
Tom Finegan150fbfc2014-01-14 18:04:35 -080094 check_lag_in_frames_realtime_deadline(stream_config->g_lag_in_frames,
clang-format6c4d83e2016-08-08 19:03:30 -070095 global_config->deadline, &warning_list);
Tom Finegan249366b2013-11-25 12:05:19 -080096 /* Count and print warnings. */
clang-format6c4d83e2016-08-08 19:03:30 -070097 for (warning = warning_list.warning_node; warning != NULL;
98 warning = warning->next_warning, ++num_warnings) {
Tom Finegan249366b2013-11-25 12:05:19 -080099 warn(warning->warning_string);
100 }
101
102 free_warning_list(&warning_list);
103
104 if (num_warnings) {
clang-format6c4d83e2016-08-08 19:03:30 -0700105 if (!disable_prompt && !continue_prompt(num_warnings)) exit(EXIT_FAILURE);
Tom Finegan249366b2013-11-25 12:05:19 -0800106 }
107}