2004-08-09 20:14:51 +00:00
|
|
|
/* GStreamer
|
2006-01-28 04:39:18 +00:00
|
|
|
* Copyright (C) 2003 Julien Moutte <julien@moutte.net>
|
|
|
|
* Copyright (C) 2005,2006 David A. Schleef <ds@schleef.org>
|
2004-08-09 20:14:51 +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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/interfaces/xoverlay.h>
|
|
|
|
#include <gst/video/gstvideosink.h>
|
|
|
|
#include <gst/video/video.h>
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
#include <string.h>
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
#include <GL/glx.h>
|
|
|
|
#include <GL/gl.h>
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-06-23 09:09:44 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_debug_glimage_sink);
|
2006-01-28 04:39:18 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_debug_glimage_sink
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
#define GST_TYPE_GLIMAGE_SINK \
|
|
|
|
(gst_glimage_sink_get_type())
|
|
|
|
#define GST_GLIMAGE_SINK(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GLIMAGE_SINK,GstGLImageSink))
|
|
|
|
#define GST_GLIMAGE_SINK_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GLIMAGE_SINK,GstGLImageSinkClass))
|
|
|
|
#define GST_IS_GLIMAGE_SINK(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GLIMAGE_SINK))
|
2006-06-23 09:09:44 +00:00
|
|
|
#define GST_IS_GLIMAGE_SINK_CLASS(klass) \
|
2006-01-28 04:39:18 +00:00
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GLIMAGE_SINK))
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
typedef struct _GstGLImageSink GstGLImageSink;
|
|
|
|
typedef struct _GstGLImageSinkClass GstGLImageSinkClass;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
struct _GstGLImageSink
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
GstVideoSink video_sink;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
/* properties */
|
|
|
|
char *display_name;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
/* caps */
|
|
|
|
GstCaps *caps;
|
|
|
|
int fps_n, fps_d;
|
|
|
|
int par_n, par_d;
|
|
|
|
int height, width;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
Window window;
|
|
|
|
Window parent_window;
|
|
|
|
XVisualInfo *visinfo;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
Display *display;
|
|
|
|
GLXContext context;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
int max_texture_size;
|
|
|
|
gboolean have_yuv;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gboolean use_rgb;
|
|
|
|
gboolean use_rgbx;
|
|
|
|
gboolean use_yuy2;
|
|
|
|
};
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
struct _GstGLImageSinkClass
|
|
|
|
{
|
|
|
|
GstVideoSinkClass video_sink_class;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
};
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +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);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +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 GstCaps *gst_glimage_sink_get_caps (GstBaseSink * bsink);
|
|
|
|
static gboolean gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps);
|
|
|
|
static GstFlowReturn gst_glimage_sink_render (GstBaseSink * bsink,
|
|
|
|
GstBuffer * buf);
|
|
|
|
|
|
|
|
static void gst_glimage_sink_create_window (GstGLImageSink * glimage_sink);
|
|
|
|
static gboolean gst_glimage_sink_init_display (GstGLImageSink * glimage_sink);
|
|
|
|
static void gst_glimage_sink_update_caps (GstGLImageSink * glimage_sink);
|
|
|
|
static void gst_glimage_sink_push_image (GstGLImageSink * glimage_sink,
|
|
|
|
GstBuffer * buf);
|
|
|
|
|
2006-04-25 21:56:38 +00:00
|
|
|
static const GstElementDetails gst_glimage_sink_details =
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_ELEMENT_DETAILS ("OpenGL video sink",
|
|
|
|
"Sink/Video",
|
|
|
|
"A videosink based on OpenGL",
|
|
|
|
"David Schleef <ds@schleef.org>");
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
#ifdef GL_YCBCR_MESA
|
|
|
|
#define YUV_CAPS ";" GST_VIDEO_CAPS_YUV ("{ UYVY, YUY2 }")
|
|
|
|
#else
|
|
|
|
#define YUV_CAPS
|
|
|
|
#endif
|
|
|
|
static GstStaticPadTemplate gst_glimage_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_BGRx YUV_CAPS)
|
|
|
|
);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
ARG_DISPLAY
|
|
|
|
};
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_BOILERPLATE (GstGLImageSink, gst_glimage_sink, GstVideoSink,
|
|
|
|
GST_TYPE_VIDEO_SINK);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
|
|
|
static void
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_glimage_sink_base_init (gpointer g_class)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_element_class_set_details (element_class, &gst_glimage_sink_details);
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&gst_glimage_sink_template));
|
2004-08-09 20:14:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_glimage_sink_class_init (GstGLImageSinkClass * klass)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
GstBaseSinkClass *gstbasesink_class;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
gstbasesink_class = (GstBaseSinkClass *) klass;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gobject_class->set_property = gst_glimage_sink_set_property;
|
|
|
|
gobject_class->get_property = gst_glimage_sink_get_property;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_DISPLAY,
|
|
|
|
g_param_spec_string ("display", "Display", "X Display name",
|
|
|
|
NULL, G_PARAM_READWRITE));
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gobject_class->finalize = gst_glimage_sink_finalize;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gstelement_class->change_state = gst_glimage_sink_change_state;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gstbasesink_class->get_caps = gst_glimage_sink_get_caps;
|
|
|
|
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;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
static void
|
|
|
|
gst_glimage_sink_init (GstGLImageSink * glimage_sink,
|
|
|
|
GstGLImageSinkClass * glimage_sink_class)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
int screen;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-02-14 11:36:30 +00:00
|
|
|
glimage_sink->display = XOpenDisplay (NULL);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
screen = DefaultScreen (glimage_sink->display);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-02-14 11:36:30 +00:00
|
|
|
XSynchronize (glimage_sink->display, True);
|
|
|
|
/* XSetErrorHandler (error_handler); */
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink->width = 400;
|
|
|
|
glimage_sink->height = 400;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_glimage_sink_update_caps (glimage_sink);
|
|
|
|
glimage_sink->display_name = g_strdup ("");
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_glimage_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (object);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DISPLAY:
|
|
|
|
if (glimage_sink->display_name) {
|
|
|
|
g_free (glimage_sink->display_name);
|
|
|
|
}
|
|
|
|
glimage_sink->display_name = g_strdup (g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_glimage_sink_finalize (GObject * object)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (object);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_caps_unref (glimage_sink->caps);
|
|
|
|
g_free (glimage_sink->display_name);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_glimage_sink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (object);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DISPLAY:
|
2006-08-15 19:29:58 +00:00
|
|
|
g_value_set_string (value, glimage_sink->display_name);
|
2006-01-28 04:39:18 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
/*
|
|
|
|
* GstElement methods
|
|
|
|
*/
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstGLImageSink *glimage_sink;
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_DEBUG ("change state");
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (element);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
if (!gst_glimage_sink_init_display (glimage_sink)) {
|
|
|
|
GST_ELEMENT_ERROR (glimage_sink, RESOURCE, WRITE, (NULL),
|
|
|
|
("Could not initialize OpenGL"));
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
2006-01-28 04:39:18 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
/* FIXME clear window */
|
|
|
|
glimage_sink->fps_n = 0;
|
|
|
|
glimage_sink->fps_d = 1;
|
|
|
|
GST_VIDEO_SINK_WIDTH (glimage_sink) = 0;
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink) = 0;
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
/* FIXME dispose of window */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
/*
|
|
|
|
* GstBaseSink methods
|
|
|
|
*/
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
static void
|
|
|
|
gst_glimage_sink_get_times (GstBaseSink * bsink, GstBuffer * buf,
|
|
|
|
GstClockTime * start, GstClockTime * end)
|
|
|
|
{
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_glimage_sink_get_caps (GstBaseSink * bsink)
|
|
|
|
{
|
|
|
|
GstGLImageSink *glimage_sink;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (bsink);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_DEBUG ("get caps returning %" GST_PTR_FORMAT, glimage_sink->caps);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
return gst_caps_ref (glimage_sink->caps);
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
static gboolean
|
|
|
|
gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
|
|
|
GstCaps *intersection;
|
|
|
|
GstStructure *structure;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
gboolean ret;
|
|
|
|
const GValue *fps;
|
|
|
|
const GValue *par;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (bsink);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
intersection = gst_caps_intersect (glimage_sink->caps, caps);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
if (gst_caps_is_empty (intersection)) {
|
|
|
|
return FALSE;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_caps_unref (intersection);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
ret = gst_structure_get_int (structure, "width", &width);
|
|
|
|
ret &= gst_structure_get_int (structure, "height", &height);
|
|
|
|
fps = gst_structure_get_value (structure, "framerate");
|
|
|
|
ret &= (fps != NULL);
|
|
|
|
par = gst_structure_get_value (structure, "pixel-aspect-ratio");
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return FALSE;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink->width = width;
|
|
|
|
glimage_sink->height = height;
|
|
|
|
glimage_sink->fps_n = gst_value_get_fraction_numerator (fps);
|
|
|
|
glimage_sink->fps_d = gst_value_get_fraction_denominator (fps);
|
|
|
|
if (par) {
|
|
|
|
glimage_sink->par_n = gst_value_get_fraction_numerator (par);
|
|
|
|
glimage_sink->par_d = gst_value_get_fraction_denominator (par);
|
2004-08-09 20:14:51 +00:00
|
|
|
} else {
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink->par_n = 1;
|
|
|
|
glimage_sink->par_d = 1;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_VIDEO_SINK_WIDTH (glimage_sink) = width;
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink) = height;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
if (strcmp (gst_structure_get_name (structure), "video/x-raw-rgb") == 0) {
|
|
|
|
int red_mask;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_DEBUG ("using RGB");
|
|
|
|
glimage_sink->use_rgb = TRUE;
|
|
|
|
gst_structure_get_int (structure, "red_mask", &red_mask);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
if (red_mask == 0xff000000) {
|
|
|
|
glimage_sink->use_rgbx = TRUE;
|
|
|
|
} else {
|
|
|
|
glimage_sink->use_rgbx = FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned int fourcc;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_DEBUG ("using YUV");
|
|
|
|
glimage_sink->use_rgb = FALSE;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_structure_get_fourcc (structure, "format", &fourcc);
|
|
|
|
if (fourcc == GST_MAKE_FOURCC ('Y', 'U', 'Y', '2')) {
|
|
|
|
glimage_sink->use_yuy2 = TRUE;
|
|
|
|
} else {
|
|
|
|
glimage_sink->use_yuy2 = FALSE;
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
#if 0
|
|
|
|
if (!glimage_sink->window) {
|
|
|
|
gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (glimage_sink));
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
if (!glimage_sink->window) {
|
|
|
|
gst_glimage_sink_create_window (glimage_sink);
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
return TRUE;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_glimage_sink_render (GstBaseSink * bsink, GstBuffer * buf)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
GstGLImageSink *glimage_sink;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink = GST_GLIMAGE_SINK (bsink);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_glimage_sink_push_image (glimage_sink, buf);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
return GST_FLOW_OK;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
/*
|
|
|
|
* helper functions
|
|
|
|
*/
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
static void
|
|
|
|
gst_caps_set_all (GstCaps * caps, char *field, ...)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
|
|
|
GstStructure *structure;
|
2006-01-28 04:39:18 +00:00
|
|
|
va_list var_args;
|
|
|
|
int i;
|
2004-08-27 19:18:24 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
for (i = 0; i < gst_caps_get_size (caps); i++) {
|
|
|
|
structure = gst_caps_get_structure (caps, i);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
va_start (var_args, field);
|
|
|
|
gst_structure_set_valist (structure, field, var_args);
|
|
|
|
va_end (var_args);
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
static void
|
|
|
|
gst_glimage_sink_update_caps (GstGLImageSink * glimage_sink)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
int max_size;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
if (glimage_sink->display == NULL) {
|
|
|
|
gst_caps_unref (glimage_sink->caps);
|
|
|
|
glimage_sink->caps =
|
|
|
|
gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD
|
|
|
|
(glimage_sink)));
|
|
|
|
return;
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
caps = gst_caps_from_string (GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_BGRx);
|
|
|
|
#ifdef GL_YCBCR_MESA
|
|
|
|
if (glimage_sink->have_yuv) {
|
|
|
|
GstCaps *ycaps =
|
|
|
|
gst_caps_from_string (GST_VIDEO_CAPS_YUV ("{ UYVY, YUY2 }"));
|
|
|
|
gst_caps_append (ycaps, caps);
|
|
|
|
caps = ycaps;
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
#endif
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
max_size = glimage_sink->max_texture_size;
|
|
|
|
if (max_size == 0) {
|
|
|
|
max_size = 1024;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_caps_set_all (caps,
|
|
|
|
"width", GST_TYPE_INT_RANGE, 16, max_size,
|
|
|
|
"height", GST_TYPE_INT_RANGE, 16, max_size, NULL);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
if (glimage_sink->caps) {
|
|
|
|
gst_caps_unref (glimage_sink->caps);
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink->caps = caps;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_glimage_sink_create_window (GstGLImageSink * glimage_sink)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
gboolean ret;
|
|
|
|
Window root;
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
Screen *screen;
|
|
|
|
int scrnum;
|
|
|
|
int mask;
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
screen = XDefaultScreenOfDisplay (glimage_sink->display);
|
|
|
|
scrnum = XScreenNumberOfScreen (screen);
|
|
|
|
root = XRootWindow (glimage_sink->display, scrnum);
|
|
|
|
|
|
|
|
if (glimage_sink->parent_window) {
|
|
|
|
XWindowAttributes pattr;
|
|
|
|
|
|
|
|
XGetWindowAttributes (glimage_sink->display, glimage_sink->parent_window,
|
|
|
|
&pattr);
|
|
|
|
width = pattr.width;
|
|
|
|
height = pattr.height;
|
|
|
|
} else {
|
|
|
|
width = GST_VIDEO_SINK (glimage_sink)->width;
|
|
|
|
height = GST_VIDEO_SINK (glimage_sink)->height;
|
|
|
|
}
|
|
|
|
attr.background_pixel = 0;
|
|
|
|
attr.border_pixel = 0;
|
|
|
|
attr.colormap = XCreateColormap (glimage_sink->display, root,
|
|
|
|
glimage_sink->visinfo->visual, AllocNone);
|
|
|
|
if (glimage_sink->parent_window) {
|
|
|
|
attr.override_redirect = True;
|
|
|
|
} else {
|
|
|
|
attr.override_redirect = False;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
mask = CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_DEBUG ("creating window with size %d x %d", width, height);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink->window = XCreateWindow (glimage_sink->display, root, 0, 0,
|
|
|
|
width, height,
|
|
|
|
0, glimage_sink->visinfo->depth, InputOutput,
|
|
|
|
glimage_sink->visinfo->visual, mask, &attr);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
if (glimage_sink->parent_window) {
|
|
|
|
ret = XReparentWindow (glimage_sink->display, glimage_sink->window,
|
|
|
|
glimage_sink->parent_window, 0, 0);
|
|
|
|
XMapWindow (glimage_sink->display, glimage_sink->window);
|
|
|
|
} else {
|
|
|
|
XMapWindow (glimage_sink->display, glimage_sink->window);
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glXMakeCurrent (glimage_sink->display, glimage_sink->window,
|
|
|
|
glimage_sink->context);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glDepthFunc (GL_LESS);
|
|
|
|
glEnable (GL_DEPTH_TEST);
|
|
|
|
glClearColor (0.2, 0.2, 0.2, 1.0);
|
|
|
|
glViewport (0, 0, width, height);
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
static gboolean
|
|
|
|
gst_glimage_sink_init_display (GstGLImageSink * glimage_sink)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
gboolean ret;
|
|
|
|
XVisualInfo *visinfo;
|
|
|
|
Screen *screen;
|
|
|
|
Window root;
|
|
|
|
int scrnum;
|
|
|
|
int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 8,
|
|
|
|
GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, None
|
|
|
|
};
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
int error_base;
|
|
|
|
int event_base;
|
|
|
|
int mask;
|
|
|
|
const char *extstring;
|
|
|
|
Window window;
|
|
|
|
|
2006-02-22 14:37:20 +00:00
|
|
|
GST_LOG_OBJECT (glimage_sink, "initializing display");
|
2006-01-28 04:39:18 +00:00
|
|
|
|
|
|
|
glimage_sink->display = XOpenDisplay (NULL);
|
|
|
|
if (glimage_sink->display == NULL) {
|
2006-02-22 14:37:20 +00:00
|
|
|
GST_ERROR_OBJECT (glimage_sink, "Could not open display");
|
2006-01-28 04:39:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
screen = XDefaultScreenOfDisplay (glimage_sink->display);
|
|
|
|
scrnum = XScreenNumberOfScreen (screen);
|
|
|
|
root = XRootWindow (glimage_sink->display, scrnum);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
ret = glXQueryExtension (glimage_sink->display, &error_base, &event_base);
|
|
|
|
if (!ret) {
|
2006-02-22 14:37:20 +00:00
|
|
|
GST_LOG_OBJECT (glimage_sink, "No GLX extension");
|
2006-01-28 04:39:18 +00:00
|
|
|
return FALSE;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
visinfo = glXChooseVisual (glimage_sink->display, scrnum, attrib);
|
|
|
|
if (visinfo == NULL) {
|
2006-02-22 14:37:20 +00:00
|
|
|
GST_LOG_OBJECT (glimage_sink, "No usable visual");
|
2006-01-28 04:39:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink->visinfo = visinfo;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink->context = glXCreateContext (glimage_sink->display,
|
|
|
|
visinfo, NULL, True);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
attr.background_pixel = 0;
|
|
|
|
attr.border_pixel = 0;
|
|
|
|
attr.colormap = XCreateColormap (glimage_sink->display, root,
|
|
|
|
visinfo->visual, AllocNone);
|
|
|
|
attr.event_mask = StructureNotifyMask | ExposureMask;
|
|
|
|
attr.override_redirect = True;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
//mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
|
|
mask = CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
window = XCreateWindow (glimage_sink->display, root, 0, 0,
|
|
|
|
100, 100, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glXMakeCurrent (glimage_sink->display, window, glimage_sink->context);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glGetIntegerv (GL_MAX_TEXTURE_SIZE, &glimage_sink->max_texture_size);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
extstring = (const char *) glGetString (GL_EXTENSIONS);
|
|
|
|
#ifdef GL_YCBCR_MESA
|
|
|
|
if (strstr (extstring, "GL_MESA_ycbcr_texture")) {
|
|
|
|
glimage_sink->have_yuv = TRUE;
|
|
|
|
} else {
|
|
|
|
glimage_sink->have_yuv = FALSE;
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
2006-01-28 04:39:18 +00:00
|
|
|
#else
|
|
|
|
glimage_sink->have_yuv = FALSE;
|
|
|
|
#endif
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glXMakeCurrent (glimage_sink->display, None, NULL);
|
|
|
|
XDestroyWindow (glimage_sink->display, window);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_glimage_sink_push_image (GstGLImageSink * glimage_sink, GstBuffer * buf)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
int texture_size;
|
|
|
|
XWindowAttributes attr;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
g_return_if_fail (buf != NULL);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
if (glimage_sink->display == NULL || glimage_sink->window == 0) {
|
|
|
|
g_warning ("display or window not set up\n");
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glXMakeCurrent (glimage_sink->display, glimage_sink->window,
|
|
|
|
glimage_sink->context);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
if (glimage_sink->parent_window) {
|
|
|
|
XGetWindowAttributes (glimage_sink->display, glimage_sink->parent_window,
|
|
|
|
&attr);
|
|
|
|
//gst_glimage_sink_set_window_size (glimage_sink, attr.width, attr.height);
|
|
|
|
} else {
|
|
|
|
XGetWindowAttributes (glimage_sink->display, glimage_sink->window, &attr);
|
|
|
|
glViewport (0, 0, attr.width, attr.height);
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glMatrixMode (GL_PROJECTION);
|
|
|
|
glLoadIdentity ();
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glMatrixMode (GL_MODELVIEW);
|
|
|
|
glLoadIdentity ();
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glDisable (GL_CULL_FACE);
|
|
|
|
glEnable (GL_TEXTURE_2D);
|
|
|
|
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glColor4f (1, 1, 1, 1);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
#define TEXID 1000
|
|
|
|
glBindTexture (GL_TEXTURE_2D, TEXID);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
for (texture_size = 64;
|
|
|
|
(texture_size < GST_VIDEO_SINK (glimage_sink)->width ||
|
|
|
|
texture_size < GST_VIDEO_SINK (glimage_sink)->height) &&
|
|
|
|
(texture_size > 0); texture_size <<= 1);
|
|
|
|
|
|
|
|
if (glimage_sink->use_rgb) {
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, texture_size,
|
|
|
|
texture_size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
|
|
|
|
if (glimage_sink->use_rgbx) {
|
|
|
|
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0,
|
|
|
|
GST_VIDEO_SINK (glimage_sink)->width,
|
|
|
|
GST_VIDEO_SINK (glimage_sink)->height,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, GST_BUFFER_DATA (buf));
|
|
|
|
} else {
|
|
|
|
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0,
|
|
|
|
GST_VIDEO_SINK (glimage_sink)->width,
|
|
|
|
GST_VIDEO_SINK (glimage_sink)->height,
|
|
|
|
GL_BGRA, GL_UNSIGNED_BYTE, GST_BUFFER_DATA (buf));
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-01-28 04:39:18 +00:00
|
|
|
#ifdef GL_YCBCR_MESA
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, GL_YCBCR_MESA, texture_size,
|
|
|
|
texture_size, 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_REV_MESA, NULL);
|
|
|
|
|
|
|
|
if (glimage_sink->use_yuy2) {
|
|
|
|
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0,
|
|
|
|
GST_VIDEO_SINK (glimage_sink)->width,
|
|
|
|
GST_VIDEO_SINK (glimage_sink)->height,
|
|
|
|
GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_REV_MESA, GST_BUFFER_DATA (buf));
|
|
|
|
} else {
|
|
|
|
glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0,
|
|
|
|
GST_VIDEO_SINK (glimage_sink)->width,
|
|
|
|
GST_VIDEO_SINK (glimage_sink)->height,
|
|
|
|
GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, GST_BUFFER_DATA (buf));
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
2006-01-28 04:39:18 +00:00
|
|
|
#else
|
|
|
|
g_assert_not_reached ();
|
|
|
|
#endif
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glColor4f (1, 0, 1, 1);
|
|
|
|
glBegin (GL_QUADS);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glNormal3f (0, 0, -1);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
{
|
|
|
|
double xmax = GST_VIDEO_SINK (glimage_sink)->width / (double) texture_size;
|
|
|
|
double ymax = GST_VIDEO_SINK (glimage_sink)->height / (double) texture_size;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glTexCoord2f (xmax, 0);
|
|
|
|
glVertex3f (1.0, 1.0, 0);
|
|
|
|
glTexCoord2f (0, 0);
|
|
|
|
glVertex3f (-1.0, 1.0, 0);
|
|
|
|
glTexCoord2f (0, ymax);
|
|
|
|
glVertex3f (-1.0, -1.0, 0);
|
|
|
|
glTexCoord2f (xmax, ymax);
|
|
|
|
glVertex3f (1.0, -1.0, 0);
|
|
|
|
glEnd ();
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glFlush ();
|
|
|
|
glXSwapBuffers (glimage_sink->display, glimage_sink->window);
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
#ifdef unused
|
2004-08-09 20:14:51 +00:00
|
|
|
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
static void gst_glimage_sink_set_window_size (GstGLImageSink * glimage_sink,
|
|
|
|
int width, int height);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_glimage_sink_set_window_size (GstGLImageSink * glimage_sink,
|
|
|
|
int width, int height)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_DEBUG ("resizing to %d x %d",
|
|
|
|
GST_VIDEO_SINK_WIDTH (glimage_sink),
|
|
|
|
GST_VIDEO_SINK_HEIGHT (glimage_sink));
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
if (glimage_sink->display && glimage_sink->window) {
|
|
|
|
XResizeWindow (glimage_sink->display, glimage_sink->window, width, height);
|
|
|
|
XSync (glimage_sink->display, False);
|
|
|
|
glViewport (0, 0, width, height);
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2006-01-28 04:39:18 +00:00
|
|
|
gst_glimage_sink_set_xwindow_id (GstXOverlay * overlay, XID xwindow_id)
|
2004-08-09 20:14:51 +00:00
|
|
|
{
|
2006-01-28 04:39:18 +00:00
|
|
|
GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (overlay);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_DEBUG ("set_xwindow_id %ld", xwindow_id);
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
g_return_if_fail (GST_IS_GLIMAGE_SINK (glimage_sink));
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
/* If the element has not initialized the X11 context try to do so */
|
|
|
|
if (!glimage_sink->display) {
|
|
|
|
g_warning ("X display not inited\n");
|
|
|
|
}
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
if (glimage_sink->parent_window == xwindow_id)
|
|
|
|
return;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
glimage_sink->parent_window = xwindow_id;
|
2004-08-09 20:14:51 +00:00
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
XSync (glimage_sink->display, False);
|
|
|
|
gst_glimage_sink_create_window (glimage_sink);
|
2004-08-09 20:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
if (!gst_element_register (plugin, "glimagesink",
|
2006-09-22 15:59:59 +00:00
|
|
|
GST_RANK_NONE, GST_TYPE_GLIMAGE_SINK))
|
2004-08-09 20:14:51 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2006-01-28 04:39:18 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_debug_glimage_sink, "glimagesink", 0,
|
2004-08-09 20:14:51 +00:00
|
|
|
"glimagesink element");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"glimagesink",
|
2006-01-28 04:39:18 +00:00
|
|
|
"OpenGL video output plugin",
|
2006-04-01 10:09:11 +00:00
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|