vdpau_private.h revision 9e51c200a78b8be8be195e0d82d69e952afd1343
1/************************************************************************** 2 * 3 * Copyright 2010 Younes Manton & Thomas Balling Sørensen. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28#ifndef VDPAU_PRIVATE_H 29#define VDPAU_PRIVATE_H 30 31#include <assert.h> 32 33#include <vdpau/vdpau.h> 34#include <vdpau/vdpau_x11.h> 35 36#include "pipe/p_compiler.h" 37#include "pipe/p_video_decoder.h" 38 39#include "util/u_debug.h" 40#include "util/u_rect.h" 41#include "vl/vl_compositor.h" 42 43#include "vl_winsys.h" 44 45/* Full VDPAU API documentation available at : 46 * ftp://download.nvidia.com/XFree86/vdpau/doxygen/html/index.html */ 47 48#define INFORMATION G3DVL VDPAU Driver Shared Library version VER_MAJOR.VER_MINOR 49#define QUOTEME(x) #x 50#define TOSTRING(x) QUOTEME(x) 51#define INFORMATION_STRING TOSTRING(INFORMATION) 52#define VL_HANDLES 53 54static inline enum pipe_video_chroma_format 55ChromaToPipe(VdpChromaType vdpau_type) 56{ 57 switch (vdpau_type) { 58 case VDP_CHROMA_TYPE_420: 59 return PIPE_VIDEO_CHROMA_FORMAT_420; 60 case VDP_CHROMA_TYPE_422: 61 return PIPE_VIDEO_CHROMA_FORMAT_422; 62 case VDP_CHROMA_TYPE_444: 63 return PIPE_VIDEO_CHROMA_FORMAT_444; 64 default: 65 assert(0); 66 } 67 68 return -1; 69} 70 71static inline VdpChromaType 72PipeToChroma(enum pipe_video_chroma_format pipe_type) 73{ 74 switch (pipe_type) { 75 case PIPE_VIDEO_CHROMA_FORMAT_420: 76 return VDP_CHROMA_TYPE_420; 77 case PIPE_VIDEO_CHROMA_FORMAT_422: 78 return VDP_CHROMA_TYPE_422; 79 case PIPE_VIDEO_CHROMA_FORMAT_444: 80 return VDP_CHROMA_TYPE_444; 81 default: 82 assert(0); 83 } 84 85 return -1; 86} 87 88static inline enum pipe_format 89FormatYCBCRToPipe(VdpYCbCrFormat vdpau_format) 90{ 91 switch (vdpau_format) { 92 case VDP_YCBCR_FORMAT_NV12: 93 return PIPE_FORMAT_NV12; 94 case VDP_YCBCR_FORMAT_YV12: 95 return PIPE_FORMAT_YV12; 96 case VDP_YCBCR_FORMAT_UYVY: 97 return PIPE_FORMAT_UYVY; 98 case VDP_YCBCR_FORMAT_YUYV: 99 return PIPE_FORMAT_YUYV; 100 case VDP_YCBCR_FORMAT_Y8U8V8A8: /* Not defined in p_format.h */ 101 return PIPE_FORMAT_NONE; 102 case VDP_YCBCR_FORMAT_V8U8Y8A8: 103 return PIPE_FORMAT_VUYA; 104 default: 105 assert(0); 106 } 107 108 return PIPE_FORMAT_NONE; 109} 110 111static inline VdpYCbCrFormat 112PipeToFormatYCBCR(enum pipe_format p_format) 113{ 114 switch (p_format) { 115 case PIPE_FORMAT_NV12: 116 return VDP_YCBCR_FORMAT_NV12; 117 case PIPE_FORMAT_YV12: 118 return VDP_YCBCR_FORMAT_YV12; 119 case PIPE_FORMAT_UYVY: 120 return VDP_YCBCR_FORMAT_UYVY; 121 case PIPE_FORMAT_YUYV: 122 return VDP_YCBCR_FORMAT_YUYV; 123 //case PIPE_FORMAT_YUVA: 124 // return VDP_YCBCR_FORMAT_Y8U8V8A8; 125 case PIPE_FORMAT_VUYA: 126 return VDP_YCBCR_FORMAT_V8U8Y8A8; 127 default: 128 assert(0); 129 } 130 131 return -1; 132} 133 134static inline enum pipe_format 135FormatRGBAToPipe(VdpRGBAFormat vdpau_format) 136{ 137 switch (vdpau_format) { 138 case VDP_RGBA_FORMAT_A8: 139 return PIPE_FORMAT_A8_UNORM; 140 case VDP_RGBA_FORMAT_B10G10R10A2: 141 return PIPE_FORMAT_B10G10R10A2_UNORM; 142 case VDP_RGBA_FORMAT_B8G8R8A8: 143 return PIPE_FORMAT_B8G8R8A8_UNORM; 144 case VDP_RGBA_FORMAT_R10G10B10A2: 145 return PIPE_FORMAT_R10G10B10A2_UNORM; 146 case VDP_RGBA_FORMAT_R8G8B8A8: 147 return PIPE_FORMAT_R8G8B8A8_UNORM; 148 default: 149 assert(0); 150 } 151 152 return PIPE_FORMAT_NONE; 153} 154 155static inline VdpRGBAFormat 156PipeToFormatRGBA(enum pipe_format p_format) 157{ 158 switch (p_format) { 159 case PIPE_FORMAT_A8_UNORM: 160 return VDP_RGBA_FORMAT_A8; 161 case PIPE_FORMAT_B10G10R10A2_UNORM: 162 return VDP_RGBA_FORMAT_B10G10R10A2; 163 case PIPE_FORMAT_B8G8R8A8_UNORM: 164 return VDP_RGBA_FORMAT_B8G8R8A8; 165 case PIPE_FORMAT_R10G10B10A2_UNORM: 166 return VDP_RGBA_FORMAT_R10G10B10A2; 167 case PIPE_FORMAT_R8G8B8A8_UNORM: 168 return VDP_RGBA_FORMAT_R8G8B8A8; 169 default: 170 assert(0); 171 } 172 173 return -1; 174} 175 176static inline enum pipe_format 177FormatIndexedToPipe(VdpRGBAFormat vdpau_format) 178{ 179 switch (vdpau_format) { 180 case VDP_INDEXED_FORMAT_A4I4: 181 return PIPE_FORMAT_A4R4_UNORM; 182 case VDP_INDEXED_FORMAT_I4A4: 183 return PIPE_FORMAT_R4A4_UNORM; 184 case VDP_INDEXED_FORMAT_A8I8: 185 return PIPE_FORMAT_A8R8_UNORM; 186 case VDP_INDEXED_FORMAT_I8A8: 187 return PIPE_FORMAT_R8A8_UNORM; 188 default: 189 assert(0); 190 } 191 192 return PIPE_FORMAT_NONE; 193} 194 195static inline enum pipe_format 196FormatColorTableToPipe(VdpColorTableFormat vdpau_format) 197{ 198 switch(vdpau_format) { 199 case VDP_COLOR_TABLE_FORMAT_B8G8R8X8: 200 return PIPE_FORMAT_B8G8R8X8_UNORM; 201 default: 202 assert(0); 203 } 204 205 return PIPE_FORMAT_NONE; 206} 207 208static inline enum pipe_video_profile 209ProfileToPipe(VdpDecoderProfile vdpau_profile) 210{ 211 switch (vdpau_profile) { 212 case VDP_DECODER_PROFILE_MPEG1: 213 return PIPE_VIDEO_PROFILE_MPEG1; 214 case VDP_DECODER_PROFILE_MPEG2_SIMPLE: 215 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE; 216 case VDP_DECODER_PROFILE_MPEG2_MAIN: 217 return PIPE_VIDEO_PROFILE_MPEG2_MAIN; 218 case VDP_DECODER_PROFILE_H264_BASELINE: 219 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE; 220 case VDP_DECODER_PROFILE_H264_MAIN: 221 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN; 222 case VDP_DECODER_PROFILE_H264_HIGH: 223 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH; 224 case VDP_DECODER_PROFILE_MPEG4_PART2_SP: 225 return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE; 226 case VDP_DECODER_PROFILE_MPEG4_PART2_ASP: 227 return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE; 228 case VDP_DECODER_PROFILE_VC1_SIMPLE: 229 return PIPE_VIDEO_PROFILE_VC1_SIMPLE; 230 case VDP_DECODER_PROFILE_VC1_MAIN: 231 return PIPE_VIDEO_PROFILE_VC1_MAIN; 232 case VDP_DECODER_PROFILE_VC1_ADVANCED: 233 return PIPE_VIDEO_PROFILE_VC1_ADVANCED; 234 default: 235 return PIPE_VIDEO_PROFILE_UNKNOWN; 236 } 237} 238 239static inline VdpDecoderProfile 240PipeToProfile(enum pipe_video_profile p_profile) 241{ 242 switch (p_profile) { 243 case PIPE_VIDEO_PROFILE_MPEG1: 244 return VDP_DECODER_PROFILE_MPEG1; 245 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE: 246 return VDP_DECODER_PROFILE_MPEG2_SIMPLE; 247 case PIPE_VIDEO_PROFILE_MPEG2_MAIN: 248 return VDP_DECODER_PROFILE_MPEG2_MAIN; 249 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE: 250 return VDP_DECODER_PROFILE_H264_BASELINE; 251 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN: 252 return VDP_DECODER_PROFILE_H264_MAIN; 253 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH: 254 return VDP_DECODER_PROFILE_H264_HIGH; 255 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE: 256 return VDP_DECODER_PROFILE_MPEG4_PART2_SP; 257 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE: 258 return VDP_DECODER_PROFILE_MPEG4_PART2_ASP; 259 case PIPE_VIDEO_PROFILE_VC1_SIMPLE: 260 return VDP_DECODER_PROFILE_VC1_SIMPLE; 261 case PIPE_VIDEO_PROFILE_VC1_MAIN: 262 return VDP_DECODER_PROFILE_VC1_MAIN; 263 case PIPE_VIDEO_PROFILE_VC1_ADVANCED: 264 return VDP_DECODER_PROFILE_VC1_ADVANCED; 265 default: 266 assert(0); 267 return -1; 268 } 269} 270 271static inline struct pipe_video_rect * 272RectToPipe(const VdpRect *src, struct pipe_video_rect *dst) 273{ 274 if (src) { 275 dst->x = MIN2(src->x1, src->x0); 276 dst->y = MIN2(src->y1, src->y0); 277 dst->w = abs(src->x1 - src->x0); 278 dst->h = abs(src->y1 - src->y0); 279 return dst; 280 } 281 return NULL; 282} 283 284typedef struct 285{ 286 struct vl_screen *vscreen; 287 struct vl_context *context; 288 struct vl_compositor compositor; 289} vlVdpDevice; 290 291typedef struct 292{ 293 vlVdpDevice *device; 294 Drawable drawable; 295} vlVdpPresentationQueueTarget; 296 297typedef struct 298{ 299 vlVdpDevice *device; 300 Drawable drawable; 301 struct vl_compositor compositor; 302 struct u_rect dirty_area; 303} vlVdpPresentationQueue; 304 305typedef struct 306{ 307 vlVdpDevice *device; 308 struct vl_compositor compositor; 309} vlVdpVideoMixer; 310 311typedef struct 312{ 313 vlVdpDevice *device; 314 struct pipe_video_buffer *video_buffer; 315} vlVdpSurface; 316 317typedef uint64_t vlVdpTime; 318 319typedef struct 320{ 321 vlVdpTime timestamp; 322 vlVdpDevice *device; 323 struct pipe_surface *surface; 324 struct pipe_sampler_view *sampler_view; 325 struct pipe_fence_handle *fence; 326 struct u_rect dirty_area; 327} vlVdpOutputSurface; 328 329typedef struct 330{ 331 vlVdpDevice *device; 332 struct pipe_video_decoder *decoder; 333 unsigned num_buffers; 334 void **buffers; 335 unsigned cur_buffer; 336} vlVdpDecoder; 337 338typedef uint32_t vlHandle; 339 340boolean vlCreateHTAB(void); 341void vlDestroyHTAB(void); 342vlHandle vlAddDataHTAB(void *data); 343void* vlGetDataHTAB(vlHandle handle); 344void vlRemoveDataHTAB(vlHandle handle); 345 346boolean vlGetFuncFTAB(VdpFuncId function_id, void **func); 347 348/* Public functions */ 349VdpDeviceCreateX11 vdp_imp_device_create_x11; 350VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11; 351 352/* Internal function pointers */ 353VdpGetErrorString vlVdpGetErrorString; 354VdpDeviceDestroy vlVdpDeviceDestroy; 355VdpGetProcAddress vlVdpGetProcAddress; 356VdpGetApiVersion vlVdpGetApiVersion; 357VdpGetInformationString vlVdpGetInformationString; 358VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities; 359VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities; 360VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities; 361VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities; 362VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities; 363VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities; 364VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities; 365VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities; 366VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport; 367VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport; 368VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange; 369VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport; 370VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange; 371VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate; 372VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy; 373VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters; 374VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr; 375VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr; 376VdpDecoderCreate vlVdpDecoderCreate; 377VdpDecoderDestroy vlVdpDecoderDestroy; 378VdpDecoderGetParameters vlVdpDecoderGetParameters; 379VdpDecoderRender vlVdpDecoderRender; 380VdpOutputSurfaceCreate vlVdpOutputSurfaceCreate; 381VdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy; 382VdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters; 383VdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative; 384VdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative; 385VdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed; 386VdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr; 387VdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface; 388VdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface; 389VdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate; 390VdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy; 391VdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters; 392VdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative; 393VdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy; 394VdpPresentationQueueCreate vlVdpPresentationQueueCreate; 395VdpPresentationQueueDestroy vlVdpPresentationQueueDestroy; 396VdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor; 397VdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor; 398VdpPresentationQueueGetTime vlVdpPresentationQueueGetTime; 399VdpPresentationQueueDisplay vlVdpPresentationQueueDisplay; 400VdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle; 401VdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus; 402VdpPreemptionCallback vlVdpPreemptionCallback; 403VdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister; 404VdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables; 405VdpVideoMixerCreate vlVdpVideoMixerCreate; 406VdpVideoMixerRender vlVdpVideoMixerRender; 407VdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues; 408VdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport; 409VdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables; 410VdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues; 411VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues; 412VdpVideoMixerDestroy vlVdpVideoMixerDestroy; 413VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix; 414 415#define VDPAU_OUT 0 416#define VDPAU_ERR 1 417#define VDPAU_WARN 2 418#define VDPAU_TRACE 3 419 420static inline void VDPAU_MSG(unsigned int level, const char *fmt, ...) 421{ 422 static int debug_level = -1; 423 424 if (debug_level == -1) { 425 debug_level = MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0); 426 } 427 428 if (level <= debug_level) { 429 va_list ap; 430 va_start(ap, fmt); 431 _debug_vprintf(fmt, ap); 432 va_end(ap); 433 } 434} 435 436#endif /* VDPAU_PRIVATE_H */ 437