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 "frontend/vdpau_interop.h"
40
#include "frontend/vdpau_dmabuf.h"
41
#include "frontend/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_VIDEO_CHROMA_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;
137
#ifdef VDP_YCBCR_FORMAT_P010
138
case VDP_YCBCR_FORMAT_P010:
139
return PIPE_FORMAT_P010;
141
#ifdef VDP_YCBCR_FORMAT_P016
142
case VDP_YCBCR_FORMAT_P016:
143
return PIPE_FORMAT_P016;
146
/* NOTE: Can't be "unreachable", as it's quite reachable. */
147
debug_assert(!"unexpected VdpYCbCrFormat");
148
#if defined(NDEBUG) || defined(DEBUG)
151
#ifdef VDP_YCBCR_FORMAT_Y_UV_444
152
case VDP_YCBCR_FORMAT_Y_UV_444:
154
#ifdef VDP_YCBCR_FORMAT_Y_U_V_444
155
case VDP_YCBCR_FORMAT_Y_U_V_444:
157
#ifdef VDP_YCBCR_FORMAT_Y_U_V_444_16
158
case VDP_YCBCR_FORMAT_Y_U_V_444_16:
160
return PIPE_FORMAT_NONE;
165
static inline VdpYCbCrFormat
166
PipeToFormatYCBCR(enum pipe_format p_format)
169
case PIPE_FORMAT_NV12:
170
return VDP_YCBCR_FORMAT_NV12;
171
case PIPE_FORMAT_YV12:
172
return VDP_YCBCR_FORMAT_YV12;
173
case PIPE_FORMAT_UYVY:
174
return VDP_YCBCR_FORMAT_UYVY;
175
case PIPE_FORMAT_YUYV:
176
return VDP_YCBCR_FORMAT_YUYV;
177
case PIPE_FORMAT_R8G8B8A8_UNORM:
178
return VDP_YCBCR_FORMAT_Y8U8V8A8;
179
case PIPE_FORMAT_B8G8R8A8_UNORM:
180
return VDP_YCBCR_FORMAT_V8U8Y8A8;
188
static inline VdpRGBAFormat
189
PipeToFormatRGBA(enum pipe_format p_format)
192
case PIPE_FORMAT_A8_UNORM:
193
return VDP_RGBA_FORMAT_A8;
194
case PIPE_FORMAT_B10G10R10A2_UNORM:
195
return VDP_RGBA_FORMAT_B10G10R10A2;
196
case PIPE_FORMAT_B8G8R8A8_UNORM:
197
return VDP_RGBA_FORMAT_B8G8R8A8;
198
case PIPE_FORMAT_R10G10B10A2_UNORM:
199
return VDP_RGBA_FORMAT_R10G10B10A2;
200
case PIPE_FORMAT_R8G8B8A8_UNORM:
201
return VDP_RGBA_FORMAT_R8G8B8A8;
209
static inline enum pipe_format
210
FormatIndexedToPipe(VdpRGBAFormat vdpau_format)
212
switch (vdpau_format) {
213
case VDP_INDEXED_FORMAT_A4I4:
214
return PIPE_FORMAT_R4A4_UNORM;
215
case VDP_INDEXED_FORMAT_I4A4:
216
return PIPE_FORMAT_A4R4_UNORM;
217
case VDP_INDEXED_FORMAT_A8I8:
218
return PIPE_FORMAT_A8R8_UNORM;
219
case VDP_INDEXED_FORMAT_I8A8:
220
return PIPE_FORMAT_R8A8_UNORM;
225
return PIPE_FORMAT_NONE;
228
static inline enum pipe_format
229
FormatColorTableToPipe(VdpColorTableFormat vdpau_format)
231
switch(vdpau_format) {
232
case VDP_COLOR_TABLE_FORMAT_B8G8R8X8:
233
return PIPE_FORMAT_B8G8R8X8_UNORM;
238
return PIPE_FORMAT_NONE;
241
static inline enum pipe_video_profile
242
ProfileToPipe(VdpDecoderProfile vdpau_profile)
244
switch (vdpau_profile) {
245
case VDP_DECODER_PROFILE_MPEG1:
246
return PIPE_VIDEO_PROFILE_MPEG1;
247
case VDP_DECODER_PROFILE_MPEG2_SIMPLE:
248
return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE;
249
case VDP_DECODER_PROFILE_MPEG2_MAIN:
250
return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
251
case VDP_DECODER_PROFILE_H264_BASELINE:
252
return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE;
253
case VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE:
254
return PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE;
255
case VDP_DECODER_PROFILE_H264_MAIN:
256
return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN;
257
case VDP_DECODER_PROFILE_H264_HIGH:
258
return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
259
case VDP_DECODER_PROFILE_MPEG4_PART2_SP:
260
return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE;
261
case VDP_DECODER_PROFILE_MPEG4_PART2_ASP:
262
return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE;
263
case VDP_DECODER_PROFILE_VC1_SIMPLE:
264
return PIPE_VIDEO_PROFILE_VC1_SIMPLE;
265
case VDP_DECODER_PROFILE_VC1_MAIN:
266
return PIPE_VIDEO_PROFILE_VC1_MAIN;
267
case VDP_DECODER_PROFILE_VC1_ADVANCED:
268
return PIPE_VIDEO_PROFILE_VC1_ADVANCED;
269
case VDP_DECODER_PROFILE_HEVC_MAIN:
270
return PIPE_VIDEO_PROFILE_HEVC_MAIN;
271
case VDP_DECODER_PROFILE_HEVC_MAIN_10:
272
return PIPE_VIDEO_PROFILE_HEVC_MAIN_10;
273
case VDP_DECODER_PROFILE_HEVC_MAIN_STILL:
274
return PIPE_VIDEO_PROFILE_HEVC_MAIN_STILL;
275
case VDP_DECODER_PROFILE_HEVC_MAIN_12:
276
return PIPE_VIDEO_PROFILE_HEVC_MAIN_12;
277
case VDP_DECODER_PROFILE_HEVC_MAIN_444:
278
return PIPE_VIDEO_PROFILE_HEVC_MAIN_444;
280
return PIPE_VIDEO_PROFILE_UNKNOWN;
284
static inline VdpDecoderProfile
285
PipeToProfile(enum pipe_video_profile p_profile)
288
case PIPE_VIDEO_PROFILE_MPEG1:
289
return VDP_DECODER_PROFILE_MPEG1;
290
case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
291
return VDP_DECODER_PROFILE_MPEG2_SIMPLE;
292
case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
293
return VDP_DECODER_PROFILE_MPEG2_MAIN;
294
case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
295
return VDP_DECODER_PROFILE_H264_BASELINE;
296
case PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE:
297
return VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE;
298
case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
299
return VDP_DECODER_PROFILE_H264_MAIN;
300
case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
301
return VDP_DECODER_PROFILE_H264_HIGH;
302
case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE:
303
return VDP_DECODER_PROFILE_MPEG4_PART2_SP;
304
case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE:
305
return VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
306
case PIPE_VIDEO_PROFILE_VC1_SIMPLE:
307
return VDP_DECODER_PROFILE_VC1_SIMPLE;
308
case PIPE_VIDEO_PROFILE_VC1_MAIN:
309
return VDP_DECODER_PROFILE_VC1_MAIN;
310
case PIPE_VIDEO_PROFILE_VC1_ADVANCED:
311
return VDP_DECODER_PROFILE_VC1_ADVANCED;
312
case PIPE_VIDEO_PROFILE_HEVC_MAIN:
313
return VDP_DECODER_PROFILE_HEVC_MAIN;
314
case PIPE_VIDEO_PROFILE_HEVC_MAIN_10:
315
return VDP_DECODER_PROFILE_HEVC_MAIN_10;
316
case PIPE_VIDEO_PROFILE_HEVC_MAIN_STILL:
317
return VDP_DECODER_PROFILE_HEVC_MAIN_STILL;
318
case PIPE_VIDEO_PROFILE_HEVC_MAIN_12:
319
return VDP_DECODER_PROFILE_HEVC_MAIN_12;
320
case PIPE_VIDEO_PROFILE_HEVC_MAIN_444:
321
return VDP_DECODER_PROFILE_HEVC_MAIN_444;
328
static inline struct u_rect *
329
RectToPipe(const VdpRect *src, struct u_rect *dst)
341
static inline struct pipe_box
342
RectToPipeBox(const VdpRect *rect, struct pipe_resource *res)
349
box.width = res->width0;
350
box.height = res->height0;
354
if (rect->x1 > rect->x0 &&
355
rect->y1 > rect->y0) {
358
box.width = rect->x1 - box.x;
359
box.height = rect->y1 - box.y;
370
CheckSurfaceParams(struct pipe_screen *screen,
371
const struct pipe_resource *templ)
373
return screen->is_format_supported(screen, templ->format, templ->target,
375
templ->nr_storage_samples, templ->bind);
380
struct pipe_reference reference;
381
struct vl_screen *vscreen;
382
struct pipe_context *context;
383
struct vl_compositor compositor;
384
struct pipe_sampler_view *dummy_sv;
391
struct vl_compositor_state cstate;
394
bool supported, enabled;
395
float luma_min, luma_max;
399
bool supported, enabled, spatial;
400
struct vl_deint_filter *filter;
404
bool supported, enabled;
405
struct vl_bicubic_filter *filter;
409
bool supported, enabled;
411
struct vl_median_filter *filter;
415
bool supported, enabled;
417
struct vl_matrix_filter *filter;
420
unsigned video_width, video_height;
421
enum pipe_video_chroma_format chroma_format;
422
unsigned max_layers, skip_chroma_deint;
431
struct pipe_video_buffer templat, *video_buffer;
437
struct pipe_sampler_view *sampler_view;
438
} vlVdpBitmapSurface;
440
typedef uint64_t vlVdpTime;
445
struct pipe_surface *surface;
446
struct pipe_sampler_view *sampler_view;
447
struct pipe_fence_handle *fence;
448
struct vl_compositor_state cstate;
449
struct u_rect dirty_area;
451
} vlVdpOutputSurface;
457
} vlVdpPresentationQueueTarget;
463
struct vl_compositor_state cstate;
464
vlVdpOutputSurface *last_surf;
465
} vlVdpPresentationQueue;
471
struct pipe_video_codec *decoder;
474
typedef uint32_t vlHandle;
476
boolean vlCreateHTAB(void);
477
void vlDestroyHTAB(void);
478
vlHandle vlAddDataHTAB(void *data);
479
void* vlGetDataHTAB(vlHandle handle);
480
void vlRemoveDataHTAB(vlHandle handle);
482
boolean vlGetFuncFTAB(VdpFuncId function_id, void **func);
484
/* Public functions */
485
VdpDeviceCreateX11 vdp_imp_device_create_x11;
487
void vlVdpDefaultSamplerViewTemplate(struct pipe_sampler_view *templ, struct pipe_resource *res);
489
/* Internal function pointers */
490
VdpGetErrorString vlVdpGetErrorString;
491
VdpDeviceDestroy vlVdpDeviceDestroy;
492
void vlVdpDeviceFree(vlVdpDevice *dev);
493
VdpGetProcAddress vlVdpGetProcAddress;
494
VdpGetApiVersion vlVdpGetApiVersion;
495
VdpGetInformationString vlVdpGetInformationString;
496
VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities;
497
VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities;
498
VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities;
499
VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities;
500
VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities;
501
VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities;
502
VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities;
503
VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities;
504
VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport;
505
VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport;
506
VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange;
507
VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport;
508
VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange;
509
VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate;
510
VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy;
511
VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters;
512
VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr;
513
VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr;
514
void vlVdpVideoSurfaceClear(vlVdpSurface *vlsurf);
515
VdpDecoderCreate vlVdpDecoderCreate;
516
VdpDecoderDestroy vlVdpDecoderDestroy;
517
VdpDecoderGetParameters vlVdpDecoderGetParameters;
518
VdpDecoderRender vlVdpDecoderRender;
519
VdpOutputSurfaceCreate vlVdpOutputSurfaceCreate;
520
VdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy;
521
VdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters;
522
VdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative;
523
VdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative;
524
VdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed;
525
VdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr;
526
VdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface;
527
VdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface;
528
VdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate;
529
VdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy;
530
VdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters;
531
VdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative;
532
VdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy;
533
VdpPresentationQueueCreate vlVdpPresentationQueueCreate;
534
VdpPresentationQueueDestroy vlVdpPresentationQueueDestroy;
535
VdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor;
536
VdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor;
537
VdpPresentationQueueGetTime vlVdpPresentationQueueGetTime;
538
VdpPresentationQueueDisplay vlVdpPresentationQueueDisplay;
539
VdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle;
540
VdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus;
541
VdpPreemptionCallback vlVdpPreemptionCallback;
542
VdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister;
543
VdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables;
544
VdpVideoMixerCreate vlVdpVideoMixerCreate;
545
VdpVideoMixerRender vlVdpVideoMixerRender;
546
VdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues;
547
VdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport;
548
VdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables;
549
VdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues;
550
VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues;
551
VdpVideoMixerDestroy vlVdpVideoMixerDestroy;
552
VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix;
553
/* Winsys specific internal function pointers */
554
VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11;
557
/* interop for GL gallium frontend */
558
VdpVideoSurfaceGallium vlVdpVideoSurfaceGallium;
559
VdpOutputSurfaceGallium vlVdpOutputSurfaceGallium;
560
VdpVideoSurfaceDMABuf vlVdpVideoSurfaceDMABuf;
561
VdpOutputSurfaceDMABuf vlVdpOutputSurfaceDMABuf;
566
#define VDPAU_TRACE 3
568
static inline void VDPAU_MSG(unsigned int level, const char *fmt, ...)
570
static int debug_level = -1;
572
if (debug_level == -1) {
573
debug_level = MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0);
576
if (level <= debug_level) {
579
_debug_vprintf(fmt, ap);
585
DeviceReference(vlVdpDevice **ptr, vlVdpDevice *dev)
587
vlVdpDevice *old_dev = *ptr;
589
if (pipe_reference(&(*ptr)->reference, &dev->reference))
590
vlVdpDeviceFree(old_dev);
594
#endif /* VDPAU_PRIVATE_H */