]> git.sesse.net Git - vlc/commitdiff
XCB: Factor picture allocation
authorRémi Denis-Courmont <remi@remlab.net>
Mon, 20 Apr 2009 10:01:58 +0000 (13:01 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 25 Apr 2009 19:10:36 +0000 (22:10 +0300)
modules/video_output/xcb/common.c
modules/video_output/xcb/x11.c
modules/video_output/xcb/xcb_vlc.h

index afc0133db13b97aa05de316e259bff9a335fd448..b6d8f4437353a71e3e0d3c5e211dfa8e86c3f9d5 100644 (file)
@@ -158,3 +158,75 @@ int GetWindowSize (struct vout_window_t *wnd, xcb_connection_t *conn,
     free (geo);
     return 0;
 }
+
+/**
+ * Initialize a picture buffer as shared memory, according to the video output
+ * format. If a XCB connection pointer is supplied, the segment is attached to
+ * the X server (MIT-SHM extension).
+ */
+int PictureInit (vout_thread_t *vout, picture_t *pic, xcb_connection_t *conn)
+{
+    assert (pic->i_status == FREE_PICTURE);
+    vout_InitPicture (vout, pic, vout->output.i_chroma,
+                      vout->output.i_width, vout->output.i_height,
+                      vout->output.i_aspect);
+
+    const size_t size = pic->p->i_pitch * pic->p->i_lines;
+
+    /* Allocate shared memory segment */
+    int id = shmget (IPC_PRIVATE, size, IPC_CREAT | 0700);
+    if (id == -1)
+    {
+        msg_Err (vout, "shared memory allocation error: %m");
+        return VLC_EGENERIC;
+    }
+
+    /* Attach the segment to VLC */
+    void *shm = shmat (id, NULL, 0 /* read/write */);
+    if (-1 == (intptr_t)shm)
+    {
+        msg_Err (vout, "shared memory attachment error: %m");
+        shmctl (id, IPC_RMID, 0);
+        return VLC_EGENERIC;
+    }
+
+    xcb_shm_seg_t segment;
+    if (conn != NULL)
+    {
+        /* Attach the segment to X */
+        xcb_void_cookie_t ck;
+
+        segment = xcb_generate_id (conn);
+        ck = xcb_shm_attach_checked (conn, segment, id, 1);
+
+        if (CheckError (vout, "shared memory server-side error", ck))
+        {
+            msg_Info (vout, "using buggy X11 server - SSH proxying?");
+            segment = 0;
+        }
+    }
+    else
+        segment = 0;
+
+    shmctl (id, IPC_RMID, 0);
+    pic->p_sys = (void *)(uintptr_t)segment;
+    pic->p->p_pixels = shm;
+    pic->i_status = DESTROYED_PICTURE;
+    pic->i_type = DIRECT_PICTURE;
+    return VLC_SUCCESS;
+}
+
+/**
+ * Release picture private data: detach the shared memory segment.
+ */
+void PictureDeinit (picture_t *pic, xcb_connection_t *conn)
+{
+    xcb_shm_seg_t segment = (uintptr_t)pic->p_sys;
+
+    if (segment != 0)
+    {
+        assert (conn != NULL);
+        xcb_shm_detach (conn, segment);
+    }
+    shmdt (pic->p->p_pixels);
+}
index d6e8eec6dd1c713ada036e4a578544192a9700d2..6679b18dfeed1f65c78b1d73de13801debd3e4e3 100644 (file)
@@ -27,9 +27,6 @@
 #include <stdlib.h>
 #include <assert.h>
 
-#include <sys/types.h>
-#include <sys/shm.h>
-
 #include <xcb/xcb.h>
 #include <xcb/shm.h>
 
@@ -299,74 +296,6 @@ static void Close (vlc_object_t *obj)
     free (p_sys);
 }
 
-#define SHM_ERR ((void *)(intptr_t)(-1))
-
-static int PictureInit (vout_thread_t *vout, picture_t *pic)
-{
-    vout_sys_t *p_sys = vout->p_sys;
-
-    assert (pic->i_status == FREE_PICTURE);
-    vout_InitPicture (vout, pic, vout->output.i_chroma,
-                      vout->output.i_width, vout->output.i_height,
-                      vout->output.i_aspect);
-
-    void *shm = SHM_ERR;
-    const size_t size = pic->p->i_pitch * pic->p->i_lines;
-
-    /* Allocate shared memory segment */
-    int id = shmget (IPC_PRIVATE, size, IPC_CREAT | 0700);
-    if (id == -1)
-    {
-        msg_Err (vout, "shared memory allocation error: %m");
-        return VLC_EGENERIC;
-    }
-
-    /* Attach the segment to VLC */
-    shm = shmat (id, NULL, 0 /* read/write */);
-    if (shm == SHM_ERR)
-    {
-        msg_Err (vout, "shared memory attachment error: %m");
-        shmctl (id, IPC_RMID, 0);
-        return VLC_EGENERIC;
-    }
-
-    xcb_shm_seg_t segment;
-    if (p_sys->shm)
-    {
-        /* Attach the segment to X */
-        xcb_void_cookie_t ck;
-        segment = xcb_generate_id (p_sys->conn);
-        ck = xcb_shm_attach_checked (p_sys->conn, segment, id, 1);
-
-        if (CheckError (vout, "shared memory server-side error", ck))
-        {
-            msg_Info (vout, "using buggy X11 server - SSH proxying?");
-            segment = 0;
-        }
-    }
-    else
-        segment = 0;
-
-    shmctl (id, IPC_RMID, 0);
-    pic->p_sys = (void *)(uintptr_t)segment;
-    pic->p->p_pixels = shm;
-    pic->i_status = DESTROYED_PICTURE;
-    pic->i_type = DIRECT_PICTURE;
-    return VLC_SUCCESS;
-}
-
-
-/**
- * Release picture private data
- */
-static void PictureDeinit (vout_thread_t *vout, picture_t *pic)
-{
-    xcb_shm_seg_t segment = (uintptr_t)pic->p_sys;
-
-    if (segment != 0)
-        xcb_shm_detach (vout->p_sys->conn, segment);
-    shmdt (pic->p->p_pixels);
-}
 
 /**
  * Allocate drawable window and picture buffers.
@@ -414,7 +343,7 @@ static int Init (vout_thread_t *vout)
             break;
         if (pic->i_status != FREE_PICTURE)
             continue;
-        if (PictureInit (vout, pic))
+        if (PictureInit (vout, pic, p_sys->shm ? p_sys->conn : NULL))
             break;
         PP_OUTPUTPICTURE[I_OUTPUTPICTURES++] = pic;
     }
@@ -428,7 +357,7 @@ static int Init (vout_thread_t *vout)
 static void Deinit (vout_thread_t *vout)
 {
     for (int i = 0; i < I_OUTPUTPICTURES; i++)
-        PictureDeinit (vout, PP_OUTPUTPICTURE[i]);
+        PictureDeinit (PP_OUTPUTPICTURE[i], vout->p_sys->conn);
 }
 
 /**
index d6c4b8831ee5a3ede69aa7ec6c04c0a4a083daa5..113824b9d59e66ee233c74a77e4d8365c0bc8f24 100644 (file)
@@ -45,3 +45,5 @@ struct vout_window_t *GetWindow (vout_thread_t *obj,
                                  bool *restrict pshm);
 int GetWindowSize (struct vout_window_t *wnd, xcb_connection_t *conn,
                    unsigned *restrict width, unsigned *restrict height);
+int PictureInit (vout_thread_t *vout, picture_t *pic, xcb_connection_t *conn);
+void PictureDeinit (picture_t *pic, xcb_connection_t *conn);