2008-08-13 15:59:09 +00:00
|
|
|
/*
|
2008-05-19 16:57:39 +00:00
|
|
|
* GStreamer
|
2008-09-20 13:44:24 +00:00
|
|
|
* Copyright (C) 2003 Julien Moutte <julien@moutte.net>
|
|
|
|
* Copyright (C) 2005,2006,2007 David A. Schleef <ds@schleef.org>
|
2008-05-19 16:57:39 +00:00
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2015-05-06 13:47:04 +00:00
|
|
|
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
2008-05-19 16:57:39 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-05-19 16:57:39 +00:00
|
|
|
*/
|
|
|
|
|
2008-09-29 21:45:10 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-glimagesink
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: glimagesink
|
2008-09-29 21:45:10 +00:00
|
|
|
*
|
|
|
|
* glimagesink renders video frames to a drawable on a local or remote
|
2008-11-13 00:23:51 +00:00
|
|
|
* display using OpenGL. This element can receive a Window ID from the
|
2012-06-05 12:59:31 +00:00
|
|
|
* application through the VideoOverlay interface and will then render video
|
2008-09-29 21:45:10 +00:00
|
|
|
* frames in this drawable.
|
2008-11-13 00:23:51 +00:00
|
|
|
* If no Window ID was provided by the application, the element will
|
2008-09-29 21:45:10 +00:00
|
|
|
* create its own internal window and render into it.
|
|
|
|
*
|
2014-08-01 06:41:13 +00:00
|
|
|
* See the #GstGLDisplay documentation for a list of environment variables that
|
|
|
|
* can override window/platform detection.
|
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* ## Scaling
|
|
|
|
*
|
2008-09-29 21:45:10 +00:00
|
|
|
* Depends on the driver, OpenGL handles hardware accelerated
|
|
|
|
* scaling of video frames. This means that the element will just accept
|
|
|
|
* incoming video frames no matter their geometry and will then put them to the
|
2009-07-31 15:17:55 +00:00
|
|
|
* drawable scaling them on the fly. Using the #GstGLImageSink:force-aspect-ratio
|
2008-09-29 21:45:10 +00:00
|
|
|
* property it is possible to enforce scaling with a constant aspect ratio,
|
|
|
|
* which means drawing black borders around the video frame.
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
|
|
|
* ## Events
|
|
|
|
*
|
2008-09-29 21:45:10 +00:00
|
|
|
* Through the gl thread, glimagesink handle some events coming from the drawable
|
|
|
|
* to manage its appearance even when the data is not flowing (GST_STATE_PAUSED).
|
2008-11-13 00:23:51 +00:00
|
|
|
* That means that even when the element is paused, it will receive expose events
|
2008-09-29 21:45:10 +00:00
|
|
|
* from the drawable and draw the latest frame with correct borders/aspect-ratio.
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
|
|
|
* ## Examples
|
2008-09-29 21:45:10 +00:00
|
|
|
* |[
|
2014-08-10 17:07:28 +00:00
|
|
|
* gst-launch-1.0 -v videotestsrc ! video/x-raw ! glimagesink
|
2008-09-29 21:45:10 +00:00
|
|
|
* ]| A pipeline to test hardware scaling.
|
|
|
|
* No special opengl extension is used in this pipeline, that's why it should work
|
|
|
|
* with OpenGL >= 1.1. That's the case if you are using the MESA3D driver v1.3.
|
|
|
|
* |[
|
2014-08-10 17:07:28 +00:00
|
|
|
* gst-launch-1.0 -v videotestsrc ! video/x-raw,format=I420 ! glimagesink
|
2008-09-29 21:45:10 +00:00
|
|
|
* ]| A pipeline to test hardware scaling and hardware colorspace conversion.
|
2008-11-13 00:23:51 +00:00
|
|
|
* When your driver supports GLSL (OpenGL Shading Language needs OpenGL >= 2.1),
|
2008-09-29 21:45:10 +00:00
|
|
|
* the 4 following format YUY2, UYVY, I420, YV12 and AYUV are converted to RGB32
|
|
|
|
* through some fragment shaders and using one framebuffer (FBO extension OpenGL >= 1.4).
|
|
|
|
* If your driver does not support GLSL but supports MESA_YCbCr extension then
|
|
|
|
* the you can use YUY2 and UYVY. In this case the colorspace conversion is automatically
|
|
|
|
* made when loading the texture and therefore no framebuffer is used.
|
|
|
|
* |[
|
2014-08-10 17:07:28 +00:00
|
|
|
* gst-launch-1.0 -v gltestsrc ! glimagesink
|
2008-09-29 21:45:10 +00:00
|
|
|
* ]| A pipeline 100% OpenGL.
|
|
|
|
* No special opengl extension is used in this pipeline, that's why it should work
|
|
|
|
* with OpenGL >= 1.1. That's the case if you are using the MESA3D driver v1.3.
|
|
|
|
* |[
|
2014-08-10 17:07:28 +00:00
|
|
|
* gst-plugins-bas/tests/examples/gl/generic/cube
|
2008-09-29 21:45:10 +00:00
|
|
|
* ]| The graphic FPS scene can be greater than the input video FPS.
|
2008-11-13 00:23:51 +00:00
|
|
|
* The graphic scene can be written from a client code through the
|
2008-09-29 21:45:10 +00:00
|
|
|
* two glfilterapp properties.
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2008-09-29 21:45:10 +00:00
|
|
|
*/
|
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-06-05 12:59:31 +00:00
|
|
|
#include <gst/video/videooverlay.h>
|
2014-07-06 21:20:01 +00:00
|
|
|
#include <gst/video/navigation.h>
|
2015-11-10 04:37:05 +00:00
|
|
|
#include <gst/video/gstvideoaffinetransformationmeta.h>
|
2008-05-18 11:12:46 +00:00
|
|
|
|
|
|
|
#include "gstglimagesink.h"
|
2015-05-06 13:47:04 +00:00
|
|
|
#include "gstglsinkbin.h"
|
2017-01-13 00:08:10 +00:00
|
|
|
#include "gstglutils.h"
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
#include <gst/gl/gstglviewconvert.h>
|
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
GST_DEBUG_CATEGORY (gst_debug_glimage_sink);
|
|
|
|
#define GST_CAT_DEFAULT gst_debug_glimage_sink
|
|
|
|
|
2015-05-06 13:47:20 +00:00
|
|
|
#define DEFAULT_SHOW_PREROLL_FRAME TRUE
|
|
|
|
#define DEFAULT_HANDLE_EVENTS TRUE
|
|
|
|
#define DEFAULT_FORCE_ASPECT_RATIO TRUE
|
2015-05-14 05:10:59 +00:00
|
|
|
#define DEFAULT_IGNORE_ALPHA TRUE
|
2015-05-06 13:47:20 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
#define DEFAULT_MULTIVIEW_MODE GST_VIDEO_MULTIVIEW_MODE_MONO
|
|
|
|
#define DEFAULT_MULTIVIEW_FLAGS GST_VIDEO_MULTIVIEW_FLAGS_NONE
|
|
|
|
#define DEFAULT_MULTIVIEW_DOWNMIX GST_GL_STEREO_DOWNMIX_ANAGLYPH_GREEN_MAGENTA_DUBOIS
|
|
|
|
|
2015-05-06 13:47:04 +00:00
|
|
|
typedef GstGLSinkBin GstGLImageSinkBin;
|
|
|
|
typedef GstGLSinkBinClass GstGLImageSinkBinClass;
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstGLImageSinkBin, gst_gl_image_sink_bin, GST_TYPE_GL_SINK_BIN);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_BIN_0,
|
2016-05-16 12:02:28 +00:00
|
|
|
PROP_BIN_ROTATE_METHOD,
|
2015-05-06 13:47:04 +00:00
|
|
|
PROP_BIN_FORCE_ASPECT_RATIO,
|
2015-05-06 13:47:27 +00:00
|
|
|
PROP_BIN_PIXEL_ASPECT_RATIO,
|
2015-05-06 13:47:20 +00:00
|
|
|
PROP_BIN_HANDLE_EVENTS,
|
|
|
|
PROP_BIN_CONTEXT,
|
2015-06-15 12:43:54 +00:00
|
|
|
PROP_BIN_IGNORE_ALPHA,
|
2015-05-06 13:47:20 +00:00
|
|
|
PROP_BIN_SHOW_PREROLL_FRAME,
|
2015-05-29 16:26:32 +00:00
|
|
|
PROP_BIN_OUTPUT_MULTIVIEW_LAYOUT,
|
|
|
|
PROP_BIN_OUTPUT_MULTIVIEW_FLAGS,
|
|
|
|
PROP_BIN_OUTPUT_MULTIVIEW_DOWNMIX_MODE
|
2015-05-06 13:47:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_BIN_0,
|
|
|
|
SIGNAL_BIN_CLIENT_DRAW,
|
|
|
|
SIGNAL_BIN_CLIENT_RESHAPE,
|
|
|
|
SIGNAL_BIN_LAST,
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint gst_gl_image_sink_bin_signals[SIGNAL_BIN_LAST] = { 0 };
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_image_sink_bin_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * param_spec)
|
|
|
|
{
|
|
|
|
g_object_set_property (G_OBJECT (GST_GL_SINK_BIN (object)->sink),
|
|
|
|
param_spec->name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_image_sink_bin_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * param_spec)
|
|
|
|
{
|
|
|
|
g_object_get_property (G_OBJECT (GST_GL_SINK_BIN (object)->sink),
|
|
|
|
param_spec->name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_on_client_reshape (GstGLImageSink * sink, GstGLContext * context,
|
|
|
|
guint width, guint height, gpointer data)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_signal_emit (data, gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_RESHAPE],
|
|
|
|
0, context, width, height, &ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_on_client_draw (GstGLImageSink * sink, GstGLContext * context,
|
|
|
|
GstSample * sample, gpointer data)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_signal_emit (data, gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_DRAW], 0,
|
|
|
|
context, sample, &ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-16 12:02:28 +00:00
|
|
|
#define DEFAULT_ROTATE_METHOD GST_GL_ROTATE_METHOD_IDENTITY
|
|
|
|
|
|
|
|
#define GST_TYPE_GL_ROTATE_METHOD (gst_gl_rotate_method_get_type())
|
|
|
|
|
|
|
|
static const GEnumValue rotate_methods[] = {
|
|
|
|
{GST_GL_ROTATE_METHOD_IDENTITY, "Identity (no rotation)", "none"},
|
|
|
|
{GST_GL_ROTATE_METHOD_90R, "Rotate clockwise 90 degrees", "clockwise"},
|
|
|
|
{GST_GL_ROTATE_METHOD_180, "Rotate 180 degrees", "rotate-180"},
|
|
|
|
{GST_GL_ROTATE_METHOD_90L, "Rotate counter-clockwise 90 degrees",
|
|
|
|
"counterclockwise"},
|
|
|
|
{GST_GL_ROTATE_METHOD_FLIP_HORIZ, "Flip horizontally", "horizontal-flip"},
|
|
|
|
{GST_GL_ROTATE_METHOD_FLIP_VERT, "Flip vertically", "vertical-flip"},
|
|
|
|
{GST_GL_ROTATE_METHOD_FLIP_UL_LR,
|
|
|
|
"Flip across upper left/lower right diagonal", "upper-left-diagonal"},
|
|
|
|
{GST_GL_ROTATE_METHOD_FLIP_UR_LL,
|
|
|
|
"Flip across upper right/lower left diagonal", "upper-right-diagonal"},
|
|
|
|
{GST_GL_ROTATE_METHOD_AUTO,
|
|
|
|
"Select rotate method based on image-orientation tag", "automatic"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static GType
|
|
|
|
gst_gl_rotate_method_get_type (void)
|
|
|
|
{
|
|
|
|
static GType rotate_method_type = 0;
|
|
|
|
|
|
|
|
if (!rotate_method_type) {
|
|
|
|
rotate_method_type = g_enum_register_static ("GstGLRotateMethod",
|
|
|
|
rotate_methods);
|
|
|
|
}
|
|
|
|
return rotate_method_type;
|
|
|
|
}
|
|
|
|
|
2015-05-06 13:47:04 +00:00
|
|
|
static void
|
|
|
|
gst_gl_image_sink_bin_init (GstGLImageSinkBin * self)
|
|
|
|
{
|
|
|
|
GstGLImageSink *sink = g_object_new (GST_TYPE_GLIMAGE_SINK, NULL);
|
|
|
|
|
|
|
|
g_signal_connect (sink, "client-reshape", (GCallback) _on_client_reshape,
|
|
|
|
self);
|
|
|
|
g_signal_connect (sink, "client-draw", (GCallback) _on_client_draw, self);
|
|
|
|
|
|
|
|
gst_gl_sink_bin_finish_init_with_element (GST_GL_SINK_BIN (self),
|
|
|
|
GST_ELEMENT (sink));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_image_sink_bin_class_init (GstGLImageSinkBinClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->get_property = gst_gl_image_sink_bin_get_property;
|
|
|
|
gobject_class->set_property = gst_gl_image_sink_bin_set_property;
|
|
|
|
|
2015-05-06 13:47:20 +00:00
|
|
|
/* gl sink */
|
2016-05-16 12:02:28 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BIN_ROTATE_METHOD,
|
|
|
|
g_param_spec_enum ("rotate-method",
|
|
|
|
"rotate method",
|
|
|
|
"rotate method",
|
|
|
|
GST_TYPE_GL_ROTATE_METHOD, DEFAULT_ROTATE_METHOD,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-05-06 13:47:04 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BIN_FORCE_ASPECT_RATIO,
|
|
|
|
g_param_spec_boolean ("force-aspect-ratio",
|
|
|
|
"Force aspect ratio",
|
2015-05-06 13:47:20 +00:00
|
|
|
"When enabled, scaling will respect original aspect ratio",
|
|
|
|
DEFAULT_FORCE_ASPECT_RATIO,
|
2015-05-06 13:47:04 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-05-06 13:47:20 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BIN_HANDLE_EVENTS,
|
2015-06-15 12:43:54 +00:00
|
|
|
g_param_spec_boolean ("handle-events", "Handle XEvents",
|
|
|
|
"When enabled, XEvents will be selected and handled",
|
|
|
|
DEFAULT_HANDLE_EVENTS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_BIN_IGNORE_ALPHA,
|
2015-05-06 13:47:20 +00:00
|
|
|
g_param_spec_boolean ("ignore-alpha", "Ignore Alpha",
|
|
|
|
"When enabled, alpha will be ignored and converted to black",
|
2015-05-14 05:10:59 +00:00
|
|
|
DEFAULT_IGNORE_ALPHA, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-05-06 13:47:20 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BIN_CONTEXT,
|
|
|
|
g_param_spec_object ("context", "OpenGL context", "Get OpenGL context",
|
2016-10-05 01:19:12 +00:00
|
|
|
GST_TYPE_GL_CONTEXT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2015-05-06 13:47:27 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BIN_PIXEL_ASPECT_RATIO,
|
|
|
|
gst_param_spec_fraction ("pixel-aspect-ratio", "Pixel Aspect Ratio",
|
|
|
|
"The pixel aspect ratio of the device", 0, 1, G_MAXINT, 1, 1, 1,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-05-06 13:47:04 +00:00
|
|
|
|
2015-05-06 13:47:20 +00:00
|
|
|
/* video sink */
|
|
|
|
g_object_class_install_property (gobject_class, PROP_BIN_SHOW_PREROLL_FRAME,
|
|
|
|
g_param_spec_boolean ("show-preroll-frame", "Show preroll frame",
|
|
|
|
"Whether to render video frames during preroll",
|
|
|
|
DEFAULT_SHOW_PREROLL_FRAME,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_BIN_OUTPUT_MULTIVIEW_LAYOUT,
|
|
|
|
g_param_spec_enum ("output-multiview-mode", "Output Multiview Mode",
|
|
|
|
"Choose output mode for multiview/3D video",
|
|
|
|
GST_TYPE_VIDEO_MULTIVIEW_MODE, DEFAULT_MULTIVIEW_MODE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_BIN_OUTPUT_MULTIVIEW_FLAGS,
|
|
|
|
g_param_spec_flags ("output-multiview-flags", "Output Multiview Flags",
|
|
|
|
"Output multiview layout modifier flags",
|
|
|
|
GST_TYPE_VIDEO_MULTIVIEW_FLAGS, DEFAULT_MULTIVIEW_FLAGS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_BIN_OUTPUT_MULTIVIEW_DOWNMIX_MODE,
|
|
|
|
g_param_spec_enum ("output-multiview-downmix-mode",
|
|
|
|
"Mode for mono downmixed output",
|
|
|
|
"Output anaglyph type to generate when downmixing to mono",
|
|
|
|
GST_TYPE_GL_STEREO_DOWNMIX_MODE_TYPE, DEFAULT_MULTIVIEW_DOWNMIX,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-05-06 13:47:04 +00:00
|
|
|
gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_DRAW] =
|
2015-05-29 16:26:32 +00:00
|
|
|
g_signal_new ("client-draw", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_BOOLEAN, 2,
|
2016-10-05 01:19:12 +00:00
|
|
|
GST_TYPE_GL_CONTEXT, GST_TYPE_SAMPLE);
|
2015-05-06 13:47:04 +00:00
|
|
|
|
|
|
|
gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_RESHAPE] =
|
|
|
|
g_signal_new ("client-reshape", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
|
2016-10-05 01:19:12 +00:00
|
|
|
G_TYPE_BOOLEAN, 3, GST_TYPE_GL_CONTEXT, G_TYPE_UINT, G_TYPE_UINT);
|
2015-05-06 13:47:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-28 09:07:24 +00:00
|
|
|
#define GST_GLIMAGE_SINK_GET_LOCK(glsink) \
|
|
|
|
(GST_GLIMAGE_SINK(glsink)->drawing_lock)
|
|
|
|
#define GST_GLIMAGE_SINK_LOCK(glsink) \
|
|
|
|
(g_mutex_lock(&GST_GLIMAGE_SINK_GET_LOCK (glsink)))
|
|
|
|
#define GST_GLIMAGE_SINK_UNLOCK(glsink) \
|
|
|
|
(g_mutex_unlock(&GST_GLIMAGE_SINK_GET_LOCK (glsink)))
|
|
|
|
|
2014-05-30 00:27:14 +00:00
|
|
|
#define USING_OPENGL(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL, 1, 0))
|
|
|
|
#define USING_OPENGL3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL3, 3, 1))
|
|
|
|
#define USING_GLES(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES, 1, 0))
|
|
|
|
#define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0))
|
|
|
|
#define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0))
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2014-11-27 10:05:45 +00:00
|
|
|
#define SUPPORTED_GL_APIS GST_GL_API_OPENGL | GST_GL_API_GLES2 | GST_GL_API_OPENGL3
|
|
|
|
|
2013-06-28 09:00:07 +00:00
|
|
|
static void gst_glimage_sink_thread_init_redisplay (GstGLImageSink * gl_sink);
|
2014-10-21 11:18:51 +00:00
|
|
|
static void gst_glimage_sink_cleanup_glthread (GstGLImageSink * gl_sink);
|
2013-06-11 02:26:50 +00:00
|
|
|
static void gst_glimage_sink_on_close (GstGLImageSink * gl_sink);
|
2014-06-01 05:02:52 +00:00
|
|
|
static void gst_glimage_sink_on_resize (GstGLImageSink * gl_sink,
|
2013-08-28 09:07:24 +00:00
|
|
|
gint width, gint height);
|
2014-06-01 05:02:52 +00:00
|
|
|
static void gst_glimage_sink_on_draw (GstGLImageSink * gl_sink);
|
2013-08-28 09:07:24 +00:00
|
|
|
static gboolean gst_glimage_sink_redisplay (GstGLImageSink * gl_sink);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
static void gst_glimage_sink_finalize (GObject * object);
|
|
|
|
static void gst_glimage_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * param_spec);
|
|
|
|
static void gst_glimage_sink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * param_spec);
|
|
|
|
|
2016-05-16 12:02:28 +00:00
|
|
|
static gboolean gst_glimage_sink_event (GstBaseSink * sink, GstEvent * event);
|
2012-08-10 05:31:20 +00:00
|
|
|
static gboolean gst_glimage_sink_query (GstBaseSink * bsink, GstQuery * query);
|
2013-11-12 23:43:16 +00:00
|
|
|
static void gst_glimage_sink_set_context (GstElement * element,
|
|
|
|
GstContext * context);
|
2009-10-04 00:23:45 +00:00
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_glimage_sink_change_state (GstElement * element, GstStateChange transition);
|
|
|
|
|
|
|
|
static void gst_glimage_sink_get_times (GstBaseSink * bsink, GstBuffer * buf,
|
|
|
|
GstClockTime * start, GstClockTime * end);
|
|
|
|
static gboolean gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps);
|
2015-02-02 13:11:06 +00:00
|
|
|
static GstCaps *gst_glimage_sink_get_caps (GstBaseSink * bsink,
|
|
|
|
GstCaps * filter);
|
2014-04-13 12:14:52 +00:00
|
|
|
static GstFlowReturn gst_glimage_sink_prepare (GstBaseSink * bsink,
|
|
|
|
GstBuffer * buf);
|
2014-05-27 10:28:27 +00:00
|
|
|
static GstFlowReturn gst_glimage_sink_show_frame (GstVideoSink * bsink,
|
2008-05-18 11:12:46 +00:00
|
|
|
GstBuffer * buf);
|
2012-07-06 09:07:45 +00:00
|
|
|
static gboolean gst_glimage_sink_propose_allocation (GstBaseSink * bsink,
|
|
|
|
GstQuery * query);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2012-06-05 12:59:31 +00:00
|
|
|
static void gst_glimage_sink_video_overlay_init (GstVideoOverlayInterface *
|
|
|
|
iface);
|
|
|
|
static void gst_glimage_sink_set_window_handle (GstVideoOverlay * overlay,
|
2010-09-16 12:00:29 +00:00
|
|
|
guintptr id);
|
2012-06-05 12:59:31 +00:00
|
|
|
static void gst_glimage_sink_expose (GstVideoOverlay * overlay);
|
2015-05-29 08:03:52 +00:00
|
|
|
static void gst_glimage_sink_set_render_rectangle (GstVideoOverlay * overlay,
|
|
|
|
gint x, gint y, gint width, gint height);
|
|
|
|
static void gst_glimage_sink_handle_events (GstVideoOverlay * overlay,
|
2014-10-29 11:24:16 +00:00
|
|
|
gboolean handle_events);
|
2015-05-29 16:26:32 +00:00
|
|
|
static gboolean update_output_format (GstGLImageSink * glimage_sink);
|
2014-10-29 11:24:16 +00:00
|
|
|
|
2015-06-18 03:43:50 +00:00
|
|
|
#define GST_GL_SINK_CAPS \
|
2015-10-28 13:44:26 +00:00
|
|
|
"video/x-raw(" GST_CAPS_FEATURE_MEMORY_GL_MEMORY "), " \
|
|
|
|
"format = (string) RGBA, " \
|
|
|
|
"width = " GST_VIDEO_SIZE_RANGE ", " \
|
|
|
|
"height = " GST_VIDEO_SIZE_RANGE ", " \
|
|
|
|
"framerate = " GST_VIDEO_FPS_RANGE ", " \
|
2015-11-10 04:37:05 +00:00
|
|
|
"texture-target = (string) { 2D, external-oes } " \
|
2015-10-28 13:44:26 +00:00
|
|
|
" ; " \
|
|
|
|
"video/x-raw(" GST_CAPS_FEATURE_MEMORY_GL_MEMORY "," \
|
|
|
|
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION "), " \
|
|
|
|
"format = (string) RGBA, " \
|
|
|
|
"width = " GST_VIDEO_SIZE_RANGE ", " \
|
|
|
|
"height = " GST_VIDEO_SIZE_RANGE ", " \
|
|
|
|
"framerate = " GST_VIDEO_FPS_RANGE ", " \
|
2015-11-10 04:37:05 +00:00
|
|
|
"texture-target = (string) { 2D, external-oes } "
|
2015-06-18 03:43:50 +00:00
|
|
|
|
2015-05-06 13:46:49 +00:00
|
|
|
static GstStaticPadTemplate gst_glimage_sink_template =
|
2015-10-28 13:44:26 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2015-05-06 13:46:49 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2015-10-28 13:44:26 +00:00
|
|
|
GST_STATIC_CAPS (GST_GL_SINK_CAPS));
|
2015-05-06 13:46:49 +00:00
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
enum
|
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_DISPLAY,
|
2016-05-16 12:02:28 +00:00
|
|
|
PROP_ROTATE_METHOD,
|
2010-05-04 09:37:38 +00:00
|
|
|
PROP_FORCE_ASPECT_RATIO,
|
2014-03-06 07:11:22 +00:00
|
|
|
PROP_PIXEL_ASPECT_RATIO,
|
2014-10-29 11:24:16 +00:00
|
|
|
PROP_CONTEXT,
|
2015-01-30 04:13:27 +00:00
|
|
|
PROP_HANDLE_EVENTS,
|
|
|
|
PROP_IGNORE_ALPHA,
|
2015-05-29 16:26:32 +00:00
|
|
|
PROP_OUTPUT_MULTIVIEW_LAYOUT,
|
|
|
|
PROP_OUTPUT_MULTIVIEW_FLAGS,
|
|
|
|
PROP_OUTPUT_MULTIVIEW_DOWNMIX_MODE
|
2008-05-18 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
2014-06-01 05:02:52 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_0,
|
|
|
|
CLIENT_DRAW_SIGNAL,
|
|
|
|
CLIENT_RESHAPE_SIGNAL,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint gst_glimage_sink_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2015-08-11 22:20:10 +00:00
|
|
|
static void
|
|
|
|
_display_size_to_stream_size (GstGLImageSink * gl_sink, gdouble x,
|
|
|
|
gdouble y, gdouble * stream_x, gdouble * stream_y)
|
|
|
|
{
|
|
|
|
gdouble stream_width, stream_height;
|
|
|
|
|
|
|
|
stream_width = (gdouble) GST_VIDEO_INFO_WIDTH (&gl_sink->out_info);
|
|
|
|
stream_height = (gdouble) GST_VIDEO_INFO_HEIGHT (&gl_sink->out_info);
|
|
|
|
|
|
|
|
/* from display coordinates to stream coordinates */
|
|
|
|
if (gl_sink->display_rect.w > 0)
|
|
|
|
*stream_x =
|
|
|
|
(x - gl_sink->display_rect.x) / gl_sink->display_rect.w * stream_width;
|
|
|
|
else
|
|
|
|
*stream_x = 0.;
|
|
|
|
|
|
|
|
/* clip to stream size */
|
|
|
|
if (*stream_x < 0.)
|
|
|
|
*stream_x = 0.;
|
|
|
|
if (*stream_x > GST_VIDEO_INFO_WIDTH (&gl_sink->out_info))
|
|
|
|
*stream_x = GST_VIDEO_INFO_WIDTH (&gl_sink->out_info);
|
|
|
|
|
|
|
|
/* same for y-axis */
|
|
|
|
if (gl_sink->display_rect.h > 0)
|
|
|
|
*stream_y =
|
|
|
|
(y - gl_sink->display_rect.y) / gl_sink->display_rect.h * stream_height;
|
|
|
|
else
|
|
|
|
*stream_y = 0.;
|
|
|
|
|
|
|
|
if (*stream_y < 0.)
|
|
|
|
*stream_y = 0.;
|
|
|
|
if (*stream_y > GST_VIDEO_INFO_HEIGHT (&gl_sink->out_info))
|
|
|
|
*stream_y = GST_VIDEO_INFO_HEIGHT (&gl_sink->out_info);
|
|
|
|
|
|
|
|
GST_TRACE ("transform %fx%f into %fx%f", x, y, *stream_x, *stream_y);
|
|
|
|
}
|
|
|
|
|
2016-05-16 12:02:28 +00:00
|
|
|
/* rotate 90 */
|
|
|
|
static const gfloat clockwise_matrix[] = {
|
|
|
|
0.0f, -1.0f, 0.0f, 0.0f,
|
|
|
|
1.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* rotate 180 */
|
|
|
|
static const gfloat clockwise_180_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,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* rotate 270 */
|
|
|
|
static const gfloat counterclockwise_matrix[] = {
|
|
|
|
0.0f, 1.0f, 0.0f, 0.0f,
|
|
|
|
-1.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* horizontal-flip */
|
|
|
|
static const gfloat horizontal_flip_matrix[] = {
|
2016-08-01 06:12:35 +00:00
|
|
|
-1.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 1.0f, 0.0f, 0.0f,
|
2016-05-16 12:02:28 +00:00
|
|
|
0.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* vertical-flip */
|
|
|
|
static const gfloat vertical_flip_matrix[] = {
|
2016-08-01 06:12:35 +00:00
|
|
|
1.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, -1.0f, 0.0f, 0.0f,
|
2016-05-16 12:02:28 +00:00
|
|
|
0.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* upper-left-diagonal */
|
|
|
|
static const gfloat upper_left_matrix[] = {
|
|
|
|
0.0f, 1.0f, 0.0f, 0.0f,
|
|
|
|
1.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* upper-right-diagonal */
|
|
|
|
static const gfloat upper_right_matrix[] = {
|
|
|
|
0.0f, -1.0f, 0.0f, 0.0f,
|
|
|
|
-1.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_glimage_sink_set_rotate_method (GstGLImageSink * gl_sink,
|
|
|
|
GstGLRotateMethod method, gboolean from_tag)
|
|
|
|
{
|
|
|
|
GstGLRotateMethod tag_method = DEFAULT_ROTATE_METHOD;
|
|
|
|
GST_GLIMAGE_SINK_LOCK (gl_sink);
|
|
|
|
if (from_tag)
|
|
|
|
tag_method = method;
|
|
|
|
else
|
|
|
|
gl_sink->rotate_method = method;
|
|
|
|
|
|
|
|
if (gl_sink->rotate_method == GST_GL_ROTATE_METHOD_AUTO)
|
|
|
|
method = tag_method;
|
|
|
|
else
|
|
|
|
method = gl_sink->rotate_method;
|
|
|
|
|
|
|
|
if (method != gl_sink->current_rotate_method) {
|
|
|
|
GST_DEBUG_OBJECT (gl_sink, "Changing method from %s to %s",
|
|
|
|
rotate_methods[gl_sink->current_rotate_method].value_nick,
|
|
|
|
rotate_methods[method].value_nick);
|
|
|
|
|
|
|
|
switch (method) {
|
|
|
|
case GST_GL_ROTATE_METHOD_IDENTITY:
|
|
|
|
gl_sink->transform_matrix = NULL;
|
|
|
|
gl_sink->output_mode_changed = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_GL_ROTATE_METHOD_90R:
|
|
|
|
gl_sink->transform_matrix = clockwise_matrix;
|
|
|
|
gl_sink->output_mode_changed = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_GL_ROTATE_METHOD_180:
|
|
|
|
gl_sink->transform_matrix = clockwise_180_matrix;
|
|
|
|
gl_sink->output_mode_changed = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_GL_ROTATE_METHOD_90L:
|
|
|
|
gl_sink->transform_matrix = counterclockwise_matrix;
|
|
|
|
gl_sink->output_mode_changed = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_GL_ROTATE_METHOD_FLIP_HORIZ:
|
|
|
|
gl_sink->transform_matrix = horizontal_flip_matrix;
|
|
|
|
gl_sink->output_mode_changed = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_GL_ROTATE_METHOD_FLIP_VERT:
|
|
|
|
gl_sink->transform_matrix = vertical_flip_matrix;
|
|
|
|
gl_sink->output_mode_changed = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_GL_ROTATE_METHOD_FLIP_UL_LR:
|
|
|
|
gl_sink->transform_matrix = upper_left_matrix;
|
|
|
|
gl_sink->output_mode_changed = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_GL_ROTATE_METHOD_FLIP_UR_LL:
|
|
|
|
gl_sink->transform_matrix = upper_right_matrix;
|
|
|
|
gl_sink->output_mode_changed = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_sink->current_rotate_method = method;
|
|
|
|
}
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (gl_sink);
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:20:01 +00:00
|
|
|
static void
|
|
|
|
gst_glimage_sink_navigation_send_event (GstNavigation * navigation, GstStructure
|
|
|
|
* structure)
|
|
|
|
{
|
|
|
|
GstGLImageSink *sink = GST_GLIMAGE_SINK (navigation);
|
2015-12-26 21:34:29 +00:00
|
|
|
gboolean handled = FALSE;
|
2014-07-06 21:20:01 +00:00
|
|
|
GstEvent *event = NULL;
|
2014-11-20 03:43:58 +00:00
|
|
|
GstGLWindow *window;
|
2014-08-06 13:48:03 +00:00
|
|
|
guint width, height;
|
2015-08-11 22:20:10 +00:00
|
|
|
gdouble x, y;
|
2014-08-06 13:48:03 +00:00
|
|
|
|
2015-11-17 00:08:52 +00:00
|
|
|
if (!sink->context) {
|
|
|
|
gst_structure_free (structure);
|
2014-11-20 03:43:58 +00:00
|
|
|
return;
|
2015-11-17 00:08:52 +00:00
|
|
|
}
|
2014-11-20 03:43:58 +00:00
|
|
|
|
|
|
|
window = gst_gl_context_get_window (sink->context);
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_WINDOW (window));
|
2014-08-06 13:48:03 +00:00
|
|
|
|
|
|
|
width = GST_VIDEO_SINK_WIDTH (sink);
|
|
|
|
height = GST_VIDEO_SINK_HEIGHT (sink);
|
|
|
|
gst_gl_window_get_surface_dimensions (window, &width, &height);
|
2014-07-06 21:20:01 +00:00
|
|
|
|
2014-08-06 13:48:03 +00:00
|
|
|
/* Converting pointer coordinates to the non scaled geometry */
|
2015-08-11 22:20:10 +00:00
|
|
|
if (width != 0 && gst_structure_get_double (structure, "pointer_x", &x)
|
|
|
|
&& height != 0 && gst_structure_get_double (structure, "pointer_y", &y)) {
|
|
|
|
gdouble stream_x, stream_y;
|
|
|
|
|
|
|
|
_display_size_to_stream_size (sink, x, y, &stream_x, &stream_y);
|
|
|
|
|
2014-08-06 13:48:03 +00:00
|
|
|
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE,
|
2015-08-11 22:20:10 +00:00
|
|
|
stream_x, "pointer_y", G_TYPE_DOUBLE, stream_y, NULL);
|
2014-08-06 13:48:03 +00:00
|
|
|
}
|
2014-07-06 21:20:01 +00:00
|
|
|
|
2015-12-26 21:34:29 +00:00
|
|
|
event = gst_event_new_navigation (structure);
|
|
|
|
if (event) {
|
|
|
|
gst_event_ref (event);
|
|
|
|
handled = gst_pad_push_event (GST_VIDEO_SINK_PAD (sink), event);
|
2014-07-06 21:20:01 +00:00
|
|
|
|
2015-12-26 21:34:29 +00:00
|
|
|
if (!handled)
|
|
|
|
gst_element_post_message ((GstElement *) sink,
|
|
|
|
gst_navigation_message_new_event ((GstObject *) sink, event));
|
|
|
|
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
2014-08-19 04:23:21 +00:00
|
|
|
gst_object_unref (window);
|
2014-07-06 21:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_glimage_sink_navigation_interface_init (GstNavigationInterface * iface)
|
|
|
|
{
|
|
|
|
iface->send_event = gst_glimage_sink_navigation_send_event;
|
|
|
|
}
|
|
|
|
|
2012-06-05 12:59:31 +00:00
|
|
|
#define gst_glimage_sink_parent_class parent_class
|
2012-05-30 03:46:21 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLImageSink, gst_glimage_sink,
|
2012-06-05 12:59:31 +00:00
|
|
|
GST_TYPE_VIDEO_SINK, G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_OVERLAY,
|
|
|
|
gst_glimage_sink_video_overlay_init);
|
2014-07-06 21:20:01 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_NAVIGATION,
|
|
|
|
gst_glimage_sink_navigation_interface_init);
|
2012-06-05 12:59:31 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_debug_glimage_sink, "glimagesink", 0,
|
|
|
|
"OpenGL Video Sink"));
|
2008-05-18 11:12:46 +00:00
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_glimage_sink_class_init (GstGLImageSinkClass * klass)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
GstBaseSinkClass *gstbasesink_class;
|
2014-05-27 10:28:27 +00:00
|
|
|
GstVideoSinkClass *gstvideosink_class;
|
2012-05-30 03:46:21 +00:00
|
|
|
GstElementClass *element_class;
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
gstbasesink_class = (GstBaseSinkClass *) klass;
|
2014-05-27 10:28:27 +00:00
|
|
|
gstvideosink_class = (GstVideoSinkClass *) klass;
|
2012-06-05 12:59:31 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
gobject_class->set_property = gst_glimage_sink_set_property;
|
|
|
|
gobject_class->get_property = gst_glimage_sink_get_property;
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2016-05-16 12:02:28 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ROTATE_METHOD,
|
|
|
|
g_param_spec_enum ("rotate-method",
|
|
|
|
"rotate method",
|
|
|
|
"rotate method",
|
|
|
|
GST_TYPE_GL_ROTATE_METHOD, DEFAULT_ROTATE_METHOD,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2009-04-19 22:52:41 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO,
|
2015-05-06 13:47:20 +00:00
|
|
|
g_param_spec_boolean ("force-aspect-ratio", "Force aspect ratio",
|
|
|
|
"When enabled, scaling will respect original aspect ratio",
|
|
|
|
DEFAULT_FORCE_ASPECT_RATIO,
|
2010-10-19 15:00:33 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-04-19 22:52:41 +00:00
|
|
|
|
2010-05-04 09:37:38 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PIXEL_ASPECT_RATIO,
|
2013-07-16 12:22:53 +00:00
|
|
|
gst_param_spec_fraction ("pixel-aspect-ratio", "Pixel Aspect Ratio",
|
2014-04-23 08:55:38 +00:00
|
|
|
"The pixel aspect ratio of the device", 0, 1, G_MAXINT, 1, 1, 1,
|
2010-05-04 09:37:38 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2014-07-07 08:52:06 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CONTEXT,
|
2015-05-06 13:47:20 +00:00
|
|
|
g_param_spec_object ("context", "OpenGL context", "Get OpenGL context",
|
2016-10-05 01:19:12 +00:00
|
|
|
GST_TYPE_GL_CONTEXT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2014-07-07 08:52:06 +00:00
|
|
|
|
2014-10-29 11:24:16 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_HANDLE_EVENTS,
|
|
|
|
g_param_spec_boolean ("handle-events", "Handle XEvents",
|
2015-05-14 05:10:59 +00:00
|
|
|
"When enabled, XEvents will be selected and handled",
|
|
|
|
DEFAULT_HANDLE_EVENTS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2014-10-29 11:24:16 +00:00
|
|
|
|
2015-05-06 13:47:20 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_IGNORE_ALPHA,
|
2015-01-30 04:13:27 +00:00
|
|
|
g_param_spec_boolean ("ignore-alpha", "Ignore Alpha",
|
2015-05-14 05:10:59 +00:00
|
|
|
"When enabled, alpha will be ignored and converted to black",
|
|
|
|
DEFAULT_IGNORE_ALPHA, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-01-30 04:13:27 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_OUTPUT_MULTIVIEW_LAYOUT,
|
|
|
|
g_param_spec_enum ("output-multiview-mode",
|
|
|
|
"Output Multiview Mode",
|
|
|
|
"Choose output mode for multiview/3D video",
|
|
|
|
GST_TYPE_VIDEO_MULTIVIEW_MODE, DEFAULT_MULTIVIEW_MODE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_OUTPUT_MULTIVIEW_FLAGS,
|
|
|
|
g_param_spec_flags ("output-multiview-flags",
|
|
|
|
"Output Multiview Flags",
|
|
|
|
"Output multiview layout modifier flags",
|
|
|
|
GST_TYPE_VIDEO_MULTIVIEW_FLAGS, DEFAULT_MULTIVIEW_FLAGS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_OUTPUT_MULTIVIEW_DOWNMIX_MODE,
|
|
|
|
g_param_spec_enum ("output-multiview-downmix-mode",
|
|
|
|
"Mode for mono downmixed output",
|
|
|
|
"Output anaglyph type to generate when downmixing to mono",
|
|
|
|
GST_TYPE_GL_STEREO_DOWNMIX_MODE_TYPE, DEFAULT_MULTIVIEW_DOWNMIX,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2014-04-23 08:55:38 +00:00
|
|
|
gst_element_class_set_metadata (element_class, "OpenGL video sink",
|
|
|
|
"Sink/Video", "A videosink based on OpenGL",
|
|
|
|
"Julien Isorce <julien.isorce@gmail.com>");
|
|
|
|
|
2014-06-01 05:02:52 +00:00
|
|
|
/**
|
|
|
|
* GstGLImageSink::client-draw:
|
|
|
|
* @object: the #GstGLImageSink
|
|
|
|
* @texture: the #guint id of the texture.
|
|
|
|
* @width: the #guint width of the texture.
|
|
|
|
* @height: the #guint height of the texture.
|
|
|
|
*
|
|
|
|
* Will be emitted before actually drawing the texture. The client should
|
|
|
|
* redraw the surface/contents with the @texture, @width and @height and
|
|
|
|
* and return %TRUE.
|
|
|
|
*
|
|
|
|
* Returns: whether the texture was redrawn by the signal. If not, a
|
|
|
|
* default redraw will occur.
|
|
|
|
*/
|
|
|
|
gst_glimage_sink_signals[CLIENT_DRAW_SIGNAL] =
|
|
|
|
g_signal_new ("client-draw", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
|
2016-10-05 01:19:12 +00:00
|
|
|
G_TYPE_BOOLEAN, 2, GST_TYPE_GL_CONTEXT, GST_TYPE_SAMPLE);
|
2014-06-01 05:02:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstGLImageSink::client-reshape:
|
|
|
|
* @object: the #GstGLImageSink
|
|
|
|
* @width: the #guint width of the texture.
|
|
|
|
* @height: the #guint height of the texture.
|
|
|
|
*
|
|
|
|
* The client should resize the surface/window/viewport with the @width and
|
|
|
|
* @height and return %TRUE.
|
|
|
|
*
|
|
|
|
* Returns: whether the content area was resized by the signal. If not, a
|
|
|
|
* default viewport resize will occur.
|
|
|
|
*/
|
|
|
|
gst_glimage_sink_signals[CLIENT_RESHAPE_SIGNAL] =
|
|
|
|
g_signal_new ("client-reshape", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
|
2016-10-05 01:19:12 +00:00
|
|
|
G_TYPE_BOOLEAN, 3, GST_TYPE_GL_CONTEXT, G_TYPE_UINT, G_TYPE_UINT);
|
2014-06-01 05:02:52 +00:00
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_glimage_sink_template);
|
2012-05-30 03:46:21 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
gobject_class->finalize = gst_glimage_sink_finalize;
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
gstelement_class->change_state = gst_glimage_sink_change_state;
|
2013-11-12 23:43:16 +00:00
|
|
|
gstelement_class->set_context = gst_glimage_sink_set_context;
|
2016-05-16 12:02:28 +00:00
|
|
|
gstbasesink_class->event = gst_glimage_sink_event;
|
2012-08-10 05:31:20 +00:00
|
|
|
gstbasesink_class->query = GST_DEBUG_FUNCPTR (gst_glimage_sink_query);
|
2009-02-11 06:39:14 +00:00
|
|
|
gstbasesink_class->set_caps = gst_glimage_sink_set_caps;
|
2015-02-02 13:11:06 +00:00
|
|
|
gstbasesink_class->get_caps = gst_glimage_sink_get_caps;
|
2009-02-11 06:39:14 +00:00
|
|
|
gstbasesink_class->get_times = gst_glimage_sink_get_times;
|
2014-04-13 12:14:52 +00:00
|
|
|
gstbasesink_class->prepare = gst_glimage_sink_prepare;
|
2012-07-06 09:07:45 +00:00
|
|
|
gstbasesink_class->propose_allocation = gst_glimage_sink_propose_allocation;
|
2014-05-27 10:28:27 +00:00
|
|
|
|
|
|
|
gstvideosink_class->show_frame =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_glimage_sink_show_frame);
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_glimage_sink_init (GstGLImageSink * glimage_sink)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
glimage_sink->window_id = 0;
|
2009-06-06 12:34:57 +00:00
|
|
|
glimage_sink->new_window_id = 0;
|
2009-02-11 06:39:14 +00:00
|
|
|
glimage_sink->display = NULL;
|
2014-07-09 19:03:42 +00:00
|
|
|
glimage_sink->keep_aspect_ratio = TRUE;
|
2014-05-30 01:35:04 +00:00
|
|
|
glimage_sink->par_n = 0;
|
2013-07-16 12:22:53 +00:00
|
|
|
glimage_sink->par_d = 1;
|
2013-08-28 09:07:24 +00:00
|
|
|
glimage_sink->redisplay_texture = 0;
|
2014-11-06 22:55:20 +00:00
|
|
|
glimage_sink->handle_events = TRUE;
|
2015-01-30 04:13:27 +00:00
|
|
|
glimage_sink->ignore_alpha = TRUE;
|
2015-06-18 04:04:37 +00:00
|
|
|
glimage_sink->overlay_compositor = NULL;
|
2013-08-28 09:07:24 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
glimage_sink->mview_output_mode = DEFAULT_MULTIVIEW_MODE;
|
|
|
|
glimage_sink->mview_output_flags = DEFAULT_MULTIVIEW_FLAGS;
|
|
|
|
glimage_sink->mview_downmix_mode = DEFAULT_MULTIVIEW_DOWNMIX;
|
|
|
|
|
2016-05-16 12:02:28 +00:00
|
|
|
glimage_sink->current_rotate_method = DEFAULT_ROTATE_METHOD;
|
|
|
|
glimage_sink->transform_matrix = NULL;
|
|
|
|
|
2013-08-28 09:07:24 +00:00
|
|
|
g_mutex_init (&glimage_sink->drawing_lock);
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_glimage_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (object);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (prop_id) {
|
2016-05-16 12:02:28 +00:00
|
|
|
case PROP_ROTATE_METHOD:
|
|
|
|
gst_glimage_sink_set_rotate_method (glimage_sink,
|
|
|
|
g_value_get_enum (value), FALSE);
|
|
|
|
break;
|
2009-04-19 22:52:41 +00:00
|
|
|
case PROP_FORCE_ASPECT_RATIO:
|
|
|
|
{
|
|
|
|
glimage_sink->keep_aspect_ratio = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
}
|
2010-05-04 09:37:38 +00:00
|
|
|
case PROP_PIXEL_ASPECT_RATIO:
|
|
|
|
{
|
2013-07-16 12:22:53 +00:00
|
|
|
glimage_sink->par_n = gst_value_get_fraction_numerator (value);
|
|
|
|
glimage_sink->par_d = gst_value_get_fraction_denominator (value);
|
2010-05-04 09:37:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-10-29 11:24:16 +00:00
|
|
|
case PROP_HANDLE_EVENTS:
|
|
|
|
gst_glimage_sink_handle_events (GST_VIDEO_OVERLAY (glimage_sink),
|
|
|
|
g_value_get_boolean (value));
|
|
|
|
break;
|
2015-01-30 04:13:27 +00:00
|
|
|
case PROP_IGNORE_ALPHA:
|
|
|
|
glimage_sink->ignore_alpha = g_value_get_boolean (value);
|
|
|
|
break;
|
2015-05-29 16:26:32 +00:00
|
|
|
case PROP_OUTPUT_MULTIVIEW_LAYOUT:
|
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
|
|
|
glimage_sink->mview_output_mode = g_value_get_enum (value);
|
|
|
|
glimage_sink->output_mode_changed = TRUE;
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
|
|
|
break;
|
|
|
|
case PROP_OUTPUT_MULTIVIEW_FLAGS:
|
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
|
|
|
glimage_sink->mview_output_flags = g_value_get_flags (value);
|
|
|
|
glimage_sink->output_mode_changed = TRUE;
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
|
|
|
break;
|
|
|
|
case PROP_OUTPUT_MULTIVIEW_DOWNMIX_MODE:
|
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
|
|
|
glimage_sink->mview_downmix_mode = g_value_get_enum (value);
|
|
|
|
glimage_sink->output_mode_changed = TRUE;
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
|
|
|
break;
|
2009-02-11 06:39:14 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_glimage_sink_finalize (GObject * object)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (object);
|
2013-08-28 09:07:24 +00:00
|
|
|
g_mutex_clear (&glimage_sink->drawing_lock);
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_DEBUG ("finalized");
|
2014-06-29 20:26:47 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_glimage_sink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (object);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (prop_id) {
|
2016-05-16 12:02:28 +00:00
|
|
|
case PROP_ROTATE_METHOD:
|
|
|
|
g_value_set_enum (value, glimage_sink->current_rotate_method);
|
|
|
|
break;
|
2009-04-19 22:52:41 +00:00
|
|
|
case PROP_FORCE_ASPECT_RATIO:
|
|
|
|
g_value_set_boolean (value, glimage_sink->keep_aspect_ratio);
|
|
|
|
break;
|
2010-05-04 09:37:38 +00:00
|
|
|
case PROP_PIXEL_ASPECT_RATIO:
|
2013-07-16 12:22:53 +00:00
|
|
|
gst_value_set_fraction (value, glimage_sink->par_n, glimage_sink->par_d);
|
2010-05-04 09:37:38 +00:00
|
|
|
break;
|
2014-07-07 08:52:06 +00:00
|
|
|
case PROP_CONTEXT:
|
|
|
|
g_value_set_object (value, glimage_sink->context);
|
2014-08-28 13:42:30 +00:00
|
|
|
break;
|
2014-10-29 11:24:16 +00:00
|
|
|
case PROP_HANDLE_EVENTS:
|
|
|
|
g_value_set_boolean (value, glimage_sink->handle_events);
|
|
|
|
break;
|
2015-01-30 04:13:27 +00:00
|
|
|
case PROP_IGNORE_ALPHA:
|
|
|
|
g_value_set_boolean (value, glimage_sink->ignore_alpha);
|
|
|
|
break;
|
2015-05-29 16:26:32 +00:00
|
|
|
case PROP_OUTPUT_MULTIVIEW_LAYOUT:
|
|
|
|
g_value_set_enum (value, glimage_sink->mview_output_mode);
|
|
|
|
break;
|
|
|
|
case PROP_OUTPUT_MULTIVIEW_FLAGS:
|
|
|
|
g_value_set_flags (value, glimage_sink->mview_output_flags);
|
|
|
|
break;
|
|
|
|
case PROP_OUTPUT_MULTIVIEW_DOWNMIX_MODE:
|
|
|
|
g_value_set_enum (value, glimage_sink->mview_downmix_mode);
|
|
|
|
break;
|
2009-02-11 06:39:14 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:20:01 +00:00
|
|
|
static void
|
|
|
|
gst_glimage_sink_key_event_cb (GstGLWindow * window, char *event_name, char
|
|
|
|
*key_string, GstGLImageSink * gl_sink)
|
|
|
|
{
|
2016-01-14 05:59:12 +00:00
|
|
|
GST_DEBUG_OBJECT (gl_sink, "event %s key %s pressed", event_name, key_string);
|
2014-07-06 21:20:01 +00:00
|
|
|
gst_navigation_send_key_event (GST_NAVIGATION (gl_sink),
|
|
|
|
event_name, key_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_glimage_sink_mouse_event_cb (GstGLWindow * window, char *event_name,
|
|
|
|
int button, double posx, double posy, GstGLImageSink * gl_sink)
|
|
|
|
{
|
2016-01-14 05:59:12 +00:00
|
|
|
GST_DEBUG_OBJECT (gl_sink, "event %s at %g, %g", event_name, posx, posy);
|
2014-07-06 21:20:01 +00:00
|
|
|
gst_navigation_send_mouse_event (GST_NAVIGATION (gl_sink),
|
|
|
|
event_name, button, posx, posy);
|
|
|
|
}
|
|
|
|
|
2013-11-14 04:27:52 +00:00
|
|
|
static gboolean
|
|
|
|
_ensure_gl_setup (GstGLImageSink * gl_sink)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
GST_TRACE_OBJECT (gl_sink, "Ensuring setup");
|
2015-02-12 13:56:12 +00:00
|
|
|
|
2013-11-14 04:27:52 +00:00
|
|
|
if (!gl_sink->context) {
|
2015-04-21 02:19:46 +00:00
|
|
|
GST_OBJECT_LOCK (gl_sink->display);
|
2015-03-03 06:26:47 +00:00
|
|
|
do {
|
2015-06-15 15:09:54 +00:00
|
|
|
GstGLContext *other_context = NULL;
|
|
|
|
GstGLWindow *window = NULL;
|
2014-04-06 09:57:12 +00:00
|
|
|
|
2015-06-15 15:09:54 +00:00
|
|
|
if (gl_sink->context) {
|
2015-03-03 06:26:47 +00:00
|
|
|
gst_object_unref (gl_sink->context);
|
2015-06-15 15:09:54 +00:00
|
|
|
gl_sink->context = NULL;
|
|
|
|
}
|
2015-02-12 13:56:12 +00:00
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
GST_DEBUG_OBJECT (gl_sink,
|
|
|
|
"No current context, creating one for %" GST_PTR_FORMAT,
|
|
|
|
gl_sink->display);
|
2014-04-06 09:57:12 +00:00
|
|
|
|
2015-06-15 15:09:54 +00:00
|
|
|
if (gl_sink->other_context) {
|
|
|
|
other_context = gst_object_ref (gl_sink->other_context);
|
|
|
|
} else {
|
|
|
|
other_context =
|
|
|
|
gst_gl_display_get_gl_context_for_thread (gl_sink->display, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_gl_display_create_context (gl_sink->display,
|
|
|
|
other_context, &gl_sink->context, &error)) {
|
|
|
|
if (other_context)
|
|
|
|
gst_object_unref (other_context);
|
2015-05-13 13:54:52 +00:00
|
|
|
GST_OBJECT_UNLOCK (gl_sink->display);
|
2015-06-15 15:09:54 +00:00
|
|
|
goto context_error;
|
2015-05-13 13:54:52 +00:00
|
|
|
}
|
2014-04-06 09:57:12 +00:00
|
|
|
|
2015-06-15 15:09:54 +00:00
|
|
|
GST_DEBUG_OBJECT (gl_sink,
|
|
|
|
"created context %" GST_PTR_FORMAT " from other context %"
|
|
|
|
GST_PTR_FORMAT, gl_sink->context, gl_sink->other_context);
|
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
window = gst_gl_context_get_window (gl_sink->context);
|
2015-02-12 13:56:12 +00:00
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
GST_DEBUG_OBJECT (gl_sink, "got window %" GST_PTR_FORMAT, window);
|
2014-04-06 09:57:12 +00:00
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
if (!gl_sink->window_id && !gl_sink->new_window_id)
|
|
|
|
gst_video_overlay_prepare_window_handle (GST_VIDEO_OVERLAY (gl_sink));
|
2015-02-12 13:56:12 +00:00
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
GST_DEBUG_OBJECT (gl_sink,
|
|
|
|
"window_id : %" G_GUINTPTR_FORMAT " , new_window_id : %"
|
|
|
|
G_GUINTPTR_FORMAT, gl_sink->window_id, gl_sink->new_window_id);
|
2014-04-06 09:57:12 +00:00
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
if (gl_sink->window_id != gl_sink->new_window_id) {
|
|
|
|
gl_sink->window_id = gl_sink->new_window_id;
|
|
|
|
GST_DEBUG_OBJECT (gl_sink, "Setting window handle on gl window");
|
|
|
|
gst_gl_window_set_window_handle (window, gl_sink->window_id);
|
|
|
|
}
|
2015-02-12 13:56:12 +00:00
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
gst_gl_window_handle_events (window, gl_sink->handle_events);
|
|
|
|
|
|
|
|
/* setup callbacks */
|
|
|
|
gst_gl_window_set_resize_callback (window,
|
|
|
|
GST_GL_WINDOW_RESIZE_CB (gst_glimage_sink_on_resize),
|
|
|
|
gst_object_ref (gl_sink), (GDestroyNotify) gst_object_unref);
|
|
|
|
gst_gl_window_set_draw_callback (window,
|
|
|
|
GST_GL_WINDOW_CB (gst_glimage_sink_on_draw),
|
|
|
|
gst_object_ref (gl_sink), (GDestroyNotify) gst_object_unref);
|
|
|
|
gst_gl_window_set_close_callback (window,
|
|
|
|
GST_GL_WINDOW_CB (gst_glimage_sink_on_close),
|
|
|
|
gst_object_ref (gl_sink), (GDestroyNotify) gst_object_unref);
|
|
|
|
gl_sink->key_sig_id = g_signal_connect (window, "key-event", G_CALLBACK
|
|
|
|
(gst_glimage_sink_key_event_cb), gl_sink);
|
|
|
|
gl_sink->mouse_sig_id =
|
|
|
|
g_signal_connect (window, "mouse-event",
|
|
|
|
G_CALLBACK (gst_glimage_sink_mouse_event_cb), gl_sink);
|
|
|
|
|
2015-05-29 08:03:52 +00:00
|
|
|
if (gl_sink->x >= 0 && gl_sink->y >= 0 && gl_sink->width > 0 &&
|
|
|
|
gl_sink->height > 0) {
|
|
|
|
gst_gl_window_set_render_rectangle (window, gl_sink->x, gl_sink->y,
|
|
|
|
gl_sink->width, gl_sink->height);
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
if (other_context)
|
|
|
|
gst_object_unref (other_context);
|
|
|
|
gst_object_unref (window);
|
|
|
|
} while (!gst_gl_display_add_context (gl_sink->display, gl_sink->context));
|
2015-04-21 02:19:46 +00:00
|
|
|
GST_OBJECT_UNLOCK (gl_sink->display);
|
2015-02-12 13:56:12 +00:00
|
|
|
} else
|
2015-05-29 16:26:32 +00:00
|
|
|
GST_TRACE_OBJECT (gl_sink, "Already have a context");
|
2013-11-14 04:27:52 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
context_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (gl_sink, RESOURCE, NOT_FOUND, ("%s", error->message),
|
|
|
|
(NULL));
|
2015-06-15 15:09:54 +00:00
|
|
|
|
|
|
|
if (gl_sink->context) {
|
|
|
|
gst_object_unref (gl_sink->context);
|
|
|
|
gl_sink->context = NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-02 08:08:26 +00:00
|
|
|
g_clear_error (&error);
|
2015-06-15 15:09:54 +00:00
|
|
|
|
2013-11-14 04:27:52 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 12:02:28 +00:00
|
|
|
static gboolean
|
|
|
|
gst_glimage_sink_event (GstBaseSink * sink, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstGLImageSink *gl_sink = GST_GLIMAGE_SINK (sink);
|
|
|
|
GstTagList *taglist;
|
|
|
|
gchar *orientation;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (gl_sink, "handling %s event", GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_TAG:
|
|
|
|
gst_event_parse_tag (event, &taglist);
|
|
|
|
|
|
|
|
if (gst_tag_list_get_string (taglist, "image-orientation", &orientation)) {
|
|
|
|
if (!g_strcmp0 ("rotate-0", orientation))
|
|
|
|
gst_glimage_sink_set_rotate_method (gl_sink,
|
|
|
|
GST_GL_ROTATE_METHOD_IDENTITY, TRUE);
|
|
|
|
else if (!g_strcmp0 ("rotate-90", orientation))
|
|
|
|
gst_glimage_sink_set_rotate_method (gl_sink, GST_GL_ROTATE_METHOD_90R,
|
|
|
|
TRUE);
|
|
|
|
else if (!g_strcmp0 ("rotate-180", orientation))
|
|
|
|
gst_glimage_sink_set_rotate_method (gl_sink, GST_GL_ROTATE_METHOD_180,
|
|
|
|
TRUE);
|
|
|
|
else if (!g_strcmp0 ("rotate-270", orientation))
|
|
|
|
gst_glimage_sink_set_rotate_method (gl_sink, GST_GL_ROTATE_METHOD_90L,
|
|
|
|
TRUE);
|
|
|
|
else if (!g_strcmp0 ("flip-rotate-0", orientation))
|
|
|
|
gst_glimage_sink_set_rotate_method (gl_sink,
|
|
|
|
GST_GL_ROTATE_METHOD_FLIP_HORIZ, TRUE);
|
|
|
|
else if (!g_strcmp0 ("flip-rotate-90", orientation))
|
|
|
|
gst_glimage_sink_set_rotate_method (gl_sink,
|
|
|
|
GST_GL_ROTATE_METHOD_FLIP_UR_LL, TRUE);
|
|
|
|
else if (!g_strcmp0 ("flip-rotate-180", orientation))
|
|
|
|
gst_glimage_sink_set_rotate_method (gl_sink,
|
|
|
|
GST_GL_ROTATE_METHOD_FLIP_VERT, TRUE);
|
|
|
|
else if (!g_strcmp0 ("flip-rotate-270", orientation))
|
|
|
|
gst_glimage_sink_set_rotate_method (gl_sink,
|
|
|
|
GST_GL_ROTATE_METHOD_FLIP_UL_LR, TRUE);
|
|
|
|
|
|
|
|
g_free (orientation);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_BASE_SINK_CLASS (parent_class)->event (sink, event);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-04 00:23:45 +00:00
|
|
|
static gboolean
|
2012-08-10 05:31:20 +00:00
|
|
|
gst_glimage_sink_query (GstBaseSink * bsink, GstQuery * query)
|
2009-10-04 00:23:45 +00:00
|
|
|
{
|
2012-08-10 05:31:20 +00:00
|
|
|
GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (bsink);
|
2009-10-04 00:23:45 +00:00
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2013-11-12 23:43:16 +00:00
|
|
|
case GST_QUERY_CONTEXT:
|
|
|
|
{
|
2017-01-12 10:35:25 +00:00
|
|
|
if (gst_gl_handle_context_query ((GstElement *) glimage_sink, query,
|
|
|
|
glimage_sink->display, glimage_sink->context,
|
|
|
|
glimage_sink->other_context))
|
|
|
|
return TRUE;
|
2015-05-04 13:42:36 +00:00
|
|
|
break;
|
2013-11-12 23:43:16 +00:00
|
|
|
}
|
2014-11-11 23:49:59 +00:00
|
|
|
case GST_QUERY_DRAIN:
|
|
|
|
{
|
2015-05-29 16:26:32 +00:00
|
|
|
GstBuffer *buf[2];
|
2014-11-11 23:49:59 +00:00
|
|
|
|
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
|
|
|
glimage_sink->redisplay_texture = 0;
|
2015-05-29 16:26:32 +00:00
|
|
|
buf[0] = glimage_sink->stored_buffer[0];
|
|
|
|
buf[1] = glimage_sink->stored_buffer[1];
|
|
|
|
glimage_sink->stored_buffer[0] = glimage_sink->stored_buffer[1] = NULL;
|
2015-11-16 04:46:41 +00:00
|
|
|
glimage_sink->stored_sync_meta = glimage_sink->next_sync_meta = NULL;
|
2014-11-11 23:49:59 +00:00
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
gst_buffer_replace (buf, NULL);
|
|
|
|
gst_buffer_replace (buf + 1, NULL);
|
2014-11-11 23:49:59 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
gst_buffer_replace (&glimage_sink->input_buffer, NULL);
|
|
|
|
gst_buffer_replace (&glimage_sink->input_buffer2, NULL);
|
2014-11-11 23:49:59 +00:00
|
|
|
gst_buffer_replace (&glimage_sink->next_buffer, NULL);
|
2015-05-29 16:26:32 +00:00
|
|
|
gst_buffer_replace (&glimage_sink->next_buffer2, NULL);
|
2015-05-19 06:22:00 +00:00
|
|
|
gst_buffer_replace (&glimage_sink->next_sync, NULL);
|
2014-11-11 23:49:59 +00:00
|
|
|
|
|
|
|
res = GST_BASE_SINK_CLASS (parent_class)->query (bsink, query);
|
|
|
|
break;
|
|
|
|
}
|
2009-10-04 00:23:45 +00:00
|
|
|
default:
|
2012-08-10 05:31:20 +00:00
|
|
|
res = GST_BASE_SINK_CLASS (parent_class)->query (bsink, query);
|
2009-10-04 00:23:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
static void
|
|
|
|
gst_glimage_sink_set_context (GstElement * element, GstContext * context)
|
|
|
|
{
|
|
|
|
GstGLImageSink *gl_sink = GST_GLIMAGE_SINK (element);
|
|
|
|
|
2014-10-29 11:22:14 +00:00
|
|
|
gst_gl_handle_set_context (element, context, &gl_sink->display,
|
|
|
|
&gl_sink->other_context);
|
2014-11-27 10:05:45 +00:00
|
|
|
|
|
|
|
if (gl_sink->display)
|
|
|
|
gst_gl_display_filter_gl_api (gl_sink->display, SUPPORTED_GL_APIS);
|
2015-09-28 12:20:29 +00:00
|
|
|
|
|
|
|
GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
|
2013-11-12 23:43:16 +00:00
|
|
|
}
|
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
static GstStateChangeReturn
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
|
2014-05-25 20:43:22 +00:00
|
|
|
GST_DEBUG ("changing state: %s => %s",
|
|
|
|
gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)),
|
|
|
|
gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition)));
|
2009-02-11 06:39:14 +00:00
|
|
|
|
|
|
|
glimage_sink = GST_GLIMAGE_SINK (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2015-03-13 09:38:54 +00:00
|
|
|
if (!gst_gl_ensure_element_data (glimage_sink, &glimage_sink->display,
|
|
|
|
&glimage_sink->other_context))
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
|
|
|
|
gst_gl_display_filter_gl_api (glimage_sink->display, SUPPORTED_GL_APIS);
|
2015-10-15 20:03:06 +00:00
|
|
|
|
2015-04-21 02:19:46 +00:00
|
|
|
if (!_ensure_gl_setup (glimage_sink))
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
2015-10-15 20:03:06 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2013-06-12 13:17:30 +00:00
|
|
|
g_atomic_int_set (&glimage_sink->to_quit, 0);
|
2009-02-11 06:39:14 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
2009-02-11 05:57:31 +00:00
|
|
|
return ret;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2009-10-04 00:23:45 +00:00
|
|
|
{
|
2015-05-29 16:26:32 +00:00
|
|
|
GstBuffer *buf[2];
|
|
|
|
|
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
2013-08-28 09:32:29 +00:00
|
|
|
/* mark the redisplay_texture as unavailable (=0)
|
|
|
|
* to avoid drawing
|
|
|
|
*/
|
2015-05-29 16:26:32 +00:00
|
|
|
glimage_sink->redisplay_texture = 0;
|
|
|
|
buf[0] = glimage_sink->stored_buffer[0];
|
|
|
|
buf[1] = glimage_sink->stored_buffer[1];
|
|
|
|
glimage_sink->stored_buffer[0] = glimage_sink->stored_buffer[1] = NULL;
|
2015-11-16 04:46:41 +00:00
|
|
|
glimage_sink->stored_sync_meta = glimage_sink->next_sync_meta = NULL;
|
2015-05-29 16:26:32 +00:00
|
|
|
|
2015-05-19 06:22:00 +00:00
|
|
|
if (glimage_sink->stored_sync)
|
|
|
|
gst_buffer_unref (glimage_sink->stored_sync);
|
|
|
|
glimage_sink->stored_sync = NULL;
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
|
|
|
|
|
|
|
gst_buffer_replace (buf, NULL);
|
|
|
|
gst_buffer_replace (buf + 1, NULL);
|
|
|
|
|
|
|
|
gst_object_replace ((GstObject **) & glimage_sink->convert_views, NULL);
|
|
|
|
gst_buffer_replace (&glimage_sink->input_buffer, NULL);
|
|
|
|
gst_buffer_replace (&glimage_sink->input_buffer2, NULL);
|
2014-09-21 11:36:49 +00:00
|
|
|
gst_buffer_replace (&glimage_sink->next_buffer, NULL);
|
2015-05-29 16:26:32 +00:00
|
|
|
gst_buffer_replace (&glimage_sink->next_buffer2, NULL);
|
2015-05-19 06:22:00 +00:00
|
|
|
gst_buffer_replace (&glimage_sink->next_sync, NULL);
|
2015-05-29 16:26:32 +00:00
|
|
|
|
2009-10-04 00:23:45 +00:00
|
|
|
glimage_sink->window_id = 0;
|
2015-03-05 20:49:50 +00:00
|
|
|
/* but do not reset glimage_sink->new_window_id */
|
2013-07-16 12:11:46 +00:00
|
|
|
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_VIDEO_SINK_WIDTH (glimage_sink) = 1;
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink) = 1;
|
2015-04-28 16:30:05 +00:00
|
|
|
/* Clear cached caps */
|
2015-05-29 16:26:32 +00:00
|
|
|
if (glimage_sink->out_caps) {
|
|
|
|
gst_caps_unref (glimage_sink->out_caps);
|
|
|
|
glimage_sink->out_caps = NULL;
|
2015-04-28 16:30:05 +00:00
|
|
|
}
|
2015-11-10 02:52:30 +00:00
|
|
|
if (glimage_sink->in_caps) {
|
|
|
|
gst_caps_unref (glimage_sink->in_caps);
|
|
|
|
glimage_sink->in_caps = NULL;
|
|
|
|
}
|
2015-10-15 20:03:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2015-11-11 02:37:59 +00:00
|
|
|
if (glimage_sink->overlay_compositor) {
|
|
|
|
gst_object_unref (glimage_sink->overlay_compositor);
|
|
|
|
glimage_sink->overlay_compositor = NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
if (glimage_sink->context) {
|
|
|
|
GstGLWindow *window = gst_gl_context_get_window (glimage_sink->context);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2013-07-16 12:11:46 +00:00
|
|
|
gst_gl_window_send_message (window,
|
|
|
|
GST_GL_WINDOW_CB (gst_glimage_sink_cleanup_glthread), glimage_sink);
|
|
|
|
|
2013-07-15 13:58:04 +00:00
|
|
|
gst_gl_window_set_resize_callback (window, NULL, NULL, NULL);
|
|
|
|
gst_gl_window_set_draw_callback (window, NULL, NULL, NULL);
|
|
|
|
gst_gl_window_set_close_callback (window, NULL, NULL, NULL);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2015-04-07 03:28:22 +00:00
|
|
|
if (glimage_sink->key_sig_id)
|
|
|
|
g_signal_handler_disconnect (window, glimage_sink->key_sig_id);
|
|
|
|
glimage_sink->key_sig_id = 0;
|
|
|
|
if (glimage_sink->mouse_sig_id)
|
|
|
|
g_signal_handler_disconnect (window, glimage_sink->mouse_sig_id);
|
|
|
|
glimage_sink->mouse_sig_id = 0;
|
|
|
|
|
2013-06-13 04:36:41 +00:00
|
|
|
gst_object_unref (window);
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_object_unref (glimage_sink->context);
|
|
|
|
glimage_sink->context = NULL;
|
2014-06-29 20:25:43 +00:00
|
|
|
}
|
2016-04-19 06:30:39 +00:00
|
|
|
|
2016-04-19 02:51:14 +00:00
|
|
|
glimage_sink->window_id = 0;
|
2015-10-15 20:03:06 +00:00
|
|
|
|
2015-04-27 05:20:56 +00:00
|
|
|
if (glimage_sink->other_context) {
|
|
|
|
gst_object_unref (glimage_sink->other_context);
|
|
|
|
glimage_sink->other_context = NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-29 20:25:43 +00:00
|
|
|
if (glimage_sink->display) {
|
2013-06-13 04:36:41 +00:00
|
|
|
gst_object_unref (glimage_sink->display);
|
2013-06-11 08:50:12 +00:00
|
|
|
glimage_sink->display = NULL;
|
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_glimage_sink_get_times (GstBaseSink * bsink, GstBuffer * buf,
|
|
|
|
GstClockTime * start, GstClockTime * end)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLImageSink *glimagesink;
|
|
|
|
|
|
|
|
glimagesink = GST_GLIMAGE_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 {
|
2015-05-29 16:26:32 +00:00
|
|
|
if (GST_VIDEO_INFO_FPS_N (&glimagesink->out_info) > 0) {
|
2009-02-11 06:39:14 +00:00
|
|
|
*end = *start +
|
2012-07-12 08:07:34 +00:00
|
|
|
gst_util_uint64_scale_int (GST_SECOND,
|
2015-05-29 16:26:32 +00:00
|
|
|
GST_VIDEO_INFO_FPS_D (&glimagesink->out_info),
|
|
|
|
GST_VIDEO_INFO_FPS_N (&glimagesink->out_info));
|
2009-02-11 06:39:14 +00:00
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_glimage_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
|
|
|
|
{
|
|
|
|
GstCaps *tmp = NULL;
|
|
|
|
GstCaps *result = NULL;
|
|
|
|
|
2015-04-28 07:37:59 +00:00
|
|
|
tmp = gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD (bsink));
|
2015-02-02 13:11:06 +00:00
|
|
|
|
|
|
|
if (filter) {
|
2015-05-29 16:26:32 +00:00
|
|
|
GST_DEBUG_OBJECT (bsink, "intersecting with filter caps %" GST_PTR_FORMAT,
|
|
|
|
filter);
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
} else {
|
|
|
|
result = tmp;
|
|
|
|
}
|
|
|
|
|
2015-06-18 03:43:50 +00:00
|
|
|
result = gst_gl_overlay_compositor_add_caps (result);
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
GST_DEBUG_OBJECT (bsink, "returning caps: %" GST_PTR_FORMAT, result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
static gboolean
|
2015-05-29 16:26:32 +00:00
|
|
|
configure_display_from_info (GstGLImageSink * glimage_sink,
|
|
|
|
GstVideoInfo * vinfo)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gboolean ok;
|
|
|
|
gint par_n, par_d;
|
2010-05-04 09:37:38 +00:00
|
|
|
gint display_par_n, display_par_d;
|
|
|
|
guint display_ratio_num, display_ratio_den;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
width = GST_VIDEO_INFO_WIDTH (vinfo);
|
|
|
|
height = GST_VIDEO_INFO_HEIGHT (vinfo);
|
2009-10-04 00:23:45 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
par_n = GST_VIDEO_INFO_PAR_N (vinfo);
|
|
|
|
par_d = GST_VIDEO_INFO_PAR_D (vinfo);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-07-12 08:07:34 +00:00
|
|
|
if (!par_n)
|
|
|
|
par_n = 1;
|
|
|
|
|
2010-05-04 09:37:38 +00:00
|
|
|
/* get display's PAR */
|
2013-07-16 12:22:53 +00:00
|
|
|
if (glimage_sink->par_n != 0 && glimage_sink->par_d != 0) {
|
|
|
|
display_par_n = glimage_sink->par_n;
|
|
|
|
display_par_d = glimage_sink->par_d;
|
2010-05-04 09:37:38 +00:00
|
|
|
} else {
|
|
|
|
display_par_n = 1;
|
|
|
|
display_par_d = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok = gst_video_calculate_display_ratio (&display_ratio_num,
|
|
|
|
&display_ratio_den, width, height, par_n, par_d, display_par_n,
|
|
|
|
display_par_d);
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_TRACE ("PAR: %u/%u DAR:%u/%u", par_n, par_d, display_par_n,
|
|
|
|
display_par_d);
|
|
|
|
|
2010-05-04 09:37:38 +00:00
|
|
|
if (height % display_ratio_den == 0) {
|
|
|
|
GST_DEBUG ("keeping video height");
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_VIDEO_SINK_WIDTH (glimage_sink) = (guint)
|
2010-05-04 09:37:38 +00:00
|
|
|
gst_util_uint64_scale_int (height, display_ratio_num,
|
|
|
|
display_ratio_den);
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink) = height;
|
2010-05-04 09:37:38 +00:00
|
|
|
} else if (width % display_ratio_num == 0) {
|
|
|
|
GST_DEBUG ("keeping video width");
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_VIDEO_SINK_WIDTH (glimage_sink) = width;
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink) = (guint)
|
2010-05-04 09:37:38 +00:00
|
|
|
gst_util_uint64_scale_int (width, display_ratio_den, display_ratio_num);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("approximating while keeping video height");
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_VIDEO_SINK_WIDTH (glimage_sink) = (guint)
|
2010-05-04 09:37:38 +00:00
|
|
|
gst_util_uint64_scale_int (height, display_ratio_num,
|
|
|
|
display_ratio_den);
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink) = height;
|
2010-05-04 09:37:38 +00:00
|
|
|
}
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_DEBUG ("scaling to %dx%d", GST_VIDEO_SINK_WIDTH (glimage_sink),
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink));
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-04-28 16:30:05 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
/* Called with GST_GLIMAGE_SINK lock held, to
|
|
|
|
* copy in_info to out_info and update out_caps */
|
|
|
|
static gboolean
|
|
|
|
update_output_format (GstGLImageSink * glimage_sink)
|
|
|
|
{
|
|
|
|
GstVideoInfo *out_info = &glimage_sink->out_info;
|
|
|
|
gboolean input_is_mono = FALSE;
|
|
|
|
GstVideoMultiviewMode mv_mode;
|
2015-09-17 07:22:47 +00:00
|
|
|
GstGLWindow *window = NULL;
|
2015-11-10 04:37:05 +00:00
|
|
|
GstGLTextureTarget previous_target;
|
|
|
|
GstStructure *s;
|
|
|
|
const gchar *target_str;
|
2015-11-10 02:52:30 +00:00
|
|
|
GstCaps *out_caps;
|
2015-05-29 16:26:32 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
*out_info = glimage_sink->in_info;
|
2015-11-10 04:37:05 +00:00
|
|
|
previous_target = glimage_sink->texture_target;
|
2015-05-29 16:26:32 +00:00
|
|
|
|
|
|
|
mv_mode = GST_VIDEO_INFO_MULTIVIEW_MODE (&glimage_sink->in_info);
|
|
|
|
|
|
|
|
if (mv_mode == GST_VIDEO_MULTIVIEW_MODE_NONE ||
|
|
|
|
mv_mode == GST_VIDEO_MULTIVIEW_MODE_MONO ||
|
|
|
|
mv_mode == GST_VIDEO_MULTIVIEW_MODE_LEFT ||
|
|
|
|
mv_mode == GST_VIDEO_MULTIVIEW_MODE_RIGHT)
|
|
|
|
input_is_mono = TRUE;
|
|
|
|
|
|
|
|
if (input_is_mono == FALSE &&
|
|
|
|
glimage_sink->mview_output_mode != GST_VIDEO_MULTIVIEW_MODE_NONE) {
|
|
|
|
/* Input is multiview, and output wants a conversion - configure 3d converter now,
|
|
|
|
* otherwise defer it until either the caps or the 3D output mode changes */
|
|
|
|
gst_video_multiview_video_info_change_mode (out_info,
|
|
|
|
glimage_sink->mview_output_mode, glimage_sink->mview_output_flags);
|
2014-04-06 09:57:12 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
if (glimage_sink->convert_views == NULL) {
|
|
|
|
glimage_sink->convert_views = gst_gl_view_convert_new ();
|
|
|
|
gst_gl_view_convert_set_context (glimage_sink->convert_views,
|
|
|
|
glimage_sink->context);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (glimage_sink->convert_views) {
|
|
|
|
gst_object_unref (glimage_sink->convert_views);
|
|
|
|
glimage_sink->convert_views = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = configure_display_from_info (glimage_sink, out_info);
|
|
|
|
|
|
|
|
if (glimage_sink->convert_views) {
|
|
|
|
/* Match actual output window size for pixel-aligned output,
|
|
|
|
* even though we can't necessarily match the starting left/right
|
|
|
|
* view parity properly */
|
|
|
|
glimage_sink->out_info.width = MAX (1, glimage_sink->display_rect.w);
|
|
|
|
glimage_sink->out_info.height = MAX (1, glimage_sink->display_rect.h);
|
|
|
|
GST_LOG_OBJECT (glimage_sink, "Set 3D output scale to %d,%d",
|
|
|
|
glimage_sink->display_rect.w, glimage_sink->display_rect.h);
|
2015-11-10 02:52:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 04:37:05 +00:00
|
|
|
s = gst_caps_get_structure (glimage_sink->in_caps, 0);
|
|
|
|
target_str = gst_structure_get_string (s, "texture-target");
|
|
|
|
|
|
|
|
if (!target_str)
|
|
|
|
target_str = GST_GL_TEXTURE_TARGET_2D_STR;
|
|
|
|
|
|
|
|
glimage_sink->texture_target = gst_gl_texture_target_from_string (target_str);
|
|
|
|
if (!glimage_sink->texture_target)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-11-10 02:52:30 +00:00
|
|
|
out_caps = gst_video_info_to_caps (out_info);
|
|
|
|
gst_caps_set_features (out_caps, 0,
|
|
|
|
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY));
|
2015-11-10 04:37:05 +00:00
|
|
|
gst_caps_set_simple (out_caps, "texture-target", G_TYPE_STRING,
|
|
|
|
target_str, NULL);
|
2015-11-10 02:52:30 +00:00
|
|
|
|
|
|
|
if (glimage_sink->convert_views) {
|
|
|
|
gst_caps_set_simple (out_caps, "texture-target", G_TYPE_STRING,
|
|
|
|
GST_GL_TEXTURE_TARGET_2D_STR, NULL);
|
2015-05-29 16:26:32 +00:00
|
|
|
|
2015-11-10 04:37:05 +00:00
|
|
|
glimage_sink->texture_target = GST_GL_TEXTURE_TARGET_2D;
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
2015-11-10 02:52:30 +00:00
|
|
|
gst_gl_view_convert_set_caps (glimage_sink->convert_views,
|
|
|
|
glimage_sink->in_caps, out_caps);
|
2015-05-29 16:26:32 +00:00
|
|
|
g_object_set (glimage_sink->convert_views, "downmix-mode",
|
|
|
|
glimage_sink->mview_downmix_mode, NULL);
|
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
|
|
|
}
|
|
|
|
|
2015-11-10 02:52:30 +00:00
|
|
|
if (glimage_sink->out_caps)
|
|
|
|
gst_caps_unref (glimage_sink->out_caps);
|
|
|
|
glimage_sink->out_caps = out_caps;
|
|
|
|
|
2015-11-10 04:37:05 +00:00
|
|
|
if (previous_target != GST_GL_TEXTURE_TARGET_NONE &&
|
|
|
|
glimage_sink->texture_target != previous_target) {
|
|
|
|
/* regenerate the shader for the changed target */
|
|
|
|
GstGLWindow *window = gst_gl_context_get_window (glimage_sink->context);
|
|
|
|
gst_gl_window_send_message (window,
|
|
|
|
GST_GL_WINDOW_CB (gst_glimage_sink_cleanup_glthread), glimage_sink);
|
|
|
|
gst_object_unref (window);
|
|
|
|
}
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
glimage_sink->output_mode_changed = FALSE;
|
2015-09-17 07:22:47 +00:00
|
|
|
|
|
|
|
if (glimage_sink->context)
|
|
|
|
window = gst_gl_context_get_window (glimage_sink->context);
|
|
|
|
if (window) {
|
|
|
|
gst_gl_window_queue_resize (window);
|
|
|
|
gst_object_unref (window);
|
|
|
|
}
|
2014-05-06 23:11:25 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
return ret;
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
static gboolean
|
|
|
|
gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2012-06-05 12:59:31 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
2015-05-29 16:26:32 +00:00
|
|
|
gboolean ok;
|
|
|
|
GstVideoInfo vinfo;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bsink, "set caps with %" GST_PTR_FORMAT, caps);
|
2012-07-12 08:07:34 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (bsink);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
ok = gst_video_info_from_caps (&vinfo, caps);
|
|
|
|
if (!ok)
|
|
|
|
return FALSE;
|
2014-04-13 12:14:52 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
if (!_ensure_gl_setup (glimage_sink))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
2015-11-10 02:52:30 +00:00
|
|
|
if (glimage_sink->in_caps)
|
|
|
|
gst_caps_unref (glimage_sink->in_caps);
|
|
|
|
glimage_sink->in_caps = gst_caps_ref (caps);
|
2015-05-29 16:26:32 +00:00
|
|
|
glimage_sink->in_info = vinfo;
|
|
|
|
ok = update_output_format (glimage_sink);
|
|
|
|
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Take the input_buffer and run it through 3D conversion if needed.
|
|
|
|
* Called with glimagesink lock, but might drop it temporarily */
|
|
|
|
static gboolean
|
|
|
|
prepare_next_buffer (GstGLImageSink * glimage_sink)
|
|
|
|
{
|
|
|
|
GstBuffer *in_buffer, *next_buffer, *old_buffer;
|
|
|
|
GstBuffer *in_buffer2 = NULL, *next_buffer2 = NULL, *old_buffer2;
|
2015-11-16 04:46:41 +00:00
|
|
|
GstBuffer *next_sync = NULL, *old_sync;
|
2015-05-29 16:26:32 +00:00
|
|
|
GstGLSyncMeta *sync_meta;
|
|
|
|
GstVideoFrame gl_frame;
|
|
|
|
GstGLViewConvert *convert_views = NULL;
|
|
|
|
GstVideoInfo *info;
|
|
|
|
|
|
|
|
if (glimage_sink->input_buffer == NULL)
|
|
|
|
return TRUE; /* No input buffer to process */
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_MULTIVIEW_MODE (&glimage_sink->in_info) ==
|
|
|
|
GST_VIDEO_MULTIVIEW_MODE_FRAME_BY_FRAME) {
|
|
|
|
if (glimage_sink->input_buffer2 == NULL)
|
|
|
|
return TRUE; /* Need 2nd input buffer to process */
|
|
|
|
in_buffer2 = gst_buffer_ref (glimage_sink->input_buffer2);
|
2012-09-20 13:16:08 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
in_buffer = gst_buffer_ref (glimage_sink->input_buffer);
|
|
|
|
if (glimage_sink->convert_views &&
|
|
|
|
(GST_VIDEO_INFO_MULTIVIEW_MODE (&glimage_sink->in_info) !=
|
|
|
|
GST_VIDEO_INFO_MULTIVIEW_MODE (&glimage_sink->out_info) ||
|
|
|
|
GST_VIDEO_INFO_MULTIVIEW_FLAGS (&glimage_sink->in_info) !=
|
|
|
|
GST_VIDEO_INFO_MULTIVIEW_FLAGS (&glimage_sink->out_info)))
|
|
|
|
convert_views = gst_object_ref (glimage_sink->convert_views);
|
|
|
|
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
|
|
|
|
|
|
|
if (convert_views) {
|
|
|
|
info = &glimage_sink->out_info;
|
|
|
|
|
|
|
|
if (gst_gl_view_convert_submit_input_buffer (glimage_sink->convert_views,
|
|
|
|
GST_BUFFER_IS_DISCONT (in_buffer), in_buffer) != GST_FLOW_OK) {
|
|
|
|
gst_buffer_replace (&in_buffer2, NULL);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (in_buffer2) {
|
|
|
|
if (gst_gl_view_convert_submit_input_buffer (glimage_sink->convert_views,
|
|
|
|
GST_BUFFER_IS_DISCONT (in_buffer2), in_buffer2) != GST_FLOW_OK) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
2013-11-12 23:43:16 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
if (gst_gl_view_convert_get_output (glimage_sink->convert_views,
|
|
|
|
&next_buffer) != GST_FLOW_OK)
|
|
|
|
goto fail;
|
|
|
|
if (GST_VIDEO_INFO_MULTIVIEW_MODE (info) ==
|
|
|
|
GST_VIDEO_MULTIVIEW_MODE_FRAME_BY_FRAME) {
|
|
|
|
if (gst_gl_view_convert_get_output (glimage_sink->convert_views,
|
|
|
|
&next_buffer2) != GST_FLOW_OK)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
gst_object_unref (convert_views);
|
2015-11-10 23:31:07 +00:00
|
|
|
convert_views = NULL;
|
2015-05-29 16:26:32 +00:00
|
|
|
|
|
|
|
if (next_buffer == NULL) {
|
|
|
|
/* Not ready to paint a buffer yet */
|
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
next_buffer = in_buffer;
|
|
|
|
info = &glimage_sink->in_info;
|
|
|
|
}
|
2015-06-18 04:04:37 +00:00
|
|
|
|
2015-11-11 02:37:59 +00:00
|
|
|
if (!glimage_sink->overlay_compositor) {
|
|
|
|
if (!(glimage_sink->overlay_compositor =
|
|
|
|
gst_gl_overlay_compositor_new (glimage_sink->context))) {
|
|
|
|
gst_buffer_unref (next_buffer);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-21 22:47:56 +00:00
|
|
|
gst_gl_overlay_compositor_upload_overlays (glimage_sink->overlay_compositor,
|
2015-07-22 03:48:25 +00:00
|
|
|
next_buffer);
|
2015-06-18 04:04:37 +00:00
|
|
|
|
2015-11-16 04:46:41 +00:00
|
|
|
sync_meta = gst_buffer_get_gl_sync_meta (next_buffer);
|
|
|
|
|
|
|
|
if (!sync_meta) {
|
|
|
|
next_sync = gst_buffer_new ();
|
|
|
|
sync_meta = gst_buffer_add_gl_sync_meta (glimage_sink->context, next_sync);
|
|
|
|
gst_gl_sync_meta_set_sync_point (sync_meta, glimage_sink->context);
|
|
|
|
}
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
/* in_buffer invalid now */
|
|
|
|
if (!gst_video_frame_map (&gl_frame, info, next_buffer,
|
2014-11-05 09:18:06 +00:00
|
|
|
GST_MAP_READ | GST_MAP_GL)) {
|
2015-05-29 16:26:32 +00:00
|
|
|
gst_buffer_unref (next_buffer);
|
2015-11-13 16:09:13 +00:00
|
|
|
GST_ERROR ("Failed to map video frame.");
|
2015-05-29 16:26:32 +00:00
|
|
|
goto fail;
|
2014-11-05 09:18:06 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 06:22:00 +00:00
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
2014-11-05 09:18:06 +00:00
|
|
|
glimage_sink->next_tex = *(guint *) gl_frame.data[0];
|
|
|
|
|
2015-05-19 06:22:00 +00:00
|
|
|
old_buffer = glimage_sink->next_buffer;
|
2015-05-29 16:26:32 +00:00
|
|
|
glimage_sink->next_buffer = next_buffer;
|
|
|
|
old_buffer2 = glimage_sink->next_buffer2;
|
|
|
|
glimage_sink->next_buffer2 = next_buffer2;
|
2015-05-19 06:22:00 +00:00
|
|
|
|
|
|
|
old_sync = glimage_sink->next_sync;
|
|
|
|
glimage_sink->next_sync = next_sync;
|
2015-11-16 04:46:41 +00:00
|
|
|
glimage_sink->next_sync_meta = sync_meta;
|
2015-05-29 16:26:32 +00:00
|
|
|
|
|
|
|
/* Need to drop the lock again, to avoid a deadlock if we're
|
|
|
|
* dropping the last ref on this buffer and it goes back to our
|
|
|
|
* allocator */
|
2015-05-19 06:22:00 +00:00
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
|
|
|
|
|
|
|
if (old_buffer)
|
|
|
|
gst_buffer_unref (old_buffer);
|
2015-05-29 16:26:32 +00:00
|
|
|
if (old_buffer2)
|
|
|
|
gst_buffer_unref (old_buffer2);
|
2015-05-19 06:22:00 +00:00
|
|
|
if (old_sync)
|
|
|
|
gst_buffer_unref (old_sync);
|
2014-11-05 09:18:06 +00:00
|
|
|
gst_video_frame_unmap (&gl_frame);
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
fail:
|
2015-11-10 23:31:07 +00:00
|
|
|
if (convert_views)
|
|
|
|
gst_object_unref (convert_views);
|
2015-05-29 16:26:32 +00:00
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_glimage_sink_prepare (GstBaseSink * bsink, GstBuffer * buf)
|
|
|
|
{
|
|
|
|
GstGLImageSink *glimage_sink;
|
2015-11-04 13:13:01 +00:00
|
|
|
GstGLSyncMeta *sync_meta;
|
2015-05-29 16:26:32 +00:00
|
|
|
GstBuffer **target;
|
|
|
|
GstBuffer *old_input;
|
|
|
|
|
|
|
|
glimage_sink = GST_GLIMAGE_SINK (bsink);
|
|
|
|
|
|
|
|
GST_TRACE ("preparing buffer:%p", buf);
|
|
|
|
|
|
|
|
if (GST_VIDEO_SINK_WIDTH (glimage_sink) < 1 ||
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink) < 1) {
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_ensure_gl_setup (glimage_sink))
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
|
2015-12-18 00:49:25 +00:00
|
|
|
sync_meta = gst_buffer_get_gl_sync_meta (buf);
|
|
|
|
if (sync_meta)
|
|
|
|
gst_gl_sync_meta_wait (sync_meta, glimage_sink->context);
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
2016-01-13 02:17:56 +00:00
|
|
|
if (glimage_sink->window_resized) {
|
|
|
|
glimage_sink->window_resized = FALSE;
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
|
|
|
GST_DEBUG_OBJECT (glimage_sink, "Sending reconfigure event on sinkpad.");
|
|
|
|
gst_pad_push_event (GST_BASE_SINK (glimage_sink)->sinkpad,
|
|
|
|
gst_event_new_reconfigure ());
|
|
|
|
GST_GLIMAGE_SINK_LOCK (glimage_sink);
|
|
|
|
}
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
target = &glimage_sink->input_buffer;
|
|
|
|
if (GST_VIDEO_INFO_MULTIVIEW_MODE (&glimage_sink->in_info) ==
|
|
|
|
GST_VIDEO_MULTIVIEW_MODE_FRAME_BY_FRAME &&
|
|
|
|
!GST_BUFFER_FLAG_IS_SET (buf, GST_VIDEO_BUFFER_FLAG_FIRST_IN_BUNDLE)) {
|
|
|
|
target = &glimage_sink->input_buffer2;
|
|
|
|
}
|
|
|
|
old_input = *target;
|
|
|
|
*target = gst_buffer_ref (buf);
|
|
|
|
|
|
|
|
if (glimage_sink->output_mode_changed)
|
|
|
|
update_output_format (glimage_sink);
|
|
|
|
|
|
|
|
if (!prepare_next_buffer (glimage_sink)) {
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
|
|
|
if (old_input)
|
|
|
|
gst_buffer_unref (old_input);
|
|
|
|
goto convert_views_failed;
|
|
|
|
}
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (glimage_sink);
|
|
|
|
|
|
|
|
if (old_input)
|
|
|
|
gst_buffer_unref (old_input);
|
|
|
|
|
2009-06-06 12:34:57 +00:00
|
|
|
if (glimage_sink->window_id != glimage_sink->new_window_id) {
|
2013-09-15 04:23:43 +00:00
|
|
|
GstGLWindow *window = gst_gl_context_get_window (glimage_sink->context);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2009-06-06 12:34:57 +00:00
|
|
|
glimage_sink->window_id = glimage_sink->new_window_id;
|
2013-06-12 13:17:30 +00:00
|
|
|
gst_gl_window_set_window_handle (window, glimage_sink->window_id);
|
|
|
|
|
|
|
|
gst_object_unref (window);
|
2009-06-06 12:34:57 +00:00
|
|
|
}
|
2013-06-13 04:36:41 +00:00
|
|
|
|
2014-04-13 12:14:52 +00:00
|
|
|
return GST_FLOW_OK;
|
2015-05-29 16:26:32 +00:00
|
|
|
convert_views_failed:
|
2014-04-13 12:14:52 +00:00
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (glimage_sink, RESOURCE, NOT_FOUND,
|
2015-05-29 16:26:32 +00:00
|
|
|
("%s", "Failed to convert multiview video buffer"), (NULL));
|
2014-04-13 12:14:52 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2014-05-27 10:28:27 +00:00
|
|
|
gst_glimage_sink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
|
2014-04-13 12:14:52 +00:00
|
|
|
{
|
|
|
|
GstGLImageSink *glimage_sink;
|
|
|
|
|
|
|
|
GST_TRACE ("rendering buffer:%p", buf);
|
|
|
|
|
2014-05-27 10:28:27 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (vsink);
|
2014-04-13 12:14:52 +00:00
|
|
|
|
|
|
|
GST_TRACE ("redisplay texture:%u of size:%ux%u, window size:%ux%u",
|
2015-05-29 16:26:32 +00:00
|
|
|
glimage_sink->next_tex, GST_VIDEO_INFO_WIDTH (&glimage_sink->out_info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&glimage_sink->out_info),
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_VIDEO_SINK_WIDTH (glimage_sink),
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink));
|
|
|
|
|
2013-08-28 09:07:24 +00:00
|
|
|
/* Ask the underlying window to redraw its content */
|
|
|
|
if (!gst_glimage_sink_redisplay (glimage_sink))
|
2012-07-06 09:07:45 +00:00
|
|
|
goto redisplay_failed;
|
|
|
|
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_TRACE ("post redisplay");
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
if (g_atomic_int_get (&glimage_sink->to_quit) != 0) {
|
|
|
|
GST_ELEMENT_ERROR (glimage_sink, RESOURCE, NOT_FOUND,
|
2016-07-12 05:29:29 +00:00
|
|
|
("%s", "Quit requested"), (NULL));
|
2013-06-12 13:17:30 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-07-06 09:07:45 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
redisplay_failed:
|
|
|
|
{
|
2011-11-24 15:02:32 +00:00
|
|
|
GST_ELEMENT_ERROR (glimage_sink, RESOURCE, NOT_FOUND,
|
2016-07-12 05:29:29 +00:00
|
|
|
("%s", "Window redisplay failed"), (NULL));
|
2011-11-24 15:02:32 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2012-07-06 09:07:45 +00:00
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-05 12:59:31 +00:00
|
|
|
gst_glimage_sink_video_overlay_init (GstVideoOverlayInterface * iface)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2010-09-16 12:00:29 +00:00
|
|
|
iface->set_window_handle = gst_glimage_sink_set_window_handle;
|
2015-05-29 08:03:52 +00:00
|
|
|
iface->set_render_rectangle = gst_glimage_sink_set_render_rectangle;
|
2014-10-29 11:24:16 +00:00
|
|
|
iface->handle_events = gst_glimage_sink_handle_events;
|
2009-02-11 06:39:14 +00:00
|
|
|
iface->expose = gst_glimage_sink_expose;
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-05 12:59:31 +00:00
|
|
|
gst_glimage_sink_set_window_handle (GstVideoOverlay * overlay, guintptr id)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (overlay);
|
2013-07-17 09:22:02 +00:00
|
|
|
guintptr window_id = (guintptr) id;
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
g_return_if_fail (GST_IS_GLIMAGE_SINK (overlay));
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2013-07-19 14:28:20 +00:00
|
|
|
GST_DEBUG ("set_xwindow_id %" G_GUINT64_FORMAT, (guint64) window_id);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-06-06 12:34:57 +00:00
|
|
|
glimage_sink->new_window_id = window_id;
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2012-06-05 12:59:31 +00:00
|
|
|
gst_glimage_sink_expose (GstVideoOverlay * overlay)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (overlay);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2013-06-11 02:26:50 +00:00
|
|
|
/* redisplay opengl scene */
|
2017-09-11 08:11:19 +00:00
|
|
|
if (glimage_sink->display) {
|
|
|
|
if (glimage_sink->window_id
|
|
|
|
&& glimage_sink->window_id != glimage_sink->new_window_id) {
|
2013-09-15 04:23:43 +00:00
|
|
|
GstGLWindow *window = gst_gl_context_get_window (glimage_sink->context);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2009-06-09 18:35:26 +00:00
|
|
|
glimage_sink->window_id = glimage_sink->new_window_id;
|
2013-06-12 13:17:30 +00:00
|
|
|
gst_gl_window_set_window_handle (window, glimage_sink->window_id);
|
|
|
|
|
|
|
|
gst_object_unref (window);
|
2009-06-09 18:35:26 +00:00
|
|
|
}
|
|
|
|
|
2013-08-28 09:07:24 +00:00
|
|
|
gst_glimage_sink_redisplay (glimage_sink);
|
2009-06-09 18:35:26 +00:00
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
2012-07-06 09:07:45 +00:00
|
|
|
|
2014-10-29 11:24:16 +00:00
|
|
|
static void
|
|
|
|
gst_glimage_sink_handle_events (GstVideoOverlay * overlay,
|
|
|
|
gboolean handle_events)
|
|
|
|
{
|
|
|
|
GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (overlay);
|
|
|
|
|
|
|
|
glimage_sink->handle_events = handle_events;
|
|
|
|
if (G_LIKELY (glimage_sink->context)) {
|
|
|
|
GstGLWindow *window;
|
|
|
|
window = gst_gl_context_get_window (glimage_sink->context);
|
|
|
|
gst_gl_window_handle_events (window, handle_events);
|
|
|
|
gst_object_unref (window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 08:03:52 +00:00
|
|
|
static void
|
|
|
|
gst_glimage_sink_set_render_rectangle (GstVideoOverlay * overlay,
|
|
|
|
gint x, gint y, gint width, gint height)
|
|
|
|
{
|
|
|
|
GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (overlay);
|
|
|
|
|
|
|
|
if (G_LIKELY (glimage_sink->context)) {
|
|
|
|
GstGLWindow *window;
|
|
|
|
window = gst_gl_context_get_window (glimage_sink->context);
|
|
|
|
gst_gl_window_set_render_rectangle (window, x, y, width, height);
|
|
|
|
gst_object_unref (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
glimage_sink->x = x;
|
|
|
|
glimage_sink->y = y;
|
|
|
|
glimage_sink->width = width;
|
|
|
|
glimage_sink->height = height;
|
|
|
|
}
|
|
|
|
|
2012-07-06 09:07:45 +00:00
|
|
|
static gboolean
|
|
|
|
gst_glimage_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (bsink);
|
|
|
|
GstStructure *config;
|
|
|
|
GstCaps *caps;
|
2017-09-05 20:20:44 +00:00
|
|
|
GstBufferPool *pool = NULL;
|
|
|
|
GstVideoInfo info;
|
2012-07-06 09:07:45 +00:00
|
|
|
guint size;
|
|
|
|
gboolean need_pool;
|
2015-07-20 18:24:22 +00:00
|
|
|
GstStructure *allocation_meta = NULL;
|
2012-07-06 09:07:45 +00:00
|
|
|
|
2013-11-14 04:27:52 +00:00
|
|
|
if (!_ensure_gl_setup (glimage_sink))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-07-06 09:07:45 +00:00
|
|
|
gst_query_parse_allocation (query, &caps, &need_pool);
|
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
goto no_caps;
|
|
|
|
|
2017-09-05 20:20:44 +00:00
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto invalid_caps;
|
2012-07-06 09:07:45 +00:00
|
|
|
|
2017-09-05 20:20:44 +00:00
|
|
|
/* the normal size of a frame */
|
|
|
|
size = info.size;
|
2012-07-06 09:07:45 +00:00
|
|
|
|
2017-09-05 20:20:44 +00:00
|
|
|
if (need_pool) {
|
2015-06-13 00:14:37 +00:00
|
|
|
GST_DEBUG_OBJECT (glimage_sink, "create new pool");
|
2015-03-05 20:49:50 +00:00
|
|
|
|
2015-06-13 00:14:37 +00:00
|
|
|
pool = gst_gl_buffer_pool_new (glimage_sink->context);
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, 0, 0);
|
2015-08-15 12:31:15 +00:00
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_GL_SYNC_META);
|
2015-03-05 20:49:50 +00:00
|
|
|
|
2015-06-26 18:12:22 +00:00
|
|
|
if (!gst_buffer_pool_set_config (pool, config)) {
|
|
|
|
g_object_unref (pool);
|
2015-06-13 00:14:37 +00:00
|
|
|
goto config_failed;
|
2015-06-26 18:12:22 +00:00
|
|
|
}
|
2017-09-05 20:20:44 +00:00
|
|
|
}
|
2015-03-05 20:49:50 +00:00
|
|
|
|
2017-09-05 20:20:44 +00:00
|
|
|
/* we need at least 2 buffer because we hold on to the last one */
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, 2, 0);
|
|
|
|
if (pool)
|
2015-06-26 18:12:22 +00:00
|
|
|
g_object_unref (pool);
|
2012-07-06 09:07:45 +00:00
|
|
|
|
2014-10-17 13:22:24 +00:00
|
|
|
if (glimage_sink->context->gl_vtable->FenceSync)
|
|
|
|
gst_query_add_allocation_meta (query, GST_GL_SYNC_META_API_TYPE, 0);
|
2012-07-06 09:07:45 +00:00
|
|
|
|
2015-07-20 18:24:22 +00:00
|
|
|
if (glimage_sink->window_width != 0 && glimage_sink->window_height != 0) {
|
|
|
|
allocation_meta =
|
|
|
|
gst_structure_new ("GstVideoOverlayCompositionMeta",
|
|
|
|
"width", G_TYPE_UINT, glimage_sink->window_width,
|
|
|
|
"height", G_TYPE_UINT, glimage_sink->window_height, NULL);
|
|
|
|
GST_DEBUG ("sending alloc query with size %dx%d",
|
|
|
|
glimage_sink->window_width, glimage_sink->window_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_query_add_allocation_meta (query,
|
|
|
|
GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE, allocation_meta);
|
2016-05-14 13:27:26 +00:00
|
|
|
gst_query_add_allocation_meta (query,
|
|
|
|
GST_VIDEO_AFFINE_TRANSFORMATION_META_API_TYPE, 0);
|
2015-07-20 18:24:22 +00:00
|
|
|
|
2015-07-23 10:18:47 +00:00
|
|
|
if (allocation_meta)
|
|
|
|
gst_structure_free (allocation_meta);
|
|
|
|
|
2012-07-06 09:07:45 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_caps:
|
|
|
|
{
|
2015-03-05 20:49:50 +00:00
|
|
|
GST_WARNING_OBJECT (bsink, "no caps specified");
|
2012-07-06 09:07:45 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
invalid_caps:
|
|
|
|
{
|
2015-03-05 20:49:50 +00:00
|
|
|
GST_WARNING_OBJECT (bsink, "invalid caps specified");
|
2012-07-06 09:07:45 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
config_failed:
|
|
|
|
{
|
2015-03-05 20:49:50 +00:00
|
|
|
GST_WARNING_OBJECT (bsink, "failed setting config");
|
2012-07-06 09:07:45 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2014-10-21 11:18:51 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
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
|
|
|
|
};
|
2015-05-01 02:04:28 +00:00
|
|
|
|
|
|
|
static const GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
|
2014-10-21 11:18:51 +00:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2013-06-11 02:26:50 +00:00
|
|
|
static void
|
2014-11-29 13:18:55 +00:00
|
|
|
_bind_buffer (GstGLImageSink * gl_sink)
|
2013-06-11 02:26:50 +00:00
|
|
|
{
|
2014-10-21 11:18:51 +00:00
|
|
|
const GstGLFuncs *gl = gl_sink->context->gl_vtable;
|
|
|
|
|
2015-05-01 02:04:28 +00:00
|
|
|
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, gl_sink->vbo_indices);
|
2014-10-21 11:18:51 +00:00
|
|
|
gl->BindBuffer (GL_ARRAY_BUFFER, gl_sink->vertex_buffer);
|
|
|
|
|
|
|
|
/* Load the vertex position */
|
2014-11-29 13:18:55 +00:00
|
|
|
gl->VertexAttribPointer (gl_sink->attr_position, 3, GL_FLOAT, GL_FALSE,
|
2014-10-21 11:18:51 +00:00
|
|
|
5 * sizeof (GLfloat), (void *) 0);
|
|
|
|
|
|
|
|
/* Load the texture coordinate */
|
2014-11-29 13:18:55 +00:00
|
|
|
gl->VertexAttribPointer (gl_sink->attr_texture, 2, GL_FLOAT, GL_FALSE,
|
2014-10-21 11:18:51 +00:00
|
|
|
5 * sizeof (GLfloat), (void *) (3 * sizeof (GLfloat)));
|
|
|
|
|
2014-11-29 13:18:55 +00:00
|
|
|
gl->EnableVertexAttribArray (gl_sink->attr_position);
|
|
|
|
gl->EnableVertexAttribArray (gl_sink->attr_texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_unbind_buffer (GstGLImageSink * gl_sink)
|
|
|
|
{
|
|
|
|
const GstGLFuncs *gl = gl_sink->context->gl_vtable;
|
2014-10-21 11:18:51 +00:00
|
|
|
|
2015-05-01 02:04:28 +00:00
|
|
|
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
|
2014-10-21 11:18:51 +00:00
|
|
|
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
|
2014-11-29 13:18:55 +00:00
|
|
|
|
|
|
|
gl->DisableVertexAttribArray (gl_sink->attr_position);
|
|
|
|
gl->DisableVertexAttribArray (gl_sink->attr_texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called in the gl thread */
|
|
|
|
static void
|
|
|
|
gst_glimage_sink_thread_init_redisplay (GstGLImageSink * gl_sink)
|
|
|
|
{
|
|
|
|
const GstGLFuncs *gl = gl_sink->context->gl_vtable;
|
2015-09-04 06:02:32 +00:00
|
|
|
GError *error = NULL;
|
2015-11-10 04:37:05 +00:00
|
|
|
GstGLSLStage *frag_stage, *vert_stage;
|
|
|
|
|
2016-03-23 03:14:40 +00:00
|
|
|
vert_stage = gst_glsl_stage_new_with_string (gl_sink->context,
|
|
|
|
GL_VERTEX_SHADER, GST_GLSL_VERSION_NONE,
|
|
|
|
GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY,
|
2016-05-14 13:27:26 +00:00
|
|
|
gst_gl_shader_string_vertex_mat4_vertex_transform);
|
2015-11-10 04:37:05 +00:00
|
|
|
if (gl_sink->texture_target == GST_GL_TEXTURE_TARGET_EXTERNAL_OES) {
|
|
|
|
frag_stage = gst_glsl_stage_new_with_string (gl_sink->context,
|
|
|
|
GL_FRAGMENT_SHADER, GST_GLSL_VERSION_NONE,
|
|
|
|
GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY,
|
|
|
|
gst_gl_shader_string_fragment_external_oes_default);
|
|
|
|
} else {
|
|
|
|
frag_stage = gst_glsl_stage_new_default_fragment (gl_sink->context);
|
|
|
|
}
|
|
|
|
if (!vert_stage || !frag_stage) {
|
|
|
|
GST_ERROR_OBJECT (gl_sink, "Failed to retreive fragment shader for "
|
|
|
|
"texture target");
|
|
|
|
if (vert_stage)
|
|
|
|
gst_object_unref (vert_stage);
|
|
|
|
if (frag_stage)
|
|
|
|
gst_object_unref (frag_stage);
|
|
|
|
gst_glimage_sink_cleanup_glthread (gl_sink);
|
|
|
|
return;
|
|
|
|
}
|
2014-11-29 13:18:55 +00:00
|
|
|
|
2015-09-04 06:02:32 +00:00
|
|
|
if (!(gl_sink->redisplay_shader =
|
|
|
|
gst_gl_shader_new_link_with_stages (gl_sink->context, &error,
|
2015-11-10 04:37:05 +00:00
|
|
|
vert_stage, frag_stage, NULL))) {
|
2015-09-04 06:02:32 +00:00
|
|
|
GST_ERROR_OBJECT (gl_sink, "Failed to link shader: %s", error->message);
|
2014-11-29 13:18:55 +00:00
|
|
|
gst_glimage_sink_cleanup_glthread (gl_sink);
|
2015-09-04 06:02:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_sink->attr_position =
|
|
|
|
gst_gl_shader_get_attribute_location (gl_sink->redisplay_shader,
|
|
|
|
"a_position");
|
|
|
|
gl_sink->attr_texture =
|
|
|
|
gst_gl_shader_get_attribute_location (gl_sink->redisplay_shader,
|
|
|
|
"a_texcoord");
|
2014-11-29 13:18:55 +00:00
|
|
|
|
|
|
|
if (gl->GenVertexArrays) {
|
|
|
|
gl->GenVertexArrays (1, &gl_sink->vao);
|
|
|
|
gl->BindVertexArray (gl_sink->vao);
|
|
|
|
}
|
|
|
|
|
2015-05-01 02:04:28 +00:00
|
|
|
if (!gl_sink->vertex_buffer) {
|
|
|
|
gl->GenBuffers (1, &gl_sink->vertex_buffer);
|
|
|
|
gl->BindBuffer (GL_ARRAY_BUFFER, gl_sink->vertex_buffer);
|
|
|
|
gl->BufferData (GL_ARRAY_BUFFER, 4 * 5 * sizeof (GLfloat), vertices,
|
|
|
|
GL_STATIC_DRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gl_sink->vbo_indices) {
|
|
|
|
gl->GenBuffers (1, &gl_sink->vbo_indices);
|
|
|
|
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, gl_sink->vbo_indices);
|
|
|
|
gl->BufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (indices), indices,
|
|
|
|
GL_STATIC_DRAW);
|
|
|
|
}
|
2014-11-29 13:18:55 +00:00
|
|
|
|
2014-12-11 07:15:02 +00:00
|
|
|
if (gl->GenVertexArrays) {
|
2015-05-01 02:04:28 +00:00
|
|
|
_bind_buffer (gl_sink);
|
2014-11-29 13:18:55 +00:00
|
|
|
gl->BindVertexArray (0);
|
2014-12-11 07:15:02 +00:00
|
|
|
}
|
2015-05-01 02:04:28 +00:00
|
|
|
|
|
|
|
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
|
2014-10-21 11:18:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_glimage_sink_cleanup_glthread (GstGLImageSink * gl_sink)
|
|
|
|
{
|
|
|
|
const GstGLFuncs *gl = gl_sink->context->gl_vtable;
|
|
|
|
|
|
|
|
if (gl_sink->redisplay_shader) {
|
|
|
|
gst_object_unref (gl_sink->redisplay_shader);
|
|
|
|
gl_sink->redisplay_shader = NULL;
|
|
|
|
}
|
|
|
|
|
2014-12-11 07:15:02 +00:00
|
|
|
if (gl_sink->vao) {
|
2014-11-29 13:18:55 +00:00
|
|
|
gl->DeleteVertexArrays (1, &gl_sink->vao);
|
2014-12-11 07:15:02 +00:00
|
|
|
gl_sink->vao = 0;
|
|
|
|
}
|
2015-05-01 02:04:28 +00:00
|
|
|
|
2015-05-14 11:21:01 +00:00
|
|
|
if (gl_sink->vertex_buffer) {
|
|
|
|
gl->DeleteBuffers (1, &gl_sink->vertex_buffer);
|
|
|
|
gl_sink->vertex_buffer = 0;
|
|
|
|
}
|
|
|
|
|
2015-05-01 02:04:28 +00:00
|
|
|
if (gl_sink->vbo_indices) {
|
2015-05-14 11:21:01 +00:00
|
|
|
gl->DeleteBuffers (1, &gl_sink->vbo_indices);
|
2015-05-01 02:04:28 +00:00
|
|
|
gl_sink->vbo_indices = 0;
|
|
|
|
}
|
2015-06-18 04:04:37 +00:00
|
|
|
|
2015-11-10 23:31:07 +00:00
|
|
|
if (gl_sink->overlay_compositor)
|
|
|
|
gst_gl_overlay_compositor_free_overlays (gl_sink->overlay_compositor);
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
/* Called with object lock held */
|
|
|
|
static void
|
2015-09-17 07:22:47 +00:00
|
|
|
gst_glimage_sink_on_resize (GstGLImageSink * gl_sink, gint width, gint height)
|
2015-05-29 16:26:32 +00:00
|
|
|
{
|
|
|
|
/* Here gl_sink members (ex:gl_sink->out_info) have a life time of set_caps.
|
|
|
|
* It means that they cannot change between two set_caps
|
2013-08-28 09:07:24 +00:00
|
|
|
*/
|
2015-09-17 07:22:47 +00:00
|
|
|
const GstGLFuncs *gl;
|
2014-06-01 05:02:52 +00:00
|
|
|
gboolean do_reshape;
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2015-09-17 07:22:47 +00:00
|
|
|
GST_DEBUG_OBJECT (gl_sink, "GL Window resized to %ux%u", width, height);
|
|
|
|
|
2013-06-11 02:26:50 +00:00
|
|
|
/* check if a client reshape callback is registered */
|
2014-06-01 05:02:52 +00:00
|
|
|
g_signal_emit (gl_sink, gst_glimage_sink_signals[CLIENT_RESHAPE_SIGNAL], 0,
|
2014-07-07 08:52:06 +00:00
|
|
|
gl_sink->context, width, height, &do_reshape);
|
2015-05-29 16:26:32 +00:00
|
|
|
GST_GLIMAGE_SINK_LOCK (gl_sink);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2015-09-17 07:22:47 +00:00
|
|
|
gl = gl_sink->context->gl_vtable;
|
2014-11-06 23:01:59 +00:00
|
|
|
width = MAX (1, width);
|
|
|
|
height = MAX (1, height);
|
|
|
|
|
2015-07-01 12:01:45 +00:00
|
|
|
/* Check if we would suggest a different width/height now */
|
2016-01-13 02:17:56 +00:00
|
|
|
gl_sink->window_resized = ((gl_sink->window_width != width)
|
2015-07-01 12:01:45 +00:00
|
|
|
|| (gl_sink->window_height != height))
|
|
|
|
&& (gl_sink->window_width != 0)
|
|
|
|
&& (gl_sink->window_height != 0);
|
|
|
|
|
2015-08-21 20:42:18 +00:00
|
|
|
gl_sink->window_width = width;
|
|
|
|
gl_sink->window_height = height;
|
|
|
|
|
2015-08-31 09:21:54 +00:00
|
|
|
gst_gl_insert_debug_marker (gl_sink->context, "%s window resize to %ix%i",
|
|
|
|
GST_OBJECT_NAME (gl_sink), width, height);
|
|
|
|
|
2013-06-11 02:26:50 +00:00
|
|
|
/* default reshape */
|
2014-06-01 05:02:52 +00:00
|
|
|
if (!do_reshape) {
|
2013-06-11 02:26:50 +00:00
|
|
|
if (gl_sink->keep_aspect_ratio) {
|
|
|
|
GstVideoRectangle src, dst, result;
|
|
|
|
|
|
|
|
src.x = 0;
|
|
|
|
src.y = 0;
|
2016-05-16 12:02:28 +00:00
|
|
|
if (gl_sink->current_rotate_method == GST_GL_ROTATE_METHOD_90R
|
|
|
|
|| gl_sink->current_rotate_method == GST_GL_ROTATE_METHOD_90L
|
|
|
|
|| gl_sink->current_rotate_method == GST_GL_ROTATE_METHOD_FLIP_UL_LR
|
|
|
|
|| gl_sink->current_rotate_method ==
|
|
|
|
GST_GL_ROTATE_METHOD_FLIP_UR_LL) {
|
|
|
|
src.h = GST_VIDEO_SINK_WIDTH (gl_sink);
|
|
|
|
src.w = GST_VIDEO_SINK_HEIGHT (gl_sink);
|
|
|
|
} else {
|
|
|
|
src.w = GST_VIDEO_SINK_WIDTH (gl_sink);
|
|
|
|
src.h = GST_VIDEO_SINK_HEIGHT (gl_sink);
|
|
|
|
}
|
2013-06-11 02:26:50 +00:00
|
|
|
|
|
|
|
dst.x = 0;
|
|
|
|
dst.y = 0;
|
|
|
|
dst.w = width;
|
|
|
|
dst.h = height;
|
|
|
|
|
|
|
|
gst_video_sink_center_rect (src, dst, &result, TRUE);
|
2015-05-29 16:26:32 +00:00
|
|
|
gl_sink->output_mode_changed |= (result.w != gl_sink->display_rect.w);
|
|
|
|
gl_sink->output_mode_changed |= (result.h != gl_sink->display_rect.h);
|
|
|
|
gl_sink->display_rect = result;
|
2013-06-11 02:26:50 +00:00
|
|
|
} else {
|
2015-05-29 16:26:32 +00:00
|
|
|
gl_sink->output_mode_changed |= (width != gl_sink->display_rect.w);
|
|
|
|
gl_sink->output_mode_changed |= (height != gl_sink->display_rect.h);
|
|
|
|
|
|
|
|
gl_sink->display_rect.x = 0;
|
|
|
|
gl_sink->display_rect.y = 0;
|
|
|
|
gl_sink->display_rect.w = width;
|
|
|
|
gl_sink->display_rect.h = height;
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|
2015-09-17 07:22:47 +00:00
|
|
|
|
|
|
|
gl->Viewport (gl_sink->display_rect.x, gl_sink->display_rect.y,
|
|
|
|
gl_sink->display_rect.w, gl_sink->display_rect.h);
|
|
|
|
GST_DEBUG_OBJECT (gl_sink, "GL output area now %u,%u %ux%u",
|
|
|
|
gl_sink->display_rect.x, gl_sink->display_rect.y,
|
|
|
|
gl_sink->display_rect.w, gl_sink->display_rect.h);
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|
2015-09-17 07:22:47 +00:00
|
|
|
GST_GLIMAGE_SINK_UNLOCK (gl_sink);
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-01 05:02:52 +00:00
|
|
|
gst_glimage_sink_on_draw (GstGLImageSink * gl_sink)
|
2013-06-11 02:26:50 +00:00
|
|
|
{
|
2015-05-29 16:26:32 +00:00
|
|
|
/* Here gl_sink members (ex:gl_sink->out_info) have a life time of set_caps.
|
2013-08-28 09:07:24 +00:00
|
|
|
* It means that they cannot not change between two set_caps as well as
|
|
|
|
* for the redisplay_texture size.
|
|
|
|
* Whereas redisplay_texture id changes every sink_render
|
|
|
|
*/
|
|
|
|
|
|
|
|
const GstGLFuncs *gl = NULL;
|
2013-11-06 21:55:49 +00:00
|
|
|
GstGLWindow *window = NULL;
|
2015-03-14 15:16:55 +00:00
|
|
|
gboolean do_redisplay = FALSE;
|
|
|
|
GstSample *sample = NULL;
|
2015-11-10 04:37:05 +00:00
|
|
|
guint gl_target = gst_gl_texture_target_to_gl (gl_sink->texture_target);
|
2013-08-28 09:07:24 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_GLIMAGE_SINK (gl_sink));
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = gl_sink->context->gl_vtable;
|
2013-08-28 09:07:24 +00:00
|
|
|
|
|
|
|
GST_GLIMAGE_SINK_LOCK (gl_sink);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
|
|
|
/* check if texture is ready for being drawn */
|
2013-08-28 09:07:24 +00:00
|
|
|
if (!gl_sink->redisplay_texture) {
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (gl_sink);
|
2013-06-11 02:26:50 +00:00
|
|
|
return;
|
2013-08-28 09:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-11-06 21:55:49 +00:00
|
|
|
window = gst_gl_context_get_window (gl_sink->context);
|
|
|
|
window->is_drawing = TRUE;
|
|
|
|
|
2013-06-11 02:26:50 +00:00
|
|
|
/* opengl scene */
|
2015-08-31 09:21:54 +00:00
|
|
|
gst_gl_insert_debug_marker (gl_sink->context, "%s element drawing texture %u",
|
|
|
|
GST_OBJECT_NAME (gl_sink), gl_sink->redisplay_texture);
|
2013-06-11 02:26:50 +00:00
|
|
|
GST_TRACE ("redrawing texture:%u", gl_sink->redisplay_texture);
|
|
|
|
|
2015-11-16 04:46:41 +00:00
|
|
|
if (gl_sink->stored_sync_meta)
|
|
|
|
gst_gl_sync_meta_wait (gl_sink->stored_sync_meta,
|
|
|
|
gst_gl_context_get_current ());
|
2015-02-03 02:32:47 +00:00
|
|
|
|
2013-06-11 02:26:50 +00:00
|
|
|
/* make sure that the environnement is clean */
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_clear_shader (gl_sink->context);
|
2015-11-10 04:37:05 +00:00
|
|
|
gl->BindTexture (gl_target, 0);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
sample = gst_sample_new (gl_sink->stored_buffer[0],
|
|
|
|
gl_sink->out_caps, &GST_BASE_SINK (gl_sink)->segment, NULL);
|
2014-06-01 05:02:52 +00:00
|
|
|
g_signal_emit (gl_sink, gst_glimage_sink_signals[CLIENT_DRAW_SIGNAL], 0,
|
2015-03-14 15:16:55 +00:00
|
|
|
gl_sink->context, sample, &do_redisplay);
|
|
|
|
gst_sample_unref (sample);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2015-05-29 16:26:32 +00:00
|
|
|
if (gl_sink->stored_buffer[1]) {
|
|
|
|
sample = gst_sample_new (gl_sink->stored_buffer[1],
|
|
|
|
gl_sink->out_caps, &GST_BASE_SINK (gl_sink)->segment, NULL);
|
|
|
|
g_signal_emit (gl_sink, gst_glimage_sink_signals[CLIENT_DRAW_SIGNAL], 0,
|
|
|
|
gl_sink->context, sample, &do_redisplay);
|
|
|
|
gst_sample_unref (sample);
|
|
|
|
}
|
|
|
|
|
2014-06-01 05:02:52 +00:00
|
|
|
if (!do_redisplay) {
|
2015-01-30 04:13:27 +00:00
|
|
|
gfloat alpha = gl_sink->ignore_alpha ? 1.0f : 0.0f;
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2015-01-30 04:13:27 +00:00
|
|
|
gl->ClearColor (0.0, 0.0, 0.0, alpha);
|
2014-10-21 11:18:51 +00:00
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2015-01-30 04:13:27 +00:00
|
|
|
if (gl_sink->ignore_alpha) {
|
|
|
|
gl->BlendColor (0.0, 0.0, 0.0, alpha);
|
2015-02-24 17:54:54 +00:00
|
|
|
gl->BlendFunc (GL_SRC_ALPHA, GL_CONSTANT_COLOR);
|
2015-01-30 04:13:27 +00:00
|
|
|
gl->BlendEquation (GL_FUNC_ADD);
|
|
|
|
gl->Enable (GL_BLEND);
|
|
|
|
}
|
|
|
|
|
2014-10-21 11:18:51 +00:00
|
|
|
gst_gl_shader_use (gl_sink->redisplay_shader);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2014-11-29 13:18:55 +00:00
|
|
|
if (gl->GenVertexArrays)
|
|
|
|
gl->BindVertexArray (gl_sink->vao);
|
2017-03-14 03:15:00 +00:00
|
|
|
_bind_buffer (gl_sink);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2014-10-21 11:18:51 +00:00
|
|
|
gl->ActiveTexture (GL_TEXTURE0);
|
2015-11-10 04:37:05 +00:00
|
|
|
gl->BindTexture (gl_target, gl_sink->redisplay_texture);
|
2014-10-21 11:18:51 +00:00
|
|
|
gst_gl_shader_set_uniform_1i (gl_sink->redisplay_shader, "tex", 0);
|
2016-03-23 03:14:40 +00:00
|
|
|
{
|
2015-11-10 04:37:05 +00:00
|
|
|
GstVideoAffineTransformationMeta *af_meta;
|
2016-05-14 13:27:26 +00:00
|
|
|
gfloat matrix[16];
|
2015-11-10 04:37:05 +00:00
|
|
|
|
|
|
|
af_meta =
|
|
|
|
gst_buffer_get_video_affine_transformation_meta
|
|
|
|
(gl_sink->stored_buffer[0]);
|
2016-05-14 13:27:26 +00:00
|
|
|
|
2017-08-17 03:46:04 +00:00
|
|
|
if (gl_sink->transform_matrix) {
|
|
|
|
gfloat tmp[16];
|
2016-05-16 12:02:28 +00:00
|
|
|
|
2017-08-17 03:46:04 +00:00
|
|
|
gst_gl_get_affine_transformation_meta_as_ndc_ext (af_meta, tmp);
|
|
|
|
gst_gl_multiply_matrix4 (tmp, gl_sink->transform_matrix, matrix);
|
|
|
|
} else {
|
|
|
|
gst_gl_get_affine_transformation_meta_as_ndc_ext (af_meta, matrix);
|
|
|
|
}
|
2016-05-16 12:02:28 +00:00
|
|
|
|
2016-05-14 13:27:26 +00:00
|
|
|
gst_gl_shader_set_uniform_matrix_4fv (gl_sink->redisplay_shader,
|
|
|
|
"u_transformation", 1, FALSE, matrix);
|
2015-11-10 04:37:05 +00:00
|
|
|
}
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2015-05-01 02:04:28 +00:00
|
|
|
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2015-11-10 04:37:05 +00:00
|
|
|
gl->BindTexture (gl_target, 0);
|
2015-03-03 05:48:24 +00:00
|
|
|
gst_gl_context_clear_shader (gl_sink->context);
|
|
|
|
|
2014-11-29 13:18:55 +00:00
|
|
|
if (gl->GenVertexArrays)
|
|
|
|
gl->BindVertexArray (0);
|
2017-03-14 03:15:00 +00:00
|
|
|
_unbind_buffer (gl_sink);
|
2015-01-30 04:13:27 +00:00
|
|
|
|
|
|
|
if (gl_sink->ignore_alpha)
|
|
|
|
gl->Disable (GL_BLEND);
|
2015-08-14 15:36:48 +00:00
|
|
|
|
|
|
|
gst_gl_overlay_compositor_draw_overlays (gl_sink->overlay_compositor);
|
2014-06-01 05:02:52 +00:00
|
|
|
}
|
|
|
|
/* end default opengl scene */
|
2013-11-06 21:55:49 +00:00
|
|
|
window->is_drawing = FALSE;
|
|
|
|
gst_object_unref (window);
|
|
|
|
|
2013-08-28 09:07:24 +00:00
|
|
|
GST_GLIMAGE_SINK_UNLOCK (gl_sink);
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_glimage_sink_on_close (GstGLImageSink * gl_sink)
|
|
|
|
{
|
2014-07-27 03:26:00 +00:00
|
|
|
GstGLWindow *window;
|
|
|
|
|
2016-07-12 05:29:29 +00:00
|
|
|
GST_WARNING_OBJECT (gl_sink, "Output window was closed");
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2014-07-27 03:26:00 +00:00
|
|
|
window = gst_gl_context_get_window (gl_sink->context);
|
|
|
|
|
2015-04-07 03:24:06 +00:00
|
|
|
if (gl_sink->key_sig_id)
|
|
|
|
g_signal_handler_disconnect (window, gl_sink->key_sig_id);
|
|
|
|
gl_sink->key_sig_id = 0;
|
|
|
|
if (gl_sink->mouse_sig_id)
|
|
|
|
g_signal_handler_disconnect (window, gl_sink->mouse_sig_id);
|
|
|
|
gl_sink->mouse_sig_id = 0;
|
2014-07-27 03:26:00 +00:00
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
g_atomic_int_set (&gl_sink->to_quit, 1);
|
2014-07-27 03:26:00 +00:00
|
|
|
|
|
|
|
gst_object_unref (window);
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-08-28 09:07:24 +00:00
|
|
|
gst_glimage_sink_redisplay (GstGLImageSink * gl_sink)
|
2013-06-11 02:26:50 +00:00
|
|
|
{
|
2013-06-12 13:17:30 +00:00
|
|
|
GstGLWindow *window;
|
2015-05-29 16:26:32 +00:00
|
|
|
GstBuffer *old_stored_buffer[2], *old_sync;
|
2016-10-26 05:30:43 +00:00
|
|
|
gulong handler_id;
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
window = gst_gl_context_get_window (gl_sink->context);
|
2014-04-21 08:50:19 +00:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
handler_id =
|
|
|
|
g_signal_handler_find (GST_ELEMENT_PARENT (gl_sink), G_SIGNAL_MATCH_ID,
|
|
|
|
gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_DRAW], 0,
|
|
|
|
NULL, NULL, NULL);
|
2015-03-14 16:30:42 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
if (G_UNLIKELY (!gl_sink->redisplay_shader) && (!handler_id
|
|
|
|
|| !gl_sink->other_context)) {
|
|
|
|
gst_gl_window_send_message (window,
|
|
|
|
GST_GL_WINDOW_CB (gst_glimage_sink_thread_init_redisplay), gl_sink);
|
2015-01-29 11:25:00 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
/* if the shader is still null it means it failed to be useable */
|
|
|
|
if (G_UNLIKELY (!gl_sink->redisplay_shader)) {
|
|
|
|
gst_object_unref (window);
|
|
|
|
return FALSE;
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
gst_gl_window_set_preferred_size (window, GST_VIDEO_SINK_WIDTH (gl_sink),
|
|
|
|
GST_VIDEO_SINK_HEIGHT (gl_sink));
|
|
|
|
gst_gl_window_show (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recreate the output texture if needed */
|
|
|
|
GST_GLIMAGE_SINK_LOCK (gl_sink);
|
|
|
|
if (gl_sink->window_resized) {
|
|
|
|
gl_sink->window_resized = FALSE;
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (gl_sink);
|
|
|
|
GST_DEBUG_OBJECT (gl_sink, "Sending reconfigure event on sinkpad.");
|
|
|
|
gst_pad_push_event (GST_BASE_SINK (gl_sink)->sinkpad,
|
|
|
|
gst_event_new_reconfigure ());
|
2015-05-29 16:26:32 +00:00
|
|
|
GST_GLIMAGE_SINK_LOCK (gl_sink);
|
2016-10-26 05:30:43 +00:00
|
|
|
}
|
2016-01-13 02:17:56 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
if (gl_sink->output_mode_changed && gl_sink->input_buffer != NULL) {
|
|
|
|
GST_DEBUG ("Recreating output after mode/size change");
|
|
|
|
update_output_format (gl_sink);
|
|
|
|
prepare_next_buffer (gl_sink);
|
|
|
|
}
|
2015-05-29 16:26:32 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
if (gl_sink->next_buffer == NULL) {
|
|
|
|
/* Nothing to display yet */
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (gl_sink);
|
|
|
|
gst_object_unref (window);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-05-29 16:26:32 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
/* Avoid to release the texture while drawing */
|
|
|
|
gl_sink->redisplay_texture = gl_sink->next_tex;
|
|
|
|
old_stored_buffer[0] = gl_sink->stored_buffer[0];
|
|
|
|
old_stored_buffer[1] = gl_sink->stored_buffer[1];
|
|
|
|
gl_sink->stored_buffer[0] = gst_buffer_ref (gl_sink->next_buffer);
|
|
|
|
if (gl_sink->next_buffer2)
|
|
|
|
gl_sink->stored_buffer[1] = gst_buffer_ref (gl_sink->next_buffer2);
|
|
|
|
else
|
|
|
|
gl_sink->stored_buffer[1] = NULL;
|
2015-05-29 16:26:32 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
old_sync = gl_sink->stored_sync;
|
|
|
|
if (gl_sink->next_sync)
|
|
|
|
gl_sink->stored_sync = gst_buffer_ref (gl_sink->next_sync);
|
|
|
|
else
|
|
|
|
gl_sink->stored_sync = NULL;
|
|
|
|
gl_sink->stored_sync_meta = gl_sink->next_sync_meta;
|
|
|
|
GST_GLIMAGE_SINK_UNLOCK (gl_sink);
|
2015-05-29 16:26:32 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
gst_buffer_replace (old_stored_buffer, NULL);
|
|
|
|
gst_buffer_replace (old_stored_buffer + 1, NULL);
|
|
|
|
if (old_sync)
|
|
|
|
gst_buffer_unref (old_sync);
|
2015-05-29 16:26:32 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
/* Drawing is asynchronous: gst_gl_window_draw is not blocking
|
|
|
|
* It means that it does not wait for stuff to be executed in other threads
|
|
|
|
*/
|
|
|
|
gst_gl_window_draw (window);
|
2013-06-12 13:17:30 +00:00
|
|
|
gst_object_unref (window);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
return TRUE;
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|