705b57e72c0aeadf0324e7003304059634d3aada
[mesa.git] / src / gallium / state_trackers / vdpau / vdpau_private.h
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
50 static inline enum pipe_video_chroma_format
51 ChromaToPipe(VdpChromaType vdpau_type)
52 {
53 switch (vdpau_type) {
54 case VDP_CHROMA_TYPE_420:
55 return PIPE_VIDEO_CHROMA_FORMAT_420;
56 case VDP_CHROMA_TYPE_422:
57 return PIPE_VIDEO_CHROMA_FORMAT_422;
58 case VDP_CHROMA_TYPE_444:
59 return PIPE_VIDEO_CHROMA_FORMAT_444;
60 default:
61 assert(0);
62 }
63
64 return -1;
65 }
66
67 static inline VdpChromaType
68 PipeToChroma(enum pipe_video_chroma_format pipe_type)
69 {
70 switch (pipe_type) {
71 case PIPE_VIDEO_CHROMA_FORMAT_420:
72 return VDP_CHROMA_TYPE_420;
73 case PIPE_VIDEO_CHROMA_FORMAT_422:
74 return VDP_CHROMA_TYPE_422;
75 case PIPE_VIDEO_CHROMA_FORMAT_444:
76 return VDP_CHROMA_TYPE_444;
77 default:
78 assert(0);
79 }
80
81 return -1;
82 }
83
84
85 static inline enum pipe_format
86 FormatYCBCRToPipe(VdpYCbCrFormat vdpau_format)
87 {
88 switch (vdpau_format) {
89 case VDP_YCBCR_FORMAT_NV12:
90 return PIPE_FORMAT_NV12;
91 case VDP_YCBCR_FORMAT_YV12:
92 return PIPE_FORMAT_YV12;
93 case VDP_YCBCR_FORMAT_UYVY:
94 return PIPE_FORMAT_UYVY;
95 case VDP_YCBCR_FORMAT_YUYV:
96 return PIPE_FORMAT_YUYV;
97 case VDP_YCBCR_FORMAT_Y8U8V8A8: /* Not defined in p_format.h */
98 return PIPE_FORMAT_NONE;
99 case VDP_YCBCR_FORMAT_V8U8Y8A8:
100 return PIPE_FORMAT_VUYA;
101 default:
102 assert(0);
103 }
104
105 return PIPE_FORMAT_NONE;
106 }
107
108 static inline VdpYCbCrFormat
109 PipeToFormatYCBCR(enum pipe_format p_format)
110 {
111 switch (p_format) {
112 case PIPE_FORMAT_NV12:
113 return VDP_YCBCR_FORMAT_NV12;
114 case PIPE_FORMAT_YV12:
115 return VDP_YCBCR_FORMAT_YV12;
116 case PIPE_FORMAT_UYVY:
117 return VDP_YCBCR_FORMAT_UYVY;
118 case PIPE_FORMAT_YUYV:
119 return VDP_YCBCR_FORMAT_YUYV;
120 //case PIPE_FORMAT_YUVA:
121 // return VDP_YCBCR_FORMAT_Y8U8V8A8;
122 case PIPE_FORMAT_VUYA:
123 return VDP_YCBCR_FORMAT_V8U8Y8A8;
124 default:
125 assert(0);
126 }
127
128 return -1;
129 }
130
131 static inline enum pipe_format
132 FormatRGBAToPipe(VdpRGBAFormat vdpau_format)
133 {
134 switch (vdpau_format) {
135 case VDP_RGBA_FORMAT_A8:
136 return PIPE_FORMAT_A8_UNORM;
137 case VDP_RGBA_FORMAT_B10G10R10A2:
138 return PIPE_FORMAT_B10G10R10A2_UNORM;
139 case VDP_RGBA_FORMAT_B8G8R8A8:
140 return PIPE_FORMAT_B8G8R8A8_UNORM;
141 case VDP_RGBA_FORMAT_R10G10B10A2:
142 return PIPE_FORMAT_R10G10B10A2_UNORM;
143 case VDP_RGBA_FORMAT_R8G8B8A8:
144 return PIPE_FORMAT_R8G8B8A8_UNORM;
145 default:
146 assert(0);
147 }
148
149 return PIPE_FORMAT_NONE;
150 }
151
152 static inline VdpRGBAFormat
153 PipeToFormatRGBA(enum pipe_format p_format)
154 {
155 switch (p_format) {
156 case PIPE_FORMAT_A8_UNORM:
157 return VDP_RGBA_FORMAT_A8;
158 case PIPE_FORMAT_B10G10R10A2_UNORM:
159 return VDP_RGBA_FORMAT_B10G10R10A2;
160 case PIPE_FORMAT_B8G8R8A8_UNORM:
161 return VDP_RGBA_FORMAT_B8G8R8A8;
162 case PIPE_FORMAT_R10G10B10A2_UNORM:
163 return VDP_RGBA_FORMAT_R10G10B10A2;
164 case PIPE_FORMAT_R8G8B8A8_UNORM:
165 return VDP_RGBA_FORMAT_R8G8B8A8;
166 default:
167 assert(0);
168 }
169
170 return -1;
171 }
172
173 static inline enum pipe_format
174 FormatIndexedToPipe(VdpRGBAFormat vdpau_format)
175 {
176 switch (vdpau_format) {
177 case VDP_INDEXED_FORMAT_A4I4:
178 return PIPE_FORMAT_A4R4_UNORM;
179 case VDP_INDEXED_FORMAT_I4A4:
180 return PIPE_FORMAT_R4A4_UNORM;
181 case VDP_INDEXED_FORMAT_A8I8:
182 return PIPE_FORMAT_A8R8_UNORM;
183 case VDP_INDEXED_FORMAT_I8A8:
184 return PIPE_FORMAT_R8A8_UNORM;
185 default:
186 assert(0);
187 }
188
189 return PIPE_FORMAT_NONE;
190 }
191
192 static inline enum pipe_format
193 FormatColorTableToPipe(VdpColorTableFormat vdpau_format)
194 {
195 switch(vdpau_format) {
196 case VDP_COLOR_TABLE_FORMAT_B8G8R8X8:
197 return PIPE_FORMAT_B8G8R8X8_UNORM;
198 default:
199 assert(0);
200 }
201 return PIPE_FORMAT_NONE;
202 }
203
204
205 static inline enum pipe_video_profile
206 ProfileToPipe(VdpDecoderProfile vdpau_profile)
207 {
208 switch (vdpau_profile) {
209 case VDP_DECODER_PROFILE_MPEG1:
210 return PIPE_VIDEO_PROFILE_MPEG1;
211 case VDP_DECODER_PROFILE_MPEG2_SIMPLE:
212 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE;
213 case VDP_DECODER_PROFILE_MPEG2_MAIN:
214 return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
215 case VDP_DECODER_PROFILE_H264_BASELINE:
216 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE;
217 case VDP_DECODER_PROFILE_H264_MAIN: /* Not defined in p_format.h */
218 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN;
219 case VDP_DECODER_PROFILE_H264_HIGH:
220 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
221 default:
222 return PIPE_VIDEO_PROFILE_UNKNOWN;
223 }
224 }
225
226 static inline VdpDecoderProfile
227 PipeToProfile(enum pipe_video_profile p_profile)
228 {
229 switch (p_profile) {
230 case PIPE_VIDEO_PROFILE_MPEG1:
231 return VDP_DECODER_PROFILE_MPEG1;
232 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
233 return VDP_DECODER_PROFILE_MPEG2_SIMPLE;
234 case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
235 return VDP_DECODER_PROFILE_MPEG2_MAIN;
236 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
237 return VDP_DECODER_PROFILE_H264_BASELINE;
238 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN: /* Not defined in p_format.h */
239 return VDP_DECODER_PROFILE_H264_MAIN;
240 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
241 return VDP_DECODER_PROFILE_H264_HIGH;
242 default:
243 assert(0);
244 return -1;
245 }
246 }
247
248 static inline struct pipe_video_rect *
249 RectToPipe(const VdpRect *src, struct pipe_video_rect *dst)
250 {
251 if (src) {
252 dst->x = MIN2(src->x1, src->x0);
253 dst->y = MIN2(src->y1, src->y0);
254 dst->w = abs(src->x1 - src->x0);
255 dst->h = abs(src->y1 - src->y0);
256 return dst;
257 }
258 return NULL;
259 }
260
261 typedef struct
262 {
263 struct vl_screen *vscreen;
264 struct vl_context *context;
265 struct vl_compositor compositor;
266 } vlVdpDevice;
267
268 typedef struct
269 {
270 vlVdpDevice *device;
271 Drawable drawable;
272 } vlVdpPresentationQueueTarget;
273
274 typedef struct
275 {
276 vlVdpDevice *device;
277 Drawable drawable;
278 struct vl_compositor compositor;
279 } vlVdpPresentationQueue;
280
281 typedef struct
282 {
283 vlVdpDevice *device;
284 struct vl_compositor compositor;
285 } vlVdpVideoMixer;
286
287 typedef struct
288 {
289 vlVdpDevice *device;
290 struct pipe_video_buffer *video_buffer;
291 } vlVdpSurface;
292
293 typedef struct
294 {
295 vlVdpDevice *device;
296 struct pipe_surface *surface;
297 struct pipe_sampler_view *sampler_view;
298 } vlVdpOutputSurface;
299
300 typedef struct
301 {
302 vlVdpDevice *device;
303 struct pipe_video_decoder *decoder;
304 unsigned num_buffers;
305 void **buffers;
306 unsigned cur_buffer;
307 } vlVdpDecoder;
308
309 typedef uint32_t vlHandle;
310
311 boolean vlCreateHTAB(void);
312 void vlDestroyHTAB(void);
313 vlHandle vlAddDataHTAB(void *data);
314 void* vlGetDataHTAB(vlHandle handle);
315 void vlRemoveDataHTAB(vlHandle handle);
316
317 boolean vlGetFuncFTAB(VdpFuncId function_id, void **func);
318
319 /* Public functions */
320 VdpDeviceCreateX11 vdp_imp_device_create_x11;
321 VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11;
322
323 /* Internal function pointers */
324 VdpGetErrorString vlVdpGetErrorString;
325 VdpDeviceDestroy vlVdpDeviceDestroy;
326 VdpGetProcAddress vlVdpGetProcAddress;
327 VdpGetApiVersion vlVdpGetApiVersion;
328 VdpGetInformationString vlVdpGetInformationString;
329 VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities;
330 VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities;
331 VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities;
332 VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities;
333 VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities;
334 VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities;
335 VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities;
336 VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities;
337 VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport;
338 VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport;
339 VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange;
340 VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport;
341 VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange;
342 VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate;
343 VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy;
344 VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters;
345 VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr;
346 VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr;
347 VdpDecoderCreate vlVdpDecoderCreate;
348 VdpDecoderDestroy vlVdpDecoderDestroy;
349 VdpDecoderGetParameters vlVdpDecoderGetParameters;
350 VdpDecoderRender vlVdpDecoderRender;
351 VdpOutputSurfaceCreate vlVdpOutputSurfaceCreate;
352 VdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy;
353 VdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters;
354 VdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative;
355 VdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative;
356 VdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed;
357 VdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr;
358 VdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface;
359 VdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface;
360 VdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate;
361 VdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy;
362 VdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters;
363 VdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative;
364 VdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy;
365 VdpPresentationQueueCreate vlVdpPresentationQueueCreate;
366 VdpPresentationQueueDestroy vlVdpPresentationQueueDestroy;
367 VdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor;
368 VdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor;
369 VdpPresentationQueueGetTime vlVdpPresentationQueueGetTime;
370 VdpPresentationQueueDisplay vlVdpPresentationQueueDisplay;
371 VdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle;
372 VdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus;
373 VdpPreemptionCallback vlVdpPreemptionCallback;
374 VdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister;
375 VdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables;
376 VdpVideoMixerCreate vlVdpVideoMixerCreate;
377 VdpVideoMixerRender vlVdpVideoMixerRender;
378 VdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues;
379 VdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport;
380 VdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables;
381 VdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues;
382 VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues;
383 VdpVideoMixerDestroy vlVdpVideoMixerDestroy;
384 VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix;
385
386 #define VDPAU_OUT 0
387 #define VDPAU_ERR 1
388 #define VDPAU_WARN 2
389 #define VDPAU_TRACE 3
390
391 static inline void VDPAU_MSG(unsigned int level, const char *fmt, ...)
392 {
393 static int debug_level = -1;
394
395 if (debug_level == -1) {
396 debug_level = MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0);
397 }
398
399 if (level <= debug_level) {
400 va_list ap;
401 va_start(ap, fmt);
402 _debug_vprintf(fmt, ap);
403 va_end(ap);
404 }
405 }
406
407 #endif // VDPAU_PRIVATE_H