From 737067e793ab0bda60b7ec28af9b6fa51ace4581 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Fri, 1 Dec 2017 11:59:01 -0500 Subject: [PATCH] kmssink: Add display-width/height properties This is to be used with gst_video_overlay_set_render_rectangle() so the application can calculate a rectangle that fits inside the display. The property changes are notify in a way that you can watch either notify::display-width or notify::display-height and both will be up-to-data when this is called back. Before the element is started, the size will be 0x0. https://bugzilla.gnome.org/show_bug.cgi?id=784599 --- sys/kms/gstkmssink.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/sys/kms/gstkmssink.c b/sys/kms/gstkmssink.c index 0d3fc5837a..c3c57a7f88 100644 --- a/sys/kms/gstkmssink.c +++ b/sys/kms/gstkmssink.c @@ -86,6 +86,8 @@ enum PROP_PLANE_ID, PROP_FORCE_MODESETTING, PROP_CAN_SCALE, + PROP_DISPLAY_WIDTH, + PROP_DISPLAY_HEIGHT, PROP_N }; @@ -659,8 +661,12 @@ retry_find_plane: self->render_rect.x = 0; self->render_rect.y = 0; + + GST_OBJECT_LOCK (self); self->hdisplay = self->render_rect.w = crtc->mode.hdisplay; self->vdisplay = self->render_rect.h = crtc->mode.vdisplay; + GST_OBJECT_UNLOCK (self); + self->buffer_id = crtc->buffer_id; self->mm_width = conn->mmWidth; @@ -673,6 +679,9 @@ retry_find_plane: gst_poll_add_fd (self->poll, &self->pollfd); gst_poll_fd_ctl_read (self->poll, &self->pollfd, TRUE); + g_object_notify_by_pspec (G_OBJECT (self), g_properties[PROP_DISPLAY_WIDTH]); + g_object_notify_by_pspec (G_OBJECT (self), g_properties[PROP_DISPLAY_HEIGHT]); + ret = TRUE; bail: @@ -785,6 +794,14 @@ gst_kms_sink_stop (GstBaseSink * bsink) self->fd = -1; } + GST_OBJECT_LOCK (bsink); + self->hdisplay = 0; + self->vdisplay = 0; + GST_OBJECT_UNLOCK (bsink); + + g_object_notify_by_pspec (G_OBJECT (self), g_properties[PROP_DISPLAY_WIDTH]); + g_object_notify_by_pspec (G_OBJECT (self), g_properties[PROP_DISPLAY_HEIGHT]); + return TRUE; } @@ -1596,6 +1613,16 @@ gst_kms_sink_get_property (GObject * object, guint prop_id, case PROP_CAN_SCALE: g_value_set_boolean (value, sink->can_scale); break; + case PROP_DISPLAY_WIDTH: + GST_OBJECT_LOCK (sink); + g_value_set_int (value, sink->hdisplay); + GST_OBJECT_UNLOCK (sink); + break; + case PROP_DISPLAY_HEIGHT: + GST_OBJECT_LOCK (sink); + g_value_set_int (value, sink->vdisplay); + GST_OBJECT_UNLOCK (sink); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1728,6 +1755,30 @@ gst_kms_sink_class_init (GstKMSSinkClass * klass) "User can tell kmssink if the driver can support scale", TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT); + /** + * kmssink:display-width + * + * Actual width of the display. This is read only and only available in + * PAUSED and PLAYING state. It's meant to be used with + * gst_video_overlay_set_render_rectangle() function. + */ + g_properties[PROP_DISPLAY_WIDTH] = + g_param_spec_int ("display-width", "Display Width", + "Width of the display surface in pixels", 0, G_MAXINT, 0, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + + /** + * kmssink:display-height + * + * Actual height of the display. This is read only and only available in + * PAUSED and PLAYING state. It's meant to be used with + * gst_video_overlay_set_render_rectangle() function. + */ + g_properties[PROP_DISPLAY_HEIGHT] = + g_param_spec_int ("display-height", "Display Height", + "Height of the display surface in pixels", 0, G_MAXINT, 0, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (gobject_class, PROP_N, g_properties); }