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