Commit 29e40a65 authored by Debargha Mukherjee's avatar Debargha Mukherjee

Unify and clean up resize arguments

Unifies the command line arguments for resize and superes.
Removes resize arguments that are currently unused.

Change-Id: I1362dffceb8257cee539f92679d1e8d79df08e66
parent c4e78942
......@@ -363,44 +363,22 @@ typedef struct aom_codec_enc_cfg {
*/
unsigned int rc_dropframe_thresh;
/*!\brief Enable/disable spatial resampling, if supported by the codec.
/*!\brief Mode for spatial resampling, if supported by the codec.
*
* Spatial resampling allows the codec to compress a lower resolution
* version of the frame, which is then upscaled by the encoder to the
* version of the frame, which is then upscaled by the decoder to the
* correct presentation resolution. This increases visual quality at
* low data rates, at the expense of CPU time on the encoder/decoder.
*/
unsigned int rc_resize_allowed;
unsigned int rc_resize_mode;
/*!\brief Internal coded frame width.
/*!\brief Frame resize numerator.
*
* If spatial resampling is enabled this specifies the width of the
* encoded frame.
*/
unsigned int rc_scaled_width;
/*!\brief Internal coded frame height.
*
* If spatial resampling is enabled this specifies the height of the
* encoded frame.
*/
unsigned int rc_scaled_height;
/*!\brief Spatial resampling up watermark.
* The numerator for resize to use, assuming 16 as the denominator.
*
* This threshold is described as a percentage of the target data buffer.
* When the data buffer rises above this percentage of fullness, the
* encoder will step up to a higher resolution version of the frame.
*/
unsigned int rc_resize_up_thresh;
/*!\brief Spatial resampling down watermark.
*
* This threshold is described as a percentage of the target data buffer.
* When the data buffer falls below this percentage of fullness, the
* encoder will step down to a lower resolution version of the frame.
* Valid numerators are 8 - 16 for now.
*/
unsigned int rc_resize_down_thresh;
unsigned int rc_resize_numerator;
/*!\brief Frame super-resolution scaling mode.
*
......
......@@ -271,16 +271,10 @@ static const arg_def_t *global_args[] = {
static const arg_def_t dropframe_thresh =
ARG_DEF(NULL, "drop-frame", 1, "Temporal resampling threshold (buf %)");
static const arg_def_t resize_allowed =
ARG_DEF(NULL, "resize-allowed", 1, "Spatial resampling enabled (bool)");
static const arg_def_t resize_width =
ARG_DEF(NULL, "resize-width", 1, "Width of encoded frame");
static const arg_def_t resize_height =
ARG_DEF(NULL, "resize-height", 1, "Height of encoded frame");
static const arg_def_t resize_up_thresh =
ARG_DEF(NULL, "resize-up", 1, "Upscale threshold (buf %)");
static const arg_def_t resize_down_thresh =
ARG_DEF(NULL, "resize-down", 1, "Downscale threshold (buf %)");
static const arg_def_t resize_mode =
ARG_DEF(NULL, "resize-mode", 1, "Frame resize mode");
static const arg_def_t resize_numerator =
ARG_DEF(NULL, "resize-numerator", 1, "Frame resize numerator");
static const struct arg_enum_list end_usage_enum[] = { { "vbr", AOM_VBR },
{ "cbr", AOM_CBR },
{ "cq", AOM_CQ },
......@@ -310,9 +304,8 @@ static const arg_def_t buf_initial_sz =
ARG_DEF(NULL, "buf-initial-sz", 1, "Client initial buffer size (ms)");
static const arg_def_t buf_optimal_sz =
ARG_DEF(NULL, "buf-optimal-sz", 1, "Client optimal buffer size (ms)");
static const arg_def_t *rc_args[] = { &dropframe_thresh, &resize_allowed,
&resize_width, &resize_height,
&resize_up_thresh, &resize_down_thresh,
static const arg_def_t *rc_args[] = { &dropframe_thresh, &resize_mode,
&resize_numerator,
#if CONFIG_FRAME_SUPERRES
&superres_mode, &superres_numerator,
#endif // CONFIG_FRAME_SUPERRES
......@@ -1012,16 +1005,10 @@ static int parse_stream_params(struct AvxEncoderConfig *global,
config->cfg.g_lag_in_frames = arg_parse_uint(&arg);
} else if (arg_match(&arg, &dropframe_thresh, argi)) {
config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg);
} else if (arg_match(&arg, &resize_allowed, argi)) {
config->cfg.rc_resize_allowed = arg_parse_uint(&arg);
} else if (arg_match(&arg, &resize_width, argi)) {
config->cfg.rc_scaled_width = arg_parse_uint(&arg);
} else if (arg_match(&arg, &resize_height, argi)) {
config->cfg.rc_scaled_height = arg_parse_uint(&arg);
} else if (arg_match(&arg, &resize_up_thresh, argi)) {
config->cfg.rc_resize_up_thresh = arg_parse_uint(&arg);
} else if (arg_match(&arg, &resize_down_thresh, argi)) {
config->cfg.rc_resize_down_thresh = arg_parse_uint(&arg);
} else if (arg_match(&arg, &resize_mode, argi)) {
config->cfg.rc_resize_mode = arg_parse_uint(&arg);
} else if (arg_match(&arg, &resize_numerator, argi)) {
config->cfg.rc_resize_numerator = arg_parse_uint(&arg);
#if CONFIG_FRAME_SUPERRES
} else if (arg_match(&arg, &superres_mode, argi)) {
config->cfg.rc_superres_mode = arg_parse_uint(&arg);
......@@ -1233,11 +1220,8 @@ static void show_stream_config(struct stream_state *stream,
SHOW(g_pass);
SHOW(g_lag_in_frames);
SHOW(rc_dropframe_thresh);
SHOW(rc_resize_allowed);
SHOW(rc_scaled_width);
SHOW(rc_scaled_height);
SHOW(rc_resize_up_thresh);
SHOW(rc_resize_down_thresh);
SHOW(rc_resize_mode);
SHOW(rc_resize_numerator);
#if CONFIG_FRAME_SUPERRES
SHOW(rc_superres_mode);
SHOW(rc_superres_numerator);
......
......@@ -243,10 +243,7 @@ static aom_codec_err_t validate_config(aom_codec_alg_priv_t *ctx,
RANGE_CHECK_HI(cfg, rc_overshoot_pct, 100);
RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100);
RANGE_CHECK(cfg, kf_mode, AOM_KF_DISABLED, AOM_KF_AUTO);
RANGE_CHECK_BOOL(cfg, rc_resize_allowed);
RANGE_CHECK_HI(cfg, rc_dropframe_thresh, 100);
RANGE_CHECK_HI(cfg, rc_resize_up_thresh, 100);
RANGE_CHECK_HI(cfg, rc_resize_down_thresh, 100);
RANGE_CHECK(cfg, g_pass, AOM_RC_ONE_PASS, AOM_RC_LAST_PASS);
RANGE_CHECK_HI(extra_cfg, min_gf_interval, MAX_LAG_BUFFERS - 1);
RANGE_CHECK_HI(extra_cfg, max_gf_interval, MAX_LAG_BUFFERS - 1);
......@@ -258,11 +255,9 @@ static aom_codec_err_t validate_config(aom_codec_alg_priv_t *ctx,
(MAX_LAG_BUFFERS - 1));
}
if (cfg->rc_resize_allowed == 1) {
RANGE_CHECK_HI(cfg, rc_scaled_width, cfg->g_w);
RANGE_CHECK_HI(cfg, rc_scaled_height, cfg->g_h);
}
RANGE_CHECK_HI(cfg, rc_resize_mode, RESIZE_DYNAMIC);
RANGE_CHECK(cfg, rc_resize_numerator, RESIZE_SCALE_DENOMINATOR / 2,
RESIZE_SCALE_DENOMINATOR);
#if CONFIG_FRAME_SUPERRES
RANGE_CHECK_HI(cfg, rc_superres_mode, SUPERRES_DYNAMIC);
RANGE_CHECK(cfg, rc_superres_numerator, SUPERRES_SCALE_DENOMINATOR / 2,
......@@ -493,22 +488,11 @@ static aom_codec_err_t set_encoder_config(
oxcf->under_shoot_pct = cfg->rc_undershoot_pct;
oxcf->over_shoot_pct = cfg->rc_overshoot_pct;
oxcf->scaled_frame_width = cfg->rc_scaled_width;
oxcf->scaled_frame_height = cfg->rc_scaled_height;
if (cfg->rc_resize_allowed == 1) {
oxcf->resize_mode =
(oxcf->scaled_frame_width == 0 || oxcf->scaled_frame_height == 0)
? RESIZE_DYNAMIC
: RESIZE_FIXED;
} else {
oxcf->resize_mode = (RESIZE_MODE)cfg->rc_resize_mode;
oxcf->resize_scale_numerator = (uint8_t)cfg->rc_resize_numerator;
if (oxcf->resize_mode == RESIZE_FIXED &&
oxcf->resize_scale_numerator == RESIZE_SCALE_DENOMINATOR)
oxcf->resize_mode = RESIZE_NONE;
}
// Initialize to input resolution if not specified.
if (oxcf->resize_mode != RESIZE_FIXED) {
oxcf->scaled_frame_width = oxcf->width;
oxcf->scaled_frame_height = oxcf->height;
}
#if CONFIG_FRAME_SUPERRES
oxcf->superres_mode = (SUPERRES_MODE)cfg->rc_superres_mode;
......@@ -1599,12 +1583,9 @@ static aom_codec_enc_cfg_map_t encoder_usage_cfg_map[] = {
25, // g_lag_in_frames
0, // rc_dropframe_thresh
0, // rc_resize_allowed
0, // rc_scaled_width
0, // rc_scaled_height
60, // rc_resize_down_thresold
30, // rc_resize_up_thresold
0, // rc_dropframe_thresh
RESIZE_NONE, // rc_resize_mode
RESIZE_SCALE_DENOMINATOR, // rc_resize_numerator
0, // rc_superres_mode
SUPERRES_SCALE_DENOMINATOR, // rc_superres_numerator
......
......@@ -546,7 +546,9 @@ typedef enum {
} RestorationType;
#endif // CONFIG_LOOP_RESTORATION
#define RESIZE_SCALE_DENOMINATOR 16
#define SUPERRES_SCALE_DENOMINATOR 16
#if CONFIG_FRAME_SUPERRES
#define SUPERRES_SCALE_BITS 3
#define SUPERRES_SCALE_NUMERATOR_MIN 8
......
......@@ -882,13 +882,12 @@ YV12_BUFFER_CONFIG *av1_scale_if_required(AV1_COMMON *cm,
}
}
#if CONFIG_FRAME_SUPERRES
void av1_calculate_superres_size(const AV1_COMMON *cm, int *width,
int *height) {
*width = *width * cm->superres_scale_numerator / SUPERRES_SCALE_DENOMINATOR;
*height = *height * cm->superres_scale_numerator / SUPERRES_SCALE_DENOMINATOR;
void av1_calculate_scaled_size(int *width, int *height, int num, int den) {
*width = *width * num / den;
*height = *height * num / den;
}
#if CONFIG_FRAME_SUPERRES
// TODO(afergs): Look for in-place upscaling
// TODO(afergs): aom_ vs av1_ functions? Which can I use?
// Upscale decoded image.
......
......@@ -79,12 +79,8 @@ YV12_BUFFER_CONFIG *av1_scale_if_required(AV1_COMMON *cm,
YV12_BUFFER_CONFIG *unscaled,
YV12_BUFFER_CONFIG *scaled);
void av1_calculate_scaled_size(int *width, int *height, int num, int den);
#if CONFIG_FRAME_SUPERRES
// This is the size after superress scaling, which could be 1:1.
// Superres scaling happens after regular downscaling.
// TODO(afergs): Limit overall reduction to 1/2 of the original size
void av1_calculate_superres_size(const AV1_COMMON *cm, int *width, int *height);
void av1_superres_upscale(AV1_COMMON *cm, BufferPool *const pool);
// Returns 1 if a superres upscaled frame is unscaled and 0 otherwise.
......
......@@ -3078,7 +3078,8 @@ static void setup_superres(AV1_COMMON *const cm, struct aom_read_bit_buffer *rb,
cm->superres_scale_numerator += SUPERRES_SCALE_NUMERATOR_MIN;
// Don't edit cm->width or cm->height directly, or the buffers won't get
// resized correctly
av1_calculate_superres_size(cm, width, height);
av1_calculate_scaled_size(width, height, cm->superres_scale_numerator,
SUPERRES_SCALE_DENOMINATOR);
} else {
// 1:1 scaling - ie. no scaling, scale not provided
cm->superres_scale_numerator = SUPERRES_SCALE_DENOMINATOR;
......
......@@ -2459,8 +2459,8 @@ AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
av1_loop_filter_init(cm);
#if CONFIG_FRAME_SUPERRES
cm->superres_scale_numerator = SUPERRES_SCALE_DENOMINATOR;
cm->superres_upscaled_width = oxcf->scaled_frame_width;
cm->superres_upscaled_height = oxcf->scaled_frame_height;
cm->superres_upscaled_width = oxcf->width;
cm->superres_upscaled_height = oxcf->height;
#endif // CONFIG_FRAME_SUPERRES
#if CONFIG_LOOP_RESTORATION
av1_loop_restoration_precal();
......@@ -3845,21 +3845,22 @@ static void set_frame_size(AV1_COMP *cpi, int width, int height) {
}
static void setup_frame_size(AV1_COMP *cpi) {
int encode_width;
int encode_height;
int encode_width = cpi->oxcf.width;
int encode_height = cpi->oxcf.height;
av1_calculate_next_scaled_size(cpi, &encode_width, &encode_height);
printf("encode size: %dx%d ", encode_width, encode_height);
uint8_t resize_num = av1_calculate_next_resize_scale(cpi);
av1_calculate_scaled_size(&encode_width, &encode_height, resize_num,
RESIZE_SCALE_DENOMINATOR);
#if CONFIG_FRAME_SUPERRES
AV1_COMMON *cm = &cpi->common;
cm->superres_upscaled_width = encode_width;
cm->superres_upscaled_height = encode_height;
cm->superres_scale_numerator = (uint8_t)av1_calculate_next_superres_scale(
cpi, encode_width, encode_width);
av1_calculate_superres_size(cm, &encode_width, &encode_height);
// printf("Resize/superres %d x %d -> %d x %d\n", encode_width, encode_height,
// cm->superres_upscaled_width, cm->superres_upscaled_height);
cm->superres_scale_numerator =
av1_calculate_next_superres_scale(cpi, encode_width, encode_width);
av1_calculate_scaled_size(&encode_width, &encode_height,
cm->superres_scale_numerator,
SUPERRES_SCALE_DENOMINATOR);
printf("superres numerator: %02d ", cm->superres_scale_numerator);
#endif // CONFIG_FRAME_SUPERRES
printf("Final encode size: %dx%d\n", encode_width, encode_height);
......
......@@ -129,7 +129,7 @@ typedef enum {
RESIZE_NONE = 0, // No frame resizing allowed.
RESIZE_FIXED = 1, // All frames are coded at the specified dimension.
RESIZE_DYNAMIC = 2 // Coded size of each frame is determined by the codec.
} RESIZE_TYPE;
} RESIZE_MODE;
#if CONFIG_FRAME_SUPERRES
typedef enum {
SUPERRES_NONE = 0,
......@@ -207,9 +207,8 @@ typedef struct AV1EncoderConfig {
unsigned int disable_tempmv;
#endif
// Internal frame size scaling.
RESIZE_TYPE resize_mode;
int scaled_frame_width;
int scaled_frame_height;
RESIZE_MODE resize_mode;
uint8_t resize_scale_numerator;
#if CONFIG_FRAME_SUPERRES
// Frame Super-Resolution size scaling.
......
......@@ -1669,44 +1669,35 @@ static unsigned int lcg_rand16(unsigned int *state) {
return *state / 65536 % 32768;
}
void av1_calculate_next_scaled_size(AV1_COMP *cpi, int *width, int *height) {
uint8_t av1_calculate_next_resize_scale(const AV1_COMP *cpi) {
static unsigned int seed = 56789;
AV1EncoderConfig *oxcf = &cpi->oxcf;
// TODO(afergs): Get width from frame instead?
*width = oxcf->width;
*height = oxcf->height;
if (oxcf->pass == 1) return;
if (oxcf->resize_mode == RESIZE_FIXED) {
*width = oxcf->scaled_frame_width;
*height = oxcf->scaled_frame_height;
return;
}
if (oxcf->resize_mode == RESIZE_DYNAMIC) {
// NOTE: RESIZE_DYNAMIC defaults to random now.
if (oxcf->pass == 2 || oxcf->pass == 0) {
int scale_num = lcg_rand16(&seed) % 4 + 13;
int scale_den = 16;
if (!(cpi->oxcf.width * scale_num / scale_den * 2 < oxcf->width ||
cpi->oxcf.height * scale_num / scale_den * 2 < oxcf->height)) {
*width = cpi->oxcf.width * scale_num / scale_den;
*height = cpi->oxcf.height * scale_num / scale_den;
}
}
const AV1EncoderConfig *oxcf = &cpi->oxcf;
if (oxcf->pass == 1) return RESIZE_SCALE_DENOMINATOR;
uint8_t new_num = RESIZE_SCALE_DENOMINATOR;
switch (oxcf->resize_mode) {
case RESIZE_NONE: new_num = RESIZE_SCALE_DENOMINATOR; break;
case RESIZE_FIXED: new_num = oxcf->resize_scale_numerator; break;
case RESIZE_DYNAMIC:
// RESIZE_DYNAMIC: Just random for now.
new_num = lcg_rand16(&seed) % 4 + 13;
break;
default: assert(0);
}
return new_num;
}
#if CONFIG_FRAME_SUPERRES
// TODO(afergs): Rename av1_rc_update_superres_scale(...)?
int av1_calculate_next_superres_scale(const AV1_COMP *cpi, int width,
int height) {
uint8_t av1_calculate_next_superres_scale(const AV1_COMP *cpi, int width,
int height) {
static unsigned int seed = 34567;
const AV1EncoderConfig *oxcf = &cpi->oxcf;
if (oxcf->pass == 1) return SUPERRES_SCALE_DENOMINATOR;
uint8_t new_num = cpi->common.superres_scale_numerator;
uint8_t new_num = SUPERRES_SCALE_DENOMINATOR;
switch (oxcf->superres_mode) {
case SUPERRES_NONE: return SUPERRES_SCALE_DENOMINATOR; break;
case SUPERRES_NONE: new_num = SUPERRES_SCALE_DENOMINATOR; break;
case SUPERRES_FIXED: new_num = oxcf->superres_scale_numerator; break;
case SUPERRES_DYNAMIC:
// SUPERRES_DYNAMIC: Just random for now.
......
......@@ -256,11 +256,10 @@ void av1_set_target_rate(struct AV1_COMP *cpi);
int av1_resize_one_pass_cbr(struct AV1_COMP *cpi);
void av1_calculate_next_scaled_size(struct AV1_COMP *cpi, int *width,
int *height);
uint8_t av1_calculate_next_resize_scale(const struct AV1_COMP *cpi);
#if CONFIG_FRAME_SUPERRES
int av1_calculate_next_superres_scale(const struct AV1_COMP *cpi, int width,
int height);
uint8_t av1_calculate_next_superres_scale(const struct AV1_COMP *cpi, int width,
int height);
#endif // CONFIG_FRAME_SUPERRES
#ifdef __cplusplus
} // extern "C"
......
......@@ -108,7 +108,7 @@ TEST_P(ActiveMapRefreshTest, Test) {
cfg_.g_lag_in_frames = 0;
cfg_.g_profile = 1;
cfg_.rc_target_bitrate = 600;
cfg_.rc_resize_allowed = 0;
cfg_.rc_resize_mode = 0;
cfg_.rc_min_quantizer = 8;
cfg_.rc_max_quantizer = 30;
cfg_.g_pass = AOM_RC_ONE_PASS;
......
......@@ -73,7 +73,7 @@ class ActiveMapTest
// Validate that this non multiple of 64 wide clip encodes
cfg_.g_lag_in_frames = 0;
cfg_.rc_target_bitrate = 400;
cfg_.rc_resize_allowed = 0;
cfg_.rc_resize_mode = 0;
cfg_.g_pass = AOM_RC_ONE_PASS;
cfg_.rc_end_usage = AOM_CBR;
cfg_.kf_max_dist = 90000;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment