mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-29 15:22:11 +02:00
Add new GStreamer plugin with custom video sink for Clapper video player. The main difference is that unlike the old one, this does not operate using `GtkGLArea` anymore, but processes and displays `GdkTextures` directly through `GtkPicture` widget. Also this one is installed like any other GStreamer plugin, thus can be used via `gst-launch-1.0` binary or even by other GTK4 apps if they wish to integrate it. In order to not depend on GL stuff at build time, this plugin uses seperate GModules called "importers" in order to import different kind of memories into GdkTexture. This allows expanding its capabilities further then we were able to do before.
133 lines
3.6 KiB
C
Vendored
133 lines
3.6 KiB
C
Vendored
/*
|
|
* GStreamer
|
|
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
|
* Copyright (C) 2015 Thibault Saunier <tsaunier@gnome.org>
|
|
* 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.
|
|
*/
|
|
|
|
#include "gstgtkutils.h"
|
|
|
|
struct invoke_context
|
|
{
|
|
GThreadFunc func;
|
|
gpointer data;
|
|
GMutex lock;
|
|
GCond cond;
|
|
gboolean fired;
|
|
|
|
gpointer res;
|
|
};
|
|
|
|
static gboolean
|
|
gst_gtk_invoke_func (struct invoke_context *info)
|
|
{
|
|
g_mutex_lock (&info->lock);
|
|
info->res = info->func (info->data);
|
|
info->fired = TRUE;
|
|
g_cond_signal (&info->cond);
|
|
g_mutex_unlock (&info->lock);
|
|
|
|
return G_SOURCE_REMOVE;
|
|
}
|
|
|
|
gpointer
|
|
gst_gtk_invoke_on_main (GThreadFunc func, gpointer data)
|
|
{
|
|
GMainContext *main_context = g_main_context_default ();
|
|
struct invoke_context info;
|
|
|
|
g_mutex_init (&info.lock);
|
|
g_cond_init (&info.cond);
|
|
info.fired = FALSE;
|
|
info.func = func;
|
|
info.data = data;
|
|
|
|
g_main_context_invoke (main_context, (GSourceFunc) gst_gtk_invoke_func,
|
|
&info);
|
|
|
|
g_mutex_lock (&info.lock);
|
|
while (!info.fired)
|
|
g_cond_wait (&info.cond, &info.lock);
|
|
g_mutex_unlock (&info.lock);
|
|
|
|
g_mutex_clear (&info.lock);
|
|
g_cond_clear (&info.cond);
|
|
|
|
return info.res;
|
|
}
|
|
|
|
/* For use with `GdkMemoryTexture` only! */
|
|
GdkMemoryFormat
|
|
gst_video_format_to_gdk_memory_format (GstVideoFormat format)
|
|
{
|
|
switch (format) {
|
|
case GST_VIDEO_FORMAT_RGBA64_LE:
|
|
case GST_VIDEO_FORMAT_RGBA64_BE:
|
|
return GDK_MEMORY_R16G16B16A16_PREMULTIPLIED;
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
return GDK_MEMORY_R8G8B8A8;
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
return GDK_MEMORY_B8G8R8A8;
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
return GDK_MEMORY_A8R8G8B8;
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
return GDK_MEMORY_A8B8G8R8;
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
return GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
return GDK_MEMORY_B8G8R8A8_PREMULTIPLIED;
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
return GDK_MEMORY_R8G8B8;
|
|
case GST_VIDEO_FORMAT_BGR:
|
|
return GDK_MEMORY_B8G8R8;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
/* This should never happen as long as above switch statement
|
|
* is updated when new formats are added to caps */
|
|
g_assert_not_reached ();
|
|
|
|
/* Fallback format */
|
|
return GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
|
|
}
|
|
|
|
GdkTexture *
|
|
gst_video_frame_into_gdk_texture (GstVideoFrame *frame)
|
|
{
|
|
GdkTexture *texture;
|
|
GBytes *bytes;
|
|
|
|
bytes = g_bytes_new_with_free_func (
|
|
GST_VIDEO_FRAME_PLANE_DATA (frame, 0),
|
|
GST_VIDEO_FRAME_HEIGHT (frame) * GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0),
|
|
(GDestroyNotify) gst_buffer_unref,
|
|
gst_buffer_ref (frame->buffer));
|
|
|
|
texture = gdk_memory_texture_new (
|
|
GST_VIDEO_FRAME_WIDTH (frame),
|
|
GST_VIDEO_FRAME_HEIGHT (frame),
|
|
gst_video_format_to_gdk_memory_format (GST_VIDEO_FRAME_FORMAT (frame)),
|
|
bytes,
|
|
GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0));
|
|
|
|
g_bytes_unref (bytes);
|
|
|
|
return texture;
|
|
}
|