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