xref: /OK3568_Linux_fs/external/rknpu2/examples/3rdparty/mpp/include/rockchip/mpp_meta.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 __MPP_META_H__
18 #define __MPP_META_H__
19 
20 #include <stdint.h>
21 #include "rk_type.h"
22 
23 #define FOURCC_META(a, b, c, d) ((RK_U32)(a) << 24  | \
24                                 ((RK_U32)(b) << 16) | \
25                                 ((RK_U32)(c) << 8)  | \
26                                 ((RK_U32)(d) << 0))
27 
28 /*
29  * Mpp Metadata definition
30  *
31  * Metadata is for information transmision in mpp.
32  * Mpp task will contain two meta data:
33  *
34  * 1. Data flow metadata
35  *    This metadata contains information of input / output data flow. For example
36  *    A. decoder input side task the input packet must be defined and output frame
37  *    may not be defined. Then decoder will try malloc or use committed buffer to
38  *    complete decoding.
39  *    B. decoder output side task
40  *
41  *
42  * 2. Flow control metadata
43  *
44  */
45 typedef enum MppMetaDataType_e {
46     /*
47      * mpp meta data of data flow
48      * reference counter will be used for these meta data type
49      */
50     TYPE_FRAME                  = FOURCC_META('m', 'f', 'r', 'm'),
51     TYPE_PACKET                 = FOURCC_META('m', 'p', 'k', 't'),
52     TYPE_BUFFER                 = FOURCC_META('m', 'b', 'u', 'f'),
53 
54     /* mpp meta data of normal data type */
55     TYPE_S32                    = FOURCC_META('s', '3', '2', ' '),
56     TYPE_S64                    = FOURCC_META('s', '6', '4', ' '),
57     TYPE_PTR                    = FOURCC_META('p', 't', 'r', ' '),
58 } MppMetaType;
59 
60 typedef enum MppMetaKey_e {
61     /* data flow key */
62     KEY_INPUT_FRAME             = FOURCC_META('i', 'f', 'r', 'm'),
63     KEY_INPUT_PACKET            = FOURCC_META('i', 'p', 'k', 't'),
64     KEY_OUTPUT_FRAME            = FOURCC_META('o', 'f', 'r', 'm'),
65     KEY_OUTPUT_PACKET           = FOURCC_META('o', 'p', 'k', 't'),
66     /* output motion information for motion detection */
67     KEY_MOTION_INFO             = FOURCC_META('m', 'v', 'i', 'f'),
68     KEY_HDR_INFO                = FOURCC_META('h', 'd', 'r', ' '),
69     KEY_HDR_META_OFFSET         = FOURCC_META('h', 'd', 'r', 'o'),
70     KEY_HDR_META_SIZE           = FOURCC_META('h', 'd', 'r', 'l'),
71 
72     /* flow control key */
73     KEY_INPUT_BLOCK             = FOURCC_META('i', 'b', 'l', 'k'),
74     KEY_OUTPUT_BLOCK            = FOURCC_META('o', 'b', 'l', 'k'),
75     KEY_INPUT_IDR_REQ           = FOURCC_META('i', 'i', 'd', 'r'),   /* input idr frame request flag */
76     KEY_OUTPUT_INTRA            = FOURCC_META('o', 'i', 'd', 'r'),   /* output intra frame indicator */
77 
78     /* mpp_frame / mpp_packet meta data info key */
79     KEY_TEMPORAL_ID             = FOURCC_META('t', 'l', 'i', 'd'),
80     KEY_LONG_REF_IDX            = FOURCC_META('l', 't', 'i', 'd'),
81     KEY_ENC_AVERAGE_QP          = FOURCC_META('a', 'v', 'g', 'q'),
82     KEY_ROI_DATA                = FOURCC_META('r', 'o', 'i', ' '),
83     KEY_OSD_DATA                = FOURCC_META('o', 's', 'd', ' '),
84     KEY_OSD_DATA2               = FOURCC_META('o', 's', 'd', '2'),
85     KEY_USER_DATA               = FOURCC_META('u', 's', 'r', 'd'),
86     KEY_USER_DATAS              = FOURCC_META('u', 'r', 'd', 's'),
87 
88     /*
89      * For vepu580 roi buffer config mode
90      * The encoder roi structure is so complex that we should provide a buffer
91      * tunnel for externl user to config encoder hardware by direct sending
92      * roi data buffer.
93      * This way can reduce the config parsing and roi buffer data generating
94      * overhead in mpp.
95      */
96     KEY_ROI_DATA2               = FOURCC_META('r', 'o', 'i', '2'),
97 
98     /*
99      * qpmap for rv1109/1126 encoder qpmap config
100      * Input data is a MppBuffer which contains an array of 16bit Vepu541RoiCfg.
101      * And each 16bit represents a 16x16 block qp info.
102      *
103      * H.264 - 16x16 block qp is arranged in raster order:
104      * each value is a 16bit data
105      * 00 01 02 03 04 05 06 07 -> 00 01 02 03 04 05 06 07
106      * 10 11 12 13 14 15 16 17    10 11 12 13 14 15 16 17
107      * 20 21 22 23 24 25 26 27    20 21 22 23 24 25 26 27
108      * 30 31 32 33 34 35 36 37    30 31 32 33 34 35 36 37
109      *
110      * H.265 - 16x16 block qp is reorder to 64x64/32x32 ctu order then 64x64 / 32x32 ctu raster order
111      * 64x64 ctu
112      * 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
113      * 10 11 12 13 14 15 16 17
114      * 20 21 22 23 24 25 26 27
115      * 30 31 32 33 34 35 36 37
116      * 32x32 ctu
117      * 00 01 02 03 04 05 06 07 -> 00 01 10 11 02 03 12 13 04 05 14 15 06 07 16 17
118      * 10 11 12 13 14 15 16 17    20 21 30 31 22 23 32 33 24 25 34 35 26 27 36 37
119      * 20 21 22 23 24 25 26 27
120      * 30 31 32 33 34 35 36 37
121      */
122     KEY_QPMAP0                  = FOURCC_META('e', 'q', 'm', '0'),
123 
124     /* input motion list for smart p rate control */
125     KEY_MV_LIST                 = FOURCC_META('m', 'v', 'l', 't'),
126 
127     /* frame long-term reference frame operation */
128     KEY_ENC_MARK_LTR            = FOURCC_META('m', 'l', 't', 'r'),
129     KEY_ENC_USE_LTR             = FOURCC_META('u', 'l', 't', 'r'),
130 
131     /* MLVEC specified encoder feature  */
132     KEY_ENC_FRAME_QP            = FOURCC_META('f', 'r', 'm', 'q'),
133     KEY_ENC_BASE_LAYER_PID      = FOURCC_META('b', 'p', 'i', 'd'),
134 
135     /* Thumbnail info for decoder output frame */
136     KEY_DEC_TBN_EN              = FOURCC_META('t', 'b', 'e', 'n'),
137     KEY_DEC_TBN_Y_OFFSET        = FOURCC_META('t', 'b', 'y', 'o'),
138     KEY_DEC_TBN_UV_OFFSET       = FOURCC_META('t', 'b', 'c', 'o'),
139 } MppMetaKey;
140 
141 #define mpp_meta_get(meta) mpp_meta_get_with_tag(meta, MODULE_TAG, __FUNCTION__)
142 
143 #include "mpp_frame.h"
144 #include "mpp_packet.h"
145 
146 #ifdef __cplusplus
147 extern "C" {
148 #endif
149 
150 MPP_RET mpp_meta_get_with_tag(MppMeta *meta, const char *tag, const char *caller);
151 MPP_RET mpp_meta_put(MppMeta meta);
152 RK_S32  mpp_meta_size(MppMeta meta);
153 
154 MPP_RET mpp_meta_set_s32(MppMeta meta, MppMetaKey key, RK_S32 val);
155 MPP_RET mpp_meta_set_s64(MppMeta meta, MppMetaKey key, RK_S64 val);
156 MPP_RET mpp_meta_set_ptr(MppMeta meta, MppMetaKey key, void  *val);
157 MPP_RET mpp_meta_get_s32(MppMeta meta, MppMetaKey key, RK_S32 *val);
158 MPP_RET mpp_meta_get_s64(MppMeta meta, MppMetaKey key, RK_S64 *val);
159 MPP_RET mpp_meta_get_ptr(MppMeta meta, MppMetaKey key, void  **val);
160 
161 MPP_RET mpp_meta_set_frame (MppMeta meta, MppMetaKey key, MppFrame  frame);
162 MPP_RET mpp_meta_set_packet(MppMeta meta, MppMetaKey key, MppPacket packet);
163 MPP_RET mpp_meta_set_buffer(MppMeta meta, MppMetaKey key, MppBuffer buffer);
164 MPP_RET mpp_meta_get_frame (MppMeta meta, MppMetaKey key, MppFrame  *frame);
165 MPP_RET mpp_meta_get_packet(MppMeta meta, MppMetaKey key, MppPacket *packet);
166 MPP_RET mpp_meta_get_buffer(MppMeta meta, MppMetaKey key, MppBuffer *buffer);
167 
168 MPP_RET mpp_meta_get_s32_d(MppMeta meta, MppMetaKey key, RK_S32 *val, RK_S32 def);
169 MPP_RET mpp_meta_get_s64_d(MppMeta meta, MppMetaKey key, RK_S64 *val, RK_S64 def);
170 MPP_RET mpp_meta_get_ptr_d(MppMeta meta, MppMetaKey key, void  **val, void *def);
171 MPP_RET mpp_meta_get_frame_d(MppMeta meta, MppMetaKey key, MppFrame *frame, MppFrame def);
172 MPP_RET mpp_meta_get_packet_d(MppMeta meta, MppMetaKey key, MppPacket *packet, MppPacket def);
173 MPP_RET mpp_meta_get_buffer_d(MppMeta meta, MppMetaKey key, MppBuffer *buffer, MppBuffer def);
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #endif /*__MPP_META_H__*/
180