mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 19:20:35 +00:00
[062/906] git-svn-id: svn://svn.wobow.com/GStreamer_playground/gst-plugins-gl@421 93df14bb-0f41-7a43-8087-d3e2a2f0e464
This commit is contained in:
parent
98e2942fed
commit
f0e8c70845
4 changed files with 2282 additions and 0 deletions
124
gst-libs/gst/gl/gstglbuffer.c
Normal file
124
gst-libs/gst/gl/gstglbuffer.c
Normal file
|
@ -0,0 +1,124 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gstglbuffer.h"
|
||||
|
||||
static GObjectClass* gst_gl_buffer_parent_class;
|
||||
|
||||
static void
|
||||
gst_gl_buffer_finalize (GstGLBuffer* buffer)
|
||||
{
|
||||
//wait clear textures end, blocking call
|
||||
gst_gl_display_clearTexture (buffer->display, buffer->texture,
|
||||
buffer->texture_u, buffer->texture_v);
|
||||
|
||||
g_object_unref (buffer->display);
|
||||
|
||||
GST_MINI_OBJECT_CLASS (gst_gl_buffer_parent_class)->
|
||||
finalize (GST_MINI_OBJECT (buffer));
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_buffer_init (GstGLBuffer* buffer, gpointer g_class)
|
||||
{
|
||||
buffer->display = NULL;
|
||||
buffer->video_format = 0;
|
||||
buffer->texture = 0;
|
||||
buffer->texture_u = 0;
|
||||
buffer->texture_v = 0;
|
||||
buffer->width = 0;
|
||||
buffer->height = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_buffer_class_init (gpointer g_class, gpointer class_data)
|
||||
{
|
||||
GstMiniObjectClass* mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
|
||||
|
||||
gst_gl_buffer_parent_class = g_type_class_peek_parent (g_class);
|
||||
|
||||
mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
|
||||
gst_gl_buffer_finalize;
|
||||
}
|
||||
|
||||
|
||||
GType
|
||||
gst_gl_buffer_get_type (void)
|
||||
{
|
||||
static GType _gst_gl_buffer_type;
|
||||
|
||||
if (G_UNLIKELY (_gst_gl_buffer_type == 0)) {
|
||||
static const GTypeInfo info = {
|
||||
sizeof (GstBufferClass),
|
||||
NULL,
|
||||
NULL,
|
||||
gst_gl_buffer_class_init,
|
||||
NULL,
|
||||
NULL,
|
||||
sizeof (GstGLBuffer),
|
||||
0,
|
||||
(GInstanceInitFunc) gst_gl_buffer_init,
|
||||
NULL
|
||||
};
|
||||
_gst_gl_buffer_type = g_type_register_static (GST_TYPE_BUFFER,
|
||||
"GstGLBuffer", &info, 0);
|
||||
}
|
||||
return _gst_gl_buffer_type;
|
||||
}
|
||||
|
||||
|
||||
GstGLBuffer*
|
||||
gst_gl_buffer_new_from_video_format (GstGLDisplay* display,
|
||||
GstVideoFormat video_format, gint context_width, gint context_height,
|
||||
gint width, gint height)
|
||||
{
|
||||
GstGLBuffer *buffer;
|
||||
|
||||
g_return_val_if_fail (video_format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
|
||||
g_return_val_if_fail (display != NULL, NULL);
|
||||
g_return_val_if_fail (width > 0, NULL);
|
||||
g_return_val_if_fail (height > 0, NULL);
|
||||
|
||||
buffer = (GstGLBuffer *) gst_mini_object_new (GST_TYPE_GL_BUFFER);
|
||||
|
||||
buffer->display = g_object_ref (display);
|
||||
buffer->width = width;
|
||||
buffer->height = height;
|
||||
buffer->video_format = video_format;
|
||||
GST_BUFFER_SIZE (buffer) = gst_gl_buffer_format_get_size (video_format, context_width, context_height);
|
||||
|
||||
//blocking call, init texture
|
||||
gst_gl_display_textureRequested (buffer->display, buffer->video_format,
|
||||
buffer->width, buffer->height,
|
||||
&buffer->texture, &buffer->texture_u, &buffer->texture_v) ;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
gst_gl_buffer_format_get_size (GstVideoFormat format, int width, int height)
|
||||
{
|
||||
/* this is not strictly true, but it's used for compatibility with
|
||||
* queue and BaseTransform */
|
||||
return width * height * 4;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_gl_buffer_format_parse_caps (GstCaps * caps, GstVideoFormat * format,
|
||||
gint* width, gint* height)
|
||||
{
|
||||
GstStructure *structure;
|
||||
gboolean ret;
|
||||
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
|
||||
if (!gst_structure_has_name (structure, "video/x-raw-gl"))
|
||||
return FALSE;
|
||||
|
||||
ret = gst_structure_get_int (structure, "width", width);
|
||||
ret &= gst_structure_get_int (structure, "height", height);
|
||||
|
||||
return ret;
|
||||
}
|
54
gst-libs/gst/gl/gstglbuffer.h
Normal file
54
gst-libs/gst/gl/gstglbuffer.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef _GST_GL_BUFFER_H_
|
||||
#define _GST_GL_BUFFER_H_
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
#include "gstgldisplay.h"
|
||||
|
||||
typedef struct _GstGLBuffer GstGLBuffer;
|
||||
|
||||
#define GST_TYPE_GL_BUFFER (gst_gl_buffer_get_type())
|
||||
|
||||
#define GST_IS_GL_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GL_BUFFER))
|
||||
#define GST_GL_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_GL_BUFFER, GstGLBuffer))
|
||||
|
||||
|
||||
|
||||
struct _GstGLBuffer {
|
||||
GstBuffer buffer;
|
||||
|
||||
GstGLDisplay *display;
|
||||
|
||||
GstVideoFormat video_format;
|
||||
|
||||
GLuint texture;
|
||||
GLuint texture_u;
|
||||
GLuint texture_v;
|
||||
|
||||
gint width;
|
||||
gint height;
|
||||
};
|
||||
|
||||
GType gst_gl_buffer_get_type (void);
|
||||
|
||||
#define gst_gl_buffer_ref(x) ((GstGLBuffer *)(gst_buffer_ref((GstBuffer *)(x))))
|
||||
#define gst_gl_buffer_unref(x) (gst_buffer_unref((GstBuffer *)(x)))
|
||||
|
||||
GstGLBuffer* gst_gl_buffer_new_from_video_format (GstGLDisplay* display, GstVideoFormat format,
|
||||
gint context_width, gint context_height,
|
||||
gint width, gint height);
|
||||
gint gst_gl_buffer_format_get_size (GstVideoFormat format, gint width, gint height);
|
||||
gboolean gst_gl_buffer_format_parse_caps (GstCaps* caps, GstVideoFormat* format,
|
||||
gint* width, gint* height);
|
||||
|
||||
|
||||
#define GST_GL_VIDEO_CAPS \
|
||||
"video/x-raw-gl," \
|
||||
"width=(int)[1,1920]," \
|
||||
"height=(int)[1,1080]," \
|
||||
"pixel-aspect-ratio=(fraction)1/1," \
|
||||
"framerate=(fraction)[0/1,100/1]"
|
||||
|
||||
#endif
|
||||
|
1909
gst-libs/gst/gl/gstgldisplay.c
Normal file
1909
gst-libs/gst/gl/gstgldisplay.c
Normal file
File diff suppressed because it is too large
Load diff
195
gst-libs/gst/gl/gstgldisplay.h
Normal file
195
gst-libs/gst/gl/gstgldisplay.h
Normal file
|
@ -0,0 +1,195 @@
|
|||
#ifndef __GST_GL_H__
|
||||
#define __GST_GL_H__
|
||||
|
||||
#include <gl/glew.h>
|
||||
#include <GL/freeglut.h>
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
#define GST_TYPE_GL_DISPLAY \
|
||||
(gst_gl_display_get_type())
|
||||
#define GST_GL_DISPLAY(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_DISPLAY,GstGLDisplay))
|
||||
#define GST_GL_DISPLAY_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GL_DISPLAY,GstGLDisplayClass))
|
||||
#define GST_IS_GL_DISPLAY(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_DISPLAY))
|
||||
#define GST_IS_GL_DISPLAY_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GL_DISPLAY))
|
||||
|
||||
typedef struct _GstGLDisplay GstGLDisplay;
|
||||
typedef struct _GstGLDisplayClass GstGLDisplayClass;
|
||||
|
||||
//Message type
|
||||
typedef enum {
|
||||
GST_GL_DISPLAY_ACTION_CREATE,
|
||||
GST_GL_DISPLAY_ACTION_DESTROY,
|
||||
GST_GL_DISPLAY_ACTION_VISIBLE,
|
||||
GST_GL_DISPLAY_ACTION_PREPARE,
|
||||
GST_GL_DISPLAY_ACTION_CHANGE,
|
||||
GST_GL_DISPLAY_ACTION_CLEAR,
|
||||
GST_GL_DISPLAY_ACTION_VIDEO,
|
||||
GST_GL_DISPLAY_ACTION_REDISPLAY
|
||||
|
||||
} GstGLDisplayAction;
|
||||
|
||||
|
||||
//Message to communicate with the glut thread
|
||||
typedef struct _GstGLDisplayMsg {
|
||||
GstGLDisplayAction action;
|
||||
gint glutWinId;
|
||||
GstGLDisplay* display;
|
||||
} GstGLDisplayMsg;
|
||||
|
||||
|
||||
//Texture pool elements
|
||||
typedef struct _GstGLDisplayTex {
|
||||
GLuint texture;
|
||||
GLuint texture_u;
|
||||
GLuint texture_v;
|
||||
} GstGLDisplayTex;
|
||||
|
||||
|
||||
//Client callbacks
|
||||
typedef void (* CRCB) ( GLuint, GLuint );
|
||||
typedef gboolean (* CDCB) ( GLuint, GLuint, GLuint);
|
||||
|
||||
struct _GstGLDisplay {
|
||||
GObject object;
|
||||
|
||||
GMutex *mutex;
|
||||
|
||||
GQueue* texturePool;
|
||||
|
||||
GCond *cond_make;
|
||||
GCond *cond_fill;
|
||||
GCond *cond_clear;
|
||||
GCond *cond_video;
|
||||
|
||||
GCond *cond_create;
|
||||
GCond *cond_destroy;
|
||||
gint glutWinId;
|
||||
gulong winId;
|
||||
GString *title;
|
||||
gint win_xpos;
|
||||
gint win_ypos;
|
||||
gint glcontext_width;
|
||||
gint glcontext_height;
|
||||
gboolean visible;
|
||||
|
||||
//intput frame buffer object (video -> GL)
|
||||
GLuint fbo;
|
||||
GLuint depthBuffer;
|
||||
GLuint textureFBO;
|
||||
GLuint textureFBOWidth;
|
||||
GLuint textureFBOHeight;
|
||||
|
||||
//graphic frame buffer object (GL texture -> GL scene)
|
||||
GLuint graphicFBO;
|
||||
GLuint graphicDepthBuffer;
|
||||
GLuint graphicTexture;
|
||||
|
||||
GLuint requestedTexture;
|
||||
GLuint requestedTexture_u;
|
||||
GLuint requestedTexture_v;
|
||||
GstVideoFormat requestedVideo_format;
|
||||
GLuint requestedTextureWidth;
|
||||
GLuint requestedTextureHeight;
|
||||
|
||||
GLuint candidateTexture;
|
||||
GLuint candidateTexture_u;
|
||||
GLuint candidateTexture_v;
|
||||
GstVideoFormat candidateVideo_format;
|
||||
GLuint candidateTextureWidth;
|
||||
GLuint candidateTextureHeight;
|
||||
gpointer candidateData;
|
||||
|
||||
GLuint currentTexture;
|
||||
GLuint currentTexture_u;
|
||||
GLuint currentTexture_v;
|
||||
GstVideoFormat currentVideo_format;
|
||||
GLuint currentTextureWidth;
|
||||
GLuint currentTextureHeight;
|
||||
|
||||
GLuint textureTrash;
|
||||
GLuint textureTrash_u;
|
||||
GLuint textureTrash_v;
|
||||
|
||||
//output frame buffer object (GL -> video)
|
||||
GLuint videoFBO;
|
||||
GLuint videoDepthBuffer;
|
||||
GLuint videoTexture;
|
||||
GLuint videoTexture_u;
|
||||
GLuint videoTexture_v;
|
||||
gint outputWidth;
|
||||
gint outputHeight;
|
||||
GstVideoFormat outputVideo_format;
|
||||
gpointer outputData;
|
||||
GLenum multipleRT[3];
|
||||
|
||||
//from video to texture
|
||||
|
||||
gchar* textFProgram_YUY2_UYVY;
|
||||
GLhandleARB GLSLProgram_YUY2;
|
||||
GLhandleARB GLSLProgram_UYVY;
|
||||
|
||||
gchar* textFProgram_I420_YV12;
|
||||
GLhandleARB GLSLProgram_I420_YV12;
|
||||
|
||||
gchar* textFProgram_AYUV;
|
||||
GLhandleARB GLSLProgram_AYUV;
|
||||
|
||||
//from texture to video
|
||||
|
||||
gchar* textFProgram_to_YUY2_UYVY;
|
||||
GLhandleARB GLSLProgram_to_YUY2;
|
||||
GLhandleARB GLSLProgram_to_UYVY;
|
||||
|
||||
gchar* textFProgram_to_I420_YV12;
|
||||
GLhandleARB GLSLProgram_to_I420_YV12;
|
||||
|
||||
gchar* textFProgram_to_AYUV;
|
||||
GLhandleARB GLSLProgram_to_AYUV;
|
||||
|
||||
//client callbacks
|
||||
CRCB clientReshapeCallback;
|
||||
CDCB clientDrawCallback;
|
||||
};
|
||||
|
||||
|
||||
struct _GstGLDisplayClass {
|
||||
GObjectClass object_class;
|
||||
};
|
||||
|
||||
GType gst_gl_display_get_type (void);
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
//-------------------- Public déclarations ------------------
|
||||
//------------------------------------------------------------
|
||||
GstGLDisplay *gst_gl_display_new (void);
|
||||
void gst_gl_display_initGLContext (GstGLDisplay* display,
|
||||
GLint x, GLint y,
|
||||
GLint graphic_width, GLint graphic_height,
|
||||
GLint video_width, GLint video_height,
|
||||
gulong winId,
|
||||
gboolean visible);
|
||||
void gst_gl_display_setClientReshapeCallback (GstGLDisplay* display, CRCB cb);
|
||||
void gst_gl_display_setClientDrawCallback (GstGLDisplay* display, CDCB cb);
|
||||
void gst_gl_display_setVisibleWindow (GstGLDisplay* display, gboolean visible);
|
||||
void gst_gl_display_textureRequested (GstGLDisplay* display, GstVideoFormat format,
|
||||
gint width, gint height, guint* texture,
|
||||
guint* texture_u, guint* texture_v);
|
||||
void gst_gl_display_textureChanged (GstGLDisplay* display, GstVideoFormat video_format,
|
||||
GLuint texture, GLuint texture_u, GLuint texture_v,
|
||||
gint width, gint height, gpointer data);
|
||||
void gst_gl_display_clearTexture (GstGLDisplay* display, guint texture,
|
||||
guint texture_u, guint texture_v);
|
||||
|
||||
void gst_gl_display_videoChanged (GstGLDisplay* display, GstVideoFormat video_format,
|
||||
gpointer data);
|
||||
void gst_gl_display_postRedisplay (GstGLDisplay* display);
|
||||
void gst_gl_display_set_windowId (GstGLDisplay* display, gulong winId);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue