1 /* 2 * Copyright 2020 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 18 #ifndef __HAL_AV1D_GLOBAL_H__ 19 #define __HAL_AV1D_GLOBAL_H__ 20 21 #include "mpp_hal.h" 22 #include "mpp_debug.h" 23 #include "mpp_device.h" 24 #include "hal_bufs.h" 25 26 #include "dxva_syntax.h" 27 28 #define AV1D_DBG_ERROR (0x00000001) 29 #define AV1D_DBG_ASSERT (0x00000002) 30 #define AV1D_DBG_WARNNING (0x00000004) 31 #define AV1D_DBG_LOG (0x00000008) 32 33 #define AV1D_DBG_HARD_MODE (0x00000010) 34 35 extern RK_U32 hal_av1d_debug; 36 37 #define AV1D_DBG(level, fmt, ...)\ 38 do {\ 39 if (level & hal_av1d_debug)\ 40 { mpp_log(fmt, ## __VA_ARGS__); }\ 41 } while (0) 42 43 44 #define AV1D_ERR(fmt, ...)\ 45 do {\ 46 if (AV1D_DBG_ERROR & hal_av1d_debug)\ 47 { mpp_log(fmt, ## __VA_ARGS__); }\ 48 } while (0) 49 50 #define ASSERT(val)\ 51 do {\ 52 if (AV1D_DBG_ASSERT & hal_av1d_debug)\ 53 { mpp_assert(val); }\ 54 } while (0) 55 56 #define AV1D_WARNNING(fmt, ...)\ 57 do {\ 58 if (AV1D_DBG_WARNNING & hal_av1d_debug)\ 59 { mpp_log(fmt, ## __VA_ARGS__); }\ 60 } while (0) 61 62 #define AV1D_LOG(fmt, ...)\ 63 do {\ 64 if (AV1D_DBG_LOG & hal_av1d_debug)\ 65 { mpp_log(fmt, ## __VA_ARGS__); }\ 66 } while (0) 67 68 69 //!< vaule check 70 #define VAL_CHECK(ret, val, ...)\ 71 do{\ 72 if (!(val)){\ 73 ret = MPP_ERR_VALUE; \ 74 AV1D_WARNNING("value error(%d).\n", __LINE__); \ 75 goto __FAILED; \ 76 }} while (0) 77 //!< memory malloc check 78 #define MEM_CHECK(ret, val, ...)\ 79 do{\ 80 if (!(val)) {\ 81 ret = MPP_ERR_MALLOC; \ 82 AV1D_ERR("malloc buffer error(%d).\n", __LINE__); \ 83 ASSERT(0); goto __FAILED; \ 84 }} while (0) 85 86 #define BUF_CHECK(ret, val, ...)\ 87 do{\ 88 if (val) {\ 89 ret = MPP_ERR_BUFFER_FULL; \ 90 AV1D_ERR("buffer get error(%d).\n", __LINE__); \ 91 ASSERT(0); goto __FAILED; \ 92 }} while (0) 93 94 #define BUF_PUT(val, ...)\ 95 do{\ 96 if (val) {\ 97 if (mpp_buffer_put(val)) {\ 98 AV1D_ERR("buffer put error(%d).\n", __LINE__); \ 99 ASSERT(0); \ 100 }\ 101 }} while (0) 102 103 //!< input check 104 #define INP_CHECK(ret, val, ...)\ 105 do{\ 106 if ((val)) {\ 107 ret = MPP_ERR_INIT; \ 108 AV1D_WARNNING("input empty(%d).\n", __LINE__); \ 109 goto __RETURN; \ 110 }} while (0) 111 //!< function return check 112 #define FUN_CHECK(val)\ 113 do{\ 114 if ((val) < 0) {\ 115 AV1D_WARNNING("Function error(%d).\n", __LINE__); \ 116 goto __FAILED; \ 117 }} while (0) 118 119 #define MAX_MB_SEGMENTS 8 120 121 enum Av1SegLevelFeatures { 122 SEG_AV1_LVL_ALT_Q, // Use alternate Quantizer .... 123 SEG_AV1_LVL_ALT_LF_Y_V, // Use alternate loop filter value on y plane 124 // vertical 125 SEG_AV1_LVL_ALT_LF_Y_H, // Use alternate loop filter value on y plane 126 // horizontal 127 SEG_AV1_LVL_ALT_LF_U, // Use alternate loop filter value on u plane 128 SEG_AV1_LVL_ALT_LF_V, // Use alternate loop filter value on v plane 129 SEG_AV1_LVL_REF_FRAME, // Optional Segment reference frame 130 SEG_AV1_LVL_SKIP, // Optional Segment (0,0) + skip mode 131 SEG_AV1_LVL_GLOBALMV, 132 SEG_AV1_LVL_MAX 133 }; 134 135 #define AV1_ACTIVE_REFS 3 136 #define AV1_ACTIVE_REFS_EX 7 137 #define AV1_REF_LIST_SIZE 8 138 #define AV1_REF_SCALE_SHIFT 14 139 140 enum MvReferenceFrame { 141 NONE = -1, 142 INTRA_FRAME = 0, 143 LAST_FRAME = 1, 144 LAST2_FRAME_EX = 2, 145 LAST3_FRAME_EX = 3, 146 GOLDEN_FRAME_EX = 4, 147 BWDREF_FRAME_EX = 5, 148 ALTREF2_FRAME_EX = 6, 149 ALTREF_FRAME_EX = 7, 150 MAX_REF_FRAMES_EX = 8, 151 GOLDEN_FRAME = 2, 152 ALTREF_FRAME = 3, 153 154 MAX_REF_FRAMES = 4 155 }; 156 157 enum { 158 AV1_FRAME_KEY = 0, 159 AV1_FRAME_INTER = 1, 160 AV1_FRAME_INTRA_ONLY = 2, 161 AV1_FRAME_SWITCH = 3, 162 }; 163 164 #define AV1DEC_MAX_PIC_BUFFERS 24 165 #define AV1DEC_DYNAMIC_PIC_LIMIT 10 166 #define ALLOWED_REFS_PER_FRAME_EX 7 167 168 typedef struct FilmGrainMemory_t { 169 RK_U8 scaling_lut_y[256]; 170 RK_U8 scaling_lut_cb[256]; 171 RK_U8 scaling_lut_cr[256]; 172 RK_S16 cropped_luma_grain_block[4096]; 173 RK_S16 cropped_chroma_grain_block[1024 * 2]; 174 } FilmGrainMemory; 175 176 typedef struct av1d_hal_ctx_t { 177 const MppHalApi *api; 178 RK_U8 *bitstream; 179 RK_U32 strm_len; 180 181 HalDecTask *in_task; 182 MppBufSlots slots; 183 MppBufSlots packet_slots; 184 MppDecCfgSet *cfg; 185 MppBufferGroup buf_group; 186 187 MppCbCtx *dec_cb; 188 MppDev dev; 189 void *reg_ctx; 190 RK_U32 fast_mode; 191 const MppDecHwCap *hw_info; 192 } Av1dHalCtx; 193 194 #endif /* __HAL_AV1D_GLOBAL_H__ */ 195