You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

697 lines
20KB

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