+
+ // Workaround for multiple frame contexts. In some frames we can't use prev_mi
+ // since its previous frame could be changed during decoding time. The idea is
+ // we put a empty invisible frame in front of them, then we will not use
+ // prev_mi when encoding these frames.
+ if (cpi->oxcf.error_resilient_mode == 0 && cpi->oxcf.pass == 2 &&
+ cpi->svc.encode_empty_frame_state == NEED_TO_ENCODE) {
+ if ((cpi->svc.number_temporal_layers > 1 &&
+ cpi->svc.temporal_layer_id < cpi->svc.number_temporal_layers - 1) ||
+ (cpi->svc.number_spatial_layers > 1 &&
+ cpi->svc.spatial_layer_id == 0)) {
+ struct lookahead_entry *buf = vp9_lookahead_peek(cpi->lookahead, 0);
+
+ if (buf != NULL) {
+ cpi->svc.empty_frame.ts_start = buf->ts_start;
+ cpi->svc.empty_frame.ts_end = buf->ts_end;
+ cpi->svc.encode_empty_frame_state = ENCODING;
+ cpi->common.show_frame = 0;
+ cpi->ref_frame_flags = 0;
+ cpi->common.frame_type = INTER_FRAME;
+ cpi->lst_fb_idx =
+ cpi->gld_fb_idx = cpi->alt_fb_idx = SMALL_FRAME_FB_IDX;
+
+ // Gradually make the empty frame smaller to save bits. Make it half of
+ // its previous size because of the scaling factor restriction.
+ cpi->svc.empty_frame_width >>= 1;
+ cpi->svc.empty_frame_width = (cpi->svc.empty_frame_width + 1) & ~1;
+ if (cpi->svc.empty_frame_width < 16)
+ cpi->svc.empty_frame_width = 16;
+
+ cpi->svc.empty_frame_height >>= 1;
+ cpi->svc.empty_frame_height = (cpi->svc.empty_frame_height + 1) & ~1;
+ if (cpi->svc.empty_frame_height < 16)
+ cpi->svc.empty_frame_height = 16;
+
+ width = cpi->svc.empty_frame_width;
+ height = cpi->svc.empty_frame_height;
+ }
+ }
+ }
+