Initial code release
[pkgs/xorg/lib/libXvMC.git] / packaging / 1.0.6-updates.patch
1 diff --git a/Makefile.am b/Makefile.am
2 index a733b52..bc315df 100644
3 --- a/Makefile.am
4 +++ b/Makefile.am
5 @@ -19,7 +19,7 @@
6  #  TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
7  #  PERFORMANCE OF THIS SOFTWARE.
8  
9 -SUBDIRS = src include
10 +SUBDIRS = src include wrapper
11  
12  pkgconfigdir = $(libdir)/pkgconfig
13  pkgconfig_DATA = xvmc.pc
14 diff --git a/configure.ac b/configure.ac
15 index 6a904dd..5fb8113 100644
16 --- a/configure.ac
17 +++ b/configure.ac
18 @@ -1,59 +1,60 @@
19 -dnl  Copyright 2005 Red Hat, Inc.
20 -dnl 
21 -dnl  Permission to use, copy, modify, distribute, and sell this software and its
22 -dnl  documentation for any purpose is hereby granted without fee, provided that
23 -dnl  the above copyright notice appear in all copies and that both that
24 -dnl  copyright notice and this permission notice appear in supporting
25 -dnl  documentation, and that the name of Red Hat not be used in
26 -dnl  advertising or publicity pertaining to distribution of the software without
27 -dnl  specific, written prior permission.  Red Hat makes no
28 -dnl  representations about the suitability of this software for any purpose.  It
29 -dnl  is provided "as is" without express or implied warranty.
30 -dnl 
31 -dnl  RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
32 -dnl  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
33 -dnl  EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
34 -dnl  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
35 -dnl  DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
36 -dnl  TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
37 -dnl  PERFORMANCE OF THIS SOFTWARE.
38 -dnl
39 -dnl Process this file with autoconf to create configure.
40 -
41 +#  Copyright 2005 Red Hat, Inc.
42 +#
43 +#  Permission to use, copy, modify, distribute, and sell this software and its
44 +#  documentation for any purpose is hereby granted without fee, provided that
45 +#  the above copyright notice appear in all copies and that both that
46 +#  copyright notice and this permission notice appear in supporting
47 +#  documentation, and that the name of Red Hat not be used in
48 +#  advertising or publicity pertaining to distribution of the software without
49 +#  specific, written prior permission.  Red Hat makes no
50 +#  representations about the suitability of this software for any purpose.  It
51 +#  is provided "as is" without express or implied warranty.
52 +#
53 +#  RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
54 +#  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
55 +#  EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
56 +#  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
57 +#  DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
58 +#  TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
59 +#  PERFORMANCE OF THIS SOFTWARE.
60 +#
61 +
62 +# Initialize Autoconf
63  AC_PREREQ([2.60])
64 +AC_INIT([libXvMC], [1.0.6],
65 +       [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [libXvMC])
66 +AC_CONFIG_SRCDIR([Makefile.am])
67 +AC_CONFIG_HEADERS([config.h])
68  
69 -AC_INIT([libXvMC],
70 -       [1.0.6],
71 -       [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
72 -       [libXvMC])
73 +# Initialize Automake
74  AM_INIT_AUTOMAKE([foreign dist-bzip2])
75  AM_MAINTAINER_MODE
76  
77 -# Require xorg-macros: XORG_DEFAULT_OPTIONS
78 +# Initialize libtool
79 +AC_PROG_LIBTOOL
80 +
81 +# Require X.Org macros 1.8 or later for AC_PROG_INSTALL
82  m4_ifndef([XORG_MACROS_VERSION],
83 -          [m4_fatal([must install xorg-macros 1.3 or later before running autoconf/autogen])])
84 -XORG_MACROS_VERSION(1.3)
85 +          [m4_fatal([must install xorg-macros 1.8 or later before running autoconf/autogen])])
86 +XORG_MACROS_VERSION(1.8)
87  XORG_DEFAULT_OPTIONS
88 -AM_CONFIG_HEADER(config.h)
89 -
90 -# Check for progs
91 -AC_PROG_LIBTOOL
92 +XORG_CHECK_MALLOC_ZERO
93  
94 -# Check for dependencies
95 +# Obtain compiler/linker options for depedencies
96  PKG_CHECK_MODULES(XVMC, x11 xext xv xextproto videoproto)
97  
98 -AC_CHECK_FUNC([shmat], AC_DEFINE(HAS_SHM,1,[Has shm*() functions]))
99 +# Checks for library functions.
100 +AC_CHECK_FUNCS([shmat])
101                   
102 -XORG_CHECK_MALLOC_ZERO
103 -
104 -dnl Allow checking code with lint, sparse, etc.
105 +# Allow checking code with lint, sparse, etc.
106  XORG_WITH_LINT
107  LINT_FLAGS="${LINT_FLAGS} ${XVMC_CFLAGS}"
108  
109 -
110 -AC_OUTPUT([Makefile
111 -           include/Makefile
112 -          include/X11/Makefile
113 -          include/X11/extensions/Makefile
114 -          src/Makefile
115 -           xvmc.pc])
116 +AC_CONFIG_FILES([Makefile
117 +               include/Makefile
118 +               include/X11/Makefile
119 +               include/X11/extensions/Makefile
120 +               src/Makefile
121 +               wrapper/Makefile
122 +               xvmc.pc])
123 +AC_OUTPUT
124 diff --git a/src/Makefile.am b/src/Makefile.am
125 index 741e7c5..05284fe 100644
126 --- a/src/Makefile.am
127 +++ b/src/Makefile.am
128 @@ -1,34 +1,16 @@
129 -lib_LTLIBRARIES = libXvMC.la libXvMCW.la
130 +lib_LTLIBRARIES = libXvMC.la
131  
132 -libXvMC_la_SOURCES = \
133 -         XvMC.c \
134 -         XvMClibint.h
135 -
136 -libXvMCW_la_SOURCES = \
137 -       XvMCWrapper.c
138 -
139 -AM_CFLAGS = $(CWARNFLAGS) @XVMC_CFLAGS@
140 -AM_CPPFLAGS = -I$(top_srcdir)/include @MALLOC_ZERO_CFLAGS@
141 -
142 -libXvMC_la_LIBADD = @XVMC_LIBS@
143 -libXvMC_la_CFLAGS = $(AM_CFLAGS)
144 -
145 -libXvMCW_la_LIBADD = @XVMC_LIBS@
146 -libXvMCW_la_CFLAGS =                           \
147 -       $(AM_CFLAGS)                            \
148 -       -DXVMC_CONFIGDIR=$(sysconfdir)/X11              \
149 -       -DXVMC_SOVERSION=\".1.0\"               \
150 -       -DXV_SOVERSION=\".1.0\"
151 +AM_CPPFLAGS = -I$(top_srcdir)/include $(MALLOC_ZERO_CFLAGS)
152 +AM_CFLAGS = $(CWARNFLAGS) $(XVMC_CFLAGS)
153  
154 +libXvMC_la_SOURCES = XvMC.c XvMClibint.h
155 +libXvMC_la_LIBADD = $(XVMC_LIBS)
156  libXvMC_la_LDFLAGS = -version-number 1:0:0 -no-undefined
157 -libXvMCW_la_LDFLAGS = -version-number 1:0:0 -no-undefined
158 -
159  
160  if LINT
161 -ALL_LINT_FLAGS=$(LINT_FLAGS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
162 +ALL_LINT_FLAGS=$(LINT_FLAGS) $(DEFS) $(DEFAULT_INCLUDES) \
163                  $(AM_CPPFLAGS) $(CPPFLAGS)
164  
165  lint:
166 -       $(LINT) $(ALL_LINT_FLAGS) $(libXvMC_la_SOURCES) $(XVMC_LIBS)
167 -       $(LINT) $(ALL_LINT_FLAGS) $(libXvMCW_la_CFLAGS) $(libXvMCW_la_SOURCES) $(XVMC_LIBS)
168 +       $(LINT) $(ALL_LINT_FLAGS) $(libXvMC_la_SOURCES) $(AM_CFLAGS) $(XVMC_LIBS)
169  endif LINT
170 diff --git a/src/XvMC.c b/src/XvMC.c
171 index 3bf5a43..eb8e7e8 100644
172 --- a/src/XvMC.c
173 +++ b/src/XvMC.c
174 @@ -3,7 +3,7 @@
175  #endif
176  #include <stdio.h>
177  #include "XvMClibint.h"
178 -#ifdef HAS_SHM
179 +#ifdef HAVE_SHMAT
180  #ifndef Lynx
181  #include <sys/ipc.h>
182  #include <sys/shm.h>
183 @@ -11,7 +11,7 @@
184  #include <ipc.h>
185  #include <shm.h>
186  #endif /* Lynx */
187 -#endif /* HAS_SHM */
188 +#endif /* HAVE_SHMAT */
189  #include <unistd.h>
190  #include <sys/time.h>
191  #include <X11/extensions/Xext.h>
192 @@ -487,7 +487,7 @@ Status XvMCGetDRInfo(Display *dpy, XvPortID port,
193      char *tmpBuf = NULL;
194      CARD32 magic;
195  
196 -#ifdef HAS_SHM
197 +#ifdef HAVE_SHMAT
198      volatile CARD32 *shMem;
199      struct timezone here;
200      struct timeval now;
201 @@ -503,7 +503,7 @@ Status XvMCGetDRInfo(Display *dpy, XvPortID port,
202      req->port = port;
203      magic = 0;
204      req->magic = 0;
205 -#ifdef HAS_SHM 
206 +#ifdef HAVE_SHMAT
207      req->shmKey = shmget(IPC_PRIVATE, 1024, IPC_CREAT | 0600);
208  
209      /*
210 @@ -541,14 +541,14 @@ Status XvMCGetDRInfo(Display *dpy, XvPortID port,
211      if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
212          UnlockDisplay (dpy);
213          SyncHandle ();
214 -#ifdef HAS_SHM
215 +#ifdef HAVE_SHMAT
216         if ( req->shmKey >= 0) {
217             shmdt( (const void *) shMem );
218         }            
219  #endif
220          return -1;
221      }
222 -#ifdef HAS_SHM
223 +#ifdef HAVE_SHMAT
224      shmdt( (const void *) shMem );
225  #endif
226  
227 diff --git a/src/XvMCWrapper.c b/src/XvMCWrapper.c
228 deleted file mode 100644
229 index d3800e7..0000000
230 --- a/src/XvMCWrapper.c
231 +++ /dev/null
232 @@ -1,781 +0,0 @@
233 -/*****************************************************************************
234 - * XvMC Wrapper including the Nonstandard VLD extension.
235 - *
236 - * Copyright (c) 2004 The Unichrome project. All rights reserved.
237 - *
238 - *
239 - * Permission is hereby granted, free of charge, to any person obtaining a
240 - * copy of this software and associated documentation files (the "Software"),
241 - * to deal in the Software without restriction, including without limitation
242 - * the rights to use, copy, modify, merge, publish, distribute, sublicense,
243 - * and/or sell copies of the Software, and to permit persons to whom the
244 - * Software is furnished to do so, subject to the following conditions:
245 - *
246 - * The above copyright notice and this permission notice shall be included in
247 - * all copies or substantial portions of the Software.
248 - *
249 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
250 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
251 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
252 - * AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
253 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
254 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
255 - * DEALINGS IN THE SOFTWARE.
256 - *
257 - * Author: Thomas Hellström (2004)
258 - */
259 -
260 -/*
261 - * BUGS: The wrapper really should maintain one symbol table per port. This 
262 - * could possibly be impemented, To do that, the port-independent symbols need to be lifted out,
263 - * and one would have to create a number of mapping tables:
264 - *
265 - *                 port  -> symbol table
266 - *                 context -> port
267 - *                 surface -> port
268 - *                 subpicture -> port
269 - *
270 - * and reference the right table when needed. 
271 - * This needs to be done only if there is a player that wants to access two displays with different
272 - * hardware simultaneously. Not likely as of today.
273 - */
274 -
275 -#ifdef HAVE_CONFIG_H
276 -  #include "config.h"
277 -#endif
278 -
279 -#include <X11/Xlib.h>
280 -#include <X11/extensions/XvMC.h>
281 -#include <X11/extensions/XvMClib.h>
282 -#include <X11/extensions/vldXvMC.h>
283 -#include <dlfcn.h>
284 -#include <stdio.h>
285 -#include <string.h>
286 -#include <ctype.h>
287 -#include <stdlib.h>
288 -
289 -
290 -typedef Bool (*XvMCQueryExtensionP) (Display *, int *, int *);
291 -typedef Status (*XvMCQueryVersionP) (Display *, int *,int *);
292 -typedef XvMCSurfaceInfo * (*XvMCListSurfaceTypesP)(Display *, XvPortID, int *);
293 -typedef Status (* XvMCCreateContextP) (Display *,XvPortID,int ,int ,int ,int ,XvMCContext * );
294 -typedef Status (*XvMCDestroyContextP) (Display *, XvMCContext * );
295 -typedef Status (*XvMCCreateSurfaceP)(Display *,XvMCContext *,XvMCSurface *);
296 -typedef Status (*XvMCDestroySurfaceP)(Display *, XvMCSurface *);
297 -typedef XvImageFormatValues * (*XvMCListSubpictureTypesP) (Display *,XvPortID ,int ,int *);
298 -typedef Status (*XvMCPutSurfaceP)(Display *,XvMCSurface *,Drawable ,short , short , unsigned short , 
299 -                                 unsigned short ,short ,short ,unsigned short ,unsigned short ,int );
300 -typedef Status (*XvMCHideSurfaceP)(Display *, XvMCSurface *);
301 -typedef Status (*XvMCCreateSubpictureP) (Display *, XvMCContext *, XvMCSubpicture *, 
302 -                                        unsigned short, unsigned short,int);
303 -typedef Status (*XvMCClearSubpictureP) (Display *,XvMCSubpicture *,short,short,unsigned short,unsigned short,
304 -                                       unsigned int);
305 -typedef Status (*XvMCCompositeSubpictureP) (Display *, XvMCSubpicture *,XvImage *,short,short,
306 -                                           unsigned short, unsigned short,short,short);
307 -typedef Status (*XvMCDestroySubpictureP) (Display *, XvMCSubpicture *);
308 -typedef Status (*XvMCSetSubpicturePaletteP) (Display *, XvMCSubpicture *, unsigned char *);
309 -typedef Status (*XvMCBlendSubpictureP) (Display *d,XvMCSurface *,XvMCSubpicture *,short,
310 -                                       short,unsigned short,unsigned short,short,short,
311 -                                       unsigned short,unsigned short);
312 -typedef Status (*XvMCBlendSubpicture2P) (Display *,XvMCSurface *,XvMCSurface *,
313 -                                        XvMCSubpicture *,short,short,unsigned short,
314 -                                        unsigned short,short,short,unsigned short,
315 -                                        unsigned short);
316 -typedef Status (*XvMCSyncSurfaceP) (Display *, XvMCSurface *);
317 -typedef Status (*XvMCFlushSurfaceP) (Display *, XvMCSurface *);
318 -typedef Status (*XvMCGetSurfaceStatusP) (Display *, XvMCSurface *, int *);
319 -typedef Status (*XvMCRenderSurfaceP) (Display *,XvMCContext *,unsigned int,XvMCSurface *,
320 -                                     XvMCSurface *,XvMCSurface *,unsigned int,unsigned int,
321 -                                     unsigned int,XvMCMacroBlockArray *,XvMCBlockArray *);
322 -typedef Status (*XvMCSyncSubpictureP) (Display *, XvMCSubpicture *);
323 -typedef Status (*XvMCFlushSubpictureP) (Display *, XvMCSubpicture *);
324 -typedef Status (*XvMCGetSubpictureStatusP) (Display *, XvMCSubpicture *, int *);
325 -typedef Status (*XvMCCreateBlocksP) (Display *, XvMCContext *,unsigned int,XvMCBlockArray *);
326 -typedef Status (*XvMCDestroyBlocksP) (Display *,XvMCBlockArray *);
327 -typedef Status (*XvMCCreateMacroBlocksP) (Display *,XvMCContext *,unsigned int,
328 -                                         XvMCMacroBlockArray *);
329 -typedef Status (*XvMCDestroyMacroBlocksP) (Display *,XvMCMacroBlockArray *);
330 -typedef XvAttribute *(*XvMCQueryAttributesP) (Display *,XvMCContext *,int *);
331 -typedef Status (*XvMCSetAttributeP) (Display *,XvMCContext *, Atom, int);
332 -typedef Status (*XvMCGetAttributeP) (Display *,XvMCContext *, Atom, int *);
333 -
334 -/*
335 - * Nonstandard VLD acceleration level:
336 - */ 
337 -  
338 -typedef Status (*XvMCBeginSurfaceP) (Display *,XvMCContext *,XvMCSurface *,
339 -                                    XvMCSurface *,XvMCSurface *f,const XvMCMpegControl *);
340 -typedef Status (*XvMCLoadQMatrixP) (Display *, XvMCContext *,const XvMCQMatrix *);
341 -typedef Status (*XvMCPutSliceP)(Display *,XvMCContext *, char *,int);
342 -typedef Status (*XvMCPutSlice2P)(Display *,XvMCContext *, char *,int, unsigned);
343 -typedef Status (*XvMCGetDRInfoP)(Display *, XvPortID, char **, char **, int *, int *, 
344 -                                 int *, int *);
345 -
346 -
347 -typedef struct {
348 -    XvMCQueryExtensionP   XvMCQueryExtension; 
349 -    XvMCQueryVersionP   XvMCQueryVersion; 
350 -    XvMCListSurfaceTypesP  XvMCListSurfaceTypes;
351 -    XvMCCreateContextP   XvMCCreateContext; 
352 -    XvMCDestroyContextP   XvMCDestroyContext; 
353 -    XvMCCreateSurfaceP  XvMCCreateSurface;
354 -    XvMCDestroySurfaceP  XvMCDestroySurface;
355 -    XvMCListSubpictureTypesP    XvMCListSubpictureTypes; 
356 -    XvMCPutSurfaceP   XvMCPutSurface;
357 -    XvMCHideSurfaceP   XvMCHideSurface;
358 -    XvMCCreateSubpictureP   XvMCCreateSubpicture;
359 -    XvMCClearSubpictureP     XvMCClearSubpicture;                            
360 -    XvMCCompositeSubpictureP    XvMCCompositeSubpicture; 
361 -    XvMCDestroySubpictureP    XvMCDestroySubpicture; 
362 -    XvMCSetSubpicturePaletteP    XvMCSetSubpicturePalette; 
363 -    XvMCBlendSubpictureP    XvMCBlendSubpicture; 
364 -    XvMCBlendSubpicture2P   XvMCBlendSubpicture2;
365 -    XvMCSyncSurfaceP    XvMCSyncSurface; 
366 -    XvMCFlushSurfaceP    XvMCFlushSurface; 
367 -    XvMCGetSurfaceStatusP    XvMCGetSurfaceStatus; 
368 -    XvMCRenderSurfaceP    XvMCRenderSurface; 
369 -    XvMCSyncSubpictureP    XvMCSyncSubpicture; 
370 -    XvMCFlushSubpictureP    XvMCFlushSubpicture; 
371 -    XvMCGetSubpictureStatusP    XvMCGetSubpictureStatus; 
372 -    XvMCCreateBlocksP    XvMCCreateBlocks; 
373 -    XvMCDestroyBlocksP    XvMCDestroyBlocks; 
374 -    XvMCCreateMacroBlocksP   XvMCCreateMacroBlocks;
375 -    XvMCDestroyMacroBlocksP    XvMCDestroyMacroBlocks; 
376 -    XvMCQueryAttributesP    XvMCQueryAttributes; 
377 -    XvMCSetAttributeP    XvMCSetAttribute; 
378 -    XvMCGetAttributeP    XvMCGetAttribute; 
379 -
380 -    /*
381 -     * Nonstandard VLD acceleration level:
382 -     */ 
383 -  
384 -    XvMCBeginSurfaceP    XvMCBeginSurface; 
385 -    XvMCLoadQMatrixP    XvMCLoadQMatrix; 
386 -    XvMCPutSliceP   XvMCPutSlice;
387 -    XvMCPutSlice2P   XvMCPutSlice2;
388 -
389 -    /*
390 -     * Driver name function.
391 -     */
392 -
393 -    XvMCGetDRInfoP XvMCGetDRInfo;
394 -
395 -    int preInitialised;
396 -    int initialised;
397 -    int vldextension;
398 -} XvMCWrapper;
399 -
400 -static XvMCWrapper xW;
401 -static int wrapperInit = 0;
402 -static int wrapperPreInit = 0;
403 -static void *xvhandle;
404 -static void *handle2;
405 -
406 -#define BUFLEN 200
407 -
408 -#define STRS(ARG) STR(ARG)
409 -#define STR(ARG) #ARG
410 -
411 -#define XW_RSYM(base,handle,handle2,pointer, retval)                   \
412 -    do {                                                               \
413 -       register char *err;                                             \
414 -       base.pointer = (pointer##P) dlsym((handle),#pointer);           \
415 -       if ((err = dlerror()) != NULL) {                                \
416 -           if (!handle2) {                                             \
417 -               fprintf(stderr,"%s\n",err); return retval;              \
418 -           }                                                           \
419 -           base.pointer = (pointer##P) dlsym((handle2),#pointer);      \
420 -           if ((err = dlerror()) != NULL) {                            \
421 -               fprintf(stderr,"%s\n",err); return retval;              \
422 -           }                                                           \
423 -       }                                                               \
424 -    } while (0);
425 -
426 -#define XW_RSYM2(base,handle,handle2,pointer)                  \
427 -    base.pointer = (pointer##P) dlsym((handle),#pointer);      \
428 -    if (dlerror() != NULL) {                                   \
429 -       base.pointer = (pointer##P) dlsym((handle2),#pointer);  \
430 -       if (dlerror() != NULL) return;                          \
431 -    }                                                  
432 -
433 -
434 -/*
435 - * Try to dlopen a shared library, versionless first.
436 - */
437 -
438 -
439 -static void  *dlopenversion(const char *lib, const char *version, int flag) 
440 -{
441 -  void *ret;
442 -  int curLen,verLen;
443 -  char *curName;
444 -  const char *tail;
445 -
446 -  
447 -  curLen = strlen(lib) + (verLen = strlen(version)) + 1;
448 -  curName = (char *) malloc(curLen * sizeof(char));
449 -  strncpy( curName, lib, curLen);
450 -  if (verLen > 1) {
451 -    if (NULL != (tail = strstr(version+1,"."))) {
452 -      strncat( curName, version, tail - version);
453 -    } else {
454 -      strncat( curName, version, verLen);
455 -    }
456 -  }
457 -  ret = dlopen(curName, flag);
458 -  free(curName);
459 -  return ret;
460 -}
461 -
462 -static int preInitW(Display *dpy) 
463 -{
464 -
465 -    /*
466 -     * Resolve functions that are not hw driver specific.
467 -     */
468 -
469 -    void *handleZ = NULL;
470 -
471 -    wrapperPreInit = 1;
472 -    xW.preInitialised = 0;
473 -    xW.initialised = 0;
474 -    xvhandle = dlopenversion("libXv.so", XV_SOVERSION, RTLD_LAZY | RTLD_GLOBAL);
475 -    if (!xvhandle) {
476 -       fprintf(stderr,"XvMCWrapper: Warning! Could not open shared "
477 -               "library \"libXv.so" XV_SOVERSION "\"\nThis may cause relocation "
478 -               "errors later.\nError was: \"%s\".\n",dlerror());
479 -    } 
480 -    handle2 = dlopenversion("libXvMC.so", XVMC_SOVERSION, RTLD_LAZY | RTLD_GLOBAL);
481 -    if (!handle2) {
482 -       fprintf(stderr,"XvMCWrapper: Could not load XvMC "
483 -               "library \"libXvMC.so" XVMC_SOVERSION "\". Failing\n");
484 -       fprintf(stderr,"%s\n",dlerror());
485 -       return 1;
486 -    }
487 -    XW_RSYM(xW, handle2, handleZ, XvMCQueryExtension, 1);
488 -    XW_RSYM(xW, handle2, handleZ, XvMCQueryVersion, 1);
489 -    xW.preInitialised = 1;
490 -    return 0;
491 -}
492 -
493 -static void initW(Display *dpy, XvPortID port) 
494 -{
495 -    char nameBuffer[BUFLEN];
496 -    void *handle;
497 -    int tmp;
498 -    char *clientName = NULL;
499 -    char *err;
500 -    FILE *configFile; 
501 -    int nameLen = 0;
502 -    int major,minor,patchLevel,isLocal;
503 -    char *busID = NULL;
504 -
505 -    wrapperInit = 1;
506 -    xW.initialised = 0;
507 -
508 -    if (!wrapperPreInit) 
509 -       if (preInitW( dpy )) return;
510 -
511 -    /*
512 -     * Will the DDX tell us the client driver name?
513 -     */ 
514 -
515 -    xW.XvMCGetDRInfo = (XvMCGetDRInfoP)
516 -       dlsym(handle2,"XvMCGetDRInfo");
517 -
518 -    if ((err = dlerror()) == NULL) {
519 -       if (0 == xW.XvMCGetDRInfo( dpy, port, &clientName, &busID, &major, 
520 -                                   &minor,&patchLevel, &isLocal)) {
521 -           nameLen = strlen(clientName);
522 -           XFree(busID);
523 -           if (!isLocal) {
524 -               fprintf(stderr,"XvMCWrapper: X server is not local. Cannot run XvMC.\n");
525 -               XFree(clientName);
526 -               return;
527 -           }
528 -       } else {
529 -           clientName = NULL;
530 -       }
531 -    } 
532 -
533 -    if (clientName && (nameLen < BUFLEN-7) && (nameLen > 0)) {
534 -       nameLen += 3;
535 -       strncpy(nameBuffer,"lib",BUFLEN-1);
536 -       strncpy(nameBuffer+3, clientName, BUFLEN-4);
537 -       strncpy(nameBuffer + nameLen, ".so", BUFLEN-nameLen-1);
538 -       nameBuffer[BUFLEN-1] = 0;
539 -       XFree(clientName);
540 -       handle = dlopenversion(nameBuffer, XVMC_SOVERSION,RTLD_LAZY);
541 -    } else {
542 -       /*
543 -        * No. Try to obtain it from the config file.
544 -        */
545 -      
546 -       if (clientName) XFree(clientName);
547 -
548 -       configFile = fopen(STRS(XVMC_CONFIGDIR) "/XvMCConfig","r");
549 -      
550 -       xW.initialised = 0;
551 -       xW.vldextension = 0;
552 -
553 -       if (NULL == configFile) {
554 -           fprintf(stderr,"XvMCWrapper: Could not open config file \"%s\".\n",
555 -                   STRS(XVMC_CONFIGDIR) "/XvMCConfig");
556 -           perror("XvMCWrapper");
557 -           return;
558 -       }
559 -
560 -       if (NULL == fgets(nameBuffer, BUFLEN, configFile)) {
561 -           fclose(configFile);
562 -           fprintf(stderr,"XvMCWrapper: Could not read XvMC library name.\n");
563 -           perror("XvMCWrapper");
564 -           return;
565 -       }
566 -       
567 -       fclose(configFile);
568 -       if ((tmp = strlen(nameBuffer)) == 0) {
569 -           fprintf(stderr,"XvMCWrapper: Zero length XvMC library name.\n");
570 -           fprintf(stderr,"%s\n",dlerror());
571 -           return;
572 -       }
573 -
574 -       /*
575 -        * Skip trailing newlines and garbage.
576 -        */
577 -       
578 -       while (iscntrl(nameBuffer[tmp-1])) {
579 -           nameBuffer[tmp-1] = 0;
580 -           if (--tmp == 0) {
581 -               fprintf(stderr,"XvMCWrapper: Zero length XvMC library name.\n");
582 -               return;
583 -           }
584 -       }
585 -       handle = dlopen(nameBuffer,RTLD_LAZY);
586 -    }
587 -    if (!handle) {
588 -       fprintf(stderr,"XvMCWrapper: Could not load hardware specific XvMC "
589 -               "library \"%s\".\n",nameBuffer);
590 -       fprintf(stderr,"%s\n",dlerror());
591 -       return;
592 -    }
593 -
594 -    XW_RSYM(xW, handle, handle2, XvMCListSurfaceTypes,);
595 -    XW_RSYM(xW, handle, handle2, XvMCCreateContext,);
596 -    XW_RSYM(xW, handle, handle2, XvMCDestroyContext,);
597 -    XW_RSYM(xW, handle, handle2, XvMCCreateSurface,);
598 -    XW_RSYM(xW, handle, handle2, XvMCDestroySurface,);
599 -    XW_RSYM(xW, handle, handle2, XvMCListSubpictureTypes,);
600 -    XW_RSYM(xW, handle, handle2, XvMCHideSurface,);
601 -    XW_RSYM(xW, handle, handle2, XvMCCreateSubpicture,);
602 -    XW_RSYM(xW, handle, handle2, XvMCClearSubpicture,);
603 -    XW_RSYM(xW, handle, handle2, XvMCCompositeSubpicture,);
604 -    XW_RSYM(xW, handle, handle2, XvMCDestroySubpicture,);
605 -    XW_RSYM(xW, handle, handle2, XvMCSetSubpicturePalette,);
606 -    XW_RSYM(xW, handle, handle2, XvMCBlendSubpicture,);
607 -    XW_RSYM(xW, handle, handle2, XvMCBlendSubpicture2,);
608 -    XW_RSYM(xW, handle, handle2, XvMCPutSurface,);
609 -    XW_RSYM(xW, handle, handle2, XvMCSyncSurface,);
610 -    XW_RSYM(xW, handle, handle2, XvMCFlushSurface,);
611 -    XW_RSYM(xW, handle, handle2, XvMCGetSurfaceStatus,);
612 -    XW_RSYM(xW, handle, handle2, XvMCRenderSurface,);
613 -    XW_RSYM(xW, handle, handle2, XvMCSyncSubpicture,);
614 -    XW_RSYM(xW, handle, handle2, XvMCFlushSubpicture,);
615 -    XW_RSYM(xW, handle, handle2, XvMCGetSubpictureStatus,);
616 -    XW_RSYM(xW, handle, handle2, XvMCCreateBlocks,);
617 -    XW_RSYM(xW, handle, handle2, XvMCDestroyBlocks,);
618 -    XW_RSYM(xW, handle, handle2, XvMCCreateMacroBlocks,);
619 -    XW_RSYM(xW, handle, handle2, XvMCDestroyMacroBlocks,);
620 -    XW_RSYM(xW, handle, handle2, XvMCQueryAttributes,);
621 -    XW_RSYM(xW, handle, handle2, XvMCSetAttribute,);
622 -    XW_RSYM(xW, handle, handle2, XvMCGetAttribute,);
623 -    xW.initialised = 1;
624 -    XW_RSYM2(xW, handle, handle2, XvMCBeginSurface);
625 -    XW_RSYM(xW, handle, handle2, XvMCLoadQMatrix,);
626 -    XW_RSYM(xW, handle, handle2, XvMCPutSlice,);
627 -    XW_RSYM(xW, handle, handle2, XvMCPutSlice2,);
628 -    xW.vldextension = 1;
629 -}
630 -
631 -
632 -Bool XvMCQueryExtension (Display *display, int *eventBase, int *errBase)
633 -{
634 -    if (!wrapperPreInit) preInitW( display );
635 -    if (!xW.preInitialised) return 0;
636 -    return (*xW.XvMCQueryExtension)(display, eventBase, errBase);
637 -}
638 -
639 -Status XvMCQueryVersion (Display *display, int *major_versionp,
640 -                        int *minor_versionp)
641 -{
642 -    if (!wrapperPreInit) preInitW( display );
643 -    if (!xW.preInitialised) return 0;
644 -    return (*xW.XvMCQueryVersion)(display, major_versionp, minor_versionp);
645 -}
646 -
647 -
648 -XvMCSurfaceInfo * XvMCListSurfaceTypes(Display *dpy, XvPortID port, int *num) 
649 -{
650 -    if (!wrapperInit) initW( dpy, port);
651 -    if (!xW.initialised) return NULL;
652 -    return (*xW.XvMCListSurfaceTypes)(dpy, port, num);
653 -}
654 -
655 -Status XvMCCreateContext (
656 -    Display *display,
657 -    XvPortID port,
658 -    int surface_type_id,
659 -    int width,
660 -    int height,
661 -    int flags,
662 -    XvMCContext * context
663 -    )
664 -{
665 -    if (!wrapperInit) initW(display, port);
666 -    if (!xW.initialised) return BadValue;
667 -    return (*xW.XvMCCreateContext)(display, port, surface_type_id,
668 -                                  width, height, flags, context);
669 -}
670 -
671 -Status XvMCDestroyContext (Display *display, XvMCContext * context)
672 -{
673 -    if (!xW.initialised) return BadValue;
674 -    return (*xW.XvMCDestroyContext)(display, context);
675 -}
676 -
677 -Status 
678 -XvMCCreateSurface(
679 -    Display *display,
680 -    XvMCContext * context,
681 -    XvMCSurface * surface
682 -    )
683 -{
684 -    if (!xW.initialised) return BadValue;
685 -    return (*xW.XvMCCreateSurface)(display, context, surface);
686 -}
687 -
688 -Status XvMCDestroySurface(Display *display, XvMCSurface *surface)
689 -{
690 -    if (!xW.initialised) return BadValue;
691 -    return (*xW.XvMCDestroySurface)(display, surface);
692 -}
693 -
694 -
695 -XvImageFormatValues * XvMCListSubpictureTypes (
696 -    Display * display,
697 -    XvPortID port,
698 -    int surface_type_id,
699 -    int *count_return
700 -    )
701 -{
702 -    if (!xW.initialised) return NULL;
703 -    return (*xW.XvMCListSubpictureTypes)(display, port, surface_type_id,
704 -                                        count_return);
705 -}
706 -
707 -
708 -Status
709 -XvMCPutSurface(
710 -    Display *display,
711 -    XvMCSurface *surface,
712 -    Drawable draw,
713 -    short srcx, 
714 -    short srcy, 
715 -    unsigned short srcw, 
716 -    unsigned short srch,
717 -    short destx,
718 -    short desty,
719 -    unsigned short destw,
720 -    unsigned short desth,
721 -    int flags
722 -    )
723 -{
724 -    if (!xW.initialised) return BadValue;
725 -    return (*xW.XvMCPutSurface)(display, surface, draw, srcx, srcy, srcw, srch,
726 -                               destx, desty, destw, desth, flags);
727 -}
728 -
729 -Status XvMCHideSurface(Display *display, XvMCSurface *surface)
730 -{
731 -    if (!xW.initialised) return BadValue;
732 -    return (*xW.XvMCHideSurface)(display, surface);
733 -}
734 -
735 -
736 -Status
737 -XvMCCreateSubpicture (
738 -    Display *display, 
739 -    XvMCContext *context,
740 -    XvMCSubpicture *subpicture, 
741 -    unsigned short width,
742 -    unsigned short height,
743 -    int xvimage_id
744 -    )
745 -{
746 -    if (!xW.initialised) return BadValue;
747 -    return (*xW.XvMCCreateSubpicture)(display, context, subpicture, width, height,
748 -                                     xvimage_id);
749 -}
750 -
751 -
752 -Status
753 -XvMCClearSubpicture (
754 -    Display *display,
755 -    XvMCSubpicture *subpicture,
756 -    short x,
757 -    short y,
758 -    unsigned short width,
759 -    unsigned short height,
760 -    unsigned int color
761 -    )
762 -{
763 -    if (!xW.initialised) return BadValue;
764 -    return (*xW.XvMCClearSubpicture)(display, subpicture, x, y, width, height, color);
765 -}
766 -
767 -
768 -Status
769 -XvMCCompositeSubpicture (
770 -    Display *display,
771 -    XvMCSubpicture *subpicture,
772 -    XvImage *image,
773 -    short srcx,
774 -    short srcy,
775 -    unsigned short width,
776 -    unsigned short height,
777 -    short dstx,
778 -    short dsty
779 -    )
780 -{
781 -    if (!xW.initialised) return BadValue;
782 -    return (*xW.XvMCCompositeSubpicture)(display, subpicture, image, srcx, srcy,
783 -                                        width, height, dstx, dsty);
784 -}
785 -
786 -Status
787 -XvMCDestroySubpicture (Display *display, XvMCSubpicture *subpicture)
788 -{
789 -    if (!xW.initialised) return BadValue;
790 -    return (*xW.XvMCDestroySubpicture)(display, subpicture);
791 -}
792 -
793 -Status
794 -XvMCSetSubpicturePalette (
795 -    Display *display, 
796 -    XvMCSubpicture *subpicture, 
797 -    unsigned char *palette
798 -    )
799 -{
800 -    if (!xW.initialised) return BadValue;
801 -    return (*xW.XvMCSetSubpicturePalette)(display, subpicture, palette);
802 -}
803 -
804 -
805 -Status
806 -XvMCBlendSubpicture (
807 -    Display *display,
808 -    XvMCSurface *target_surface,
809 -    XvMCSubpicture *subpicture,
810 -    short subx,
811 -    short suby,
812 -    unsigned short subw,
813 -    unsigned short subh,
814 -    short surfx,
815 -    short surfy,
816 -    unsigned short surfw,
817 -    unsigned short surfh
818 -    )
819 -{
820 -    if (!xW.initialised) return BadValue;
821 -    return (*xW.XvMCBlendSubpicture)(display, target_surface, subpicture,
822 -                                    subx, suby, subw, subh, surfx, surfy,
823 -                                    surfw, surfh);
824 -}
825 -
826 -Status
827 -XvMCBlendSubpicture2 (
828 -    Display *display,
829 -    XvMCSurface *source_surface,
830 -    XvMCSurface *target_surface,
831 -    XvMCSubpicture *subpicture,
832 -    short subx,
833 -    short suby,
834 -    unsigned short subw,
835 -    unsigned short subh,
836 -    short surfx,
837 -    short surfy,
838 -    unsigned short surfw,
839 -    unsigned short surfh
840 -    )
841 -{
842 -    if (!xW.initialised) return BadValue;
843 -    return (*xW.XvMCBlendSubpicture2)(display, source_surface, target_surface, subpicture,
844 -                                     subx, suby, subw, subh, surfx, surfy, surfw, surfh);
845 -}
846 -
847 -
848 -Status XvMCSyncSurface (Display *display, XvMCSurface *surface)
849 -{
850 -    if (!xW.initialised) return BadValue;
851 -    return (*xW.XvMCSyncSurface)(display, surface);
852 -}
853 -
854 -Status XvMCFlushSurface (Display *display, XvMCSurface *surface)
855 -{
856 -    if (!xW.initialised) return BadValue;
857 -    return (*xW.XvMCFlushSurface)(display, surface);
858 -}
859 -
860 -Status XvMCGetSurfaceStatus (Display *display, XvMCSurface *surface, int *stat)
861 -{
862 -    if (!xW.initialised) return BadValue;
863 -    return (*xW.XvMCGetSurfaceStatus)(display, surface, stat);
864 -}
865 -
866 -Status XvMCRenderSurface ( 
867 -    Display *display,
868 -    XvMCContext *context,
869 -    unsigned int picture_structure,
870 -    XvMCSurface *target_surface,
871 -    XvMCSurface *past_surface,
872 -    XvMCSurface *future_surface,
873 -    unsigned int flags,
874 -    unsigned int num_macroblocks,
875 -    unsigned int first_macroblock,
876 -    XvMCMacroBlockArray *macroblock_array,
877 -    XvMCBlockArray *blocks
878 -    )
879 -{
880 -    if (!xW.initialised) return BadValue;
881 -    return (*xW.XvMCRenderSurface)(display, context, picture_structure, target_surface,
882 -                                  past_surface, future_surface, flags, num_macroblocks,
883 -                                  first_macroblock, macroblock_array, blocks);
884 -}
885 -
886 -Status XvMCSyncSubpicture (Display *display, XvMCSubpicture *subpicture)
887 -{
888 -    if (!xW.initialised) return BadValue;
889 -    return (*xW.XvMCSyncSubpicture)(display, subpicture);
890 -}
891 -
892 -Status XvMCFlushSubpicture (Display *display, XvMCSubpicture *subpicture)
893 -{
894 -    if (!xW.initialised) return BadValue;
895 -    return (*xW.XvMCFlushSubpicture)(display, subpicture);
896 -}
897 -Status
898 -XvMCGetSubpictureStatus (Display *display, XvMCSubpicture *subpic, int *stat)
899 -{
900 -    if (!xW.initialised) return BadValue;
901 -    return (*xW.XvMCGetSubpictureStatus)(display, subpic, stat);
902 -}
903 -
904 -Status XvMCCreateBlocks (
905 -    Display *display, 
906 -    XvMCContext *context,
907 -    unsigned int num_blocks,
908 -    XvMCBlockArray *block
909 -    )
910 -{
911 -    if (!xW.initialised) return BadValue;
912 -    return (*xW.XvMCCreateBlocks)(display, context, num_blocks, block);
913 -}
914 -
915 -
916 -Status XvMCDestroyBlocks (Display *display,XvMCBlockArray *block)
917 -{
918 -    if (!xW.initialised) return BadValue;
919 -    return (*xW.XvMCDestroyBlocks)(display, block);
920 -}
921 -
922 -Status XvMCCreateMacroBlocks (
923 -    Display *display,
924 -    XvMCContext *context,
925 -    unsigned int num_blocks,
926 -    XvMCMacroBlockArray *blocks
927 -    )
928 -{
929 -    if (!xW.initialised) return BadValue;
930 -    return (*xW.XvMCCreateMacroBlocks)(display, context, num_blocks, blocks);
931 -}
932 -
933 -
934 -Status XvMCDestroyMacroBlocks (
935 -    Display *display,
936 -    XvMCMacroBlockArray *block
937 -    )
938 -{
939 -    if (!xW.initialised) return BadValue;
940 -    return (*xW.XvMCDestroyMacroBlocks)(display, block);
941 -}
942 -
943 -
944 -XvAttribute *
945 -XvMCQueryAttributes (
946 -    Display *display,
947 -    XvMCContext *context,
948 -    int *number
949 -    )
950 -{
951 -    if (!xW.initialised) return NULL;
952 -    return (*xW.XvMCQueryAttributes)(display, context, number);
953 -}
954 -  
955 -
956 -Status
957 -XvMCSetAttribute (
958 -    Display *display,
959 -    XvMCContext *context, 
960 -    Atom attribute, 
961 -    int value
962 -    )
963 -{
964 -    if (!xW.initialised) return BadValue;
965 -    return (*xW.XvMCSetAttribute)(display, context, attribute, value);
966 -}
967 -
968 -
969 -Status
970 -XvMCGetAttribute (
971 -    Display *display,
972 -    XvMCContext *context, 
973 -    Atom attribute, 
974 -    int *value
975 -    )
976 -{
977 -    if (!xW.initialised) return BadValue;
978 -    return (*xW.XvMCGetAttribute)(display, context, attribute, value);
979 -}
980 -
981 -
982 -Status XvMCBeginSurface(Display *display,
983 -                       XvMCContext *context,
984 -                       XvMCSurface *target_surface,
985 -                       XvMCSurface *past_surface,
986 -                       XvMCSurface *future_surface,
987 -                       const XvMCMpegControl *control)
988 -{
989 -    if (!xW.vldextension) return BadValue;
990 -    return (*xW.XvMCBeginSurface)(display, context, target_surface, past_surface, future_surface, 
991 -                                 control);
992 -}
993 -
994 -Status XvMCLoadQMatrix(Display *display, XvMCContext *context,
995 -                      const XvMCQMatrix *qmx)
996 -{
997 -    if (!xW.vldextension) return BadValue;
998 -    return (*xW.XvMCLoadQMatrix)(display, context, qmx);
999 -}
1000 -
1001 -Status XvMCPutSlice(Display *display,XvMCContext *context,
1002 -                   char *slice, int nBytes)
1003 -{
1004 -    if (!xW.vldextension) return BadValue;
1005 -    return (*xW.XvMCPutSlice)(display, context, slice, nBytes);
1006 -}
1007 -
1008 -Status XvMCPutSlice2(Display *display,XvMCContext *context,
1009 -                    char *slice, int nBytes, int sliceCode)
1010 -{
1011 -    if (!xW.vldextension) return BadValue;
1012 -    return (*xW.XvMCPutSlice2)(display, context, slice, nBytes, sliceCode);
1013 -}
1014 diff --git a/wrapper/Makefile.am b/wrapper/Makefile.am
1015 new file mode 100644
1016 index 0000000..b3a1c21
1017 --- /dev/null
1018 +++ b/wrapper/Makefile.am
1019 @@ -0,0 +1,22 @@
1020 +lib_LTLIBRARIES = libXvMCW.la
1021 +
1022 +AM_CPPFLAGS =                                  \
1023 +       -I$(top_srcdir)/include                 \
1024 +       $(MALLOC_ZERO_CFLAGS)                   \
1025 +       -DXVMC_CONFIGDIR=$(sysconfdir)/X11      \
1026 +       -DXVMC_SOVERSION=\".1.0\"               \
1027 +       -DXV_SOVERSION=\".1.0\"
1028 +
1029 +AM_CFLAGS = $(CWARNFLAGS) $(XVMC_CFLAGS)
1030 +
1031 +libXvMCW_la_SOURCES = XvMCWrapper.c
1032 +libXvMCW_la_LIBADD = $(XVMC_LIBS)
1033 +libXvMCW_la_LDFLAGS = -version-number 1:0:0 -no-undefined
1034 +
1035 +if LINT
1036 +ALL_LINT_FLAGS=$(LINT_FLAGS) $(DEFS) $(DEFAULT_INCLUDES) \
1037 +                $(AM_CPPFLAGS) $(CPPFLAGS)
1038 +
1039 +lint:
1040 +       $(LINT) $(ALL_LINT_FLAGS) $(libXvMCW_la_SOURCES) $(AM_CFLAGS) $(XVMC_LIBS)
1041 +endif LINT
1042 diff --git a/wrapper/XvMCWrapper.c b/wrapper/XvMCWrapper.c
1043 new file mode 100644
1044 index 0000000..bff5a8b
1045 --- /dev/null
1046 +++ b/wrapper/XvMCWrapper.c
1047 @@ -0,0 +1,781 @@
1048 +/*****************************************************************************
1049 + * XvMC Wrapper including the Nonstandard VLD extension.
1050 + *
1051 + * Copyright (c) 2004 The Unichrome project. All rights reserved.
1052 + *
1053 + *
1054 + * Permission is hereby granted, free of charge, to any person obtaining a
1055 + * copy of this software and associated documentation files (the "Software"),
1056 + * to deal in the Software without restriction, including without limitation
1057 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1058 + * and/or sell copies of the Software, and to permit persons to whom the
1059 + * Software is furnished to do so, subject to the following conditions:
1060 + *
1061 + * The above copyright notice and this permission notice shall be included in
1062 + * all copies or substantial portions of the Software.
1063 + *
1064 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1065 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1066 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1067 + * AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1068 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1069 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1070 + * DEALINGS IN THE SOFTWARE.
1071 + *
1072 + * Author: Thomas Hellström (2004)
1073 + */
1074 +
1075 +/*
1076 + * BUGS: The wrapper really should maintain one symbol table per port. This
1077 + * could possibly be impemented, To do that, the port-independent symbols need to be lifted out,
1078 + * and one would have to create a number of mapping tables:
1079 + *
1080 + *                 port  -> symbol table
1081 + *                 context -> port
1082 + *                 surface -> port
1083 + *                 subpicture -> port
1084 + *
1085 + * and reference the right table when needed.
1086 + * This needs to be done only if there is a player that wants to access two displays with different
1087 + * hardware simultaneously. Not likely as of today.
1088 + */
1089 +
1090 +#ifdef HAVE_CONFIG_H
1091 +  #include "config.h"
1092 +#endif
1093 +
1094 +#include <X11/Xlib.h>
1095 +#include <X11/extensions/XvMC.h>
1096 +#include <X11/extensions/XvMClib.h>
1097 +#include <X11/extensions/vldXvMC.h>
1098 +#include <dlfcn.h>
1099 +#include <stdio.h>
1100 +#include <string.h>
1101 +#include <ctype.h>
1102 +#include <stdlib.h>
1103 +
1104 +
1105 +typedef Bool (*XvMCQueryExtensionP) (Display *, int *, int *);
1106 +typedef Status (*XvMCQueryVersionP) (Display *, int *,int *);
1107 +typedef XvMCSurfaceInfo * (*XvMCListSurfaceTypesP)(Display *, XvPortID, int *);
1108 +typedef Status (* XvMCCreateContextP) (Display *,XvPortID,int ,int ,int ,int ,XvMCContext * );
1109 +typedef Status (*XvMCDestroyContextP) (Display *, XvMCContext * );
1110 +typedef Status (*XvMCCreateSurfaceP)(Display *,XvMCContext *,XvMCSurface *);
1111 +typedef Status (*XvMCDestroySurfaceP)(Display *, XvMCSurface *);
1112 +typedef XvImageFormatValues * (*XvMCListSubpictureTypesP) (Display *,XvPortID ,int ,int *);
1113 +typedef Status (*XvMCPutSurfaceP)(Display *,XvMCSurface *,Drawable ,short , short , unsigned short ,
1114 +                                 unsigned short ,short ,short ,unsigned short ,unsigned short ,int );
1115 +typedef Status (*XvMCHideSurfaceP)(Display *, XvMCSurface *);
1116 +typedef Status (*XvMCCreateSubpictureP) (Display *, XvMCContext *, XvMCSubpicture *,
1117 +                                        unsigned short, unsigned short,int);
1118 +typedef Status (*XvMCClearSubpictureP) (Display *,XvMCSubpicture *,short,short,unsigned short,unsigned short,
1119 +                                       unsigned int);
1120 +typedef Status (*XvMCCompositeSubpictureP) (Display *, XvMCSubpicture *,XvImage *,short,short,
1121 +                                           unsigned short, unsigned short,short,short);
1122 +typedef Status (*XvMCDestroySubpictureP) (Display *, XvMCSubpicture *);
1123 +typedef Status (*XvMCSetSubpicturePaletteP) (Display *, XvMCSubpicture *, unsigned char *);
1124 +typedef Status (*XvMCBlendSubpictureP) (Display *d,XvMCSurface *,XvMCSubpicture *,short,
1125 +                                       short,unsigned short,unsigned short,short,short,
1126 +                                       unsigned short,unsigned short);
1127 +typedef Status (*XvMCBlendSubpicture2P) (Display *,XvMCSurface *,XvMCSurface *,
1128 +                                        XvMCSubpicture *,short,short,unsigned short,
1129 +                                        unsigned short,short,short,unsigned short,
1130 +                                        unsigned short);
1131 +typedef Status (*XvMCSyncSurfaceP) (Display *, XvMCSurface *);
1132 +typedef Status (*XvMCFlushSurfaceP) (Display *, XvMCSurface *);
1133 +typedef Status (*XvMCGetSurfaceStatusP) (Display *, XvMCSurface *, int *);
1134 +typedef Status (*XvMCRenderSurfaceP) (Display *,XvMCContext *,unsigned int,XvMCSurface *,
1135 +                                     XvMCSurface *,XvMCSurface *,unsigned int,unsigned int,
1136 +                                     unsigned int,XvMCMacroBlockArray *,XvMCBlockArray *);
1137 +typedef Status (*XvMCSyncSubpictureP) (Display *, XvMCSubpicture *);
1138 +typedef Status (*XvMCFlushSubpictureP) (Display *, XvMCSubpicture *);
1139 +typedef Status (*XvMCGetSubpictureStatusP) (Display *, XvMCSubpicture *, int *);
1140 +typedef Status (*XvMCCreateBlocksP) (Display *, XvMCContext *,unsigned int,XvMCBlockArray *);
1141 +typedef Status (*XvMCDestroyBlocksP) (Display *,XvMCBlockArray *);
1142 +typedef Status (*XvMCCreateMacroBlocksP) (Display *,XvMCContext *,unsigned int,
1143 +                                         XvMCMacroBlockArray *);
1144 +typedef Status (*XvMCDestroyMacroBlocksP) (Display *,XvMCMacroBlockArray *);
1145 +typedef XvAttribute *(*XvMCQueryAttributesP) (Display *,XvMCContext *,int *);
1146 +typedef Status (*XvMCSetAttributeP) (Display *,XvMCContext *, Atom, int);
1147 +typedef Status (*XvMCGetAttributeP) (Display *,XvMCContext *, Atom, int *);
1148 +
1149 +/*
1150 + * Nonstandard VLD acceleration level:
1151 + */
1152 +
1153 +typedef Status (*XvMCBeginSurfaceP) (Display *,XvMCContext *,XvMCSurface *,
1154 +                                    XvMCSurface *,XvMCSurface *f,const XvMCMpegControl *);
1155 +typedef Status (*XvMCLoadQMatrixP) (Display *, XvMCContext *,const XvMCQMatrix *);
1156 +typedef Status (*XvMCPutSliceP)(Display *,XvMCContext *, char *,int);
1157 +typedef Status (*XvMCPutSlice2P)(Display *,XvMCContext *, char *,int, unsigned);
1158 +typedef Status (*XvMCGetDRInfoP)(Display *, XvPortID, char **, char **, int *, int *,
1159 +                                 int *, int *);
1160 +
1161 +
1162 +typedef struct {
1163 +    XvMCQueryExtensionP   XvMCQueryExtension;
1164 +    XvMCQueryVersionP   XvMCQueryVersion;
1165 +    XvMCListSurfaceTypesP  XvMCListSurfaceTypes;
1166 +    XvMCCreateContextP   XvMCCreateContext;
1167 +    XvMCDestroyContextP   XvMCDestroyContext;
1168 +    XvMCCreateSurfaceP  XvMCCreateSurface;
1169 +    XvMCDestroySurfaceP  XvMCDestroySurface;
1170 +    XvMCListSubpictureTypesP    XvMCListSubpictureTypes;
1171 +    XvMCPutSurfaceP   XvMCPutSurface;
1172 +    XvMCHideSurfaceP   XvMCHideSurface;
1173 +    XvMCCreateSubpictureP   XvMCCreateSubpicture;
1174 +    XvMCClearSubpictureP     XvMCClearSubpicture;
1175 +    XvMCCompositeSubpictureP    XvMCCompositeSubpicture;
1176 +    XvMCDestroySubpictureP    XvMCDestroySubpicture;
1177 +    XvMCSetSubpicturePaletteP    XvMCSetSubpicturePalette;
1178 +    XvMCBlendSubpictureP    XvMCBlendSubpicture;
1179 +    XvMCBlendSubpicture2P   XvMCBlendSubpicture2;
1180 +    XvMCSyncSurfaceP    XvMCSyncSurface;
1181 +    XvMCFlushSurfaceP    XvMCFlushSurface;
1182 +    XvMCGetSurfaceStatusP    XvMCGetSurfaceStatus;
1183 +    XvMCRenderSurfaceP    XvMCRenderSurface;
1184 +    XvMCSyncSubpictureP    XvMCSyncSubpicture;
1185 +    XvMCFlushSubpictureP    XvMCFlushSubpicture;
1186 +    XvMCGetSubpictureStatusP    XvMCGetSubpictureStatus;
1187 +    XvMCCreateBlocksP    XvMCCreateBlocks;
1188 +    XvMCDestroyBlocksP    XvMCDestroyBlocks;
1189 +    XvMCCreateMacroBlocksP   XvMCCreateMacroBlocks;
1190 +    XvMCDestroyMacroBlocksP    XvMCDestroyMacroBlocks;
1191 +    XvMCQueryAttributesP    XvMCQueryAttributes;
1192 +    XvMCSetAttributeP    XvMCSetAttribute;
1193 +    XvMCGetAttributeP    XvMCGetAttribute;
1194 +
1195 +    /*
1196 +     * Nonstandard VLD acceleration level:
1197 +     */
1198 +
1199 +    XvMCBeginSurfaceP    XvMCBeginSurface;
1200 +    XvMCLoadQMatrixP    XvMCLoadQMatrix;
1201 +    XvMCPutSliceP   XvMCPutSlice;
1202 +    XvMCPutSlice2P   XvMCPutSlice2;
1203 +
1204 +    /*
1205 +     * Driver name function.
1206 +     */
1207 +
1208 +    XvMCGetDRInfoP XvMCGetDRInfo;
1209 +
1210 +    int preInitialised;
1211 +    int initialised;
1212 +    int vldextension;
1213 +} XvMCWrapper;
1214 +
1215 +static XvMCWrapper xW;
1216 +static int wrapperInit = 0;
1217 +static int wrapperPreInit = 0;
1218 +static void *xvhandle;
1219 +static void *handle2;
1220 +
1221 +#define BUFLEN 200
1222 +
1223 +#define STRS(ARG) STR(ARG)
1224 +#define STR(ARG) #ARG
1225 +
1226 +#define XW_RSYM(base,handle,handle2,pointer, retval)                   \
1227 +    do {                                                               \
1228 +       register char *err;                                             \
1229 +       base.pointer = (pointer##P) dlsym((handle),#pointer);           \
1230 +       if ((err = dlerror()) != NULL) {                                \
1231 +           if (!handle2) {                                             \
1232 +               fprintf(stderr,"%s\n",err); return retval;              \
1233 +           }                                                           \
1234 +           base.pointer = (pointer##P) dlsym((handle2),#pointer);      \
1235 +           if ((err = dlerror()) != NULL) {                            \
1236 +               fprintf(stderr,"%s\n",err); return retval;              \
1237 +           }                                                           \
1238 +       }                                                               \
1239 +    } while (0);
1240 +
1241 +#define XW_RSYM2(base,handle,handle2,pointer)                  \
1242 +    base.pointer = (pointer##P) dlsym((handle),#pointer);      \
1243 +    if (dlerror() != NULL) {                                   \
1244 +       base.pointer = (pointer##P) dlsym((handle2),#pointer);  \
1245 +       if (dlerror() != NULL) return;                          \
1246 +    }
1247 +
1248 +
1249 +/*
1250 + * Try to dlopen a shared library, versionless first.
1251 + */
1252 +
1253 +
1254 +static void  *dlopenversion(const char *lib, const char *version, int flag)
1255 +{
1256 +  void *ret;
1257 +  int curLen,verLen;
1258 +  char *curName;
1259 +  const char *tail;
1260 +
1261 +
1262 +  curLen = strlen(lib) + (verLen = strlen(version)) + 1;
1263 +  curName = (char *) malloc(curLen * sizeof(char));
1264 +  strncpy( curName, lib, curLen);
1265 +  if (verLen > 1) {
1266 +    if (NULL != (tail = strstr(version+1,"."))) {
1267 +      strncat( curName, version, tail - version);
1268 +    } else {
1269 +      strncat( curName, version, verLen);
1270 +    }
1271 +  }
1272 +  ret = dlopen(curName, flag);
1273 +  free(curName);
1274 +  return ret;
1275 +}
1276 +
1277 +static int preInitW(Display *dpy)
1278 +{
1279 +
1280 +    /*
1281 +     * Resolve functions that are not hw driver specific.
1282 +     */
1283 +
1284 +    void *handleZ = NULL;
1285 +
1286 +    wrapperPreInit = 1;
1287 +    xW.preInitialised = 0;
1288 +    xW.initialised = 0;
1289 +    xvhandle = dlopenversion("libXv.so", XV_SOVERSION, RTLD_LAZY | RTLD_GLOBAL);
1290 +    if (!xvhandle) {
1291 +       fprintf(stderr,"XvMCWrapper: Warning! Could not open shared "
1292 +               "library \"libXv.so" XV_SOVERSION "\"\nThis may cause relocation "
1293 +               "errors later.\nError was: \"%s\".\n",dlerror());
1294 +    }
1295 +    handle2 = dlopenversion("libXvMC.so", XVMC_SOVERSION, RTLD_LAZY | RTLD_GLOBAL);
1296 +    if (!handle2) {
1297 +       fprintf(stderr,"XvMCWrapper: Could not load XvMC "
1298 +               "library \"libXvMC.so" XVMC_SOVERSION "\". Failing\n");
1299 +       fprintf(stderr,"%s\n",dlerror());
1300 +       return 1;
1301 +    }
1302 +    XW_RSYM(xW, handle2, handleZ, XvMCQueryExtension, 1);
1303 +    XW_RSYM(xW, handle2, handleZ, XvMCQueryVersion, 1);
1304 +    xW.preInitialised = 1;
1305 +    return 0;
1306 +}
1307 +
1308 +static void initW(Display *dpy, XvPortID port)
1309 +{
1310 +    char nameBuffer[BUFLEN];
1311 +    void *handle;
1312 +    int tmp;
1313 +    char *clientName = NULL;
1314 +    char *err;
1315 +    FILE *configFile;
1316 +    int nameLen = 0;
1317 +    int major,minor,patchLevel,isLocal;
1318 +    char *busID = NULL;
1319 +
1320 +    wrapperInit = 1;
1321 +    xW.initialised = 0;
1322 +
1323 +    if (!wrapperPreInit)
1324 +       if (preInitW( dpy )) return;
1325 +
1326 +    /*
1327 +     * Will the DDX tell us the client driver name?
1328 +     */
1329 +
1330 +    xW.XvMCGetDRInfo = (XvMCGetDRInfoP)
1331 +       dlsym(handle2,"XvMCGetDRInfo");
1332 +
1333 +    if ((err = dlerror()) == NULL) {
1334 +       if (0 == xW.XvMCGetDRInfo( dpy, port, &clientName, &busID, &major,
1335 +                                   &minor,&patchLevel, &isLocal)) {
1336 +           nameLen = strlen(clientName);
1337 +           XFree(busID);
1338 +           if (!isLocal) {
1339 +               fprintf(stderr,"XvMCWrapper: X server is not local. Cannot run XvMC.\n");
1340 +               XFree(clientName);
1341 +               return;
1342 +           }
1343 +       } else {
1344 +           clientName = NULL;
1345 +       }
1346 +    }
1347 +
1348 +    if (clientName && (nameLen < BUFLEN-7) && (nameLen > 0)) {
1349 +       nameLen += 3;
1350 +       strncpy(nameBuffer,"lib",BUFLEN-1);
1351 +       strncpy(nameBuffer+3, clientName, BUFLEN-4);
1352 +       strncpy(nameBuffer + nameLen, ".so", BUFLEN-nameLen-1);
1353 +       nameBuffer[BUFLEN-1] = 0;
1354 +       XFree(clientName);
1355 +       handle = dlopenversion(nameBuffer, XVMC_SOVERSION,RTLD_LAZY);
1356 +    } else {
1357 +       /*
1358 +        * No. Try to obtain it from the config file.
1359 +        */
1360 +
1361 +       if (clientName) XFree(clientName);
1362 +
1363 +       configFile = fopen(STRS(XVMC_CONFIGDIR) "/XvMCConfig","r");
1364 +
1365 +       xW.initialised = 0;
1366 +       xW.vldextension = 0;
1367 +
1368 +       if (NULL == configFile) {
1369 +           fprintf(stderr,"XvMCWrapper: Could not open config file \"%s\".\n",
1370 +                   STRS(XVMC_CONFIGDIR) "/XvMCConfig");
1371 +           perror("XvMCWrapper");
1372 +           return;
1373 +       }
1374 +
1375 +       if (NULL == fgets(nameBuffer, BUFLEN, configFile)) {
1376 +           fclose(configFile);
1377 +           fprintf(stderr,"XvMCWrapper: Could not read XvMC library name.\n");
1378 +           perror("XvMCWrapper");
1379 +           return;
1380 +       }
1381 +
1382 +       fclose(configFile);
1383 +       if ((tmp = strlen(nameBuffer)) == 0) {
1384 +           fprintf(stderr,"XvMCWrapper: Zero length XvMC library name.\n");
1385 +           fprintf(stderr,"%s\n",dlerror());
1386 +           return;
1387 +       }
1388 +
1389 +       /*
1390 +        * Skip trailing newlines and garbage.
1391 +        */
1392 +
1393 +       while (iscntrl(nameBuffer[tmp-1])) {
1394 +           nameBuffer[tmp-1] = 0;
1395 +           if (--tmp == 0) {
1396 +               fprintf(stderr,"XvMCWrapper: Zero length XvMC library name.\n");
1397 +               return;
1398 +           }
1399 +       }
1400 +       handle = dlopen(nameBuffer,RTLD_LAZY);
1401 +    }
1402 +    if (!handle) {
1403 +       fprintf(stderr,"XvMCWrapper: Could not load hardware specific XvMC "
1404 +               "library \"%s\".\n",nameBuffer);
1405 +       fprintf(stderr,"%s\n",dlerror());
1406 +       return;
1407 +    }
1408 +
1409 +    XW_RSYM(xW, handle, handle2, XvMCListSurfaceTypes,);
1410 +    XW_RSYM(xW, handle, handle2, XvMCCreateContext,);
1411 +    XW_RSYM(xW, handle, handle2, XvMCDestroyContext,);
1412 +    XW_RSYM(xW, handle, handle2, XvMCCreateSurface,);
1413 +    XW_RSYM(xW, handle, handle2, XvMCDestroySurface,);
1414 +    XW_RSYM(xW, handle, handle2, XvMCListSubpictureTypes,);
1415 +    XW_RSYM(xW, handle, handle2, XvMCHideSurface,);
1416 +    XW_RSYM(xW, handle, handle2, XvMCCreateSubpicture,);
1417 +    XW_RSYM(xW, handle, handle2, XvMCClearSubpicture,);
1418 +    XW_RSYM(xW, handle, handle2, XvMCCompositeSubpicture,);
1419 +    XW_RSYM(xW, handle, handle2, XvMCDestroySubpicture,);
1420 +    XW_RSYM(xW, handle, handle2, XvMCSetSubpicturePalette,);
1421 +    XW_RSYM(xW, handle, handle2, XvMCBlendSubpicture,);
1422 +    XW_RSYM(xW, handle, handle2, XvMCBlendSubpicture2,);
1423 +    XW_RSYM(xW, handle, handle2, XvMCPutSurface,);
1424 +    XW_RSYM(xW, handle, handle2, XvMCSyncSurface,);
1425 +    XW_RSYM(xW, handle, handle2, XvMCFlushSurface,);
1426 +    XW_RSYM(xW, handle, handle2, XvMCGetSurfaceStatus,);
1427 +    XW_RSYM(xW, handle, handle2, XvMCRenderSurface,);
1428 +    XW_RSYM(xW, handle, handle2, XvMCSyncSubpicture,);
1429 +    XW_RSYM(xW, handle, handle2, XvMCFlushSubpicture,);
1430 +    XW_RSYM(xW, handle, handle2, XvMCGetSubpictureStatus,);
1431 +    XW_RSYM(xW, handle, handle2, XvMCCreateBlocks,);
1432 +    XW_RSYM(xW, handle, handle2, XvMCDestroyBlocks,);
1433 +    XW_RSYM(xW, handle, handle2, XvMCCreateMacroBlocks,);
1434 +    XW_RSYM(xW, handle, handle2, XvMCDestroyMacroBlocks,);
1435 +    XW_RSYM(xW, handle, handle2, XvMCQueryAttributes,);
1436 +    XW_RSYM(xW, handle, handle2, XvMCSetAttribute,);
1437 +    XW_RSYM(xW, handle, handle2, XvMCGetAttribute,);
1438 +    xW.initialised = 1;
1439 +    XW_RSYM2(xW, handle, handle2, XvMCBeginSurface);
1440 +    XW_RSYM(xW, handle, handle2, XvMCLoadQMatrix,);
1441 +    XW_RSYM(xW, handle, handle2, XvMCPutSlice,);
1442 +    XW_RSYM(xW, handle, handle2, XvMCPutSlice2,);
1443 +    xW.vldextension = 1;
1444 +}
1445 +
1446 +
1447 +Bool XvMCQueryExtension (Display *display, int *eventBase, int *errBase)
1448 +{
1449 +    if (!wrapperPreInit) preInitW( display );
1450 +    if (!xW.preInitialised) return 0;
1451 +    return (*xW.XvMCQueryExtension)(display, eventBase, errBase);
1452 +}
1453 +
1454 +Status XvMCQueryVersion (Display *display, int *major_versionp,
1455 +                        int *minor_versionp)
1456 +{
1457 +    if (!wrapperPreInit) preInitW( display );
1458 +    if (!xW.preInitialised) return 0;
1459 +    return (*xW.XvMCQueryVersion)(display, major_versionp, minor_versionp);
1460 +}
1461 +
1462 +
1463 +XvMCSurfaceInfo * XvMCListSurfaceTypes(Display *dpy, XvPortID port, int *num)
1464 +{
1465 +    if (!wrapperInit) initW( dpy, port);
1466 +    if (!xW.initialised) return NULL;
1467 +    return (*xW.XvMCListSurfaceTypes)(dpy, port, num);
1468 +}
1469 +
1470 +Status XvMCCreateContext (
1471 +    Display *display,
1472 +    XvPortID port,
1473 +    int surface_type_id,
1474 +    int width,
1475 +    int height,
1476 +    int flags,
1477 +    XvMCContext * context
1478 +    )
1479 +{
1480 +    if (!wrapperInit) initW(display, port);
1481 +    if (!xW.initialised) return BadValue;
1482 +    return (*xW.XvMCCreateContext)(display, port, surface_type_id,
1483 +                                  width, height, flags, context);
1484 +}
1485 +
1486 +Status XvMCDestroyContext (Display *display, XvMCContext * context)
1487 +{
1488 +    if (!xW.initialised) return BadValue;
1489 +    return (*xW.XvMCDestroyContext)(display, context);
1490 +}
1491 +
1492 +Status
1493 +XvMCCreateSurface(
1494 +    Display *display,
1495 +    XvMCContext * context,
1496 +    XvMCSurface * surface
1497 +    )
1498 +{
1499 +    if (!xW.initialised) return BadValue;
1500 +    return (*xW.XvMCCreateSurface)(display, context, surface);
1501 +}
1502 +
1503 +Status XvMCDestroySurface(Display *display, XvMCSurface *surface)
1504 +{
1505 +    if (!xW.initialised) return BadValue;
1506 +    return (*xW.XvMCDestroySurface)(display, surface);
1507 +}
1508 +
1509 +
1510 +XvImageFormatValues * XvMCListSubpictureTypes (
1511 +    Display * display,
1512 +    XvPortID port,
1513 +    int surface_type_id,
1514 +    int *count_return
1515 +    )
1516 +{
1517 +    if (!xW.initialised) return NULL;
1518 +    return (*xW.XvMCListSubpictureTypes)(display, port, surface_type_id,
1519 +                                        count_return);
1520 +}
1521 +
1522 +
1523 +Status
1524 +XvMCPutSurface(
1525 +    Display *display,
1526 +    XvMCSurface *surface,
1527 +    Drawable draw,
1528 +    short srcx,
1529 +    short srcy,
1530 +    unsigned short srcw,
1531 +    unsigned short srch,
1532 +    short destx,
1533 +    short desty,
1534 +    unsigned short destw,
1535 +    unsigned short desth,
1536 +    int flags
1537 +    )
1538 +{
1539 +    if (!xW.initialised) return BadValue;
1540 +    return (*xW.XvMCPutSurface)(display, surface, draw, srcx, srcy, srcw, srch,
1541 +                               destx, desty, destw, desth, flags);
1542 +}
1543 +
1544 +Status XvMCHideSurface(Display *display, XvMCSurface *surface)
1545 +{
1546 +    if (!xW.initialised) return BadValue;
1547 +    return (*xW.XvMCHideSurface)(display, surface);
1548 +}
1549 +
1550 +
1551 +Status
1552 +XvMCCreateSubpicture (
1553 +    Display *display,
1554 +    XvMCContext *context,
1555 +    XvMCSubpicture *subpicture,
1556 +    unsigned short width,
1557 +    unsigned short height,
1558 +    int xvimage_id
1559 +    )
1560 +{
1561 +    if (!xW.initialised) return BadValue;
1562 +    return (*xW.XvMCCreateSubpicture)(display, context, subpicture, width, height,
1563 +                                     xvimage_id);
1564 +}
1565 +
1566 +
1567 +Status
1568 +XvMCClearSubpicture (
1569 +    Display *display,
1570 +    XvMCSubpicture *subpicture,
1571 +    short x,
1572 +    short y,
1573 +    unsigned short width,
1574 +    unsigned short height,
1575 +    unsigned int color
1576 +    )
1577 +{
1578 +    if (!xW.initialised) return BadValue;
1579 +    return (*xW.XvMCClearSubpicture)(display, subpicture, x, y, width, height, color);
1580 +}
1581 +
1582 +
1583 +Status
1584 +XvMCCompositeSubpicture (
1585 +    Display *display,
1586 +    XvMCSubpicture *subpicture,
1587 +    XvImage *image,
1588 +    short srcx,
1589 +    short srcy,
1590 +    unsigned short width,
1591 +    unsigned short height,
1592 +    short dstx,
1593 +    short dsty
1594 +    )
1595 +{
1596 +    if (!xW.initialised) return BadValue;
1597 +    return (*xW.XvMCCompositeSubpicture)(display, subpicture, image, srcx, srcy,
1598 +                                        width, height, dstx, dsty);
1599 +}
1600 +
1601 +Status
1602 +XvMCDestroySubpicture (Display *display, XvMCSubpicture *subpicture)
1603 +{
1604 +    if (!xW.initialised) return BadValue;
1605 +    return (*xW.XvMCDestroySubpicture)(display, subpicture);
1606 +}
1607 +
1608 +Status
1609 +XvMCSetSubpicturePalette (
1610 +    Display *display,
1611 +    XvMCSubpicture *subpicture,
1612 +    unsigned char *palette
1613 +    )
1614 +{
1615 +    if (!xW.initialised) return BadValue;
1616 +    return (*xW.XvMCSetSubpicturePalette)(display, subpicture, palette);
1617 +}
1618 +
1619 +
1620 +Status
1621 +XvMCBlendSubpicture (
1622 +    Display *display,
1623 +    XvMCSurface *target_surface,
1624 +    XvMCSubpicture *subpicture,
1625 +    short subx,
1626 +    short suby,
1627 +    unsigned short subw,
1628 +    unsigned short subh,
1629 +    short surfx,
1630 +    short surfy,
1631 +    unsigned short surfw,
1632 +    unsigned short surfh
1633 +    )
1634 +{
1635 +    if (!xW.initialised) return BadValue;
1636 +    return (*xW.XvMCBlendSubpicture)(display, target_surface, subpicture,
1637 +                                    subx, suby, subw, subh, surfx, surfy,
1638 +                                    surfw, surfh);
1639 +}
1640 +
1641 +Status
1642 +XvMCBlendSubpicture2 (
1643 +    Display *display,
1644 +    XvMCSurface *source_surface,
1645 +    XvMCSurface *target_surface,
1646 +    XvMCSubpicture *subpicture,
1647 +    short subx,
1648 +    short suby,
1649 +    unsigned short subw,
1650 +    unsigned short subh,
1651 +    short surfx,
1652 +    short surfy,
1653 +    unsigned short surfw,
1654 +    unsigned short surfh
1655 +    )
1656 +{
1657 +    if (!xW.initialised) return BadValue;
1658 +    return (*xW.XvMCBlendSubpicture2)(display, source_surface, target_surface, subpicture,
1659 +                                     subx, suby, subw, subh, surfx, surfy, surfw, surfh);
1660 +}
1661 +
1662 +
1663 +Status XvMCSyncSurface (Display *display, XvMCSurface *surface)
1664 +{
1665 +    if (!xW.initialised) return BadValue;
1666 +    return (*xW.XvMCSyncSurface)(display, surface);
1667 +}
1668 +
1669 +Status XvMCFlushSurface (Display *display, XvMCSurface *surface)
1670 +{
1671 +    if (!xW.initialised) return BadValue;
1672 +    return (*xW.XvMCFlushSurface)(display, surface);
1673 +}
1674 +
1675 +Status XvMCGetSurfaceStatus (Display *display, XvMCSurface *surface, int *stat)
1676 +{
1677 +    if (!xW.initialised) return BadValue;
1678 +    return (*xW.XvMCGetSurfaceStatus)(display, surface, stat);
1679 +}
1680 +
1681 +Status XvMCRenderSurface (
1682 +    Display *display,
1683 +    XvMCContext *context,
1684 +    unsigned int picture_structure,
1685 +    XvMCSurface *target_surface,
1686 +    XvMCSurface *past_surface,
1687 +    XvMCSurface *future_surface,
1688 +    unsigned int flags,
1689 +    unsigned int num_macroblocks,
1690 +    unsigned int first_macroblock,
1691 +    XvMCMacroBlockArray *macroblock_array,
1692 +    XvMCBlockArray *blocks
1693 +    )
1694 +{
1695 +    if (!xW.initialised) return BadValue;
1696 +    return (*xW.XvMCRenderSurface)(display, context, picture_structure, target_surface,
1697 +                                  past_surface, future_surface, flags, num_macroblocks,
1698 +                                  first_macroblock, macroblock_array, blocks);
1699 +}
1700 +
1701 +Status XvMCSyncSubpicture (Display *display, XvMCSubpicture *subpicture)
1702 +{
1703 +    if (!xW.initialised) return BadValue;
1704 +    return (*xW.XvMCSyncSubpicture)(display, subpicture);
1705 +}
1706 +
1707 +Status XvMCFlushSubpicture (Display *display, XvMCSubpicture *subpicture)
1708 +{
1709 +    if (!xW.initialised) return BadValue;
1710 +    return (*xW.XvMCFlushSubpicture)(display, subpicture);
1711 +}
1712 +Status
1713 +XvMCGetSubpictureStatus (Display *display, XvMCSubpicture *subpic, int *stat)
1714 +{
1715 +    if (!xW.initialised) return BadValue;
1716 +    return (*xW.XvMCGetSubpictureStatus)(display, subpic, stat);
1717 +}
1718 +
1719 +Status XvMCCreateBlocks (
1720 +    Display *display,
1721 +    XvMCContext *context,
1722 +    unsigned int num_blocks,
1723 +    XvMCBlockArray *block
1724 +    )
1725 +{
1726 +    if (!xW.initialised) return BadValue;
1727 +    return (*xW.XvMCCreateBlocks)(display, context, num_blocks, block);
1728 +}
1729 +
1730 +
1731 +Status XvMCDestroyBlocks (Display *display,XvMCBlockArray *block)
1732 +{
1733 +    if (!xW.initialised) return BadValue;
1734 +    return (*xW.XvMCDestroyBlocks)(display, block);
1735 +}
1736 +
1737 +Status XvMCCreateMacroBlocks (
1738 +    Display *display,
1739 +    XvMCContext *context,
1740 +    unsigned int num_blocks,
1741 +    XvMCMacroBlockArray *blocks
1742 +    )
1743 +{
1744 +    if (!xW.initialised) return BadValue;
1745 +    return (*xW.XvMCCreateMacroBlocks)(display, context, num_blocks, blocks);
1746 +}
1747 +
1748 +
1749 +Status XvMCDestroyMacroBlocks (
1750 +    Display *display,
1751 +    XvMCMacroBlockArray *block
1752 +    )
1753 +{
1754 +    if (!xW.initialised) return BadValue;
1755 +    return (*xW.XvMCDestroyMacroBlocks)(display, block);
1756 +}
1757 +
1758 +
1759 +XvAttribute *
1760 +XvMCQueryAttributes (
1761 +    Display *display,
1762 +    XvMCContext *context,
1763 +    int *number
1764 +    )
1765 +{
1766 +    if (!xW.initialised) return NULL;
1767 +    return (*xW.XvMCQueryAttributes)(display, context, number);
1768 +}
1769 +
1770 +
1771 +Status
1772 +XvMCSetAttribute (
1773 +    Display *display,
1774 +    XvMCContext *context,
1775 +    Atom attribute,
1776 +    int value
1777 +    )
1778 +{
1779 +    if (!xW.initialised) return BadValue;
1780 +    return (*xW.XvMCSetAttribute)(display, context, attribute, value);
1781 +}
1782 +
1783 +
1784 +Status
1785 +XvMCGetAttribute (
1786 +    Display *display,
1787 +    XvMCContext *context,
1788 +    Atom attribute,
1789 +    int *value
1790 +    )
1791 +{
1792 +    if (!xW.initialised) return BadValue;
1793 +    return (*xW.XvMCGetAttribute)(display, context, attribute, value);
1794 +}
1795 +
1796 +
1797 +Status XvMCBeginSurface(Display *display,
1798 +                       XvMCContext *context,
1799 +                       XvMCSurface *target_surface,
1800 +                       XvMCSurface *past_surface,
1801 +                       XvMCSurface *future_surface,
1802 +                       const XvMCMpegControl *control)
1803 +{
1804 +    if (!xW.vldextension) return BadValue;
1805 +    return (*xW.XvMCBeginSurface)(display, context, target_surface, past_surface, future_surface,
1806 +                                 control);
1807 +}
1808 +
1809 +Status XvMCLoadQMatrix(Display *display, XvMCContext *context,
1810 +                      const XvMCQMatrix *qmx)
1811 +{
1812 +    if (!xW.vldextension) return BadValue;
1813 +    return (*xW.XvMCLoadQMatrix)(display, context, qmx);
1814 +}
1815 +
1816 +Status XvMCPutSlice(Display *display,XvMCContext *context,
1817 +                   char *slice, int nBytes)
1818 +{
1819 +    if (!xW.vldextension) return BadValue;
1820 +    return (*xW.XvMCPutSlice)(display, context, slice, nBytes);
1821 +}
1822 +
1823 +Status XvMCPutSlice2(Display *display,XvMCContext *context,
1824 +                    char *slice, int nBytes, int sliceCode)
1825 +{
1826 +    if (!xW.vldextension) return BadValue;
1827 +    return (*xW.XvMCPutSlice2)(display, context, slice, nBytes, sliceCode);
1828 +}