2010-03-05 17:11:52 +00:00
|
|
|
/*
|
2012-01-03 13:34:09 +00:00
|
|
|
* gstvaapiupload.c - VA-API video uploader
|
2010-03-05 17:11:52 +00:00
|
|
|
*
|
2011-06-14 11:52:56 +00:00
|
|
|
* gstreamer-vaapi (C) 2010-2011 Splitted-Desktop Systems
|
2011-12-07 18:09:55 +00:00
|
|
|
* Copyright (C) 2011 Intel Corporation
|
2010-03-05 17:11:52 +00:00
|
|
|
*
|
2011-10-18 07:06:52 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1
|
|
|
|
* of the License, or (at your option) any later version.
|
2010-03-05 17:11:52 +00:00
|
|
|
*
|
2011-10-18 07:06:52 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-03-05 17:11:52 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-10-18 07:06:52 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-03-05 17:11:52 +00:00
|
|
|
*
|
2011-10-18 07:06:52 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
2010-03-05 17:11:52 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-23 15:22:47 +00:00
|
|
|
/**
|
2012-01-03 13:34:09 +00:00
|
|
|
* SECTION:gstvaapiupload
|
|
|
|
* @short_description: A video to VA flow filter
|
2010-03-23 15:22:47 +00:00
|
|
|
*
|
2012-01-03 13:34:09 +00:00
|
|
|
* vaapiupload converts from raw YUV pixels to VA surfaces suitable
|
|
|
|
* for the vaapisink element, for example.
|
2010-03-23 15:22:47 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-05 17:11:52 +00:00
|
|
|
#include "config.h"
|
2011-11-04 20:50:15 +00:00
|
|
|
|
2010-03-05 17:11:52 +00:00
|
|
|
#include <gst/gst.h>
|
2010-03-15 17:10:56 +00:00
|
|
|
#include <gst/video/video.h>
|
2011-11-04 20:50:15 +00:00
|
|
|
#include <gst/video/videocontext.h>
|
2010-03-16 09:03:10 +00:00
|
|
|
#include <gst/vaapi/gstvaapivideosink.h>
|
2011-09-05 14:18:14 +00:00
|
|
|
#include <gst/vaapi/gstvaapivideobuffer.h>
|
2011-11-04 20:50:15 +00:00
|
|
|
|
2011-11-05 00:07:52 +00:00
|
|
|
#if USE_VAAPI_GLX
|
|
|
|
#include <gst/vaapi/gstvaapivideobuffer_glx.h>
|
|
|
|
#define gst_vaapi_video_buffer_new_from_pool(pool) \
|
|
|
|
gst_vaapi_video_buffer_glx_new_from_pool(pool)
|
|
|
|
#define gst_vaapi_video_buffer_new_from_buffer(buffer) \
|
|
|
|
gst_vaapi_video_buffer_glx_new_from_buffer(buffer)
|
|
|
|
#endif
|
|
|
|
|
2011-11-04 20:50:15 +00:00
|
|
|
#include "gstvaapipluginutil.h"
|
2012-01-03 13:34:09 +00:00
|
|
|
#include "gstvaapiupload.h"
|
2010-03-05 17:11:52 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
#define GST_PLUGIN_NAME "vaapiupload"
|
|
|
|
#define GST_PLUGIN_DESC "A video to VA flow filter"
|
2010-03-15 17:10:56 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapiupload);
|
|
|
|
#define GST_CAT_DEFAULT gst_debug_vaapiupload
|
2010-03-15 17:10:56 +00:00
|
|
|
|
2010-03-05 17:11:52 +00:00
|
|
|
/* ElementFactory information */
|
2012-01-03 13:34:09 +00:00
|
|
|
static const GstElementDetails gst_vaapiupload_details =
|
2010-03-05 17:11:52 +00:00
|
|
|
GST_ELEMENT_DETAILS(
|
2010-05-10 09:32:47 +00:00
|
|
|
"VA-API colorspace converter",
|
|
|
|
"Filter/Converter/Video",
|
|
|
|
GST_PLUGIN_DESC,
|
2011-10-19 12:43:56 +00:00
|
|
|
"Gwenole Beauchesne <gwenole.beauchesne@intel.com>");
|
2010-03-05 17:11:52 +00:00
|
|
|
|
|
|
|
/* Default templates */
|
2012-01-03 13:34:09 +00:00
|
|
|
static const char gst_vaapiupload_yuv_caps_str[] =
|
2010-03-15 17:10:56 +00:00
|
|
|
"video/x-raw-yuv, "
|
2010-05-12 09:34:37 +00:00
|
|
|
"width = (int) [ 1, MAX ], "
|
2010-03-15 17:10:56 +00:00
|
|
|
"height = (int) [ 1, MAX ]; ";
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
static const char gst_vaapiupload_vaapi_caps_str[] =
|
2010-05-07 06:35:31 +00:00
|
|
|
GST_VAAPI_SURFACE_CAPS;
|
2010-03-15 17:10:56 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
static GstStaticPadTemplate gst_vaapiupload_sink_factory =
|
2010-03-05 17:11:52 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE(
|
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-01-03 13:34:09 +00:00
|
|
|
GST_STATIC_CAPS(gst_vaapiupload_yuv_caps_str));
|
2010-03-05 17:11:52 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
static GstStaticPadTemplate gst_vaapiupload_src_factory =
|
2010-03-05 17:11:52 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE(
|
|
|
|
"src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-01-03 13:34:09 +00:00
|
|
|
GST_STATIC_CAPS(gst_vaapiupload_vaapi_caps_str));
|
2010-03-05 17:11:52 +00:00
|
|
|
|
2011-11-04 20:50:15 +00:00
|
|
|
#define GstVideoContextClass GstVideoContextInterface
|
|
|
|
GST_BOILERPLATE_WITH_INTERFACE(
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload,
|
|
|
|
gst_vaapiupload,
|
2010-03-05 17:11:52 +00:00
|
|
|
GstBaseTransform,
|
2011-11-04 20:50:15 +00:00
|
|
|
GST_TYPE_BASE_TRANSFORM,
|
|
|
|
GstVideoContext,
|
|
|
|
GST_TYPE_VIDEO_CONTEXT,
|
|
|
|
gst_video_context);
|
2010-03-05 17:11:52 +00:00
|
|
|
|
2011-09-05 14:20:20 +00:00
|
|
|
/*
|
|
|
|
* Direct rendering levels (direct-rendering)
|
|
|
|
* 0: upstream allocated YUV pixels
|
2012-01-03 13:34:09 +00:00
|
|
|
* 1: vaapiupload allocated YUV pixels (mapped from VA image)
|
|
|
|
* 2: vaapiupload allocated YUV pixels (mapped from VA surface)
|
2011-09-05 14:20:20 +00:00
|
|
|
*/
|
2010-03-19 08:42:51 +00:00
|
|
|
#define DIRECT_RENDERING_DEFAULT 2
|
|
|
|
|
2010-03-18 16:18:17 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
|
2010-03-19 08:42:51 +00:00
|
|
|
PROP_DIRECT_RENDERING,
|
2010-03-18 16:18:17 +00:00
|
|
|
};
|
|
|
|
|
2010-05-12 09:34:37 +00:00
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_start(GstBaseTransform *trans);
|
2010-05-12 09:34:37 +00:00
|
|
|
|
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_stop(GstBaseTransform *trans);
|
2010-03-15 17:10:56 +00:00
|
|
|
|
2010-03-05 17:11:52 +00:00
|
|
|
static GstFlowReturn
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_transform(
|
2010-03-05 17:11:52 +00:00
|
|
|
GstBaseTransform *trans,
|
|
|
|
GstBuffer *inbuf,
|
|
|
|
GstBuffer *outbuf
|
|
|
|
);
|
|
|
|
|
2010-03-15 17:10:56 +00:00
|
|
|
static GstCaps *
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_transform_caps(
|
2010-03-15 17:10:56 +00:00
|
|
|
GstBaseTransform *trans,
|
|
|
|
GstPadDirection direction,
|
|
|
|
GstCaps *caps
|
|
|
|
);
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_set_caps(
|
2010-03-15 17:10:56 +00:00
|
|
|
GstBaseTransform *trans,
|
|
|
|
GstCaps *incaps,
|
|
|
|
GstCaps *outcaps
|
|
|
|
);
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_get_unit_size(
|
2010-03-15 17:10:56 +00:00
|
|
|
GstBaseTransform *trans,
|
|
|
|
GstCaps *caps,
|
|
|
|
guint *size
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_sinkpad_buffer_alloc(
|
2010-03-15 17:10:56 +00:00
|
|
|
GstPad *pad,
|
|
|
|
guint64 offset,
|
|
|
|
guint size,
|
|
|
|
GstCaps *caps,
|
|
|
|
GstBuffer **pbuf
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_prepare_output_buffer(
|
2010-03-15 17:10:56 +00:00
|
|
|
GstBaseTransform *trans,
|
|
|
|
GstBuffer *inbuf,
|
|
|
|
gint size,
|
|
|
|
GstCaps *caps,
|
|
|
|
GstBuffer **poutbuf
|
|
|
|
);
|
|
|
|
|
2011-11-04 20:50:15 +00:00
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_query(
|
2011-11-04 20:50:15 +00:00
|
|
|
GstPad *pad,
|
|
|
|
GstQuery *query
|
|
|
|
);
|
|
|
|
|
|
|
|
/* GstVideoContext interface */
|
|
|
|
|
|
|
|
static void
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_set_video_context(GstVideoContext *context, const gchar *type,
|
2011-11-04 20:50:15 +00:00
|
|
|
const GValue *value)
|
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload *upload = GST_VAAPIUPLOAD (context);
|
|
|
|
gst_vaapi_set_display (type, value, &upload->display);
|
2011-11-04 20:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_video_context_supported (GstVaapiUpload *upload, GType iface_type)
|
2011-11-04 20:50:15 +00:00
|
|
|
{
|
|
|
|
return (iface_type == GST_TYPE_VIDEO_CONTEXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_video_context_interface_init(GstVideoContextInterface *iface)
|
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
iface->set_context = gst_vaapiupload_set_video_context;
|
2011-11-04 20:50:15 +00:00
|
|
|
}
|
|
|
|
|
2010-03-15 17:10:56 +00:00
|
|
|
static void
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_destroy(GstVaapiUpload *upload)
|
2010-03-15 17:10:56 +00:00
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
if (upload->images) {
|
|
|
|
g_object_unref(upload->images);
|
|
|
|
upload->images = NULL;
|
2010-03-15 17:10:56 +00:00
|
|
|
}
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (upload->surfaces) {
|
|
|
|
g_object_unref(upload->surfaces);
|
|
|
|
upload->surfaces = NULL;
|
2010-03-15 17:10:56 +00:00
|
|
|
}
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (upload->display) {
|
|
|
|
g_object_unref(upload->display);
|
|
|
|
upload->display = NULL;
|
2010-03-15 17:10:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-12 09:34:37 +00:00
|
|
|
static void
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_base_init(gpointer klass)
|
2010-03-05 17:11:52 +00:00
|
|
|
{
|
|
|
|
GstElementClass * const element_class = GST_ELEMENT_CLASS(klass);
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_element_class_set_details(element_class, &gst_vaapiupload_details);
|
2010-03-05 17:11:52 +00:00
|
|
|
|
2010-03-15 17:10:56 +00:00
|
|
|
/* sink pad */
|
2010-03-05 17:11:52 +00:00
|
|
|
gst_element_class_add_pad_template(
|
|
|
|
element_class,
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_static_pad_template_get(&gst_vaapiupload_sink_factory)
|
2010-03-05 17:11:52 +00:00
|
|
|
);
|
2010-03-15 17:10:56 +00:00
|
|
|
|
|
|
|
/* src pad */
|
2010-03-05 17:11:52 +00:00
|
|
|
gst_element_class_add_pad_template(
|
|
|
|
element_class,
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_static_pad_template_get(&gst_vaapiupload_src_factory)
|
2010-03-05 17:11:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-03-15 17:10:56 +00:00
|
|
|
static void
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_finalize(GObject *object)
|
2010-03-15 17:10:56 +00:00
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_destroy(GST_VAAPIUPLOAD(object));
|
2010-03-15 17:10:56 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS(parent_class)->finalize(object);
|
|
|
|
}
|
|
|
|
|
2010-03-18 16:18:17 +00:00
|
|
|
|
|
|
|
static void
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_set_property(
|
2010-03-18 16:18:17 +00:00
|
|
|
GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec
|
|
|
|
)
|
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload * const upload = GST_VAAPIUPLOAD(object);
|
2010-03-18 16:18:17 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2010-03-19 08:42:51 +00:00
|
|
|
case PROP_DIRECT_RENDERING:
|
2012-01-03 13:34:09 +00:00
|
|
|
GST_OBJECT_LOCK(upload);
|
|
|
|
upload->direct_rendering = g_value_get_uint(value);
|
|
|
|
GST_OBJECT_UNLOCK(upload);
|
2010-03-18 16:18:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_get_property(
|
2010-03-18 16:18:17 +00:00
|
|
|
GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec
|
|
|
|
)
|
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload * const upload = GST_VAAPIUPLOAD(object);
|
2010-03-18 16:18:17 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2010-03-19 08:42:51 +00:00
|
|
|
case PROP_DIRECT_RENDERING:
|
2012-01-03 13:34:09 +00:00
|
|
|
g_value_set_uint(value, upload->direct_rendering);
|
2010-03-18 16:18:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-15 17:10:56 +00:00
|
|
|
static void
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_class_init(GstVaapiUploadClass *klass)
|
2010-03-05 17:11:52 +00:00
|
|
|
{
|
|
|
|
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
|
|
|
|
GstBaseTransformClass * const trans_class = GST_BASE_TRANSFORM_CLASS(klass);
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT(gst_debug_vaapiupload,
|
2011-09-14 19:12:41 +00:00
|
|
|
GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
object_class->finalize = gst_vaapiupload_finalize;
|
|
|
|
object_class->set_property = gst_vaapiupload_set_property;
|
|
|
|
object_class->get_property = gst_vaapiupload_get_property;
|
2010-03-15 17:10:56 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
trans_class->start = gst_vaapiupload_start;
|
|
|
|
trans_class->stop = gst_vaapiupload_stop;
|
|
|
|
trans_class->transform = gst_vaapiupload_transform;
|
|
|
|
trans_class->transform_caps = gst_vaapiupload_transform_caps;
|
|
|
|
trans_class->set_caps = gst_vaapiupload_set_caps;
|
|
|
|
trans_class->get_unit_size = gst_vaapiupload_get_unit_size;
|
|
|
|
trans_class->prepare_output_buffer = gst_vaapiupload_prepare_output_buffer;
|
2010-03-18 16:18:17 +00:00
|
|
|
|
2010-03-23 15:22:47 +00:00
|
|
|
/**
|
2012-01-03 13:34:09 +00:00
|
|
|
* GstVaapiUpload:direct-rendering:
|
2010-03-23 15:22:47 +00:00
|
|
|
*
|
|
|
|
* Selects the direct rendering level.
|
|
|
|
* <orderedlist>
|
|
|
|
* <listitem override="0">
|
|
|
|
* Disables direct rendering.
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* Enables direct rendering to the output buffer. i.e. this
|
|
|
|
* tries to use a single buffer for both sink and src pads.
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* Enables direct rendering to the underlying surface. i.e. with
|
|
|
|
* drivers supporting vaDeriveImage(), the output surface pixels
|
|
|
|
* will be modified directly.
|
|
|
|
* </listitem>
|
|
|
|
* </orderedlist>
|
|
|
|
*/
|
2010-03-18 16:18:17 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class,
|
2010-03-19 08:42:51 +00:00
|
|
|
PROP_DIRECT_RENDERING,
|
|
|
|
g_param_spec_uint("direct-rendering",
|
|
|
|
"Direct rendering",
|
|
|
|
"Direct rendering level",
|
|
|
|
0, 2,
|
|
|
|
DIRECT_RENDERING_DEFAULT,
|
|
|
|
G_PARAM_READWRITE));
|
2010-03-05 17:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_init(GstVaapiUpload *upload, GstVaapiUploadClass *klass)
|
2010-03-05 17:11:52 +00:00
|
|
|
{
|
2011-11-04 20:50:15 +00:00
|
|
|
GstPad *sinkpad, *srcpad;
|
2010-03-15 17:10:56 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
upload->display = NULL;
|
|
|
|
upload->images = NULL;
|
|
|
|
upload->images_reset = FALSE;
|
|
|
|
upload->image_width = 0;
|
|
|
|
upload->image_height = 0;
|
|
|
|
upload->surfaces = NULL;
|
|
|
|
upload->surfaces_reset = FALSE;
|
|
|
|
upload->surface_width = 0;
|
|
|
|
upload->surface_height = 0;
|
|
|
|
upload->direct_rendering_caps = 0;
|
|
|
|
upload->direct_rendering = G_MAXUINT32;
|
2010-03-15 17:10:56 +00:00
|
|
|
|
|
|
|
/* Override buffer allocator on sink pad */
|
2012-01-03 13:34:09 +00:00
|
|
|
sinkpad = gst_element_get_static_pad(GST_ELEMENT(upload), "sink");
|
2010-03-15 17:10:56 +00:00
|
|
|
gst_pad_set_bufferalloc_function(
|
|
|
|
sinkpad,
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_sinkpad_buffer_alloc
|
2010-03-15 17:10:56 +00:00
|
|
|
);
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_pad_set_query_function(sinkpad, gst_vaapiupload_query);
|
2010-03-15 17:10:56 +00:00
|
|
|
g_object_unref(sinkpad);
|
2011-11-04 20:50:15 +00:00
|
|
|
|
|
|
|
/* Override query on src pad */
|
2012-01-03 13:34:09 +00:00
|
|
|
srcpad = gst_element_get_static_pad(GST_ELEMENT(upload), "src");
|
|
|
|
gst_pad_set_query_function(srcpad, gst_vaapiupload_query);
|
2012-01-03 17:16:35 +00:00
|
|
|
g_object_unref(srcpad);
|
2010-03-15 17:10:56 +00:00
|
|
|
}
|
|
|
|
|
2010-05-12 09:34:37 +00:00
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_start(GstBaseTransform *trans)
|
2010-03-15 17:10:56 +00:00
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload * const upload = GST_VAAPIUPLOAD(trans);
|
2010-03-15 17:10:56 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (!gst_vaapi_ensure_display(upload, &upload->display))
|
2010-03-15 17:10:56 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-05-12 09:34:37 +00:00
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_stop(GstBaseTransform *trans)
|
2010-03-15 17:10:56 +00:00
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload * const upload = GST_VAAPIUPLOAD(trans);
|
2010-03-15 17:10:56 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (upload->display) {
|
|
|
|
g_object_unref(upload->display);
|
|
|
|
upload->display = NULL;
|
2010-03-15 17:10:56 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
2010-03-05 17:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_transform(
|
2010-03-05 17:11:52 +00:00
|
|
|
GstBaseTransform *trans,
|
|
|
|
GstBuffer *inbuf,
|
|
|
|
GstBuffer *outbuf
|
|
|
|
)
|
2010-03-15 17:10:56 +00:00
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload * const upload = GST_VAAPIUPLOAD(trans);
|
2011-09-05 14:20:20 +00:00
|
|
|
GstVaapiVideoBuffer *vbuffer;
|
2010-03-15 17:10:56 +00:00
|
|
|
GstVaapiSurface *surface;
|
|
|
|
GstVaapiImage *image;
|
2011-09-08 11:09:17 +00:00
|
|
|
gboolean success;
|
2010-03-15 17:10:56 +00:00
|
|
|
|
2011-09-05 14:20:20 +00:00
|
|
|
vbuffer = GST_VAAPI_VIDEO_BUFFER(outbuf);
|
2010-03-15 17:10:56 +00:00
|
|
|
surface = gst_vaapi_video_buffer_get_surface(vbuffer);
|
|
|
|
if (!surface)
|
|
|
|
return GST_FLOW_UNEXPECTED;
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (upload->direct_rendering) {
|
2010-03-16 17:57:57 +00:00
|
|
|
if (!GST_VAAPI_IS_VIDEO_BUFFER(inbuf)) {
|
|
|
|
GST_DEBUG("GstVaapiVideoBuffer was expected");
|
|
|
|
return GST_FLOW_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2011-09-05 14:20:20 +00:00
|
|
|
vbuffer = GST_VAAPI_VIDEO_BUFFER(inbuf);
|
|
|
|
image = gst_vaapi_video_buffer_get_image(vbuffer);
|
2010-03-16 17:57:57 +00:00
|
|
|
if (!image)
|
|
|
|
return GST_FLOW_UNEXPECTED;
|
|
|
|
if (!gst_vaapi_image_unmap(image))
|
|
|
|
return GST_FLOW_UNEXPECTED;
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (upload->direct_rendering < 2) {
|
2011-09-08 11:09:17 +00:00
|
|
|
if (!gst_vaapi_surface_put_image(surface, image))
|
|
|
|
goto error_put_image;
|
|
|
|
}
|
2010-03-16 17:57:57 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
image = gst_vaapi_video_pool_get_object(upload->images);
|
2010-03-16 17:57:57 +00:00
|
|
|
if (!image)
|
|
|
|
return GST_FLOW_UNEXPECTED;
|
|
|
|
|
2011-12-12 13:34:03 +00:00
|
|
|
gst_vaapi_image_update_from_buffer(image, inbuf, NULL);
|
2011-09-08 11:09:17 +00:00
|
|
|
success = gst_vaapi_surface_put_image(surface, image);
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapi_video_pool_put_object(upload->images, image);
|
2011-09-08 11:09:17 +00:00
|
|
|
if (!success)
|
|
|
|
goto error_put_image;
|
2010-03-15 17:10:56 +00:00
|
|
|
return GST_FLOW_OK;
|
2011-09-08 11:09:17 +00:00
|
|
|
|
|
|
|
error_put_image:
|
|
|
|
{
|
|
|
|
GST_WARNING("failed to upload %" GST_FOURCC_FORMAT " image "
|
|
|
|
"to surface 0x%08x",
|
|
|
|
GST_FOURCC_ARGS(gst_vaapi_image_get_format(image)),
|
|
|
|
gst_vaapi_surface_get_id(surface));
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2010-03-15 17:10:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_transform_caps(
|
2010-03-15 17:10:56 +00:00
|
|
|
GstBaseTransform *trans,
|
|
|
|
GstPadDirection direction,
|
|
|
|
GstCaps *caps
|
|
|
|
)
|
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload * const upload = GST_VAAPIUPLOAD(trans);
|
2010-03-15 17:10:56 +00:00
|
|
|
GstCaps *out_caps = NULL;
|
|
|
|
GstStructure *structure;
|
|
|
|
const GValue *v_width, *v_height, *v_framerate, *v_par;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_IS_CAPS(caps), NULL);
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure(caps, 0);
|
|
|
|
v_width = gst_structure_get_value(structure, "width");
|
|
|
|
v_height = gst_structure_get_value(structure, "height");
|
|
|
|
v_framerate = gst_structure_get_value(structure, "framerate");
|
|
|
|
v_par = gst_structure_get_value(structure, "pixel-aspect-ratio");
|
|
|
|
|
|
|
|
if (!v_width || !v_height)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (direction == GST_PAD_SINK) {
|
|
|
|
if (!gst_structure_has_name(structure, "video/x-raw-yuv"))
|
|
|
|
return NULL;
|
2012-01-03 13:34:09 +00:00
|
|
|
out_caps = gst_caps_from_string(gst_vaapiupload_vaapi_caps_str);
|
2010-03-15 17:10:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-11-04 21:16:23 +00:00
|
|
|
if (!gst_structure_has_name(structure, GST_VAAPI_SURFACE_CAPS_NAME))
|
2010-03-15 17:10:56 +00:00
|
|
|
return NULL;
|
2012-01-03 13:34:09 +00:00
|
|
|
out_caps = gst_caps_from_string(gst_vaapiupload_yuv_caps_str);
|
|
|
|
if (upload->display) {
|
2010-03-16 08:43:16 +00:00
|
|
|
GstCaps *allowed_caps, *inter_caps;
|
2012-01-03 13:34:09 +00:00
|
|
|
allowed_caps = gst_vaapi_display_get_image_caps(upload->display);
|
2010-03-15 17:10:56 +00:00
|
|
|
if (!allowed_caps)
|
|
|
|
return NULL;
|
2010-03-16 08:43:16 +00:00
|
|
|
inter_caps = gst_caps_intersect(out_caps, allowed_caps);
|
2010-03-15 17:10:56 +00:00
|
|
|
gst_caps_unref(allowed_caps);
|
|
|
|
gst_caps_unref(out_caps);
|
2010-03-16 08:43:16 +00:00
|
|
|
out_caps = inter_caps;
|
2010-03-15 17:10:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure(out_caps, 0);
|
|
|
|
gst_structure_set_value(structure, "width", v_width);
|
|
|
|
gst_structure_set_value(structure, "height", v_height);
|
2011-12-08 14:44:09 +00:00
|
|
|
gst_structure_set(structure, "type", G_TYPE_STRING, "vaapi", NULL);
|
2011-11-04 23:47:25 +00:00
|
|
|
gst_structure_set(structure, "opengl", G_TYPE_BOOLEAN, USE_VAAPI_GLX, NULL);
|
2010-03-15 17:10:56 +00:00
|
|
|
if (v_framerate)
|
|
|
|
gst_structure_set_value(structure, "framerate", v_framerate);
|
|
|
|
if (v_par)
|
|
|
|
gst_structure_set_value(structure, "pixel-aspect-ratio", v_par);
|
|
|
|
return out_caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_ensure_image_pool(GstVaapiUpload *upload, GstCaps *caps)
|
2010-03-15 17:10:56 +00:00
|
|
|
{
|
2010-03-16 17:57:57 +00:00
|
|
|
GstStructure * const structure = gst_caps_get_structure(caps, 0);
|
2010-03-15 17:10:56 +00:00
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
gst_structure_get_int(structure, "width", &width);
|
|
|
|
gst_structure_get_int(structure, "height", &height);
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (width != upload->image_width || height != upload->image_height) {
|
|
|
|
upload->image_width = width;
|
|
|
|
upload->image_height = height;
|
|
|
|
if (upload->images)
|
|
|
|
g_object_unref(upload->images);
|
|
|
|
upload->images = gst_vaapi_image_pool_new(upload->display, caps);
|
|
|
|
if (!upload->images)
|
2010-03-15 17:10:56 +00:00
|
|
|
return FALSE;
|
2012-01-03 13:34:09 +00:00
|
|
|
upload->images_reset = TRUE;
|
2010-03-15 17:10:56 +00:00
|
|
|
}
|
2010-03-16 17:57:57 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_ensure_surface_pool(GstVaapiUpload *upload, GstCaps *caps)
|
2010-03-16 17:57:57 +00:00
|
|
|
{
|
|
|
|
GstStructure * const structure = gst_caps_get_structure(caps, 0);
|
|
|
|
gint width, height;
|
2010-03-15 17:10:56 +00:00
|
|
|
|
|
|
|
gst_structure_get_int(structure, "width", &width);
|
|
|
|
gst_structure_get_int(structure, "height", &height);
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (width != upload->surface_width || height != upload->surface_height) {
|
|
|
|
upload->surface_width = width;
|
|
|
|
upload->surface_height = height;
|
|
|
|
if (upload->surfaces)
|
|
|
|
g_object_unref(upload->surfaces);
|
|
|
|
upload->surfaces = gst_vaapi_surface_pool_new(upload->display, caps);
|
|
|
|
if (!upload->surfaces)
|
2010-03-15 17:10:56 +00:00
|
|
|
return FALSE;
|
2012-01-03 13:34:09 +00:00
|
|
|
upload->surfaces_reset = TRUE;
|
2011-09-08 12:50:24 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_ensure_direct_rendering_caps(
|
|
|
|
GstVaapiUpload *upload,
|
2011-09-08 12:50:24 +00:00
|
|
|
GstCaps *caps
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiSurface *surface;
|
|
|
|
GstVaapiImage *image;
|
|
|
|
GstVaapiImageFormat vaformat;
|
|
|
|
GstVideoFormat vformat;
|
|
|
|
GstStructure *structure;
|
|
|
|
gint width, height;
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (!upload->images_reset && !upload->surfaces_reset)
|
2011-09-08 12:50:24 +00:00
|
|
|
return;
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
upload->images_reset = FALSE;
|
|
|
|
upload->surfaces_reset = FALSE;
|
|
|
|
upload->direct_rendering_caps = 0;
|
2011-09-08 12:50:24 +00:00
|
|
|
|
|
|
|
structure = gst_caps_get_structure(caps, 0);
|
|
|
|
if (!structure)
|
|
|
|
return;
|
|
|
|
gst_structure_get_int(structure, "width", &width);
|
|
|
|
gst_structure_get_int(structure, "height", &height);
|
|
|
|
|
|
|
|
/* Translate from Gst video format to VA image format */
|
|
|
|
if (!gst_video_format_parse_caps(caps, &vformat, NULL, NULL))
|
|
|
|
return;
|
|
|
|
if (!gst_video_format_is_yuv(vformat))
|
|
|
|
return;
|
2011-12-12 17:13:19 +00:00
|
|
|
vaformat = gst_vaapi_image_format_from_video(vformat);
|
2011-09-08 12:50:24 +00:00
|
|
|
if (!vaformat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Check if we can alias sink & output buffers (same data_size) */
|
2012-01-03 13:34:09 +00:00
|
|
|
image = gst_vaapi_video_pool_get_object(upload->images);
|
2011-09-08 12:50:24 +00:00
|
|
|
if (image) {
|
2012-01-03 13:34:09 +00:00
|
|
|
if (upload->direct_rendering_caps == 0 &&
|
2011-09-08 12:50:24 +00:00
|
|
|
(gst_vaapi_image_get_format(image) == vaformat &&
|
|
|
|
gst_vaapi_image_is_linear(image) &&
|
|
|
|
(gst_vaapi_image_get_data_size(image) ==
|
|
|
|
gst_video_format_get_size(vformat, width, height))))
|
2012-01-03 13:34:09 +00:00
|
|
|
upload->direct_rendering_caps = 1;
|
|
|
|
gst_vaapi_video_pool_put_object(upload->images, image);
|
2011-09-08 12:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we can access to the surface pixels directly */
|
2012-01-03 13:34:09 +00:00
|
|
|
surface = gst_vaapi_video_pool_get_object(upload->surfaces);
|
2011-09-08 12:50:24 +00:00
|
|
|
if (surface) {
|
|
|
|
image = gst_vaapi_surface_derive_image(surface);
|
|
|
|
if (image) {
|
|
|
|
if (gst_vaapi_image_map(image)) {
|
2012-01-03 13:34:09 +00:00
|
|
|
if (upload->direct_rendering_caps == 1 &&
|
2011-09-08 12:50:24 +00:00
|
|
|
(gst_vaapi_image_get_format(image) == vaformat &&
|
|
|
|
gst_vaapi_image_is_linear(image) &&
|
|
|
|
(gst_vaapi_image_get_data_size(image) ==
|
|
|
|
gst_video_format_get_size(vformat, width, height))))
|
2012-01-03 13:34:09 +00:00
|
|
|
upload->direct_rendering_caps = 2;
|
2011-09-08 12:50:24 +00:00
|
|
|
gst_vaapi_image_unmap(image);
|
2010-03-18 15:53:50 +00:00
|
|
|
}
|
2011-09-08 12:50:24 +00:00
|
|
|
g_object_unref(image);
|
2010-03-18 15:53:50 +00:00
|
|
|
}
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapi_video_pool_put_object(upload->surfaces, surface);
|
2010-03-15 17:10:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-16 17:57:57 +00:00
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_negotiate_buffers(
|
|
|
|
GstVaapiUpload *upload,
|
2010-03-16 17:57:57 +00:00
|
|
|
GstCaps *incaps,
|
|
|
|
GstCaps *outcaps
|
|
|
|
)
|
|
|
|
{
|
2010-03-19 08:42:51 +00:00
|
|
|
guint dr;
|
2010-03-18 15:58:28 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (!gst_vaapiupload_ensure_image_pool(upload, incaps))
|
2010-03-16 17:57:57 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (!gst_vaapiupload_ensure_surface_pool(upload, outcaps))
|
2010-03-16 17:57:57 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_ensure_direct_rendering_caps(upload, incaps);
|
|
|
|
dr = MIN(upload->direct_rendering, upload->direct_rendering_caps);
|
|
|
|
if (upload->direct_rendering != dr) {
|
|
|
|
upload->direct_rendering = dr;
|
2010-03-19 08:42:51 +00:00
|
|
|
GST_DEBUG("direct-rendering level: %d", dr);
|
2010-03-18 15:58:28 +00:00
|
|
|
}
|
2010-03-18 08:16:59 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_set_caps(
|
2010-03-18 08:16:59 +00:00
|
|
|
GstBaseTransform *trans,
|
|
|
|
GstCaps *incaps,
|
|
|
|
GstCaps *outcaps
|
|
|
|
)
|
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload * const upload = GST_VAAPIUPLOAD(trans);
|
2010-03-18 08:16:59 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (!gst_vaapiupload_negotiate_buffers(upload, incaps, outcaps))
|
2010-03-18 08:16:59 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-03-16 17:57:57 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-15 17:10:56 +00:00
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_get_unit_size(
|
2010-03-15 17:10:56 +00:00
|
|
|
GstBaseTransform *trans,
|
|
|
|
GstCaps *caps,
|
|
|
|
guint *size
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstStructure * const structure = gst_caps_get_structure(caps, 0);
|
|
|
|
GstVideoFormat format;
|
|
|
|
gint width, height;
|
|
|
|
|
2011-11-04 21:16:23 +00:00
|
|
|
if (gst_structure_has_name(structure, GST_VAAPI_SURFACE_CAPS_NAME))
|
2010-03-15 17:10:56 +00:00
|
|
|
*size = 0;
|
|
|
|
else {
|
|
|
|
if (!gst_video_format_parse_caps(caps, &format, &width, &height))
|
|
|
|
return FALSE;
|
|
|
|
*size = gst_video_format_get_size(format, width, height);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_buffer_alloc(
|
2010-03-15 17:10:56 +00:00
|
|
|
GstBaseTransform *trans,
|
|
|
|
guint size,
|
|
|
|
GstCaps *caps,
|
|
|
|
GstBuffer **pbuf
|
|
|
|
)
|
2010-03-05 17:11:52 +00:00
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload * const upload = GST_VAAPIUPLOAD(trans);
|
2010-03-16 17:57:57 +00:00
|
|
|
GstBuffer *buffer = NULL;
|
2010-03-18 15:53:50 +00:00
|
|
|
GstVaapiImage *image = NULL;
|
2011-09-05 14:20:20 +00:00
|
|
|
GstVaapiSurface *surface = NULL;
|
|
|
|
GstVaapiVideoBuffer *vbuffer;
|
2010-03-16 17:57:57 +00:00
|
|
|
|
2010-03-19 08:42:51 +00:00
|
|
|
/* Check if we can use direct-rendering */
|
2012-01-03 13:34:09 +00:00
|
|
|
if (!gst_vaapiupload_negotiate_buffers(upload, caps, caps))
|
2010-03-16 17:57:57 +00:00
|
|
|
goto error;
|
2012-01-03 13:34:09 +00:00
|
|
|
if (!upload->direct_rendering)
|
2010-03-16 17:57:57 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
switch (upload->direct_rendering) {
|
2010-03-19 08:42:51 +00:00
|
|
|
case 2:
|
2012-01-03 13:34:09 +00:00
|
|
|
buffer = gst_vaapi_video_buffer_new_from_pool(upload->surfaces);
|
2011-09-05 14:20:20 +00:00
|
|
|
if (!buffer)
|
|
|
|
goto error;
|
|
|
|
vbuffer = GST_VAAPI_VIDEO_BUFFER(buffer);
|
|
|
|
|
2010-03-19 08:42:51 +00:00
|
|
|
surface = gst_vaapi_video_buffer_get_surface(vbuffer);
|
|
|
|
image = gst_vaapi_surface_derive_image(surface);
|
2011-09-06 16:34:33 +00:00
|
|
|
if (image && gst_vaapi_image_get_data_size(image) == size) {
|
2010-03-18 15:53:50 +00:00
|
|
|
gst_vaapi_video_buffer_set_image(vbuffer, image);
|
2011-09-06 15:47:10 +00:00
|
|
|
gst_object_unref(image); /* video buffer owns an extra reference */
|
2010-03-19 08:42:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-09-05 14:20:20 +00:00
|
|
|
|
2010-03-19 08:42:51 +00:00
|
|
|
/* We can't use the derive-image optimization. Disable it. */
|
2012-01-03 13:34:09 +00:00
|
|
|
upload->direct_rendering = 1;
|
2011-09-05 14:20:20 +00:00
|
|
|
gst_buffer_unref(buffer);
|
|
|
|
buffer = NULL;
|
|
|
|
|
2010-03-19 08:42:51 +00:00
|
|
|
case 1:
|
2012-01-03 13:34:09 +00:00
|
|
|
buffer = gst_vaapi_video_buffer_new_from_pool(upload->images);
|
2011-09-05 14:20:20 +00:00
|
|
|
if (!buffer)
|
2010-03-18 15:53:50 +00:00
|
|
|
goto error;
|
2011-09-05 14:20:20 +00:00
|
|
|
vbuffer = GST_VAAPI_VIDEO_BUFFER(buffer);
|
|
|
|
|
|
|
|
image = gst_vaapi_video_buffer_get_image(vbuffer);
|
2010-03-19 08:42:51 +00:00
|
|
|
break;
|
2010-03-18 15:53:50 +00:00
|
|
|
}
|
2010-03-16 17:57:57 +00:00
|
|
|
g_assert(image);
|
|
|
|
|
|
|
|
if (!gst_vaapi_image_map(image))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
GST_BUFFER_DATA(buffer) = gst_vaapi_image_get_plane(image, 0);
|
|
|
|
GST_BUFFER_SIZE(buffer) = gst_vaapi_image_get_data_size(image);
|
|
|
|
|
|
|
|
gst_buffer_set_caps(buffer, caps);
|
|
|
|
*pbuf = buffer;
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* We can't use the inout-buffers optimization. Disable it. */
|
2011-09-05 14:20:20 +00:00
|
|
|
GST_DEBUG("disable in/out buffer optimization");
|
2010-03-16 17:57:57 +00:00
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref(buffer);
|
2012-01-03 13:34:09 +00:00
|
|
|
upload->direct_rendering = 0;
|
2010-03-05 17:11:52 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-15 17:10:56 +00:00
|
|
|
static GstFlowReturn
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_sinkpad_buffer_alloc(
|
2010-03-15 17:10:56 +00:00
|
|
|
GstPad *pad,
|
|
|
|
guint64 offset,
|
|
|
|
guint size,
|
|
|
|
GstCaps *caps,
|
|
|
|
GstBuffer **pbuf
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstBaseTransform *trans;
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
|
|
|
trans = GST_BASE_TRANSFORM(gst_pad_get_parent_element(pad));
|
|
|
|
if (!trans)
|
|
|
|
return GST_FLOW_UNEXPECTED;
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
ret = gst_vaapiupload_buffer_alloc(trans, size, caps, pbuf);
|
2010-03-15 17:10:56 +00:00
|
|
|
g_object_unref(trans);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_prepare_output_buffer(
|
2010-03-15 17:10:56 +00:00
|
|
|
GstBaseTransform *trans,
|
|
|
|
GstBuffer *inbuf,
|
|
|
|
gint size,
|
|
|
|
GstCaps *caps,
|
|
|
|
GstBuffer **poutbuf
|
|
|
|
)
|
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload * const upload = GST_VAAPIUPLOAD(trans);
|
2011-09-05 14:20:20 +00:00
|
|
|
GstBuffer *buffer = NULL;
|
2010-03-15 17:10:56 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (upload->direct_rendering == 2) {
|
2011-09-05 14:20:20 +00:00
|
|
|
if (GST_VAAPI_IS_VIDEO_BUFFER(inbuf)) {
|
|
|
|
buffer = gst_vaapi_video_buffer_new_from_buffer(inbuf);
|
|
|
|
GST_BUFFER_SIZE(buffer) = size;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GST_DEBUG("upstream element destroyed our in/out buffer");
|
2012-01-03 13:34:09 +00:00
|
|
|
upload->direct_rendering = 1;
|
2010-03-18 08:45:57 +00:00
|
|
|
}
|
2011-09-05 14:20:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!buffer) {
|
2012-01-03 13:34:09 +00:00
|
|
|
buffer = gst_vaapi_video_buffer_new_from_pool(upload->surfaces);
|
2010-03-16 17:57:57 +00:00
|
|
|
if (!buffer)
|
|
|
|
return GST_FLOW_UNEXPECTED;
|
|
|
|
}
|
2010-03-15 17:10:56 +00:00
|
|
|
|
|
|
|
gst_buffer_set_caps(buffer, caps);
|
|
|
|
*poutbuf = buffer;
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2011-11-04 20:50:15 +00:00
|
|
|
|
|
|
|
static gboolean
|
2012-01-03 13:34:09 +00:00
|
|
|
gst_vaapiupload_query(GstPad *pad, GstQuery *query)
|
2011-11-04 20:50:15 +00:00
|
|
|
{
|
2012-01-03 13:34:09 +00:00
|
|
|
GstVaapiUpload *upload = GST_VAAPIUPLOAD (gst_pad_get_parent_element (pad));
|
2011-11-04 20:50:15 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
GST_DEBUG ("sharing display %p", upload->display);
|
2011-11-04 20:50:15 +00:00
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
if (gst_vaapi_reply_to_query (query, upload->display))
|
2011-11-04 20:50:15 +00:00
|
|
|
res = TRUE;
|
|
|
|
else
|
|
|
|
res = gst_pad_query_default (pad, query);
|
|
|
|
|
2012-01-03 13:34:09 +00:00
|
|
|
g_object_unref (upload);
|
2011-11-04 20:50:15 +00:00
|
|
|
return res;
|
|
|
|
}
|