vpxenc: Move config check code into its own source files.

- Add command line args that allow display of warnings without prompting
  for user input.
- Extend warning code to make it somewhat scalable.

Change-Id: I2bad8f9315f6eed120c2e1bbe0a2a5ede15fbf35
This commit is contained in:
Tom Finegan 2013-11-25 12:05:19 -08:00
parent 939b297ac7
commit 249366b1ac
4 changed files with 155 additions and 31 deletions

View File

@ -41,6 +41,7 @@ vpxenc.SRCS += args.c args.h y4minput.c y4minput.h vpxenc.h
vpxenc.SRCS += ivfdec.c ivfdec.h
vpxenc.SRCS += ivfenc.c ivfenc.h
vpxenc.SRCS += tools_common.c tools_common.h
vpxenc.SRCS += warnings.c warnings.h
vpxenc.SRCS += webmenc.c webmenc.h
vpxenc.SRCS += vpx_ports/mem_ops.h
vpxenc.SRCS += vpx_ports/mem_ops_aligned.h

View File

@ -40,6 +40,7 @@
#include "vpx_ports/mem_ops.h"
#include "vpx_ports/vpx_timer.h"
#include "./vpxstats.h"
#include "./warnings.h"
#include "./webmenc.h"
#include "./y4minput.h"
@ -238,13 +239,16 @@ static const arg_def_t rate_hist_n = ARG_DEF(NULL, "rate-hist", 1,
static const arg_def_t disable_warnings =
ARG_DEF(NULL, "disable-warnings", 0,
"Disable warnings about potentially incorrect encode settings.");
static const arg_def_t disable_warning_prompt =
ARG_DEF("y", "disable-warning-prompt", 0,
"Display warnings, but do not prompt user to continue.");
static const arg_def_t *main_args[] = {
&debugmode,
&outputfile, &codecarg, &passes, &pass_arg, &fpf_name, &limit, &skip,
&deadline, &best_dl, &good_dl, &rt_dl,
&quietarg, &verbosearg, &psnrarg, &use_ivf, &out_part, &q_hist_n,
&rate_hist_n, &disable_warnings,
&rate_hist_n, &disable_warnings, &disable_warning_prompt,
NULL
};
@ -987,6 +991,10 @@ static void parse_global_config(struct VpxEncoderConfig *global, char **argv) {
global->show_q_hist_buckets = arg_parse_uint(&arg);
else if (arg_match(&arg, &rate_hist_n, argi))
global->show_rate_hist_buckets = arg_parse_uint(&arg);
else if (arg_match(&arg, &disable_warnings, argi))
global->disable_warnings = 1;
else if (arg_match(&arg, &disable_warning_prompt, argi))
global->disable_warning_prompt = 1;
else
argj++;
}
@ -1259,7 +1267,7 @@ static int parse_stream_params(struct VpxEncoderConfig *global,
#define FOREACH_STREAM(func) \
do { \
struct stream_state *stream; \
for(stream = streams; stream; stream = stream->next) { \
for (stream = streams; stream; stream = stream->next) { \
func; \
} \
} while (0)
@ -1729,31 +1737,6 @@ static void print_time(const char *label, int64_t etl) {
}
}
int continue_prompt() {
int c;
fprintf(stderr, "Continue? (y to continue) ");
c = getchar();
return c == 'y';
}
void check_quantizer(struct VpxEncoderConfig* config, int min_q, int max_q) {
int check_failed = 0;
if (config->disable_warnings)
return;
if (min_q == max_q || abs(max_q - min_q) < 8) {
check_failed = 1;
}
if (check_failed) {
warn("Bad quantizer values. Quantizer values must not be equal, and "
"should differ by at least 8.");
if (!continue_prompt())
exit(EXIT_FAILURE);
}
}
int main(int argc, const char **argv_) {
int pass;
@ -1807,10 +1790,9 @@ int main(int argc, const char **argv_) {
if (argi[0][0] == '-' && argi[0][1])
die("Error: Unrecognized option %s\n", *argi);
FOREACH_STREAM(
check_quantizer(&global,
stream->config.cfg.rc_min_quantizer,
stream->config.cfg.rc_max_quantizer););
FOREACH_STREAM(check_encoder_config(global.disable_warning_prompt,
&global, &stream->config.cfg););
/* Handle non-option arguments */
input.filename = argv[0];

116
warnings.c Normal file
View File

@ -0,0 +1,116 @@
/*
* Copyright (c) 2013 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "./warnings.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "vpx/vpx_encoder.h"
#include "./tools_common.h"
#include "./vpxenc.h"
static const char quantizer_warning_string[] =
"Bad quantizer values. Quantizer values should not be equal, and should "
"differ by at least 8.";
static const char lag_in_frames_with_realtime[] =
"Lag in frames is ignored when deadline is set to realtime.";
struct WarningListNode {
const char *warning_string;
struct WarningListNode *next_warning;
};
struct WarningList {
struct WarningListNode *warning_node;
};
static void add_warning(const char *warning_string,
struct WarningList *warning_list) {
struct WarningListNode **node = &warning_list->warning_node;
struct WarningListNode *new_node = malloc(sizeof(*new_node));
if (new_node == NULL) {
fatal("Unable to allocate warning node.");
}
new_node->warning_string = warning_string;
new_node->next_warning = NULL;
while (*node != NULL)
node = &(*node)->next_warning;
*node = new_node;
}
static void free_warning_list(struct WarningList *warning_list) {
struct WarningListNode *node = warning_list->warning_node;
while (warning_list->warning_node != NULL) {
node = warning_list->warning_node->next_warning;
free(warning_list->warning_node);
warning_list->warning_node = node;
}
}
static int continue_prompt(int num_warnings) {
int c;
fprintf(stderr,
"%d encoder configuration warning(s). Continue? (y to continue) ",
num_warnings);
c = getchar();
return c == 'y';
}
static void check_lag_in_frames_realtime_deadline(
int lag_in_frames,
int deadline,
struct WarningList *warning_list) {
if (deadline == VPX_DL_REALTIME && lag_in_frames != 0)
add_warning(lag_in_frames_with_realtime, warning_list);
}
static void check_quantizer(int min_q, int max_q,
struct WarningList *warning_list) {
if (min_q == max_q || abs(max_q - min_q) < 8)
add_warning(quantizer_warning_string, warning_list);
}
void check_encoder_config(int disable_prompt,
const struct VpxEncoderConfig *global_config,
const struct vpx_codec_enc_cfg *stream_config) {
int num_warnings = 0;
struct WarningListNode *warning = NULL;
struct WarningList warning_list = {0};
check_quantizer(stream_config->rc_min_quantizer,
stream_config->rc_max_quantizer,
&warning_list);
check_lag_in_frames_realtime_deadline(stream_config->g_lag_in_frames,
global_config->deadline,
&warning_list);
/* Count and print warnings. */
for (warning = warning_list.warning_node;
warning != NULL;
warning = warning->next_warning,
++num_warnings) {
warn(warning->warning_string);
}
free_warning_list(&warning_list);
if (num_warnings) {
if (!disable_prompt && !continue_prompt(num_warnings))
exit(EXIT_FAILURE);
}
}

25
warnings.h Normal file
View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2013 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WARNINGS_H_
#define WARNINGS_H_
struct vpx_codec_enc_cfg;
struct VpxEncoderConfig;
/*
* Checks config for improperly used settings. Warns user upon encountering
* settings that will lead to poor output quality. Prompts user to continue
* when warnings are issued.
*/
void check_encoder_config(int disable_prompt,
const struct VpxEncoderConfig *global_config,
const struct vpx_codec_enc_cfg *stream_config);
#endif // WARNINGS_H_