Refine VP10 REFRESH_FRAME_CONTEXT_MODE
[aom.git] / warnings.c
blob7ac678ab4aabfee4a94ce7916f0580f1205c5b25
1 /*
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
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 */
11 #include "./warnings.h"
13 #include <assert.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
18 #include "vpx/vpx_encoder.h"
20 #include "./tools_common.h"
21 #include "./vpxenc.h"
23 static const char quantizer_warning_string[] =
24 "Bad quantizer values. Quantizer values should not be equal, and should "
25 "differ by at least 8.";
26 static const char lag_in_frames_with_realtime[] =
27 "Lag in frames is ignored when deadline is set to realtime.";
29 struct WarningListNode {
30 const char *warning_string;
31 struct WarningListNode *next_warning;
34 struct WarningList {
35 struct WarningListNode *warning_node;
38 static void add_warning(const char *warning_string,
39 struct WarningList *warning_list) {
40 struct WarningListNode **node = &warning_list->warning_node;
42 struct WarningListNode *new_node = malloc(sizeof(*new_node));
43 if (new_node == NULL) {
44 fatal("Unable to allocate warning node.");
47 new_node->warning_string = warning_string;
48 new_node->next_warning = NULL;
50 while (*node != NULL)
51 node = &(*node)->next_warning;
53 *node = new_node;
56 static void free_warning_list(struct WarningList *warning_list) {
57 while (warning_list->warning_node != NULL) {
58 struct WarningListNode *const node = warning_list->warning_node;
59 warning_list->warning_node = node->next_warning;
60 free(node);
64 static 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';
73 static void check_quantizer(int min_q, int max_q,
74 struct WarningList *warning_list) {
75 const int lossless = min_q == 0 && max_q == 0;
76 if (!lossless && (min_q == max_q || abs(max_q - min_q) < 8))
77 add_warning(quantizer_warning_string, warning_list);
80 static void check_lag_in_frames_realtime_deadline(
81 int lag_in_frames,
82 int deadline,
83 struct WarningList *warning_list) {
84 if (deadline == VPX_DL_REALTIME && lag_in_frames != 0)
85 add_warning(lag_in_frames_with_realtime, warning_list);
88 void check_encoder_config(int disable_prompt,
89 const struct VpxEncoderConfig *global_config,
90 const struct vpx_codec_enc_cfg *stream_config) {
91 int num_warnings = 0;
92 struct WarningListNode *warning = NULL;
93 struct WarningList warning_list = {0};
95 check_quantizer(stream_config->rc_min_quantizer,
96 stream_config->rc_max_quantizer,
97 &warning_list);
98 check_lag_in_frames_realtime_deadline(stream_config->g_lag_in_frames,
99 global_config->deadline,
100 &warning_list);
101 /* Count and print warnings. */
102 for (warning = warning_list.warning_node;
103 warning != NULL;
104 warning = warning->next_warning,
105 ++num_warnings) {
106 warn(warning->warning_string);
109 free_warning_list(&warning_list);
111 if (num_warnings) {
112 if (!disable_prompt && !continue_prompt(num_warnings))
113 exit(EXIT_FAILURE);