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 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.
26 **************************************************************************/
32 void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line)
34 fputs(doc_string, stderr);
36 fprintf(stderr, " FAIL!\n\t\"%s\" at %s:%u\n", pred_string, file, line);
38 fputs(" PASS!\n", stderr);
47 unsigned int chroma_format
,
48 const unsigned int *mc_types
,
49 unsigned int num_mc_types
,
52 unsigned int *is_overlay
,
53 unsigned int *intra_unsigned
56 unsigned int found_port
= 0;
57 XvAdaptorInfo
*adaptor_info
;
58 unsigned int num_adaptors
;
60 int ev_base
, err_base
;
61 unsigned int i
, j
, k
, l
;
63 if (!XvMCQueryExtension(display
, &ev_base
, &err_base
))
65 if (XvQueryAdaptors(display
, XDefaultRootWindow(display
), &num_adaptors
, &adaptor_info
) != Success
)
68 for (i
= 0; i
< num_adaptors
&& !found_port
; ++i
)
70 if (adaptor_info
[i
].type
& XvImageMask
)
72 XvMCSurfaceInfo
*surface_info
= XvMCListSurfaceTypes(display
, adaptor_info
[i
].base_id
, &num_types
);
76 for (j
= 0; j
< num_types
&& !found_port
; ++j
)
80 surface_info
[j
].chroma_format
== chroma_format
&&
81 surface_info
[j
].max_width
>= width
&&
82 surface_info
[j
].max_height
>= height
85 for (k
= 0; k
< num_mc_types
&& !found_port
; ++k
)
87 if (surface_info
[j
].mc_type
== mc_types
[k
])
89 for (l
= 0; l
< adaptor_info
[i
].num_ports
&& !found_port
; ++l
)
91 if (XvGrabPort(display
, adaptor_info
[i
].base_id
+ l
, CurrentTime
) == Success
)
93 *port_id
= adaptor_info
[i
].base_id
+ l
;
94 *surface_type_id
= surface_info
[j
].surface_type_id
;
95 *is_overlay
= surface_info
[j
].flags
& XVMC_OVERLAID_SURFACE
;
96 *intra_unsigned
= surface_info
[j
].flags
& XVMC_INTRA_UNSIGNED
;
110 XvFreeAdaptorInfo(adaptor_info
);
115 unsigned int align(unsigned int value
, unsigned int alignment
)
117 return (value
+ alignment
- 1) & ~(alignment
- 1);
120 /* From the glibc manual */
121 int timeval_subtract(struct timeval
*result
, struct timeval
*x
, struct timeval
*y
)
123 /* Perform the carry for the later subtraction by updating y. */
124 if (x
->tv_usec
< y
->tv_usec
)
126 int nsec
= (y
->tv_usec
- x
->tv_usec
) / 1000000 + 1;
127 y
->tv_usec
-= 1000000 * nsec
;
130 if (x
->tv_usec
- y
->tv_usec
> 1000000)
132 int nsec
= (x
->tv_usec
- y
->tv_usec
) / 1000000;
133 y
->tv_usec
+= 1000000 * nsec
;
138 * Compute the time remaining to wait.
139 * tv_usec is certainly positive.
141 result
->tv_sec
= x
->tv_sec
- y
->tv_sec
;
142 result
->tv_usec
= x
->tv_usec
- y
->tv_usec
;
144 /* Return 1 if result is negative. */
145 return x
->tv_sec
< y
->tv_sec
;