2014-06-03 11:51:30 +00:00
|
|
|
#ifndef ENCODERSTATE_H_
|
|
|
|
#define ENCODERSTATE_H_
|
|
|
|
/*****************************************************************************
|
2021-11-23 06:46:06 +00:00
|
|
|
* This file is part of uvg266 VVC encoder.
|
2014-06-03 11:51:30 +00:00
|
|
|
*
|
2021-10-07 08:32:59 +00:00
|
|
|
* Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
* other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
|
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
* INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
|
2014-06-03 11:51:30 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-12-17 11:42:57 +00:00
|
|
|
/**
|
|
|
|
* \ingroup Control
|
2014-06-03 11:51:30 +00:00
|
|
|
* \file
|
2015-12-17 11:42:57 +00:00
|
|
|
* Top level of the encoder implementation.
|
2014-06-03 11:51:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bitstream.h"
|
|
|
|
#include "cabac.h"
|
2016-04-01 14:14:23 +00:00
|
|
|
#include "cu.h"
|
|
|
|
#include "encoder.h"
|
|
|
|
#include "global.h" // IWYU pragma: keep
|
|
|
|
#include "image.h"
|
|
|
|
#include "imagelist.h"
|
2022-04-28 11:26:05 +00:00
|
|
|
#include "uvg266.h"
|
2014-06-03 11:51:30 +00:00
|
|
|
#include "tables.h"
|
|
|
|
#include "threadqueue.h"
|
2016-04-01 14:14:23 +00:00
|
|
|
#include "videoframe.h"
|
2014-06-04 14:45:46 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
struct uvg_rc_data;
|
2014-06-04 14:45:46 +00:00
|
|
|
|
2014-06-03 11:51:30 +00:00
|
|
|
typedef enum {
|
|
|
|
ENCODER_STATE_TYPE_INVALID = 'i',
|
|
|
|
ENCODER_STATE_TYPE_MAIN = 'M',
|
|
|
|
ENCODER_STATE_TYPE_SLICE = 'S',
|
|
|
|
ENCODER_STATE_TYPE_TILE = 'T',
|
|
|
|
ENCODER_STATE_TYPE_WAVEFRONT_ROW = 'W',
|
|
|
|
} encoder_state_type;
|
|
|
|
|
|
|
|
|
2016-08-24 01:16:48 +00:00
|
|
|
typedef struct lcu_stats_t {
|
|
|
|
//! \brief Number of bits that were spent
|
|
|
|
uint32_t bits;
|
|
|
|
|
2019-09-03 07:57:13 +00:00
|
|
|
uint32_t pixels;
|
|
|
|
|
2016-08-24 01:16:48 +00:00
|
|
|
//! \brief Weight of the LCU for rate control
|
|
|
|
double weight;
|
|
|
|
|
2019-11-13 06:55:31 +00:00
|
|
|
double original_weight;
|
|
|
|
|
2016-08-24 01:16:48 +00:00
|
|
|
//! \brief Lambda value which was used for this LCU
|
|
|
|
double lambda;
|
|
|
|
|
2020-09-14 11:24:56 +00:00
|
|
|
double adjust_lambda;
|
|
|
|
|
2016-08-24 01:16:48 +00:00
|
|
|
//! \brief Rate control alpha parameter
|
|
|
|
double rc_alpha;
|
|
|
|
|
|
|
|
//! \brief Rate control beta parameter
|
|
|
|
double rc_beta;
|
2019-09-26 10:09:28 +00:00
|
|
|
double distortion;
|
2019-10-09 07:30:24 +00:00
|
|
|
int i_cost;
|
2019-09-26 10:09:28 +00:00
|
|
|
|
2019-09-25 09:12:21 +00:00
|
|
|
int8_t qp;
|
2020-09-14 11:24:56 +00:00
|
|
|
int8_t adjust_qp;
|
2019-09-26 10:09:28 +00:00
|
|
|
uint8_t skipped;
|
2016-08-24 01:16:48 +00:00
|
|
|
} lcu_stats_t;
|
|
|
|
|
2014-06-03 11:51:30 +00:00
|
|
|
|
2016-08-10 00:46:23 +00:00
|
|
|
typedef struct encoder_state_config_frame_t {
|
2016-08-21 04:16:59 +00:00
|
|
|
/**
|
|
|
|
* \brief Frame-level lambda.
|
|
|
|
*
|
|
|
|
* Use state->lambda or state->lambda_sqrt for cost computations.
|
|
|
|
*
|
|
|
|
* \see encoder_state_t::lambda
|
|
|
|
* \see encoder_state_t::lambda_sqrt
|
|
|
|
*/
|
|
|
|
double lambda;
|
|
|
|
|
2016-08-10 00:46:23 +00:00
|
|
|
int32_t num; /*!< \brief Frame number */
|
|
|
|
int32_t poc; /*!< \brief Picture order count */
|
|
|
|
int8_t gop_offset; /*!< \brief Offset in the gop structure */
|
2017-09-19 06:20:10 +00:00
|
|
|
int32_t irap_poc; /*!< \brief POC of the associated IRAP picture */
|
2016-08-21 04:16:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Frame-level quantization parameter
|
|
|
|
*
|
|
|
|
* \see encoder_state_t::qp
|
|
|
|
*/
|
|
|
|
int8_t QP;
|
|
|
|
//! \brief quantization factor
|
|
|
|
double QP_factor;
|
|
|
|
|
2017-06-26 12:31:57 +00:00
|
|
|
//! Current pictures available for references
|
2015-03-04 14:13:57 +00:00
|
|
|
image_list_t *ref;
|
2014-06-03 11:51:30 +00:00
|
|
|
int8_t ref_list;
|
2015-03-19 10:24:52 +00:00
|
|
|
|
2017-06-26 12:31:57 +00:00
|
|
|
//! L0 and L1 reference index list
|
|
|
|
uint8_t ref_LX[2][16];
|
|
|
|
//! L0 reference index list size
|
|
|
|
uint8_t ref_LX_size[2];
|
2017-09-19 06:20:10 +00:00
|
|
|
|
|
|
|
bool is_irap;
|
2014-06-03 11:51:30 +00:00
|
|
|
uint8_t pictype;
|
2022-04-28 11:18:09 +00:00
|
|
|
enum uvg_slice_type slicetype;
|
2015-04-17 14:31:22 +00:00
|
|
|
|
|
|
|
//! Total number of bits written.
|
|
|
|
uint64_t total_bits_coded;
|
2015-04-29 11:24:33 +00:00
|
|
|
|
|
|
|
//! Number of bits written in the current GOP.
|
|
|
|
uint64_t cur_gop_bits_coded;
|
|
|
|
|
2020-03-19 08:47:28 +00:00
|
|
|
//! Number of bits written in the current frame.
|
2019-09-26 10:09:28 +00:00
|
|
|
uint64_t cur_frame_bits_coded;
|
|
|
|
|
2015-05-04 09:20:41 +00:00
|
|
|
//! Number of bits targeted for the current GOP.
|
2015-05-06 11:08:18 +00:00
|
|
|
double cur_gop_target_bits;
|
|
|
|
|
2016-08-24 02:38:10 +00:00
|
|
|
//! Number of bits targeted for the current picture.
|
|
|
|
double cur_pic_target_bits;
|
|
|
|
|
2015-05-06 11:08:18 +00:00
|
|
|
// Parameters used in rate control
|
|
|
|
double rc_alpha;
|
|
|
|
double rc_beta;
|
2015-05-04 09:20:41 +00:00
|
|
|
|
2016-08-21 03:27:58 +00:00
|
|
|
/**
|
|
|
|
* \brief Indicates that this encoder state is ready for encoding the
|
2022-04-28 11:18:09 +00:00
|
|
|
* next frame i.e. uvg_encoder_prepare has been called.
|
2016-08-21 03:27:58 +00:00
|
|
|
*/
|
|
|
|
bool prepared;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Indicates that the previous frame has been encoded and the
|
|
|
|
* encoded data written and the encoding the next frame has not been
|
|
|
|
* started yet.
|
|
|
|
*/
|
|
|
|
bool done;
|
|
|
|
|
2016-08-24 01:16:48 +00:00
|
|
|
/**
|
|
|
|
* \brief Information about the coded LCUs.
|
|
|
|
*
|
|
|
|
* Used for rate control.
|
|
|
|
*/
|
|
|
|
lcu_stats_t *lcu_stats;
|
|
|
|
|
2019-11-12 10:12:57 +00:00
|
|
|
pthread_mutex_t rc_lock;
|
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
struct uvg_rc_data *new_ratecontrol;
|
2019-09-03 07:57:13 +00:00
|
|
|
|
2020-03-19 08:47:28 +00:00
|
|
|
struct encoder_state_t const *previous_layer_state;
|
2020-03-18 10:29:25 +00:00
|
|
|
|
2020-02-04 12:15:38 +00:00
|
|
|
/**
|
|
|
|
* \brief Calculated adaptive QP offset for each LCU.
|
|
|
|
*/
|
|
|
|
double *aq_offsets;
|
|
|
|
|
2022-02-06 18:08:28 +00:00
|
|
|
int8_t max_qp_delta_depth;
|
|
|
|
|
2017-01-31 10:28:28 +00:00
|
|
|
/**
|
|
|
|
* \brief Whether next NAL is the first NAL in the access unit.
|
|
|
|
*/
|
|
|
|
bool first_nal;
|
2019-10-09 12:48:58 +00:00
|
|
|
double icost;
|
2019-11-12 10:12:57 +00:00
|
|
|
double remaining_weight;
|
2019-10-09 12:48:58 +00:00
|
|
|
double i_bits_left;
|
2017-01-31 10:28:28 +00:00
|
|
|
|
2019-12-05 09:58:18 +00:00
|
|
|
double *c_para;
|
|
|
|
double *k_para;
|
2021-01-04 17:04:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
cu_info_t* hmvp_lut; //!< \brief Look-up table for HMVP, one for each LCU row
|
|
|
|
uint8_t* hmvp_size; //!< \brief HMVP LUT size
|
2022-04-20 05:12:42 +00:00
|
|
|
bool jccr_sign;
|
2021-01-04 17:04:50 +00:00
|
|
|
|
2016-08-10 00:46:23 +00:00
|
|
|
} encoder_state_config_frame_t;
|
2014-06-03 11:51:30 +00:00
|
|
|
|
2016-08-10 00:46:23 +00:00
|
|
|
typedef struct encoder_state_config_tile_t {
|
2014-06-05 12:54:58 +00:00
|
|
|
//Current sub-frame
|
2015-03-04 11:17:33 +00:00
|
|
|
videoframe_t *frame;
|
2014-06-03 11:51:30 +00:00
|
|
|
|
|
|
|
int32_t id;
|
2017-05-31 10:17:59 +00:00
|
|
|
|
2014-06-03 11:51:30 +00:00
|
|
|
//Tile: offset in LCU for current encoder_state in global coordinates
|
|
|
|
int32_t lcu_offset_x;
|
|
|
|
int32_t lcu_offset_y;
|
2017-05-31 10:17:59 +00:00
|
|
|
|
|
|
|
//Tile: offset in pixels
|
|
|
|
int32_t offset_x;
|
|
|
|
int32_t offset_y;
|
|
|
|
|
2014-06-03 11:51:30 +00:00
|
|
|
//Position of the first element in tile scan in global coordinates
|
|
|
|
int32_t lcu_offset_in_ts;
|
|
|
|
|
2016-08-17 12:56:34 +00:00
|
|
|
// This is a buffer for the non-loopfiltered bottom pixels of every LCU-row
|
|
|
|
// in the tile. They are packed such that each LCU-row index maps to the
|
|
|
|
// y-coordinate.
|
2014-06-03 11:51:30 +00:00
|
|
|
yuv_t *hor_buf_search;
|
2016-08-17 12:56:34 +00:00
|
|
|
// This is a buffer for the non-loopfiltered rightmost pixels of every
|
|
|
|
// LCU-column. They are packed such that each LCU-column index maps to the
|
|
|
|
// x-coordinate.
|
2014-06-03 11:51:30 +00:00
|
|
|
yuv_t *ver_buf_search;
|
2017-06-30 13:12:52 +00:00
|
|
|
|
|
|
|
// This is a buffer for the deblocked bottom pixels of every LCU in the
|
|
|
|
// tile. They are packed such that each LCU-row index maps to the
|
|
|
|
// y-coordinate.
|
2014-06-03 11:51:30 +00:00
|
|
|
yuv_t *hor_buf_before_sao;
|
2017-06-30 13:12:52 +00:00
|
|
|
|
|
|
|
// This is a buffer for the deblocked right pixels of every LCU in the
|
|
|
|
// tile. They are packed such that each LCU-column index maps to the
|
|
|
|
// x-coordinate.
|
|
|
|
yuv_t *ver_buf_before_sao;
|
|
|
|
|
2015-03-17 09:13:48 +00:00
|
|
|
//Jobs for each individual LCU of a wavefront row.
|
2015-03-04 14:28:56 +00:00
|
|
|
threadqueue_job_t **wf_jobs;
|
2021-07-23 07:40:19 +00:00
|
|
|
threadqueue_job_t **wf_recon_jobs;
|
2016-06-06 14:23:47 +00:00
|
|
|
|
2015-03-04 11:48:58 +00:00
|
|
|
} encoder_state_config_tile_t;
|
2014-06-03 11:51:30 +00:00
|
|
|
|
2021-07-23 18:44:09 +00:00
|
|
|
typedef struct encoder_state_config_alf_t {
|
2019-08-15 08:01:38 +00:00
|
|
|
//ALF adaptation parameter set
|
2021-07-23 18:44:09 +00:00
|
|
|
struct alf_aps* apss; //[ALF_CTB_MAX_NUM_APS];
|
|
|
|
struct cc_alf_filter_param* cc_filter_param;
|
2019-08-15 08:01:38 +00:00
|
|
|
int tile_group_num_aps;
|
2021-07-23 18:44:09 +00:00
|
|
|
int8_t* tile_group_luma_aps_id;
|
2019-08-15 08:01:38 +00:00
|
|
|
int tile_group_chroma_aps_id;
|
2020-08-07 09:09:19 +00:00
|
|
|
bool tile_group_cc_alf_cb_enabled_flag;
|
|
|
|
bool tile_group_cc_alf_cr_enabled_flag;
|
|
|
|
int tile_group_cc_alf_cb_aps_id;
|
|
|
|
int tile_group_cc_alf_cr_aps_id;
|
2020-10-13 14:43:03 +00:00
|
|
|
//struct param_set_map *param_set_map; //mahdollisesti define during run
|
2019-08-15 08:01:38 +00:00
|
|
|
uint32_t num_of_param_sets;
|
|
|
|
bool tile_group_alf_enabled_flag[3/*MAX_NUM_COMPONENT*/];
|
2021-07-23 18:44:09 +00:00
|
|
|
} encoder_state_config_alf_t;
|
|
|
|
|
|
|
|
typedef struct encoder_state_config_slice_t {
|
|
|
|
int32_t id;
|
|
|
|
|
|
|
|
//Global coordinates
|
|
|
|
int32_t start_in_ts;
|
|
|
|
int32_t end_in_ts;
|
|
|
|
|
|
|
|
//Global coordinates
|
|
|
|
int32_t start_in_rs;
|
|
|
|
int32_t end_in_rs;
|
2019-08-15 08:01:38 +00:00
|
|
|
|
2021-07-23 18:44:09 +00:00
|
|
|
encoder_state_config_alf_t *alf;
|
2020-10-01 15:57:06 +00:00
|
|
|
//unsigned num_hor_virtual_boundaries;
|
|
|
|
//unsigned num_ver_virtual_boundaries;
|
|
|
|
//unsigned virtual_boundaries_pos_x[3];
|
|
|
|
//unsigned virtual_boundaries_pos_y[3];
|
2015-03-04 11:48:58 +00:00
|
|
|
} encoder_state_config_slice_t;
|
2014-06-03 11:51:30 +00:00
|
|
|
|
2016-08-10 00:46:23 +00:00
|
|
|
typedef struct encoder_state_config_wfrow_t {
|
2014-06-03 11:51:30 +00:00
|
|
|
//Row in tile coordinates of the wavefront
|
|
|
|
int32_t lcu_offset_y;
|
2015-03-04 11:48:58 +00:00
|
|
|
} encoder_state_config_wfrow_t;
|
2014-06-03 11:51:30 +00:00
|
|
|
|
|
|
|
typedef struct lcu_order_element {
|
|
|
|
//This it used for leaf of the encoding tree. All is relative to the tile.
|
|
|
|
int id;
|
|
|
|
int index;
|
2015-03-04 10:25:42 +00:00
|
|
|
struct encoder_state_t *encoder_state;
|
2015-03-04 11:32:11 +00:00
|
|
|
vector2d_t position;
|
|
|
|
vector2d_t position_px; //Top-left
|
|
|
|
vector2d_t size;
|
2014-06-03 11:51:30 +00:00
|
|
|
int first_column;
|
|
|
|
int first_row;
|
|
|
|
int last_column;
|
|
|
|
int last_row;
|
2020-09-24 14:07:37 +00:00
|
|
|
lcu_coeff_t *coeff;
|
2014-06-03 11:51:30 +00:00
|
|
|
|
|
|
|
struct lcu_order_element *above;
|
|
|
|
struct lcu_order_element *below;
|
|
|
|
struct lcu_order_element *left;
|
|
|
|
struct lcu_order_element *right;
|
2015-03-04 11:49:59 +00:00
|
|
|
} lcu_order_element_t;
|
2014-06-03 11:51:30 +00:00
|
|
|
|
2015-03-04 10:25:42 +00:00
|
|
|
typedef struct encoder_state_t {
|
2015-03-04 10:26:57 +00:00
|
|
|
const encoder_control_t *encoder_control;
|
2014-06-03 11:51:30 +00:00
|
|
|
encoder_state_type type;
|
|
|
|
|
|
|
|
//List of children, the last item of this list is a pseudo-encoder with encoder_control = NULL
|
|
|
|
//Use for (i = 0; encoder_state->children[i].encoder_control; ++i) {
|
2015-03-04 10:25:42 +00:00
|
|
|
struct encoder_state_t *children;
|
|
|
|
struct encoder_state_t *parent;
|
2014-06-03 11:51:30 +00:00
|
|
|
|
2014-06-05 07:09:25 +00:00
|
|
|
//Pointer to the encoder_state of the previous frame
|
2015-03-04 10:25:42 +00:00
|
|
|
struct encoder_state_t *previous_encoder_state;
|
2020-03-18 10:29:25 +00:00
|
|
|
|
2016-08-10 00:46:23 +00:00
|
|
|
encoder_state_config_frame_t *frame;
|
2015-03-04 11:48:58 +00:00
|
|
|
encoder_state_config_tile_t *tile;
|
|
|
|
encoder_state_config_slice_t *slice;
|
|
|
|
encoder_state_config_wfrow_t *wfrow;
|
2014-06-03 11:51:30 +00:00
|
|
|
|
|
|
|
int is_leaf; //A leaf encoder state is one which should encode LCUs...
|
2015-03-04 11:49:59 +00:00
|
|
|
lcu_order_element_t *lcu_order;
|
2014-06-03 11:51:30 +00:00
|
|
|
uint32_t lcu_order_count;
|
|
|
|
|
2015-03-04 11:20:18 +00:00
|
|
|
bitstream_t stream;
|
2015-03-04 11:27:32 +00:00
|
|
|
cabac_data_t cabac;
|
2021-12-03 07:09:57 +00:00
|
|
|
cabac_data_t search_cabac;
|
2015-06-17 11:17:30 +00:00
|
|
|
|
2014-06-19 08:23:01 +00:00
|
|
|
uint32_t stats_bitstream_length; //Bitstream length written in bytes
|
2016-08-21 04:16:59 +00:00
|
|
|
|
|
|
|
//! \brief Lambda for SSE
|
|
|
|
double lambda;
|
|
|
|
//! \brief Lambda for SAD and SATD
|
|
|
|
double lambda_sqrt;
|
|
|
|
//! \brief Quantization parameter for the current LCU
|
|
|
|
int8_t qp;
|
|
|
|
|
2021-03-16 08:22:40 +00:00
|
|
|
double c_lambda;
|
|
|
|
|
2016-08-21 04:36:13 +00:00
|
|
|
/**
|
|
|
|
* \brief Whether a QP delta value must be coded for the current LCU.
|
|
|
|
*/
|
|
|
|
bool must_code_qp_delta;
|
|
|
|
|
|
|
|
/**
|
2017-05-08 07:54:06 +00:00
|
|
|
* \brief QP value of the last CU in the last coded quantization group.
|
|
|
|
*
|
|
|
|
* A quantization group is a square of width
|
|
|
|
* (LCU_WIDTH >> encoder_control->max_qp_delta_depth). All CUs of in the
|
|
|
|
* same quantization group share the QP predictor value, but may have
|
|
|
|
* different QP values.
|
|
|
|
*
|
|
|
|
* Set to the frame QP at the beginning of a wavefront row or a tile and
|
|
|
|
* updated when the last CU of a quantization group is coded.
|
2016-08-21 04:36:13 +00:00
|
|
|
*/
|
2017-05-08 07:54:06 +00:00
|
|
|
int8_t last_qp;
|
2016-08-21 04:36:13 +00:00
|
|
|
|
2014-06-05 07:09:25 +00:00
|
|
|
//Jobs to wait for
|
2015-03-04 14:28:56 +00:00
|
|
|
threadqueue_job_t * tqj_recon_done; //Reconstruction is done
|
|
|
|
threadqueue_job_t * tqj_bitstream_written; //Bitstream is written
|
2021-07-22 20:21:00 +00:00
|
|
|
threadqueue_job_t* tqj_alf_process; //ALF processed for the slice
|
2019-08-28 15:45:58 +00:00
|
|
|
|
|
|
|
//Constraint structure
|
|
|
|
void * constraint;
|
|
|
|
|
|
|
|
|
2015-03-04 10:25:42 +00:00
|
|
|
} encoder_state_t;
|
2014-06-03 11:51:30 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
void uvg_encode_one_frame(encoder_state_t * const state, uvg_picture* frame);
|
2014-06-03 11:51:30 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
void uvg_encoder_prepare(encoder_state_t *state);
|
2014-06-03 11:51:30 +00:00
|
|
|
|
2014-06-03 12:25:16 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
int uvg_encoder_state_match_children_of_previous_frame(encoder_state_t * const state);
|
2014-06-05 07:09:25 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
coeff_scan_order_t uvg_get_scan_order(int8_t cu_type, int intra_mode, int depth);
|
2014-06-03 11:51:30 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
void uvg_encoder_create_ref_lists(const encoder_state_t *const state);
|
2015-05-14 15:33:57 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
lcu_stats_t* uvg_get_lcu_stats(encoder_state_t *state, int lcu_x, int lcu_y);
|
2016-08-24 01:16:48 +00:00
|
|
|
|
2016-10-06 12:27:01 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
int uvg_get_cu_ref_qp(const encoder_state_t *state, int x, int y, int last_qp);
|
2017-05-08 07:54:06 +00:00
|
|
|
|
2016-10-06 12:27:01 +00:00
|
|
|
/**
|
|
|
|
* Whether the parameter sets should be written with the current frame.
|
|
|
|
*/
|
|
|
|
static INLINE bool encoder_state_must_write_vps(const encoder_state_t *state)
|
|
|
|
{
|
|
|
|
const int32_t frame = state->frame->num;
|
2017-02-06 11:00:25 +00:00
|
|
|
const int32_t vps_period = state->encoder_control->cfg.vps_period;
|
2016-10-06 12:27:01 +00:00
|
|
|
|
|
|
|
return (vps_period > 0 && frame % vps_period == 0) ||
|
|
|
|
(vps_period >= 0 && frame == 0);
|
|
|
|
}
|
|
|
|
|
2017-05-08 07:54:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Returns true if the CU is the last CU in its containing
|
|
|
|
* quantization group.
|
|
|
|
*
|
|
|
|
* \param state encoder state
|
|
|
|
* \param x x-coordinate of the left edge of the CU
|
|
|
|
* \param y y-cooradinate of the top edge of the CU
|
|
|
|
* \param depth depth in the CU tree
|
|
|
|
* \return true, if it's the last CU in its QG, otherwise false
|
|
|
|
*/
|
|
|
|
static INLINE bool is_last_cu_in_qg(const encoder_state_t *state, int x, int y, int depth)
|
|
|
|
{
|
2022-02-06 18:08:28 +00:00
|
|
|
if (state->frame->max_qp_delta_depth < 0) return false;
|
2017-05-08 07:54:06 +00:00
|
|
|
|
|
|
|
const int cu_width = LCU_WIDTH >> depth;
|
2022-02-06 18:08:28 +00:00
|
|
|
const int qg_width = LCU_WIDTH >> state->frame->max_qp_delta_depth;
|
2017-05-08 07:54:06 +00:00
|
|
|
const int right = x + cu_width;
|
|
|
|
const int bottom = y + cu_width;
|
|
|
|
return (right % qg_width == 0 || right >= state->tile->frame->width) &&
|
|
|
|
(bottom % qg_width == 0 || bottom >= state->tile->frame->height);
|
|
|
|
}
|
|
|
|
|
2019-06-05 12:57:18 +00:00
|
|
|
static const uint8_t g_group_idx[64] = {
|
|
|
|
0, 1, 2, 3, 4, 4, 5, 5,
|
|
|
|
6, 6, 6, 6, 7, 7, 7, 7,
|
|
|
|
8, 8, 8, 8, 8, 8, 8, 8,
|
|
|
|
9, 9, 9, 9, 9, 9, 9, 9,
|
|
|
|
10,10,10,10,10,10,10,10,
|
|
|
|
10,10,10,10,10,10,10,10,
|
|
|
|
11,11,11,11,11,11,11,11,
|
|
|
|
11,11,11,11,11,11,11,11
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2018-08-30 12:04:04 +00:00
|
|
|
static const uint8_t g_group_idx[128] = {
|
2014-06-03 11:51:30 +00:00
|
|
|
0, 1, 2, 3, 4, 4, 5, 5, 6, 6,
|
|
|
|
6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
|
|
|
|
8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
|
2018-08-30 12:04:04 +00:00
|
|
|
9, 9,10,10,10,10,10,10,10,10,
|
|
|
|
10,10,10,10,10,10,10,10,11,11,
|
|
|
|
11,11,11,11,11,11,11,11,11,11,
|
|
|
|
11,11,11,11,12,12,12,12,12,12,
|
|
|
|
12,12,12,12,12,12,12,12,12,12,
|
|
|
|
12,12,12,12,12,12,12,12,12,12,
|
|
|
|
12,12,12,12,12,12,13,13,13,13,
|
|
|
|
13,13,13,13,13,13,13,13,13,13,
|
|
|
|
13,13,13,13,13,13,13,13,13,13,
|
|
|
|
13,13,13,13,13,13,13,13 };
|
2019-06-05 12:57:18 +00:00
|
|
|
*/
|
2014-06-03 11:51:30 +00:00
|
|
|
|
2019-06-05 12:57:18 +00:00
|
|
|
static const uint8_t g_min_in_group[14] = {
|
|
|
|
0,1,2,3,4,6,8,12,16,24,32,48,64,96 };
|
2014-06-03 11:51:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define C1FLAG_NUMBER 8 // maximum number of largerThan1 flag coded in one chunk
|
|
|
|
#define C2FLAG_NUMBER 1 // maximum number of largerThan2 flag coded in one chunk
|
|
|
|
|
|
|
|
//Get the data for vertical buffer position at the left of LCU identified by the position in pixel
|
|
|
|
#define OFFSET_VER_BUF(position_x, position_y, cur_pic, i) ((position_y) + i + ((position_x)/LCU_WIDTH - 1) * (cur_pic)->height)
|
|
|
|
#define OFFSET_VER_BUF_C(position_x, position_y, cur_pic, i) ((position_y/2) + i + ((position_x)/LCU_WIDTH - 1) * (cur_pic)->height / 2)
|
|
|
|
|
|
|
|
//Get the data for horizontal buffer position at the top of LCU identified by the position in pixel
|
|
|
|
#define OFFSET_HOR_BUF(position_x, position_y, cur_pic, i) ((position_x) + i + ((position_y)/LCU_WIDTH - 1) * (cur_pic)->width)
|
|
|
|
#define OFFSET_HOR_BUF_C(position_x, position_y, cur_pic, i) ((position_x/2) + i + ((position_y)/LCU_WIDTH - 1) * (cur_pic)->width / 2)
|
|
|
|
|
2015-12-17 11:42:57 +00:00
|
|
|
/** @} */
|
2014-06-03 11:51:30 +00:00
|
|
|
|
|
|
|
#endif //ENCODERSTATE_H_
|