Commit 81d41ccd authored by Jean-Paul Saman's avatar Jean-Paul Saman

codec/avcodec/vaapi: use vout_window_* returned handle to X-Window.

parent a844bbbb
......@@ -32,6 +32,7 @@
#include <vlc_plugin.h>
#include <vlc_picture.h>
#include <vlc_vout_display.h>
#include <vlc_vout_window.h>
#include <vlc_picture_pool.h>
#ifdef HAVE_AVCODEC_VAAPI
......@@ -52,30 +53,21 @@
#include <X11/Xutil.h>
typedef struct vlc_vaapi_x11_window_t
{
int screen;
Visual *visual;
Window root;
Window window;
} vlc_vaapi_x11_window_t;
struct vout_display_sys_t
{
vlc_va_conn_t *conn;
vout_window_t *embed; /* VLC window (when windowed) */
vlc_vaapi_x11_window_t x11;
bool visible; /* whether to draw */
vout_window_t *embed;
picture_pool_t *pool; /* picture pool */
unsigned int i_display_order;
bool visible; /* whether to draw */
};
static picture_pool_t *Pool (vout_display_t *, unsigned);
static void DisplayPicture (vout_display_t *, picture_t *, subpicture_t *);
static int Control (vout_display_t *, int, va_list);
static void Manage (vout_display_t *);
/* */
static int FindVAFourCC(vout_display_t *vd)
......@@ -119,62 +111,6 @@ error:
return VLC_EGENERIC;
}
/* X11 Window */
static int CreateWindow(vout_display_t *vd)
{
vout_display_sys_t *sys = (vout_display_sys_t *) vd->sys;
sys->x11.screen = DefaultScreen(sys->conn->p_display_x11);
sys->x11.visual = DefaultVisual(sys->conn->p_display_x11, sys->x11.screen);
sys->x11.root = RootWindow(sys->conn->p_display_x11, sys->x11.screen);
XWindowAttributes attr;
XGetWindowAttributes(sys->conn->p_display_x11, sys->x11.root, &attr);
uint32_t depth = attr.depth;
if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
depth = 24;
XVisualInfo vi;
XVisualInfo *vi_info = &vi;
XMatchVisualInfo(sys->conn->p_display_x11, sys->x11.screen, depth, TrueColor, vi_info);
XSetWindowAttributes xswa;
uint32_t xswa_mask;
xswa_mask = CWBorderPixel | CWBackPixel;
xswa.border_pixel = BlackPixel(sys->conn->p_display_x11, sys->x11.screen);
xswa.background_pixel = WhitePixel(sys->conn->p_display_x11, sys->x11.screen);
msg_Info(vd, "Creating X11 window with: x=%d,y=%d - w=%d,h=%d",
vd->source.i_y_offset, vd->source.i_x_offset,
vd->cfg->display.width, vd->cfg->display.height);
sys->x11.window = XCreateWindow(sys->conn->p_display_x11, sys->x11.root,
vd->source.i_y_offset, vd->source.i_x_offset,
vd->cfg->display.width, vd->cfg->display.height,
0, depth,
InputOutput, vi_info->visual, xswa_mask, &xswa);
if (sys->x11.window == None)
return VLC_EGENERIC;
int map = XMapWindow(sys->conn->p_display_x11, sys->x11.window);
if (map == BadWindow)
return VLC_EGENERIC;
return VLC_SUCCESS;
}
static void DestroyWindow(vout_display_t *vd)
{
vout_display_sys_t *sys = (vout_display_sys_t *) vd->sys;
if (sys->x11.window != None)
{
XUnmapWindow(sys->conn->p_display_x11, sys->x11.window);
//x11_wait_event(sys->conn->p_display_x11, sys->x11.window, UnmapNotify);
XDestroyWindow(sys->conn->p_display_x11, sys->x11.window);
sys->x11.window = None;
}
}
static vout_window_t *MakeWindow (vout_display_t *vd)
{
vout_window_cfg_t wnd_cfg;
......@@ -211,6 +147,7 @@ int OpenVaapiX11 (vlc_object_t *obj)
sys->conn = NULL;
sys->pool = NULL;
sys->visible = false;
sys->i_display_order = 0;
sys->embed = MakeWindow(vd);
if (unlikely(sys->embed == NULL))
......@@ -224,9 +161,6 @@ int OpenVaapiX11 (vlc_object_t *obj)
if (FindVAFourCC(vd) != VLC_SUCCESS)
goto error;
if (CreateWindow(vd) != VLC_SUCCESS)
goto error;
msg_Dbg(vd, "using VAAPI X11 window (version %d.%d)",
sys->conn->i_version_major, sys->conn->i_version_minor);
......@@ -268,8 +202,6 @@ void CloseVaapiX11 (vlc_object_t *obj)
if (sys->conn)
{
DestroyWindow(vd);
if (sys->conn->p_display_x11)
{
XFlush(sys->conn->p_display_x11);
......@@ -342,30 +274,11 @@ static int Control (vout_display_t *vd, int query, va_list ap)
cfg->display.width, cfg->display.height))
return VLC_EGENERIC;
vout_display_place_t place;
vout_display_PlacePicture (&place, source, cfg, false);
return VLC_SUCCESS;
}
case VOUT_DISPLAY_RESET_PICTURES:
{
#if 0
if (sys->pool)
{
picture_pool_Delete (sys->pool);
sys->pool = NULL;
}
#endif
vout_display_place_t place;
vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
vd->fmt.i_width = vd->source.i_width * place.width / vd->source.i_visible_width;
vd->fmt.i_height = vd->source.i_height * place.height / vd->source.i_visible_height;
vd->fmt.i_visible_width = place.width;
vd->fmt.i_visible_height = place.height;
vd->fmt.i_x_offset = vd->source.i_x_offset * place.width / vd->source.i_visible_width;
vd->fmt.i_y_offset = vd->source.i_y_offset * place.height / vd->source.i_visible_height;
assert(0);
return VLC_SUCCESS;
}
......@@ -381,29 +294,18 @@ static int Control (vout_display_t *vd, int query, va_list ap)
}
}
static void Manage (vout_display_t *vd)
{
VLC_UNUSED(vd);
#if 0
vout_display_sys_t *sys = vd->sys;
xcb_connection_t *conn = XGetXCBConnection (sys->display);
ManageEvent (vd, conn, &sys->visible);
#endif
}
static void PictureRelease(picture_t *pic)
{
assert(pic);
assert(sizeof(pic->p_sys) == sizeof(picture_sys_t));
if( pic->p_sys->surface )
if (pic->p_sys->surface)
{
vlc_mutex_lock(&pic->p_sys->surface->lock);
pic->p_sys->surface->i_refcount--;
assert(pic->p_sys->surface->i_refcount == 0);
assert(pic->p_sys->surface->i_refcount >= 0);
vlc_mutex_unlock(&pic->p_sys->surface->lock);
pic->p_sys->surface = NULL;
pic->p_sys->surface = NULL; /* FIXME: needed ? */
}
}
......@@ -418,14 +320,6 @@ static void DisplayPicture(vout_display_t *vd, picture_t *pic, subpicture_t *sub
/* FIXME: blend subpicture into VAAPI structure */
}
#endif
vout_display_place_t place;
vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
VARectangle va_rec = { .x = place.x, .y = place.y,
.width = place.width, .height = place.height };
unsigned int flags = VA_FRAME_PICTURE;
if (!pic->b_progressive)
flags = pic->b_top_field_first ? VA_TOP_FIELD : VA_BOTTOM_FIELD;
assert(pic->p_sys);
if (pic->p_sys->surface == NULL)
......@@ -434,30 +328,53 @@ static void DisplayPicture(vout_display_t *vd, picture_t *pic, subpicture_t *sub
picture_Release(pic);
return;
}
if (pic->p_sys->surface->i_refcount > 1)
unsigned int i_order = (sys->i_display_order > 0) ?
sys->i_display_order++ : pic->p_sys->surface->i_order;
if (i_order != pic->p_sys->surface->i_order)
{
/* Reset picture */
vlc_mutex_lock(&pic->p_sys->surface->lock);
msg_Err(vd, "Reclaimed picture - %d (%p)", pic->p_sys->surface->i_id, pic);
pic->p_sys->surface->i_refcount--;
assert(pic->p_sys->surface->i_refcount < 3);
msg_Err(vd, "Reclaimed picture - id=%d, order=%d, refcount=%d (%p)",
pic->p_sys->surface->i_id, pic->p_sys->surface->i_order,
pic->p_sys->surface->i_refcount, pic);
if (pic->p_sys->surface->i_refcount > 1)
pic->p_sys->surface->i_refcount = 1;
vlc_mutex_unlock(&pic->p_sys->surface->lock);
pic->p_sys->surface = NULL;
picture_Release(pic);
return;
}
vout_display_place_t place;
vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
VASurfaceID i_surface_id = pic->p_sys->surface->i_id;
assert(sys->x11.window != None);
VAStatus status = vaPutSurface(sys->conn->p_display,
i_surface_id,
sys->x11.window,
sys->embed->handle.xid,
pic->format.i_y_offset, pic->format.i_x_offset,
pic->format.i_visible_width, pic->format.i_visible_height,
vd->source.i_y_offset, vd->source.i_x_offset,
vd->fmt.i_visible_width, vd->fmt.i_visible_height,
NULL, 0, //&va_rec, 1, /* client supplied destination clip list, cliplist count */
flags);
place.y, place.x, place.width, place.height,
NULL, 0, /* clipping */
/* NOTE: vaCreateContext() specifies VA_PROGRESSIVE */
#if 0
VA_FRAME_PICTURE);
#else
pic->b_progressive ? VA_FRAME_PICTURE :
(pic->b_top_field_first ? VA_TOP_FIELD : VA_BOTTOM_FIELD));
#endif
if (status != VA_STATUS_SUCCESS)
msg_Err(vd, "failed displaying picture (id=%d) %d", i_surface_id, status);
PictureRelease(pic); /* Release pic->p_sys->surface */
#if 0
else
msg_Info(vd, "displaying picture (id=%d, order=%d, refcount=%d)",
pic->p_sys->surface->i_id, pic->p_sys->surface->i_order,
pic->p_sys->surface->i_refcount);
#endif
if ((status != VA_STATUS_ERROR_INVALID_SURFACE) &&
(status != VA_STATUS_ERROR_INVALID_DISPLAY))
PictureRelease(pic);
picture_Release(pic);
}
......@@ -490,8 +407,8 @@ static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
break;
}
pic_array[count] = pic;
pic_array[count]->b_progressive = true;
pic_array[count]->p_sys = sys;
//pic_array[count]->pf_release = PictureRelease;
}
if (count == 0)
......@@ -502,7 +419,6 @@ static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
goto error;
free(pic_array);
XFlush(sys->conn->p_display_x11);
return sys->pool;
error:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment