warnings.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include "./warnings.h"
  11. #include <assert.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "vpx/vpx_encoder.h"
  16. #include "./tools_common.h"
  17. #include "./vpxenc.h"
  18. static const char quantizer_warning_string[] =
  19. "Bad quantizer values. Quantizer values should not be equal, and should "
  20. "differ by at least 8.";
  21. static const char lag_in_frames_with_realtime[] =
  22. "Lag in frames is ignored when deadline is set to realtime for cbr mode.";
  23. struct WarningListNode {
  24. const char *warning_string;
  25. struct WarningListNode *next_warning;
  26. };
  27. struct WarningList {
  28. struct WarningListNode *warning_node;
  29. };
  30. static void add_warning(const char *warning_string,
  31. struct WarningList *warning_list) {
  32. struct WarningListNode **node = &warning_list->warning_node;
  33. struct WarningListNode *new_node = malloc(sizeof(*new_node));
  34. if (new_node == NULL) {
  35. fatal("Unable to allocate warning node.");
  36. }
  37. new_node->warning_string = warning_string;
  38. new_node->next_warning = NULL;
  39. while (*node != NULL) node = &(*node)->next_warning;
  40. *node = new_node;
  41. }
  42. static void free_warning_list(struct WarningList *warning_list) {
  43. while (warning_list->warning_node != NULL) {
  44. struct WarningListNode *const node = warning_list->warning_node;
  45. warning_list->warning_node = node->next_warning;
  46. free(node);
  47. }
  48. }
  49. static int continue_prompt(int num_warnings) {
  50. int c;
  51. fprintf(stderr,
  52. "%d encoder configuration warning(s). Continue? (y to continue) ",
  53. num_warnings);
  54. c = getchar();
  55. return c == 'y';
  56. }
  57. static void check_quantizer(int min_q, int max_q,
  58. struct WarningList *warning_list) {
  59. const int lossless = min_q == 0 && max_q == 0;
  60. if (!lossless && (min_q == max_q || abs(max_q - min_q) < 8))
  61. add_warning(quantizer_warning_string, warning_list);
  62. }
  63. static void check_lag_in_frames_realtime_deadline(
  64. int lag_in_frames, int deadline, int rc_end_usage,
  65. struct WarningList *warning_list) {
  66. if (deadline == VPX_DL_REALTIME && lag_in_frames != 0 && rc_end_usage == 1)
  67. add_warning(lag_in_frames_with_realtime, warning_list);
  68. }
  69. void check_encoder_config(int disable_prompt,
  70. const struct VpxEncoderConfig *global_config,
  71. const struct vpx_codec_enc_cfg *stream_config) {
  72. int num_warnings = 0;
  73. struct WarningListNode *warning = NULL;
  74. struct WarningList warning_list = { 0 };
  75. check_quantizer(stream_config->rc_min_quantizer,
  76. stream_config->rc_max_quantizer, &warning_list);
  77. check_lag_in_frames_realtime_deadline(
  78. stream_config->g_lag_in_frames, global_config->deadline,
  79. stream_config->rc_end_usage, &warning_list);
  80. /* Count and print warnings. */
  81. for (warning = warning_list.warning_node; warning != NULL;
  82. warning = warning->next_warning, ++num_warnings) {
  83. warn(warning->warning_string);
  84. }
  85. free_warning_list(&warning_list);
  86. if (num_warnings) {
  87. if (!disable_prompt && !continue_prompt(num_warnings)) exit(EXIT_FAILURE);
  88. }
  89. }