mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-29 15:22:11 +02:00
Compare commits
1 Commits
gluploader
...
vaglimport
Author | SHA1 | Date | |
---|---|---|---|
|
6f4cd930af |
4
lib/gst/meson.build
vendored
4
lib/gst/meson.build
vendored
@@ -2,4 +2,6 @@ if get_option('lib')
|
||||
subdir('clapper')
|
||||
endif
|
||||
|
||||
subdir('plugin')
|
||||
if not get_option('gst-plugin').disabled()
|
||||
subdir('plugin')
|
||||
endif
|
||||
|
414
lib/gst/plugin/importers/gstclappergluploader.c
vendored
414
lib/gst/plugin/importers/gstclappergluploader.c
vendored
@@ -22,36 +22,6 @@
|
||||
#endif
|
||||
|
||||
#include "gstclappergluploader.h"
|
||||
#include "gst/plugin/gstgtkutils.h"
|
||||
|
||||
#include <gst/gl/egl/gsteglimage.h>
|
||||
#include <gst/allocators/gstdmabuf.h>
|
||||
|
||||
static const GLfloat vertices[] = {
|
||||
1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
||||
-1.0f, 1.0f, 0.0f, 0.0f, 0.0f,
|
||||
-1.0f, -1.0f, 0.0f, 0.0f, 1.0f,
|
||||
1.0f, -1.0f, 0.0f, 1.0f, 1.0f
|
||||
};
|
||||
static const GLushort indices[] = {
|
||||
0, 1, 2, 0, 2, 3
|
||||
};
|
||||
|
||||
/* GTK4 renders things upside down ¯\_(ツ)_/¯ */
|
||||
static const gfloat vertical_flip_matrix[] = {
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, -1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f,
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GstClapperGLUploader *dmabuf_bi;
|
||||
GLuint id;
|
||||
guint width;
|
||||
guint height;
|
||||
} GstClapperDmabufTexData;
|
||||
|
||||
#define GST_CAT_DEFAULT gst_clapper_gl_uploader_debug
|
||||
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
||||
@@ -59,350 +29,6 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
||||
#define parent_class gst_clapper_gl_uploader_parent_class
|
||||
GST_CLAPPER_IMPORTER_DEFINE (GstClapperGLUploader, gst_clapper_gl_uploader, GST_TYPE_CLAPPER_GL_BASE_IMPORTER);
|
||||
|
||||
static void
|
||||
gst_clapper_gl_uploader_bind_buffer (GstClapperGLUploader *self)
|
||||
{
|
||||
GstClapperGLBaseImporter *gl_bi = GST_CLAPPER_GL_BASE_IMPORTER_CAST (self);
|
||||
const GstGLFuncs *gl = gl_bi->gst_context->gl_vtable;
|
||||
|
||||
gl->BindBuffer (GL_ARRAY_BUFFER, self->vertex_buffer);
|
||||
|
||||
/* Load the vertex position */
|
||||
gl->VertexAttribPointer (self->attr_position, 3, GL_FLOAT, GL_FALSE,
|
||||
5 * sizeof (GLfloat), (void *) 0);
|
||||
|
||||
/* Load the texture coordinate */
|
||||
gl->VertexAttribPointer (self->attr_texture, 2, GL_FLOAT, GL_FALSE,
|
||||
5 * sizeof (GLfloat), (void *) (3 * sizeof (GLfloat)));
|
||||
|
||||
gl->EnableVertexAttribArray (self->attr_position);
|
||||
gl->EnableVertexAttribArray (self->attr_texture);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_clapper_gl_uploader_unbind_buffer (GstClapperGLUploader *self)
|
||||
{
|
||||
GstClapperGLBaseImporter *gl_bi = GST_CLAPPER_GL_BASE_IMPORTER_CAST (self);
|
||||
const GstGLFuncs *gl = gl_bi->gst_context->gl_vtable;
|
||||
|
||||
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
|
||||
gl->DisableVertexAttribArray (self->attr_position);
|
||||
gl->DisableVertexAttribArray (self->attr_texture);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
prepare_dmabuf_support_on_main (GstClapperGLUploader *self)
|
||||
{
|
||||
GstClapperGLBaseImporter *gl_bi = GST_CLAPPER_GL_BASE_IMPORTER_CAST (self);
|
||||
GstGLSLStage *frag_stage, *vert_stage;
|
||||
GError *error = NULL;
|
||||
gchar *frag_str;
|
||||
const GstGLFuncs *gl;
|
||||
|
||||
GST_OBJECT_LOCK (self);
|
||||
|
||||
/* FIXME: Return if already prepared */
|
||||
|
||||
gdk_gl_context_make_current (gl_bi->gdk_context);
|
||||
gst_gl_context_activate (gl_bi->gst_context, TRUE);
|
||||
|
||||
if (!((vert_stage = gst_glsl_stage_new_with_string (gl_bi->gst_context,
|
||||
GL_VERTEX_SHADER, GST_GLSL_VERSION_NONE,
|
||||
GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY,
|
||||
gst_gl_shader_string_vertex_mat4_vertex_transform)))) {
|
||||
gdk_gl_context_make_current (gl_bi->gdk_context);
|
||||
gst_gl_context_activate (gl_bi->gst_context, TRUE);
|
||||
|
||||
GST_OBJECT_UNLOCK (self);
|
||||
GST_ERROR ("Failed to retrieve vertex shader for texture target");
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
frag_str = gst_gl_shader_string_fragment_external_oes_get_default (
|
||||
gl_bi->gst_context, GST_GLSL_VERSION_NONE,
|
||||
GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY);
|
||||
frag_stage = gst_glsl_stage_new_with_string (gl_bi->gst_context,
|
||||
GL_FRAGMENT_SHADER, GST_GLSL_VERSION_NONE,
|
||||
GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, frag_str);
|
||||
|
||||
g_free (frag_str);
|
||||
|
||||
if (!frag_stage) {
|
||||
gst_gl_context_activate (gl_bi->gst_context, FALSE);
|
||||
gdk_gl_context_clear_current ();
|
||||
|
||||
GST_OBJECT_UNLOCK (self);
|
||||
GST_ERROR ("Failed to retrieve fragment shader for texture target");
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!((self->shader = gst_gl_shader_new_link_with_stages (gl_bi->gst_context,
|
||||
&error, vert_stage, frag_stage, NULL)))) {
|
||||
gst_gl_context_activate (gl_bi->gst_context, FALSE);
|
||||
gdk_gl_context_clear_current ();
|
||||
|
||||
GST_OBJECT_UNLOCK (self);
|
||||
|
||||
GST_ERROR ("Failed to initialize shader: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
self->attr_position =
|
||||
gst_gl_shader_get_attribute_location (self->shader, "a_position");
|
||||
self->attr_texture =
|
||||
gst_gl_shader_get_attribute_location (self->shader, "a_texcoord");
|
||||
|
||||
gl = gl_bi->gst_context->gl_vtable;
|
||||
|
||||
if (gl->GenVertexArrays) {
|
||||
gl->GenVertexArrays (1, &self->vao);
|
||||
gl->BindVertexArray (self->vao);
|
||||
}
|
||||
|
||||
gl->GenBuffers (1, &self->vertex_buffer);
|
||||
gl->BindBuffer (GL_ARRAY_BUFFER, self->vertex_buffer);
|
||||
gl->BufferData (GL_ARRAY_BUFFER, 4 * 5 * sizeof (GLfloat), vertices, GL_STATIC_DRAW);
|
||||
|
||||
if (gl->GenVertexArrays) {
|
||||
gst_clapper_gl_uploader_bind_buffer (self);
|
||||
gl->BindVertexArray (0);
|
||||
}
|
||||
|
||||
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
|
||||
//self->prepared = TRUE;
|
||||
|
||||
gst_gl_context_activate (gl_bi->gst_context, FALSE);
|
||||
gdk_gl_context_clear_current ();
|
||||
|
||||
GST_OBJECT_UNLOCK (self);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_tex_data_free (GstClapperDmabufTexData *tex_data)
|
||||
{
|
||||
GstClapperGLBaseImporter *gl_bi = GST_CLAPPER_GL_BASE_IMPORTER_CAST (tex_data->dmabuf_bi);
|
||||
|
||||
if (G_LIKELY (tex_data->id > 0)) {
|
||||
const GstGLFuncs *gl;
|
||||
|
||||
GST_OBJECT_LOCK (gl_bi);
|
||||
|
||||
gl = gl_bi->gst_context->gl_vtable;
|
||||
|
||||
gdk_gl_context_make_current (gl_bi->gdk_context);
|
||||
gst_gl_context_activate (gl_bi->gst_context, TRUE);
|
||||
|
||||
gl->DeleteTextures (1, &tex_data->id);
|
||||
|
||||
gst_gl_context_activate (gl_bi->gst_context, FALSE);
|
||||
gdk_gl_context_clear_current ();
|
||||
|
||||
GST_OBJECT_UNLOCK (gl_bi);
|
||||
}
|
||||
|
||||
gst_object_unref (tex_data->dmabuf_bi);
|
||||
g_slice_free (GstClapperDmabufTexData, tex_data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_dmabuf_into_texture (GstClapperGLUploader *self, gint *fds, GstVideoInfo *v_info,
|
||||
gsize *offsets, GstClapperDmabufTexData *tex_data)
|
||||
{
|
||||
GstClapperGLBaseImporter *gl_bi = GST_CLAPPER_GL_BASE_IMPORTER_CAST (self);
|
||||
GstEGLImage *image;
|
||||
const GstGLFuncs *gl;
|
||||
|
||||
image = gst_egl_image_from_dmabuf_direct_target (gl_bi->gst_context,
|
||||
fds, offsets, v_info, self->gst_tex_target);
|
||||
|
||||
/* If HW colorspace conversion failed and there is only one
|
||||
* plane, we can just make it into single EGLImage as is */
|
||||
if (!image && GST_VIDEO_INFO_N_PLANES (v_info) == 1)
|
||||
image = gst_egl_image_from_dmabuf (gl_bi->gst_context,
|
||||
fds[0], v_info, 0, offsets[0]);
|
||||
|
||||
if (!image)
|
||||
return FALSE;
|
||||
|
||||
gl = gl_bi->gst_context->gl_vtable;
|
||||
|
||||
gl->GenTextures (1, &tex_data->id);
|
||||
tex_data->width = GST_VIDEO_INFO_WIDTH (v_info);
|
||||
tex_data->height = GST_VIDEO_INFO_HEIGHT (v_info);
|
||||
|
||||
gl->BindTexture (self->gl_tex_target, tex_data->id);
|
||||
|
||||
gl->TexParameteri (self->gl_tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
gl->TexParameteri (self->gl_tex_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
gl->TexParameteri (self->gl_tex_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
gl->TexParameteri (self->gl_tex_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
gl->EGLImageTargetTexture2D (self->gl_tex_target, gst_egl_image_get_image (image));
|
||||
|
||||
gl->BindTexture (GL_TEXTURE_2D, 0);
|
||||
gst_egl_image_unref (image);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_oes_texture_into_2d (GstClapperGLUploader *self, GstClapperDmabufTexData *tex_data)
|
||||
{
|
||||
GstClapperGLBaseImporter *gl_bi = GST_CLAPPER_GL_BASE_IMPORTER_CAST (self);
|
||||
GLuint framebuffer, tex_id;
|
||||
GLenum status;
|
||||
const GstGLFuncs *gl;
|
||||
|
||||
gl = gl_bi->gst_context->gl_vtable;
|
||||
|
||||
gl->GenFramebuffers (1, &framebuffer);
|
||||
gl->BindFramebuffer (GL_FRAMEBUFFER, framebuffer);
|
||||
|
||||
gl->GenTextures (1, &tex_id);
|
||||
gl->BindTexture (GL_TEXTURE_2D, tex_id);
|
||||
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, tex_data->width, tex_data->height, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
|
||||
gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D, tex_id, 0);
|
||||
|
||||
status = gl->CheckFramebufferStatus (GL_FRAMEBUFFER);
|
||||
if (G_UNLIKELY (status != GL_FRAMEBUFFER_COMPLETE)) {
|
||||
GST_ERROR ("Invalid framebuffer status: %u", status);
|
||||
|
||||
gl->BindTexture (GL_TEXTURE_2D, 0);
|
||||
gl->DeleteTextures (1, &tex_id);
|
||||
|
||||
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
||||
gl->DeleteFramebuffers (1, &framebuffer);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gl->Viewport (0, 0, tex_data->width, tex_data->height);
|
||||
|
||||
gst_gl_shader_use (self->shader);
|
||||
|
||||
if (gl->BindVertexArray)
|
||||
gl->BindVertexArray (self->vao);
|
||||
|
||||
gst_clapper_gl_uploader_bind_buffer (self);
|
||||
|
||||
gl->ActiveTexture (GL_TEXTURE0);
|
||||
gl->BindTexture (self->gl_tex_target, tex_data->id);
|
||||
|
||||
gst_gl_shader_set_uniform_1i (self->shader, "tex", 0);
|
||||
gst_gl_shader_set_uniform_matrix_4fv (self->shader,
|
||||
"u_transformation", 1, FALSE, vertical_flip_matrix);
|
||||
|
||||
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
|
||||
|
||||
if (gl->BindVertexArray)
|
||||
gl->BindVertexArray (0);
|
||||
else
|
||||
gst_clapper_gl_uploader_unbind_buffer (self);
|
||||
|
||||
gl->BindTexture (self->gl_tex_target, 0);
|
||||
|
||||
/* Replace External OES texture with newly created 2D */
|
||||
gl->DeleteTextures (1, &tex_data->id);
|
||||
tex_data->id = tex_id;
|
||||
|
||||
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
||||
gl->DeleteFramebuffers (1, &framebuffer);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GdkTexture *
|
||||
dmabuf_into_gdk_texture (GstClapperGLUploader *self, GstVideoInfo *v_info, gint *fds, gsize *offsets)
|
||||
{
|
||||
GstClapperGLBaseImporter *gl_bi = GST_CLAPPER_GL_BASE_IMPORTER_CAST (self);
|
||||
GdkTexture *texture = NULL;
|
||||
GstClapperDmabufTexData *tex_data;
|
||||
|
||||
tex_data = g_slice_new (GstClapperDmabufTexData);
|
||||
tex_data->dmabuf_bi = gst_object_ref (self);
|
||||
|
||||
GST_OBJECT_LOCK (self);
|
||||
|
||||
gdk_gl_context_make_current (gl_bi->gdk_context);
|
||||
gst_gl_context_activate (gl_bi->gst_context, TRUE);
|
||||
|
||||
if (!_dmabuf_into_texture (self, fds, v_info, offsets, tex_data))
|
||||
goto finish;
|
||||
|
||||
/* GTK4 does not support External OES textures.
|
||||
* Make it into 2D using framebuffer + shader */
|
||||
if (self->gst_tex_target == GST_GL_TEXTURE_TARGET_EXTERNAL_OES) {
|
||||
if (G_UNLIKELY (!_oes_texture_into_2d (self, tex_data)))
|
||||
goto finish;
|
||||
}
|
||||
|
||||
texture = gdk_gl_texture_new (gl_bi->gdk_context,
|
||||
tex_data->id,
|
||||
tex_data->width,
|
||||
tex_data->height,
|
||||
(GDestroyNotify) _tex_data_free,
|
||||
tex_data);
|
||||
|
||||
finish:
|
||||
gst_gl_context_activate (gl_bi->gst_context, FALSE);
|
||||
gdk_gl_context_clear_current ();
|
||||
|
||||
GST_OBJECT_UNLOCK (self);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
verify_dmabuf_memory (GstBuffer *buffer, GstVideoInfo *info, gint *fds, gsize *offsets)
|
||||
{
|
||||
guint i, n_planes = GST_VIDEO_INFO_N_PLANES (info);
|
||||
|
||||
for (i = 0; i < n_planes; i++) {
|
||||
GstMemory *memory;
|
||||
gsize plane_size, mem_skip;
|
||||
guint mem_idx, length;
|
||||
|
||||
plane_size = gst_gl_get_plane_data_size (info, NULL, i);
|
||||
|
||||
if (!gst_buffer_find_memory (buffer,
|
||||
GST_VIDEO_INFO_PLANE_OFFSET (info, i),
|
||||
plane_size, &mem_idx, &length, &mem_skip)) {
|
||||
GST_DEBUG ("Could not find memory %u", i);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* We cannot have more then one DMABuf per plane */
|
||||
if (length != 1) {
|
||||
GST_DEBUG ("Data for plane %u spans %u memories", i, length);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memory = gst_buffer_peek_memory (buffer, mem_idx);
|
||||
|
||||
offsets[i] = memory->offset + mem_skip;
|
||||
fds[i] = gst_dmabuf_memory_get_fd (memory);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_update_elements_caps_locked (GstClapperGLUploader *self, GstCaps *upload_sink_caps)
|
||||
{
|
||||
@@ -478,14 +104,6 @@ gst_clapper_gl_uploader_prepare (GstClapperImporter *importer)
|
||||
self->color_convert = gst_gl_color_convert_new (gl_bi->gst_context);
|
||||
|
||||
GST_OBJECT_UNLOCK (self);
|
||||
|
||||
if (!(! !gst_gtk_invoke_on_main (
|
||||
(GThreadFunc) (GCallback) prepare_dmabuf_support_on_main, self))) {
|
||||
GST_WARNING_OBJECT (self, "Could not prepare DMABuf support");
|
||||
|
||||
/* FIXME: Continue to allow using glupload/cc as fallback */
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
@@ -521,38 +139,12 @@ gst_clapper_gl_uploader_generate_texture (GstClapperImporter *importer,
|
||||
GstClapperGLUploader *self = GST_CLAPPER_GL_UPLOADER_CAST (importer);
|
||||
GstClapperGLBaseImporter *gl_bi = GST_CLAPPER_GL_BASE_IMPORTER_CAST (importer);
|
||||
GstBuffer *upload_buf, *color_buf;
|
||||
GstVideoMeta *meta;
|
||||
GdkTexture *texture;
|
||||
|
||||
/* XXX: We both upload and perform color conversion here, thus we skip
|
||||
* upload for buffers that are not going to be shown and gain more free
|
||||
* CPU time to prepare the next one. Improves performance on weak HW. */
|
||||
|
||||
if ((meta = gst_buffer_get_video_meta (buffer))) {
|
||||
guint i;
|
||||
|
||||
GST_VIDEO_INFO_WIDTH (v_info) = meta->width;
|
||||
GST_VIDEO_INFO_HEIGHT (v_info) = meta->height;
|
||||
|
||||
for (i = 0; i < meta->n_planes; i++) {
|
||||
GST_VIDEO_INFO_PLANE_OFFSET (v_info, i) = meta->offset[i];
|
||||
GST_VIDEO_INFO_PLANE_STRIDE (v_info, i) = meta->stride[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME: if can do dmabuf and seems like we have dmabuf here */
|
||||
{
|
||||
gint fds[GST_VIDEO_MAX_PLANES];
|
||||
gsize offsets[GST_VIDEO_MAX_PLANES];
|
||||
|
||||
if (verify_dmabuf_memory (buffer, v_info, fds, offsets)) {
|
||||
if ((texture = dmabuf_into_gdk_texture (self, v_info, fds, offsets))) {
|
||||
GST_TRACE_OBJECT (self, "Got texture from DMABuf, skipping upload of %" GST_PTR_FORMAT, buffer);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GST_LOG_OBJECT (self, "Uploading %" GST_PTR_FORMAT, buffer);
|
||||
|
||||
GST_OBJECT_LOCK (self);
|
||||
@@ -587,7 +179,6 @@ gst_clapper_gl_uploader_generate_texture (GstClapperImporter *importer,
|
||||
texture = gst_clapper_gl_base_importer_make_gl_texture (gl_bi, color_buf, &self->v_info);
|
||||
gst_buffer_unref (color_buf);
|
||||
|
||||
done:
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -596,9 +187,6 @@ gst_clapper_gl_uploader_init (GstClapperGLUploader *self)
|
||||
{
|
||||
gst_video_info_init (&self->pending_v_info);
|
||||
gst_video_info_init (&self->v_info);
|
||||
|
||||
self->gst_tex_target = GST_GL_TEXTURE_TARGET_EXTERNAL_OES;
|
||||
self->gl_tex_target = gst_gl_texture_target_to_gl (self->gst_tex_target);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -609,8 +197,6 @@ gst_clapper_gl_uploader_finalize (GObject *object)
|
||||
gst_clear_object (&self->upload);
|
||||
gst_clear_object (&self->color_convert);
|
||||
|
||||
gst_clear_object (&self->shader);
|
||||
|
||||
GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
|
||||
}
|
||||
|
||||
|
13
lib/gst/plugin/importers/gstclappergluploader.h
vendored
13
lib/gst/plugin/importers/gstclappergluploader.h
vendored
@@ -21,8 +21,6 @@
|
||||
|
||||
#include "gstclapperglbaseimporter.h"
|
||||
|
||||
#include <gst/gl/gstglfuncs.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_CLAPPER_GL_UPLOADER (gst_clapper_gl_uploader_get_type())
|
||||
@@ -39,17 +37,6 @@ struct _GstClapperGLUploader
|
||||
|
||||
GstVideoInfo pending_v_info, v_info;
|
||||
gboolean has_pending_v_info;
|
||||
|
||||
/* DMABuf fast-path */
|
||||
GstGLTextureTarget gst_tex_target;
|
||||
guint gl_tex_target;
|
||||
|
||||
GstGLShader *shader;
|
||||
|
||||
GLuint vao;
|
||||
GLuint vertex_buffer;
|
||||
GLint attr_position;
|
||||
GLint attr_texture;
|
||||
};
|
||||
|
||||
G_END_DECLS
|
||||
|
83
lib/gst/plugin/importers/gstclappervaglimporter.c
vendored
Normal file
83
lib/gst/plugin/importers/gstclappervaglimporter.c
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Rafał Dzięgiel <rafostar.github@gmail.com>
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gstclappervaglimporter.h"
|
||||
#include "gst/plugin/gstgdkformats.h"
|
||||
|
||||
#include <gst/va/gstva.h>
|
||||
|
||||
#define GST_CAT_DEFAULT gst_clapper_va_gl_importer_debug
|
||||
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
||||
|
||||
#define parent_class gst_clapper_va_gl_importer_parent_class
|
||||
GST_CLAPPER_IMPORTER_DEFINE (GstClapperVAGLImporter, gst_clapper_va_gl_importer, GST_TYPE_CLAPPER_GL_BASE_IMPORTER);
|
||||
|
||||
static GdkTexture *
|
||||
gst_clapper_va_gl_importer_generate_texture (GstClapperImporter *importer,
|
||||
GstBuffer *buffer, GstVideoInfo *v_info)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_clapper_va_gl_importer_init (GstClapperVAGLImporter *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gst_clapper_va_gl_importer_class_init (GstClapperVAGLImporterClass *klass)
|
||||
{
|
||||
GstClapperImporterClass *importer_class = (GstClapperImporterClass *) klass;
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "clappervaglimporter", 0,
|
||||
"Clapper VA GL Importer");
|
||||
|
||||
importer_class->generate_texture = gst_clapper_va_gl_importer_generate_texture;
|
||||
}
|
||||
|
||||
GstClapperImporter *
|
||||
make_importer (void)
|
||||
{
|
||||
return g_object_new (GST_TYPE_CLAPPER_VA_GL_IMPORTER, NULL);
|
||||
}
|
||||
|
||||
GstCaps *
|
||||
make_caps (GstRank *rank, GStrv *context_types)
|
||||
{
|
||||
GstCaps *caps, *tmp;
|
||||
|
||||
*rank = GST_RANK_PRIMARY;
|
||||
|
||||
tmp = gst_caps_from_string (
|
||||
GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_VA,
|
||||
"{ " GST_GDK_GL_TEXTURE_FORMATS " }"));
|
||||
|
||||
caps = gst_caps_copy (tmp);
|
||||
gst_caps_set_features_simple (caps, gst_caps_features_new (
|
||||
GST_CAPS_FEATURE_MEMORY_VA,
|
||||
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, NULL));
|
||||
|
||||
gst_caps_append (caps, tmp);
|
||||
|
||||
return caps;
|
||||
}
|
36
lib/gst/plugin/importers/gstclappervaglimporter.h
vendored
Normal file
36
lib/gst/plugin/importers/gstclappervaglimporter.h
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Rafał Dzięgiel <rafostar.github@gmail.com>
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gstclapperglbaseimporter.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_CLAPPER_VA_GL_IMPORTER (gst_clapper_va_gl_importer_get_type())
|
||||
G_DECLARE_FINAL_TYPE (GstClapperVAGLImporter, gst_clapper_va_gl_importer, GST, CLAPPER_VA_GL_IMPORTER, GstClapperGLBaseImporter)
|
||||
|
||||
#define GST_CLAPPER_VA_GL_IMPORTER_CAST(obj) ((GstClapperVAGLImporter *)(obj))
|
||||
|
||||
struct _GstClapperVAGLImporter
|
||||
{
|
||||
GstClapperGLBaseImporter parent;
|
||||
};
|
||||
|
||||
G_END_DECLS
|
101
lib/gst/plugin/importers/meson.build
vendored
101
lib/gst/plugin/importers/meson.build
vendored
@@ -1,38 +1,25 @@
|
||||
gst_clapper_gl_base_importer_dep = dependency('', required: false)
|
||||
|
||||
all_importers = [
|
||||
'glimporter',
|
||||
'gluploader',
|
||||
'rawimporter',
|
||||
]
|
||||
|
||||
build_glbase = (
|
||||
plugin_needs_gl_base = (
|
||||
not get_option('glimporter').disabled()
|
||||
or not get_option('gluploader').disabled()
|
||||
or not get_option('vaglimporter').disabled()
|
||||
)
|
||||
gl_support_required = (
|
||||
plugin_gl_support_required = (
|
||||
get_option('glimporter').enabled()
|
||||
or get_option('gluploader').enabled()
|
||||
or get_option('vaglimporter').enabled()
|
||||
)
|
||||
|
||||
# We cannot build any importers without sink that they depend on
|
||||
if not gst_clapper_sink_dep.found()
|
||||
foreach imp : all_importers
|
||||
if get_option(imp).enabled()
|
||||
error('"@0@" option was enabled, but it requires building gstreamer plugin'.format(imp))
|
||||
endif
|
||||
endforeach
|
||||
endif
|
||||
|
||||
gst_plugin_gl_base_deps = [gst_clapper_sink_dep, gstgl_dep, gstglproto_dep]
|
||||
gst_plugin_gl_deps = [gstgl_dep, gstglproto_dep]
|
||||
have_gtk_gl_windowing = false
|
||||
|
||||
if gst_gl_have_window_x11 and (gst_gl_have_platform_egl or gst_gl_have_platform_glx)
|
||||
gtk_x11_dep = dependency('gtk4-x11', required: false)
|
||||
if gtk_x11_dep.found()
|
||||
gst_plugin_gl_base_deps += gtk_x11_dep
|
||||
gst_plugin_gl_deps += gtk_x11_dep
|
||||
if gst_gl_have_platform_glx
|
||||
gst_plugin_gl_base_deps += gstglx11_dep
|
||||
gst_plugin_gl_deps += gstglx11_dep
|
||||
endif
|
||||
have_gtk_gl_windowing = true
|
||||
endif
|
||||
@@ -41,40 +28,44 @@ endif
|
||||
if gst_gl_have_window_wayland and gst_gl_have_platform_egl
|
||||
gtk_wayland_dep = dependency('gtk4-wayland', required: false)
|
||||
if gtk_wayland_dep.found()
|
||||
gst_plugin_gl_base_deps += [gtk_wayland_dep, gstglwayland_dep]
|
||||
gst_plugin_gl_deps += [gtk_wayland_dep, gstglwayland_dep]
|
||||
have_gtk_gl_windowing = true
|
||||
endif
|
||||
endif
|
||||
|
||||
if gl_support_required and not have_gtk_gl_windowing
|
||||
if plugin_gl_support_required and not have_gtk_gl_windowing
|
||||
error('GL-based importer was enabled, but support for current GL windowing is missing')
|
||||
endif
|
||||
|
||||
if gst_gl_have_platform_egl
|
||||
gst_plugin_gl_base_deps += gstglegl_dep
|
||||
gst_plugin_gl_deps += gstglegl_dep
|
||||
endif
|
||||
|
||||
foreach dep : gst_plugin_gl_base_deps
|
||||
gst_clapper_gl_base_importer_deps = [
|
||||
gst_clapper_sink_dep
|
||||
] + gst_plugin_gl_deps
|
||||
|
||||
foreach dep : gst_clapper_gl_base_importer_deps
|
||||
if not dep.found()
|
||||
if gl_support_required
|
||||
if plugin_gl_support_required
|
||||
error('GL-based importer was enabled, but required dependencies were not found')
|
||||
endif
|
||||
build_glbase = false
|
||||
plugin_needs_gl_base = false
|
||||
endif
|
||||
endforeach
|
||||
|
||||
if build_glbase
|
||||
if plugin_needs_gl_base
|
||||
gst_clapper_gl_base_importer_dep = declare_dependency(
|
||||
link_with: library('gstclapperglbaseimporter',
|
||||
'gstclapperglbaseimporter.c',
|
||||
c_args: gst_clapper_plugin_args,
|
||||
include_directories: configinc,
|
||||
dependencies: gst_plugin_gl_base_deps,
|
||||
dependencies: gst_clapper_gl_base_importer_deps,
|
||||
version: libversion,
|
||||
install: true,
|
||||
),
|
||||
include_directories: configinc,
|
||||
dependencies: gst_plugin_gl_base_deps,
|
||||
dependencies: gst_clapper_gl_base_importer_deps,
|
||||
)
|
||||
endif
|
||||
|
||||
@@ -100,25 +91,11 @@ build_gluploader = (
|
||||
and gst_clapper_gl_base_importer_dep.found()
|
||||
)
|
||||
|
||||
gluploader_deps = [
|
||||
gst_clapper_gl_base_importer_dep,
|
||||
gstallocators_dep,
|
||||
]
|
||||
|
||||
foreach dep : gluploader_deps
|
||||
if not dep.found()
|
||||
if get_option('gluploader').enabled()
|
||||
error('GL uploader was enabled, but required dependencies were not found')
|
||||
endif
|
||||
build_gluploader = false
|
||||
endif
|
||||
endforeach
|
||||
|
||||
if build_gluploader
|
||||
library(
|
||||
'gstclappergluploader',
|
||||
'gstclappergluploader.c',
|
||||
dependencies: gluploader_deps,
|
||||
dependencies: gst_clapper_gl_base_importer_dep,
|
||||
include_directories: configinc,
|
||||
c_args: gst_clapper_plugin_args,
|
||||
install: true,
|
||||
@@ -130,7 +107,6 @@ endif
|
||||
build_rawimporter = (
|
||||
not get_option('rawimporter').disabled()
|
||||
and (not build_gluploader or get_option('rawimporter').enabled())
|
||||
and gst_clapper_sink_dep.found()
|
||||
)
|
||||
|
||||
if build_rawimporter
|
||||
@@ -144,3 +120,38 @@ if build_rawimporter
|
||||
install_dir: gst_clapper_importers_libdir,
|
||||
)
|
||||
endif
|
||||
|
||||
gst_va_dep = dependency('gstreamer-va-1.0',
|
||||
version: gst_req,
|
||||
required: false,
|
||||
)
|
||||
|
||||
gst_clapper_va_gl_importer_deps = [
|
||||
gst_clapper_gl_base_importer_dep,
|
||||
gst_va_dep,
|
||||
]
|
||||
|
||||
foreach dep : gst_clapper_va_gl_importer_deps
|
||||
if not dep.found()
|
||||
if get_option('vaglimporter').enabled()
|
||||
error('VA GL-based importer was enabled, but required dependencies were not found')
|
||||
endif
|
||||
endif
|
||||
endforeach
|
||||
|
||||
build_vaglimporter = (
|
||||
not get_option('vaglimporter').disabled()
|
||||
and gst_clapper_gl_base_importer_dep.found()
|
||||
)
|
||||
|
||||
if build_vaglimporter
|
||||
library(
|
||||
'gstclappervaglimporter',
|
||||
'gstclappervaglimporter.c',
|
||||
dependencies: gst_clapper_va_gl_importer_deps,
|
||||
include_directories: configinc,
|
||||
c_args: gst_clapper_plugin_args,
|
||||
install: true,
|
||||
install_dir: gst_clapper_importers_libdir,
|
||||
)
|
||||
endif
|
||||
|
27
lib/gst/plugin/meson.build
vendored
27
lib/gst/plugin/meson.build
vendored
@@ -4,8 +4,6 @@ gst_clapper_plugin_args = [
|
||||
'-DHAVE_CONFIG_H',
|
||||
'-DGST_USE_UNSTABLE_API',
|
||||
]
|
||||
|
||||
gst_clapper_sink_dep = dependency('', required: false)
|
||||
gtk4_dep = dependency('gtk4', version: '>=4.6.0', required: false)
|
||||
|
||||
gmodule_dep = dependency('gmodule-2.0',
|
||||
@@ -22,13 +20,12 @@ gst_clapper_plugin_deps = [
|
||||
gmodule_dep,
|
||||
]
|
||||
|
||||
build_gst_plugin = not get_option('gst-plugin').disabled()
|
||||
foreach dep : gst_clapper_plugin_deps
|
||||
if not dep.found()
|
||||
if get_option('gst-plugin').enabled()
|
||||
error('GStreamer plugin was enabled, but required dependencies were not found')
|
||||
endif
|
||||
build_gst_plugin = false
|
||||
subdir_done()
|
||||
endif
|
||||
endforeach
|
||||
|
||||
@@ -45,19 +42,17 @@ gst_clapper_plugin_sources = [
|
||||
'gstclapperimporterloader.c',
|
||||
]
|
||||
|
||||
if build_gst_plugin
|
||||
gst_clapper_sink_dep = declare_dependency(
|
||||
link_with: library('gstclapper',
|
||||
gst_clapper_plugin_sources,
|
||||
c_args: gst_clapper_plugin_args,
|
||||
include_directories: configinc,
|
||||
dependencies: gst_clapper_plugin_deps,
|
||||
install: true,
|
||||
install_dir: gst_plugins_libdir,
|
||||
),
|
||||
gst_clapper_sink_dep = declare_dependency(
|
||||
link_with: library('gstclapper',
|
||||
gst_clapper_plugin_sources,
|
||||
c_args: gst_clapper_plugin_args,
|
||||
include_directories: configinc,
|
||||
dependencies: gst_clapper_plugin_deps,
|
||||
)
|
||||
endif
|
||||
install: true,
|
||||
install_dir: gst_plugins_libdir,
|
||||
),
|
||||
include_directories: configinc,
|
||||
dependencies: gst_clapper_plugin_deps,
|
||||
)
|
||||
|
||||
subdir('importers')
|
||||
|
4
lib/meson.build
vendored
4
lib/meson.build
vendored
@@ -196,8 +196,6 @@ gsttag_dep = dependency('gstreamer-tag-1.0', version: gst_req,
|
||||
fallback: ['gst-plugins-base', 'tag_dep'])
|
||||
gstvideo_dep = dependency('gstreamer-video-1.0', version: gst_req,
|
||||
fallback: ['gst-plugins-base', 'video_dep'])
|
||||
gstallocators_dep = dependency('gstreamer-allocators-1.0', version: gst_req,
|
||||
fallback : ['gst-plugins-base', 'allocators_dep'])
|
||||
|
||||
# GStreamer OpenGL
|
||||
gstgl_dep = dependency('gstreamer-gl-1.0', version: gst_req,
|
||||
@@ -261,7 +259,7 @@ gir_init_section = ['--add-init-section=extern void gst_init(gint*,gchar**);' +
|
||||
'gst_init(NULL,NULL);', '--quiet'
|
||||
]
|
||||
|
||||
gst_clapper_plugin_libdir = join_paths(get_option('prefix'), libdir, 'clapper-@0@'.format(api_version), 'gst', 'plugin')
|
||||
gst_clapper_plugin_libdir = join_paths(get_option('prefix'), libdir, 'clapper-0.0', 'gst', 'plugin')
|
||||
gst_clapper_importers_libdir = join_paths(gst_clapper_plugin_libdir, 'importers')
|
||||
cdata.set_quoted('CLAPPER_SINK_IMPORTER_PATH', gst_clapper_importers_libdir)
|
||||
|
||||
|
@@ -14,6 +14,11 @@ option('gst-plugin',
|
||||
description: 'Build GStreamer plugin (includes GTK video sink element)'
|
||||
)
|
||||
|
||||
option('vaglimporter',
|
||||
type: 'feature',
|
||||
value: 'auto',
|
||||
description: 'Build VA memory GL-based importer for clappersink'
|
||||
)
|
||||
option('glimporter',
|
||||
type: 'feature',
|
||||
value: 'auto',
|
||||
|
Reference in New Issue
Block a user