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