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