mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
plugins: add helpers to create video caps with features.
Add gst_vaapi_video_format_new_template_caps_with_features() helper function to add the supplied caps feature string on GStreamer >= 1.2. Add gst_vaapi_find_preferred_caps_feature() helper function to discover the "best" caps feature to use for the supplied pad. In practice, we will always favor memory:VASurface first, then meta:GLTextureUploadMeta, and finally the system memory caps. https://bugzilla.gnome.org/show_bug.cgi?id=719372
This commit is contained in:
parent
b065ae7d7f
commit
ef9819ecf4
2 changed files with 111 additions and 0 deletions
|
@ -475,6 +475,98 @@ gst_vaapi_video_format_new_template_caps_from_list (GArray * formats)
|
||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GstCaps *
|
||||||
|
gst_vaapi_video_format_new_template_caps_with_features (GstVideoFormat format,
|
||||||
|
const gchar * features_string)
|
||||||
|
{
|
||||||
|
GstCaps *caps;
|
||||||
|
|
||||||
|
caps = gst_vaapi_video_format_new_template_caps (format);
|
||||||
|
if (!caps)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
#if GST_CHECK_VERSION(1,1,0)
|
||||||
|
GstCapsFeatures *const features =
|
||||||
|
gst_caps_features_new (features_string, NULL);
|
||||||
|
if (!features) {
|
||||||
|
gst_caps_unref (caps);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
gst_caps_set_features (caps, 0, features);
|
||||||
|
#endif
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
GstVaapiCapsFeature
|
||||||
|
gst_vaapi_find_preferred_caps_feature (GstPad * pad, GstVideoFormat format)
|
||||||
|
{
|
||||||
|
GstVaapiCapsFeature feature = GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY;
|
||||||
|
#if GST_CHECK_VERSION(1,1,0)
|
||||||
|
guint i, num_structures;
|
||||||
|
GstCaps *caps = NULL;
|
||||||
|
GstCaps *gl_texture_upload_caps = NULL;
|
||||||
|
GstCaps *sysmem_caps = NULL;
|
||||||
|
GstCaps *vaapi_caps = NULL;
|
||||||
|
GstCaps *out_caps;
|
||||||
|
|
||||||
|
out_caps = gst_pad_peer_query_caps (pad, NULL);
|
||||||
|
if (!out_caps)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
gl_texture_upload_caps =
|
||||||
|
gst_vaapi_video_format_new_template_caps_with_features
|
||||||
|
(GST_VIDEO_FORMAT_RGBA,
|
||||||
|
GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META);
|
||||||
|
if (!gl_texture_upload_caps)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (format == GST_VIDEO_FORMAT_ENCODED)
|
||||||
|
format = GST_VIDEO_FORMAT_NV12;
|
||||||
|
|
||||||
|
vaapi_caps =
|
||||||
|
gst_vaapi_video_format_new_template_caps_with_features (format,
|
||||||
|
GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE);
|
||||||
|
if (!vaapi_caps)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
sysmem_caps =
|
||||||
|
gst_vaapi_video_format_new_template_caps_with_features (format,
|
||||||
|
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
|
||||||
|
if (!sysmem_caps)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
num_structures = gst_caps_get_size (out_caps);
|
||||||
|
for (i = 0; i < num_structures; i++) {
|
||||||
|
GstCapsFeatures *const features = gst_caps_get_features (out_caps, i);
|
||||||
|
GstStructure *const structure = gst_caps_get_structure (out_caps, i);
|
||||||
|
|
||||||
|
caps = gst_caps_new_full (gst_structure_copy (structure), NULL);
|
||||||
|
if (!caps)
|
||||||
|
continue;
|
||||||
|
gst_caps_set_features (caps, 0, gst_caps_features_copy (features));
|
||||||
|
|
||||||
|
if (gst_caps_can_intersect (caps, vaapi_caps) &&
|
||||||
|
feature < GST_VAAPI_CAPS_FEATURE_VAAPI_SURFACE)
|
||||||
|
feature = GST_VAAPI_CAPS_FEATURE_VAAPI_SURFACE;
|
||||||
|
else if (gst_caps_can_intersect (caps, gl_texture_upload_caps) &&
|
||||||
|
feature < GST_VAAPI_CAPS_FEATURE_GL_TEXTURE_UPLOAD_META)
|
||||||
|
feature = GST_VAAPI_CAPS_FEATURE_GL_TEXTURE_UPLOAD_META;
|
||||||
|
else if (gst_caps_can_intersect (caps, sysmem_caps) &&
|
||||||
|
feature < GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY)
|
||||||
|
feature = GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY;
|
||||||
|
gst_caps_replace (&caps, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
gst_caps_replace (&gl_texture_upload_caps, NULL);
|
||||||
|
gst_caps_replace (&sysmem_caps, NULL);
|
||||||
|
gst_caps_replace (&vaapi_caps, NULL);
|
||||||
|
gst_caps_replace (&caps, NULL);
|
||||||
|
gst_caps_replace (&out_caps, NULL);
|
||||||
|
#endif
|
||||||
|
return feature;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gst_caps_set_interlaced (GstCaps * caps, GstVideoInfo * vip)
|
gst_caps_set_interlaced (GstCaps * caps, GstVideoInfo * vip)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
|
|
||||||
#include <gst/vaapi/gstvaapidisplay.h>
|
#include <gst/vaapi/gstvaapidisplay.h>
|
||||||
#include <gst/vaapi/gstvaapisurface.h>
|
#include <gst/vaapi/gstvaapisurface.h>
|
||||||
|
#if GST_CHECK_VERSION(1,0,0)
|
||||||
|
#include "gstvaapivideomemory.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
gboolean
|
gboolean
|
||||||
|
@ -65,6 +68,13 @@ gboolean
|
||||||
gst_vaapi_value_set_format_list (GValue * value, GArray * formats);
|
gst_vaapi_value_set_format_list (GValue * value, GArray * formats);
|
||||||
|
|
||||||
/* Helpers to build video caps */
|
/* Helpers to build video caps */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY = 1,
|
||||||
|
GST_VAAPI_CAPS_FEATURE_GL_TEXTURE_UPLOAD_META,
|
||||||
|
GST_VAAPI_CAPS_FEATURE_VAAPI_SURFACE,
|
||||||
|
} GstVaapiCapsFeature;
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GstCaps *
|
GstCaps *
|
||||||
gst_vaapi_video_format_new_template_caps (GstVideoFormat format);
|
gst_vaapi_video_format_new_template_caps (GstVideoFormat format);
|
||||||
|
@ -73,6 +83,15 @@ G_GNUC_INTERNAL
|
||||||
GstCaps *
|
GstCaps *
|
||||||
gst_vaapi_video_format_new_template_caps_from_list (GArray * formats);
|
gst_vaapi_video_format_new_template_caps_from_list (GArray * formats);
|
||||||
|
|
||||||
|
G_GNUC_INTERNAL
|
||||||
|
GstCaps *
|
||||||
|
gst_vaapi_video_format_new_template_caps_with_features (GstVideoFormat format,
|
||||||
|
const gchar * features_string);
|
||||||
|
|
||||||
|
G_GNUC_INTERNAL
|
||||||
|
GstVaapiCapsFeature
|
||||||
|
gst_vaapi_find_preferred_caps_feature (GstPad * pad, GstVideoFormat format);
|
||||||
|
|
||||||
/* Helpers to handle interlaced contents */
|
/* Helpers to handle interlaced contents */
|
||||||
#if GST_CHECK_VERSION(1,0,0)
|
#if GST_CHECK_VERSION(1,0,0)
|
||||||
# define GST_CAPS_INTERLACED_MODES \
|
# define GST_CAPS_INTERLACED_MODES \
|
||||||
|
|
Loading…
Reference in a new issue