]> git.sesse.net Git - ffmpeg/blob - libavdevice/xcbgrab.c
Merge commit '656e31ed8728b0c095d037dc9764fc8137c87200'
[ffmpeg] / libavdevice / xcbgrab.c
1 /*
2  * XCB input grabber
3  * Copyright (C) 2014 Luca Barbato <lu_zero@gentoo.org>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "config.h"
23
24 #include <stdlib.h>
25 #include <xcb/xcb.h>
26
27 #if CONFIG_LIBXCB_XFIXES
28 #include <xcb/xfixes.h>
29 #endif
30
31 #if CONFIG_LIBXCB_SHM
32 #include <sys/shm.h>
33 #include <xcb/shm.h>
34 #endif
35
36 #if CONFIG_LIBXCB_SHAPE
37 #include <xcb/shape.h>
38 #endif
39
40 #include "libavutil/internal.h"
41 #include "libavutil/mathematics.h"
42 #include "libavutil/opt.h"
43 #include "libavutil/parseutils.h"
44 #include "libavutil/time.h"
45
46 #include "libavformat/avformat.h"
47 #include "libavformat/internal.h"
48
49 typedef struct XCBGrabContext {
50     const AVClass *class;
51
52     xcb_connection_t *conn;
53     xcb_screen_t *screen;
54     xcb_window_t window;
55 #if CONFIG_LIBXCB_SHM
56     xcb_shm_seg_t segment;
57 #endif
58     int64_t time_frame;
59     AVRational time_base;
60
61     int x, y;
62     int width, height;
63     int frame_size;
64     int bpp;
65
66     int draw_mouse;
67     int follow_mouse;
68     int show_region;
69     int region_border;
70     int centered;
71
72     const char *video_size;
73     const char *framerate;
74
75     int has_shm;
76 } XCBGrabContext;
77
78 #define FOLLOW_CENTER -1
79
80 #define OFFSET(x) offsetof(XCBGrabContext, x)
81 #define D AV_OPT_FLAG_DECODING_PARAM
82 static const AVOption options[] = {
83     { "x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
84     { "y", "Initial y coordinate.", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
85     { "grab_x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
86     { "grab_y", "Initial y coordinate.", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
87     { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "vga" }, 0, 0, D },
88     { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc" }, 0, 0, D },
89     { "draw_mouse", "Draw the mouse pointer.", OFFSET(draw_mouse), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, D },
90     { "follow_mouse", "Move the grabbing region when the mouse pointer reaches within specified amount of pixels to the edge of region.",
91       OFFSET(follow_mouse), AV_OPT_TYPE_INT, { .i64 = 0 },  FOLLOW_CENTER, INT_MAX, D, "follow_mouse" },
92     { "centered", "Keep the mouse pointer at the center of grabbing region when following.", 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, INT_MIN, INT_MAX, D, "follow_mouse" },
93     { "show_region", "Show the grabbing region.", OFFSET(show_region), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
94     { "region_border", "Set the region border thickness.", OFFSET(region_border), AV_OPT_TYPE_INT, { .i64 = 3 }, 1, 128, D },
95     { NULL },
96 };
97
98 static const AVClass xcbgrab_class = {
99     .class_name = "xcbgrab indev",
100     .item_name  = av_default_item_name,
101     .option     = options,
102     .version    = LIBAVUTIL_VERSION_INT,
103     .category   = AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT,
104 };
105
106 static int xcbgrab_reposition(AVFormatContext *s,
107                               xcb_query_pointer_reply_t *p,
108                               xcb_get_geometry_reply_t *geo)
109 {
110     XCBGrabContext *c = s->priv_data;
111     int x = c->x, y = c->y;
112     int w = c->width, h = c->height, f = c->follow_mouse;
113     int p_x, p_y;
114
115     if (!p || !geo)
116         return AVERROR(EIO);
117
118     p_x = p->win_x;
119     p_y = p->win_y;
120
121     if (f == FOLLOW_CENTER) {
122         x = p_x - w / 2;
123         y = p_y - h / 2;
124     } else {
125         int left   = x + f;
126         int right  = x + w - f;
127         int top    = y + f;
128         int bottom = y + h + f;
129         if (p_x > right) {
130             x += p_x - right;
131         } else if (p_x < left) {
132             x -= left - p_x;
133         }
134         if (p_y > bottom) {
135             y += p_y - bottom;
136         } else if (p_y < top) {
137             y -= top - p_y;
138         }
139     }
140
141     c->x = FFMIN(FFMAX(0, x), geo->width  - w);
142     c->y = FFMIN(FFMAX(0, y), geo->height - h);
143
144     return 0;
145 }
146
147 static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt)
148 {
149     XCBGrabContext *c = s->priv_data;
150     xcb_get_image_cookie_t iq;
151     xcb_get_image_reply_t *img;
152     xcb_drawable_t drawable = c->screen->root;
153     uint8_t *data;
154     int length, ret;
155
156     iq  = xcb_get_image(c->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
157                         c->x, c->y, c->width, c->height, ~0);
158
159     img = xcb_get_image_reply(c->conn, iq, NULL);
160     if (!img)
161         return AVERROR(EAGAIN);
162
163     data   = xcb_get_image_data(img);
164     length = xcb_get_image_data_length(img);
165
166     ret = av_new_packet(pkt, length);
167
168     if (!ret)
169         memcpy(pkt->data, data, length);
170
171     free(img);
172
173     return ret;
174 }
175
176 static void wait_frame(AVFormatContext *s, AVPacket *pkt)
177 {
178     XCBGrabContext *c = s->priv_data;
179     int64_t curtime, delay;
180     int64_t frame_time = av_rescale_q(1, c->time_base, AV_TIME_BASE_Q);
181
182     c->time_frame += frame_time;
183
184     for (;;) {
185         curtime = av_gettime();
186         delay   = c->time_frame - curtime;
187         if (delay <= 0)
188             break;
189         av_usleep(delay);
190     }
191
192     pkt->pts = curtime;
193 }
194
195 #if CONFIG_LIBXCB_SHM
196 static int check_shm(xcb_connection_t *conn)
197 {
198     xcb_shm_query_version_cookie_t cookie = xcb_shm_query_version(conn);
199     xcb_shm_query_version_reply_t *reply;
200
201     reply = xcb_shm_query_version_reply(conn, cookie, NULL);
202     if (reply) {
203         free(reply);
204         return 1;
205     }
206
207     return 0;
208 }
209
210 static void dealloc_shm(void *unused, uint8_t *data)
211 {
212     shmdt(data);
213 }
214
215 static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket *pkt)
216 {
217     XCBGrabContext *c = s->priv_data;
218     xcb_shm_get_image_cookie_t iq;
219     xcb_shm_get_image_reply_t *img;
220     xcb_drawable_t drawable = c->screen->root;
221     uint8_t *data;
222     int size = c->frame_size + FF_INPUT_BUFFER_PADDING_SIZE;
223     int id   = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777);
224     xcb_generic_error_t *e = NULL;
225
226     if (id == -1) {
227         char errbuf[1024];
228         int err = AVERROR(errno);
229         av_strerror(err, errbuf, sizeof(errbuf));
230         av_log(s, AV_LOG_ERROR, "Cannot get %d bytes of shared memory: %s.\n",
231                size, errbuf);
232         return err;
233     }
234
235     xcb_shm_attach(c->conn, c->segment, id, 0);
236
237     iq = xcb_shm_get_image(c->conn, drawable,
238                            c->x, c->y, c->width, c->height, ~0,
239                            XCB_IMAGE_FORMAT_Z_PIXMAP, c->segment, 0);
240
241     xcb_shm_detach(c->conn, c->segment);
242
243     img = xcb_shm_get_image_reply(c->conn, iq, &e);
244
245     xcb_flush(c->conn);
246
247     if (e) {
248         av_log(s, AV_LOG_ERROR,
249                "Cannot get the image data "
250                "event_error: response_type:%u error_code:%u "
251                "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
252                e->response_type, e->error_code,
253                e->sequence, e->resource_id, e->minor_code, e->major_code);
254
255         shmctl(id, IPC_RMID, 0);
256         return AVERROR(EACCES);
257     }
258
259     free(img);
260
261     data = shmat(id, NULL, 0);
262     shmctl(id, IPC_RMID, 0);
263
264     if ((intptr_t)data == -1)
265         return AVERROR(errno);
266
267     pkt->buf = av_buffer_create(data, size, dealloc_shm, NULL, 0);
268     if (!pkt->buf) {
269         shmdt(data);
270         return AVERROR(ENOMEM);
271     }
272
273     pkt->data = pkt->buf->data;
274     pkt->size = c->frame_size;
275
276     return 0;
277 }
278 #endif /* CONFIG_LIBXCB_SHM */
279
280 #if CONFIG_LIBXCB_XFIXES
281 static int check_xfixes(xcb_connection_t *conn)
282 {
283     xcb_xfixes_query_version_cookie_t cookie;
284     xcb_xfixes_query_version_reply_t *reply;
285
286     cookie = xcb_xfixes_query_version(conn, XCB_XFIXES_MAJOR_VERSION,
287                                       XCB_XFIXES_MINOR_VERSION);
288     reply  = xcb_xfixes_query_version_reply(conn, cookie, NULL);
289
290     if (reply) {
291         free(reply);
292         return 1;
293     }
294     return 0;
295 }
296
297 #define BLEND(target, source, alpha) \
298     (target) + ((source) * (255 - (alpha)) + 255 / 2) / 255
299
300 static void xcbgrab_draw_mouse(AVFormatContext *s, AVPacket *pkt,
301                                xcb_query_pointer_reply_t *p,
302                                xcb_get_geometry_reply_t *geo)
303 {
304     XCBGrabContext *gr = s->priv_data;
305     uint32_t *cursor;
306     uint8_t *image = pkt->data;
307     int stride     = gr->bpp / 8;
308     xcb_xfixes_get_cursor_image_cookie_t cc;
309     xcb_xfixes_get_cursor_image_reply_t *ci;
310     int cx, cy, x, y, w, h, c_off, i_off;
311
312     cc = xcb_xfixes_get_cursor_image(gr->conn);
313     ci = xcb_xfixes_get_cursor_image_reply(gr->conn, cc, NULL);
314     if (!ci)
315         return;
316
317     cursor = xcb_xfixes_get_cursor_image_cursor_image(ci);
318     if (!cursor)
319         return;
320
321     cx = ci->x - ci->xhot;
322     cy = ci->y - ci->yhot;
323
324     x = FFMAX(cx, gr->x);
325     y = FFMAX(cy, gr->y);
326
327     w = FFMIN(cx + ci->width,  gr->x + gr->width)  - x;
328     h = FFMIN(cy + ci->height, gr->y + gr->height) - y;
329
330     c_off = x - cx;
331     i_off = x - gr->x;
332
333     cursor += (y - cy) * ci->width;
334     image  += (y - gr->y) * gr->width * stride;
335
336     for (y = 0; y < h; y++) {
337         cursor += c_off;
338         image  += i_off * stride;
339         for (x = 0; x < w; x++, cursor++, image += stride) {
340             int r, g, b, a;
341
342             r =  *cursor        & 0xff;
343             g = (*cursor >>  8) & 0xff;
344             b = (*cursor >> 16) & 0xff;
345             a = (*cursor >> 24) & 0xff;
346
347             if (!a)
348                 continue;
349
350             if (a == 255) {
351                 image[0] = r;
352                 image[1] = g;
353                 image[2] = b;
354             } else {
355                 image[0] = BLEND(r, image[0], a);
356                 image[1] = BLEND(g, image[1], a);
357                 image[2] = BLEND(b, image[2], a);
358             }
359
360         }
361         cursor +=  ci->width - w - c_off;
362         image  += (gr->width - w - i_off) * stride;
363     }
364
365     free(ci);
366 }
367 #endif /* CONFIG_LIBXCB_XFIXES */
368
369 static void xcbgrab_update_region(AVFormatContext *s)
370 {
371     XCBGrabContext *c     = s->priv_data;
372     const uint32_t args[] = { c->x - c->region_border,
373                               c->y - c->region_border };
374
375     xcb_configure_window(c->conn,
376                          c->window,
377                          XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
378                          args);
379 }
380
381 static int xcbgrab_read_packet(AVFormatContext *s, AVPacket *pkt)
382 {
383     XCBGrabContext *c = s->priv_data;
384     xcb_query_pointer_cookie_t pc;
385     xcb_get_geometry_cookie_t gc;
386     xcb_query_pointer_reply_t *p  = NULL;
387     xcb_get_geometry_reply_t *geo = NULL;
388     int ret = 0;
389
390     wait_frame(s, pkt);
391
392     if (c->follow_mouse || c->draw_mouse) {
393         pc  = xcb_query_pointer(c->conn, c->screen->root);
394         gc  = xcb_get_geometry(c->conn, c->screen->root);
395         p   = xcb_query_pointer_reply(c->conn, pc, NULL);
396         geo = xcb_get_geometry_reply(c->conn, gc, NULL);
397     }
398
399     if (c->follow_mouse && p->same_screen)
400         xcbgrab_reposition(s, p, geo);
401
402     if (c->show_region)
403         xcbgrab_update_region(s);
404
405 #if CONFIG_LIBXCB_SHM
406     if (c->has_shm && xcbgrab_frame_shm(s, pkt) < 0)
407         c->has_shm = 0;
408 #endif
409     if (!c->has_shm)
410         ret = xcbgrab_frame(s, pkt);
411
412 #if CONFIG_LIBXCB_XFIXES
413     if (c->draw_mouse && p->same_screen)
414         xcbgrab_draw_mouse(s, pkt, p, geo);
415 #endif
416
417     free(p);
418     free(geo);
419
420     return ret;
421 }
422
423 static av_cold int xcbgrab_read_close(AVFormatContext *s)
424 {
425     XCBGrabContext *ctx = s->priv_data;
426
427     xcb_disconnect(ctx->conn);
428
429     return 0;
430 }
431
432 static xcb_screen_t *get_screen(const xcb_setup_t *setup, int screen_num)
433 {
434     xcb_screen_iterator_t it = xcb_setup_roots_iterator(setup);
435     xcb_screen_t *screen     = NULL;
436
437     for (; it.rem > 0; xcb_screen_next (&it)) {
438         if (!screen_num) {
439             screen = it.data;
440             break;
441         }
442
443         screen_num--;
444     }
445
446     return screen;
447 }
448
449 static int pixfmt_from_pixmap_format(AVFormatContext *s, int depth,
450                                      int *pix_fmt)
451 {
452     XCBGrabContext *c        = s->priv_data;
453     const xcb_setup_t *setup = xcb_get_setup(c->conn);
454     const xcb_format_t *fmt  = xcb_setup_pixmap_formats(setup);
455     int length               = xcb_setup_pixmap_formats_length(setup);
456
457     *pix_fmt = 0;
458
459     while (length--) {
460         if (fmt->depth == depth) {
461             switch (depth) {
462             case 32:
463                 if (fmt->bits_per_pixel == 32)
464                     *pix_fmt = AV_PIX_FMT_0RGB;
465                 break;
466             case 24:
467                 if (fmt->bits_per_pixel == 32)
468                     *pix_fmt = AV_PIX_FMT_0RGB32;
469                 else if (fmt->bits_per_pixel == 24)
470                     *pix_fmt = AV_PIX_FMT_RGB24;
471                 break;
472             case 16:
473                 if (fmt->bits_per_pixel == 16)
474                     *pix_fmt = AV_PIX_FMT_RGB565;
475                 break;
476             case 15:
477                 if (fmt->bits_per_pixel == 16)
478                     *pix_fmt = AV_PIX_FMT_RGB555;
479                 break;
480             case 8:
481                 if (fmt->bits_per_pixel == 8)
482                     *pix_fmt = AV_PIX_FMT_RGB8;
483                 break;
484             }
485         }
486
487         if (*pix_fmt) {
488             c->bpp        = fmt->bits_per_pixel;
489             c->frame_size = c->width * c->height * fmt->bits_per_pixel / 8;
490             return 0;
491         }
492
493         fmt++;
494     }
495     av_log(s, AV_LOG_ERROR, "Pixmap format not mappable.\n");
496
497     return AVERROR_PATCHWELCOME;
498 }
499
500 static int create_stream(AVFormatContext *s)
501 {
502     XCBGrabContext *c = s->priv_data;
503     AVStream *st      = avformat_new_stream(s, NULL);
504     xcb_get_geometry_cookie_t gc;
505     xcb_get_geometry_reply_t *geo;
506     int ret;
507
508     if (!st)
509         return AVERROR(ENOMEM);
510
511     ret = av_parse_video_size(&c->width, &c->height, c->video_size);
512     if (ret < 0)
513         return ret;
514
515     ret = av_parse_video_rate(&st->avg_frame_rate, c->framerate);
516     if (ret < 0)
517         return ret;
518
519     avpriv_set_pts_info(st, 64, 1, 1000000);
520
521     gc  = xcb_get_geometry(c->conn, c->screen->root);
522     geo = xcb_get_geometry_reply(c->conn, gc, NULL);
523
524     c->width      = FFMIN(geo->width, c->width);
525     c->height     = FFMIN(geo->height, c->height);
526     c->time_base  = (AVRational){ st->avg_frame_rate.den,
527                                   st->avg_frame_rate.num };
528     c->time_frame = av_gettime();
529
530     st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
531     st->codec->codec_id   = AV_CODEC_ID_RAWVIDEO;
532     st->codec->width      = c->width;
533     st->codec->height     = c->height;
534     st->codec->time_base  = c->time_base;
535
536     ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codec->pix_fmt);
537
538     free(geo);
539
540     return ret;
541 }
542
543 static void draw_rectangle(AVFormatContext *s)
544 {
545     XCBGrabContext *c = s->priv_data;
546     xcb_gcontext_t gc = xcb_generate_id(c->conn);
547     uint32_t mask     = XCB_GC_FOREGROUND |
548                         XCB_GC_BACKGROUND |
549                         XCB_GC_LINE_WIDTH |
550                         XCB_GC_LINE_STYLE |
551                         XCB_GC_FILL_STYLE;
552     uint32_t values[] = { c->screen->black_pixel,
553                           c->screen->white_pixel,
554                           c->region_border,
555                           XCB_LINE_STYLE_DOUBLE_DASH,
556                           XCB_FILL_STYLE_SOLID };
557     xcb_rectangle_t r = { 1, 1,
558                           c->width  + c->region_border * 2 - 3,
559                           c->height + c->region_border * 2 - 3 };
560
561     xcb_create_gc(c->conn, gc, c->window, mask, values);
562
563     xcb_poly_rectangle(c->conn, c->window, gc, 1, &r);
564 }
565
566 static void setup_window(AVFormatContext *s)
567 {
568     XCBGrabContext *c = s->priv_data;
569     uint32_t mask     = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
570     uint32_t values[] = { 1,
571                           XCB_EVENT_MASK_EXPOSURE |
572                           XCB_EVENT_MASK_STRUCTURE_NOTIFY };
573     xcb_rectangle_t rect = { 0, 0, c->width, c->height };
574
575     c->window = xcb_generate_id(c->conn);
576
577     xcb_create_window(c->conn, XCB_COPY_FROM_PARENT,
578                       c->window,
579                       c->screen->root,
580                       c->x - c->region_border,
581                       c->y - c->region_border,
582                       c->width + c->region_border * 2,
583                       c->height + c->region_border * 2,
584                       0,
585                       XCB_WINDOW_CLASS_INPUT_OUTPUT,
586                       XCB_COPY_FROM_PARENT,
587                       mask, values);
588
589 #if CONFIG_LIBXCB_SHAPE
590     xcb_shape_rectangles(c->conn, XCB_SHAPE_SO_SUBTRACT,
591                          XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
592                          c->window,
593                          c->region_border, c->region_border,
594                          1, &rect);
595 #endif
596
597     xcb_map_window(c->conn, c->window);
598
599     draw_rectangle(s);
600 }
601
602 static av_cold int xcbgrab_read_header(AVFormatContext *s)
603 {
604     XCBGrabContext *c = s->priv_data;
605     int screen_num, ret;
606     const xcb_setup_t *setup;
607     char *display_name = av_strdup(s->filename);
608
609     if (!display_name)
610         return AVERROR(ENOMEM);
611
612     if (!sscanf(s->filename, "%[^+]+%d,%d", display_name, &c->x, &c->y)) {
613         *display_name = 0;
614         sscanf(s->filename, "+%d,%d", &c->x, &c->y);
615     }
616
617     c->conn = xcb_connect(display_name[0] ? display_name : NULL, &screen_num);
618     av_freep(&display_name);
619
620     if ((ret = xcb_connection_has_error(c->conn))) {
621         av_log(s, AV_LOG_ERROR, "Cannot open display %s, error %d.\n",
622                s->filename[0] ? s->filename : "default", ret);
623         return AVERROR(EIO);
624     }
625
626     setup = xcb_get_setup(c->conn);
627
628     c->screen = get_screen(setup, screen_num);
629     if (!c->screen) {
630         av_log(s, AV_LOG_ERROR, "The screen %d does not exist.\n",
631                screen_num);
632         xcbgrab_read_close(s);
633         return AVERROR(EIO);
634     }
635
636     ret = create_stream(s);
637
638     if (ret < 0) {
639         xcbgrab_read_close(s);
640         return ret;
641     }
642
643 #if CONFIG_LIBXCB_SHM
644     if ((c->has_shm = check_shm(c->conn)))
645         c->segment = xcb_generate_id(c->conn);
646 #endif
647
648 #if CONFIG_LIBXCB_XFIXES
649     if (c->draw_mouse) {
650         if (!(c->draw_mouse = check_xfixes(c->conn))) {
651             av_log(s, AV_LOG_WARNING,
652                    "XFixes not available, cannot draw the mouse.\n");
653         }
654         if (c->bpp < 24) {
655             avpriv_report_missing_feature(s, "%d bits per pixel screen",
656                                           c->bpp);
657             c->draw_mouse = 0;
658         }
659     }
660 #endif
661
662     if (c->show_region)
663         setup_window(s);
664
665     return 0;
666 }
667
668 AVInputFormat ff_x11grab_xcb_demuxer = {
669     .name           = "x11grab",
670     .long_name      = NULL_IF_CONFIG_SMALL("X11 screen capture, using XCB"),
671     .priv_data_size = sizeof(XCBGrabContext),
672     .read_header    = xcbgrab_read_header,
673     .read_packet    = xcbgrab_read_packet,
674     .read_close     = xcbgrab_read_close,
675     .flags          = AVFMT_NOFILE,
676     .priv_class     = &xcbgrab_class,
677 };