Commit 02c8a569 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

screen_xcb: run in a thread - remove input control latency

parent 075a0342
...@@ -91,11 +91,14 @@ vlc_module_end () ...@@ -91,11 +91,14 @@ vlc_module_end ()
/* /*
* Local prototypes * Local prototypes
*/ */
static int Demux (demux_t *); static void *Thread (void *);
static int Control (demux_t *, int, va_list); static int Control (demux_t *, int, va_list);
struct demux_sys_t struct demux_sys_t
{ {
/* WARNING: Control() is concurrent with Thread()/Demux().
* Currently, the thread owns everything in read/write, if it exists.
* We destroy it on pause, and re-create it on resume. */
xcb_connection_t *conn; xcb_connection_t *conn;
es_out_id_t *es; es_out_id_t *es;
es_format_t fmt; es_format_t fmt;
...@@ -103,6 +106,10 @@ struct demux_sys_t ...@@ -103,6 +106,10 @@ struct demux_sys_t
xcb_window_t root, window; xcb_window_t root, window;
int16_t x, y; int16_t x, y;
uint16_t w, h; uint16_t w, h;
/* Thread does not use. This is for input thread only: */
vlc_thread_t thread;
bool running;
}; };
/** /**
...@@ -116,6 +123,7 @@ static int Open (vlc_object_t *obj) ...@@ -116,6 +123,7 @@ static int Open (vlc_object_t *obj)
if (p_sys == NULL) if (p_sys == NULL)
return VLC_ENOMEM; return VLC_ENOMEM;
demux->p_sys = p_sys; demux->p_sys = p_sys;
p_sys->running = false;
/* Connect to X server */ /* Connect to X server */
char *display = var_CreateGetNonEmptyString (obj, "x11-display"); char *display = var_CreateGetNonEmptyString (obj, "x11-display");
...@@ -237,9 +245,12 @@ static int Open (vlc_object_t *obj) ...@@ -237,9 +245,12 @@ static int Open (vlc_object_t *obj)
p_sys->fmt.video.i_frame_rate_base = 1000; p_sys->fmt.video.i_frame_rate_base = 1000;
p_sys->es = NULL; p_sys->es = NULL;
p_sys->pts = VLC_TS_INVALID; p_sys->pts = VLC_TS_INVALID;
if (vlc_clone (&p_sys->thread, Thread, demux, VLC_THREAD_PRIORITY_INPUT))
goto error;
p_sys->running = true;
/* Initializes demux */ /* Initializes demux */
demux->pf_demux = Demux; demux->pf_demux = NULL;
demux->pf_control = Control; demux->pf_control = Control;
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -257,6 +268,11 @@ static void Close (vlc_object_t *obj) ...@@ -257,6 +268,11 @@ static void Close (vlc_object_t *obj)
demux_t *demux = (demux_t *)obj; demux_t *demux = (demux_t *)obj;
demux_sys_t *p_sys = demux->p_sys; demux_sys_t *p_sys = demux->p_sys;
if (p_sys->running)
{
vlc_cancel (p_sys->thread);
vlc_join (p_sys->thread, NULL);
}
xcb_disconnect (p_sys->conn); xcb_disconnect (p_sys->conn);
free (p_sys); free (p_sys);
} }
...@@ -305,11 +321,23 @@ static int Control (demux_t *demux, int query, va_list args) ...@@ -305,11 +321,23 @@ static int Control (demux_t *demux, int query, va_list args)
case DEMUX_SET_PAUSE_STATE: case DEMUX_SET_PAUSE_STATE:
{ {
bool pausing = va_arg (args, int); bool pausing = va_arg (args, int);
if (pausing != p_sys->running)
return VLC_SUCCESS; /* No-op. FIXME: is it needed? */
if (!pausing) if (!pausing)
{ {
p_sys->pts = VLC_TS_INVALID; p_sys->pts = VLC_TS_INVALID;
es_out_Control (demux->out, ES_OUT_RESET_PCR); es_out_Control (demux->out, ES_OUT_RESET_PCR);
if (vlc_clone (&p_sys->thread, Thread, demux,
VLC_THREAD_PRIORITY_INPUT))
return VLC_EGENERIC;
} }
else
{
vlc_cancel (p_sys->thread);
vlc_join (p_sys->thread, NULL);
}
p_sys->running = !pausing;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -330,7 +358,7 @@ static int Control (demux_t *demux, int query, va_list args) ...@@ -330,7 +358,7 @@ static int Control (demux_t *demux, int query, va_list args)
/** /**
* Processing callback * Processing callback
*/ */
static int Demux (demux_t *demux) static void Demux (demux_t *demux)
{ {
demux_sys_t *p_sys = demux->p_sys; demux_sys_t *p_sys = demux->p_sys;
xcb_connection_t *conn = p_sys->conn; xcb_connection_t *conn = p_sys->conn;
...@@ -341,6 +369,8 @@ static int Demux (demux_t *demux) ...@@ -341,6 +369,8 @@ static int Demux (demux_t *demux)
else else
p_sys->pts = now; p_sys->pts = now;
int canc = vlc_savecancel ();
/* Update capture region (if needed) */ /* Update capture region (if needed) */
xcb_get_geometry_cookie_t gc = xcb_get_geometry (conn, p_sys->window); xcb_get_geometry_cookie_t gc = xcb_get_geometry (conn, p_sys->window);
int16_t x = p_sys->x, y = p_sys->y; int16_t x = p_sys->x, y = p_sys->y;
...@@ -354,7 +384,7 @@ static int Demux (demux_t *demux) ...@@ -354,7 +384,7 @@ static int Demux (demux_t *demux)
if (geo == NULL) if (geo == NULL)
{ {
msg_Err (demux, "bad X11 drawable 0x%08"PRIx32, p_sys->window); msg_Err (demux, "bad X11 drawable 0x%08"PRIx32, p_sys->window);
return 0; goto out;
} }
uint16_t w = geo->width - x; uint16_t w = geo->width - x;
...@@ -380,7 +410,7 @@ static int Demux (demux_t *demux) ...@@ -380,7 +410,7 @@ static int Demux (demux_t *demux)
xcb_translate_coordinates_reply_t *coords = xcb_translate_coordinates_reply_t *coords =
xcb_translate_coordinates_reply (conn, tc, NULL); xcb_translate_coordinates_reply (conn, tc, NULL);
if (coords == NULL) if (coords == NULL)
return 1; goto out;
x = coords->dst_x; x = coords->dst_x;
y = coords->dst_y; y = coords->dst_y;
free (coords); free (coords);
...@@ -388,24 +418,31 @@ static int Demux (demux_t *demux) ...@@ -388,24 +418,31 @@ static int Demux (demux_t *demux)
/* Capture screen */ /* Capture screen */
if (p_sys->es == NULL) if (p_sys->es == NULL)
return 1; goto out;
xcb_get_image_reply_t *img; xcb_get_image_reply_t *img;
img = xcb_get_image_reply (conn, img = xcb_get_image_reply (conn,
xcb_get_image (conn, XCB_IMAGE_FORMAT_Z_PIXMAP, p_sys->root, xcb_get_image (conn, XCB_IMAGE_FORMAT_Z_PIXMAP, p_sys->root,
x, y, w, h, ~0), NULL); x, y, w, h, ~0), NULL);
if (img == NULL) if (img == NULL)
return 1; goto out;
/* Send block - zero copy */ /* Send block - zero copy */
block_t *block = block_heap_Alloc (img, xcb_get_image_data (img), block_t *block = block_heap_Alloc (img, xcb_get_image_data (img),
xcb_get_image_data_length (img)); xcb_get_image_data_length (img));
if (block == NULL) if (block == NULL)
return 0; goto out;
block->i_pts = block->i_dts = now; block->i_pts = block->i_dts = now;
es_out_Control (demux->out, ES_OUT_SET_PCR, now); es_out_Control (demux->out, ES_OUT_SET_PCR, now);
es_out_Send (demux->out, p_sys->es, block); es_out_Send (demux->out, p_sys->es, block);
p_sys->pts += p_sys->interval; p_sys->pts += p_sys->interval;
return 1; out:
vlc_restorecancel (canc);
}
static void *Thread (void *data)
{
for (;;)
Demux (data);
} }
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