1 /* 2 * Copyright (c) 2021 Rockchip Electronics Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __MPP_LOG_H__ 17 #define __MPP_LOG_H__ 18 19 #include <stdio.h> 20 #include <stdlib.h> 21 22 #include "rk_type.h" 23 24 /* 25 * mpp runtime log system usage: 26 * mpp_err is for error status message, it will print for sure. 27 * mpp_log is for important message like open/close/reset/flush, it will print too. 28 * mpp_dbg is for all optional message. it can be controlled by debug and flag. 29 */ 30 31 #define mpp_log(fmt, ...) _mpp_log(MODULE_TAG, fmt, NULL, ##__VA_ARGS__) 32 #define mpp_err(fmt, ...) _mpp_err(MODULE_TAG, fmt, NULL, ##__VA_ARGS__) 33 34 #define _mpp_dbg(debug, flag, fmt, ...) \ 35 do { \ 36 if (debug & flag) \ 37 mpp_log(fmt, ##__VA_ARGS__); \ 38 } while (0) 39 40 #define mpp_dbg(flag, fmt, ...) _mpp_dbg(mpp_debug, flag, fmt, ##__VA_ARGS__) 41 42 /* 43 * _f function will add function name to the log 44 */ 45 #define mpp_log_f(fmt, ...) _mpp_log(MODULE_TAG, fmt, __FUNCTION__, ##__VA_ARGS__) 46 #define mpp_err_f(fmt, ...) _mpp_err(MODULE_TAG, fmt, __FUNCTION__, ##__VA_ARGS__) 47 #define _mpp_dbg_f(debug, flag, fmt, ...) \ 48 do { \ 49 if (debug & flag) \ 50 mpp_log_f(fmt, ##__VA_ARGS__); \ 51 } while (0) 52 53 #define mpp_dbg_f(flag, fmt, ...) _mpp_dbg_f(mpp_debug, flag, fmt, ##__VA_ARGS__) 54 55 #define MPP_DBG_TIMING (0x00000001) 56 #define MPP_DBG_PTS (0x00000002) 57 #define MPP_DBG_INFO (0x00000004) 58 #define MPP_DBG_PLATFORM (0x00000010) 59 60 #define MPP_DBG_DUMP_LOG (0x00000100) 61 #define MPP_DBG_DUMP_IN (0x00000200) 62 #define MPP_DBG_DUMP_OUT (0x00000400) 63 #define MPP_DBG_DUMP_CFG (0x00000800) 64 65 #define mpp_dbg_pts(fmt, ...) mpp_dbg(MPP_DBG_PTS, fmt, ##__VA_ARGS__) 66 #define mpp_dbg_info(fmt, ...) mpp_dbg(MPP_DBG_INFO, fmt, ##__VA_ARGS__) 67 #define mpp_dbg_platform(fmt, ...) mpp_dbg(MPP_DBG_PLATFORM, fmt, ##__VA_ARGS__) 68 69 #define MPP_ABORT (0x10000000) 70 71 /* 72 * mpp_dbg usage: 73 * 74 * in h264d module define module debug flag variable like: h265d_debug 75 * then define h265d_dbg macro as follow : 76 * 77 * extern unsigned int h265d_debug; 78 * 79 * #define H265D_DBG_FUNCTION (0x00000001) 80 * #define H265D_DBG_VPS (0x00000002) 81 * #define H265D_DBG_SPS (0x00000004) 82 * #define H265D_DBG_PPS (0x00000008) 83 * #define H265D_DBG_SLICE_HDR (0x00000010) 84 * 85 * #define h265d_dbg(flag, fmt, ...) mpp_dbg(h265d_debug, flag, fmt, ## __VA_ARGS__) 86 * 87 * finally use environment control the debug flag 88 * 89 * mpp_get_env_u32("h264d_debug", &h265d_debug, 0) 90 * 91 */ 92 /* 93 * sub-module debug flag usage example: 94 * +------+-------------------+ 95 * | 8bit | 24bit | 96 * +------+-------------------+ 97 * 0~15 bit: software debug print 98 * 16~23 bit: hardware debug print 99 * 24~31 bit: information print format 100 */ 101 102 #define mpp_abort() \ 103 do { \ 104 if (mpp_debug & MPP_ABORT) { \ 105 abort(); \ 106 } \ 107 } while (0) 108 109 #define MPP_STRINGS(x) MPP_TO_STRING(x) 110 #define MPP_TO_STRING(x) #x 111 112 #define mpp_assert(cond) \ 113 do { \ 114 if (!(cond)) { \ 115 mpp_err("Assertion %s failed at %s:%d\n", MPP_STRINGS(cond), __FUNCTION__, __LINE__); \ 116 mpp_abort(); \ 117 } \ 118 } while (0) 119 120 #ifdef __cplusplus 121 extern "C" { 122 #endif 123 124 extern unsigned int mpp_debug; 125 126 void mpp_log_set_flag(unsigned int flag); 127 unsigned int mpp_log_get_flag(void); 128 129 void _mpp_log(const char *tag, const char *fmt, const char *func, ...); 130 void _mpp_err(const char *tag, const char *fmt, const char *func, ...); 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 #endif /* __MPP_LOG_H__ */ 137