2015-07-16 19:59:59 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2015 Matthew Waters <matthew@centricular.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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtkgstsink
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: GstGtkBaseSink
|
2015-07-16 19:59:59 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstgtkbasesink.h"
|
2015-09-24 09:37:04 +00:00
|
|
|
#include "gstgtkutils.h"
|
2015-07-16 19:59:59 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY (gst_debug_gtk_base_sink);
|
|
|
|
#define GST_CAT_DEFAULT gst_debug_gtk_base_sink
|
|
|
|
|
|
|
|
#define DEFAULT_FORCE_ASPECT_RATIO TRUE
|
2021-05-07 16:19:55 +00:00
|
|
|
#define DEFAULT_DISPLAY_PAR_N 0
|
|
|
|
#define DEFAULT_DISPLAY_PAR_D 1
|
2021-05-07 16:22:06 +00:00
|
|
|
#define DEFAULT_VIDEO_PAR_N 0
|
|
|
|
#define DEFAULT_VIDEO_PAR_D 1
|
2015-07-16 19:59:59 +00:00
|
|
|
#define DEFAULT_IGNORE_ALPHA TRUE
|
|
|
|
|
|
|
|
static void gst_gtk_base_sink_finalize (GObject * object);
|
|
|
|
static void gst_gtk_base_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * param_spec);
|
|
|
|
static void gst_gtk_base_sink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * param_spec);
|
|
|
|
|
|
|
|
static gboolean gst_gtk_base_sink_start (GstBaseSink * bsink);
|
2015-09-19 09:46:37 +00:00
|
|
|
static gboolean gst_gtk_base_sink_stop (GstBaseSink * bsink);
|
2015-07-16 19:59:59 +00:00
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_gtk_base_sink_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
|
|
|
|
|
|
|
static void gst_gtk_base_sink_get_times (GstBaseSink * bsink, GstBuffer * buf,
|
|
|
|
GstClockTime * start, GstClockTime * end);
|
|
|
|
static gboolean gst_gtk_base_sink_set_caps (GstBaseSink * bsink,
|
|
|
|
GstCaps * caps);
|
|
|
|
static GstFlowReturn gst_gtk_base_sink_show_frame (GstVideoSink * bsink,
|
|
|
|
GstBuffer * buf);
|
|
|
|
|
2015-08-11 11:34:59 +00:00
|
|
|
static void
|
|
|
|
gst_gtk_base_sink_navigation_interface_init (GstNavigationInterface * iface);
|
|
|
|
|
2015-07-16 19:59:59 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_WIDGET,
|
|
|
|
PROP_FORCE_ASPECT_RATIO,
|
|
|
|
PROP_PIXEL_ASPECT_RATIO,
|
2021-05-07 16:22:06 +00:00
|
|
|
PROP_VIDEO_ASPECT_RATIO_OVERRIDE,
|
2015-07-16 19:59:59 +00:00
|
|
|
PROP_IGNORE_ALPHA,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define gst_gtk_base_sink_parent_class parent_class
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstGtkBaseSink, gst_gtk_base_sink,
|
2015-08-11 11:34:59 +00:00
|
|
|
GST_TYPE_VIDEO_SINK,
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_NAVIGATION,
|
|
|
|
gst_gtk_base_sink_navigation_interface_init);
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_debug_gtk_base_sink,
|
2015-07-16 19:59:59 +00:00
|
|
|
"gtkbasesink", 0, "Gtk Video Sink base class"));
|
|
|
|
|
2015-09-24 08:51:31 +00:00
|
|
|
|
2015-07-16 19:59:59 +00:00
|
|
|
static void
|
|
|
|
gst_gtk_base_sink_class_init (GstGtkBaseSinkClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
GstBaseSinkClass *gstbasesink_class;
|
|
|
|
GstVideoSinkClass *gstvideosink_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
gstbasesink_class = (GstBaseSinkClass *) klass;
|
|
|
|
gstvideosink_class = (GstVideoSinkClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_gtk_base_sink_set_property;
|
|
|
|
gobject_class->get_property = gst_gtk_base_sink_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_WIDGET,
|
|
|
|
g_param_spec_object ("widget", "Gtk Widget",
|
2015-07-17 19:57:37 +00:00
|
|
|
"The GtkWidget to place in the widget hierarchy "
|
|
|
|
"(must only be get from the GTK main thread)",
|
2021-10-11 12:27:24 +00:00
|
|
|
GTK_TYPE_WIDGET,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS |
|
|
|
|
GST_PARAM_DOC_SHOW_DEFAULT));
|
2015-07-16 19:59:59 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO,
|
|
|
|
g_param_spec_boolean ("force-aspect-ratio",
|
|
|
|
"Force aspect ratio",
|
|
|
|
"When enabled, scaling will respect original aspect ratio",
|
|
|
|
DEFAULT_FORCE_ASPECT_RATIO,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PIXEL_ASPECT_RATIO,
|
|
|
|
gst_param_spec_fraction ("pixel-aspect-ratio", "Pixel Aspect Ratio",
|
2021-05-11 09:28:57 +00:00
|
|
|
"The pixel aspect ratio of the device",
|
|
|
|
0, G_MAXINT, G_MAXINT, 1, DEFAULT_DISPLAY_PAR_N,
|
|
|
|
DEFAULT_DISPLAY_PAR_D, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-07-16 19:59:59 +00:00
|
|
|
|
2021-05-07 16:22:06 +00:00
|
|
|
/**
|
|
|
|
* GstGtkBaseSink:video-aspect-ratio-override:
|
|
|
|
*
|
|
|
|
* The pixel aspect ratio of the video (0/1 = follow stream)
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_VIDEO_ASPECT_RATIO_OVERRIDE,
|
|
|
|
gst_param_spec_fraction ("video-aspect-ratio-override",
|
|
|
|
"Video Pixel Aspect Ratio",
|
|
|
|
"The pixel aspect ratio of the video (0/1 = follow stream)", 0,
|
|
|
|
G_MAXINT, G_MAXINT, 1, DEFAULT_VIDEO_PAR_N, DEFAULT_VIDEO_PAR_D,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2015-07-16 19:59:59 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_IGNORE_ALPHA,
|
|
|
|
g_param_spec_boolean ("ignore-alpha", "Ignore Alpha",
|
|
|
|
"When enabled, alpha will be ignored and converted to black",
|
|
|
|
DEFAULT_IGNORE_ALPHA, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_gtk_base_sink_finalize;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_gtk_base_sink_change_state;
|
|
|
|
gstbasesink_class->set_caps = gst_gtk_base_sink_set_caps;
|
|
|
|
gstbasesink_class->get_times = gst_gtk_base_sink_get_times;
|
|
|
|
gstbasesink_class->start = gst_gtk_base_sink_start;
|
2015-09-19 09:46:37 +00:00
|
|
|
gstbasesink_class->stop = gst_gtk_base_sink_stop;
|
2015-07-16 19:59:59 +00:00
|
|
|
|
|
|
|
gstvideosink_class->show_frame = gst_gtk_base_sink_show_frame;
|
2020-06-20 23:34:43 +00:00
|
|
|
|
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_GTK_BASE_SINK, 0);
|
2015-07-16 19:59:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gtk_base_sink_init (GstGtkBaseSink * gtk_sink)
|
|
|
|
{
|
|
|
|
gtk_sink->force_aspect_ratio = DEFAULT_FORCE_ASPECT_RATIO;
|
2021-05-07 16:19:55 +00:00
|
|
|
gtk_sink->par_n = DEFAULT_DISPLAY_PAR_N;
|
|
|
|
gtk_sink->par_d = DEFAULT_DISPLAY_PAR_D;
|
2021-05-07 16:22:06 +00:00
|
|
|
gtk_sink->video_par_n = DEFAULT_VIDEO_PAR_N;
|
|
|
|
gtk_sink->video_par_d = DEFAULT_VIDEO_PAR_D;
|
2015-07-16 19:59:59 +00:00
|
|
|
gtk_sink->ignore_alpha = DEFAULT_IGNORE_ALPHA;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gtk_base_sink_finalize (GObject * object)
|
|
|
|
{
|
2016-02-16 08:59:13 +00:00
|
|
|
GstGtkBaseSink *gtk_sink = GST_GTK_BASE_SINK (object);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (gtk_sink);
|
|
|
|
if (gtk_sink->window && gtk_sink->window_destroy_id)
|
|
|
|
g_signal_handler_disconnect (gtk_sink->window, gtk_sink->window_destroy_id);
|
|
|
|
if (gtk_sink->widget && gtk_sink->widget_destroy_id)
|
|
|
|
g_signal_handler_disconnect (gtk_sink->widget, gtk_sink->widget_destroy_id);
|
2015-07-16 19:59:59 +00:00
|
|
|
|
|
|
|
g_clear_object (>k_sink->widget);
|
2016-02-16 08:59:13 +00:00
|
|
|
GST_OBJECT_UNLOCK (gtk_sink);
|
2015-07-16 19:59:59 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
widget_destroy_cb (GtkWidget * widget, GstGtkBaseSink * gtk_sink)
|
|
|
|
{
|
|
|
|
GST_OBJECT_LOCK (gtk_sink);
|
2015-10-16 15:40:50 +00:00
|
|
|
g_clear_object (>k_sink->widget);
|
|
|
|
GST_OBJECT_UNLOCK (gtk_sink);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_destroy_cb (GtkWidget * widget, GstGtkBaseSink * gtk_sink)
|
|
|
|
{
|
|
|
|
GST_OBJECT_LOCK (gtk_sink);
|
|
|
|
gtk_sink->window = NULL;
|
2015-07-16 19:59:59 +00:00
|
|
|
GST_OBJECT_UNLOCK (gtk_sink);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkGstBaseWidget *
|
|
|
|
gst_gtk_base_sink_get_widget (GstGtkBaseSink * gtk_sink)
|
|
|
|
{
|
|
|
|
if (gtk_sink->widget != NULL)
|
2021-05-04 17:27:30 +00:00
|
|
|
return g_object_ref (gtk_sink->widget);
|
2015-07-16 19:59:59 +00:00
|
|
|
|
|
|
|
/* Ensure GTK is initialized, this has no side effect if it was already
|
|
|
|
* initialized. Also, we do that lazily, so the application can be first */
|
|
|
|
if (!gtk_init_check (NULL, NULL)) {
|
2021-10-11 08:22:41 +00:00
|
|
|
GST_INFO_OBJECT (gtk_sink, "Could not ensure GTK initialization.");
|
2015-07-16 19:59:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (GST_GTK_BASE_SINK_GET_CLASS (gtk_sink)->create_widget);
|
|
|
|
gtk_sink->widget = (GtkGstBaseWidget *)
|
|
|
|
GST_GTK_BASE_SINK_GET_CLASS (gtk_sink)->create_widget ();
|
|
|
|
|
|
|
|
gtk_sink->bind_aspect_ratio =
|
|
|
|
g_object_bind_property (gtk_sink, "force-aspect-ratio", gtk_sink->widget,
|
|
|
|
"force-aspect-ratio", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
|
|
gtk_sink->bind_pixel_aspect_ratio =
|
|
|
|
g_object_bind_property (gtk_sink, "pixel-aspect-ratio", gtk_sink->widget,
|
|
|
|
"pixel-aspect-ratio", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2021-05-07 16:22:06 +00:00
|
|
|
gtk_sink->bind_video_aspect_ratio =
|
|
|
|
g_object_bind_property (gtk_sink, "video-aspect-ratio-override",
|
|
|
|
gtk_sink->widget, "video-aspect-ratio-override",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2015-07-16 19:59:59 +00:00
|
|
|
gtk_sink->bind_ignore_alpha =
|
|
|
|
g_object_bind_property (gtk_sink, "ignore-alpha", gtk_sink->widget,
|
|
|
|
"ignore-alpha", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
|
|
|
|
|
|
/* Take the floating ref, other wise the destruction of the container will
|
2019-09-02 12:27:35 +00:00
|
|
|
* make this widget disappear possibly before we are done. */
|
2022-12-26 14:00:18 +00:00
|
|
|
g_object_ref_sink (gtk_sink->widget);
|
|
|
|
|
2016-02-16 08:59:13 +00:00
|
|
|
gtk_sink->widget_destroy_id = g_signal_connect (gtk_sink->widget, "destroy",
|
2015-07-16 19:59:59 +00:00
|
|
|
G_CALLBACK (widget_destroy_cb), gtk_sink);
|
|
|
|
|
2015-08-11 11:34:59 +00:00
|
|
|
/* back pointer */
|
|
|
|
gtk_gst_base_widget_set_element (GTK_GST_BASE_WIDGET (gtk_sink->widget),
|
|
|
|
GST_ELEMENT (gtk_sink));
|
|
|
|
|
2021-05-04 17:27:30 +00:00
|
|
|
return g_object_ref (gtk_sink->widget);
|
2015-07-16 19:59:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 22:27:19 +00:00
|
|
|
GtkWidget *
|
|
|
|
gst_gtk_base_sink_acquire_widget (GstGtkBaseSink * gtk_sink)
|
|
|
|
{
|
|
|
|
gpointer widget = NULL;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (gtk_sink);
|
|
|
|
if (gtk_sink->widget != NULL)
|
2021-05-04 17:27:30 +00:00
|
|
|
widget = g_object_ref (gtk_sink->widget);
|
2020-09-03 22:27:19 +00:00
|
|
|
GST_OBJECT_UNLOCK (gtk_sink);
|
|
|
|
|
|
|
|
if (!widget)
|
|
|
|
widget =
|
|
|
|
gst_gtk_invoke_on_main ((GThreadFunc) gst_gtk_base_sink_get_widget,
|
|
|
|
gtk_sink);
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2015-07-16 19:59:59 +00:00
|
|
|
static void
|
|
|
|
gst_gtk_base_sink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstGtkBaseSink *gtk_sink = GST_GTK_BASE_SINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_WIDGET:
|
2015-09-24 08:51:31 +00:00
|
|
|
{
|
2021-05-04 17:27:30 +00:00
|
|
|
g_value_take_object (value, gst_gtk_base_sink_acquire_widget (gtk_sink));
|
2015-07-16 19:59:59 +00:00
|
|
|
break;
|
2015-09-24 08:51:31 +00:00
|
|
|
}
|
2015-07-16 19:59:59 +00:00
|
|
|
case PROP_FORCE_ASPECT_RATIO:
|
|
|
|
g_value_set_boolean (value, gtk_sink->force_aspect_ratio);
|
|
|
|
break;
|
|
|
|
case PROP_PIXEL_ASPECT_RATIO:
|
|
|
|
gst_value_set_fraction (value, gtk_sink->par_n, gtk_sink->par_d);
|
|
|
|
break;
|
2021-05-07 16:22:06 +00:00
|
|
|
case PROP_VIDEO_ASPECT_RATIO_OVERRIDE:
|
|
|
|
gst_value_set_fraction (value, gtk_sink->video_par_n,
|
|
|
|
gtk_sink->video_par_d);
|
|
|
|
break;
|
2015-07-16 19:59:59 +00:00
|
|
|
case PROP_IGNORE_ALPHA:
|
|
|
|
g_value_set_boolean (value, gtk_sink->ignore_alpha);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gtk_base_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstGtkBaseSink *gtk_sink = GST_GTK_BASE_SINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_FORCE_ASPECT_RATIO:
|
|
|
|
gtk_sink->force_aspect_ratio = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case PROP_PIXEL_ASPECT_RATIO:
|
|
|
|
gtk_sink->par_n = gst_value_get_fraction_numerator (value);
|
|
|
|
gtk_sink->par_d = gst_value_get_fraction_denominator (value);
|
|
|
|
break;
|
2021-05-07 16:22:06 +00:00
|
|
|
case PROP_VIDEO_ASPECT_RATIO_OVERRIDE:
|
|
|
|
gtk_sink->video_par_n = gst_value_get_fraction_numerator (value);
|
|
|
|
gtk_sink->video_par_d = gst_value_get_fraction_denominator (value);
|
|
|
|
break;
|
2015-07-16 19:59:59 +00:00
|
|
|
case PROP_IGNORE_ALPHA:
|
|
|
|
gtk_sink->ignore_alpha = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-11 11:34:59 +00:00
|
|
|
static void
|
|
|
|
gst_gtk_base_sink_navigation_send_event (GstNavigation * navigation,
|
2022-02-14 15:08:23 +00:00
|
|
|
GstEvent * event)
|
2015-08-11 11:34:59 +00:00
|
|
|
{
|
|
|
|
GstGtkBaseSink *sink = GST_GTK_BASE_SINK (navigation);
|
|
|
|
GstPad *pad;
|
2021-05-05 12:28:15 +00:00
|
|
|
gdouble x, y;
|
|
|
|
|
2022-02-14 15:08:23 +00:00
|
|
|
event = gst_event_make_writable (event);
|
|
|
|
|
|
|
|
if (gst_navigation_event_get_coordinates (event, &x, &y)) {
|
2021-05-05 12:28:15 +00:00
|
|
|
GtkGstBaseWidget *widget = gst_gtk_base_sink_get_widget (sink);
|
|
|
|
gdouble stream_x, stream_y;
|
|
|
|
|
2021-10-11 08:22:41 +00:00
|
|
|
if (widget == NULL) {
|
|
|
|
GST_ERROR_OBJECT (sink, "Could not ensure GTK initialization.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-05 12:28:15 +00:00
|
|
|
gtk_gst_base_widget_display_size_to_stream_size (widget,
|
|
|
|
x, y, &stream_x, &stream_y);
|
2022-02-14 15:08:23 +00:00
|
|
|
gst_navigation_event_set_coordinates (event, stream_x, stream_y);
|
2022-12-26 14:00:18 +00:00
|
|
|
g_object_unref (widget);
|
2021-05-05 12:28:15 +00:00
|
|
|
}
|
2015-08-11 11:34:59 +00:00
|
|
|
|
|
|
|
pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (sink));
|
|
|
|
|
2022-02-14 15:08:23 +00:00
|
|
|
GST_TRACE_OBJECT (sink, "navigation event %" GST_PTR_FORMAT,
|
|
|
|
gst_event_get_structure (event));
|
2015-08-11 11:34:59 +00:00
|
|
|
|
2016-03-09 23:44:57 +00:00
|
|
|
if (GST_IS_PAD (pad) && GST_IS_EVENT (event)) {
|
|
|
|
if (!gst_pad_send_event (pad, gst_event_ref (event))) {
|
|
|
|
/* If upstream didn't handle the event we'll post a message with it
|
|
|
|
* for the application in case it wants to do something with it */
|
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (sink),
|
|
|
|
gst_navigation_message_new_event (GST_OBJECT_CAST (sink), event));
|
|
|
|
}
|
|
|
|
gst_event_unref (event);
|
2015-09-28 14:25:00 +00:00
|
|
|
gst_object_unref (pad);
|
|
|
|
}
|
2015-08-11 11:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gtk_base_sink_navigation_interface_init (GstNavigationInterface * iface)
|
|
|
|
{
|
2022-02-14 15:08:23 +00:00
|
|
|
iface->send_event_simple = gst_gtk_base_sink_navigation_send_event;
|
2015-08-11 11:34:59 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 19:59:59 +00:00
|
|
|
static gboolean
|
2015-09-24 08:51:31 +00:00
|
|
|
gst_gtk_base_sink_start_on_main (GstBaseSink * bsink)
|
2015-07-16 19:59:59 +00:00
|
|
|
{
|
|
|
|
GstGtkBaseSink *gst_sink = GST_GTK_BASE_SINK (bsink);
|
|
|
|
GstGtkBaseSinkClass *klass = GST_GTK_BASE_SINK_GET_CLASS (bsink);
|
|
|
|
GtkWidget *toplevel;
|
2022-12-26 14:00:18 +00:00
|
|
|
GtkGstBaseWidget *widget;
|
2015-07-16 19:59:59 +00:00
|
|
|
|
2022-12-26 14:00:18 +00:00
|
|
|
widget = gst_gtk_base_sink_get_widget (gst_sink);
|
|
|
|
if (!widget) {
|
2021-10-11 08:22:41 +00:00
|
|
|
GST_ERROR_OBJECT (bsink, "Could not ensure GTK initialization.");
|
2015-07-16 19:59:59 +00:00
|
|
|
return FALSE;
|
2021-10-11 08:22:41 +00:00
|
|
|
}
|
2015-07-16 19:59:59 +00:00
|
|
|
|
|
|
|
/* After this point, gtk_sink->widget will always be set */
|
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (gst_sink->widget));
|
|
|
|
if (!gtk_widget_is_toplevel (toplevel)) {
|
|
|
|
/* sanity check */
|
|
|
|
g_assert (klass->window_title);
|
|
|
|
|
|
|
|
/* User did not add widget its own UI, let's popup a new GtkWindow to
|
|
|
|
* make gst-launch-1.0 work. */
|
2015-09-19 09:46:37 +00:00
|
|
|
gst_sink->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (gst_sink->window), 640, 480);
|
|
|
|
gtk_window_set_title (GTK_WINDOW (gst_sink->window), klass->window_title);
|
|
|
|
gtk_container_add (GTK_CONTAINER (gst_sink->window), toplevel);
|
2016-02-16 08:59:13 +00:00
|
|
|
gst_sink->window_destroy_id = g_signal_connect (gst_sink->window, "destroy",
|
2015-10-16 15:40:50 +00:00
|
|
|
G_CALLBACK (window_destroy_cb), gst_sink);
|
2015-09-19 09:46:37 +00:00
|
|
|
}
|
|
|
|
|
2022-12-26 14:00:18 +00:00
|
|
|
g_object_unref (widget);
|
|
|
|
|
2015-09-19 09:46:37 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2015-09-24 08:51:31 +00:00
|
|
|
gst_gtk_base_sink_start (GstBaseSink * bsink)
|
|
|
|
{
|
2015-09-24 09:37:04 +00:00
|
|
|
return ! !gst_gtk_invoke_on_main ((GThreadFunc)
|
|
|
|
gst_gtk_base_sink_start_on_main, bsink);
|
2015-09-24 08:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gtk_base_sink_stop_on_main (GstBaseSink * bsink)
|
2015-09-19 09:46:37 +00:00
|
|
|
{
|
|
|
|
GstGtkBaseSink *gst_sink = GST_GTK_BASE_SINK (bsink);
|
|
|
|
|
|
|
|
if (gst_sink->window) {
|
|
|
|
gtk_widget_destroy (gst_sink->window);
|
|
|
|
gst_sink->window = NULL;
|
|
|
|
gst_sink->widget = NULL;
|
2015-07-16 19:59:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-09-23 09:42:51 +00:00
|
|
|
static gboolean
|
2015-09-24 08:51:31 +00:00
|
|
|
gst_gtk_base_sink_stop (GstBaseSink * bsink)
|
2015-09-23 09:42:51 +00:00
|
|
|
{
|
2015-09-24 16:51:39 +00:00
|
|
|
GstGtkBaseSink *gst_sink = GST_GTK_BASE_SINK (bsink);
|
|
|
|
|
|
|
|
if (gst_sink->window)
|
|
|
|
return ! !gst_gtk_invoke_on_main ((GThreadFunc)
|
|
|
|
gst_gtk_base_sink_stop_on_main, bsink);
|
|
|
|
|
|
|
|
return TRUE;
|
2015-09-24 08:51:31 +00:00
|
|
|
}
|
2015-09-23 09:42:51 +00:00
|
|
|
|
2015-09-24 08:51:31 +00:00
|
|
|
static void
|
2015-09-24 13:51:28 +00:00
|
|
|
gst_gtk_widget_show_all_and_unref (GtkWidget * widget)
|
2015-09-24 08:51:31 +00:00
|
|
|
{
|
|
|
|
gtk_widget_show_all (widget);
|
|
|
|
g_object_unref (widget);
|
2015-09-23 09:42:51 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 19:59:59 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_gtk_base_sink_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstGtkBaseSink *gtk_sink = GST_GTK_BASE_SINK (element);
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (element, "changing state: %s => %s",
|
|
|
|
gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)),
|
|
|
|
gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition)));
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
2015-09-23 09:42:51 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2015-09-24 08:51:31 +00:00
|
|
|
{
|
|
|
|
GtkWindow *window = NULL;
|
|
|
|
|
2015-09-23 09:42:51 +00:00
|
|
|
GST_OBJECT_LOCK (gtk_sink);
|
|
|
|
if (gtk_sink->window)
|
2018-02-21 10:12:10 +00:00
|
|
|
window = g_object_ref (GTK_WINDOW (gtk_sink->window));
|
2015-09-23 09:42:51 +00:00
|
|
|
GST_OBJECT_UNLOCK (gtk_sink);
|
2015-09-24 08:51:31 +00:00
|
|
|
|
|
|
|
if (window)
|
2015-09-24 13:51:28 +00:00
|
|
|
gst_gtk_invoke_on_main ((GThreadFunc) gst_gtk_widget_show_all_and_unref,
|
|
|
|
window);
|
2015-09-24 08:51:31 +00:00
|
|
|
|
2015-09-23 09:42:51 +00:00
|
|
|
break;
|
2015-09-24 08:51:31 +00:00
|
|
|
}
|
2015-07-16 19:59:59 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
GST_OBJECT_LOCK (gtk_sink);
|
|
|
|
if (gtk_sink->widget)
|
|
|
|
gtk_gst_base_widget_set_buffer (gtk_sink->widget, NULL);
|
|
|
|
GST_OBJECT_UNLOCK (gtk_sink);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gtk_base_sink_get_times (GstBaseSink * bsink, GstBuffer * buf,
|
|
|
|
GstClockTime * start, GstClockTime * end)
|
|
|
|
{
|
|
|
|
GstGtkBaseSink *gtk_sink;
|
|
|
|
|
|
|
|
gtk_sink = GST_GTK_BASE_SINK (bsink);
|
|
|
|
|
|
|
|
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 (>k_sink->v_info) > 0) {
|
|
|
|
*end = *start +
|
|
|
|
gst_util_uint64_scale_int (GST_SECOND,
|
|
|
|
GST_VIDEO_INFO_FPS_D (>k_sink->v_info),
|
|
|
|
GST_VIDEO_INFO_FPS_N (>k_sink->v_info));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_gtk_base_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstGtkBaseSink *gtk_sink = GST_GTK_BASE_SINK (bsink);
|
|
|
|
|
|
|
|
GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (>k_sink->v_info, caps))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (gtk_sink);
|
|
|
|
|
|
|
|
if (gtk_sink->widget == NULL) {
|
|
|
|
GST_OBJECT_UNLOCK (gtk_sink);
|
|
|
|
GST_ELEMENT_ERROR (gtk_sink, RESOURCE, NOT_FOUND,
|
|
|
|
("%s", "Output widget was destroyed"), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-09-24 13:51:28 +00:00
|
|
|
if (!gtk_gst_base_widget_set_format (gtk_sink->widget, >k_sink->v_info)) {
|
|
|
|
GST_OBJECT_UNLOCK (gtk_sink);
|
2015-07-16 19:59:59 +00:00
|
|
|
return FALSE;
|
2015-09-24 13:51:28 +00:00
|
|
|
}
|
2015-07-16 19:59:59 +00:00
|
|
|
GST_OBJECT_UNLOCK (gtk_sink);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_gtk_base_sink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
|
|
|
|
{
|
|
|
|
GstGtkBaseSink *gtk_sink;
|
|
|
|
|
|
|
|
GST_TRACE ("rendering buffer:%p", buf);
|
|
|
|
|
|
|
|
gtk_sink = GST_GTK_BASE_SINK (vsink);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (vsink);
|
|
|
|
|
|
|
|
if (gtk_sink->widget == NULL) {
|
|
|
|
GST_OBJECT_UNLOCK (gtk_sink);
|
|
|
|
GST_ELEMENT_ERROR (gtk_sink, RESOURCE, NOT_FOUND,
|
|
|
|
("%s", "Output widget was destroyed"), (NULL));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_gst_base_widget_set_buffer (gtk_sink->widget, buf);
|
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (gtk_sink);
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|