vdpau_private.h revision bd5fd67a3e3cda4b7676dd4745fc5d5524709210
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_context.h>
38
39#include <util/u_debug.h>
40#include <vl/vl_compositor.h>
41
42#include <vl_winsys.h>
43
44#define INFORMATION G3DVL VDPAU Driver Shared Library version VER_MAJOR.VER_MINOR
45#define QUOTEME(x) #x
46#define TOSTRING(x) QUOTEME(x)
47#define INFORMATION_STRING TOSTRING(INFORMATION)
48#define VL_HANDLES
49#define VL_NUM_DECODE_BUFFERS 4
50
51static inline enum pipe_video_chroma_format
52ChromaToPipe(VdpChromaType vdpau_type)
53{
54   switch (vdpau_type) {
55      case VDP_CHROMA_TYPE_420:
56         return PIPE_VIDEO_CHROMA_FORMAT_420;
57      case VDP_CHROMA_TYPE_422:
58         return PIPE_VIDEO_CHROMA_FORMAT_422;
59      case VDP_CHROMA_TYPE_444:
60         return PIPE_VIDEO_CHROMA_FORMAT_444;
61      default:
62         assert(0);
63   }
64
65   return -1;
66}
67
68static inline VdpChromaType
69PipeToChroma(enum pipe_video_chroma_format pipe_type)
70{
71   switch (pipe_type) {
72      case PIPE_VIDEO_CHROMA_FORMAT_420:
73         return VDP_CHROMA_TYPE_420;
74      case PIPE_VIDEO_CHROMA_FORMAT_422:
75         return VDP_CHROMA_TYPE_422;
76      case PIPE_VIDEO_CHROMA_FORMAT_444:
77         return VDP_CHROMA_TYPE_444;
78      default:
79         assert(0);
80   }
81
82   return -1;
83}
84
85
86static inline enum pipe_format
87FormatToPipe(VdpYCbCrFormat vdpau_format)
88{
89   switch (vdpau_format) {
90      case VDP_YCBCR_FORMAT_NV12:
91         return PIPE_FORMAT_NV12;
92      case VDP_YCBCR_FORMAT_YV12:
93         return PIPE_FORMAT_YV12;
94      case VDP_YCBCR_FORMAT_UYVY:
95         return PIPE_FORMAT_UYVY;
96      case VDP_YCBCR_FORMAT_YUYV:
97         return PIPE_FORMAT_YUYV;
98      case VDP_YCBCR_FORMAT_Y8U8V8A8: /* Not defined in p_format.h */
99         return 0;
100      case VDP_YCBCR_FORMAT_V8U8Y8A8:
101	     return PIPE_FORMAT_VUYA;
102      default:
103         assert(0);
104   }
105
106   return -1;
107}
108
109static inline enum pipe_format
110FormatRGBAToPipe(VdpRGBAFormat vdpau_format)
111{
112   switch (vdpau_format) {
113      case VDP_RGBA_FORMAT_A8:
114         return PIPE_FORMAT_A8_UNORM;
115      case VDP_RGBA_FORMAT_B10G10R10A2:
116         return PIPE_FORMAT_B10G10R10A2_UNORM;
117      case VDP_RGBA_FORMAT_B8G8R8A8:
118         return PIPE_FORMAT_B8G8R8A8_UNORM;
119      case VDP_RGBA_FORMAT_R10G10B10A2:
120         return PIPE_FORMAT_R10G10B10A2_UNORM;
121      case VDP_RGBA_FORMAT_R8G8B8A8:
122         return PIPE_FORMAT_R8G8B8A8_UNORM;
123      default:
124         assert(0);
125   }
126
127   return -1;
128}
129
130static inline VdpYCbCrFormat
131PipeToFormat(enum pipe_format p_format)
132{
133   switch (p_format) {
134      case PIPE_FORMAT_NV12:
135         return VDP_YCBCR_FORMAT_NV12;
136      case PIPE_FORMAT_YV12:
137         return VDP_YCBCR_FORMAT_YV12;
138      case PIPE_FORMAT_UYVY:
139         return VDP_YCBCR_FORMAT_UYVY;
140      case PIPE_FORMAT_YUYV:
141         return VDP_YCBCR_FORMAT_YUYV;
142      //case PIPE_FORMAT_YUVA:
143        // return VDP_YCBCR_FORMAT_Y8U8V8A8;
144      case PIPE_FORMAT_VUYA:
145	 return VDP_YCBCR_FORMAT_V8U8Y8A8;
146      default:
147         assert(0);
148   }
149
150   return -1;
151}
152
153static inline enum pipe_video_profile
154ProfileToPipe(VdpDecoderProfile vdpau_profile)
155{
156   switch (vdpau_profile) {
157      case VDP_DECODER_PROFILE_MPEG1:
158         return PIPE_VIDEO_PROFILE_MPEG1;
159      case VDP_DECODER_PROFILE_MPEG2_SIMPLE:
160         return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE;
161      case VDP_DECODER_PROFILE_MPEG2_MAIN:
162         return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
163      case VDP_DECODER_PROFILE_H264_BASELINE:
164         return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE;
165      case VDP_DECODER_PROFILE_H264_MAIN: /* Not defined in p_format.h */
166         return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN;
167      case VDP_DECODER_PROFILE_H264_HIGH:
168	     return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
169      default:
170         return PIPE_VIDEO_PROFILE_UNKNOWN;
171   }
172}
173
174typedef struct
175{
176   Display *display;
177   int screen;
178   struct vl_screen *vscreen;
179   struct vl_context *context;
180} vlVdpDevice;
181
182typedef struct
183{
184   vlVdpDevice *device;
185   Drawable drawable;
186} vlVdpPresentationQueueTarget;
187
188typedef struct
189{
190   vlVdpDevice *device;
191   Drawable drawable;
192   struct vl_compositor compositor;
193} vlVdpPresentationQueue;
194
195typedef struct
196{
197   vlVdpDevice *device;
198   struct vl_compositor compositor;
199} vlVdpVideoMixer;
200
201typedef struct
202{
203   vlVdpDevice *device;
204   struct pipe_video_buffer *video_buffer;
205} vlVdpSurface;
206
207typedef struct
208{
209   vlVdpDevice *device;
210   struct pipe_surface *surface;
211   struct pipe_sampler_view *sampler_view;
212} vlVdpOutputSurface;
213
214typedef struct
215{
216   vlVdpDevice *device;
217   struct pipe_video_decoder *decoder;
218   struct pipe_video_decode_buffer *buffer[VL_NUM_DECODE_BUFFERS];
219   unsigned cur_buffer;
220} vlVdpDecoder;
221
222typedef uint32_t vlHandle;
223
224boolean vlCreateHTAB(void);
225void vlDestroyHTAB(void);
226vlHandle vlAddDataHTAB(void *data);
227void* vlGetDataHTAB(vlHandle handle);
228void vlRemoveDataHTAB(vlHandle handle);
229
230boolean vlGetFuncFTAB(VdpFuncId function_id, void **func);
231
232/* Public functions */
233VdpDeviceCreateX11 vdp_imp_device_create_x11;
234VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11;
235
236/* Internal function pointers */
237VdpGetErrorString vlVdpGetErrorString;
238VdpDeviceDestroy vlVdpDeviceDestroy;
239VdpGetProcAddress vlVdpGetProcAddress;
240VdpGetApiVersion vlVdpGetApiVersion;
241VdpGetInformationString vlVdpGetInformationString;
242VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities;
243VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities;
244VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities;
245VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities;
246VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities;
247VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities;
248VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities;
249VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities;
250VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport;
251VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport;
252VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange;
253VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport;
254VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange;
255VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate;
256VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy;
257VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters;
258VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr;
259VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr;
260VdpDecoderCreate vlVdpDecoderCreate;
261VdpDecoderDestroy vlVdpDecoderDestroy;
262VdpDecoderGetParameters vlVdpDecoderGetParameters;
263VdpDecoderRender vlVdpDecoderRender;
264VdpOutputSurfaceCreate vlVdpOutputSurfaceCreate;
265VdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy;
266VdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters;
267VdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative;
268VdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative;
269VdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed;
270VdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr;
271VdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface;
272VdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface;
273VdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate;
274VdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy;
275VdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters;
276VdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative;
277VdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy;
278VdpPresentationQueueCreate vlVdpPresentationQueueCreate;
279VdpPresentationQueueDestroy vlVdpPresentationQueueDestroy;
280VdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor;
281VdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor;
282VdpPresentationQueueGetTime vlVdpPresentationQueueGetTime;
283VdpPresentationQueueDisplay vlVdpPresentationQueueDisplay;
284VdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle;
285VdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus;
286VdpPreemptionCallback vlVdpPreemptionCallback;
287VdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister;
288VdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables;
289VdpVideoMixerCreate vlVdpVideoMixerCreate;
290VdpVideoMixerRender vlVdpVideoMixerRender;
291VdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues;
292VdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport;
293VdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables;
294VdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues;
295VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues;
296VdpVideoMixerDestroy vlVdpVideoMixerDestroy;
297VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix;
298
299#define VDPAU_OUT   0
300#define VDPAU_ERR   1
301#define VDPAU_WARN  2
302#define VDPAU_TRACE 3
303
304static inline void VDPAU_MSG(unsigned int level, const char *fmt, ...)
305{
306   static int debug_level = -1;
307
308   if (debug_level == -1) {
309      debug_level = MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0);
310   }
311
312   if (level <= debug_level) {
313      va_list ap;
314      va_start(ap, fmt);
315      _debug_vprintf(fmt, ap);
316      va_end(ap);
317   }
318}
319
320#endif // VDPAU_PRIVATE_H
321