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.

621 lines
21KB

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