27 #if CONFIG_LIBXCB_XFIXES 28 #include <xcb/xfixes.h> 36 #if CONFIG_LIBXCB_SHAPE 37 #include <xcb/shape.h> 80 #define FOLLOW_CENTER -1 82 #define OFFSET(x) offsetof(XCBGrabContext, x) 83 #define D AV_OPT_FLAG_DECODING_PARAM 92 {
"follow_mouse",
"Move the grabbing region when the mouse pointer reaches within specified amount of pixels to the edge of region.",
94 {
"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" },
109 xcb_query_pointer_reply_t *p,
110 xcb_get_geometry_reply_t *geo)
113 int x = c->
x,
y = c->
y;
128 int right = x + w - f;
130 int bottom =
y +
h + f;
133 }
else if (p_x < left) {
138 }
else if (p_y < top) {
152 xcb_get_image_cookie_t iq;
153 xcb_get_image_reply_t *
img;
154 xcb_drawable_t drawable = c->
screen->root;
155 xcb_generic_error_t *e =
NULL;
159 iq = xcb_get_image(c->
conn, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
162 img = xcb_get_image_reply(c->
conn, iq, &e);
166 "Cannot get the image data " 167 "event_error: response_type:%u error_code:%u " 168 "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
169 e->response_type, e->error_code,
170 e->sequence, e->resource_id, e->minor_code, e->major_code);
177 data = xcb_get_image_data(img);
178 length = xcb_get_image_data_length(img);
183 memcpy(pkt->
data, data, length);
193 int64_t curtime, delay;
209 #if CONFIG_LIBXCB_SHM 210 static int check_shm(xcb_connection_t *
conn)
212 xcb_shm_query_version_cookie_t cookie = xcb_shm_query_version(conn);
213 xcb_shm_query_version_reply_t *reply;
215 reply = xcb_shm_query_version_reply(conn, cookie,
NULL);
233 id = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777);
242 xcb_shm_attach(c->
conn, c->segment,
id, 0);
243 data = shmat(
id,
NULL, 0);
244 shmctl(
id, IPC_RMID, 0);
245 if ((intptr_t)data == -1 || !data)
254 xcb_shm_get_image_cookie_t iq;
255 xcb_shm_get_image_reply_t *
img;
256 xcb_drawable_t drawable = c->
screen->root;
257 xcb_generic_error_t *e =
NULL;
260 ret = allocate_shm(s);
264 iq = xcb_shm_get_image(c->
conn, drawable,
266 XCB_IMAGE_FORMAT_Z_PIXMAP, c->segment, 0);
267 img = xcb_shm_get_image_reply(c->
conn, iq, &e);
273 "Cannot get the image data " 274 "event_error: response_type:%u error_code:%u " 275 "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
276 e->response_type, e->error_code,
277 e->sequence, e->resource_id, e->minor_code, e->major_code);
291 #if CONFIG_LIBXCB_XFIXES 292 static int check_xfixes(xcb_connection_t *
conn)
294 xcb_xfixes_query_version_cookie_t cookie;
295 xcb_xfixes_query_version_reply_t *reply;
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);
308 #define BLEND(target, source, alpha) \ 309 (target) + ((source) * (255 - (alpha)) + 255 / 2) / 255 312 xcb_query_pointer_reply_t *p,
313 xcb_get_geometry_reply_t *geo)
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;
323 cc = xcb_xfixes_get_cursor_image(gr->
conn);
324 ci = xcb_xfixes_get_cursor_image_reply(gr->
conn, cc,
NULL);
328 cursor = xcb_xfixes_get_cursor_image_cursor_image(ci);
332 cx = ci->x - ci->xhot;
333 cy = ci->y - ci->yhot;
344 cursor += (y - cy) * ci->width;
347 for (y = 0; y <
h; y++) {
350 for (x = 0; x <
w; x++, cursor++, image +=
stride) {
354 g = (*cursor >> 8) & 0xff;
355 b = (*cursor >> 16) & 0xff;
356 a = (*cursor >> 24) & 0xff;
366 image[0] = BLEND(r, image[0], a);
367 image[1] = BLEND(g, image[1], a);
368 image[2] = BLEND(b, image[2], a);
372 cursor += ci->width - w - c_off;
373 image += (gr->
width - w - i_off) * stride;
386 xcb_configure_window(c->
conn,
388 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
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;
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);
416 #if CONFIG_LIBXCB_SHM 417 if (c->
has_shm && xcbgrab_frame_shm(s, pkt) < 0)
423 #if CONFIG_LIBXCB_XFIXES 424 if (ret >= 0 && c->
draw_mouse && p->same_screen)
425 xcbgrab_draw_mouse(s, pkt, p, geo);
438 #if CONFIG_LIBXCB_SHM 444 xcb_disconnect(ctx->
conn);
449 static xcb_screen_t *
get_screen(
const xcb_setup_t *setup,
int screen_num)
451 xcb_screen_iterator_t it = xcb_setup_roots_iterator(setup);
454 for (; it.rem > 0; xcb_screen_next (&it)) {
470 const xcb_setup_t *setup = xcb_get_setup(c->
conn);
471 const xcb_format_t *
fmt = xcb_setup_pixmap_formats(setup);
472 int length = xcb_setup_pixmap_formats_length(setup);
477 if (fmt->depth == depth) {
480 if (fmt->bits_per_pixel == 32)
484 if (fmt->bits_per_pixel == 32)
486 else if (fmt->bits_per_pixel == 24)
490 if (fmt->bits_per_pixel == 16)
494 if (fmt->bits_per_pixel == 16)
498 if (fmt->bits_per_pixel == 8)
505 c->
bpp = fmt->bits_per_pixel;
521 xcb_get_geometry_cookie_t gc;
522 xcb_get_geometry_reply_t *geo;
538 gc = xcb_get_geometry(c->
conn, c->
screen->root);
539 geo = xcb_get_geometry_reply(c->
conn, gc,
NULL);
541 if (c->
x + c->
width > geo->width ||
542 c->
y + c->
height > geo->height) {
544 "Capture area %dx%d at position %d.%d " 545 "outside the screen size %dx%d\n",
548 geo->width, geo->height);
571 xcb_gcontext_t gc = xcb_generate_id(c->
conn);
572 uint32_t
mask = XCB_GC_FOREGROUND |
577 uint32_t values[] = { c->
screen->black_pixel,
580 XCB_LINE_STYLE_DOUBLE_DASH,
581 XCB_FILL_STYLE_SOLID };
582 xcb_rectangle_t
r = { 1, 1,
586 xcb_create_gc(c->
conn, gc, c->
window, mask, values);
588 xcb_poly_rectangle(c->
conn, c->
window, gc, 1, &r);
594 uint32_t
mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
595 uint32_t values[] = { 1,
596 XCB_EVENT_MASK_EXPOSURE |
597 XCB_EVENT_MASK_STRUCTURE_NOTIFY };
602 xcb_create_window(c->
conn, XCB_COPY_FROM_PARENT,
610 XCB_WINDOW_CLASS_INPUT_OUTPUT,
611 XCB_COPY_FROM_PARENT,
614 #if CONFIG_LIBXCB_SHAPE 615 xcb_shape_rectangles(c->
conn, XCB_SHAPE_SO_SUBTRACT,
616 XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
631 const xcb_setup_t *setup;
637 if (!sscanf(s->
url,
"%[^+]+%d,%d", display_name, &c->
x, &c->
y)) {
639 sscanf(s->
url,
"+%d,%d", &c->
x, &c->
y);
642 c->
conn = xcb_connect(display_name[0] ? display_name :
NULL, &screen_num);
645 if ((ret = xcb_connection_has_error(c->
conn))) {
647 s->
url[0] ? s->
url :
"default", ret);
651 setup = xcb_get_setup(c->
conn);
668 #if CONFIG_LIBXCB_SHM 670 c->segment = xcb_generate_id(c->
conn);
673 #if CONFIG_LIBXCB_XFIXES 677 "XFixes not available, cannot draw the mouse.\n");
701 .priv_class = &xcbgrab_class,
static xcb_screen_t * get_screen(const xcb_setup_t *setup, int screen_num)
AVInputFormat ff_xcbgrab_demuxer
static enum AVPixelFormat pix_fmt
static av_cold int xcbgrab_read_header(AVFormatContext *s)
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
static int create_stream(AVFormatContext *s)
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.
static void xcbgrab_update_region(AVFormatContext *s)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
packed RGB 8:8:8, 24bpp, RGBRGB...
static void draw_rectangle(AVFormatContext *s)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
const char * av_default_item_name(void *ptr)
Return the context name.
int av_usleep(unsigned usec)
Sleep for a period of time.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
static const AVClass xcbgrab_class
static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt)
static av_cold int read_close(AVFormatContext *ctx)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static int pixfmt_from_pixmap_format(AVFormatContext *s, int depth, int *pix_fmt)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
char * url
input or output URL.
enum AVMediaType codec_type
General type of the encoded data.
AVRational avg_frame_rate
Average framerate.
common internal API header
static const AVOption options[]
const char AVS_Value args
static void wait_frame(AVFormatContext *s, AVPacket *pkt)
static int read_header(FFV1Context *f)
int64_t av_gettime(void)
Get the current time in microseconds.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
char * av_strdup(const char *s)
Duplicate a string.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Describe the class of an AVClass context structure.
static int xcbgrab_read_packet(AVFormatContext *s, AVPacket *pkt)
Rational number (pair of numerator and denominator).
static void setup_window(AVFormatContext *s)
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.
static int xcbgrab_reposition(AVFormatContext *s, xcb_query_pointer_reply_t *p, xcb_get_geometry_reply_t *geo)
static av_cold int xcbgrab_read_close(AVFormatContext *s)
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
#define AV_PIX_FMT_RGB555
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
void * priv_data
Format private data.
#define AV_PIX_FMT_RGB565
AVCodecParameters * codecpar
Codec parameters associated with this stream.
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_PIX_FMT_0RGB32