Feature matching x11grab.
---
configure | 11 +
libavdevice/Makefile | 1 +
libavdevice/alldevices.c | 1 +
libavdevice/xcbgrab.c | 646 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 659 insertions(+)
create mode 100644 libavdevice/xcbgrab.c
diff --git a/configure b/configure
index 22b699f..60aa3ca 100755
--- a/configure
+++ b/configure
@@ -213,6 +213,7 @@ External library support:
native MPEG-4/Xvid encoder exists [no]
--enable-openssl enable openssl [no]
--enable-x11grab enable X11 grabbing [no]
+ --enable-xcbgrab enable xcb grabbing [no]
--enable-zlib enable zlib [autodetect]
Toolchain options:
@@ -1172,6 +1173,7 @@ EXTERNAL_LIBRARY_LIST="
libxvid
openssl
x11grab
+ xcbgrab
zlib
"
@@ -1390,6 +1392,7 @@ HEADERS_LIST="
sys_param_h
sys_resource_h
sys_select_h
+ sys_shm_h
sys_soundcard_h
sys_time_h
sys_un_h
@@ -2093,6 +2096,7 @@ v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h"
vfwcap_indev_deps="capCreateCaptureWindow vfwcap_defines"
vfwcap_indev_extralibs="-lavicap32"
x11grab_indev_deps="x11grab XShmCreateImage"
+xcbgrab_indev_deps="xcbgrab"
# protocols
ffrtmpcrypt_protocol_deps="!librtmp_protocol"
@@ -4257,6 +4261,13 @@ require Xext X11/extensions/XShm.h XShmCreateImage
-lXext &&
require Xfixes X11/extensions/Xfixes.h XFixesGetCursorImage -lXfixes &&
{ enabled xlib || die "ERROR: Xlib not found"; }
+enabled xcbgrab &&
+require_pkg_config xcb-composite xcb/composite.h
xcb_composite_name_window_pixmap &&
+require_pkg_config xcb-event xcb/xcb_event.h xcb_event_get_error_label &&
+require_pkg_config xcb-xfixes xcb/xfixes.h xcb_xfixes_get_cursor_image &&
+require_pkg_config xcb-shm xcb/shm.h xcb_shm_attach &&
+check_header sys/shm.h
+
enabled vdpau &&
check_cpp_condition vdpau/vdpau.h "defined
VDP_DECODER_PROFILE_MPEG4_PART2_ASP" ||
disable vdpau
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index 25e126c..7adae65 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -23,6 +23,7 @@ OBJS-$(CONFIG_SNDIO_OUTDEV) += sndio_common.o
sndio_enc.o
OBJS-$(CONFIG_V4L2_INDEV) += v4l2.o
OBJS-$(CONFIG_VFWCAP_INDEV) += vfwcap.o
OBJS-$(CONFIG_X11GRAB_INDEV) += x11grab.o
+OBJS-$(CONFIG_XCBGRAB_INDEV) += xcbgrab.o
# external libraries
OBJS-$(CONFIG_LIBCDIO_INDEV) += libcdio.o
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index 155f7a8..c154ed1 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -58,6 +58,7 @@ void avdevice_register_all(void)
REGISTER_INDEV (V4L2, v4l2);
REGISTER_INDEV (VFWCAP, vfwcap);
REGISTER_INDEV (X11GRAB, x11grab);
+ REGISTER_INDEV (XCBGRAB, xcbgrab);
/* external libraries */
REGISTER_INDEV (LIBCDIO, libcdio);
diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c
new file mode 100644
index 0000000..a671554
--- /dev/null
+++ b/libavdevice/xcbgrab.c
@@ -0,0 +1,646 @@
+/*
+ * XCB input
+ * Copyright (c) 2014 Luca Barbato <[email protected]>
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <xcb/xcb.h>
+#include <xcb/composite.h>
+#include <xcb/xcb_event.h>
+#include <xcb/xfixes.h>
+#if HAVE_SYS_SHM_H
+# include <sys/shm.h>
+# include <xcb/shm.h>
+#endif
+
+#include "libavformat/avformat.h"
+#include "libavformat/internal.h"
+
+#include "libavutil/mathematics.h"
+#include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/time.h"
+
+
+typedef struct XCBGrabContext {
+ const AVClass *class;
+
+ xcb_connection_t *conn;
+ xcb_screen_t *screen;
+ xcb_window_t window;
+ xcb_shm_seg_t segment;
+
+ int64_t time_frame;
+ AVRational time_base;
+
+ int x, y;
+ int width, height;
+ int frame_size;
+ int bpp;
+
+ int draw_mouse;
+ int follow_mouse;
+ int show_region;
+ int region_border;
+ int centered;
+
+ const char *video_size;
+ const char *framerate;
+
+ int has_shm;
+} XCBGrabContext;
+
+#define FOLLOW_CENTER -1
+
+#define OFFSET(x) offsetof(XCBGrabContext, x)
+#define D AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+ { "video_size", "A string describing frame size, such as 640x480 or
hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "vga"}, 0, 0, D },
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc"},
0, 0, D },
+ { "draw_mouse", "Draw the mouse pointer.", OFFSET(draw_mouse),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, D },
+ { "follow_mouse", "Move the grabbing region when the mouse pointer reaches
within specified amount of pixels to the edge of region.",
+ OFFSET(follow_mouse), AV_OPT_TYPE_INT, { .i64 = 0}, FOLLOW_CENTER,
INT_MAX, D, "follow_mouse" },
+ { "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" },
+ { "show_region", "Show the grabbing region.", OFFSET(show_region),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
+ { "region_border", "Set the region border thickness.",
OFFSET(region_border), AV_OPT_TYPE_INT, { .i64 = 3 }, 1, 128, D },
+ { NULL },
+};
+
+static const AVClass xcbgrab_class = {
+ .class_name = "xcbgrab indev",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static int xcbgrab_reposition(AVFormatContext *s,
+ xcb_query_pointer_reply_t *p,
+ xcb_get_geometry_reply_t *geo)
+{
+ XCBGrabContext *g = s->priv_data;
+ int x = g->x, y = g->y, p_x = p->win_x, p_y = p->win_y;
+ int w = g->width, h = g->height, f = g->follow_mouse;
+
+ if (!p || !geo)
+ return AVERROR(EIO);
+
+ if (f == FOLLOW_CENTER) {
+ x = p_x - w / 2;
+ y = p_y - h / 2;
+ } else {
+ int left = x + f;
+ int right = x + w - f;
+ int top = y + f;
+ int bottom = y + h + f;
+ if (p_x > right) {
+ x += p_x - right;
+ } else if (p_x < left) {
+ x -= left - p_x;
+ }
+ if (p_y > bottom) {
+ y += p_y - bottom;
+ } else if (p_y < top) {
+ y -= top - p_y;
+ }
+ }
+
+ g->x = FFMIN(FFMAX(0, x), geo->width - w);
+ g->y = FFMIN(FFMAX(0, y), geo->height - h);
+
+ return 0;
+}
+
+static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt)
+{
+ XCBGrabContext *g = s->priv_data;
+ xcb_get_image_cookie_t iq;
+ xcb_get_image_reply_t *img;
+ xcb_drawable_t drawable = g->screen->root;
+ uint8_t *data;
+ int length;
+
+ iq = xcb_get_image(g->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
+ g->x, g->y, g->width, g->height, ~0);
+ img = xcb_get_image_reply(g->conn, iq, NULL);
+
+ if (!img)
+ return AVERROR(EAGAIN);
+
+ data = xcb_get_image_data(img);
+ length = xcb_get_image_data_length(img);
+
+ av_new_packet(pkt, length);
+
+ memcpy(pkt->data, data, length);
+
+ free(img);
+
+ return 0;
+}
+
+static void wait_frame(AVFormatContext *s, AVPacket *pkt)
+{
+ XCBGrabContext *g = s->priv_data;
+ int64_t curtime, delay;
+ int64_t frame_time = av_rescale_q(1, g->time_base, AV_TIME_BASE_Q);
+
+ g->time_frame += frame_time;
+
+ for (;;) {
+ curtime = av_gettime();
+ delay = g->time_frame - curtime;
+ if (delay <= 0)
+ break;
+ av_usleep(delay);
+ }
+
+ pkt->pts = curtime;
+}
+
+#if HAVE_SYS_SHM_H
+static void dealloc_shm(void *unused, uint8_t *data)
+{
+ (void)unused;
+
+ shmdt(data);
+}
+
+static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket *pkt)
+{
+ XCBGrabContext *g = s->priv_data;
+ xcb_shm_get_image_cookie_t iq;
+ xcb_shm_get_image_reply_t *img;
+ xcb_drawable_t drawable = g->screen->root;
+ uint8_t *data;
+ int size = g->frame_size + FF_INPUT_BUFFER_PADDING_SIZE;
+ int id = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777);
+ xcb_generic_error_t *e = NULL;
+
+ if (id == -1) {
+ char errbuf[1024];
+ av_strerror(AVERROR(errno), errbuf, sizeof(errbuf));
+ av_log(s, AV_LOG_ERROR, "shmget %d failed: %s\n", size, errbuf);
+ return AVERROR(ENOMEM);
+ }
+
+ xcb_shm_attach(g->conn, g->segment, id, 0);
+
+ iq = xcb_shm_get_image(g->conn, drawable,
+ g->x, g->y, g->width, g->height, ~0,
+ XCB_IMAGE_FORMAT_Z_PIXMAP, g->segment, 0);
+
+ img = xcb_shm_get_image_reply(g->conn, iq, &e);
+ if (e)
+ av_log(s, AV_LOG_ERROR,
+ "event_error: %s: response_type:%u error_code:%u "
+ "sequence:%u resource_id:%u minor_code:%u major_code:%u\n",
+ xcb_event_get_error_label(e->error_code), e->response_type,
+ e->error_code, e->sequence, e->resource_id, e->minor_code,
+ e->major_code);
+
+ xcb_shm_detach(g->conn, g->segment);
+ xcb_flush(g->conn);
+
+ if (!img) {
+ shmctl(id, IPC_RMID, 0);
+ return AVERROR(ENOMEM);
+ }
+ free(img);
+
+
+ data = shmat(id, NULL, 0);
+ shmctl(id, IPC_RMID, 0);
+
+ if ((intptr_t)data == -1)
+ return AVERROR(ENOMEM);
+
+ pkt->buf = av_buffer_create(data, size, dealloc_shm, NULL, 0);
+
+ if (!pkt->buf) {
+ shmdt(data);
+ return AVERROR(ENOMEM);
+ }
+
+ pkt->data = pkt->buf->data;
+ pkt->size = g->frame_size;
+
+ return 0;
+}
+#endif
+
+#define BLEND(target, source, alpha) \
+ (target) + ((source) * (255 - (alpha)) + 255 / 2) / 255
+
+static int xcbgrab_draw_mouse(AVFormatContext *s, AVPacket *pkt,
+ xcb_query_pointer_reply_t *p,
+ xcb_get_geometry_reply_t *geo)
+{
+ XCBGrabContext *gr = s->priv_data;
+ uint32_t *cursor = NULL;
+ uint8_t *image = pkt->data;
+ int stride = gr->bpp / 8;
+ xcb_xfixes_get_cursor_image_cookie_t cc;
+ xcb_xfixes_get_cursor_image_reply_t *ci;
+ int cx, cy, x, y, w, h, c_off, i_off;
+
+ cc = xcb_xfixes_get_cursor_image(gr->conn);
+ ci = xcb_xfixes_get_cursor_image_reply(gr->conn, cc, NULL);
+ cursor = xcb_xfixes_get_cursor_image_cursor_image(ci);
+
+ if (!cursor)
+ return 0;
+
+ cx = ci->x - ci->xhot;
+ cy = ci->y - ci->yhot;
+
+ x = FFMAX(cx, gr->x);
+ y = FFMAX(cy, gr->y);
+
+ w = FFMIN(cx + ci->width, gr->x + gr->width) - x;
+ h = FFMIN(cy + ci->height, gr->y + gr->height) - y;
+
+ c_off = x - cx;
+ i_off = x - gr->x;
+
+ cursor += (y - cy) * ci->width;
+ image += (y - gr->y) * gr->width * stride;
+
+ for (y = 0; y < h; y++) {
+ cursor += c_off;
+ image += i_off * stride;
+ for (x = 0; x < w; x++, cursor++, image += stride) {
+ int r, g, b, a;
+
+ r = *cursor & 0xff;
+ g = (*cursor >> 8) & 0xff;
+ b = (*cursor >> 16) & 0xff;
+ a = (*cursor >> 24) & 0xff;
+
+ if (!a)
+ continue;
+
+ if (a == 255) {
+ image[0] = r;
+ image[1] = g;
+ image[2] = b;
+ } else {
+ image[0] = BLEND(r, image[0], a);
+ image[1] = BLEND(g, image[1], a);
+ image[2] = BLEND(b, image[2], a);
+ }
+
+ }
+ cursor += ci->width - w - c_off;
+ image += (gr->width - w - i_off) * stride;
+ }
+
+ free(ci);
+
+ return 0;
+}
+
+static void xcbgrab_update_region(AVFormatContext *s)
+{
+ XCBGrabContext *g = s->priv_data;
+ const uint32_t args[] = { g->x - g->region_border,
+ g->y - g->region_border };
+
+ xcb_configure_window(g->conn,
+ g->window,
+ XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
+ args);
+}
+
+static int xcbgrab_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ XCBGrabContext *g = s->priv_data;
+ xcb_query_pointer_cookie_t pc;
+ xcb_get_geometry_cookie_t gc;
+ xcb_query_pointer_reply_t *p = NULL;
+ xcb_get_geometry_reply_t *geo = NULL;
+ int ret = 0;
+
+ wait_frame(s, pkt);
+
+ if (g->follow_mouse || g->draw_mouse) {
+ pc = xcb_query_pointer(g->conn, g->screen->root);
+ gc = xcb_get_geometry(g->conn, g->screen->root);
+ p = xcb_query_pointer_reply(g->conn, pc, NULL);
+ geo = xcb_get_geometry_reply(g->conn, gc, NULL);
+ }
+
+ if (g->follow_mouse) {
+ xcbgrab_reposition(s, p, geo);
+ if (g->show_region)
+ xcbgrab_update_region(s);
+ }
+
+#if HAVE_SYS_SHM_H
+ if (g->has_shm && xcbgrab_frame_shm(s, pkt) < 0)
+ g->has_shm = 0;
+#endif
+ if (!g->has_shm)
+ ret = xcbgrab_frame(s, pkt);
+
+ if (g->draw_mouse)
+ ret = xcbgrab_draw_mouse(s, pkt, p, geo);
+
+ free(p);
+ free(geo);
+
+ return ret;
+}
+
+static int xcbgrab_read_close(AVFormatContext *s)
+{
+ XCBGrabContext *g = s->priv_data;
+
+ xcb_disconnect(g->conn);
+
+ return 0;
+}
+
+static xcb_screen_t *get_screen(const xcb_setup_t *setup, int screen_num)
+{
+ xcb_screen_iterator_t it = xcb_setup_roots_iterator(setup);
+ xcb_screen_t *screen = NULL;
+
+ for (; it.rem > 0; xcb_screen_next (&it)) {
+ if (!screen_num) {
+ screen = it.data;
+ break;
+ }
+
+ screen_num--;
+ }
+
+ return screen;
+}
+
+static int check_shm(xcb_connection_t *conn)
+{
+#if HAVE_SYS_SHM_H
+ xcb_shm_query_version_cookie_t cookie = xcb_shm_query_version(conn);
+ xcb_shm_query_version_reply_t *reply;
+
+ reply = xcb_shm_query_version_reply(conn, cookie, NULL);
+ if (reply) {
+ free(reply);
+ return 1;
+ }
+#endif
+ return 0;
+}
+
+static int check_xfixes(xcb_connection_t *conn)
+{
+ xcb_xfixes_query_version_cookie_t cookie;
+ xcb_xfixes_query_version_reply_t *reply;
+
+ cookie = xcb_xfixes_query_version(conn, XCB_XFIXES_MAJOR_VERSION,
+ XCB_XFIXES_MINOR_VERSION);
+ reply = xcb_xfixes_query_version_reply(conn, cookie, NULL);
+
+ if (reply) {
+ free(reply);
+ return 1;
+ }
+ return 0;
+}
+
+static int pixfmt_from_pixmap_format(AVFormatContext *s, int depth)
+{
+ XCBGrabContext *g = s->priv_data;
+ const xcb_setup_t *setup = xcb_get_setup(g->conn);
+ const xcb_format_t *fmt = xcb_setup_pixmap_formats(setup);
+ int length = xcb_setup_pixmap_formats_length(setup);
+
+ g->frame_size = g->width * g->height;
+
+ while (length--) {
+ if (fmt->depth == depth) {
+ g->bpp = fmt->bits_per_pixel;
+ switch (depth) {
+ case 32:
+ if (fmt->bits_per_pixel == 32) {
+ g->frame_size *= 4;
+ return AV_PIX_FMT_ARGB;
+ }
+ break;
+ case 24:
+ if (fmt->bits_per_pixel == 32) {
+ g->frame_size *= 4;
+ return AV_PIX_FMT_RGB32;
+ } else if (fmt->bits_per_pixel == 24) {
+ g->frame_size *= 3;
+ return AV_PIX_FMT_RGB24;
+ }
+ break;
+ case 16:
+ if (fmt->bits_per_pixel == 16) {
+ g->frame_size *= 2;
+ return AV_PIX_FMT_RGB565;
+ }
+ break;
+ case 15:
+ if (fmt->bits_per_pixel == 16) {
+ g->frame_size *= 2;
+ return AV_PIX_FMT_RGB555;
+ }
+ break;
+ case 8:
+ if (fmt->bits_per_pixel == 8)
+ return AV_PIX_FMT_RGB8;
+ }
+ }
+ fmt++;
+ }
+ av_log(s, AV_LOG_ERROR, "Pixmap format not mappable\n");
+
+ return AVERROR_PATCHWELCOME;
+}
+
+
+static int create_stream(AVFormatContext *s)
+{
+ XCBGrabContext *g = s->priv_data;
+ AVStream *st = avformat_new_stream(s, NULL);
+ int ret;
+ xcb_get_geometry_cookie_t gc;
+ xcb_get_geometry_reply_t *geo;
+
+ if (!st)
+ return AVERROR(ENOMEM);
+
+ ret = av_parse_video_size(&g->width, &g->height, g->video_size);
+ if (ret < 0)
+ return ret;
+
+ ret = av_parse_video_rate(&st->avg_frame_rate, g->framerate);
+ if (ret < 0)
+ return ret;
+
+ avpriv_set_pts_info(st, 64, 1, 1000000);
+
+ gc = xcb_get_geometry(g->conn, g->screen->root);
+ geo = xcb_get_geometry_reply(g->conn, gc, NULL);
+
+ g->width = FFMIN(geo->width, g->width);
+ g->height = FFMIN(geo->height, g->height);
+ g->time_base = (AVRational){ st->avg_frame_rate.den,
+ st->avg_frame_rate.num };
+ g->time_frame = av_gettime();
+
+
+ st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+ st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
+ st->codec->width = g->width;
+ st->codec->height = g->height;
+ st->codec->time_base = g->time_base;
+
+ ret = pixfmt_from_pixmap_format(s, geo->depth);
+
+ free(geo);
+
+ if (ret < 0)
+ return ret;
+
+ st->codec->pix_fmt = ret;
+
+ return 0;
+}
+
+static void draw_rectangle(AVFormatContext *s)
+{
+ XCBGrabContext *g = s->priv_data;
+ xcb_gcontext_t gc = xcb_generate_id(g->conn);
+ uint32_t mask = XCB_GC_FOREGROUND |
+ XCB_GC_BACKGROUND |
+ XCB_GC_LINE_WIDTH |
+ XCB_GC_LINE_STYLE |
+ XCB_GC_FILL_STYLE;
+ uint32_t values[] = { g->screen->black_pixel,
+ g->screen->white_pixel,
+ g->region_border,
+ XCB_LINE_STYLE_DOUBLE_DASH,
+ XCB_FILL_STYLE_SOLID };
+ xcb_rectangle_t r = { 1, 1,
+ g->width + g->region_border * 2 - 3,
+ g->height + g->region_border * 2 - 3 };
+
+ xcb_create_gc(g->conn, gc, g->window, mask, values);
+
+ xcb_poly_rectangle(g->conn, g->window, gc, 1, &r);
+}
+
+static void setup_window(AVFormatContext *s)
+{
+ XCBGrabContext *g = s->priv_data;
+ uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
+ uint32_t values[] = { 1,
+ XCB_EVENT_MASK_EXPOSURE |
+ XCB_EVENT_MASK_STRUCTURE_NOTIFY };
+ xcb_rectangle_t rect = { g->x, g->y, g->width, g->height };
+
+ g->window = xcb_generate_id(g->conn);
+
+ xcb_create_window(g->conn, XCB_COPY_FROM_PARENT,
+ g->window,
+ g->screen->root,
+ g->x - g->region_border,
+ g->y - g->region_border,
+ g->width + g->region_border * 2,
+ g->height + g->region_border * 2,
+ 0,
+ XCB_WINDOW_CLASS_INPUT_OUTPUT,
+ XCB_COPY_FROM_PARENT,
+ mask, values);
+
+ xcb_shape_rectangles(g->conn, XCB_SHAPE_SO_SUBTRACT,
+ XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
+ g->window,
+ g->region_border, g->region_border,
+ 1, &rect);
+
+ xcb_map_window(g->conn, g->window);
+
+ draw_rectangle(s);
+}
+
+av_cold static int xcbgrab_read_header(AVFormatContext *s)
+{
+ XCBGrabContext *g = s->priv_data;
+ int screen_num, ret;
+ const xcb_setup_t *setup;
+
+ g->conn = xcb_connect(s->filename, &screen_num);
+ if ((ret = xcb_connection_has_error(g->conn))) {
+ av_log(s, AV_LOG_ERROR, "Cannot open display %s, error %d\n",
+ s->filename ? s->filename : "default", ret);
+ return AVERROR(EIO);
+ }
+ setup = xcb_get_setup(g->conn);
+
+ g->screen = get_screen(setup, screen_num);
+ if (!g->screen) {
+ av_log(s, AV_LOG_ERROR, "The screen %d does not exist.\n",
+ screen_num);
+ }
+
+ g->segment = xcb_generate_id(g->conn);
+ g->has_shm = check_shm(g->conn);
+
+ ret = create_stream(s);
+
+ if (ret < 0) {
+ xcbgrab_read_close(s);
+ return ret;
+ }
+
+ if (g->draw_mouse) {
+ if (!(g->draw_mouse = check_xfixes(g->conn))) {
+ av_log(s, AV_LOG_WARNING,
+ "XFixes not available, cannot draw the mouse.\n");
+ }
+ if (g->bpp < 24) {
+ avpriv_report_missing_feature(s, "%d bits per pixel screen",
+ g->bpp);
+ g->draw_mouse = 0;
+ }
+ }
+
+ if (g->show_region)
+ setup_window(s);
+
+ return 0;
+}
+
+AVInputFormat ff_xcbgrab_demuxer = {
+ .name = "xcbgrab",
+ .long_name = NULL_IF_CONFIG_SMALL("xcbgrab"),
+ .priv_data_size = sizeof(XCBGrabContext),
+ .read_header = xcbgrab_read_header,
+ .read_packet = xcbgrab_read_packet,
+ .read_close = xcbgrab_read_close,
+ .flags = AVFMT_NOFILE,
+ .priv_class = &xcbgrab_class,
+};
+
--
1.8.5.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel