1 /**************************************************************************
3 * Copyright 2010 Younes Manton & Thomas Balling Sørensen.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #ifndef VDPAU_PRIVATE_H
29 #define VDPAU_PRIVATE_H
33 #include <vdpau/vdpau.h>
34 #include <vdpau/vdpau_x11.h>
36 #include "pipe/p_compiler.h"
37 #include "pipe/p_video_decoder.h"
39 #include "util/u_debug.h"
40 #include "util/u_rect.h"
41 #include "os/os_thread.h"
43 #include "vl/vl_compositor.h"
44 #include "vl/vl_csc.h"
45 #include "vl/vl_matrix_filter.h"
46 #include "vl/vl_median_filter.h"
47 #include "vl/vl_winsys.h"
49 /* Full VDPAU API documentation available at :
50 * ftp://download.nvidia.com/XFree86/vdpau/doxygen/html/index.html */
52 #define INFORMATION G3DVL VDPAU Driver Shared Library version VER_MAJOR.VER_MINOR
54 #define TOSTRING(x) QUOTEME(x)
55 #define INFORMATION_STRING TOSTRING(INFORMATION)
58 static inline enum pipe_video_chroma_format
59 ChromaToPipe(VdpChromaType vdpau_type
)
62 case VDP_CHROMA_TYPE_420
:
63 return PIPE_VIDEO_CHROMA_FORMAT_420
;
64 case VDP_CHROMA_TYPE_422
:
65 return PIPE_VIDEO_CHROMA_FORMAT_422
;
66 case VDP_CHROMA_TYPE_444
:
67 return PIPE_VIDEO_CHROMA_FORMAT_444
;
75 static inline VdpChromaType
76 PipeToChroma(enum pipe_video_chroma_format pipe_type
)
79 case PIPE_VIDEO_CHROMA_FORMAT_420
:
80 return VDP_CHROMA_TYPE_420
;
81 case PIPE_VIDEO_CHROMA_FORMAT_422
:
82 return VDP_CHROMA_TYPE_422
;
83 case PIPE_VIDEO_CHROMA_FORMAT_444
:
84 return VDP_CHROMA_TYPE_444
;
92 static inline enum pipe_format
93 FormatYCBCRToPipe(VdpYCbCrFormat vdpau_format
)
95 switch (vdpau_format
) {
96 case VDP_YCBCR_FORMAT_NV12
:
97 return PIPE_FORMAT_NV12
;
98 case VDP_YCBCR_FORMAT_YV12
:
99 return PIPE_FORMAT_YV12
;
100 case VDP_YCBCR_FORMAT_UYVY
:
101 return PIPE_FORMAT_UYVY
;
102 case VDP_YCBCR_FORMAT_YUYV
:
103 return PIPE_FORMAT_YUYV
;
104 case VDP_YCBCR_FORMAT_Y8U8V8A8
:
105 return PIPE_FORMAT_R8G8B8A8_UNORM
;
106 case VDP_YCBCR_FORMAT_V8U8Y8A8
:
107 return PIPE_FORMAT_B8G8R8A8_UNORM
;
112 return PIPE_FORMAT_NONE
;
115 static inline VdpYCbCrFormat
116 PipeToFormatYCBCR(enum pipe_format p_format
)
119 case PIPE_FORMAT_NV12
:
120 return VDP_YCBCR_FORMAT_NV12
;
121 case PIPE_FORMAT_YV12
:
122 return VDP_YCBCR_FORMAT_YV12
;
123 case PIPE_FORMAT_UYVY
:
124 return VDP_YCBCR_FORMAT_UYVY
;
125 case PIPE_FORMAT_YUYV
:
126 return VDP_YCBCR_FORMAT_YUYV
;
127 case PIPE_FORMAT_R8G8B8A8_UNORM
:
128 return VDP_YCBCR_FORMAT_Y8U8V8A8
;
129 case PIPE_FORMAT_B8G8R8A8_UNORM
:
130 return VDP_YCBCR_FORMAT_V8U8Y8A8
;
138 static inline enum pipe_format
139 FormatRGBAToPipe(VdpRGBAFormat vdpau_format
)
141 switch (vdpau_format
) {
142 case VDP_RGBA_FORMAT_A8
:
143 return PIPE_FORMAT_A8_UNORM
;
144 case VDP_RGBA_FORMAT_B10G10R10A2
:
145 return PIPE_FORMAT_B10G10R10A2_UNORM
;
146 case VDP_RGBA_FORMAT_B8G8R8A8
:
147 return PIPE_FORMAT_B8G8R8A8_UNORM
;
148 case VDP_RGBA_FORMAT_R10G10B10A2
:
149 return PIPE_FORMAT_R10G10B10A2_UNORM
;
150 case VDP_RGBA_FORMAT_R8G8B8A8
:
151 return PIPE_FORMAT_R8G8B8A8_UNORM
;
156 return PIPE_FORMAT_NONE
;
159 static inline VdpRGBAFormat
160 PipeToFormatRGBA(enum pipe_format p_format
)
163 case PIPE_FORMAT_A8_UNORM
:
164 return VDP_RGBA_FORMAT_A8
;
165 case PIPE_FORMAT_B10G10R10A2_UNORM
:
166 return VDP_RGBA_FORMAT_B10G10R10A2
;
167 case PIPE_FORMAT_B8G8R8A8_UNORM
:
168 return VDP_RGBA_FORMAT_B8G8R8A8
;
169 case PIPE_FORMAT_R10G10B10A2_UNORM
:
170 return VDP_RGBA_FORMAT_R10G10B10A2
;
171 case PIPE_FORMAT_R8G8B8A8_UNORM
:
172 return VDP_RGBA_FORMAT_R8G8B8A8
;
180 static inline enum pipe_format
181 FormatIndexedToPipe(VdpRGBAFormat vdpau_format
)
183 switch (vdpau_format
) {
184 case VDP_INDEXED_FORMAT_A4I4
:
185 return PIPE_FORMAT_A4R4_UNORM
;
186 case VDP_INDEXED_FORMAT_I4A4
:
187 return PIPE_FORMAT_R4A4_UNORM
;
188 case VDP_INDEXED_FORMAT_A8I8
:
189 return PIPE_FORMAT_A8R8_UNORM
;
190 case VDP_INDEXED_FORMAT_I8A8
:
191 return PIPE_FORMAT_R8A8_UNORM
;
196 return PIPE_FORMAT_NONE
;
199 static inline enum pipe_format
200 FormatColorTableToPipe(VdpColorTableFormat vdpau_format
)
202 switch(vdpau_format
) {
203 case VDP_COLOR_TABLE_FORMAT_B8G8R8X8
:
204 return PIPE_FORMAT_B8G8R8X8_UNORM
;
209 return PIPE_FORMAT_NONE
;
212 static inline enum pipe_video_profile
213 ProfileToPipe(VdpDecoderProfile vdpau_profile
)
215 switch (vdpau_profile
) {
216 case VDP_DECODER_PROFILE_MPEG1
:
217 return PIPE_VIDEO_PROFILE_MPEG1
;
218 case VDP_DECODER_PROFILE_MPEG2_SIMPLE
:
219 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
;
220 case VDP_DECODER_PROFILE_MPEG2_MAIN
:
221 return PIPE_VIDEO_PROFILE_MPEG2_MAIN
;
222 case VDP_DECODER_PROFILE_H264_BASELINE
:
223 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
;
224 case VDP_DECODER_PROFILE_H264_MAIN
:
225 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
;
226 case VDP_DECODER_PROFILE_H264_HIGH
:
227 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
;
228 case VDP_DECODER_PROFILE_MPEG4_PART2_SP
:
229 return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
;
230 case VDP_DECODER_PROFILE_MPEG4_PART2_ASP
:
231 return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
;
232 case VDP_DECODER_PROFILE_VC1_SIMPLE
:
233 return PIPE_VIDEO_PROFILE_VC1_SIMPLE
;
234 case VDP_DECODER_PROFILE_VC1_MAIN
:
235 return PIPE_VIDEO_PROFILE_VC1_MAIN
;
236 case VDP_DECODER_PROFILE_VC1_ADVANCED
:
237 return PIPE_VIDEO_PROFILE_VC1_ADVANCED
;
239 return PIPE_VIDEO_PROFILE_UNKNOWN
;
243 static inline VdpDecoderProfile
244 PipeToProfile(enum pipe_video_profile p_profile
)
247 case PIPE_VIDEO_PROFILE_MPEG1
:
248 return VDP_DECODER_PROFILE_MPEG1
;
249 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
:
250 return VDP_DECODER_PROFILE_MPEG2_SIMPLE
;
251 case PIPE_VIDEO_PROFILE_MPEG2_MAIN
:
252 return VDP_DECODER_PROFILE_MPEG2_MAIN
;
253 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
:
254 return VDP_DECODER_PROFILE_H264_BASELINE
;
255 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
:
256 return VDP_DECODER_PROFILE_H264_MAIN
;
257 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
:
258 return VDP_DECODER_PROFILE_H264_HIGH
;
259 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
:
260 return VDP_DECODER_PROFILE_MPEG4_PART2_SP
;
261 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
:
262 return VDP_DECODER_PROFILE_MPEG4_PART2_ASP
;
263 case PIPE_VIDEO_PROFILE_VC1_SIMPLE
:
264 return VDP_DECODER_PROFILE_VC1_SIMPLE
;
265 case PIPE_VIDEO_PROFILE_VC1_MAIN
:
266 return VDP_DECODER_PROFILE_VC1_MAIN
;
267 case PIPE_VIDEO_PROFILE_VC1_ADVANCED
:
268 return VDP_DECODER_PROFILE_VC1_ADVANCED
;
275 static inline struct u_rect
*
276 RectToPipe(const VdpRect
*src
, struct u_rect
*dst
)
288 static inline struct pipe_box
289 RectToPipeBox(const VdpRect
*rect
, struct pipe_resource
*res
)
296 box
.width
= res
->width0
;
297 box
.height
= res
->height0
;
301 box
.x
= MIN2(rect
->x0
, rect
->x1
);
302 box
.y
= MIN2(rect
->y0
, rect
->y1
);
303 box
.width
= abs(rect
->x1
- rect
->x0
);
304 box
.height
= abs(rect
->y1
- rect
->y0
);
312 struct vl_screen
*vscreen
;
313 struct pipe_context
*context
;
314 struct vl_compositor compositor
;
318 struct vl_compositor_state
*cstate
;
319 VdpOutputSurface surface
;
327 } vlVdpPresentationQueueTarget
;
333 struct vl_compositor_state cstate
;
334 } vlVdpPresentationQueue
;
339 struct vl_compositor_state cstate
;
342 bool supported
, enabled
;
344 struct vl_median_filter
*filter
;
348 bool supported
, enabled
;
350 struct vl_matrix_filter
*filter
;
353 unsigned video_width
, video_height
;
354 enum pipe_video_chroma_format chroma_format
;
355 unsigned max_layers
, skip_chroma_deint
;
356 float luma_key_min
, luma_key_max
;
365 struct pipe_video_buffer templat
, *video_buffer
;
371 struct pipe_sampler_view
*sampler_view
;
372 } vlVdpBitmapSurface
;
374 typedef uint64_t vlVdpTime
;
380 struct pipe_surface
*surface
;
381 struct pipe_sampler_view
*sampler_view
;
382 struct pipe_fence_handle
*fence
;
383 struct vl_compositor_state cstate
;
384 struct u_rect dirty_area
;
385 } vlVdpOutputSurface
;
390 struct pipe_video_decoder
*decoder
;
393 typedef uint32_t vlHandle
;
395 boolean
vlCreateHTAB(void);
396 void vlDestroyHTAB(void);
397 vlHandle
vlAddDataHTAB(void *data
);
398 void* vlGetDataHTAB(vlHandle handle
);
399 void vlRemoveDataHTAB(vlHandle handle
);
401 boolean
vlGetFuncFTAB(VdpFuncId function_id
, void **func
);
403 /* Public functions */
404 VdpDeviceCreateX11 vdp_imp_device_create_x11
;
405 VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11
;
407 void vlVdpDefaultSamplerViewTemplate(struct pipe_sampler_view
*templ
, struct pipe_resource
*res
);
409 /* Delayed rendering funtionality */
410 void vlVdpResolveDelayedRendering(vlVdpDevice
*dev
, struct pipe_surface
*surface
, struct u_rect
*dirty_area
);
411 void vlVdpSave4DelayedRendering(vlVdpDevice
*dev
, VdpOutputSurface surface
, struct vl_compositor_state
*cstate
);
413 /* Internal function pointers */
414 VdpGetErrorString vlVdpGetErrorString
;
415 VdpDeviceDestroy vlVdpDeviceDestroy
;
416 VdpGetProcAddress vlVdpGetProcAddress
;
417 VdpGetApiVersion vlVdpGetApiVersion
;
418 VdpGetInformationString vlVdpGetInformationString
;
419 VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities
;
420 VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities
;
421 VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities
;
422 VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities
;
423 VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities
;
424 VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities
;
425 VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities
;
426 VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities
;
427 VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport
;
428 VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport
;
429 VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange
;
430 VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport
;
431 VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange
;
432 VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate
;
433 VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy
;
434 VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters
;
435 VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr
;
436 VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr
;
437 void vlVdpVideoSurfaceClear(vlVdpSurface
*vlsurf
);
438 VdpDecoderCreate vlVdpDecoderCreate
;
439 VdpDecoderDestroy vlVdpDecoderDestroy
;
440 VdpDecoderGetParameters vlVdpDecoderGetParameters
;
441 VdpDecoderRender vlVdpDecoderRender
;
442 VdpOutputSurfaceCreate vlVdpOutputSurfaceCreate
;
443 VdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy
;
444 VdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters
;
445 VdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative
;
446 VdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative
;
447 VdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed
;
448 VdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr
;
449 VdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface
;
450 VdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface
;
451 VdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate
;
452 VdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy
;
453 VdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters
;
454 VdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative
;
455 VdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy
;
456 VdpPresentationQueueCreate vlVdpPresentationQueueCreate
;
457 VdpPresentationQueueDestroy vlVdpPresentationQueueDestroy
;
458 VdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor
;
459 VdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor
;
460 VdpPresentationQueueGetTime vlVdpPresentationQueueGetTime
;
461 VdpPresentationQueueDisplay vlVdpPresentationQueueDisplay
;
462 VdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle
;
463 VdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus
;
464 VdpPreemptionCallback vlVdpPreemptionCallback
;
465 VdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister
;
466 VdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables
;
467 VdpVideoMixerCreate vlVdpVideoMixerCreate
;
468 VdpVideoMixerRender vlVdpVideoMixerRender
;
469 VdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues
;
470 VdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport
;
471 VdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables
;
472 VdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues
;
473 VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues
;
474 VdpVideoMixerDestroy vlVdpVideoMixerDestroy
;
475 VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix
;
480 #define VDPAU_TRACE 3
482 static inline void VDPAU_MSG(unsigned int level
, const char *fmt
, ...)
484 static int debug_level
= -1;
486 if (debug_level
== -1) {
487 debug_level
= MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0);
490 if (level
<= debug_level
) {
493 _debug_vprintf(fmt
, ap
);
498 #endif /* VDPAU_PRIVATE_H */