26 #include <xcb/shape.h> 28 #if CONFIG_LIBXCB_XFIXES 29 #include <xcb/xfixes.h> 75 #define FOLLOW_CENTER -1 77 #define OFFSET(x) offsetof(XCBGrabContext, x) 78 #define D AV_OPT_FLAG_DECODING_PARAM 87 {
"follow_mouse",
"Move the grabbing region when the mouse pointer reaches within specified amount of pixels to the edge of region.",
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" },
103 xcb_query_pointer_reply_t *p,
104 xcb_get_geometry_reply_t *geo)
107 int x = c->
x,
y = c->
y;
122 int right = x + w - f;
124 int bottom =
y + h + f;
127 }
else if (p_x < left) {
132 }
else if (p_y < top) {
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;
153 iq = xcb_get_image(c->
conn, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
156 img = xcb_get_image_reply(c->
conn, iq, &e);
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);
171 data = xcb_get_image_data(img);
172 length = xcb_get_image_data_length(img);
177 memcpy(pkt->
data, data, length);
187 int64_t curtime, delay;
203 #if CONFIG_LIBXCB_SHM 204 static int check_shm(xcb_connection_t *
conn)
206 xcb_shm_query_version_cookie_t cookie = xcb_shm_query_version(conn);
207 xcb_shm_query_version_reply_t *reply;
209 reply = xcb_shm_query_version_reply(conn, cookie,
NULL);
218 static void dealloc_shm(
void *unused,
uint8_t *
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;
231 int id = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777);
232 xcb_generic_error_t *e =
NULL;
243 xcb_shm_attach(c->
conn, c->segment,
id, 0);
245 iq = xcb_shm_get_image(c->
conn, drawable,
247 XCB_IMAGE_FORMAT_Z_PIXMAP, c->segment, 0);
249 xcb_shm_detach(c->
conn, c->segment);
251 img = xcb_shm_get_image_reply(c->
conn, iq, &e);
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);
263 shmctl(
id, IPC_RMID, 0);
269 data = shmat(
id,
NULL, 0);
270 shmctl(
id, IPC_RMID, 0);
272 if ((intptr_t)data == -1)
288 #if CONFIG_LIBXCB_XFIXES 289 static int check_xfixes(xcb_connection_t *
conn)
291 xcb_xfixes_query_version_cookie_t cookie;
292 xcb_xfixes_query_version_reply_t *reply;
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);
305 #define BLEND(target, source, alpha) \ 306 (target) + ((source) * (255 - (alpha)) + 255 / 2) / 255 309 xcb_query_pointer_reply_t *p,
310 xcb_get_geometry_reply_t *geo)
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;
320 cc = xcb_xfixes_get_cursor_image(gr->
conn);
321 ci = xcb_xfixes_get_cursor_image_reply(gr->
conn, cc,
NULL);
325 cursor = xcb_xfixes_get_cursor_image_cursor_image(ci);
329 cx = ci->x - ci->xhot;
330 cy = ci->y - ci->yhot;
341 cursor += (y - cy) * ci->width;
344 for (y = 0; y < h; y++) {
347 for (x = 0; x < w; x++, cursor++, image +=
stride) {
351 g = (*cursor >> 8) & 0xff;
352 b = (*cursor >> 16) & 0xff;
353 a = (*cursor >> 24) & 0xff;
363 image[0] = BLEND(r, image[0], a);
364 image[1] = BLEND(g, image[1], a);
365 image[2] = BLEND(b, image[2], a);
369 cursor += ci->width - w - c_off;
370 image += (gr->
width - w - i_off) * stride;
383 xcb_configure_window(c->
conn,
385 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
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;
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);
413 #if CONFIG_LIBXCB_SHM 414 if (c->
has_shm && xcbgrab_frame_shm(s, pkt) < 0)
420 #if CONFIG_LIBXCB_XFIXES 421 if (ret >= 0 && c->
draw_mouse && p->same_screen)
422 xcbgrab_draw_mouse(s, pkt, p, geo);
435 xcb_disconnect(ctx->
conn);
440 static xcb_screen_t *
get_screen(
const xcb_setup_t *setup,
int screen_num)
442 xcb_screen_iterator_t it = xcb_setup_roots_iterator(setup);
445 for (; it.rem > 0; xcb_screen_next (&it)) {
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);
468 if (fmt->depth == depth) {
471 if (fmt->bits_per_pixel == 32)
475 if (fmt->bits_per_pixel == 32)
477 else if (fmt->bits_per_pixel == 24)
481 if (fmt->bits_per_pixel == 16)
485 if (fmt->bits_per_pixel == 16)
489 if (fmt->bits_per_pixel == 8)
496 c->
bpp = fmt->bits_per_pixel;
512 xcb_get_geometry_cookie_t gc;
513 xcb_get_geometry_reply_t *geo;
529 gc = xcb_get_geometry(c->
conn, c->
screen->root);
530 geo = xcb_get_geometry_reply(c->
conn, gc,
NULL);
532 if (c->
x + c->
width > geo->width ||
533 c->
y + c->
height > geo->height) {
535 "Capture area %dx%d at position %d.%d " 536 "outside the screen size %dx%d\n",
539 geo->width, geo->height);
562 xcb_gcontext_t gc = xcb_generate_id(c->
conn);
563 uint32_t
mask = XCB_GC_FOREGROUND |
568 uint32_t values[] = { c->
screen->black_pixel,
571 XCB_LINE_STYLE_DOUBLE_DASH,
572 XCB_FILL_STYLE_SOLID };
573 xcb_rectangle_t
r = { 1, 1,
577 xcb_create_gc(c->
conn, gc, c->
window, mask, values);
579 xcb_poly_rectangle(c->
conn, c->
window, gc, 1, &r);
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 };
593 xcb_create_window(c->
conn, XCB_COPY_FROM_PARENT,
601 XCB_WINDOW_CLASS_INPUT_OUTPUT,
602 XCB_COPY_FROM_PARENT,
605 xcb_shape_rectangles(c->
conn, XCB_SHAPE_SO_SUBTRACT,
606 XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
620 const xcb_setup_t *setup;
625 sscanf(opts,
"%d,%d", &c->
x, &c->
y);
632 c->
conn = xcb_connect(host, &screen_num);
634 if ((ret = xcb_connection_has_error(c->
conn))) {
636 s->
filename[0] ? host :
"default", ret);
645 setup = xcb_get_setup(c->
conn);
662 #if CONFIG_LIBXCB_SHM 664 c->segment = xcb_generate_id(c->
conn);
667 #if CONFIG_LIBXCB_XFIXES 671 "XFixes not available, cannot draw the mouse.\n");
695 .priv_class = &xcbgrab_class,
static xcb_screen_t * get_screen(const xcb_setup_t *setup, int screen_num)
AVInputFormat ff_xcbgrab_demuxer
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.
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).
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)
int av_usleep(unsigned usec)
Sleep for a period of time.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
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. ...
enum AVMediaType codec_type
General type of the encoded data.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
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.
AVRational avg_frame_rate
Average framerate.
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
common internal API header
char filename[1024]
input or output filename
static const AVOption options[]
enum AVPixelFormat pix_fmt
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 Libav, patches welcome.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
char * av_strdup(const char *s)
Duplicate the string s.
uint8_t * data
The data buffer.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Describe the class of an AVClass context structure.
static int xcbgrab_read_packet(AVFormatContext *s, AVPacket *pkt)
rational number numerator/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
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...