mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 16:08:51 +00:00
plugins: re-indent all video processing related source code.
This commit is contained in:
parent
cf352336b3
commit
9c888b8b8e
4 changed files with 1747 additions and 1794 deletions
File diff suppressed because it is too large
Load diff
|
@ -31,32 +31,23 @@
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define GST_TYPE_VAAPIPOSTPROC \
|
#define GST_TYPE_VAAPIPOSTPROC \
|
||||||
(gst_vaapipostproc_get_type())
|
(gst_vaapipostproc_get_type ())
|
||||||
|
#define GST_VAAPIPOSTPROC(obj) \
|
||||||
#define GST_VAAPIPOSTPROC(obj) \
|
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VAAPIPOSTPROC, GstVaapiPostproc))
|
||||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
|
#define GST_VAAPIPOSTPROC_CLASS(klass) \
|
||||||
GST_TYPE_VAAPIPOSTPROC, \
|
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VAAPIPOSTPROC, \
|
||||||
GstVaapiPostproc))
|
GstVaapiPostprocClass))
|
||||||
|
|
||||||
#define GST_VAAPIPOSTPROC_CLASS(klass) \
|
|
||||||
(G_TYPE_CHECK_CLASS_CAST((klass), \
|
|
||||||
GST_TYPE_VAAPIPOSTPROC, \
|
|
||||||
GstVaapiPostprocClass))
|
|
||||||
|
|
||||||
#define GST_IS_VAAPIPOSTPROC(obj) \
|
#define GST_IS_VAAPIPOSTPROC(obj) \
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_VAAPIPOSTPROC))
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_VAAPIPOSTPROC))
|
||||||
|
|
||||||
#define GST_IS_VAAPIPOSTPROC_CLASS(klass) \
|
#define GST_IS_VAAPIPOSTPROC_CLASS(klass) \
|
||||||
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_VAAPIPOSTPROC))
|
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_VAAPIPOSTPROC))
|
||||||
|
#define GST_VAAPIPOSTPROC_GET_CLASS(obj) \
|
||||||
|
(G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_VAAPIPOSTPROC, \
|
||||||
|
GstVaapiPostprocClass))
|
||||||
|
|
||||||
#define GST_VAAPIPOSTPROC_GET_CLASS(obj) \
|
typedef struct _GstVaapiPostproc GstVaapiPostproc;
|
||||||
(G_TYPE_INSTANCE_GET_CLASS((obj), \
|
typedef struct _GstVaapiPostprocClass GstVaapiPostprocClass;
|
||||||
GST_TYPE_VAAPIPOSTPROC, \
|
typedef struct _GstVaapiDeinterlaceState GstVaapiDeinterlaceState;
|
||||||
GstVaapiPostprocClass))
|
|
||||||
|
|
||||||
typedef struct _GstVaapiPostproc GstVaapiPostproc;
|
|
||||||
typedef struct _GstVaapiPostprocClass GstVaapiPostprocClass;
|
|
||||||
typedef struct _GstVaapiDeinterlaceState GstVaapiDeinterlaceState;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GstVaapiDeinterlaceMode:
|
* GstVaapiDeinterlaceMode:
|
||||||
|
@ -64,10 +55,11 @@ typedef struct _GstVaapiDeinterlaceState GstVaapiDeinterlaceState;
|
||||||
* @GST_VAAPI_DEINTERLACE_MODE_INTERLACED: Force deinterlacing.
|
* @GST_VAAPI_DEINTERLACE_MODE_INTERLACED: Force deinterlacing.
|
||||||
* @GST_VAAPI_DEINTERLACE_MODE_DISABLED: Never perform deinterlacing.
|
* @GST_VAAPI_DEINTERLACE_MODE_DISABLED: Never perform deinterlacing.
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum
|
||||||
GST_VAAPI_DEINTERLACE_MODE_AUTO = 0,
|
{
|
||||||
GST_VAAPI_DEINTERLACE_MODE_INTERLACED,
|
GST_VAAPI_DEINTERLACE_MODE_AUTO = 0,
|
||||||
GST_VAAPI_DEINTERLACE_MODE_DISABLED,
|
GST_VAAPI_DEINTERLACE_MODE_INTERLACED,
|
||||||
|
GST_VAAPI_DEINTERLACE_MODE_DISABLED,
|
||||||
} GstVaapiDeinterlaceMode;
|
} GstVaapiDeinterlaceMode;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -97,20 +89,21 @@ typedef enum {
|
||||||
*
|
*
|
||||||
* The set of operations that are to be performed for each frame.
|
* The set of operations that are to be performed for each frame.
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum
|
||||||
GST_VAAPI_POSTPROC_FLAG_FORMAT = 1 << GST_VAAPI_FILTER_OP_FORMAT,
|
{
|
||||||
GST_VAAPI_POSTPROC_FLAG_DENOISE = 1 << GST_VAAPI_FILTER_OP_DENOISE,
|
GST_VAAPI_POSTPROC_FLAG_FORMAT = 1 << GST_VAAPI_FILTER_OP_FORMAT,
|
||||||
GST_VAAPI_POSTPROC_FLAG_SHARPEN = 1 << GST_VAAPI_FILTER_OP_SHARPEN,
|
GST_VAAPI_POSTPROC_FLAG_DENOISE = 1 << GST_VAAPI_FILTER_OP_DENOISE,
|
||||||
GST_VAAPI_POSTPROC_FLAG_HUE = 1 << GST_VAAPI_FILTER_OP_HUE,
|
GST_VAAPI_POSTPROC_FLAG_SHARPEN = 1 << GST_VAAPI_FILTER_OP_SHARPEN,
|
||||||
GST_VAAPI_POSTPROC_FLAG_SATURATION = 1 << GST_VAAPI_FILTER_OP_SATURATION,
|
GST_VAAPI_POSTPROC_FLAG_HUE = 1 << GST_VAAPI_FILTER_OP_HUE,
|
||||||
GST_VAAPI_POSTPROC_FLAG_BRIGHTNESS = 1 << GST_VAAPI_FILTER_OP_BRIGHTNESS,
|
GST_VAAPI_POSTPROC_FLAG_SATURATION = 1 << GST_VAAPI_FILTER_OP_SATURATION,
|
||||||
GST_VAAPI_POSTPROC_FLAG_CONTRAST = 1 << GST_VAAPI_FILTER_OP_CONTRAST,
|
GST_VAAPI_POSTPROC_FLAG_BRIGHTNESS = 1 << GST_VAAPI_FILTER_OP_BRIGHTNESS,
|
||||||
GST_VAAPI_POSTPROC_FLAG_DEINTERLACE = 1 << GST_VAAPI_FILTER_OP_DEINTERLACING,
|
GST_VAAPI_POSTPROC_FLAG_CONTRAST = 1 << GST_VAAPI_FILTER_OP_CONTRAST,
|
||||||
GST_VAAPI_POSTPROC_FLAG_SCALE = 1 << GST_VAAPI_FILTER_OP_SCALING,
|
GST_VAAPI_POSTPROC_FLAG_DEINTERLACE = 1 << GST_VAAPI_FILTER_OP_DEINTERLACING,
|
||||||
|
GST_VAAPI_POSTPROC_FLAG_SCALE = 1 << GST_VAAPI_FILTER_OP_SCALING,
|
||||||
|
|
||||||
/* Additional custom flags */
|
/* Additional custom flags */
|
||||||
GST_VAAPI_POSTPROC_FLAG_CUSTOM = 1 << 20,
|
GST_VAAPI_POSTPROC_FLAG_CUSTOM = 1 << 20,
|
||||||
GST_VAAPI_POSTPROC_FLAG_SIZE = GST_VAAPI_POSTPROC_FLAG_CUSTOM,
|
GST_VAAPI_POSTPROC_FLAG_SIZE = GST_VAAPI_POSTPROC_FLAG_CUSTOM,
|
||||||
} GstVaapiPostprocFlags;
|
} GstVaapiPostprocFlags;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -124,65 +117,68 @@ typedef enum {
|
||||||
*
|
*
|
||||||
* Context used to maintain deinterlacing state.
|
* Context used to maintain deinterlacing state.
|
||||||
*/
|
*/
|
||||||
struct _GstVaapiDeinterlaceState {
|
struct _GstVaapiDeinterlaceState
|
||||||
GstBuffer *buffers[GST_VAAPI_DEINTERLACE_MAX_REFERENCES];
|
{
|
||||||
guint buffers_index;
|
GstBuffer *buffers[GST_VAAPI_DEINTERLACE_MAX_REFERENCES];
|
||||||
GstVaapiSurface *surfaces[GST_VAAPI_DEINTERLACE_MAX_REFERENCES];
|
guint buffers_index;
|
||||||
guint num_surfaces;
|
GstVaapiSurface *surfaces[GST_VAAPI_DEINTERLACE_MAX_REFERENCES];
|
||||||
guint deint : 1;
|
guint num_surfaces;
|
||||||
guint tff : 1;
|
guint deint:1;
|
||||||
|
guint tff:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstVaapiPostproc {
|
struct _GstVaapiPostproc
|
||||||
/*< private >*/
|
{
|
||||||
GstVaapiPluginBase parent_instance;
|
/*< private >*/
|
||||||
|
GstVaapiPluginBase parent_instance;
|
||||||
|
|
||||||
GstVaapiFilter *filter;
|
GstVaapiFilter *filter;
|
||||||
GPtrArray *filter_ops;
|
GPtrArray *filter_ops;
|
||||||
GstVaapiVideoPool *filter_pool;
|
GstVaapiVideoPool *filter_pool;
|
||||||
GstVideoInfo filter_pool_info;
|
GstVideoInfo filter_pool_info;
|
||||||
gboolean filter_pool_active;
|
gboolean filter_pool_active;
|
||||||
GArray *filter_formats;
|
GArray *filter_formats;
|
||||||
GstVideoFormat format; /* output video format (encoded) */
|
GstVideoFormat format; /* output video format (encoded) */
|
||||||
guint width;
|
guint width;
|
||||||
guint height;
|
guint height;
|
||||||
guint flags;
|
guint flags;
|
||||||
|
|
||||||
GstCaps *allowed_sinkpad_caps;
|
GstCaps *allowed_sinkpad_caps;
|
||||||
GstVideoInfo sinkpad_info;
|
GstVideoInfo sinkpad_info;
|
||||||
GstCaps *allowed_srcpad_caps;
|
GstCaps *allowed_srcpad_caps;
|
||||||
GstVideoInfo srcpad_info;
|
GstVideoInfo srcpad_info;
|
||||||
|
|
||||||
/* Deinterlacing */
|
/* Deinterlacing */
|
||||||
GstVaapiDeinterlaceMode deinterlace_mode;
|
GstVaapiDeinterlaceMode deinterlace_mode;
|
||||||
GstVaapiDeinterlaceMethod deinterlace_method;
|
GstVaapiDeinterlaceMethod deinterlace_method;
|
||||||
GstVaapiDeinterlaceState deinterlace_state;
|
GstVaapiDeinterlaceState deinterlace_state;
|
||||||
GstClockTime field_duration;
|
GstClockTime field_duration;
|
||||||
|
|
||||||
/* Basic filter values */
|
/* Basic filter values */
|
||||||
gfloat denoise_level;
|
gfloat denoise_level;
|
||||||
gfloat sharpen_level;
|
gfloat sharpen_level;
|
||||||
|
|
||||||
/* Color balance filter values */
|
/* Color balance filter values */
|
||||||
GstVaapiScaleMethod scale_method;
|
GstVaapiScaleMethod scale_method;
|
||||||
gfloat hue;
|
gfloat hue;
|
||||||
gfloat saturation;
|
gfloat saturation;
|
||||||
gfloat brightness;
|
gfloat brightness;
|
||||||
gfloat contrast;
|
gfloat contrast;
|
||||||
|
|
||||||
guint get_va_surfaces : 1;
|
guint get_va_surfaces:1;
|
||||||
guint has_vpp : 1;
|
guint has_vpp:1;
|
||||||
guint use_vpp : 1;
|
guint use_vpp:1;
|
||||||
guint keep_aspect : 1;
|
guint keep_aspect:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstVaapiPostprocClass {
|
struct _GstVaapiPostprocClass
|
||||||
/*< private >*/
|
{
|
||||||
GstVaapiPluginBaseClass parent_class;
|
/*< private >*/
|
||||||
|
GstVaapiPluginBaseClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType
|
GType
|
||||||
gst_vaapipostproc_get_type(void) G_GNUC_CONST;
|
gst_vaapipostproc_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -36,475 +36,464 @@
|
||||||
#define GST_HELPER_NAME "vaapiupload"
|
#define GST_HELPER_NAME "vaapiupload"
|
||||||
#define GST_HELPER_DESC "VA-API video uploader"
|
#define GST_HELPER_DESC "VA-API video uploader"
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapi_uploader);
|
GST_DEBUG_CATEGORY_STATIC (gst_debug_vaapi_uploader);
|
||||||
#define GST_CAT_DEFAULT gst_debug_vaapi_uploader
|
#define GST_CAT_DEFAULT gst_debug_vaapi_uploader
|
||||||
|
|
||||||
G_DEFINE_TYPE(GstVaapiUploader, gst_vaapi_uploader, G_TYPE_OBJECT)
|
G_DEFINE_TYPE (GstVaapiUploader, gst_vaapi_uploader, G_TYPE_OBJECT);
|
||||||
|
|
||||||
#define GST_VAAPI_UPLOADER_CAST(obj) \
|
#define GST_VAAPI_UPLOADER_CAST(obj) \
|
||||||
((GstVaapiUploader *)(obj))
|
((GstVaapiUploader *)(obj))
|
||||||
|
#define GST_VAAPI_UPLOADER_GET_PRIVATE(obj) \
|
||||||
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_VAAPI_TYPE_UPLOADER, \
|
||||||
|
GstVaapiUploaderPrivate))
|
||||||
|
|
||||||
#define GST_VAAPI_UPLOADER_GET_PRIVATE(obj) \
|
struct _GstVaapiUploaderPrivate
|
||||||
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
|
{
|
||||||
GST_VAAPI_TYPE_UPLOADER, \
|
GstVaapiDisplay *display;
|
||||||
GstVaapiUploaderPrivate))
|
GstCaps *allowed_caps;
|
||||||
|
GstVaapiVideoPool *images;
|
||||||
struct _GstVaapiUploaderPrivate {
|
GstVideoInfo image_info;
|
||||||
GstVaapiDisplay *display;
|
GstVaapiVideoPool *surfaces;
|
||||||
GstCaps *allowed_caps;
|
GstVideoInfo surface_info;
|
||||||
GstVaapiVideoPool *images;
|
guint direct_rendering;
|
||||||
GstVideoInfo image_info;
|
|
||||||
GstVaapiVideoPool *surfaces;
|
|
||||||
GstVideoInfo surface_info;
|
|
||||||
guint direct_rendering;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
PROP_0,
|
{
|
||||||
|
PROP_0,
|
||||||
|
|
||||||
PROP_DISPLAY,
|
PROP_DISPLAY,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vaapi_uploader_destroy(GstVaapiUploader *uploader)
|
gst_vaapi_uploader_destroy (GstVaapiUploader * uploader)
|
||||||
{
|
{
|
||||||
GstVaapiUploaderPrivate * const priv = uploader->priv;
|
GstVaapiUploaderPrivate *const priv = uploader->priv;
|
||||||
|
|
||||||
gst_caps_replace(&priv->allowed_caps, NULL);
|
gst_caps_replace (&priv->allowed_caps, NULL);
|
||||||
gst_vaapi_video_pool_replace(&priv->images, NULL);
|
gst_vaapi_video_pool_replace (&priv->images, NULL);
|
||||||
gst_vaapi_video_pool_replace(&priv->surfaces, NULL);
|
gst_vaapi_video_pool_replace (&priv->surfaces, NULL);
|
||||||
gst_vaapi_display_replace(&priv->display, NULL);
|
gst_vaapi_display_replace (&priv->display, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ensure_display(GstVaapiUploader *uploader, GstVaapiDisplay *display)
|
ensure_display (GstVaapiUploader * uploader, GstVaapiDisplay * display)
|
||||||
{
|
{
|
||||||
GstVaapiUploaderPrivate * const priv = uploader->priv;
|
GstVaapiUploaderPrivate *const priv = uploader->priv;
|
||||||
|
|
||||||
gst_vaapi_display_replace(&priv->display, display);
|
gst_vaapi_display_replace (&priv->display, display);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
ensure_image (GstVaapiImage * image)
|
||||||
|
{
|
||||||
|
guint i, num_planes, width, height;
|
||||||
|
|
||||||
|
/* Make the image fully dirty */
|
||||||
|
if (!gst_vaapi_image_map (image))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
gst_vaapi_image_get_size (image, &width, &height);
|
||||||
|
|
||||||
|
num_planes = gst_vaapi_image_get_plane_count (image);
|
||||||
|
for (i = 0; i < num_planes; i++) {
|
||||||
|
guchar *const plane = gst_vaapi_image_get_plane (image, i);
|
||||||
|
if (plane)
|
||||||
|
memset (plane, 0, gst_vaapi_image_get_pitch (image, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gst_vaapi_image_unmap (image))
|
||||||
|
gst_vaapi_image_unmap (image);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
ensure_allowed_caps (GstVaapiUploader * uploader)
|
||||||
|
{
|
||||||
|
GstVaapiUploaderPrivate *const priv = uploader->priv;
|
||||||
|
GstVaapiSurface *surface = NULL;
|
||||||
|
GArray *formats = NULL, *out_formats = NULL;
|
||||||
|
GstCaps *out_caps;
|
||||||
|
guint i;
|
||||||
|
gboolean success = FALSE;
|
||||||
|
|
||||||
|
enum
|
||||||
|
{ WIDTH = 64, HEIGHT = 64 };
|
||||||
|
|
||||||
|
if (priv->allowed_caps)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
formats = gst_vaapi_display_get_image_formats (priv->display);
|
||||||
ensure_image(GstVaapiImage *image)
|
if (!formats)
|
||||||
{
|
goto cleanup;
|
||||||
guint i, num_planes, width, height;
|
|
||||||
|
|
||||||
/* Make the image fully dirty */
|
out_formats = g_array_sized_new (FALSE, FALSE, sizeof (GstVideoFormat),
|
||||||
if (!gst_vaapi_image_map(image))
|
formats->len);
|
||||||
return FALSE;
|
if (!out_formats)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
gst_vaapi_image_get_size(image, &width, &height);
|
surface = gst_vaapi_surface_new (priv->display,
|
||||||
|
GST_VAAPI_CHROMA_TYPE_YUV420, WIDTH, HEIGHT);
|
||||||
|
if (!surface)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
num_planes = gst_vaapi_image_get_plane_count(image);
|
for (i = 0; i < formats->len; i++) {
|
||||||
for (i = 0; i < num_planes; i++) {
|
const GstVideoFormat format = g_array_index (formats, GstVideoFormat, i);
|
||||||
guchar * const plane = gst_vaapi_image_get_plane(image, i);
|
GstVaapiImage *image;
|
||||||
if (plane)
|
|
||||||
memset(plane, 0, gst_vaapi_image_get_pitch(image, i));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gst_vaapi_image_unmap(image))
|
if (format == GST_VIDEO_FORMAT_UNKNOWN)
|
||||||
gst_vaapi_image_unmap(image);
|
continue;
|
||||||
return TRUE;
|
image = gst_vaapi_image_new (priv->display, format, WIDTH, HEIGHT);
|
||||||
}
|
if (!image)
|
||||||
|
continue;
|
||||||
|
if (ensure_image (image) && gst_vaapi_surface_put_image (surface, image))
|
||||||
|
g_array_append_val (out_formats, format);
|
||||||
|
gst_vaapi_object_unref (image);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
out_caps = gst_vaapi_video_format_new_template_caps_from_list (out_formats);
|
||||||
ensure_allowed_caps(GstVaapiUploader *uploader)
|
if (!out_caps)
|
||||||
{
|
goto cleanup;
|
||||||
GstVaapiUploaderPrivate * const priv = uploader->priv;
|
|
||||||
GstVaapiSurface *surface = NULL;
|
|
||||||
GArray *formats = NULL, *out_formats = NULL;
|
|
||||||
GstCaps *out_caps;
|
|
||||||
guint i;
|
|
||||||
gboolean success = FALSE;
|
|
||||||
|
|
||||||
enum { WIDTH = 64, HEIGHT = 64 };
|
gst_caps_replace (&priv->allowed_caps, out_caps);
|
||||||
|
gst_caps_unref (out_caps);
|
||||||
if (priv->allowed_caps)
|
success = TRUE;
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
formats = gst_vaapi_display_get_image_formats(priv->display);
|
|
||||||
if (!formats)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
out_formats = g_array_sized_new(FALSE, FALSE, sizeof(GstVideoFormat),
|
|
||||||
formats->len);
|
|
||||||
if (!out_formats)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
surface = gst_vaapi_surface_new(priv->display,
|
|
||||||
GST_VAAPI_CHROMA_TYPE_YUV420, WIDTH, HEIGHT);
|
|
||||||
if (!surface)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
for (i = 0; i < formats->len; i++) {
|
|
||||||
const GstVideoFormat format =
|
|
||||||
g_array_index(formats, GstVideoFormat, i);
|
|
||||||
GstVaapiImage *image;
|
|
||||||
|
|
||||||
if (format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
||||||
continue;
|
|
||||||
image = gst_vaapi_image_new(priv->display, format, WIDTH, HEIGHT);
|
|
||||||
if (!image)
|
|
||||||
continue;
|
|
||||||
if (ensure_image(image) && gst_vaapi_surface_put_image(surface, image))
|
|
||||||
g_array_append_val(out_formats, format);
|
|
||||||
gst_vaapi_object_unref(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
out_caps = gst_vaapi_video_format_new_template_caps_from_list(out_formats);
|
|
||||||
if (!out_caps)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
gst_caps_replace(&priv->allowed_caps, out_caps);
|
|
||||||
gst_caps_unref(out_caps);
|
|
||||||
success = TRUE;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (out_formats)
|
if (out_formats)
|
||||||
g_array_unref(out_formats);
|
g_array_unref (out_formats);
|
||||||
if (formats)
|
if (formats)
|
||||||
g_array_unref(formats);
|
g_array_unref (formats);
|
||||||
if (surface)
|
if (surface)
|
||||||
gst_vaapi_object_unref(surface);
|
gst_vaapi_object_unref (surface);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ensure_image_pool(GstVaapiUploader *uploader, GstCaps *caps,
|
ensure_image_pool (GstVaapiUploader * uploader, GstCaps * caps,
|
||||||
gboolean *caps_changed_ptr)
|
gboolean * caps_changed_ptr)
|
||||||
{
|
{
|
||||||
GstVaapiUploaderPrivate * const priv = uploader->priv;
|
GstVaapiUploaderPrivate *const priv = uploader->priv;
|
||||||
GstVaapiVideoPool *pool;
|
GstVaapiVideoPool *pool;
|
||||||
GstVideoInfo vi;
|
GstVideoInfo vi;
|
||||||
GstVideoFormat format;
|
GstVideoFormat format;
|
||||||
guint width, height;
|
guint width, height;
|
||||||
|
|
||||||
if (!gst_video_info_from_caps(&vi, caps))
|
if (!gst_video_info_from_caps (&vi, caps))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
format = GST_VIDEO_INFO_FORMAT(&vi);
|
format = GST_VIDEO_INFO_FORMAT (&vi);
|
||||||
width = GST_VIDEO_INFO_WIDTH(&vi);
|
width = GST_VIDEO_INFO_WIDTH (&vi);
|
||||||
height = GST_VIDEO_INFO_HEIGHT(&vi);
|
height = GST_VIDEO_INFO_HEIGHT (&vi);
|
||||||
|
|
||||||
*caps_changed_ptr =
|
*caps_changed_ptr =
|
||||||
format != GST_VIDEO_INFO_FORMAT(&priv->image_info) ||
|
format != GST_VIDEO_INFO_FORMAT (&priv->image_info) ||
|
||||||
width != GST_VIDEO_INFO_WIDTH(&priv->image_info) ||
|
width != GST_VIDEO_INFO_WIDTH (&priv->image_info) ||
|
||||||
height != GST_VIDEO_INFO_HEIGHT(&priv->image_info);
|
height != GST_VIDEO_INFO_HEIGHT (&priv->image_info);
|
||||||
if (!*caps_changed_ptr)
|
if (!*caps_changed_ptr)
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
pool = gst_vaapi_image_pool_new(priv->display, &vi);
|
|
||||||
if (!pool)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
gst_video_info_set_format(&priv->image_info, format, width, height);
|
|
||||||
gst_vaapi_video_pool_replace(&priv->images, pool);
|
|
||||||
gst_vaapi_video_pool_unref(pool);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
pool = gst_vaapi_image_pool_new (priv->display, &vi);
|
||||||
|
if (!pool)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
gst_video_info_set_format (&priv->image_info, format, width, height);
|
||||||
|
gst_vaapi_video_pool_replace (&priv->images, pool);
|
||||||
|
gst_vaapi_video_pool_unref (pool);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ensure_surface_pool(GstVaapiUploader *uploader, GstCaps *caps,
|
ensure_surface_pool (GstVaapiUploader * uploader, GstCaps * caps,
|
||||||
gboolean *caps_changed_ptr)
|
gboolean * caps_changed_ptr)
|
||||||
{
|
{
|
||||||
GstVaapiUploaderPrivate * const priv = uploader->priv;
|
GstVaapiUploaderPrivate *const priv = uploader->priv;
|
||||||
GstVaapiVideoPool *pool;
|
GstVaapiVideoPool *pool;
|
||||||
GstVideoInfo vi;
|
GstVideoInfo vi;
|
||||||
GstVideoFormat format;
|
GstVideoFormat format;
|
||||||
guint width, height;
|
guint width, height;
|
||||||
|
|
||||||
if (!gst_video_info_from_caps(&vi, caps))
|
if (!gst_video_info_from_caps (&vi, caps))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
format = GST_VIDEO_INFO_FORMAT(&vi);
|
format = GST_VIDEO_INFO_FORMAT (&vi);
|
||||||
width = GST_VIDEO_INFO_WIDTH(&vi);
|
width = GST_VIDEO_INFO_WIDTH (&vi);
|
||||||
height = GST_VIDEO_INFO_HEIGHT(&vi);
|
height = GST_VIDEO_INFO_HEIGHT (&vi);
|
||||||
|
|
||||||
*caps_changed_ptr =
|
*caps_changed_ptr =
|
||||||
format != GST_VIDEO_INFO_FORMAT(&priv->surface_info) ||
|
format != GST_VIDEO_INFO_FORMAT (&priv->surface_info) ||
|
||||||
width != GST_VIDEO_INFO_WIDTH(&priv->surface_info) ||
|
width != GST_VIDEO_INFO_WIDTH (&priv->surface_info) ||
|
||||||
height != GST_VIDEO_INFO_HEIGHT(&priv->surface_info);
|
height != GST_VIDEO_INFO_HEIGHT (&priv->surface_info);
|
||||||
if (!*caps_changed_ptr)
|
if (!*caps_changed_ptr)
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
/* Always try to downsample source buffers to YUV 4:2:0 format as
|
|
||||||
this saves memory bandwidth for further rendering */
|
|
||||||
/* XXX: this also means that visual quality is not preserved */
|
|
||||||
if (format != GST_VIDEO_FORMAT_ENCODED) {
|
|
||||||
const GstVaapiChromaType chroma_type =
|
|
||||||
gst_vaapi_video_format_get_chroma_type(format);
|
|
||||||
if (chroma_type != GST_VAAPI_CHROMA_TYPE_YUV420) {
|
|
||||||
const GstVideoFormat image_format =
|
|
||||||
GST_VIDEO_INFO_FORMAT(&priv->image_info);
|
|
||||||
GST_INFO("use implicit conversion of %s buffers to NV12 surfaces",
|
|
||||||
gst_video_format_to_string(image_format));
|
|
||||||
gst_video_info_set_format(&vi, GST_VIDEO_FORMAT_NV12, width, height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pool = gst_vaapi_surface_pool_new(priv->display, &vi);
|
|
||||||
if (!pool)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
gst_video_info_set_format(&priv->surface_info, format, width, height);
|
|
||||||
gst_vaapi_video_pool_replace(&priv->surfaces, pool);
|
|
||||||
gst_vaapi_video_pool_unref(pool);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
/* Always try to downsample source buffers to YUV 4:2:0 format as
|
||||||
gst_vaapi_uploader_finalize(GObject *object)
|
this saves memory bandwidth for further rendering */
|
||||||
{
|
/* XXX: this also means that visual quality is not preserved */
|
||||||
gst_vaapi_uploader_destroy(GST_VAAPI_UPLOADER_CAST(object));
|
if (format != GST_VIDEO_FORMAT_ENCODED) {
|
||||||
|
const GstVaapiChromaType chroma_type =
|
||||||
G_OBJECT_CLASS(gst_vaapi_uploader_parent_class)->finalize(object);
|
gst_vaapi_video_format_get_chroma_type (format);
|
||||||
}
|
if (chroma_type != GST_VAAPI_CHROMA_TYPE_YUV420) {
|
||||||
|
const GstVideoFormat image_format =
|
||||||
static void
|
GST_VIDEO_INFO_FORMAT (&priv->image_info);
|
||||||
gst_vaapi_uploader_set_property(GObject *object, guint prop_id,
|
GST_INFO ("use implicit conversion of %s buffers to NV12 surfaces",
|
||||||
const GValue *value, GParamSpec *pspec)
|
gst_video_format_to_string (image_format));
|
||||||
{
|
gst_video_info_set_format (&vi, GST_VIDEO_FORMAT_NV12, width, height);
|
||||||
GstVaapiUploader * const uploader = GST_VAAPI_UPLOADER_CAST(object);
|
|
||||||
|
|
||||||
switch (prop_id) {
|
|
||||||
case PROP_DISPLAY:
|
|
||||||
ensure_display(uploader, g_value_get_pointer(value));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pool = gst_vaapi_surface_pool_new (priv->display, &vi);
|
||||||
|
if (!pool)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
gst_video_info_set_format (&priv->surface_info, format, width, height);
|
||||||
|
gst_vaapi_video_pool_replace (&priv->surfaces, pool);
|
||||||
|
gst_vaapi_video_pool_unref (pool);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vaapi_uploader_get_property(GObject *object, guint prop_id,
|
gst_vaapi_uploader_finalize (GObject * object)
|
||||||
GValue *value, GParamSpec *pspec)
|
|
||||||
{
|
{
|
||||||
GstVaapiUploader * const uploader = GST_VAAPI_UPLOADER_CAST(object);
|
gst_vaapi_uploader_destroy (GST_VAAPI_UPLOADER_CAST (object));
|
||||||
|
|
||||||
switch (prop_id) {
|
G_OBJECT_CLASS (gst_vaapi_uploader_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_vaapi_uploader_set_property (GObject * object, guint prop_id,
|
||||||
|
const GValue * value, GParamSpec * pspec)
|
||||||
|
{
|
||||||
|
GstVaapiUploader *const uploader = GST_VAAPI_UPLOADER_CAST (object);
|
||||||
|
|
||||||
|
switch (prop_id) {
|
||||||
case PROP_DISPLAY:
|
case PROP_DISPLAY:
|
||||||
g_value_set_pointer(value, uploader->priv->display);
|
ensure_display (uploader, g_value_get_pointer (value));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vaapi_uploader_class_init(GstVaapiUploaderClass *klass)
|
gst_vaapi_uploader_get_property (GObject * object, guint prop_id,
|
||||||
|
GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
|
GstVaapiUploader *const uploader = GST_VAAPI_UPLOADER_CAST (object);
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_INIT(gst_debug_vaapi_uploader,
|
switch (prop_id) {
|
||||||
GST_HELPER_NAME, 0, GST_HELPER_DESC);
|
case PROP_DISPLAY:
|
||||||
|
g_value_set_pointer (value, uploader->priv->display);
|
||||||
g_type_class_add_private(klass, sizeof(GstVaapiUploaderPrivate));
|
break;
|
||||||
|
default:
|
||||||
object_class->finalize = gst_vaapi_uploader_finalize;
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
object_class->set_property = gst_vaapi_uploader_set_property;
|
break;
|
||||||
object_class->get_property = gst_vaapi_uploader_get_property;
|
}
|
||||||
|
|
||||||
g_object_class_install_property(
|
|
||||||
object_class,
|
|
||||||
PROP_DISPLAY,
|
|
||||||
g_param_spec_pointer(
|
|
||||||
"display",
|
|
||||||
"Display",
|
|
||||||
"The GstVaapiDisplay this object is bound to",
|
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vaapi_uploader_init(GstVaapiUploader *uploader)
|
gst_vaapi_uploader_class_init (GstVaapiUploaderClass * klass)
|
||||||
{
|
{
|
||||||
GstVaapiUploaderPrivate *priv;
|
GObjectClass *const object_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
priv = GST_VAAPI_UPLOADER_GET_PRIVATE(uploader);
|
GST_DEBUG_CATEGORY_INIT (gst_debug_vaapi_uploader,
|
||||||
uploader->priv = priv;
|
GST_HELPER_NAME, 0, GST_HELPER_DESC);
|
||||||
|
|
||||||
gst_video_info_init(&priv->image_info);
|
g_type_class_add_private (klass, sizeof (GstVaapiUploaderPrivate));
|
||||||
gst_video_info_init(&priv->surface_info);
|
|
||||||
|
object_class->finalize = gst_vaapi_uploader_finalize;
|
||||||
|
object_class->set_property = gst_vaapi_uploader_set_property;
|
||||||
|
object_class->get_property = gst_vaapi_uploader_get_property;
|
||||||
|
|
||||||
|
g_object_class_install_property (object_class,
|
||||||
|
PROP_DISPLAY,
|
||||||
|
g_param_spec_pointer ("display",
|
||||||
|
"Display",
|
||||||
|
"The GstVaapiDisplay this object is bound to",
|
||||||
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_vaapi_uploader_init (GstVaapiUploader * uploader)
|
||||||
|
{
|
||||||
|
GstVaapiUploaderPrivate *priv;
|
||||||
|
|
||||||
|
priv = GST_VAAPI_UPLOADER_GET_PRIVATE (uploader);
|
||||||
|
uploader->priv = priv;
|
||||||
|
|
||||||
|
gst_video_info_init (&priv->image_info);
|
||||||
|
gst_video_info_init (&priv->surface_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
GstVaapiUploader *
|
GstVaapiUploader *
|
||||||
gst_vaapi_uploader_new(GstVaapiDisplay *display)
|
gst_vaapi_uploader_new (GstVaapiDisplay * display)
|
||||||
{
|
{
|
||||||
return g_object_new(GST_VAAPI_TYPE_UPLOADER, "display", display, NULL);
|
return g_object_new (GST_VAAPI_TYPE_UPLOADER, "display", display, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gst_vaapi_uploader_ensure_display(
|
gst_vaapi_uploader_ensure_display (GstVaapiUploader * uploader,
|
||||||
GstVaapiUploader *uploader,
|
GstVaapiDisplay * display)
|
||||||
GstVaapiDisplay *display
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(GST_VAAPI_IS_UPLOADER(uploader), FALSE);
|
g_return_val_if_fail (GST_VAAPI_IS_UPLOADER (uploader), FALSE);
|
||||||
g_return_val_if_fail(display != NULL, FALSE);
|
g_return_val_if_fail (display != NULL, FALSE);
|
||||||
|
|
||||||
return ensure_display(uploader,display);
|
return ensure_display (uploader, display);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gst_vaapi_uploader_ensure_caps(
|
gst_vaapi_uploader_ensure_caps (GstVaapiUploader * uploader,
|
||||||
GstVaapiUploader *uploader,
|
GstCaps * src_caps, GstCaps * out_caps)
|
||||||
GstCaps *src_caps,
|
|
||||||
GstCaps *out_caps
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
GstVaapiUploaderPrivate *priv;
|
GstVaapiUploaderPrivate *priv;
|
||||||
GstVaapiImage *image;
|
GstVaapiImage *image;
|
||||||
gboolean image_caps_changed, surface_caps_changed;
|
gboolean image_caps_changed, surface_caps_changed;
|
||||||
|
|
||||||
g_return_val_if_fail(GST_VAAPI_IS_UPLOADER(uploader), FALSE);
|
g_return_val_if_fail (GST_VAAPI_IS_UPLOADER (uploader), FALSE);
|
||||||
g_return_val_if_fail(src_caps != NULL, FALSE);
|
g_return_val_if_fail (src_caps != NULL, FALSE);
|
||||||
|
|
||||||
if (!out_caps)
|
if (!out_caps)
|
||||||
out_caps = src_caps;
|
out_caps = src_caps;
|
||||||
|
|
||||||
if (!ensure_image_pool(uploader, src_caps, &image_caps_changed))
|
if (!ensure_image_pool (uploader, src_caps, &image_caps_changed))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!ensure_surface_pool(uploader, out_caps, &surface_caps_changed))
|
if (!ensure_surface_pool (uploader, out_caps, &surface_caps_changed))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!image_caps_changed && !surface_caps_changed)
|
if (!image_caps_changed && !surface_caps_changed)
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
priv = uploader->priv;
|
|
||||||
priv->direct_rendering = 0;
|
|
||||||
|
|
||||||
/* Check if we can alias source and output buffers (same data_size) */
|
|
||||||
image = gst_vaapi_video_pool_get_object(priv->images);
|
|
||||||
if (image) {
|
|
||||||
if ((gst_vaapi_image_get_format(image) ==
|
|
||||||
GST_VIDEO_INFO_FORMAT(&priv->image_info)) &&
|
|
||||||
gst_vaapi_image_is_linear(image) &&
|
|
||||||
(gst_vaapi_image_get_data_size(image) ==
|
|
||||||
GST_VIDEO_INFO_SIZE(&priv->image_info)))
|
|
||||||
priv->direct_rendering = 1;
|
|
||||||
gst_vaapi_video_pool_put_object(priv->images, image);
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_INFO("direct-rendering: level %u", priv->direct_rendering);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
priv = uploader->priv;
|
||||||
|
priv->direct_rendering = 0;
|
||||||
|
|
||||||
|
/* Check if we can alias source and output buffers (same data_size) */
|
||||||
|
image = gst_vaapi_video_pool_get_object (priv->images);
|
||||||
|
if (image) {
|
||||||
|
if ((gst_vaapi_image_get_format (image) ==
|
||||||
|
GST_VIDEO_INFO_FORMAT (&priv->image_info)) &&
|
||||||
|
gst_vaapi_image_is_linear (image) &&
|
||||||
|
(gst_vaapi_image_get_data_size (image) ==
|
||||||
|
GST_VIDEO_INFO_SIZE (&priv->image_info)))
|
||||||
|
priv->direct_rendering = 1;
|
||||||
|
gst_vaapi_video_pool_put_object (priv->images, image);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_INFO ("direct-rendering: level %u", priv->direct_rendering);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gst_vaapi_uploader_process(
|
gst_vaapi_uploader_process (GstVaapiUploader * uploader,
|
||||||
GstVaapiUploader *uploader,
|
GstBuffer * src_buffer, GstBuffer * out_buffer)
|
||||||
GstBuffer *src_buffer,
|
|
||||||
GstBuffer *out_buffer
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
GstVaapiVideoMeta *src_meta, *out_meta;
|
GstVaapiVideoMeta *src_meta, *out_meta;
|
||||||
GstVaapiSurface *surface;
|
GstVaapiSurface *surface;
|
||||||
GstVaapiImage *image;
|
GstVaapiImage *image;
|
||||||
|
|
||||||
g_return_val_if_fail(GST_VAAPI_IS_UPLOADER(uploader), FALSE);
|
g_return_val_if_fail (GST_VAAPI_IS_UPLOADER (uploader), FALSE);
|
||||||
|
|
||||||
out_meta = gst_buffer_get_vaapi_video_meta(out_buffer);
|
out_meta = gst_buffer_get_vaapi_video_meta (out_buffer);
|
||||||
if (!out_meta) {
|
if (!out_meta) {
|
||||||
GST_WARNING("expected an output video buffer");
|
GST_WARNING ("expected an output video buffer");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
surface = gst_vaapi_video_meta_get_surface (out_meta);
|
||||||
|
g_return_val_if_fail (surface != NULL, FALSE);
|
||||||
|
|
||||||
|
src_meta = gst_buffer_get_vaapi_video_meta (src_buffer);
|
||||||
|
if (src_meta) {
|
||||||
|
/* GstVaapiVideoBuffer with mapped VA image */
|
||||||
|
image = gst_vaapi_video_meta_get_image (src_meta);
|
||||||
|
if (!image || !gst_vaapi_image_unmap (image))
|
||||||
|
return FALSE;
|
||||||
|
} else {
|
||||||
|
/* Regular GstBuffer that needs to be uploaded to a VA image */
|
||||||
|
image = gst_vaapi_video_meta_get_image (out_meta);
|
||||||
|
if (!image) {
|
||||||
|
image = gst_vaapi_video_pool_get_object (uploader->priv->images);
|
||||||
|
if (!image)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
gst_vaapi_video_meta_set_image (out_meta, image);
|
||||||
}
|
}
|
||||||
|
if (!gst_vaapi_image_update_from_buffer (image, src_buffer, NULL))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
g_return_val_if_fail (image != NULL, FALSE);
|
||||||
|
|
||||||
surface = gst_vaapi_video_meta_get_surface(out_meta);
|
if (!gst_vaapi_surface_put_image (surface, image)) {
|
||||||
g_return_val_if_fail(surface != NULL, FALSE);
|
GST_WARNING ("failed to upload YUV buffer to VA surface");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
src_meta = gst_buffer_get_vaapi_video_meta(src_buffer);
|
/* Map again for next uploads */
|
||||||
if (src_meta) {
|
if (!gst_vaapi_image_map (image))
|
||||||
/* GstVaapiVideoBuffer with mapped VA image */
|
return FALSE;
|
||||||
image = gst_vaapi_video_meta_get_image(src_meta);
|
return TRUE;
|
||||||
if (!image || !gst_vaapi_image_unmap(image))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* Regular GstBuffer that needs to be uploaded to a VA image */
|
|
||||||
image = gst_vaapi_video_meta_get_image(out_meta);
|
|
||||||
if (!image) {
|
|
||||||
image = gst_vaapi_video_pool_get_object(uploader->priv->images);
|
|
||||||
if (!image)
|
|
||||||
return FALSE;
|
|
||||||
gst_vaapi_video_meta_set_image(out_meta, image);
|
|
||||||
}
|
|
||||||
if (!gst_vaapi_image_update_from_buffer(image, src_buffer, NULL))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
g_return_val_if_fail(image != NULL, FALSE);
|
|
||||||
|
|
||||||
if (!gst_vaapi_surface_put_image(surface, image)) {
|
|
||||||
GST_WARNING("failed to upload YUV buffer to VA surface");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Map again for next uploads */
|
|
||||||
if (!gst_vaapi_image_map(image))
|
|
||||||
return FALSE;
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GstCaps *
|
GstCaps *
|
||||||
gst_vaapi_uploader_get_caps(GstVaapiUploader *uploader)
|
gst_vaapi_uploader_get_caps (GstVaapiUploader * uploader)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(GST_VAAPI_IS_UPLOADER(uploader), NULL);
|
g_return_val_if_fail (GST_VAAPI_IS_UPLOADER (uploader), NULL);
|
||||||
|
|
||||||
if (!ensure_allowed_caps(uploader))
|
if (!ensure_allowed_caps (uploader))
|
||||||
return NULL;
|
return NULL;
|
||||||
return uploader->priv->allowed_caps;
|
return uploader->priv->allowed_caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
GstBuffer *
|
GstBuffer *
|
||||||
gst_vaapi_uploader_get_buffer(GstVaapiUploader *uploader)
|
gst_vaapi_uploader_get_buffer (GstVaapiUploader * uploader)
|
||||||
{
|
{
|
||||||
GstVaapiUploaderPrivate *priv;
|
GstVaapiUploaderPrivate *priv;
|
||||||
GstVaapiImage *image;
|
GstVaapiImage *image;
|
||||||
GstVaapiVideoMeta *meta;
|
GstVaapiVideoMeta *meta;
|
||||||
GstVaapiSurfaceProxy *proxy;
|
GstVaapiSurfaceProxy *proxy;
|
||||||
GstBuffer *buffer;
|
GstBuffer *buffer;
|
||||||
|
|
||||||
g_return_val_if_fail(GST_VAAPI_IS_UPLOADER(uploader), NULL);
|
g_return_val_if_fail (GST_VAAPI_IS_UPLOADER (uploader), NULL);
|
||||||
|
|
||||||
priv = uploader->priv;
|
priv = uploader->priv;
|
||||||
|
|
||||||
buffer = gst_vaapi_video_buffer_new_from_pool(priv->images);
|
buffer = gst_vaapi_video_buffer_new_from_pool (priv->images);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
GST_WARNING("failed to allocate video buffer");
|
GST_WARNING ("failed to allocate video buffer");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy = gst_vaapi_surface_proxy_new_from_pool(
|
proxy =
|
||||||
GST_VAAPI_SURFACE_POOL(priv->surfaces));
|
gst_vaapi_surface_proxy_new_from_pool (GST_VAAPI_SURFACE_POOL
|
||||||
if (!proxy) {
|
(priv->surfaces));
|
||||||
GST_WARNING("failed to allocate VA surface");
|
if (!proxy) {
|
||||||
goto error;
|
GST_WARNING ("failed to allocate VA surface");
|
||||||
}
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
meta = gst_buffer_get_vaapi_video_meta(buffer);
|
meta = gst_buffer_get_vaapi_video_meta (buffer);
|
||||||
gst_vaapi_video_meta_set_surface_proxy(meta, proxy);
|
gst_vaapi_video_meta_set_surface_proxy (meta, proxy);
|
||||||
gst_vaapi_surface_proxy_unref(proxy);
|
gst_vaapi_surface_proxy_unref (proxy);
|
||||||
|
|
||||||
image = gst_vaapi_video_meta_get_image(meta);
|
|
||||||
if (!gst_vaapi_image_map(image)) {
|
|
||||||
GST_WARNING("failed to map VA image");
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
image = gst_vaapi_video_meta_get_image (meta);
|
||||||
|
if (!gst_vaapi_image_map (image)) {
|
||||||
|
GST_WARNING ("failed to map VA image");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
#if !GST_CHECK_VERSION(1,0,0)
|
#if !GST_CHECK_VERSION(1,0,0)
|
||||||
GST_BUFFER_DATA(buffer) = gst_vaapi_image_get_plane(image, 0);
|
GST_BUFFER_DATA (buffer) = gst_vaapi_image_get_plane (image, 0);
|
||||||
GST_BUFFER_SIZE(buffer) = gst_vaapi_image_get_data_size(image);
|
GST_BUFFER_SIZE (buffer) = gst_vaapi_image_get_data_size (image);
|
||||||
#endif
|
#endif
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
gst_buffer_unref(buffer);
|
gst_buffer_unref (buffer);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gst_vaapi_uploader_has_direct_rendering(GstVaapiUploader *uploader)
|
gst_vaapi_uploader_has_direct_rendering (GstVaapiUploader * uploader)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(GST_VAAPI_IS_UPLOADER(uploader), FALSE);
|
g_return_val_if_fail (GST_VAAPI_IS_UPLOADER (uploader), FALSE);
|
||||||
|
|
||||||
return uploader->priv->direct_rendering;
|
return uploader->priv->direct_rendering;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,87 +30,73 @@
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define GST_VAAPI_TYPE_UPLOADER \
|
#define GST_VAAPI_TYPE_UPLOADER \
|
||||||
(gst_vaapi_uploader_get_type())
|
(gst_vaapi_uploader_get_type ())
|
||||||
|
#define GST_VAAPI_UPLOADER(obj) \
|
||||||
#define GST_VAAPI_UPLOADER(obj) \
|
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_VAAPI_TYPE_UPLOADER, \
|
||||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
|
GstVaapiUploader))
|
||||||
GST_VAAPI_TYPE_UPLOADER, \
|
#define GST_VAAPI_UPLOADER_CLASS(klass) \
|
||||||
GstVaapiUploader))
|
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_VAAPI_TYPE_UPLOADER, \
|
||||||
|
GstVaapiUploaderClass))
|
||||||
#define GST_VAAPI_UPLOADER_CLASS(klass) \
|
|
||||||
(G_TYPE_CHECK_CLASS_CAST((klass), \
|
|
||||||
GST_VAAPI_TYPE_UPLOADER, \
|
|
||||||
GstVaapiUploaderClass))
|
|
||||||
|
|
||||||
#define GST_VAAPI_IS_UPLOADER(obj) \
|
#define GST_VAAPI_IS_UPLOADER(obj) \
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_UPLOADER))
|
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_VAAPI_TYPE_UPLOADER))
|
||||||
|
|
||||||
#define GST_VAAPI_IS_UPLOADER_CLASS(klass) \
|
#define GST_VAAPI_IS_UPLOADER_CLASS(klass) \
|
||||||
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_UPLOADER))
|
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_VAAPI_TYPE_UPLOADER))
|
||||||
|
#define GST_VAAPI_UPLOADER_GET_CLASS(obj) \
|
||||||
|
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_VAAPI_TYPE_UPLOADER, \
|
||||||
|
GstVaapiUploaderClass))
|
||||||
|
|
||||||
#define GST_VAAPI_UPLOADER_GET_CLASS(obj) \
|
typedef struct _GstVaapiUploader GstVaapiUploader;
|
||||||
(G_TYPE_INSTANCE_GET_CLASS((obj), \
|
typedef struct _GstVaapiUploaderPrivate GstVaapiUploaderPrivate;
|
||||||
GST_VAAPI_TYPE_UPLOADER, \
|
typedef struct _GstVaapiUploaderClass GstVaapiUploaderClass;
|
||||||
GstVaapiUploaderClass))
|
|
||||||
|
|
||||||
typedef struct _GstVaapiUploader GstVaapiUploader;
|
struct _GstVaapiUploader
|
||||||
typedef struct _GstVaapiUploaderPrivate GstVaapiUploaderPrivate;
|
{
|
||||||
typedef struct _GstVaapiUploaderClass GstVaapiUploaderClass;
|
/*< private >*/
|
||||||
|
GObject parent_instance;
|
||||||
|
|
||||||
struct _GstVaapiUploader {
|
GstVaapiUploaderPrivate *priv;
|
||||||
/*< private >*/
|
|
||||||
GObject parent_instance;
|
|
||||||
|
|
||||||
GstVaapiUploaderPrivate *priv;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstVaapiUploaderClass {
|
struct _GstVaapiUploaderClass
|
||||||
/*< private >*/
|
{
|
||||||
GObjectClass parent_class;
|
/*< private >*/
|
||||||
|
GObjectClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GType
|
GType
|
||||||
gst_vaapi_uploader_get_type(void) G_GNUC_CONST;
|
gst_vaapi_uploader_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GstVaapiUploader *
|
GstVaapiUploader *
|
||||||
gst_vaapi_uploader_new(GstVaapiDisplay *display);
|
gst_vaapi_uploader_new (GstVaapiDisplay * display);
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
gboolean
|
gboolean
|
||||||
gst_vaapi_uploader_ensure_display(
|
gst_vaapi_uploader_ensure_display (GstVaapiUploader * uploader,
|
||||||
GstVaapiUploader *uploader,
|
GstVaapiDisplay * display);
|
||||||
GstVaapiDisplay *display
|
|
||||||
);
|
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
gboolean
|
gboolean
|
||||||
gst_vaapi_uploader_ensure_caps(
|
gst_vaapi_uploader_ensure_caps (GstVaapiUploader * uploader,
|
||||||
GstVaapiUploader *uploader,
|
GstCaps * src_caps, GstCaps * out_caps);
|
||||||
GstCaps *src_caps,
|
|
||||||
GstCaps *out_caps
|
|
||||||
);
|
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
gboolean
|
gboolean
|
||||||
gst_vaapi_uploader_process(
|
gst_vaapi_uploader_process (GstVaapiUploader * uploader,
|
||||||
GstVaapiUploader *uploader,
|
GstBuffer * src_buffer, GstBuffer * out_buffer);
|
||||||
GstBuffer *src_buffer,
|
|
||||||
GstBuffer *out_buffer
|
|
||||||
);
|
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GstCaps *
|
GstCaps *
|
||||||
gst_vaapi_uploader_get_caps(GstVaapiUploader *uploader);
|
gst_vaapi_uploader_get_caps (GstVaapiUploader * uploader);
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GstBuffer *
|
GstBuffer *
|
||||||
gst_vaapi_uploader_get_buffer(GstVaapiUploader *uploader);
|
gst_vaapi_uploader_get_buffer (GstVaapiUploader * uploader);
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
gboolean
|
gboolean
|
||||||
gst_vaapi_uploader_has_direct_rendering(GstVaapiUploader *uploader);
|
gst_vaapi_uploader_has_direct_rendering (GstVaapiUploader * uploader);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue