Merge "vp9: Fix to SVC and denoising for fixed pattern case."

This commit is contained in:
Marco Paniconi 2017-07-12 19:13:05 +00:00 committed by Gerrit Code Review
commit f6586b8bf8
3 changed files with 55 additions and 17 deletions

View File

@ -420,12 +420,23 @@ static void swap_frame_buffer(YV12_BUFFER_CONFIG *const dest,
src->y_buffer = tmp_buf; src->y_buffer = tmp_buf;
} }
void vp9_denoiser_update_frame_info(VP9_DENOISER *denoiser, void vp9_denoise_init_svc(VP9_COMP *cpi) {
YV12_BUFFER_CONFIG src, // For fixed pattern SVC, on base temporal layer. Note we only denoise
FRAME_TYPE frame_type, // higher spatial layer for SVC.
int refresh_golden_frame, if (cpi->svc.temporal_layering_mode != VP9E_TEMPORAL_LAYERING_MODE_BYPASS &&
int refresh_last_frame, int resized, cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1 &&
int svc_base_is_key) { cpi->svc.temporal_layer_id == 0) {
VP9_DENOISER *denoiser = &cpi->denoiser;
copy_frame(&denoiser->running_avg_y[LAST_FRAME],
&denoiser->running_avg_y[GOLDEN_FRAME]);
}
}
void vp9_denoiser_update_frame_info(
VP9_DENOISER *denoiser, YV12_BUFFER_CONFIG src, FRAME_TYPE frame_type,
int refresh_alt_ref_frame, int refresh_golden_frame, int refresh_last_frame,
int resized, int svc_base_is_key, int svc_fixed_pattern,
int temporal_layer_id) {
// Copy source into denoised reference buffers on KEY_FRAME or // Copy source into denoised reference buffers on KEY_FRAME or
// if the just encoded frame was resized. For SVC, copy source if the base // if the just encoded frame was resized. For SVC, copy source if the base
// spatial layer was key frame. // spatial layer was key frame.
@ -440,12 +451,15 @@ void vp9_denoiser_update_frame_info(VP9_DENOISER *denoiser,
} }
// If more than one refresh occurs, must copy frame buffer. // If more than one refresh occurs, must copy frame buffer.
if (refresh_golden_frame + refresh_last_frame > 1) { if (refresh_golden_frame + refresh_last_frame + refresh_alt_ref_frame > 1) {
if (refresh_golden_frame) { if (refresh_golden_frame) {
copy_frame(&denoiser->running_avg_y[GOLDEN_FRAME], copy_frame(&denoiser->running_avg_y[GOLDEN_FRAME],
&denoiser->running_avg_y[INTRA_FRAME]); &denoiser->running_avg_y[INTRA_FRAME]);
} }
if (refresh_last_frame) { // For fixed pattern SVC: update denoised last_frame if alt_ref is
// refreshed, only for non-zero temporal layer.
if (refresh_last_frame ||
(refresh_alt_ref_frame && svc_fixed_pattern && temporal_layer_id > 0)) {
copy_frame(&denoiser->running_avg_y[LAST_FRAME], copy_frame(&denoiser->running_avg_y[LAST_FRAME],
&denoiser->running_avg_y[INTRA_FRAME]); &denoiser->running_avg_y[INTRA_FRAME]);
} }
@ -454,11 +468,24 @@ void vp9_denoiser_update_frame_info(VP9_DENOISER *denoiser,
swap_frame_buffer(&denoiser->running_avg_y[GOLDEN_FRAME], swap_frame_buffer(&denoiser->running_avg_y[GOLDEN_FRAME],
&denoiser->running_avg_y[INTRA_FRAME]); &denoiser->running_avg_y[INTRA_FRAME]);
} }
if (refresh_last_frame) { // For fixed pattern SVC: update denoised last_frame if alt_ref is
// refreshed, only for non-zero temporal layer.
if (refresh_last_frame ||
(refresh_alt_ref_frame && svc_fixed_pattern && temporal_layer_id > 0)) {
swap_frame_buffer(&denoiser->running_avg_y[LAST_FRAME], swap_frame_buffer(&denoiser->running_avg_y[LAST_FRAME],
&denoiser->running_avg_y[INTRA_FRAME]); &denoiser->running_avg_y[INTRA_FRAME]);
} }
} }
// For fixed pattern SVC we need to keep track of denoised last_frame for base
// temporal layer (since alt_ref refresh may update denoised last_frame on
// the upper/middle temporal layers).We do this by copying the current
// denoised last into the denoised golden_frame, for temporal_layer_id = 0.
// For the fixed pattern SVC golden is always spatial reference and is never
// used for denoising, so we can use it to keep track of denoised last_frame.
if (svc_fixed_pattern && temporal_layer_id == 0) {
copy_frame(&denoiser->running_avg_y[GOLDEN_FRAME],
&denoiser->running_avg_y[LAST_FRAME]);
}
} }
void vp9_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx) { void vp9_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx) {

View File

@ -62,12 +62,13 @@ typedef struct {
struct VP9_COMP; struct VP9_COMP;
void vp9_denoiser_update_frame_info(VP9_DENOISER *denoiser, void vp9_denoise_init_svc(struct VP9_COMP *cpi);
YV12_BUFFER_CONFIG src,
FRAME_TYPE frame_type, void vp9_denoiser_update_frame_info(
int refresh_golden_frame, VP9_DENOISER *denoiser, YV12_BUFFER_CONFIG src, FRAME_TYPE frame_type,
int refresh_last_frame, int resized, int refresh_alt_ref_frame, int refresh_golden_frame, int refresh_last_frame,
int svc_base_is_key); int resized, int svc_base_is_key, int svc_fixed_pattern,
int temporal_layer_id);
void vp9_denoiser_denoise(struct VP9_COMP *cpi, MACROBLOCK *mb, int mi_row, void vp9_denoiser_denoise(struct VP9_COMP *cpi, MACROBLOCK *mb, int mi_row,
int mi_col, BLOCK_SIZE bs, PICK_MODE_CONTEXT *ctx, int mi_col, BLOCK_SIZE bs, PICK_MODE_CONTEXT *ctx,

View File

@ -2806,17 +2806,21 @@ void vp9_update_reference_frames(VP9_COMP *cpi) {
if (cpi->oxcf.noise_sensitivity > 0 && denoise_svc(cpi) && if (cpi->oxcf.noise_sensitivity > 0 && denoise_svc(cpi) &&
cpi->denoiser.denoising_level > kDenLowLow) { cpi->denoiser.denoising_level > kDenLowLow) {
int svc_base_is_key = 0; int svc_base_is_key = 0;
int svc_fixed_pattern = 0;
if (cpi->use_svc) { if (cpi->use_svc) {
int layer = LAYER_IDS_TO_IDX(cpi->svc.spatial_layer_id, int layer = LAYER_IDS_TO_IDX(cpi->svc.spatial_layer_id,
cpi->svc.temporal_layer_id, cpi->svc.temporal_layer_id,
cpi->svc.number_temporal_layers); cpi->svc.number_temporal_layers);
LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer]; LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer];
svc_base_is_key = lc->is_key_frame; svc_base_is_key = lc->is_key_frame;
svc_fixed_pattern = (cpi->svc.temporal_layering_mode !=
VP9E_TEMPORAL_LAYERING_MODE_BYPASS);
} }
vp9_denoiser_update_frame_info( vp9_denoiser_update_frame_info(
&cpi->denoiser, *cpi->Source, cpi->common.frame_type, &cpi->denoiser, *cpi->Source, cpi->common.frame_type,
cpi->refresh_golden_frame, cpi->refresh_last_frame, cpi->resize_pending, cpi->refresh_alt_ref_frame, cpi->refresh_golden_frame,
svc_base_is_key); cpi->refresh_last_frame, cpi->resize_pending, svc_base_is_key,
svc_fixed_pattern, cpi->svc.temporal_layer_id);
} }
#endif #endif
if (is_one_pass_cbr_svc(cpi)) { if (is_one_pass_cbr_svc(cpi)) {
@ -3448,6 +3452,12 @@ static void encode_without_recode_loop(VP9_COMP *cpi, size_t *size,
vp9_update_noise_estimate(cpi); vp9_update_noise_estimate(cpi);
#if CONFIG_VP9_TEMPORAL_DENOISING
if (cpi->oxcf.noise_sensitivity > 0 && cpi->use_svc &&
cpi->denoiser.denoising_level > kDenLowLow)
vp9_denoise_init_svc(cpi);
#endif
// Scene detection is always used for VBR mode or screen-content case. // Scene detection is always used for VBR mode or screen-content case.
// For other cases (e.g., CBR mode) use it for 5 <= speed < 8 for now // For other cases (e.g., CBR mode) use it for 5 <= speed < 8 for now
// (need to check encoding time cost for doing this for speed 8). // (need to check encoding time cost for doing this for speed 8).