FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
xcbgrab.c
Go to the documentation of this file.
1 /*
2  * XCB input grabber
3  * Copyright (C) 2014 Luca Barbato <lu_zero@gentoo.org>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "config.h"
23 
24 #include <stdlib.h>
25 #include <xcb/xcb.h>
26 
27 #if CONFIG_LIBXCB_XFIXES
28 #include <xcb/xfixes.h>
29 #endif
30 
31 #if CONFIG_LIBXCB_SHM
32 #include <sys/shm.h>
33 #include <xcb/shm.h>
34 #endif
35 
36 #if CONFIG_LIBXCB_SHAPE
37 #include <xcb/shape.h>
38 #endif
39 
40 #include "libavutil/internal.h"
41 #include "libavutil/mathematics.h"
42 #include "libavutil/opt.h"
43 #include "libavutil/parseutils.h"
44 #include "libavutil/time.h"
45 
46 #include "libavformat/avformat.h"
47 #include "libavformat/internal.h"
48 
49 typedef struct XCBGrabContext {
50  const AVClass *class;
51 
52  xcb_connection_t *conn;
53  xcb_screen_t *screen;
54  xcb_window_t window;
55 #if CONFIG_LIBXCB_SHM
56  xcb_shm_seg_t segment;
57 #endif
58  int64_t time_frame;
60 
61  int x, y;
62  int width, height;
64  int bpp;
65 
70  int centered;
71 
72  const char *video_size;
73  const char *framerate;
74 
75  int has_shm;
77 
78 #define FOLLOW_CENTER -1
79 
80 #define OFFSET(x) offsetof(XCBGrabContext, x)
81 #define D AV_OPT_FLAG_DECODING_PARAM
82 static const AVOption options[] = {
83  { "x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
84  { "y", "Initial y coordinate.", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
85  { "grab_x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
86  { "grab_y", "Initial y coordinate.", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
87  { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "vga" }, 0, 0, D },
88  { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc" }, 0, 0, D },
89  { "draw_mouse", "Draw the mouse pointer.", OFFSET(draw_mouse), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, D },
90  { "follow_mouse", "Move the grabbing region when the mouse pointer reaches within specified amount of pixels to the edge of region.",
91  OFFSET(follow_mouse), AV_OPT_TYPE_INT, { .i64 = 0 }, FOLLOW_CENTER, INT_MAX, D, "follow_mouse" },
92  { "centered", "Keep the mouse pointer at the center of grabbing region when following.", 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, INT_MIN, INT_MAX, D, "follow_mouse" },
93  { "show_region", "Show the grabbing region.", OFFSET(show_region), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
94  { "region_border", "Set the region border thickness.", OFFSET(region_border), AV_OPT_TYPE_INT, { .i64 = 3 }, 1, 128, D },
95  { NULL },
96 };
97 
98 static const AVClass xcbgrab_class = {
99  .class_name = "xcbgrab indev",
100  .item_name = av_default_item_name,
101  .option = options,
102  .version = LIBAVUTIL_VERSION_INT,
104 };
105 
107  xcb_query_pointer_reply_t *p,
108  xcb_get_geometry_reply_t *geo)
109 {
110  XCBGrabContext *c = s->priv_data;
111  int x = c->x, y = c->y;
112  int w = c->width, h = c->height, f = c->follow_mouse;
113  int p_x, p_y;
114 
115  if (!p || !geo)
116  return AVERROR(EIO);
117 
118  p_x = p->win_x;
119  p_y = p->win_y;
120 
121  if (f == FOLLOW_CENTER) {
122  x = p_x - w / 2;
123  y = p_y - h / 2;
124  } else {
125  int left = x + f;
126  int right = x + w - f;
127  int top = y + f;
128  int bottom = y + h + f;
129  if (p_x > right) {
130  x += p_x - right;
131  } else if (p_x < left) {
132  x -= left - p_x;
133  }
134  if (p_y > bottom) {
135  y += p_y - bottom;
136  } else if (p_y < top) {
137  y -= top - p_y;
138  }
139  }
140 
141  c->x = FFMIN(FFMAX(0, x), geo->width - w);
142  c->y = FFMIN(FFMAX(0, y), geo->height - h);
143 
144  return 0;
145 }
146 
148 {
149  XCBGrabContext *c = s->priv_data;
150  xcb_get_image_cookie_t iq;
151  xcb_get_image_reply_t *img;
152  xcb_drawable_t drawable = c->screen->root;
153  xcb_generic_error_t *e = NULL;
154  uint8_t *data;
155  int length, ret;
156 
157  iq = xcb_get_image(c->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
158  c->x, c->y, c->width, c->height, ~0);
159 
160  img = xcb_get_image_reply(c->conn, iq, &e);
161 
162  if (e) {
163  av_log(s, AV_LOG_ERROR,
164  "Cannot get the image data "
165  "event_error: response_type:%u error_code:%u "
166  "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
167  e->response_type, e->error_code,
168  e->sequence, e->resource_id, e->minor_code, e->major_code);
169  return AVERROR(EACCES);
170  }
171 
172  if (!img)
173  return AVERROR(EAGAIN);
174 
175  data = xcb_get_image_data(img);
176  length = xcb_get_image_data_length(img);
177 
178  ret = av_new_packet(pkt, length);
179 
180  if (!ret)
181  memcpy(pkt->data, data, length);
182 
183  free(img);
184 
185  return ret;
186 }
187 
189 {
190  XCBGrabContext *c = s->priv_data;
191  int64_t curtime, delay;
192  int64_t frame_time = av_rescale_q(1, c->time_base, AV_TIME_BASE_Q);
193 
194  c->time_frame += frame_time;
195 
196  for (;;) {
197  curtime = av_gettime();
198  delay = c->time_frame - curtime;
199  if (delay <= 0)
200  break;
201  av_usleep(delay);
202  }
203 
204  pkt->pts = curtime;
205 }
206 
207 #if CONFIG_LIBXCB_SHM
208 static int check_shm(xcb_connection_t *conn)
209 {
210  xcb_shm_query_version_cookie_t cookie = xcb_shm_query_version(conn);
211  xcb_shm_query_version_reply_t *reply;
212 
213  reply = xcb_shm_query_version_reply(conn, cookie, NULL);
214  if (reply) {
215  free(reply);
216  return 1;
217  }
218 
219  return 0;
220 }
221 
222 static void dealloc_shm(void *unused, uint8_t *data)
223 {
224  shmdt(data);
225 }
226 
227 static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket *pkt)
228 {
229  XCBGrabContext *c = s->priv_data;
230  xcb_shm_get_image_cookie_t iq;
231  xcb_shm_get_image_reply_t *img;
232  xcb_drawable_t drawable = c->screen->root;
233  uint8_t *data;
235  int id = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777);
236  xcb_generic_error_t *e = NULL;
237 
238  if (id == -1) {
239  char errbuf[1024];
240  int err = AVERROR(errno);
241  av_strerror(err, errbuf, sizeof(errbuf));
242  av_log(s, AV_LOG_ERROR, "Cannot get %d bytes of shared memory: %s.\n",
243  size, errbuf);
244  return err;
245  }
246 
247  xcb_shm_attach(c->conn, c->segment, id, 0);
248 
249  iq = xcb_shm_get_image(c->conn, drawable,
250  c->x, c->y, c->width, c->height, ~0,
251  XCB_IMAGE_FORMAT_Z_PIXMAP, c->segment, 0);
252 
253  xcb_shm_detach(c->conn, c->segment);
254 
255  img = xcb_shm_get_image_reply(c->conn, iq, &e);
256 
257  xcb_flush(c->conn);
258 
259  if (e) {
260  av_log(s, AV_LOG_ERROR,
261  "Cannot get the image data "
262  "event_error: response_type:%u error_code:%u "
263  "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
264  e->response_type, e->error_code,
265  e->sequence, e->resource_id, e->minor_code, e->major_code);
266 
267  shmctl(id, IPC_RMID, 0);
268  return AVERROR(EACCES);
269  }
270 
271  free(img);
272 
273  data = shmat(id, NULL, 0);
274  shmctl(id, IPC_RMID, 0);
275 
276  if ((intptr_t)data == -1)
277  return AVERROR(errno);
278 
279  pkt->buf = av_buffer_create(data, size, dealloc_shm, NULL, 0);
280  if (!pkt->buf) {
281  shmdt(data);
282  return AVERROR(ENOMEM);
283  }
284 
285  pkt->data = pkt->buf->data;
286  pkt->size = c->frame_size;
287 
288  return 0;
289 }
290 #endif /* CONFIG_LIBXCB_SHM */
291 
292 #if CONFIG_LIBXCB_XFIXES
293 static int check_xfixes(xcb_connection_t *conn)
294 {
295  xcb_xfixes_query_version_cookie_t cookie;
296  xcb_xfixes_query_version_reply_t *reply;
297 
298  cookie = xcb_xfixes_query_version(conn, XCB_XFIXES_MAJOR_VERSION,
299  XCB_XFIXES_MINOR_VERSION);
300  reply = xcb_xfixes_query_version_reply(conn, cookie, NULL);
301 
302  if (reply) {
303  free(reply);
304  return 1;
305  }
306  return 0;
307 }
308 
309 #define BLEND(target, source, alpha) \
310  (target) + ((source) * (255 - (alpha)) + 255 / 2) / 255
311 
312 static void xcbgrab_draw_mouse(AVFormatContext *s, AVPacket *pkt,
313  xcb_query_pointer_reply_t *p,
314  xcb_get_geometry_reply_t *geo)
315 {
316  XCBGrabContext *gr = s->priv_data;
317  uint32_t *cursor;
318  uint8_t *image = pkt->data;
319  int stride = gr->bpp / 8;
320  xcb_xfixes_get_cursor_image_cookie_t cc;
321  xcb_xfixes_get_cursor_image_reply_t *ci;
322  int cx, cy, x, y, w, h, c_off, i_off;
323 
324  cc = xcb_xfixes_get_cursor_image(gr->conn);
325  ci = xcb_xfixes_get_cursor_image_reply(gr->conn, cc, NULL);
326  if (!ci)
327  return;
328 
329  cursor = xcb_xfixes_get_cursor_image_cursor_image(ci);
330  if (!cursor)
331  return;
332 
333  cx = ci->x - ci->xhot;
334  cy = ci->y - ci->yhot;
335 
336  x = FFMAX(cx, gr->x);
337  y = FFMAX(cy, gr->y);
338 
339  w = FFMIN(cx + ci->width, gr->x + gr->width) - x;
340  h = FFMIN(cy + ci->height, gr->y + gr->height) - y;
341 
342  c_off = x - cx;
343  i_off = x - gr->x;
344 
345  cursor += (y - cy) * ci->width;
346  image += (y - gr->y) * gr->width * stride;
347 
348  for (y = 0; y < h; y++) {
349  cursor += c_off;
350  image += i_off * stride;
351  for (x = 0; x < w; x++, cursor++, image += stride) {
352  int r, g, b, a;
353 
354  r = *cursor & 0xff;
355  g = (*cursor >> 8) & 0xff;
356  b = (*cursor >> 16) & 0xff;
357  a = (*cursor >> 24) & 0xff;
358 
359  if (!a)
360  continue;
361 
362  if (a == 255) {
363  image[0] = r;
364  image[1] = g;
365  image[2] = b;
366  } else {
367  image[0] = BLEND(r, image[0], a);
368  image[1] = BLEND(g, image[1], a);
369  image[2] = BLEND(b, image[2], a);
370  }
371 
372  }
373  cursor += ci->width - w - c_off;
374  image += (gr->width - w - i_off) * stride;
375  }
376 
377  free(ci);
378 }
379 #endif /* CONFIG_LIBXCB_XFIXES */
380 
382 {
383  XCBGrabContext *c = s->priv_data;
384  const uint32_t args[] = { c->x - c->region_border,
385  c->y - c->region_border };
386 
387  xcb_configure_window(c->conn,
388  c->window,
389  XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
390  args);
391 }
392 
394 {
395  XCBGrabContext *c = s->priv_data;
396  xcb_query_pointer_cookie_t pc;
397  xcb_get_geometry_cookie_t gc;
398  xcb_query_pointer_reply_t *p = NULL;
399  xcb_get_geometry_reply_t *geo = NULL;
400  int ret = 0;
401 
402  wait_frame(s, pkt);
403 
404  if (c->follow_mouse || c->draw_mouse) {
405  pc = xcb_query_pointer(c->conn, c->screen->root);
406  gc = xcb_get_geometry(c->conn, c->screen->root);
407  p = xcb_query_pointer_reply(c->conn, pc, NULL);
408  geo = xcb_get_geometry_reply(c->conn, gc, NULL);
409  }
410 
411  if (c->follow_mouse && p->same_screen)
412  xcbgrab_reposition(s, p, geo);
413 
414  if (c->show_region)
416 
417 #if CONFIG_LIBXCB_SHM
418  if (c->has_shm && xcbgrab_frame_shm(s, pkt) < 0)
419  c->has_shm = 0;
420 #endif
421  if (!c->has_shm)
422  ret = xcbgrab_frame(s, pkt);
423 
424 #if CONFIG_LIBXCB_XFIXES
425  if (ret >= 0 && c->draw_mouse && p->same_screen)
426  xcbgrab_draw_mouse(s, pkt, p, geo);
427 #endif
428 
429  free(p);
430  free(geo);
431 
432  return ret;
433 }
434 
436 {
437  XCBGrabContext *ctx = s->priv_data;
438 
439  xcb_disconnect(ctx->conn);
440 
441  return 0;
442 }
443 
444 static xcb_screen_t *get_screen(const xcb_setup_t *setup, int screen_num)
445 {
446  xcb_screen_iterator_t it = xcb_setup_roots_iterator(setup);
447  xcb_screen_t *screen = NULL;
448 
449  for (; it.rem > 0; xcb_screen_next (&it)) {
450  if (!screen_num) {
451  screen = it.data;
452  break;
453  }
454 
455  screen_num--;
456  }
457 
458  return screen;
459 }
460 
462  int *pix_fmt)
463 {
464  XCBGrabContext *c = s->priv_data;
465  const xcb_setup_t *setup = xcb_get_setup(c->conn);
466  const xcb_format_t *fmt = xcb_setup_pixmap_formats(setup);
467  int length = xcb_setup_pixmap_formats_length(setup);
468 
469  *pix_fmt = 0;
470 
471  while (length--) {
472  if (fmt->depth == depth) {
473  switch (depth) {
474  case 32:
475  if (fmt->bits_per_pixel == 32)
476  *pix_fmt = AV_PIX_FMT_0RGB;
477  break;
478  case 24:
479  if (fmt->bits_per_pixel == 32)
480  *pix_fmt = AV_PIX_FMT_0RGB32;
481  else if (fmt->bits_per_pixel == 24)
482  *pix_fmt = AV_PIX_FMT_RGB24;
483  break;
484  case 16:
485  if (fmt->bits_per_pixel == 16)
486  *pix_fmt = AV_PIX_FMT_RGB565;
487  break;
488  case 15:
489  if (fmt->bits_per_pixel == 16)
490  *pix_fmt = AV_PIX_FMT_RGB555;
491  break;
492  case 8:
493  if (fmt->bits_per_pixel == 8)
494  *pix_fmt = AV_PIX_FMT_RGB8;
495  break;
496  }
497  }
498 
499  if (*pix_fmt) {
500  c->bpp = fmt->bits_per_pixel;
501  c->frame_size = c->width * c->height * fmt->bits_per_pixel / 8;
502  return 0;
503  }
504 
505  fmt++;
506  }
507  av_log(s, AV_LOG_ERROR, "Pixmap format not mappable.\n");
508 
509  return AVERROR_PATCHWELCOME;
510 }
511 
513 {
514  XCBGrabContext *c = s->priv_data;
516  xcb_get_geometry_cookie_t gc;
517  xcb_get_geometry_reply_t *geo;
518  int ret;
519 
520  if (!st)
521  return AVERROR(ENOMEM);
522 
523  ret = av_parse_video_size(&c->width, &c->height, c->video_size);
524  if (ret < 0)
525  return ret;
526 
528  if (ret < 0)
529  return ret;
530 
531  avpriv_set_pts_info(st, 64, 1, 1000000);
532 
533  gc = xcb_get_geometry(c->conn, c->screen->root);
534  geo = xcb_get_geometry_reply(c->conn, gc, NULL);
535 
536  if (c->x + c->width > geo->width ||
537  c->y + c->height > geo->height) {
538  av_log(s, AV_LOG_ERROR,
539  "Capture area %dx%d at position %d.%d "
540  "outside the screen size %dx%d\n",
541  c->width, c->height,
542  c->x, c->y,
543  geo->width, geo->height);
544  return AVERROR(EINVAL);
545  }
546 
548  st->avg_frame_rate.num };
549  c->time_frame = av_gettime();
550 
553  st->codec->width = c->width;
554  st->codec->height = c->height;
555  st->codec->time_base = c->time_base;
556 
557  ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codec->pix_fmt);
558 
559  free(geo);
560 
561  return ret;
562 }
563 
565 {
566  XCBGrabContext *c = s->priv_data;
567  xcb_gcontext_t gc = xcb_generate_id(c->conn);
568  uint32_t mask = XCB_GC_FOREGROUND |
569  XCB_GC_BACKGROUND |
570  XCB_GC_LINE_WIDTH |
571  XCB_GC_LINE_STYLE |
572  XCB_GC_FILL_STYLE;
573  uint32_t values[] = { c->screen->black_pixel,
574  c->screen->white_pixel,
575  c->region_border,
576  XCB_LINE_STYLE_DOUBLE_DASH,
577  XCB_FILL_STYLE_SOLID };
578  xcb_rectangle_t r = { 1, 1,
579  c->width + c->region_border * 2 - 3,
580  c->height + c->region_border * 2 - 3 };
581 
582  xcb_create_gc(c->conn, gc, c->window, mask, values);
583 
584  xcb_poly_rectangle(c->conn, c->window, gc, 1, &r);
585 }
586 
588 {
589  XCBGrabContext *c = s->priv_data;
590  uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
591  uint32_t values[] = { 1,
592  XCB_EVENT_MASK_EXPOSURE |
593  XCB_EVENT_MASK_STRUCTURE_NOTIFY };
594  xcb_rectangle_t rect = { 0, 0, c->width, c->height };
595 
596  c->window = xcb_generate_id(c->conn);
597 
598  xcb_create_window(c->conn, XCB_COPY_FROM_PARENT,
599  c->window,
600  c->screen->root,
601  c->x - c->region_border,
602  c->y - c->region_border,
603  c->width + c->region_border * 2,
604  c->height + c->region_border * 2,
605  0,
606  XCB_WINDOW_CLASS_INPUT_OUTPUT,
607  XCB_COPY_FROM_PARENT,
608  mask, values);
609 
610 #if CONFIG_LIBXCB_SHAPE
611  xcb_shape_rectangles(c->conn, XCB_SHAPE_SO_SUBTRACT,
612  XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
613  c->window,
615  1, &rect);
616 #endif
617 
618  xcb_map_window(c->conn, c->window);
619 
620  draw_rectangle(s);
621 }
622 
624 {
625  XCBGrabContext *c = s->priv_data;
626  int screen_num, ret;
627  const xcb_setup_t *setup;
628  char *display_name = av_strdup(s->filename);
629 
630  if (!display_name)
631  return AVERROR(ENOMEM);
632 
633  if (!sscanf(s->filename, "%[^+]+%d,%d", display_name, &c->x, &c->y)) {
634  *display_name = 0;
635  sscanf(s->filename, "+%d,%d", &c->x, &c->y);
636  }
637 
638  c->conn = xcb_connect(display_name[0] ? display_name : NULL, &screen_num);
639  av_freep(&display_name);
640 
641  if ((ret = xcb_connection_has_error(c->conn))) {
642  av_log(s, AV_LOG_ERROR, "Cannot open display %s, error %d.\n",
643  s->filename[0] ? s->filename : "default", ret);
644  return AVERROR(EIO);
645  }
646 
647  setup = xcb_get_setup(c->conn);
648 
649  c->screen = get_screen(setup, screen_num);
650  if (!c->screen) {
651  av_log(s, AV_LOG_ERROR, "The screen %d does not exist.\n",
652  screen_num);
654  return AVERROR(EIO);
655  }
656 
657  ret = create_stream(s);
658 
659  if (ret < 0) {
661  return ret;
662  }
663 
664 #if CONFIG_LIBXCB_SHM
665  if ((c->has_shm = check_shm(c->conn)))
666  c->segment = xcb_generate_id(c->conn);
667 #endif
668 
669 #if CONFIG_LIBXCB_XFIXES
670  if (c->draw_mouse) {
671  if (!(c->draw_mouse = check_xfixes(c->conn))) {
673  "XFixes not available, cannot draw the mouse.\n");
674  }
675  if (c->bpp < 24) {
676  avpriv_report_missing_feature(s, "%d bits per pixel screen",
677  c->bpp);
678  c->draw_mouse = 0;
679  }
680  }
681 #endif
682 
683  if (c->show_region)
684  setup_window(s);
685 
686  return 0;
687 }
688 
690  .name = "x11grab",
691  .long_name = NULL_IF_CONFIG_SMALL("X11 screen capture, using XCB"),
692  .priv_data_size = sizeof(XCBGrabContext),
696  .flags = AVFMT_NOFILE,
697  .priv_class = &xcbgrab_class,
698 };
static xcb_screen_t * get_screen(const xcb_setup_t *setup, int screen_num)
Definition: xcbgrab.c:444
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
xcb_connection_t * conn
Definition: xcbgrab.c:52
static enum AVPixelFormat pix_fmt
static av_cold int xcbgrab_read_header(AVFormatContext *s)
Definition: xcbgrab.c:623
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:173
static int create_stream(AVFormatContext *s)
Definition: xcbgrab.c:512
AVOption.
Definition: opt.h:255
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:142
static void xcbgrab_update_region(AVFormatContext *s)
Definition: xcbgrab.c:381
const char * fmt
Definition: avisynth_c.h:632
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:65
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4083
const char * g
Definition: vf_curves.c:108
static void draw_rectangle(AVFormatContext *s)
Definition: xcbgrab.c:564
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:1424
const char * b
Definition: vf_curves.c:109
xcb_window_t window
Definition: xcbgrab.c:54
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1722
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:76
static AVPacket pkt
int centered
Definition: xcbgrab.c:70
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1631
Format I/O context.
Definition: avformat.h:1273
#define img
int frame_size
Definition: xcbgrab.c:63
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
uint8_t
#define av_cold
Definition: attributes.h:74
AVOptions.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:3749
static const AVClass xcbgrab_class
Definition: xcbgrab.c:98
xcb_screen_t * screen
Definition: xcbgrab.c:53
AVInputFormat ff_x11grab_xcb_demuxer
Definition: xcbgrab.c:689
uint8_t * data
Definition: avcodec.h:1423
static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt)
Definition: xcbgrab.c:147
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
ptrdiff_t size
Definition: opengl_enc.c:101
#define av_log(a,...)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:140
static int pixfmt_from_pixmap_format(AVFormatContext *s, int depth, int *pix_fmt)
Definition: xcbgrab.c:461
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:83
AVRational time_base
Definition: xcbgrab.c:59
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static const uint16_t mask[17]
Definition: lzw.c:38
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
const char * r
Definition: vf_curves.c:107
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1406
GLsizei GLsizei * length
Definition: opengl_enc.c:115
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:28
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:925
#define FFMAX(a, b)
Definition: common.h:79
int depth
Definition: v4l.c:62
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:861
Definition: hls.c:68
common internal API header
static SDL_Surface * screen
Definition: ffplay.c:360
char filename[1024]
input or output filename
Definition: avformat.h:1349
#define FFMIN(a, b)
Definition: common.h:81
float y
static const AVOption options[]
Definition: xcbgrab.c:82
const char * framerate
Definition: xcbgrab.c:73
int width
picture width / height.
Definition: avcodec.h:1681
static void wait_frame(AVFormatContext *s, AVPacket *pkt)
Definition: xcbgrab.c:188
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:623
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
Stream structure.
Definition: avformat.h:842
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
int64_t time_frame
Definition: xcbgrab.c:58
const char * video_size
Definition: xcbgrab.c:72
enum AVMediaType codec_type
Definition: avcodec.h:1510
enum AVCodecID codec_id
Definition: avcodec.h:1519
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:252
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:267
uint8_t * data
The data buffer.
Definition: buffer.h:89
int show_region
Definition: xcbgrab.c:68
Describe the class of an AVClass context structure.
Definition: log.h:67
Definition: f_ebur128.c:90
static int xcbgrab_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: xcbgrab.c:393
rational number numerator/denominator
Definition: rational.h:43
misc parsing utilities
#define OFFSET(x)
Definition: xcbgrab.c:80
static void setup_window(AVFormatContext *s)
Definition: xcbgrab.c:587
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static int flags
Definition: cpu.c:47
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
Definition: error.c:68
static int xcbgrab_reposition(AVFormatContext *s, xcb_query_pointer_reply_t *p, xcb_get_geometry_reply_t *geo)
Definition: xcbgrab.c:106
Main libavformat public API header.
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
#define D
Definition: xcbgrab.c:81
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:465
static double c[64]
int region_border
Definition: xcbgrab.c:69
static av_cold int xcbgrab_read_close(AVFormatContext *s)
Definition: xcbgrab.c:435
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:88
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:368
int den
denominator
Definition: rational.h:45
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:636
int follow_mouse
Definition: xcbgrab.c:67
void * priv_data
Format private data.
Definition: avformat.h:1301
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:367
int draw_mouse
Definition: xcbgrab.c:66
#define av_freep(p)
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:628
#define FOLLOW_CENTER
Definition: xcbgrab.c:78
#define stride
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:276
This structure stores compressed data.
Definition: avcodec.h:1400
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1416
#define AV_PIX_FMT_0RGB32
Definition: pixfmt.h:361