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. #include <xcb/shape.h>
  25. #if CONFIG_LIBXCB_XFIXES
  26. #include <xcb/xfixes.h>
  27. #endif
  28. #if CONFIG_LIBXCB_SHM
  29. #include <sys/shm.h>
  30. #include <xcb/shm.h>
  31. #endif
  32. #include "libavutil/internal.h"
  33. #include "libavutil/mathematics.h"
  34. #include "libavutil/opt.h"
  35. #include "libavutil/parseutils.h"
  36. #include "libavutil/time.h"
  37. #include "libavformat/avformat.h"
  38. #include "libavformat/internal.h"
  39. typedef struct XCBGrabContext {
  40. const AVClass *class;
  41. xcb_connection_t *conn;
  42. xcb_screen_t *screen;
  43. xcb_window_t window;
  44. #if CONFIG_LIBXCB_SHM
  45. xcb_shm_seg_t segment;
  46. #endif
  47. int64_t time_frame;
  48. AVRational time_base;
  49. int x, y;
  50. int width, height;
  51. int frame_size;
  52. int bpp;
  53. int draw_mouse;
  54. int follow_mouse;
  55. int show_region;
  56. int region_border;
  57. int centered;
  58. const char *video_size;
  59. const char *framerate;
  60. int has_shm;
  61. } XCBGrabContext;
  62. #define FOLLOW_CENTER -1
  63. #define OFFSET(x) offsetof(XCBGrabContext, x)
  64. #define D AV_OPT_FLAG_DECODING_PARAM
  65. static const AVOption options[] = {
  66. { "x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
  67. { "y", "Initial y coordinate.", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
  68. { "grab_x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
  69. { "grab_y", "Initial y coordinate.", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
  70. { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "vga" }, 0, 0, D },
  71. { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc" }, 0, 0, D },
  72. { "draw_mouse", "Draw the mouse pointer.", OFFSET(draw_mouse), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, D },
  73. { "follow_mouse", "Move the grabbing region when the mouse pointer reaches within specified amount of pixels to the edge of region.",
  74. OFFSET(follow_mouse), AV_OPT_TYPE_INT, { .i64 = 0 }, FOLLOW_CENTER, INT_MAX, D, "follow_mouse" },
  75. { "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" },
  76. { "show_region", "Show the grabbing region.", OFFSET(show_region), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
  77. { "region_border", "Set the region border thickness.", OFFSET(region_border), AV_OPT_TYPE_INT, { .i64 = 3 }, 1, 128, D },
  78. { NULL },
  79. };
  80. static const AVClass xcbgrab_class = {
  81. .class_name = "xcbgrab indev",
  82. .item_name = av_default_item_name,
  83. .option = options,
  84. .version = LIBAVUTIL_VERSION_INT,
  85. };
  86. static int xcbgrab_reposition(AVFormatContext *s,
  87. xcb_query_pointer_reply_t *p,
  88. xcb_get_geometry_reply_t *geo)
  89. {
  90. XCBGrabContext *c = s->priv_data;
  91. int x = c->x, y = c->y;
  92. int w = c->width, h = c->height, f = c->follow_mouse;
  93. int p_x, p_y;
  94. if (!p || !geo)
  95. return AVERROR(EIO);
  96. p_x = p->win_x;
  97. p_y = p->win_y;
  98. if (f == FOLLOW_CENTER) {
  99. x = p_x - w / 2;
  100. y = p_y - h / 2;
  101. } else {
  102. int left = x + f;
  103. int right = x + w - f;
  104. int top = y + f;
  105. int bottom = y + h + f;
  106. if (p_x > right) {
  107. x += p_x - right;
  108. } else if (p_x < left) {
  109. x -= left - p_x;
  110. }
  111. if (p_y > bottom) {
  112. y += p_y - bottom;
  113. } else if (p_y < top) {
  114. y -= top - p_y;
  115. }
  116. }
  117. c->x = FFMIN(FFMAX(0, x), geo->width - w);
  118. c->y = FFMIN(FFMAX(0, y), geo->height - h);
  119. return 0;
  120. }
  121. static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt)
  122. {
  123. XCBGrabContext *c = s->priv_data;
  124. xcb_get_image_cookie_t iq;
  125. xcb_get_image_reply_t *img;
  126. xcb_drawable_t drawable = c->screen->root;
  127. xcb_generic_error_t *e = NULL;
  128. uint8_t *data;
  129. int length, ret;
  130. iq = xcb_get_image(c->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
  131. c->x, c->y, c->width, c->height, ~0);
  132. img = xcb_get_image_reply(c->conn, iq, &e);
  133. if (e) {
  134. av_log(s, AV_LOG_ERROR,
  135. "Cannot get the image data "
  136. "event_error: response_type:%u error_code:%u "
  137. "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
  138. e->response_type, e->error_code,
  139. e->sequence, e->resource_id, e->minor_code, e->major_code);
  140. return AVERROR(EACCES);
  141. }
  142. if (!img)
  143. return AVERROR(EAGAIN);
  144. data = xcb_get_image_data(img);
  145. length = xcb_get_image_data_length(img);
  146. ret = av_new_packet(pkt, length);
  147. if (!ret)
  148. memcpy(pkt->data, data, length);
  149. free(img);
  150. return ret;
  151. }
  152. static void wait_frame(AVFormatContext *s, AVPacket *pkt)
  153. {
  154. XCBGrabContext *c = s->priv_data;
  155. int64_t curtime, delay;
  156. int64_t frame_time = av_rescale_q(1, c->time_base, AV_TIME_BASE_Q);
  157. c->time_frame += frame_time;
  158. for (;;) {
  159. curtime = av_gettime();
  160. delay = c->time_frame - curtime;
  161. if (delay <= 0)
  162. break;
  163. av_usleep(delay);
  164. }
  165. pkt->pts = curtime;
  166. }
  167. #if CONFIG_LIBXCB_SHM
  168. static int check_shm(xcb_connection_t *conn)
  169. {
  170. xcb_shm_query_version_cookie_t cookie = xcb_shm_query_version(conn);
  171. xcb_shm_query_version_reply_t *reply;
  172. reply = xcb_shm_query_version_reply(conn, cookie, NULL);
  173. if (reply) {
  174. free(reply);
  175. return 1;
  176. }
  177. return 0;
  178. }
  179. static void dealloc_shm(void *unused, uint8_t *data)
  180. {
  181. shmdt(data);
  182. }
  183. static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket *pkt)
  184. {
  185. XCBGrabContext *c = s->priv_data;
  186. xcb_shm_get_image_cookie_t iq;
  187. xcb_shm_get_image_reply_t *img;
  188. xcb_drawable_t drawable = c->screen->root;
  189. uint8_t *data;
  190. int size = c->frame_size + AV_INPUT_BUFFER_PADDING_SIZE;
  191. int id = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777);
  192. xcb_generic_error_t *e = NULL;
  193. if (id == -1) {
  194. char errbuf[1024];
  195. int err = AVERROR(errno);
  196. av_strerror(err, errbuf, sizeof(errbuf));
  197. av_log(s, AV_LOG_ERROR, "Cannot get %d bytes of shared memory: %s.\n",
  198. size, errbuf);
  199. return err;
  200. }
  201. xcb_shm_attach(c->conn, c->segment, id, 0);
  202. iq = xcb_shm_get_image(c->conn, drawable,
  203. c->x, c->y, c->width, c->height, ~0,
  204. XCB_IMAGE_FORMAT_Z_PIXMAP, c->segment, 0);
  205. xcb_shm_detach(c->conn, c->segment);
  206. img = xcb_shm_get_image_reply(c->conn, iq, &e);
  207. xcb_flush(c->conn);
  208. if (e) {
  209. av_log(s, AV_LOG_ERROR,
  210. "Cannot get the image data "
  211. "event_error: response_type:%u error_code:%u "
  212. "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
  213. e->response_type, e->error_code,
  214. e->sequence, e->resource_id, e->minor_code, e->major_code);
  215. shmctl(id, IPC_RMID, 0);
  216. return AVERROR(EACCES);
  217. }
  218. free(img);
  219. data = shmat(id, NULL, 0);
  220. shmctl(id, IPC_RMID, 0);
  221. if ((intptr_t)data == -1)
  222. return AVERROR(errno);
  223. pkt->buf = av_buffer_create(data, size, dealloc_shm, NULL, 0);
  224. if (!pkt->buf) {
  225. shmdt(data);
  226. return AVERROR(ENOMEM);
  227. }
  228. pkt->data = pkt->buf->data;
  229. pkt->size = c->frame_size;
  230. return 0;
  231. }
  232. #endif /* CONFIG_LIBXCB_SHM */
  233. #if CONFIG_LIBXCB_XFIXES
  234. static int check_xfixes(xcb_connection_t *conn)
  235. {
  236. xcb_xfixes_query_version_cookie_t cookie;
  237. xcb_xfixes_query_version_reply_t *reply;
  238. cookie = xcb_xfixes_query_version(conn, XCB_XFIXES_MAJOR_VERSION,
  239. XCB_XFIXES_MINOR_VERSION);
  240. reply = xcb_xfixes_query_version_reply(conn, cookie, NULL);
  241. if (reply) {
  242. free(reply);
  243. return 1;
  244. }
  245. return 0;
  246. }
  247. #define BLEND(target, source, alpha) \
  248. (target) + ((source) * (255 - (alpha)) + 255 / 2) / 255
  249. static void xcbgrab_draw_mouse(AVFormatContext *s, AVPacket *pkt,
  250. xcb_query_pointer_reply_t *p,
  251. xcb_get_geometry_reply_t *geo)
  252. {
  253. XCBGrabContext *gr = s->priv_data;
  254. uint32_t *cursor;
  255. uint8_t *image = pkt->data;
  256. int stride = gr->bpp / 8;
  257. xcb_xfixes_get_cursor_image_cookie_t cc;
  258. xcb_xfixes_get_cursor_image_reply_t *ci;
  259. int cx, cy, x, y, w, h, c_off, i_off;
  260. cc = xcb_xfixes_get_cursor_image(gr->conn);
  261. ci = xcb_xfixes_get_cursor_image_reply(gr->conn, cc, NULL);
  262. if (!ci)
  263. return;
  264. cursor = xcb_xfixes_get_cursor_image_cursor_image(ci);
  265. if (!cursor)
  266. return;
  267. cx = ci->x - ci->xhot;
  268. cy = ci->y - ci->yhot;
  269. x = FFMAX(cx, gr->x);
  270. y = FFMAX(cy, gr->y);
  271. w = FFMIN(cx + ci->width, gr->x + gr->width) - x;
  272. h = FFMIN(cy + ci->height, gr->y + gr->height) - y;
  273. c_off = x - cx;
  274. i_off = x - gr->x;
  275. cursor += (y - cy) * ci->width;
  276. image += (y - gr->y) * gr->width * stride;
  277. for (y = 0; y < h; y++) {
  278. cursor += c_off;
  279. image += i_off * stride;
  280. for (x = 0; x < w; x++, cursor++, image += stride) {
  281. int r, g, b, a;
  282. r = *cursor & 0xff;
  283. g = (*cursor >> 8) & 0xff;
  284. b = (*cursor >> 16) & 0xff;
  285. a = (*cursor >> 24) & 0xff;
  286. if (!a)
  287. continue;
  288. if (a == 255) {
  289. image[0] = r;
  290. image[1] = g;
  291. image[2] = b;
  292. } else {
  293. image[0] = BLEND(r, image[0], a);
  294. image[1] = BLEND(g, image[1], a);
  295. image[2] = BLEND(b, image[2], a);
  296. }
  297. }
  298. cursor += ci->width - w - c_off;
  299. image += (gr->width - w - i_off) * stride;
  300. }
  301. free(ci);
  302. }
  303. #endif /* CONFIG_LIBXCB_XFIXES */
  304. static void xcbgrab_update_region(AVFormatContext *s)
  305. {
  306. XCBGrabContext *c = s->priv_data;
  307. const uint32_t args[] = { c->x - c->region_border,
  308. c->y - c->region_border };
  309. xcb_configure_window(c->conn,
  310. c->window,
  311. XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
  312. args);
  313. }
  314. static int xcbgrab_read_packet(AVFormatContext *s, AVPacket *pkt)
  315. {
  316. XCBGrabContext *c = s->priv_data;
  317. xcb_query_pointer_cookie_t pc;
  318. xcb_get_geometry_cookie_t gc;
  319. xcb_query_pointer_reply_t *p = NULL;
  320. xcb_get_geometry_reply_t *geo = NULL;
  321. int ret = 0;
  322. wait_frame(s, pkt);
  323. if (c->follow_mouse || c->draw_mouse) {
  324. pc = xcb_query_pointer(c->conn, c->screen->root);
  325. gc = xcb_get_geometry(c->conn, c->screen->root);
  326. p = xcb_query_pointer_reply(c->conn, pc, NULL);
  327. geo = xcb_get_geometry_reply(c->conn, gc, NULL);
  328. }
  329. if (c->follow_mouse && p->same_screen)
  330. xcbgrab_reposition(s, p, geo);
  331. if (c->show_region)
  332. xcbgrab_update_region(s);
  333. #if CONFIG_LIBXCB_SHM
  334. if (c->has_shm && xcbgrab_frame_shm(s, pkt) < 0)
  335. c->has_shm = 0;
  336. #endif
  337. if (!c->has_shm)
  338. ret = xcbgrab_frame(s, pkt);
  339. #if CONFIG_LIBXCB_XFIXES
  340. if (ret >= 0 && c->draw_mouse && p->same_screen)
  341. xcbgrab_draw_mouse(s, pkt, p, geo);
  342. #endif
  343. free(p);
  344. free(geo);
  345. return ret;
  346. }
  347. static av_cold int xcbgrab_read_close(AVFormatContext *s)
  348. {
  349. XCBGrabContext *ctx = s->priv_data;
  350. xcb_disconnect(ctx->conn);
  351. return 0;
  352. }
  353. static xcb_screen_t *get_screen(const xcb_setup_t *setup, int screen_num)
  354. {
  355. xcb_screen_iterator_t it = xcb_setup_roots_iterator(setup);
  356. xcb_screen_t *screen = NULL;
  357. for (; it.rem > 0; xcb_screen_next (&it)) {
  358. if (!screen_num) {
  359. screen = it.data;
  360. break;
  361. }
  362. screen_num--;
  363. }
  364. return screen;
  365. }
  366. static int pixfmt_from_pixmap_format(AVFormatContext *s, int depth,
  367. int *pix_fmt)
  368. {
  369. XCBGrabContext *c = s->priv_data;
  370. const xcb_setup_t *setup = xcb_get_setup(c->conn);
  371. const xcb_format_t *fmt = xcb_setup_pixmap_formats(setup);
  372. int length = xcb_setup_pixmap_formats_length(setup);
  373. *pix_fmt = 0;
  374. while (length--) {
  375. if (fmt->depth == depth) {
  376. switch (depth) {
  377. case 32:
  378. if (fmt->bits_per_pixel == 32)
  379. *pix_fmt = AV_PIX_FMT_ARGB;
  380. break;
  381. case 24:
  382. if (fmt->bits_per_pixel == 32)
  383. *pix_fmt = AV_PIX_FMT_RGB32;
  384. else if (fmt->bits_per_pixel == 24)
  385. *pix_fmt = AV_PIX_FMT_RGB24;
  386. break;
  387. case 16:
  388. if (fmt->bits_per_pixel == 16)
  389. *pix_fmt = AV_PIX_FMT_RGB565;
  390. break;
  391. case 15:
  392. if (fmt->bits_per_pixel == 16)
  393. *pix_fmt = AV_PIX_FMT_RGB555;
  394. break;
  395. case 8:
  396. if (fmt->bits_per_pixel == 8)
  397. *pix_fmt = AV_PIX_FMT_RGB8;
  398. break;
  399. }
  400. }
  401. if (*pix_fmt) {
  402. c->bpp = fmt->bits_per_pixel;
  403. c->frame_size = c->width * c->height * fmt->bits_per_pixel / 8;
  404. return 0;
  405. }
  406. fmt++;
  407. }
  408. avpriv_report_missing_feature(s, "Mapping this pixmap format");
  409. return AVERROR_PATCHWELCOME;
  410. }
  411. static int create_stream(AVFormatContext *s)
  412. {
  413. XCBGrabContext *c = s->priv_data;
  414. AVStream *st = avformat_new_stream(s, NULL);
  415. xcb_get_geometry_cookie_t gc;
  416. xcb_get_geometry_reply_t *geo;
  417. int ret;
  418. if (!st)
  419. return AVERROR(ENOMEM);
  420. ret = av_parse_video_size(&c->width, &c->height, c->video_size);
  421. if (ret < 0)
  422. return ret;
  423. ret = av_parse_video_rate(&st->avg_frame_rate, c->framerate);
  424. if (ret < 0)
  425. return ret;
  426. avpriv_set_pts_info(st, 64, 1, 1000000);
  427. gc = xcb_get_geometry(c->conn, c->screen->root);
  428. geo = xcb_get_geometry_reply(c->conn, gc, NULL);
  429. if (c->x + c->width > geo->width ||
  430. c->y + c->height > geo->height) {
  431. av_log(s, AV_LOG_ERROR,
  432. "Capture area %dx%d at position %d.%d "
  433. "outside the screen size %dx%d\n",
  434. c->width, c->height,
  435. c->x, c->y,
  436. geo->width, geo->height);
  437. return AVERROR(EINVAL);
  438. }
  439. c->time_base = (AVRational){ st->avg_frame_rate.den,
  440. st->avg_frame_rate.num };
  441. c->time_frame = av_gettime();
  442. st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
  443. st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
  444. st->codecpar->width = c->width;
  445. st->codecpar->height = c->height;
  446. ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codecpar->format);
  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_xcbgrab_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. };