Commit 06f4977c authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

screen_xcb: use timer, simplify earlier commit

parent 1b4cfa96
...@@ -91,7 +91,7 @@ vlc_module_end () ...@@ -91,7 +91,7 @@ vlc_module_end ()
/* /*
* Local prototypes * Local prototypes
*/ */
static void *Thread (void *); static void Demux (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
...@@ -107,9 +107,8 @@ struct demux_sys_t ...@@ -107,9 +107,8 @@ struct demux_sys_t
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: */ /* Timer does not use this, only input threa: */
vlc_thread_t thread; vlc_timer_t timer;
bool running;
}; };
/** /**
...@@ -123,7 +122,6 @@ static int Open (vlc_object_t *obj) ...@@ -123,7 +122,6 @@ 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");
...@@ -245,9 +243,9 @@ static int Open (vlc_object_t *obj) ...@@ -245,9 +243,9 @@ 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)) if (vlc_timer_create (&p_sys->timer, Demux, demux))
goto error; goto error;
p_sys->running = true; vlc_timer_schedule (&p_sys->timer, false, 1, p_sys->interval);
/* Initializes demux */ /* Initializes demux */
demux->pf_demux = NULL; demux->pf_demux = NULL;
...@@ -255,7 +253,8 @@ static int Open (vlc_object_t *obj) ...@@ -255,7 +253,8 @@ static int Open (vlc_object_t *obj)
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:
Close (obj); xcb_disconnect (p_sys->conn);
free (p_sys);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -268,11 +267,7 @@ static void Close (vlc_object_t *obj) ...@@ -268,11 +267,7 @@ 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_timer_destroy (&p_sys->timer);
{
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);
} }
...@@ -322,22 +317,13 @@ static int Control (demux_t *demux, int query, va_list args) ...@@ -322,22 +317,13 @@ static int Control (demux_t *demux, int query, va_list args)
{ {
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_timer_schedule (&p_sys->timer, false,
{ pausing ? 0 : 1, p_sys->interval);
vlc_cancel (p_sys->thread);
vlc_join (p_sys->thread, NULL);
}
p_sys->running = !pausing;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -358,18 +344,11 @@ static int Control (demux_t *demux, int query, va_list args) ...@@ -358,18 +344,11 @@ static int Control (demux_t *demux, int query, va_list args)
/** /**
* Processing callback * Processing callback
*/ */
static void Demux (demux_t *demux) static void Demux (void *data)
{ {
demux_t *demux = data;
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;
mtime_t now = mdate ();
if (p_sys->pts != VLC_TS_INVALID)
mwait (p_sys->pts);
else
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);
...@@ -384,7 +363,7 @@ static void Demux (demux_t *demux) ...@@ -384,7 +363,7 @@ static void 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);
goto out; return;
} }
uint16_t w = geo->width - x; uint16_t w = geo->width - x;
...@@ -410,7 +389,7 @@ static void Demux (demux_t *demux) ...@@ -410,7 +389,7 @@ static void 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)
goto out; return;
x = coords->dst_x; x = coords->dst_x;
y = coords->dst_y; y = coords->dst_y;
free (coords); free (coords);
...@@ -418,31 +397,26 @@ static void Demux (demux_t *demux) ...@@ -418,31 +397,26 @@ static void Demux (demux_t *demux)
/* Capture screen */ /* Capture screen */
if (p_sys->es == NULL) if (p_sys->es == NULL)
goto out; return;
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)
goto out; return;
/* 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)
goto out; return;
block->i_pts = block->i_dts = now;
if (p_sys->pts == VLC_TS_INVALID)
p_sys->pts = mdate ();
block->i_pts = block->i_dts = p_sys->pts;
es_out_Control (demux->out, ES_OUT_SET_PCR, now); es_out_Control (demux->out, ES_OUT_SET_PCR, p_sys->pts);
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;
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