OSDN Git Service

Merge remote-tracking branch 'qatar/master'
[coroid/ffmpeg_saccubus.git] / libavdevice / x11grab.c
1 /*
2  * X11 video grab interface
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg integration:
7  * Copyright (C) 2006 Clemens Fruhwirth <clemens@endorphin.org>
8  *                    Edouard Gomez <ed.gomez@free.fr>
9  *
10  * This file contains code from grab.c:
11  * Copyright (c) 2000-2001 Fabrice Bellard
12  *
13  * This file contains code from the xvidcap project:
14  * Copyright (C) 1997-1998 Rasca, Berlin
15  *               2003-2004 Karl H. Beckers, Frankfurt
16  *
17  * FFmpeg is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 2 of the License, or
20  * (at your option) any later version.
21  *
22  * FFmpeg is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with FFmpeg; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30  */
31
32 /**
33  * @file
34  * X11 frame device demuxer by Clemens Fruhwirth <clemens@endorphin.org>
35  * and Edouard Gomez <ed.gomez@free.fr>.
36  */
37
38 #include "config.h"
39 #include "libavutil/log.h"
40 #include "libavutil/opt.h"
41 #include "libavutil/parseutils.h"
42 #include <time.h>
43 #include <X11/X.h>
44 #include <X11/Xlib.h>
45 #include <X11/Xlibint.h>
46 #include <X11/Xproto.h>
47 #include <X11/Xutil.h>
48 #include <sys/shm.h>
49 #include <X11/extensions/shape.h>
50 #include <X11/extensions/XShm.h>
51 #include <X11/extensions/Xfixes.h>
52 #include "avdevice.h"
53
54 /**
55  * X11 Device Demuxer context
56  */
57 struct x11_grab
58 {
59     const AVClass *class;    /**< Class for private options. */
60     int frame_size;          /**< Size in bytes of a grabbed frame */
61     AVRational time_base;    /**< Time base */
62     int64_t time_frame;      /**< Current time */
63
64     char *video_size;        /**< String describing video size, set by a private option. */
65     int height;              /**< Height of the grab frame */
66     int width;               /**< Width of the grab frame */
67     int x_off;               /**< Horizontal top-left corner coordinate */
68     int y_off;               /**< Vertical top-left corner coordinate */
69
70     Display *dpy;            /**< X11 display from which x11grab grabs frames */
71     XImage *image;           /**< X11 image holding the grab */
72     int use_shm;             /**< !0 when using XShm extension */
73     XShmSegmentInfo shminfo; /**< When using XShm, keeps track of XShm infos */
74     int  draw_mouse;         /**< Set by a private option. */
75     int  follow_mouse;       /**< Set by a private option. */
76     int  show_region;        /**< set by a private option. */
77     char *framerate;         /**< Set by a private option. */
78
79     Window region_win;       /**< This is used by show_region option. */
80 };
81
82 #define REGION_WIN_BORDER 3
83 /**
84  * Draw grabbing region window
85  *
86  * @param s x11_grab context
87  */
88 static void
89 x11grab_draw_region_win(struct x11_grab *s)
90 {
91     Display *dpy = s->dpy;
92     int screen;
93     Window win = s->region_win;
94     GC gc;
95
96     screen = DefaultScreen(dpy);
97     gc = XCreateGC(dpy, win, 0, 0);
98     XSetForeground(dpy, gc, WhitePixel(dpy, screen));
99     XSetBackground(dpy, gc, BlackPixel(dpy, screen));
100     XSetLineAttributes(dpy, gc, REGION_WIN_BORDER, LineDoubleDash, 0, 0);
101     XDrawRectangle(dpy, win, gc,
102                    1, 1,
103                    (s->width  + REGION_WIN_BORDER * 2) - 1 * 2 - 1,
104                    (s->height + REGION_WIN_BORDER * 2) - 1 * 2 - 1);
105     XFreeGC(dpy, gc);
106 }
107
108 /**
109  * Initialize grabbing region window
110  *
111  * @param s x11_grab context
112  */
113 static void
114 x11grab_region_win_init(struct x11_grab *s)
115 {
116     Display *dpy = s->dpy;
117     int screen;
118     XSetWindowAttributes attribs;
119     XRectangle rect;
120
121     screen = DefaultScreen(dpy);
122     attribs.override_redirect = True;
123     s->region_win = XCreateWindow(dpy, RootWindow(dpy, screen),
124                                   s->x_off  - REGION_WIN_BORDER,
125                                   s->y_off  - REGION_WIN_BORDER,
126                                   s->width  + REGION_WIN_BORDER * 2,
127                                   s->height + REGION_WIN_BORDER * 2,
128                                   0, CopyFromParent,
129                                   InputOutput, CopyFromParent,
130                                   CWOverrideRedirect, &attribs);
131     rect.x = 0;
132     rect.y = 0;
133     rect.width  = s->width;
134     rect.height = s->height;
135     XShapeCombineRectangles(dpy, s->region_win,
136                             ShapeBounding, REGION_WIN_BORDER, REGION_WIN_BORDER,
137                             &rect, 1, ShapeSubtract, 0);
138     XMapWindow(dpy, s->region_win);
139     XSelectInput(dpy, s->region_win, ExposureMask | StructureNotifyMask);
140     x11grab_draw_region_win(s);
141 }
142
143 /**
144  * Initialize the x11 grab device demuxer (public device demuxer API).
145  *
146  * @param s1 Context from avformat core
147  * @param ap Parameters from avformat core
148  * @return <ul>
149  *          <li>AVERROR(ENOMEM) no memory left</li>
150  *          <li>AVERROR(EIO) other failure case</li>
151  *          <li>0 success</li>
152  *         </ul>
153  */
154 static int
155 x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
156 {
157     struct x11_grab *x11grab = s1->priv_data;
158     Display *dpy;
159     AVStream *st = NULL;
160     enum PixelFormat input_pixfmt;
161     XImage *image;
162     int x_off = 0;
163     int y_off = 0;
164     int screen;
165     int use_shm;
166     char *dpyname, *offset;
167     int ret = 0;
168     AVRational framerate;
169
170     dpyname = av_strdup(s1->filename);
171     offset = strchr(dpyname, '+');
172     if (offset) {
173         sscanf(offset, "%d,%d", &x_off, &y_off);
174         x11grab->draw_mouse = !strstr(offset, "nomouse");
175         *offset= 0;
176     }
177
178     if ((ret = av_parse_video_size(&x11grab->width, &x11grab->height, x11grab->video_size)) < 0) {
179         av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n");
180         goto out;
181     }
182     if ((ret = av_parse_video_rate(&framerate, x11grab->framerate)) < 0) {
183         av_log(s1, AV_LOG_ERROR, "Could not parse framerate: %s.\n", x11grab->framerate);
184         goto out;
185     }
186 #if FF_API_FORMAT_PARAMETERS
187     if (ap->width > 0)
188         x11grab->width = ap->width;
189     if (ap->height > 0)
190         x11grab->height = ap->height;
191     if (ap->time_base.num)
192         framerate = (AVRational){ap->time_base.den, ap->time_base.num};
193 #endif
194     av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n",
195            s1->filename, dpyname, x_off, y_off, x11grab->width, x11grab->height);
196
197     dpy = XOpenDisplay(dpyname);
198     av_freep(&dpyname);
199     if(!dpy) {
200         av_log(s1, AV_LOG_ERROR, "Could not open X display.\n");
201         ret = AVERROR(EIO);
202         goto out;
203     }
204
205     st = av_new_stream(s1, 0);
206     if (!st) {
207         ret = AVERROR(ENOMEM);
208         goto out;
209     }
210     av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
211
212     screen = DefaultScreen(dpy);
213
214     if (x11grab->follow_mouse) {
215         int screen_w, screen_h;
216         Window w;
217
218         screen_w = DisplayWidth(dpy, screen);
219         screen_h = DisplayHeight(dpy, screen);
220         XQueryPointer(dpy, RootWindow(dpy, screen), &w, &w, &x_off, &y_off, &ret, &ret, &ret);
221         x_off -= x11grab->width / 2;
222         y_off -= x11grab->height / 2;
223         x_off = FFMIN(FFMAX(x_off, 0), screen_w - x11grab->width);
224         y_off = FFMIN(FFMAX(y_off, 0), screen_h - x11grab->height);
225         av_log(s1, AV_LOG_INFO, "followmouse is enabled, resetting grabbing region to x: %d y: %d\n", x_off, y_off);
226     }
227
228     use_shm = XShmQueryExtension(dpy);
229     av_log(s1, AV_LOG_INFO, "shared memory extension%s found\n", use_shm ? "" : " not");
230
231     if(use_shm) {
232         int scr = XDefaultScreen(dpy);
233         image = XShmCreateImage(dpy,
234                                 DefaultVisual(dpy, scr),
235                                 DefaultDepth(dpy, scr),
236                                 ZPixmap,
237                                 NULL,
238                                 &x11grab->shminfo,
239                                 x11grab->width, x11grab->height);
240         x11grab->shminfo.shmid = shmget(IPC_PRIVATE,
241                                         image->bytes_per_line * image->height,
242                                         IPC_CREAT|0777);
243         if (x11grab->shminfo.shmid == -1) {
244             av_log(s1, AV_LOG_ERROR, "Fatal: Can't get shared memory!\n");
245             ret = AVERROR(ENOMEM);
246             goto out;
247         }
248         x11grab->shminfo.shmaddr = image->data = shmat(x11grab->shminfo.shmid, 0, 0);
249         x11grab->shminfo.readOnly = False;
250
251         if (!XShmAttach(dpy, &x11grab->shminfo)) {
252             av_log(s1, AV_LOG_ERROR, "Fatal: Failed to attach shared memory!\n");
253             /* needs some better error subroutine :) */
254             ret = AVERROR(EIO);
255             goto out;
256         }
257     } else {
258         image = XGetImage(dpy, RootWindow(dpy, screen),
259                           x_off,y_off,
260                           x11grab->width, x11grab->height,
261                           AllPlanes, ZPixmap);
262     }
263
264     switch (image->bits_per_pixel) {
265     case 8:
266         av_log (s1, AV_LOG_DEBUG, "8 bit palette\n");
267         input_pixfmt = PIX_FMT_PAL8;
268         break;
269     case 16:
270         if (       image->red_mask   == 0xf800 &&
271                    image->green_mask == 0x07e0 &&
272                    image->blue_mask  == 0x001f ) {
273             av_log (s1, AV_LOG_DEBUG, "16 bit RGB565\n");
274             input_pixfmt = PIX_FMT_RGB565;
275         } else if (image->red_mask   == 0x7c00 &&
276                    image->green_mask == 0x03e0 &&
277                    image->blue_mask  == 0x001f ) {
278             av_log(s1, AV_LOG_DEBUG, "16 bit RGB555\n");
279             input_pixfmt = PIX_FMT_RGB555;
280         } else {
281             av_log(s1, AV_LOG_ERROR, "RGB ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel);
282             av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask);
283             ret = AVERROR(EIO);
284             goto out;
285         }
286         break;
287     case 24:
288         if (        image->red_mask   == 0xff0000 &&
289                     image->green_mask == 0x00ff00 &&
290                     image->blue_mask  == 0x0000ff ) {
291             input_pixfmt = PIX_FMT_BGR24;
292         } else if ( image->red_mask   == 0x0000ff &&
293                     image->green_mask == 0x00ff00 &&
294                     image->blue_mask  == 0xff0000 ) {
295             input_pixfmt = PIX_FMT_RGB24;
296         } else {
297             av_log(s1, AV_LOG_ERROR,"rgb ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel);
298             av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask);
299             ret = AVERROR(EIO);
300             goto out;
301         }
302         break;
303     case 32:
304         input_pixfmt = PIX_FMT_RGB32;
305         break;
306     default:
307         av_log(s1, AV_LOG_ERROR, "image depth %i not supported ... aborting\n", image->bits_per_pixel);
308         ret = AVERROR(EINVAL);
309         goto out;
310     }
311
312     x11grab->frame_size = x11grab->width * x11grab->height * image->bits_per_pixel/8;
313     x11grab->dpy = dpy;
314     x11grab->time_base  = (AVRational){framerate.den, framerate.num};
315     x11grab->time_frame = av_gettime() / av_q2d(x11grab->time_base);
316     x11grab->x_off = x_off;
317     x11grab->y_off = y_off;
318     x11grab->image = image;
319     x11grab->use_shm = use_shm;
320
321     st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
322     st->codec->codec_id = CODEC_ID_RAWVIDEO;
323     st->codec->width  = x11grab->width;
324     st->codec->height = x11grab->height;
325     st->codec->pix_fmt = input_pixfmt;
326     st->codec->time_base = x11grab->time_base;
327     st->codec->bit_rate = x11grab->frame_size * 1/av_q2d(x11grab->time_base) * 8;
328
329 out:
330     return ret;
331 }
332
333 /**
334  * Paint a mouse pointer in an X11 image.
335  *
336  * @param image image to paint the mouse pointer to
337  * @param s context used to retrieve original grabbing rectangle
338  *          coordinates
339  */
340 static void
341 paint_mouse_pointer(XImage *image, struct x11_grab *s)
342 {
343     int x_off = s->x_off;
344     int y_off = s->y_off;
345     int width = s->width;
346     int height = s->height;
347     Display *dpy = s->dpy;
348     XFixesCursorImage *xcim;
349     int x, y;
350     int line, column;
351     int to_line, to_column;
352     int pixstride = image->bits_per_pixel >> 3;
353     /* Warning: in its insanity, xlib provides unsigned image data through a
354      * char* pointer, so we have to make it uint8_t to make things not break.
355      * Anyone who performs further investigation of the xlib API likely risks
356      * permanent brain damage. */
357     uint8_t *pix = image->data;
358
359     /* Code doesn't currently support 16-bit or PAL8 */
360     if (image->bits_per_pixel != 24 && image->bits_per_pixel != 32)
361         return;
362
363     xcim = XFixesGetCursorImage(dpy);
364
365     x = xcim->x - xcim->xhot;
366     y = xcim->y - xcim->yhot;
367
368     to_line = FFMIN((y + xcim->height), (height + y_off));
369     to_column = FFMIN((x + xcim->width), (width + x_off));
370
371     for (line = FFMAX(y, y_off); line < to_line; line++) {
372         for (column = FFMAX(x, x_off); column < to_column; column++) {
373             int  xcim_addr = (line - y) * xcim->width + column - x;
374             int image_addr = ((line - y_off) * width + column - x_off) * pixstride;
375             int r = (uint8_t)(xcim->pixels[xcim_addr] >>  0);
376             int g = (uint8_t)(xcim->pixels[xcim_addr] >>  8);
377             int b = (uint8_t)(xcim->pixels[xcim_addr] >> 16);
378             int a = (uint8_t)(xcim->pixels[xcim_addr] >> 24);
379
380             if (a == 255) {
381                 pix[image_addr+0] = r;
382                 pix[image_addr+1] = g;
383                 pix[image_addr+2] = b;
384             } else if (a) {
385                 /* pixel values from XFixesGetCursorImage come premultiplied by alpha */
386                 pix[image_addr+0] = r + (pix[image_addr+0]*(255-a) + 255/2) / 255;
387                 pix[image_addr+1] = g + (pix[image_addr+1]*(255-a) + 255/2) / 255;
388                 pix[image_addr+2] = b + (pix[image_addr+2]*(255-a) + 255/2) / 255;
389             }
390         }
391     }
392
393     XFree(xcim);
394     xcim = NULL;
395 }
396
397
398 /**
399  * Read new data in the image structure.
400  *
401  * @param dpy X11 display to grab from
402  * @param d
403  * @param image Image where the grab will be put
404  * @param x Top-Left grabbing rectangle horizontal coordinate
405  * @param y Top-Left grabbing rectangle vertical coordinate
406  * @return 0 if error, !0 if successful
407  */
408 static int
409 xget_zpixmap(Display *dpy, Drawable d, XImage *image, int x, int y)
410 {
411     xGetImageReply rep;
412     xGetImageReq *req;
413     long nbytes;
414
415     if (!image) {
416         return 0;
417     }
418
419     LockDisplay(dpy);
420     GetReq(GetImage, req);
421
422     /* First set up the standard stuff in the request */
423     req->drawable = d;
424     req->x = x;
425     req->y = y;
426     req->width = image->width;
427     req->height = image->height;
428     req->planeMask = (unsigned int)AllPlanes;
429     req->format = ZPixmap;
430
431     if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.length) {
432         UnlockDisplay(dpy);
433         SyncHandle();
434         return 0;
435     }
436
437     nbytes = (long)rep.length << 2;
438     _XReadPad(dpy, image->data, nbytes);
439
440     UnlockDisplay(dpy);
441     SyncHandle();
442     return 1;
443 }
444
445 /**
446  * Grab a frame from x11 (public device demuxer API).
447  *
448  * @param s1 Context from avformat core
449  * @param pkt Packet holding the brabbed frame
450  * @return frame size in bytes
451  */
452 static int
453 x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
454 {
455     struct x11_grab *s = s1->priv_data;
456     Display *dpy = s->dpy;
457     XImage *image = s->image;
458     int x_off = s->x_off;
459     int y_off = s->y_off;
460
461     int screen;
462     Window root;
463     int follow_mouse = s->follow_mouse;
464
465     int64_t curtime, delay;
466     struct timespec ts;
467
468     /* Calculate the time of the next frame */
469     s->time_frame += INT64_C(1000000);
470
471     /* wait based on the frame rate */
472     for(;;) {
473         curtime = av_gettime();
474         delay = s->time_frame * av_q2d(s->time_base) - curtime;
475         if (delay <= 0) {
476             if (delay < INT64_C(-1000000) * av_q2d(s->time_base)) {
477                 s->time_frame += INT64_C(1000000);
478             }
479             break;
480         }
481         ts.tv_sec = delay / 1000000;
482         ts.tv_nsec = (delay % 1000000) * 1000;
483         nanosleep(&ts, NULL);
484     }
485
486     av_init_packet(pkt);
487     pkt->data = image->data;
488     pkt->size = s->frame_size;
489     pkt->pts = curtime;
490
491     screen = DefaultScreen(dpy);
492     root = RootWindow(dpy, screen);
493     if (follow_mouse) {
494         int screen_w, screen_h;
495         int pointer_x, pointer_y, _;
496         Window w;
497
498         screen_w = DisplayWidth(dpy, screen);
499         screen_h = DisplayHeight(dpy, screen);
500         XQueryPointer(dpy, root, &w, &w, &pointer_x, &pointer_y, &_, &_, &_);
501         if (follow_mouse == -1) {
502             // follow the mouse, put it at center of grabbing region
503             x_off += pointer_x - s->width  / 2 - x_off;
504             y_off += pointer_y - s->height / 2 - y_off;
505         } else {
506             // follow the mouse, but only move the grabbing region when mouse
507             // reaches within certain pixels to the edge.
508             if (pointer_x > x_off + s->width - follow_mouse) {
509                 x_off += pointer_x - (x_off + s->width - follow_mouse);
510             } else if (pointer_x < x_off + follow_mouse)
511                 x_off -= (x_off + follow_mouse) - pointer_x;
512             if (pointer_y > y_off + s->height - follow_mouse) {
513                 y_off += pointer_y - (y_off + s->height - follow_mouse);
514             } else if (pointer_y < y_off + follow_mouse)
515                 y_off -= (y_off + follow_mouse) - pointer_y;
516         }
517         // adjust grabbing region position if it goes out of screen.
518         s->x_off = x_off = FFMIN(FFMAX(x_off, 0), screen_w - s->width);
519         s->y_off = y_off = FFMIN(FFMAX(y_off, 0), screen_h - s->height);
520
521         if (s->show_region && s->region_win)
522             XMoveWindow(dpy, s->region_win,
523                         s->x_off - REGION_WIN_BORDER,
524                         s->y_off - REGION_WIN_BORDER);
525     }
526
527     if (s->show_region) {
528         if (s->region_win) {
529             XEvent evt;
530             // clean up the events, and do the initinal draw or redraw.
531             for (evt.type = NoEventMask; XCheckMaskEvent(dpy, ExposureMask | StructureNotifyMask, &evt); );
532             if (evt.type)
533                 x11grab_draw_region_win(s);
534         } else {
535             x11grab_region_win_init(s);
536         }
537     }
538
539     if(s->use_shm) {
540         if (!XShmGetImage(dpy, root, image, x_off, y_off, AllPlanes)) {
541             av_log (s1, AV_LOG_INFO, "XShmGetImage() failed\n");
542         }
543     } else {
544         if (!xget_zpixmap(dpy, root, image, x_off, y_off)) {
545             av_log (s1, AV_LOG_INFO, "XGetZPixmap() failed\n");
546         }
547     }
548
549     if (s->draw_mouse) {
550         paint_mouse_pointer(image, s);
551     }
552
553     return s->frame_size;
554 }
555
556 /**
557  * Close x11 frame grabber (public device demuxer API).
558  *
559  * @param s1 Context from avformat core
560  * @return 0 success, !0 failure
561  */
562 static int
563 x11grab_read_close(AVFormatContext *s1)
564 {
565     struct x11_grab *x11grab = s1->priv_data;
566
567     /* Detach cleanly from shared mem */
568     if (x11grab->use_shm) {
569         XShmDetach(x11grab->dpy, &x11grab->shminfo);
570         shmdt(x11grab->shminfo.shmaddr);
571         shmctl(x11grab->shminfo.shmid, IPC_RMID, NULL);
572     }
573
574     /* Destroy X11 image */
575     if (x11grab->image) {
576         XDestroyImage(x11grab->image);
577         x11grab->image = NULL;
578     }
579
580     if (x11grab->region_win) {
581         XDestroyWindow(x11grab->dpy, x11grab->region_win);
582     }
583
584     /* Free X11 display */
585     XCloseDisplay(x11grab->dpy);
586     return 0;
587 }
588
589 #define OFFSET(x) offsetof(struct x11_grab, x)
590 #define DEC AV_OPT_FLAG_DECODING_PARAM
591 static const AVOption options[] = {
592     { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = "vga"}, 0, 0, DEC },
593     { "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC },
594     { "draw_mouse", "Draw the mouse pointer.", OFFSET(draw_mouse), FF_OPT_TYPE_INT, { 1 }, 0, 1, DEC },
595     { "follow_mouse", "Move the grabbing region when the mouse pointer reaches within specified amount of pixels to the edge of region.",
596       OFFSET(follow_mouse), FF_OPT_TYPE_INT, { 0 }, -1, INT_MAX, DEC, "follow_mouse" },
597     { "centered", "Keep the mouse pointer at the center of grabbing region when following.", 0, FF_OPT_TYPE_CONST, { -1 }, INT_MIN, INT_MAX, DEC, "follow_mouse" },
598     { "show_region", "Show the grabbing region.", OFFSET(show_region), FF_OPT_TYPE_INT, { 0 }, 0, 1, DEC },
599     { NULL },
600 };
601
602 static const AVClass x11_class = {
603     .class_name = "X11grab indev",
604     .item_name  = av_default_item_name,
605     .option     = options,
606     .version    = LIBAVUTIL_VERSION_INT,
607 };
608
609 /** x11 grabber device demuxer declaration */
610 AVInputFormat ff_x11_grab_device_demuxer =
611 {
612     "x11grab",
613     NULL_IF_CONFIG_SMALL("X11grab"),
614     sizeof(struct x11_grab),
615     NULL,
616     x11grab_read_header,
617     x11grab_read_packet,
618     x11grab_read_close,
619     .flags = AVFMT_NOFILE,
620     .priv_class = &x11_class,
621 };