]> git.sesse.net Git - vlc/commitdiff
* modules/video_output/x11/xcommon.c: try to detect XShmAttach() failure (eg. when...
authorGildas Bazin <gbazin@videolan.org>
Tue, 14 Jun 2005 17:24:01 +0000 (17:24 +0000)
committerGildas Bazin <gbazin@videolan.org>
Tue, 14 Jun 2005 17:24:01 +0000 (17:24 +0000)
modules/video_output/x11/xcommon.c

index 181d2acad2e60eed8308fd9519d5ad626cce4a18..7f3eefbed05dbe7b1200a48c79699b3e135fa2e9 100644 (file)
@@ -103,6 +103,7 @@ static IMAGE_TYPE *CreateImage    ( vout_thread_t *,
 #ifdef HAVE_SYS_SHM_H
 static IMAGE_TYPE *CreateShmImage ( vout_thread_t *,
                                     Display *, EXTRA_ARGS_SHM, int, int );
+static vlc_bool_t b_shm = VLC_TRUE;
 #endif
 
 static void ToggleFullScreen      ( vout_thread_t * );
@@ -1222,7 +1223,8 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
                             &p_pic->p_sys->shminfo,
                             p_vout->output.i_width, p_vout->output.i_height );
     }
-    else
+
+    if( !p_vout->p_sys->b_shm || !p_pic->p_sys->p_image )
 #endif /* HAVE_SYS_SHM_H */
     {
         /* Create image without XShm extension */
@@ -1238,6 +1240,14 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
                          p_vout->p_sys->i_bytes_per_pixel,
 #endif
                          p_vout->output.i_width, p_vout->output.i_height );
+
+#ifdef HAVE_SYS_SHM_H
+        if( p_pic->p_sys->p_image && p_vout->p_sys->b_shm )
+        {
+            msg_Warn( p_vout, "couldn't create SHM image, disabling SHM." );
+            p_vout->p_sys->b_shm = VLC_FALSE;
+        }
+#endif /* HAVE_SYS_SHM_H */
     }
 
     if( p_pic->p_sys->p_image == NULL )
@@ -2006,6 +2016,7 @@ static IMAGE_TYPE * CreateShmImage( vout_thread_t *p_vout,
                                     int i_width, int i_height )
 {
     IMAGE_TYPE *p_image;
+    Status result;
 
     /* Create XImage / XvImage */
 #ifdef MODULE_NAME_IS_xvideo
@@ -2047,7 +2058,10 @@ static IMAGE_TYPE * CreateShmImage( vout_thread_t *p_vout,
     p_shm->readOnly = True;
 
     /* Attach shared memory segment to X server */
-    if( XShmAttach( p_display, p_shm ) == False )
+    XSynchronize( p_display, True );
+    b_shm = VLC_TRUE;
+    result = XShmAttach( p_display, p_shm );
+    if( result == False || !b_shm )
     {
         msg_Err( p_vout, "cannot attach shared memory to X server" );
         IMAGE_FREE( p_image );
@@ -2055,6 +2069,7 @@ static IMAGE_TYPE * CreateShmImage( vout_thread_t *p_vout,
         shmdt( p_shm->shmaddr );
         return NULL;
     }
+    XSynchronize( p_display, False );
 
     /* Send image to X server. This instruction is required, since having
      * built a Shm XImage and not using it causes an error on XCloseDisplay,
@@ -2148,6 +2163,14 @@ static int X11ErrorHandler( Display * display, XErrorEvent * event )
         return 0;
     }
 
+    if( event->request_code == 150 /* MIT-SHM */ &&
+        event->minor_code == X_ShmAttach )
+    {
+        fprintf(stderr, "XShmAttach failed\n");
+        b_shm = VLC_FALSE;
+        return 0;
+    }
+
     XSetErrorHandler(NULL);
     return (XSetErrorHandler(X11ErrorHandler))( display, event );
 }