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