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.

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