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"
48 #include "vl_winsys.h"
50 /* Full VDPAU API documentation available at :
51 * ftp://download.nvidia.com/XFree86/vdpau/doxygen/html/index.html */
53 #define INFORMATION G3DVL VDPAU Driver Shared Library version VER_MAJOR.VER_MINOR
55 #define TOSTRING(x) QUOTEME(x)
56 #define INFORMATION_STRING TOSTRING(INFORMATION)
59 static inline enum pipe_video_chroma_format
60 ChromaToPipe(VdpChromaType vdpau_type
)
63 case VDP_CHROMA_TYPE_420
:
64 return PIPE_VIDEO_CHROMA_FORMAT_420
;
65 case VDP_CHROMA_TYPE_422
:
66 return PIPE_VIDEO_CHROMA_FORMAT_422
;
67 case VDP_CHROMA_TYPE_444
:
68 return PIPE_VIDEO_CHROMA_FORMAT_444
;
76 static inline VdpChromaType
77 PipeToChroma(enum pipe_video_chroma_format pipe_type
)
80 case PIPE_VIDEO_CHROMA_FORMAT_420
:
81 return VDP_CHROMA_TYPE_420
;
82 case PIPE_VIDEO_CHROMA_FORMAT_422
:
83 return VDP_CHROMA_TYPE_422
;
84 case PIPE_VIDEO_CHROMA_FORMAT_444
:
85 return VDP_CHROMA_TYPE_444
;
93 static inline enum pipe_format
94 FormatYCBCRToPipe(VdpYCbCrFormat vdpau_format
)
96 switch (vdpau_format
) {
97 case VDP_YCBCR_FORMAT_NV12
:
98 return PIPE_FORMAT_NV12
;
99 case VDP_YCBCR_FORMAT_YV12
:
100 return PIPE_FORMAT_YV12
;
101 case VDP_YCBCR_FORMAT_UYVY
:
102 return PIPE_FORMAT_UYVY
;
103 case VDP_YCBCR_FORMAT_YUYV
:
104 return PIPE_FORMAT_YUYV
;
105 case VDP_YCBCR_FORMAT_Y8U8V8A8
:
106 return PIPE_FORMAT_R8G8B8A8_UNORM
;
107 case VDP_YCBCR_FORMAT_V8U8Y8A8
:
108 return PIPE_FORMAT_B8G8R8A8_UNORM
;
113 return PIPE_FORMAT_NONE
;
116 static inline VdpYCbCrFormat
117 PipeToFormatYCBCR(enum pipe_format p_format
)
120 case PIPE_FORMAT_NV12
:
121 return VDP_YCBCR_FORMAT_NV12
;
122 case PIPE_FORMAT_YV12
:
123 return VDP_YCBCR_FORMAT_YV12
;
124 case PIPE_FORMAT_UYVY
:
125 return VDP_YCBCR_FORMAT_UYVY
;
126 case PIPE_FORMAT_YUYV
:
127 return VDP_YCBCR_FORMAT_YUYV
;
128 case PIPE_FORMAT_R8G8B8A8_UNORM
:
129 return VDP_YCBCR_FORMAT_Y8U8V8A8
;
130 case PIPE_FORMAT_B8G8R8A8_UNORM
:
131 return VDP_YCBCR_FORMAT_V8U8Y8A8
;
139 static inline enum pipe_format
140 FormatRGBAToPipe(VdpRGBAFormat vdpau_format
)
142 switch (vdpau_format
) {
143 case VDP_RGBA_FORMAT_A8
:
144 return PIPE_FORMAT_A8_UNORM
;
145 case VDP_RGBA_FORMAT_B10G10R10A2
:
146 return PIPE_FORMAT_B10G10R10A2_UNORM
;
147 case VDP_RGBA_FORMAT_B8G8R8A8
:
148 return PIPE_FORMAT_B8G8R8A8_UNORM
;
149 case VDP_RGBA_FORMAT_R10G10B10A2
:
150 return PIPE_FORMAT_R10G10B10A2_UNORM
;
151 case VDP_RGBA_FORMAT_R8G8B8A8
:
152 return PIPE_FORMAT_R8G8B8A8_UNORM
;
157 return PIPE_FORMAT_NONE
;
160 static inline VdpRGBAFormat
161 PipeToFormatRGBA(enum pipe_format p_format
)
164 case PIPE_FORMAT_A8_UNORM
:
165 return VDP_RGBA_FORMAT_A8
;
166 case PIPE_FORMAT_B10G10R10A2_UNORM
:
167 return VDP_RGBA_FORMAT_B10G10R10A2
;
168 case PIPE_FORMAT_B8G8R8A8_UNORM
:
169 return VDP_RGBA_FORMAT_B8G8R8A8
;
170 case PIPE_FORMAT_R10G10B10A2_UNORM
:
171 return VDP_RGBA_FORMAT_R10G10B10A2
;
172 case PIPE_FORMAT_R8G8B8A8_UNORM
:
173 return VDP_RGBA_FORMAT_R8G8B8A8
;
181 static inline enum pipe_format
182 FormatIndexedToPipe(VdpRGBAFormat vdpau_format
)
184 switch (vdpau_format
) {
185 case VDP_INDEXED_FORMAT_A4I4
:
186 return PIPE_FORMAT_A4R4_UNORM
;
187 case VDP_INDEXED_FORMAT_I4A4
:
188 return PIPE_FORMAT_R4A4_UNORM
;
189 case VDP_INDEXED_FORMAT_A8I8
:
190 return PIPE_FORMAT_A8R8_UNORM
;
191 case VDP_INDEXED_FORMAT_I8A8
:
192 return PIPE_FORMAT_R8A8_UNORM
;
197 return PIPE_FORMAT_NONE
;
200 static inline enum pipe_format
201 FormatColorTableToPipe(VdpColorTableFormat vdpau_format
)
203 switch(vdpau_format
) {
204 case VDP_COLOR_TABLE_FORMAT_B8G8R8X8
:
205 return PIPE_FORMAT_B8G8R8X8_UNORM
;
210 return PIPE_FORMAT_NONE
;
213 static inline enum pipe_video_profile
214 ProfileToPipe(VdpDecoderProfile vdpau_profile
)
216 switch (vdpau_profile
) {
217 case VDP_DECODER_PROFILE_MPEG1
:
218 return PIPE_VIDEO_PROFILE_MPEG1
;
219 case VDP_DECODER_PROFILE_MPEG2_SIMPLE
:
220 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
;
221 case VDP_DECODER_PROFILE_MPEG2_MAIN
:
222 return PIPE_VIDEO_PROFILE_MPEG2_MAIN
;
223 case VDP_DECODER_PROFILE_H264_BASELINE
:
224 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
;
225 case VDP_DECODER_PROFILE_H264_MAIN
:
226 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
;
227 case VDP_DECODER_PROFILE_H264_HIGH
:
228 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
;
229 case VDP_DECODER_PROFILE_MPEG4_PART2_SP
:
230 return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
;
231 case VDP_DECODER_PROFILE_MPEG4_PART2_ASP
:
232 return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
;
233 case VDP_DECODER_PROFILE_VC1_SIMPLE
:
234 return PIPE_VIDEO_PROFILE_VC1_SIMPLE
;
235 case VDP_DECODER_PROFILE_VC1_MAIN
:
236 return PIPE_VIDEO_PROFILE_VC1_MAIN
;
237 case VDP_DECODER_PROFILE_VC1_ADVANCED
:
238 return PIPE_VIDEO_PROFILE_VC1_ADVANCED
;
240 return PIPE_VIDEO_PROFILE_UNKNOWN
;
244 static inline VdpDecoderProfile
245 PipeToProfile(enum pipe_video_profile p_profile
)
248 case PIPE_VIDEO_PROFILE_MPEG1
:
249 return VDP_DECODER_PROFILE_MPEG1
;
250 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
:
251 return VDP_DECODER_PROFILE_MPEG2_SIMPLE
;
252 case PIPE_VIDEO_PROFILE_MPEG2_MAIN
:
253 return VDP_DECODER_PROFILE_MPEG2_MAIN
;
254 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
:
255 return VDP_DECODER_PROFILE_H264_BASELINE
;
256 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
:
257 return VDP_DECODER_PROFILE_H264_MAIN
;
258 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
:
259 return VDP_DECODER_PROFILE_H264_HIGH
;
260 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
:
261 return VDP_DECODER_PROFILE_MPEG4_PART2_SP
;
262 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
:
263 return VDP_DECODER_PROFILE_MPEG4_PART2_ASP
;
264 case PIPE_VIDEO_PROFILE_VC1_SIMPLE
:
265 return VDP_DECODER_PROFILE_VC1_SIMPLE
;
266 case PIPE_VIDEO_PROFILE_VC1_MAIN
:
267 return VDP_DECODER_PROFILE_VC1_MAIN
;
268 case PIPE_VIDEO_PROFILE_VC1_ADVANCED
:
269 return VDP_DECODER_PROFILE_VC1_ADVANCED
;
276 static inline struct u_rect
*
277 RectToPipe(const VdpRect
*src
, struct u_rect
*dst
)
289 static inline struct pipe_box
290 RectToPipeBox(const VdpRect
*rect
, struct pipe_resource
*res
)
297 box
.width
= res
->width0
;
298 box
.height
= res
->height0
;
302 box
.x
= MIN2(rect
->x0
, rect
->x1
);
303 box
.y
= MIN2(rect
->y0
, rect
->y1
);
304 box
.width
= abs(rect
->x1
- rect
->x0
);
305 box
.height
= abs(rect
->y1
- rect
->y0
);
313 struct vl_screen
*vscreen
;
314 struct pipe_context
*context
;
315 struct vl_compositor compositor
;
319 struct vl_compositor_state
*cstate
;
320 VdpOutputSurface surface
;
328 } vlVdpPresentationQueueTarget
;
334 struct vl_compositor_state cstate
;
335 } vlVdpPresentationQueue
;
340 struct vl_compositor_state cstate
;
343 bool supported
, enabled
;
345 struct vl_median_filter
*filter
;
349 bool supported
, enabled
;
351 struct vl_matrix_filter
*filter
;
354 unsigned video_width
, video_height
;
355 enum pipe_video_chroma_format chroma_format
;
356 unsigned max_layers
, skip_chroma_deint
;
357 float luma_key_min
, luma_key_max
;
366 struct pipe_video_buffer templat
, *video_buffer
;
372 struct pipe_sampler_view
*sampler_view
;
373 } vlVdpBitmapSurface
;
375 typedef uint64_t vlVdpTime
;
381 struct pipe_surface
*surface
;
382 struct pipe_sampler_view
*sampler_view
;
383 struct pipe_fence_handle
*fence
;
384 struct vl_compositor_state cstate
;
385 struct u_rect dirty_area
;
386 } vlVdpOutputSurface
;
391 struct pipe_video_decoder
*decoder
;
394 typedef uint32_t vlHandle
;
396 boolean
vlCreateHTAB(void);
397 void vlDestroyHTAB(void);
398 vlHandle
vlAddDataHTAB(void *data
);
399 void* vlGetDataHTAB(vlHandle handle
);
400 void vlRemoveDataHTAB(vlHandle handle
);
402 boolean
vlGetFuncFTAB(VdpFuncId function_id
, void **func
);
404 /* Public functions */
405 VdpDeviceCreateX11 vdp_imp_device_create_x11
;
406 VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11
;
408 void vlVdpDefaultSamplerViewTemplate(struct pipe_sampler_view
*templ
, struct pipe_resource
*res
);
410 /* Delayed rendering funtionality */
411 void vlVdpResolveDelayedRendering(vlVdpDevice
*dev
, struct pipe_surface
*surface
, struct u_rect
*dirty_area
);
412 void vlVdpSave4DelayedRendering(vlVdpDevice
*dev
, VdpOutputSurface surface
, struct vl_compositor_state
*cstate
);
414 /* Internal function pointers */
415 VdpGetErrorString vlVdpGetErrorString
;
416 VdpDeviceDestroy vlVdpDeviceDestroy
;
417 VdpGetProcAddress vlVdpGetProcAddress
;
418 VdpGetApiVersion vlVdpGetApiVersion
;
419 VdpGetInformationString vlVdpGetInformationString
;
420 VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities
;
421 VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities
;
422 VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities
;
423 VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities
;
424 VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities
;
425 VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities
;
426 VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities
;
427 VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities
;
428 VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport
;
429 VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport
;
430 VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange
;
431 VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport
;
432 VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange
;
433 VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate
;
434 VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy
;
435 VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters
;
436 VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr
;
437 VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr
;
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 */