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 graphicBufferHStride; 152 uint32_t graphicBufferVStride; 153 uint32_t graphicBufferColorFormat; 154 uint32_t graphicBufferWidth; 155 uint32_t graphicBufferHeight; 156 VideoExtensionBuffer *ext; 157 void* nativeWindow; 158 uint32_t rotationDegrees; 159 #ifdef TARGET_HAS_ISV 160 uint32_t vppBufferNum; 161 #endif 162 }; 163 164 struct VideoErrorInfo { 165 VideoDecodeErrorType type; 166 uint32_t num_mbs; 167 union { 168 struct {uint32_t start_mb; uint32_t end_mb;} mb_pos; 169 } error_data; 170 }; 171 172 struct VideoErrorBuffer { 173 uint32_t errorNumber; // Error number should be no more than MAX_ERR_NUM 174 int64_t timeStamp; // presentation time stamp 175 VideoErrorInfo errorArray[MAX_ERR_NUM]; 176 }; 177 178 struct VideoRenderBuffer { 179 VASurfaceID surface; 180 VADisplay display; 181 int32_t scanFormat; //progressive, top-field first, or bottom-field first 182 int64_t timeStamp; // presentation time stamp 183 mutable volatile bool renderDone; // indicated whether frame is rendered, this must be set to false by the client of this library once 184 // surface is rendered. Not setting this flag will lead to DECODE_NO_SURFACE error. 185 void * graphicBufferHandle; 186 int32_t graphicBufferIndex; //the index in graphichandle array 187 uint32_t flag; 188 mutable volatile bool driverRenderDone; 189 VideoFrameRawData *rawData; 190 191 VideoErrorBuffer errBuf; 192 }; 193 194 struct VideoSurfaceBuffer { 195 VideoRenderBuffer renderBuffer; 196 int32_t pictureOrder; // picture order count, valid only for AVC format 197 bool referenceFrame; // indicated whether frame associated with this surface is a reference I/P frame 198 bool asReferernce; // indicated wheter frame is used as reference (as a result surface can not be used for decoding) 199 VideoFrameRawData *mappedData; 200 VideoSurfaceBuffer *next; 201 }; 202 203 struct VideoFormatInfo { 204 bool valid; // indicates whether format info is valid. MimeType is always valid. 205 char *mimeType; 206 uint32_t width; 207 uint32_t height; 208 uint32_t surfaceWidth; 209 uint32_t surfaceHeight; 210 uint32_t surfaceNumber; 211 VASurfaceID *ctxSurfaces; 212 int32_t aspectX; 213 int32_t aspectY; 214 int32_t cropLeft; 215 int32_t cropRight; 216 int32_t cropTop; 217 int32_t cropBottom; 218 int32_t colorMatrix; 219 int32_t videoRange; 220 int32_t bitrate; 221 int32_t framerateNom; 222 int32_t framerateDenom; 223 uint32_t actualBufferNeeded; 224 int32_t flags; // indicate whether current picture is field or frame 225 VideoExtensionBuffer *ext; 226 }; 227 228 // TODO: categorize the follow errors as fatal and non-fatal. 229 typedef enum { 230 DECODE_NOT_STARTED = -10, 231 DECODE_NEED_RESTART = -9, 232 DECODE_NO_CONFIG = -8, 233 DECODE_NO_SURFACE = -7, 234 DECODE_NO_REFERENCE = -6, 235 DECODE_NO_PARSER = -5, 236 DECODE_INVALID_DATA = -4, 237 DECODE_DRIVER_FAIL = -3, 238 DECODE_PARSER_FAIL = -2, 239 DECODE_MEMORY_FAIL = -1, 240 DECODE_FAIL = 0, 241 DECODE_SUCCESS = 1, 242 DECODE_FORMAT_CHANGE = 2, 243 DECODE_FRAME_DROPPED = 3, 244 DECODE_MULTIPLE_FRAME = 4, 245 } VIDEO_DECODE_STATUS; 246 247 typedef int32_t Decode_Status; 248 249 #ifndef NULL 250 #define NULL 0 251 #endif 252 253 inline bool checkFatalDecoderError(Decode_Status status) { 254 if (status == DECODE_NOT_STARTED || 255 status == DECODE_NEED_RESTART || 256 status == DECODE_NO_PARSER || 257 status == DECODE_INVALID_DATA || 258 status == DECODE_MEMORY_FAIL || 259 status == DECODE_FAIL) { 260 return true; 261 } else { 262 return false; 263 } 264 } 265 266 #endif // VIDEO_DECODER_DEFS_H_ 267