av1/encoder/encoder.c
// Determines whether to use screen content tools for the key frame group.
// This function modifies "cm->allow_screen_content_tools",
// "cm->allow_intrabc" and "cpi->is_screen_content_type".
Determines whether to use screen content tools for the key frame group.
Determines whether to use screen content tools for the key frame group .
static void determine_sc_tools_with_encoding(AV1_COMP *cpi, const int q_orig) {
  if (!is_stat_consumption_stage_twopass(cpi)) return;
  AV1_COMMON *const cm = &cpi->common;
  int projected_size_pass[3] = { 0 };
  PSNR_STATS psnr[3];
  const int is_key_frame = cm->current_frame.frame_type == KEY_FRAME;
  const int allow_screen_content_tools_orig_decision =
      cm->allow_screen_content_tools;
  const int allow_intrabc_orig_decision = cm->allow_intrabc;
  const int is_screen_content_type_orig_decision = cpi->is_screen_content_type;
  if (cpi->sf.rt_sf.use_nonrd_pick_mode || cpi->oxcf.fwd_kf_enabled ||
      cpi->oxcf.superres_mode != SUPERRES_NONE || cpi->oxcf.mode == REALTIME ||
      is_screen_content_type_orig_decision || !is_key_frame) {
    return;
  }
  const int q_for_screen_content_quick_run =
      is_lossless_requested(&cpi->oxcf) ? q_orig : AOMMAX(q_orig, 244);
  const int partition_search_type_orig = cpi->sf.part_sf.partition_search_type;
  const BLOCK_SIZE fixed_partition_block_size_orig =
      cpi->sf.part_sf.always_this_block_size;
  {
    aom_clear_system_state();
    cpi->source =
        av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source);
    if (cpi->unscaled_last_source != NULL) {
      cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source,
                                               &cpi->scaled_last_source);
    }
    setup_frame(cpi);
    if (cm->seg.enabled) {
      if (!cm->seg.update_data && cm->prev_frame) {
        segfeatures_copy(&cm->seg, &cm->prev_frame->seg);
        cm->seg.enabled = cm->prev_frame->seg.enabled;
      } else {
        av1_calculate_segdata(&cm->seg);
      }
    } else {
      memset(&cm->seg, 0, sizeof(cm->seg));
    }
    segfeatures_copy(&cm->cur_frame->seg, &cm->seg);
    cm->cur_frame->seg.enabled = cm->seg.enabled;
  }
  for (int pass = 0; pass < 2; ++pass) {
    set_or_save_encoding_params_for_screen_content(cpi, pass);
#if CONFIG_TUNE_VMAF
    if (cpi->oxcf.tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING ||
        cpi->oxcf.tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING ||
        cpi->oxcf.tuning == AOM_TUNE_VMAF_MAX_GAIN) {
      av1_set_quantizer(
          cm, av1_get_vmaf_base_qindex(cpi, q_for_screen_content_quick_run));
    } else {
#endif
      av1_set_quantizer(cm, q_for_screen_content_quick_run);
#if CONFIG_TUNE_VMAF
    }
#endif
    if (cpi->oxcf.deltaq_mode != NO_DELTA_Q) av1_init_quantizer(cpi);
    av1_set_variance_partition_thresholds(cpi, q_for_screen_content_quick_run,
                                          0);
    av1_encode_frame(cpi);
    screen_content_tools_determination(
        cpi, allow_screen_content_tools_orig_decision,
        allow_intrabc_orig_decision, is_screen_content_type_orig_decision, pass,
        projected_size_pass, psnr);
  }
  cpi->sf.part_sf.partition_search_type = partition_search_type_orig;
  cpi->sf.part_sf.always_this_block_size = fixed_partition_block_size_orig;
}
static void determine_sc_tools_with_encoding ( AV1_COMP * cpi , const int q_orig ) { if ( ! is_stat_consumption_stage_twopass ( cpi ) ) return ; AV1_COMMON * const cm = & cpi -> common ; int projected_size_pass [ 3 ] = { 0 } ; PSNR_STATS psnr [ 3 ] ; const int is_key_frame = cm -> current_frame . frame_type == KEY_FRAME ; const int allow_screen_content_tools_orig_decision = cm -> allow_screen_content_tools ; const int allow_intrabc_orig_decision = cm -> allow_intrabc ; const int is_screen_content_type_orig_decision = cpi -> is_screen_content_type ; if ( cpi -> sf . rt_sf . use_nonrd_pick_mode || cpi -> oxcf . fwd_kf_enabled || cpi -> oxcf . superres_mode != SUPERRES_NONE || cpi -> oxcf . mode == REALTIME || is_screen_content_type_orig_decision || ! is_key_frame ) { return ; } const int q_for_screen_content_quick_run = is_lossless_requested ( & cpi -> oxcf ) ? q_orig : AOMMAX ( q_orig , 244 ) ; const int partition_search_type_orig = cpi -> sf . part_sf . partition_search_type ; const BLOCK_SIZE fixed_partition_block_size_orig = cpi -> sf . part_sf . always_this_block_size ; { aom_clear_system_state ( ) ; cpi -> source = av1_scale_if_required ( cm , cpi -> unscaled_source , & cpi -> scaled_source ) ; if ( cpi -> unscaled_last_source != NULL ) { cpi -> last_source = av1_scale_if_required ( cm , cpi -> unscaled_last_source , & cpi -> scaled_last_source ) ; } setup_frame ( cpi ) ; if ( cm -> seg . enabled ) { if ( ! cm -> seg . update_data && cm -> prev_frame ) { segfeatures_copy ( & cm -> seg , & cm -> prev_frame -> seg ) ; cm -> seg . enabled = cm -> prev_frame -> seg . enabled ; } else { av1_calculate_segdata ( & cm -> seg ) ; } } else { memset ( & cm -> seg , 0 , sizeof ( cm -> seg ) ) ; } segfeatures_copy ( & cm -> cur_frame -> seg , & cm -> seg ) ; cm -> cur_frame -> seg . enabled = cm -> seg . enabled ; } for ( int pass = 0 ; pass < 2 ; ++ pass ) { set_or_save_encoding_params_for_screen_content ( cpi , pass ) ; #if CONFIG_TUNE_VMAF if ( cpi -> oxcf . tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING || cpi -> oxcf . tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING || cpi -> oxcf . tuning == AOM_TUNE_VMAF_MAX_GAIN ) { av1_set_quantizer ( cm , av1_get_vmaf_base_qindex ( cpi , q_for_screen_content_quick_run ) ) ; } else { #endif 
      av1_set_quantizer(cm, q_for_screen_content_quick_run); #if CONFIG_TUNE_VMAF } #endif if ( cpi -> oxcf . deltaq_mode != NO_DELTA_Q ) av1_init_quantizer ( cpi ) ; av1_set_variance_partition_thresholds ( cpi , q_for_screen_content_quick_run , 0 ) ; av1_encode_frame ( cpi ) ; screen_content_tools_determination ( cpi , allow_screen_content_tools_orig_decision , allow_intrabc_orig_decision , is_screen_content_type_orig_decision , pass , projected_size_pass , psnr ) ; } cpi -> sf . part_sf . partition_search_type = partition_search_type_orig ; cpi -> sf . part_sf . always_this_block_size = fixed_partition_block_size_orig ; }
Determines whether to use screen content tools for the key frame group.
Determines whether to use screen content tools for the key frame group .
// Variables to help determine if we should allow screen content tools. // Turn off the encoding trial for forward key frame and superres. // TODO(chengchen): multiple encoding for the lossless mode is time consuming. // Find a better way to determine whether screen content tools should be used // for lossless coding. // Use a high q and a fixed partition to do quick encoding. // Setup necessary params for encoding, including frame source, etc. // The two encodes is to help determine whether to use screen content tools, // with a high q and fixed partition. // Then reset the partition speed feature. // transform / motion compensation build reconstruction frame // Screen content decision // Set partition speed feature back.