FFmpeg  2.6.3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules 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 "libavformat/avformat.h"
41 #include "libavformat/internal.h"
42 
43 #include "libavutil/mathematics.h"
44 #include "libavutil/opt.h"
45 #include "libavutil/parseutils.h"
46 #include "libavutil/time.h"
47 
48 typedef struct XCBGrabContext {
49  const AVClass *class;
50 
51  xcb_connection_t *conn;
52  xcb_screen_t *screen;
53  xcb_window_t window;
54 #if CONFIG_LIBXCB_SHM
55  xcb_shm_seg_t segment;
56 #endif
57  int64_t time_frame;
59 
60  int x, y;
61  int width, height;
63  int bpp;
64 
69  int centered;
70 
71  const char *video_size;
72  const char *framerate;
73 
74  int has_shm;
76 
77 #define FOLLOW_CENTER -1
78 
79 #define OFFSET(x) offsetof(XCBGrabContext, x)
80 #define D AV_OPT_FLAG_DECODING_PARAM
81 static const AVOption options[] = {
82  { "x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
83  { "y", "Initial y coordinate.", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
84  { "grab_x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
85  { "grab_y", "Initial y coordinate.", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },
86  { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "vga" }, 0, 0, D },
87  { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc" }, 0, 0, D },
88  { "draw_mouse", "Draw the mouse pointer.", OFFSET(draw_mouse), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, D },
89  { "follow_mouse", "Move the grabbing region when the mouse pointer reaches within specified amount of pixels to the edge of region.",
90  OFFSET(follow_mouse), AV_OPT_TYPE_INT, { .i64 = 0 }, FOLLOW_CENTER, INT_MAX, D, "follow_mouse" },
91  { "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" },
92  { "show_region", "Show the grabbing region.", OFFSET(show_region), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
93  { "region_border", "Set the region border thickness.", OFFSET(region_border), AV_OPT_TYPE_INT, { .i64 = 3 }, 1, 128, D },
94  { NULL },
95 };
96 
97 static const AVClass xcbgrab_class = {
98  .class_name = "xcbgrab indev",
99  .item_name = av_default_item_name,
100  .option = options,
101  .version = LIBAVUTIL_VERSION_INT,
103 };
104 
106  xcb_query_pointer_reply_t *p,
107  xcb_get_geometry_reply_t *geo)
108 {
109  XCBGrabContext *c = s->priv_data;
110  int x = c->x, y = c->y;
111  int w = c->width, h = c->height, f = c->follow_mouse;
112  int p_x, p_y;
113 
114  if (!p || !geo)
115  return AVERROR(EIO);
116 
117  p_x = p->win_x;
118  p_y = p->win_y;
119 
120  if (f == FOLLOW_CENTER) {
121  x = p_x - w / 2;
122  y = p_y - h / 2;
123  } else {
124  int left = x + f;
125  int right = x + w - f;
126  int top = y + f;
127  int bottom = y + h + f;
128  if (p_x > right) {
129  x += p_x - right;
130  } else if (p_x < left) {
131  x -= left - p_x;
132  }
133  if (p_y > bottom) {
134  y += p_y - bottom;
135  } else if (p_y < top) {
136  y -= top - p_y;
137  }
138  }
139 
140  c->x = FFMIN(FFMAX(0, x), geo->width - w);
141  c->y = FFMIN(FFMAX(0, y), geo->height - h);
142 
143  return 0;
144 }
145 
147 {
148  XCBGrabContext *c = s->priv_data;
149  xcb_get_image_cookie_t iq;
150  xcb_get_image_reply_t *img;
151  xcb_drawable_t drawable = c->screen->root;
152  xcb_generic_error_t *e = NULL;
153  uint8_t *data;
154  int length, ret;
155 
156  iq = xcb_get_image(c->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
157  c->x, c->y, c->width, c->height, ~0);
158 
159  img = xcb_get_image_reply(c->conn, iq, &e);
160 
161  if (e) {
162  av_log(s, AV_LOG_ERROR,
163  "Cannot get the image data "
164  "event_error: response_type:%u error_code:%u "
165  "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
166  e->response_type, e->error_code,
167  e->sequence, e->resource_id, e->minor_code, e->major_code);
168  return AVERROR(EACCES);
169  }
170 
171  if (!img)
172  return AVERROR(EAGAIN);
173 
174  data = xcb_get_image_data(img);
175  length = xcb_get_image_data_length(img);
176 
177  ret = av_new_packet(pkt, length);
178 
179  if (!ret)
180  memcpy(pkt->data, data, length);
181 
182  free(img);
183 
184  return ret;
185 }
186 
188 {
189  XCBGrabContext *c = s->priv_data;
190  int64_t curtime, delay;
191  int64_t frame_time = av_rescale_q(1, c->time_base, AV_TIME_BASE_Q);
192 
193  c->time_frame += frame_time;
194 
195  for (;;) {
196  curtime = av_gettime();
197  delay = c->time_frame - curtime;
198  if (delay <= 0)
199  break;
200  av_usleep(delay);
201  }
202 
203  pkt->pts = curtime;
204 }
205 
206 #if CONFIG_LIBXCB_SHM
207 static int check_shm(xcb_connection_t *conn)
208 {
209  xcb_shm_query_version_cookie_t cookie = xcb_shm_query_version(conn);
210  xcb_shm_query_version_reply_t *reply;
211 
212  reply = xcb_shm_query_version_reply(conn, cookie, NULL);
213  if (reply) {
214  free(reply);
215  return 1;
216  }
217 
218  return 0;
219 }
220 
221 static void dealloc_shm(void *unused, uint8_t *data)
222 {
223  shmdt(data);
224 }
225 
226 static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket *pkt)
227 {
228  XCBGrabContext *c = s->priv_data;
229  xcb_shm_get_image_cookie_t iq;
230  xcb_shm_get_image_reply_t *img;
231  xcb_drawable_t drawable = c->screen->root;
232  uint8_t *data;
234  int id = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777);
235  xcb_generic_error_t *e = NULL;
236 
237  if (id == -1) {
238  char errbuf[1024];
239  int err = AVERROR(errno);
240  av_strerror(err, errbuf, sizeof(errbuf));
241  av_log(s, AV_LOG_ERROR, "Cannot get %d bytes of shared memory: %s.\n",
242  size, errbuf);
243  return err;
244  }
245 
246  xcb_shm_attach(c->conn, c->segment, id, 0);
247 
248  iq = xcb_shm_get_image(c->conn, drawable,
249  c->x, c->y, c->width, c->height, ~0,
250  XCB_IMAGE_FORMAT_Z_PIXMAP, c->segment, 0);
251 
252  xcb_shm_detach(c->conn, c->segment);
253 
254  img = xcb_shm_get_image_reply(c->conn, iq, &e);
255 
256  xcb_flush(c->conn);
257 
258  if (e) {
259  av_log(s, AV_LOG_ERROR,
260  "Cannot get the image data "
261  "event_error: response_type:%u error_code:%u "
262  "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
263  e->response_type, e->error_code,
264  e->sequence, e->resource_id, e->minor_code, e->major_code);
265 
266  shmctl(id, IPC_RMID, 0);
267  return AVERROR(EACCES);
268  }
269 
270  free(img);
271 
272  data = shmat(id, NULL, 0);
273  shmctl(id, IPC_RMID, 0);
274 
275  if ((intptr_t)data == -1)
276  return AVERROR(errno);
277 
278  pkt->buf = av_buffer_create(data, size, dealloc_shm, NULL, 0);
279  if (!pkt->buf) {
280  shmdt(data);
281  return AVERROR(ENOMEM);
282  }
283 
284  pkt->data = pkt->buf->data;
285  pkt->size = c->frame_size;
286 
287  return 0;
288 }
289 #endif /* CONFIG_LIBXCB_SHM */
290 
291 #if CONFIG_LIBXCB_XFIXES
292 static int check_xfixes(xcb_connection_t *conn)
293 {
294  xcb_xfixes_query_version_cookie_t cookie;
295  xcb_xfixes_query_version_reply_t *reply;
296 
297  cookie = xcb_xfixes_query_version(conn, XCB_XFIXES_MAJOR_VERSION,
298  XCB_XFIXES_MINOR_VERSION);
299  reply = xcb_xfixes_query_version_reply(conn, cookie, NULL);
300 
301  if (reply) {
302  free(reply);
303  return 1;
304  }
305  return 0;
306 }
307 
308 #define BLEND(target, source, alpha) \
309  (target) + ((source) * (255 - (alpha)) + 255 / 2) / 255
310 
311 static void xcbgrab_draw_mouse(AVFormatContext *s, AVPacket *pkt,
312  xcb_query_pointer_reply_t *p,
313  xcb_get_geometry_reply_t *geo)
314 {
315  XCBGrabContext *gr = s->priv_data;
316  uint32_t *cursor;
317  uint8_t *image = pkt->data;
318  int stride = gr->bpp / 8;
319  xcb_xfixes_get_cursor_image_cookie_t cc;
320  xcb_xfixes_get_cursor_image_reply_t *ci;
321  int cx, cy, x, y, w, h, c_off, i_off;
322 
323  cc = xcb_xfixes_get_cursor_image(gr->conn);
324  ci = xcb_xfixes_get_cursor_image_reply(gr->conn, cc, NULL);
325  if (!ci)
326  return;
327 
328  cursor = xcb_xfixes_get_cursor_image_cursor_image(ci);
329  if (!cursor)
330  return;
331 
332  cx = ci->x - ci->xhot;
333  cy = ci->y - ci->yhot;
334 
335  x = FFMAX(cx, gr->x);
336  y = FFMAX(cy, gr->y);
337 
338  w = FFMIN(cx + ci->width, gr->x + gr->width) - x;
339  h = FFMIN(cy + ci->height, gr->y + gr->height) - y;
340 
341  c_off = x - cx;
342  i_off = x - gr->x;
343 
344  cursor += (y - cy) * ci->width;
345  image += (y - gr->y) * gr->width * stride;
346 
347  for (y = 0; y < h; y++) {
348  cursor += c_off;
349  image += i_off * stride;
350  for (x = 0; x < w; x++, cursor++, image += stride) {
351  int r, g, b, a;
352 
353  r = *cursor & 0xff;
354  g = (*cursor >> 8) & 0xff;
355  b = (*cursor >> 16) & 0xff;
356  a = (*cursor >> 24) & 0xff;
357 
358  if (!a)
359  continue;
360 
361  if (a == 255) {
362  image[0] = r;
363  image[1] = g;
364  image[2] = b;
365  } else {
366  image[0] = BLEND(r, image[0], a);
367  image[1] = BLEND(g, image[1], a);
368  image[2] = BLEND(b, image[2], a);
369  }
370 
371  }
372  cursor += ci->width - w - c_off;
373  image += (gr->width - w - i_off) * stride;
374  }
375 
376  free(ci);
377 }
378 #endif /* CONFIG_LIBXCB_XFIXES */
379 
381 {
382  XCBGrabContext *c = s->priv_data;
383  const uint32_t args[] = { c->x - c->region_border,
384  c->y - c->region_border };
385 
386  xcb_configure_window(c->conn,
387  c->window,
388  XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
389  args);
390 }
391 
393 {
394  XCBGrabContext *c = s->priv_data;
395  xcb_query_pointer_cookie_t pc;
396  xcb_get_geometry_cookie_t gc;
397  xcb_query_pointer_reply_t *p = NULL;
398  xcb_get_geometry_reply_t *geo = NULL;
399  int ret = 0;
400 
401  wait_frame(s, pkt);
402 
403  if (c->follow_mouse || c->draw_mouse) {
404  pc = xcb_query_pointer(c->conn, c->screen->root);
405  gc = xcb_get_geometry(c->conn, c->screen->root);
406  p = xcb_query_pointer_reply(c->conn, pc, NULL);
407  geo = xcb_get_geometry_reply(c->conn, gc, NULL);
408  }
409 
410  if (c->follow_mouse && p->same_screen)
411  xcbgrab_reposition(s, p, geo);
412 
413  if (c->show_region)
415 
416 #if CONFIG_LIBXCB_SHM
417  if (c->has_shm && xcbgrab_frame_shm(s, pkt) < 0)
418  c->has_shm = 0;
419 #endif
420  if (!c->has_shm)
421  ret = xcbgrab_frame(s, pkt);
422 
423 #if CONFIG_LIBXCB_XFIXES
424  if (ret >= 0 && c->draw_mouse && p->same_screen)
425  xcbgrab_draw_mouse(s, pkt, p, geo);
426 #endif
427 
428  free(p);
429  free(geo);
430 
431  return ret;
432 }
433 
435 {
436  XCBGrabContext *ctx = s->priv_data;
437 
438  xcb_disconnect(ctx->conn);
439 
440  return 0;
441 }
442 
443 static xcb_screen_t *get_screen(const xcb_setup_t *setup, int screen_num)
444 {
445  xcb_screen_iterator_t it = xcb_setup_roots_iterator(setup);
446  xcb_screen_t *screen = NULL;
447 
448  for (; it.rem > 0; xcb_screen_next (&it)) {
449  if (!screen_num) {
450  screen = it.data;
451  break;
452  }
453 
454  screen_num--;
455  }
456 
457  return screen;
458 }
459 
461  int *pix_fmt)
462 {
463  XCBGrabContext *c = s->priv_data;
464  const xcb_setup_t *setup = xcb_get_setup(c->conn);
465  const xcb_format_t *fmt = xcb_setup_pixmap_formats(setup);
466  int length = xcb_setup_pixmap_formats_length(setup);
467 
468  *pix_fmt = 0;
469 
470  while (length--) {
471  if (fmt->depth == depth) {
472  switch (depth) {
473  case 32:
474  if (fmt->bits_per_pixel == 32)
475  *pix_fmt = AV_PIX_FMT_0RGB;
476  break;
477  case 24:
478  if (fmt->bits_per_pixel == 32)
479  *pix_fmt = AV_PIX_FMT_0RGB32;
480  else if (fmt->bits_per_pixel == 24)
481  *pix_fmt = AV_PIX_FMT_RGB24;
482  break;
483  case 16:
484  if (fmt->bits_per_pixel == 16)
485  *pix_fmt = AV_PIX_FMT_RGB565;
486  break;
487  case 15:
488  if (fmt->bits_per_pixel == 16)
489  *pix_fmt = AV_PIX_FMT_RGB555;
490  break;
491  case 8:
492  if (fmt->bits_per_pixel == 8)
493  *pix_fmt = AV_PIX_FMT_RGB8;
494  break;
495  }
496  }
497 
498  if (*pix_fmt) {
499  c->bpp = fmt->bits_per_pixel;
500  c->frame_size = c->width * c->height * fmt->bits_per_pixel / 8;
501  return 0;
502  }
503 
504  fmt++;
505  }
506  av_log(s, AV_LOG_ERROR, "Pixmap format not mappable.\n");
507 
508  return AVERROR_PATCHWELCOME;
509 }
510 
512 {
513  XCBGrabContext *c = s->priv_data;
515  xcb_get_geometry_cookie_t gc;
516  xcb_get_geometry_reply_t *geo;
517  int ret;
518 
519  if (!st)
520  return AVERROR(ENOMEM);
521 
522  ret = av_parse_video_size(&c->width, &c->height, c->video_size);
523  if (ret < 0)
524  return ret;
525 
527  if (ret < 0)
528  return ret;
529 
530  avpriv_set_pts_info(st, 64, 1, 1000000);
531 
532  gc = xcb_get_geometry(c->conn, c->screen->root);
533  geo = xcb_get_geometry_reply(c->conn, gc, NULL);
534 
535  if (c->x + c->width >= geo->width ||
536  c->y + c->height >= geo->height) {
537  av_log(s, AV_LOG_ERROR,
538  "Capture area %dx%d at position %d.%d "
539  "outside the screen size %dx%d\n",
540  c->width, c->height,
541  c->x, c->y,
542  geo->width, geo->height);
543  return AVERROR(EINVAL);
544  }
545 
547  st->avg_frame_rate.num };
548  c->time_frame = av_gettime();
549 
552  st->codec->width = c->width;
553  st->codec->height = c->height;
554  st->codec->time_base = c->time_base;
555 
556  ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codec->pix_fmt);
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  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  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:443
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:669
xcb_connection_t * conn
Definition: xcbgrab.c:51
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:169
static int create_stream(AVFormatContext *s)
Definition: xcbgrab.c:511
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:138
static void xcbgrab_update_region(AVFormatContext *s)
Definition: xcbgrab.c:380
const char * fmt
Definition: avisynth_c.h:670
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:181
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:70
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:3993
const char * g
Definition: vf_curves.c:108
static void draw_rectangle(AVFormatContext *s)
Definition: xcbgrab.c:563
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:1161
const char * b
Definition: vf_curves.c:109
xcb_window_t window
Definition: xcbgrab.c:53
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1442
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:76
static AVPacket pkt
int centered
Definition: xcbgrab.c:69
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1367
Format I/O context.
Definition: avformat.h:1214
#define img
int frame_size
Definition: xcbgrab.c:62
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:71
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:3659
static const AVClass xcbgrab_class
Definition: xcbgrab.c:97
xcb_screen_t * screen
Definition: xcbgrab.c:52
AVInputFormat ff_x11grab_xcb_demuxer
Definition: xcbgrab.c:687
uint8_t * data
Definition: avcodec.h:1160
static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt)
Definition: xcbgrab.c:146
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:460
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:58
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:175
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:180
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:1143
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:878
#define FFMAX(a, b)
Definition: common.h:64
int depth
Definition: v4l.c:61
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:814
Definition: hls.c:68
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:628
static SDL_Surface * screen
Definition: ffplay.c:354
char filename[1024]
input or output filename
Definition: avformat.h:1290
#define FFMIN(a, b)
Definition: common.h:66
float y
static const AVOption options[]
Definition: xcbgrab.c:81
const char * framerate
Definition: xcbgrab.c:72
ret
Definition: avfilter.c:974
int width
picture width / height.
Definition: avcodec.h:1412
static void wait_frame(AVFormatContext *s, AVPacket *pkt)
Definition: xcbgrab.c:187
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:619
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
Stream structure.
Definition: avformat.h:795
#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:57
const char * video_size
Definition: xcbgrab.c:71
enum AVMediaType codec_type
Definition: avcodec.h:1247
enum AVCodecID codec_id
Definition: avcodec.h:1256
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:253
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:265
uint8_t * data
The data buffer.
Definition: buffer.h:89
int show_region
Definition: xcbgrab.c:67
Describe the class of an AVClass context structure.
Definition: log.h:66
Definition: f_ebur128.c:90
static int xcbgrab_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: xcbgrab.c:392
rational number numerator/denominator
Definition: rational.h:43
misc parsing utilities
#define OFFSET(x)
Definition: xcbgrab.c:79
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:68
static int xcbgrab_reposition(AVFormatContext *s, xcb_query_pointer_reply_t *p, xcb_get_geometry_reply_t *geo)
Definition: xcbgrab.c:105
Main libavformat public API header.
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
#define D
Definition: xcbgrab.c:80
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:418
static double c[64]
int region_border
Definition: xcbgrab.c:68
static av_cold int xcbgrab_read_close(AVFormatContext *s)
Definition: xcbgrab.c:434
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:93
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:346
int den
denominator
Definition: rational.h:45
int follow_mouse
Definition: xcbgrab.c:66
void * priv_data
Format private data.
Definition: avformat.h:1242
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:345
int draw_mouse
Definition: xcbgrab.c:65
#define av_freep(p)
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:581
#define FOLLOW_CENTER
Definition: xcbgrab.c:77
#define stride
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:262
This structure stores compressed data.
Definition: avcodec.h:1137
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1153
#define AV_PIX_FMT_0RGB32
Definition: pixfmt.h:339