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