From a46ad6b5bef3304c9ab5b0280c506536eea78e7f Mon Sep 17 00:00:00 2001 From: Yi A Wang Date: Wed, 9 Aug 2017 18:32:13 -0700 Subject: [PATCH] FEI: plugin: Add virtual methods to base encode Two new virtual methods are added to gstvaapiencode. load_control_data(): load the FEI input buffers set by the upstream elements save_stats_to_meta(): save the FEI output buffers to Meta for downnstream elements https://bugzilla.gnome.org/show_bug.cgi?id=785712 https://bugzilla.gnome.org/show_bug.cgi?id=784667 Signed-off-by: Sreerenj Balachandran --- gst/vaapi/gstvaapiencode.c | 22 ++++++++++++++++++++++ gst/vaapi/gstvaapiencode.h | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/gst/vaapi/gstvaapiencode.c b/gst/vaapi/gstvaapiencode.c index fc8cf6e02a..b3988394a9 100644 --- a/gst/vaapi/gstvaapiencode.c +++ b/gst/vaapi/gstvaapiencode.c @@ -271,6 +271,9 @@ gst_vaapiencode_push_frame (GstVaapiEncode * encode, gint64 timeout) GstVaapiEncoderStatus status; GstBuffer *out_buffer; GstFlowReturn ret; +#if USE_H264_FEI_ENCODER + GstVaapiFeiVideoMeta *feimeta = NULL; +#endif status = gst_vaapi_encoder_get_buffer_with_timeout (encode->encoder, &codedbuf_proxy, timeout); @@ -295,6 +298,15 @@ gst_vaapiencode_push_frame (GstVaapiEncode * encode, gint64 timeout) out_buffer = NULL; ret = klass->alloc_buffer (encode, GST_VAAPI_CODED_BUFFER_PROXY_BUFFER (codedbuf_proxy), &out_buffer); + +#if USE_H264_FEI_ENCODER + if (klass->save_stats_to_meta) { + feimeta = klass->save_stats_to_meta (encode, codedbuf_proxy); + if (feimeta != NULL) + gst_buffer_set_vaapi_fei_video_meta (out_buffer, feimeta); + } +#endif + gst_vaapi_coded_buffer_proxy_replace (&codedbuf_proxy, NULL); if (ret != GST_FLOW_OK) goto error_allocate_buffer; @@ -617,6 +629,10 @@ gst_vaapiencode_handle_frame (GstVideoEncoder * venc, GstVaapiSurfaceProxy *proxy; GstFlowReturn ret; GstBuffer *buf; +#if USE_H264_FEI_ENCODER + GstVaapiFeiVideoMeta *feimeta = NULL; + GstVaapiEncodeClass *const klass = GST_VAAPIENCODE_GET_CLASS (venc); +#endif buf = NULL; ret = gst_vaapi_plugin_base_get_input_buffer (GST_VAAPI_PLUGIN_BASE (encode), @@ -635,6 +651,12 @@ gst_vaapiencode_handle_frame (GstVideoEncoder * venc, if (!proxy) goto error_buffer_no_surface_proxy; +#if USE_H264_FEI_ENCODER + feimeta = gst_buffer_get_vaapi_fei_video_meta (buf); + if (feimeta && klass->load_control_data) + klass->load_control_data (encode, feimeta, proxy); +#endif + gst_video_codec_frame_set_user_data (frame, gst_vaapi_surface_proxy_ref (proxy), (GDestroyNotify) gst_vaapi_surface_proxy_unref); diff --git a/gst/vaapi/gstvaapiencode.h b/gst/vaapi/gstvaapiencode.h index 72121f79eb..b63828526c 100644 --- a/gst/vaapi/gstvaapiencode.h +++ b/gst/vaapi/gstvaapiencode.h @@ -27,6 +27,12 @@ #include "gstvaapipluginbase.h" #include +#if USE_H264_FEI_ENCODER +#include +#include +#include "gstvaapifeivideometa.h" +#endif + G_BEGIN_DECLS #define GST_TYPE_VAAPIENCODE \ @@ -81,6 +87,18 @@ struct _GstVaapiEncodeClass GstVaapiCodedBuffer * coded_buf, GstBuffer ** outbuf_ptr); GstVaapiProfile (*get_profile) (GstCaps * caps); + +#if USE_H264_FEI_ENCODER + + gboolean (*load_control_data) (GstVaapiEncode *encoder, + GstVaapiFeiVideoMeta *feimeta, + GstVaapiSurfaceProxy *proxy); + + GstVaapiFeiVideoMeta* (*save_stats_to_meta) (GstVaapiEncode *base_encode, + GstVaapiCodedBufferProxy *proxy); + +#endif + }; GType