vdpau_private.h revision bbb48e983d232d67031250127b3c2acfc086369e
1/**************************************************************************
2 *
3 * Copyright 2010 Younes Manton & Thomas Balling Sørensen.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28#ifndef VDPAU_PRIVATE_H
29#define VDPAU_PRIVATE_H
30
31#include <assert.h>
32
33#include <vdpau/vdpau.h>
34#include <vdpau/vdpau_x11.h>
35
36#include "pipe/p_compiler.h"
37#include "pipe/p_video_decoder.h"
38
39#include "util/u_debug.h"
40#include "util/u_rect.h"
41#include "vl/vl_compositor.h"
42#include "vl/vl_median_filter.h"
43
44#include "vl_winsys.h"
45
46/* Full VDPAU API documentation available at :
47 * ftp://download.nvidia.com/XFree86/vdpau/doxygen/html/index.html */
48
49#define INFORMATION G3DVL VDPAU Driver Shared Library version VER_MAJOR.VER_MINOR
50#define QUOTEME(x) #x
51#define TOSTRING(x) QUOTEME(x)
52#define INFORMATION_STRING TOSTRING(INFORMATION)
53#define VL_HANDLES
54
55static inline enum pipe_video_chroma_format
56ChromaToPipe(VdpChromaType vdpau_type)
57{
58   switch (vdpau_type) {
59      case VDP_CHROMA_TYPE_420:
60         return PIPE_VIDEO_CHROMA_FORMAT_420;
61      case VDP_CHROMA_TYPE_422:
62         return PIPE_VIDEO_CHROMA_FORMAT_422;
63      case VDP_CHROMA_TYPE_444:
64         return PIPE_VIDEO_CHROMA_FORMAT_444;
65      default:
66         assert(0);
67   }
68
69   return -1;
70}
71
72static inline VdpChromaType
73PipeToChroma(enum pipe_video_chroma_format pipe_type)
74{
75   switch (pipe_type) {
76      case PIPE_VIDEO_CHROMA_FORMAT_420:
77         return VDP_CHROMA_TYPE_420;
78      case PIPE_VIDEO_CHROMA_FORMAT_422:
79         return VDP_CHROMA_TYPE_422;
80      case PIPE_VIDEO_CHROMA_FORMAT_444:
81         return VDP_CHROMA_TYPE_444;
82      default:
83         assert(0);
84   }
85
86   return -1;
87}
88
89static inline enum pipe_format
90FormatYCBCRToPipe(VdpYCbCrFormat vdpau_format)
91{
92   switch (vdpau_format) {
93      case VDP_YCBCR_FORMAT_NV12:
94         return PIPE_FORMAT_NV12;
95      case VDP_YCBCR_FORMAT_YV12:
96         return PIPE_FORMAT_YV12;
97      case VDP_YCBCR_FORMAT_UYVY:
98         return PIPE_FORMAT_UYVY;
99      case VDP_YCBCR_FORMAT_YUYV:
100         return PIPE_FORMAT_YUYV;
101      case VDP_YCBCR_FORMAT_Y8U8V8A8: /* Not defined in p_format.h */
102         return PIPE_FORMAT_NONE;
103      case VDP_YCBCR_FORMAT_V8U8Y8A8:
104	     return PIPE_FORMAT_VUYA;
105      default:
106         assert(0);
107   }
108
109   return PIPE_FORMAT_NONE;
110}
111
112static inline VdpYCbCrFormat
113PipeToFormatYCBCR(enum pipe_format p_format)
114{
115   switch (p_format) {
116      case PIPE_FORMAT_NV12:
117         return VDP_YCBCR_FORMAT_NV12;
118      case PIPE_FORMAT_YV12:
119         return VDP_YCBCR_FORMAT_YV12;
120      case PIPE_FORMAT_UYVY:
121         return VDP_YCBCR_FORMAT_UYVY;
122      case PIPE_FORMAT_YUYV:
123         return VDP_YCBCR_FORMAT_YUYV;
124      //case PIPE_FORMAT_YUVA:
125        // return VDP_YCBCR_FORMAT_Y8U8V8A8;
126      case PIPE_FORMAT_VUYA:
127         return VDP_YCBCR_FORMAT_V8U8Y8A8;
128      default:
129         assert(0);
130   }
131
132   return -1;
133}
134
135static inline enum pipe_format
136FormatRGBAToPipe(VdpRGBAFormat vdpau_format)
137{
138   switch (vdpau_format) {
139      case VDP_RGBA_FORMAT_A8:
140         return PIPE_FORMAT_A8_UNORM;
141      case VDP_RGBA_FORMAT_B10G10R10A2:
142         return PIPE_FORMAT_B10G10R10A2_UNORM;
143      case VDP_RGBA_FORMAT_B8G8R8A8:
144         return PIPE_FORMAT_B8G8R8A8_UNORM;
145      case VDP_RGBA_FORMAT_R10G10B10A2:
146         return PIPE_FORMAT_R10G10B10A2_UNORM;
147      case VDP_RGBA_FORMAT_R8G8B8A8:
148         return PIPE_FORMAT_R8G8B8A8_UNORM;
149      default:
150         assert(0);
151   }
152
153   return PIPE_FORMAT_NONE;
154}
155
156static inline VdpRGBAFormat
157PipeToFormatRGBA(enum pipe_format p_format)
158{
159   switch (p_format) {
160      case PIPE_FORMAT_A8_UNORM:
161         return VDP_RGBA_FORMAT_A8;
162      case PIPE_FORMAT_B10G10R10A2_UNORM:
163         return VDP_RGBA_FORMAT_B10G10R10A2;
164      case PIPE_FORMAT_B8G8R8A8_UNORM:
165         return VDP_RGBA_FORMAT_B8G8R8A8;
166      case PIPE_FORMAT_R10G10B10A2_UNORM:
167         return VDP_RGBA_FORMAT_R10G10B10A2;
168      case PIPE_FORMAT_R8G8B8A8_UNORM:
169         return VDP_RGBA_FORMAT_R8G8B8A8;
170      default:
171         assert(0);
172   }
173
174   return -1;
175}
176
177static inline enum pipe_format
178FormatIndexedToPipe(VdpRGBAFormat vdpau_format)
179{
180   switch (vdpau_format) {
181      case VDP_INDEXED_FORMAT_A4I4:
182         return PIPE_FORMAT_A4R4_UNORM;
183      case VDP_INDEXED_FORMAT_I4A4:
184         return PIPE_FORMAT_R4A4_UNORM;
185      case VDP_INDEXED_FORMAT_A8I8:
186         return PIPE_FORMAT_A8R8_UNORM;
187      case VDP_INDEXED_FORMAT_I8A8:
188         return PIPE_FORMAT_R8A8_UNORM;
189      default:
190         assert(0);
191   }
192
193   return PIPE_FORMAT_NONE;
194}
195
196static inline enum pipe_format
197FormatColorTableToPipe(VdpColorTableFormat vdpau_format)
198{
199   switch(vdpau_format) {
200      case VDP_COLOR_TABLE_FORMAT_B8G8R8X8:
201         return PIPE_FORMAT_B8G8R8X8_UNORM;
202      default:
203         assert(0);
204   }
205
206   return PIPE_FORMAT_NONE;
207}
208
209static inline enum pipe_video_profile
210ProfileToPipe(VdpDecoderProfile vdpau_profile)
211{
212   switch (vdpau_profile) {
213      case VDP_DECODER_PROFILE_MPEG1:
214         return PIPE_VIDEO_PROFILE_MPEG1;
215      case VDP_DECODER_PROFILE_MPEG2_SIMPLE:
216         return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE;
217      case VDP_DECODER_PROFILE_MPEG2_MAIN:
218         return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
219      case VDP_DECODER_PROFILE_H264_BASELINE:
220         return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE;
221      case VDP_DECODER_PROFILE_H264_MAIN:
222         return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN;
223      case VDP_DECODER_PROFILE_H264_HIGH:
224         return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
225      case VDP_DECODER_PROFILE_MPEG4_PART2_SP:
226         return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE;
227      case VDP_DECODER_PROFILE_MPEG4_PART2_ASP:
228         return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE;
229      case VDP_DECODER_PROFILE_VC1_SIMPLE:
230         return PIPE_VIDEO_PROFILE_VC1_SIMPLE;
231      case VDP_DECODER_PROFILE_VC1_MAIN:
232         return PIPE_VIDEO_PROFILE_VC1_MAIN;
233      case VDP_DECODER_PROFILE_VC1_ADVANCED:
234         return PIPE_VIDEO_PROFILE_VC1_ADVANCED;
235      default:
236         return PIPE_VIDEO_PROFILE_UNKNOWN;
237   }
238}
239
240static inline VdpDecoderProfile
241PipeToProfile(enum pipe_video_profile p_profile)
242{
243   switch (p_profile) {
244      case PIPE_VIDEO_PROFILE_MPEG1:
245         return VDP_DECODER_PROFILE_MPEG1;
246      case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
247         return VDP_DECODER_PROFILE_MPEG2_SIMPLE;
248      case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
249         return VDP_DECODER_PROFILE_MPEG2_MAIN;
250      case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
251         return VDP_DECODER_PROFILE_H264_BASELINE;
252      case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
253         return VDP_DECODER_PROFILE_H264_MAIN;
254      case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
255         return VDP_DECODER_PROFILE_H264_HIGH;
256      case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE:
257         return VDP_DECODER_PROFILE_MPEG4_PART2_SP;
258      case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE:
259         return VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
260      case PIPE_VIDEO_PROFILE_VC1_SIMPLE:
261         return VDP_DECODER_PROFILE_VC1_SIMPLE;
262      case PIPE_VIDEO_PROFILE_VC1_MAIN:
263         return VDP_DECODER_PROFILE_VC1_MAIN;
264      case PIPE_VIDEO_PROFILE_VC1_ADVANCED:
265         return VDP_DECODER_PROFILE_VC1_ADVANCED;
266      default:
267         assert(0);
268         return -1;
269   }
270}
271
272static inline struct pipe_video_rect *
273RectToPipe(const VdpRect *src, struct pipe_video_rect *dst)
274{
275   if (src) {
276      dst->x = MIN2(src->x1, src->x0);
277      dst->y = MIN2(src->y1, src->y0);
278      dst->w = abs(src->x1 - src->x0);
279      dst->h = abs(src->y1 - src->y0);
280      return dst;
281   }
282   return NULL;
283}
284
285typedef struct
286{
287   struct vl_screen *vscreen;
288   struct vl_context *context;
289   struct vl_compositor compositor;
290} vlVdpDevice;
291
292typedef struct
293{
294   vlVdpDevice *device;
295   Drawable drawable;
296} vlVdpPresentationQueueTarget;
297
298typedef struct
299{
300   vlVdpDevice *device;
301   Drawable drawable;
302   struct vl_compositor compositor;
303   struct u_rect dirty_area;
304} vlVdpPresentationQueue;
305
306typedef struct
307{
308   vlVdpDevice *device;
309   struct vl_compositor compositor;
310
311   struct {
312      bool supported, enabled;
313      float level;
314      struct vl_median_filter *filter;
315   } noise_reduction;
316
317   unsigned video_width, video_height;
318   enum pipe_video_chroma_format chroma_format;
319   unsigned max_layers, skip_chroma_deint, custom_csc;
320   float luma_key_min, luma_key_max, sharpness;
321   float csc[16];
322} vlVdpVideoMixer;
323
324typedef struct
325{
326   vlVdpDevice *device;
327   struct pipe_video_buffer templat, *video_buffer;
328} vlVdpSurface;
329
330typedef uint64_t vlVdpTime;
331
332typedef struct
333{
334   vlVdpTime timestamp;
335   vlVdpDevice *device;
336   struct pipe_surface *surface;
337   struct pipe_sampler_view *sampler_view;
338   struct pipe_fence_handle *fence;
339   struct u_rect dirty_area;
340} vlVdpOutputSurface;
341
342typedef struct
343{
344   vlVdpDevice *device;
345   struct pipe_video_decoder *decoder;
346} vlVdpDecoder;
347
348typedef uint32_t vlHandle;
349
350boolean vlCreateHTAB(void);
351void vlDestroyHTAB(void);
352vlHandle vlAddDataHTAB(void *data);
353void* vlGetDataHTAB(vlHandle handle);
354void vlRemoveDataHTAB(vlHandle handle);
355
356boolean vlGetFuncFTAB(VdpFuncId function_id, void **func);
357
358/* Public functions */
359VdpDeviceCreateX11 vdp_imp_device_create_x11;
360VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11;
361
362/* Internal function pointers */
363VdpGetErrorString vlVdpGetErrorString;
364VdpDeviceDestroy vlVdpDeviceDestroy;
365VdpGetProcAddress vlVdpGetProcAddress;
366VdpGetApiVersion vlVdpGetApiVersion;
367VdpGetInformationString vlVdpGetInformationString;
368VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities;
369VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities;
370VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities;
371VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities;
372VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities;
373VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities;
374VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities;
375VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities;
376VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport;
377VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport;
378VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange;
379VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport;
380VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange;
381VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate;
382VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy;
383VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters;
384VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr;
385VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr;
386VdpDecoderCreate vlVdpDecoderCreate;
387VdpDecoderDestroy vlVdpDecoderDestroy;
388VdpDecoderGetParameters vlVdpDecoderGetParameters;
389VdpDecoderRender vlVdpDecoderRender;
390VdpOutputSurfaceCreate vlVdpOutputSurfaceCreate;
391VdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy;
392VdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters;
393VdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative;
394VdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative;
395VdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed;
396VdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr;
397VdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface;
398VdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface;
399VdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate;
400VdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy;
401VdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters;
402VdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative;
403VdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy;
404VdpPresentationQueueCreate vlVdpPresentationQueueCreate;
405VdpPresentationQueueDestroy vlVdpPresentationQueueDestroy;
406VdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor;
407VdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor;
408VdpPresentationQueueGetTime vlVdpPresentationQueueGetTime;
409VdpPresentationQueueDisplay vlVdpPresentationQueueDisplay;
410VdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle;
411VdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus;
412VdpPreemptionCallback vlVdpPreemptionCallback;
413VdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister;
414VdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables;
415VdpVideoMixerCreate vlVdpVideoMixerCreate;
416VdpVideoMixerRender vlVdpVideoMixerRender;
417VdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues;
418VdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport;
419VdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables;
420VdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues;
421VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues;
422VdpVideoMixerDestroy vlVdpVideoMixerDestroy;
423VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix;
424
425#define VDPAU_OUT   0
426#define VDPAU_ERR   1
427#define VDPAU_WARN  2
428#define VDPAU_TRACE 3
429
430static inline void VDPAU_MSG(unsigned int level, const char *fmt, ...)
431{
432   static int debug_level = -1;
433
434   if (debug_level == -1) {
435      debug_level = MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0);
436   }
437
438   if (level <= debug_level) {
439      va_list ap;
440      va_start(ap, fmt);
441      _debug_vprintf(fmt, ap);
442      va_end(ap);
443   }
444}
445
446#endif /* VDPAU_PRIVATE_H */
447