2020-03-22 18:00:50 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2020 Igalia, S.L.
|
|
|
|
* Author: Víctor Jáquez <vjaquez@igalia.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstvadecoder.h"
|
|
|
|
|
2022-03-25 14:56:01 +00:00
|
|
|
#include <gst/va/gstva.h>
|
2022-09-13 12:46:37 +00:00
|
|
|
#include <gst/va/gstvavideoformat.h>
|
2022-02-23 07:25:08 +00:00
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
#include "gstvacaps.h"
|
2021-05-06 10:23:23 +00:00
|
|
|
#include "gstvadisplay_priv.h"
|
2022-02-03 09:10:44 +00:00
|
|
|
#include "gstvaprofile.h"
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
struct _GstVaDecoder
|
|
|
|
{
|
|
|
|
GstObject parent;
|
|
|
|
|
|
|
|
GArray *available_profiles;
|
|
|
|
GstCaps *srcpad_caps;
|
|
|
|
GstCaps *sinkpad_caps;
|
|
|
|
GstVaDisplay *display;
|
|
|
|
VAConfigID config;
|
|
|
|
VAContextID context;
|
|
|
|
VAProfile profile;
|
|
|
|
guint rt_format;
|
|
|
|
gint coded_width;
|
|
|
|
gint coded_height;
|
|
|
|
};
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_va_decoder_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_va_decoder_debug
|
|
|
|
|
|
|
|
#define gst_va_decoder_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstVaDecoder, gst_va_decoder, GST_TYPE_OBJECT,
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_va_decoder_debug, "vadecoder", 0,
|
|
|
|
"VA Decoder"));
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_DISPLAY = 1,
|
|
|
|
PROP_PROFILE,
|
|
|
|
PROP_WIDTH,
|
|
|
|
PROP_HEIGHT,
|
|
|
|
PROP_CHROMA,
|
|
|
|
N_PROPERTIES
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *g_properties[N_PROPERTIES];
|
|
|
|
|
2020-11-30 14:01:01 +00:00
|
|
|
static gboolean _destroy_buffers (GstVaDecodePicture * pic);
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
static void
|
|
|
|
gst_va_decoder_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVaDecoder *self = GST_VA_DECODER (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:{
|
|
|
|
g_assert (!self->display);
|
|
|
|
self->display = g_value_dup_object (value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_va_decoder_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVaDecoder *self = GST_VA_DECODER (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_object (value, self->display);
|
|
|
|
break;
|
|
|
|
case PROP_PROFILE:
|
|
|
|
g_value_set_int (value, self->profile);
|
|
|
|
break;
|
|
|
|
case PROP_CHROMA:
|
|
|
|
g_value_set_uint (value, self->rt_format);
|
|
|
|
break;
|
|
|
|
case PROP_WIDTH:
|
|
|
|
g_value_set_int (value, self->coded_width);
|
|
|
|
break;
|
|
|
|
case PROP_HEIGHT:
|
|
|
|
g_value_set_int (value, self->coded_height);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_va_decoder_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GstVaDecoder *self = GST_VA_DECODER (object);
|
|
|
|
|
2021-10-12 09:48:17 +00:00
|
|
|
if (!gst_va_decoder_close (self))
|
|
|
|
GST_WARNING_OBJECT (self, "VaDecoder is not successfully closed");
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
g_clear_pointer (&self->available_profiles, g_array_unref);
|
|
|
|
gst_clear_object (&self->display);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_va_decoder_class_init (GstVaDecoderClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_va_decoder_set_property;
|
|
|
|
gobject_class->get_property = gst_va_decoder_get_property;
|
|
|
|
gobject_class->dispose = gst_va_decoder_dispose;
|
|
|
|
|
|
|
|
g_properties[PROP_DISPLAY] =
|
2022-10-19 14:44:07 +00:00
|
|
|
g_param_spec_object ("display", "GstVaDisplay", "GstVaDisplay object",
|
2020-03-22 18:00:50 +00:00
|
|
|
GST_TYPE_VA_DISPLAY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
g_properties[PROP_PROFILE] =
|
|
|
|
g_param_spec_int ("va-profile", "VAProfile", "VA Profile",
|
|
|
|
VAProfileNone, 50, VAProfileNone,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
g_properties[PROP_CHROMA] =
|
2022-10-19 14:44:07 +00:00
|
|
|
g_param_spec_uint ("va-rt-format", "VARTFormat", "VA RT Format",
|
2020-03-22 18:00:50 +00:00
|
|
|
VA_RT_FORMAT_YUV420, VA_RT_FORMAT_PROTECTED, VA_RT_FORMAT_YUV420,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
g_properties[PROP_WIDTH] =
|
|
|
|
g_param_spec_int ("coded-width", "coded-picture-width",
|
|
|
|
"coded picture width", 0, G_MAXINT, 0,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
g_properties[PROP_HEIGHT] =
|
|
|
|
g_param_spec_int ("coded-height", "coded-picture-height",
|
|
|
|
"coded picture height", 0, G_MAXINT, 0,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
g_object_class_install_properties (gobject_class, N_PROPERTIES, g_properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_va_decoder_init (GstVaDecoder * self)
|
|
|
|
{
|
|
|
|
self->profile = VAProfileNone;
|
|
|
|
self->config = VA_INVALID_ID;
|
|
|
|
self->context = VA_INVALID_ID;
|
2020-07-27 09:14:49 +00:00
|
|
|
self->rt_format = 0;
|
2020-03-22 18:00:50 +00:00
|
|
|
self->coded_width = 0;
|
|
|
|
self->coded_height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_va_decoder_initialize (GstVaDecoder * self, guint32 codec)
|
|
|
|
{
|
|
|
|
if (self->available_profiles)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
self->available_profiles = gst_va_display_get_profiles (self->display, codec,
|
|
|
|
VAEntrypointVLD);
|
|
|
|
|
|
|
|
return (self->available_profiles != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
GstVaDecoder *
|
|
|
|
gst_va_decoder_new (GstVaDisplay * display, guint32 codec)
|
|
|
|
{
|
|
|
|
GstVaDecoder *self;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DISPLAY (display), NULL);
|
|
|
|
|
|
|
|
self = g_object_new (GST_TYPE_VA_DECODER, "display", display, NULL);
|
2024-03-15 18:03:58 +00:00
|
|
|
gst_object_ref_sink (self);
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
if (!gst_va_decoder_initialize (self, codec))
|
|
|
|
gst_clear_object (&self);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_va_decoder_is_open (GstVaDecoder * self)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
ret = (self->config != VA_INVALID_ID && self->profile != VAProfileNone);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_va_decoder_open (GstVaDecoder * self, VAProfile profile, guint rt_format)
|
|
|
|
{
|
|
|
|
VAConfigAttrib attrib = {
|
|
|
|
.type = VAConfigAttribRTFormat,
|
|
|
|
.value = rt_format,
|
|
|
|
};
|
2020-08-18 09:38:46 +00:00
|
|
|
VAConfigID config;
|
2020-03-22 18:00:50 +00:00
|
|
|
VADisplay dpy;
|
|
|
|
VAStatus status;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
|
2020-08-18 09:38:46 +00:00
|
|
|
if (gst_va_decoder_is_open (self))
|
2020-03-22 18:00:50 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!gst_va_decoder_has_profile (self, profile)) {
|
2022-02-03 09:10:44 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Unsupported profile: %s",
|
|
|
|
gst_va_profile_name (profile));
|
2020-03-22 18:00:50 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dpy = gst_va_display_get_va_dpy (self->display);
|
2020-08-18 09:38:46 +00:00
|
|
|
status = vaCreateConfig (dpy, profile, VAEntrypointVLD, &attrib, 1, &config);
|
2020-03-22 18:00:50 +00:00
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
|
|
|
GST_ERROR_OBJECT (self, "vaCreateConfig: %s", vaErrorStr (status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (self);
|
2020-08-18 09:38:46 +00:00
|
|
|
self->config = config;
|
2020-03-22 18:00:50 +00:00
|
|
|
self->profile = profile;
|
|
|
|
self->rt_format = rt_format;
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
|
|
|
|
/* now we should return now only this profile's caps */
|
|
|
|
gst_caps_replace (&self->srcpad_caps, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_va_decoder_close (GstVaDecoder * self)
|
|
|
|
{
|
|
|
|
VADisplay dpy;
|
|
|
|
VAStatus status;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
|
|
|
|
if (!gst_va_decoder_is_open (self))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
dpy = gst_va_display_get_va_dpy (self->display);
|
|
|
|
|
|
|
|
if (self->context != VA_INVALID_ID) {
|
|
|
|
status = vaDestroyContext (dpy, self->context);
|
|
|
|
if (status != VA_STATUS_SUCCESS)
|
|
|
|
GST_ERROR_OBJECT (self, "vaDestroyContext: %s", vaErrorStr (status));
|
|
|
|
}
|
|
|
|
|
|
|
|
status = vaDestroyConfig (dpy, self->config);
|
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
|
|
|
GST_ERROR_OBJECT (self, "vaDestroyConfig: %s", vaErrorStr (status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
gst_va_decoder_init (self);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
|
|
|
|
gst_caps_replace (&self->srcpad_caps, NULL);
|
|
|
|
gst_caps_replace (&self->sinkpad_caps, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2021-07-17 18:29:45 +00:00
|
|
|
gst_va_decoder_set_frame_size_with_surfaces (GstVaDecoder * self,
|
|
|
|
gint coded_width, gint coded_height, GArray * surfaces)
|
2020-03-22 18:00:50 +00:00
|
|
|
{
|
2020-08-18 09:38:46 +00:00
|
|
|
VAContextID context;
|
2020-03-22 18:00:50 +00:00
|
|
|
VADisplay dpy;
|
|
|
|
VAStatus status;
|
|
|
|
VASurfaceID *render_targets = NULL;
|
|
|
|
gint num_render_targets = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
|
2020-08-18 09:38:46 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
2020-03-22 18:00:50 +00:00
|
|
|
if (self->context != VA_INVALID_ID) {
|
2020-08-18 09:38:46 +00:00
|
|
|
GST_OBJECT_UNLOCK (self);
|
2021-07-17 18:29:45 +00:00
|
|
|
GST_INFO_OBJECT (self, "decoder already has a context");
|
2020-03-22 18:00:50 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2020-08-18 09:38:46 +00:00
|
|
|
GST_OBJECT_UNLOCK (self);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
if (!gst_va_decoder_is_open (self)) {
|
|
|
|
GST_ERROR_OBJECT (self, "decoder has not been opened yet");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surfaces) {
|
|
|
|
num_render_targets = surfaces->len;
|
|
|
|
render_targets = (VASurfaceID *) surfaces->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
dpy = gst_va_display_get_va_dpy (self->display);
|
|
|
|
|
|
|
|
status = vaCreateContext (dpy, self->config, coded_width, coded_height,
|
2020-08-18 09:38:46 +00:00
|
|
|
VA_PROGRESSIVE, render_targets, num_render_targets, &context);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
2023-08-24 10:12:09 +00:00
|
|
|
GST_ERROR_OBJECT (self, "vaCreateContext: %s", vaErrorStr (status));
|
2020-03-22 18:00:50 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (self);
|
2020-08-18 09:38:46 +00:00
|
|
|
self->context = context;
|
2020-03-22 18:00:50 +00:00
|
|
|
self->coded_width = coded_width;
|
|
|
|
self->coded_height = coded_height;
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-07-17 18:29:45 +00:00
|
|
|
gboolean
|
|
|
|
gst_va_decoder_set_frame_size (GstVaDecoder * self, gint coded_width,
|
|
|
|
gint coded_height)
|
|
|
|
{
|
|
|
|
return gst_va_decoder_set_frame_size_with_surfaces (self, coded_width,
|
|
|
|
coded_height, NULL);
|
|
|
|
}
|
|
|
|
|
2021-07-17 18:37:52 +00:00
|
|
|
/* This function is only used by codecs where frame size can change
|
|
|
|
* without a context reset, as for example VP9 */
|
2021-07-14 06:27:34 +00:00
|
|
|
gboolean
|
2021-07-17 18:37:52 +00:00
|
|
|
gst_va_decoder_update_frame_size (GstVaDecoder * self, gint coded_width,
|
2021-07-14 06:27:34 +00:00
|
|
|
gint coded_height)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
|
|
|
|
if (!gst_va_decoder_is_open (self)) {
|
|
|
|
GST_ERROR_OBJECT (self, "decoder has not been opened yet");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
if (self->context == VA_INVALID_ID) {
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
2021-07-17 18:37:52 +00:00
|
|
|
GST_INFO_OBJECT (self, "decoder does not have a context");
|
2021-07-14 06:27:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
self->coded_width = coded_width;
|
|
|
|
self->coded_height = coded_height;
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
static gboolean
|
|
|
|
_get_codec_caps (GstVaDecoder * self)
|
|
|
|
{
|
|
|
|
GstCaps *sinkpad_caps = NULL, *srcpad_caps = NULL;
|
|
|
|
|
|
|
|
if (!gst_va_decoder_is_open (self)
|
|
|
|
&& GST_IS_VA_DISPLAY_WRAPPED (self->display)) {
|
|
|
|
if (gst_va_caps_from_profiles (self->display, self->available_profiles,
|
|
|
|
VAEntrypointVLD, &sinkpad_caps, &srcpad_caps)) {
|
|
|
|
gst_caps_replace (&self->sinkpad_caps, sinkpad_caps);
|
|
|
|
gst_caps_replace (&self->srcpad_caps, srcpad_caps);
|
|
|
|
gst_caps_unref (srcpad_caps);
|
|
|
|
gst_caps_unref (sinkpad_caps);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_va_decoder_get_srcpad_caps (GstVaDecoder * self)
|
|
|
|
{
|
|
|
|
GstCaps *srcpad_caps = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
|
2021-01-15 08:05:06 +00:00
|
|
|
if (g_atomic_pointer_get (&self->srcpad_caps))
|
2020-03-22 18:00:50 +00:00
|
|
|
return gst_caps_ref (self->srcpad_caps);
|
|
|
|
|
|
|
|
if (_get_codec_caps (self))
|
|
|
|
return gst_caps_ref (self->srcpad_caps);
|
|
|
|
|
|
|
|
if (gst_va_decoder_is_open (self)) {
|
|
|
|
srcpad_caps = gst_va_create_raw_caps_from_config (self->display,
|
|
|
|
self->config);
|
2022-08-16 12:45:46 +00:00
|
|
|
if (!srcpad_caps) {
|
|
|
|
GST_WARNING_OBJECT (self, "Invalid configuration caps");
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-03-22 18:00:50 +00:00
|
|
|
gst_caps_replace (&self->srcpad_caps, srcpad_caps);
|
|
|
|
gst_caps_unref (srcpad_caps);
|
|
|
|
|
|
|
|
return gst_caps_ref (self->srcpad_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_va_decoder_get_sinkpad_caps (GstVaDecoder * self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
|
2021-01-15 08:05:06 +00:00
|
|
|
if (g_atomic_pointer_get (&self->sinkpad_caps))
|
2020-03-22 18:00:50 +00:00
|
|
|
return gst_caps_ref (self->sinkpad_caps);
|
|
|
|
|
|
|
|
if (_get_codec_caps (self))
|
|
|
|
return gst_caps_ref (self->sinkpad_caps);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_va_decoder_has_profile (GstVaDecoder * self, VAProfile profile)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
|
|
|
|
if (profile == VAProfileNone)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < self->available_profiles->len; i++) {
|
|
|
|
if (g_array_index (self->available_profiles, VAProfile, i) == profile)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
gst_va_decoder_get_mem_types (GstVaDecoder * self)
|
|
|
|
{
|
|
|
|
VASurfaceAttrib *attribs;
|
|
|
|
guint i, attrib_count;
|
|
|
|
gint ret = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), 0);
|
|
|
|
|
|
|
|
if (!gst_va_decoder_is_open (self))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
attribs = gst_va_get_surface_attribs (self->display, self->config,
|
|
|
|
&attrib_count);
|
|
|
|
if (!attribs)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < attrib_count; i++) {
|
|
|
|
if (attribs[i].value.type != VAGenericValueTypeInteger)
|
|
|
|
continue;
|
|
|
|
switch (attribs[i].type) {
|
|
|
|
case VASurfaceAttribMemoryType:
|
|
|
|
ret = attribs[i].value.value.i;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (attribs);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-08-01 13:47:19 +00:00
|
|
|
GArray *
|
|
|
|
gst_va_decoder_get_surface_formats (GstVaDecoder * self)
|
|
|
|
{
|
|
|
|
GArray *formats;
|
|
|
|
GstVideoFormat format;
|
|
|
|
VASurfaceAttrib *attribs;
|
|
|
|
guint i, attrib_count;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), NULL);
|
|
|
|
|
|
|
|
if (!gst_va_decoder_is_open (self))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
attribs = gst_va_get_surface_attribs (self->display, self->config,
|
|
|
|
&attrib_count);
|
|
|
|
if (!attribs)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
formats = g_array_new (FALSE, FALSE, sizeof (GstVideoFormat));
|
|
|
|
|
|
|
|
for (i = 0; i < attrib_count; i++) {
|
|
|
|
if (attribs[i].value.type != VAGenericValueTypeInteger)
|
|
|
|
continue;
|
|
|
|
switch (attribs[i].type) {
|
|
|
|
case VASurfaceAttribPixelFormat:
|
|
|
|
format = gst_va_video_format_from_va_fourcc (attribs[i].value.value.i);
|
|
|
|
if (format != GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
g_array_append_val (formats, format);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (attribs);
|
|
|
|
|
|
|
|
if (formats->len == 0) {
|
|
|
|
g_array_unref (formats);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
gboolean
|
|
|
|
gst_va_decoder_add_param_buffer (GstVaDecoder * self, GstVaDecodePicture * pic,
|
|
|
|
gint type, gpointer data, gsize size)
|
|
|
|
{
|
|
|
|
VABufferID buffer;
|
|
|
|
VADisplay dpy;
|
|
|
|
VAStatus status;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
g_return_val_if_fail (self->context != VA_INVALID_ID, FALSE);
|
|
|
|
g_return_val_if_fail (pic && data && size > 0, FALSE);
|
|
|
|
|
|
|
|
dpy = gst_va_display_get_va_dpy (self->display);
|
|
|
|
status = vaCreateBuffer (dpy, self->context, type, size, 1, data, &buffer);
|
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
|
|
|
GST_ERROR_OBJECT (self, "vaCreateBuffer: %s", vaErrorStr (status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_append_val (pic->buffers, buffer);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2021-01-19 07:07:38 +00:00
|
|
|
gst_va_decoder_add_slice_buffer_with_n_params (GstVaDecoder * self,
|
|
|
|
GstVaDecodePicture * pic, gpointer params_data, gsize params_size,
|
|
|
|
guint params_num, gpointer slice_data, gsize slice_size)
|
2020-03-22 18:00:50 +00:00
|
|
|
{
|
|
|
|
VABufferID params_buffer, slice_buffer;
|
|
|
|
VADisplay dpy;
|
|
|
|
VAStatus status;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
g_return_val_if_fail (self->context != VA_INVALID_ID, FALSE);
|
|
|
|
g_return_val_if_fail (pic && slice_data && slice_size > 0
|
|
|
|
&& params_data && params_size > 0, FALSE);
|
|
|
|
|
|
|
|
dpy = gst_va_display_get_va_dpy (self->display);
|
|
|
|
status = vaCreateBuffer (dpy, self->context, VASliceParameterBufferType,
|
2021-01-19 07:07:38 +00:00
|
|
|
params_size, params_num, params_data, ¶ms_buffer);
|
2020-03-22 18:00:50 +00:00
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
|
|
|
GST_ERROR_OBJECT (self, "vaCreateBuffer: %s", vaErrorStr (status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = vaCreateBuffer (dpy, self->context, VASliceDataBufferType,
|
|
|
|
slice_size, 1, slice_data, &slice_buffer);
|
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
|
|
|
GST_ERROR_OBJECT (self, "vaCreateBuffer: %s", vaErrorStr (status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_append_val (pic->slices, params_buffer);
|
|
|
|
g_array_append_val (pic->slices, slice_buffer);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-01-19 07:07:38 +00:00
|
|
|
gboolean
|
|
|
|
gst_va_decoder_add_slice_buffer (GstVaDecoder * self, GstVaDecodePicture * pic,
|
|
|
|
gpointer params_data, gsize params_size, gpointer slice_data,
|
|
|
|
gsize slice_size)
|
|
|
|
{
|
|
|
|
return gst_va_decoder_add_slice_buffer_with_n_params (self, pic, params_data,
|
|
|
|
params_size, 1, slice_data, slice_size);
|
|
|
|
}
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
gboolean
|
2021-01-19 07:17:58 +00:00
|
|
|
gst_va_decoder_decode_with_aux_surface (GstVaDecoder * self,
|
|
|
|
GstVaDecodePicture * pic, gboolean use_aux)
|
2020-03-22 18:00:50 +00:00
|
|
|
{
|
|
|
|
VADisplay dpy;
|
|
|
|
VAStatus status;
|
2021-01-19 07:17:58 +00:00
|
|
|
VASurfaceID surface = VA_INVALID_ID;
|
2020-03-22 18:00:50 +00:00
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
g_return_val_if_fail (self->context != VA_INVALID_ID, FALSE);
|
2020-09-24 10:29:49 +00:00
|
|
|
g_return_val_if_fail (pic, FALSE);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
2021-01-19 07:17:58 +00:00
|
|
|
if (use_aux) {
|
|
|
|
surface = gst_va_decode_picture_get_aux_surface (pic);
|
|
|
|
} else {
|
|
|
|
surface = gst_va_decode_picture_get_surface (pic);
|
|
|
|
}
|
2020-09-24 10:29:49 +00:00
|
|
|
if (surface == VA_INVALID_ID) {
|
|
|
|
GST_ERROR_OBJECT (self, "Decode picture without VASurfaceID");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_TRACE_OBJECT (self, "Decode to surface %#x", surface);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
dpy = gst_va_display_get_va_dpy (self->display);
|
|
|
|
|
2020-09-24 10:29:49 +00:00
|
|
|
status = vaBeginPicture (dpy, self->context, surface);
|
2020-03-22 18:00:50 +00:00
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
2020-09-17 17:54:28 +00:00
|
|
|
GST_WARNING_OBJECT (self, "vaBeginPicture: %s", vaErrorStr (status));
|
2020-03-22 18:00:50 +00:00
|
|
|
goto fail_end_pic;
|
|
|
|
}
|
|
|
|
|
2020-09-19 12:08:46 +00:00
|
|
|
if (pic->buffers->len > 0) {
|
|
|
|
status = vaRenderPicture (dpy, self->context,
|
|
|
|
(VABufferID *) pic->buffers->data, pic->buffers->len);
|
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
|
|
|
GST_WARNING_OBJECT (self, "vaRenderPicture: %s", vaErrorStr (status));
|
|
|
|
goto fail_end_pic;
|
|
|
|
}
|
2020-03-22 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 12:08:46 +00:00
|
|
|
if (pic->slices->len > 0) {
|
|
|
|
status = vaRenderPicture (dpy, self->context,
|
|
|
|
(VABufferID *) pic->slices->data, pic->slices->len);
|
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
|
|
|
GST_WARNING_OBJECT (self, "vaRenderPicture: %s", vaErrorStr (status));
|
|
|
|
goto fail_end_pic;
|
|
|
|
}
|
2020-03-22 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status = vaEndPicture (dpy, self->context);
|
2020-11-30 14:01:01 +00:00
|
|
|
if (status != VA_STATUS_SUCCESS)
|
2020-09-17 17:54:28 +00:00
|
|
|
GST_WARNING_OBJECT (self, "vaEndPicture: %s", vaErrorStr (status));
|
2020-11-30 14:01:01 +00:00
|
|
|
else
|
|
|
|
ret = TRUE;
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
bail:
|
2020-11-30 14:01:01 +00:00
|
|
|
_destroy_buffers (pic);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
fail_end_pic:
|
|
|
|
{
|
|
|
|
status = vaEndPicture (dpy, self->context);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-19 07:17:58 +00:00
|
|
|
gboolean
|
|
|
|
gst_va_decoder_decode (GstVaDecoder * self, GstVaDecodePicture * pic)
|
|
|
|
{
|
|
|
|
return gst_va_decoder_decode_with_aux_surface (self, pic, FALSE);
|
|
|
|
}
|
|
|
|
|
2021-07-17 18:45:48 +00:00
|
|
|
gboolean
|
|
|
|
gst_va_decoder_config_is_equal (GstVaDecoder * self, VAProfile new_profile,
|
|
|
|
guint new_rtformat, gint new_width, gint new_height)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
|
|
|
|
/* @TODO: Check if current buffers are large enough, and reuse
|
|
|
|
* them */
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
ret = (self->profile == new_profile && self->rt_format == new_rtformat
|
|
|
|
&& self->coded_width == new_width && self->coded_height == new_height);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-07-17 18:48:21 +00:00
|
|
|
gboolean
|
|
|
|
gst_va_decoder_get_config (GstVaDecoder * self, VAProfile * profile,
|
|
|
|
guint * rt_format, gint * width, gint * height)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_VA_DECODER (self), FALSE);
|
|
|
|
|
|
|
|
if (!gst_va_decoder_is_open (self))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
if (profile)
|
|
|
|
*profile = self->profile;
|
|
|
|
if (rt_format)
|
|
|
|
*rt_format = self->rt_format;
|
|
|
|
if (width)
|
|
|
|
*width = self->coded_width;
|
|
|
|
if (height)
|
|
|
|
*height = self->coded_height;
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-11-26 06:04:31 +00:00
|
|
|
static gboolean
|
2020-11-30 14:01:01 +00:00
|
|
|
_destroy_buffers (GstVaDecodePicture * pic)
|
2020-03-22 18:00:50 +00:00
|
|
|
{
|
2022-09-22 16:53:30 +00:00
|
|
|
GstVaDisplay *display;
|
2020-03-22 18:00:50 +00:00
|
|
|
VABufferID buffer;
|
|
|
|
VADisplay dpy;
|
|
|
|
VAStatus status;
|
|
|
|
guint i;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
2022-09-22 16:53:30 +00:00
|
|
|
display = gst_va_buffer_peek_display (pic->gstbuffer);
|
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
dpy = gst_va_display_get_va_dpy (display);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
2021-10-13 07:58:29 +00:00
|
|
|
if (pic->buffers) {
|
|
|
|
for (i = 0; i < pic->buffers->len; i++) {
|
|
|
|
buffer = g_array_index (pic->buffers, VABufferID, i);
|
|
|
|
status = vaDestroyBuffer (dpy, buffer);
|
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
|
|
|
ret = FALSE;
|
|
|
|
GST_WARNING ("Failed to destroy parameter buffer: %s",
|
|
|
|
vaErrorStr (status));
|
|
|
|
}
|
2020-03-22 18:00:50 +00:00
|
|
|
}
|
2021-10-13 07:58:29 +00:00
|
|
|
|
|
|
|
pic->buffers = g_array_set_size (pic->buffers, 0);
|
2020-03-22 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
2021-10-13 07:58:29 +00:00
|
|
|
if (pic->slices) {
|
|
|
|
for (i = 0; i < pic->slices->len; i++) {
|
|
|
|
buffer = g_array_index (pic->slices, VABufferID, i);
|
|
|
|
status = vaDestroyBuffer (dpy, buffer);
|
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
|
|
|
ret = FALSE;
|
|
|
|
GST_WARNING ("Failed to destroy slice buffer: %s", vaErrorStr (status));
|
|
|
|
}
|
2020-03-22 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
2021-10-13 07:58:29 +00:00
|
|
|
pic->slices = g_array_set_size (pic->slices, 0);
|
|
|
|
}
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstVaDecodePicture *
|
2020-11-26 06:04:31 +00:00
|
|
|
gst_va_decode_picture_new (GstVaDecoder * self, GstBuffer * buffer)
|
2020-03-22 18:00:50 +00:00
|
|
|
{
|
|
|
|
GstVaDecodePicture *pic;
|
|
|
|
|
2020-09-24 10:29:49 +00:00
|
|
|
g_return_val_if_fail (buffer && GST_IS_BUFFER (buffer), NULL);
|
2020-11-26 06:04:31 +00:00
|
|
|
g_return_val_if_fail (self && GST_IS_VA_DECODER (self), NULL);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
2023-03-06 16:16:26 +00:00
|
|
|
pic = g_new (GstVaDecodePicture, 1);
|
2020-09-24 10:29:49 +00:00
|
|
|
pic->gstbuffer = gst_buffer_ref (buffer);
|
2020-03-22 18:00:50 +00:00
|
|
|
pic->buffers = g_array_sized_new (FALSE, FALSE, sizeof (VABufferID), 16);
|
|
|
|
pic->slices = g_array_sized_new (FALSE, FALSE, sizeof (VABufferID), 64);
|
|
|
|
|
|
|
|
return pic;
|
|
|
|
}
|
|
|
|
|
2020-09-24 10:29:49 +00:00
|
|
|
VASurfaceID
|
|
|
|
gst_va_decode_picture_get_surface (GstVaDecodePicture * pic)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (pic, VA_INVALID_ID);
|
|
|
|
g_return_val_if_fail (pic->gstbuffer, VA_INVALID_ID);
|
|
|
|
|
2020-10-06 17:54:26 +00:00
|
|
|
return gst_va_buffer_get_surface (pic->gstbuffer);
|
2020-09-24 10:29:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-19 07:17:58 +00:00
|
|
|
VASurfaceID
|
|
|
|
gst_va_decode_picture_get_aux_surface (GstVaDecodePicture * pic)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (pic, VA_INVALID_ID);
|
|
|
|
g_return_val_if_fail (pic->gstbuffer, VA_INVALID_ID);
|
|
|
|
|
|
|
|
return gst_va_buffer_get_aux_surface (pic->gstbuffer);
|
|
|
|
}
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
void
|
|
|
|
gst_va_decode_picture_free (GstVaDecodePicture * pic)
|
|
|
|
{
|
|
|
|
g_return_if_fail (pic);
|
|
|
|
|
2021-10-13 07:58:29 +00:00
|
|
|
_destroy_buffers (pic);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
2020-09-24 10:29:49 +00:00
|
|
|
gst_buffer_unref (pic->gstbuffer);
|
2020-03-22 18:00:50 +00:00
|
|
|
g_clear_pointer (&pic->buffers, g_array_unref);
|
|
|
|
g_clear_pointer (&pic->slices, g_array_unref);
|
|
|
|
|
2023-03-06 16:16:26 +00:00
|
|
|
g_free (pic);
|
2020-03-22 18:00:50 +00:00
|
|
|
}
|
2020-09-21 04:51:53 +00:00
|
|
|
|
2020-10-12 17:20:10 +00:00
|
|
|
GstVaDecodePicture *
|
|
|
|
gst_va_decode_picture_dup (GstVaDecodePicture * pic)
|
|
|
|
{
|
|
|
|
GstVaDecodePicture *dup;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pic, NULL);
|
|
|
|
|
2023-03-06 16:16:26 +00:00
|
|
|
dup = g_new0 (GstVaDecodePicture, 1);
|
2020-10-12 17:20:10 +00:00
|
|
|
|
2020-11-30 16:12:14 +00:00
|
|
|
/* dups only need gstbuffer */
|
|
|
|
dup->gstbuffer = gst_buffer_ref (pic->gstbuffer);
|
2020-10-12 17:20:10 +00:00
|
|
|
return dup;
|
|
|
|
}
|