27 #if CONFIG_LIBXCB_XFIXES
28 #include <xcb/xfixes.h>
36 #if CONFIG_LIBXCB_SHAPE
37 #include <xcb/shape.h>
78 #define FOLLOW_CENTER -1
80 #define OFFSET(x) offsetof(XCBGrabContext, x)
81 #define D AV_OPT_FLAG_DECODING_PARAM
87 {
"video_size",
"A string describing frame size, such as 640x480 or hd720.",
OFFSET(video_size),
AV_OPT_TYPE_STRING, {.str =
"vga" }, 0, 0,
D },
90 {
"follow_mouse",
"Move the grabbing region when the mouse pointer reaches within specified amount of pixels to the edge of region.",
92 {
"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" },
93 {
"show_region",
"Show the grabbing region.",
OFFSET(show_region),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
D },
94 {
"region_border",
"Set the region border thickness.",
OFFSET(region_border),
AV_OPT_TYPE_INT, { .i64 = 3 }, 1, 128,
D },
107 xcb_query_pointer_reply_t *p,
108 xcb_get_geometry_reply_t *geo)
111 int x = c->
x, y = c->
y;
126 int right = x + w - f;
128 int bottom = y +
h + f;
131 }
else if (p_x < left) {
136 }
else if (p_y < top) {
150 xcb_get_image_cookie_t iq;
151 xcb_get_image_reply_t *
img;
152 xcb_drawable_t drawable = c->
screen->root;
153 xcb_generic_error_t *e =
NULL;
157 iq = xcb_get_image(c->
conn, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
160 img = xcb_get_image_reply(c->
conn, iq, &e);
164 "Cannot get the image data "
165 "event_error: response_type:%u error_code:%u "
166 "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
167 e->response_type, e->error_code,
168 e->sequence, e->resource_id, e->minor_code, e->major_code);
175 data = xcb_get_image_data(img);
176 length = xcb_get_image_data_length(img);
181 memcpy(pkt->
data, data, length);
191 int64_t curtime, delay;
207 #if CONFIG_LIBXCB_SHM
208 static int check_shm(xcb_connection_t *conn)
210 xcb_shm_query_version_cookie_t cookie = xcb_shm_query_version(conn);
211 xcb_shm_query_version_reply_t *reply;
213 reply = xcb_shm_query_version_reply(conn, cookie,
NULL);
222 static void dealloc_shm(
void *unused,
uint8_t *
data)
230 xcb_shm_get_image_cookie_t iq;
231 xcb_shm_get_image_reply_t *
img;
232 xcb_drawable_t drawable = c->
screen->root;
235 int id = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777);
236 xcb_generic_error_t *e =
NULL;
247 xcb_shm_attach(c->
conn, c->segment,
id, 0);
249 iq = xcb_shm_get_image(c->
conn, drawable,
251 XCB_IMAGE_FORMAT_Z_PIXMAP, c->segment, 0);
253 xcb_shm_detach(c->
conn, c->segment);
255 img = xcb_shm_get_image_reply(c->
conn, iq, &e);
261 "Cannot get the image data "
262 "event_error: response_type:%u error_code:%u "
263 "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
264 e->response_type, e->error_code,
265 e->sequence, e->resource_id, e->minor_code, e->major_code);
267 shmctl(
id, IPC_RMID, 0);
273 data = shmat(
id,
NULL, 0);
274 shmctl(
id, IPC_RMID, 0);
276 if ((intptr_t)data == -1)
292 #if CONFIG_LIBXCB_XFIXES
293 static int check_xfixes(xcb_connection_t *conn)
295 xcb_xfixes_query_version_cookie_t cookie;
296 xcb_xfixes_query_version_reply_t *reply;
298 cookie = xcb_xfixes_query_version(conn, XCB_XFIXES_MAJOR_VERSION,
299 XCB_XFIXES_MINOR_VERSION);
300 reply = xcb_xfixes_query_version_reply(conn, cookie,
NULL);
309 #define BLEND(target, source, alpha) \
310 (target) + ((source) * (255 - (alpha)) + 255 / 2) / 255
313 xcb_query_pointer_reply_t *p,
314 xcb_get_geometry_reply_t *geo)
320 xcb_xfixes_get_cursor_image_cookie_t cc;
321 xcb_xfixes_get_cursor_image_reply_t *ci;
322 int cx, cy, x, y, w,
h, c_off, i_off;
324 cc = xcb_xfixes_get_cursor_image(gr->
conn);
325 ci = xcb_xfixes_get_cursor_image_reply(gr->
conn, cc,
NULL);
329 cursor = xcb_xfixes_get_cursor_image_cursor_image(ci);
333 cx = ci->x - ci->xhot;
334 cy = ci->y - ci->yhot;
345 cursor += (y - cy) * ci->width;
348 for (y = 0; y <
h; y++) {
351 for (x = 0; x < w; x++, cursor++, image +=
stride) {
355 g = (*cursor >> 8) & 0xff;
356 b = (*cursor >> 16) & 0xff;
357 a = (*cursor >> 24) & 0xff;
367 image[0] = BLEND(r, image[0], a);
368 image[1] = BLEND(g, image[1], a);
369 image[2] = BLEND(b, image[2], a);
373 cursor += ci->width - w - c_off;
374 image += (gr->
width - w - i_off) * stride;
387 xcb_configure_window(c->
conn,
389 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
396 xcb_query_pointer_cookie_t pc;
397 xcb_get_geometry_cookie_t gc;
398 xcb_query_pointer_reply_t *p =
NULL;
399 xcb_get_geometry_reply_t *geo =
NULL;
405 pc = xcb_query_pointer(c->
conn, c->
screen->root);
406 gc = xcb_get_geometry(c->
conn, c->
screen->root);
407 p = xcb_query_pointer_reply(c->
conn, pc,
NULL);
408 geo = xcb_get_geometry_reply(c->
conn, gc,
NULL);
417 #if CONFIG_LIBXCB_SHM
418 if (c->
has_shm && xcbgrab_frame_shm(s, pkt) < 0)
424 #if CONFIG_LIBXCB_XFIXES
425 if (ret >= 0 && c->
draw_mouse && p->same_screen)
426 xcbgrab_draw_mouse(s, pkt, p, geo);
439 xcb_disconnect(ctx->
conn);
444 static xcb_screen_t *
get_screen(
const xcb_setup_t *setup,
int screen_num)
446 xcb_screen_iterator_t it = xcb_setup_roots_iterator(setup);
449 for (; it.rem > 0; xcb_screen_next (&it)) {
465 const xcb_setup_t *setup = xcb_get_setup(c->
conn);
466 const xcb_format_t *
fmt = xcb_setup_pixmap_formats(setup);
467 int length = xcb_setup_pixmap_formats_length(setup);
472 if (fmt->depth == depth) {
475 if (fmt->bits_per_pixel == 32)
479 if (fmt->bits_per_pixel == 32)
481 else if (fmt->bits_per_pixel == 24)
485 if (fmt->bits_per_pixel == 16)
489 if (fmt->bits_per_pixel == 16)
493 if (fmt->bits_per_pixel == 8)
500 c->
bpp = fmt->bits_per_pixel;
516 xcb_get_geometry_cookie_t gc;
517 xcb_get_geometry_reply_t *geo;
533 gc = xcb_get_geometry(c->
conn, c->
screen->root);
534 geo = xcb_get_geometry_reply(c->
conn, gc,
NULL);
536 if (c->
x + c->
width > geo->width ||
537 c->
y + c->
height > geo->height) {
539 "Capture area %dx%d at position %d.%d "
540 "outside the screen size %dx%d\n",
543 geo->width, geo->height);
567 xcb_gcontext_t gc = xcb_generate_id(c->
conn);
568 uint32_t
mask = XCB_GC_FOREGROUND |
573 uint32_t values[] = { c->
screen->black_pixel,
576 XCB_LINE_STYLE_DOUBLE_DASH,
577 XCB_FILL_STYLE_SOLID };
578 xcb_rectangle_t
r = { 1, 1,
582 xcb_create_gc(c->
conn, gc, c->
window, mask, values);
584 xcb_poly_rectangle(c->
conn, c->
window, gc, 1, &r);
590 uint32_t
mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
591 uint32_t values[] = { 1,
592 XCB_EVENT_MASK_EXPOSURE |
593 XCB_EVENT_MASK_STRUCTURE_NOTIFY };
598 xcb_create_window(c->
conn, XCB_COPY_FROM_PARENT,
606 XCB_WINDOW_CLASS_INPUT_OUTPUT,
607 XCB_COPY_FROM_PARENT,
610 #if CONFIG_LIBXCB_SHAPE
611 xcb_shape_rectangles(c->
conn, XCB_SHAPE_SO_SUBTRACT,
612 XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
627 const xcb_setup_t *setup;
633 if (!sscanf(s->
filename,
"%[^+]+%d,%d", display_name, &c->
x, &c->
y)) {
638 c->
conn = xcb_connect(display_name[0] ? display_name :
NULL, &screen_num);
641 if ((ret = xcb_connection_has_error(c->
conn))) {
647 setup = xcb_get_setup(c->
conn);
664 #if CONFIG_LIBXCB_SHM
666 c->segment = xcb_generate_id(c->
conn);
669 #if CONFIG_LIBXCB_XFIXES
673 "XFixes not available, cannot draw the mouse.\n");
697 .priv_class = &xcbgrab_class,
static xcb_screen_t * get_screen(const xcb_setup_t *setup, int screen_num)
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)
ptrdiff_t const GLvoid * data
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 AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int av_usleep(unsigned usec)
Sleep for a period of time.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
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
AVInputFormat ff_x11grab_xcb_demuxer
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. ...
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.
AVCodecContext * codec
Codec context associated with this stream.
common internal API header
static SDL_Surface * screen
char filename[1024]
input or output filename
static const AVOption options[]
int width
picture width / height.
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)
enum AVMediaType codec_type
#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.
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)
GLint GLenum GLboolean GLsizei stride
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
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