Commit 41b451eb authored by Minghai Shang's avatar Minghai Shang

[spatial svc]Remove key frame quantizer settings since key frame is decided by rate control

Change-Id: I7eda0f5e678034f0e9c2ab481c517d2e9b280eb5
parent e319e4bf
......@@ -58,9 +58,6 @@ static const arg_def_t quantizers_arg =
ARG_DEF("q", "quantizers", 1, "quantizers for non key frames, also will "
"be applied to key frames if -qn is not specified (lowest to "
"highest layer)");
static const arg_def_t quantizers_keyframe_arg =
ARG_DEF("qn", "quantizers-keyframe", 1, "quantizers for key frames (lowest "
"to highest layer)");
static const arg_def_t passes_arg =
ARG_DEF("p", "passes", 1, "Number of passes (1/2)");
static const arg_def_t pass_arg =
......@@ -79,10 +76,9 @@ static const arg_def_t max_bitrate_arg =
static const arg_def_t *svc_args[] = {
&encoding_mode_arg, &frames_arg, &width_arg, &height_arg,
&timebase_arg, &bitrate_arg, &skip_frames_arg, &layers_arg,
&kf_dist_arg, &scale_factors_arg, &quantizers_arg,
&quantizers_keyframe_arg, &passes_arg, &pass_arg,
&fpf_name_arg, &min_q_arg, &max_q_arg, &min_bitrate_arg,
&max_bitrate_arg, NULL
&kf_dist_arg, &scale_factors_arg, &quantizers_arg, &passes_arg,
&pass_arg, &fpf_name_arg, &min_q_arg, &max_q_arg,
&min_bitrate_arg, &max_bitrate_arg, NULL
};
static const SVC_ENCODING_MODE default_encoding_mode =
......@@ -183,9 +179,7 @@ static void parse_command_line(int argc, const char **argv_,
} else if (arg_match(&arg, &scale_factors_arg, argi)) {
vpx_svc_set_scale_factors(svc_ctx, arg.val);
} else if (arg_match(&arg, &quantizers_arg, argi)) {
vpx_svc_set_quantizers(svc_ctx, arg.val, 0);
} else if (arg_match(&arg, &quantizers_keyframe_arg, argi)) {
vpx_svc_set_quantizers(svc_ctx, arg.val, 1);
vpx_svc_set_quantizers(svc_ctx, arg.val);
} else if (arg_match(&arg, &passes_arg, argi)) {
passes = arg_parse_uint(&arg);
if (passes < 1 || passes > 2) {
......
......@@ -177,48 +177,20 @@ TEST_F(SvcTest, SetQuantizersOption) {
codec_initialized_ = true;
}
TEST_F(SvcTest, SetKeyFrameQuantizersOption) {
svc_.spatial_layers = 2;
vpx_codec_err_t res = vpx_svc_set_options(&svc_,
"quantizers-keyframe=not-quantizers");
EXPECT_EQ(VPX_CODEC_OK, res);
res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
vpx_svc_set_options(&svc_, "quantizers-keyframe=40,45");
res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
EXPECT_EQ(VPX_CODEC_OK, res);
codec_initialized_ = true;
}
TEST_F(SvcTest, SetQuantizers) {
vpx_codec_err_t res = vpx_svc_set_quantizers(NULL, "40,30", 0);
vpx_codec_err_t res = vpx_svc_set_quantizers(NULL, "40,30");
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
res = vpx_svc_set_quantizers(&svc_, NULL, 0);
res = vpx_svc_set_quantizers(&svc_, NULL);
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
svc_.spatial_layers = 2;
res = vpx_svc_set_quantizers(&svc_, "40", 0);
res = vpx_svc_set_quantizers(&svc_, "40");
EXPECT_EQ(VPX_CODEC_OK, res);
res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
res = vpx_svc_set_quantizers(&svc_, "40,30", 0);
EXPECT_EQ(VPX_CODEC_OK, res);
res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
EXPECT_EQ(VPX_CODEC_OK, res);
codec_initialized_ = true;
}
TEST_F(SvcTest, SetKeyFrameQuantizers) {
vpx_codec_err_t res = vpx_svc_set_quantizers(NULL, "40,31", 1);
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
res = vpx_svc_set_quantizers(&svc_, NULL, 1);
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
res = vpx_svc_set_quantizers(&svc_, "40,30", 1);
res = vpx_svc_set_quantizers(&svc_, "40,30");
EXPECT_EQ(VPX_CODEC_OK, res);
res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
EXPECT_EQ(VPX_CODEC_OK, res);
......@@ -249,7 +221,7 @@ TEST_F(SvcTest, SetScaleFactors) {
TEST_F(SvcTest, FirstFrameHasLayers) {
svc_.spatial_layers = 2;
vpx_svc_set_scale_factors(&svc_, "4/16,16/16");
vpx_svc_set_quantizers(&svc_, "40,30", 0);
vpx_svc_set_quantizers(&svc_, "40,30");
vpx_codec_err_t res =
vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
......@@ -284,7 +256,7 @@ TEST_F(SvcTest, FirstFrameHasLayers) {
TEST_F(SvcTest, EncodeThreeFrames) {
svc_.spatial_layers = 2;
vpx_svc_set_scale_factors(&svc_, "4/16,16/16");
vpx_svc_set_quantizers(&svc_, "40,30", 0);
vpx_svc_set_quantizers(&svc_, "40,30");
int decoded_frames = 0;
vpx_codec_err_t res_dec;
int frame_size;
......@@ -360,7 +332,7 @@ TEST_F(SvcTest, EncodeThreeFrames) {
TEST_F(SvcTest, GetLayerResolution) {
svc_.spatial_layers = 2;
vpx_svc_set_scale_factors(&svc_, "4/16,8/16");
vpx_svc_set_quantizers(&svc_, "40,30", 0);
vpx_svc_set_quantizers(&svc_, "40,30");
vpx_codec_err_t res =
vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
......@@ -399,7 +371,7 @@ TEST_F(SvcTest, TwoPassEncode) {
svc_.spatial_layers = 2;
codec_enc_.g_pass = VPX_RC_FIRST_PASS;
vpx_svc_set_scale_factors(&svc_, "4/16,16/16");
vpx_svc_set_quantizers(&svc_, "40,30", 0);
vpx_svc_set_quantizers(&svc_, "40,30");
vpx_codec_err_t res =
vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
......
......@@ -59,14 +59,11 @@ typedef struct FrameData {
typedef struct SvcInternal {
char options[OPTION_BUFFER_SIZE]; // set by vpx_svc_set_options
char quantizers[OPTION_BUFFER_SIZE]; // set by vpx_svc_set_quantizers
char quantizers_keyframe[OPTION_BUFFER_SIZE]; // set by
// vpx_svc_set_quantizers
char scale_factors[OPTION_BUFFER_SIZE]; // set by vpx_svc_set_scale_factors
// values extracted from option, quantizers
int scaling_factor_num[VPX_SS_MAX_LAYERS];
int scaling_factor_den[VPX_SS_MAX_LAYERS];
int quantizer_keyframe[VPX_SS_MAX_LAYERS];
int quantizer[VPX_SS_MAX_LAYERS];
// accumulated statistics
......@@ -215,8 +212,7 @@ static vpx_codec_err_t set_option_encoding_mode(SvcContext *svc_ctx,
}
static vpx_codec_err_t parse_quantizer_values(SvcContext *svc_ctx,
const char *quantizer_values,
const int is_keyframe) {
const char *quantizer_values) {
char *input_string;
char *token;
const char *delim = ",";
......@@ -227,11 +223,6 @@ static vpx_codec_err_t parse_quantizer_values(SvcContext *svc_ctx,
SvcInternal *const si = get_svc_internal(svc_ctx);
if (quantizer_values == NULL || strlen(quantizer_values) == 0) {
if (is_keyframe) {
// If there non settings for key frame, we will apply settings from
// non key frame. So just simply return here.
return VPX_CODEC_INVALID_PARAM;
}
input_string = strdup(DEFAULT_QUANTIZER_VALUES);
} else {
input_string = strdup(quantizer_values);
......@@ -252,12 +243,7 @@ static vpx_codec_err_t parse_quantizer_values(SvcContext *svc_ctx,
} else {
q = 0;
}
if (is_keyframe) {
si->quantizer_keyframe[i + VPX_SS_MAX_LAYERS - svc_ctx->spatial_layers]
= q;
} else {
si->quantizer[i + VPX_SS_MAX_LAYERS - svc_ctx->spatial_layers] = q;
}
si->quantizer[i + VPX_SS_MAX_LAYERS - svc_ctx->spatial_layers] = q;
}
if (res == VPX_CODEC_OK && found != svc_ctx->spatial_layers) {
svc_log(svc_ctx, SVC_LOG_ERROR,
......@@ -342,7 +328,6 @@ static vpx_codec_err_t parse_options(SvcContext *svc_ctx, const char *options) {
char *option_name;
char *option_value;
char *input_ptr;
int is_keyframe_qaunt_set = 0;
vpx_codec_err_t res = VPX_CODEC_OK;
if (options == NULL) return VPX_CODEC_OK;
......@@ -368,17 +353,8 @@ static vpx_codec_err_t parse_options(SvcContext *svc_ctx, const char *options) {
res = parse_scale_factors(svc_ctx, option_value);
if (res != VPX_CODEC_OK) break;
} else if (strcmp("quantizers", option_name) == 0) {
res = parse_quantizer_values(svc_ctx, option_value, 0);
if (res != VPX_CODEC_OK) break;
if (!is_keyframe_qaunt_set) {
SvcInternal *const si = get_svc_internal(svc_ctx);
memcpy(get_svc_internal(svc_ctx)->quantizer_keyframe, si->quantizer,
sizeof(si->quantizer));
}
} else if (strcmp("quantizers-keyframe", option_name) == 0) {
res = parse_quantizer_values(svc_ctx, option_value, 1);
res = parse_quantizer_values(svc_ctx, option_value);
if (res != VPX_CODEC_OK) break;
is_keyframe_qaunt_set = 1;
} else {
svc_log(svc_ctx, SVC_LOG_ERROR, "invalid option: %s\n", option_name);
res = VPX_CODEC_INVALID_PARAM;
......@@ -401,19 +377,13 @@ vpx_codec_err_t vpx_svc_set_options(SvcContext *svc_ctx, const char *options) {
}
vpx_codec_err_t vpx_svc_set_quantizers(SvcContext *svc_ctx,
const char *quantizers,
const int is_for_keyframe) {
const char *quantizers) {
SvcInternal *const si = get_svc_internal(svc_ctx);
if (svc_ctx == NULL || quantizers == NULL || si == NULL) {
return VPX_CODEC_INVALID_PARAM;
}
if (is_for_keyframe) {
strncpy(si->quantizers_keyframe, quantizers, sizeof(si->quantizers));
si->quantizers_keyframe[sizeof(si->quantizers_keyframe) - 1] = '\0';
} else {
strncpy(si->quantizers, quantizers, sizeof(si->quantizers));
si->quantizers[sizeof(si->quantizers) - 1] = '\0';
}
strncpy(si->quantizers, quantizers, sizeof(si->quantizers));
si->quantizers[sizeof(si->quantizers) - 1] = '\0';
return VPX_CODEC_OK;
}
......@@ -460,13 +430,9 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
return VPX_CODEC_INVALID_PARAM;
}
res = parse_quantizer_values(svc_ctx, si->quantizers, 0);
res = parse_quantizer_values(svc_ctx, si->quantizers);
if (res != VPX_CODEC_OK) return res;
res = parse_quantizer_values(svc_ctx, si->quantizers_keyframe, 1);
if (res != VPX_CODEC_OK)
memcpy(si->quantizer_keyframe, si->quantizer, sizeof(si->quantizer));
res = parse_scale_factors(svc_ctx, si->scale_factors);
if (res != VPX_CODEC_OK) return res;
......@@ -741,13 +707,8 @@ static void set_svc_parameters(SvcContext *svc_ctx,
layer_index = layer + VPX_SS_MAX_LAYERS - si->layers;
if (codec_ctx->config.enc->g_pass == VPX_RC_ONE_PASS) {
if (vpx_svc_is_keyframe(svc_ctx)) {
svc_params.min_quantizer = si->quantizer_keyframe[layer_index];
svc_params.max_quantizer = si->quantizer_keyframe[layer_index];
} else {
svc_params.min_quantizer = si->quantizer[layer_index];
svc_params.max_quantizer = si->quantizer[layer_index];
}
svc_params.min_quantizer = si->quantizer[layer_index];
svc_params.max_quantizer = si->quantizer[layer_index];
} else {
svc_params.min_quantizer = codec_ctx->config.enc->rc_min_quantizer;
svc_params.max_quantizer = codec_ctx->config.enc->rc_max_quantizer;
......
......@@ -64,8 +64,7 @@ vpx_codec_err_t vpx_svc_set_options(SvcContext *svc_ctx, const char *options);
* e.g., "60,53,39,33,27"
*/
vpx_codec_err_t vpx_svc_set_quantizers(SvcContext *svc_ctx,
const char *quantizer_values,
const int is_for_keyframe);
const char *quantizer_values);
/**
* Set SVC scale factors
......
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