]> git.sesse.net Git - vlc/blobdiff - modules/video_output/xcb/xvideo.c
Made XCB xvideo independant of VOUT_MAX_PICTURES.
[vlc] / modules / video_output / xcb / xvideo.c
index 0cd0576c8b4fe76fed2b3124241123cb79f6f217..ecb58ba2e0352d1f42c4795c20219ecce0fa29a7 100644 (file)
@@ -71,7 +71,7 @@ vlc_module_begin ()
     add_shortcut ("xvideo")
 vlc_module_end ()
 
-#define MAX_PICTURES (VOUT_MAX_PICTURES)
+#define MAX_PICTURES (128)
 
 struct vout_display_sys_t
 {
@@ -86,6 +86,7 @@ struct vout_display_sys_t
     uint16_t width;      /* display width */
     uint16_t height;     /* display height */
     uint32_t data_size;  /* picture byte size (for non-SHM) */
+    bool     swap_uv;    /* U/V pointer must be swapped in a picture */
     bool shm;            /* whether to use MIT-SHM */
     bool visible;        /* whether it makes sense to draw at all */
 
@@ -297,6 +298,9 @@ static int Open (vlc_object_t *obj)
 {
     vout_display_t *vd = (vout_display_t *)obj;
     vout_display_sys_t *p_sys = malloc (sizeof (*p_sys));
+
+    if (!var_CreateGetBool (obj, "overlay"))
+        return VLC_EGENERIC;
     if (p_sys == NULL)
         return VLC_ENOMEM;
 
@@ -316,6 +320,7 @@ static int Open (vlc_object_t *obj)
     p_sys->conn = conn;
     p_sys->att = NULL;
     p_sys->pool = NULL;
+    p_sys->swap_uv = false;
 
     if (!CheckXVideo (vd, conn))
     {
@@ -328,7 +333,7 @@ static int Open (vlc_object_t *obj)
     /* Cache adaptors infos */
     xcb_xv_query_adaptors_reply_t *adaptors =
         xcb_xv_query_adaptors_reply (conn,
-            xcb_xv_query_adaptors (conn, p_sys->embed->xid), NULL);
+            xcb_xv_query_adaptors (conn, p_sys->embed->handle.xid), NULL);
     if (adaptors == NULL)
         goto error;
 
@@ -395,7 +400,10 @@ static int Open (vlc_object_t *obj)
             if (xfmt != NULL)
             {
                 p_sys->id = xfmt->id;
-                fmt.i_chroma = chroma;
+                p_sys->swap_uv = vlc_fourcc_AreUVPlanesSwapped (fmt.i_chroma,
+                                                                chroma);
+                if (!p_sys->swap_uv)
+                    fmt.i_chroma = chroma;
                 if (xfmt->type == XCB_XV_IMAGE_FORMAT_INFO_TYPE_RGB)
                 {
                     fmt.i_rmask = xfmt->red_mask;
@@ -452,7 +460,7 @@ static int Open (vlc_object_t *obj)
             xcb_void_cookie_t c;
 
             c = xcb_create_window_checked (conn, f->depth, p_sys->window,
-                 p_sys->embed->xid, 0, 0, 1, 1, 0,
+                 p_sys->embed->handle.xid, 0, 0, 1, 1, 0,
                  XCB_WINDOW_CLASS_INPUT_OUTPUT, f->visual,
                  XCB_CW_EVENT_MASK, &mask);
 
@@ -465,6 +473,7 @@ static int Open (vlc_object_t *obj)
             }
         }
         xcb_xv_ungrab_port (conn, p_sys->port, XCB_CURRENT_TIME);
+        msg_Dbg (vd, "no usable X11 visual");
         continue; /* No workable XVideo format (visual/depth) */
 
     created_window:
@@ -523,10 +532,13 @@ static int Open (vlc_object_t *obj)
     vd->manage = Manage;
 
     /* */
-    vout_display_SendEventFullscreen (vd, false);
+    bool is_fullscreen = vd->cfg->is_fullscreen;
+    if (is_fullscreen && vout_window_SetFullScreen (p_sys->embed, true))
+        is_fullscreen = false;
+    vout_display_SendEventFullscreen (vd, is_fullscreen);
     unsigned width, height;
     if (!GetWindowSize (p_sys->embed, conn, &width, &height))
-        vout_display_SendEventDisplaySize (vd, width, height, false);
+        vout_display_SendEventDisplaySize (vd, width, height, is_fullscreen);
 
     return VLC_SUCCESS;
 
@@ -557,6 +569,11 @@ static void Close (vlc_object_t *obj)
         picture_pool_Delete (p_sys->pool);
     }
 
+    /* show the default cursor */
+    xcb_change_window_attributes (p_sys->conn, p_sys->embed->handle.xid, XCB_CW_CURSOR,
+                                  &(uint32_t) { XCB_CURSOR_NONE });
+    xcb_flush (p_sys->conn);
+
     free (p_sys->att);
     xcb_disconnect (p_sys->conn);
     vout_display_DeleteWindow (vd, p_sys->embed);
@@ -569,31 +586,31 @@ static void Close (vlc_object_t *obj)
 static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
 {
     vout_display_sys_t *p_sys = vd->sys;
-    (void)requested_count;
 
     if (!p_sys->pool)
     {
-        picture_t *pic = picture_New (vd->fmt.i_chroma, p_sys->att->width,
-                                      p_sys->att->height, 0, 1);
-        if (!pic)
-            return NULL;
-
         memset (p_sys->resource, 0, sizeof(p_sys->resource));
 
+        const uint32_t *pitches =
+            xcb_xv_query_image_attributes_pitches (p_sys->att);
         const uint32_t *offsets =
             xcb_xv_query_image_attributes_offsets (p_sys->att);
         p_sys->data_size = p_sys->att->data_size;
 
         unsigned count;
         picture_t *pic_array[MAX_PICTURES];
-        for (count = 0; count < MAX_PICTURES; count++)
+        for (count = 0; count < requested_count; count++)
         {
+            if (count >= MAX_PICTURES)
+                break;
             picture_resource_t *res = &p_sys->resource[count];
 
-            for (int i = 0; i < pic->i_planes; i++)
+            for (int i = 0; i < __MIN (p_sys->att->num_planes, PICTURE_PLANE_MAX); i++)
             {
-                res->p[i].i_lines = pic->p[i].i_lines; /* FIXME seems wrong*/
-                res->p[i].i_pitch = pic->p[i].i_pitch;
+                res->p[i].i_lines =
+                    ((i + 1 < p_sys->att->num_planes ? offsets[i+1] :
+                                                       p_sys->data_size) - offsets[i]) / pitches[i];
+                res->p[i].i_pitch = pitches[i];
             }
             if (PictureResourceAlloc (vd, res, p_sys->att->data_size,
                                       p_sys->conn, p_sys->shm))
@@ -601,9 +618,9 @@ static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
 
             /* Allocate further planes as specified by XVideo */
             /* We assume that offsets[0] is zero */
-            for (int i = 1; i < pic->i_planes; i++)
+            for (int i = 1; i < __MIN (p_sys->att->num_planes, PICTURE_PLANE_MAX); i++)
                 res->p[i].p_pixels = res->p[0].p_pixels + offsets[i];
-            if (vd->fmt.i_chroma == VLC_CODEC_YV12)
+            if (p_sys->swap_uv)
             {   /* YVU: swap U and V planes */
                 uint8_t *buf = res->p[2].p_pixels;
                 res->p[2].p_pixels = res->p[1].p_pixels;
@@ -618,7 +635,6 @@ static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
                 break;
             }
         }
-        picture_Release (pic);
 
         if (count == 0)
             return NULL;
@@ -739,14 +755,13 @@ static int Control (vout_display_t *vd, int query, va_list ap)
     case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
     {
         unsigned state = va_arg (ap, unsigned);
-        bool b_on_top = (state & VOUT_WINDOW_STATE_ABOVE) != 0;
-        return vout_window_SetState (p_sys->embed, b_on_top);
+        return vout_window_SetState (p_sys->embed, state);
     }
 
     /* Hide the mouse. It will be send when
      * vout_display_t::info.b_hide_mouse is false */
     case VOUT_DISPLAY_HIDE_MOUSE:
-        xcb_change_window_attributes (p_sys->conn, p_sys->embed->xid,
+        xcb_change_window_attributes (p_sys->conn, p_sys->embed->handle.xid,
                                   XCB_CW_CURSOR, &(uint32_t){ p_sys->cursor });
         return VLC_SUCCESS;
     case VOUT_DISPLAY_RESET_PICTURES: