diff options
author | Sreerenj Balachandran <sreerenj.balachandran@intel.com> | 2013-02-15 18:42:12 +0200 |
---|---|---|
committer | Gwenole Beauchesne <gwenole.beauchesne@intel.com> | 2013-07-08 18:52:56 +0200 |
commit | e66e72e7e3d714309db64727eb1cc1f8b337c5a1 (patch) | |
tree | c97644894e057f3fb63b412916550fc46b2b234b | |
parent | 746631c64c1b5282e98b483bc672d4714c21dc4b (diff) |
decoder: add support for video cropping.
Add gst_vaapi_picture_set_crop_rect() helper function to copy the video
cropping information from raw bitstreams to each picture being decoded.
Also add helper function to surface proxy to propagate that information
outside of libgstvaapi. e.g. plug-in elements or standalone applications.
Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapidecoder_objects.c | 20 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapidecoder_objects.h | 7 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapisurfaceproxy.c | 57 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapisurfaceproxy.h | 7 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapisurfaceproxy_priv.h | 13 |
5 files changed, 104 insertions, 0 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_objects.c b/gst-libs/gst/vaapi/gstvaapidecoder_objects.c index 3390aea7..92f0f7bb 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_objects.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_objects.c @@ -128,6 +128,11 @@ gst_vaapi_picture_create( } GST_VAAPI_PICTURE_FLAG_UNSET(picture, GST_VAAPI_PICTURE_FLAG_FF); } + + if (parent_picture->has_crop_rect) { + picture->has_crop_rect = TRUE; + picture->crop_rect = parent_picture->crop_rect; + } } else { picture->type = GST_VAAPI_PICTURE_TYPE_NONE; @@ -308,6 +313,10 @@ gst_vaapi_picture_output(GstVaapiPicture *picture) return FALSE; proxy = gst_vaapi_surface_proxy_ref(picture->proxy); + + if (picture->has_crop_rect) + gst_vaapi_surface_proxy_set_crop_rect(proxy, &picture->crop_rect); + gst_video_codec_frame_set_user_data(out_frame, proxy, (GDestroyNotify)gst_vaapi_mini_object_unref); @@ -330,6 +339,17 @@ gst_vaapi_picture_output(GstVaapiPicture *picture) return TRUE; } +void +gst_vaapi_picture_set_crop_rect(GstVaapiPicture *picture, + const GstVaapiRectangle *crop_rect) +{ + g_return_if_fail(GST_VAAPI_IS_PICTURE(picture)); + + picture->has_crop_rect = crop_rect != NULL; + if (picture->has_crop_rect) + picture->crop_rect = *crop_rect; +} + /* ------------------------------------------------------------------------- */ /* --- Slices --- */ /* ------------------------------------------------------------------------- */ diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_objects.h b/gst-libs/gst/vaapi/gstvaapidecoder_objects.h index f0e173f6..9bc2436c 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_objects.h +++ b/gst-libs/gst/vaapi/gstvaapidecoder_objects.h @@ -131,6 +131,8 @@ struct _GstVaapiPicture { GstClockTime pts; gint32 poc; guint structure; + GstVaapiRectangle crop_rect; + guint has_crop_rect : 1; }; G_GNUC_INTERNAL @@ -166,6 +168,11 @@ G_GNUC_INTERNAL gboolean gst_vaapi_picture_output(GstVaapiPicture *picture); +G_GNUC_INTERNAL +void +gst_vaapi_picture_set_crop_rect(GstVaapiPicture *picture, + const GstVaapiRectangle *crop_rect); + static inline gpointer gst_vaapi_picture_ref(gpointer ptr) { diff --git a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c index a2cd002f..9df4eaf0 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c +++ b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c @@ -34,6 +34,27 @@ #include "gstvaapidebug.h" static void +set_crop_rect_from_surface(GstVaapiSurfaceProxy *proxy) +{ + guint width, height; + + gst_vaapi_surface_get_size(proxy->surface, &width, &height); + proxy->crop_rect.x = 0; + proxy->crop_rect.y = 0; + proxy->crop_rect.width = width; + proxy->crop_rect.height = height; +} + +static inline void +set_crop_rect(GstVaapiSurfaceProxy *proxy, const GstVaapiRectangle *crop_rect) +{ + if (crop_rect) + proxy->crop_rect = *crop_rect; + else + set_crop_rect_from_surface(proxy); +} + +static void gst_vaapi_surface_proxy_finalize(GstVaapiSurfaceProxy *proxy) { if (proxy->destroy_func) @@ -74,6 +95,8 @@ gst_vaapi_surface_proxy_new_from_pool(GstVaapiSurfacePool *pool) proxy->surface = gst_vaapi_video_pool_get_object(proxy->pool); if (!proxy->surface) goto error; + set_crop_rect_from_surface(proxy); + proxy->timestamp = GST_CLOCK_TIME_NONE; proxy->duration = GST_CLOCK_TIME_NONE; proxy->destroy_func = NULL; @@ -238,3 +261,37 @@ gst_vaapi_surface_proxy_set_destroy_notify(GstVaapiSurfaceProxy *proxy, proxy->destroy_func = destroy_func; proxy->destroy_data = user_data; } + +/** + * gst_vaapi_surface_proxy_get_crop_rect: + * @proxy: a #GstVaapiSurfaceProxy + * + * Returns the #GstVaapiRectangle stored in the @proxy and that + * represents the cropping rectangle for the underlying surface to be + * used for rendering. + * + * Return value: the #GstVaapiRectangle + */ +const GstVaapiRectangle * +gst_vaapi_surface_proxy_get_crop_rect(GstVaapiSurfaceProxy *proxy) +{ + g_return_val_if_fail(proxy != NULL, NULL); + + return GST_VAAPI_SURFACE_PROXY_CROP_RECT(proxy); +} + +/** + * gst_vaapi_surface_proxy_set_crop_rect: + * @proxy: #GstVaapiSurfaceProxy + * @crop_rect: the #GstVaapiRectangle to be stored in @proxy + * + * Associates the @crop_rect with the @proxy + */ +void +gst_vaapi_surface_proxy_set_crop_rect(GstVaapiSurfaceProxy *proxy, + const GstVaapiRectangle *crop_rect) +{ + g_return_if_fail(proxy != NULL); + + set_crop_rect(proxy, crop_rect); +} diff --git a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h index c9def570..69ddbc49 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h +++ b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h @@ -117,6 +117,13 @@ void gst_vaapi_surface_proxy_set_destroy_notify(GstVaapiSurfaceProxy *proxy, GDestroyNotify destroy_func, gpointer user_data); +const GstVaapiRectangle * +gst_vaapi_surface_proxy_get_crop_rect(GstVaapiSurfaceProxy *proxy); + +void +gst_vaapi_surface_proxy_set_crop_rect(GstVaapiSurfaceProxy *proxy, + const GstVaapiRectangle *crop_rect); + G_END_DECLS #endif /* GST_VAAPI_SURFACE_PROXY_H */ diff --git a/gst-libs/gst/vaapi/gstvaapisurfaceproxy_priv.h b/gst-libs/gst/vaapi/gstvaapisurfaceproxy_priv.h index d3fbcbc3..6e5d7582 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfaceproxy_priv.h +++ b/gst-libs/gst/vaapi/gstvaapisurfaceproxy_priv.h @@ -41,6 +41,7 @@ struct _GstVaapiSurfaceProxy { GstClockTime duration; GDestroyNotify destroy_func; gpointer destroy_data; + GstVaapiRectangle crop_rect; }; #define GST_VAAPI_SURFACE_PROXY_FLAGS GST_VAAPI_MINI_OBJECT_FLAGS @@ -98,4 +99,16 @@ struct _GstVaapiSurfaceProxy { #define GST_VAAPI_SURFACE_PROXY_DURATION(proxy) \ proxy->duration +/** + * GST_VAAPI_SURFACE_PROXY_CROP_RECT: + * @proxy: a #GstVaapiSurfaceProxy + * + * Macro that evaluates to the video cropping rectangle of the underlying @proxy surface. + * + * This is an internal macro that does not do any run-time type check. + */ +#undef GST_VAAPI_SURFACE_PROXY_CROP_RECT +#define GST_VAAPI_SURFACE_PROXY_CROP_RECT(proxy) \ + &(proxy)->crop_rect + #endif /* GST_VAAPI_SURFACE_PROXY_PRIV_H */ |