av1代码学习2---av1_get_compressed_da

2020-06-21  本文已影响0人  青吟乐

1,函数功能

函数主要调用 av1_encode_strategy进行下一层的编码,完成后计算psnr,根据相应操作点的级别统计信息和编码的次序对cpi进行更新(便于解码?)

2,代码学习

/*第二层,调用av1_encode_strategy进行下一步编码,获取编码后的数据,计算psnr*/
int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
                            size_t *size, uint8_t *dest, int64_t *time_stamp,
                            int64_t *time_end, int flush,
                            const aom_rational64_t *timestamp_ratio) {
  const AV1EncoderConfig *const oxcf = &cpi->oxcf;
  AV1_COMMON *const cm =
      &cpi->common;  //结构体AV1_COMP中的common部分就是AV1_COMMON

#if CONFIG_BITSTREAM_DEBUG
  assert(cpi->oxcf.max_threads == 0 &&
         "bitstream debug tool does not support multithreading");
  bitstream_queue_record_write();
  aom_bitstream_queue_set_frame_write(cm->current_frame.frame_number * 2 +
                                      cm->show_frame);
#endif
  /*是否是用自适应量化b*/
  cm->use_quant_b_adapt = cpi->oxcf.quant_b_adapt;
  /*解码时候按照当前帧的要求进行解码(看起来像是这样的)*/
  cm->showable_frame = 0;
  *size = 0;
#if CONFIG_INTERNAL_STATS
  struct aom_usec_timer cmptimer;
  aom_usec_timer_start(&cmptimer);
#endif

  // Normal defaults
  cm->refresh_frame_context = oxcf->frame_parallel_decoding_mode
                                  ? REFRESH_FRAME_CONTEXT_DISABLED
                                  : REFRESH_FRAME_CONTEXT_BACKWARD;
  if (oxcf->large_scale_tile)
    cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED;

  // Initialize fields related to forward keyframes
  cpi->no_show_kf = 0;

  if (assign_cur_frame_new_fb(cm) == NULL) return AOM_CODEC_ERROR;
  /*编码入口*/
  const int result =
      av1_encode_strategy(cpi, size, dest, frame_flags, time_stamp, time_end,
                          timestamp_ratio, flush);
  if (result != AOM_CODEC_OK && result != -1) {
    return AOM_CODEC_ERROR;
  } else if (result == -1) {
    // Returning -1 indicates no frame encoded; more input is required
    return -1;
  }
#if CONFIG_INTERNAL_STATS
  aom_usec_timer_mark(&cmptimer);
  cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer);
#endif  // CONFIG_INTERNAL_STATS
  //编码完成后计算psnr
  if (cpi->b_calculate_psnr) {
    if (cm->show_existing_frame || (oxcf->pass != 1 && cm->show_frame)) {
      generate_psnr_packet(cpi);
    }
  }
  //根据相应操作点的级别统计信息和编码的次序对cpi进行初始化
  if (cpi->keep_level_stats && oxcf->pass != 1) {
    // Initialize level info. at the beginning of each sequence.
    if (cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) {
      av1_init_level_info(cpi);
    }
    av1_update_level_info(cpi, *size, *time_stamp, *time_end);
  }

#if CONFIG_INTERNAL_STATS
  if (oxcf->pass != 1) {
    compute_internal_stats(cpi, (int)(*size));
  }
#endif  // CONFIG_INTERNAL_STATS
#if CONFIG_SPEED_STATS
  if (cpi->oxcf.pass != 1 && !cm->show_existing_frame) {
    cpi->tx_search_count += cpi->td.mb.tx_search_count;
    cpi->td.mb.tx_search_count = 0;
  }
#endif  // CONFIG_SPEED_STATS

  aom_clear_system_state();

  return 0;
}

上一篇下一篇

猜你喜欢

热点阅读