254 lines
4.9 KiB
C
Executable File
254 lines
4.9 KiB
C
Executable File
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* rockchip uvc mpp encode
|
|
*
|
|
* Copyright (C) 2022 Rockchip Electronics Co., Ltd.
|
|
*
|
|
* Author: Bin Yang <yangbin@rock-chips.com>
|
|
*/
|
|
|
|
#ifndef __MPI_ENCODE_H__
|
|
#define __MPI_ENCODE_H__
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#if defined(_WIN32)
|
|
#include "vld.h"
|
|
#endif
|
|
|
|
#define MODULE_TAG "mpi_enc"
|
|
|
|
#include "rk_mpi.h"
|
|
#include "mpp_common.h"
|
|
#include "mpp_mem.h"
|
|
#include "uvc-log.h"
|
|
|
|
#ifdef LOG_TAG
|
|
#undef LOG_TAG
|
|
#endif
|
|
#define LOG_TAG "UVC-MPP"
|
|
|
|
#define mpp_log(format, ...) uvc_info(format, ## __VA_ARGS__)
|
|
#define mpp_err(format, ...) uvc_err(format, ## __VA_ARGS__)
|
|
#define mpp_err_f(format, ...) uvc_err(format, ## __VA_ARGS__)
|
|
|
|
#define MPP_ENC_CFG_MIN_FPS 0U
|
|
#define MPP_ENC_CFG_MAX_FPS 100U
|
|
#define MPP_ENC_CFG_MIN_BPS 2 * 1000U
|
|
#define MPP_ENC_CFG_MAX_BPS 98 * 1000 * 1000U
|
|
|
|
typedef struct
|
|
{
|
|
RK_U32 fbc;
|
|
RK_U32 split_mode;
|
|
RK_U32 split_arg;
|
|
} UVCEncCommonCfg;
|
|
|
|
typedef struct
|
|
{
|
|
RK_U32 quant;
|
|
RK_U32 qfactor;
|
|
RK_U32 gop;
|
|
MppEncRcMode rc_mode;
|
|
RK_U32 bps;
|
|
RK_U32 framerate;
|
|
} UVCEncMjpegCfg;
|
|
|
|
typedef struct
|
|
{
|
|
RK_U32 gop;
|
|
MppEncRcMode rc_mode;
|
|
RK_U32 framerate;
|
|
RK_S32 qp_init;
|
|
RK_U32 bps;
|
|
} UVCEncH264Cfg;
|
|
|
|
typedef struct
|
|
{
|
|
RK_U32 gop;
|
|
MppEncRcMode rc_mode;
|
|
RK_U32 framerate;
|
|
RK_S32 qp_init;
|
|
RK_U32 bps;
|
|
} UVCEncH265Cfg;
|
|
|
|
typedef struct
|
|
{
|
|
UVCEncCommonCfg common_cfg;
|
|
UVCEncMjpegCfg mjpeg_cfg;
|
|
UVCEncH264Cfg h264_cfg;
|
|
UVCEncH265Cfg h265_cfg;
|
|
} UVCEncCfg;
|
|
|
|
typedef struct {
|
|
MppFrame frame;
|
|
MppPacket packet;
|
|
|
|
// base flow context
|
|
MppCtx ctx;
|
|
MppApi *mpi;
|
|
RK_S32 chn;
|
|
|
|
// global flow control flag
|
|
RK_U32 frm_eos;
|
|
RK_U32 pkt_eos;
|
|
RK_U32 frm_pkt_cnt;
|
|
RK_S32 frame_num;
|
|
RK_S32 frame_count;
|
|
RK_U64 stream_size;
|
|
/* end of encoding flag when set quit the loop */
|
|
volatile RK_U32 loop_end;
|
|
|
|
// src and dst
|
|
FILE *fp_input;
|
|
FILE *fp_output;
|
|
FILE *fp_verify;
|
|
|
|
// base flow context
|
|
MppEncCfg cfg;
|
|
MppEncPrepCfg prep_cfg;
|
|
MppEncRcCfg rc_cfg;
|
|
MppEncCodecCfg codec_cfg;
|
|
MppEncSliceSplit split_cfg;
|
|
MppEncOSDPltCfg osd_plt_cfg;
|
|
MppEncOSDPlt osd_plt;
|
|
MppEncOSDData osd_data;
|
|
//RoiRegionCfg roi_region;
|
|
//MppEncROICfg roi_cfg;
|
|
|
|
// input / output
|
|
MppBufferGroup buf_grp;
|
|
MppBuffer frm_buf;
|
|
MppBuffer pkt_buf;
|
|
MppBuffer md_info;
|
|
MppEncSeiMode sei_mode;
|
|
MppEncHeaderMode header_mode;
|
|
|
|
// paramter for resource malloc
|
|
RK_U32 width;
|
|
RK_U32 height;
|
|
RK_U32 hor_stride;
|
|
RK_U32 ver_stride;
|
|
MppFrameFormat fmt;
|
|
MppCodingType type;
|
|
RK_S32 loop_times;
|
|
//CamSource *cam_ctx;
|
|
//MppEncRoiCtx roi_ctx;
|
|
|
|
// resources
|
|
size_t header_size;
|
|
size_t frame_size;
|
|
size_t mdinfo_size;
|
|
/* NOTE: packet buffer may overflow */
|
|
size_t packet_size;
|
|
|
|
RK_U32 osd_enable;
|
|
RK_U32 osd_mode;
|
|
RK_U32 split_mode;
|
|
RK_U32 split_arg;
|
|
|
|
RK_U32 user_data_enable;
|
|
RK_U32 roi_enable;
|
|
|
|
// rate control runtime parameter
|
|
RK_S32 fps_in_flex;
|
|
RK_S32 fps_in_den;
|
|
RK_S32 fps_in_num;
|
|
RK_S32 fps_out_flex;
|
|
RK_S32 fps_out_den;
|
|
RK_S32 fps_out_num;
|
|
RK_S32 bps;
|
|
RK_S32 bps_max;
|
|
RK_S32 bps_min;
|
|
RK_S32 rc_mode;
|
|
RK_S32 gop_mode;
|
|
RK_S32 gop_len;
|
|
RK_S32 vi_len;
|
|
RK_S32 quant;
|
|
RK_S32 qfactor;
|
|
|
|
RK_S64 first_frm;
|
|
RK_S64 first_pkt;
|
|
} MpiEncData;
|
|
|
|
typedef struct MpiEncTestArgs_t {
|
|
char *file_input;
|
|
char *file_output;
|
|
char *file_cfg;
|
|
//dictionary *cfg_ini;
|
|
|
|
RK_U32 save_in_en;
|
|
RK_U32 save_out_en;
|
|
|
|
MppCodingType type;
|
|
MppCodingType type_src; /* for file source input */
|
|
MppFrameFormat format;
|
|
RK_S32 frame_num;
|
|
RK_S32 loop_cnt;
|
|
RK_S32 nthreads;
|
|
|
|
RK_S32 width;
|
|
RK_S32 height;
|
|
RK_S32 hor_stride;
|
|
RK_S32 ver_stride;
|
|
|
|
RK_U32 split_mode;
|
|
RK_U32 split_arg;
|
|
|
|
/* -rc */
|
|
RK_S32 rc_mode;
|
|
|
|
RK_S32 bps_target;
|
|
RK_S32 bps_max;
|
|
RK_S32 bps_min;
|
|
|
|
/* -fps */
|
|
RK_S32 fps_in_flex;
|
|
RK_S32 fps_in_num;
|
|
RK_S32 fps_in_den;
|
|
RK_S32 fps_out_flex;
|
|
RK_S32 fps_out_num;
|
|
RK_S32 fps_out_den;
|
|
|
|
/* -qc */
|
|
RK_S32 qp_init;
|
|
RK_S32 qp_min;
|
|
RK_S32 qp_max;
|
|
RK_S32 qp_min_i;
|
|
RK_S32 qp_max_i;
|
|
|
|
/* -g gop mode */
|
|
RK_S32 gop_mode;
|
|
RK_S32 gop_len;
|
|
RK_S32 vi_len;
|
|
|
|
RK_S32 quant;
|
|
RK_S32 qfactor;
|
|
|
|
/* -v q runtime log disable flag */
|
|
RK_U32 quiet;
|
|
/* -v f runtime fps log flag */
|
|
//RK_U32 trace_fps;
|
|
//FpsCalc fps;
|
|
RK_U32 psnr_en;
|
|
RK_U32 ssim_en;
|
|
char *file_slt;
|
|
} MpiEncArgs;
|
|
|
|
typedef struct {
|
|
MpiEncArgs *cmd; // pointer to global command line info
|
|
MpiEncData ctx; // context of encoder
|
|
UVCEncCfg *cfg;
|
|
} MpiEncMultiCtxInfo;
|
|
|
|
void mpi_enc_cmd_config(MpiEncArgs *cmd, struct v4l2_pix_format* fmt,
|
|
MppFrameFormat format);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|