Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 1 | /* |
| 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 18 | #include "aom/aom_encoder.h" |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 19 | |
| 20 | #include "./tools_common.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 21 | #include "./aomenc.h" |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 22 | |
| 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."; |
| 28 | |
| 29 | struct WarningListNode { |
| 30 | const char *warning_string; |
| 31 | struct WarningListNode *next_warning; |
| 32 | }; |
| 33 | |
| 34 | struct WarningList { |
| 35 | struct WarningListNode *warning_node; |
| 36 | }; |
| 37 | |
| 38 | static 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-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 50 | while (*node != NULL) node = &(*node)->next_warning; |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 51 | |
| 52 | *node = new_node; |
| 53 | } |
| 54 | |
| 55 | static void free_warning_list(struct WarningList *warning_list) { |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 56 | while (warning_list->warning_node != NULL) { |
James Zern | c04c313 | 2014-02-08 13:10:27 -0800 | [diff] [blame] | 57 | struct WarningListNode *const node = warning_list->warning_node; |
| 58 | warning_list->warning_node = node->next_warning; |
| 59 | free(node); |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
| 63 | static 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 Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 72 | static void check_quantizer(int min_q, int max_q, |
| 73 | struct WarningList *warning_list) { |
Yaowu Xu | 2341747 | 2013-12-05 13:52:47 -0800 | [diff] [blame] | 74 | const int lossless = min_q == 0 && max_q == 0; |
| 75 | if (!lossless && (min_q == max_q || abs(max_q - min_q) < 8)) |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 76 | add_warning(quantizer_warning_string, warning_list); |
| 77 | } |
| 78 | |
Tom Finegan | 150fbfc | 2014-01-14 18:04:35 -0800 | [diff] [blame] | 79 | static void check_lag_in_frames_realtime_deadline( |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 80 | int lag_in_frames, int deadline, struct WarningList *warning_list) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 81 | if (deadline == AOM_DL_REALTIME && lag_in_frames != 0) |
Tom Finegan | 150fbfc | 2014-01-14 18:04:35 -0800 | [diff] [blame] | 82 | add_warning(lag_in_frames_with_realtime, warning_list); |
| 83 | } |
| 84 | |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 85 | void check_encoder_config(int disable_prompt, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 86 | const struct AvxEncoderConfig *global_config, |
| 87 | const struct aom_codec_enc_cfg *stream_config) { |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 88 | int num_warnings = 0; |
| 89 | struct WarningListNode *warning = NULL; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 90 | struct WarningList warning_list = { 0 }; |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 91 | |
| 92 | check_quantizer(stream_config->rc_min_quantizer, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 93 | stream_config->rc_max_quantizer, &warning_list); |
Tom Finegan | 150fbfc | 2014-01-14 18:04:35 -0800 | [diff] [blame] | 94 | check_lag_in_frames_realtime_deadline(stream_config->g_lag_in_frames, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 95 | global_config->deadline, &warning_list); |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 96 | /* Count and print warnings. */ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 97 | for (warning = warning_list.warning_node; warning != NULL; |
| 98 | warning = warning->next_warning, ++num_warnings) { |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 99 | warn(warning->warning_string); |
| 100 | } |
| 101 | |
| 102 | free_warning_list(&warning_list); |
| 103 | |
| 104 | if (num_warnings) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 105 | if (!disable_prompt && !continue_prompt(num_warnings)) exit(EXIT_FAILURE); |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 106 | } |
| 107 | } |