From 5f78f7cdf4c49f321bfe1c0fdab53662e7ce43c8 Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Fri, 19 Jan 2024 10:16:13 +0800 Subject: [PATCH 04/43] kmssink: Fix cropping for video with non-square aspect ratio Give the original video source size to DRM instead of the scaled one. Signed-off-by: Jeffy Chen --- sys/kms/gstkmssink.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/sys/kms/gstkmssink.c b/sys/kms/gstkmssink.c index c1e9f64..f80b346 100644 --- a/sys/kms/gstkmssink.c +++ b/sys/kms/gstkmssink.c @@ -1898,15 +1898,18 @@ gst_kms_sink_show_frame (GstVideoSink * vsink, GstBuffer * buf) if (buf) { buffer = gst_kms_sink_get_input_buffer (self, buf); vinfo = &self->vinfo; - video_width = src.w = GST_VIDEO_SINK_WIDTH (self); - video_height = src.h = GST_VIDEO_SINK_HEIGHT (self); + src.w = GST_VIDEO_SINK_WIDTH (self); + src.h = GST_VIDEO_SINK_HEIGHT (self); } else if (self->last_buffer) { buffer = gst_buffer_ref (self->last_buffer); vinfo = &self->last_vinfo; - video_width = src.w = self->last_width; - video_height = src.h = self->last_height; + src.w = self->last_width; + src.h = self->last_height; } + video_width = GST_VIDEO_INFO_WIDTH (vinfo); + video_height = GST_VIDEO_INFO_HEIGHT (vinfo); + /* Make sure buf is not used accidentally */ buf = NULL; @@ -1927,8 +1930,8 @@ gst_kms_sink_show_frame (GstVideoSink * vsink, GstBuffer * buf) if ((crop = gst_buffer_get_video_crop_meta (buffer))) { GstVideoInfo cropped_vinfo = *vinfo; - cropped_vinfo.width = crop->width; - cropped_vinfo.height = crop->height; + video_width = src.w = cropped_vinfo.width = crop->width; + video_height = src.h = cropped_vinfo.height = crop->height; if (!gst_kms_sink_calculate_display_ratio (self, &cropped_vinfo, &src.w, &src.h)) @@ -1947,13 +1950,9 @@ retry_set_plane: result.x += self->render_rect.x; result.y += self->render_rect.y; - if (crop) { - src.w = crop->width; - src.h = crop->height; - } else { - src.w = video_width; - src.h = video_height; - } + /* Restore the real source size */ + src.w = video_width; + src.h = video_height; /* handle out of screen case */ if ((result.x + result.w) > self->hdisplay) -- 2.20.1