273 lines
7.1 KiB
C
273 lines
7.1 KiB
C
|
|
||
|
|
||
|
#ifndef _AW_UTIL_H_
|
||
|
#define _AW_UTIL_H_
|
||
|
|
||
|
#ifndef LOG_TAG
|
||
|
#define LOG_TAG "aw_util"
|
||
|
#endif
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <time.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/time.h>
|
||
|
|
||
|
#include "AW_VideoInput_API.h"
|
||
|
|
||
|
#define LOG_LEVEL_DEBUG "debug"
|
||
|
#define LOG_LEVEL_INFO "info"
|
||
|
#define LOG_LEVEL_WARNING "warn"
|
||
|
#define LOG_LEVEL_ERROR "error"
|
||
|
|
||
|
#define ENABLE_PRINTF_LOG 0
|
||
|
|
||
|
#define aw_logv(fmt, arg...)
|
||
|
|
||
|
#if ENABLE_PRINTF_LOG
|
||
|
#define aw_loge(fmt, arg...) printf("%s:%s <%s:%d> "fmt"\n", LOG_LEVEL_ERROR, LOG_TAG, __FUNCTION__, __LINE__, ##arg)
|
||
|
#define aw_logw(fmt, arg...) printf("%s:%s <%s:%d> "fmt"\n", LOG_LEVEL_WARNING, LOG_TAG, __FUNCTION__, __LINE__, ##arg)
|
||
|
#define aw_logd(fmt, arg...) printf("%s:%s <%s:%d> "fmt"\n", LOG_LEVEL_DEBUG, LOG_TAG, __FUNCTION__, __LINE__, ##arg)
|
||
|
#else
|
||
|
#define aw_loge(fmt, arg...) printf("%s:%s <%s:%d> "fmt"\n", LOG_LEVEL_ERROR, LOG_TAG, __FUNCTION__, __LINE__, ##arg)
|
||
|
#define aw_logw(fmt, arg...) printf("%s:%s <%s:%d> "fmt"\n", LOG_LEVEL_WARNING, LOG_TAG, __FUNCTION__, __LINE__, ##arg)
|
||
|
#define aw_logd(fmt, arg...)
|
||
|
#endif
|
||
|
|
||
|
#define MAIN_CHANNEL_CHANNEL_ID CSI_SENSOR_0_VIPP_0
|
||
|
#define MAIN_CHANNEL_ENCODE_TYPE 0//0:H264; 1:JPG; 2:H265
|
||
|
#define MAIN_CHANNEL_WIDTH 0//if read from flash, size will be insteaded; 0 means according sensor to set default size
|
||
|
#define MAIN_CHANNEL_HEIGHT 0//same as width
|
||
|
#define MAIN_CHANNEL_FPS 15
|
||
|
#define MAIN_CHANNEL_BIT_RATE 1536//kb
|
||
|
#define MAIN_CHANNEL_GOP 40
|
||
|
#define MAIN_CHANNEL_PRODUCT_MODE 0/* 0:static ipc, 1:moving ipc, 2: doorbell, 3:cdr, 4:sdv, 5:projection, 6:UAV(Unmanned Aerial Vehicle) */
|
||
|
#define MAIN_CHANNEL_VBR 1
|
||
|
#define MAIN_CHANNEL_INIT_QP 35
|
||
|
#define MAIN_CHANNEL_I_MIN_QP 25
|
||
|
#define MAIN_CHANNEL_I_MAX_QP 45
|
||
|
#define MAIN_CHANNEL_P_MIN_QP 25
|
||
|
#define MAIN_CHANNEL_P_MAX_QP 45
|
||
|
#define MAIN_CHANNEL_OUT_MODE OUTPUT_MODE_STREAM
|
||
|
#define MAIN_CHANNEL_PXL_FMT RT_PIXEL_LBC_25X
|
||
|
#define MAIN_CHANNEL_REDUCE_REFREC_MEM 0//Can save memory space
|
||
|
#define MAIN_CHANNEL_AIISP_ENABLE 0
|
||
|
#define MAIN_CHANNEL_TDM_RXBUF_CNT 0
|
||
|
|
||
|
#define SAVE_BITSTREAM_COUNT (100)
|
||
|
|
||
|
#define AW_UTIL_FILE_PATH_MAX_LEN (100)
|
||
|
|
||
|
#define RUN_THIS_LINE aw_logw("run this line!")
|
||
|
|
||
|
typedef enum {
|
||
|
HELP,
|
||
|
ENCODE_FRAME_NUM,
|
||
|
ENCODE_FORMAT_0,
|
||
|
ENCODE_FORMAT_1,
|
||
|
SRC_SIZE_0,
|
||
|
DST_SIZE_0,
|
||
|
SRC_SIZE_1,
|
||
|
BIT_RATE_0,
|
||
|
BIT_RATE_1,
|
||
|
INPUT_FILE_NAME,
|
||
|
OUTPUT_FILE_NAME,
|
||
|
SUPPORT_SECOND_CHANNEL,
|
||
|
SUPPORT_THIRD_CHANNEL,
|
||
|
ENCODE_LOCAL_YUV,
|
||
|
PIXEL_FORMAT,
|
||
|
PIXEL_FORMAT_1,
|
||
|
PIXEL_FORMAT_2,
|
||
|
USE_VIPP_NUM,
|
||
|
USE_VIPP_NUM_1,
|
||
|
USE_VIPP_NUM_2,
|
||
|
ENABLE_SHARP,
|
||
|
JPG_SIZE,
|
||
|
ONLINE_MODE,
|
||
|
SHARE_BUF_NUM,
|
||
|
ENABLE_ROI,
|
||
|
ENABLE_FORCE_I_FRAME,
|
||
|
ENABLE_MOTION_SEARCH,
|
||
|
ENABLE_OSD,
|
||
|
ENABLE_ORL,
|
||
|
ENABLE_RESET_SIZE,
|
||
|
ENABLE_GDC,
|
||
|
COLOR_SPACE,
|
||
|
ROTATE_ANGEL,
|
||
|
VIN_BUF_NUM,
|
||
|
ENABLE_CROP,
|
||
|
ENABLE_GRAY,
|
||
|
ENABLE_WB_YUV_TEST,
|
||
|
P_INTRA_REFRESH,
|
||
|
EN_2D_3D_NR_TEST,
|
||
|
DST_FPS,
|
||
|
ENABLE_AIISP,
|
||
|
AIISP_MODE,
|
||
|
TDM_RXBUF_CNT,
|
||
|
AIISP_AUTO_SWITCH,
|
||
|
AIISP_SWITCH_INTERVAL,
|
||
|
ISP_AIISP_BIN_PATH,
|
||
|
ISP_DAY_BIN_PATH,
|
||
|
NPU_LUT_MODEL_FILE_PATH,
|
||
|
NPU_MODEL_FILE_PATH,
|
||
|
ARGB_TYPE,
|
||
|
INVALID
|
||
|
}ARGUMENT_T;
|
||
|
|
||
|
typedef struct {
|
||
|
char Short[16];
|
||
|
char Name[128];
|
||
|
ARGUMENT_T argument;
|
||
|
char Description[512];
|
||
|
}argument_t;
|
||
|
|
||
|
extern argument_t ArgumentMapping[];
|
||
|
|
||
|
//for demo use to parse input argument.
|
||
|
typedef struct demo_video_param{
|
||
|
|
||
|
int encoder_num;
|
||
|
char InputFileName[128];
|
||
|
char OutputFilePath[128]; //can be whole file path, can be part of it, decided by demo. e.g.:/mnt/extsd/test.mp4, /mnt/extsd/prefix
|
||
|
int c0_src_size;
|
||
|
int c0_dst_size;
|
||
|
int c0_src_w;
|
||
|
int c0_src_h;
|
||
|
int c0_dst_w;
|
||
|
int c0_dst_h;
|
||
|
int c0_bitrate; //bps
|
||
|
int c0_encoder_format; //0:h264 1:mjpeg 2:h265
|
||
|
|
||
|
int c1_src_size;
|
||
|
int c1_src_w;
|
||
|
int c1_src_h;
|
||
|
int c1_bitrate;
|
||
|
int c1_encoder_format;
|
||
|
|
||
|
int encode_local_yuv;
|
||
|
int en_second_channel;
|
||
|
int en_third_channel;
|
||
|
RT_PIXELFORMAT_TYPE pixelformat;
|
||
|
RT_PIXELFORMAT_TYPE pixelformat_1;
|
||
|
RT_PIXELFORMAT_TYPE pixelformat_2;
|
||
|
int use_vipp_num;
|
||
|
int use_vipp_num_1;
|
||
|
int use_vipp_num_2;
|
||
|
int enable_sharp;
|
||
|
int jpg_width;
|
||
|
int jpg_heigh;
|
||
|
int bonline_channel;
|
||
|
int share_buf_num;
|
||
|
int jpg_mode; //1:mjpeg, 0:jpeg
|
||
|
int enable_roi;
|
||
|
int enable_motion_search;
|
||
|
int enable_force_key_frame;
|
||
|
int enable_osd;
|
||
|
int enable_orl;
|
||
|
int enable_reset_size; ///< test venc reset size
|
||
|
RTVencMotionSearchParam motion_search_param;
|
||
|
int enable_gdc;
|
||
|
/**
|
||
|
color space value:
|
||
|
7, V4L2_COLORSPACE_JPEG;
|
||
|
3, V4L2_COLORSPACE_REC709;
|
||
|
31,V4L2_COLORSPACE_REC709_PART_RANGE;
|
||
|
*/
|
||
|
int color_space;
|
||
|
int rotate_angle;
|
||
|
int vin_buf_num;
|
||
|
int enable_crop;
|
||
|
int enable_gray;
|
||
|
int enable_wbyuv;
|
||
|
int enable_p_intra_refresh;
|
||
|
int en_2d_3d_nr;
|
||
|
int dst_fps;
|
||
|
int enable_aiisp;
|
||
|
int aiisp_mode;
|
||
|
int tdm_rxbuf_cnt;
|
||
|
int aiisp_auto_switch;
|
||
|
int aiisp_switch_interval;
|
||
|
char isp_aiisp_bin_path[AW_UTIL_FILE_PATH_MAX_LEN];
|
||
|
char isp_day_bin_path[AW_UTIL_FILE_PATH_MAX_LEN];
|
||
|
char npu_lut_model_file_path[AW_UTIL_FILE_PATH_MAX_LEN];
|
||
|
char npu_model_file_path[AW_UTIL_FILE_PATH_MAX_LEN];
|
||
|
int argb_type;
|
||
|
}demo_video_param;
|
||
|
|
||
|
#pragma pack(push, 1)
|
||
|
struct BMPHeader {
|
||
|
char signature[2];
|
||
|
unsigned int fileSize;
|
||
|
short reserved1;
|
||
|
short reserved2;
|
||
|
unsigned int dataOffset;
|
||
|
};
|
||
|
struct DIBHeader {
|
||
|
unsigned int dibSize;
|
||
|
int width;
|
||
|
int height;
|
||
|
short planes;
|
||
|
short bitsPerPixel;
|
||
|
unsigned int compression;
|
||
|
unsigned int imageSize;
|
||
|
int xPixelsPerMeter;
|
||
|
int yPixelsPerMeter;
|
||
|
unsigned int colorsInColorTable;
|
||
|
unsigned int importantColorCount;
|
||
|
};
|
||
|
#pragma pack(pop)
|
||
|
|
||
|
void ParseArgument(demo_video_param *param, char *argument, char *value);
|
||
|
int check_param(demo_video_param *pparam);
|
||
|
void PrintDemoUsage(void);
|
||
|
int rt_is_format422(rt_pixelformat_type pixelformat);
|
||
|
int rt_cal_input_buffer_size(int w, int h, rt_pixelformat_type pixelformat, int read_file);
|
||
|
int bmp_32_to_argb8888(unsigned char* imageData, uint32_t* argbData, struct DIBHeader *dibHeader);
|
||
|
int bmp_24_to_argb8888(unsigned char* imageData, uint32_t* argbData, struct DIBHeader *dibHeader);
|
||
|
int bmp_32_to_argb1555(unsigned char* imageData, uint16_t* argbData, struct DIBHeader *dibHeader);
|
||
|
int bmp_24_to_argb1555(unsigned char* imageData, uint16_t* argbData, struct DIBHeader *dibHeader, int alpha);
|
||
|
unsigned char *deal_bmp_data(FILE* fd, VideoInputOSD *pOverlayInfo, int index);
|
||
|
|
||
|
|
||
|
#define RT_PRINTF_LINE aw_logd("func = %s, line = %d", __FUNCTION__, __LINE__)
|
||
|
|
||
|
typedef u_int64_t uint64_t;
|
||
|
|
||
|
static inline int ALIGN_XXB(int align, int src_value)
|
||
|
{
|
||
|
if(align <= 0 || src_value <= 0)
|
||
|
{
|
||
|
aw_loge("param error: align = %d, src_value = %d", align, src_value);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
while((src_value%align) != 0)
|
||
|
src_value++;
|
||
|
|
||
|
return src_value;
|
||
|
}
|
||
|
|
||
|
static inline uint64_t get_cur_time_us()
|
||
|
{
|
||
|
uint64_t curr;
|
||
|
struct timespec t;
|
||
|
|
||
|
memset(&t, 0, sizeof(struct timespec));
|
||
|
t.tv_sec = t.tv_nsec = 0;
|
||
|
clock_gettime(CLOCK_MONOTONIC, &t);
|
||
|
curr = ((uint64_t)(t.tv_sec)*1000000000LL + t.tv_nsec)/1000LL;
|
||
|
return curr;
|
||
|
}
|
||
|
static inline int64_t get_timeofday(void)
|
||
|
{
|
||
|
struct timeval tv;
|
||
|
int64_t time;
|
||
|
|
||
|
memset(&tv, 0, sizeof(struct timeval));
|
||
|
gettimeofday(&tv,NULL);
|
||
|
time = tv.tv_sec*1000000 + tv.tv_usec;
|
||
|
return time;
|
||
|
}
|
||
|
#endif
|
||
|
|