vdpau_private.h revision 1d1d038c85ebb37f1da4540f092563e8ecab7dfb
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 <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
87FormatYCBCRToPipe(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 VdpYCbCrFormat
110PipeToFormatYCBCR(enum pipe_format p_format)
111{
112   switch (p_format) {
113      case PIPE_FORMAT_NV12:
114         return VDP_YCBCR_FORMAT_NV12;
115      case PIPE_FORMAT_YV12:
116         return VDP_YCBCR_FORMAT_YV12;
117      case PIPE_FORMAT_UYVY:
118         return VDP_YCBCR_FORMAT_UYVY;
119      case PIPE_FORMAT_YUYV:
120         return VDP_YCBCR_FORMAT_YUYV;
121      //case PIPE_FORMAT_YUVA:
122        // return VDP_YCBCR_FORMAT_Y8U8V8A8;
123      case PIPE_FORMAT_VUYA:
124	 return VDP_YCBCR_FORMAT_V8U8Y8A8;
125      default:
126         assert(0);
127   }
128
129   return -1;
130}
131
132static inline enum pipe_format
133FormatRGBAToPipe(VdpRGBAFormat vdpau_format)
134{
135   switch (vdpau_format) {
136      case VDP_RGBA_FORMAT_A8:
137         return PIPE_FORMAT_A8_UNORM;
138      case VDP_RGBA_FORMAT_B10G10R10A2:
139         return PIPE_FORMAT_B10G10R10A2_UNORM;
140      case VDP_RGBA_FORMAT_B8G8R8A8:
141         return PIPE_FORMAT_B8G8R8A8_UNORM;
142      case VDP_RGBA_FORMAT_R10G10B10A2:
143         return PIPE_FORMAT_R10G10B10A2_UNORM;
144      case VDP_RGBA_FORMAT_R8G8B8A8:
145         return PIPE_FORMAT_R8G8B8A8_UNORM;
146      default:
147         assert(0);
148   }
149
150   return -1;
151}
152
153static inline VdpRGBAFormat
154PipeToFormatRGBA(enum pipe_format p_format)
155{
156   switch (p_format) {
157      case PIPE_FORMAT_A8_UNORM:
158         return VDP_RGBA_FORMAT_A8;
159      case PIPE_FORMAT_B10G10R10A2_UNORM:
160         return VDP_RGBA_FORMAT_B10G10R10A2;
161      case PIPE_FORMAT_B8G8R8A8_UNORM:
162         return VDP_RGBA_FORMAT_B8G8R8A8;
163      case PIPE_FORMAT_R10G10B10A2_UNORM:
164         return VDP_RGBA_FORMAT_R10G10B10A2;
165      case PIPE_FORMAT_R8G8B8A8_UNORM:
166         return VDP_RGBA_FORMAT_R8G8B8A8;
167      default:
168         assert(0);
169   }
170
171   return -1;
172}
173
174static inline enum pipe_video_profile
175ProfileToPipe(VdpDecoderProfile vdpau_profile)
176{
177   switch (vdpau_profile) {
178      case VDP_DECODER_PROFILE_MPEG1:
179         return PIPE_VIDEO_PROFILE_MPEG1;
180      case VDP_DECODER_PROFILE_MPEG2_SIMPLE:
181         return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE;
182      case VDP_DECODER_PROFILE_MPEG2_MAIN:
183         return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
184      case VDP_DECODER_PROFILE_H264_BASELINE:
185         return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE;
186      case VDP_DECODER_PROFILE_H264_MAIN: /* Not defined in p_format.h */
187         return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN;
188      case VDP_DECODER_PROFILE_H264_HIGH:
189	     return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
190      default:
191         return PIPE_VIDEO_PROFILE_UNKNOWN;
192   }
193}
194
195static inline VdpDecoderProfile
196PipeToProfile(enum pipe_video_profile p_profile)
197{
198   switch (p_profile) {
199      case PIPE_VIDEO_PROFILE_MPEG1:
200         return VDP_DECODER_PROFILE_MPEG1;
201      case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
202         return VDP_DECODER_PROFILE_MPEG2_SIMPLE;
203      case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
204         return VDP_DECODER_PROFILE_MPEG2_MAIN;
205      case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
206         return VDP_DECODER_PROFILE_H264_BASELINE;
207      case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN: /* Not defined in p_format.h */
208         return VDP_DECODER_PROFILE_H264_MAIN;
209      case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
210	     return VDP_DECODER_PROFILE_H264_HIGH;
211      default:
212         assert(0);
213         return -1;
214   }
215}
216
217typedef struct
218{
219   struct vl_screen *vscreen;
220   struct vl_context *context;
221} vlVdpDevice;
222
223typedef struct
224{
225   vlVdpDevice *device;
226   Drawable drawable;
227} vlVdpPresentationQueueTarget;
228
229typedef struct
230{
231   vlVdpDevice *device;
232   Drawable drawable;
233   struct vl_compositor compositor;
234} vlVdpPresentationQueue;
235
236typedef struct
237{
238   vlVdpDevice *device;
239   struct vl_compositor compositor;
240} vlVdpVideoMixer;
241
242typedef struct
243{
244   vlVdpDevice *device;
245   struct pipe_video_buffer *video_buffer;
246} vlVdpSurface;
247
248typedef struct
249{
250   vlVdpDevice *device;
251   struct pipe_surface *surface;
252   struct pipe_sampler_view *sampler_view;
253} vlVdpOutputSurface;
254
255typedef struct
256{
257   vlVdpDevice *device;
258   struct pipe_video_decoder *decoder;
259   void *buffer[VL_NUM_DECODE_BUFFERS];
260   unsigned cur_buffer;
261} vlVdpDecoder;
262
263typedef uint32_t vlHandle;
264
265boolean vlCreateHTAB(void);
266void vlDestroyHTAB(void);
267vlHandle vlAddDataHTAB(void *data);
268void* vlGetDataHTAB(vlHandle handle);
269void vlRemoveDataHTAB(vlHandle handle);
270
271boolean vlGetFuncFTAB(VdpFuncId function_id, void **func);
272
273/* Public functions */
274VdpDeviceCreateX11 vdp_imp_device_create_x11;
275VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11;
276
277/* Internal function pointers */
278VdpGetErrorString vlVdpGetErrorString;
279VdpDeviceDestroy vlVdpDeviceDestroy;
280VdpGetProcAddress vlVdpGetProcAddress;
281VdpGetApiVersion vlVdpGetApiVersion;
282VdpGetInformationString vlVdpGetInformationString;
283VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities;
284VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities;
285VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities;
286VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities;
287VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities;
288VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities;
289VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities;
290VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities;
291VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport;
292VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport;
293VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange;
294VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport;
295VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange;
296VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate;
297VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy;
298VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters;
299VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr;
300VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr;
301VdpDecoderCreate vlVdpDecoderCreate;
302VdpDecoderDestroy vlVdpDecoderDestroy;
303VdpDecoderGetParameters vlVdpDecoderGetParameters;
304VdpDecoderRender vlVdpDecoderRender;
305VdpOutputSurfaceCreate vlVdpOutputSurfaceCreate;
306VdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy;
307VdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters;
308VdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative;
309VdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative;
310VdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed;
311VdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr;
312VdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface;
313VdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface;
314VdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate;
315VdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy;
316VdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters;
317VdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative;
318VdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy;
319VdpPresentationQueueCreate vlVdpPresentationQueueCreate;
320VdpPresentationQueueDestroy vlVdpPresentationQueueDestroy;
321VdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor;
322VdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor;
323VdpPresentationQueueGetTime vlVdpPresentationQueueGetTime;
324VdpPresentationQueueDisplay vlVdpPresentationQueueDisplay;
325VdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle;
326VdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus;
327VdpPreemptionCallback vlVdpPreemptionCallback;
328VdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister;
329VdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables;
330VdpVideoMixerCreate vlVdpVideoMixerCreate;
331VdpVideoMixerRender vlVdpVideoMixerRender;
332VdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues;
333VdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport;
334VdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables;
335VdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues;
336VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues;
337VdpVideoMixerDestroy vlVdpVideoMixerDestroy;
338VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix;
339
340#define VDPAU_OUT   0
341#define VDPAU_ERR   1
342#define VDPAU_WARN  2
343#define VDPAU_TRACE 3
344
345static inline void VDPAU_MSG(unsigned int level, const char *fmt, ...)
346{
347   static int debug_level = -1;
348
349   if (debug_level == -1) {
350      debug_level = MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0);
351   }
352
353   if (level <= debug_level) {
354      va_list ap;
355      va_start(ap, fmt);
356      _debug_vprintf(fmt, ap);
357      va_end(ap);
358   }
359}
360
361#endif // VDPAU_PRIVATE_H
362