Merge commit 'bb3ead7e54fec205c595cfb8b1d8900d50d3d1cc'
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 3 Sep 2014 11:29:49 +0000 (13:29 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 3 Sep 2014 11:30:24 +0000 (13:30 +0200)
* commit 'bb3ead7e54fec205c595cfb8b1d8900d50d3d1cc':
  x11grab: Fallback to normal XImage if SHM is not supported

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavdevice/x11grab.c

@@@ -220,39 -250,16 +249,18 @@@ static int x11grab_read_header(AVFormat
                 x_off, y_off);
      }
  
 -    use_shm = XShmQueryExtension(dpy);
 -    av_log(s1, AV_LOG_INFO,
 -           "shared memory extension %sfound\n", use_shm ? "" : "not ");
 +    if (x11grab->use_shm) {
 +        use_shm = XShmQueryExtension(dpy);
 +        av_log(s1, AV_LOG_INFO,
 +               "shared memory extension %sfound\n", use_shm ? "" : "not ");
 +    }
  
-     if (use_shm) {
-         int scr = XDefaultScreen(dpy);
-         image = XShmCreateImage(dpy,
-                                 DefaultVisual(dpy, scr),
-                                 DefaultDepth(dpy, scr),
-                                 ZPixmap,
-                                 NULL,
-                                 &x11grab->shminfo,
-                                 x11grab->width, x11grab->height);
-         x11grab->shminfo.shmid = shmget(IPC_PRIVATE,
-                                         image->bytes_per_line * image->height,
-                                         IPC_CREAT | 0777);
-         if (x11grab->shminfo.shmid == -1) {
-             av_log(s1, AV_LOG_ERROR, "Fatal: Can't get shared memory!\n");
-             ret = AVERROR(ENOMEM);
-             goto out;
-         }
-         x11grab->shminfo.shmaddr  = image->data = shmat(x11grab->shminfo.shmid, 0, 0);
-         x11grab->shminfo.readOnly = False;
-         if (!XShmAttach(dpy, &x11grab->shminfo)) {
-             av_log(s1, AV_LOG_ERROR, "Fatal: Failed to attach shared memory!\n");
-             /* needs some better error subroutine :) */
-             ret = AVERROR(EIO);
-             goto out;
-         }
-     } else {
+     if (use_shm && setup_shm(s1, dpy, &image) < 0) {
+         av_log(s1, AV_LOG_WARNING, "Falling back to XGetImage\n");
+         use_shm = 0;
+     }
+     if (!use_shm) {
          image = XGetImage(dpy, RootWindow(dpy, screen),
                            x_off, y_off,
                            x11grab->width, x11grab->height,