From 26ce7f2344f0b5a88d5390586be526d46df794dc Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Wed, 26 Feb 2014 18:35:29 +0200 Subject: [PATCH] waylandsink: handle the list of supported formats properly enum wl_shm_format is not a flags enum, as it may have been in the past, so multiple formats cannot be stored in a bitfield. Use an array instead. --- ext/wayland/gstwaylandsink.c | 30 ++++++++++++++++++++++-------- ext/wayland/gstwaylandsink.h | 1 - ext/wayland/wldisplay.c | 4 +++- ext/wayland/wldisplay.h | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c index 2e5ac6e..cf90509 100644 --- a/ext/wayland/gstwaylandsink.c +++ b/ext/wayland/gstwaylandsink.c @@ -219,29 +219,37 @@ gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps) GstWaylandSink *sink; GstBufferPool *newpool; GstVideoInfo info; + enum wl_shm_format format; + GArray *formats; + gint i; GstStructure *structure; static GstAllocationParams params = { 0, 0, 0, 15, }; - guint size; sink = GST_WAYLAND_SINK (bsink); GST_LOG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps); + /* extract info from caps */ if (!gst_video_info_from_caps (&info, caps)) goto invalid_format; - if (!gst_wayland_sink_format_from_caps (&sink->format, caps)) + format = gst_video_format_to_wayland_format (GST_VIDEO_INFO_FORMAT (&info)); + if (format == -1) goto invalid_format; - if (!(sink->display->formats & (1 << sink->format))) { - GST_DEBUG_OBJECT (sink, "%s not available", - gst_wayland_format_to_string (sink->format)); - return FALSE; + /* verify we support the requested format */ + formats = sink->display->formats; + for (i = 0; i < formats->len; i++) { + if (g_array_index (formats, uint32_t, i) == format) + break; } + if (i >= formats->len) + goto unsupported_format; + + /* store the video size */ sink->video_width = info.width; sink->video_height = info.height; - size = info.size; /* create a new pool for the new configuration */ newpool = gst_wayland_buffer_pool_new (sink->display); @@ -252,7 +260,7 @@ gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps) } structure = gst_buffer_pool_get_config (newpool); - gst_buffer_pool_config_set_params (structure, caps, size, 2, 0); + gst_buffer_pool_config_set_params (structure, caps, info.size, 2, 0); gst_buffer_pool_config_set_allocator (structure, NULL, ¶ms); if (!gst_buffer_pool_set_config (newpool, structure)) goto config_failed; @@ -268,6 +276,12 @@ invalid_format: "Could not locate image format from caps %" GST_PTR_FORMAT, caps); return FALSE; } +unsupported_format: + { + GST_DEBUG_OBJECT (sink, "Format %s is not available on the display", + gst_wayland_format_to_string (format)); + return FALSE; + } config_failed: { GST_DEBUG_OBJECT (bsink, "failed setting config"); diff --git a/ext/wayland/gstwaylandsink.h b/ext/wayland/gstwaylandsink.h index c7b0694..9b7091f 100644 --- a/ext/wayland/gstwaylandsink.h +++ b/ext/wayland/gstwaylandsink.h @@ -58,7 +58,6 @@ struct _GstWaylandSink gint video_width; gint video_height; - enum wl_shm_format format; gchar *display_name; }; diff --git a/ext/wayland/wldisplay.c b/ext/wayland/wldisplay.c index 5445251..590fc98 100644 --- a/ext/wayland/wldisplay.c +++ b/ext/wayland/wldisplay.c @@ -43,6 +43,7 @@ gst_wl_display_class_init (GstWlDisplayClass * klass) static void gst_wl_display_init (GstWlDisplay * self) { + self->formats = g_array_new (FALSE, FALSE, sizeof (uint32_t)); self->wl_fd_poll = gst_poll_new (TRUE); } @@ -56,6 +57,7 @@ gst_wl_display_finalize (GObject * gobject) if (self->thread) g_thread_join (self->thread); + g_array_unref (self->formats); gst_poll_free (self->wl_fd_poll); if (self->shm) @@ -117,7 +119,7 @@ shm_format (void *data, struct wl_shm *wl_shm, uint32_t format) { GstWlDisplay *self = data; - self->formats |= (1 << format); + g_array_append_val (self->formats, format); } static const struct wl_shm_listener shm_listener = { diff --git a/ext/wayland/wldisplay.h b/ext/wayland/wldisplay.h index 149b921..dbe49d9 100644 --- a/ext/wayland/wldisplay.h +++ b/ext/wayland/wldisplay.h @@ -47,7 +47,7 @@ struct _GstWlDisplay struct wl_compositor *compositor; struct wl_shell *shell; struct wl_shm *shm; - guint32 formats; + GArray *formats; /* private */ gboolean own_display; -- 2.7.4