1 /*
2 * Copyright (c) 2009-2011 Intel Corporation. All rights reserved.
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 VIDEO_DECODER_DEFS_H_
18 #define VIDEO_DECODER_DEFS_H_
19
20 #include <va/va.h>
21 #include <stdint.h>
22
23 // format specific data, for future extension.
24 struct VideoExtensionBuffer {
25 int32_t extType;
26 int32_t extSize;
27 uint8_t *extData;
28 };
29
30 typedef enum {
31 PACKED_FRAME_TYPE,
32 } VIDEO_EXTENSION_TYPE;
33
34 struct VideoFrameRawData {
35 int32_t width;
36 int32_t height;
37 int32_t pitch[3];
38 int32_t offset[3];
39 uint32_t fourcc; //NV12
40 int32_t size;
41 uint8_t *data;
42 bool own; // own data or derived from surface. If true, the library will release the memory during clearnup
43 };
44
45 struct PackedFrameData {
46 int64_t timestamp;
47 int32_t offSet;
48 };
49
50 // flags for VideoDecodeBuffer, VideoConfigBuffer and VideoRenderBuffer
51 typedef enum {
52 // indicates if sample has discontinuity in time stamp (happen after seeking usually)
53 HAS_DISCONTINUITY = 0x01,
54
55 // indicates wheter the sample contains a complete frame or end of frame.
56 HAS_COMPLETE_FRAME = 0x02,
57
58 // indicate whether surfaceNumber field in the VideoConfigBuffer is valid
59 HAS_SURFACE_NUMBER = 0x04,
60
61 // indicate whether profile field in the VideoConfigBuffer is valid
62 HAS_VA_PROFILE = 0x08,
63
64 // indicate whether output order will be the same as decoder order
65 WANT_LOW_DELAY = 0x10, // make display order same as decoding order
66
67 // indicates whether error concealment algorithm should be enabled to automatically conceal error.
68 WANT_ERROR_CONCEALMENT = 0x20,
69
70 // indicate wheter raw data should be output.
71 WANT_RAW_OUTPUT = 0x40,
72
73 // indicate sample is decoded but should not be displayed.
74 WANT_DECODE_ONLY = 0x80,
75
76 // indicate surfaceNumber field is valid and it contains minimum surface number to allocate.
77 HAS_MINIMUM_SURFACE_NUMBER = 0x100,
78
79 // indicates surface created will be protected
80 WANT_SURFACE_PROTECTION = 0x400,
81
82 // indicates if extra data is appended at end of buffer
83 HAS_EXTRADATA = 0x800,
84
85 // indicates if buffer contains codec data
86 HAS_CODECDATA = 0x1000,
87
88 // indicate if it use graphic buffer.
89 USE_NATIVE_GRAPHIC_BUFFER = 0x2000,
90
91 // indicate whether it is a sync frame in container
92 IS_SYNC_FRAME = 0x4000,
93
94 // indicate whether video decoder buffer contains secure data
95 IS_SECURE_DATA = 0x8000,
96
97 // indicate it's the last output frame of the sequence
98 IS_EOS = 0x10000,
99
100 // indicate should allocate tiling surfaces
101 USE_TILING_MEMORY = 0x20000,
102
103 // indicate the frame has resolution change
104 IS_RESOLUTION_CHANGE = 0x40000,
105
106 // indicate whether video decoder buffer contains only one field
107 IS_SINGLE_FIELD = 0x80000,
108
109 // indicate adaptive playback mode
110 WANT_ADAPTIVE_PLAYBACK = 0x100000,
111
112 // indicate the modular drm type
113 IS_SUBSAMPLE_ENCRYPTION = 0x200000,
114
115 // indicate meta data mode
116 WANT_STORE_META_DATA = 0x400000,
117 } VIDEO_BUFFER_FLAG;
118
119 typedef enum
120 {
121 DecodeHeaderError = 0,
122 DecodeMBError = 1,
123 DecodeSliceMissing = 2,
124 DecodeRefMissing = 3,
125 } VideoDecodeErrorType;
126
127 #define MAX_ERR_NUM 10
128
129 struct VideoDecodeBuffer {
130 uint8_t *data;
131 int32_t size;
132 int64_t timeStamp;
133 uint32_t flag;
134 uint32_t rotationDegrees;
135 VideoExtensionBuffer *ext;
136 };
137
138
139 //#define MAX_GRAPHIC_BUFFER_NUM (16 + 1 + 11) // max DPB + 1 + AVC_EXTRA_NUM
140 #define MAX_GRAPHIC_BUFFER_NUM 64 // extended for VPP
141
142 struct VideoConfigBuffer {
143 uint8_t *data;
144 int32_t size;
145 int32_t width;
146 int32_t height;
147 uint32_t surfaceNumber;
148 VAProfile profile;
149 uint32_t flag;
150 void *graphicBufferHandler[MAX_GRAPHIC_BUFFER_NUM];
151 uint32_t graphicBufferStride;
152 uint32_t graphicBufferColorFormat;
153 uint32_t graphicBufferWidth;
154 uint32_t graphicBufferHeight;
155 VideoExtensionBuffer *ext;
156 void* nativeWindow;
157 uint32_t rotationDegrees;
158 #ifdef TARGET_HAS_ISV
159 uint32_t vppBufferNum;
160 #endif
161 };
162
163 struct VideoErrorInfo {
164 VideoDecodeErrorType type;
165 uint32_t num_mbs;
166 union {
167 struct {uint32_t start_mb; uint32_t end_mb;} mb_pos;
168 } error_data;
169 };
170
171 struct VideoErrorBuffer {
172 uint32_t errorNumber; // Error number should be no more than MAX_ERR_NUM
173 int64_t timeStamp; // presentation time stamp
174 VideoErrorInfo errorArray[MAX_ERR_NUM];
175 };
176
177 struct VideoRenderBuffer {
178 VASurfaceID surface;
179 VADisplay display;
180 int32_t scanFormat; //progressive, top-field first, or bottom-field first
181 int64_t timeStamp; // presentation time stamp
182 mutable volatile bool renderDone; // indicated whether frame is rendered, this must be set to false by the client of this library once
183 // surface is rendered. Not setting this flag will lead to DECODE_NO_SURFACE error.
184 void * graphicBufferHandle;
185 int32_t graphicBufferIndex; //the index in graphichandle array
186 uint32_t flag;
187 mutable volatile bool driverRenderDone;
188 VideoFrameRawData *rawData;
189
190 VideoErrorBuffer errBuf;
191 };
192
193 struct VideoSurfaceBuffer {
194 VideoRenderBuffer renderBuffer;
195 int32_t pictureOrder; // picture order count, valid only for AVC format
196 bool referenceFrame; // indicated whether frame associated with this surface is a reference I/P frame
197 bool asReferernce; // indicated wheter frame is used as reference (as a result surface can not be used for decoding)
198 VideoFrameRawData *mappedData;
199 VideoSurfaceBuffer *next;
200 };
201
202 struct VideoFormatInfo {
203 bool valid; // indicates whether format info is valid. MimeType is always valid.
204 char *mimeType;
205 uint32_t width;
206 uint32_t height;
207 uint32_t surfaceWidth;
208 uint32_t surfaceHeight;
209 uint32_t surfaceNumber;
210 VASurfaceID *ctxSurfaces;
211 int32_t aspectX;
212 int32_t aspectY;
213 int32_t cropLeft;
214 int32_t cropRight;
215 int32_t cropTop;
216 int32_t cropBottom;
217 int32_t colorMatrix;
218 int32_t videoRange;
219 int32_t bitrate;
220 int32_t framerateNom;
221 int32_t framerateDenom;
222 uint32_t actualBufferNeeded;
223 int32_t flags; // indicate whether current picture is field or frame
224 VideoExtensionBuffer *ext;
225 };
226
227 // TODO: categorize the follow errors as fatal and non-fatal.
228 typedef enum {
229 DECODE_NOT_STARTED = -10,
230 DECODE_NEED_RESTART = -9,
231 DECODE_NO_CONFIG = -8,
232 DECODE_NO_SURFACE = -7,
233 DECODE_NO_REFERENCE = -6,
234 DECODE_NO_PARSER = -5,
235 DECODE_INVALID_DATA = -4,
236 DECODE_DRIVER_FAIL = -3,
237 DECODE_PARSER_FAIL = -2,
238 DECODE_MEMORY_FAIL = -1,
239 DECODE_FAIL = 0,
240 DECODE_SUCCESS = 1,
241 DECODE_FORMAT_CHANGE = 2,
242 DECODE_FRAME_DROPPED = 3,
243 DECODE_MULTIPLE_FRAME = 4,
244 } VIDEO_DECODE_STATUS;
245
246 typedef int32_t Decode_Status;
247
248 #ifndef NULL
249 #define NULL 0
250 #endif
251
checkFatalDecoderError(Decode_Status status)252 inline bool checkFatalDecoderError(Decode_Status status) {
253 if (status == DECODE_NOT_STARTED ||
254 status == DECODE_NEED_RESTART ||
255 status == DECODE_NO_PARSER ||
256 status == DECODE_INVALID_DATA ||
257 status == DECODE_MEMORY_FAIL ||
258 status == DECODE_FAIL) {
259 return true;
260 } else {
261 return false;
262 }
263 }
264
265 #endif // VIDEO_DECODER_DEFS_H_
266