TUT HEVC Encoder
Loading...
Searching...
No Matches
Macros | Functions | Variables
encoderstate.c File Reference
#include "encoderstate.h"
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cabac.h"
#include "context.h"
#include "encode_coding_tree.h"
#include "encoder_state-bitstream.h"
#include "filter.h"
#include "image.h"
#include "rate_control.h"
#include "sao.h"
#include "search.h"
#include "tables.h"
#include "threadqueue.h"
#include "strategies/strategies-picture.h"
Include dependency graph for encoderstate.c:

Macros

#define _USE_MATH_DEFINES
 
#define SAO_BUF_WIDTH   (1 + SAO_DELAY_PX + LCU_WIDTH)
 
#define SAO_BUF_WIDTH_C   (1 + SAO_DELAY_PX/2 + LCU_WIDTH_C)
 

Functions

int kvz_encoder_state_match_children_of_previous_frame (encoder_state_t *const state)
 
static void encoder_state_recdata_before_sao_to_bufs (encoder_state_t *const state, const lcu_order_element_t *const lcu, yuv_t *const hor_buf, yuv_t *const ver_buf)
 Save edge pixels before SAO to buffers.
 
static void encoder_state_recdata_to_bufs (encoder_state_t *const state, const lcu_order_element_t *const lcu, yuv_t *const hor_buf, yuv_t *const ver_buf)
 
static void encoder_sao_reconstruct (const encoder_state_t *const state, const lcu_order_element_t *const lcu)
 Do SAO reconstuction for all available pixels.
 
static void encode_sao_color (encoder_state_t *const state, sao_info_t *sao, color_t color_i)
 
static void encode_sao_merge_flags (encoder_state_t *const state, sao_info_t *sao, unsigned x_ctb, unsigned y_ctb)
 
static void encode_sao (encoder_state_t *const state, unsigned x_lcu, uint16_t y_lcu, sao_info_t *sao_luma, sao_info_t *sao_chroma)
 Encode SAO information.
 
static void set_cu_qps (encoder_state_t *state, int x, int y, int depth, int *last_qp, int *prev_qp)
 Sets the QP for each CU in state->tile->frame->cu_array.
 
static void encoder_state_worker_encode_lcu (void *opaque)
 
static void encoder_state_encode_leaf (encoder_state_t *const state)
 
static void encoder_state_encode (encoder_state_t *const main_state)
 
static void encoder_state_worker_encode_children (void *opaque)
 
static int encoder_state_tree_is_a_chain (const encoder_state_t *const state)
 
static void encoder_ref_insertion_sort (const encoder_state_t *const state, uint8_t reflist[16], uint8_t length, bool reverse)
 
void kvz_encoder_create_ref_lists (const encoder_state_t *const state)
 Generate reference picture lists.
 
static void encoder_state_remove_refs (encoder_state_t *state)
 Remove any references that should no longer be used.
 
static void encoder_set_source_picture (encoder_state_t *const state, kvz_picture *frame)
 
static void encoder_state_init_children (encoder_state_t *const state)
 
static void normalize_lcu_weights (encoder_state_t *const state)
 
static bool edge_lcu (int id, int lcus_x, int lcus_y, bool xdiv64, bool ydiv64)
 
static double ws_weight (int y, int h)
 Return weight for 360 degree ERP video.
 
static void init_erp_aqp_roi (const encoder_control_t *encoder, kvz_picture *frame)
 Update ROI QPs for 360 video with equirectangular projection.
 
static void next_roi_frame_from_file (kvz_picture *frame, FILE *file, enum kvz_roi_format format)
 
static void encoder_state_init_new_frame (encoder_state_t *const state, kvz_picture *frame)
 
static void _encode_one_frame_add_bitstream_deps (const encoder_state_t *const state, threadqueue_job_t *const job)
 
void kvz_encode_one_frame (encoder_state_t *const state, kvz_picture *frame)
 
void kvz_encoder_prepare (encoder_state_t *state)
 Prepare the encoder state for encoding the next frame.
 
coeff_scan_order_t kvz_get_scan_order (int8_t cu_type, int intra_mode, int depth)
 
lcu_stats_tkvz_get_lcu_stats (encoder_state_t *state, int lcu_x, int lcu_y)
 
int kvz_get_cu_ref_qp (const encoder_state_t *state, int x, int y, int last_qp)
 

Variables

static const double ERP_AQP_STRENGTH = 3.0
 Strength of QP adjustments when using adaptive QP for 360 video.
 

Macro Definition Documentation

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES

◆ SAO_BUF_WIDTH

#define SAO_BUF_WIDTH   (1 + SAO_DELAY_PX + LCU_WIDTH)

◆ SAO_BUF_WIDTH_C

#define SAO_BUF_WIDTH_C   (1 + SAO_DELAY_PX/2 + LCU_WIDTH_C)

Function Documentation

◆ _encode_one_frame_add_bitstream_deps()

static void _encode_one_frame_add_bitstream_deps ( const encoder_state_t *const  state,
threadqueue_job_t *const  job 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ edge_lcu()

static bool edge_lcu ( int  id,
int  lcus_x,
int  lcus_y,
bool  xdiv64,
bool  ydiv64 
)
static
Here is the caller graph for this function:

◆ encode_sao()

static void encode_sao ( encoder_state_t *const  state,
unsigned  x_lcu,
uint16_t  y_lcu,
sao_info_t sao_luma,
sao_info_t sao_chroma 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_sao_color()

static void encode_sao_color ( encoder_state_t *const  state,
sao_info_t sao,
color_t  color_i 
)
static

sao_type_idx_luma: TR, cMax = 2, cRiceParam = 0, bins = {0, bypass} sao_type_idx_chroma: TR, cMax = 2, cRiceParam = 0, bins = {0, bypass}

sao_offset_abs[][][][]: TR, cMax = (1 << (Min(bitDepth, 10) - 5)) - 1, cRiceParam = 0, bins = {bypass x N}

sao_offset_sign[][][][]: FL, cMax = 1, bins = {bypass} sao_band_position[][][]: FL, cMax = 31, bins = {bypass x N} sao_eo_class_luma: FL, cMax = 3, bins = {bypass x 3} sao_eo_class_chroma: FL, cMax = 3, bins = {bypass x 3}

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_sao_merge_flags()

static void encode_sao_merge_flags ( encoder_state_t *const  state,
sao_info_t sao,
unsigned  x_ctb,
unsigned  y_ctb 
)
static
Here is the caller graph for this function:

◆ encoder_ref_insertion_sort()

static void encoder_ref_insertion_sort ( const encoder_state_t *const  state,
uint8_t  reflist[16],
uint8_t  length,
bool  reverse 
)
static
Here is the caller graph for this function:

◆ encoder_sao_reconstruct()

static void encoder_sao_reconstruct ( const encoder_state_t *const  state,
const lcu_order_element_t *const  lcu 
)
static

Does SAO reconstruction for all pixels that are available after the given LCU has been deblocked. This means the following pixels:

  • bottom-right block of SAO_DELAY_PX times SAO_DELAY_PX in the lcu to the left and up
  • the rightmost SAO_DELAY_PX pixels of the LCU to the left (excluding the bottommost pixel)
  • the bottommost SAO_DELAY_PX pixels of the LCU above (excluding the rightmost pixels)
  • all pixels inside the LCU, excluding the rightmost SAO_DELAY_PX and bottommost SAO_DELAY_PX
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encoder_set_source_picture()

static void encoder_set_source_picture ( encoder_state_t *const  state,
kvz_picture frame 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encoder_state_encode()

static void encoder_state_encode ( encoder_state_t *const  main_state)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encoder_state_encode_leaf()

static void encoder_state_encode_leaf ( encoder_state_t *const  state)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encoder_state_init_children()

static void encoder_state_init_children ( encoder_state_t *const  state)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encoder_state_init_new_frame()

static void encoder_state_init_new_frame ( encoder_state_t *const  state,
kvz_picture frame 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encoder_state_recdata_before_sao_to_bufs()

static void encoder_state_recdata_before_sao_to_bufs ( encoder_state_t *const  state,
const lcu_order_element_t *const  lcu,
yuv_t *const  hor_buf,
yuv_t *const  ver_buf 
)
static

Copies pixels at the edges of the area that will be filtered with SAO to the given buffers. If deblocking is enabled, the pixels must have been deblocked before this.

The saved pixels will be needed later when doing SAO for the neighboring areas.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encoder_state_recdata_to_bufs()

static void encoder_state_recdata_to_bufs ( encoder_state_t *const  state,
const lcu_order_element_t *const  lcu,
yuv_t *const  hor_buf,
yuv_t *const  ver_buf 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encoder_state_remove_refs()

static void encoder_state_remove_refs ( encoder_state_t state)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encoder_state_tree_is_a_chain()

static int encoder_state_tree_is_a_chain ( const encoder_state_t *const  state)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encoder_state_worker_encode_children()

static void encoder_state_worker_encode_children ( void opaque)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encoder_state_worker_encode_lcu()

static void encoder_state_worker_encode_lcu ( void opaque)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_erp_aqp_roi()

static void init_erp_aqp_roi ( const encoder_control_t encoder,
kvz_picture frame 
)
static

Updates the ROI parameters in frame->roi.

Parameters
encoderencoder control
frameframe that will have the ROI map
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_encode_one_frame()

void kvz_encode_one_frame ( encoder_state_t *const  state,
kvz_picture frame 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_encoder_create_ref_lists()

void kvz_encoder_create_ref_lists ( const encoder_state_t *const  state)
Parameters
statemain encoder state
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_encoder_prepare()

void kvz_encoder_prepare ( encoder_state_t state)
  • Add the previous reconstructed picture as a reference, if needed.
  • Free the previous reconstructed and source pictures.
  • Create a new cu array, if needed.
  • Update frame count and POC.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_encoder_state_match_children_of_previous_frame()

int kvz_encoder_state_match_children_of_previous_frame ( encoder_state_t *const  state)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_get_cu_ref_qp()

int kvz_get_cu_ref_qp ( const encoder_state_t state,
int  x,
int  y,
int  last_qp 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_get_lcu_stats()

lcu_stats_t * kvz_get_lcu_stats ( encoder_state_t state,
int  lcu_x,
int  lcu_y 
)
Here is the caller graph for this function:

◆ kvz_get_scan_order()

coeff_scan_order_t kvz_get_scan_order ( int8_t  cu_type,
int  intra_mode,
int  depth 
)
Here is the caller graph for this function:

◆ next_roi_frame_from_file()

static void next_roi_frame_from_file ( kvz_picture frame,
FILE file,
enum kvz_roi_format  format 
)
static
Here is the caller graph for this function:

◆ normalize_lcu_weights()

static void normalize_lcu_weights ( encoder_state_t *const  state)
static
Here is the caller graph for this function:

◆ set_cu_qps()

static void set_cu_qps ( encoder_state_t state,
int  x,
int  y,
int  depth,
int last_qp,
int prev_qp 
)
static

The QPs are used in deblocking and QP prediction.

The QP delta for a quantization group is coded when the first CU with coded block flag set is encountered. Hence, for the purposes of deblocking and QP prediction, all CUs in before the first one that has cbf set use the QP predictor and all CUs after that use (QP predictor

  • QP delta).
Parameters
stateencoder state
xx-coordinate of the left edge of the root CU
yy-coordinate of the top edge of the root CU
depthdepth in the CU quadtree
last_qpQP of the last CU in the last quantization group
prev_qp-1 if QP delta has not been coded in current QG, otherwise the QP of the current QG
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ws_weight()

static double ws_weight ( int  y,
int  h 
)
static

Returns the scaling factor of area from equirectangular projection to spherical surface.

Parameters
yy-coordinate of the pixel
hheight of the picture
Here is the caller graph for this function:

Variable Documentation

◆ ERP_AQP_STRENGTH

const double ERP_AQP_STRENGTH = 3.0
static

Determined empirically.