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.
This commit is contained in:
Víctor Manuel Jáquez Leal 2019-08-05 19:47:30 +02:00
parent 4b5459b1b1
commit f7c1ac036d
5 changed files with 171 additions and 3 deletions

View file

@ -63,6 +63,7 @@ libgstvaapi_source_c = \
gstvaapiparser_frame.c \ gstvaapiparser_frame.c \
gstvaapipixmap.c \ gstvaapipixmap.c \
gstvaapiprofile.c \ gstvaapiprofile.c \
gstvaapiprofilecaps.c \
gstvaapisubpicture.c \ gstvaapisubpicture.c \
gstvaapisurface.c \ gstvaapisurface.c \
gstvaapisurface_drm.c \ gstvaapisurface_drm.c \
@ -97,6 +98,7 @@ libgstvaapi_source_h = \
gstvaapiobject.h \ gstvaapiobject.h \
gstvaapipixmap.h \ gstvaapipixmap.h \
gstvaapiprofile.h \ gstvaapiprofile.h \
gstvaapiprofilecaps.h \
gstvaapisubpicture.h \ gstvaapisubpicture.h \
gstvaapisurface.h \ gstvaapisurface.h \
gstvaapisurface_drm.h \ gstvaapisurface_drm.h \

View file

@ -0,0 +1,118 @@
/*
* gstvaapiprofilecaps.h - VA config attributes as gstreamer capabilities
*
* Copyright (C) 2019 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 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;
}

View file

@ -0,0 +1,42 @@
/*
* gstvaapiprofilecaps.h - VA config attributes as gstreamer capabilities
*
* Copyright (C) 2019 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 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 <gst/gst.h>
#include <gst/vaapi/gstvaapidisplay.h>
#include <gst/vaapi/gstvaapiprofile.h>
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 */

View file

@ -24,6 +24,7 @@ gstlibvaapi_sources = [
'gstvaapiparser_frame.c', 'gstvaapiparser_frame.c',
'gstvaapipixmap.c', 'gstvaapipixmap.c',
'gstvaapiprofile.c', 'gstvaapiprofile.c',
'gstvaapiprofilecaps.c',
'gstvaapisubpicture.c', 'gstvaapisubpicture.c',
'gstvaapisurface.c', 'gstvaapisurface.c',
'gstvaapisurface_drm.c', 'gstvaapisurface_drm.c',
@ -61,6 +62,7 @@ gstlibvaapi_headers = [
'gstvaapiobject.h', 'gstvaapiobject.h',
'gstvaapipixmap.h', 'gstvaapipixmap.h',
'gstvaapiprofile.h', 'gstvaapiprofile.h',
'gstvaapiprofilecaps.h',
'gstvaapisubpicture.h', 'gstvaapisubpicture.h',
'gstvaapisurface.h', 'gstvaapisurface.h',
'gstvaapisurface_drm.h', 'gstvaapisurface_drm.h',

View file

@ -24,6 +24,7 @@
#include "gstcompat.h" #include "gstcompat.h"
#include <gst/vaapi/gstvaapidisplay.h> #include <gst/vaapi/gstvaapidisplay.h>
#include <gst/vaapi/gstvaapiprofilecaps.h>
#include "gstvaapidecode.h" #include "gstvaapidecode.h"
#include "gstvaapidecode_props.h" #include "gstvaapidecode_props.h"
@ -1214,15 +1215,14 @@ gst_vaapidecode_ensure_allowed_sinkpad_caps (GstVaapiDecode * decode)
{ {
GstCaps *caps, *allowed_sinkpad_caps; GstCaps *caps, *allowed_sinkpad_caps;
GArray *profiles; GArray *profiles;
GstVaapiDisplay *const display = GST_VAAPI_PLUGIN_BASE_DISPLAY (decode);
guint i; guint i;
gboolean base_only = FALSE; gboolean base_only = FALSE;
gboolean have_high = FALSE; gboolean have_high = FALSE;
gboolean have_mvc = FALSE; gboolean have_mvc = FALSE;
gboolean have_svc = FALSE; gboolean have_svc = FALSE;
profiles = profiles = gst_vaapi_display_get_decode_profiles (display);
gst_vaapi_display_get_decode_profiles (GST_VAAPI_PLUGIN_BASE_DISPLAY
(decode));
if (!profiles) if (!profiles)
goto error_no_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, gst_structure_set (structure, "profile", G_TYPE_STRING,
profile_name, NULL); profile_name, NULL);
gst_vaapi_profile_caps_append_decoder (display, profile, structure);
allowed_sinkpad_caps = gst_caps_merge (allowed_sinkpad_caps, caps); allowed_sinkpad_caps = gst_caps_merge (allowed_sinkpad_caps, caps);
have_mvc |= is_mvc_profile (profile); have_mvc |= is_mvc_profile (profile);
have_svc |= is_svc_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); 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); g_array_unref (profiles);
return TRUE; return TRUE;