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