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 VMWARE 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_codec.h"
39 #include "state_tracker/vdpau_interop.h"
41 #include "util/u_debug.h"
42 #include "util/u_rect.h"
43 #include "os/os_thread.h"
45 #include "vl/vl_video_buffer.h"
46 #include "vl/vl_compositor.h"
47 #include "vl/vl_csc.h"
48 #include "vl/vl_deint_filter.h"
49 #include "vl/vl_matrix_filter.h"
50 #include "vl/vl_median_filter.h"
51 #include "vl/vl_winsys.h"
53 /* Full VDPAU API documentation available at :
54 * ftp://download.nvidia.com/XFree86/vdpau/doxygen/html/index.html */
56 #define INFORMATION G3DVL VDPAU Driver Shared Library version VER_MAJOR.VER_MINOR
58 #define TOSTRING(x) QUOTEME(x)
59 #define INFORMATION_STRING TOSTRING(INFORMATION)
61 static inline enum pipe_video_chroma_format
62 ChromaToPipe(VdpChromaType vdpau_type
)
65 case VDP_CHROMA_TYPE_420
:
66 return PIPE_VIDEO_CHROMA_FORMAT_420
;
67 case VDP_CHROMA_TYPE_422
:
68 return PIPE_VIDEO_CHROMA_FORMAT_422
;
69 case VDP_CHROMA_TYPE_444
:
70 return PIPE_VIDEO_CHROMA_FORMAT_444
;
78 static inline VdpChromaType
79 PipeToChroma(enum pipe_video_chroma_format pipe_type
)
82 case PIPE_VIDEO_CHROMA_FORMAT_420
:
83 return VDP_CHROMA_TYPE_420
;
84 case PIPE_VIDEO_CHROMA_FORMAT_422
:
85 return VDP_CHROMA_TYPE_422
;
86 case PIPE_VIDEO_CHROMA_FORMAT_444
:
87 return VDP_CHROMA_TYPE_444
;
95 static inline enum pipe_video_chroma_format
96 FormatYCBCRToPipeChroma(VdpYCbCrFormat vdpau_format
)
98 switch (vdpau_format
) {
99 case VDP_YCBCR_FORMAT_NV12
:
100 return PIPE_VIDEO_CHROMA_FORMAT_420
;
101 case VDP_YCBCR_FORMAT_YV12
:
102 return PIPE_VIDEO_CHROMA_FORMAT_420
;
103 case VDP_YCBCR_FORMAT_UYVY
:
104 return PIPE_VIDEO_CHROMA_FORMAT_422
;
105 case VDP_YCBCR_FORMAT_YUYV
:
106 return PIPE_VIDEO_CHROMA_FORMAT_422
;
107 case VDP_YCBCR_FORMAT_Y8U8V8A8
:
108 return PIPE_VIDEO_CHROMA_FORMAT_444
;
109 case VDP_YCBCR_FORMAT_V8U8Y8A8
:
110 return PIPE_VIDEO_CHROMA_FORMAT_444
;
115 return PIPE_FORMAT_NONE
;
118 static inline enum pipe_format
119 FormatYCBCRToPipe(VdpYCbCrFormat vdpau_format
)
121 switch (vdpau_format
) {
122 case VDP_YCBCR_FORMAT_NV12
:
123 return PIPE_FORMAT_NV12
;
124 case VDP_YCBCR_FORMAT_YV12
:
125 return PIPE_FORMAT_YV12
;
126 case VDP_YCBCR_FORMAT_UYVY
:
127 return PIPE_FORMAT_UYVY
;
128 case VDP_YCBCR_FORMAT_YUYV
:
129 return PIPE_FORMAT_YUYV
;
130 case VDP_YCBCR_FORMAT_Y8U8V8A8
:
131 return PIPE_FORMAT_R8G8B8A8_UNORM
;
132 case VDP_YCBCR_FORMAT_V8U8Y8A8
:
133 return PIPE_FORMAT_B8G8R8A8_UNORM
;
138 return PIPE_FORMAT_NONE
;
141 static inline VdpYCbCrFormat
142 PipeToFormatYCBCR(enum pipe_format p_format
)
145 case PIPE_FORMAT_NV12
:
146 return VDP_YCBCR_FORMAT_NV12
;
147 case PIPE_FORMAT_YV12
:
148 return VDP_YCBCR_FORMAT_YV12
;
149 case PIPE_FORMAT_UYVY
:
150 return VDP_YCBCR_FORMAT_UYVY
;
151 case PIPE_FORMAT_YUYV
:
152 return VDP_YCBCR_FORMAT_YUYV
;
153 case PIPE_FORMAT_R8G8B8A8_UNORM
:
154 return VDP_YCBCR_FORMAT_Y8U8V8A8
;
155 case PIPE_FORMAT_B8G8R8A8_UNORM
:
156 return VDP_YCBCR_FORMAT_V8U8Y8A8
;
164 static inline enum pipe_format
165 FormatRGBAToPipe(VdpRGBAFormat vdpau_format
)
167 switch (vdpau_format
) {
168 case VDP_RGBA_FORMAT_A8
:
169 return PIPE_FORMAT_A8_UNORM
;
170 case VDP_RGBA_FORMAT_B10G10R10A2
:
171 return PIPE_FORMAT_B10G10R10A2_UNORM
;
172 case VDP_RGBA_FORMAT_B8G8R8A8
:
173 return PIPE_FORMAT_B8G8R8A8_UNORM
;
174 case VDP_RGBA_FORMAT_R10G10B10A2
:
175 return PIPE_FORMAT_R10G10B10A2_UNORM
;
176 case VDP_RGBA_FORMAT_R8G8B8A8
:
177 return PIPE_FORMAT_R8G8B8A8_UNORM
;
182 return PIPE_FORMAT_NONE
;
185 static inline VdpRGBAFormat
186 PipeToFormatRGBA(enum pipe_format p_format
)
189 case PIPE_FORMAT_A8_UNORM
:
190 return VDP_RGBA_FORMAT_A8
;
191 case PIPE_FORMAT_B10G10R10A2_UNORM
:
192 return VDP_RGBA_FORMAT_B10G10R10A2
;
193 case PIPE_FORMAT_B8G8R8A8_UNORM
:
194 return VDP_RGBA_FORMAT_B8G8R8A8
;
195 case PIPE_FORMAT_R10G10B10A2_UNORM
:
196 return VDP_RGBA_FORMAT_R10G10B10A2
;
197 case PIPE_FORMAT_R8G8B8A8_UNORM
:
198 return VDP_RGBA_FORMAT_R8G8B8A8
;
206 static inline enum pipe_format
207 FormatIndexedToPipe(VdpRGBAFormat vdpau_format
)
209 switch (vdpau_format
) {
210 case VDP_INDEXED_FORMAT_A4I4
:
211 return PIPE_FORMAT_R4A4_UNORM
;
212 case VDP_INDEXED_FORMAT_I4A4
:
213 return PIPE_FORMAT_A4R4_UNORM
;
214 case VDP_INDEXED_FORMAT_A8I8
:
215 return PIPE_FORMAT_A8R8_UNORM
;
216 case VDP_INDEXED_FORMAT_I8A8
:
217 return PIPE_FORMAT_R8A8_UNORM
;
222 return PIPE_FORMAT_NONE
;
225 static inline enum pipe_format
226 FormatColorTableToPipe(VdpColorTableFormat vdpau_format
)
228 switch(vdpau_format
) {
229 case VDP_COLOR_TABLE_FORMAT_B8G8R8X8
:
230 return PIPE_FORMAT_B8G8R8X8_UNORM
;
235 return PIPE_FORMAT_NONE
;
238 static inline enum pipe_video_profile
239 ProfileToPipe(VdpDecoderProfile vdpau_profile
)
241 switch (vdpau_profile
) {
242 case VDP_DECODER_PROFILE_MPEG1
:
243 return PIPE_VIDEO_PROFILE_MPEG1
;
244 case VDP_DECODER_PROFILE_MPEG2_SIMPLE
:
245 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
;
246 case VDP_DECODER_PROFILE_MPEG2_MAIN
:
247 return PIPE_VIDEO_PROFILE_MPEG2_MAIN
;
248 case VDP_DECODER_PROFILE_H264_BASELINE
:
249 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
;
250 case VDP_DECODER_PROFILE_H264_MAIN
:
251 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
;
252 case VDP_DECODER_PROFILE_H264_HIGH
:
253 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
;
254 case VDP_DECODER_PROFILE_MPEG4_PART2_SP
:
255 return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
;
256 case VDP_DECODER_PROFILE_MPEG4_PART2_ASP
:
257 return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
;
258 case VDP_DECODER_PROFILE_VC1_SIMPLE
:
259 return PIPE_VIDEO_PROFILE_VC1_SIMPLE
;
260 case VDP_DECODER_PROFILE_VC1_MAIN
:
261 return PIPE_VIDEO_PROFILE_VC1_MAIN
;
262 case VDP_DECODER_PROFILE_VC1_ADVANCED
:
263 return PIPE_VIDEO_PROFILE_VC1_ADVANCED
;
265 return PIPE_VIDEO_PROFILE_UNKNOWN
;
269 static inline VdpDecoderProfile
270 PipeToProfile(enum pipe_video_profile p_profile
)
273 case PIPE_VIDEO_PROFILE_MPEG1
:
274 return VDP_DECODER_PROFILE_MPEG1
;
275 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
:
276 return VDP_DECODER_PROFILE_MPEG2_SIMPLE
;
277 case PIPE_VIDEO_PROFILE_MPEG2_MAIN
:
278 return VDP_DECODER_PROFILE_MPEG2_MAIN
;
279 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
:
280 return VDP_DECODER_PROFILE_H264_BASELINE
;
281 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
:
282 return VDP_DECODER_PROFILE_H264_MAIN
;
283 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
:
284 return VDP_DECODER_PROFILE_H264_HIGH
;
285 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
:
286 return VDP_DECODER_PROFILE_MPEG4_PART2_SP
;
287 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
:
288 return VDP_DECODER_PROFILE_MPEG4_PART2_ASP
;
289 case PIPE_VIDEO_PROFILE_VC1_SIMPLE
:
290 return VDP_DECODER_PROFILE_VC1_SIMPLE
;
291 case PIPE_VIDEO_PROFILE_VC1_MAIN
:
292 return VDP_DECODER_PROFILE_VC1_MAIN
;
293 case PIPE_VIDEO_PROFILE_VC1_ADVANCED
:
294 return VDP_DECODER_PROFILE_VC1_ADVANCED
;
301 static inline struct u_rect
*
302 RectToPipe(const VdpRect
*src
, struct u_rect
*dst
)
314 static inline struct pipe_box
315 RectToPipeBox(const VdpRect
*rect
, struct pipe_resource
*res
)
322 box
.width
= res
->width0
;
323 box
.height
= res
->height0
;
327 box
.x
= MIN2(rect
->x0
, rect
->x1
);
328 box
.y
= MIN2(rect
->y0
, rect
->y1
);
329 box
.width
= abs(rect
->x1
- rect
->x0
);
330 box
.height
= abs(rect
->y1
- rect
->y0
);
337 CheckSurfaceParams(struct pipe_screen
*screen
,
338 const struct pipe_resource
*templ
)
340 return screen
->is_format_supported(
341 screen
, templ
->format
, templ
->target
, templ
->nr_samples
, templ
->bind
);
346 struct pipe_reference reference
;
347 struct vl_screen
*vscreen
;
348 struct pipe_context
*context
;
349 struct vl_compositor compositor
;
350 struct pipe_sampler_view
*dummy_sv
;
354 struct vl_compositor_state
*cstate
;
355 VdpOutputSurface surface
;
362 struct vl_compositor_state cstate
;
365 bool supported
, enabled
, spatial
;
366 struct vl_deint_filter
*filter
;
370 bool supported
, enabled
;
372 struct vl_median_filter
*filter
;
376 bool supported
, enabled
;
378 struct vl_matrix_filter
*filter
;
381 unsigned video_width
, video_height
;
382 enum pipe_video_chroma_format chroma_format
;
383 unsigned max_layers
, skip_chroma_deint
;
384 float luma_key_min
, luma_key_max
;
393 struct pipe_video_buffer templat
, *video_buffer
;
399 struct pipe_sampler_view
*sampler_view
;
400 } vlVdpBitmapSurface
;
402 typedef uint64_t vlVdpTime
;
407 struct pipe_surface
*surface
;
408 struct pipe_sampler_view
*sampler_view
;
409 struct pipe_fence_handle
*fence
;
410 struct vl_compositor_state cstate
;
411 struct u_rect dirty_area
;
412 } vlVdpOutputSurface
;
418 } vlVdpPresentationQueueTarget
;
424 struct vl_compositor_state cstate
;
425 vlVdpOutputSurface
*last_surf
;
426 } vlVdpPresentationQueue
;
432 struct pipe_video_codec
*decoder
;
435 typedef uint32_t vlHandle
;
437 boolean
vlCreateHTAB(void);
438 void vlDestroyHTAB(void);
439 vlHandle
vlAddDataHTAB(void *data
);
440 void* vlGetDataHTAB(vlHandle handle
);
441 void vlRemoveDataHTAB(vlHandle handle
);
443 boolean
vlGetFuncFTAB(VdpFuncId function_id
, void **func
);
445 /* Public functions */
446 VdpDeviceCreateX11 vdp_imp_device_create_x11
;
448 void vlVdpDefaultSamplerViewTemplate(struct pipe_sampler_view
*templ
, struct pipe_resource
*res
);
450 /* Delayed rendering funtionality */
451 void vlVdpResolveDelayedRendering(vlVdpDevice
*dev
, struct pipe_surface
*surface
, struct u_rect
*dirty_area
);
452 void vlVdpSave4DelayedRendering(vlVdpDevice
*dev
, VdpOutputSurface surface
, struct vl_compositor_state
*cstate
);
454 /* Internal function pointers */
455 VdpGetErrorString vlVdpGetErrorString
;
456 VdpDeviceDestroy vlVdpDeviceDestroy
;
457 void vlVdpDeviceFree(vlVdpDevice
*dev
);
458 VdpGetProcAddress vlVdpGetProcAddress
;
459 VdpGetApiVersion vlVdpGetApiVersion
;
460 VdpGetInformationString vlVdpGetInformationString
;
461 VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities
;
462 VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities
;
463 VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities
;
464 VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities
;
465 VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities
;
466 VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities
;
467 VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities
;
468 VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities
;
469 VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport
;
470 VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport
;
471 VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange
;
472 VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport
;
473 VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange
;
474 VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate
;
475 VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy
;
476 VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters
;
477 VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr
;
478 VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr
;
479 void vlVdpVideoSurfaceClear(vlVdpSurface
*vlsurf
);
480 VdpDecoderCreate vlVdpDecoderCreate
;
481 VdpDecoderDestroy vlVdpDecoderDestroy
;
482 VdpDecoderGetParameters vlVdpDecoderGetParameters
;
483 VdpDecoderRender vlVdpDecoderRender
;
484 VdpOutputSurfaceCreate vlVdpOutputSurfaceCreate
;
485 VdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy
;
486 VdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters
;
487 VdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative
;
488 VdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative
;
489 VdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed
;
490 VdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr
;
491 VdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface
;
492 VdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface
;
493 VdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate
;
494 VdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy
;
495 VdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters
;
496 VdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative
;
497 VdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy
;
498 VdpPresentationQueueCreate vlVdpPresentationQueueCreate
;
499 VdpPresentationQueueDestroy vlVdpPresentationQueueDestroy
;
500 VdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor
;
501 VdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor
;
502 VdpPresentationQueueGetTime vlVdpPresentationQueueGetTime
;
503 VdpPresentationQueueDisplay vlVdpPresentationQueueDisplay
;
504 VdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle
;
505 VdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus
;
506 VdpPreemptionCallback vlVdpPreemptionCallback
;
507 VdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister
;
508 VdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables
;
509 VdpVideoMixerCreate vlVdpVideoMixerCreate
;
510 VdpVideoMixerRender vlVdpVideoMixerRender
;
511 VdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues
;
512 VdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport
;
513 VdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables
;
514 VdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues
;
515 VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues
;
516 VdpVideoMixerDestroy vlVdpVideoMixerDestroy
;
517 VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix
;
518 /* Winsys specific internal function pointers */
519 VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11
;
522 /* interop to mesa state tracker */
523 VdpVideoSurfaceGallium vlVdpVideoSurfaceGallium
;
524 VdpOutputSurfaceGallium vlVdpOutputSurfaceGallium
;
529 #define VDPAU_TRACE 3
531 static inline void VDPAU_MSG(unsigned int level
, const char *fmt
, ...)
533 static int debug_level
= -1;
535 if (debug_level
== -1) {
536 debug_level
= MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0);
539 if (level
<= debug_level
) {
542 _debug_vprintf(fmt
, ap
);
548 DeviceReference(vlVdpDevice
**ptr
, vlVdpDevice
*dev
)
550 vlVdpDevice
*old_dev
= *ptr
;
552 if (pipe_reference(&(*ptr
)->reference
, &dev
->reference
))
553 vlVdpDeviceFree(old_dev
);
557 #endif /* VDPAU_PRIVATE_H */