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.

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