1 /* SPDX-License-Identifier: Apache-2.0 OR MIT */ 2 /* 3 * Copyright (c) 2015 Rockchip Electronics Co., Ltd. 4 */ 5 6 #ifndef __MPP_META_H__ 7 #define __MPP_META_H__ 8 9 #include <stdint.h> 10 #include "rk_type.h" 11 12 #define FOURCC_META(a, b, c, d) ((RK_U32)(a) << 24 | \ 13 ((RK_U32)(b) << 16) | \ 14 ((RK_U32)(c) << 8) | \ 15 ((RK_U32)(d) << 0)) 16 17 /* 18 * Mpp Metadata definition 19 * 20 * Metadata is for information transmision in mpp. 21 * Mpp task will contain two meta data: 22 * 23 * 1. Data flow metadata 24 * This metadata contains information of input / output data flow. For example 25 * A. decoder input side task the input packet must be defined and output frame 26 * may not be defined. Then decoder will try malloc or use committed buffer to 27 * complete decoding. 28 * B. decoder output side task 29 * 30 * 31 * 2. Flow control metadata 32 * 33 */ 34 typedef enum MppMetaKey_e { 35 /* data flow key */ 36 KEY_INPUT_FRAME = FOURCC_META('i', 'f', 'r', 'm'), 37 KEY_INPUT_PACKET = FOURCC_META('i', 'p', 'k', 't'), 38 KEY_OUTPUT_FRAME = FOURCC_META('o', 'f', 'r', 'm'), 39 KEY_OUTPUT_PACKET = FOURCC_META('o', 'p', 'k', 't'), 40 /* output motion information for motion detection */ 41 KEY_MOTION_INFO = FOURCC_META('m', 'v', 'i', 'f'), 42 KEY_HDR_INFO = FOURCC_META('h', 'd', 'r', ' '), 43 KEY_HDR_META_OFFSET = FOURCC_META('h', 'd', 'r', 'o'), 44 KEY_HDR_META_SIZE = FOURCC_META('h', 'd', 'r', 'l'), 45 46 /* flow control key */ 47 KEY_INPUT_BLOCK = FOURCC_META('i', 'b', 'l', 'k'), 48 KEY_OUTPUT_BLOCK = FOURCC_META('o', 'b', 'l', 'k'), 49 KEY_INPUT_IDR_REQ = FOURCC_META('i', 'i', 'd', 'r'), /* input idr frame request flag */ 50 KEY_OUTPUT_INTRA = FOURCC_META('o', 'i', 'd', 'r'), /* output intra frame indicator */ 51 52 /* mpp_frame / mpp_packet meta data info key */ 53 KEY_TEMPORAL_ID = FOURCC_META('t', 'l', 'i', 'd'), 54 KEY_LONG_REF_IDX = FOURCC_META('l', 't', 'i', 'd'), 55 KEY_ENC_AVERAGE_QP = FOURCC_META('a', 'v', 'g', 'q'), 56 KEY_ENC_START_QP = FOURCC_META('s', 't', 'r', 'q'), 57 KEY_ENC_BPS_RT = FOURCC_META('r', 't', 'b', 'r'), /* realtime bps */ 58 KEY_ROI_DATA = FOURCC_META('r', 'o', 'i', ' '), 59 KEY_JPEG_ROI_DATA = FOURCC_META('j', 'r', 'o', 'i'), 60 KEY_OSD_DATA = FOURCC_META('o', 's', 'd', ' '), 61 KEY_OSD_DATA2 = FOURCC_META('o', 's', 'd', '2'), 62 KEY_OSD_DATA3 = FOURCC_META('o', 's', 'd', '3'), 63 KEY_USER_DATA = FOURCC_META('u', 's', 'r', 'd'), 64 KEY_USER_DATAS = FOURCC_META('u', 'r', 'd', 's'), 65 66 /* num of inter different size predicted block */ 67 KEY_LVL64_INTER_NUM = FOURCC_META('l', '6', '4', 'p'), 68 KEY_LVL32_INTER_NUM = FOURCC_META('l', '3', '2', 'p'), 69 KEY_LVL16_INTER_NUM = FOURCC_META('l', '1', '6', 'p'), 70 KEY_LVL8_INTER_NUM = FOURCC_META('l', '8', 'p', ' '), 71 /* num of intra different size predicted block */ 72 KEY_LVL32_INTRA_NUM = FOURCC_META('l', '3', '2', 'i'), 73 KEY_LVL16_INTRA_NUM = FOURCC_META('l', '1', '6', 'i'), 74 KEY_LVL8_INTRA_NUM = FOURCC_META('l', '8', 'i', ' '), 75 KEY_LVL4_INTRA_NUM = FOURCC_META('l', '4', 'i', ' '), 76 /* output P skip frame indicator */ 77 KEY_OUTPUT_PSKIP = FOURCC_META('o', 'p', 's', 'p'), 78 /* 79 * Input P-skip frame request 80 * KEY_INPUT_PSKIP: The skip frame will be referenced in the next frame. 81 * KEY_INPUT_PSKIP_NON_REF: The skip frame will not be referenced as a frame. 82 */ 83 KEY_INPUT_PSKIP = FOURCC_META('i', 'p', 's', 'p'), 84 KEY_INPUT_PSKIP_NON_REF = FOURCC_META('i', 'p', 'n', 'r'), 85 KEY_ENC_SSE = FOURCC_META('e', 's', 's', 'e'), 86 87 /* 88 * For vepu580 roi buffer config mode 89 * The encoder roi structure is so complex that we should provide a buffer 90 * tunnel for externl user to config encoder hardware by direct sending 91 * roi data buffer. 92 * This way can reduce the config parsing and roi buffer data generating 93 * overhead in mpp. 94 */ 95 KEY_ROI_DATA2 = FOURCC_META('r', 'o', 'i', '2'), 96 97 /* 98 * qpmap for rv1109/1126 encoder qpmap config 99 * Input data is a MppBuffer which contains an array of 16bit Vepu541RoiCfg. 100 * And each 16bit represents a 16x16 block qp info. 101 * 102 * H.264 - 16x16 block qp is arranged in raster order: 103 * each value is a 16bit data 104 * 00 01 02 03 04 05 06 07 -> 00 01 02 03 04 05 06 07 105 * 10 11 12 13 14 15 16 17 10 11 12 13 14 15 16 17 106 * 20 21 22 23 24 25 26 27 20 21 22 23 24 25 26 27 107 * 30 31 32 33 34 35 36 37 30 31 32 33 34 35 36 37 108 * 109 * H.265 - 16x16 block qp is reorder to 64x64/32x32 ctu order then 64x64 / 32x32 ctu raster order 110 * 64x64 ctu 111 * 00 01 02 03 04 05 06 07 -> 00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33 04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37 112 * 10 11 12 13 14 15 16 17 113 * 20 21 22 23 24 25 26 27 114 * 30 31 32 33 34 35 36 37 115 * 32x32 ctu 116 * 00 01 02 03 04 05 06 07 -> 00 01 10 11 02 03 12 13 04 05 14 15 06 07 16 17 117 * 10 11 12 13 14 15 16 17 20 21 30 31 22 23 32 33 24 25 34 35 26 27 36 37 118 * 20 21 22 23 24 25 26 27 119 * 30 31 32 33 34 35 36 37 120 */ 121 KEY_QPMAP0 = FOURCC_META('e', 'q', 'm', '0'), 122 123 /* 124 * shared memory buffer for object dectection flag from NPU, for rv1126b 125 * Picture width is aligned to 16, each 16x16 block is 8bit data. 126 * H.264: 16x16 block is arranged in raster order. 127 * H.265: 16x16 block is reordered to ctu order then ctu raster order 128 */ 129 KEY_NPU_SOBJ_FLAG = FOURCC_META('n', 'p', 'u', 's'), 130 /* userspace object dectection flag from NPU, for rk3588 and rk3576 */ 131 KEY_NPU_UOBJ_FLAG = FOURCC_META('n', 'p', 'u', 'u'), 132 133 /* 134 * smart v4 encoder input key 135 */ 136 KEY_BUFFER_UPSCALE = FOURCC_META('u', 'b', 'u', 'f'), 137 KEY_BUFFER_DOWNSCALE = FOURCC_META('d', 'b', 'u', 'f'), 138 139 /* frame long-term reference frame operation */ 140 KEY_ENC_MARK_LTR = FOURCC_META('m', 'l', 't', 'r'), 141 KEY_ENC_USE_LTR = FOURCC_META('u', 'l', 't', 'r'), 142 143 /* MLVEC specified encoder feature */ 144 KEY_ENC_FRAME_QP = FOURCC_META('f', 'r', 'm', 'q'), 145 KEY_ENC_BASE_LAYER_PID = FOURCC_META('b', 'p', 'i', 'd'), 146 147 /* Thumbnail info for decoder output frame */ 148 KEY_DEC_TBN_EN = FOURCC_META('t', 'b', 'e', 'n'), 149 KEY_DEC_TBN_Y_OFFSET = FOURCC_META('t', 'b', 'y', 'o'), 150 KEY_DEC_TBN_UV_OFFSET = FOURCC_META('t', 'b', 'c', 'o'), 151 152 /* combo frame */ 153 KEY_COMBO_FRAME = FOURCC_META('c', 'f', 'r', 'm'), 154 KEY_CHANNEL_ID = FOURCC_META('c', 'h', 'a', 'n'), 155 156 /* Preprocess (pp) operation metat data */ 157 /* Motion Detection output buffer */ 158 KEY_PP_MD_BUF = FOURCC_META('m', 'd', 'b', 'f'), 159 /* Occlusion Detection output buffer */ 160 KEY_PP_OD_BUF = FOURCC_META('o', 'd', 'b', 'f'), 161 /* pp output data */ 162 KEY_PP_OUT = FOURCC_META('o', 'p', 'p', ' '), 163 } MppMetaKey; 164 165 #define mpp_meta_get(meta) mpp_meta_get_with_tag(meta, MODULE_TAG, __FUNCTION__) 166 167 #include "mpp_frame.h" 168 #include "mpp_packet.h" 169 170 #ifdef __cplusplus 171 extern "C" { 172 #endif 173 174 MPP_RET mpp_meta_get_with_tag(MppMeta *meta, const char *tag, const char *caller); 175 MPP_RET mpp_meta_put(MppMeta meta); 176 RK_S32 mpp_meta_size(MppMeta meta); 177 MppMeta mpp_meta_dup(MppMeta meta); 178 179 MPP_RET mpp_meta_set_s32(MppMeta meta, MppMetaKey key, RK_S32 val); 180 MPP_RET mpp_meta_set_s64(MppMeta meta, MppMetaKey key, RK_S64 val); 181 MPP_RET mpp_meta_set_ptr(MppMeta meta, MppMetaKey key, void *val); 182 MPP_RET mpp_meta_get_s32(MppMeta meta, MppMetaKey key, RK_S32 *val); 183 MPP_RET mpp_meta_get_s64(MppMeta meta, MppMetaKey key, RK_S64 *val); 184 MPP_RET mpp_meta_get_ptr(MppMeta meta, MppMetaKey key, void **val); 185 186 MPP_RET mpp_meta_set_frame (MppMeta meta, MppMetaKey key, MppFrame frame); 187 MPP_RET mpp_meta_set_packet(MppMeta meta, MppMetaKey key, MppPacket packet); 188 MPP_RET mpp_meta_set_buffer(MppMeta meta, MppMetaKey key, MppBuffer buffer); 189 MPP_RET mpp_meta_get_frame (MppMeta meta, MppMetaKey key, MppFrame *frame); 190 MPP_RET mpp_meta_get_packet(MppMeta meta, MppMetaKey key, MppPacket *packet); 191 MPP_RET mpp_meta_get_buffer(MppMeta meta, MppMetaKey key, MppBuffer *buffer); 192 193 MPP_RET mpp_meta_get_s32_d(MppMeta meta, MppMetaKey key, RK_S32 *val, RK_S32 def); 194 MPP_RET mpp_meta_get_s64_d(MppMeta meta, MppMetaKey key, RK_S64 *val, RK_S64 def); 195 MPP_RET mpp_meta_get_ptr_d(MppMeta meta, MppMetaKey key, void **val, void *def); 196 MPP_RET mpp_meta_get_frame_d(MppMeta meta, MppMetaKey key, MppFrame *frame, MppFrame def); 197 MPP_RET mpp_meta_get_packet_d(MppMeta meta, MppMetaKey key, MppPacket *packet, MppPacket def); 198 MPP_RET mpp_meta_get_buffer_d(MppMeta meta, MppMetaKey key, MppBuffer *buffer, MppBuffer def); 199 200 #ifdef __cplusplus 201 } 202 #endif 203 204 #endif /*__MPP_META_H__*/ 205