mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
Fix GstVaapiDisplay initialization.
This commit is contained in:
parent
0dd58839e1
commit
5fdc1dc943
3 changed files with 122 additions and 135 deletions
|
@ -53,12 +53,110 @@ enum {
|
||||||
static void
|
static void
|
||||||
gst_vaapi_display_set_display(GstVaapiDisplay *display, VADisplay va_display);
|
gst_vaapi_display_set_display(GstVaapiDisplay *display, VADisplay va_display);
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_vaapi_display_destroy(GstVaapiDisplay *display)
|
||||||
|
{
|
||||||
|
GstVaapiDisplayPrivate * const priv = display->priv;
|
||||||
|
|
||||||
|
if (priv->profiles) {
|
||||||
|
g_free(priv->profiles);
|
||||||
|
priv->profiles = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priv->image_formats) {
|
||||||
|
g_free(priv->image_formats);
|
||||||
|
priv->image_formats = NULL;
|
||||||
|
priv->num_image_formats = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priv->subpicture_formats) {
|
||||||
|
g_free(priv->subpicture_formats);
|
||||||
|
priv->subpicture_formats = NULL;
|
||||||
|
priv->num_subpicture_formats = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priv->subpicture_flags) {
|
||||||
|
g_free(priv->subpicture_flags);
|
||||||
|
priv->subpicture_flags = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priv->display) {
|
||||||
|
vaTerminate(priv->display);
|
||||||
|
priv->display = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_vaapi_display_create(GstVaapiDisplay *display)
|
||||||
|
{
|
||||||
|
GstVaapiDisplayPrivate * const priv = display->priv;
|
||||||
|
VAStatus status;
|
||||||
|
int major_version, minor_version;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
status = vaInitialize(priv->display, &major_version, &minor_version);
|
||||||
|
if (!vaapi_check_status(status, "vaInitialize()"))
|
||||||
|
return FALSE;
|
||||||
|
D(bug("VA-API version %d.%d\n", major_version, minor_version));
|
||||||
|
|
||||||
|
/* VA profiles */
|
||||||
|
priv->num_profiles = vaMaxNumProfiles(priv->display);
|
||||||
|
priv->profiles = g_new(VAProfile, priv->num_profiles);
|
||||||
|
if (!priv->profiles)
|
||||||
|
return FALSE;
|
||||||
|
status = vaQueryConfigProfiles(priv->display,
|
||||||
|
priv->profiles,
|
||||||
|
&priv->num_profiles);
|
||||||
|
if (!vaapi_check_status(status, "vaQueryConfigProfiles()"))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
D(bug("%d profiles\n", priv->num_profiles));
|
||||||
|
for (i = 0; i < priv->num_profiles; i++)
|
||||||
|
D(bug(" %s\n", string_of_VAProfile(priv->profiles[i])));
|
||||||
|
|
||||||
|
/* VA image formats */
|
||||||
|
priv->num_image_formats = vaMaxNumImageFormats(priv->display);
|
||||||
|
priv->image_formats = g_new(VAImageFormat, priv->num_image_formats);
|
||||||
|
if (!priv->image_formats)
|
||||||
|
return FALSE;
|
||||||
|
status = vaQueryImageFormats(priv->display,
|
||||||
|
priv->image_formats,
|
||||||
|
&priv->num_image_formats);
|
||||||
|
if (!vaapi_check_status(status, "vaQueryImageFormats()"))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
D(bug("%d image formats\n", priv->num_image_formats));
|
||||||
|
for (i = 0; i < priv->num_image_formats; i++)
|
||||||
|
D(bug(" %s\n", string_of_FOURCC(priv->image_formats[i].fourcc)));
|
||||||
|
|
||||||
|
/* VA subpicture formats */
|
||||||
|
priv->num_subpicture_formats = vaMaxNumSubpictureFormats(priv->display);
|
||||||
|
priv->subpicture_formats = g_new(VAImageFormat, priv->num_subpicture_formats);
|
||||||
|
if (!priv->subpicture_formats)
|
||||||
|
return FALSE;
|
||||||
|
priv->subpicture_flags = g_new(unsigned int, priv->num_subpicture_formats);
|
||||||
|
if (!priv->subpicture_flags)
|
||||||
|
return FALSE;
|
||||||
|
status = vaQuerySubpictureFormats(priv->display,
|
||||||
|
priv->subpicture_formats,
|
||||||
|
priv->subpicture_flags,
|
||||||
|
&priv->num_subpicture_formats);
|
||||||
|
if (!vaapi_check_status(status, "vaQuerySubpictureFormats()"))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
D(bug("%d subpicture formats\n", priv->num_subpicture_formats));
|
||||||
|
for (i = 0; i < priv->num_subpicture_formats; i++)
|
||||||
|
D(bug(" %s\n", string_of_FOURCC(priv->subpicture_formats[i].fourcc)));
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vaapi_display_finalize(GObject *object)
|
gst_vaapi_display_finalize(GObject *object)
|
||||||
{
|
{
|
||||||
GstVaapiDisplay * const display = GST_VAAPI_DISPLAY(object);
|
GstVaapiDisplay * const display = GST_VAAPI_DISPLAY(object);
|
||||||
|
|
||||||
gst_vaapi_display_set_display(display, NULL);
|
gst_vaapi_display_destroy(display);
|
||||||
|
|
||||||
G_OBJECT_CLASS(gst_vaapi_display_parent_class)->finalize(object);
|
G_OBJECT_CLASS(gst_vaapi_display_parent_class)->finalize(object);
|
||||||
}
|
}
|
||||||
|
@ -135,129 +233,37 @@ gst_vaapi_display_init(GstVaapiDisplay *display)
|
||||||
priv->num_subpicture_formats = 0;
|
priv->num_subpicture_formats = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GstVaapiDisplay *
|
||||||
|
gst_vaapi_display_new_with_display(VADisplay va_display)
|
||||||
|
{
|
||||||
|
return g_object_new(GST_VAAPI_TYPE_DISPLAY,
|
||||||
|
"display", va_display,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
VADisplay
|
VADisplay
|
||||||
gst_vaapi_display_get_display(GstVaapiDisplay *display)
|
gst_vaapi_display_get_display(GstVaapiDisplay *display)
|
||||||
{
|
{
|
||||||
GstVaapiDisplayPrivate *priv = display->priv;
|
|
||||||
|
|
||||||
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
|
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
|
||||||
|
|
||||||
return priv->display;
|
return display->priv->display;
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_vaapi_display_destroy_resources(GstVaapiDisplay *display)
|
|
||||||
{
|
|
||||||
GstVaapiDisplayPrivate *priv = display->priv;
|
|
||||||
|
|
||||||
if (priv->profiles) {
|
|
||||||
g_free(priv->profiles);
|
|
||||||
priv->profiles = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (priv->image_formats) {
|
|
||||||
g_free(priv->image_formats);
|
|
||||||
priv->image_formats = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (priv->subpicture_formats) {
|
|
||||||
g_free(priv->subpicture_formats);
|
|
||||||
priv->subpicture_formats = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (priv->subpicture_flags) {
|
|
||||||
g_free(priv->subpicture_flags);
|
|
||||||
priv->subpicture_flags = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_vaapi_display_create_resources(GstVaapiDisplay *display)
|
|
||||||
{
|
|
||||||
GstVaapiDisplayPrivate *priv = display->priv;
|
|
||||||
VAStatus status;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
/* VA profiles */
|
|
||||||
priv->num_profiles = vaMaxNumProfiles(priv->display);
|
|
||||||
priv->profiles = g_new(VAProfile, priv->num_profiles);
|
|
||||||
if (!priv->profiles)
|
|
||||||
return FALSE;
|
|
||||||
status = vaQueryConfigProfiles(priv->display,
|
|
||||||
priv->profiles,
|
|
||||||
&priv->num_profiles);
|
|
||||||
if (!vaapi_check_status(status, "vaQueryConfigProfiles()"))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
D(bug("%d profiles\n", priv->num_profiles));
|
|
||||||
for (i = 0; i < priv->num_profiles; i++)
|
|
||||||
D(bug(" %s\n", string_of_VAProfile(priv->profiles[i])));
|
|
||||||
|
|
||||||
/* VA image formats */
|
|
||||||
priv->num_image_formats = vaMaxNumImageFormats(priv->display);
|
|
||||||
priv->image_formats = g_new(VAImageFormat, priv->num_image_formats);
|
|
||||||
if (!priv->image_formats)
|
|
||||||
return FALSE;
|
|
||||||
status = vaQueryImageFormats(priv->display,
|
|
||||||
priv->image_formats,
|
|
||||||
&priv->num_image_formats);
|
|
||||||
if (!vaapi_check_status(status, "vaQueryImageFormats()"))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
D(bug("%d image formats\n", priv->num_image_formats));
|
|
||||||
for (i = 0; i < priv->num_image_formats; i++)
|
|
||||||
D(bug(" %s\n", string_of_FOURCC(priv->image_formats[i].fourcc)));
|
|
||||||
|
|
||||||
/* VA subpicture formats */
|
|
||||||
priv->num_subpicture_formats = vaMaxNumSubpictureFormats(priv->display);
|
|
||||||
priv->subpicture_formats = g_new(VAImageFormat, priv->num_subpicture_formats);
|
|
||||||
if (!priv->subpicture_formats)
|
|
||||||
return FALSE;
|
|
||||||
priv->subpicture_flags = g_new(unsigned int, priv->num_subpicture_formats);
|
|
||||||
if (!priv->subpicture_flags)
|
|
||||||
return FALSE;
|
|
||||||
status = vaQuerySubpictureFormats(priv->display,
|
|
||||||
priv->subpicture_formats,
|
|
||||||
priv->subpicture_flags,
|
|
||||||
&priv->num_subpicture_formats);
|
|
||||||
if (!vaapi_check_status(status, "vaQuerySubpictureFormats()"))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
D(bug("%d subpicture formats\n", priv->num_subpicture_formats));
|
|
||||||
for (i = 0; i < priv->num_subpicture_formats; i++)
|
|
||||||
D(bug(" %s\n", string_of_FOURCC(priv->subpicture_formats[i].fourcc)));
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_vaapi_display_set_display(GstVaapiDisplay *display, VADisplay va_display)
|
gst_vaapi_display_set_display(GstVaapiDisplay *display, VADisplay va_display)
|
||||||
{
|
{
|
||||||
GstVaapiDisplayPrivate *priv = display->priv;
|
GstVaapiDisplayPrivate * const priv = display->priv;
|
||||||
VAStatus status;
|
|
||||||
int major_version, minor_version;
|
|
||||||
|
|
||||||
g_return_if_fail(GST_VAAPI_IS_DISPLAY(display));
|
g_return_if_fail(GST_VAAPI_IS_DISPLAY(display));
|
||||||
|
|
||||||
if (priv->display) {
|
if (priv->display)
|
||||||
gst_vaapi_display_destroy_resources(display);
|
gst_vaapi_display_destroy(display);
|
||||||
|
|
||||||
/* XXX: make sure this VADisplay is really the last occurrence */
|
|
||||||
status = vaTerminate(priv->display);
|
|
||||||
if (!vaapi_check_status(status, "vaTerminate()"))
|
|
||||||
return;
|
|
||||||
priv->display = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (va_display) {
|
if (va_display) {
|
||||||
status = vaInitialize(va_display, &major_version, &minor_version);
|
|
||||||
if (!vaapi_check_status(status, "vaInitialize()"))
|
|
||||||
return;
|
|
||||||
priv->display = va_display;
|
priv->display = va_display;
|
||||||
D(bug("VA-API version %d.%d\n", major_version, minor_version));
|
if (!gst_vaapi_display_create(display)) {
|
||||||
|
printf("FAIL\n");
|
||||||
if (!gst_vaapi_display_create_resources(display)) {
|
gst_vaapi_display_destroy(display);
|
||||||
gst_vaapi_display_destroy_resources(display);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,9 @@ struct _GstVaapiDisplayClass {
|
||||||
GType
|
GType
|
||||||
gst_vaapi_display_get_type(void);
|
gst_vaapi_display_get_type(void);
|
||||||
|
|
||||||
|
GstVaapiDisplay *
|
||||||
|
gst_vaapi_display_new_with_display(VADisplay va_display);
|
||||||
|
|
||||||
VADisplay
|
VADisplay
|
||||||
gst_vaapi_display_get_display(GstVaapiDisplay *display);
|
gst_vaapi_display_get_display(GstVaapiDisplay *display);
|
||||||
|
|
||||||
|
|
|
@ -44,10 +44,6 @@ enum {
|
||||||
PROP_X11_DISPLAY
|
PROP_X11_DISPLAY
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
gst_vaapi_display_x11_set_display(GstVaapiDisplayX11 *display,
|
|
||||||
Display *x11_display);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vaapi_display_x11_finalize(GObject *object)
|
gst_vaapi_display_x11_finalize(GObject *object)
|
||||||
{
|
{
|
||||||
|
@ -64,7 +60,7 @@ gst_vaapi_display_x11_set_property(GObject *object,
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_X11_DISPLAY:
|
case PROP_X11_DISPLAY:
|
||||||
gst_vaapi_display_x11_set_display(display, g_value_get_pointer(value));
|
display->priv->display = 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);
|
||||||
|
@ -122,36 +118,18 @@ gst_vaapi_display_x11_init(GstVaapiDisplayX11 *display)
|
||||||
Display *
|
Display *
|
||||||
gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
|
gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
|
||||||
{
|
{
|
||||||
GstVaapiDisplayX11Private *priv = display->priv;
|
|
||||||
|
|
||||||
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
|
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
|
||||||
|
|
||||||
return priv->display;
|
return display->priv->display;
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_vaapi_display_x11_set_display(GstVaapiDisplayX11 *display,
|
|
||||||
Display *x11_display)
|
|
||||||
{
|
|
||||||
GstVaapiDisplayX11Private *priv = display->priv;
|
|
||||||
|
|
||||||
g_return_if_fail(GST_VAAPI_IS_DISPLAY_X11(display));
|
|
||||||
|
|
||||||
if (x11_display) {
|
|
||||||
VADisplay va_display = vaGetDisplay(x11_display);
|
|
||||||
if (va_display)
|
|
||||||
g_object_set(GST_VAAPI_DISPLAY(display),
|
|
||||||
"display", va_display,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->display = x11_display;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GstVaapiDisplay *
|
GstVaapiDisplay *
|
||||||
gst_vaapi_display_x11_new(Display *x11_display)
|
gst_vaapi_display_x11_new(Display *x11_display)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail(x11_display, NULL);
|
||||||
|
|
||||||
return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
|
return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
|
||||||
"x11-display", x11_display,
|
"x11-display", x11_display,
|
||||||
|
"display", vaGetDisplay(x11_display),
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue