[091/906] start to revive the gltestsrc

git-svn-id: svn://svn.wobow.com/GStreamer_playground/gst-plugins-gl@503 93df14bb-0f41-7a43-8087-d3e2a2f0e464
This commit is contained in:
Julien Isorce 2008-06-11 18:33:53 +00:00 committed by Tim-Philipp Müller
parent f5f2e51a31
commit bca92ed962
5 changed files with 951 additions and 2 deletions

View file

@ -3,12 +3,16 @@ lib_LTLIBRARIES = libgstgl-@GST_MAJORMINOR@.la
libgstgl_@GST_MAJORMINOR@_la_SOURCES = \
gstgldisplay.c \
gstglbuffer.c
gstglbuffer.c \
gstglfilter.c \
gltestsrc.c
libgstgl_@GST_MAJORMINOR@includedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/gl
libgstgl_@GST_MAJORMINOR@include_HEADERS = \
gstgldisplay.h \
gstglbuffer.h
gstglbuffer.h \
gstglfilter.h \
gltestsrc.h
libgstgl_@GST_MAJORMINOR@_la_LIBADD = \
$(GST_PLUGINS_BASE_LIBS) -lgstvideo-$(GST_MAJORMINOR) \

495
gst-libs/gst/gl/gltestsrc.c Normal file
View file

@ -0,0 +1,495 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* 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
/* non-GST-specific stuff */
#include "gstgltestsrc.h"
#include "gltestsrc.h"
#include "gstglbuffer.h"
#include <string.h>
#include <stdlib.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
enum
{
COLOR_WHITE = 0,
COLOR_YELLOW,
COLOR_CYAN,
COLOR_GREEN,
COLOR_MAGENTA,
COLOR_RED,
COLOR_BLUE,
COLOR_BLACK,
COLOR_NEG_I,
COLOR_POS_Q,
COLOR_SUPER_BLACK,
COLOR_DARK_GREY
};
static const struct vts_color_struct vts_colors[] = {
/* 100% white */
{255, 128, 128, 255, 255, 255, 255},
/* yellow */
{226, 0, 155, 255, 255, 0, 255},
/* cyan */
{179, 170, 0, 0, 255, 255, 255},
/* green */
{150, 46, 21, 0, 255, 0, 255},
/* magenta */
{105, 212, 235, 255, 0, 255, 255},
/* red */
{76, 85, 255, 255, 0, 0, 255},
/* blue */
{29, 255, 107, 0, 0, 255, 255},
/* black */
{16, 128, 128, 0, 0, 0, 255},
/* -I */
{16, 198, 21, 0, 0, 128, 255},
/* +Q */
{16, 235, 198, 0, 128, 255, 255},
/* superblack */
{0, 128, 128, 0, 0, 0, 255},
/* 5% grey */
{32, 128, 128, 32, 32, 32, 255},
};
static void
gst_gl_test_src_unicolor (GstGLTestSrc * v, GstGLBuffer * buffer, int w,
int h, const struct vts_color_struct *color);
void
gst_gl_test_src_smpte (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
int i;
glClearColor (0.0, 0.0, 0.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable (GL_CULL_FACE);
glDisable (GL_TEXTURE_RECTANGLE_ARB);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
for (i = 0; i < 7; i++) {
glColor4f (vts_colors[i].R * (1 / 255.0f), vts_colors[i].G * (1 / 255.0f),
vts_colors[i].B * (1 / 255.0f), 1.0f);
glBegin (GL_QUADS);
glVertex3f (-1.0f + i * (2.0f / 7.0f), -1.0f + 2.0 * (2.0f / 3.0f), 0);
glVertex3f (-1.0f + (i + 1.0f) * (2.0f / 7.0f), -1.0f + 2.0f * (2.0f / 3.0f), 0);
glVertex3f (-1.0f + (i + 1.0f) * (2.0f / 7.0f), -1.0f, 0);
glVertex3f (-1.0f + i * (2.0f / 7.0f), -1.0f, 0);
glEnd ();
}
for (i = 0; i < 7; i++) {
int k;
if (i & 1) {
k = 7;
} else {
k = 6 - i;
}
glColor4f (vts_colors[k].R * (1 / 255.0f), vts_colors[k].G * (1 / 255.0f),
vts_colors[k].B * (1 / 255.0f), 1.0f);
glBegin (GL_QUADS);
glVertex3f (-1.0f + i * (2.0f / 7.0f), -1.0f + 2.0f * (3.0f / 4.0f), 0);
glVertex3f (-1.0f + (i + 1) * (2.0f / 7.0f), -1.0f + 2.0f * (3.0f / 4.0f), 0);
glVertex3f (-1.0f + (i + 1) * (2.0f / 7.0f), -1.0f + 2.0f * (2.0f / 3.0f), 0);
glVertex3f (-1.0f + i * (2.0f / 7.0f), -1.0f + 2.0f * (2.0f / 3.0f), 0);
glEnd ();
}
for (i = 0; i < 3; i++) {
int k;
if (i == 0) {
k = 8;
} else if (i == 1) {
k = 0;
} else {
k = 9;
}
glColor4f (vts_colors[k].R * (1 / 255.0f), vts_colors[k].G * (1 / 255.0f),
vts_colors[k].B * (1 / 255.0f), 1.0f);
glBegin (GL_QUADS);
glVertex3f (-1.0f + i * (2.0f / 6.0f), -1.0f + 2.0f * 1, 0);
glVertex3f (-1.0f + (i + 1) * (2.0f / 6.0f), -1.0f + 2.0f * 1, 0);
glVertex3f (-1.0f + (i + 1) * (2.0f / 6.0f), -1.0f + 2.0f * (3.0f / 4.0f), 0);
glVertex3f (-1.0f + i * (2.0f / 6.0f), -1.0f + 2.0f * (3.0f / 4.0f), 0);
glEnd ();
}
for (i = 0; i < 3; i++) {
int k;
if (i == 0) {
k = COLOR_SUPER_BLACK;
} else if (i == 1) {
k = COLOR_BLACK;
} else {
k = COLOR_DARK_GREY;
}
glColor4f (vts_colors[k].R * (1 / 255.0f), vts_colors[k].G * (1 / 255.0f),
vts_colors[k].B * (1 / 255.0f), 1.0f);
glBegin (GL_QUADS);
glVertex3f (-1.0f + 2.0f * (0.5f + i * (1.0f / 12.0f)), -1.0 + 2.0f * 1, 0);
glVertex3f (-1.0f + 2.0f * (0.5f + (i + 1) * (1.0f / 12.0f)), -1.0f + 2.0f * 1, 0);
glVertex3f (-1.0f + 2.0f * (0.5f + (i + 1) * (1.0f / 12.0f)),
-1.0f + 2.0f * (3.0f / 4.0f), 0);
glVertex3f (-1.0f + 2.0f * (0.5f + i * (1.0f / 12.0f)), -1.0f + 2.0f * (3.0f / 4.0f),
0);
glEnd ();
}
glColor4f (0.5, 0.5, 0.5, 1.0);
glBegin (GL_QUADS);
glVertex3f (-1.0 + 2.0 * (0.75), -1.0 + 2.0 * 1, 0);
glVertex3f (-1.0 + 2.0 * (1.0), -1.0 + 2.0 * 1, 0);
glVertex3f (-1.0 + 2.0 * (1.0), -1.0 + 2.0 * (3.0 / 4.0), 0);
glVertex3f (-1.0 + 2.0 * (0.75), -1.0 + 2.0 * (3.0 / 4.0), 0);
glEnd ();
}
void
gst_gl_test_src_snow (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
glClearColor (0.0, 0.0, 0.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
/* FIXME snow requires a fragment shader. Please write. */
glColor4f (0.5, 0.5, 0.5, 1.0);
glBegin (GL_QUADS);
glVertex3f (-1.0 + 2.0 * (0.0), -1.0 + 2.0 * 1, 0);
glVertex3f (-1.0 + 2.0 * (1.0), -1.0 + 2.0 * 1, 0);
glVertex3f (-1.0 + 2.0 * (1.0), -1.0 + 2.0 * (0.0), 0);
glVertex3f (-1.0 + 2.0 * (0.0), -1.0 + 2.0 * (0.0), 0);
glEnd ();
}
static void
gst_gl_test_src_unicolor (GstGLTestSrc * v, GstGLBuffer * buffer, int w,
int h, const struct vts_color_struct *color)
{
glClearColor (color->R * (1 / 255.0f), color->G * (1 / 255.0f),
color->B * (1 / 255.0f), 1.0f);
glClear (GL_COLOR_BUFFER_BIT);
}
void
gst_gl_test_src_black (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
gst_gl_test_src_unicolor (v, buffer, w, h, vts_colors + COLOR_BLACK);
}
void
gst_gl_test_src_white (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
gst_gl_test_src_unicolor (v, buffer, w, h, vts_colors + COLOR_WHITE);
}
void
gst_gl_test_src_red (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
gst_gl_test_src_unicolor (v, buffer, w, h, vts_colors + COLOR_RED);
}
void
gst_gl_test_src_green (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
gst_gl_test_src_unicolor (v, buffer, w, h, vts_colors + COLOR_GREEN);
}
void
gst_gl_test_src_blue (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
gst_gl_test_src_unicolor (v, buffer, w, h, vts_colors + COLOR_BLUE);
}
void
gst_gl_test_src_checkers1 (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
#if 0
int x, y;
paintinfo pi = { NULL, };
paintinfo *p = &pi;
struct fourcc_list_struct *fourcc;
p->width = w;
p->height = h;
fourcc = v->fourcc;
if (fourcc == NULL)
return;
fourcc->paint_setup (p, dest);
p->paint_hline = fourcc->paint_hline;
for (y = 0; y < h; y++) {
p->color = vts_colors + COLOR_GREEN;
p->paint_hline (p, 0, y, w);
for (x = (y % 2); x < w; x += 2) {
p->color = vts_colors + COLOR_RED;
p->paint_hline (p, x, y, 1);
}
}
#endif
}
void
gst_gl_test_src_checkers2 (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
#if 0
int x, y;
paintinfo pi = { NULL, };
paintinfo *p = &pi;
struct fourcc_list_struct *fourcc;
p->width = w;
p->height = h;
fourcc = v->fourcc;
if (fourcc == NULL)
return;
fourcc->paint_setup (p, dest);
p->paint_hline = fourcc->paint_hline;
p->color = vts_colors + COLOR_GREEN;
for (y = 0; y < h; y++) {
p->paint_hline (p, 0, y, w);
}
for (y = 0; y < h; y += 2) {
for (x = ((y % 4) == 0) ? 0 : 2; x < w; x += 4) {
guint len = (x < (w - 1)) ? 2 : (w - x);
p->color = vts_colors + COLOR_RED;
p->paint_hline (p, x, y + 0, len);
if (G_LIKELY ((y + 1) < h)) {
p->paint_hline (p, x, y + 1, len);
}
}
}
#endif
}
void
gst_gl_test_src_checkers4 (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
#if 0
int x, y;
paintinfo pi = { NULL, };
paintinfo *p = &pi;
struct fourcc_list_struct *fourcc;
p->width = w;
p->height = h;
fourcc = v->fourcc;
if (fourcc == NULL)
return;
fourcc->paint_setup (p, dest);
p->paint_hline = fourcc->paint_hline;
p->color = vts_colors + COLOR_GREEN;
for (y = 0; y < h; y++) {
p->paint_hline (p, 0, y, w);
}
for (y = 0; y < h; y += 4) {
for (x = ((y % 8) == 0) ? 0 : 4; x < w; x += 8) {
guint len = (x < (w - 3)) ? 4 : (w - x);
p->color = vts_colors + COLOR_RED;
p->paint_hline (p, x, y + 0, len);
if (G_LIKELY ((y + 1) < h)) {
p->paint_hline (p, x, y + 1, len);
if (G_LIKELY ((y + 2) < h)) {
p->paint_hline (p, x, y + 2, len);
if (G_LIKELY ((y + 3) < h)) {
p->paint_hline (p, x, y + 3, len);
}
}
}
}
}
#endif
}
void
gst_gl_test_src_checkers8 (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
#if 0
int x, y;
paintinfo pi = { NULL, };
paintinfo *p = &pi;
struct fourcc_list_struct *fourcc;
p->width = w;
p->height = h;
fourcc = v->fourcc;
if (fourcc == NULL)
return;
fourcc->paint_setup (p, dest);
p->paint_hline = fourcc->paint_hline;
p->color = vts_colors + COLOR_GREEN;
for (y = 0; y < h; y++) {
p->paint_hline (p, 0, y, w);
}
for (y = 0; y < h; y += 8) {
for (x = ((GST_ROUND_UP_8 (y) % 16) == 0) ? 0 : 8; x < w; x += 16) {
guint len = (x < (w - 7)) ? 8 : (w - x);
p->color = vts_colors + COLOR_RED;
p->paint_hline (p, x, y + 0, len);
if (G_LIKELY ((y + 1) < h)) {
p->paint_hline (p, x, y + 1, len);
if (G_LIKELY ((y + 2) < h)) {
p->paint_hline (p, x, y + 2, len);
if (G_LIKELY ((y + 3) < h)) {
p->paint_hline (p, x, y + 3, len);
if (G_LIKELY ((y + 4) < h)) {
p->paint_hline (p, x, y + 4, len);
if (G_LIKELY ((y + 5) < h)) {
p->paint_hline (p, x, y + 5, len);
if (G_LIKELY ((y + 6) < h)) {
p->paint_hline (p, x, y + 6, len);
if (G_LIKELY ((y + 7) < h)) {
p->paint_hline (p, x, y + 7, len);
}
}
}
}
}
}
}
}
}
#endif
}
void
gst_gl_test_src_circular (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
{
#if 0
int i;
int j;
paintinfo pi = { NULL, };
paintinfo *p = &pi;
struct fourcc_list_struct *fourcc;
struct vts_color_struct color;
static uint8_t sine_array[256];
static int sine_array_inited = FALSE;
double freq[8];
#ifdef SCALE_AMPLITUDE
double ampl[8];
#endif
int d;
if (!sine_array_inited) {
for (i = 0; i < 256; i++) {
sine_array[i] =
floor (255 * (0.5 + 0.5 * sin (i * 2 * M_PI / 256)) + 0.5);
}
sine_array_inited = TRUE;
}
p->width = w;
p->height = h;
fourcc = v->fourcc;
if (fourcc == NULL)
return;
fourcc->paint_setup (p, dest);
p->paint_hline = fourcc->paint_hline;
color = vts_colors[COLOR_BLACK];
p->color = &color;
for (i = 1; i < 8; i++) {
freq[i] = 200 * pow (2.0, -(i - 1) / 4.0);
#ifdef SCALE_AMPLITUDE
{
double x;
x = 2 * M_PI * freq[i] / w;
ampl[i] = sin (x) / x;
}
#endif
}
for (i = 0; i < w; i++) {
for (j = 0; j < h; j++) {
double dist;
int seg;
dist =
sqrt ((2 * i - w) * (2 * i - w) + (2 * j - h) * (2 * j -
h)) / (2 * w);
seg = floor (dist * 16);
if (seg == 0 || seg >= 8) {
color.Y = 255;
} else {
#ifdef SCALE_AMPLITUDE
double a;
#endif
d = floor (256 * dist * freq[seg] + 0.5);
#ifdef SCALE_AMPLITUDE
a = ampl[seg];
if (a < 0)
a = 0;
color.Y = 128 + a * (sine_array[d & 0xff] - 128);
#else
color.Y = sine_array[d & 0xff];
#endif
}
color.R = color.Y;
color.G = color.Y;
color.B = color.Y;
p->paint_hline (p, i, j, 1);
}
}
#endif
}

View file

@ -0,0 +1,57 @@
/* GStreamer
* Copyright (C) <2003> David A. Schleef <ds@schleef.org>
*
* 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.
*/
#ifndef __GL_TEST_SRC_H__
#define __GL_TEST_SRC_H__
#include <glib.h>
#include "gstglbuffer.h"
struct vts_color_struct {
guint8 Y, U, V;
guint8 R, G, B;
guint8 A;
};
void gst_gl_test_src_smpte (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
void gst_gl_test_src_snow (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
void gst_gl_test_src_black (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
void gst_gl_test_src_white (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
void gst_gl_test_src_red (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
void gst_gl_test_src_green (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
void gst_gl_test_src_blue (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
void gst_gl_test_src_checkers1 (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
void gst_gl_test_src_checkers2 (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
void gst_gl_test_src_checkers4 (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
void gst_gl_test_src_checkers8 (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
void gst_gl_test_src_circular (GstGLTestSrc * v,
GstGLBuffer *buffer, int w, int h);
#endif

View file

@ -0,0 +1,316 @@
/*
* GStreamer
* 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
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstglfilter.h"
#define GST_CAT_DEFAULT gst_gl_filter_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
static GstStaticPadTemplate gst_gl_filter_src_pad_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_GL_VIDEO_CAPS)
);
static GstStaticPadTemplate gst_gl_filter_sink_pad_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_GL_VIDEO_CAPS)
);
#define DEBUG_INIT(bla) \
GST_DEBUG_CATEGORY_INIT (gst_gl_filter_debug, "glfilter", 0, "glfilter element");
GST_BOILERPLATE_FULL (GstGLFilter, gst_gl_filter, GstBaseTransform,
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
static void gst_gl_filter_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gl_filter_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static GstCaps* gst_gl_filter_transform_caps (GstBaseTransform* bt,
GstPadDirection direction, GstCaps* caps);
static void gst_gl_filter_reset (GstGLFilter * filter);
static gboolean gst_gl_filter_start (GstBaseTransform * bt);
static gboolean gst_gl_filter_stop (GstBaseTransform * bt);
static gboolean gst_gl_filter_get_unit_size (GstBaseTransform * trans,
GstCaps * caps, guint * size);
static GstFlowReturn gst_gl_filter_transform (GstBaseTransform * bt,
GstBuffer * inbuf, GstBuffer * outbuf);
static GstFlowReturn gst_gl_filter_prepare_output_buffer (GstBaseTransform *
trans, GstBuffer * input, gint size, GstCaps * caps, GstBuffer ** buf);
static gboolean gst_gl_filter_set_caps (GstBaseTransform * bt, GstCaps * incaps,
GstCaps * outcaps);
static gboolean gst_gl_filter_do_transform (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void
gst_gl_filter_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_filter_src_pad_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_filter_sink_pad_template));
}
static void
gst_gl_filter_class_init (GstGLFilterClass * klass)
{
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_filter_set_property;
gobject_class->get_property = gst_gl_filter_get_property;
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
gst_gl_filter_transform_caps;
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_filter_transform;
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_filter_start;
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_filter_stop;
GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_filter_set_caps;
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size = gst_gl_filter_get_unit_size;
GST_BASE_TRANSFORM_CLASS (klass)->prepare_output_buffer =
gst_gl_filter_prepare_output_buffer;
klass->set_caps = NULL;
klass->filter = NULL;
klass->onInitFBO = NULL;
}
static void
gst_gl_filter_init (GstGLFilter * filter, GstGLFilterClass * klass)
{
//gst_element_create_all_pads (GST_ELEMENT (filter));
filter->sinkpad = gst_element_get_static_pad (GST_ELEMENT (filter), "sink");
filter->srcpad = gst_element_get_static_pad (GST_ELEMENT (filter), "src");
gst_gl_filter_reset (filter);
}
static void
gst_gl_filter_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
//GstGLFilter *filter = GST_GL_FILTER (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filter_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
//GstGLFilter *filter = GST_GL_FILTER (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filter_reset (GstGLFilter* filter)
{
if (filter->display)
{
//blocking call, delete the FBO
gst_gl_display_rejectFBO (filter->display, filter->fbo,
filter->depthbuffer, filter->texture);
g_object_unref (filter->display);
filter->display = NULL;
}
filter->video_format = GST_VIDEO_FORMAT_UNKNOWN;
filter->width = 0;
filter->height = 0;
filter->fbo = 0;
filter->depthbuffer = 0;
filter->texture = 0;
}
static gboolean
gst_gl_filter_start (GstBaseTransform* bt)
{
return TRUE;
}
static gboolean
gst_gl_filter_stop (GstBaseTransform* bt)
{
GstGLFilter *filter = GST_GL_FILTER (bt);
gst_gl_filter_reset (filter);
return TRUE;
}
static GstCaps*
gst_gl_filter_transform_caps (GstBaseTransform* bt,
GstPadDirection direction, GstCaps* caps)
{
GstGLFilter* filter = GST_GL_FILTER (bt);
GstStructure* structure = gst_caps_get_structure (caps, 0);
GstCaps* ret = gst_caps_copy (caps);
const GValue* par = NULL;
structure = gst_structure_copy (gst_caps_get_structure (ret, 0));
gst_structure_set (structure,
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
gst_caps_merge_structure (ret, gst_structure_copy (structure));
if ((par = gst_structure_get_value (structure, "pixel-aspect-ratio")))
{
gst_structure_set (structure,
"pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
gst_caps_merge_structure (ret, structure);
}
else
gst_structure_free (structure);
GST_DEBUG_OBJECT (bt, "returning caps: %" GST_PTR_FORMAT, ret);
return ret;
}
static gboolean
gst_gl_filter_get_unit_size (GstBaseTransform* trans, GstCaps* caps,
guint* size)
{
gboolean ret;
GstVideoFormat video_format;
gint width;
gint height;
ret = gst_gl_buffer_format_parse_caps (caps, &video_format, &width, &height);
if (ret)
*size = gst_gl_buffer_format_get_size (video_format, width, height);
return TRUE;
}
static GstFlowReturn
gst_gl_filter_prepare_output_buffer (GstBaseTransform* trans,
GstBuffer* inbuf, gint size, GstCaps* caps, GstBuffer** buf)
{
GstGLFilter* filter = NULL;
GstGLBuffer* gl_inbuf = GST_GL_BUFFER (inbuf);
GstGLBuffer* gl_outbuf = NULL;
filter = GST_GL_FILTER (trans);
if (filter->display == NULL)
{
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
filter->display = g_object_ref (gl_inbuf->display);
//blocking call, generate a FBO
gst_gl_display_requestFBO (filter->display, filter->width, filter->height,
&filter->fbo, &filter->depthbuffer, &filter->texture);
if (filter_class->onInitFBO)
filter_class->onInitFBO (filter);
}
gl_outbuf = gst_gl_buffer_new_from_video_format (filter->display,
filter->video_format,
filter->width, filter->height,
filter->width, filter->height,
gl_inbuf->width, gl_inbuf->height);
*buf = GST_BUFFER (gl_outbuf);
gst_buffer_set_caps (*buf, caps);
return GST_FLOW_OK;
}
static gboolean
gst_gl_filter_set_caps (GstBaseTransform* bt, GstCaps* incaps,
GstCaps* outcaps)
{
GstGLFilter* filter = GST_GL_FILTER (bt);
gboolean ret = FALSE;
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
ret = gst_gl_buffer_format_parse_caps (outcaps, &filter->video_format,
&filter->width, &filter->height);
if (filter_class->set_caps)
filter_class->set_caps (filter, incaps, outcaps);
if (!ret)
{
GST_DEBUG ("bad caps");
return FALSE;
}
GST_ERROR ("set_caps %d %d", filter->width, filter->height);
return ret;
}
static GstFlowReturn
gst_gl_filter_transform (GstBaseTransform* bt, GstBuffer* inbuf,
GstBuffer* outbuf)
{
GstGLFilter* filter;
GstGLBuffer* gl_inbuf = GST_GL_BUFFER (inbuf);
GstGLBuffer* gl_outbuf = GST_GL_BUFFER (outbuf);
filter = GST_GL_FILTER (bt);
gst_gl_filter_do_transform (filter, gl_inbuf, gl_outbuf);
return GST_FLOW_OK;
}
static gboolean
gst_gl_filter_do_transform (GstGLFilter* filter,
GstGLBuffer* inbuf, GstGLBuffer* outbuf)
{
GstGLDisplay* display = inbuf->display;
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
filter_class->filter (filter, inbuf, outbuf);
return TRUE;
}

View file

@ -0,0 +1,77 @@
/*
* GStreamer
* 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
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef _GST_GL_FILTER_H_
#define _GST_GL_FILTER_H_
#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include <gst/video/video.h>
#include "gstglbuffer.h"
G_BEGIN_DECLS
#define GST_TYPE_GL_FILTER (gst_gl_filter_get_type())
#define GST_GL_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_FILTER,GstGLFilter))
#define GST_IS_GL_FILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_FILTER))
#define GST_GL_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_GL_FILTER,GstGLFilterClass))
#define GST_IS_GL_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_GL_FILTER))
#define GST_GL_FILTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_GL_FILTER,GstGLFilterClass))
typedef struct _GstGLFilter GstGLFilter;
typedef struct _GstGLFilterClass GstGLFilterClass;
typedef gboolean (*GstGLFilterSetCaps) (GstGLFilter* filter,
GstCaps* incaps, GstCaps* outcaps);
typedef gboolean (*GstGLFilterProcessFunc) (GstGLFilter *filter,
GstGLBuffer *inbuf, GstGLBuffer *outbuf);
typedef void (*GstGLFilterOnInitFBO) (GstGLFilter *filter);
struct _GstGLFilter
{
GstBaseTransform base_transform;
GstPad *srcpad;
GstPad *sinkpad;
GstGLDisplay *display;
GstVideoFormat video_format;
gint width;
gint height;
guint fbo;
guint depthbuffer;
guint texture;
};
struct _GstGLFilterClass
{
GstBaseTransformClass base_transform_class;
GstGLFilterSetCaps set_caps;
GstGLFilterProcessFunc filter;
GstGLFilterOnInitFBO onInitFBO;
};
GType gst_gl_filter_get_type(void);
G_END_DECLS
#endif