Commit 390ad737 authored by Minghai Shang's avatar Minghai Shang

[spatial svc]Add is_spatial_svc() helper function.

Change-Id: Ice5376100d8e27cbdaddfd3cd06898cedd2720fe
parent 7ec06cdd
......@@ -26,7 +26,7 @@ static INLINE int vp9_preserve_existing_gf(VP9_COMP *cpi) {
return !cpi->multi_arf_allowed && cpi->refresh_golden_frame &&
cpi->rc.is_src_frame_alt_ref &&
(!cpi->use_svc || // Add spatial svc base layer case here
(cpi->svc.number_temporal_layers == 1 &&
(is_spatial_svc(cpi) &&
cpi->svc.spatial_layer_id == 0 &&
cpi->svc.layer_context[0].gold_ref_idx >=0 &&
cpi->oxcf.ss_play_alternate[0]));
......
......@@ -131,7 +131,7 @@ static void setup_frame(VP9_COMP *cpi) {
}
if (cm->frame_type == KEY_FRAME) {
if (!(cpi->use_svc && cpi->svc.number_temporal_layers == 1))
if (!is_spatial_svc(cpi))
cpi->refresh_golden_frame = 1;
cpi->refresh_alt_ref_frame = 1;
} else {
......@@ -477,7 +477,7 @@ static void update_frame_size(VP9_COMP *cpi) {
vp9_init_context_buffers(cm);
init_macroblockd(cm, xd);
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
if (is_spatial_svc(cpi)) {
if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer,
cm->width, cm->height,
cm->subsampling_x, cm->subsampling_y,
......@@ -1582,7 +1582,7 @@ void vp9_update_reference_frames(VP9_COMP *cpi) {
cpi->alt_fb_idx = cpi->gld_fb_idx;
cpi->gld_fb_idx = tmp;
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
if (is_spatial_svc(cpi)) {
cpi->svc.layer_context[0].gold_ref_idx = cpi->gld_fb_idx;
cpi->svc.layer_context[0].alt_ref_idx = cpi->alt_fb_idx;
}
......@@ -2006,7 +2006,7 @@ static void get_ref_frame_flags(VP9_COMP *cpi) {
cpi->ref_frame_flags &= ~VP9_GOLD_FLAG;
if (cpi->rc.frames_till_gf_update_due == INT_MAX &&
!(cpi->use_svc && cpi->svc.number_temporal_layers == 1))
!is_spatial_svc(cpi))
cpi->ref_frame_flags &= ~VP9_GOLD_FLAG;
if (cpi->alt_is_last)
......@@ -2052,9 +2052,7 @@ static void configure_skippable_frame(VP9_COMP *cpi) {
// according to the variance
SVC *const svc = &cpi->svc;
const int is_spatial_svc = (svc->number_spatial_layers > 1) &&
(svc->number_temporal_layers == 1);
TWO_PASS *const twopass = is_spatial_svc ?
TWO_PASS *const twopass = is_spatial_svc(cpi) ?
&svc->layer_context[svc->spatial_layer_id].twopass
: &cpi->twopass;
......@@ -2182,7 +2180,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
// Check if the current frame is skippable for the partition search in the
// second pass according to the first pass stats
if (cpi->pass == 2 &&
(!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) {
(!cpi->use_svc || is_spatial_svc(cpi))) {
configure_skippable_frame(cpi);
}
......@@ -2434,7 +2432,7 @@ int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags,
vpx_usec_timer_start(&timer);
#if CONFIG_SPATIAL_SVC
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1)
if (is_spatial_svc(cpi))
res = vp9_svc_lookahead_push(cpi, cpi->lookahead, sd, time_stamp, end_time,
frame_flags);
else
......@@ -2557,14 +2555,11 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
YV12_BUFFER_CONFIG *force_src_buffer = NULL;
MV_REFERENCE_FRAME ref_frame;
int arf_src_index;
const int is_spatial_svc = cpi->use_svc &&
(cpi->svc.number_temporal_layers == 1) &&
(cpi->svc.number_spatial_layers > 1);
if (!cpi)
return -1;
if (is_spatial_svc && cpi->pass == 2) {
if (is_spatial_svc(cpi) && cpi->pass == 2) {
#if CONFIG_SPATIAL_SVC
vp9_svc_lookahead_peek(cpi, cpi->lookahead, 0, 1);
#endif
......@@ -2591,7 +2586,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
assert(arf_src_index <= rc->frames_to_key);
#if CONFIG_SPATIAL_SVC
if (is_spatial_svc)
if (is_spatial_svc(cpi))
cpi->source = vp9_svc_lookahead_peek(cpi, cpi->lookahead,
arf_src_index, 0);
else
......@@ -2601,7 +2596,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
cpi->alt_ref_source = cpi->source;
#if CONFIG_SPATIAL_SVC
if (is_spatial_svc && cpi->svc.spatial_layer_id > 0) {
if (is_spatial_svc(cpi) && cpi->svc.spatial_layer_id > 0) {
int i;
// Reference a hidden frame from a lower layer
for (i = cpi->svc.spatial_layer_id - 1; i >= 0; --i) {
......@@ -2636,7 +2631,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
// Get last frame source.
if (cm->current_video_frame > 0) {
#if CONFIG_SPATIAL_SVC
if (is_spatial_svc)
if (is_spatial_svc(cpi))
cpi->last_source = vp9_svc_lookahead_peek(cpi, cpi->lookahead, -1, 0);
else
#endif
......@@ -2647,7 +2642,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
// Read in the source frame.
#if CONFIG_SPATIAL_SVC
if (is_spatial_svc)
if (is_spatial_svc(cpi))
cpi->source = vp9_svc_lookahead_pop(cpi, cpi->lookahead, flush);
else
#endif
......@@ -2763,13 +2758,13 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
}
if (cpi->pass == 1 &&
(!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) {
(!cpi->use_svc || is_spatial_svc(cpi))) {
const int lossless = is_lossless_requested(&cpi->oxcf);
cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4;
cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add;
vp9_first_pass(cpi);
} else if (cpi->pass == 2 &&
(!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) {
(!cpi->use_svc || is_spatial_svc(cpi))) {
Pass2Encode(cpi, size, dest, frame_flags);
} else if (cpi->use_svc) {
SvcEncode(cpi, size, dest, frame_flags);
......
......@@ -536,10 +536,16 @@ YV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm,
void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags);
static INLINE int is_spatial_svc(const struct VP9_COMP *const cpi) {
return cpi->use_svc &&
cpi->svc.number_temporal_layers == 1 &&
cpi->svc.number_spatial_layers > 1;
}
static INLINE int is_altref_enabled(const VP9_COMP *const cpi) {
return cpi->oxcf.mode != REALTIME && cpi->oxcf.lag_in_frames > 0 &&
(cpi->oxcf.play_alternate &&
(!(cpi->use_svc && cpi->svc.number_temporal_layers == 1) ||
(!is_spatial_svc(cpi) ||
cpi->oxcf.ss_play_alternate[cpi->svc.spatial_layer_id]));
}
......
......@@ -258,7 +258,7 @@ void vp9_init_first_pass(VP9_COMP *cpi) {
}
void vp9_end_first_pass(VP9_COMP *cpi) {
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
if (is_spatial_svc(cpi)) {
int i;
for (i = 0; i < cpi->svc.number_spatial_layers; ++i) {
output_stats(&cpi->svc.layer_context[i].twopass.total_stats,
......@@ -446,7 +446,7 @@ void vp9_first_pass(VP9_COMP *cpi) {
set_first_pass_params(cpi);
vp9_set_quantizer(cm, find_fp_qindex());
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
if (is_spatial_svc(cpi)) {
MV_REFERENCE_FRAME ref_frame = LAST_FRAME;
const YV12_BUFFER_CONFIG *scaled_ref_buf = NULL;
twopass = &cpi->svc.layer_context[cpi->svc.spatial_layer_id].twopass;
......@@ -615,8 +615,7 @@ void vp9_first_pass(VP9_COMP *cpi) {
&unscaled_last_source_buf_2d);
// TODO(pengchong): Replace the hard-coded threshold
if (raw_motion_error > 25 ||
(cpi->use_svc && cpi->svc.number_temporal_layers == 1)) {
if (raw_motion_error > 25 || is_spatial_svc(cpi)) {
// Test last reference frame using the previous best mv as the
// starting point (best reference) for the search.
first_pass_motion_search(cpi, x, &best_ref_mv.as_mv, &mv.as_mv,
......@@ -898,7 +897,7 @@ void vp9_first_pass(VP9_COMP *cpi) {
vp9_extend_frame_borders(new_yv12);
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
if (is_spatial_svc(cpi)) {
vp9_update_reference_frames(cpi);
} else {
// Swap frame pointers so last frame refers to the frame we just compressed.
......@@ -967,10 +966,8 @@ static int get_twopass_worst_quality(const VP9_COMP *cpi,
BPER_MB_NORMBITS) / num_mbs;
int q;
int is_svc_upper_layer = 0;
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1 &&
cpi->svc.spatial_layer_id > 0) {
if (is_spatial_svc(cpi) && cpi->svc.spatial_layer_id > 0)
is_svc_upper_layer = 1;
}
// Try and pick a max Q that will be high enough to encode the
// content at the given rate.
......@@ -2102,7 +2099,7 @@ void configure_buffer_updates(VP9_COMP *cpi) {
assert(0);
break;
}
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
if (is_spatial_svc(cpi)) {
if (cpi->svc.layer_context[cpi->svc.spatial_layer_id].gold_ref_idx < 0)
cpi->refresh_golden_frame = 0;
if (cpi->alt_ref_source == NULL)
......@@ -2121,9 +2118,8 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
int target_rate;
LAYER_CONTEXT *lc = NULL;
const int is_spatial_svc = (cpi->use_svc &&
cpi->svc.number_temporal_layers == 1);
if (is_spatial_svc) {
if (is_spatial_svc(cpi)) {
lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id];
frames_left = (int)(twopass->total_stats.count -
lc->current_video_frame_in_layer);
......@@ -2151,7 +2147,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
vp9_rc_set_frame_target(cpi, target_rate);
cm->frame_type = INTER_FRAME;
if (is_spatial_svc) {
if (is_spatial_svc(cpi)) {
if (cpi->svc.spatial_layer_id == 0) {
lc->is_key_frame = 0;
} else {
......@@ -2167,7 +2163,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
vp9_clear_system_state();
if (is_spatial_svc && twopass->kf_intra_err_min == 0) {
if (is_spatial_svc(cpi) && twopass->kf_intra_err_min == 0) {
twopass->kf_intra_err_min = KF_MB_INTRA_MIN * cpi->common.MBs;
twopass->gf_intra_err_min = GF_MB_INTRA_MIN * cpi->common.MBs;
}
......@@ -2175,7 +2171,8 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
if (cpi->oxcf.rc_mode == VPX_Q) {
twopass->active_worst_quality = cpi->oxcf.cq_level;
} else if (cm->current_video_frame == 0 ||
(is_spatial_svc && lc->current_video_frame_in_layer == 0)) {
(is_spatial_svc(cpi) &&
lc->current_video_frame_in_layer == 0)) {
// Special case code for first frame.
const int section_target_bandwidth = (int)(twopass->bits_left /
frames_left);
......@@ -2201,7 +2198,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
cm->frame_type = INTER_FRAME;
}
if (is_spatial_svc) {
if (is_spatial_svc(cpi)) {
if (cpi->svc.spatial_layer_id == 0) {
lc->is_key_frame = (cm->frame_type == KEY_FRAME);
if (lc->is_key_frame)
......@@ -2232,7 +2229,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
}
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
if (!is_spatial_svc)
if (!is_spatial_svc(cpi))
cpi->refresh_golden_frame = 1;
}
......
......@@ -1236,7 +1236,7 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) {
cm->frame_type = KEY_FRAME;
rc->source_alt_ref_active = 0;
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
if (is_spatial_svc(cpi)) {
cpi->svc.layer_context[cpi->svc.spatial_layer_id].is_key_frame = 1;
cpi->ref_frame_flags &=
(~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
......@@ -1248,7 +1248,7 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) {
} else {
cm->frame_type = INTER_FRAME;
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
if (is_spatial_svc(cpi)) {
LAYER_CONTEXT *lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id];
if (cpi->svc.spatial_layer_id == 0) {
lc->is_key_frame = 0;
......
......@@ -222,8 +222,7 @@ void vp9_inc_frame_in_layer(SVC *svc) {
}
int vp9_is_upper_layer_key_frame(const VP9_COMP *const cpi) {
return cpi->use_svc &&
cpi->svc.number_temporal_layers == 1 &&
return is_spatial_svc(cpi) &&
cpi->svc.spatial_layer_id > 0 &&
cpi->svc.layer_context[cpi->svc.spatial_layer_id].is_key_frame;
}
......
......@@ -442,7 +442,7 @@ void vp9_temporal_filter(VP9_COMP *cpi, int distance) {
}
// Setup scaling factors. Scaling on each of the arnr frames is not supported
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
if (is_spatial_svc(cpi)) {
// In spatial svc the scaling factors might be less then 1/2. So we will use
// non-normative scaling.
int frame_used = 0;
......
......@@ -910,14 +910,14 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi;
#if CONFIG_SPATIAL_SVC
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1)
if (is_spatial_svc(cpi))
cpi->svc.layer_context[cpi->svc.spatial_layer_id].layer_size += size;
#endif
// Pack invisible frames with the next visible frame
if (cpi->common.show_frame == 0
#if CONFIG_SPATIAL_SVC
|| (cpi->use_svc && cpi->svc.number_temporal_layers == 1 &&
|| (is_spatial_svc(cpi) &&
cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1)
#endif
) {
......@@ -945,7 +945,7 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
if (lib_flags & FRAMEFLAGS_KEY
#if CONFIG_SPATIAL_SVC
|| (cpi->use_svc && cpi->svc.number_temporal_layers == 1 &&
|| (is_spatial_svc(cpi) &&
cpi->svc.layer_context[0].is_key_frame)
#endif
)
......@@ -987,7 +987,7 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
cx_data += size;
cx_data_sz -= size;
#if CONFIG_SPATIAL_SVC
if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
if (is_spatial_svc(cpi)) {
vpx_codec_cx_pkt_t pkt = {0};
int i;
pkt.kind = VPX_CODEC_SPATIAL_SVC_LAYER_SIZES;
......
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