From 71e5fd536f1ce2dd33d992437609c98fbedabc69 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Tue, 27 Aug 2013 18:06:10 +0200 Subject: [PATCH] filter: allow specification of render target regions. Add support for rendering the source surface to a particular region within the supplied target surface. The default background color is black. --- docs/reference/libs/libs-sections.txt | 1 + gst-libs/gst/vaapi/gstvaapifilter.c | 52 ++++++++++++++++++++++++--- gst-libs/gst/vaapi/gstvaapifilter.h | 4 +++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/docs/reference/libs/libs-sections.txt b/docs/reference/libs/libs-sections.txt index b70eaaaaa9..cc00f43012 100644 --- a/docs/reference/libs/libs-sections.txt +++ b/docs/reference/libs/libs-sections.txt @@ -387,6 +387,7 @@ gst_vaapi_filter_get_formats gst_vaapi_filter_set_operation gst_vaapi_filter_set_format gst_vaapi_filter_set_cropping_rectangle +gst_vaapi_filter_set_target_rectangle gst_vaapi_filter_set_denoising_level gst_vaapi_filter_set_sharpening_level gst_vaapi_filter_set_hue diff --git a/gst-libs/gst/vaapi/gstvaapifilter.c b/gst-libs/gst/vaapi/gstvaapifilter.c index 78ab1078ae..ef07eb4fc3 100755 --- a/gst-libs/gst/vaapi/gstvaapifilter.c +++ b/gst-libs/gst/vaapi/gstvaapifilter.c @@ -64,7 +64,9 @@ struct _GstVaapiFilter { GstVideoFormat format; GArray *formats; GstVaapiRectangle crop_rect; + GstVaapiRectangle target_rect; guint use_crop_rect : 1; + guint use_target_rect : 1; }; /* ------------------------------------------------------------------------- */ @@ -1178,6 +1180,7 @@ gst_vaapi_filter_process_unlocked(GstVaapiFilter *filter, if (!ensure_operations(filter)) return GST_VAAPI_FILTER_STATUS_ERROR_ALLOCATION_FAILED; + /* Build surface region (source) */ if (filter->use_crop_rect) { const GstVaapiRectangle * const crop_rect = &filter->crop_rect; @@ -1199,10 +1202,27 @@ gst_vaapi_filter_process_unlocked(GstVaapiFilter *filter, src_rect.height = GST_VAAPI_SURFACE_HEIGHT(src_surface); } - dst_rect.x = 0; - dst_rect.y = 0; - dst_rect.width = GST_VAAPI_SURFACE_WIDTH(dst_surface); - dst_rect.height = GST_VAAPI_SURFACE_HEIGHT(dst_surface); + /* Build output region (target) */ + if (filter->use_target_rect) { + const GstVaapiRectangle * const target_rect = &filter->target_rect; + + if ((target_rect->x + target_rect->width > + GST_VAAPI_SURFACE_WIDTH(dst_surface)) || + (target_rect->y + target_rect->height > + GST_VAAPI_SURFACE_HEIGHT(dst_surface))) + goto error; + + dst_rect.x = target_rect->x; + dst_rect.y = target_rect->y; + dst_rect.width = target_rect->width; + dst_rect.height = target_rect->height; + } + else { + dst_rect.x = 0; + dst_rect.y = 0; + dst_rect.width = GST_VAAPI_SURFACE_WIDTH(dst_surface); + dst_rect.height = GST_VAAPI_SURFACE_HEIGHT(dst_surface); + } for (i = 0, num_filters = 0; i < filter->operations->len; i++) { GstVaapiFilterOpData * const op_data = @@ -1351,6 +1371,30 @@ gst_vaapi_filter_set_cropping_rectangle(GstVaapiFilter *filter, return TRUE; } +/** + * gst_vaapi_filter_set_target_rectangle: + * @filter: a #GstVaapiFilter + * @rect: the target render region + * + * Sets the region within the target surface where the source surface + * would be rendered. i.e. where the hardware accelerator would emit + * the outcome of video processing. If @rect is %NULL, the whole + * source surface will be used. + * + * Return value: %TRUE if the operation is supported, %FALSE otherwise. + */ +gboolean +gst_vaapi_filter_set_target_rectangle(GstVaapiFilter *filter, + const GstVaapiRectangle *rect) +{ + g_return_val_if_fail(filter != NULL, FALSE); + + filter->use_target_rect = rect != NULL; + if (filter->use_target_rect) + filter->target_rect = *rect; + return TRUE; +} + /** * gst_vaapi_filter_set_denoising_level: * @filter: a #GstVaapiFilter diff --git a/gst-libs/gst/vaapi/gstvaapifilter.h b/gst-libs/gst/vaapi/gstvaapifilter.h index bd770771e6..2ea44052b9 100755 --- a/gst-libs/gst/vaapi/gstvaapifilter.h +++ b/gst-libs/gst/vaapi/gstvaapifilter.h @@ -167,6 +167,10 @@ gboolean gst_vaapi_filter_set_cropping_rectangle(GstVaapiFilter *filter, const GstVaapiRectangle *rect); +gboolean +gst_vaapi_filter_set_target_rectangle(GstVaapiFilter *filter, + const GstVaapiRectangle *rect); + gboolean gst_vaapi_filter_set_denoising_level(GstVaapiFilter *filter, gfloat level);