xref: /OK3568_Linux_fs/external/mpp/mpp/codec/dec/vp8/vp8d_parser.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 
52 
53 typedef enum {
54     VP8_YCbCr_BT601,
55     VP8_CUSTOM
56 } vpColorSpace_e;
57 
58 typedef struct {
59     RK_U32 lowvalue;
60     RK_U32 range;
61     RK_U32 value;
62     RK_S32 count;
63     RK_U32 pos;
64     RK_U8 *buffer;
65     RK_U32 BitCounter;
66     RK_U32 streamEndPos;
67     RK_U32 strmError;
68 } vpBoolCoder_t;
69 
70 typedef struct {
71     RK_U8              probLuma16x16PredMode[4];
72     RK_U8              probChromaPredMode[3];
73     RK_U8              probMvContext[2][VP8_MV_PROBS_PER_COMPONENT];
74     RK_U8              probCoeffs[4][8][3][11];
75 } vp8EntropyProbs_t;
76 
77 typedef struct VP8Frame {
78     MppFrame f;
79     RK_S32 slot_index;
80     RK_S8 ref_count;
81     RK_U8 invisible;
82 } VP8Frame;
83 
84 
85 typedef struct VP8DParserContext {
86     DXVA_PicParams_VP8 *dxva_ctx;
87     RK_U8           *bitstream_sw_buf;
88     RK_U32          max_stream_size;
89     RK_U32          stream_size;
90 
91     VP8Frame       *frame_out;
92     VP8Frame       *frame_ref;
93     VP8Frame       *frame_golden;
94     VP8Frame       *frame_alternate;
95 
96     vpBoolCoder_t       bitstr;
97 
98     RK_U32             decMode;
99 
100     /* Current frame dimensions */
101     RK_U32             width;
102     RK_U32             height;
103     RK_U32             scaledWidth;
104     RK_U32             scaledHeight;
105 
106     RK_U8             vpVersion;
107     RK_U32             vpProfile;
108 
109     RK_U32             keyFrame;
110 
111     RK_U8              coeffSkipMode;
112 
113     /* DCT coefficient partitions */
114     RK_U32             offsetToDctParts;
115     RK_U32             nbrDctPartitions;
116     RK_U32             dctPartitionOffsets[MAX_NBR_OF_DCT_PARTITIONS];
117 
118     vpColorSpace_e     colorSpace;
119     RK_U32             clamping;
120     RK_U32             showFrame;
121 
122 
123     RK_U32             refreshGolden;
124     RK_U32             refreshAlternate;
125     RK_U32             refreshLast;
126     RK_U32             refreshEntropyProbs;
127     RK_U32             copyBufferToGolden;
128     RK_U32             copyBufferToAlternate;
129 
130     RK_U32             refFrameSignBias[2];
131     RK_U32             useAsReference;
132     RK_U32             loopFilterType;
133     RK_U32             loopFilterLevel;
134     RK_U32             loopFilterSharpness;
135 
136     /* Quantization parameters */
137     RK_S8             qpYAc, qpYDc, qpY2Ac, qpY2Dc, qpChAc, qpChDc;
138 
139     /* From here down, frame-to-frame persisting stuff */
140     RK_U32             vp7ScanOrder[16];
141     RK_U32             vp7PrevScanOrder[16];
142 
143     /* Probabilities */
144     RK_U32             probIntra;
145     RK_U32             probRefLast;
146     RK_U32             probRefGolden;
147     RK_U32             probMbSkipFalse;
148     RK_U32             probSegment[3];
149     vp8EntropyProbs_t entropy, entropyLast;
150 
151     /* Segment and macroblock specific values */
152     RK_U32             segmentationEnabled;
153     RK_U32             segmentationMapUpdate;
154     RK_U32             segmentFeatureMode; /* delta/abs */
155     RK_S32             segmentQp[MAX_NBR_OF_SEGMENTS];
156     RK_S32             segmentLoopfilter[MAX_NBR_OF_SEGMENTS];
157     RK_U32             modeRefLfEnabled;
158     RK_S32             mbRefLfDelta[MAX_NBR_OF_MB_REF_LF_DELTAS];
159     RK_S32             mbModeLfDelta[MAX_NBR_OF_MB_MODE_LF_DELTAS];
160 
161     RK_U32             frameTagSize;
162 
163     /* Value to remember last frames prediction for hits into most
164     * probable reference frame */
165     RK_U32             refbuPredHits;
166 
167 
168     RK_S32          dcPred[2];
169     RK_S32          dcMatch[2];
170 
171     RK_U32          frame_cnt;
172     RK_U64          pts;
173 
174     RK_U32          needKeyFrame;
175     MppPacket       input_packet;
176     RK_U32          eos;
177 
178     MppBufSlots packet_slots;
179     MppBufSlots frame_slots;
180 
181     // FILE *fp_dbg_file[VP8D_DBG_FILE_NUM];
182     FILE *fp_dbg_yuv;
183 } VP8DParserContext_t;
184 
185 MPP_RET  vp8d_parser_init   (void *ctx, ParserCfg *cfg);
186 MPP_RET  vp8d_parser_deinit (void *ctx);
187 MPP_RET  vp8d_parser_reset  (void *ctx);
188 MPP_RET  vp8d_parser_flush  (void *ctx);
189 MPP_RET  vp8d_parser_control(void *ctx, MpiCmd cmd_type, void *param);
190 MPP_RET  vp8d_parser_prepare(void *ctx, MppPacket pkt, HalDecTask *task);
191 MPP_RET  vp8d_parser_parse  (void *ctx, HalDecTask *task);
192 MPP_RET  vp8d_parser_callback(void *ctx, void *hal_info);
193 
194 #endif
195 
196