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 {
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->codecpar->width = c->width;
554  st->codecpar->height = c->height;
555 
556  ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codecpar->format);
557 
558  free(geo);
559 
560  return ret;
561 }
562 
564 {
565  XCBGrabContext *c = s->priv_data;
566  xcb_gcontext_t gc = xcb_generate_id(c->conn);
567  uint32_t mask = XCB_GC_FOREGROUND |
568  XCB_GC_BACKGROUND |
569  XCB_GC_LINE_WIDTH |
570  XCB_GC_LINE_STYLE |
571  XCB_GC_FILL_STYLE;
572  uint32_t values[] = { c->screen->black_pixel,
573  c->screen->white_pixel,
574  c->region_border,
575  XCB_LINE_STYLE_DOUBLE_DASH,
576  XCB_FILL_STYLE_SOLID };
577  xcb_rectangle_t r = { 1, 1,
578  c->width + c->region_border * 2 - 3,
579  c->height + c->region_border * 2 - 3 };
580 
581  xcb_create_gc(c->conn, gc, c->window, mask, values);
582 
583  xcb_poly_rectangle(c->conn, c->window, gc, 1, &r);
584 }
585 
587 {
588  XCBGrabContext *c = s->priv_data;
589  uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
590  uint32_t values[] = { 1,
591  XCB_EVENT_MASK_EXPOSURE |
592  XCB_EVENT_MASK_STRUCTURE_NOTIFY };
593  av_unused xcb_rectangle_t rect = { 0, 0, c->width, c->height };
594 
595  c->window = xcb_generate_id(c->conn);
596 
597  xcb_create_window(c->conn, XCB_COPY_FROM_PARENT,
598  c->window,
599  c->screen->root,
600  c->x - c->region_border,
601  c->y - c->region_border,
602  c->width + c->region_border * 2,
603  c->height + c->region_border * 2,
604  0,
605  XCB_WINDOW_CLASS_INPUT_OUTPUT,
606  XCB_COPY_FROM_PARENT,
607  mask, values);
608 
609 #if CONFIG_LIBXCB_SHAPE
610  xcb_shape_rectangles(c->conn, XCB_SHAPE_SO_SUBTRACT,
611  XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
612  c->window,
614  1, &rect);
615 #endif
616 
617  xcb_map_window(c->conn, c->window);
618 
619  draw_rectangle(s);
620 }
621 
623 {
624  XCBGrabContext *c = s->priv_data;
625  int screen_num, ret;
626  const xcb_setup_t *setup;
627  char *display_name = av_strdup(s->filename);
628 
629  if (!display_name)
630  return AVERROR(ENOMEM);
631 
632  if (!sscanf(s->filename, "%[^+]+%d,%d", display_name, &c->x, &c->y)) {
633  *display_name = 0;
634  sscanf(s->filename, "+%d,%d", &c->x, &c->y);
635  }
636 
637  c->conn = xcb_connect(display_name[0] ? display_name : NULL, &screen_num);
638  av_freep(&display_name);
639 
640  if ((ret = xcb_connection_has_error(c->conn))) {
641  av_log(s, AV_LOG_ERROR, "Cannot open display %s, error %d.\n",
642  s->filename[0] ? s->filename : "default", ret);
643  return AVERROR(EIO);
644  }
645 
646  setup = xcb_get_setup(c->conn);
647 
648  c->screen = get_screen(setup, screen_num);
649  if (!c->screen) {
650  av_log(s, AV_LOG_ERROR, "The screen %d does not exist.\n",
651  screen_num);
653  return AVERROR(EIO);
654  }
655 
656  ret = create_stream(s);
657 
658  if (ret < 0) {
660  return ret;
661  }
662 
663 #if CONFIG_LIBXCB_SHM
664  if ((c->has_shm = check_shm(c->conn)))
665  c->segment = xcb_generate_id(c->conn);
666 #endif
667 
668 #if CONFIG_LIBXCB_XFIXES
669  if (c->draw_mouse) {
670  if (!(c->draw_mouse = check_xfixes(c->conn))) {
672  "XFixes not available, cannot draw the mouse.\n");
673  }
674  if (c->bpp < 24) {
675  avpriv_report_missing_feature(s, "%d bits per pixel screen",
676  c->bpp);
677  c->draw_mouse = 0;
678  }
679  }
680 #endif
681 
682  if (c->show_region)
683  setup_window(s);
684 
685  return 0;
686 }
687 
689  .name = "x11grab",
690  .long_name = NULL_IF_CONFIG_SMALL("X11 screen capture, using XCB"),
691  .priv_data_size = sizeof(XCBGrabContext),
695  .flags = AVFMT_NOFILE,
696  .priv_class = &xcbgrab_class,
697 };
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:768
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:622
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:174
static int create_stream(AVFormatContext *s)
Definition: xcbgrab.c:512
AVOption.
Definition: opt.h:245
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:143
static void xcbgrab_update_region(AVFormatContext *s)
Definition: xcbgrab.c:381
const char * fmt
Definition: avisynth_c.h:769
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
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:4560
const char * g
Definition: vf_curves.c:112
static void draw_rectangle(AVFormatContext *s)
Definition: xcbgrab.c:563
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3980
int num
Numerator.
Definition: rational.h:59
int size
Definition: avcodec.h:1602
const char * b
Definition: vf_curves.c:113
xcb_window_t window
Definition: xcbgrab.c:54
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:76
static AVPacket pkt
int centered
Definition: xcbgrab.c:70
Format I/O context.
Definition: avformat.h:1338
#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:82
int width
Video only.
Definition: avcodec.h:4046
AVOptions.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4193
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:688
uint8_t * data
Definition: avcodec.h:1601
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:142
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:86
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:176
const char * r
Definition: vf_curves.c:111
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3976
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1584
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:967
#define FFMAX(a, b)
Definition: common.h:94
int depth
Definition: v4l.c:62
Definition: hls.c:67
common internal API header
char filename[1024]
input or output filename
Definition: avformat.h:1414
#define FFMIN(a, b)
Definition: common.h:96
static const AVOption options[]
Definition: xcbgrab.c:82
const char * framerate
Definition: xcbgrab.c:73
AVFormatContext * ctx
Definition: movenc.c:48
static void wait_frame(AVFormatContext *s, AVPacket *pkt)
Definition: xcbgrab.c:188
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:514
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
Stream structure.
Definition: avformat.h:889
#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
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:267
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:254
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:91
static int xcbgrab_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: xcbgrab.c:393
Rational number (pair of numerator and denominator).
Definition: rational.h:58
misc parsing utilities
#define OFFSET(x)
Definition: xcbgrab.c:80
static void setup_window(AVFormatContext *s)
Definition: xcbgrab.c:586
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:105
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:478
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:87
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:329
int den
Denominator.
Definition: rational.h:60
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:734
int follow_mouse
Definition: xcbgrab.c:67
void * priv_data
Format private data.
Definition: avformat.h:1366
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:328
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:664
#define FOLLOW_CENTER
Definition: xcbgrab.c:78
AVCodecParameters * codecpar
Definition: avformat.h:1241
#define stride
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:251
This structure stores compressed data.
Definition: avcodec.h:1578
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1594
#define av_unused
Definition: attributes.h:126
#define AV_PIX_FMT_0RGB32
Definition: pixfmt.h:322