From d5542fa8c0c33ff54968f4b46632920a52fd91cb Mon Sep 17 00:00:00 2001 From: Sreerenj Balachandran Date: Wed, 9 Aug 2017 15:49:21 -0700 Subject: [PATCH] FEI: libs: Add fei codec objects to surface proxy Add fei codec objects to surface proxy since handling the fei buffers(codec objects here) external to gstvaapisurfaceproxy will make the code complicated. Especially considering the behavior of encoder where the input frame order from upstream and output frame order to the downstream are not sequential. Other contributors: Zhong, Xiaoxia xiaominc Leilei Li, Jing B https://bugzilla.gnome.org/show_bug.cgi?id=785712 https://bugzilla.gnome.org/show_bug.cgi?id=784667 --- gst-libs/gst/vaapi/gstvaapisurfaceproxy.c | 271 +++++++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapisurfaceproxy.h | 44 ++++ gst-libs/gst/vaapi/gstvaapisurfaceproxy_priv.h | 9 + 3 files changed, 324 insertions(+) diff --git a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c index 2b6e1d5..fc72e35 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c +++ b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c @@ -50,6 +50,27 @@ gst_vaapi_surface_proxy_finalize (GstVaapiSurfaceProxy * proxy) /* Notify the user function that the object is now destroyed */ if (proxy->destroy_func) proxy->destroy_func (proxy->destroy_data); + +#if USE_H264_FEI_ENCODER + if (proxy->mvpred) + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->mvpred, NULL); + if (proxy->mbcntrl) + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->mbcntrl, NULL); + if (proxy->qp) + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->qp, NULL); + if (proxy->mbcode) + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->mbcode, NULL); + if (proxy->mv) + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->mv, NULL); + if (proxy->dist) + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->dist, NULL); +#endif } static inline const GstVaapiMiniObjectClass * @@ -69,6 +90,14 @@ gst_vaapi_surface_proxy_init_properties (GstVaapiSurfaceProxy * proxy) proxy->timestamp = GST_CLOCK_TIME_NONE; proxy->duration = GST_CLOCK_TIME_NONE; proxy->has_crop_rect = FALSE; +#if USE_H264_FEI_ENCODER + proxy->mvpred = NULL; + proxy->mbcntrl = NULL; + proxy->qp = NULL; + proxy->mbcode = NULL; + proxy->mv = NULL; + proxy->dist = NULL; +#endif } /** @@ -189,6 +218,52 @@ gst_vaapi_surface_proxy_copy (GstVaapiSurfaceProxy * proxy) copy->has_crop_rect = proxy->has_crop_rect; if (copy->has_crop_rect) copy->crop_rect = proxy->crop_rect; + +#if USE_H264_FEI_ENCODER + + if (proxy->mv) + copy->mv = (GstVaapiEncFeiMv *) + gst_vaapi_fei_codec_object_ref (GST_VAAPI_FEI_CODEC_OBJECT (proxy->mv)); + else + copy->mv = NULL; + + if (proxy->mbcode) + copy->mbcode = (GstVaapiEncFeiMbCode *) + gst_vaapi_fei_codec_object_ref (GST_VAAPI_FEI_CODEC_OBJECT + (proxy->mbcode)); + else + copy->mbcode = NULL; + + if (proxy->mvpred) + copy->mvpred = (GstVaapiEncFeiMvPredictor *) + gst_vaapi_fei_codec_object_ref (GST_VAAPI_FEI_CODEC_OBJECT + (proxy->mvpred)); + else + copy->mvpred = NULL; + + if (proxy->qp) + copy->qp = (GstVaapiEncFeiQp *) + gst_vaapi_fei_codec_object_ref (GST_VAAPI_FEI_CODEC_OBJECT (proxy->qp)); + else + copy->qp = NULL; + + if (proxy->mbcntrl) + copy->mbcntrl = (GstVaapiEncFeiMbControl *) + gst_vaapi_fei_codec_object_ref (GST_VAAPI_FEI_CODEC_OBJECT + (proxy->mbcntrl)); + else + copy->mbcntrl = NULL; + + if (proxy->dist) + copy->dist = (GstVaapiEncFeiDistortion *) + gst_vaapi_fei_codec_object_ref (GST_VAAPI_FEI_CODEC_OBJECT + (proxy->dist)); + else + copy->dist = NULL; + + +#endif + return copy; } @@ -402,3 +477,199 @@ gst_vaapi_surface_proxy_set_crop_rect (GstVaapiSurfaceProxy * proxy, if (proxy->has_crop_rect) proxy->crop_rect = *crop_rect; } + +#if USE_H264_FEI_ENCODER + +/** + * gst_vaapi_surface_proxy_get_fei_mb_code: + * @proxy: a #GstVaapiSurfaceProxy + * + * Returns the #GstVaapiEncFeiMbCode stored in the @proxy + * + * Return value: the #GstVaapiEncFeiMbcode, or %NULL if none was + * associated with the surface proxy + */ +GstVaapiEncFeiMbCode * +gst_vaapi_surface_proxy_get_fei_mb_code (GstVaapiSurfaceProxy * proxy) +{ + g_return_val_if_fail (proxy != NULL, NULL); + return proxy->mbcode; +} + +/** + * gst_vaapi_surface_proxy_get_fei_mv: + * @proxy: a #GstVaapiSurfaceProxy + * + * Returns the #GstVaapiEncFeiMv stored in the @proxy + * + * Return value: the #GstVaapiEncFeiMv, or %NULL if none was + * associated with the surface proxy + */ +GstVaapiEncFeiMv * +gst_vaapi_surface_proxy_get_fei_mv (GstVaapiSurfaceProxy * proxy) +{ + g_return_val_if_fail (proxy != NULL, NULL); + return proxy->mv; +} + +/** + * gst_vaapi_surface_proxy_get_fei_distortion: + * @proxy: a #GstVaapiSurfaceProxy + * + * Returns the #GstVaapiEncFeiDistortion stored in the @proxy + * + * Return value: the #GstVaapiEncFeiDistortion, or %NULL if none was + * associated with the surface proxy + */ +GstVaapiEncFeiDistortion * +gst_vaapi_surface_proxy_get_fei_distortion (GstVaapiSurfaceProxy * proxy) +{ + g_return_val_if_fail (proxy != NULL, NULL); + return proxy->dist; +} + +/** + * gst_vaapi_surface_proxy_get_fei_qp: + * @proxy: a #GstVaapiSurfaceProxy + * + * Returns the #GstVaapiEncFeiQp stored in the @proxy + * + * Return value: the #GstVaapiEncFeiQp, or %NULL if none was + * associated with the surface proxy + */ +GstVaapiEncFeiQp * +gst_vaapi_surface_proxy_get_fei_qp (GstVaapiSurfaceProxy * proxy) +{ + g_return_val_if_fail (proxy != NULL, NULL); + return proxy->qp; +} + +/** + * gst_vaapi_surface_proxy_get_fei_mv_predictor: + * @proxy: a #GstVaapiSurfaceProxy + * + * Returns the #GstVaapiEncFeiMvPredictor stored in the @proxy + * + * Return value: the #GstVaapiEncFeiMvPredictor, or %NULL if none was + * associated with the surface proxy + */ +GstVaapiEncFeiMvPredictor * +gst_vaapi_surface_proxy_get_fei_mv_predictor (GstVaapiSurfaceProxy * proxy) +{ + g_return_val_if_fail (proxy != NULL, NULL); + return proxy->mvpred; +} + +/** + * gst_vaapi_surface_proxy_get_fei_mb_control: + * @proxy: a #GstVaapiSurfaceProxy + * + * Returns the #GstVaapiEncFeiMbControl stored in the @proxy + * + * Return value: the #GstVaapiEncFeiMbControl, or %NULL if none was + * associated with the surface proxy + */ +GstVaapiEncFeiMbControl * +gst_vaapi_surface_proxy_get_fei_mb_control (GstVaapiSurfaceProxy * proxy) +{ + g_return_val_if_fail (proxy != NULL, NULL); + return proxy->mbcntrl; +} + +/** + * gst_vaapi_surface_proxy_set_fei_mb_code: + * @proxy: #GstVaapiSurfaceProxy + * @mbcode: the #GstVaapiEncFeiMbCode to be stored in @proxy + * + * Associates the @mbcode with the @proxy + */ +void +gst_vaapi_surface_proxy_set_fei_mb_code (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiMbCode * mbcode) +{ + g_return_if_fail (proxy != NULL); + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->mbcode, (GstVaapiFeiCodecObject *) mbcode); +} + +/** + * gst_vaapi_surface_proxy_set_fei_mv: + * @proxy: #GstVaapiSurfaceProxy + * @mv: the #GstVaapiEncFeiMv to be stored in @proxy + * + * Associates the @mv with the @proxy + */ +void +gst_vaapi_surface_proxy_set_fei_mv (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiMv * mv) +{ + g_return_if_fail (proxy != NULL); + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->mv, (GstVaapiFeiCodecObject *) mv); +} + +/** + * gst_vaapi_surface_proxy_set_fei_distortion: + * @proxy: #GstVaapiSurfaceProxy + * @dist: the #GstVaapiEncFeiDistortion to be stored in @proxy + * + * Associates the @dist with the @proxy + */ +void +gst_vaapi_surface_proxy_set_fei_distortion (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiDistortion * dist) +{ + g_return_if_fail (proxy != NULL); + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->dist, (GstVaapiFeiCodecObject *) dist); +} + +/** + * gst_vaapi_surface_proxy_set_fei_qp: + * @proxy: #GstVaapiSurfaceProxy + * @qp: the #GstVaapiEncFeiQp to be stored in @proxy + * + * Associates the @qp with the @proxy + */ +void +gst_vaapi_surface_proxy_set_fei_qp (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiQp * qp) +{ + g_return_if_fail (proxy != NULL); + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->qp, (GstVaapiFeiCodecObject *) qp); +} + +/** + * gst_vaapi_surface_proxy_set_fei_mv_predictor: + * @proxy: #GstVaapiSurfaceProxy + * @mvpred: the #GstVaapiEncFeiMvPredictor to be stored in @proxy + * + * Associates the @mvpred with the @proxy + */ +void +gst_vaapi_surface_proxy_set_fei_mv_predictor (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiMvPredictor * mvpred) +{ + g_return_if_fail (proxy != NULL); + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->mvpred, (GstVaapiFeiCodecObject *) mvpred); +} + +/** + * gst_vaapi_surface_proxy_set_fei_mb_control: + * @proxy: #GstVaapiSurfaceProxy + * @mbcntrl: the #GstVaapiEncFeiMbControl to be stored in @proxy + * + * Associates the @mbcntrl with the @proxy + */ +void +gst_vaapi_surface_proxy_set_fei_mb_control (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiMbControl * mbcntrl) +{ + g_return_if_fail (proxy != NULL); + gst_vaapi_fei_codec_object_replace ((GstVaapiFeiCodecObject **) & + proxy->mbcntrl, (GstVaapiFeiCodecObject *) mbcntrl); +} + +#endif diff --git a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h index 1dc218c..5f6c16e 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h +++ b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h @@ -28,6 +28,10 @@ #include #include +#if USE_H264_FEI_ENCODER +#include +#endif + G_BEGIN_DECLS /** @@ -152,6 +156,46 @@ void gst_vaapi_surface_proxy_set_crop_rect (GstVaapiSurfaceProxy * proxy, const GstVaapiRectangle * crop_rect); +#if USE_H264_FEI_ENCODER + +GstVaapiEncFeiMbCode * +gst_vaapi_surface_proxy_get_fei_mb_code (GstVaapiSurfaceProxy * proxy); + +GstVaapiEncFeiMv * +gst_vaapi_surface_proxy_get_fei_mv (GstVaapiSurfaceProxy * proxy); + +GstVaapiEncFeiDistortion * +gst_vaapi_surface_proxy_get_fei_distortion (GstVaapiSurfaceProxy * proxy); + +GstVaapiEncFeiQp * +gst_vaapi_surface_proxy_get_fei_qp (GstVaapiSurfaceProxy * proxy); + +GstVaapiEncFeiMvPredictor * +gst_vaapi_surface_proxy_get_fei_mv_predictor (GstVaapiSurfaceProxy * proxy); + +GstVaapiEncFeiMbControl * +gst_vaapi_surface_proxy_get_fei_mb_control (GstVaapiSurfaceProxy * proxy); + +void +gst_vaapi_surface_proxy_set_fei_mb_code (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiMbCode *mbcode); +void +gst_vaapi_surface_proxy_set_fei_mv (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiMv *mv); +void +gst_vaapi_surface_proxy_set_fei_distortion (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiDistortion *dist); +void +gst_vaapi_surface_proxy_set_fei_qp (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiQp *mbcode); +void +gst_vaapi_surface_proxy_set_fei_mv_predictor (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiMvPredictor *mvpred); +void +gst_vaapi_surface_proxy_set_fei_mb_control (GstVaapiSurfaceProxy * proxy, + GstVaapiEncFeiMbControl *mbcntrl); +#endif + 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 d3bc7ab..1540c7c 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfaceproxy_priv.h +++ b/gst-libs/gst/vaapi/gstvaapisurfaceproxy_priv.h @@ -48,6 +48,15 @@ struct _GstVaapiSurfaceProxy gpointer destroy_data; GstVaapiRectangle crop_rect; guint has_crop_rect:1; + +#if USE_H264_FEI_ENCODER + GstVaapiEncFeiMvPredictor *mvpred; + GstVaapiEncFeiMbControl *mbcntrl; + GstVaapiEncFeiQp *qp; + GstVaapiEncFeiMbCode *mbcode; + GstVaapiEncFeiMv *mv; + GstVaapiEncFeiDistortion *dist; +#endif }; #define GST_VAAPI_SURFACE_PROXY_FLAGS GST_VAAPI_MINI_OBJECT_FLAGS -- 2.7.4