2012-09-16 11:23:09 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
2014-03-24 13:34:13 +00:00
|
|
|
* Copyright (C) 2012-2014 Matthew Waters <ystree00@gmail.com>
|
2017-02-22 12:55:58 +00:00
|
|
|
* Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
|
2012-09-16 11:23:09 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2012-09-16 11:23:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-07-10 15:03:04 +00:00
|
|
|
#include "gl.h"
|
2012-09-16 11:23:09 +00:00
|
|
|
#include "gstglupload.h"
|
2021-03-18 03:20:34 +00:00
|
|
|
#include "gstglfuncs.h"
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-05-06 10:59:24 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
2017-07-07 15:15:12 +00:00
|
|
|
#include "egl/gsteglimage.h"
|
2020-03-09 10:21:53 +00:00
|
|
|
#include "egl/gsteglimage_private.h"
|
2016-01-21 13:18:17 +00:00
|
|
|
#include "egl/gstglmemoryegl.h"
|
2016-11-23 04:57:05 +00:00
|
|
|
#include "egl/gstglcontext_egl.h"
|
2014-05-06 10:59:24 +00:00
|
|
|
#endif
|
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
#if GST_GL_HAVE_DMABUF
|
|
|
|
#include <gst/allocators/gstdmabuf.h>
|
2023-05-19 08:25:28 +00:00
|
|
|
#include <libdrm/drm_fourcc.h>
|
2015-11-13 16:24:30 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-22 12:55:58 +00:00
|
|
|
#if GST_GL_HAVE_VIV_DIRECTVIV
|
|
|
|
#include <gst/allocators/gstphysmemory.h>
|
2018-03-22 06:56:28 +00:00
|
|
|
#include <gst/gl/gstglfuncs.h>
|
2017-02-22 12:55:58 +00:00
|
|
|
#endif
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstglupload
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: GstGLUpload
|
2012-09-27 05:53:46 +00:00
|
|
|
* @short_description: an object that uploads to GL textures
|
|
|
|
* @see_also: #GstGLDownload, #GstGLMemory
|
|
|
|
*
|
|
|
|
* #GstGLUpload is an object that uploads data from system memory into GL textures.
|
|
|
|
*
|
2013-07-18 09:36:27 +00:00
|
|
|
* A #GstGLUpload can be created with gst_gl_upload_new()
|
2012-09-27 05:53:46 +00:00
|
|
|
*/
|
|
|
|
|
2014-05-30 00:27:14 +00:00
|
|
|
#define USING_OPENGL(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL, 1, 0))
|
|
|
|
#define USING_OPENGL3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL3, 3, 1))
|
|
|
|
#define USING_GLES(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES, 1, 0))
|
|
|
|
#define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0))
|
|
|
|
#define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0))
|
2013-09-15 04:23:43 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_gl_upload_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_upload_debug
|
|
|
|
|
2015-06-18 09:33:29 +00:00
|
|
|
static void gst_gl_upload_finalize (GObject * object);
|
|
|
|
|
2015-10-29 14:42:42 +00:00
|
|
|
static GstGLTextureTarget
|
|
|
|
_caps_get_texture_target (GstCaps * caps, GstGLTextureTarget default_target)
|
|
|
|
{
|
|
|
|
GstGLTextureTarget ret = 0;
|
|
|
|
GstStructure *s = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
if (gst_structure_has_field_typed (s, "texture-target", G_TYPE_STRING)) {
|
|
|
|
const gchar *target_str = gst_structure_get_string (s, "texture-target");
|
|
|
|
ret = gst_gl_texture_target_from_string (target_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
ret = default_target;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-05-29 16:15:51 +00:00
|
|
|
/* Define the maximum number of planes we can upload - handle 2 views per buffer */
|
|
|
|
#define GST_GL_UPLOAD_MAX_PLANES (GST_VIDEO_MAX_PLANES * 2)
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
typedef struct _UploadMethod UploadMethod;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
struct _GstGLUploadPrivate
|
|
|
|
{
|
2023-05-21 09:23:39 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
GstVideoInfo in_info;
|
|
|
|
GstVideoInfoDmaDrm in_info_drm;
|
|
|
|
};
|
2014-11-05 09:18:06 +00:00
|
|
|
GstVideoInfo out_info;
|
|
|
|
GstCaps *in_caps;
|
|
|
|
GstCaps *out_caps;
|
2014-05-29 05:50:56 +00:00
|
|
|
|
|
|
|
GstBuffer *outbuf;
|
2014-11-05 09:18:06 +00:00
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
/* all method impl pointers */
|
|
|
|
gpointer *upload_impl;
|
|
|
|
|
|
|
|
/* current method */
|
2015-01-21 09:17:04 +00:00
|
|
|
const UploadMethod *method;
|
2014-11-05 09:18:06 +00:00
|
|
|
gpointer method_impl;
|
|
|
|
int method_i;
|
2018-07-04 07:17:11 +00:00
|
|
|
|
|
|
|
/* saved method for reconfigure */
|
|
|
|
int saved_method_i;
|
2012-12-06 07:40:26 +00:00
|
|
|
};
|
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
#define DEBUG_INIT \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_upload_debug, "glupload", 0, "upload");
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLUpload, gst_gl_upload, GST_TYPE_OBJECT,
|
|
|
|
G_ADD_PRIVATE (GstGLUpload) DEBUG_INIT);
|
|
|
|
|
2023-06-01 10:34:31 +00:00
|
|
|
static gboolean
|
|
|
|
filter_features (GstCapsFeatures * features,
|
|
|
|
G_GNUC_UNUSED GstStructure * structure, gpointer user_data)
|
|
|
|
{
|
|
|
|
const GstCapsFeatures *user_features = user_data;
|
|
|
|
GQuark feature;
|
|
|
|
guint i, num;
|
|
|
|
|
|
|
|
if (gst_caps_features_is_any (features))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
num = gst_caps_features_get_size (user_features);
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
feature = gst_caps_features_get_nth_id (user_features, i);
|
|
|
|
if (gst_caps_features_contains_id (features, feature))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_filter_caps_with_features (const GstCaps * caps,
|
|
|
|
const GstCapsFeatures * features, GstCaps ** ret_caps)
|
|
|
|
{
|
|
|
|
GstCaps *tmp = NULL;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
if (gst_caps_is_empty (caps))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gst_caps_is_any (caps)) {
|
|
|
|
if (ret_caps) {
|
|
|
|
tmp = gst_caps_new_empty ();
|
|
|
|
gst_caps_set_features_simple (tmp, gst_caps_features_copy (features));
|
|
|
|
*ret_caps = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = gst_caps_copy (caps);
|
|
|
|
gst_caps_filter_and_map_in_place (tmp, filter_features, (gpointer) features);
|
|
|
|
|
|
|
|
if (gst_caps_is_empty (tmp)) {
|
|
|
|
gst_clear_caps (&tmp);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret_caps)
|
|
|
|
*ret_caps = tmp;
|
|
|
|
else
|
|
|
|
gst_clear_caps (&tmp);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
static GstCaps *
|
2015-12-29 07:16:04 +00:00
|
|
|
_set_caps_features_with_passthrough (const GstCaps * caps,
|
|
|
|
const gchar * feature_name, GstCapsFeatures * passthrough)
|
2015-02-02 13:11:06 +00:00
|
|
|
{
|
2015-12-29 07:16:04 +00:00
|
|
|
guint i, j, m, n;
|
|
|
|
GstCaps *tmp;
|
2015-02-02 13:11:06 +00:00
|
|
|
|
2016-03-16 11:48:00 +00:00
|
|
|
tmp = gst_caps_new_empty ();
|
2015-12-29 07:16:04 +00:00
|
|
|
|
|
|
|
n = gst_caps_get_size (caps);
|
2015-02-02 13:11:06 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2015-12-29 07:16:04 +00:00
|
|
|
GstCapsFeatures *features, *orig_features;
|
2016-03-16 11:48:00 +00:00
|
|
|
GstStructure *s = gst_caps_get_structure (caps, i);
|
2015-03-06 17:36:12 +00:00
|
|
|
|
2015-12-29 07:16:04 +00:00
|
|
|
orig_features = gst_caps_get_features (caps, i);
|
2015-03-06 17:36:12 +00:00
|
|
|
features = gst_caps_features_new (feature_name, NULL);
|
2015-12-29 07:16:04 +00:00
|
|
|
|
2016-03-16 11:48:00 +00:00
|
|
|
if (gst_caps_features_is_any (orig_features)) {
|
|
|
|
/* if we have any features, we add both the features with and without @passthrough */
|
|
|
|
gst_caps_append_structure_full (tmp, gst_structure_copy (s),
|
|
|
|
gst_caps_features_copy (features));
|
2015-12-29 07:16:04 +00:00
|
|
|
|
2016-03-16 11:48:00 +00:00
|
|
|
m = gst_caps_features_get_size (passthrough);
|
|
|
|
for (j = 0; j < m; j++) {
|
|
|
|
const gchar *feature = gst_caps_features_get_nth (passthrough, j);
|
2015-12-29 07:16:04 +00:00
|
|
|
|
2016-03-16 11:48:00 +00:00
|
|
|
/* if we already have the features */
|
|
|
|
if (gst_caps_features_contains (features, feature))
|
|
|
|
continue;
|
2015-12-29 07:16:04 +00:00
|
|
|
|
|
|
|
gst_caps_features_add (features, feature);
|
|
|
|
}
|
2016-03-16 11:48:00 +00:00
|
|
|
} else {
|
|
|
|
m = gst_caps_features_get_size (orig_features);
|
|
|
|
for (j = 0; j < m; j++) {
|
|
|
|
const gchar *feature = gst_caps_features_get_nth (orig_features, j);
|
|
|
|
|
|
|
|
/* if we already have the features */
|
|
|
|
if (gst_caps_features_contains (features, feature))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (g_strcmp0 (feature, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (gst_caps_features_contains (passthrough, feature)) {
|
|
|
|
gst_caps_features_add (features, feature);
|
|
|
|
}
|
|
|
|
}
|
2015-12-29 07:16:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 11:48:00 +00:00
|
|
|
gst_caps_append_structure_full (tmp, gst_structure_copy (s), features);
|
2015-02-02 13:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2016-01-04 09:26:09 +00:00
|
|
|
static GstCaps *
|
|
|
|
_caps_intersect_texture_target (GstCaps * caps, GstGLTextureTarget target_mask)
|
|
|
|
{
|
|
|
|
GValue targets = G_VALUE_INIT;
|
|
|
|
GstCaps *ret, *target;
|
|
|
|
|
|
|
|
target = gst_caps_copy (caps);
|
|
|
|
gst_gl_value_set_texture_target_from_mask (&targets, target_mask);
|
|
|
|
gst_caps_set_value (target, "texture-target", &targets);
|
|
|
|
|
|
|
|
ret = gst_caps_intersect_full (caps, target, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
|
2017-03-10 16:57:51 +00:00
|
|
|
g_value_unset (&targets);
|
2016-01-04 09:26:09 +00:00
|
|
|
gst_caps_unref (target);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
METHOD_FLAG_CAN_SHARE_CONTEXT = 1,
|
2022-07-07 13:40:22 +00:00
|
|
|
METHOD_FLAG_CAN_ACCEPT_RAW = 2, /* This method can accept raw memory input caps */
|
2014-11-05 09:18:06 +00:00
|
|
|
} GstGLUploadMethodFlags;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
struct _UploadMethod
|
|
|
|
{
|
|
|
|
const gchar *name;
|
|
|
|
GstGLUploadMethodFlags flags;
|
|
|
|
|
2015-04-28 16:20:09 +00:00
|
|
|
GstStaticCaps *input_template_caps;
|
2015-04-28 10:11:07 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
gpointer (*new) (GstGLUpload * upload);
|
2016-08-22 07:18:27 +00:00
|
|
|
GstCaps *(*transform_caps) (gpointer impl, GstGLContext * context,
|
2015-02-02 13:11:06 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps);
|
2014-11-05 09:18:06 +00:00
|
|
|
gboolean (*accept) (gpointer impl, GstBuffer * buffer, GstCaps * in_caps,
|
|
|
|
GstCaps * out_caps);
|
2015-02-02 13:11:06 +00:00
|
|
|
void (*propose_allocation) (gpointer impl, GstQuery * decide_query,
|
|
|
|
GstQuery * query);
|
2014-11-05 09:18:06 +00:00
|
|
|
GstGLUploadReturn (*perform) (gpointer impl, GstBuffer * buffer,
|
|
|
|
GstBuffer ** outbuf);
|
|
|
|
void (*free) (gpointer impl);
|
|
|
|
} _UploadMethod;
|
|
|
|
|
|
|
|
struct GLMemoryUpload
|
|
|
|
{
|
|
|
|
GstGLUpload *upload;
|
2016-08-22 07:18:27 +00:00
|
|
|
GstGLTextureTarget input_target;
|
2016-08-29 05:43:10 +00:00
|
|
|
GstGLTextureTarget output_target;
|
2014-11-05 09:18:06 +00:00
|
|
|
};
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static gpointer
|
|
|
|
_gl_memory_upload_new (GstGLUpload * upload)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
2014-11-05 09:18:06 +00:00
|
|
|
struct GLMemoryUpload *mem = g_new0 (struct GLMemoryUpload, 1);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
mem->upload = upload;
|
2016-08-22 07:18:27 +00:00
|
|
|
mem->input_target = GST_GL_TEXTURE_TARGET_NONE;
|
2016-08-29 05:43:10 +00:00
|
|
|
mem->output_target = GST_GL_TEXTURE_TARGET_NONE;
|
2014-11-05 09:18:06 +00:00
|
|
|
|
|
|
|
return mem;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
static GstCaps *
|
2016-08-22 07:18:27 +00:00
|
|
|
_gl_memory_upload_transform_caps (gpointer impl, GstGLContext * context,
|
2015-02-02 13:11:06 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps)
|
|
|
|
{
|
2016-08-22 07:18:27 +00:00
|
|
|
struct GLMemoryUpload *upload = impl;
|
2015-12-29 07:16:04 +00:00
|
|
|
GstCapsFeatures *passthrough =
|
|
|
|
gst_caps_features_from_string
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION);
|
|
|
|
GstCaps *ret;
|
|
|
|
|
|
|
|
ret =
|
|
|
|
_set_caps_features_with_passthrough (caps,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY, passthrough);
|
|
|
|
|
|
|
|
gst_caps_features_free (passthrough);
|
|
|
|
|
2016-01-04 09:26:09 +00:00
|
|
|
if (direction == GST_PAD_SINK) {
|
|
|
|
GstCaps *tmp;
|
2016-08-22 07:18:27 +00:00
|
|
|
GstGLTextureTarget target_mask;
|
|
|
|
|
|
|
|
if (upload->input_target != GST_GL_TEXTURE_TARGET_NONE) {
|
|
|
|
target_mask = 1 << upload->input_target;
|
|
|
|
} else {
|
|
|
|
target_mask = 1 << GST_GL_TEXTURE_TARGET_2D |
|
|
|
|
1 << GST_GL_TEXTURE_TARGET_RECTANGLE |
|
|
|
|
1 << GST_GL_TEXTURE_TARGET_EXTERNAL_OES;
|
|
|
|
}
|
2016-01-04 09:26:09 +00:00
|
|
|
|
|
|
|
tmp = _caps_intersect_texture_target (ret, target_mask);
|
|
|
|
gst_caps_unref (ret);
|
|
|
|
ret = tmp;
|
|
|
|
} else {
|
|
|
|
gint i, n;
|
|
|
|
|
|
|
|
n = gst_caps_get_size (ret);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (ret, i);
|
|
|
|
|
|
|
|
gst_structure_remove_fields (s, "texture-target", NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 07:16:04 +00:00
|
|
|
return ret;
|
2015-02-02 13:11:06 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static gboolean
|
|
|
|
_gl_memory_upload_accept (gpointer impl, GstBuffer * buffer, GstCaps * in_caps,
|
|
|
|
GstCaps * out_caps)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
2014-11-05 09:18:06 +00:00
|
|
|
struct GLMemoryUpload *upload = impl;
|
2015-07-27 06:36:40 +00:00
|
|
|
GstCapsFeatures *features;
|
2014-11-05 09:18:06 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
features = gst_caps_get_features (out_caps, 0);
|
2015-07-27 06:36:40 +00:00
|
|
|
if (!gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY))
|
|
|
|
return FALSE;
|
2015-06-18 11:34:58 +00:00
|
|
|
|
2015-02-02 13:35:26 +00:00
|
|
|
features = gst_caps_get_features (in_caps, 0);
|
2015-07-27 06:36:40 +00:00
|
|
|
if (!gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY)
|
|
|
|
&& !gst_caps_features_contains (features,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY))
|
2014-11-05 09:18:06 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2015-02-02 13:15:30 +00:00
|
|
|
if (buffer) {
|
2015-05-29 16:15:51 +00:00
|
|
|
GstVideoInfo *in_info = &upload->upload->priv->in_info;
|
|
|
|
guint expected_memories = GST_VIDEO_INFO_N_PLANES (in_info);
|
|
|
|
|
|
|
|
/* Support stereo views for separated multiview mode */
|
|
|
|
if (GST_VIDEO_INFO_MULTIVIEW_MODE (in_info) ==
|
|
|
|
GST_VIDEO_MULTIVIEW_MODE_SEPARATED)
|
|
|
|
expected_memories *= GST_VIDEO_INFO_VIEWS (in_info);
|
|
|
|
|
|
|
|
if (gst_buffer_n_memory (buffer) != expected_memories)
|
2015-02-02 13:15:30 +00:00
|
|
|
return FALSE;
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2015-05-29 16:15:51 +00:00
|
|
|
for (i = 0; i < expected_memories; i++) {
|
2015-02-02 13:15:30 +00:00
|
|
|
GstMemory *mem = gst_buffer_peek_memory (buffer, i);
|
2014-11-05 09:18:06 +00:00
|
|
|
|
2015-02-02 13:15:30 +00:00
|
|
|
if (!gst_is_gl_memory (mem))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-11-05 09:18:06 +00:00
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
return TRUE;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
static void
|
|
|
|
_gl_memory_upload_propose_allocation (gpointer impl, GstQuery * decide_query,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
2015-03-11 16:56:16 +00:00
|
|
|
struct GLMemoryUpload *upload = impl;
|
|
|
|
GstBufferPool *pool = NULL;
|
|
|
|
guint n_pools, i;
|
2015-12-01 23:09:25 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
GstCapsFeatures *features;
|
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, NULL);
|
2017-07-07 04:41:17 +00:00
|
|
|
if (caps == NULL)
|
|
|
|
goto invalid_caps;
|
2015-12-01 23:09:25 +00:00
|
|
|
features = gst_caps_get_features (caps, 0);
|
2015-02-02 13:11:06 +00:00
|
|
|
|
2015-12-01 23:09:25 +00:00
|
|
|
/* Only offer our custom allocator if that type of memory was negotiated. */
|
|
|
|
if (gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY)) {
|
|
|
|
GstAllocator *allocator;
|
|
|
|
GstAllocationParams params;
|
|
|
|
gst_allocation_params_init (¶ms);
|
2015-02-02 13:11:06 +00:00
|
|
|
|
2015-12-18 02:17:34 +00:00
|
|
|
allocator =
|
2016-06-28 03:51:22 +00:00
|
|
|
GST_ALLOCATOR (gst_gl_memory_allocator_get_default (upload->
|
|
|
|
upload->context));
|
2015-12-01 23:09:25 +00:00
|
|
|
gst_query_add_allocation_param (query, allocator, ¶ms);
|
|
|
|
gst_object_unref (allocator);
|
2016-01-21 13:18:17 +00:00
|
|
|
|
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
|
|
|
if (upload->upload->context
|
|
|
|
&& gst_gl_context_get_gl_platform (upload->upload->context) ==
|
|
|
|
GST_GL_PLATFORM_EGL) {
|
|
|
|
allocator =
|
|
|
|
GST_ALLOCATOR (gst_allocator_find (GST_GL_MEMORY_EGL_ALLOCATOR_NAME));
|
|
|
|
gst_query_add_allocation_param (query, allocator, ¶ms);
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
}
|
|
|
|
#endif
|
2015-12-01 23:09:25 +00:00
|
|
|
}
|
2015-03-11 16:56:16 +00:00
|
|
|
|
|
|
|
n_pools = gst_query_get_n_allocation_pools (query);
|
|
|
|
for (i = 0; i < n_pools; i++) {
|
|
|
|
gst_query_parse_nth_allocation_pool (query, i, &pool, NULL, NULL, NULL);
|
|
|
|
if (!GST_IS_GL_BUFFER_POOL (pool)) {
|
|
|
|
gst_object_unref (pool);
|
|
|
|
pool = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pool) {
|
|
|
|
GstStructure *config;
|
|
|
|
GstVideoInfo info;
|
|
|
|
gsize size;
|
|
|
|
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto invalid_caps;
|
|
|
|
|
|
|
|
pool = gst_gl_buffer_pool_new (upload->upload->context);
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
|
|
|
|
/* the normal size of a frame */
|
|
|
|
size = info.size;
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, 0, 0);
|
2015-08-15 12:31:15 +00:00
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_GL_SYNC_META);
|
2015-10-29 14:42:42 +00:00
|
|
|
if (upload->upload->priv->out_caps) {
|
|
|
|
GstGLTextureTarget target;
|
|
|
|
const gchar *target_pool_option_str;
|
|
|
|
|
|
|
|
target =
|
|
|
|
_caps_get_texture_target (upload->upload->priv->out_caps,
|
|
|
|
GST_GL_TEXTURE_TARGET_2D);
|
|
|
|
target_pool_option_str =
|
|
|
|
gst_gl_texture_target_to_buffer_pool_option (target);
|
|
|
|
gst_buffer_pool_config_add_option (config, target_pool_option_str);
|
|
|
|
}
|
2015-03-11 16:56:16 +00:00
|
|
|
|
2015-06-26 19:34:35 +00:00
|
|
|
if (!gst_buffer_pool_set_config (pool, config)) {
|
|
|
|
gst_object_unref (pool);
|
2015-03-11 16:56:16 +00:00
|
|
|
goto config_failed;
|
2015-06-26 19:34:35 +00:00
|
|
|
}
|
2015-03-11 16:56:16 +00:00
|
|
|
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, 1, 0);
|
|
|
|
}
|
|
|
|
|
2015-03-13 12:40:04 +00:00
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
|
|
|
|
2015-03-11 16:56:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (upload->upload, "invalid caps specified");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
config_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (upload->upload, "failed setting config");
|
|
|
|
return;
|
|
|
|
}
|
2015-02-02 13:11:06 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static GstGLUploadReturn
|
|
|
|
_gl_memory_upload_perform (gpointer impl, GstBuffer * buffer,
|
|
|
|
GstBuffer ** outbuf)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
2014-11-05 09:18:06 +00:00
|
|
|
struct GLMemoryUpload *upload = impl;
|
|
|
|
GstGLMemory *gl_mem;
|
2015-05-29 16:15:51 +00:00
|
|
|
int i, n;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2015-05-29 16:15:51 +00:00
|
|
|
n = gst_buffer_n_memory (buffer);
|
|
|
|
for (i = 0; i < n; i++) {
|
2014-11-05 09:18:06 +00:00
|
|
|
GstMemory *mem = gst_buffer_peek_memory (buffer, i);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
gl_mem = (GstGLMemory *) mem;
|
2015-06-10 06:36:15 +00:00
|
|
|
if (!gst_gl_context_can_share (upload->upload->context,
|
|
|
|
gl_mem->mem.context))
|
2014-11-05 09:18:06 +00:00
|
|
|
return GST_GL_UPLOAD_UNSHARED_GL_CONTEXT;
|
2015-06-11 08:26:50 +00:00
|
|
|
|
2016-08-29 05:43:10 +00:00
|
|
|
if (upload->output_target == GST_GL_TEXTURE_TARGET_NONE &&
|
|
|
|
upload->upload->priv->out_caps) {
|
|
|
|
upload->output_target =
|
|
|
|
_caps_get_texture_target (upload->upload->priv->out_caps,
|
|
|
|
GST_GL_TEXTURE_TARGET_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* always track the last input texture target so ::transform_caps() can
|
|
|
|
* use it to build the output caps */
|
|
|
|
upload->input_target = gl_mem->tex_target;
|
|
|
|
if (upload->output_target != gl_mem->tex_target) {
|
2016-08-22 07:18:27 +00:00
|
|
|
*outbuf = NULL;
|
|
|
|
return GST_GL_UPLOAD_RECONFIGURE;
|
|
|
|
}
|
|
|
|
|
2015-12-14 02:43:59 +00:00
|
|
|
if (gst_is_gl_memory_pbo (mem))
|
|
|
|
gst_gl_memory_pbo_upload_transfer ((GstGLMemoryPBO *) mem);
|
2014-11-05 09:18:06 +00:00
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
*outbuf = gst_buffer_ref (buffer);
|
|
|
|
|
2015-01-14 11:08:43 +00:00
|
|
|
return GST_GL_UPLOAD_DONE;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static void
|
|
|
|
_gl_memory_upload_free (gpointer impl)
|
|
|
|
{
|
|
|
|
g_free (impl);
|
|
|
|
}
|
|
|
|
|
2015-04-28 16:20:09 +00:00
|
|
|
|
|
|
|
static GstStaticCaps _gl_memory_upload_caps =
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY, GST_GL_MEMORY_VIDEO_FORMATS_STR));
|
|
|
|
|
2015-01-21 09:17:04 +00:00
|
|
|
static const UploadMethod _gl_memory_upload = {
|
2014-11-05 09:18:06 +00:00
|
|
|
"GLMemory",
|
|
|
|
METHOD_FLAG_CAN_SHARE_CONTEXT,
|
2015-04-28 16:20:09 +00:00
|
|
|
&_gl_memory_upload_caps,
|
2014-11-05 09:18:06 +00:00
|
|
|
&_gl_memory_upload_new,
|
2015-02-02 13:11:06 +00:00
|
|
|
&_gl_memory_upload_transform_caps,
|
2014-11-05 09:18:06 +00:00
|
|
|
&_gl_memory_upload_accept,
|
2015-02-02 13:11:06 +00:00
|
|
|
&_gl_memory_upload_propose_allocation,
|
2014-11-05 09:18:06 +00:00
|
|
|
&_gl_memory_upload_perform,
|
|
|
|
&_gl_memory_upload_free
|
|
|
|
};
|
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
#if GST_GL_HAVE_DMABUF
|
2023-01-30 06:59:34 +00:00
|
|
|
typedef struct _GstEGLImageCacheEntry
|
|
|
|
{
|
|
|
|
GstEGLImage *eglimage[GST_VIDEO_MAX_PLANES];
|
|
|
|
} GstEGLImageCacheEntry;
|
|
|
|
|
|
|
|
typedef struct _GstEGLImageCache
|
|
|
|
{
|
|
|
|
gint ref_count;
|
|
|
|
GHashTable *hash_table; /* for GstMemory -> GstEGLImageCacheEntry lookup */
|
|
|
|
GMutex lock; /* protects hash_table */
|
|
|
|
} GstEGLImageCache;
|
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
struct DmabufUpload
|
|
|
|
{
|
|
|
|
GstGLUpload *upload;
|
|
|
|
|
2016-05-04 02:17:59 +00:00
|
|
|
GstEGLImage *eglimage[GST_VIDEO_MAX_PLANES];
|
2023-01-30 06:59:34 +00:00
|
|
|
GstEGLImageCache *eglimage_cache;
|
2018-11-09 08:32:49 +00:00
|
|
|
GstGLFormat formats[GST_VIDEO_MAX_PLANES];
|
2015-11-13 16:24:30 +00:00
|
|
|
GstBuffer *outbuf;
|
|
|
|
GstGLVideoAllocationParams *params;
|
2018-07-05 08:17:27 +00:00
|
|
|
guint n_mem;
|
|
|
|
|
|
|
|
gboolean direct;
|
2020-02-12 17:25:54 +00:00
|
|
|
GstGLTextureTarget target;
|
2018-07-05 08:17:27 +00:00
|
|
|
GstVideoInfo out_info;
|
2019-08-29 17:42:39 +00:00
|
|
|
/* only used for pointer comparison */
|
2023-05-21 09:23:39 +00:00
|
|
|
gpointer in_caps;
|
2018-07-05 08:17:27 +00:00
|
|
|
gpointer out_caps;
|
2015-11-13 16:24:30 +00:00
|
|
|
};
|
|
|
|
|
2023-01-30 06:59:34 +00:00
|
|
|
static void
|
|
|
|
gst_egl_image_cache_ref (GstEGLImageCache * cache)
|
|
|
|
{
|
|
|
|
g_atomic_int_inc (&cache->ref_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_egl_image_cache_unref (GstEGLImageCache * cache)
|
|
|
|
{
|
|
|
|
if (g_atomic_int_dec_and_test (&cache->ref_count)) {
|
|
|
|
g_hash_table_unref (cache->hash_table);
|
|
|
|
g_mutex_clear (&cache->lock);
|
2023-05-25 06:48:11 +00:00
|
|
|
g_free (cache);
|
2023-01-30 06:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_egl_image_cache_entry_remove (GstEGLImageCache * cache, GstMiniObject * mem)
|
|
|
|
{
|
|
|
|
g_mutex_lock (&cache->lock);
|
|
|
|
g_hash_table_remove (cache->hash_table, mem);
|
|
|
|
g_mutex_unlock (&cache->lock);
|
|
|
|
gst_egl_image_cache_unref (cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstEGLImageCacheEntry *
|
|
|
|
gst_egl_image_cache_entry_new (GstEGLImageCache * cache, GstMemory * mem)
|
|
|
|
{
|
|
|
|
GstEGLImageCacheEntry *cache_entry;
|
|
|
|
|
|
|
|
cache_entry = g_new0 (GstEGLImageCacheEntry, 1);
|
|
|
|
gst_egl_image_cache_ref (cache);
|
|
|
|
gst_mini_object_weak_ref (GST_MINI_OBJECT (mem),
|
|
|
|
(GstMiniObjectNotify) gst_egl_image_cache_entry_remove, cache);
|
|
|
|
g_mutex_lock (&cache->lock);
|
|
|
|
g_hash_table_insert (cache->hash_table, mem, cache_entry);
|
|
|
|
g_mutex_unlock (&cache->lock);
|
|
|
|
|
|
|
|
return cache_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_egl_image_cache_entry_free (GstEGLImageCacheEntry * cache_entry)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
|
|
|
|
if (cache_entry->eglimage[i])
|
|
|
|
gst_egl_image_unref (cache_entry->eglimage[i]);
|
|
|
|
}
|
|
|
|
g_free (cache_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Looks up a cache_entry for mem if mem is different from previous_mem.
|
|
|
|
* If mem is the same as previous_mem, the costly lookup is skipped and the
|
|
|
|
* provided (previous) cache_entry is used instead.
|
|
|
|
*
|
|
|
|
* Returns the cached eglimage for the given plane from the cache_entry, or
|
|
|
|
* NULL. previous_mem is set to mem.
|
|
|
|
*/
|
|
|
|
static GstEGLImage *
|
|
|
|
gst_egl_image_cache_lookup (GstEGLImageCache * cache, GstMemory * mem,
|
|
|
|
gint plane, GstMemory ** previous_mem, GstEGLImageCacheEntry ** cache_entry)
|
|
|
|
{
|
|
|
|
if (mem != *previous_mem) {
|
|
|
|
g_mutex_lock (&cache->lock);
|
|
|
|
*cache_entry = g_hash_table_lookup (cache->hash_table, mem);
|
|
|
|
g_mutex_unlock (&cache->lock);
|
|
|
|
*previous_mem = mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*cache_entry)
|
|
|
|
return (*cache_entry)->eglimage[plane];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates a new cache_entry for mem if no cache_entry is provided.
|
|
|
|
* Stores the eglimage for the given plane in the cache_entry.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_egl_image_cache_store (GstEGLImageCache * cache, GstMemory * mem,
|
|
|
|
gint plane, GstEGLImage * eglimage, GstEGLImageCacheEntry ** cache_entry)
|
|
|
|
{
|
|
|
|
if (!(*cache_entry))
|
|
|
|
*cache_entry = gst_egl_image_cache_entry_new (cache, mem);
|
|
|
|
(*cache_entry)->eglimage[plane] = eglimage;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstEGLImageCache *
|
|
|
|
gst_egl_image_cache_new (void)
|
|
|
|
{
|
|
|
|
GstEGLImageCache *cache;
|
|
|
|
|
|
|
|
cache = g_new0 (GstEGLImageCache, 1);
|
|
|
|
cache->ref_count = 1;
|
|
|
|
|
|
|
|
cache->hash_table = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
|
|
NULL, (GDestroyNotify) gst_egl_image_cache_entry_free);
|
|
|
|
g_mutex_init (&cache->lock);
|
|
|
|
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
static GstStaticCaps _dma_buf_upload_caps =
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_DMA_DRM_CAPS_MAKE ";"
|
2016-03-09 22:01:12 +00:00
|
|
|
GST_VIDEO_CAPS_MAKE (GST_GL_MEMORY_VIDEO_FORMATS_STR));
|
2015-11-13 16:24:30 +00:00
|
|
|
|
|
|
|
static gpointer
|
|
|
|
_dma_buf_upload_new (GstGLUpload * upload)
|
|
|
|
{
|
|
|
|
struct DmabufUpload *dmabuf = g_new0 (struct DmabufUpload, 1);
|
|
|
|
dmabuf->upload = upload;
|
2023-01-30 06:59:34 +00:00
|
|
|
dmabuf->eglimage_cache = gst_egl_image_cache_new ();
|
2020-02-18 12:46:08 +00:00
|
|
|
dmabuf->target = GST_GL_TEXTURE_TARGET_2D;
|
2015-11-13 16:24:30 +00:00
|
|
|
return dmabuf;
|
|
|
|
}
|
|
|
|
|
2023-05-19 08:25:28 +00:00
|
|
|
/* Append all drm format strings to drm_formats array. */
|
|
|
|
static void
|
|
|
|
_append_drm_formats_from_video_format (GstGLContext * context,
|
|
|
|
GstVideoFormat format, gboolean include_external, GPtrArray * drm_formats)
|
|
|
|
{
|
|
|
|
gint32 i, fourcc;
|
|
|
|
const GArray *dma_modifiers = NULL;
|
|
|
|
char *drm_format;
|
|
|
|
|
|
|
|
fourcc = gst_video_dma_drm_fourcc_from_format (format);
|
|
|
|
if (fourcc == DRM_FORMAT_INVALID)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!gst_gl_context_egl_get_format_modifiers (context, fourcc,
|
|
|
|
&dma_modifiers))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* No modifier info, we just consider it as linear and external_only. */
|
|
|
|
if (!dma_modifiers) {
|
|
|
|
if (include_external) {
|
|
|
|
drm_format =
|
|
|
|
gst_video_dma_drm_fourcc_to_string (fourcc, DRM_FORMAT_MOD_LINEAR);
|
|
|
|
g_ptr_array_add (drm_formats, drm_format);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dma_modifiers->len; i++) {
|
|
|
|
GstGLDmaModifier *mod = &g_array_index (dma_modifiers, GstGLDmaModifier, i);
|
|
|
|
|
|
|
|
if (!mod->external_only || include_external) {
|
|
|
|
drm_format = gst_video_dma_drm_fourcc_to_string (fourcc, mod->modifier);
|
|
|
|
g_ptr_array_add (drm_formats, drm_format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given the video formats in src GValue, collecting all the according
|
|
|
|
drm formats to dst GValue. Return FALSE if no valid drm formats found. */
|
|
|
|
static gboolean
|
|
|
|
_dma_buf_transform_gst_formats_to_drm_formats (GstGLContext * context,
|
|
|
|
const GValue * video_value, gboolean include_external, GValue * drm_value)
|
|
|
|
{
|
|
|
|
GstVideoFormat gst_format;
|
|
|
|
GPtrArray *all_drm_formats = NULL;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
all_drm_formats = g_ptr_array_new ();
|
|
|
|
|
|
|
|
if (G_VALUE_HOLDS_STRING (video_value)) {
|
|
|
|
gst_format =
|
|
|
|
gst_video_format_from_string (g_value_get_string (video_value));
|
|
|
|
if (gst_format != GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
_append_drm_formats_from_video_format (context, gst_format,
|
|
|
|
include_external, all_drm_formats);
|
|
|
|
}
|
|
|
|
} else if (GST_VALUE_HOLDS_LIST (video_value)) {
|
|
|
|
guint num_values = gst_value_list_get_size (video_value);
|
|
|
|
|
|
|
|
for (i = 0; i < num_values; i++) {
|
|
|
|
const GValue *val = gst_value_list_get_value (video_value, i);
|
|
|
|
|
|
|
|
gst_format = gst_video_format_from_string (g_value_get_string (val));
|
|
|
|
if (gst_format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_append_drm_formats_from_video_format (context, gst_format,
|
|
|
|
include_external, all_drm_formats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all_drm_formats->len == 0) {
|
|
|
|
g_ptr_array_unref (all_drm_formats);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all_drm_formats->len == 1) {
|
|
|
|
g_value_init (drm_value, G_TYPE_STRING);
|
|
|
|
g_value_take_string (drm_value, g_ptr_array_index (all_drm_formats, 0));
|
|
|
|
} else {
|
|
|
|
GValue item = G_VALUE_INIT;
|
|
|
|
|
|
|
|
gst_value_list_init (drm_value, all_drm_formats->len);
|
|
|
|
|
|
|
|
for (i = 0; i < all_drm_formats->len; i++) {
|
|
|
|
g_value_init (&item, G_TYPE_STRING);
|
|
|
|
g_value_take_string (&item, g_ptr_array_index (all_drm_formats, i));
|
|
|
|
gst_value_list_append_value (drm_value, &item);
|
|
|
|
g_value_unset (&item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The strings are already token by the GValue, no need to free. */
|
|
|
|
g_ptr_array_unref (all_drm_formats);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-05-19 11:25:15 +00:00
|
|
|
static gboolean
|
|
|
|
_check_modifier (GstGLContext * context, guint32 fourcc,
|
|
|
|
guint64 modifier, gboolean include_external)
|
|
|
|
{
|
|
|
|
const GArray *dma_modifiers;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* If no context provide, no further check. */
|
|
|
|
if (!context)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!gst_gl_context_egl_get_format_modifiers (context, fourcc,
|
|
|
|
&dma_modifiers))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!dma_modifiers) {
|
|
|
|
/* recognize the fourcc but no modifier info, consider it as linear */
|
|
|
|
if (modifier == DRM_FORMAT_MOD_LINEAR)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dma_modifiers->len; i++) {
|
|
|
|
GstGLDmaModifier *mod = &g_array_index (dma_modifiers, GstGLDmaModifier, i);
|
|
|
|
|
|
|
|
if (!mod->external_only || include_external) {
|
|
|
|
if (mod->modifier == modifier)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
static void
|
|
|
|
_set_default_formats_list (GstStructure * structure)
|
|
|
|
{
|
|
|
|
GValue formats = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&formats, GST_TYPE_LIST);
|
|
|
|
gst_value_deserialize (&formats, GST_GL_MEMORY_VIDEO_FORMATS_STR);
|
|
|
|
gst_structure_take_value (structure, "format", &formats);
|
|
|
|
}
|
|
|
|
|
2023-05-19 11:25:15 +00:00
|
|
|
static GstVideoFormat
|
|
|
|
_get_video_format_from_drm_format (GstGLContext * context,
|
|
|
|
const gchar * drm_format, gboolean include_external)
|
|
|
|
{
|
|
|
|
GstVideoFormat gst_format;
|
|
|
|
guint32 fourcc;
|
|
|
|
guint64 modifier;
|
|
|
|
|
|
|
|
fourcc = gst_video_dma_drm_fourcc_from_string (drm_format, &modifier);
|
|
|
|
if (fourcc == DRM_FORMAT_INVALID)
|
|
|
|
return GST_VIDEO_FORMAT_UNKNOWN;
|
|
|
|
|
|
|
|
gst_format = gst_video_dma_drm_fourcc_to_format (fourcc);
|
|
|
|
if (gst_format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
return GST_VIDEO_FORMAT_UNKNOWN;
|
|
|
|
|
|
|
|
if (!_check_modifier (context, fourcc, modifier, include_external))
|
|
|
|
return GST_VIDEO_FORMAT_UNKNOWN;
|
|
|
|
|
|
|
|
return gst_format;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given the drm formats in src GValue, collecting all the according
|
|
|
|
gst formats to dst GValue. Return FALSE if no valid drm formats found. */
|
|
|
|
static gboolean
|
|
|
|
_dma_buf_transform_drm_formats_to_gst_formats (GstGLContext * context,
|
|
|
|
const GValue * drm_value, gboolean include_external, GValue * video_value)
|
|
|
|
{
|
|
|
|
GstVideoFormat gst_format;
|
|
|
|
GArray *all_formats = NULL;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
all_formats = g_array_new (FALSE, FALSE, sizeof (GstVideoFormat));
|
|
|
|
|
|
|
|
if (G_VALUE_HOLDS_STRING (drm_value)) {
|
|
|
|
gst_format = _get_video_format_from_drm_format (context,
|
|
|
|
g_value_get_string (drm_value), include_external);
|
|
|
|
|
|
|
|
if (gst_format != GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
g_array_append_val (all_formats, gst_format);
|
|
|
|
} else if (GST_VALUE_HOLDS_LIST (drm_value)) {
|
|
|
|
guint num_values = gst_value_list_get_size (drm_value);
|
|
|
|
|
|
|
|
for (i = 0; i < num_values; i++) {
|
|
|
|
const GValue *val = gst_value_list_get_value (drm_value, i);
|
|
|
|
|
|
|
|
gst_format = _get_video_format_from_drm_format (context,
|
|
|
|
g_value_get_string (val), include_external);
|
|
|
|
if (gst_format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_array_append_val (all_formats, gst_format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all_formats->len == 0) {
|
|
|
|
g_array_unref (all_formats);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all_formats->len == 1) {
|
|
|
|
g_value_init (video_value, G_TYPE_STRING);
|
|
|
|
gst_format = g_array_index (all_formats, GstVideoFormat, 0);
|
|
|
|
g_value_set_string (video_value, gst_video_format_to_string (gst_format));
|
|
|
|
} else {
|
|
|
|
GValue item = G_VALUE_INIT;
|
|
|
|
|
|
|
|
gst_value_list_init (video_value, all_formats->len);
|
|
|
|
|
|
|
|
for (i = 0; i < all_formats->len; i++) {
|
|
|
|
g_value_init (&item, G_TYPE_STRING);
|
|
|
|
gst_format = g_array_index (all_formats, GstVideoFormat, i);
|
|
|
|
g_value_set_string (&item, gst_video_format_to_string (gst_format));
|
|
|
|
gst_value_list_append_value (video_value, &item);
|
|
|
|
g_value_unset (&item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_unref (all_formats);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
static gboolean
|
|
|
|
_dma_buf_convert_format_field_in_structure (GstGLContext * context,
|
|
|
|
GstStructure * structure, GstPadDirection direction,
|
|
|
|
gboolean include_external)
|
|
|
|
{
|
|
|
|
const GValue *val;
|
|
|
|
|
|
|
|
if (direction == GST_PAD_SRC) {
|
|
|
|
GValue drm_formats = G_VALUE_INIT;
|
|
|
|
|
|
|
|
/* No context available, we can not know the real modifiers.
|
|
|
|
Just leaving all format related fields blank. */
|
|
|
|
if (!context) {
|
|
|
|
gst_structure_set (structure, "format", G_TYPE_STRING, "DMA_DRM", NULL);
|
|
|
|
gst_structure_remove_field (structure, "drm-format");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* When no format provided, just list all supported formats
|
|
|
|
and find all the possible drm-format. */
|
|
|
|
if (!(val = gst_structure_get_value (structure, "format"))) {
|
|
|
|
_set_default_formats_list (structure);
|
|
|
|
val = gst_structure_get_value (structure, "format");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_dma_buf_transform_gst_formats_to_drm_formats (context,
|
|
|
|
val, include_external, &drm_formats)) {
|
|
|
|
gst_structure_take_value (structure, "drm-format", &drm_formats);
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_structure_set (structure, "format", G_TYPE_STRING, "DMA_DRM", NULL);
|
|
|
|
} else {
|
|
|
|
GValue gst_formats = G_VALUE_INIT;
|
|
|
|
|
|
|
|
/* Reject the traditional "format" field directly. */
|
|
|
|
if (g_strcmp0 (gst_structure_get_string (structure, "format"),
|
|
|
|
"DMA_DRM") != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* If no drm-field in the src, we just list all
|
|
|
|
supported formats in dst. */
|
|
|
|
if (!(val = gst_structure_get_value (structure, "drm-format"))) {
|
|
|
|
gst_structure_remove_field (structure, "format");
|
|
|
|
gst_structure_remove_field (structure, "drm-format");
|
|
|
|
_set_default_formats_list (structure);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_dma_buf_transform_drm_formats_to_gst_formats (context,
|
|
|
|
val, include_external, &gst_formats)) {
|
|
|
|
gst_structure_take_value (structure, "format", &gst_formats);
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_structure_remove_field (structure, "drm-format");
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_dma_buf_check_target (GstStructure * structure, GstGLTextureTarget target_mask)
|
|
|
|
{
|
|
|
|
const GValue *target_val;
|
|
|
|
const gchar *target_str;
|
|
|
|
GstGLTextureTarget target;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
target_val = gst_structure_get_value (structure, "texture-target");
|
|
|
|
|
|
|
|
/* If no texture-target set, it means a default of 2D. */
|
|
|
|
if (!target_val)
|
|
|
|
return (1 << GST_GL_TEXTURE_TARGET_2D) & target_mask;
|
|
|
|
|
|
|
|
if (G_VALUE_HOLDS_STRING (target_val)) {
|
|
|
|
target_str = g_value_get_string (target_val);
|
|
|
|
target = gst_gl_texture_target_from_string (target_str);
|
|
|
|
|
|
|
|
return (1 << target) & target_mask;
|
|
|
|
} else if (GST_VALUE_HOLDS_LIST (target_val)) {
|
|
|
|
guint num_values = gst_value_list_get_size (target_val);
|
|
|
|
|
|
|
|
for (i = 0; i < num_values; i++) {
|
|
|
|
const GValue *val = gst_value_list_get_value (target_val, i);
|
|
|
|
|
|
|
|
target_str = g_value_get_string (val);
|
|
|
|
target = gst_gl_texture_target_from_string (target_str);
|
|
|
|
if ((1 << target) & target_mask)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_dma_buf_check_formats_in_structure (GstGLContext * context,
|
|
|
|
GstStructure * structure, gboolean include_external)
|
|
|
|
{
|
|
|
|
const GValue *all_formats;
|
|
|
|
GstVideoFormat gst_format;
|
|
|
|
guint32 fourcc;
|
|
|
|
|
|
|
|
all_formats = gst_structure_get_value (structure, "format");
|
|
|
|
if (!all_formats)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (G_VALUE_HOLDS_STRING (all_formats)) {
|
|
|
|
gst_format =
|
|
|
|
gst_video_format_from_string (g_value_get_string (all_formats));
|
|
|
|
if (gst_format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
fourcc = gst_video_dma_drm_fourcc_from_format (gst_format);
|
|
|
|
if (fourcc == DRM_FORMAT_INVALID)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!_check_modifier (context, fourcc,
|
|
|
|
DRM_FORMAT_MOD_LINEAR, include_external))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
} else if (GST_VALUE_HOLDS_LIST (all_formats)) {
|
|
|
|
GValue video_value = G_VALUE_INIT;
|
|
|
|
guint num_values = gst_value_list_get_size (all_formats);
|
|
|
|
GArray *gst_formats = g_array_new (FALSE, FALSE, sizeof (GstVideoFormat));
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_values; i++) {
|
|
|
|
const GValue *val = gst_value_list_get_value (all_formats, i);
|
|
|
|
|
|
|
|
gst_format = gst_video_format_from_string (g_value_get_string (val));
|
|
|
|
if (gst_format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fourcc = gst_video_dma_drm_fourcc_from_format (gst_format);
|
|
|
|
if (fourcc == DRM_FORMAT_INVALID)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!_check_modifier (context, fourcc,
|
|
|
|
DRM_FORMAT_MOD_LINEAR, include_external))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_array_append_val (gst_formats, gst_format);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_formats->len == 0) {
|
|
|
|
g_array_unref (gst_formats);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_formats->len == 1) {
|
|
|
|
g_value_init (&video_value, G_TYPE_STRING);
|
|
|
|
gst_format = g_array_index (gst_formats, GstVideoFormat, 0);
|
|
|
|
g_value_set_string (&video_value,
|
|
|
|
gst_video_format_to_string (gst_format));
|
|
|
|
} else {
|
|
|
|
GValue item = G_VALUE_INIT;
|
|
|
|
|
|
|
|
gst_value_list_init (&video_value, gst_formats->len);
|
|
|
|
|
|
|
|
for (i = 0; i < gst_formats->len; i++) {
|
|
|
|
g_value_init (&item, G_TYPE_STRING);
|
|
|
|
|
|
|
|
gst_format = g_array_index (gst_formats, GstVideoFormat, i);
|
|
|
|
g_value_set_string (&item, gst_video_format_to_string (gst_format));
|
|
|
|
gst_value_list_append_value (&video_value, &item);
|
|
|
|
g_value_unset (&item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_unref (gst_formats);
|
|
|
|
|
|
|
|
gst_structure_take_value (structure, "format", &video_value);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
_dma_buf_upload_transform_caps_common (GstCaps * caps,
|
|
|
|
GstGLContext * context, GstPadDirection direction,
|
|
|
|
gboolean include_external, GstGLTextureTarget target_mask,
|
|
|
|
const gchar * from_feature, const gchar * to_feature)
|
|
|
|
{
|
|
|
|
guint i, n;
|
|
|
|
GstCaps *ret_caps, *tmp_caps, *caps_to_transform;
|
|
|
|
GstCapsFeatures *passthrough, *features;
|
|
|
|
|
|
|
|
if (direction == GST_PAD_SINK) {
|
|
|
|
g_return_val_if_fail
|
|
|
|
(!g_strcmp0 (from_feature, GST_CAPS_FEATURE_MEMORY_DMABUF) ||
|
|
|
|
!g_strcmp0 (from_feature, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY), NULL);
|
|
|
|
g_return_val_if_fail
|
|
|
|
(!g_strcmp0 (to_feature, GST_CAPS_FEATURE_MEMORY_GL_MEMORY), NULL);
|
|
|
|
} else {
|
|
|
|
g_return_val_if_fail
|
|
|
|
(!g_strcmp0 (to_feature, GST_CAPS_FEATURE_MEMORY_DMABUF) ||
|
|
|
|
!g_strcmp0 (to_feature, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY), NULL);
|
|
|
|
g_return_val_if_fail
|
|
|
|
(!g_strcmp0 (from_feature, GST_CAPS_FEATURE_MEMORY_GL_MEMORY), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
features = gst_caps_features_new (from_feature, NULL);
|
|
|
|
if (!_filter_caps_with_features (caps, features, &caps_to_transform)) {
|
|
|
|
gst_caps_features_free (features);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
gst_caps_features_free (features);
|
|
|
|
|
|
|
|
if (gst_caps_is_any (caps_to_transform)) {
|
|
|
|
tmp_caps = caps_to_transform;
|
|
|
|
goto passthrough;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp_caps = gst_caps_new_empty ();
|
|
|
|
n = gst_caps_get_size (caps_to_transform);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstStructure *s;
|
|
|
|
GstCapsFeatures *features;
|
|
|
|
|
|
|
|
features = gst_caps_get_features (caps_to_transform, i);
|
|
|
|
g_assert (gst_caps_features_contains (features, from_feature));
|
|
|
|
|
|
|
|
s = gst_caps_get_structure (caps_to_transform, i);
|
|
|
|
|
|
|
|
if (direction == GST_PAD_SRC && !_dma_buf_check_target (s, target_mask))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
s = gst_structure_copy (s);
|
|
|
|
|
|
|
|
if (!g_strcmp0 (from_feature, GST_CAPS_FEATURE_MEMORY_DMABUF) ||
|
|
|
|
!g_strcmp0 (to_feature, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
|
|
|
|
/* Convert drm-format/format fields for DMABuf */
|
|
|
|
if (!_dma_buf_convert_format_field_in_structure (context, s,
|
|
|
|
direction, include_external)) {
|
|
|
|
gst_structure_free (s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!_dma_buf_check_formats_in_structure (context, s, include_external)) {
|
|
|
|
gst_structure_free (s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_append_structure_full (tmp_caps, s,
|
|
|
|
gst_caps_features_copy (features));
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_unref (caps_to_transform);
|
|
|
|
|
|
|
|
if (gst_caps_is_empty (tmp_caps)) {
|
|
|
|
gst_caps_unref (tmp_caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
passthrough:
|
|
|
|
/* Change the feature name. */
|
|
|
|
passthrough = gst_caps_features_from_string
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION);
|
|
|
|
ret_caps = _set_caps_features_with_passthrough (tmp_caps,
|
|
|
|
to_feature, passthrough);
|
|
|
|
|
|
|
|
gst_caps_features_free (passthrough);
|
|
|
|
gst_caps_unref (tmp_caps);
|
|
|
|
|
|
|
|
return ret_caps;
|
|
|
|
}
|
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
static GstCaps *
|
2016-08-22 07:18:27 +00:00
|
|
|
_dma_buf_upload_transform_caps (gpointer impl, GstGLContext * context,
|
2015-11-13 16:24:30 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps)
|
|
|
|
{
|
2018-10-17 15:09:26 +00:00
|
|
|
struct DmabufUpload *dmabuf = impl;
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
GstCaps *ret, *tmp;
|
2015-11-13 16:24:30 +00:00
|
|
|
|
2018-07-17 15:43:40 +00:00
|
|
|
if (context) {
|
2021-03-18 03:20:34 +00:00
|
|
|
const GstGLFuncs *gl = context->gl_vtable;
|
|
|
|
|
|
|
|
if (!gl->EGLImageTargetTexture2D)
|
|
|
|
return NULL;
|
|
|
|
|
2018-07-17 15:43:40 +00:00
|
|
|
/* Don't propose DMABuf caps feature unless it can be supported */
|
|
|
|
if (gst_gl_context_get_gl_platform (context) != GST_GL_PLATFORM_EGL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!gst_gl_context_check_feature (context, "EGL_KHR_image_base"))
|
|
|
|
return NULL;
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
|
|
|
|
if (!gst_gl_context_egl_supports_modifier (context))
|
|
|
|
return NULL;
|
2018-07-17 15:43:40 +00:00
|
|
|
}
|
|
|
|
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
g_assert (dmabuf->target == GST_GL_TEXTURE_TARGET_2D);
|
2019-02-08 12:38:04 +00:00
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
if (direction == GST_PAD_SINK) {
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
ret = _dma_buf_upload_transform_caps_common (caps, context, direction,
|
|
|
|
TRUE, 1 << dmabuf->target, GST_CAPS_FEATURE_MEMORY_DMABUF,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
|
|
|
tmp = _dma_buf_upload_transform_caps_common (caps, context, direction,
|
|
|
|
TRUE, 1 << dmabuf->target, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
|
|
|
if (!ret) {
|
|
|
|
ret = tmp;
|
|
|
|
tmp = NULL;
|
|
|
|
}
|
|
|
|
if (tmp)
|
|
|
|
ret = gst_caps_merge (ret, tmp);
|
2016-01-04 09:26:09 +00:00
|
|
|
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
if (!ret) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload,
|
|
|
|
"direction %s, fails to transformed DMA caps %" GST_PTR_FORMAT,
|
|
|
|
"sink", caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-04 09:26:09 +00:00
|
|
|
|
|
|
|
tmp = _caps_intersect_texture_target (ret, 1 << GST_GL_TEXTURE_TARGET_2D);
|
|
|
|
gst_caps_unref (ret);
|
|
|
|
ret = tmp;
|
2015-11-13 16:24:30 +00:00
|
|
|
} else {
|
|
|
|
gint i, n;
|
|
|
|
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
ret = _dma_buf_upload_transform_caps_common (caps, context, direction,
|
|
|
|
TRUE, 1 << dmabuf->target, GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_DMABUF);
|
|
|
|
tmp = _dma_buf_upload_transform_caps_common (caps, context, direction,
|
|
|
|
TRUE, 1 << dmabuf->target, GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
|
|
|
|
if (!ret) {
|
|
|
|
ret = tmp;
|
|
|
|
tmp = NULL;
|
|
|
|
}
|
|
|
|
if (tmp)
|
|
|
|
ret = gst_caps_merge (ret, tmp);
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload,
|
|
|
|
"direction %s, fails to transformed DMA caps %" GST_PTR_FORMAT,
|
|
|
|
"src", caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-05 13:17:30 +00:00
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
n = gst_caps_get_size (ret);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (ret, i);
|
|
|
|
|
|
|
|
gst_structure_remove_fields (s, "texture-target", NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload, "direction %s, transformed %"
|
|
|
|
GST_PTR_FORMAT " into %" GST_PTR_FORMAT,
|
|
|
|
direction == GST_PAD_SRC ? "src" : "sink", caps, ret);
|
2018-10-17 15:09:26 +00:00
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_dma_buf_upload_accept (gpointer impl, GstBuffer * buffer, GstCaps * in_caps,
|
|
|
|
GstCaps * out_caps)
|
|
|
|
{
|
|
|
|
struct DmabufUpload *dmabuf = impl;
|
2023-05-21 09:23:39 +00:00
|
|
|
GstVideoInfoDmaDrm *in_info_drm = &dmabuf->upload->priv->in_info_drm;
|
|
|
|
GstVideoInfo *in_info = &in_info_drm->vinfo;
|
2018-12-12 14:48:09 +00:00
|
|
|
GstVideoInfo *out_info = &dmabuf->out_info;
|
2023-05-21 09:23:39 +00:00
|
|
|
guint n_planes;
|
2015-11-13 16:24:30 +00:00
|
|
|
GstVideoMeta *meta;
|
|
|
|
guint n_mem;
|
|
|
|
GstMemory *mems[GST_VIDEO_MAX_PLANES];
|
2023-01-30 06:59:34 +00:00
|
|
|
GstMemory *previous_mem = NULL;
|
|
|
|
GstEGLImageCacheEntry *cache_entry = NULL;
|
2018-07-05 08:17:27 +00:00
|
|
|
gsize offset[GST_VIDEO_MAX_PLANES];
|
|
|
|
gint fd[GST_VIDEO_MAX_PLANES];
|
2015-11-13 16:24:30 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
n_mem = gst_buffer_n_memory (buffer);
|
|
|
|
meta = gst_buffer_get_video_meta (buffer);
|
|
|
|
|
2021-03-18 03:20:34 +00:00
|
|
|
if (!dmabuf->upload->context->gl_vtable->EGLImageTargetTexture2D)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
/* dmabuf upload is only supported with EGL contexts. */
|
2016-12-01 09:24:18 +00:00
|
|
|
if (gst_gl_context_get_gl_platform (dmabuf->upload->context) !=
|
|
|
|
GST_GL_PLATFORM_EGL)
|
2015-11-13 16:24:30 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!gst_gl_context_check_feature (dmabuf->upload->context,
|
2021-10-14 06:48:59 +00:00
|
|
|
"EGL_KHR_image_base")) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload, "no EGL_KHR_image_base extension");
|
2015-11-13 16:24:30 +00:00
|
|
|
return FALSE;
|
2021-10-14 06:48:59 +00:00
|
|
|
}
|
2015-11-13 16:24:30 +00:00
|
|
|
|
2023-05-21 09:23:39 +00:00
|
|
|
if (!gst_gl_context_egl_supports_modifier (dmabuf->upload->context)) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload, "no modifier support");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-03-05 23:03:49 +00:00
|
|
|
if (dmabuf->target == GST_GL_TEXTURE_TARGET_EXTERNAL_OES &&
|
|
|
|
!gst_gl_context_check_feature (dmabuf->upload->context,
|
2021-10-14 06:48:59 +00:00
|
|
|
"GL_OES_EGL_image_external")) {
|
2023-01-18 21:39:03 +00:00
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload, "no GL_OES_EGL_image_external extension");
|
2020-03-05 23:03:49 +00:00
|
|
|
return FALSE;
|
2021-10-14 06:48:59 +00:00
|
|
|
}
|
2020-03-05 23:03:49 +00:00
|
|
|
|
2023-05-21 09:23:39 +00:00
|
|
|
/* If caps changes from the last time, do more check. */
|
|
|
|
if (in_caps != dmabuf->in_caps) {
|
|
|
|
GstCapsFeatures *filter_features;
|
|
|
|
|
|
|
|
filter_features =
|
|
|
|
gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY, NULL);
|
|
|
|
if (_filter_caps_with_features (in_caps, filter_features, NULL)) {
|
|
|
|
in_info_drm->drm_fourcc = gst_video_dma_drm_fourcc_from_format
|
|
|
|
(GST_VIDEO_INFO_FORMAT (in_info));
|
|
|
|
if (in_info_drm->drm_fourcc == DRM_FORMAT_INVALID) {
|
|
|
|
gst_caps_features_free (filter_features);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
in_info_drm->drm_modifier = DRM_FORMAT_MOD_LINEAR;
|
|
|
|
} else if (!gst_caps_features_contains (gst_caps_get_features (in_caps, 0),
|
|
|
|
GST_CAPS_FEATURE_MEMORY_DMABUF)) {
|
|
|
|
gst_caps_features_free (filter_features);
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload,
|
|
|
|
"Not a dma caps %" GST_PTR_FORMAT, in_caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gst_caps_features_free (filter_features);
|
|
|
|
|
|
|
|
if (in_info_drm->drm_modifier == DRM_FORMAT_MOD_LINEAR) {
|
|
|
|
g_assert (GST_VIDEO_INFO_FORMAT (in_info) != GST_VIDEO_FORMAT_UNKNOWN);
|
|
|
|
g_assert (GST_VIDEO_INFO_FORMAT (in_info) != GST_VIDEO_FORMAT_ENCODED);
|
|
|
|
} else {
|
|
|
|
if (!gst_video_info_dma_drm_to_video_info (in_info_drm, in_info))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dmabuf->direct && !gst_egl_image_check_dmabuf_direct_with_dma_drm
|
|
|
|
(dmabuf->upload->context, in_info_drm, dmabuf->target)) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload,
|
|
|
|
"Direct mode does not support %" GST_FOURCC_FORMAT ":0x%016"
|
|
|
|
G_GINT64_MODIFIER "x with target: %s",
|
|
|
|
GST_FOURCC_ARGS (in_info_drm->drm_fourcc), in_info_drm->drm_modifier,
|
|
|
|
gst_gl_texture_target_to_string (dmabuf->target));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dmabuf->in_caps = in_caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
n_planes = GST_VIDEO_INFO_N_PLANES (in_info);
|
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
/* This will eliminate most non-dmabuf out there */
|
2021-10-14 06:48:59 +00:00
|
|
|
if (!gst_is_dmabuf_memory (gst_buffer_peek_memory (buffer, 0))) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload, "input not dmabuf");
|
2015-11-13 16:24:30 +00:00
|
|
|
return FALSE;
|
2021-10-14 06:48:59 +00:00
|
|
|
}
|
2015-11-13 16:24:30 +00:00
|
|
|
|
|
|
|
/* We cannot have multiple dmabuf per plane */
|
2021-10-14 06:48:59 +00:00
|
|
|
if (n_mem > n_planes) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload,
|
|
|
|
"number of memory (%u) != number of planes (%u)", n_mem, n_planes);
|
2015-11-13 16:24:30 +00:00
|
|
|
return FALSE;
|
2021-10-14 06:48:59 +00:00
|
|
|
}
|
2015-11-13 16:24:30 +00:00
|
|
|
|
|
|
|
/* Update video info based on video meta */
|
|
|
|
if (meta) {
|
|
|
|
in_info->width = meta->width;
|
|
|
|
in_info->height = meta->height;
|
|
|
|
|
|
|
|
for (i = 0; i < meta->n_planes; i++) {
|
|
|
|
in_info->offset[i] = meta->offset[i];
|
|
|
|
in_info->stride[i] = meta->stride[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 14:48:09 +00:00
|
|
|
if (out_caps != dmabuf->out_caps) {
|
|
|
|
dmabuf->out_caps = out_caps;
|
|
|
|
if (!gst_video_info_from_caps (out_info, out_caps))
|
|
|
|
return FALSE;
|
2022-11-08 17:47:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When we zero-copy tiles, we need to propagate the strides, which contains
|
|
|
|
* the tile dimension. This is because the shader needs to know the padded
|
|
|
|
* size in order to correctly sample into these special buffer.
|
|
|
|
*/
|
|
|
|
if (meta && GST_VIDEO_FORMAT_INFO_IS_TILED (out_info->finfo)) {
|
|
|
|
out_info->width = meta->width;
|
|
|
|
out_info->height = meta->height;
|
|
|
|
|
|
|
|
for (i = 0; i < meta->n_planes; i++) {
|
|
|
|
out_info->offset[i] = meta->offset[i];
|
|
|
|
out_info->stride[i] = meta->stride[i];
|
|
|
|
}
|
|
|
|
}
|
2018-07-05 08:17:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
if (dmabuf->params)
|
|
|
|
gst_gl_allocation_params_free ((GstGLAllocationParams *) dmabuf->params);
|
2023-05-21 09:23:39 +00:00
|
|
|
if (!(dmabuf->params = gst_gl_video_allocation_params_new_wrapped_gl_handle
|
|
|
|
(dmabuf->upload->context, NULL, out_info, -1, NULL, dmabuf->target,
|
|
|
|
0, NULL, NULL, NULL)))
|
2015-11-13 16:24:30 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Find and validate all memories */
|
|
|
|
for (i = 0; i < n_planes; i++) {
|
|
|
|
guint plane_size;
|
|
|
|
guint length;
|
2018-07-05 08:17:27 +00:00
|
|
|
guint mem_idx;
|
|
|
|
gsize mem_skip;
|
2015-11-13 16:24:30 +00:00
|
|
|
|
|
|
|
plane_size = gst_gl_get_plane_data_size (in_info, NULL, i);
|
|
|
|
|
|
|
|
if (!gst_buffer_find_memory (buffer, in_info->offset[i], plane_size,
|
2021-10-14 06:48:59 +00:00
|
|
|
&mem_idx, &length, &mem_skip)) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload, "could not find memory %u", i);
|
2015-11-13 16:24:30 +00:00
|
|
|
return FALSE;
|
2021-10-14 06:48:59 +00:00
|
|
|
}
|
2015-11-13 16:24:30 +00:00
|
|
|
|
|
|
|
/* We can't have more then one dmabuf per plane */
|
2021-10-14 06:48:59 +00:00
|
|
|
if (length != 1) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload, "data for plane %u spans %u memories",
|
|
|
|
i, length);
|
2015-11-13 16:24:30 +00:00
|
|
|
return FALSE;
|
2021-10-14 06:48:59 +00:00
|
|
|
}
|
2015-11-13 16:24:30 +00:00
|
|
|
|
2018-07-05 08:17:27 +00:00
|
|
|
mems[i] = gst_buffer_peek_memory (buffer, mem_idx);
|
2015-11-13 16:24:30 +00:00
|
|
|
|
|
|
|
/* And all memory found must be dmabuf */
|
2021-10-14 06:48:59 +00:00
|
|
|
if (!gst_is_dmabuf_memory (mems[i])) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload, "memory %u is not dmabuf", i);
|
2015-11-13 16:24:30 +00:00
|
|
|
return FALSE;
|
2021-10-14 06:48:59 +00:00
|
|
|
}
|
2018-07-05 08:17:27 +00:00
|
|
|
|
|
|
|
offset[i] = mems[i]->offset + mem_skip;
|
|
|
|
fd[i] = gst_dmabuf_memory_get_fd (mems[i]);
|
2015-11-13 16:24:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 10:21:53 +00:00
|
|
|
if (dmabuf->direct) {
|
2018-07-05 08:17:27 +00:00
|
|
|
dmabuf->n_mem = 1;
|
2023-05-21 09:23:39 +00:00
|
|
|
} else {
|
2018-07-05 08:17:27 +00:00
|
|
|
dmabuf->n_mem = n_planes;
|
2023-05-21 09:23:39 +00:00
|
|
|
}
|
2018-07-05 08:17:27 +00:00
|
|
|
|
2023-01-30 06:59:34 +00:00
|
|
|
/* Now create an EGLImage for each dmabuf */
|
2018-07-05 08:17:27 +00:00
|
|
|
for (i = 0; i < dmabuf->n_mem; i++) {
|
2023-01-30 06:59:34 +00:00
|
|
|
/*
|
|
|
|
* Check if an EGLImage is cached. Remember the previous memory and cache
|
|
|
|
* entry to avoid repeated lookups if all mems[i] point to the same memory.
|
|
|
|
*/
|
|
|
|
dmabuf->eglimage[i] = gst_egl_image_cache_lookup (dmabuf->eglimage_cache,
|
|
|
|
mems[i], i, &previous_mem, &cache_entry);
|
2019-06-23 10:34:49 +00:00
|
|
|
if (dmabuf->eglimage[i]) {
|
|
|
|
dmabuf->formats[i] = dmabuf->eglimage[i]->format;
|
2015-11-13 16:24:30 +00:00
|
|
|
continue;
|
2019-06-23 10:34:49 +00:00
|
|
|
}
|
2015-11-13 16:24:30 +00:00
|
|
|
|
|
|
|
/* otherwise create one and cache it */
|
2023-05-21 09:23:39 +00:00
|
|
|
if (dmabuf->direct) {
|
|
|
|
dmabuf->eglimage[i] = gst_egl_image_from_dmabuf_direct_target_with_dma_drm
|
|
|
|
(dmabuf->upload->context, fd, offset, in_info_drm, dmabuf->target);
|
|
|
|
} else {
|
|
|
|
dmabuf->eglimage[i] = gst_egl_image_from_dmabuf_with_dma_drm
|
|
|
|
(dmabuf->upload->context, fd[i], in_info_drm, i, offset[i]);
|
|
|
|
}
|
2015-11-13 16:24:30 +00:00
|
|
|
|
2021-10-14 06:48:59 +00:00
|
|
|
if (!dmabuf->eglimage[i]) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload, "could not create eglimage");
|
2015-11-13 16:24:30 +00:00
|
|
|
return FALSE;
|
2021-10-14 06:48:59 +00:00
|
|
|
}
|
2015-11-13 16:24:30 +00:00
|
|
|
|
2023-01-30 06:59:34 +00:00
|
|
|
gst_egl_image_cache_store (dmabuf->eglimage_cache, mems[i], i,
|
|
|
|
dmabuf->eglimage[i], &cache_entry);
|
2018-11-09 08:32:49 +00:00
|
|
|
dmabuf->formats[i] = dmabuf->eglimage[i]->format;
|
2015-11-13 16:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_dma_buf_upload_propose_allocation (gpointer impl, GstQuery * decide_query,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
/* nothing to do for now. */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_dma_buf_upload_perform_gl_thread (GstGLContext * context,
|
|
|
|
struct DmabufUpload *dmabuf)
|
|
|
|
{
|
|
|
|
GstGLMemoryAllocator *allocator;
|
|
|
|
|
|
|
|
allocator =
|
|
|
|
GST_GL_MEMORY_ALLOCATOR (gst_allocator_find
|
2016-05-04 02:17:59 +00:00
|
|
|
(GST_GL_MEMORY_EGL_ALLOCATOR_NAME));
|
2015-11-13 16:24:30 +00:00
|
|
|
|
|
|
|
/* FIXME: buffer pool */
|
|
|
|
dmabuf->outbuf = gst_buffer_new ();
|
2018-11-09 08:32:49 +00:00
|
|
|
gst_gl_memory_setup_buffer (allocator, dmabuf->outbuf, dmabuf->params,
|
|
|
|
dmabuf->formats, (gpointer *) dmabuf->eglimage, dmabuf->n_mem);
|
2015-11-13 16:24:30 +00:00
|
|
|
gst_object_unref (allocator);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstGLUploadReturn
|
|
|
|
_dma_buf_upload_perform (gpointer impl, GstBuffer * buffer, GstBuffer ** outbuf)
|
|
|
|
{
|
|
|
|
struct DmabufUpload *dmabuf = impl;
|
|
|
|
|
2020-03-09 10:21:53 +00:00
|
|
|
/* The direct path sets sinkpad caps to RGBA but this may be incorrect for
|
|
|
|
* the non-direct path, if that path fails to accept. In that case, we need
|
|
|
|
* to reconfigure.
|
|
|
|
*/
|
|
|
|
if (!dmabuf->direct &&
|
|
|
|
GST_VIDEO_INFO_FORMAT (&dmabuf->upload->priv->in_info) !=
|
|
|
|
GST_VIDEO_INFO_FORMAT (&dmabuf->out_info))
|
|
|
|
return GST_GL_UPLOAD_RECONFIGURE;
|
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
gst_gl_context_thread_add (dmabuf->upload->context,
|
|
|
|
(GstGLContextThreadFunc) _dma_buf_upload_perform_gl_thread, dmabuf);
|
|
|
|
|
|
|
|
if (!dmabuf->outbuf)
|
|
|
|
return GST_GL_UPLOAD_ERROR;
|
|
|
|
|
|
|
|
gst_buffer_add_parent_buffer_meta (dmabuf->outbuf, buffer);
|
|
|
|
|
|
|
|
*outbuf = dmabuf->outbuf;
|
|
|
|
dmabuf->outbuf = NULL;
|
|
|
|
|
|
|
|
return GST_GL_UPLOAD_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_dma_buf_upload_free (gpointer impl)
|
|
|
|
{
|
|
|
|
struct DmabufUpload *dmabuf = impl;
|
|
|
|
|
|
|
|
if (dmabuf->params)
|
|
|
|
gst_gl_allocation_params_free ((GstGLAllocationParams *) dmabuf->params);
|
2023-01-30 06:59:34 +00:00
|
|
|
gst_egl_image_cache_unref (dmabuf->eglimage_cache);
|
2015-11-13 16:24:30 +00:00
|
|
|
|
|
|
|
g_free (impl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const UploadMethod _dma_buf_upload = {
|
|
|
|
"Dmabuf",
|
2022-07-07 13:40:22 +00:00
|
|
|
METHOD_FLAG_CAN_ACCEPT_RAW,
|
2015-11-13 16:24:30 +00:00
|
|
|
&_dma_buf_upload_caps,
|
|
|
|
&_dma_buf_upload_new,
|
|
|
|
&_dma_buf_upload_transform_caps,
|
|
|
|
&_dma_buf_upload_accept,
|
|
|
|
&_dma_buf_upload_propose_allocation,
|
|
|
|
&_dma_buf_upload_perform,
|
|
|
|
&_dma_buf_upload_free
|
|
|
|
};
|
|
|
|
|
2019-08-29 17:42:39 +00:00
|
|
|
/* a variant of the DMABuf uploader that relies on HW color conversion instead
|
2018-07-05 08:17:27 +00:00
|
|
|
* of shaders */
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
_direct_dma_buf_upload_new (GstGLUpload * upload)
|
|
|
|
{
|
|
|
|
struct DmabufUpload *dmabuf = _dma_buf_upload_new (upload);
|
|
|
|
dmabuf->direct = TRUE;
|
|
|
|
gst_video_info_init (&dmabuf->out_info);
|
|
|
|
return dmabuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
_direct_dma_buf_upload_transform_caps (gpointer impl, GstGLContext * context,
|
|
|
|
GstPadDirection direction, GstCaps * caps)
|
|
|
|
{
|
2018-10-17 15:09:26 +00:00
|
|
|
struct DmabufUpload *dmabuf = impl;
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
GstCaps *ret, *tmp;
|
2018-07-05 08:17:27 +00:00
|
|
|
|
2020-02-18 12:46:08 +00:00
|
|
|
if (context) {
|
2021-03-18 03:20:34 +00:00
|
|
|
const GstGLFuncs *gl = context->gl_vtable;
|
|
|
|
|
|
|
|
if (!gl->EGLImageTargetTexture2D)
|
|
|
|
return NULL;
|
|
|
|
|
2020-02-18 12:46:08 +00:00
|
|
|
/* Don't propose direct DMABuf caps feature unless it can be supported */
|
|
|
|
if (gst_gl_context_get_gl_platform (context) != GST_GL_PLATFORM_EGL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (dmabuf->target == GST_GL_TEXTURE_TARGET_EXTERNAL_OES &&
|
|
|
|
!gst_gl_context_check_feature (context, "GL_OES_EGL_image_external"))
|
|
|
|
return NULL;
|
|
|
|
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
if (!gst_gl_context_egl_supports_modifier (context))
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-02-18 12:46:08 +00:00
|
|
|
|
2018-07-05 08:17:27 +00:00
|
|
|
if (direction == GST_PAD_SINK) {
|
|
|
|
gint i, n;
|
2020-02-12 17:25:54 +00:00
|
|
|
GstGLTextureTarget target_mask;
|
2018-07-05 08:17:27 +00:00
|
|
|
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
ret = _dma_buf_upload_transform_caps_common (caps, context, direction,
|
|
|
|
dmabuf->target == GST_GL_TEXTURE_TARGET_EXTERNAL_OES,
|
|
|
|
1 << dmabuf->target, GST_CAPS_FEATURE_MEMORY_DMABUF,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
|
|
|
tmp = _dma_buf_upload_transform_caps_common (caps, context, direction,
|
|
|
|
dmabuf->target == GST_GL_TEXTURE_TARGET_EXTERNAL_OES,
|
|
|
|
1 << dmabuf->target, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
|
|
|
if (!ret) {
|
|
|
|
ret = tmp;
|
|
|
|
tmp = NULL;
|
|
|
|
}
|
|
|
|
if (tmp)
|
|
|
|
ret = gst_caps_merge (ret, tmp);
|
2018-07-05 08:17:27 +00:00
|
|
|
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
if (!ret) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload,
|
|
|
|
"direction %s, fails to transformed DMA caps %" GST_PTR_FORMAT,
|
|
|
|
"sink", caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The direct mode, sampling an imported texture will return an RGBA
|
|
|
|
vector in the same colorspace as the source image. If the source
|
|
|
|
image is stored in YUV(or some other basis) then the YUV values will
|
|
|
|
be transformed to RGB values. So, any input format is transformed to:
|
|
|
|
"video/x-raw(memory:GLMemory), format=(string)RGBA" as output. */
|
2018-07-05 08:17:27 +00:00
|
|
|
gst_caps_set_simple (ret, "format", G_TYPE_STRING, "RGBA", NULL);
|
|
|
|
|
|
|
|
n = gst_caps_get_size (ret);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (ret, i);
|
|
|
|
|
|
|
|
gst_structure_remove_fields (s, "chroma-site", NULL);
|
|
|
|
gst_structure_remove_fields (s, "colorimetry", NULL);
|
|
|
|
}
|
2020-02-18 12:46:08 +00:00
|
|
|
|
|
|
|
target_mask = 1 << dmabuf->target;
|
2020-02-12 17:25:54 +00:00
|
|
|
tmp = _caps_intersect_texture_target (ret, target_mask);
|
2018-07-05 08:17:27 +00:00
|
|
|
gst_caps_unref (ret);
|
|
|
|
ret = tmp;
|
|
|
|
} else {
|
|
|
|
gint i, n;
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
GstCaps *tmp_caps;
|
|
|
|
|
|
|
|
/* The src caps may only contain RGBA format, and we should list
|
|
|
|
all possible supported formats to detect the conversion for
|
|
|
|
DMABuf kind memory. */
|
|
|
|
tmp_caps = gst_caps_copy (caps);
|
|
|
|
for (i = 0; i < gst_caps_get_size (tmp_caps); i++)
|
|
|
|
_set_default_formats_list (gst_caps_get_structure (tmp_caps, i));
|
|
|
|
|
|
|
|
ret = _dma_buf_upload_transform_caps_common (tmp_caps, context, direction,
|
|
|
|
dmabuf->target == GST_GL_TEXTURE_TARGET_EXTERNAL_OES,
|
|
|
|
1 << dmabuf->target, GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_DMABUF);
|
|
|
|
gst_caps_unref (tmp_caps);
|
|
|
|
|
|
|
|
tmp = _dma_buf_upload_transform_caps_common (caps, context, direction,
|
|
|
|
dmabuf->target == GST_GL_TEXTURE_TARGET_EXTERNAL_OES,
|
|
|
|
1 << dmabuf->target, GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
ret = tmp;
|
|
|
|
tmp = NULL;
|
|
|
|
}
|
|
|
|
if (tmp)
|
|
|
|
ret = gst_caps_merge (ret, tmp);
|
2018-07-05 08:17:27 +00:00
|
|
|
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
if (!ret) {
|
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload,
|
|
|
|
"direction %s, fails to transformed DMA caps %" GST_PTR_FORMAT,
|
|
|
|
"src", caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-05 08:17:27 +00:00
|
|
|
|
|
|
|
n = gst_caps_get_size (ret);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (ret, i);
|
|
|
|
|
|
|
|
gst_structure_remove_fields (s, "texture-target", NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
glupload: enable drm kind caps in glupload plugin for DMA buf
Most of the time, the RGB kind formats are OpenGL native supported
format which has only one plane. They can be imported at one shot
using no matter DIRECT or INDIRECT mode.
While YUV kind formats which have multi planes have two ways to import.
They can be DIRECT imported, which requires GL_OES_EGL_image_external
extension. The output format should be RGBA and TARGET should be set
as OES after imported. The other way, they can be INDIRECT imported,
which makes each plane as a texture. In this mode, the imported textures
have different fourcc from the original format. For example, the NV12
format can be imported as a R8 texture for the first plane and RG88
texture for the second plane. The output TARGET should be sets as 2D
in this mode.
When converting sink caps to src caps, we first filter the feature of
"video/x-raw(memory:DMABuf)" and system memory. Then Based on the
external_only flag (INDIRECT mode does not care while DIRECT mode cares),
we transform the drm-format into the gst video format.
When converting src caps into sink caps, we first filter the correct
TARGET(INDIRECT mode contains 2D only while DIRECT mode contains 2D,
OES or both of them) gstructure. Then Based on the include_external flag
(INDIRECT mode always true while DIRECT mode depends on TARGET), we
transform the gst video format into drm-format.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-19 14:44:52 +00:00
|
|
|
GST_DEBUG_OBJECT (dmabuf->upload, "direction %s, transformed %"
|
|
|
|
GST_PTR_FORMAT " into %" GST_PTR_FORMAT,
|
|
|
|
direction == GST_PAD_SRC ? "src" : "sink", caps, ret);
|
2018-10-17 15:09:26 +00:00
|
|
|
|
2018-07-05 08:17:27 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const UploadMethod _direct_dma_buf_upload = {
|
|
|
|
"DirectDmabuf",
|
2022-11-30 04:04:09 +00:00
|
|
|
METHOD_FLAG_CAN_ACCEPT_RAW,
|
2018-07-05 08:17:27 +00:00
|
|
|
&_dma_buf_upload_caps,
|
|
|
|
&_direct_dma_buf_upload_new,
|
|
|
|
&_direct_dma_buf_upload_transform_caps,
|
|
|
|
&_dma_buf_upload_accept,
|
|
|
|
&_dma_buf_upload_propose_allocation,
|
|
|
|
&_dma_buf_upload_perform,
|
|
|
|
&_dma_buf_upload_free
|
|
|
|
};
|
|
|
|
|
2020-02-18 12:46:08 +00:00
|
|
|
/* a variant of the direct DMABuf uploader that uses external OES textures */
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
_direct_dma_buf_external_upload_new (GstGLUpload * upload)
|
|
|
|
{
|
|
|
|
struct DmabufUpload *dmabuf = _direct_dma_buf_upload_new (upload);
|
|
|
|
dmabuf->target = GST_GL_TEXTURE_TARGET_EXTERNAL_OES;
|
|
|
|
return dmabuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const UploadMethod _direct_dma_buf_external_upload = {
|
|
|
|
"DirectDmabufExternal",
|
2022-11-30 04:04:09 +00:00
|
|
|
METHOD_FLAG_CAN_ACCEPT_RAW,
|
2020-02-18 12:46:08 +00:00
|
|
|
&_dma_buf_upload_caps,
|
|
|
|
&_direct_dma_buf_external_upload_new,
|
|
|
|
&_direct_dma_buf_upload_transform_caps,
|
|
|
|
&_dma_buf_upload_accept,
|
|
|
|
&_dma_buf_upload_propose_allocation,
|
|
|
|
&_dma_buf_upload_perform,
|
|
|
|
&_dma_buf_upload_free
|
|
|
|
};
|
|
|
|
|
2015-11-13 16:24:30 +00:00
|
|
|
#endif /* GST_GL_HAVE_DMABUF */
|
2014-11-05 09:18:06 +00:00
|
|
|
|
|
|
|
struct GLUploadMeta
|
|
|
|
{
|
|
|
|
GstGLUpload *upload;
|
|
|
|
|
|
|
|
gboolean result;
|
|
|
|
GstVideoGLTextureUploadMeta *meta;
|
2015-05-29 16:15:51 +00:00
|
|
|
guint texture_ids[GST_GL_UPLOAD_MAX_PLANES];
|
2016-08-02 08:21:20 +00:00
|
|
|
GstBufferPool *pool;
|
2014-11-05 09:18:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
_upload_meta_upload_new (GstGLUpload * upload)
|
2014-05-07 14:59:42 +00:00
|
|
|
{
|
2014-11-05 09:18:06 +00:00
|
|
|
struct GLUploadMeta *meta = g_new0 (struct GLUploadMeta, 1);
|
2014-05-07 14:59:42 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
meta->upload = upload;
|
2016-08-22 07:18:27 +00:00
|
|
|
meta->pool = NULL;
|
2014-05-07 14:59:42 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
return meta;
|
2014-05-07 14:59:42 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
static GstCaps *
|
2016-08-22 07:18:27 +00:00
|
|
|
_upload_meta_upload_transform_caps (gpointer impl, GstGLContext * context,
|
2015-02-02 13:11:06 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps)
|
|
|
|
{
|
2015-12-29 07:16:04 +00:00
|
|
|
GstCapsFeatures *passthrough =
|
|
|
|
gst_caps_features_from_string
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION);
|
2015-02-02 13:11:06 +00:00
|
|
|
GstCaps *ret;
|
|
|
|
|
|
|
|
if (direction == GST_PAD_SINK) {
|
2016-01-04 09:26:09 +00:00
|
|
|
GstCaps *tmp;
|
|
|
|
|
2015-12-29 07:16:04 +00:00
|
|
|
ret =
|
|
|
|
_set_caps_features_with_passthrough (caps,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY, passthrough);
|
2016-01-04 09:26:09 +00:00
|
|
|
|
|
|
|
tmp = _caps_intersect_texture_target (ret, 1 << GST_GL_TEXTURE_TARGET_2D);
|
|
|
|
gst_caps_unref (ret);
|
|
|
|
ret = tmp;
|
2015-02-02 13:11:06 +00:00
|
|
|
} else {
|
2015-10-28 13:44:26 +00:00
|
|
|
gint i, n;
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
ret =
|
2015-12-29 07:16:04 +00:00
|
|
|
_set_caps_features_with_passthrough (caps,
|
|
|
|
GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META, passthrough);
|
2015-02-05 00:05:02 +00:00
|
|
|
gst_caps_set_simple (ret, "format", G_TYPE_STRING, "RGBA", NULL);
|
2015-10-28 13:44:26 +00:00
|
|
|
|
|
|
|
n = gst_caps_get_size (ret);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (ret, i);
|
|
|
|
|
|
|
|
gst_structure_remove_fields (s, "texture-target", NULL);
|
|
|
|
}
|
2015-02-02 13:11:06 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 07:16:04 +00:00
|
|
|
gst_caps_features_free (passthrough);
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static gboolean
|
|
|
|
_upload_meta_upload_accept (gpointer impl, GstBuffer * buffer,
|
|
|
|
GstCaps * in_caps, GstCaps * out_caps)
|
2013-11-14 04:27:52 +00:00
|
|
|
{
|
2014-11-05 09:18:06 +00:00
|
|
|
struct GLUploadMeta *upload = impl;
|
2015-07-27 06:36:40 +00:00
|
|
|
GstCapsFeatures *features;
|
2014-11-05 09:18:06 +00:00
|
|
|
GstVideoGLTextureUploadMeta *meta;
|
|
|
|
gboolean ret = TRUE;
|
2016-08-02 08:21:20 +00:00
|
|
|
GstStructure *config;
|
|
|
|
gsize size;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
features = gst_caps_get_features (in_caps, 0);
|
2013-11-14 04:27:52 +00:00
|
|
|
|
2015-07-27 06:36:40 +00:00
|
|
|
if (!gst_caps_features_contains (features,
|
|
|
|
GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META))
|
2014-11-05 09:18:06 +00:00
|
|
|
ret = FALSE;
|
2014-06-03 03:59:51 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
features = gst_caps_get_features (out_caps, 0);
|
2015-07-27 06:36:40 +00:00
|
|
|
if (!gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY))
|
2014-11-05 09:18:06 +00:00
|
|
|
ret = FALSE;
|
2014-09-23 02:02:18 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
if (!ret)
|
|
|
|
return ret;
|
2014-05-12 11:51:38 +00:00
|
|
|
|
2016-08-22 07:18:27 +00:00
|
|
|
if (upload->pool == NULL)
|
|
|
|
upload->pool = gst_gl_buffer_pool_new (upload->upload->context);
|
|
|
|
|
2016-08-02 08:21:20 +00:00
|
|
|
if (!gst_buffer_pool_is_active (upload->pool)) {
|
|
|
|
config = gst_buffer_pool_get_config (upload->pool);
|
|
|
|
|
|
|
|
size = upload->upload->priv->in_info.size;
|
|
|
|
gst_buffer_pool_config_set_params (config, in_caps, size, 0, 0);
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_set_config (upload->pool, config)) {
|
|
|
|
GST_WARNING_OBJECT (upload->upload, "failed to set bufferpool config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gst_buffer_pool_set_active (upload->pool, TRUE);
|
|
|
|
}
|
2015-12-16 07:41:06 +00:00
|
|
|
|
2015-02-02 13:15:30 +00:00
|
|
|
if (buffer) {
|
|
|
|
if ((meta = gst_buffer_get_video_gl_texture_upload_meta (buffer)) == NULL)
|
|
|
|
return FALSE;
|
2014-09-21 11:36:49 +00:00
|
|
|
|
2015-02-02 13:15:30 +00:00
|
|
|
if (meta->texture_type[0] != GST_VIDEO_GL_TEXTURE_TYPE_RGBA) {
|
|
|
|
GST_FIXME_OBJECT (upload, "only single rgba texture supported");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (meta->texture_orientation !=
|
|
|
|
GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL) {
|
|
|
|
GST_FIXME_OBJECT (upload, "only x-normal, y-normal textures supported");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-11-05 09:18:06 +00:00
|
|
|
}
|
2014-09-21 11:36:49 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-05-12 11:51:38 +00:00
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
static void
|
|
|
|
_upload_meta_upload_propose_allocation (gpointer impl, GstQuery * decide_query,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
struct GLUploadMeta *upload = impl;
|
|
|
|
GstStructure *gl_context;
|
|
|
|
gchar *platform, *gl_apis;
|
|
|
|
gpointer handle;
|
|
|
|
|
|
|
|
gl_apis =
|
2016-06-28 03:51:22 +00:00
|
|
|
gst_gl_api_to_string (gst_gl_context_get_gl_api (upload->upload->
|
|
|
|
context));
|
2016-05-03 15:16:51 +00:00
|
|
|
platform =
|
2016-06-28 03:51:22 +00:00
|
|
|
gst_gl_platform_to_string (gst_gl_context_get_gl_platform (upload->
|
|
|
|
upload->context));
|
2015-02-02 13:11:06 +00:00
|
|
|
handle = (gpointer) gst_gl_context_get_gl_context (upload->upload->context);
|
|
|
|
|
|
|
|
gl_context =
|
|
|
|
gst_structure_new ("GstVideoGLTextureUploadMeta", "gst.gl.GstGLContext",
|
2016-10-05 01:19:12 +00:00
|
|
|
GST_TYPE_GL_CONTEXT, upload->upload->context, "gst.gl.context.handle",
|
2015-02-02 13:11:06 +00:00
|
|
|
G_TYPE_POINTER, handle, "gst.gl.context.type", G_TYPE_STRING, platform,
|
|
|
|
"gst.gl.context.apis", G_TYPE_STRING, gl_apis, NULL);
|
|
|
|
gst_query_add_allocation_meta (query,
|
|
|
|
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, gl_context);
|
|
|
|
|
|
|
|
g_free (gl_apis);
|
|
|
|
g_free (platform);
|
|
|
|
gst_structure_free (gl_context);
|
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
/*
|
|
|
|
* Uploads using gst_video_gl_texture_upload_meta_upload().
|
|
|
|
* i.e. consumer of GstVideoGLTextureUploadMeta
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_do_upload_with_meta (GstGLContext * context, struct GLUploadMeta *upload)
|
|
|
|
{
|
|
|
|
if (!gst_video_gl_texture_upload_meta_upload (upload->meta,
|
|
|
|
upload->texture_ids)) {
|
|
|
|
upload->result = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
upload->result = TRUE;
|
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static GstGLUploadReturn
|
|
|
|
_upload_meta_upload_perform (gpointer impl, GstBuffer * buffer,
|
|
|
|
GstBuffer ** outbuf)
|
|
|
|
{
|
|
|
|
struct GLUploadMeta *upload = impl;
|
|
|
|
int i;
|
2015-05-29 16:15:51 +00:00
|
|
|
GstVideoInfo *in_info = &upload->upload->priv->in_info;
|
|
|
|
guint max_planes = GST_VIDEO_INFO_N_PLANES (in_info);
|
|
|
|
|
|
|
|
/* Support stereo views for separated multiview mode */
|
|
|
|
if (GST_VIDEO_INFO_MULTIVIEW_MODE (in_info) ==
|
|
|
|
GST_VIDEO_MULTIVIEW_MODE_SEPARATED)
|
|
|
|
max_planes *= GST_VIDEO_INFO_VIEWS (in_info);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
GST_LOG_OBJECT (upload, "Attempting upload with GstVideoGLTextureUploadMeta");
|
2014-09-21 11:36:49 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
upload->meta = gst_buffer_get_video_gl_texture_upload_meta (buffer);
|
2014-09-21 11:36:49 +00:00
|
|
|
|
2016-08-02 08:21:20 +00:00
|
|
|
if (gst_buffer_pool_acquire_buffer (upload->pool, outbuf,
|
|
|
|
NULL) != GST_FLOW_OK) {
|
|
|
|
GST_WARNING_OBJECT (upload, "failed to acquire buffer from bufferpool");
|
|
|
|
return GST_GL_UPLOAD_ERROR;
|
|
|
|
}
|
2014-11-05 09:18:06 +00:00
|
|
|
|
2015-05-29 16:15:51 +00:00
|
|
|
for (i = 0; i < GST_GL_UPLOAD_MAX_PLANES; i++) {
|
2014-11-05 09:18:06 +00:00
|
|
|
guint tex_id = 0;
|
2014-05-06 10:59:24 +00:00
|
|
|
|
2015-05-29 16:15:51 +00:00
|
|
|
if (i < max_planes) {
|
2014-11-05 09:18:06 +00:00
|
|
|
GstMemory *mem = gst_buffer_peek_memory (*outbuf, i);
|
|
|
|
tex_id = ((GstGLMemory *) mem)->tex_id;
|
2013-11-14 04:27:52 +00:00
|
|
|
}
|
2014-11-05 09:18:06 +00:00
|
|
|
|
|
|
|
upload->texture_ids[i] = tex_id;
|
2013-11-14 04:27:52 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 16:15:51 +00:00
|
|
|
GST_LOG ("Uploading with GLTextureUploadMeta with textures "
|
|
|
|
"%i,%i,%i,%i / %i,%i,%i,%i",
|
|
|
|
upload->texture_ids[0], upload->texture_ids[1],
|
|
|
|
upload->texture_ids[2], upload->texture_ids[3],
|
|
|
|
upload->texture_ids[4], upload->texture_ids[5],
|
|
|
|
upload->texture_ids[6], upload->texture_ids[7]);
|
2014-11-05 09:18:06 +00:00
|
|
|
|
|
|
|
gst_gl_context_thread_add (upload->upload->context,
|
|
|
|
(GstGLContextThreadFunc) _do_upload_with_meta, upload);
|
|
|
|
|
|
|
|
if (!upload->result)
|
|
|
|
return GST_GL_UPLOAD_ERROR;
|
|
|
|
|
2015-01-14 11:08:43 +00:00
|
|
|
return GST_GL_UPLOAD_DONE;
|
2014-11-05 09:18:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_upload_meta_upload_free (gpointer impl)
|
|
|
|
{
|
|
|
|
struct GLUploadMeta *upload = impl;
|
|
|
|
|
2015-02-26 12:20:26 +00:00
|
|
|
g_return_if_fail (impl != NULL);
|
|
|
|
|
2016-08-02 08:21:20 +00:00
|
|
|
if (upload->pool)
|
|
|
|
gst_object_unref (upload->pool);
|
2015-12-16 07:41:06 +00:00
|
|
|
|
2014-12-25 21:59:42 +00:00
|
|
|
g_free (upload);
|
2014-11-05 09:18:06 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 16:20:09 +00:00
|
|
|
static GstStaticCaps _upload_meta_upload_caps =
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META, "RGBA"));
|
|
|
|
|
2015-01-21 09:17:04 +00:00
|
|
|
static const UploadMethod _upload_meta_upload = {
|
2014-11-05 09:18:06 +00:00
|
|
|
"UploadMeta",
|
|
|
|
METHOD_FLAG_CAN_SHARE_CONTEXT,
|
2015-04-28 16:20:09 +00:00
|
|
|
&_upload_meta_upload_caps,
|
2014-11-05 09:18:06 +00:00
|
|
|
&_upload_meta_upload_new,
|
2015-02-02 13:11:06 +00:00
|
|
|
&_upload_meta_upload_transform_caps,
|
2014-11-05 09:18:06 +00:00
|
|
|
&_upload_meta_upload_accept,
|
2015-02-02 13:11:06 +00:00
|
|
|
&_upload_meta_upload_propose_allocation,
|
2014-11-05 09:18:06 +00:00
|
|
|
&_upload_meta_upload_perform,
|
|
|
|
&_upload_meta_upload_free
|
|
|
|
};
|
|
|
|
|
2015-07-27 20:58:22 +00:00
|
|
|
struct RawUploadFrame
|
|
|
|
{
|
|
|
|
gint ref_count;
|
|
|
|
GstVideoFrame frame;
|
|
|
|
};
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
struct RawUpload
|
|
|
|
{
|
|
|
|
GstGLUpload *upload;
|
2015-07-27 20:58:22 +00:00
|
|
|
struct RawUploadFrame *in_frame;
|
2015-12-16 07:41:06 +00:00
|
|
|
GstGLVideoAllocationParams *params;
|
2014-11-05 09:18:06 +00:00
|
|
|
};
|
|
|
|
|
2015-07-27 20:58:22 +00:00
|
|
|
static struct RawUploadFrame *
|
|
|
|
_raw_upload_frame_new (struct RawUpload *raw, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
struct RawUploadFrame *frame;
|
2015-08-16 16:13:12 +00:00
|
|
|
GstVideoInfo *info;
|
|
|
|
gint i;
|
2015-07-27 20:58:22 +00:00
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return NULL;
|
|
|
|
|
2023-01-08 17:13:43 +00:00
|
|
|
frame = g_new (struct RawUploadFrame, 1);
|
2015-07-27 20:58:22 +00:00
|
|
|
frame->ref_count = 1;
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&frame->frame, &raw->upload->priv->in_info,
|
|
|
|
buffer, GST_MAP_READ)) {
|
2023-01-08 17:13:43 +00:00
|
|
|
g_free (frame);
|
2015-07-27 20:58:22 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
raw->upload->priv->in_info = frame->frame.info;
|
2015-08-16 16:13:12 +00:00
|
|
|
info = &raw->upload->priv->in_info;
|
|
|
|
|
|
|
|
/* Recalculate the offsets (and size) */
|
|
|
|
info->size = 0;
|
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (info); i++) {
|
|
|
|
info->offset[i] = info->size;
|
|
|
|
info->size += gst_gl_get_plane_data_size (info, NULL, i);
|
|
|
|
}
|
2015-07-27 20:58:22 +00:00
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_raw_upload_frame_ref (struct RawUploadFrame *frame)
|
|
|
|
{
|
|
|
|
g_atomic_int_inc (&frame->ref_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_raw_upload_frame_unref (struct RawUploadFrame *frame)
|
|
|
|
{
|
|
|
|
if (g_atomic_int_dec_and_test (&frame->ref_count)) {
|
|
|
|
gst_video_frame_unmap (&frame->frame);
|
2023-01-08 17:13:43 +00:00
|
|
|
g_free (frame);
|
2015-07-27 20:58:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static gpointer
|
|
|
|
_raw_data_upload_new (GstGLUpload * upload)
|
|
|
|
{
|
|
|
|
struct RawUpload *raw = g_new0 (struct RawUpload, 1);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
raw->upload = upload;
|
2014-05-09 21:59:43 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
return raw;
|
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
static GstCaps *
|
2016-08-22 07:18:27 +00:00
|
|
|
_raw_data_upload_transform_caps (gpointer impl, GstGLContext * context,
|
2015-02-02 13:11:06 +00:00
|
|
|
GstPadDirection direction, GstCaps * caps)
|
|
|
|
{
|
2015-12-29 07:16:04 +00:00
|
|
|
GstCapsFeatures *passthrough =
|
|
|
|
gst_caps_features_from_string
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION);
|
2015-02-02 13:11:06 +00:00
|
|
|
GstCaps *ret;
|
|
|
|
|
|
|
|
if (direction == GST_PAD_SINK) {
|
2016-01-04 09:26:09 +00:00
|
|
|
GstGLTextureTarget target_mask = 0;
|
glupload: make raw manner only consider system memory
The current _raw_data_upload_transform_caps() only simply apply
"memory:GLMemory" to all input caps to transform the output caps.
This is not precise and may cause problem. For example, if the
input caps include:
video/x-raw(memory:DMABuf), width=(int)1920, height=(int)1080, \
interlace-mode=(string)progressive, multiview-mode=(string)mono, \
framerate=(fraction)30/1, drm-format=(string)NV12:0x0100000000000002
it will be changed as
video/x-raw(memory:GLMemory), width=(int)1920, height=(int)1080, \
interlace-mode=(string)progressive, multiview-mode=(string)mono, \
framerate=(fraction)30/1, drm-format=(string)NV12:0x0100000000000002
For GLMemory kind caps, no drm-format should appear.
So we should let it only transforms which it can recognize.
We also should recognize the system memory caps in _accept() early, if
the input is not system memory, we just return early.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-25 02:41:21 +00:00
|
|
|
GstCapsFeatures *filter_features;
|
2016-01-04 09:26:09 +00:00
|
|
|
GstCaps *tmp;
|
|
|
|
|
glupload: make raw manner only consider system memory
The current _raw_data_upload_transform_caps() only simply apply
"memory:GLMemory" to all input caps to transform the output caps.
This is not precise and may cause problem. For example, if the
input caps include:
video/x-raw(memory:DMABuf), width=(int)1920, height=(int)1080, \
interlace-mode=(string)progressive, multiview-mode=(string)mono, \
framerate=(fraction)30/1, drm-format=(string)NV12:0x0100000000000002
it will be changed as
video/x-raw(memory:GLMemory), width=(int)1920, height=(int)1080, \
interlace-mode=(string)progressive, multiview-mode=(string)mono, \
framerate=(fraction)30/1, drm-format=(string)NV12:0x0100000000000002
For GLMemory kind caps, no drm-format should appear.
So we should let it only transforms which it can recognize.
We also should recognize the system memory caps in _accept() early, if
the input is not system memory, we just return early.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-25 02:41:21 +00:00
|
|
|
filter_features =
|
|
|
|
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
|
|
|
|
if (!_filter_caps_with_features (caps, filter_features, &tmp)) {
|
|
|
|
gst_caps_features_free (filter_features);
|
|
|
|
gst_caps_features_free (passthrough);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
gst_caps_features_free (filter_features);
|
|
|
|
|
|
|
|
ret = _set_caps_features_with_passthrough (tmp,
|
2015-12-29 07:16:04 +00:00
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY, passthrough);
|
glupload: make raw manner only consider system memory
The current _raw_data_upload_transform_caps() only simply apply
"memory:GLMemory" to all input caps to transform the output caps.
This is not precise and may cause problem. For example, if the
input caps include:
video/x-raw(memory:DMABuf), width=(int)1920, height=(int)1080, \
interlace-mode=(string)progressive, multiview-mode=(string)mono, \
framerate=(fraction)30/1, drm-format=(string)NV12:0x0100000000000002
it will be changed as
video/x-raw(memory:GLMemory), width=(int)1920, height=(int)1080, \
interlace-mode=(string)progressive, multiview-mode=(string)mono, \
framerate=(fraction)30/1, drm-format=(string)NV12:0x0100000000000002
For GLMemory kind caps, no drm-format should appear.
So we should let it only transforms which it can recognize.
We also should recognize the system memory caps in _accept() early, if
the input is not system memory, we just return early.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-25 02:41:21 +00:00
|
|
|
gst_caps_unref (tmp);
|
2016-01-04 09:26:09 +00:00
|
|
|
|
|
|
|
target_mask |= 1 << GST_GL_TEXTURE_TARGET_2D;
|
|
|
|
target_mask |= 1 << GST_GL_TEXTURE_TARGET_RECTANGLE;
|
|
|
|
tmp = _caps_intersect_texture_target (ret, target_mask);
|
|
|
|
gst_caps_unref (ret);
|
|
|
|
ret = tmp;
|
2015-02-02 13:11:06 +00:00
|
|
|
} else {
|
2015-10-28 13:44:26 +00:00
|
|
|
gint i, n;
|
|
|
|
|
2015-12-29 07:16:04 +00:00
|
|
|
ret =
|
|
|
|
_set_caps_features_with_passthrough (caps,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY, passthrough);
|
2015-10-28 13:44:26 +00:00
|
|
|
|
|
|
|
n = gst_caps_get_size (ret);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (ret, i);
|
|
|
|
|
|
|
|
gst_structure_remove_fields (s, "texture-target", NULL);
|
|
|
|
}
|
2015-02-02 13:11:06 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 07:16:04 +00:00
|
|
|
gst_caps_features_free (passthrough);
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static gboolean
|
|
|
|
_raw_data_upload_accept (gpointer impl, GstBuffer * buffer, GstCaps * in_caps,
|
|
|
|
GstCaps * out_caps)
|
|
|
|
{
|
|
|
|
struct RawUpload *raw = impl;
|
2015-07-27 06:36:40 +00:00
|
|
|
GstCapsFeatures *features;
|
2014-11-05 09:18:06 +00:00
|
|
|
|
glupload: make raw manner only consider system memory
The current _raw_data_upload_transform_caps() only simply apply
"memory:GLMemory" to all input caps to transform the output caps.
This is not precise and may cause problem. For example, if the
input caps include:
video/x-raw(memory:DMABuf), width=(int)1920, height=(int)1080, \
interlace-mode=(string)progressive, multiview-mode=(string)mono, \
framerate=(fraction)30/1, drm-format=(string)NV12:0x0100000000000002
it will be changed as
video/x-raw(memory:GLMemory), width=(int)1920, height=(int)1080, \
interlace-mode=(string)progressive, multiview-mode=(string)mono, \
framerate=(fraction)30/1, drm-format=(string)NV12:0x0100000000000002
For GLMemory kind caps, no drm-format should appear.
So we should let it only transforms which it can recognize.
We also should recognize the system memory caps in _accept() early, if
the input is not system memory, we just return early.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
2023-05-25 02:41:21 +00:00
|
|
|
features =
|
|
|
|
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
|
|
|
|
/* Also consider the omited system memory feature cases, such as
|
|
|
|
video/x-raw(meta:GstVideoOverlayComposition) */
|
|
|
|
if (!_filter_caps_with_features (in_caps, features, NULL)) {
|
|
|
|
gst_caps_features_free (features);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gst_caps_features_free (features);
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
features = gst_caps_get_features (out_caps, 0);
|
2015-07-27 06:36:40 +00:00
|
|
|
if (!gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY))
|
|
|
|
return FALSE;
|
2014-11-05 09:18:06 +00:00
|
|
|
|
2015-09-30 03:31:50 +00:00
|
|
|
if (raw->in_frame)
|
|
|
|
_raw_upload_frame_unref (raw->in_frame);
|
2015-07-27 20:58:22 +00:00
|
|
|
raw->in_frame = _raw_upload_frame_new (raw, buffer);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2015-12-16 07:41:06 +00:00
|
|
|
if (raw->params)
|
|
|
|
gst_gl_allocation_params_free ((GstGLAllocationParams *) raw->params);
|
|
|
|
if (!(raw->params =
|
|
|
|
gst_gl_video_allocation_params_new_wrapped_data (raw->upload->context,
|
|
|
|
NULL, &raw->upload->priv->in_info, -1, NULL,
|
2016-06-28 03:51:22 +00:00
|
|
|
GST_GL_TEXTURE_TARGET_2D, 0, NULL, raw->in_frame,
|
2015-12-17 04:23:13 +00:00
|
|
|
(GDestroyNotify) _raw_upload_frame_unref)))
|
2015-12-16 07:41:06 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2015-07-27 20:58:22 +00:00
|
|
|
return (raw->in_frame != NULL);
|
2013-11-14 04:27:52 +00:00
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
static void
|
|
|
|
_raw_data_upload_propose_allocation (gpointer impl, GstQuery * decide_query,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, 0);
|
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static GstGLUploadReturn
|
|
|
|
_raw_data_upload_perform (gpointer impl, GstBuffer * buffer,
|
|
|
|
GstBuffer ** outbuf)
|
2013-11-14 04:27:52 +00:00
|
|
|
{
|
2015-12-16 07:41:06 +00:00
|
|
|
GstGLBaseMemoryAllocator *allocator;
|
2014-11-05 09:18:06 +00:00
|
|
|
struct RawUpload *raw = impl;
|
|
|
|
int i;
|
2015-05-29 16:15:51 +00:00
|
|
|
GstVideoInfo *in_info = &raw->upload->priv->in_info;
|
2015-12-16 07:41:06 +00:00
|
|
|
guint n_mem = GST_VIDEO_INFO_N_PLANES (in_info);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2015-12-16 07:41:06 +00:00
|
|
|
allocator =
|
2015-12-18 02:17:34 +00:00
|
|
|
GST_GL_BASE_MEMORY_ALLOCATOR (gst_gl_memory_allocator_get_default
|
|
|
|
(raw->upload->context));
|
2015-07-14 07:40:32 +00:00
|
|
|
|
2015-07-28 12:59:24 +00:00
|
|
|
/* FIXME Use a buffer pool to cache the generated textures */
|
2015-07-27 19:58:10 +00:00
|
|
|
*outbuf = gst_buffer_new ();
|
2019-09-27 14:10:43 +00:00
|
|
|
raw->params->parent.context = raw->upload->context;
|
|
|
|
if (gst_gl_memory_setup_buffer ((GstGLMemoryAllocator *) allocator, *outbuf,
|
|
|
|
raw->params, NULL, raw->in_frame->frame.data, n_mem)) {
|
2015-12-16 07:41:06 +00:00
|
|
|
|
2019-09-27 14:10:43 +00:00
|
|
|
for (i = 0; i < n_mem; i++)
|
|
|
|
_raw_upload_frame_ref (raw->in_frame);
|
|
|
|
gst_buffer_add_gl_sync_meta (raw->upload->context, *outbuf);
|
|
|
|
} else {
|
|
|
|
GST_ERROR_OBJECT (raw->upload, "Failed to allocate wrapped texture");
|
|
|
|
gst_buffer_unref (*outbuf);
|
2019-11-15 09:06:13 +00:00
|
|
|
gst_object_unref (allocator);
|
2019-09-27 14:10:43 +00:00
|
|
|
return GST_GL_UPLOAD_ERROR;
|
2014-11-05 09:18:06 +00:00
|
|
|
}
|
2015-12-16 07:41:06 +00:00
|
|
|
gst_object_unref (allocator);
|
2015-07-27 20:58:22 +00:00
|
|
|
_raw_upload_frame_unref (raw->in_frame);
|
|
|
|
raw->in_frame = NULL;
|
2019-09-27 14:10:43 +00:00
|
|
|
|
2015-09-30 03:31:50 +00:00
|
|
|
return GST_GL_UPLOAD_DONE;
|
2014-11-05 09:18:06 +00:00
|
|
|
}
|
2013-11-14 04:27:52 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static void
|
|
|
|
_raw_data_upload_free (gpointer impl)
|
|
|
|
{
|
|
|
|
struct RawUpload *raw = impl;
|
2013-11-14 04:27:52 +00:00
|
|
|
|
2015-12-16 07:41:06 +00:00
|
|
|
if (raw->params)
|
|
|
|
gst_gl_allocation_params_free ((GstGLAllocationParams *) raw->params);
|
|
|
|
|
2014-12-25 21:59:42 +00:00
|
|
|
g_free (raw);
|
2014-11-05 09:18:06 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 16:20:09 +00:00
|
|
|
static GstStaticCaps _raw_data_upload_caps =
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_GL_MEMORY_VIDEO_FORMATS_STR));
|
|
|
|
|
2015-01-21 09:17:04 +00:00
|
|
|
static const UploadMethod _raw_data_upload = {
|
2014-11-05 09:18:06 +00:00
|
|
|
"Raw Data",
|
|
|
|
0,
|
2015-04-28 16:20:09 +00:00
|
|
|
&_raw_data_upload_caps,
|
2014-11-05 09:18:06 +00:00
|
|
|
&_raw_data_upload_new,
|
2015-02-02 13:11:06 +00:00
|
|
|
&_raw_data_upload_transform_caps,
|
2014-11-05 09:18:06 +00:00
|
|
|
&_raw_data_upload_accept,
|
2015-02-02 13:11:06 +00:00
|
|
|
&_raw_data_upload_propose_allocation,
|
2014-11-05 09:18:06 +00:00
|
|
|
&_raw_data_upload_perform,
|
|
|
|
&_raw_data_upload_free
|
|
|
|
};
|
|
|
|
|
2017-02-22 12:55:58 +00:00
|
|
|
#if GST_GL_HAVE_VIV_DIRECTVIV
|
|
|
|
#ifndef GL_BGRA_EXT
|
|
|
|
#define GL_BGRA_EXT 0x80E1
|
|
|
|
#endif
|
|
|
|
#ifndef GL_VIV_YV12
|
|
|
|
#define GL_VIV_YV12 0x8FC0
|
|
|
|
#endif
|
|
|
|
#ifndef GL_VIV_NV12
|
|
|
|
#define GL_VIV_NV12 0x8FC1
|
|
|
|
#endif
|
|
|
|
#ifndef GL_VIV_YUY2
|
|
|
|
#define GL_VIV_YUY2 0x8FC2
|
|
|
|
#endif
|
|
|
|
#ifndef GL_VIV_UYVY
|
|
|
|
#define GL_VIV_UYVY 0x8FC3
|
|
|
|
#endif
|
|
|
|
#ifndef GL_VIV_NV21
|
|
|
|
#define GL_VIV_NV21 0x8FC4
|
|
|
|
#endif
|
|
|
|
#ifndef GL_VIV_I420
|
|
|
|
#define GL_VIV_I420 0x8FC5
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct DirectVIVUpload
|
|
|
|
{
|
|
|
|
GstGLUpload *upload;
|
|
|
|
|
|
|
|
GstGLVideoAllocationParams *params;
|
|
|
|
GstBuffer *inbuf, *outbuf;
|
|
|
|
void (*TexDirectVIVMap) (GLenum Target, GLsizei Width, GLsizei Height,
|
|
|
|
GLenum Format, GLvoid ** Logical, const GLuint * Physical);
|
|
|
|
void (*TexDirectInvalidateVIV) (GLenum Target);
|
|
|
|
gboolean loaded_functions;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GST_GL_DIRECTVIV_FORMAT "{RGBA, I420, YV12, NV12, NV21, YUY2, UYVY, BGRA, RGB16}"
|
|
|
|
|
|
|
|
static GstStaticCaps _directviv_upload_caps =
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_GL_DIRECTVIV_FORMAT));
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
_directviv_upload_new (GstGLUpload * upload)
|
|
|
|
{
|
|
|
|
struct DirectVIVUpload *directviv = g_new0 (struct DirectVIVUpload, 1);
|
|
|
|
directviv->upload = upload;
|
|
|
|
directviv->loaded_functions = FALSE;
|
|
|
|
|
|
|
|
return directviv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
_directviv_upload_transform_caps (gpointer impl, GstGLContext * context,
|
|
|
|
GstPadDirection direction, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstCapsFeatures *passthrough =
|
|
|
|
gst_caps_features_from_string
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION);
|
|
|
|
GstCaps *ret;
|
|
|
|
|
|
|
|
if (direction == GST_PAD_SINK) {
|
|
|
|
GstCaps *tmp;
|
|
|
|
|
|
|
|
ret =
|
|
|
|
_set_caps_features_with_passthrough (caps,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY, passthrough);
|
|
|
|
|
|
|
|
gst_caps_set_simple (ret, "format", G_TYPE_STRING, "RGBA", NULL);
|
|
|
|
tmp = _caps_intersect_texture_target (ret, 1 << GST_GL_TEXTURE_TARGET_2D);
|
|
|
|
gst_caps_unref (ret);
|
|
|
|
ret = tmp;
|
|
|
|
} else {
|
2022-07-07 13:54:44 +00:00
|
|
|
ret = gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
2017-02-22 12:55:58 +00:00
|
|
|
(GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY, GST_GL_DIRECTVIV_FORMAT));
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_features_free (passthrough);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
_directviv_upload_load_functions_gl_thread (GstGLContext * context,
|
|
|
|
struct DirectVIVUpload *directviv)
|
|
|
|
{
|
|
|
|
directviv->TexDirectVIVMap =
|
|
|
|
gst_gl_context_get_proc_address (context, "glTexDirectVIVMap");
|
|
|
|
directviv->TexDirectInvalidateVIV =
|
|
|
|
gst_gl_context_get_proc_address (context, "glTexDirectInvalidateVIV");
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_directviv_upload_accept (gpointer impl, GstBuffer * buffer, GstCaps * in_caps,
|
|
|
|
GstCaps * out_caps)
|
|
|
|
{
|
|
|
|
struct DirectVIVUpload *directviv = impl;
|
|
|
|
GstCapsFeatures *features;
|
|
|
|
guint n_mem;
|
|
|
|
GstMemory *mem;
|
|
|
|
|
|
|
|
if (!directviv->loaded_functions && (!directviv->TexDirectInvalidateVIV ||
|
|
|
|
!directviv->TexDirectVIVMap)) {
|
|
|
|
gst_gl_context_thread_add (directviv->upload->context,
|
|
|
|
(GstGLContextThreadFunc) _directviv_upload_load_functions_gl_thread,
|
|
|
|
directviv);
|
|
|
|
directviv->loaded_functions = TRUE;
|
|
|
|
}
|
|
|
|
if (!directviv->TexDirectInvalidateVIV || !directviv->TexDirectVIVMap)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
features = gst_caps_get_features (out_caps, 0);
|
|
|
|
if (!gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (directviv->params)
|
|
|
|
gst_gl_allocation_params_free ((GstGLAllocationParams *) directviv->params);
|
|
|
|
if (!(directviv->params =
|
|
|
|
gst_gl_video_allocation_params_new (directviv->upload->context, NULL,
|
|
|
|
&directviv->upload->priv->out_info, -1, NULL,
|
|
|
|
GST_GL_TEXTURE_TARGET_2D, GST_VIDEO_GL_TEXTURE_TYPE_RGBA)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* We only support a single memory per buffer at this point */
|
|
|
|
n_mem = gst_buffer_n_memory (buffer);
|
|
|
|
if (n_mem == 1) {
|
|
|
|
mem = gst_buffer_peek_memory (buffer, 0);
|
|
|
|
} else {
|
|
|
|
mem = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_mem == 1 && mem && gst_is_phys_memory (mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_directviv_upload_propose_allocation (gpointer impl, GstQuery * decide_query,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum
|
|
|
|
_directviv_upload_video_format_to_gl_format (GstVideoFormat format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
return GL_VIV_I420;
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
return GL_VIV_YV12;
|
|
|
|
case GST_VIDEO_FORMAT_NV12:
|
|
|
|
return GL_VIV_NV12;
|
|
|
|
case GST_VIDEO_FORMAT_NV21:
|
|
|
|
return GL_VIV_NV21;
|
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
return GL_VIV_YUY2;
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
|
|
|
return GL_VIV_UYVY;
|
|
|
|
case GST_VIDEO_FORMAT_RGB16:
|
|
|
|
return GL_RGB565;
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
return GL_RGBA;
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
return GL_BGRA_EXT;
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
|
|
return GL_RGBA;
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
return GL_BGRA_EXT;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMemory *memory;
|
|
|
|
GstMapInfo map;
|
|
|
|
guintptr phys_addr;
|
|
|
|
} DirectVIVUnmapData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_directviv_memory_unmap (DirectVIVUnmapData * data)
|
|
|
|
{
|
|
|
|
gst_memory_unmap (data->memory, &data->map);
|
|
|
|
gst_memory_unref (data->memory);
|
|
|
|
gst_buffer_unref (data->buffer);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_directviv_upload_perform_gl_thread (GstGLContext * context,
|
|
|
|
struct DirectVIVUpload *directviv)
|
|
|
|
{
|
|
|
|
static GQuark directviv_unmap_quark = 0;
|
|
|
|
GstGLMemoryAllocator *allocator;
|
|
|
|
GstMemory *in_mem;
|
|
|
|
GstGLMemory *out_gl_mem;
|
|
|
|
GstVideoInfo *in_info;
|
|
|
|
DirectVIVUnmapData *unmap_data;
|
|
|
|
GstVideoMeta *vmeta;
|
|
|
|
gint width, height, gl_format;
|
|
|
|
const GstGLFuncs *gl;
|
|
|
|
|
|
|
|
if (!directviv_unmap_quark)
|
|
|
|
directviv_unmap_quark = g_quark_from_static_string ("GstGLDirectVIVUnmap");
|
|
|
|
|
|
|
|
gl = context->gl_vtable;
|
|
|
|
|
|
|
|
g_assert (gst_buffer_n_memory (directviv->inbuf) == 1);
|
|
|
|
in_info = &directviv->upload->priv->in_info;
|
|
|
|
in_mem = gst_buffer_peek_memory (directviv->inbuf, 0);
|
|
|
|
unmap_data = g_new0 (DirectVIVUnmapData, 1);
|
|
|
|
if (!gst_memory_map (in_mem, &unmap_data->map, GST_MAP_READ)) {
|
|
|
|
g_free (unmap_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unmap_data->phys_addr = gst_phys_memory_get_phys_addr (in_mem);
|
|
|
|
if (!unmap_data->phys_addr) {
|
|
|
|
gst_memory_unmap (in_mem, &unmap_data->map);
|
|
|
|
g_free (unmap_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unmap_data->memory = gst_memory_ref (in_mem);
|
|
|
|
unmap_data->buffer = gst_buffer_ref (directviv->inbuf);
|
|
|
|
|
|
|
|
allocator =
|
|
|
|
GST_GL_MEMORY_ALLOCATOR (gst_allocator_find
|
|
|
|
(GST_GL_MEMORY_PBO_ALLOCATOR_NAME));
|
|
|
|
|
|
|
|
/* FIXME: buffer pool */
|
|
|
|
directviv->outbuf = gst_buffer_new ();
|
|
|
|
gst_gl_memory_setup_buffer (allocator, directviv->outbuf, directviv->params,
|
|
|
|
NULL, NULL, 0);
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
|
|
|
|
out_gl_mem = (GstGLMemory *) gst_buffer_peek_memory (directviv->outbuf, 0);
|
|
|
|
|
|
|
|
/* Need to keep the input memory and buffer mapped and valid until
|
|
|
|
* the GL memory is not used anymore */
|
|
|
|
gst_mini_object_set_qdata ((GstMiniObject *) out_gl_mem,
|
|
|
|
directviv_unmap_quark, unmap_data,
|
|
|
|
(GDestroyNotify) _directviv_memory_unmap);
|
|
|
|
gst_buffer_add_parent_buffer_meta (directviv->outbuf, directviv->inbuf);
|
|
|
|
|
|
|
|
/* width/height need to compensate for stride/padding */
|
|
|
|
vmeta = gst_buffer_get_video_meta (directviv->inbuf);
|
|
|
|
if (vmeta) {
|
|
|
|
width = vmeta->stride[0];
|
2017-06-12 19:29:01 +00:00
|
|
|
if (GST_VIDEO_INFO_N_PLANES (in_info) == 1)
|
|
|
|
height = gst_memory_get_sizes (in_mem, NULL, NULL) / width;
|
|
|
|
else
|
|
|
|
height = vmeta->offset[1] / width;
|
2017-02-22 12:55:58 +00:00
|
|
|
} else {
|
|
|
|
width = GST_VIDEO_INFO_PLANE_STRIDE (in_info, 0);
|
2017-06-12 19:29:01 +00:00
|
|
|
if (GST_VIDEO_INFO_N_PLANES (in_info) == 1)
|
|
|
|
height = gst_memory_get_sizes (in_mem, NULL, NULL) / width;
|
|
|
|
else
|
|
|
|
height = GST_VIDEO_INFO_PLANE_OFFSET (in_info, 1) / width;
|
2017-02-22 12:55:58 +00:00
|
|
|
}
|
|
|
|
width /= GST_VIDEO_INFO_COMP_PSTRIDE (in_info, 0);
|
|
|
|
|
|
|
|
gl_format =
|
|
|
|
_directviv_upload_video_format_to_gl_format (GST_VIDEO_INFO_FORMAT
|
|
|
|
(in_info));
|
|
|
|
|
|
|
|
gl->BindTexture (GL_TEXTURE_2D, out_gl_mem->tex_id);
|
|
|
|
directviv->TexDirectVIVMap (GL_TEXTURE_2D, width, height,
|
|
|
|
gl_format, (void **) &unmap_data->map.data, &unmap_data->phys_addr);
|
|
|
|
directviv->TexDirectInvalidateVIV (GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstGLUploadReturn
|
|
|
|
_directviv_upload_perform (gpointer impl, GstBuffer * buffer,
|
|
|
|
GstBuffer ** outbuf)
|
|
|
|
{
|
|
|
|
struct DirectVIVUpload *directviv = impl;
|
|
|
|
|
|
|
|
directviv->inbuf = buffer;
|
|
|
|
directviv->outbuf = NULL;
|
|
|
|
gst_gl_context_thread_add (directviv->upload->context,
|
|
|
|
(GstGLContextThreadFunc) _directviv_upload_perform_gl_thread, directviv);
|
|
|
|
directviv->inbuf = NULL;
|
|
|
|
|
|
|
|
if (!directviv->outbuf)
|
|
|
|
return GST_GL_UPLOAD_ERROR;
|
|
|
|
|
|
|
|
*outbuf = directviv->outbuf;
|
|
|
|
directviv->outbuf = NULL;
|
|
|
|
|
|
|
|
return GST_GL_UPLOAD_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_directviv_upload_free (gpointer impl)
|
|
|
|
{
|
|
|
|
struct DirectVIVUpload *directviv = impl;
|
|
|
|
|
|
|
|
if (directviv->params)
|
|
|
|
gst_gl_allocation_params_free ((GstGLAllocationParams *) directviv->params);
|
|
|
|
|
|
|
|
g_free (impl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const UploadMethod _directviv_upload = {
|
|
|
|
"DirectVIV",
|
|
|
|
0,
|
|
|
|
&_directviv_upload_caps,
|
|
|
|
&_directviv_upload_new,
|
|
|
|
&_directviv_upload_transform_caps,
|
|
|
|
&_directviv_upload_accept,
|
|
|
|
&_directviv_upload_propose_allocation,
|
|
|
|
&_directviv_upload_perform,
|
|
|
|
&_directviv_upload_free
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GST_GL_HAVE_VIV_DIRECTVIV */
|
|
|
|
|
2021-02-26 07:48:09 +00:00
|
|
|
#if defined(HAVE_NVMM)
|
|
|
|
#include "nvbuf_utils.h"
|
|
|
|
|
|
|
|
struct NVMMUpload
|
|
|
|
{
|
|
|
|
GstGLUpload *upload;
|
|
|
|
|
|
|
|
GstGLVideoAllocationParams *params;
|
|
|
|
guint n_mem;
|
|
|
|
|
|
|
|
GstGLTextureTarget target;
|
|
|
|
GstVideoInfo out_info;
|
|
|
|
/* only used for pointer comparison */
|
|
|
|
gpointer out_caps;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GST_CAPS_FEATURE_MEMORY_NVMM "memory:NVMM"
|
|
|
|
|
|
|
|
/* FIXME: other formats? */
|
|
|
|
static GstStaticCaps _nvmm_upload_caps =
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_MEMORY_NVMM,
|
|
|
|
"RGBA"));
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
_nvmm_upload_new (GstGLUpload * upload)
|
|
|
|
{
|
|
|
|
struct NVMMUpload *nvmm = g_new0 (struct NVMMUpload, 1);
|
|
|
|
nvmm->upload = upload;
|
|
|
|
nvmm->target = GST_GL_TEXTURE_TARGET_EXTERNAL_OES;
|
|
|
|
return nvmm;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
_nvmm_upload_transform_caps (gpointer impl, GstGLContext * context,
|
|
|
|
GstPadDirection direction, GstCaps * caps)
|
|
|
|
{
|
|
|
|
struct NVMMUpload *nvmm = impl;
|
|
|
|
GstCapsFeatures *passthrough;
|
|
|
|
GstCaps *ret;
|
|
|
|
|
|
|
|
if (context) {
|
|
|
|
const GstGLFuncs *gl = context->gl_vtable;
|
|
|
|
|
|
|
|
if (!gl->EGLImageTargetTexture2D)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Don't propose NVMM caps feature unless it can be supported */
|
|
|
|
if (gst_gl_context_get_gl_platform (context) != GST_GL_PLATFORM_EGL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!gst_gl_context_check_feature (context, "EGL_KHR_image_base"))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
passthrough = gst_caps_features_from_string
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION);
|
|
|
|
|
|
|
|
if (direction == GST_PAD_SINK) {
|
|
|
|
GstCaps *tmp;
|
|
|
|
|
|
|
|
ret =
|
|
|
|
_set_caps_features_with_passthrough (caps,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY, passthrough);
|
|
|
|
|
|
|
|
tmp =
|
|
|
|
_caps_intersect_texture_target (ret,
|
|
|
|
1 << GST_GL_TEXTURE_TARGET_EXTERNAL_OES);
|
|
|
|
gst_caps_unref (ret);
|
|
|
|
ret = tmp;
|
|
|
|
} else {
|
|
|
|
gint i, n;
|
|
|
|
|
|
|
|
ret =
|
|
|
|
_set_caps_features_with_passthrough (caps,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_NVMM, passthrough);
|
|
|
|
|
|
|
|
n = gst_caps_get_size (ret);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (ret, i);
|
|
|
|
|
|
|
|
gst_structure_remove_fields (s, "texture-target", NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_features_free (passthrough);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (nvmm->upload, "transformed %" GST_PTR_FORMAT " into %"
|
|
|
|
GST_PTR_FORMAT, caps, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_nvmm_upload_accept (gpointer impl, GstBuffer * buffer, GstCaps * in_caps,
|
|
|
|
GstCaps * out_caps)
|
|
|
|
{
|
|
|
|
struct NVMMUpload *nvmm = impl;
|
|
|
|
GstVideoInfo *in_info = &nvmm->upload->priv->in_info;
|
|
|
|
GstVideoInfo *out_info = &nvmm->out_info;
|
|
|
|
GstVideoMeta *meta;
|
|
|
|
GstMapInfo in_map_info = GST_MAP_INFO_INIT;
|
|
|
|
guint n_mem;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
n_mem = gst_buffer_n_memory (buffer);
|
|
|
|
if (n_mem != 1) {
|
|
|
|
GST_DEBUG_OBJECT (nvmm->upload, "NVMM uploader only supports "
|
|
|
|
"1 memory, not %u", n_mem);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta = gst_buffer_get_video_meta (buffer);
|
|
|
|
|
|
|
|
if (!nvmm->upload->context->gl_vtable->EGLImageTargetTexture2D)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* NVMM upload is only supported with EGL contexts. */
|
|
|
|
if (gst_gl_context_get_gl_platform (nvmm->upload->context) !=
|
|
|
|
GST_GL_PLATFORM_EGL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!gst_gl_context_check_feature (nvmm->upload->context,
|
|
|
|
"EGL_KHR_image_base"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!gst_buffer_map (buffer, &in_map_info, GST_MAP_READ)) {
|
|
|
|
GST_DEBUG_OBJECT (nvmm->upload, "Failed to map readonly NvBuffer");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (in_map_info.size != NvBufferGetSize ()) {
|
|
|
|
GST_DEBUG_OBJECT (nvmm->upload, "Memory size (%" G_GSIZE_FORMAT ") is "
|
|
|
|
"not the same as what NvBuffer advertises (%u)", in_map_info.size,
|
|
|
|
NvBufferGetSize ());
|
|
|
|
gst_buffer_unmap (buffer, &in_map_info);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gst_buffer_unmap (buffer, &in_map_info);
|
|
|
|
|
|
|
|
/* Update video info based on video meta */
|
|
|
|
if (meta) {
|
|
|
|
in_info->width = meta->width;
|
|
|
|
in_info->height = meta->height;
|
|
|
|
|
|
|
|
for (i = 0; i < meta->n_planes; i++) {
|
|
|
|
in_info->offset[i] = meta->offset[i];
|
|
|
|
in_info->stride[i] = meta->stride[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (out_caps != nvmm->out_caps) {
|
|
|
|
nvmm->out_caps = out_caps;
|
|
|
|
if (!gst_video_info_from_caps (out_info, out_caps))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvmm->params)
|
|
|
|
gst_gl_allocation_params_free ((GstGLAllocationParams *) nvmm->params);
|
|
|
|
if (!(nvmm->params =
|
|
|
|
gst_gl_video_allocation_params_new_wrapped_gl_handle (nvmm->
|
|
|
|
upload->context, NULL, out_info, -1, NULL, nvmm->target, 0, NULL,
|
|
|
|
NULL, NULL))) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_nvmm_upload_propose_allocation (gpointer impl, GstQuery * decide_query,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
/* nothing to do for now. */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_egl_image_mem_unref (GstEGLImage * image, GstMemory * mem)
|
|
|
|
{
|
|
|
|
GstGLDisplayEGL *egl_display = NULL;
|
|
|
|
EGLDisplay display;
|
|
|
|
|
|
|
|
egl_display = gst_gl_display_egl_from_gl_display (image->context->display);
|
|
|
|
if (!egl_display) {
|
|
|
|
GST_ERROR ("Could not retrieve GstGLDisplayEGL from GstGLDisplay");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
display =
|
|
|
|
(EGLDisplay) gst_gl_display_get_handle (GST_GL_DISPLAY (egl_display));
|
|
|
|
|
|
|
|
if (NvDestroyEGLImage (display, image->image)) {
|
|
|
|
GST_ERROR ("Failed to destroy EGLImage %p from NvBuffer", image->image);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("destroyed EGLImage %p from NvBuffer", image->image);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_memory_unref (mem);
|
|
|
|
gst_object_unref (egl_display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
payload_type_to_string (NvBufferPayloadType ptype)
|
|
|
|
{
|
|
|
|
switch (ptype) {
|
|
|
|
case NvBufferPayload_SurfArray:
|
|
|
|
return "SurfArray";
|
|
|
|
case NvBufferPayload_MemHandle:
|
|
|
|
return "MemHandle";
|
|
|
|
default:
|
|
|
|
return "<unknown>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
pixel_format_to_string (NvBufferColorFormat fmt)
|
|
|
|
{
|
|
|
|
switch (fmt) {
|
|
|
|
case NvBufferColorFormat_YUV420:
|
|
|
|
return "YUV420";
|
|
|
|
case NvBufferColorFormat_YVU420:
|
|
|
|
return "YVU420";
|
|
|
|
case NvBufferColorFormat_YUV422:
|
|
|
|
return "YUV422";
|
|
|
|
case NvBufferColorFormat_YUV420_ER:
|
|
|
|
return "YUV420_ER";
|
|
|
|
case NvBufferColorFormat_YVU420_ER:
|
|
|
|
return "YVU420_ER";
|
|
|
|
case NvBufferColorFormat_NV12:
|
|
|
|
return "NV12";
|
|
|
|
case NvBufferColorFormat_NV12_ER:
|
|
|
|
return "NV12_ER";
|
|
|
|
case NvBufferColorFormat_NV21:
|
|
|
|
return "NV21";
|
|
|
|
case NvBufferColorFormat_NV21_ER:
|
|
|
|
return "NV21_ER";
|
|
|
|
case NvBufferColorFormat_UYVY:
|
|
|
|
return "UYVY";
|
|
|
|
case NvBufferColorFormat_UYVY_ER:
|
|
|
|
return "UYVY_ER";
|
|
|
|
case NvBufferColorFormat_VYUY:
|
|
|
|
return "VYUY";
|
|
|
|
case NvBufferColorFormat_VYUY_ER:
|
|
|
|
return "VYUY_ER";
|
|
|
|
case NvBufferColorFormat_YUYV:
|
|
|
|
return "YUYV";
|
|
|
|
case NvBufferColorFormat_YUYV_ER:
|
|
|
|
return "YUYV_ER";
|
|
|
|
case NvBufferColorFormat_YVYU:
|
|
|
|
return "YVYU";
|
|
|
|
case NvBufferColorFormat_YVYU_ER:
|
|
|
|
return "YVYU_ER";
|
|
|
|
case NvBufferColorFormat_ABGR32:
|
|
|
|
return "ABGR32";
|
|
|
|
case NvBufferColorFormat_XRGB32:
|
|
|
|
return "XRGB32";
|
|
|
|
case NvBufferColorFormat_ARGB32:
|
|
|
|
return "ARGB32";
|
|
|
|
case NvBufferColorFormat_NV12_10LE:
|
|
|
|
return "NV12_10LE";
|
|
|
|
case NvBufferColorFormat_NV12_10LE_709:
|
|
|
|
return "NV12_10LE_709";
|
|
|
|
case NvBufferColorFormat_NV12_10LE_709_ER:
|
|
|
|
return "NV12_10LE_709_ER";
|
|
|
|
case NvBufferColorFormat_NV12_10LE_2020:
|
|
|
|
return "NV12_2020";
|
|
|
|
case NvBufferColorFormat_NV21_10LE:
|
|
|
|
return "NV21_10LE";
|
|
|
|
case NvBufferColorFormat_NV12_12LE:
|
|
|
|
return "NV12_12LE";
|
|
|
|
case NvBufferColorFormat_NV12_12LE_2020:
|
|
|
|
return "NV12_12LE_2020";
|
|
|
|
case NvBufferColorFormat_NV21_12LE:
|
|
|
|
return "NV21_12LE";
|
|
|
|
case NvBufferColorFormat_YUV420_709:
|
|
|
|
return "YUV420_709";
|
|
|
|
case NvBufferColorFormat_YUV420_709_ER:
|
|
|
|
return "YUV420_709_ER";
|
|
|
|
case NvBufferColorFormat_NV12_709:
|
|
|
|
return "NV12_709";
|
|
|
|
case NvBufferColorFormat_NV12_709_ER:
|
|
|
|
return "NV12_709_ER";
|
|
|
|
case NvBufferColorFormat_YUV420_2020:
|
|
|
|
return "YUV420_2020";
|
|
|
|
case NvBufferColorFormat_NV12_2020:
|
|
|
|
return "NV12_2020";
|
|
|
|
case NvBufferColorFormat_SignedR16G16:
|
|
|
|
return "SignedR16G16";
|
|
|
|
case NvBufferColorFormat_A32:
|
|
|
|
return "A32";
|
|
|
|
case NvBufferColorFormat_YUV444:
|
|
|
|
return "YUV444";
|
|
|
|
case NvBufferColorFormat_GRAY8:
|
|
|
|
return "GRAY8";
|
|
|
|
case NvBufferColorFormat_NV16:
|
|
|
|
return "NV16";
|
|
|
|
case NvBufferColorFormat_NV16_10LE:
|
|
|
|
return "NV16_10LE";
|
|
|
|
case NvBufferColorFormat_NV24:
|
|
|
|
return "NV24";
|
|
|
|
case NvBufferColorFormat_NV16_ER:
|
|
|
|
return "NV16_ER";
|
|
|
|
case NvBufferColorFormat_NV24_ER:
|
|
|
|
return "NV24_ER";
|
|
|
|
case NvBufferColorFormat_NV16_709:
|
|
|
|
return "NV16_709";
|
|
|
|
case NvBufferColorFormat_NV24_709:
|
|
|
|
return "NV24_709";
|
|
|
|
case NvBufferColorFormat_NV16_709_ER:
|
|
|
|
return "NV16_709_ER";
|
|
|
|
case NvBufferColorFormat_NV24_709_ER:
|
|
|
|
return "NV24_709_ER";
|
|
|
|
case NvBufferColorFormat_NV24_10LE_709:
|
|
|
|
return "NV24_10LE_709";
|
|
|
|
case NvBufferColorFormat_NV24_10LE_709_ER:
|
|
|
|
return "NV24_10LE_709_ER";
|
|
|
|
case NvBufferColorFormat_NV24_10LE_2020:
|
|
|
|
return "NV24_10LE_2020";
|
|
|
|
case NvBufferColorFormat_NV24_12LE_2020:
|
|
|
|
return "NV24_12LE_2020";
|
|
|
|
case NvBufferColorFormat_RGBA_10_10_10_2_709:
|
|
|
|
return "RGBA_10_10_10_2_709";
|
|
|
|
case NvBufferColorFormat_RGBA_10_10_10_2_2020:
|
|
|
|
return "RGBA_10_10_10_2_2020";
|
|
|
|
case NvBufferColorFormat_BGRA_10_10_10_2_709:
|
|
|
|
return "BGRA_10_10_10_2_709";
|
|
|
|
case NvBufferColorFormat_BGRA_10_10_10_2_2020:
|
|
|
|
return "BGRA_10_10_10_2_2020";
|
|
|
|
case NvBufferColorFormat_Invalid:
|
|
|
|
return "Invalid";
|
|
|
|
default:
|
|
|
|
return "<unknown>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_nv_buf_params (GstObject * debug_object, NvBufferParamsEx * params)
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (debug_object, "nvbuffer fd: %u size %i nv_buffer: %p of "
|
|
|
|
"size %u, payload: (0x%x) %s, pixel format: (0x%x) %s, n_planes: %u, "
|
|
|
|
"plane 0 { wxh: %ux%u, pitch: %u, offset: %u, psize: %u, layout: %u } "
|
|
|
|
"plane 1 { wxh: %ux%u, pitch: %u, offset: %u, psize: %u, layout: %u } "
|
|
|
|
"plane 2 { wxh: %ux%u, pitch: %u, offset: %u, psize: %u, layout: %u }",
|
|
|
|
params->params.dmabuf_fd, params->params.memsize,
|
|
|
|
params->params.nv_buffer, params->params.nv_buffer_size,
|
|
|
|
params->params.payloadType,
|
|
|
|
payload_type_to_string (params->params.payloadType),
|
|
|
|
params->params.pixel_format,
|
|
|
|
pixel_format_to_string (params->params.pixel_format),
|
|
|
|
params->params.num_planes, params->params.width[0],
|
|
|
|
params->params.height[0], params->params.pitch[0],
|
|
|
|
params->params.offset[0], params->params.psize[0],
|
|
|
|
params->params.offset[0], params->params.width[1],
|
|
|
|
params->params.height[1], params->params.pitch[1],
|
|
|
|
params->params.offset[1], params->params.psize[1],
|
|
|
|
params->params.offset[1], params->params.width[2],
|
|
|
|
params->params.height[2], params->params.pitch[2],
|
|
|
|
params->params.offset[2], params->params.psize[2],
|
|
|
|
params->params.offset[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstGLUploadReturn
|
|
|
|
_nvmm_upload_perform (gpointer impl, GstBuffer * buffer, GstBuffer ** outbuf)
|
|
|
|
{
|
|
|
|
struct NVMMUpload *nvmm = impl;
|
|
|
|
GstGLMemoryAllocator *allocator = NULL;
|
|
|
|
GstMapInfo in_map_info = GST_MAP_INFO_INIT;
|
|
|
|
GstGLDisplayEGL *egl_display = NULL;
|
|
|
|
GstEGLImage *eglimage = NULL;
|
|
|
|
EGLDisplay display = EGL_NO_DISPLAY;
|
|
|
|
EGLImageKHR image = EGL_NO_IMAGE;
|
|
|
|
int in_dmabuf_fd;
|
|
|
|
NvBufferParamsEx params = { 0, };
|
|
|
|
GstGLUploadReturn ret = GST_GL_UPLOAD_ERROR;
|
|
|
|
|
|
|
|
if (!gst_buffer_map (buffer, &in_map_info, GST_MAP_READ)) {
|
|
|
|
GST_DEBUG_OBJECT (nvmm->upload, "Failed to map readonly NvBuffer");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ExtractFdFromNvBuffer (in_map_info.data, &in_dmabuf_fd)) {
|
|
|
|
GST_DEBUG_OBJECT (nvmm->upload, "Failed to extract fd from NvBuffer");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (NvBufferGetParamsEx (in_dmabuf_fd, ¶ms)) {
|
|
|
|
GST_WARNING_OBJECT (nvmm->upload, "Failed to get NvBuffer params");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
dump_nv_buf_params ((GstObject *) nvmm->upload, ¶ms);
|
|
|
|
|
|
|
|
egl_display =
|
|
|
|
gst_gl_display_egl_from_gl_display (nvmm->upload->context->display);
|
|
|
|
if (!egl_display) {
|
|
|
|
GST_WARNING ("Failed to retrieve GstGLDisplayEGL from GstGLDisplay");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
display =
|
|
|
|
(EGLDisplay) gst_gl_display_get_handle (GST_GL_DISPLAY (egl_display));
|
|
|
|
|
|
|
|
image = NvEGLImageFromFd (display, in_dmabuf_fd);
|
|
|
|
if (!image) {
|
|
|
|
GST_DEBUG_OBJECT (nvmm->upload, "Failed construct EGLImage "
|
|
|
|
"from NvBuffer fd %i", in_dmabuf_fd);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (nvmm->upload, "constructed EGLImage %p "
|
|
|
|
"from NvBuffer fd %i", image, in_dmabuf_fd);
|
|
|
|
|
|
|
|
eglimage = gst_egl_image_new_wrapped (nvmm->upload->context, image,
|
|
|
|
GST_GL_RGBA, gst_memory_ref (in_map_info.memory),
|
|
|
|
(GstEGLImageDestroyNotify) _egl_image_mem_unref);
|
|
|
|
if (!eglimage) {
|
|
|
|
GST_WARNING_OBJECT (nvmm->upload, "Failed to wrap constructed "
|
|
|
|
"EGLImage from NvBuffer");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_buffer_unmap (buffer, &in_map_info);
|
|
|
|
in_map_info = (GstMapInfo) GST_MAP_INFO_INIT;
|
|
|
|
|
|
|
|
allocator =
|
|
|
|
GST_GL_MEMORY_ALLOCATOR (gst_allocator_find
|
|
|
|
(GST_GL_MEMORY_EGL_ALLOCATOR_NAME));
|
|
|
|
|
|
|
|
/* TODO: buffer pool */
|
|
|
|
*outbuf = gst_buffer_new ();
|
|
|
|
if (!gst_gl_memory_setup_buffer (allocator, *outbuf, nvmm->params,
|
|
|
|
NULL, (gpointer *) & eglimage, 1)) {
|
|
|
|
GST_WARNING_OBJECT (nvmm->upload, "Failed to setup "
|
|
|
|
"NVMM -> EGLImage buffer");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
gst_egl_image_unref (eglimage);
|
|
|
|
|
|
|
|
gst_buffer_add_parent_buffer_meta (*outbuf, buffer);
|
|
|
|
|
|
|
|
/* TODO: NvBuffer has some sync functions that may be more useful here */
|
|
|
|
{
|
|
|
|
GstGLSyncMeta *sync_meta;
|
|
|
|
|
|
|
|
sync_meta = gst_buffer_add_gl_sync_meta (nvmm->upload->context, *outbuf);
|
|
|
|
if (sync_meta) {
|
|
|
|
gst_gl_sync_meta_set_sync_point (sync_meta, nvmm->upload->context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_GL_UPLOAD_DONE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (in_map_info.memory)
|
|
|
|
gst_buffer_unmap (buffer, &in_map_info);
|
|
|
|
|
|
|
|
gst_clear_object (&egl_display);
|
|
|
|
gst_clear_object (&allocator);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_nvmm_upload_free (gpointer impl)
|
|
|
|
{
|
|
|
|
struct NVMMUpload *nvmm = impl;
|
|
|
|
|
|
|
|
if (nvmm->params)
|
|
|
|
gst_gl_allocation_params_free ((GstGLAllocationParams *) nvmm->params);
|
|
|
|
|
|
|
|
g_free (impl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const UploadMethod _nvmm_upload = {
|
|
|
|
"NVMM",
|
|
|
|
0,
|
|
|
|
&_nvmm_upload_caps,
|
|
|
|
&_nvmm_upload_new,
|
|
|
|
&_nvmm_upload_transform_caps,
|
|
|
|
&_nvmm_upload_accept,
|
|
|
|
&_nvmm_upload_propose_allocation,
|
|
|
|
&_nvmm_upload_perform,
|
|
|
|
&_nvmm_upload_free
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* HAVE_NVMM */
|
|
|
|
|
2015-01-21 09:17:04 +00:00
|
|
|
static const UploadMethod *upload_methods[] = { &_gl_memory_upload,
|
2015-11-13 16:24:30 +00:00
|
|
|
#if GST_GL_HAVE_DMABUF
|
2018-07-05 08:17:27 +00:00
|
|
|
&_direct_dma_buf_upload,
|
2020-02-18 12:46:08 +00:00
|
|
|
&_direct_dma_buf_external_upload,
|
2015-11-13 16:24:30 +00:00
|
|
|
&_dma_buf_upload,
|
2017-02-22 12:55:58 +00:00
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_VIV_DIRECTVIV
|
|
|
|
&_directviv_upload,
|
2014-11-05 09:18:06 +00:00
|
|
|
#endif
|
2021-02-26 07:48:09 +00:00
|
|
|
#if defined(HAVE_NVMM)
|
|
|
|
&_nvmm_upload,
|
|
|
|
#endif /* HAVE_NVMM */
|
2022-07-07 13:40:22 +00:00
|
|
|
&_upload_meta_upload,
|
|
|
|
/* Raw data must always be last / least preferred */
|
|
|
|
&_raw_data_upload
|
2014-11-05 09:18:06 +00:00
|
|
|
};
|
|
|
|
|
2015-04-28 10:11:07 +00:00
|
|
|
static GMutex upload_global_lock;
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_gl_upload_get_input_template_caps (void)
|
|
|
|
{
|
|
|
|
GstCaps *ret = NULL;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_mutex_lock (&upload_global_lock);
|
|
|
|
|
|
|
|
/* FIXME: cache this and invalidate on changes to upload_methods */
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (upload_methods); i++) {
|
|
|
|
GstCaps *template =
|
2015-04-28 16:20:09 +00:00
|
|
|
gst_static_caps_get (upload_methods[i]->input_template_caps);
|
2015-04-28 10:11:07 +00:00
|
|
|
ret = ret == NULL ? template : gst_caps_merge (ret, template);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gst_caps_simplify (ret);
|
2015-06-18 03:43:50 +00:00
|
|
|
ret = gst_gl_overlay_compositor_add_caps (ret);
|
2015-04-28 10:11:07 +00:00
|
|
|
g_mutex_unlock (&upload_global_lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static void
|
|
|
|
gst_gl_upload_class_init (GstGLUploadClass * klass)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (klass)->finalize = gst_gl_upload_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_upload_init (GstGLUpload * upload)
|
|
|
|
{
|
2018-06-23 19:33:16 +00:00
|
|
|
upload->priv = gst_gl_upload_get_instance_private (upload);
|
2013-11-14 04:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-05 09:18:06 +00:00
|
|
|
* gst_gl_upload_new:
|
|
|
|
* @context: a #GstGLContext
|
2013-11-14 04:27:52 +00:00
|
|
|
*
|
2017-05-15 17:31:31 +00:00
|
|
|
* Returns: (transfer full): a new #GstGLUpload object
|
2013-11-14 04:27:52 +00:00
|
|
|
*/
|
2014-11-05 09:18:06 +00:00
|
|
|
GstGLUpload *
|
|
|
|
gst_gl_upload_new (GstGLContext * context)
|
2013-11-14 04:27:52 +00:00
|
|
|
{
|
2014-11-05 09:18:06 +00:00
|
|
|
GstGLUpload *upload = g_object_new (GST_TYPE_GL_UPLOAD, NULL);
|
2015-02-02 13:11:06 +00:00
|
|
|
gint i, n;
|
2013-11-14 04:27:52 +00:00
|
|
|
|
2017-05-15 17:31:31 +00:00
|
|
|
gst_object_ref_sink (upload);
|
|
|
|
|
2016-08-22 07:18:27 +00:00
|
|
|
if (context)
|
|
|
|
gst_gl_upload_set_context (upload, context);
|
|
|
|
else
|
|
|
|
upload->context = NULL;
|
2013-11-14 04:27:52 +00:00
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
n = G_N_ELEMENTS (upload_methods);
|
|
|
|
upload->priv->upload_impl = g_malloc (sizeof (gpointer) * n);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
upload->priv->upload_impl[i] = upload_methods[i]->new (upload);
|
|
|
|
}
|
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_DEBUG_OBJECT (upload, "Created new GLUpload for context %" GST_PTR_FORMAT,
|
|
|
|
context);
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
return upload;
|
|
|
|
}
|
|
|
|
|
2016-08-22 07:18:27 +00:00
|
|
|
void
|
|
|
|
gst_gl_upload_set_context (GstGLUpload * upload, GstGLContext * context)
|
|
|
|
{
|
|
|
|
g_return_if_fail (upload != NULL);
|
|
|
|
|
|
|
|
gst_object_replace ((GstObject **) & upload->context, (GstObject *) context);
|
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static void
|
|
|
|
gst_gl_upload_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstGLUpload *upload;
|
2015-02-02 13:11:06 +00:00
|
|
|
gint i, n;
|
2014-11-05 09:18:06 +00:00
|
|
|
|
|
|
|
upload = GST_GL_UPLOAD (object);
|
|
|
|
|
|
|
|
upload->priv->method_i = 0;
|
|
|
|
|
|
|
|
if (upload->context) {
|
|
|
|
gst_object_unref (upload->context);
|
|
|
|
upload->context = NULL;
|
2013-11-14 04:27:52 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
if (upload->priv->in_caps) {
|
|
|
|
gst_caps_unref (upload->priv->in_caps);
|
|
|
|
upload->priv->in_caps = NULL;
|
|
|
|
}
|
2013-11-14 04:27:52 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
if (upload->priv->out_caps) {
|
|
|
|
gst_caps_unref (upload->priv->out_caps);
|
|
|
|
upload->priv->out_caps = NULL;
|
|
|
|
}
|
2013-11-14 04:27:52 +00:00
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
n = G_N_ELEMENTS (upload_methods);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (upload->priv->upload_impl[i])
|
|
|
|
upload_methods[i]->free (upload->priv->upload_impl[i]);
|
|
|
|
}
|
|
|
|
g_free (upload->priv->upload_impl);
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
G_OBJECT_CLASS (gst_gl_upload_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
GstCaps *
|
2016-08-22 07:18:27 +00:00
|
|
|
gst_gl_upload_transform_caps (GstGLUpload * upload, GstGLContext * context,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
|
2015-02-02 13:11:06 +00:00
|
|
|
{
|
|
|
|
GstCaps *result, *tmp;
|
|
|
|
gint i;
|
|
|
|
|
2022-07-01 13:57:08 +00:00
|
|
|
if (upload->priv->method) {
|
2018-07-04 07:21:00 +00:00
|
|
|
tmp = upload->priv->method->transform_caps (upload->priv->method_impl,
|
|
|
|
context, direction, caps);
|
2022-07-07 13:40:22 +00:00
|
|
|
|
2020-02-24 15:38:56 +00:00
|
|
|
if (tmp) {
|
2022-07-07 13:40:22 +00:00
|
|
|
/* If we're generating sink pad caps, make sure to include raw caps if needed by
|
|
|
|
* the current method */
|
|
|
|
if (direction == GST_PAD_SRC
|
|
|
|
&& (upload->priv->method->flags & METHOD_FLAG_CAN_ACCEPT_RAW)) {
|
|
|
|
GstCapsFeatures *passthrough =
|
|
|
|
gst_caps_features_from_string
|
|
|
|
(GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION);
|
|
|
|
GstCaps *raw_tmp = _set_caps_features_with_passthrough (tmp,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY, passthrough);
|
|
|
|
gst_caps_append (tmp, raw_tmp);
|
|
|
|
gst_caps_features_free (passthrough);
|
|
|
|
}
|
|
|
|
|
2020-02-24 15:38:56 +00:00
|
|
|
if (filter) {
|
|
|
|
result =
|
|
|
|
gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
} else {
|
|
|
|
result = tmp;
|
|
|
|
}
|
|
|
|
if (!gst_caps_is_empty (result))
|
|
|
|
return result;
|
|
|
|
else
|
|
|
|
gst_caps_unref (result);
|
2018-07-04 07:21:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
tmp = gst_caps_new_empty ();
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (upload_methods); i++) {
|
2015-06-18 03:43:50 +00:00
|
|
|
GstCaps *tmp2;
|
|
|
|
|
2016-08-22 07:18:27 +00:00
|
|
|
tmp2 =
|
|
|
|
upload_methods[i]->transform_caps (upload->priv->upload_impl[i],
|
|
|
|
context, direction, caps);
|
2015-02-02 13:11:06 +00:00
|
|
|
|
|
|
|
if (tmp2)
|
|
|
|
tmp = gst_caps_merge (tmp, tmp2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter) {
|
|
|
|
result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
} else {
|
|
|
|
result = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_upload_propose_allocation:
|
|
|
|
* @upload: a #GstGLUpload
|
|
|
|
* @decide_query: (allow-none): a #GstQuery from a decide allocation
|
|
|
|
* @query: the proposed allocation query
|
|
|
|
*
|
|
|
|
* Adds the required allocation parameters to support uploading.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_upload_propose_allocation (GstGLUpload * upload, GstQuery * decide_query,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (upload_methods); i++)
|
|
|
|
upload_methods[i]->propose_allocation (upload->priv->upload_impl[i],
|
|
|
|
decide_query, query);
|
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
static gboolean
|
|
|
|
_gst_gl_upload_set_caps_unlocked (GstGLUpload * upload, GstCaps * in_caps,
|
|
|
|
GstCaps * out_caps)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (upload != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (gst_caps_is_fixed (in_caps), FALSE);
|
2013-11-14 04:27:52 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
if (upload->priv->in_caps && upload->priv->out_caps
|
|
|
|
&& gst_caps_is_equal (upload->priv->in_caps, in_caps)
|
|
|
|
&& gst_caps_is_equal (upload->priv->out_caps, out_caps))
|
|
|
|
return TRUE;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
gst_caps_replace (&upload->priv->in_caps, in_caps);
|
|
|
|
gst_caps_replace (&upload->priv->out_caps, out_caps);
|
2014-09-21 11:36:49 +00:00
|
|
|
|
2023-05-21 09:23:39 +00:00
|
|
|
gst_video_info_dma_drm_init (&upload->priv->in_info_drm);
|
|
|
|
if (gst_video_is_dma_drm_caps (in_caps)) {
|
|
|
|
gst_video_info_dma_drm_from_caps (&upload->priv->in_info_drm, in_caps);
|
|
|
|
} else {
|
|
|
|
gst_video_info_from_caps (&upload->priv->in_info, in_caps);
|
|
|
|
}
|
2014-11-05 09:18:06 +00:00
|
|
|
gst_video_info_from_caps (&upload->priv->out_info, out_caps);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2019-01-23 11:50:40 +00:00
|
|
|
upload->priv->method = NULL;
|
2014-11-05 09:18:06 +00:00
|
|
|
upload->priv->method_impl = NULL;
|
|
|
|
upload->priv->method_i = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
2014-11-05 09:18:06 +00:00
|
|
|
* gst_gl_upload_set_caps:
|
2012-09-27 05:53:46 +00:00
|
|
|
* @upload: a #GstGLUpload
|
2014-11-05 09:18:06 +00:00
|
|
|
* @in_caps: input #GstCaps
|
|
|
|
* @out_caps: output #GstCaps
|
2012-09-27 05:53:46 +00:00
|
|
|
*
|
2014-11-05 09:18:06 +00:00
|
|
|
* Initializes @upload with the information required for upload.
|
2012-09-27 05:53:46 +00:00
|
|
|
*
|
2014-11-05 09:18:06 +00:00
|
|
|
* Returns: whether @in_caps and @out_caps could be set on @upload
|
2012-09-27 05:53:46 +00:00
|
|
|
*/
|
2012-09-16 11:23:09 +00:00
|
|
|
gboolean
|
2014-11-05 09:18:06 +00:00
|
|
|
gst_gl_upload_set_caps (GstGLUpload * upload, GstCaps * in_caps,
|
|
|
|
GstCaps * out_caps)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
2014-05-29 06:20:30 +00:00
|
|
|
GST_OBJECT_LOCK (upload);
|
2014-11-05 09:18:06 +00:00
|
|
|
ret = _gst_gl_upload_set_caps_unlocked (upload, in_caps, out_caps);
|
2014-05-29 06:20:30 +00:00
|
|
|
GST_OBJECT_UNLOCK (upload);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_upload_get_caps:
|
|
|
|
* @upload: a #GstGLUpload
|
2015-03-18 17:12:49 +00:00
|
|
|
* @in_caps: (transfer full) (allow-none) (out): the input #GstCaps
|
|
|
|
* @out_caps: (transfer full) (allow-none) (out): the output #GstCaps
|
2014-11-05 09:18:06 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_upload_get_caps (GstGLUpload * upload, GstCaps ** in_caps,
|
|
|
|
GstCaps ** out_caps)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
2014-11-05 09:18:06 +00:00
|
|
|
GST_OBJECT_LOCK (upload);
|
|
|
|
if (in_caps)
|
|
|
|
*in_caps =
|
|
|
|
upload->priv->in_caps ? gst_caps_ref (upload->priv->in_caps) : NULL;
|
|
|
|
if (out_caps)
|
|
|
|
*out_caps =
|
|
|
|
upload->priv->out_caps ? gst_caps_ref (upload->priv->out_caps) : NULL;
|
|
|
|
GST_OBJECT_UNLOCK (upload);
|
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-05-08 05:40:33 +00:00
|
|
|
static gboolean
|
2018-07-04 07:17:11 +00:00
|
|
|
_upload_find_method (GstGLUpload * upload, gpointer last_impl)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
2016-08-22 07:18:27 +00:00
|
|
|
gint method_i;
|
|
|
|
|
2018-07-04 07:17:11 +00:00
|
|
|
/* start with the last used method after explicitly reconfiguring to
|
|
|
|
* negotiate caps for this method */
|
|
|
|
if (upload->priv->method_i == 0) {
|
|
|
|
upload->priv->method_i = upload->priv->saved_method_i;
|
|
|
|
upload->priv->saved_method_i = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (upload->priv->method_i >= G_N_ELEMENTS (upload_methods)) {
|
|
|
|
if (last_impl)
|
|
|
|
upload->priv->method_i = 0;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-07-04 07:17:11 +00:00
|
|
|
|
2018-09-14 00:02:37 +00:00
|
|
|
method_i = upload->priv->method_i;
|
2018-07-04 07:17:11 +00:00
|
|
|
|
|
|
|
if (last_impl == upload->priv->upload_impl[method_i])
|
|
|
|
return FALSE;
|
|
|
|
|
2016-08-22 07:18:27 +00:00
|
|
|
upload->priv->method = upload_methods[method_i];
|
|
|
|
upload->priv->method_impl = upload->priv->upload_impl[method_i];
|
2013-07-18 09:17:18 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
GST_DEBUG_OBJECT (upload, "attempting upload with uploader %s",
|
|
|
|
upload->priv->method->name);
|
2014-05-29 05:50:56 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
upload->priv->method_i++;
|
2014-05-08 14:38:24 +00:00
|
|
|
|
2014-05-08 05:40:33 +00:00
|
|
|
return TRUE;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_upload_perform_with_buffer:
|
|
|
|
* @upload: a #GstGLUpload
|
2016-03-06 08:35:38 +00:00
|
|
|
* @buffer: input #GstBuffer
|
2018-04-20 19:54:23 +00:00
|
|
|
* @outbuf_ptr: (out): resulting #GstBuffer
|
2014-11-05 09:18:06 +00:00
|
|
|
*
|
2015-09-30 03:31:50 +00:00
|
|
|
* Uploads @buffer using the transformation specified by
|
2016-03-06 08:35:38 +00:00
|
|
|
* gst_gl_upload_set_caps() creating a new #GstBuffer in @outbuf_ptr.
|
2014-11-05 09:18:06 +00:00
|
|
|
*
|
|
|
|
* Returns: whether the upload was successful
|
|
|
|
*/
|
2015-01-14 11:08:43 +00:00
|
|
|
GstGLUploadReturn
|
2014-11-05 09:18:06 +00:00
|
|
|
gst_gl_upload_perform_with_buffer (GstGLUpload * upload, GstBuffer * buffer,
|
|
|
|
GstBuffer ** outbuf_ptr)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
2015-01-14 11:08:43 +00:00
|
|
|
GstGLUploadReturn ret = GST_GL_UPLOAD_ERROR;
|
2020-03-26 05:46:56 +00:00
|
|
|
GstBuffer *outbuf = NULL;
|
2018-07-04 07:17:11 +00:00
|
|
|
gpointer last_impl = upload->priv->method_impl;
|
2022-06-30 08:41:01 +00:00
|
|
|
#if !defined (GST_DISABLE_DEBUG)
|
|
|
|
const UploadMethod *last_method = upload->priv->method;
|
|
|
|
#endif
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_UPLOAD (upload), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
2015-09-30 03:31:50 +00:00
|
|
|
g_return_val_if_fail (outbuf_ptr != NULL, FALSE);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
GST_OBJECT_LOCK (upload);
|
2014-05-08 03:46:29 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
#define NEXT_METHOD \
|
|
|
|
do { \
|
2018-07-04 07:17:11 +00:00
|
|
|
if (!_upload_find_method (upload, last_impl)) { \
|
2014-11-05 09:18:06 +00:00
|
|
|
GST_OBJECT_UNLOCK (upload); \
|
|
|
|
return FALSE; \
|
|
|
|
} \
|
|
|
|
goto restart; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
if (!upload->priv->method_impl)
|
2018-07-04 07:17:11 +00:00
|
|
|
_upload_find_method (upload, last_impl);
|
2013-07-18 09:17:18 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
restart:
|
|
|
|
if (!upload->priv->method->accept (upload->priv->method_impl, buffer,
|
|
|
|
upload->priv->in_caps, upload->priv->out_caps))
|
|
|
|
NEXT_METHOD;
|
2014-05-27 08:20:29 +00:00
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
ret =
|
|
|
|
upload->priv->method->perform (upload->priv->method_impl, buffer,
|
2015-09-30 03:31:50 +00:00
|
|
|
&outbuf);
|
2021-02-26 07:48:09 +00:00
|
|
|
GST_LOG_OBJECT (upload, "uploader %s returned %u, buffer: %p",
|
|
|
|
upload->priv->method->name, ret, outbuf);
|
2014-11-05 09:18:06 +00:00
|
|
|
if (ret == GST_GL_UPLOAD_UNSHARED_GL_CONTEXT) {
|
2016-12-13 20:39:01 +00:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (upload_methods); i++) {
|
2016-08-22 07:18:27 +00:00
|
|
|
if (upload_methods[i] == &_raw_data_upload) {
|
|
|
|
upload->priv->method = &_raw_data_upload;
|
|
|
|
upload->priv->method_impl = upload->priv->upload_impl[i];
|
|
|
|
upload->priv->method_i = i;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-03-26 05:46:56 +00:00
|
|
|
|
|
|
|
gst_buffer_replace (&outbuf, NULL);
|
2014-11-05 09:18:06 +00:00
|
|
|
goto restart;
|
2016-08-22 07:18:27 +00:00
|
|
|
} else if (ret == GST_GL_UPLOAD_DONE || ret == GST_GL_UPLOAD_RECONFIGURE) {
|
2022-06-30 08:41:01 +00:00
|
|
|
if (last_impl != upload->priv->method_impl
|
|
|
|
&& upload->priv->method_impl != NULL) {
|
|
|
|
/* Transform the input caps using the new method. If they are compatible with the
|
|
|
|
* existing upload method, we can skip reconfiguration */
|
|
|
|
GstCaps *caps =
|
|
|
|
upload->priv->method->transform_caps (upload->priv->method_impl,
|
|
|
|
upload->context, GST_PAD_SINK, upload->priv->in_caps);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (upload,
|
|
|
|
"Changing uploader from %s to %s with src caps %" GST_PTR_FORMAT
|
|
|
|
" and old src caps %" GST_PTR_FORMAT,
|
|
|
|
last_method != NULL ? last_method->name : "None",
|
|
|
|
upload->priv->method->name, caps, upload->priv->out_caps);
|
|
|
|
|
|
|
|
if (caps == NULL || !gst_caps_is_subset (caps, upload->priv->out_caps)) {
|
2018-07-04 07:21:00 +00:00
|
|
|
gst_buffer_replace (&outbuf, NULL);
|
|
|
|
ret = GST_GL_UPLOAD_RECONFIGURE;
|
|
|
|
}
|
2022-06-30 08:41:01 +00:00
|
|
|
gst_caps_replace (&caps, NULL);
|
2018-07-04 07:21:00 +00:00
|
|
|
}
|
2014-11-05 09:18:06 +00:00
|
|
|
/* we are done */
|
|
|
|
} else {
|
2015-02-26 12:20:26 +00:00
|
|
|
upload->priv->method_impl = NULL;
|
2020-03-26 05:46:56 +00:00
|
|
|
gst_buffer_replace (&outbuf, NULL);
|
2014-11-05 09:18:06 +00:00
|
|
|
NEXT_METHOD;
|
2014-05-29 05:50:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 07:18:27 +00:00
|
|
|
if (outbuf && buffer != outbuf)
|
2015-09-30 03:31:50 +00:00
|
|
|
gst_buffer_copy_into (outbuf, buffer,
|
|
|
|
GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
|
|
|
|
*outbuf_ptr = outbuf;
|
2014-05-29 05:50:56 +00:00
|
|
|
|
2018-07-04 07:17:11 +00:00
|
|
|
if (ret == GST_GL_UPLOAD_RECONFIGURE)
|
|
|
|
upload->priv->saved_method_i = upload->priv->method_i - 1;
|
|
|
|
|
2014-11-05 09:18:06 +00:00
|
|
|
GST_OBJECT_UNLOCK (upload);
|
2014-05-29 05:50:56 +00:00
|
|
|
|
2015-01-14 11:08:43 +00:00
|
|
|
return ret;
|
2014-11-05 09:18:06 +00:00
|
|
|
|
|
|
|
#undef NEXT_METHOD
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|