From 8f1b88dac0e64a211325cdcb2cda693b80229bd1 Mon Sep 17 00:00:00 2001 From: Hyunjun Ko Date: Thu, 30 Mar 2017 17:54:20 +0900 Subject: [PATCH] vaapiencode: handle custom event GstVaapiEncoderRegionOfInterest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Handles new custom event GstVaapiEncoderRegionOfInterest to enable/disable a ROI region. Writes a way to use new event to document. https://bugzilla.gnome.org/show_bug.cgi?id=768248 Signed-off-by: Víctor Manuel Jáquez Leal --- gst/vaapi/gstvaapiencode.c | 39 +++++++++++++++++ gst/vaapi/gstvaapiencode_h264.c | 74 +++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/gst/vaapi/gstvaapiencode.c b/gst/vaapi/gstvaapiencode.c index 12d634de3a..fc8cf6e02a 100644 --- a/gst/vaapi/gstvaapiencode.c +++ b/gst/vaapi/gstvaapiencode.c @@ -739,6 +739,45 @@ gst_vaapiencode_sink_event (GstVideoEncoder * venc, GstEvent * event) GstPad *const srcpad = GST_VAAPI_PLUGIN_BASE_SRC_PAD (encode); gboolean ret; + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CUSTOM_DOWNSTREAM:{ + const GstStructure *s = gst_event_get_structure (event); + if (gst_structure_has_name (s, "GstVaapiEncoderRegionOfInterest")) { + GstVaapiROI roi; + + if (!encode->encoder) + return TRUE; + + if (!gst_structure_get_uint (s, "roi-x", &roi.rect.x) || + !gst_structure_get_uint (s, "roi-y", &roi.rect.y) || + !gst_structure_get_uint (s, "roi-width", &roi.rect.width) || + !gst_structure_get_uint (s, "roi-height", &roi.rect.height) || + !gst_structure_get_int (s, "roi-value", &roi.roi_value)) { + return TRUE; + } + + if (roi.roi_value == 0) { + ret = gst_vaapi_encoder_del_roi (encode->encoder, &roi); + if (ret) { + GST_INFO_OBJECT (venc, "ROI: region with %d/%d/%d/%d is removed", + roi.rect.x, roi.rect.y, roi.rect.width, roi.rect.height); + } + } else { + ret = gst_vaapi_encoder_add_roi (encode->encoder, &roi); + if (ret) { + GST_INFO_OBJECT (venc, "ROI: region with %d/%d/%d/%d is added", + roi.rect.x, roi.rect.y, roi.rect.width, roi.rect.height); + } + } + gst_event_unref (event); + return ret; + } + break; + } + default: + break; + } + ret = GST_VIDEO_ENCODER_CLASS (gst_vaapiencode_parent_class)->sink_event (venc, event); if (!ret) diff --git a/gst/vaapi/gstvaapiencode_h264.c b/gst/vaapi/gstvaapiencode_h264.c index 074274524b..3f7db3e589 100644 --- a/gst/vaapi/gstvaapiencode_h264.c +++ b/gst/vaapi/gstvaapiencode_h264.c @@ -33,6 +33,80 @@ * gst-launch-1.0 -ev videotestsrc num-buffers=60 ! timeoverlay ! vaapih264enc ! h264parse ! mp4mux ! filesink location=test.mp4 * ]| * + * + * + * Region of Interest + * Since libva supports Region Of Interest for avc encoding depending on H/W, + * GStreamer VA-API supports it by #GstEvent. + * To enable ROI, an application must send an event of type GST_EVENT_CUSTOM_DOWNSTREAM, + * having a structure of name "GstVaapiEncoderRegionOfInterest" with fields set + * according to the following table: + * + * + * + * + * + * + * + * + * Name + * GType + * Description + * + * + * + * + * roi-value + * G_TYPE_INT + * specifies ROI delta QP or ROI priority. + * ROI delta QP is the value that will be added on top of the frame level QP. + * ROI priority specifies the priority of a region, it can be positive (more important) + * or negative (less important) values and is compared with non-ROI region (taken as value 0), + * + * + * + * + * roi-x + * G_TYPE_UINT + * X + * + * + * roi-y + * G_TYPE_UINT + * Y + * + * + * roi-width + * G_TYPE_UINT + * width + * + * + * roi-height + * G_TYPE_UINT + * height + * + * + * + * + * + * For example, the following code informs the encoder to enable ROI + * with a region for ROI. + * Note that if an application wants to disable the region, + * just send an event with roi-value=0 and same coordination. + * + * + * GstEvent *event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, + * gst_structure_new ("GstVaapiEncoderRegionOfInterest", + * "roi-x", G_TYPE_UINT, 1820, + * "roi-y", G_TYPE_UINT, 980, + * "roi-width", G_TYPE_UINT, 100, + * "roi-height", G_TYPE_UINT, 100, + * "roi-value", G_TYPE_INT, 4, NULL)); + * + * gst_element_send_event (pipeline, event); + * + * + * */ #include "gstcompat.h"