linux/drivers/media/platform/st/sti/hva/hva-h264.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) STMicroelectronics SA 2015
 * Authors: Yannick Fertre <[email protected]>
 *          Hugues Fruchet <[email protected]>
 */

#include "hva.h"
#include "hva-hw.h"

#define MAX_SPS_PPS_SIZE

#define BITSTREAM_OFFSET_MASK

/* video max size*/
#define H264_MAX_SIZE_W
#define H264_MAX_SIZE_H

/* macroBlocs number (width & height) */
#define MB_W(w)
#define MB_H(h)

/* formula to get temporal or spatial data size */
#define DATA_SIZE(w, h)

#define SEARCH_WINDOW_BUFFER_MAX_SIZE(w)
#define CABAC_CONTEXT_BUFFER_MAX_SIZE(w)
#define CTX_MB_BUFFER_MAX_SIZE(w)
#define SLICE_HEADER_SIZE
#define BRC_DATA_SIZE

/* source buffer copy in YUV 420 MB-tiled format with size=16*256*3/2 */
#define CURRENT_WINDOW_BUFFER_MAX_SIZE

/*
 * 4 lines of pixels (in Luma, Chroma blue and Chroma red) of top MB
 * for deblocking with size=4*16*MBx*2
 */
#define LOCAL_RECONSTRUCTED_BUFFER_MAX_SIZE(w)

/* factor for bitrate and cpb buffer size max values if profile >= high */
#define H264_FACTOR_HIGH

/* factor for bitrate and cpb buffer size max values if profile < high */
#define H264_FACTOR_BASELINE

/* number of bytes for NALU_TYPE_FILLER_DATA header and footer */
#define H264_FILLER_DATA_SIZE

struct h264_profile {};

static const struct h264_profile h264_infos_list[] =;

enum hva_brc_type {};

enum hva_entropy_coding_mode {};

enum hva_picture_coding_type {};

enum hva_h264_sampling_mode {};

enum hva_h264_nalu_type {};

enum hva_h264_sei_payload_type {};

/*
 * stereo Video Info struct
 */
struct hva_h264_stereo_video_sei {};

/*
 * struct hva_h264_td
 *
 * @frame_width: width in pixels of the buffer containing the input frame
 * @frame_height: height in pixels of the buffer containing the input frame
 * @frame_num: the parameter to be written in the slice header
 * @picture_coding_type: type I, P or B
 * @pic_order_cnt_type: POC mode, as defined in H264 std : can be 0,1,2
 * @first_picture_in_sequence: flag telling to encoder that this is the
 *			       first picture in a video sequence.
 *			       Used for VBR
 * @slice_size_type: 0 = no constraint to close the slice
 *		     1= a slice is closed as soon as the slice_mb_size limit
 *			is reached
 *		     2= a slice is closed as soon as the slice_byte_size limit
 *			is reached
 *		     3= a slice is closed as soon as either the slice_byte_size
 *			limit or the slice_mb_size limit is reached
 * @slice_mb_size: defines the slice size in number of macroblocks
 *		   (used when slice_size_type=1 or slice_size_type=3)
 * @ir_param_option: defines the number of macroblocks per frame to be
 *		     refreshed by AIR algorithm OR the refresh period
 *		     by CIR algorithm
 * @intra_refresh_type: enables the adaptive intra refresh algorithm.
 *			Disable=0 / Adaptative=1 and Cycle=2 as intra refresh
 * @use_constrained_intra_flag: constrained_intra_pred_flag from PPS
 * @transform_mode: controls the use of 4x4/8x8 transform mode
 * @disable_deblocking_filter_idc:
 *		     0: specifies that all luma and chroma block edges of
 *			the slice are filtered.
 *		     1: specifies that deblocking is disabled for all block
 *			edges of the slice.
 *		     2: specifies that all luma and chroma block edges of
 *			the slice are filtered with exception of the block edges
 *			that coincide with slice boundaries
 * @slice_alpha_c0_offset_div2: to be written in slice header,
 *				controls deblocking
 * @slice_beta_offset_div2: to be written in slice header,
 *			    controls deblocking
 * @encoder_complexity: encoder complexity control (IME).
 *		     0 = I_16x16, P_16x16, Full ME Complexity
 *		     1 = I_16x16, I_NxN, P_16x16, Full ME Complexity
 *		     2 = I_16x16, I_NXN, P_16x16, P_WxH, Full ME Complexity
 *		     4 = I_16x16, P_16x16, Reduced ME Complexity
 *		     5 = I_16x16, I_NxN, P_16x16, Reduced ME Complexity
 *		     6 = I_16x16, I_NXN, P_16x16, P_WxH, Reduced ME Complexity
 *  @chroma_qp_index_offset: coming from picture parameter set
 *			     (PPS see [H.264 STD] 7.4.2.2)
 *  @entropy_coding_mode: entropy coding mode.
 *			  0 = CAVLC
 *			  1 = CABAC
 * @brc_type: selects the bit-rate control algorithm
 *		     0 = constant Qp, (no BRC)
 *		     1 = CBR
 *		     2 = VBR
 * @quant: Quantization param used in case of fix QP encoding (no BRC)
 * @non_VCL_NALU_Size: size of non-VCL NALUs (SPS, PPS, filler),
 *		       used by BRC
 * @cpb_buffer_size: size of Coded Picture Buffer, used by BRC
 * @bit_rate: target bitrate, for BRC
 * @qp_min: min QP threshold
 * @qp_max: max QP threshold
 * @framerate_num: target framerate numerator , used by BRC
 * @framerate_den: target framerate denomurator , used by BRC
 * @delay: End-to-End Initial Delay
 * @strict_HRD_compliancy: flag for HDR compliancy (1)
 *			   May impact quality encoding
 * @addr_source_buffer: address of input frame buffer for current frame
 * @addr_fwd_Ref_Buffer: address of reference frame buffer
 * @addr_rec_buffer: address of reconstructed frame buffer
 * @addr_output_bitstream_start: output bitstream start address
 * @addr_output_bitstream_end: output bitstream end address
 * @addr_external_sw : address of external search window
 * @addr_lctx : address of context picture buffer
 * @addr_local_rec_buffer: address of local reconstructed buffer
 * @addr_spatial_context: address of spatial context buffer
 * @bitstream_offset: offset in bits between aligned bitstream start
 *		      address and first bit to be written by HVA.
 *		      Range value is [0..63]
 * @sampling_mode: Input picture format .
 *		     0: YUV420 semi_planar Interleaved
 *		     1: YUV422 raster Interleaved
 * @addr_param_out: address of output parameters structure
 * @addr_scaling_matrix: address to the coefficient of
 *			 the inverse scaling matrix
 * @addr_scaling_matrix_dir: address to the coefficient of
 *			     the direct scaling matrix
 * @addr_cabac_context_buffer: address of cabac context buffer
 * @GmvX: Input information about the horizontal global displacement of
 *	  the encoded frame versus the previous one
 * @GmvY: Input information about the vertical global displacement of
 *	  the encoded frame versus the previous one
 * @window_width: width in pixels of the window to be encoded inside
 *		  the input frame
 * @window_height: width in pixels of the window to be encoded inside
 *		   the input frame
 * @window_horizontal_offset: horizontal offset in pels for input window
 *			      within input frame
 * @window_vertical_offset: vertical offset in pels for input window
 *			    within input frame
 * @addr_roi: Map of QP offset for the Region of Interest algorithm and
 *	      also used for Error map.
 *	      Bit 0-6 used for qp offset (value -64 to 63).
 *	      Bit 7 used to force intra
 * @addr_slice_header: address to slice header
 * @slice_header_size_in_bits: size in bits of the Slice header
 * @slice_header_offset0: Slice header offset where to insert
 *			  first_Mb_in_slice
 * @slice_header_offset1: Slice header offset where to insert
 *			  slice_qp_delta
 * @slice_header_offset2: Slice header offset where to insert
 *			  num_MBs_in_slice
 * @slice_synchro_enable: enable "slice ready" interrupt after each slice
 * @max_slice_number: Maximum number of slice in a frame
 *		      (0 is strictly forbidden)
 * @rgb2_yuv_y_coeff: Four coefficients (C0C1C2C3) to convert from RGB to
 *		      YUV for the Y component.
 *		      Y = C0*R + C1*G + C2*B + C3 (C0 is on byte 0)
 * @rgb2_yuv_u_coeff: four coefficients (C0C1C2C3) to convert from RGB to
 *		      YUV for the Y component.
 *		      Y = C0*R + C1*G + C2*B + C3 (C0 is on byte 0)
 * @rgb2_yuv_v_coeff: Four coefficients (C0C1C2C3) to convert from RGB to
 *		      YUV for the U (Cb) component.
 *		      U = C0*R + C1*G + C2*B + C3 (C0 is on byte 0)
 * @slice_byte_size: maximum slice size in bytes
 *		     (used when slice_size_type=2 or slice_size_type=3)
 * @max_air_intra_mb_nb: Maximum number of intra macroblock in a frame
 *			 for the AIR algorithm
 * @brc_no_skip: Disable skipping in the Bitrate Controller
 * @addr_brc_in_out_parameter: address of static buffer for BRC parameters
 */
struct hva_h264_td {};

/*
 * struct hva_h264_slice_po
 *
 * @ slice_size: slice size
 * @ slice_start_time: start time
 * @ slice_stop_time: stop time
 * @ slice_num: slice number
 */
struct hva_h264_slice_po {};

/*
 * struct hva_h264_po
 *
 * @ bitstream_size: bitstream size
 * @ dct_bitstream_size: dtc bitstream size
 * @ stuffing_bits: number of stuffing bits inserted by the encoder
 * @ removal_time: removal time of current frame (nb of ticks 1/framerate)
 * @ hvc_start_time: hvc start time
 * @ hvc_stop_time: hvc stop time
 * @ slice_count: slice count
 */
struct hva_h264_po {};

struct hva_h264_task {};

/*
 * struct hva_h264_ctx
 *
 * @seq_info:  sequence information buffer
 * @ref_frame: reference frame buffer
 * @rec_frame: reconstructed frame buffer
 * @task:      task descriptor
 */
struct hva_h264_ctx {};

static int hva_h264_fill_slice_header(struct hva_ctx *pctx,
				      u8 *slice_header_addr,
				      struct hva_controls *ctrls,
				      int frame_num,
				      u16 *header_size,
				      u16 *header_offset0,
				      u16 *header_offset1,
				      u16 *header_offset2)
{}

static int hva_h264_fill_data_nal(struct hva_ctx *pctx,
				  unsigned int stuffing_bytes, u8 *addr,
				  unsigned int stream_size, unsigned int *size)
{}

static int hva_h264_fill_sei_nal(struct hva_ctx *pctx,
				 enum hva_h264_sei_payload_type type,
				 u8 *addr, u32 *size)
{}

static int hva_h264_prepare_task(struct hva_ctx *pctx,
				 struct hva_h264_task *task,
				 struct hva_frame *frame,
				 struct hva_stream *stream)
{}

static unsigned int hva_h264_get_stream_size(struct hva_h264_task *task)
{}

static u32 hva_h264_get_stuffing_bytes(struct hva_h264_task *task)
{}

static int hva_h264_open(struct hva_ctx *pctx)
{}

static int hva_h264_close(struct hva_ctx *pctx)
{}

static int hva_h264_encode(struct hva_ctx *pctx, struct hva_frame *frame,
			   struct hva_stream *stream)
{}

const struct hva_enc nv12h264enc =;

const struct hva_enc nv21h264enc =;