diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c index a78f8fbb3b..6a7218ae47 100755 --- a/ext/wayland/gstwaylandsink.c +++ b/ext/wayland/gstwaylandsink.c @@ -103,13 +103,10 @@ static void gst_wayland_buffer_destroy (GstWaylandSink * sink, GstWlBuffer * buffer); static int event_mask_update (uint32_t mask, void *data); -static void sync_callback (void *data); static struct display *create_display (void); static void display_handle_global (struct wl_display *display, uint32_t id, const char *interface, uint32_t version, void *data); -static void compositor_handle_visual (void *data, - struct wl_compositor *compositor, uint32_t id, uint32_t token); -static void redraw (struct wl_surface *surface, void *data, uint32_t time); +static void redraw (void *data, struct wl_callback *callback, uint32_t time); static struct window *create_window (GstWaylandSink * sink, struct display *display, int width, int height); @@ -199,11 +196,9 @@ static void gst_wayland_sink_class_init (GstWaylandSinkClass * klass) { GObjectClass *gobject_class; - GstElementClass *gstelement_class; GstBaseSinkClass *gstbasesink_class; gobject_class = (GObjectClass *) klass; - gstelement_class = (GstElementClass *) klass; gstbasesink_class = (GstBaseSinkClass *) klass; gobject_class->set_property = gst_wayland_sink_set_property; @@ -322,18 +317,6 @@ event_mask_update (uint32_t mask, void *data) return 0; } -static void -sync_callback (void *data) -{ - int *done = data; - - *done = 1; -} - -static const struct wl_compositor_listener compositor_listener = { - compositor_handle_visual, -}; - static void display_handle_global (struct wl_display *display, uint32_t id, const char *interface, uint32_t version, void *data) @@ -341,12 +324,11 @@ display_handle_global (struct wl_display *display, uint32_t id, struct display *d = data; if (strcmp (interface, "wl_compositor") == 0) { - d->compositor = wl_compositor_create (display, id, 1); - wl_compositor_add_listener (d->compositor, &compositor_listener, d); + d->compositor = wl_display_bind (display, id, &wl_compositor_interface); } else if (strcmp (interface, "wl_shell") == 0) { - d->shell = wl_shell_create (display, id, 1); + d->shell = wl_display_bind (display, id, &wl_shell_interface); } else if (strcmp (interface, "wl_shm") == 0) { - d->shm = wl_shm_create (display, id, 1); + d->shm = wl_display_bind (display, id, &wl_shm_interface); } } @@ -355,10 +337,10 @@ static struct display * create_display (void) { struct display *display; - int done; display = malloc (sizeof *display); display->display = wl_display_connect (NULL); + assert (display->display); wl_display_add_global_listener (display->display, display_handle_global, display); @@ -367,12 +349,6 @@ create_display (void) wl_display_get_fd (display->display, event_mask_update, display); - wl_display_sync_callback (display->display, sync_callback, &done); - - while (!display->xrgb_visual) { - wl_display_iterate (display->display, display->mask); - } - return display; } @@ -421,8 +397,7 @@ wayland_buffer_create (GstWaylandSink * sink) } wbuffer->wbuffer = wl_shm_create_buffer (sink->display->shm, fd, - sink->video_width, sink->video_height, stride, - sink->display->xrgb_visual); + sink->video_width, sink->video_height, stride, WL_SHM_FORMAT_XRGB32); close (fd); @@ -547,21 +522,10 @@ gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps) return TRUE; } -static void -compositor_handle_visual (void *data, - struct wl_compositor *compositor, uint32_t id, uint32_t token) -{ - struct display *d = data; - - switch (token) { - case WL_COMPOSITOR_VISUAL_XRGB32: - d->xrgb_visual = wl_visual_create (d->display, id, 1); - break; - } -} +static const struct wl_callback_listener frame_listener; static void -redraw (struct wl_surface *surface, void *data, uint32_t time) +redraw (void *data, struct wl_callback *callback, uint32_t time) { GstWaylandSink *sink = (GstWaylandSink *) data; @@ -627,6 +591,7 @@ gst_wayland_sink_preroll (GstBaseSink * bsink, GstBuffer * buffer) return gst_wayland_sink_render (bsink, buffer); } + static GstFlowReturn gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer) { @@ -692,20 +657,25 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer) wl_surface_damage (sink->window->surface, 0, 0, res.w, res.h); - wl_display_frame_callback (sink->display->display, - sink->window->surface, redraw, sink); + if (sink->callback) + wl_callback_destroy (sink->callback); + sink->callback = wl_surface_frame (sink->window->surface); + wl_callback_add_listener (sink->callback, &frame_listener, sink); wl_display_iterate (sink->display->display, sink->display->mask); } else { GST_LOG_OBJECT (sink, "Waiting to get the signal from compositor to render the next frame.."); - g_usleep (50000); sink->render_finish = TRUE; } return GST_FLOW_OK; } +static const struct wl_callback_listener frame_listener = { + redraw +}; + static gboolean plugin_init (GstPlugin * plugin) { diff --git a/ext/wayland/gstwaylandsink.h b/ext/wayland/gstwaylandsink.h index 75c5a9ac8a..678b8cfa22 100755 --- a/ext/wayland/gstwaylandsink.h +++ b/ext/wayland/gstwaylandsink.h @@ -43,7 +43,6 @@ struct display { struct wl_display *display; - struct wl_visual *xrgb_visual; struct wl_compositor *compositor; struct wl_shell *shell; struct wl_shm *shm; @@ -84,6 +83,7 @@ struct _GstWaylandSink struct display *display; struct window *window; + struct wl_callback *callback; GMutex *pool_lock; GSList *buffer_pool;