Lines Matching refs:cpi

105 void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv) {
106 MACROBLOCK *const mb = &cpi->mb;
107 cpi->common.allow_high_precision_mv = allow_high_precision_mv;
108 if (cpi->common.allow_high_precision_mv) {
117 static void setup_frame(VP9_COMP *cpi) {
118 VP9_COMMON *const cm = &cpi->common;
127 if (!cpi->use_svc)
128 cm->frame_context_idx = cpi->refresh_alt_ref_frame;
132 if (!is_two_pass_svc(cpi))
133 cpi->refresh_golden_frame = 1;
134 cpi->refresh_alt_ref_frame = 1;
135 vp9_zero(cpi->interp_filter_selected);
138 vp9_zero(cpi->interp_filter_selected[0]);
160 static void dealloc_compressor_data(VP9_COMP *cpi) {
161 VP9_COMMON *const cm = &cpi->common;
165 vpx_free(cpi->segmentation_map);
166 cpi->segmentation_map = NULL;
169 vpx_free(cpi->coding_context.last_frame_seg_map_copy);
170 cpi->coding_context.last_frame_seg_map_copy = NULL;
172 vpx_free(cpi->complexity_map);
173 cpi->complexity_map = NULL;
175 vpx_free(cpi->nmvcosts[0]);
176 vpx_free(cpi->nmvcosts[1]);
177 cpi->nmvcosts[0] = NULL;
178 cpi->nmvcosts[1] = NULL;
180 vpx_free(cpi->nmvcosts_hp[0]);
181 vpx_free(cpi->nmvcosts_hp[1]);
182 cpi->nmvcosts_hp[0] = NULL;
183 cpi->nmvcosts_hp[1] = NULL;
185 vpx_free(cpi->nmvsadcosts[0]);
186 vpx_free(cpi->nmvsadcosts[1]);
187 cpi->nmvsadcosts[0] = NULL;
188 cpi->nmvsadcosts[1] = NULL;
190 vpx_free(cpi->nmvsadcosts_hp[0]);
191 vpx_free(cpi->nmvsadcosts_hp[1]);
192 cpi->nmvsadcosts_hp[0] = NULL;
193 cpi->nmvsadcosts_hp[1] = NULL;
195 vp9_cyclic_refresh_free(cpi->cyclic_refresh);
196 cpi->cyclic_refresh = NULL;
201 vp9_free_frame_buffer(&cpi->last_frame_uf);
202 vp9_free_frame_buffer(&cpi->scaled_source);
203 vp9_free_frame_buffer(&cpi->scaled_last_source);
204 vp9_free_frame_buffer(&cpi->alt_ref_buffer);
205 vp9_lookahead_destroy(cpi->lookahead);
207 vpx_free(cpi->tok);
208 cpi->tok = 0;
210 vp9_free_pc_tree(cpi);
212 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) {
213 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[i];
219 if (cpi->source_diff_var != NULL) {
220 vpx_free(cpi->source_diff_var);
221 cpi->source_diff_var = NULL;
225 vp9_free_frame_buffer(&cpi->svc.scaled_frames[i]);
227 vpx_memset(&cpi->svc.scaled_frames[0], 0,
228 MAX_LAG_BUFFERS * sizeof(cpi->svc.scaled_frames[0]));
231 static void save_coding_context(VP9_COMP *cpi) {
232 CODING_CONTEXT *const cc = &cpi->coding_context;
233 VP9_COMMON *cm = &cpi->common;
239 vp9_copy(cc->nmvjointcost, cpi->mb.nmvjointcost);
241 vpx_memcpy(cc->nmvcosts[0], cpi->nmvcosts[0],
242 MV_VALS * sizeof(*cpi->nmvcosts[0]));
243 vpx_memcpy(cc->nmvcosts[1], cpi->nmvcosts[1],
244 MV_VALS * sizeof(*cpi->nmvcosts[1]));
245 vpx_memcpy(cc->nmvcosts_hp[0], cpi->nmvcosts_hp[0],
246 MV_VALS * sizeof(*cpi->nmvcosts_hp[0]));
247 vpx_memcpy(cc->nmvcosts_hp[1], cpi->nmvcosts_hp[1],
248 MV_VALS * sizeof(*cpi->nmvcosts_hp[1]));
252 vpx_memcpy(cpi->coding_context.last_frame_seg_map_copy,
261 static void restore_coding_context(VP9_COMP *cpi) {
262 CODING_CONTEXT *const cc = &cpi->coding_context;
263 VP9_COMMON *cm = &cpi->common;
267 vp9_copy(cpi->mb.nmvjointcost, cc->nmvjointcost);
269 vpx_memcpy(cpi->nmvcosts[0], cc->nmvcosts[0],
271 vpx_memcpy(cpi->nmvcosts[1], cc->nmvcosts[1],
273 vpx_memcpy(cpi->nmvcosts_hp[0], cc->nmvcosts_hp[0],
275 vpx_memcpy(cpi->nmvcosts_hp[1], cc->nmvcosts_hp[1],
281 cpi->coding_context.last_frame_seg_map_copy,
290 static void configure_static_seg_features(VP9_COMP *cpi) {
291 VP9_COMMON *const cm = &cpi->common;
292 const RATE_CONTROL *const rc = &cpi->rc;
301 vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
304 cpi->static_mb_pct = 0;
311 } else if (cpi->refresh_alt_ref_frame) {
314 vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
317 cpi->static_mb_pct = 0;
325 vp9_update_mbgraph_stats(cpi);
364 if (high_q || (cpi->static_mb_pct == 100)) {
375 vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
414 static void update_reference_segmentation_map(VP9_COMP *cpi) {
415 VP9_COMMON *const cm = &cpi->common;
430 static void alloc_raw_frame_buffers(VP9_COMP *cpi) {
431 VP9_COMMON *cm = &cpi->common;
432 const VP9EncoderConfig *oxcf = &cpi->oxcf;
434 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height,
440 if (!cpi->lookahead)
444 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer,
455 static void alloc_ref_frame_buffers(VP9_COMP *cpi) {
456 VP9_COMMON *const cm = &cpi->common;
462 static void alloc_util_frame_buffers(VP9_COMP *cpi) {
463 VP9_COMMON *const cm = &cpi->common;
464 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf,
474 if (vp9_realloc_frame_buffer(&cpi->scaled_source,
484 if (vp9_realloc_frame_buffer(&cpi->scaled_last_source,
495 void vp9_alloc_compressor_data(VP9_COMP *cpi) {
496 VP9_COMMON *cm = &cpi->common;
500 vpx_free(cpi->tok);
504 CHECK_MEM_ERROR(cm, cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok)));
507 vp9_setup_pc_tree(&cpi->common, cpi);
510 static void update_frame_size(VP9_COMP *cpi) {
511 VP9_COMMON *const cm = &cpi->common;
512 MACROBLOCKD *const xd = &cpi->mb.e_mbd;
518 if (is_two_pass_svc(cpi)) {
519 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer,
531 void vp9_new_framerate(VP9_COMP *cpi, double framerate) {
532 cpi->framerate = framerate < 0.1 ? 30 : framerate;
533 vp9_rc_update_framerate(cpi);
536 static void set_tile_limits(VP9_COMP *cpi) {
537 VP9_COMMON *const cm = &cpi->common;
542 cm->log2_tile_cols = clamp(cpi->oxcf.tile_columns,
544 cm->log2_tile_rows = cpi->oxcf.tile_rows;
547 static void init_buffer_indices(VP9_COMP *cpi) {
548 cpi->lst_fb_idx = 0;
549 cpi->gld_fb_idx = 1;
550 cpi->alt_fb_idx = 2;
553 static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) {
554 VP9_COMMON *const cm = &cpi->common;
556 cpi->oxcf = *oxcf;
557 cpi->framerate = oxcf->init_framerate;
568 vp9_alloc_compressor_data(cpi);
571 cpi->svc.number_spatial_layers = oxcf->ss_number_layers;
573 cpi->svc.number_temporal_layers = oxcf->ts_number_layers;
575 if ((cpi->svc.number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) ||
576 ((cpi->svc.number_temporal_layers > 1 ||
577 cpi->svc.number_spatial_layers > 1) &&
578 cpi->oxcf.pass == 2)) {
579 vp9_init_layer_context(cpi);
583 vp9_change_config(cpi, oxcf);
585 cpi->static_mb_pct = 0;
586 cpi->ref_frame_flags = 0;
588 init_buffer_indices(cpi);
590 set_tile_limits(cpi);
607 void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
608 VP9_COMMON *const cm = &cpi->common;
609 RATE_CONTROL *const rc = &cpi->rc;
620 cpi->oxcf = *oxcf;
622 if (cpi->oxcf.use_highbitdepth) {
623 cpi->mb.e_mbd.bd = (int)cm->bit_depth;
629 cpi->refresh_golden_frame = 0;
630 cpi->refresh_last_frame = 1;
635 vp9_set_high_precision_mv(cpi, 0);
641 cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout;
643 cpi->encode_breakout = cpi->oxcf.encode_breakout;
645 set_rc_buffer_sizes(rc, &cpi->oxcf);
653 vp9_new_framerate(cpi, cpi->framerate);
656 rc->worst_quality = cpi->oxcf.worst_allowed_q;
657 rc->best_quality = cpi->oxcf.best_allowed_q;
659 cm->interp_filter = cpi->sf.default_interp_filter;
661 cm->display_width = cpi->oxcf.width;
662 cm->display_height = cpi->oxcf.height;
664 if (cpi->initial_width) {
668 assert(cm->width <= cpi->initial_width);
669 assert(cm->height <= cpi->initial_height);
671 update_frame_size(cpi);
673 if ((cpi->svc.number_temporal_layers > 1 &&
674 cpi->oxcf.rc_mode == VPX_CBR) ||
675 ((cpi->svc.number_temporal_layers > 1 ||
676 cpi->svc.number_spatial_layers > 1) &&
677 cpi->oxcf.pass == 2)) {
678 vp9_update_layer_context_change_config(cpi,
679 (int)cpi->oxcf.target_bandwidth);
682 cpi->alt_ref_source = NULL;
687 cpi->frame_distortion = 0;
688 cpi->last_frame_distortion = 0;
691 set_tile_limits(cpi);
693 cpi->ext_refresh_frame_flags_pending = 0;
694 cpi->ext_refresh_frame_context_pending = 0;
697 if (cpi->oxcf.noise_sensitivity > 0) {
698 vp9_denoiser_alloc(&(cpi->denoiser), cm->width, cm->height,
753 VP9_COMP *const cpi = vpx_memalign(32, sizeof(VP9_COMP));
754 VP9_COMMON *const cm = cpi != NULL ? &cpi->common : NULL;
759 vp9_zero(*cpi);
763 vp9_remove_compressor(cpi);
769 cpi->use_svc = 0;
771 init_config(cpi, oxcf);
772 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
775 cpi->skippable_frame = 0;
778 CHECK_MEM_ERROR(cm, cpi->segmentation_map,
782 CHECK_MEM_ERROR(cm, cpi->complexity_map,
786 CHECK_MEM_ERROR(cm, cpi->cyclic_refresh,
791 CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy,
794 CHECK_MEM_ERROR(cm, cpi->nmvcosts[0],
795 vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts[0])));
796 CHECK_MEM_ERROR(cm, cpi->nmvcosts[1],
797 vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts[1])));
798 CHECK_MEM_ERROR(cm, cpi->nmvcosts_hp[0],
799 vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts_hp[0])));
800 CHECK_MEM_ERROR(cm, cpi->nmvcosts_hp[1],
801 vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts_hp[1])));
802 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts[0],
803 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts[0])));
804 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts[1],
805 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts[1])));
806 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts_hp[0],
807 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts_hp[0])));
808 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts_hp[1],
809 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts_hp[1])));
811 for (i = 0; i < (sizeof(cpi->mbgraph_stats) /
812 sizeof(cpi->mbgraph_stats[0])); i++) {
813 CHECK_MEM_ERROR(cm, cpi->mbgraph_stats[i].mb_stats,
815 sizeof(*cpi->mbgraph_stats[i].mb_stats), 1));
819 cpi->use_fp_mb_stats = 0;
820 if (cpi->use_fp_mb_stats) {
822 CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf,
825 cpi->twopass.frame_mb_stats_buf = NULL;
829 cpi->refresh_alt_ref_frame = 0;
835 cpi->multi_arf_last_grp_enabled = 0;
837 if (cpi->use_svc) {
838 cpi->multi_arf_allowed = 0;
839 cpi->multi_arf_enabled = 0;
842 cpi->multi_arf_allowed = 0;
843 cpi->multi_arf_enabled = 0;
846 cpi->multi_arf_allowed = 0;
847 cpi->multi_arf_enabled = 0;
850 cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS;
852 cpi->b_calculate_ssimg = 0;
854 cpi->count = 0;
855 cpi->bytes = 0;
857 if (cpi->b_calculate_psnr) {
858 cpi->total_y = 0.0;
859 cpi->total_u = 0.0;
860 cpi->total_v = 0.0;
861 cpi->total = 0.0;
862 cpi->total_sq_error = 0;
863 cpi->total_samples = 0;
865 cpi->totalp_y = 0.0;
866 cpi->totalp_u = 0.0;
867 cpi->totalp_v = 0.0;
868 cpi->totalp = 0.0;
869 cpi->totalp_sq_error = 0;
870 cpi->totalp_samples = 0;
872 cpi->tot_recode_hits = 0;
873 cpi->summed_quality = 0;
874 cpi->summed_weights = 0;
875 cpi->summedp_quality = 0;
876 cpi->summedp_weights = 0;
879 if (cpi->b_calculate_ssimg) {
880 cpi->total_ssimg_y = 0;
881 cpi->total_ssimg_u = 0;
882 cpi->total_ssimg_v = 0;
883 cpi->total_ssimg_all = 0;
888 cpi->first_time_stamp_ever = INT64_MAX;
890 cal_nmvjointsadcost(cpi->mb.nmvjointsadcost);
891 cpi->mb.nmvcost[0] = &cpi->nmvcosts[0][MV_MAX];
892 cpi->mb.nmvcost[1] = &cpi->nmvcosts[1][MV_MAX];
893 cpi->mb.nmvsadcost[0] = &cpi->nmvsadcosts[0][MV_MAX];
894 cpi->mb.nmvsadcost[1] = &cpi->nmvsadcosts[1][MV_MAX];
895 cal_nmvsadcosts(cpi->mb.nmvsadcost);
897 cpi->mb.nmvcost_hp[0] = &cpi->nmvcosts_hp[0][MV_MAX];
898 cpi->mb.nmvcost_hp[1] = &cpi->nmvcosts_hp[1][MV_MAX];
899 cpi->mb.nmvsadcost_hp[0] = &cpi->nmvsadcosts_hp[0][MV_MAX];
900 cpi->mb.nmvsadcost_hp[1] = &cpi->nmvsadcosts_hp[1][MV_MAX];
901 cal_nmvsadcosts_hp(cpi->mb.nmvsadcost_hp);
917 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED;
920 vp9_init_first_pass(cpi);
925 if (cpi->svc.number_spatial_layers > 1
926 || cpi->svc.number_temporal_layers > 1) {
937 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[layer_id];
961 vp9_init_second_pass_spatial_svc(cpi);
964 if (cpi->use_fp_mb_stats) {
965 const size_t psz = cpi->common.MBs * sizeof(uint8_t);
968 cpi->twopass.firstpass_mb_stats.mb_stats_start =
970 cpi->twopass.firstpass_mb_stats.mb_stats_end =
971 cpi->twopass.firstpass_mb_stats.mb_stats_start +
972 (ps - 1) * cpi->common.MBs * sizeof(uint8_t);
976 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf;
977 cpi->twopass.stats_in = cpi->twopass.stats_in_start;
978 cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1];
980 vp9_init_second_pass(cpi);
984 vp9_set_speed_features(cpi);
987 CHECK_MEM_ERROR(cm, cpi->source_diff_var,
989 cpi->source_var_thresh = 0;
990 cpi->frames_till_next_var_check = 0;
995 cpi->rd.thresh_freq_fact[i][j] = 32;
996 cpi->rd.mode_map[i][j] = j;
1001 cpi->fn_ptr[BT].sdf = SDF; \
1002 cpi->fn_ptr[BT].sdaf = SDAF; \
1003 cpi->fn_ptr[BT].vf = VF; \
1004 cpi->fn_ptr[BT].svf = SVF; \
1005 cpi->fn_ptr[BT].svaf = SVAF; \
1006 cpi->fn_ptr[BT].sdx3f = SDX3F; \
1007 cpi->fn_ptr[BT].sdx8f = SDX8F; \
1008 cpi->fn_ptr[BT].sdx4df = SDX4DF;
1074 vp9_init_quantizer(cpi);
1080 return cpi;
1083 void vp9_remove_compressor(VP9_COMP *cpi) {
1086 if (!cpi)
1089 if (cpi && (cpi->common.current_video_frame > 0)) {
1094 // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count);
1095 if (cpi->oxcf.pass != 1) {
1097 double time_encoded = (cpi->last_end_time_stamp_seen
1098 - cpi->first_time_stamp_ever) / 10000000.000;
1099 double total_encode_time = (cpi->time_receive_data +
1100 cpi->time_compress_data) / 1000.000;
1101 double dr = (double)cpi->bytes * (double) 8 / (double)1000
1104 if (cpi->b_calculate_psnr) {
1106 vpx_sse_to_psnr((double)cpi->total_samples, 255.0,
1107 (double)cpi->total_sq_error);
1109 vpx_sse_to_psnr((double)cpi->totalp_samples, 255.0,
1110 (double)cpi->totalp_sq_error);
1111 const double total_ssim = 100 * pow(cpi->summed_quality /
1112 cpi->summed_weights, 8.0);
1113 const double totalp_ssim = 100 * pow(cpi->summedp_quality /
1114 cpi->summedp_weights, 8.0);
1119 dr, cpi->total / cpi->count, total_psnr,
1120 cpi->totalp / cpi->count, totalp_psnr, total_ssim, totalp_ssim,
1124 if (cpi->b_calculate_ssimg) {
1127 cpi->total_ssimg_y / cpi->count,
1128 cpi->total_ssimg_u / cpi->count,
1129 cpi->total_ssimg_v / cpi->count,
1130 cpi->total_ssimg_all / cpi->count, total_encode_time);
1140 printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000);
1142 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame,
1143 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000,
1144 cpi->time_compress_data / 1000,
1145 (cpi->time_receive_data + cpi->time_compress_data) / 1000);
1151 if (cpi->oxcf.noise_sensitivity > 0) {
1152 vp9_denoiser_free(&(cpi->denoiser));
1156 dealloc_compressor_data(cpi);
1157 vpx_free(cpi->tok);
1159 for (i = 0; i < sizeof(cpi->mbgraph_stats) /
1160 sizeof(cpi->mbgraph_stats[0]); ++i) {
1161 vpx_free(cpi->mbgraph_stats[i].mb_stats);
1165 if (cpi->use_fp_mb_stats) {
1166 vpx_free(cpi->twopass.frame_mb_stats_buf);
1167 cpi->twopass.frame_mb_stats_buf = NULL;
1171 vp9_remove_common(&cpi->common);
1172 vpx_free(cpi);
1276 static void generate_psnr_packet(VP9_COMP *cpi) {
1280 calc_psnr(cpi->Source, cpi->common.frame_to_show, &psnr);
1287 if (is_two_pass_svc(cpi))
1288 cpi->svc.layer_context[cpi->svc.spatial_layer_id].psnr_pkt = pkt.data.psnr;
1290 vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
1293 int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags) {
1297 cpi->ref_frame_flags = ref_frame_flags;
1301 void vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags) {
1302 cpi->ext_refresh_golden_frame = (ref_frame_flags & VP9_GOLD_FLAG) != 0;
1303 cpi->ext_refresh_alt_ref_frame = (ref_frame_flags & VP9_ALT_FLAG) != 0;
1304 cpi->ext_refresh_last_frame = (ref_frame_flags & VP9_LAST_FLAG) != 0;
1305 cpi->ext_refresh_frame_flags_pending = 1;
1308 static YV12_BUFFER_CONFIG *get_vp9_ref_frame_buffer(VP9_COMP *cpi,
1318 return ref_frame == NONE ? NULL : get_ref_frame_buffer(cpi, ref_frame);
1321 int vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
1323 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag);
1332 int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
1334 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag);
1343 int vp9_update_entropy(VP9_COMP * cpi, int update) {
1344 cpi->ext_refresh_frame_context = update;
1345 cpi->ext_refresh_frame_context_pending = 1;
1476 static int recode_loop_test(const VP9_COMP *cpi,
1479 const VP9_COMMON *const cm = &cpi->common;
1480 const RATE_CONTROL *const rc = &cpi->rc;
1481 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
1491 } else if ((cpi->sf.recode_loop == ALLOW_RECODE) ||
1492 ((cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF) &&
1494 cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) {
1499 } else if (cpi->oxcf.rc_mode == VPX_CQ) {
1511 void vp9_update_reference_frames(VP9_COMP *cpi) {
1512 VP9_COMMON * const cm = &cpi->common;
1518 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx);
1520 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx);
1521 } else if (vp9_preserve_existing_gf(cpi)) {
1533 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx);
1535 tmp = cpi->alt_fb_idx;
1536 cpi->alt_fb_idx = cpi->gld_fb_idx;
1537 cpi->gld_fb_idx = tmp;
1539 if (is_two_pass_svc(cpi)) {
1540 cpi->svc.layer_context[0].gold_ref_idx = cpi->gld_fb_idx;
1541 cpi->svc.layer_context[0].alt_ref_idx = cpi->alt_fb_idx;
1544 if (cpi->refresh_alt_ref_frame) {
1545 int arf_idx = cpi->alt_fb_idx;
1546 if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) {
1547 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
1553 vpx_memcpy(cpi->interp_filter_selected[ALTREF_FRAME],
1554 cpi->interp_filter_selected[0],
1555 sizeof(cpi->interp_filter_selected[0]));
1558 if (cpi->refresh_golden_frame) {
1560 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx);
1561 if (!cpi->rc.is_src_frame_alt_ref)
1562 vpx_memcpy(cpi->interp_filter_selected[GOLDEN_FRAME],
1563 cpi->interp_filter_selected[0],
1564 sizeof(cpi->interp_filter_selected[0]));
1566 vpx_memcpy(cpi->interp_filter_selected[GOLDEN_FRAME],
1567 cpi->interp_filter_selected[ALTREF_FRAME],
1568 sizeof(cpi->interp_filter_selected[ALTREF_FRAME]));
1572 if (cpi->refresh_last_frame) {
1574 &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx);
1575 if (!cpi->rc.is_src_frame_alt_ref)
1576 vpx_memcpy(cpi->interp_filter_selected[LAST_FRAME],
1577 cpi->interp_filter_selected[0],
1578 sizeof(cpi->interp_filter_selected[0]));
1581 if (cpi->oxcf.noise_sensitivity > 0) {
1582 vp9_denoiser_update_frame_info(&cpi->denoiser,
1583 *cpi->Source,
1584 cpi->common.frame_type,
1585 cpi->refresh_alt_ref_frame,
1586 cpi->refresh_golden_frame,
1587 cpi->refresh_last_frame);
1592 static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) {
1593 MACROBLOCKD *xd = &cpi->mb.e_mbd;
1604 vp9_pick_filter_level(cpi->Source, cpi, cpi->sf.lpf_pick);
1607 cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer);
1617 void vp9_scale_references(VP9_COMP *cpi) {
1618 VP9_COMMON *cm = &cpi->common;
1623 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)];
1627 if ((cpi->ref_frame_flags & ref_mask[ref_frame - 1]) &&
1638 cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
1640 cpi->scaled_ref_idx[ref_frame - 1] = idx;
1646 static void release_scaled_references(VP9_COMP *cpi) {
1647 VP9_COMMON *cm = &cpi->common;
1651 cm->frame_bufs[cpi->scaled_ref_idx[i]].ref_count--;
1677 static void output_frame_level_debug_stats(VP9_COMP *cpi) {
1678 VP9_COMMON *const cm = &cpi->common;
1684 recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
1686 if (cpi->twopass.total_left_stats.coded_error != 0.0)
1693 cpi->common.current_video_frame, cpi->rc.this_frame_target,
1694 cpi->rc.projected_frame_size,
1695 cpi->rc.projected_frame_size / cpi->common.MBs,
1696 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target),
1697 cpi->rc.vbr_bits_off_target,
1698 cpi->rc.total_target_vs_actual,
1699 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target),
1700 cpi->rc.total_actual_bits, cm->base_qindex,
1703 vp9_convert_qindex_to_q(cpi->twopass.active_worst_quality),
1704 cpi->rc.avg_q,
1705 vp9_convert_qindex_to_q(cpi->oxcf.cq_level),
1706 cpi->refresh_last_frame, cpi->refresh_golden_frame,
1707 cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost,
1708 cpi->twopass.bits_left,
1709 cpi->twopass.total_left_stats.coded_error,
1710 cpi->twopass.bits_left /
1711 (1 + cpi->twopass.total_left_stats.coded_error),
1712 cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost,
1713 cpi->twopass.kf_zeromotion_pct);
1721 fprintf(fmodes, "%6d:%1d:%1d:%1d ", cpi->common.current_video_frame,
1722 cm->frame_type, cpi->refresh_golden_frame,
1723 cpi->refresh_alt_ref_frame);
1726 fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]);
1735 static void encode_without_recode_loop(VP9_COMP *cpi,
1737 VP9_COMMON *const cm = &cpi->common;
1740 setup_frame(cpi);
1743 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
1744 vp9_vaq_frame_setup(cpi);
1745 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
1746 vp9_setup_in_frame_q_adj(cpi);
1747 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
1748 vp9_cyclic_refresh_setup(cpi);
1751 vp9_encode_frame(cpi);
1755 // update_base_skip_probs(cpi);
1759 static void encode_with_recode_loop(VP9_COMP *cpi,
1765 VP9_COMMON *const cm = &cpi->common;
1766 RATE_CONTROL *const rc = &cpi->rc;
1776 vp9_rc_compute_frame_size_bounds(cpi, rc->this_frame_target,
1786 setup_frame(cpi);
1790 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
1791 vp9_vaq_frame_setup(cpi);
1792 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
1793 vp9_setup_in_frame_q_adj(cpi);
1797 vp9_encode_frame(cpi);
1801 // update_base_skip_probs(cpi);
1808 if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) {
1809 save_coding_context(cpi);
1810 if (!cpi->sf.use_nonrd_pick_mode)
1811 vp9_pack_bitstream(cpi, dest, size);
1814 restore_coding_context(cpi);
1820 if (cpi->oxcf.rc_mode == VPX_Q) {
1827 int kf_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
1829 int high_err_target = cpi->ambient_err;
1830 int low_err_target = cpi->ambient_err >> 1;
1863 cpi, frame_over_shoot_limit, frame_under_shoot_limit,
1884 vp9_rc_update_rate_correction_factors(cpi, 1);
1889 vp9_rc_update_rate_correction_factors(cpi, 0);
1891 q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
1895 vp9_rc_update_rate_correction_factors(cpi, 0);
1896 q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
1908 vp9_rc_update_rate_correction_factors(cpi, 1);
1911 vp9_rc_update_rate_correction_factors(cpi, 0);
1912 q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
1918 if (cpi->oxcf.rc_mode == VPX_CQ &&
1924 vp9_rc_update_rate_correction_factors(cpi, 0);
1925 q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
1952 cpi->tot_recode_hits++;
1958 static int get_ref_frame_flags(const VP9_COMP *cpi) {
1959 const int *const map = cpi->common.ref_frame_map;
1960 const int gold_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx];
1961 const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx];
1962 const int gold_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx];
1968 if (cpi->rc.frames_till_gf_update_due == INT_MAX && !is_two_pass_svc(cpi))
1980 static void set_ext_overrides(VP9_COMP *cpi) {
1985 if (cpi->ext_refresh_frame_context_pending) {
1986 cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context;
1987 cpi->ext_refresh_frame_context_pending = 0;
1989 if (cpi->ext_refresh_frame_flags_pending) {
1990 cpi->refresh_last_frame = cpi->ext_refresh_last_frame;
1991 cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame;
1992 cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame;
1993 cpi->ext_refresh_frame_flags_pending = 0;
2009 static int is_skippable_frame(const VP9_COMP *cpi) {
2014 const SVC *const svc = &cpi->svc;
2015 const TWO_PASS *const twopass = is_two_pass_svc(cpi) ?
2016 &svc->layer_context[svc->spatial_layer_id].twopass : &cpi->twopass;
2018 return (!frame_is_intra_only(&cpi->common) &&
2028 static void set_arf_sign_bias(VP9_COMP *cpi) {
2029 VP9_COMMON *const cm = &cpi->common;
2032 if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) {
2033 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
2034 arf_sign_bias = cpi->rc.source_alt_ref_active &&
2035 (!cpi->refresh_alt_ref_frame ||
2039 (cpi->rc.source_alt_ref_active && !cpi->refresh_alt_ref_frame);
2044 static void set_mv_search_params(VP9_COMP *cpi) {
2045 const VP9_COMMON *const cm = &cpi->common;
2049 cpi->mv_step_param = vp9_init_search_range(max_mv_def);
2051 if (cpi->sf.mv.auto_mv_step_size) {
2055 cpi->max_mv_magnitude = max_mv_def;
2061 cpi->mv_step_param =
2062 vp9_init_search_range(MIN(max_mv_def, 2 * cpi->max_mv_magnitude));
2063 cpi->max_mv_magnitude = 0;
2069 int setup_interp_filter_search_mask(VP9_COMP *cpi) {
2074 if (cpi->common.last_frame_type == KEY_FRAME ||
2075 cpi->refresh_alt_ref_frame)
2079 ref_total[ref] += cpi->interp_filter_selected[ref][ifilter];
2083 cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) &&
2085 cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50
2088 cpi->interp_filter_selected[ALTREF_FRAME][ifilter] * 50
2095 static void encode_frame_to_data_rate(VP9_COMP *cpi,
2099 VP9_COMMON *const cm = &cpi->common;
2100 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
2107 set_ext_overrides(cpi);
2109 cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source,
2110 &cpi->scaled_source);
2112 if (cpi->unscaled_last_source != NULL)
2113 cpi->Last_Source = vp9_scale_if_required(cm, cpi->unscaled_last_source,
2114 &cpi->scaled_last_source);
2116 vp9_scale_references(cpi);
2123 cpi->zbin_mode_boost = 0;
2124 cpi->zbin_mode_boost_enabled = 0;
2127 set_arf_sign_bias(cpi);
2132 set_mv_search_params(cpi);
2134 if (cpi->oxcf.pass == 2 &&
2135 cpi->sf.adaptive_interp_filter_search)
2136 cpi->sf.interp_filter_search_mask =
2137 setup_interp_filter_search_mask(cpi);
2152 cpi->rc.source_alt_ref_active = 0;
2167 if (is_two_pass_svc(cpi) && cm->error_resilient_mode == 0) {
2169 cpi->svc.spatial_layer_id * cpi->svc.number_temporal_layers +
2170 cpi->svc.temporal_layer_id;
2176 if (cpi->svc.number_temporal_layers == 1) {
2177 if (cpi->svc.spatial_layer_id == 0 &&
2178 cpi->svc.layer_context[0].last_frame_type == KEY_FRAME)
2182 } else if (cpi->svc.spatial_layer_id == 0) {
2186 for (i = 0; i < cpi->svc.number_temporal_layers; ++i) {
2187 if (cpi->svc.layer_context[0].frames_from_key_frame == 1 << i) {
2192 if (i == cpi->svc.number_temporal_layers)
2201 if (oxcf->pass == 2 && cpi->sf.static_segmentation)
2202 configure_static_seg_features(cpi);
2207 (!cpi->use_svc || is_two_pass_svc(cpi))) {
2208 cpi->skippable_frame = is_skippable_frame(cpi);
2216 if (vp9_rc_drop_frame(cpi)) {
2217 vp9_rc_postencode_update_drop_frame(cpi);
2246 vp9_denoise(cpi->Source, cpi->Source, l);
2254 cpi->mode_chosen_counts[i] = 0;
2258 vp9_set_speed_features(cpi);
2260 vp9_set_rd_speed_thresholds(cpi);
2261 vp9_set_rd_speed_thresholds_sub8x8(cpi);
2264 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index);
2267 cm->interp_filter = cpi->sf.default_interp_filter;
2269 vp9_set_high_precision_mv(cpi, q < HIGH_PRECISION_MV_QTHRESH);
2272 if (cpi->sf.recode_loop == DISALLOW_RECODE) {
2273 encode_without_recode_loop(cpi, q);
2275 encode_with_recode_loop(cpi, size, dest, q, bottom_index, top_index);
2281 vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME],
2291 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) {
2292 cpi->ambient_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
2297 cpi->refresh_last_frame = 1;
2302 loopfilter_frame(cpi, cm);
2305 vp9_pack_bitstream(cpi, dest, size);
2308 update_reference_segmentation_map(cpi);
2310 release_scaled_references(cpi);
2311 vp9_update_reference_frames(cpi);
2314 full_to_model_counts(cm->counts.coef[t], cpi->coef_counts[t]);
2326 if (cpi->refresh_golden_frame == 1)
2327 cpi->frame_flags |= FRAMEFLAGS_GOLDEN;
2329 cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN;
2331 if (cpi->refresh_alt_ref_frame == 1)
2332 cpi->frame_flags |= FRAMEFLAGS_ALTREF;
2334 cpi->frame_flags &= ~FRAMEFLAGS_ALTREF;
2336 cpi->ref_frame_flags = get_ref_frame_flags(cpi);
2339 vp9_rc_postencode_update(cpi, *size);
2342 output_frame_level_debug_stats(cpi);
2347 *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY;
2349 *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY;
2364 if (is_two_pass_svc(cpi) && cm->error_resilient_mode == 0)
2376 if (cpi->use_svc)
2377 vp9_inc_frame_in_layer(cpi);
2380 if (is_two_pass_svc(cpi))
2381 cpi->svc.layer_context[cpi->svc.spatial_layer_id].last_frame_type =
2385 static void SvcEncode(VP9_COMP *cpi, size_t *size, uint8_t *dest,
2387 vp9_rc_get_svc_params(cpi);
2388 encode_frame_to_data_rate(cpi, size, dest, frame_flags);
2391 static void Pass0Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest,
2393 if (cpi->oxcf.rc_mode == VPX_CBR) {
2394 vp9_rc_get_one_pass_cbr_params(cpi);
2396 vp9_rc_get_one_pass_vbr_params(cpi);
2398 encode_frame_to_data_rate(cpi, size, dest, frame_flags);
2401 static void Pass2Encode(VP9_COMP *cpi, size_t *size,
2403 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED;
2404 encode_frame_to_data_rate(cpi, size, dest, frame_flags);
2405 vp9_twopass_postencode_update(cpi);
2408 static void init_motion_estimation(VP9_COMP *cpi) {
2409 int y_stride = cpi->scaled_source.y_stride;
2411 if (cpi->sf.mv.search_method == NSTEP) {
2412 vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride);
2413 } else if (cpi->sf.mv.search_method == DIAMOND) {
2414 vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride);
2418 static void check_initial_width(VP9_COMP *cpi, int subsampling_x,
2420 VP9_COMMON *const cm = &cpi->common;
2422 if (!cpi->initial_width) {
2426 alloc_raw_frame_buffers(cpi);
2427 alloc_ref_frame_buffers(cpi);
2428 alloc_util_frame_buffers(cpi);
2430 init_motion_estimation(cpi);
2432 cpi->initial_width = cm->width;
2433 cpi->initial_height = cm->height;
2438 int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags,
2441 VP9_COMMON *cm = &cpi->common;
2447 check_initial_width(cpi, subsampling_x, subsampling_y);
2451 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags))
2454 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer);
2473 static int frame_is_reference(const VP9_COMP *cpi) {
2474 const VP9_COMMON *cm = &cpi->common;
2477 cpi->refresh_last_frame ||
2478 cpi->refresh_golden_frame ||
2479 cpi->refresh_alt_ref_frame ||
2486 void adjust_frame_rate(VP9_COMP *cpi,
2491 if (source->ts_start == cpi->first_time_stamp_ever) {
2495 int64_t last_duration = cpi->last_end_time_stamp_seen
2496 - cpi->last_time_stamp_seen;
2498 this_duration = source->ts_end - cpi->last_end_time_stamp_seen;
2507 vp9_new_framerate(cpi, 10000000.0 / this_duration);
2513 - cpi->first_time_stamp_ever), 10000000.0);
2514 double avg_duration = 10000000.0 / cpi->framerate;
2518 vp9_new_framerate(cpi, 10000000.0 / avg_duration);
2521 cpi->last_time_stamp_seen = source->ts_start;
2522 cpi->last_end_time_stamp_seen = source->ts_end;
2527 static int get_arf_src_index(VP9_COMP *cpi) {
2528 RATE_CONTROL *const rc = &cpi->rc;
2530 if (is_altref_enabled(cpi)) {
2531 if (cpi->oxcf.pass == 2) {
2532 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
2543 static void check_src_altref(VP9_COMP *cpi,
2545 RATE_CONTROL *const rc = &cpi->rc;
2547 if (cpi->oxcf.pass == 2) {
2548 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
2552 rc->is_src_frame_alt_ref = cpi->alt_ref_source &&
2553 (source == cpi->alt_ref_source);
2558 cpi->alt_ref_source = NULL;
2562 cpi->refresh_last_frame = 0;
2566 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
2569 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
2570 VP9_COMMON *const cm = &cpi->common;
2571 MACROBLOCKD *const xd = &cpi->mb.e_mbd;
2572 RATE_CONTROL *const rc = &cpi->rc;
2580 if (is_two_pass_svc(cpi)) {
2582 vp9_svc_start_frame(cpi);
2585 vp9_restore_layer_context(cpi);
2590 vp9_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV);
2595 cpi->refresh_last_frame = 1;
2596 cpi->refresh_golden_frame = 0;
2597 cpi->refresh_alt_ref_frame = 0;
2600 arf_src_index = get_arf_src_index(cpi);
2604 if ((source = vp9_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) {
2605 cpi->alt_ref_source = source;
2608 if (is_two_pass_svc(cpi) && cpi->svc.spatial_layer_id > 0) {
2611 for (i = cpi->svc.spatial_layer_id - 1; i >= 0; --i) {
2613 cpi->gld_fb_idx = cpi->svc.layer_context[i].alt_ref_idx;
2618 cpi->svc.layer_context[cpi->svc.spatial_layer_id].has_alt_frame = 1;
2623 vp9_temporal_filter(cpi, arf_src_index);
2624 vp9_extend_frame_borders(&cpi->alt_ref_buffer);
2625 force_src_buffer = &cpi->alt_ref_buffer;
2629 cpi->refresh_alt_ref_frame = 1;
2630 cpi->refresh_golden_frame = 0;
2631 cpi->refresh_last_frame = 0;
2642 if ((last_source = vp9_lookahead_peek(cpi->lookahead, -1)) == NULL)
2648 if (is_two_pass_svc(cpi))
2649 source = vp9_svc_lookahead_pop(cpi, cpi->lookahead, flush);
2652 source = vp9_lookahead_pop(cpi->lookahead, flush);
2658 check_src_altref(cpi, source);
2663 cpi->un_scaled_source = cpi->Source = force_src_buffer ? force_src_buffer
2666 cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL;
2674 if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) {
2675 vp9_end_first_pass(cpi); /* get last stats packet */
2676 cpi->twopass.first_pass_done = 1;
2681 if (source->ts_start < cpi->first_time_stamp_ever) {
2682 cpi->first_time_stamp_ever = source->ts_start;
2683 cpi->last_end_time_stamp_seen = source->ts_start;
2691 adjust_frame_rate(cpi, source);
2694 if (cpi->svc.number_temporal_layers > 1 &&
2696 vp9_update_temporal_layer_framerate(cpi);
2697 vp9_restore_layer_context(cpi);
2711 if ((oxcf->pass == 2) && (!cpi->use_svc || is_two_pass_svc(cpi))) {
2712 vp9_rc_get_second_pass_params(cpi);
2715 if (!cpi->use_svc && cpi->multi_arf_allowed) {
2717 init_buffer_indices(cpi);
2719 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
2720 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index];
2724 cpi->frame_flags = *frame_flags;
2731 vp9_set_size_literal(cpi, oxcf->scaled_frame_width,
2744 alloc_util_frame_buffers(cpi);
2745 init_motion_estimation(cpi);
2748 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)];
2775 (!cpi->use_svc || is_two_pass_svc(cpi))) {
2778 if (cpi->oxcf.use_highbitdepth)
2779 cpi->mb.fwd_txm4x4 = lossless ? vp9_high_fwht4x4 : vp9_high_fdct4x4;
2781 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4;
2782 cpi->mb.high_itxm_add = lossless ? vp9_high_iwht4x4_add :
2785 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4;
2787 cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add;
2788 vp9_first_pass(cpi, source);
2790 (!cpi->use_svc || is_two_pass_svc(cpi))) {
2791 Pass2Encode(cpi, size, dest, frame_flags);
2792 } else if (cpi->use_svc) {
2793 SvcEncode(cpi, size, dest, frame_flags);
2796 Pass0Encode(cpi, size, dest, frame_flags);
2804 release_scaled_references(cpi);
2808 cpi->droppable = !frame_is_reference(cpi);
2812 if ((cpi->svc.number_temporal_layers > 1 &&
2814 ((cpi->svc.number_temporal_layers > 1 ||
2815 cpi->svc.number_spatial_layers > 1) &&
2817 vp9_save_layer_context(cpi);
2821 cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer);
2823 if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame)
2824 generate_psnr_packet(cpi);
2829 cpi->bytes += (int)(*size);
2832 cpi->count++;
2834 if (cpi->b_calculate_psnr) {
2835 YV12_BUFFER_CONFIG *orig = cpi->Source;
2836 YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show;
2841 cpi->total += psnr.psnr[0];
2842 cpi->total_y += psnr.psnr[1];
2843 cpi->total_u += psnr.psnr[2];
2844 cpi->total_v += psnr.psnr[3];
2845 cpi->total_sq_error += psnr.sse[0];
2846 cpi->total_samples += psnr.samples[0];
2861 cpi->totalp += psnr2.psnr[0];
2862 cpi->totalp_y += psnr2.psnr[1];
2863 cpi->totalp_u += psnr2.psnr[2];
2864 cpi->totalp_v += psnr2.psnr[3];
2865 cpi->totalp_sq_error += psnr2.sse[0];
2866 cpi->totalp_samples += psnr2.samples[0];
2870 cpi->summed_quality += frame_ssim2 * weight;
2871 cpi->summed_weights += weight;
2875 cpi->summedp_quality += frame_ssim2 * weight;
2876 cpi->summedp_weights += weight;
2881 cpi->common.current_video_frame, y2, u2, v2,
2890 if (cpi->b_calculate_ssimg) {
2892 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, &v);
2893 cpi->total_ssimg_y += y;
2894 cpi->total_ssimg_u += u;
2895 cpi->total_ssimg_v += v;
2896 cpi->total_ssimg_all += frame_all;
2903 if (is_two_pass_svc(cpi) && cm->show_frame) {
2904 ++cpi->svc.spatial_layer_to_encode;
2905 if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers)
2906 cpi->svc.spatial_layer_to_encode = 0;
2911 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
2913 VP9_COMMON *cm = &cpi->common;
2941 int vp9_set_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols) {
2942 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) {
2943 const int mi_rows = cpi->common.mi_rows;
2944 const int mi_cols = cpi->common.mi_cols;
2949 cpi->segmentation_map[r * mi_cols + c] =
2953 vp9_enable_segfeature(&cpi->common.seg, 1, SEG_LVL_SKIP);
2954 vp9_enable_segmentation(&cpi->common.seg);
2956 vp9_disable_segmentation(&cpi->common.seg);
2964 int vp9_set_internal_size(VP9_COMP *cpi,
2966 VP9_COMMON *cm = &cpi->common;
2976 cm->width = (hs - 1 + cpi->oxcf.width * hr) / hs;
2977 cm->height = (vs - 1 + cpi->oxcf.height * vr) / vs;
2978 assert(cm->width <= cpi->initial_width);
2979 assert(cm->height <= cpi->initial_height);
2981 update_frame_size(cpi);
2986 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
2988 VP9_COMMON *cm = &cpi->common;
2990 check_initial_width(cpi, 1, 1);
2994 if (cm->width * 5 < cpi->initial_width) {
2995 cm->width = cpi->initial_width / 5 + 1;
2998 if (cm->width > cpi->initial_width) {
2999 cm->width = cpi->initial_width;
3006 if (cm->height * 5 < cpi->initial_height) {
3007 cm->height = cpi->initial_height / 5 + 1;
3010 if (cm->height > cpi->initial_height) {
3011 cm->height = cpi->initial_height;
3015 assert(cm->width <= cpi->initial_width);
3016 assert(cm->height <= cpi->initial_height);
3018 update_frame_size(cpi);
3023 void vp9_set_svc(VP9_COMP *cpi, int use_svc) {
3024 cpi->use_svc = use_svc;
3037 int vp9_get_quantizer(VP9_COMP *cpi) {
3038 return cpi->common.base_qindex;
3041 void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags) {
3055 vp9_use_as_reference(cpi, ref);
3072 vp9_update_reference(cpi, upd);
3076 vp9_update_entropy(cpi, 0);