mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 07:42:23 +02:00
wip3
This commit is contained in:
4
lib/gst/plugin/gstclappersink.c
vendored
4
lib/gst/plugin/gstclappersink.c
vendored
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
#define GST_CLAPPER_GL_SINK_CAPS \
|
#define GST_CLAPPER_GL_SINK_CAPS \
|
||||||
"video/x-raw(" GST_CAPS_FEATURE_MEMORY_GL_MEMORY "), " \
|
"video/x-raw(" GST_CAPS_FEATURE_MEMORY_GL_MEMORY "), " \
|
||||||
"format = (string) RGBA, " \
|
"format = (string)" SINK_FORMATS ", " \
|
||||||
"width = " GST_VIDEO_SIZE_RANGE ", " \
|
"width = " GST_VIDEO_SIZE_RANGE ", " \
|
||||||
"height = " GST_VIDEO_SIZE_RANGE ", " \
|
"height = " GST_VIDEO_SIZE_RANGE ", " \
|
||||||
"framerate = " GST_VIDEO_FPS_RANGE ", " \
|
"framerate = " GST_VIDEO_FPS_RANGE ", " \
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
" ; " \
|
" ; " \
|
||||||
"video/x-raw(" GST_CAPS_FEATURE_MEMORY_GL_MEMORY "," \
|
"video/x-raw(" GST_CAPS_FEATURE_MEMORY_GL_MEMORY "," \
|
||||||
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION "), " \
|
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION "), " \
|
||||||
"format = (string) RGBA, " \
|
"format = (string)" SINK_FORMATS ", " \
|
||||||
"width = " GST_VIDEO_SIZE_RANGE ", " \
|
"width = " GST_VIDEO_SIZE_RANGE ", " \
|
||||||
"height = " GST_VIDEO_SIZE_RANGE ", " \
|
"height = " GST_VIDEO_SIZE_RANGE ", " \
|
||||||
"framerate = " GST_VIDEO_FPS_RANGE ", " \
|
"framerate = " GST_VIDEO_FPS_RANGE ", " \
|
||||||
|
153
lib/gst/plugin/gtkclapperobject.c
vendored
153
lib/gst/plugin/gtkclapperobject.c
vendored
@@ -160,11 +160,9 @@ video_format_to_gdk_memory_format (GstVideoFormat format)
|
|||||||
return GDK_MEMORY_B8G8R8A8_PREMULTIPLIED;
|
return GDK_MEMORY_B8G8R8A8_PREMULTIPLIED;
|
||||||
case GST_VIDEO_FORMAT_RGBx:
|
case GST_VIDEO_FORMAT_RGBx:
|
||||||
return GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
|
return GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
|
||||||
/*
|
|
||||||
case GST_VIDEO_FORMAT_RGBA64_LE:
|
case GST_VIDEO_FORMAT_RGBA64_LE:
|
||||||
case GST_VIDEO_FORMAT_RGBA64_BE:
|
case GST_VIDEO_FORMAT_RGBA64_BE:
|
||||||
return GDK_MEMORY_R16G16B16A16_PREMULTIPLIED;
|
return GDK_MEMORY_R16G16B16A16_PREMULTIPLIED;
|
||||||
*/
|
|
||||||
default:
|
default:
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
@@ -275,44 +273,31 @@ gtk_clapper_object_init_redisplay (GtkClapperObject *self)
|
|||||||
self->initiated = TRUE;
|
self->initiated = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GdkTexture *
|
static gboolean
|
||||||
import_dmabuf (GtkClapperObject *self, guint n_planes,
|
_dmabuf_into_texture (GtkClapperObject *self, gint *fds, gsize *offsets)
|
||||||
gint *fds, gsize *offsets)
|
|
||||||
{
|
{
|
||||||
GdkTexture *texture;
|
|
||||||
GstEGLImage *image;
|
GstEGLImage *image;
|
||||||
const GstGLFuncs *gl;
|
const GstGLFuncs *gl;
|
||||||
|
|
||||||
_gdk_gl_context_set_active (self, TRUE);
|
|
||||||
|
|
||||||
if (!self->initiated)
|
|
||||||
gtk_clapper_object_init_redisplay (self);
|
|
||||||
|
|
||||||
image = gst_egl_image_from_dmabuf_direct_target (self->wrapped_context,
|
image = gst_egl_image_from_dmabuf_direct_target (self->wrapped_context,
|
||||||
fds, offsets, &self->v_info, GST_GL_TEXTURE_TARGET_2D);
|
fds, offsets, &self->v_info, self->texture_target);
|
||||||
|
|
||||||
/* FIXME: Can we handle `GST_GL_TEXTURE_TARGET_EXTERNAL_OES`
|
|
||||||
* without reinventing GLArea sink all over again? */
|
|
||||||
|
|
||||||
/* If HW colorspace conversion failed and there is only one
|
/* If HW colorspace conversion failed and there is only one
|
||||||
* plane, we can just make it into single EGLImage as is */
|
* plane, we can just make it into single EGLImage as is */
|
||||||
if (!image && n_planes == 1)
|
if (!image && GST_VIDEO_INFO_N_PLANES (&self->v_info) == 1)
|
||||||
image = gst_egl_image_from_dmabuf (self->wrapped_context,
|
image = gst_egl_image_from_dmabuf (self->wrapped_context,
|
||||||
fds[0], &self->v_info, 0, offsets[0]);
|
fds[0], &self->v_info, 0, offsets[0]);
|
||||||
|
|
||||||
/* Still no image? Give up then */
|
/* Still no image? Give up then */
|
||||||
if (!image) {
|
if (!image)
|
||||||
_gdk_gl_context_set_active (self, FALSE);
|
return FALSE;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
gl = self->wrapped_context->gl_vtable;
|
gl = self->wrapped_context->gl_vtable;
|
||||||
|
|
||||||
if (!self->next_texture_id)
|
if (!self->texture_id)
|
||||||
gl->GenTextures (1, &self->next_texture_id);
|
gl->GenTextures (1, &self->texture_id);
|
||||||
|
|
||||||
gl->ActiveTexture (GL_TEXTURE1);
|
gl->BindTexture (GL_TEXTURE_2D, self->texture_id);
|
||||||
gl->BindTexture (GL_TEXTURE_2D, self->next_texture_id);
|
|
||||||
|
|
||||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
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_MAG_FILTER, GL_LINEAR);
|
||||||
@@ -323,20 +308,30 @@ import_dmabuf (GtkClapperObject *self, guint n_planes,
|
|||||||
gl->EGLImageTargetTexture2D (GL_TEXTURE_2D, gst_egl_image_get_image (image));
|
gl->EGLImageTargetTexture2D (GL_TEXTURE_2D, gst_egl_image_get_image (image));
|
||||||
|
|
||||||
gl->BindTexture (GL_TEXTURE_2D, 0);
|
gl->BindTexture (GL_TEXTURE_2D, 0);
|
||||||
|
gst_egl_image_unref (image);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_ext_texture_into_2d (GtkClapperObject *self, guint tex_width, guint tex_height)
|
||||||
|
{
|
||||||
|
GLuint framebuffer, new_texture_id;
|
||||||
|
GLenum status;
|
||||||
|
const GstGLFuncs *gl;
|
||||||
|
|
||||||
|
if (!self->initiated)
|
||||||
|
gtk_clapper_object_init_redisplay (self);
|
||||||
|
|
||||||
if (!self->frame_buffer)
|
gl = self->wrapped_context->gl_vtable;
|
||||||
gl->GenFramebuffers (1, &self->frame_buffer);
|
|
||||||
|
|
||||||
gl->BindFramebuffer (GL_FRAMEBUFFER, self->frame_buffer);
|
gl->GenFramebuffers (1, &framebuffer);
|
||||||
|
gl->BindFramebuffer (GL_FRAMEBUFFER, framebuffer);
|
||||||
|
|
||||||
if (!self->texture_id)
|
gl->GenTextures (1, &new_texture_id);
|
||||||
gl->GenTextures (1, &self->texture_id);
|
|
||||||
|
|
||||||
gl->ActiveTexture (GL_TEXTURE0);
|
gl->ActiveTexture (GL_TEXTURE0);
|
||||||
gl->BindTexture (GL_TEXTURE_2D, self->texture_id);
|
gl->BindTexture (GL_TEXTURE_2D, new_texture_id);
|
||||||
|
|
||||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
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_MAG_FILTER, GL_LINEAR);
|
||||||
@@ -344,15 +339,26 @@ import_dmabuf (GtkClapperObject *self, guint n_planes,
|
|||||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
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->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, gtk_widget_get_width (GTK_WIDGET (self->picture)),
|
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, tex_width, tex_height, 0,
|
||||||
gtk_widget_get_height (GTK_WIDGET (self->picture)), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
|
||||||
gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self->texture_id, 0);
|
gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||||
|
GL_TEXTURE_2D, new_texture_id, 0);
|
||||||
|
|
||||||
if (gl->CheckFramebufferStatus (GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
status = gl->CheckFramebufferStatus (GL_FRAMEBUFFER);
|
||||||
GST_ERROR ("Wrong framebuffer status!");
|
if (G_UNLIKELY (status != GL_FRAMEBUFFER_COMPLETE)) {
|
||||||
|
GST_ERROR ("Invalid framebuffer status: %u", status);
|
||||||
|
|
||||||
gl->Viewport (0, 0, gtk_widget_get_width (GTK_WIDGET (self->picture)), gtk_widget_get_height (GTK_WIDGET (self->picture)));
|
gl->BindTexture (GL_TEXTURE_2D, 0);
|
||||||
|
gl->DeleteTextures (1, &new_texture_id);
|
||||||
|
|
||||||
|
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
||||||
|
gl->DeleteFramebuffers (1, &framebuffer);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gl->Viewport (0, 0, tex_width, tex_height);
|
||||||
|
|
||||||
gst_gl_shader_use (self->shader);
|
gst_gl_shader_use (self->shader);
|
||||||
|
|
||||||
@@ -362,7 +368,7 @@ import_dmabuf (GtkClapperObject *self, guint n_planes,
|
|||||||
gtk_clapper_object_bind_buffer (self);
|
gtk_clapper_object_bind_buffer (self);
|
||||||
|
|
||||||
gl->ActiveTexture (GL_TEXTURE0);
|
gl->ActiveTexture (GL_TEXTURE0);
|
||||||
gl->BindTexture (GL_TEXTURE_2D, self->next_texture_id);
|
gl->BindTexture (GL_TEXTURE_2D, self->texture_id);
|
||||||
|
|
||||||
gst_gl_shader_set_uniform_1i (self->shader, "tex", 0);
|
gst_gl_shader_set_uniform_1i (self->shader, "tex", 0);
|
||||||
gst_gl_shader_set_uniform_matrix_4fv (self->shader,
|
gst_gl_shader_set_uniform_matrix_4fv (self->shader,
|
||||||
@@ -375,21 +381,57 @@ import_dmabuf (GtkClapperObject *self, guint n_planes,
|
|||||||
else
|
else
|
||||||
gtk_clapper_object_unbind_buffer (self);
|
gtk_clapper_object_unbind_buffer (self);
|
||||||
|
|
||||||
//gl->BindTexture (GL_TEXTURE_EXTERNAL_OES, 0);
|
|
||||||
gl->BindTexture (GL_TEXTURE_2D, 0);
|
gl->BindTexture (GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
// unbind the framebuffer so that you don't accidentally render to it
|
/* Replace external OES texture with new 2D one */
|
||||||
|
gl->DeleteTextures (1, &self->texture_id);
|
||||||
|
self->texture_id = new_texture_id;
|
||||||
|
|
||||||
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
||||||
|
gl->DeleteFramebuffers (1, &framebuffer);
|
||||||
|
|
||||||
texture = gdk_gl_texture_new (self->gdk_context, self->texture_id,
|
return TRUE;
|
||||||
gtk_widget_get_width (GTK_WIDGET (self->picture)),
|
}
|
||||||
gtk_widget_get_height (GTK_WIDGET (self->picture)),
|
|
||||||
NULL, NULL);
|
|
||||||
|
|
||||||
if (gl->GetError () != GL_NO_ERROR)
|
static GdkTexture *
|
||||||
GST_ERROR ("SOME ERROR!!!");
|
gtk_clapper_object_import_dmabuf (GtkClapperObject *self, gint *fds, gsize *offsets)
|
||||||
|
{
|
||||||
|
GdkTexture *texture;
|
||||||
|
guint tex_width, tex_height;
|
||||||
|
|
||||||
|
_gdk_gl_context_set_active (self, TRUE);
|
||||||
|
|
||||||
|
if (!_dmabuf_into_texture (self, fds, offsets)) {
|
||||||
|
_gdk_gl_context_set_active (self, FALSE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (self->texture_target) {
|
||||||
|
case GST_GL_TEXTURE_TARGET_2D:
|
||||||
|
tex_width = GST_VIDEO_INFO_WIDTH (&self->v_info);
|
||||||
|
tex_height = GST_VIDEO_INFO_HEIGHT (&self->v_info);
|
||||||
|
break;
|
||||||
|
case GST_GL_TEXTURE_TARGET_EXTERNAL_OES:{
|
||||||
|
GtkWidget *widget = (GtkWidget *) self->picture;
|
||||||
|
gint scale;
|
||||||
|
|
||||||
|
scale = gtk_widget_get_scale_factor (widget);
|
||||||
|
tex_width = gtk_widget_get_width (widget) * scale;
|
||||||
|
tex_height = gtk_widget_get_height (widget) * scale;
|
||||||
|
|
||||||
|
if (G_LIKELY (_ext_texture_into_2d (self, tex_width, tex_height)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
g_assert_not_reached ();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
texture = gdk_gl_texture_new (self->gdk_context,
|
||||||
|
self->texture_id, tex_width, tex_height, NULL, NULL);
|
||||||
|
|
||||||
gst_egl_image_unref (image);
|
|
||||||
_gdk_gl_context_set_active (self, FALSE);
|
_gdk_gl_context_set_active (self, FALSE);
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
@@ -467,7 +509,7 @@ obtain_texture_from_current_buffer (GtkClapperObject *self)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!((texture = import_dmabuf (self, n_planes, fds, offsets))))
|
if (!((texture = gtk_clapper_object_import_dmabuf (self, fds, offsets))))
|
||||||
GST_ERROR ("Could not create texture from DMABuf");
|
GST_ERROR ("Could not create texture from DMABuf");
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
@@ -713,23 +755,6 @@ gtk_clapper_object_get_widget (GtkClapperObject *self)
|
|||||||
return (GtkWidget *) self->picture;
|
return (GtkWidget *) self->picture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
wrap_current_gl (GstGLDisplay *display, GstGLPlatform platform, GstGLContext **context)
|
wrap_current_gl (GstGLDisplay *display, GstGLPlatform platform, GstGLContext **context)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user