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.

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