Commit 2ee1caff authored by Guido Gunther's avatar Guido Gunther
Browse files

livi-gst-sink: Make code match file name

This make sure we don't have `gtk_` in backtraces although it's
internal code.

Code was originally taken from GTK4. It's license is preserved.
parent 1a357ce0
......@@ -117,12 +117,12 @@ gtk_gst_paintable_video_renderer_create_video_sink (GstPlayerVideoRenderer *rend
GstElement *sink, *glsinkbin;
GdkGLContext *ctx;
sink = g_object_new (GTK_TYPE_GST_SINK,
sink = g_object_new (LIVI_TYPE_GST_SINK,
"paintable", self,
"gl-context", self->context,
NULL);
g_object_get (GTK_GST_SINK (sink), "gl-context", &ctx, NULL);
g_object_get (LIVI_GST_SINK (sink), "gl-context", &ctx, NULL);
/* GL rendering won't work otherwise */
g_assert (self->context != NULL && ctx != NULL);
......
/*
* GStreamer
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
* Copyright 2021 Purism SPC
*
* 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.
* SPDX-License-Identifier: GPL-2.0-or-later
*
* 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.
* Authors: Matthew Waters <matthew@centricular.com>
* Benjamin Otte <otte@gnome.org>
* Guido Günther <agx@sigxcpu.org>
*
* 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.
* heavily based on gtk-gst-sink.c from GTK4 which in turn picked it
* up from GStreamer:
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
*/
#include "livi-gst-sink.h"
......@@ -36,9 +30,7 @@ enum {
};
struct _GtkGstSink
{
/* <private> */
struct _LiviGstSink {
GstVideoSink parent;
GstVideoInfo v_info;
......@@ -50,15 +42,15 @@ struct _GtkGstSink
};
GST_DEBUG_CATEGORY (gtk_debug_gst_sink);
#define GST_CAT_DEFAULT gtk_debug_gst_sink
GST_DEBUG_CATEGORY (livi_debug_gst_sink);
#define GST_CAT_DEFAULT livi_debug_gst_sink
#define FORMATS "{ BGRA, ARGB, RGBA, ABGR, RGB, BGR }"
#define NOGL_CAPS GST_VIDEO_CAPS_MAKE (FORMATS)
static GstStaticPadTemplate gtk_gst_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
static GstStaticPadTemplate livi_gst_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw(" GST_CAPS_FEATURE_MEMORY_GL_MEMORY "), "
......@@ -70,69 +62,60 @@ GST_STATIC_PAD_TEMPLATE ("sink",
"; " NOGL_CAPS)
);
G_DEFINE_TYPE_WITH_CODE (GtkGstSink, gtk_gst_sink,
G_DEFINE_TYPE_WITH_CODE (LiviGstSink, livi_gst_sink,
GST_TYPE_VIDEO_SINK,
GST_DEBUG_CATEGORY_INIT (gtk_debug_gst_sink,
"gtkgstsink", 0, "GtkGstMediaFile Video Sink"));
GST_DEBUG_CATEGORY_INIT (livi_debug_gst_sink,
"livistsink", 0, "Livi Video Sink"));
static GParamSpec *properties[N_PROPS] = { NULL, };
static void
gtk_gst_sink_get_times (GstBaseSink *bsink,
livi_gst_sink_get_times (GstBaseSink *bsink,
GstBuffer *buf,
GstClockTime *start,
GstClockTime *end)
{
GtkGstSink *gtk_sink;
LiviGstSink *livi_sink;
gtk_sink = GTK_GST_SINK (bsink);
livi_sink = LIVI_GST_SINK (bsink);
if (GST_BUFFER_TIMESTAMP_IS_VALID (buf))
{
if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
*start = GST_BUFFER_TIMESTAMP (buf);
if (GST_BUFFER_DURATION_IS_VALID (buf))
*end = *start + GST_BUFFER_DURATION (buf);
else
{
if (GST_VIDEO_INFO_FPS_N (&gtk_sink->v_info) > 0)
{
else{
if (GST_VIDEO_INFO_FPS_N (&livi_sink->v_info) > 0) {
*end = *start +
gst_util_uint64_scale_int (GST_SECOND,
GST_VIDEO_INFO_FPS_D (&gtk_sink->v_info),
GST_VIDEO_INFO_FPS_N (&gtk_sink->v_info));
GST_VIDEO_INFO_FPS_D (&livi_sink->v_info),
GST_VIDEO_INFO_FPS_N (&livi_sink->v_info));
}
}
}
}
static GstCaps *
gtk_gst_sink_get_caps (GstBaseSink *bsink,
livi_gst_sink_get_caps (GstBaseSink *bsink,
GstCaps *filter)
{
GtkGstSink *self = GTK_GST_SINK (bsink);
LiviGstSink *self = LIVI_GST_SINK (bsink);
GstCaps *tmp;
GstCaps *result;
if (self->gst_context)
{
if (self->gst_context) {
tmp = gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD (bsink));
}
else
{
}else {
tmp = gst_caps_from_string (NOGL_CAPS);
}
GST_DEBUG_OBJECT (self, "advertising own caps %" GST_PTR_FORMAT, tmp);
if (filter)
{
if (filter) {
GST_DEBUG_OBJECT (self, "intersecting with filter caps %" GST_PTR_FORMAT, filter);
result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (tmp);
}
else
{
}else {
result = tmp;
}
......@@ -142,10 +125,10 @@ gtk_gst_sink_get_caps (GstBaseSink *bsink,
}
static gboolean
gtk_gst_sink_set_caps (GstBaseSink *bsink,
livi_gst_sink_set_caps (GstBaseSink *bsink,
GstCaps *caps)
{
GtkGstSink *self = GTK_GST_SINK (bsink);
LiviGstSink *self = LIVI_GST_SINK (bsink);
GST_DEBUG_OBJECT (self, "set caps with %" GST_PTR_FORMAT, caps);
......@@ -156,24 +139,24 @@ gtk_gst_sink_set_caps (GstBaseSink *bsink,
}
static gboolean
gtk_gst_sink_query (GstBaseSink *bsink,
livi_gst_sink_query (GstBaseSink *bsink,
GstQuery *query)
{
GtkGstSink *self = GTK_GST_SINK (bsink);
LiviGstSink *self = LIVI_GST_SINK (bsink);
if (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT &&
self->gst_display != NULL &&
gst_gl_handle_context_query (GST_ELEMENT (self), query, self->gst_display, self->gst_context, self->gst_app_context))
return TRUE;
return GST_BASE_SINK_CLASS (gtk_gst_sink_parent_class)->query (bsink, query);
return GST_BASE_SINK_CLASS (livi_gst_sink_parent_class)->query (bsink, query);
}
static gboolean
gtk_gst_sink_propose_allocation (GstBaseSink *bsink,
livi_gst_sink_propose_allocation (GstBaseSink *bsink,
GstQuery *query)
{
GtkGstSink *self = GTK_GST_SINK (bsink);
LiviGstSink *self = LIVI_GST_SINK (bsink);
GstBufferPool *pool = NULL;
GstStructure *config;
GstCaps *caps;
......@@ -186,8 +169,7 @@ gtk_gst_sink_propose_allocation (GstBaseSink *bsink,
gst_query_parse_allocation (query, &caps, &need_pool);
if (caps == NULL)
{
if (caps == NULL) {
GST_DEBUG_OBJECT (bsink, "no caps specified");
return FALSE;
}
......@@ -195,8 +177,7 @@ gtk_gst_sink_propose_allocation (GstBaseSink *bsink,
if (!gst_caps_features_contains (gst_caps_get_features (caps, 0), GST_CAPS_FEATURE_MEMORY_GL_MEMORY))
return FALSE;
if (!gst_video_info_from_caps (&info, caps))
{
if (!gst_video_info_from_caps (&info, caps)) {
GST_DEBUG_OBJECT (self, "invalid caps specified");
return FALSE;
}
......@@ -204,8 +185,7 @@ gtk_gst_sink_propose_allocation (GstBaseSink *bsink,
/* the normal size of a frame */
size = info.size;
if (need_pool)
{
if (need_pool) {
GST_DEBUG_OBJECT (self, "create new pool");
pool = gst_gl_buffer_pool_new (self->gst_context);
......@@ -213,8 +193,7 @@ gtk_gst_sink_propose_allocation (GstBaseSink *bsink,
gst_buffer_pool_config_set_params (config, caps, size, 0, 0);
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_GL_SYNC_META);
if (!gst_buffer_pool_set_config (pool, config))
{
if (!gst_buffer_pool_set_config (pool, config)) {
GST_DEBUG_OBJECT (bsink, "failed setting config");
gst_object_unref (pool);
return FALSE;
......@@ -266,7 +245,7 @@ video_frame_free (GstVideoFrame *frame)
}
static GdkTexture *
gtk_gst_sink_texture_from_buffer (GtkGstSink *self,
livi_gst_sink_texture_from_buffer (LiviGstSink *self,
GstBuffer *buffer,
double *pixel_aspect_ratio)
{
......@@ -274,8 +253,7 @@ gtk_gst_sink_texture_from_buffer (GtkGstSink *self,
GdkTexture *texture;
if (self->gdk_context &&
gst_video_frame_map (frame, &self->v_info, buffer, GST_MAP_READ | GST_MAP_GL))
{
gst_video_frame_map (frame, &self->v_info, buffer, GST_MAP_READ | GST_MAP_GL)) {
GstGLSyncMeta *sync_meta;
sync_meta = gst_buffer_get_gl_sync_meta (buffer);
......@@ -292,9 +270,7 @@ gtk_gst_sink_texture_from_buffer (GtkGstSink *self,
frame);
*pixel_aspect_ratio = ((double) frame->info.par_n) / ((double) frame->info.par_d);
}
else if (gst_video_frame_map (frame, &self->v_info, buffer, GST_MAP_READ))
{
} else if (gst_video_frame_map (frame, &self->v_info, buffer, GST_MAP_READ)) {
GBytes *bytes;
bytes = g_bytes_new_with_free_func (frame->data[0],
......@@ -309,9 +285,7 @@ gtk_gst_sink_texture_from_buffer (GtkGstSink *self,
g_bytes_unref (bytes);
*pixel_aspect_ratio = ((double) frame->info.par_n) / ((double) frame->info.par_d);
}
else
{
} else {
GST_ERROR_OBJECT (self, "Could not convert buffer to texture.");
texture = NULL;
g_free (frame);
......@@ -321,22 +295,21 @@ gtk_gst_sink_texture_from_buffer (GtkGstSink *self,
}
static GstFlowReturn
gtk_gst_sink_show_frame (GstVideoSink *vsink,
livi_gst_sink_show_frame (GstVideoSink *vsink,
GstBuffer *buf)
{
GtkGstSink *self;
LiviGstSink *self;
GdkTexture *texture;
double pixel_aspect_ratio;
GST_TRACE ("rendering buffer:%p", buf);
self = GTK_GST_SINK (vsink);
self = LIVI_GST_SINK (vsink);
GST_OBJECT_LOCK (self);
texture = gtk_gst_sink_texture_from_buffer (self, buf, &pixel_aspect_ratio);
if (texture)
{
texture = livi_gst_sink_texture_from_buffer (self, buf, &pixel_aspect_ratio);
if (texture) {
gtk_gst_paintable_queue_set_texture (self->paintable, texture, pixel_aspect_ratio);
g_object_unref (texture);
}
......@@ -351,7 +324,7 @@ gtk_gst_sink_show_frame (GstVideoSink *vsink,
#define REACTIVATE_WGL_CONTEXT(ctx)
static gboolean
gtk_gst_sink_initialize_gl (GtkGstSink *self)
livi_gst_sink_initialize_gl (LiviGstSink *self)
{
GdkDisplay *display;
GError *error = NULL;
......@@ -365,8 +338,7 @@ gtk_gst_sink_initialize_gl (GtkGstSink *self)
HANDLE_EXTERNAL_WGL_MAKE_CURRENT (self->gdk_context);
gdk_gl_context_make_current (self->gdk_context);
if (GDK_IS_WAYLAND_DISPLAY (display))
{
if (GDK_IS_WAYLAND_DISPLAY (display)) {
platform = GST_GL_PLATFORM_EGL;
GST_DEBUG_OBJECT (self, "got EGL on Wayland!");
......@@ -374,22 +346,17 @@ gtk_gst_sink_initialize_gl (GtkGstSink *self)
gl_api = gst_gl_context_get_current_gl_api (platform, NULL, NULL);
gl_handle = gst_gl_context_get_current_gl_context (platform);
if (gl_handle)
{
if (gl_handle) {
struct wl_display *wayland_display;
wayland_display = gdk_wayland_display_get_wl_display (display);
self->gst_display = GST_GL_DISPLAY (gst_gl_display_wayland_new_with_display (wayland_display));
self->gst_app_context = gst_gl_context_new_wrapped (self->gst_display, gl_handle, platform, gl_api);
}
else
{
}else {
GST_ERROR_OBJECT (self, "Failed to get handle from GdkGLContext, not using Wayland EGL");
return FALSE;
}
}
else
{
}else {
GST_INFO_OBJECT (self, "Unsupported GDK display %s for GL", G_OBJECT_TYPE_NAME (display));
return FALSE;
}
......@@ -398,25 +365,21 @@ gtk_gst_sink_initialize_gl (GtkGstSink *self)
gst_gl_context_activate (self->gst_app_context, TRUE);
if (!gst_gl_context_fill_info (self->gst_app_context, &error))
{
if (!gst_gl_context_fill_info (self->gst_app_context, &error)) {
GST_ERROR_OBJECT (self, "failed to retrieve GDK context info: %s", error->message);
g_clear_error (&error);
g_clear_object (&self->gst_app_context);
g_clear_object (&self->gst_display);
HANDLE_EXTERNAL_WGL_MAKE_CURRENT (self->gdk_context);
return FALSE;
}
else
{
}else {
DEACTIVATE_WGL_CONTEXT (self->gdk_context);
gst_gl_context_activate (self->gst_app_context, FALSE);
}
succeeded = gst_gl_display_create_context (self->gst_display, self->gst_app_context, &self->gst_context, &error);
if (!succeeded)
{
if (!succeeded) {
GST_ERROR_OBJECT (self, "Couldn't create GL context: %s", error->message);
g_error_free (error);
g_clear_object (&self->gst_app_context);
......@@ -429,13 +392,13 @@ gtk_gst_sink_initialize_gl (GtkGstSink *self)
}
static void
gtk_gst_sink_set_property (GObject *object,
livi_gst_sink_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkGstSink *self = GTK_GST_SINK (object);
LiviGstSink *self = LIVI_GST_SINK (object);
switch (prop_id)
{
......@@ -447,7 +410,7 @@ gtk_gst_sink_set_property (GObject *object,
case PROP_GL_CONTEXT:
self->gdk_context = g_value_dup_object (value);
if (self->gdk_context != NULL && !gtk_gst_sink_initialize_gl (self))
if (self->gdk_context != NULL && !livi_gst_sink_initialize_gl (self))
g_clear_object (&self->gdk_context);
break;
......@@ -458,12 +421,12 @@ gtk_gst_sink_set_property (GObject *object,
}
static void
gtk_gst_sink_get_property (GObject *object,
livi_gst_sink_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkGstSink *self = GTK_GST_SINK (object);
LiviGstSink *self = LIVI_GST_SINK (object);
switch (prop_id)
{
......@@ -481,40 +444,40 @@ gtk_gst_sink_get_property (GObject *object,
}
static void
gtk_gst_sink_dispose (GObject *object)
livi_gst_sink_dispose (GObject *object)
{
GtkGstSink *self = GTK_GST_SINK (object);
LiviGstSink *self = LIVI_GST_SINK (object);
g_clear_object (&self->paintable);
g_clear_object (&self->gst_app_context);
g_clear_object (&self->gst_display);
g_clear_object (&self->gdk_context);
G_OBJECT_CLASS (gtk_gst_sink_parent_class)->dispose (object);
G_OBJECT_CLASS (livi_gst_sink_parent_class)->dispose (object);
}
static void
gtk_gst_sink_class_init (GtkGstSinkClass * klass)
livi_gst_sink_class_init (LiviGstSinkClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
GstBaseSinkClass *gstbasesink_class = GST_BASE_SINK_CLASS (klass);
GstVideoSinkClass *gstvideosink_class = GST_VIDEO_SINK_CLASS (klass);
gobject_class->set_property = gtk_gst_sink_set_property;
gobject_class->get_property = gtk_gst_sink_get_property;
gobject_class->dispose = gtk_gst_sink_dispose;
gobject_class->set_property = livi_gst_sink_set_property;
gobject_class->get_property = livi_gst_sink_get_property;
gobject_class->dispose = livi_gst_sink_dispose;
gstbasesink_class->set_caps = gtk_gst_sink_set_caps;
gstbasesink_class->get_times = gtk_gst_sink_get_times;
gstbasesink_class->query = gtk_gst_sink_query;
gstbasesink_class->propose_allocation = gtk_gst_sink_propose_allocation;
gstbasesink_class->get_caps = gtk_gst_sink_get_caps;
gstbasesink_class->set_caps = livi_gst_sink_set_caps;
gstbasesink_class->get_times = livi_gst_sink_get_times;
gstbasesink_class->query = livi_gst_sink_query;
gstbasesink_class->propose_allocation = livi_gst_sink_propose_allocation;
gstbasesink_class->get_caps = livi_gst_sink_get_caps;
gstvideosink_class->show_frame = gtk_gst_sink_show_frame;
gstvideosink_class->show_frame = livi_gst_sink_show_frame;
/**
* GtkGstSink:paintable:
* LiviGstSink:paintable:
*
* The paintable that provides the picture for this sink.
*/
......@@ -526,7 +489,7 @@ gtk_gst_sink_class_init (GtkGstSinkClass * klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
/**
* GtkGstSink:gl-context:
* LiviGstSink:gl-context:
*
* The #GdkGLContext to use for GL rendering.
*/
......@@ -540,17 +503,16 @@ gtk_gst_sink_class_init (GtkGstSinkClass * klass)
g_object_class_install_properties (gobject_class, N_PROPS, properties);
gst_element_class_set_metadata (gstelement_class,
"GtkMediaStream Video Sink",
"Sink/Video", "The video sink used by GtkMediaStream",
"µPlayer Video Sink",
"Sink/Video", "The video sink used by µPlayer",
"Matthew Waters <matthew@centricular.com>, "
"Benjamin Otte <otte@gnome.org>");
gst_element_class_add_static_pad_template (gstelement_class,
&gtk_gst_sink_template);
&livi_gst_sink_template);
}
static void
gtk_gst_sink_init (GtkGstSink * gtk_sink)
livi_gst_sink_init (LiviGstSink *self)
{
}
/*
* GStreamer
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
* Copyright 2021 Purism SPC
*
* 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.
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
......@@ -30,8 +16,8 @@
G_BEGIN_DECLS
#define GTK_TYPE_GST_SINK (gtk_gst_sink_get_type())
#define LIVI_TYPE_GST_SINK (livi_gst_sink_get_type ())
G_DECLARE_FINAL_TYPE (GtkGstSink, gtk_gst_sink, GTK, GST_SINK, GstVideoSink)
G_DECLARE_FINAL_TYPE (LiviGstSink, livi_gst_sink, LIVI, GST_SINK, GstVideoSink)
G_END_DECLS
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment