#include <stdlib.h>
#include <xcb/xcb.h>
+#include <xcb/shape.h>
#if CONFIG_LIBXCB_XFIXES
#include <xcb/xfixes.h>
#include <xcb/shm.h>
#endif
-#include "libavformat/avformat.h"
-#include "libavformat/internal.h"
-
+#include "libavutil/internal.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/time.h"
+#include "libavformat/avformat.h"
+#include "libavformat/internal.h"
+
typedef struct XCBGrabContext {
const AVClass *class;
xcb_get_image_cookie_t iq;
xcb_get_image_reply_t *img;
xcb_drawable_t drawable = c->screen->root;
+ xcb_generic_error_t *e = NULL;
uint8_t *data;
int length, ret;
iq = xcb_get_image(c->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
c->x, c->y, c->width, c->height, ~0);
- img = xcb_get_image_reply(c->conn, iq, NULL);
+ img = xcb_get_image_reply(c->conn, iq, &e);
+
+ if (e) {
+ av_log(s, AV_LOG_ERROR,
+ "Cannot get the image data "
+ "event_error: response_type:%u error_code:%u "
+ "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
+ e->response_type, e->error_code,
+ e->sequence, e->resource_id, e->minor_code, e->major_code);
+ return AVERROR(EACCES);
+ }
+
if (!img)
return AVERROR(EAGAIN);
xcb_shm_get_image_reply_t *img;
xcb_drawable_t drawable = c->screen->root;
uint8_t *data;
- int size = c->frame_size + FF_INPUT_BUFFER_PADDING_SIZE;
+ int size = c->frame_size + AV_INPUT_BUFFER_PADDING_SIZE;
int id = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777);
xcb_generic_error_t *e = NULL;
ret = xcbgrab_frame(s, pkt);
#if CONFIG_LIBXCB_XFIXES
- if (c->draw_mouse && p->same_screen)
+ if (ret >= 0 && c->draw_mouse && p->same_screen)
xcbgrab_draw_mouse(s, pkt, p, geo);
#endif
fmt++;
}
- av_log(s, AV_LOG_ERROR, "Pixmap format not mappable.\n");
+ avpriv_report_missing_feature(s, "Mapping this pixmap format");
return AVERROR_PATCHWELCOME;
}
{
XCBGrabContext *c = s->priv_data;
AVStream *st = avformat_new_stream(s, NULL);
- const char *opts = strchr(s->filename, '+');
xcb_get_geometry_cookie_t gc;
xcb_get_geometry_reply_t *geo;
int ret;
if (ret < 0)
return ret;
- if (opts)
- sscanf(opts, "%d,%d", &c->x, &c->y);
-
avpriv_set_pts_info(st, 64, 1, 1000000);
gc = xcb_get_geometry(c->conn, c->screen->root);
geo = xcb_get_geometry_reply(c->conn, gc, NULL);
- c->width = FFMIN(geo->width, c->width);
- c->height = FFMIN(geo->height, c->height);
+ if (c->x + c->width > geo->width ||
+ c->y + c->height > geo->height) {
+ av_log(s, AV_LOG_ERROR,
+ "Capture area %dx%d at position %d.%d "
+ "outside the screen size %dx%d\n",
+ c->width, c->height,
+ c->x, c->y,
+ geo->width, geo->height);
+ return AVERROR(EINVAL);
+ }
+
c->time_base = (AVRational){ st->avg_frame_rate.den,
st->avg_frame_rate.num };
c->time_frame = av_gettime();
- st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
- st->codec->width = c->width;
- st->codec->height = c->height;
- st->codec->time_base = c->time_base;
+ st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+ st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
+ st->codecpar->width = c->width;
+ st->codecpar->height = c->height;
- ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codec->pix_fmt);
+ ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codecpar->format);
free(geo);
XCBGrabContext *c = s->priv_data;
int screen_num, ret;
const xcb_setup_t *setup;
+ char *host = s->filename[0] ? s->filename : NULL;
+ const char *opts = strchr(s->filename, '+');
+
+ if (opts) {
+ sscanf(opts, "%d,%d", &c->x, &c->y);
+ host = av_strdup(s->filename);
+ if (!host)
+ return AVERROR(ENOMEM);
+ host[opts - s->filename] = '\0';
+ }
+
+ c->conn = xcb_connect(host, &screen_num);
- c->conn = xcb_connect(s->filename[0] ? s->filename : NULL, &screen_num);
if ((ret = xcb_connection_has_error(c->conn))) {
av_log(s, AV_LOG_ERROR, "Cannot open display %s, error %d.\n",
- s->filename[0] ? s->filename : "default", ret);
+ s->filename[0] ? host : "default", ret);
+ if (opts)
+ av_freep(&host);
return AVERROR(EIO);
}
+
+ if (opts)
+ av_freep(&host);
+
setup = xcb_get_setup(c->conn);
c->screen = get_screen(setup, screen_num);
return 0;
}
-AVInputFormat ff_x11grab_xcb_demuxer = {
+AVInputFormat ff_xcbgrab_demuxer = {
.name = "x11grab",
.long_name = NULL_IF_CONFIG_SMALL("X11 screen capture, using XCB"),
.priv_data_size = sizeof(XCBGrabContext),