]> git.sesse.net Git - ffmpeg/blobdiff - libavdevice/xcbgrab.c
x86: huffyuv: Use EXTERNAL_SSSE3_FAST convenience macro where appropriate
[ffmpeg] / libavdevice / xcbgrab.c
index c4db9837e8c29c03a2eccf5fa61bee89b6056228..9b85c28e24c6791426c9a3fea39aa17765c673ff 100644 (file)
@@ -23,6 +23,7 @@
 
 #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;
 
@@ -144,13 +146,25 @@ static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt)
     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);
 
@@ -213,7 +227,7 @@ static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket *pkt)
     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;
 
@@ -404,7 +418,7 @@ static int xcbgrab_read_packet(AVFormatContext *s, AVPacket *pkt)
         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
 
@@ -515,19 +529,27 @@ static int create_stream(AVFormatContext *s)
     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);
 
@@ -602,19 +624,24 @@ static av_cold int xcbgrab_read_header(AVFormatContext *s)
     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);
 
-    if (opts)
-        av_free(host);
-
     if ((ret = xcb_connection_has_error(c->conn))) {
         av_log(s, AV_LOG_ERROR, "Cannot open display %s, error %d.\n",
                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);