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"
40 #include "state_tracker/vdpau_dmabuf.h"
41 #include "state_tracker/vdpau_funcs.h"
43 #include "util/u_debug.h"
44 #include "util/u_rect.h"
45 #include "os/os_thread.h"
47 #include "vl/vl_video_buffer.h"
48 #include "vl/vl_bicubic_filter.h"
49 #include "vl/vl_compositor.h"
50 #include "vl/vl_csc.h"
51 #include "vl/vl_deint_filter.h"
52 #include "vl/vl_matrix_filter.h"
53 #include "vl/vl_median_filter.h"
54 #include "vl/vl_winsys.h"
56 /* Full VDPAU API documentation available at :
57 * ftp://download.nvidia.com/XFree86/vdpau/doxygen/html/index.html */
59 #define INFORMATION G3DVL VDPAU Driver Shared Library version VER_MAJOR.VER_MINOR
61 #define TOSTRING(x) QUOTEME(x)
62 #define INFORMATION_STRING TOSTRING(INFORMATION)
64 static inline enum pipe_video_chroma_format
65 ChromaToPipe(VdpChromaType vdpau_type
)
68 case VDP_CHROMA_TYPE_420
:
69 return PIPE_VIDEO_CHROMA_FORMAT_420
;
70 case VDP_CHROMA_TYPE_422
:
71 return PIPE_VIDEO_CHROMA_FORMAT_422
;
72 case VDP_CHROMA_TYPE_444
:
73 return PIPE_VIDEO_CHROMA_FORMAT_444
;
81 static inline VdpChromaType
82 PipeToChroma(enum pipe_video_chroma_format pipe_type
)
85 case PIPE_VIDEO_CHROMA_FORMAT_420
:
86 return VDP_CHROMA_TYPE_420
;
87 case PIPE_VIDEO_CHROMA_FORMAT_422
:
88 return VDP_CHROMA_TYPE_422
;
89 case PIPE_VIDEO_CHROMA_FORMAT_444
:
90 return VDP_CHROMA_TYPE_444
;
98 static inline enum pipe_video_chroma_format
99 FormatYCBCRToPipeChroma(VdpYCbCrFormat vdpau_format
)
101 switch (vdpau_format
) {
102 case VDP_YCBCR_FORMAT_NV12
:
103 return PIPE_VIDEO_CHROMA_FORMAT_420
;
104 case VDP_YCBCR_FORMAT_YV12
:
105 return PIPE_VIDEO_CHROMA_FORMAT_420
;
106 case VDP_YCBCR_FORMAT_UYVY
:
107 return PIPE_VIDEO_CHROMA_FORMAT_422
;
108 case VDP_YCBCR_FORMAT_YUYV
:
109 return PIPE_VIDEO_CHROMA_FORMAT_422
;
110 case VDP_YCBCR_FORMAT_Y8U8V8A8
:
111 return PIPE_VIDEO_CHROMA_FORMAT_444
;
112 case VDP_YCBCR_FORMAT_V8U8Y8A8
:
113 return PIPE_VIDEO_CHROMA_FORMAT_444
;
118 return PIPE_FORMAT_NONE
;
121 static inline enum pipe_format
122 FormatYCBCRToPipe(VdpYCbCrFormat vdpau_format
)
124 switch (vdpau_format
) {
125 case VDP_YCBCR_FORMAT_NV12
:
126 return PIPE_FORMAT_NV12
;
127 case VDP_YCBCR_FORMAT_YV12
:
128 return PIPE_FORMAT_YV12
;
129 case VDP_YCBCR_FORMAT_UYVY
:
130 return PIPE_FORMAT_UYVY
;
131 case VDP_YCBCR_FORMAT_YUYV
:
132 return PIPE_FORMAT_YUYV
;
133 case VDP_YCBCR_FORMAT_Y8U8V8A8
:
134 return PIPE_FORMAT_R8G8B8A8_UNORM
;
135 case VDP_YCBCR_FORMAT_V8U8Y8A8
:
136 return PIPE_FORMAT_B8G8R8A8_UNORM
;
141 return PIPE_FORMAT_NONE
;
144 static inline VdpYCbCrFormat
145 PipeToFormatYCBCR(enum pipe_format p_format
)
148 case PIPE_FORMAT_NV12
:
149 return VDP_YCBCR_FORMAT_NV12
;
150 case PIPE_FORMAT_YV12
:
151 return VDP_YCBCR_FORMAT_YV12
;
152 case PIPE_FORMAT_UYVY
:
153 return VDP_YCBCR_FORMAT_UYVY
;
154 case PIPE_FORMAT_YUYV
:
155 return VDP_YCBCR_FORMAT_YUYV
;
156 case PIPE_FORMAT_R8G8B8A8_UNORM
:
157 return VDP_YCBCR_FORMAT_Y8U8V8A8
;
158 case PIPE_FORMAT_B8G8R8A8_UNORM
:
159 return VDP_YCBCR_FORMAT_V8U8Y8A8
;
167 static inline VdpRGBAFormat
168 PipeToFormatRGBA(enum pipe_format p_format
)
171 case PIPE_FORMAT_A8_UNORM
:
172 return VDP_RGBA_FORMAT_A8
;
173 case PIPE_FORMAT_B10G10R10A2_UNORM
:
174 return VDP_RGBA_FORMAT_B10G10R10A2
;
175 case PIPE_FORMAT_B8G8R8A8_UNORM
:
176 return VDP_RGBA_FORMAT_B8G8R8A8
;
177 case PIPE_FORMAT_R10G10B10A2_UNORM
:
178 return VDP_RGBA_FORMAT_R10G10B10A2
;
179 case PIPE_FORMAT_R8G8B8A8_UNORM
:
180 return VDP_RGBA_FORMAT_R8G8B8A8
;
188 static inline enum pipe_format
189 FormatIndexedToPipe(VdpRGBAFormat vdpau_format
)
191 switch (vdpau_format
) {
192 case VDP_INDEXED_FORMAT_A4I4
:
193 return PIPE_FORMAT_R4A4_UNORM
;
194 case VDP_INDEXED_FORMAT_I4A4
:
195 return PIPE_FORMAT_A4R4_UNORM
;
196 case VDP_INDEXED_FORMAT_A8I8
:
197 return PIPE_FORMAT_A8R8_UNORM
;
198 case VDP_INDEXED_FORMAT_I8A8
:
199 return PIPE_FORMAT_R8A8_UNORM
;
204 return PIPE_FORMAT_NONE
;
207 static inline enum pipe_format
208 FormatColorTableToPipe(VdpColorTableFormat vdpau_format
)
210 switch(vdpau_format
) {
211 case VDP_COLOR_TABLE_FORMAT_B8G8R8X8
:
212 return PIPE_FORMAT_B8G8R8X8_UNORM
;
217 return PIPE_FORMAT_NONE
;
220 static inline enum pipe_video_profile
221 ProfileToPipe(VdpDecoderProfile vdpau_profile
)
223 switch (vdpau_profile
) {
224 case VDP_DECODER_PROFILE_MPEG1
:
225 return PIPE_VIDEO_PROFILE_MPEG1
;
226 case VDP_DECODER_PROFILE_MPEG2_SIMPLE
:
227 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
;
228 case VDP_DECODER_PROFILE_MPEG2_MAIN
:
229 return PIPE_VIDEO_PROFILE_MPEG2_MAIN
;
230 case VDP_DECODER_PROFILE_H264_BASELINE
:
231 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
;
232 case VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE
:
233 return PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE
;
234 case VDP_DECODER_PROFILE_H264_MAIN
:
235 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
;
236 case VDP_DECODER_PROFILE_H264_HIGH
:
237 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
;
238 case VDP_DECODER_PROFILE_MPEG4_PART2_SP
:
239 return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
;
240 case VDP_DECODER_PROFILE_MPEG4_PART2_ASP
:
241 return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
;
242 case VDP_DECODER_PROFILE_VC1_SIMPLE
:
243 return PIPE_VIDEO_PROFILE_VC1_SIMPLE
;
244 case VDP_DECODER_PROFILE_VC1_MAIN
:
245 return PIPE_VIDEO_PROFILE_VC1_MAIN
;
246 case VDP_DECODER_PROFILE_VC1_ADVANCED
:
247 return PIPE_VIDEO_PROFILE_VC1_ADVANCED
;
248 case VDP_DECODER_PROFILE_HEVC_MAIN
:
249 return PIPE_VIDEO_PROFILE_HEVC_MAIN
;
250 case VDP_DECODER_PROFILE_HEVC_MAIN_10
:
251 return PIPE_VIDEO_PROFILE_HEVC_MAIN_10
;
252 case VDP_DECODER_PROFILE_HEVC_MAIN_STILL
:
253 return PIPE_VIDEO_PROFILE_HEVC_MAIN_STILL
;
254 case VDP_DECODER_PROFILE_HEVC_MAIN_12
:
255 return PIPE_VIDEO_PROFILE_HEVC_MAIN_12
;
256 case VDP_DECODER_PROFILE_HEVC_MAIN_444
:
257 return PIPE_VIDEO_PROFILE_HEVC_MAIN_444
;
259 return PIPE_VIDEO_PROFILE_UNKNOWN
;
263 static inline VdpDecoderProfile
264 PipeToProfile(enum pipe_video_profile p_profile
)
267 case PIPE_VIDEO_PROFILE_MPEG1
:
268 return VDP_DECODER_PROFILE_MPEG1
;
269 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE
:
270 return VDP_DECODER_PROFILE_MPEG2_SIMPLE
;
271 case PIPE_VIDEO_PROFILE_MPEG2_MAIN
:
272 return VDP_DECODER_PROFILE_MPEG2_MAIN
;
273 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
:
274 return VDP_DECODER_PROFILE_H264_BASELINE
;
275 case PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE
:
276 return VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE
;
277 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
:
278 return VDP_DECODER_PROFILE_H264_MAIN
;
279 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
:
280 return VDP_DECODER_PROFILE_H264_HIGH
;
281 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE
:
282 return VDP_DECODER_PROFILE_MPEG4_PART2_SP
;
283 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE
:
284 return VDP_DECODER_PROFILE_MPEG4_PART2_ASP
;
285 case PIPE_VIDEO_PROFILE_VC1_SIMPLE
:
286 return VDP_DECODER_PROFILE_VC1_SIMPLE
;
287 case PIPE_VIDEO_PROFILE_VC1_MAIN
:
288 return VDP_DECODER_PROFILE_VC1_MAIN
;
289 case PIPE_VIDEO_PROFILE_VC1_ADVANCED
:
290 return VDP_DECODER_PROFILE_VC1_ADVANCED
;
291 case PIPE_VIDEO_PROFILE_HEVC_MAIN
:
292 return VDP_DECODER_PROFILE_HEVC_MAIN
;
293 case PIPE_VIDEO_PROFILE_HEVC_MAIN_10
:
294 return VDP_DECODER_PROFILE_HEVC_MAIN_10
;
295 case PIPE_VIDEO_PROFILE_HEVC_MAIN_STILL
:
296 return VDP_DECODER_PROFILE_HEVC_MAIN_STILL
;
297 case PIPE_VIDEO_PROFILE_HEVC_MAIN_12
:
298 return VDP_DECODER_PROFILE_HEVC_MAIN_12
;
299 case PIPE_VIDEO_PROFILE_HEVC_MAIN_444
:
300 return VDP_DECODER_PROFILE_HEVC_MAIN_444
;
307 static inline struct u_rect
*
308 RectToPipe(const VdpRect
*src
, struct u_rect
*dst
)
320 static inline struct pipe_box
321 RectToPipeBox(const VdpRect
*rect
, struct pipe_resource
*res
)
328 box
.width
= res
->width0
;
329 box
.height
= res
->height0
;
333 box
.x
= MIN2(rect
->x0
, rect
->x1
);
334 box
.y
= MIN2(rect
->y0
, rect
->y1
);
335 box
.width
= abs(rect
->x1
- rect
->x0
);
336 box
.height
= abs(rect
->y1
- rect
->y0
);
343 CheckSurfaceParams(struct pipe_screen
*screen
,
344 const struct pipe_resource
*templ
)
346 return screen
->is_format_supported(screen
, templ
->format
, templ
->target
,
348 templ
->nr_storage_samples
, templ
->bind
);
353 struct pipe_reference reference
;
354 struct vl_screen
*vscreen
;
355 struct pipe_context
*context
;
356 struct vl_compositor compositor
;
357 struct pipe_sampler_view
*dummy_sv
;
364 struct vl_compositor_state cstate
;
367 bool supported
, enabled
;
368 float luma_min
, luma_max
;
372 bool supported
, enabled
, spatial
;
373 struct vl_deint_filter
*filter
;
377 bool supported
, enabled
;
378 struct vl_bicubic_filter
*filter
;
382 bool supported
, enabled
;
384 struct vl_median_filter
*filter
;
388 bool supported
, enabled
;
390 struct vl_matrix_filter
*filter
;
393 unsigned video_width
, video_height
;
394 enum pipe_video_chroma_format chroma_format
;
395 unsigned max_layers
, skip_chroma_deint
;
404 struct pipe_video_buffer templat
, *video_buffer
;
410 struct pipe_sampler_view
*sampler_view
;
411 } vlVdpBitmapSurface
;
413 typedef uint64_t vlVdpTime
;
418 struct pipe_surface
*surface
;
419 struct pipe_sampler_view
*sampler_view
;
420 struct pipe_fence_handle
*fence
;
421 struct vl_compositor_state cstate
;
422 struct u_rect dirty_area
;
424 } vlVdpOutputSurface
;
430 } vlVdpPresentationQueueTarget
;
436 struct vl_compositor_state cstate
;
437 vlVdpOutputSurface
*last_surf
;
438 } vlVdpPresentationQueue
;
444 struct pipe_video_codec
*decoder
;
447 typedef uint32_t vlHandle
;
449 boolean
vlCreateHTAB(void);
450 void vlDestroyHTAB(void);
451 vlHandle
vlAddDataHTAB(void *data
);
452 void* vlGetDataHTAB(vlHandle handle
);
453 void vlRemoveDataHTAB(vlHandle handle
);
455 boolean
vlGetFuncFTAB(VdpFuncId function_id
, void **func
);
457 /* Public functions */
458 VdpDeviceCreateX11 vdp_imp_device_create_x11
;
460 void vlVdpDefaultSamplerViewTemplate(struct pipe_sampler_view
*templ
, struct pipe_resource
*res
);
462 /* Internal function pointers */
463 VdpGetErrorString vlVdpGetErrorString
;
464 VdpDeviceDestroy vlVdpDeviceDestroy
;
465 void vlVdpDeviceFree(vlVdpDevice
*dev
);
466 VdpGetProcAddress vlVdpGetProcAddress
;
467 VdpGetApiVersion vlVdpGetApiVersion
;
468 VdpGetInformationString vlVdpGetInformationString
;
469 VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities
;
470 VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities
;
471 VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities
;
472 VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities
;
473 VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities
;
474 VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities
;
475 VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities
;
476 VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities
;
477 VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport
;
478 VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport
;
479 VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange
;
480 VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport
;
481 VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange
;
482 VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate
;
483 VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy
;
484 VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters
;
485 VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr
;
486 VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr
;
487 void vlVdpVideoSurfaceClear(vlVdpSurface
*vlsurf
);
488 VdpDecoderCreate vlVdpDecoderCreate
;
489 VdpDecoderDestroy vlVdpDecoderDestroy
;
490 VdpDecoderGetParameters vlVdpDecoderGetParameters
;
491 VdpDecoderRender vlVdpDecoderRender
;
492 VdpOutputSurfaceCreate vlVdpOutputSurfaceCreate
;
493 VdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy
;
494 VdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters
;
495 VdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative
;
496 VdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative
;
497 VdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed
;
498 VdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr
;
499 VdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface
;
500 VdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface
;
501 VdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate
;
502 VdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy
;
503 VdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters
;
504 VdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative
;
505 VdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy
;
506 VdpPresentationQueueCreate vlVdpPresentationQueueCreate
;
507 VdpPresentationQueueDestroy vlVdpPresentationQueueDestroy
;
508 VdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor
;
509 VdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor
;
510 VdpPresentationQueueGetTime vlVdpPresentationQueueGetTime
;
511 VdpPresentationQueueDisplay vlVdpPresentationQueueDisplay
;
512 VdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle
;
513 VdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus
;
514 VdpPreemptionCallback vlVdpPreemptionCallback
;
515 VdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister
;
516 VdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables
;
517 VdpVideoMixerCreate vlVdpVideoMixerCreate
;
518 VdpVideoMixerRender vlVdpVideoMixerRender
;
519 VdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues
;
520 VdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport
;
521 VdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables
;
522 VdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues
;
523 VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues
;
524 VdpVideoMixerDestroy vlVdpVideoMixerDestroy
;
525 VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix
;
526 /* Winsys specific internal function pointers */
527 VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11
;
530 /* interop to mesa state tracker */
531 VdpVideoSurfaceGallium vlVdpVideoSurfaceGallium
;
532 VdpOutputSurfaceGallium vlVdpOutputSurfaceGallium
;
533 VdpVideoSurfaceDMABuf vlVdpVideoSurfaceDMABuf
;
534 VdpOutputSurfaceDMABuf vlVdpOutputSurfaceDMABuf
;
539 #define VDPAU_TRACE 3
541 static inline void VDPAU_MSG(unsigned int level
, const char *fmt
, ...)
543 static int debug_level
= -1;
545 if (debug_level
== -1) {
546 debug_level
= MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0);
549 if (level
<= debug_level
) {
552 _debug_vprintf(fmt
, ap
);
558 DeviceReference(vlVdpDevice
**ptr
, vlVdpDevice
*dev
)
560 vlVdpDevice
*old_dev
= *ptr
;
562 if (pipe_reference(&(*ptr
)->reference
, &dev
->reference
))
563 vlVdpDeviceFree(old_dev
);
567 #endif /* VDPAU_PRIVATE_H */