1 /* 2 * 3 * Copyright 2015 Rockchip Electronics Co. LTD 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #ifndef __VP8D_PARSER_H__ 19 #define __VP8D_PARSER_H__ 20 21 #include <stdio.h> 22 23 #include "parser_api.h" 24 #include "vp8d_syntax.h" 25 #include "vp8d_data.h" 26 27 #define VP8HWD_VP7 1 28 #define VP8HWD_VP8 2 29 #define VP8HWD_WEBP 3 30 31 #define DEC_MODE_VP7 9 32 #define DEC_MODE_VP8 10 33 34 #define MAX_NBR_OF_SEGMENTS (4) 35 #define MAX_NBR_OF_MB_REF_LF_DELTAS (4) 36 #define MAX_NBR_OF_MB_MODE_LF_DELTAS (4) 37 38 #define MAX_NBR_OF_DCT_PARTITIONS (8) 39 40 #define MAX_NBR_OF_VP7_MB_FEATURES (4) 41 42 #define VP8D_BUF_SIZE_BITMEM (512 * 1024) 43 #define VP8D_PROB_TABLE_SIZE (1<<16) /* TODO */ 44 #define VP8D_MAX_SEGMAP_SIZE (2048 + 1024) //1920*1080 /* TODO */ 45 #define VP8_KEY_FRAME_START_CODE 0x9d012a 46 47 #define VP8D_DBG_FUNCTION (0x00000001) 48 #define VP8D_DBG_WARNNING (0x00000004) 49 #define VP8D_DBG_LOG (0x00000008) 50 #define VP8D_DBG_SEC_HEADER (0x00000010) 51 #define VP8D_DBG_DUMP_STREAM (0x00001000) 52 53 54 typedef enum { 55 VP8_YCbCr_BT601, 56 VP8_CUSTOM 57 } vpColorSpace_e; 58 59 typedef struct { 60 RK_U32 lowvalue; 61 RK_U32 range; 62 RK_U32 value; 63 RK_S32 count; 64 RK_U32 pos; 65 RK_U8 *buffer; 66 RK_U32 BitCounter; 67 RK_U32 streamEndPos; 68 RK_U32 strmError; 69 } vpBoolCoder_t; 70 71 typedef struct { 72 RK_U8 probLuma16x16PredMode[4]; 73 RK_U8 probChromaPredMode[3]; 74 RK_U8 probMvContext[2][VP8_MV_PROBS_PER_COMPONENT]; 75 RK_U8 probCoeffs[4][8][3][11]; 76 } vp8EntropyProbs_t; 77 78 typedef struct VP8Frame { 79 MppFrame f; 80 RK_S32 slot_index; 81 RK_S8 ref_count; 82 RK_U8 invisible; 83 } VP8Frame; 84 85 86 typedef struct VP8DParserContext { 87 DXVA_PicParams_VP8 *dxva_ctx; 88 RK_U8 *bitstream_sw_buf; 89 RK_U32 max_stream_size; 90 RK_U32 stream_size; 91 92 VP8Frame *frame_out; 93 VP8Frame *frame_ref; 94 VP8Frame *frame_golden; 95 VP8Frame *frame_alternate; 96 97 vpBoolCoder_t bitstr; 98 99 RK_U32 decMode; 100 101 /* Current frame dimensions */ 102 RK_U32 width; 103 RK_U32 height; 104 RK_U32 scaledWidth; 105 RK_U32 scaledHeight; 106 107 RK_U8 vpVersion; 108 RK_U32 vpProfile; 109 110 RK_U32 keyFrame; 111 112 RK_U8 coeffSkipMode; 113 114 /* DCT coefficient partitions */ 115 RK_U32 offsetToDctParts; 116 RK_U32 nbrDctPartitions; 117 RK_U32 dctPartitionOffsets[MAX_NBR_OF_DCT_PARTITIONS]; 118 119 vpColorSpace_e colorSpace; 120 RK_U32 clamping; 121 RK_U32 showFrame; 122 123 124 RK_U32 refreshGolden; 125 RK_U32 refreshAlternate; 126 RK_U32 refreshLast; 127 RK_U32 refreshEntropyProbs; 128 RK_U32 copyBufferToGolden; 129 RK_U32 copyBufferToAlternate; 130 131 RK_U32 refFrameSignBias[2]; 132 RK_U32 useAsReference; 133 RK_U32 loopFilterType; 134 RK_U32 loopFilterLevel; 135 RK_U32 loopFilterSharpness; 136 137 /* Quantization parameters */ 138 RK_S8 qpYAc, qpYDc, qpY2Ac, qpY2Dc, qpChAc, qpChDc; 139 140 /* From here down, frame-to-frame persisting stuff */ 141 RK_U32 vp7ScanOrder[16]; 142 RK_U32 vp7PrevScanOrder[16]; 143 144 /* Probabilities */ 145 RK_U32 probIntra; 146 RK_U32 probRefLast; 147 RK_U32 probRefGolden; 148 RK_U32 probMbSkipFalse; 149 RK_U32 probSegment[3]; 150 vp8EntropyProbs_t entropy, entropyLast; 151 152 /* Segment and macroblock specific values */ 153 RK_U32 segmentationEnabled; 154 RK_U32 segmentationMapUpdate; 155 RK_U32 segmentFeatureMode; /* delta/abs */ 156 RK_S32 segmentQp[MAX_NBR_OF_SEGMENTS]; 157 RK_S32 segmentLoopfilter[MAX_NBR_OF_SEGMENTS]; 158 RK_U32 modeRefLfEnabled; 159 RK_S32 mbRefLfDelta[MAX_NBR_OF_MB_REF_LF_DELTAS]; 160 RK_S32 mbModeLfDelta[MAX_NBR_OF_MB_MODE_LF_DELTAS]; 161 162 RK_U32 frameTagSize; 163 164 /* Value to remember last frames prediction for hits into most 165 * probable reference frame */ 166 RK_U32 refbuPredHits; 167 168 169 RK_S32 dcPred[2]; 170 RK_S32 dcMatch[2]; 171 172 RK_U32 frame_cnt; 173 RK_U64 pts; 174 RK_U64 dts; 175 176 RK_U32 needKeyFrame; 177 MppPacket input_packet; 178 RK_U32 eos; 179 180 MppBufSlots packet_slots; 181 MppBufSlots frame_slots; 182 /* for debug */ 183 FILE *stream_fp; 184 RK_U32 ivf_header_flag; 185 } VP8DParserContext_t; 186 187 MPP_RET vp8d_parser_init (void *ctx, ParserCfg *cfg); 188 MPP_RET vp8d_parser_deinit (void *ctx); 189 MPP_RET vp8d_parser_reset (void *ctx); 190 MPP_RET vp8d_parser_flush (void *ctx); 191 MPP_RET vp8d_parser_control(void *ctx, MpiCmd cmd_type, void *param); 192 MPP_RET vp8d_parser_prepare(void *ctx, MppPacket pkt, HalDecTask *task); 193 MPP_RET vp8d_parser_parse (void *ctx, HalDecTask *task); 194 MPP_RET vp8d_parser_callback(void *ctx, void *hal_info); 195 196 #endif 197 198