From f7c1ac036d11b1120664ce79cbdc7d311144fd41 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Mon, 5 Aug 2019 19:47:30 +0200 Subject: [PATCH] libs: profilecaps: move caps config into a new file Implement all the appending of frame size restrictions in caps, for encoders and decoders, in a new source file. --- gst-libs/gst/vaapi/Makefile.am | 2 + gst-libs/gst/vaapi/gstvaapiprofilecaps.c | 118 +++++++++++++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapiprofilecaps.h | 42 +++++++++++ gst-libs/gst/vaapi/meson.build | 2 + gst/vaapi/gstvaapidecode.c | 10 ++- 5 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 gst-libs/gst/vaapi/gstvaapiprofilecaps.c create mode 100644 gst-libs/gst/vaapi/gstvaapiprofilecaps.h diff --git a/gst-libs/gst/vaapi/Makefile.am b/gst-libs/gst/vaapi/Makefile.am index 50ca973..4016933 100644 --- a/gst-libs/gst/vaapi/Makefile.am +++ b/gst-libs/gst/vaapi/Makefile.am @@ -63,6 +63,7 @@ libgstvaapi_source_c = \ gstvaapiparser_frame.c \ gstvaapipixmap.c \ gstvaapiprofile.c \ + gstvaapiprofilecaps.c \ gstvaapisubpicture.c \ gstvaapisurface.c \ gstvaapisurface_drm.c \ @@ -97,6 +98,7 @@ libgstvaapi_source_h = \ gstvaapiobject.h \ gstvaapipixmap.h \ gstvaapiprofile.h \ + gstvaapiprofilecaps.h \ gstvaapisubpicture.h \ gstvaapisurface.h \ gstvaapisurface_drm.h \ diff --git a/gst-libs/gst/vaapi/gstvaapiprofilecaps.c b/gst-libs/gst/vaapi/gstvaapiprofilecaps.c new file mode 100644 index 0000000..b786b77 --- /dev/null +++ b/gst-libs/gst/vaapi/gstvaapiprofilecaps.c @@ -0,0 +1,118 @@ +/* + * gstvaapiprofilecaps.h - VA config attributes as gstreamer capabilities + * + * Copyright (C) 2019 Igalia, S.L. + * Author: Víctor Jáquez + * + * 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. + * + * 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 + * Lesser General Public License for more details. + * + * 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 + */ + +/** + * SECTION:gstvaapiprofilecaps + * @short_description: VA config attributes as gstreamer capabilities + */ + +#include "sysdeps.h" +#include "gstvaapicompat.h" +#include "gstvaapicontext.h" +#include "gstvaapiprofilecaps.h" +#include "gstvaapiutils.h" + +static gboolean +init_context_info (GstVaapiDisplay * display, GstVaapiContextInfo * cip) +{ + guint value = 0; + + /* XXX: Only try a context from he first RTFormat in config. */ + if (!gst_vaapi_get_config_attribute (display, + gst_vaapi_profile_get_va_profile (cip->profile), + gst_vaapi_entrypoint_get_va_entrypoint (cip->entrypoint), + VAConfigAttribRTFormat, &value)) { + return FALSE; + } + + cip->chroma_type = to_GstVaapiChromaType (value); + return cip->chroma_type != 0; +} + +static GstVaapiContext * +create_context (GstVaapiDisplay * display, GstVaapiContextInfo * cip) +{ + if (!init_context_info (display, cip)) + return NULL; + return gst_vaapi_context_new (display, cip); +} + +static gboolean +append_caps (GstVaapiContext * context, GstStructure * structure) +{ + GstVaapiConfigSurfaceAttributes attribs = { 0, }; + + if (!gst_vaapi_context_get_surface_attributes (context, &attribs)) + return FALSE; + + if (attribs.min_width >= attribs.max_width || + attribs.min_height >= attribs.max_height) + return FALSE; + + gst_structure_set (structure, "width", GST_TYPE_INT_RANGE, attribs.min_width, + attribs.max_width, "height", GST_TYPE_INT_RANGE, attribs.min_height, + attribs.max_height, NULL); + + return TRUE; +} + +/** + * gst_vaapi_decoder_add_profile_caps: + * @display: a #GstVaapiDisplay + * @profile: a #GstVaapiProfile + * @structure: a #GstStructure + * + * Extracts the config's surface attributes, from @profile, in an + * decoder context, and transforms it into a caps formats and appended + * into @structure. + * + * Returns: %TRUE if the capabilities could be extracted and appended + * into @structure; otherwise %FALSE + **/ +gboolean +gst_vaapi_profile_caps_append_decoder (GstVaapiDisplay * display, + GstVaapiProfile profile, GstStructure * structure) +{ + GstVaapiContext *context; + GstVaapiContextInfo cip = { + GST_VAAPI_CONTEXT_USAGE_DECODE, profile, GST_VAAPI_ENTRYPOINT_VLD, 0, + }; + gboolean ret; + + g_return_val_if_fail (display != NULL, FALSE); + g_return_val_if_fail (structure != NULL, FALSE); + + context = create_context (display, &cip); + if (!context) + return FALSE; + + ret = append_caps (context, structure); + gst_vaapi_object_unref (context); + return ret; +} + +gboolean +gst_vaapi_profile_caps_append_encoder (GstVaapiDisplay * display, + GstVaapiProfile profile, GstStructure * structure) +{ + return TRUE; +} diff --git a/gst-libs/gst/vaapi/gstvaapiprofilecaps.h b/gst-libs/gst/vaapi/gstvaapiprofilecaps.h new file mode 100644 index 0000000..e7c7d58 --- /dev/null +++ b/gst-libs/gst/vaapi/gstvaapiprofilecaps.h @@ -0,0 +1,42 @@ +/* + * gstvaapiprofilecaps.h - VA config attributes as gstreamer capabilities + * + * Copyright (C) 2019 Igalia, S.L. + * Author: Víctor Jáquez + * + * 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. + * + * 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 + * Lesser General Public License for more details. + * + * 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 + */ + +#ifndef GST_VAAPI_PROFILE_CAPS_H +#define GST_VAAPI_PROFILE_CAPS_H + +#include +#include +#include + +G_BEGIN_DECLS + +gboolean +gst_vaapi_profile_caps_append_decoder (GstVaapiDisplay * display, + GstVaapiProfile profile, GstStructure * structure); + +gboolean +gst_vaapi_profile_caps_append_encoder (GstVaapiDisplay * display, + GstVaapiProfile profile, GstStructure * structure); + +G_END_DECLS + +#endif /* GST_VAAPI_PROFILE_CAPS_H */ diff --git a/gst-libs/gst/vaapi/meson.build b/gst-libs/gst/vaapi/meson.build index c5c40f7..eb67b75 100644 --- a/gst-libs/gst/vaapi/meson.build +++ b/gst-libs/gst/vaapi/meson.build @@ -24,6 +24,7 @@ gstlibvaapi_sources = [ 'gstvaapiparser_frame.c', 'gstvaapipixmap.c', 'gstvaapiprofile.c', + 'gstvaapiprofilecaps.c', 'gstvaapisubpicture.c', 'gstvaapisurface.c', 'gstvaapisurface_drm.c', @@ -61,6 +62,7 @@ gstlibvaapi_headers = [ 'gstvaapiobject.h', 'gstvaapipixmap.h', 'gstvaapiprofile.h', + 'gstvaapiprofilecaps.h', 'gstvaapisubpicture.h', 'gstvaapisurface.h', 'gstvaapisurface_drm.h', diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c index 12878d4..6f58906 100644 --- a/gst/vaapi/gstvaapidecode.c +++ b/gst/vaapi/gstvaapidecode.c @@ -24,6 +24,7 @@ #include "gstcompat.h" #include +#include #include "gstvaapidecode.h" #include "gstvaapidecode_props.h" @@ -1214,15 +1215,14 @@ gst_vaapidecode_ensure_allowed_sinkpad_caps (GstVaapiDecode * decode) { GstCaps *caps, *allowed_sinkpad_caps; GArray *profiles; + GstVaapiDisplay *const display = GST_VAAPI_PLUGIN_BASE_DISPLAY (decode); guint i; gboolean base_only = FALSE; gboolean have_high = FALSE; gboolean have_mvc = FALSE; gboolean have_svc = FALSE; - profiles = - gst_vaapi_display_get_decode_profiles (GST_VAAPI_PLUGIN_BASE_DISPLAY - (decode)); + profiles = gst_vaapi_display_get_decode_profiles (display); if (!profiles) goto error_no_profiles; @@ -1255,6 +1255,8 @@ gst_vaapidecode_ensure_allowed_sinkpad_caps (GstVaapiDecode * decode) gst_structure_set (structure, "profile", G_TYPE_STRING, profile_name, NULL); + gst_vaapi_profile_caps_append_decoder (display, profile, structure); + allowed_sinkpad_caps = gst_caps_merge (allowed_sinkpad_caps, caps); have_mvc |= is_mvc_profile (profile); have_svc |= is_svc_profile (profile); @@ -1297,6 +1299,8 @@ gst_vaapidecode_ensure_allowed_sinkpad_caps (GstVaapiDecode * decode) } } decode->allowed_sinkpad_caps = gst_caps_simplify (allowed_sinkpad_caps); + GST_DEBUG_OBJECT (decode, "allowed sink caps %" GST_PTR_FORMAT, + decode->allowed_sinkpad_caps); g_array_unref (profiles); return TRUE; -- 2.7.4