1 /* 2 * Copyright 2015 Rockchip Electronics Co. LTD 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __UTILS_H__ 18 #define __UTILS_H__ 19 20 #include <stdio.h> 21 22 #include "mpp_debug.h" 23 #include "mpp_frame.h" 24 25 typedef struct OptionInfo_t { 26 const char* name; 27 const char* argname; 28 const char* help; 29 } OptionInfo; 30 31 typedef struct data_crc_t { 32 RK_U32 len; 33 RK_U32 sum_cnt; 34 RK_ULONG *sum; 35 RK_U32 vor; // value of the xor 36 } DataCrc; 37 38 typedef struct frame_crc_t { 39 DataCrc luma; 40 DataCrc chroma; 41 } FrmCrc; 42 43 #define show_options(opt) \ 44 do { \ 45 _show_options(sizeof(opt)/sizeof(OptionInfo), opt); \ 46 } while (0) 47 48 #define mpp_log_q(quiet, fmt, ...) \ 49 do { \ 50 if (!quiet) mpp_log(fmt, ## __VA_ARGS__); \ 51 } while (0) 52 53 #ifdef __cplusplus 54 extern "C" { 55 #endif 56 57 void _show_options(int count, OptionInfo *options); 58 void dump_mpp_frame_to_file(MppFrame frame, FILE *fp); 59 60 void calc_data_crc(RK_U8 *dat, RK_U32 len, DataCrc *crc); 61 void write_data_crc(FILE *fp, DataCrc *crc); 62 void read_data_crc(FILE *fp, DataCrc *crc); 63 64 void calc_frm_crc(MppFrame frame, FrmCrc *crc); 65 void write_frm_crc(FILE *fp, FrmCrc *crc); 66 void read_frm_crc(FILE *fp, FrmCrc *crc); 67 68 MPP_RET read_image(RK_U8 *buf, FILE *fp, RK_U32 width, RK_U32 height, 69 RK_U32 hor_stride, RK_U32 ver_stride, 70 MppFrameFormat fmt); 71 MPP_RET fill_image(RK_U8 *buf, RK_U32 width, RK_U32 height, 72 RK_U32 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt, 73 RK_U32 frame_count); 74 75 typedef struct OpsLine_t { 76 RK_U32 index; 77 char cmd[8]; 78 RK_U64 value1; 79 RK_U64 value2; 80 } OpsLine; 81 82 RK_S32 parse_config_line(const char *str, OpsLine *info); 83 84 MPP_RET name_to_frame_format(const char *name, MppFrameFormat *fmt); 85 MPP_RET name_to_coding_type(const char *name, MppCodingType *coding); 86 87 typedef void* FpsCalc; 88 typedef void (*FpsCalcCb)(RK_S64 total_time, RK_S64 total_count, RK_S64 last_time, RK_S64 last_count); 89 90 MPP_RET fps_calc_init(FpsCalc *ctx); 91 MPP_RET fps_calc_deinit(FpsCalc ctx); 92 MPP_RET fps_calc_set_cb(FpsCalc ctx, FpsCalcCb cb); 93 MPP_RET fps_calc_inc(FpsCalc ctx); 94 95 #ifdef __cplusplus 96 } 97 #endif 98 99 #endif /*__UTILS_H__*/ 100