vdpau_private.h revision 8c2bfa34a0d70ab08de44e3b091b3a097abbad97
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 unsigned video_width, video_height; 310 enum pipe_video_chroma_format chroma_format; 311 unsigned max_layers, skip_chroma_deint, custom_csc; 312 float luma_key_min, luma_key_max, sharpness, noise_reduction_level; 313 float csc[16]; 314} vlVdpVideoMixer; 315 316typedef struct 317{ 318 vlVdpDevice *device; 319 struct pipe_video_buffer *video_buffer; 320} vlVdpSurface; 321 322typedef uint64_t vlVdpTime; 323 324typedef struct 325{ 326 vlVdpTime timestamp; 327 vlVdpDevice *device; 328 struct pipe_surface *surface; 329 struct pipe_sampler_view *sampler_view; 330 struct pipe_fence_handle *fence; 331 struct u_rect dirty_area; 332} vlVdpOutputSurface; 333 334typedef struct 335{ 336 vlVdpDevice *device; 337 struct pipe_video_decoder *decoder; 338} vlVdpDecoder; 339 340typedef uint32_t vlHandle; 341 342boolean vlCreateHTAB(void); 343void vlDestroyHTAB(void); 344vlHandle vlAddDataHTAB(void *data); 345void* vlGetDataHTAB(vlHandle handle); 346void vlRemoveDataHTAB(vlHandle handle); 347 348boolean vlGetFuncFTAB(VdpFuncId function_id, void **func); 349 350/* Public functions */ 351VdpDeviceCreateX11 vdp_imp_device_create_x11; 352VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11; 353 354/* Internal function pointers */ 355VdpGetErrorString vlVdpGetErrorString; 356VdpDeviceDestroy vlVdpDeviceDestroy; 357VdpGetProcAddress vlVdpGetProcAddress; 358VdpGetApiVersion vlVdpGetApiVersion; 359VdpGetInformationString vlVdpGetInformationString; 360VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities; 361VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities; 362VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities; 363VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities; 364VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities; 365VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities; 366VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities; 367VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities; 368VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport; 369VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport; 370VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange; 371VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport; 372VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange; 373VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate; 374VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy; 375VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters; 376VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr; 377VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr; 378VdpDecoderCreate vlVdpDecoderCreate; 379VdpDecoderDestroy vlVdpDecoderDestroy; 380VdpDecoderGetParameters vlVdpDecoderGetParameters; 381VdpDecoderRender vlVdpDecoderRender; 382VdpOutputSurfaceCreate vlVdpOutputSurfaceCreate; 383VdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy; 384VdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters; 385VdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative; 386VdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative; 387VdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed; 388VdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr; 389VdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface; 390VdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface; 391VdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate; 392VdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy; 393VdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters; 394VdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative; 395VdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy; 396VdpPresentationQueueCreate vlVdpPresentationQueueCreate; 397VdpPresentationQueueDestroy vlVdpPresentationQueueDestroy; 398VdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor; 399VdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor; 400VdpPresentationQueueGetTime vlVdpPresentationQueueGetTime; 401VdpPresentationQueueDisplay vlVdpPresentationQueueDisplay; 402VdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle; 403VdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus; 404VdpPreemptionCallback vlVdpPreemptionCallback; 405VdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister; 406VdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables; 407VdpVideoMixerCreate vlVdpVideoMixerCreate; 408VdpVideoMixerRender vlVdpVideoMixerRender; 409VdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues; 410VdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport; 411VdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables; 412VdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues; 413VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues; 414VdpVideoMixerDestroy vlVdpVideoMixerDestroy; 415VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix; 416 417#define VDPAU_OUT 0 418#define VDPAU_ERR 1 419#define VDPAU_WARN 2 420#define VDPAU_TRACE 3 421 422static inline void VDPAU_MSG(unsigned int level, const char *fmt, ...) 423{ 424 static int debug_level = -1; 425 426 if (debug_level == -1) { 427 debug_level = MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0); 428 } 429 430 if (level <= debug_level) { 431 va_list ap; 432 va_start(ap, fmt); 433 _debug_vprintf(fmt, ap); 434 va_end(ap); 435 } 436} 437 438#endif /* VDPAU_PRIVATE_H */ 439