]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/omapdrmtest.git/blob - util/util.h
add viddec3 decoder test
[glsdk/omapdrmtest.git] / util / util.h
1 /*
2  * Copyright (C) 2011 Texas Instruments
3  * Author: Rob Clark <rob.clark@linaro.org>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published by
7  * the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
18 #ifndef UTIL_H_
19 #define UTIL_H_
21 #include <stdio.h>
22 #include <stdint.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <errno.h>
26 #include <unistd.h>
27 #include <assert.h>
29 #include <omap_drm.h>
30 #include <omap_drmif.h>
32 /* align x to next highest multiple of 2^n */
33 #define ALIGN2(x,n)   (((x) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))
35 typedef enum {
36         false = 0,
37         true = 1
38 } bool;
40 #include "list.h"
42 /* Display Interface:
43  *
44  * Could be either KMS or X11 depending on build and
45  * environment.  Some of details of opening/connecting, allocating buffers,
46  * etc, differ.  The intention is just to provide as simple as possible
47  * abstraction to avoid lots of duplication in each test app to handle
48  * both cases.
49  */
51 struct buffer {
52         uint32_t fourcc, width, height;
53         int nbo;
54         struct omap_bo *bo[4];
55         uint32_t pitches[4];
56         struct list unlocked;
57 };
59 struct display {
60         int fd;
61         uint32_t width, height;
62         struct omap_device *dev;
63         struct list unlocked;
65         struct buffer ** (*get_buffers)(struct display *disp, uint32_t n);
66         struct buffer ** (*get_vid_buffers)(struct display *disp,
67                         uint32_t n, uint32_t fourcc, uint32_t w, uint32_t h);
68         int (*post_buffer)(struct display *disp, struct buffer *buf);
69         int (*post_vid_buffer)(struct display *disp, struct buffer *buf,
70                         uint32_t x, uint32_t y, uint32_t w, uint32_t h);
71 };
73 /* Print display related help */
74 void disp_usage(void);
76 /* Open display.. X11 or KMS depending on cmdline args, environment,
77  * and build args
78  */
79 struct display * disp_open(int argc, char **argv);
81 /* Get normal RGB/UI buffers (ie. not scaled, not YUV) */
82 static inline struct buffer **
83 disp_get_buffers(struct display *disp, uint32_t n)
84 {
85         return disp->get_buffers(disp, n);
86 }
88 /* Get video/overlay buffers (ie. can be YUV, scaled, etc) */
89 struct buffer ** disp_get_vid_buffers(struct display *disp, uint32_t n,
90                 uint32_t fourcc, uint32_t w, uint32_t h);
92 /* flip to / post the specified buffer */
93 static inline int
94 disp_post_buffer(struct display *disp, struct buffer *buf)
95 {
96         return disp->post_buffer(disp, buf);
97 }
99 /* flip to / post the specified video buffer */
100 static inline int
101 disp_post_vid_buffer(struct display *disp, struct buffer *buf,
102                 uint32_t x, uint32_t y, uint32_t w, uint32_t h)
104         return disp->post_vid_buffer(disp, buf, x, y, w, h);
107 /* allocate a buffer from pool created by disp_get_vid_buffers() */
108 struct buffer * disp_get_vid_buffer(struct display *disp);
109 /* free to video buffer pool */
110 void disp_put_vid_buffer(struct display *disp, struct buffer *buf);
112 /* helper to setup the display for apps that just need video with
113  * no flipchain on the GUI layer
114  */
115 struct buffer * disp_get_fb(struct display *disp);
118 /* V4L2 utilities:
119  */
121 struct v4l2;
123 /* Print v4l2 related help */
124 void v4l2_usage(void);
126 /* Open v4l2 (and media0??) XXX */
127 struct v4l2 * v4l2_open(int argc, char **argv, uint32_t *fourcc,
128                 uint32_t *width, uint32_t *height);
130 /* Share the buffers w/ v4l2 via dmabuf */
131 int v4l2_reqbufs(struct v4l2 *v4l2, struct buffer **bufs, uint32_t n);
133 int v4l2_streamon(struct v4l2 *v4l2);
134 int v4l2_streamoff(struct v4l2 *v4l2);
136 /* Queue a buffer to the camera */
137 int v4l2_qbuf(struct v4l2 *v4l2, struct buffer *buf);
139 /* Dequeue buffer from camera */
140 struct buffer * v4l2_dqbuf(struct v4l2 *v4l2);
142 /* Other utilities..
143  */
145 int check_args(int argc, char **argv);
147 void fill(struct buffer *buf, int i);
149 #define FOURCC(a, b, c, d) ((uint32_t)(uint8_t)(a) | ((uint32_t)(uint8_t)(b) << 8) | ((uint32_t)(uint8_t)(c) << 16) | ((uint32_t)(uint8_t)(d) << 24 ))
150 #define FOURCC_STR(str)    FOURCC(str[0], str[1], str[2], str[3])
152 #define MSG(fmt, ...) \
153                 do { fprintf(stderr, fmt "\n", ##__VA_ARGS__); } while (0)
154 #define ERROR(fmt, ...) \
155                 do { fprintf(stderr, "ERROR:%s:%d: " fmt "\n", __func__, __LINE__, ##__VA_ARGS__); } while (0)
157 #ifndef container_of
158 #define container_of(ptr, type, member) \
159     (type *)((char *)(ptr) - (char *) &((type *)0)->member)
160 #endif
162 #ifndef MIN
163 #  define MIN(a,b)     (((a) < (b)) ? (a) : (b))
164 #endif
166 #ifndef MAX
167 #  define MAX(a,b)     (((a) > (b)) ? (a) : (b))
168 #endif
170 /* align x to next highest multiple of 2^n */
171 #define ALIGN2(x,n)   (((x) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))
173 #include <sys/time.h>
174 static inline long
175 mark(long *last)
177         struct timeval t;
178         gettimeofday(&t, NULL);
179         if (last) {
180                 return t.tv_usec - *last;
181         }
182         return t.tv_usec;
185 #endif /* UTIL_H_ */