1From 9b7e490376c888bcbe6b2802673a590409d9e82a Mon Sep 17 00:00:00 2001 2From: Jeffy Chen <jeffy.chen@rock-chips.com> 3Date: Wed, 19 Jan 2022 16:37:40 +0800 4Subject: [PATCH 30/41] kmssink: Support ignoring aspect ratio 5 6Set "force-aspect-ratio" property to false to ignore aspect ratio. 7 8Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 9--- 10 sys/kms/gstkmssink.c | 18 +++++++++++++++++- 11 sys/kms/gstkmssink.h | 2 ++ 12 2 files changed, 19 insertions(+), 1 deletion(-) 13 14diff --git a/sys/kms/gstkmssink.c b/sys/kms/gstkmssink.c 15index 8335963..3740e57 100644 16--- a/sys/kms/gstkmssink.c 17+++ b/sys/kms/gstkmssink.c 18@@ -106,6 +106,7 @@ enum 19 PROP_PLANE_PROPS, 20 PROP_FD, 21 PROP_SKIP_VSYNC, 22+ PROP_FORCE_ASPECT_RATIO, 23 PROP_N, 24 }; 25 26@@ -1582,7 +1583,7 @@ gst_kms_sink_calculate_display_ratio (GstKMSSink * self, GstVideoInfo * vinfo, 27 video_par_n = GST_VIDEO_INFO_PAR_N (vinfo); 28 video_par_d = GST_VIDEO_INFO_PAR_D (vinfo); 29 30- if (self->can_scale) { 31+ if (self->can_scale && self->keep_aspect) { 32 gst_video_calculate_device_ratio (self->hdisplay, self->vdisplay, 33 self->mm_width, self->mm_height, &dpy_par_n, &dpy_par_d); 34 } else { 35@@ -2179,6 +2180,9 @@ retry_set_plane: 36 result.x += self->render_rect.x; 37 result.y += self->render_rect.y; 38 39+ if (self->can_scale && !self->keep_aspect) 40+ result = self->render_rect; 41+ 42 if (crop) { 43 src.w = crop->width; 44 src.h = crop->height; 45@@ -2438,6 +2442,9 @@ gst_kms_sink_set_property (GObject * object, guint prop_id, 46 case PROP_SKIP_VSYNC: 47 sink->skip_vsync = g_value_get_boolean (value); 48 break; 49+ case PROP_FORCE_ASPECT_RATIO: 50+ sink->keep_aspect = g_value_get_boolean (value); 51+ break; 52 default: 53 if (!gst_video_overlay_set_property (object, PROP_N, prop_id, value)) 54 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); 55@@ -2497,6 +2504,9 @@ gst_kms_sink_get_property (GObject * object, guint prop_id, 56 case PROP_SKIP_VSYNC: 57 g_value_set_boolean (value, sink->skip_vsync); 58 break; 59+ case PROP_FORCE_ASPECT_RATIO: 60+ g_value_set_boolean (value, sink->keep_aspect); 61+ break; 62 default: 63 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); 64 break; 65@@ -2528,6 +2538,7 @@ gst_kms_sink_init (GstKMSSink * sink) 66 sink->plane_id = -1; 67 sink->saved_zpos = -1; 68 sink->can_scale = TRUE; 69+ sink->keep_aspect = TRUE; 70 gst_poll_fd_init (&sink->pollfd); 71 sink->poll = gst_poll_new (TRUE); 72 gst_video_info_init (&sink->vinfo); 73@@ -2736,6 +2747,11 @@ gst_kms_sink_class_init (GstKMSSinkClass * klass) 74 "Should be used for atomic drivers to avoid double vsync.", FALSE, 75 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT); 76 77+ g_properties[PROP_FORCE_ASPECT_RATIO] = 78+ g_param_spec_boolean ("force-aspect-ratio", "Force aspect ratio", 79+ "When enabled, scaling will respect original aspect ratio", TRUE, 80+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); 81+ 82 g_object_class_install_properties (gobject_class, PROP_N, g_properties); 83 84 gst_video_overlay_install_properties (gobject_class, PROP_N); 85diff --git a/sys/kms/gstkmssink.h b/sys/kms/gstkmssink.h 86index f221eb6..5fb712d 100644 87--- a/sys/kms/gstkmssink.h 88+++ b/sys/kms/gstkmssink.h 89@@ -112,6 +112,8 @@ struct _GstKMSSink { 90 #endif 91 92 guintptr window_handle; 93+ 94+ gboolean keep_aspect; 95 }; 96 97 struct _GstKMSSinkClass { 98-- 992.20.1 100 101