From 2551b1d976dba885f5950a7b3b170389b0f05c2c Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Wed, 19 May 2021 20:11:15 +0900 Subject: [PATCH] video: Deprecate gst_video_sink_center_rect() ... and add gst_video_center_rect() method as a replacement. The method is useful for outside of videosink subclasses as well but the old naming might be able to mislead people. Part-of: --- gst-libs/gst/video/gstvideosink.c | 68 ++++++++++++++++++++++++++------------- gst-libs/gst/video/gstvideosink.h | 8 ++++- 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/gst-libs/gst/video/gstvideosink.c b/gst-libs/gst/video/gstvideosink.c index 34e3c9d..67d634a 100644 --- a/gst-libs/gst/video/gstvideosink.c +++ b/gst-libs/gst/video/gstvideosink.c @@ -93,50 +93,74 @@ static void gst_video_sink_get_times (GstBaseSink * bsink, GstBuffer * buffer, * gst_video_sink_center_rect: * @src: the #GstVideoRectangle describing the source area * @dst: the #GstVideoRectangle describing the destination area - * @result: a pointer to a #GstVideoRectangle which will receive the result area + * @result: (out caller-allocates): a pointer to a #GstVideoRectangle which will receive the result area + * @scaling: a #gboolean indicating if scaling should be applied or not + * + * Deprecated: 1.20: Use gst_video_center_rect() instead. + */ +void +gst_video_sink_center_rect (GstVideoRectangle src, GstVideoRectangle dst, + GstVideoRectangle * result, gboolean scaling) +{ + gst_video_center_rect (&src, &dst, result, scaling); +} + +/** + * gst_video_center_rect: + * @src: a pointer to #GstVideoRectangle describing the source area + * @dst: a pointer to #GstVideoRectangle describing the destination area + * @result: (out caller-allocates): a pointer to a #GstVideoRectangle which will receive the result area * @scaling: a #gboolean indicating if scaling should be applied or not * * Takes @src rectangle and position it at the center of @dst rectangle with or * without @scaling. It handles clipping if the @src rectangle is bigger than * the @dst one and @scaling is set to FALSE. + * + * Since: 1.20 */ void -gst_video_sink_center_rect (GstVideoRectangle src, GstVideoRectangle dst, - GstVideoRectangle * result, gboolean scaling) +gst_video_center_rect (const GstVideoRectangle * src, + const GstVideoRectangle * dst, GstVideoRectangle * result, gboolean scaling) { + g_return_if_fail (src != NULL); + g_return_if_fail (dst != NULL); g_return_if_fail (result != NULL); if (!scaling) { - result->w = MIN (src.w, dst.w); - result->h = MIN (src.h, dst.h); - result->x = dst.x + (dst.w - result->w) / 2; - result->y = dst.y + (dst.h - result->h) / 2; + result->w = MIN (src->w, dst->w); + result->h = MIN (src->h, dst->h); + result->x = dst->x + (dst->w - result->w) / 2; + result->y = dst->y + (dst->h - result->h) / 2; } else { gdouble src_ratio, dst_ratio; - src_ratio = (gdouble) src.w / src.h; - dst_ratio = (gdouble) dst.w / dst.h; + g_return_if_fail (src->h != 0); + g_return_if_fail (dst->h != 0); + + src_ratio = (gdouble) src->w / src->h; + dst_ratio = (gdouble) dst->w / dst->h; if (src_ratio > dst_ratio) { - result->w = dst.w; - result->h = dst.w / src_ratio; - result->x = dst.x; - result->y = dst.y + (dst.h - result->h) / 2; + result->w = dst->w; + result->h = dst->w / src_ratio; + result->x = dst->x; + result->y = dst->y + (dst->h - result->h) / 2; } else if (src_ratio < dst_ratio) { - result->w = dst.h * src_ratio; - result->h = dst.h; - result->x = dst.x + (dst.w - result->w) / 2; - result->y = dst.y; + result->w = dst->h * src_ratio; + result->h = dst->h; + result->x = dst->x + (dst->w - result->w) / 2; + result->y = dst->y; } else { - result->x = dst.x; - result->y = dst.y; - result->w = dst.w; - result->h = dst.h; + result->x = dst->x; + result->y = dst->y; + result->w = dst->w; + result->h = dst->h; } } GST_DEBUG ("source is %dx%d dest is %dx%d, result is %dx%d with x,y %dx%d", - src.w, src.h, dst.w, dst.h, result->w, result->h, result->x, result->y); + src->w, src->h, dst->w, dst->h, + result->w, result->h, result->x, result->y); } /* Initing stuff */ diff --git a/gst-libs/gst/video/gstvideosink.h b/gst-libs/gst/video/gstvideosink.h index 329b5d2..a7a226d 100644 --- a/gst-libs/gst/video/gstvideosink.h +++ b/gst-libs/gst/video/gstvideosink.h @@ -136,10 +136,16 @@ struct _GstVideoSinkClass { GST_VIDEO_API GType gst_video_sink_get_type (void); -GST_VIDEO_API +GST_VIDEO_DEPRECATED_FOR(gst_video_center_rect) void gst_video_sink_center_rect (GstVideoRectangle src, GstVideoRectangle dst, GstVideoRectangle *result, gboolean scaling); +GST_VIDEO_API +void gst_video_center_rect (const GstVideoRectangle * src, + const GstVideoRectangle * dst, + GstVideoRectangle * result, + gboolean scaling); + G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoSink, gst_object_unref) G_END_DECLS -- 2.7.4