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.

616 lines
21KB

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