1 /**************************************************************************
3 * Copyright 2009 Younes Manton.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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 VMWARE 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.
26 **************************************************************************/
33 void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line)
35 fputs(doc_string, stderr);
37 fprintf(stderr, " FAIL!\n\t\"%s\" at %s:%u\n", pred_string, file, line);
39 fputs(" PASS!\n", stderr);
48 unsigned int chroma_format
,
49 const unsigned int *mc_types
,
50 unsigned int num_mc_types
,
53 unsigned int *is_overlay
,
54 unsigned int *intra_unsigned
57 unsigned int found_port
= 0;
58 XvAdaptorInfo
*adaptor_info
;
59 unsigned int num_adaptors
;
61 int ev_base
, err_base
;
62 unsigned int i
, j
, k
, l
;
64 if (!XvMCQueryExtension(display
, &ev_base
, &err_base
))
66 if (XvQueryAdaptors(display
, XDefaultRootWindow(display
), &num_adaptors
, &adaptor_info
) != Success
)
69 for (i
= 0; i
< num_adaptors
&& !found_port
; ++i
)
71 if (adaptor_info
[i
].type
& XvImageMask
)
73 XvMCSurfaceInfo
*surface_info
= XvMCListSurfaceTypes(display
, adaptor_info
[i
].base_id
, &num_types
);
77 for (j
= 0; j
< num_types
&& !found_port
; ++j
)
81 surface_info
[j
].chroma_format
== chroma_format
&&
82 surface_info
[j
].max_width
>= width
&&
83 surface_info
[j
].max_height
>= height
86 for (k
= 0; k
< num_mc_types
&& !found_port
; ++k
)
88 if ((surface_info
[j
].mc_type
& mc_types
[k
]) == mc_types
[k
])
90 for (l
= 0; l
< adaptor_info
[i
].num_ports
&& !found_port
; ++l
)
92 if (XvGrabPort(display
, adaptor_info
[i
].base_id
+ l
, CurrentTime
) == Success
)
94 *port_id
= adaptor_info
[i
].base_id
+ l
;
95 *surface_type_id
= surface_info
[j
].surface_type_id
;
96 *is_overlay
= surface_info
[j
].flags
& XVMC_OVERLAID_SURFACE
;
97 *intra_unsigned
= surface_info
[j
].flags
& XVMC_INTRA_UNSIGNED
;
111 XvFreeAdaptorInfo(adaptor_info
);
116 unsigned int align(unsigned int value
, unsigned int alignment
)
118 return (value
+ alignment
- 1) & ~(alignment
- 1);
121 /* From the glibc manual */
122 int timeval_subtract(struct timeval
*result
, struct timeval
*x
, struct timeval
*y
)
124 /* Perform the carry for the later subtraction by updating y. */
125 if (x
->tv_usec
< y
->tv_usec
)
127 int nsec
= (y
->tv_usec
- x
->tv_usec
) / 1000000 + 1;
128 y
->tv_usec
-= 1000000 * nsec
;
131 if (x
->tv_usec
- y
->tv_usec
> 1000000)
133 int nsec
= (x
->tv_usec
- y
->tv_usec
) / 1000000;
134 y
->tv_usec
+= 1000000 * nsec
;
139 * Compute the time remaining to wait.
140 * tv_usec is certainly positive.
142 result
->tv_sec
= x
->tv_sec
- y
->tv_sec
;
143 result
->tv_usec
= x
->tv_usec
- y
->tv_usec
;
145 /* Return 1 if result is negative. */
146 return x
->tv_sec
< y
->tv_sec
;