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_BUF_SLOT_H__ 18 #define __MPP_BUF_SLOT_H__ 19 20 #include "mpp_frame.h" 21 #include "mpp_callback.h" 22 23 /* 24 * mpp_dec will alloc 18 decoded picture buffer slot 25 * buffer slot is for transferring information between parser / mpp/ hal 26 * it represent the dpb routine in logical 27 * 28 * basic working flow: 29 * 30 * buf_slot parser hal 31 * 32 * + + + 33 * | | | 34 * | +--------+--------+ | 35 * | | | | 36 * | | do parsing here | | 37 * | | | | 38 * | +--------+--------+ | 39 * | | | 40 * | get_slot | | 41 * | <--------------------------+ | 42 * | get unused dpb slot for | | 43 * | current decoder output | | 44 * | | | 45 * | update dpb refer status | | 46 * | <--------------------------+ | 47 * | parser will send marking | | 48 * | operation to dpb slot | | 49 * | including: | | 50 * | ref/unref/output/display | | 51 * | | | 52 * | | | 53 * | | set buffer status to hal | 54 * +-------------------------------------------------------> | 55 * | | | 56 * | | +--------+--------+ 57 * | | | | 58 * | | | reg generation | 59 * | | | | 60 * | | +--------+--------+ 61 * | | | 62 * | | get buffer address info | 63 * | <-------------------------------------------------------+ 64 * | | used buffer index to get | 65 * | | physical address or iommu | 66 * | | address for hardware | 67 * | | | 68 * | | +--------+--------+ 69 * | | | | 70 * | | | set/wait hw | 71 * | | | | 72 * | | +--------+--------+ 73 * | | | 74 * | | update the output status | 75 * | <-------------------------------------------------------+ 76 * | | mark picture is available | 77 * | | for output and generate | 78 * | | output frame information | 79 * + + + 80 * 81 * typical buffer status transfer 82 * 83 * -> unused initial 84 * -> set_hw_dst by parser 85 * -> set_buffer by mpp - do alloc buffer here / info change here 86 * -> clr_hw_dst by hal() 87 * 88 * next four step can be different order 89 * -> set_dpb_ref by parser 90 * -> set_display by parser - slot ready to display, can be output 91 * -> clr_display by mpp - output buffer struct 92 * -> clr_dpb_ref by parser 93 * 94 * -> set_unused automatic clear and dec buffer ref 95 * 96 */ 97 98 typedef void* MppBufSlots; 99 100 /* 101 * buffer slot index range is 0~254, 0xff (255) will indicated the invalid index 102 */ 103 #define SLOT_IDX_BUTT (0xff) 104 105 #ifdef __cplusplus 106 extern "C" { 107 #endif 108 109 /* 110 * called by mpp context 111 * 112 * init / deinit - normal initialize and de-initialize function 113 * setup - called by parser when slot information changed 114 * is_changed - called by mpp to detect whether info change flow is needed 115 * ready - called by mpp when info changed is done 116 * 117 * typical info change flow: 118 * 119 * mpp_buf_slot_setup called in parser with changed equal to 1 120 * mpp_buf_slot_is_changed called in mpp and found info change 121 * 122 * do info change outside 123 * 124 * mpp_buf_slot_ready called in mpp when info change is done 125 * 126 */ 127 MPP_RET mpp_buf_slot_init(MppBufSlots *slots); 128 MPP_RET mpp_buf_slot_deinit(MppBufSlots slots); 129 MPP_RET mpp_buf_slot_setup(MppBufSlots slots, RK_S32 count); 130 RK_U32 mpp_buf_slot_is_changed(MppBufSlots slots); 131 MPP_RET mpp_buf_slot_ready(MppBufSlots slots); 132 size_t mpp_buf_slot_get_size(MppBufSlots slots); 133 RK_S32 mpp_buf_slot_get_count(MppBufSlots slots); 134 MPP_RET mpp_buf_slot_set_callback(MppBufSlots slots, MppCbCtx *cb_ctx); 135 /* 136 * called by parser 137 * 138 * mpp_buf_slot_get_unused 139 * - parser need a new slot for output, on field mode alloc one buffer for two field 140 * 141 * mpp_buf_slot_set_dpb_ref 142 * - mark a slot to be used as reference frame in dpb 143 * 144 * mpp_buf_slot_clr_dpb_ref 145 * - mark a slot to be unused as reference frame and remove from dpb 146 * 147 * mpp_buf_slot_set_hw_dst 148 * - mark a slot to be output destination buffer 149 * - NOTE: the frame information MUST be set here 150 * 151 * mpp_buf_slot_set_display 152 * - mark a slot to be can be display 153 * - NOTE: set display will generate a MppFrame for buffer slot internal usage 154 * for example store pts / buffer address, etc. 155 * 156 * mpp_buf_slot_inc_hw_ref 157 * - MUST be called once when one slot is used in hardware decoding as reference frame 158 * 159 * called by mpp 160 * 161 * mpp_buf_slot_get_hw_dst 162 * - mpp_dec need to get the output slot index to check buffer status 163 * 164 * mpp_buf_slot_clr_display 165 * - mark a slot has been send out to display 166 * - NOTE: will be called inside mpp_buf_slot_get_display 167 * 168 * called by hal 169 * 170 * mpp_buf_slot_clr_hw_dst 171 * - mark a slot's buffer is already decoded by hardware 172 * - NOTE: this call will clear used as output flag 173 * 174 * mpp_buf_slot_dec_hw_ref 175 * - when hal finished on hardware decoding it MUST be called once for each used slot 176 */ 177 MPP_RET mpp_buf_slot_get_unused(MppBufSlots slots, RK_S32 *index); 178 179 /* 180 * mpp_buf_slot_set_buffer 181 * - called by dec thread when find a output index has not buffer 182 * 183 * mpp_buf_slot_get_buffer 184 * - called by hal module on register generation 185 * 186 * mpp_buf_slot_get_display 187 * - called by hal thread to output a display slot's frame info 188 * NOTE: get display will generate a new MppFrame for external mpp_frame_deinit call 189 * So that external mpp_frame_deinit will not release the MppFrame used in buf_slot 190 */ 191 192 /* 193 * NOTE: 194 * buffer slot will be used both for frame and packet 195 * when buffer slot is used for packet management only inc_hw_ref and dec_hw_ref is used 196 */ 197 198 typedef enum SlotUsageType_e { 199 SLOT_CODEC_READY, // bit flag for buffer is prepared by codec 200 SLOT_CODEC_USE, // bit flag for buffer is used as reference by codec 201 SLOT_HAL_INPUT, // counter for buffer is used as hardware input 202 SLOT_HAL_OUTPUT, // counter + bit flag for buffer is used as hardware output 203 SLOT_QUEUE_USE, // bit flag for buffer is hold in different queues 204 SLOT_USAGE_BUTT, 205 } SlotUsageType; 206 207 MPP_RET mpp_buf_slot_set_flag(MppBufSlots slots, RK_S32 index, SlotUsageType type); 208 MPP_RET mpp_buf_slot_clr_flag(MppBufSlots slots, RK_S32 index, SlotUsageType type); 209 210 // TODO: can be extended here 211 typedef enum SlotQueueType_e { 212 QUEUE_OUTPUT, // queue for mpp output to user 213 QUEUE_DISPLAY, // queue for decoder output display 214 QUEUE_DEINTERLACE, // queue for deinterlace process 215 QUEUE_COLOR_CONVERT, // queue for color convertion process 216 QUEUE_BUTT, 217 } SlotQueueType; 218 219 MPP_RET mpp_buf_slot_enqueue(MppBufSlots slots, RK_S32 index, SlotQueueType type); 220 MPP_RET mpp_buf_slot_dequeue(MppBufSlots slots, RK_S32 *index, SlotQueueType type); 221 222 typedef enum SlotPropType_e { 223 SLOT_EOS, 224 SLOT_FRAME, 225 SLOT_BUFFER, 226 SLOT_FRAME_PTR, 227 SLOT_PROP_BUTT, 228 } SlotPropType; 229 230 MPP_RET mpp_buf_slot_set_prop(MppBufSlots slots, RK_S32 index, SlotPropType type, void *val); 231 MPP_RET mpp_buf_slot_get_prop(MppBufSlots slots, RK_S32 index, SlotPropType type, void *val); 232 233 typedef enum SlotsPropType_e { 234 SLOTS_EOS, 235 SLOTS_NUMERATOR, // numerator of buffer size scale ratio 236 SLOTS_DENOMINATOR, // denominator of buffer size scale ratio 237 SLOTS_HOR_ALIGN, // input must be buf_align function pointer 238 SLOTS_VER_ALIGN, // input must be buf_align function pointer 239 SLOTS_LEN_ALIGN, 240 SLOTS_COUNT, 241 SLOTS_SIZE, 242 SLOTS_FRAME_INFO, 243 SLOTS_PROP_BUTT, 244 } SlotsPropType; 245 246 typedef RK_U32 (*AlignFunc)(RK_U32 val); 247 248 RK_U32 mpp_slots_is_empty(MppBufSlots slots, SlotQueueType type); 249 RK_S32 mpp_slots_get_used_count(MppBufSlots slots); 250 RK_S32 mpp_slots_get_unused_count(MppBufSlots slots); 251 MPP_RET mpp_slots_set_prop(MppBufSlots slots, SlotsPropType type, void *val); 252 MPP_RET mpp_slots_get_prop(MppBufSlots slots, SlotsPropType type, void *val); 253 MPP_RET mpp_buf_slot_reset(MppBufSlots slots, RK_S32 index); //rest slot status when info_change no ok 254 255 // special one for generate default frame to slot at index and return pointer 256 MPP_RET mpp_buf_slot_default_info(MppBufSlots slots, RK_S32 index, void *val); 257 258 #ifdef __cplusplus 259 } 260 #endif 261 262 #endif /*__MPP_BUF_SLOT_H__*/ 263