Add VP9 encoder API for level specification.

Add control API VP9E_SET_TARGET_LEVEL that allows the encoder to
control the output bitstream level and/or keep level related
statistics.

Usage:
               255         do not care about level (default)
               0           keep level related stats only
               10          target for level 1
               11          target for level 1.1
               .
               .
               .
               62          target for level 6.2

Usage for vpxenc:

--target-level=0/255/10/11...

Change-Id: I31d1aeca19358b893e7577b4e63748c8e614034a
This commit is contained in:
hui su 2016-05-05 15:37:37 -07:00
parent e2b696c390
commit be3f0698b0
8 changed files with 73 additions and 4 deletions

View File

@ -67,6 +67,24 @@ static INLINE int get_unsigned_bits(unsigned int num_values) {
#define VP9_FRAME_MARKER 0x2
typedef enum {
LEVEL_UNKNOWN = 0,
LEVEL_1 = 10,
LEVEL_1_1 = 11,
LEVEL_2 = 20,
LEVEL_2_1 = 21,
LEVEL_3 = 30,
LEVEL_3_1 = 31,
LEVEL_4 = 40,
LEVEL_4_1 = 41,
LEVEL_5 = 50,
LEVEL_5_1 = 51,
LEVEL_5_2 = 52,
LEVEL_6 = 60,
LEVEL_6_1 = 61,
LEVEL_6_2 = 62,
LEVEL_NOT_CARE = 255,
} VP9_LEVEL;
#ifdef __cplusplus
} // extern "C"

View File

@ -168,6 +168,8 @@ typedef struct VP9Common {
int allow_high_precision_mv;
int keep_level_stats;
// Flag signaling that the frame context should be reset to default values.
// 0 or 1 implies don't reset, 2 reset just the context specified in the
// frame header, 3 reset all contexts.

View File

@ -4035,7 +4035,6 @@ static void encode_frame_internal(VP9_COMP *cpi) {
rdc->m_search_count = 0; // Count of motion search hits.
rdc->ex_search_count = 0; // Exhaustive mesh search hits.
xd->lossless = cm->base_qindex == 0 &&
cm->y_dc_delta_q == 0 &&
cm->uv_dc_delta_q == 0 &&

View File

@ -774,7 +774,6 @@ static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) {
cpi->oxcf = *oxcf;
cpi->framerate = oxcf->init_framerate;
cm->profile = oxcf->profile;
cm->bit_depth = oxcf->bit_depth;
#if CONFIG_VP9_HIGHBITDEPTH
@ -783,6 +782,9 @@ static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) {
cm->color_space = oxcf->color_space;
cm->color_range = oxcf->color_range;
cpi->target_level = oxcf->target_level;
cm->keep_level_stats = oxcf->target_level != LEVEL_NOT_CARE;
cm->width = oxcf->width;
cm->height = oxcf->height;
alloc_compressor_data(cpi);
@ -1473,6 +1475,9 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
cm->color_space = oxcf->color_space;
cm->color_range = oxcf->color_range;
cpi->target_level = oxcf->target_level;
cm->keep_level_stats = oxcf->target_level != LEVEL_NOT_CARE;
if (cm->profile <= PROFILE_1)
assert(cm->bit_depth == VPX_BITS_8);
else

View File

@ -227,6 +227,8 @@ typedef struct VP9EncoderConfig {
int max_threads;
int target_level;
vpx_fixed_buf_t two_pass_stats_in;
struct vpx_codec_pkt_list *output_pkt_list;
@ -497,6 +499,8 @@ typedef struct VP9_COMP {
int use_skin_detection;
int target_level;
NOISE_ESTIMATE noise_estimate;
// Count on how many consecutive times a block uses small/zeromv for encoding.

View File

@ -40,6 +40,7 @@ struct vp9_extracfg {
unsigned int rc_max_inter_bitrate_pct;
unsigned int gf_cbr_boost_pct;
unsigned int lossless;
unsigned int target_level;
unsigned int frame_parallel_decoding_mode;
AQ_MODE aq_mode;
unsigned int frame_periodic_boost;
@ -69,6 +70,7 @@ static struct vp9_extracfg default_extra_cfg = {
0, // rc_max_inter_bitrate_pct
0, // gf_cbr_boost_pct
0, // lossless
255, // target_level
1, // frame_parallel_decoding_mode
NO_AQ, // aq_mode
0, // frame_periodic_delta_q
@ -196,6 +198,17 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
RANGE_CHECK(cfg, ss_number_layers, 1, VPX_SS_MAX_LAYERS);
RANGE_CHECK(cfg, ts_number_layers, 1, VPX_TS_MAX_LAYERS);
{
unsigned int level = extra_cfg->target_level;
if (level != LEVEL_1 && level != LEVEL_1_1 && level != LEVEL_2 &&
level != LEVEL_2_1 && level != LEVEL_3 && level != LEVEL_3_1 &&
level != LEVEL_4 && level != LEVEL_4_1 && level != LEVEL_5 &&
level != LEVEL_5_1 && level != LEVEL_5_2 && level != LEVEL_6 &&
level != LEVEL_6_1 && level != LEVEL_6_2 &&
level != LEVEL_UNKNOWN && level != LEVEL_NOT_CARE)
ERROR("target_level is invalid");
}
if (cfg->ss_number_layers * cfg->ts_number_layers > VPX_MAX_LAYERS)
ERROR("ss_number_layers * ts_number_layers is out of range");
if (cfg->ts_number_layers > 1) {
@ -509,6 +522,8 @@ static vpx_codec_err_t set_encoder_config(
oxcf->temporal_layering_mode = (enum vp9e_temporal_layering_mode)
cfg->temporal_layering_mode;
oxcf->target_level = extra_cfg->target_level;
for (sl = 0; sl < oxcf->ss_number_layers; ++sl) {
#if CONFIG_SPATIAL_SVC
oxcf->ss_enable_auto_arf[sl] = cfg->ss_enable_auto_alt_ref[sl];
@ -535,6 +550,7 @@ static vpx_codec_err_t set_encoder_config(
/*
printf("Current VP9 Settings: \n");
printf("target_bandwidth: %d\n", oxcf->target_bandwidth);
printf("target_level: %d\n", oxcf->target_level);
printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity);
printf("sharpness: %d\n", oxcf->sharpness);
printf("cpu_used: %d\n", oxcf->cpu_used);
@ -784,6 +800,13 @@ static vpx_codec_err_t ctrl_set_frame_periodic_boost(vpx_codec_alg_priv_t *ctx,
return update_extra_cfg(ctx, &extra_cfg);
}
static vpx_codec_err_t ctrl_set_target_level(vpx_codec_alg_priv_t *ctx,
va_list args) {
struct vp9_extracfg extra_cfg = ctx->extra_cfg;
extra_cfg.target_level = CAST(VP9E_SET_LEVEL_STATS, args);
return update_extra_cfg(ctx, &extra_cfg);
}
static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx,
vpx_codec_priv_enc_mr_cfg_t *data) {
vpx_codec_err_t res = VPX_CODEC_OK;
@ -1516,6 +1539,7 @@ static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = {
{VP9E_SET_MAX_GF_INTERVAL, ctrl_set_max_gf_interval},
{VP9E_SET_SVC_REF_FRAME_CONFIG, ctrl_set_svc_ref_frame_config},
{VP9E_SET_RENDER_SIZE, ctrl_set_render_size},
{VP9E_SET_TARGET_LEVEL, ctrl_set_target_level},
// Getters
{VP8E_GET_LAST_QUANTIZER, ctrl_get_quantizer},

View File

@ -554,6 +554,15 @@ enum vp8e_enc_control_id {
* Supported in codecs: VP9
*/
VP9E_SET_RENDER_SIZE,
/*!\brief Codec control function to set target level.
*
* 255: off (default); 0: only keep level stats; 10: target for level 1.0;
* 11: target for level 1.1; ... 62: target for level 6.2
*
* Supported in codecs: VP9
*/
VP9E_SET_TARGET_LEVEL,
};
/*!\brief vpx 1-D scaling mode
@ -809,6 +818,9 @@ VPX_CTRL_USE_TYPE(VP9E_SET_SVC_REF_FRAME_CONFIG, vpx_svc_ref_frame_config_t *)
VPX_CTRL_USE_TYPE(VP9E_SET_RENDER_SIZE, int *)
#define VPX_CTRL_VP9E_SET_RENDER_SIZE
VPX_CTRL_USE_TYPE(VP9E_SET_LEVEL_STATS, unsigned int)
#define VPX_CTRL_VP9E_SET_LEVEL_STATS
/*!\endcond */
/*! @} - end defgroup vp8_encoder */
#ifdef __cplusplus

View File

@ -444,6 +444,11 @@ static const struct arg_enum_list tune_content_enum[] = {
static const arg_def_t tune_content = ARG_DEF_ENUM(
NULL, "tune-content", 1, "Tune content type", tune_content_enum);
static const arg_def_t target_level = ARG_DEF(
NULL, "target-level", 1,
"Target level (255: off (default); 0: only keep level stats; 10: level 1.0;"
" 11: level 1.1; ... 62: level 6.2)");
#endif
#if CONFIG_VP9_ENCODER
@ -454,7 +459,7 @@ static const arg_def_t *vp9_args[] = {
&gf_cbr_boost_pct, &lossless,
&frame_parallel_decoding, &aq_mode, &frame_periodic_boost,
&noise_sens, &tune_content, &input_color_space,
&min_gf_interval, &max_gf_interval,
&min_gf_interval, &max_gf_interval, &target_level,
#if CONFIG_VP9_HIGHBITDEPTH
&bitdeptharg, &inbitdeptharg,
#endif // CONFIG_VP9_HIGHBITDEPTH
@ -470,7 +475,7 @@ static const int vp9_arg_ctrl_map[] = {
VP9E_SET_LOSSLESS, VP9E_SET_FRAME_PARALLEL_DECODING, VP9E_SET_AQ_MODE,
VP9E_SET_FRAME_PERIODIC_BOOST, VP9E_SET_NOISE_SENSITIVITY,
VP9E_SET_TUNE_CONTENT, VP9E_SET_COLOR_SPACE,
VP9E_SET_MIN_GF_INTERVAL, VP9E_SET_MAX_GF_INTERVAL,
VP9E_SET_MIN_GF_INTERVAL, VP9E_SET_MAX_GF_INTERVAL, VP9E_SET_TARGET_LEVEL,
0
};
#endif