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