52 #include <sys/ioctl.h>
56 #include "console_video.h"
58 #if defined(HAVE_VIDEO_CONSOLE)
67 struct grab_x11_desc {
75 static void *grab_x11_close(
void *desc);
80 static void *grab_x11_open(
const char *name,
struct fbuf_t *geom,
int fps)
84 struct grab_x11_desc *v;
88 if (strncasecmp(name,
"X11", 3))
95 v->dpy = XOpenDisplay(NULL);
97 ast_log(LOG_WARNING,
"error opening display\n");
104 screen_num = DefaultScreen(v->dpy);
105 v->screen_width = DisplayWidth(v->dpy, screen_num);
106 v->screen_height = DisplayHeight(v->dpy, screen_num);
108 v->image = im = XGetImage(v->dpy,
109 RootWindow(v->dpy, DefaultScreen(v->dpy)),
110 b->x, b->y, b->w, b->h, AllPlanes, ZPixmap);
111 if (v->image == NULL) {
112 ast_log(LOG_WARNING,
"error creating Ximage\n");
115 switch (im->bits_per_pixel) {
117 b->pix_fmt = PIX_FMT_RGBA32;
120 b->pix_fmt = (im->green_mask == 0x7e0) ? PIX_FMT_RGB565 : PIX_FMT_RGB555;
124 ast_log(LOG_NOTICE,
"image: data %p %d bpp fmt %d, mask 0x%lx 0x%lx 0x%lx\n",
128 im->red_mask, im->green_mask, im->blue_mask);
131 b->data = (uint8_t *)im->data;
135 return grab_x11_close(v);
138 static struct fbuf_t *grab_x11_read(
void *desc)
141 struct grab_x11_desc *v = desc;
145 RootWindow(v->dpy, DefaultScreen(v->dpy)),
146 b->x, b->y, b->w, b->h, AllPlanes, ZPixmap, v->image, 0, 0);
148 b->data = (uint8_t *)v->image->data;
152 static int boundary_checks(
int x,
int limit)
154 return (x <= 0) ? 0 : (x > limit ? limit : x);
160 static void grab_x11_move(
void *desc,
int dx,
int dy)
162 struct grab_x11_desc *v = desc;
164 v->b.x = boundary_checks(v->b.x + dx, v->screen_width - v->b.w);
165 v->b.y = boundary_checks(v->b.y + dy, v->screen_height - v->b.h);
169 static void *grab_x11_close(
void *desc)
171 struct grab_x11_desc *v = desc;
174 XCloseDisplay(v->dpy);
181 static struct grab_desc grab_x11_desc = {
183 .open = grab_x11_open,
184 .read = grab_x11_read,
185 .move = grab_x11_move,
186 .close = grab_x11_close,
190 #ifdef HAVE_VIDEODEV_H
191 #include <linux/videodev.h>
193 struct grab_v4l1_desc {
202 static void *grab_v4l1_open(
const char *dev,
struct fbuf_t *geom,
int fps)
204 struct video_window vw = { 0 };
205 struct video_picture vp;
207 struct grab_v4l1_desc *v;
211 if (strncmp(dev,
"/dev/", 5))
213 fd = open(dev, O_RDONLY | O_NONBLOCK);
215 ast_log(LOG_WARNING,
"error opening camera %s\n", dev);
221 ast_log(LOG_WARNING,
"no memory for camera %s\n", dev);
237 vw.flags = fps << 16;
238 if (ioctl(fd, VIDIOCSWIN, &vw) == -1) {
239 ast_log(LOG_WARNING,
"error setting format for %s [%s]\n",
240 dev, strerror(errno));
243 if (ioctl(fd, VIDIOCGPICT, &vp) == -1) {
244 ast_log(LOG_WARNING,
"error reading picture info\n");
248 "contrast %d bright %d colour %d hue %d white %d palette %d\n",
249 vp.contrast, vp.brightness,
251 vp.whiteness, vp.palette);
256 b->pix_fmt = vp.palette;
257 vp.palette = VIDEO_PALETTE_YUV420P;
258 if (ioctl(v->fd, VIDIOCSPICT, &vp) == -1) {
259 ast_log(LOG_WARNING,
"error setting palette, using %d\n",
262 b->pix_fmt = vp.palette;
267 b->size = (b->w * b->h * 3)/2;
268 ast_log(LOG_WARNING,
"videodev %s opened, size %dx%d %d\n",
269 dev, b->w, b->h, b->size);
272 ast_log(LOG_WARNING,
"error allocating buffer %d bytes\n",
276 ast_log(LOG_WARNING,
"success opening camera\n");
290 static struct fbuf_t *grab_v4l1_read(
void *desc)
292 struct grab_v4l1_desc *v = desc;
295 int r, l = b->size - b->used;
296 r = read(v->fd, b->data + b->used, l);
311 static void *grab_v4l1_close(
void *desc)
313 struct grab_v4l1_desc *v = desc;
323 static struct grab_desc grab_v4l1_desc = {
325 .open = grab_v4l1_open,
326 .read = grab_v4l1_read,
327 .close = grab_v4l1_close,
341 #ifdef HAVE_VIDEODEV_H
Asterisk main include file. File version handling, generic pbx functions.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.
#define ast_calloc(num, len)
A wrapper for calloc()