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>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Scaling</title>
|
|
|
|
* <para>
|
|
|
|
* 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.
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Events</title>
|
|
|
|
* <para>
|
|
|
|
* 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.
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Examples</title>
|
|
|
|
* |[
|
|
|
|
* gst-launch -v videotestsrc ! "video/x-raw-rgb" ! glimagesink
|
|
|
|
* ]| 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.
|
|
|
|
* |[
|
|
|
|
* gst-launch -v videotestsrc ! "video/x-raw-yuv, format=(fourcc)I420" ! glimagesink
|
|
|
|
* ]| 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.
|
|
|
|
* |[
|
|
|
|
* gst-launch -v gltestsrc ! glimagesink
|
|
|
|
* ]| 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.
|
|
|
|
* |[
|
|
|
|
* gst-plugins-gl/tests/examples/generic/cube
|
|
|
|
* ]| 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.
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
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>
|
2008-05-18 11:12:46 +00:00
|
|
|
|
|
|
|
#include "gstglimagesink.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY (gst_debug_glimage_sink);
|
|
|
|
#define GST_CAT_DEFAULT gst_debug_glimage_sink
|
|
|
|
|
2013-06-11 02:26:50 +00:00
|
|
|
#define USING_OPENGL(display) (display->gl_api & GST_GL_API_OPENGL)
|
|
|
|
#define USING_OPENGL3(display) (display->gl_api & GST_GL_API_OPENGL3)
|
|
|
|
#define USING_GLES(display) (display->gl_api & GST_GL_API_GLES)
|
|
|
|
#define USING_GLES2(display) (display->gl_api & GST_GL_API_GLES2)
|
|
|
|
#define USING_GLES3(display) (display->gl_api & GST_GL_API_GLES3)
|
|
|
|
|
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
static void gst_glimage_sink_thread_init_redisplay (GstGLDisplay * display);
|
|
|
|
#endif
|
|
|
|
static void gst_glimage_sink_on_close (GstGLImageSink * gl_sink);
|
|
|
|
static void gst_glimage_sink_on_resize (GstGLImageSink * gl_sink, gint width,
|
|
|
|
gint height);
|
|
|
|
static void gst_glimage_sink_on_draw (GstGLImageSink * gl_sink);
|
|
|
|
static gboolean gst_glimage_sink_redisplay (GstGLImageSink * gl_sink,
|
|
|
|
GLuint texture, gint gl_width, gint gl_height, gint window_width,
|
|
|
|
gint window_height, gboolean keep_aspect_ratio);
|
|
|
|
|
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);
|
|
|
|
|
2012-08-10 05:31:20 +00:00
|
|
|
static gboolean gst_glimage_sink_query (GstBaseSink * bsink, GstQuery * query);
|
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);
|
|
|
|
static GstFlowReturn gst_glimage_sink_render (GstBaseSink * bsink,
|
|
|
|
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);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2013-06-11 02:26:50 +00:00
|
|
|
|
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
static const gchar *redisplay_vertex_shader_str_gles2 =
|
|
|
|
"attribute vec4 a_position; \n"
|
|
|
|
"attribute vec2 a_texCoord; \n"
|
|
|
|
"varying vec2 v_texCoord; \n"
|
|
|
|
"void main() \n"
|
|
|
|
"{ \n"
|
|
|
|
" gl_Position = a_position; \n"
|
|
|
|
" v_texCoord = a_texCoord; \n"
|
|
|
|
"} \n";
|
|
|
|
|
|
|
|
static const gchar *redisplay_fragment_shader_str_gles2 =
|
|
|
|
"precision mediump float; \n"
|
|
|
|
"varying vec2 v_texCoord; \n"
|
|
|
|
"uniform sampler2D s_texture; \n"
|
|
|
|
"void main() \n"
|
|
|
|
"{ \n"
|
|
|
|
" gl_FragColor = texture2D( s_texture, v_texCoord );\n"
|
|
|
|
"} \n";
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
#endif
|
|
|
|
|
2009-03-15 13:48:19 +00:00
|
|
|
static GstStaticPadTemplate gst_glimage_sink_template =
|
2012-06-05 12:59:31 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2009-03-15 13:48:19 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-09-20 13:16:08 +00:00
|
|
|
GST_STATIC_CAPS (GST_GL_UPLOAD_VIDEO_CAPS)
|
2009-03-15 13:48:19 +00:00
|
|
|
);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_DISPLAY,
|
|
|
|
PROP_CLIENT_RESHAPE_CALLBACK,
|
2009-04-19 22:52:41 +00:00
|
|
|
PROP_CLIENT_DRAW_CALLBACK,
|
2009-11-21 12:21:54 +00:00
|
|
|
PROP_CLIENT_DATA,
|
2010-05-04 09:37:38 +00:00
|
|
|
PROP_FORCE_ASPECT_RATIO,
|
|
|
|
PROP_PIXEL_ASPECT_RATIO
|
2008-05-18 11:12:46 +00:00
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
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;
|
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;
|
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
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_DISPLAY,
|
2008-05-18 11:12:46 +00:00
|
|
|
g_param_spec_string ("display", "Display", "Display name",
|
2010-10-19 15:00:33 +00:00
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CLIENT_RESHAPE_CALLBACK,
|
2010-10-19 15:00:33 +00:00
|
|
|
g_param_spec_pointer ("client-reshape-callback",
|
2009-02-11 06:39:14 +00:00
|
|
|
"Client reshape callback",
|
2008-08-13 15:59:09 +00:00
|
|
|
"Define a custom reshape callback in a client code",
|
2010-10-19 15:00:33 +00:00
|
|
|
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
|
2008-06-23 18:56:29 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CLIENT_DRAW_CALLBACK,
|
2010-10-19 15:00:33 +00:00
|
|
|
g_param_spec_pointer ("client-draw-callback", "Client draw callback",
|
|
|
|
"Define a custom draw callback in a client code",
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
|
2008-06-23 18:56:29 +00:00
|
|
|
|
2009-11-21 12:21:54 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CLIENT_DATA,
|
2010-10-19 15:00:33 +00:00
|
|
|
g_param_spec_pointer ("client-data", "Client data",
|
|
|
|
"Pass data to the draw and reshape callbacks",
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
|
2009-11-21 12:21:54 +00:00
|
|
|
|
2009-04-19 22:52:41 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO,
|
|
|
|
g_param_spec_boolean ("force-aspect-ratio",
|
|
|
|
"Force aspect ratio",
|
|
|
|
"When enabled, scaling will respect original aspect ratio", FALSE,
|
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,
|
|
|
|
g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
|
|
|
|
"The pixel aspect ratio of the device", "1/1",
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-11-21 02:34:15 +00:00
|
|
|
gst_element_class_set_metadata (element_class, "OpenGL video sink",
|
2012-05-30 03:46:21 +00:00
|
|
|
"Sink/Video", "A videosink based on OpenGL",
|
|
|
|
"Julien Isorce <julien.isorce@gmail.com>");
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&gst_glimage_sink_template));
|
|
|
|
|
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;
|
2008-05-18 11:12:46 +00:00
|
|
|
|
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;
|
|
|
|
gstbasesink_class->get_times = gst_glimage_sink_get_times;
|
|
|
|
gstbasesink_class->preroll = gst_glimage_sink_render;
|
|
|
|
gstbasesink_class->render = gst_glimage_sink_render;
|
2012-07-06 09:07:45 +00:00
|
|
|
gstbasesink_class->propose_allocation = gst_glimage_sink_propose_allocation;
|
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->display_name = NULL;
|
|
|
|
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;
|
|
|
|
glimage_sink->stored_buffer = NULL;
|
|
|
|
glimage_sink->clientReshapeCallback = NULL;
|
|
|
|
glimage_sink->clientDrawCallback = NULL;
|
2009-11-21 12:21:54 +00:00
|
|
|
glimage_sink->client_data = NULL;
|
2009-04-19 22:52:41 +00:00
|
|
|
glimage_sink->keep_aspect_ratio = FALSE;
|
2010-05-04 09:37:38 +00:00
|
|
|
glimage_sink->par = NULL;
|
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) {
|
|
|
|
case ARG_DISPLAY:
|
2008-06-07 15:27:12 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
g_free (glimage_sink->display_name);
|
|
|
|
glimage_sink->display_name = g_strdup (g_value_get_string (value));
|
|
|
|
break;
|
2008-06-07 15:27:12 +00:00
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
case PROP_CLIENT_RESHAPE_CALLBACK:
|
|
|
|
{
|
|
|
|
glimage_sink->clientReshapeCallback = g_value_get_pointer (value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_CLIENT_DRAW_CALLBACK:
|
|
|
|
{
|
|
|
|
glimage_sink->clientDrawCallback = g_value_get_pointer (value);
|
|
|
|
break;
|
|
|
|
}
|
2009-11-21 12:21:54 +00:00
|
|
|
case PROP_CLIENT_DATA:
|
|
|
|
{
|
|
|
|
glimage_sink->client_data = g_value_get_pointer (value);
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
g_free (glimage_sink->par);
|
|
|
|
glimage_sink->par = g_new0 (GValue, 1);
|
|
|
|
g_value_init (glimage_sink->par, GST_TYPE_FRACTION);
|
|
|
|
if (!g_value_transform (value, glimage_sink->par)) {
|
|
|
|
g_warning ("Could not transform string to aspect ratio");
|
|
|
|
gst_value_set_fraction (glimage_sink->par, 1, 1);
|
|
|
|
}
|
|
|
|
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);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2010-05-04 09:37:38 +00:00
|
|
|
if (glimage_sink->par) {
|
|
|
|
g_free (glimage_sink->par);
|
|
|
|
glimage_sink->par = NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
g_free (glimage_sink->display_name);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_DEBUG ("finalized");
|
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) {
|
|
|
|
case ARG_DISPLAY:
|
|
|
|
g_value_set_string (value, glimage_sink->display_name);
|
|
|
|
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:
|
2012-04-10 14:12:14 +00:00
|
|
|
if (!glimage_sink->par) {
|
|
|
|
glimage_sink->par = g_new0 (GValue, 1);
|
|
|
|
g_value_init (glimage_sink->par, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (glimage_sink->par, 1, 1);
|
|
|
|
}
|
|
|
|
if (!g_value_transform (glimage_sink->par, value))
|
|
|
|
g_warning ("Could not transform string to aspect ratio");
|
2010-05-04 09:37:38 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
case GST_QUERY_CUSTOM:
|
|
|
|
{
|
2012-06-05 12:59:31 +00:00
|
|
|
GstStructure *structure = gst_query_writable_structure (query);
|
2012-08-10 05:31:20 +00:00
|
|
|
if (gst_structure_has_name (structure, "gstgldisplay")) {
|
|
|
|
gst_structure_set (structure, "gstgldisplay", G_TYPE_POINTER,
|
|
|
|
glimage_sink->display, NULL);
|
|
|
|
res = TRUE;
|
|
|
|
} else
|
|
|
|
res = GST_BASE_SINK_CLASS (parent_class)->query (bsink, query);
|
2009-10-04 00:23:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
/*
|
|
|
|
* GstElement methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
GST_DEBUG ("change state");
|
|
|
|
|
|
|
|
glimage_sink = GST_GLIMAGE_SINK (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
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-10-22 23:11:27 +00:00
|
|
|
if (!glimage_sink->display) {
|
2013-06-12 13:17:30 +00:00
|
|
|
GstGLWindow *window;
|
|
|
|
GError *error = NULL;
|
2012-08-15 06:52:48 +00:00
|
|
|
|
|
|
|
GST_INFO ("Creating GstGLDisplay");
|
2009-10-04 00:23:45 +00:00
|
|
|
glimage_sink->display = gst_gl_display_new ();
|
2013-06-12 13:17:30 +00:00
|
|
|
window = gst_gl_window_new (glimage_sink->display);
|
|
|
|
gst_gl_display_set_window (glimage_sink->display, window);
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
if (!gst_gl_window_create_context (window, 0, &error)) {
|
2011-11-24 15:02:32 +00:00
|
|
|
GST_ELEMENT_ERROR (glimage_sink, RESOURCE, NOT_FOUND,
|
2013-06-12 13:17:30 +00:00
|
|
|
("%s", error->message), (NULL));
|
2012-04-13 10:38:11 +00:00
|
|
|
|
|
|
|
if (glimage_sink->display) {
|
2013-06-13 04:36:41 +00:00
|
|
|
gst_object_unref (glimage_sink->display);
|
2012-04-13 10:38:11 +00:00
|
|
|
glimage_sink->display = NULL;
|
|
|
|
}
|
2013-06-12 13:17:30 +00:00
|
|
|
gst_object_unref (window);
|
2012-04-13 10:38:11 +00:00
|
|
|
|
2011-11-24 15:02:32 +00:00
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
}
|
2013-06-11 02:26:50 +00:00
|
|
|
|
|
|
|
/* setup callbacks */
|
2013-06-12 13:17:30 +00:00
|
|
|
gst_gl_window_set_resize_callback (window,
|
2013-06-11 02:26:50 +00:00
|
|
|
GST_GL_WINDOW_RESIZE_CB (gst_glimage_sink_on_resize), glimage_sink);
|
2013-06-12 13:17:30 +00:00
|
|
|
gst_gl_window_set_draw_callback (window,
|
2013-06-11 02:26:50 +00:00
|
|
|
GST_GL_WINDOW_CB (gst_glimage_sink_on_draw), glimage_sink);
|
2013-06-12 13:17:30 +00:00
|
|
|
gst_gl_window_set_close_callback (window,
|
2013-06-11 02:26:50 +00:00
|
|
|
GST_GL_WINDOW_CB (gst_glimage_sink_on_close), glimage_sink);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
|
|
|
gst_object_unref (window);
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
if (glimage_sink->stored_buffer) {
|
2013-06-11 08:50:12 +00:00
|
|
|
gst_buffer_unref (glimage_sink->stored_buffer);
|
2009-10-04 00:23:45 +00:00
|
|
|
glimage_sink->stored_buffer = NULL;
|
|
|
|
}
|
2013-06-11 08:50:12 +00:00
|
|
|
if (glimage_sink->upload) {
|
2013-06-13 04:36:41 +00:00
|
|
|
gst_object_unref (glimage_sink->upload);
|
2013-06-11 08:50:12 +00:00
|
|
|
glimage_sink->upload = NULL;
|
2009-10-04 00:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glimage_sink->window_id = 0;
|
|
|
|
//but do not reset glimage_sink->new_window_id
|
|
|
|
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_VIDEO_SINK_WIDTH (glimage_sink) = 1;
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink) = 1;
|
2013-06-11 08:50:12 +00:00
|
|
|
if (glimage_sink->display) {
|
2013-06-12 13:17:30 +00:00
|
|
|
GstGLWindow *window = gst_gl_display_get_window (glimage_sink->display);
|
|
|
|
|
|
|
|
gst_gl_window_set_resize_callback (window, NULL, NULL);
|
|
|
|
gst_gl_window_set_draw_callback (window, NULL, NULL);
|
|
|
|
gst_gl_window_set_close_callback (window, NULL, NULL);
|
|
|
|
|
2013-06-13 04:36:41 +00:00
|
|
|
gst_object_unref (window);
|
|
|
|
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;
|
2013-06-11 08:50:12 +00:00
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
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 {
|
2012-07-12 08:07:34 +00:00
|
|
|
if (GST_VIDEO_INFO_FPS_N (&glimagesink->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,
|
|
|
|
GST_VIDEO_INFO_FPS_D (&glimagesink->info),
|
|
|
|
GST_VIDEO_INFO_FPS_N (&glimagesink->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
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
|
|
|
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;
|
2012-06-05 12:59:31 +00:00
|
|
|
GstVideoInfo vinfo;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
glimage_sink = GST_GLIMAGE_SINK (bsink);
|
|
|
|
|
2012-06-05 12:59:31 +00:00
|
|
|
ok = gst_video_info_from_caps (&vinfo, caps);
|
|
|
|
if (!ok)
|
|
|
|
return FALSE;
|
2009-10-04 00:23:45 +00:00
|
|
|
|
2012-06-05 12:59:31 +00:00
|
|
|
width = GST_VIDEO_INFO_WIDTH (&vinfo);
|
|
|
|
height = GST_VIDEO_INFO_HEIGHT (&vinfo);
|
2010-05-04 09:37:38 +00:00
|
|
|
|
2012-09-20 13:16:08 +00:00
|
|
|
if (glimage_sink->tex_id)
|
|
|
|
gst_gl_display_del_texture (glimage_sink->display, &glimage_sink->tex_id);
|
|
|
|
gst_gl_display_gen_texture (glimage_sink->display, &glimage_sink->tex_id,
|
|
|
|
GST_VIDEO_INFO_FORMAT (&vinfo), width, height);
|
2011-11-24 15:02:32 +00:00
|
|
|
|
2012-06-05 12:59:31 +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 */
|
|
|
|
if (glimage_sink->par) {
|
|
|
|
display_par_n = gst_value_get_fraction_numerator (glimage_sink->par);
|
|
|
|
display_par_d = gst_value_get_fraction_denominator (glimage_sink->par);
|
|
|
|
} 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));
|
|
|
|
|
|
|
|
glimage_sink->info = vinfo;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2009-06-06 12:34:57 +00:00
|
|
|
if (!glimage_sink->window_id && !glimage_sink->new_window_id)
|
2012-06-05 12:59:31 +00:00
|
|
|
gst_video_overlay_prepare_window_handle (GST_VIDEO_OVERLAY (glimage_sink));
|
2009-02-11 06:39:14 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_glimage_sink_render (GstBaseSink * bsink, GstBuffer * buf)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2012-06-05 12:59:31 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
2012-09-20 13:16:08 +00:00
|
|
|
guint tex_id;
|
|
|
|
GstVideoFrame frame;
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_TRACE ("rendering buffer:%p", buf);
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (bsink);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2012-09-20 13:16:08 +00:00
|
|
|
if (GST_VIDEO_SINK_WIDTH (glimage_sink) < 1 ||
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink) < 1) {
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&frame, &glimage_sink->info, buf,
|
|
|
|
GST_MAP_READ | GST_MAP_GL)) {
|
|
|
|
GST_WARNING ("Failed to map memory");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame.map[0].memory && gst_is_gl_memory (frame.map[0].memory)) {
|
|
|
|
tex_id = *(guint *) frame.data[0];
|
|
|
|
} else {
|
|
|
|
GST_INFO ("Input Buffer does not contain correct meta, "
|
|
|
|
"attempting to wrap for upload");
|
|
|
|
|
2013-06-11 08:50:12 +00:00
|
|
|
if (!glimage_sink->upload) {
|
|
|
|
glimage_sink->upload = gst_gl_upload_new (glimage_sink->display);
|
|
|
|
|
|
|
|
gst_gl_upload_init_format (glimage_sink->upload,
|
|
|
|
GST_VIDEO_FRAME_FORMAT (&frame), GST_VIDEO_FRAME_WIDTH (&frame),
|
|
|
|
GST_VIDEO_FRAME_HEIGHT (&frame), GST_VIDEO_FRAME_WIDTH (&frame),
|
|
|
|
GST_VIDEO_FRAME_HEIGHT (&frame));
|
|
|
|
}
|
|
|
|
|
2012-09-20 13:16:08 +00:00
|
|
|
gst_gl_upload_perform_with_data (glimage_sink->upload,
|
|
|
|
glimage_sink->tex_id, frame.data);
|
2012-07-06 09:07:45 +00:00
|
|
|
|
2012-09-20 13:16:08 +00:00
|
|
|
tex_id = glimage_sink->tex_id;
|
|
|
|
}
|
2012-07-06 09:07:45 +00:00
|
|
|
|
2009-06-06 12:34:57 +00:00
|
|
|
if (glimage_sink->window_id != glimage_sink->new_window_id) {
|
2013-06-12 13:17:30 +00:00
|
|
|
GstGLWindow *window = gst_gl_display_get_window (glimage_sink->display);
|
|
|
|
|
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
|
|
|
|
|
|
|
gst_buffer_replace (&glimage_sink->stored_buffer, buf);
|
2012-07-06 09:07:45 +00:00
|
|
|
|
2012-09-20 13:16:08 +00:00
|
|
|
GST_TRACE ("redisplay texture:%u of size:%ux%u, window size:%ux%u", tex_id,
|
|
|
|
GST_VIDEO_INFO_WIDTH (&glimage_sink->info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&glimage_sink->info),
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_VIDEO_SINK_WIDTH (glimage_sink),
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink));
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
//redisplay opengl scene
|
2013-06-11 02:26:50 +00:00
|
|
|
if (!gst_glimage_sink_redisplay (glimage_sink,
|
2012-09-20 13:16:08 +00:00
|
|
|
tex_id, GST_VIDEO_INFO_WIDTH (&glimage_sink->info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&glimage_sink->info),
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_VIDEO_SINK_WIDTH (glimage_sink),
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink),
|
2009-04-19 22:52:41 +00:00
|
|
|
glimage_sink->keep_aspect_ratio))
|
2012-07-06 09:07:45 +00:00
|
|
|
goto redisplay_failed;
|
|
|
|
|
2012-07-12 08:07:34 +00:00
|
|
|
GST_TRACE ("post redisplay");
|
|
|
|
|
2012-09-20 13:16:08 +00:00
|
|
|
gst_video_frame_unmap (&frame);
|
|
|
|
|
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,
|
|
|
|
GST_GL_DISPLAY_ERR_MSG (glimage_sink->display), (NULL));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-07-06 09:07:45 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
redisplay_failed:
|
|
|
|
{
|
2012-09-20 13:16:08 +00:00
|
|
|
gst_video_frame_unmap (&frame);
|
2011-11-24 15:02:32 +00:00
|
|
|
GST_ELEMENT_ERROR (glimage_sink, RESOURCE, NOT_FOUND,
|
2012-04-20 08:41:51 +00:00
|
|
|
GST_GL_DISPLAY_ERR_MSG (glimage_sink->display), (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;
|
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);
|
2010-09-16 12:00:29 +00:00
|
|
|
gulong window_id = (gulong) 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
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_DEBUG ("set_xwindow_id %ld", 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 */
|
2009-06-09 18:35:26 +00:00
|
|
|
if (glimage_sink->display && glimage_sink->window_id) {
|
2009-07-31 15:17:55 +00:00
|
|
|
|
2009-06-09 18:35:26 +00:00
|
|
|
if (glimage_sink->window_id != glimage_sink->new_window_id) {
|
2013-06-12 13:17:30 +00:00
|
|
|
GstGLWindow *window = gst_gl_display_get_window (glimage_sink->display);
|
|
|
|
|
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-06-11 02:26:50 +00:00
|
|
|
gst_glimage_sink_redisplay (glimage_sink, 0, 0, 0, 0, 0,
|
2009-07-31 15:17:55 +00:00
|
|
|
glimage_sink->keep_aspect_ratio);
|
2009-06-09 18:35:26 +00:00
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
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);
|
|
|
|
GstBufferPool *pool;
|
|
|
|
GstStructure *config;
|
|
|
|
GstCaps *caps;
|
|
|
|
guint size;
|
|
|
|
gboolean need_pool;
|
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, &need_pool);
|
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
goto no_caps;
|
|
|
|
|
|
|
|
if ((pool = glimage_sink->pool))
|
|
|
|
gst_object_ref (pool);
|
|
|
|
|
|
|
|
if (pool != NULL) {
|
|
|
|
GstCaps *pcaps;
|
|
|
|
|
|
|
|
/* we had a pool, check caps */
|
|
|
|
GST_DEBUG_OBJECT (glimage_sink, "check existing pool caps");
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
|
|
|
|
|
|
|
|
if (!gst_caps_is_equal (caps, pcaps)) {
|
|
|
|
GST_DEBUG_OBJECT (glimage_sink, "pool has different caps");
|
|
|
|
/* different caps, we can't use this pool */
|
|
|
|
gst_object_unref (pool);
|
|
|
|
pool = NULL;
|
|
|
|
}
|
|
|
|
gst_structure_free (config);
|
|
|
|
}
|
|
|
|
if (pool == NULL && need_pool) {
|
|
|
|
GstVideoInfo info;
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto invalid_caps;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (glimage_sink, "create new pool");
|
|
|
|
pool = gst_gl_buffer_pool_new (glimage_sink->display);
|
|
|
|
|
|
|
|
/* the normal size of a frame */
|
|
|
|
size = info.size;
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, 0, 0);
|
|
|
|
if (!gst_buffer_pool_set_config (pool, config))
|
|
|
|
goto config_failed;
|
|
|
|
}
|
|
|
|
/* we need at least 2 buffer because we hold on to the last one */
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, 2, 0);
|
|
|
|
|
|
|
|
/* we also support various metadata */
|
2012-07-07 15:11:56 +00:00
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, 0);
|
2012-07-06 09:07:45 +00:00
|
|
|
|
|
|
|
gst_object_unref (pool);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_caps:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (bsink, "no caps specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
invalid_caps:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (bsink, "invalid caps specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
config_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (bsink, "failed setting config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2013-06-11 02:26:50 +00:00
|
|
|
|
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
/* Called in the gl thread */
|
|
|
|
static void
|
|
|
|
gst_gl_display_thread_init_redisplay (GstGLImageSink * gl_sink)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
gl_sink->redisplay_shader = gst_gl_shader_new (gl_sink->display);
|
|
|
|
|
|
|
|
gst_gl_shader_set_vertex_source (gl_sink->redisplay_shader,
|
|
|
|
redisplay_vertex_shader_str_gles2);
|
|
|
|
gst_gl_shader_set_fragment_source (gl_sink->redisplay_shader,
|
|
|
|
redisplay_fragment_shader_str_gles2);
|
|
|
|
|
|
|
|
gst_gl_shader_compile (display->gl_sink->redisplay_shader, &error);
|
|
|
|
if (error) {
|
|
|
|
gst_gl_display_set_error (gl_sink->display, "%s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
error = NULL;
|
|
|
|
gst_gl_display_clear_shader (gl_sink->display);
|
|
|
|
} else {
|
|
|
|
gl_sink->redisplay_attr_position_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (display->priv->redisplay_shader,
|
|
|
|
"a_position");
|
|
|
|
gl_sink->redisplay_attr_texture_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (display->priv->redisplay_shader,
|
|
|
|
"a_texCoord");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_glimage_sink_on_resize (GstGLImageSink * gl_sink, gint width, gint height)
|
|
|
|
{
|
|
|
|
const GstGLFuncs *gl = gl_sink->display->gl_vtable;
|
|
|
|
|
|
|
|
GST_TRACE ("GL Window resized to %ux%u", width, height);
|
|
|
|
|
|
|
|
/* check if a client reshape callback is registered */
|
|
|
|
if (gl_sink->clientReshapeCallback)
|
|
|
|
gl_sink->clientReshapeCallback (width, height, gl_sink->client_data);
|
|
|
|
|
|
|
|
/* default reshape */
|
|
|
|
else {
|
|
|
|
if (gl_sink->keep_aspect_ratio) {
|
|
|
|
GstVideoRectangle src, dst, result;
|
|
|
|
|
|
|
|
src.x = 0;
|
|
|
|
src.y = 0;
|
|
|
|
src.w = gl_sink->redisplay_texture_width;
|
|
|
|
src.h = gl_sink->redisplay_texture_height;
|
|
|
|
|
|
|
|
dst.x = 0;
|
|
|
|
dst.y = 0;
|
|
|
|
dst.w = width;
|
|
|
|
dst.h = height;
|
|
|
|
|
|
|
|
gst_video_sink_center_rect (src, dst, &result, TRUE);
|
|
|
|
gl->Viewport (result.x, result.y, result.w, result.h);
|
|
|
|
} else {
|
|
|
|
gl->Viewport (0, 0, width, height);
|
|
|
|
}
|
|
|
|
#if GST_GL_HAVE_OPENGL
|
|
|
|
if (USING_OPENGL (gl_sink->display)) {
|
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->LoadIdentity ();
|
|
|
|
gluOrtho2D (0, width, 0, height);
|
|
|
|
gl->MatrixMode (GL_MODELVIEW);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_glimage_sink_on_draw (GstGLImageSink * gl_sink)
|
|
|
|
{
|
|
|
|
const GstGLFuncs *gl = gl_sink->display->gl_vtable;
|
|
|
|
|
|
|
|
/* check if texture is ready for being drawn */
|
|
|
|
if (!gl_sink->redisplay_texture)
|
|
|
|
return;
|
|
|
|
/* opengl scene */
|
|
|
|
GST_TRACE ("redrawing texture:%u", gl_sink->redisplay_texture);
|
|
|
|
|
|
|
|
/* make sure that the environnement is clean */
|
|
|
|
gst_gl_display_clear_shader (gl_sink->display);
|
|
|
|
|
|
|
|
#if GST_GL_HAVE_OPENGL
|
|
|
|
if (USING_OPENGL (gl_sink->display))
|
|
|
|
gl->Disable (GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gl->BindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
|
|
|
|
|
|
|
|
/* check if a client draw callback is registered */
|
|
|
|
if (gl_sink->clientDrawCallback) {
|
2013-06-12 13:17:30 +00:00
|
|
|
GstGLWindow *window = gst_gl_display_get_window (gl_sink->display);
|
|
|
|
|
2013-06-11 02:26:50 +00:00
|
|
|
gboolean doRedisplay =
|
|
|
|
gl_sink->clientDrawCallback (gl_sink->redisplay_texture,
|
|
|
|
gl_sink->redisplay_texture_width,
|
|
|
|
gl_sink->redisplay_texture_height,
|
|
|
|
gl_sink->client_data);
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
if (doRedisplay && window)
|
|
|
|
gst_gl_window_draw_unlocked (window,
|
2013-06-11 02:26:50 +00:00
|
|
|
gl_sink->redisplay_texture_width, gl_sink->redisplay_texture_height);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
|
|
|
gst_object_unref (window);
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|
|
|
|
/* default opengl scene */
|
|
|
|
else {
|
|
|
|
#if GST_GL_HAVE_OPENGL
|
|
|
|
if (USING_OPENGL (gl_sink->display)) {
|
|
|
|
gfloat verts[8] = { 1.0f, 1.0f,
|
|
|
|
-1.0f, 1.0f,
|
|
|
|
-1.0f, -1.0f,
|
|
|
|
1.0f, -1.0f
|
|
|
|
};
|
|
|
|
gint texcoords[8] = { gl_sink->redisplay_texture_width, 0,
|
|
|
|
0, 0,
|
|
|
|
0, gl_sink->redisplay_texture_height,
|
|
|
|
gl_sink->redisplay_texture_width,
|
|
|
|
gl_sink->redisplay_texture_height
|
|
|
|
};
|
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->LoadIdentity ();
|
|
|
|
|
|
|
|
gl->Enable (GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
gl->BindTexture (GL_TEXTURE_RECTANGLE_ARB, gl_sink->redisplay_texture);
|
|
|
|
|
|
|
|
gl->EnableClientState (GL_VERTEX_ARRAY);
|
|
|
|
gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
|
|
|
|
gl->VertexPointer (2, GL_FLOAT, 0, &verts);
|
|
|
|
gl->TexCoordPointer (2, GL_INT, 0, &texcoords);
|
|
|
|
|
|
|
|
gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
|
|
|
|
gl->DisableClientState (GL_VERTEX_ARRAY);
|
|
|
|
gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
|
|
|
|
|
|
|
|
gl->Disable (GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
if (USING_GLES2 (display)) {
|
|
|
|
const GLfloat vVertices[] = { 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
|
|
|
|
};
|
|
|
|
|
|
|
|
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
|
|
|
|
|
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
gst_gl_shader_use (gl_sink->redisplay_shader);
|
|
|
|
|
|
|
|
/* Load the vertex position */
|
|
|
|
gl->VertexAttribPointer (display->priv->redisplay_attr_position_loc, 3,
|
|
|
|
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), vVertices);
|
|
|
|
|
|
|
|
/* Load the texture coordinate */
|
|
|
|
gl->VertexAttribPointer (display->priv->redisplay_attr_texture_loc, 2,
|
|
|
|
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]);
|
|
|
|
|
|
|
|
gl->EnableVertexAttribArray (display->priv->redisplay_attr_position_loc);
|
|
|
|
gl->EnableVertexAttribArray (display->priv->redisplay_attr_texture_loc);
|
|
|
|
|
|
|
|
gl->ActiveTexture (GL_TEXTURE0);
|
|
|
|
gl->BindTexture (GL_TEXTURE_2D, display->priv->redisplay_texture);
|
|
|
|
gst_gl_shader_set_uniform_1i (display->priv->redisplay_shader,
|
|
|
|
"s_texture", 0);
|
|
|
|
|
|
|
|
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} /* end default opengl scene */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_glimage_sink_on_close (GstGLImageSink * gl_sink)
|
|
|
|
{
|
|
|
|
gst_gl_display_set_error (gl_sink->display, "Output window was closed");
|
2013-06-12 13:17:30 +00:00
|
|
|
|
|
|
|
g_atomic_int_set (&gl_sink->to_quit, 1);
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_glimage_sink_redisplay (GstGLImageSink * gl_sink, GLuint texture,
|
|
|
|
gint gl_width, gint gl_height, gint window_width, gint window_height,
|
|
|
|
gboolean keep_aspect_ratio)
|
|
|
|
{
|
2013-06-12 13:17:30 +00:00
|
|
|
GstGLWindow *window;
|
|
|
|
gboolean alive;
|
|
|
|
|
|
|
|
window = gst_gl_display_get_window (gl_sink->display);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
if (window && gst_gl_window_is_running (window)) {
|
2013-06-11 02:26:50 +00:00
|
|
|
|
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
if (USING_GLES2 (gl_sink->display)) {
|
|
|
|
if (!gl_sink->redisplay_shader) {
|
2013-06-12 13:17:30 +00:00
|
|
|
gst_gl_window_send_message (window,
|
2013-06-11 02:26:50 +00:00
|
|
|
GST_GL_WINDOW_CB (gst_glimage_sink_thread_init_redisplay), display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (texture) {
|
|
|
|
gl_sink->redisplay_texture = texture;
|
|
|
|
gl_sink->redisplay_texture_width = gl_width;
|
|
|
|
gl_sink->redisplay_texture_height = gl_height;
|
|
|
|
}
|
|
|
|
gl_sink->keep_aspect_ratio = keep_aspect_ratio;
|
2013-06-12 13:17:30 +00:00
|
|
|
if (window)
|
|
|
|
gst_gl_window_draw (window, window_width, window_height);
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|
2013-06-12 13:17:30 +00:00
|
|
|
alive = gst_gl_window_is_running (window);
|
|
|
|
gst_object_unref (window);
|
2013-06-11 02:26:50 +00:00
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
return alive;
|
2013-06-11 02:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
temp (GstGLImageSink * gl_sink)
|
|
|
|
{
|
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
if (gl_sink->redisplay_shader) {
|
2013-06-13 04:36:41 +00:00
|
|
|
gst_object_unref (gl_sink->redisplay_shader);
|
2013-06-11 02:26:50 +00:00
|
|
|
gl_sink->redisplay_shader = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|