/* * Copyright (c) 2016, Alliance for Open Media. All rights reserved. * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent. */ #ifndef AOM_AV1_ENCODER_FIRSTPASS_H_ #define AOM_AV1_ENCODER_FIRSTPASS_H_ #include <stdbool.h> #include "av1/common/av1_common_int.h" #include "av1/common/enums.h" #include "av1/encoder/lookahead.h" #include "av1/encoder/ratectrl.h" #ifdef __cplusplus extern "C" { #endif #define DOUBLE_DIVIDE_CHECK(x) … #define MIN_ZERO_MOTION … #define MAX_SR_CODED_ERROR … #define MAX_RAW_ERR_VAR … #define MIN_MV_IN_OUT … #define VLOW_MOTION_THRESHOLD … struct ThreadData; /*! * \brief The stucture of acummulated frame stats in the first pass. * * Errors (coded_error, intra_error, etc.) and counters (new_mv_count) are * normalized to each MB. MV related stats (MVc, MVr, etc.) are normalized to * the frame width and height. See function normalize_firstpass_stats. */ FIRSTPASS_STATS; // We want to keep one past stats for key frame detection // in test_candidate_kf() #define FIRSTPASS_INFO_STATS_PAST_MIN … // The size of static buffer used in FIRSTPASS_INFO. #define FIRSTPASS_INFO_STATIC_BUF_SIZE … /*! * \brief Data structure used for managing first pass stats */ FIRSTPASS_INFO; /*!\brief Init firstpass_info * * If using ext_stats_buf, the buffer needs to stay available during encoding * process. * * \ingroup rate_control * \param[out] firstpass_info struct of firstpass_info. * \param[in] ext_stats_buf external stats buffer. Pass in NULL if * choose to use internal static_stats_buf. * \param[in] ext_stats_buf_size external stats buffer size. Pass in 0 if * choose to use internal static_stats_buf. \return status */ aom_codec_err_t av1_firstpass_info_init(FIRSTPASS_INFO *firstpass_info, FIRSTPASS_STATS *ext_stats_buf, int ext_stats_buf_size); /*!\brief Move cur_index by 1 * * \ingroup rate_control * \param[out] firstpass_info struct of firstpass_info. * \return status */ aom_codec_err_t av1_firstpass_info_move_cur_index( FIRSTPASS_INFO *firstpass_info); /*!\brief Pop a stats from firstpass_info * * \ingroup rate_control * \param[out] firstpass_info struct of firstpass_info. * \return status */ aom_codec_err_t av1_firstpass_info_pop(FIRSTPASS_INFO *firstpass_info); /*!\brief Move cur_index by 1 and pop a stats from firstpass_info * * \ingroup rate_control * \param[out] firstpass_info struct of firstpass_info. * \return status */ aom_codec_err_t av1_firstpass_info_move_cur_index_and_pop( FIRSTPASS_INFO *firstpass_info); /*!\brief Push a stats into firstpass_info * * Note that the input stats will be copied into firstpass_info. * \ingroup rate_control * \param[out] firstpass_info struct of firstpass_info. * \param[in] input_stats input stats * \return status */ aom_codec_err_t av1_firstpass_info_push(FIRSTPASS_INFO *firstpass_info, const FIRSTPASS_STATS *input_stats); /*!\brief Peek at a stats from firstpass_info * * The target index is as follows. * (cur_index + offset_from_cur) % firstpass_info->stats_buf_size * * \ingroup rate_control * \param[in] firstpass_info struct of firstpass_info. * \param[in] offset_from_cur index offset from cur_index. * \return pointer to the stats. The pointer will be NULL if * stats_index_offset is invalid. */ const FIRSTPASS_STATS *av1_firstpass_info_peek( const FIRSTPASS_INFO *firstpass_info, int offset_from_cur); /*!\brief Count the future stats from the target in firstpass_info * Note that the target stats will be counted as well. * The target index is as follows. * (cur_index + offset_from_cur) % firstpass_info->stats_buf_size * * \ingroup rate_control * \param[in] firstpass_info struct of firstpass_info. * \param[in] offset_from_cur target stats's inffset * from cur_index. * \return Number of stats in the future after the target stats * including itself. */ int av1_firstpass_info_future_count(const FIRSTPASS_INFO *firstpass_info, int offset_from_cur); /*!\cond */ #define FC_ANIMATION_THRESH … enum { … } UENUM1BYTE(…) …; /*!\endcond */ /*! * \brief Data related to the current GF/ARF group and the * individual frames within the group */ GF_GROUP; /*!\cond */ GF_STATE; STATS_BUFFER_CTX; /*!\endcond */ /*! * \brief Two pass status and control data. */ TWO_PASS; /*! * \brief Frame level Two pass status and control data. */ TWO_PASS_FRAME; /*!\cond */ // This structure contains several key parameters to be accumulated for this // frame. FRAME_STATS; // This structure contains first pass data. FirstPassData; struct AV1_COMP; struct EncodeFrameParams; struct AV1EncoderConfig; struct TileDataEnc; static inline int is_fp_wavelet_energy_invalid( const FIRSTPASS_STATS *fp_stats) { … } static inline BLOCK_SIZE get_fp_block_size(int is_screen_content_type) { … } int av1_get_unit_rows_in_tile(const TileInfo *tile, const BLOCK_SIZE fp_block_size); int av1_get_unit_cols_in_tile(const TileInfo *tile, const BLOCK_SIZE fp_block_size); void av1_first_pass_row(struct AV1_COMP *cpi, struct ThreadData *td, struct TileDataEnc *tile_data, const int mb_row, const BLOCK_SIZE fp_block_size); void av1_end_first_pass(struct AV1_COMP *cpi); void av1_free_firstpass_data(FirstPassData *firstpass_data); void av1_twopass_zero_stats(FIRSTPASS_STATS *section); void av1_accumulate_stats(FIRSTPASS_STATS *section, const FIRSTPASS_STATS *frame); /*!\endcond */ /*!\brief AV1 first pass encoding. * * \ingroup rate_control * This function is the first encoding pass for the two pass encoding mode. * It encodes the whole video and collect essential information. * Two pass encoding is an encoding mode in the reference software (libaom) * of AV1 for high performance encoding. The first pass is a fast encoding * process to collect essential information to help the second pass make * encoding decisions and improve coding quality. The collected stats is used * in rate control, for example, to determine frame cut, the position of * alternative reference frame (ARF), etc. * * \param[in] cpi Top-level encoder structure * \param[in] ts_duration Duration of the frame / collection of frames * * \remark Nothing is returned. Instead, the "TWO_PASS" structure inside "cpi" * is modified to store information computed in this function. */ void av1_first_pass(struct AV1_COMP *cpi, const int64_t ts_duration); void av1_noop_first_pass_frame(struct AV1_COMP *cpi, const int64_t ts_duration); #ifdef __cplusplus } // extern "C" #endif #endif // AOM_AV1_ENCODER_FIRSTPASS_H_