1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #include "common/warnings.h"
13*77c1e3ccSAndroid Build Coastguard Worker
14*77c1e3ccSAndroid Build Coastguard Worker #include <assert.h>
15*77c1e3ccSAndroid Build Coastguard Worker #include <stdio.h>
16*77c1e3ccSAndroid Build Coastguard Worker #include <stdlib.h>
17*77c1e3ccSAndroid Build Coastguard Worker #include <string.h>
18*77c1e3ccSAndroid Build Coastguard Worker
19*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_encoder.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "apps/aomenc.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "common/tools_common.h"
22*77c1e3ccSAndroid Build Coastguard Worker
23*77c1e3ccSAndroid Build Coastguard Worker static const char quantizer_warning_string[] =
24*77c1e3ccSAndroid Build Coastguard Worker "Bad quantizer values. Quantizer values should not be equal, and should "
25*77c1e3ccSAndroid Build Coastguard Worker "differ by at least 8.";
26*77c1e3ccSAndroid Build Coastguard Worker
27*77c1e3ccSAndroid Build Coastguard Worker struct WarningListNode {
28*77c1e3ccSAndroid Build Coastguard Worker const char *warning_string;
29*77c1e3ccSAndroid Build Coastguard Worker struct WarningListNode *next_warning;
30*77c1e3ccSAndroid Build Coastguard Worker };
31*77c1e3ccSAndroid Build Coastguard Worker
32*77c1e3ccSAndroid Build Coastguard Worker struct WarningList {
33*77c1e3ccSAndroid Build Coastguard Worker struct WarningListNode *warning_node;
34*77c1e3ccSAndroid Build Coastguard Worker };
35*77c1e3ccSAndroid Build Coastguard Worker
add_warning(const char * warning_string,struct WarningList * warning_list)36*77c1e3ccSAndroid Build Coastguard Worker static void add_warning(const char *warning_string,
37*77c1e3ccSAndroid Build Coastguard Worker struct WarningList *warning_list) {
38*77c1e3ccSAndroid Build Coastguard Worker struct WarningListNode **node = &warning_list->warning_node;
39*77c1e3ccSAndroid Build Coastguard Worker
40*77c1e3ccSAndroid Build Coastguard Worker struct WarningListNode *new_node = malloc(sizeof(*new_node));
41*77c1e3ccSAndroid Build Coastguard Worker if (new_node == NULL) {
42*77c1e3ccSAndroid Build Coastguard Worker fatal("Unable to allocate warning node.");
43*77c1e3ccSAndroid Build Coastguard Worker }
44*77c1e3ccSAndroid Build Coastguard Worker
45*77c1e3ccSAndroid Build Coastguard Worker new_node->warning_string = warning_string;
46*77c1e3ccSAndroid Build Coastguard Worker new_node->next_warning = NULL;
47*77c1e3ccSAndroid Build Coastguard Worker
48*77c1e3ccSAndroid Build Coastguard Worker while (*node != NULL) node = &(*node)->next_warning;
49*77c1e3ccSAndroid Build Coastguard Worker
50*77c1e3ccSAndroid Build Coastguard Worker *node = new_node;
51*77c1e3ccSAndroid Build Coastguard Worker }
52*77c1e3ccSAndroid Build Coastguard Worker
free_warning_list(struct WarningList * warning_list)53*77c1e3ccSAndroid Build Coastguard Worker static void free_warning_list(struct WarningList *warning_list) {
54*77c1e3ccSAndroid Build Coastguard Worker while (warning_list->warning_node != NULL) {
55*77c1e3ccSAndroid Build Coastguard Worker struct WarningListNode *const node = warning_list->warning_node;
56*77c1e3ccSAndroid Build Coastguard Worker warning_list->warning_node = node->next_warning;
57*77c1e3ccSAndroid Build Coastguard Worker free(node);
58*77c1e3ccSAndroid Build Coastguard Worker }
59*77c1e3ccSAndroid Build Coastguard Worker }
60*77c1e3ccSAndroid Build Coastguard Worker
continue_prompt(int num_warnings)61*77c1e3ccSAndroid Build Coastguard Worker static int continue_prompt(int num_warnings) {
62*77c1e3ccSAndroid Build Coastguard Worker int c;
63*77c1e3ccSAndroid Build Coastguard Worker fprintf(stderr,
64*77c1e3ccSAndroid Build Coastguard Worker "%d encoder configuration warning(s). Continue? (y to continue) ",
65*77c1e3ccSAndroid Build Coastguard Worker num_warnings);
66*77c1e3ccSAndroid Build Coastguard Worker c = getchar();
67*77c1e3ccSAndroid Build Coastguard Worker return c == 'y';
68*77c1e3ccSAndroid Build Coastguard Worker }
69*77c1e3ccSAndroid Build Coastguard Worker
check_quantizer(int min_q,int max_q,struct WarningList * warning_list)70*77c1e3ccSAndroid Build Coastguard Worker static void check_quantizer(int min_q, int max_q,
71*77c1e3ccSAndroid Build Coastguard Worker struct WarningList *warning_list) {
72*77c1e3ccSAndroid Build Coastguard Worker const int lossless = min_q == 0 && max_q == 0;
73*77c1e3ccSAndroid Build Coastguard Worker if (!lossless && (min_q == max_q || abs(max_q - min_q) < 8))
74*77c1e3ccSAndroid Build Coastguard Worker add_warning(quantizer_warning_string, warning_list);
75*77c1e3ccSAndroid Build Coastguard Worker }
76*77c1e3ccSAndroid Build Coastguard Worker
check_encoder_config(int disable_prompt,const struct AvxEncoderConfig * global_config,const struct aom_codec_enc_cfg * stream_config)77*77c1e3ccSAndroid Build Coastguard Worker void check_encoder_config(int disable_prompt,
78*77c1e3ccSAndroid Build Coastguard Worker const struct AvxEncoderConfig *global_config,
79*77c1e3ccSAndroid Build Coastguard Worker const struct aom_codec_enc_cfg *stream_config) {
80*77c1e3ccSAndroid Build Coastguard Worker int num_warnings = 0;
81*77c1e3ccSAndroid Build Coastguard Worker struct WarningListNode *warning = NULL;
82*77c1e3ccSAndroid Build Coastguard Worker struct WarningList warning_list = { 0 };
83*77c1e3ccSAndroid Build Coastguard Worker (void)global_config;
84*77c1e3ccSAndroid Build Coastguard Worker check_quantizer(stream_config->rc_min_quantizer,
85*77c1e3ccSAndroid Build Coastguard Worker stream_config->rc_max_quantizer, &warning_list);
86*77c1e3ccSAndroid Build Coastguard Worker /* Count and print warnings. */
87*77c1e3ccSAndroid Build Coastguard Worker for (warning = warning_list.warning_node; warning != NULL;
88*77c1e3ccSAndroid Build Coastguard Worker warning = warning->next_warning, ++num_warnings) {
89*77c1e3ccSAndroid Build Coastguard Worker aom_tools_warn("%s", warning->warning_string);
90*77c1e3ccSAndroid Build Coastguard Worker }
91*77c1e3ccSAndroid Build Coastguard Worker
92*77c1e3ccSAndroid Build Coastguard Worker free_warning_list(&warning_list);
93*77c1e3ccSAndroid Build Coastguard Worker
94*77c1e3ccSAndroid Build Coastguard Worker if (num_warnings) {
95*77c1e3ccSAndroid Build Coastguard Worker if (!disable_prompt && !continue_prompt(num_warnings)) exit(EXIT_FAILURE);
96*77c1e3ccSAndroid Build Coastguard Worker }
97*77c1e3ccSAndroid Build Coastguard Worker }
98