We are currently experiencing downtime impacting viewing & cloning the Mesa repo, and some GitLab pages returning 503. Please see #freedesktop on IRC for more updates.

Commit 1d88b952 authored by Julien Isorce's avatar Julien Isorce Committed by Tim-Philipp Müller

glimagesink: provide GstSample in client-draw signal

Instead of prividing texture and size directly.
And apply changes to examples.

https://bugzilla.gnome.org/show_bug.cgi?id=739681
parent 0f902835
...@@ -180,12 +180,12 @@ _on_client_reshape (GstGLImageSink * sink, GstGLContext * context, ...@@ -180,12 +180,12 @@ _on_client_reshape (GstGLImageSink * sink, GstGLContext * context,
static gboolean static gboolean
_on_client_draw (GstGLImageSink * sink, GstGLContext * context, _on_client_draw (GstGLImageSink * sink, GstGLContext * context,
guint tex_id, guint width, guint height, gpointer data) GstSample * sample, gpointer data)
{ {
gboolean ret; gboolean ret;
g_signal_emit (data, gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_DRAW], 0, g_signal_emit (data, gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_DRAW], 0,
context, tex_id, width, height, &ret); context, sample, &ret);
return ret; return ret;
} }
...@@ -288,8 +288,7 @@ gst_gl_image_sink_bin_class_init (GstGLImageSinkBinClass * klass) ...@@ -288,8 +288,7 @@ gst_gl_image_sink_bin_class_init (GstGLImageSinkBinClass * klass)
gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_DRAW] = gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_DRAW] =
g_signal_new ("client-draw", G_TYPE_FROM_CLASS (klass), g_signal_new ("client-draw", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
G_TYPE_BOOLEAN, 4, GST_GL_TYPE_CONTEXT, G_TYPE_BOOLEAN, 2, GST_GL_TYPE_CONTEXT, GST_TYPE_SAMPLE);
G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_RESHAPE] = gst_gl_image_sink_bin_signals[SIGNAL_BIN_CLIENT_RESHAPE] =
g_signal_new ("client-reshape", G_TYPE_FROM_CLASS (klass), g_signal_new ("client-reshape", G_TYPE_FROM_CLASS (klass),
...@@ -516,8 +515,7 @@ gst_glimage_sink_class_init (GstGLImageSinkClass * klass) ...@@ -516,8 +515,7 @@ gst_glimage_sink_class_init (GstGLImageSinkClass * klass)
gst_glimage_sink_signals[CLIENT_DRAW_SIGNAL] = gst_glimage_sink_signals[CLIENT_DRAW_SIGNAL] =
g_signal_new ("client-draw", G_TYPE_FROM_CLASS (klass), g_signal_new ("client-draw", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
G_TYPE_BOOLEAN, 4, GST_GL_TYPE_CONTEXT, G_TYPE_BOOLEAN, 2, GST_GL_TYPE_CONTEXT, GST_TYPE_SAMPLE);
G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
/** /**
* GstGLImageSink::client-reshape: * GstGLImageSink::client-reshape:
...@@ -1472,8 +1470,9 @@ gst_glimage_sink_on_draw (GstGLImageSink * gl_sink) ...@@ -1472,8 +1470,9 @@ gst_glimage_sink_on_draw (GstGLImageSink * gl_sink)
const GstGLFuncs *gl = NULL; const GstGLFuncs *gl = NULL;
GstGLWindow *window = NULL; GstGLWindow *window = NULL;
gboolean do_redisplay; gboolean do_redisplay = FALSE;
GstGLSyncMeta *sync_meta; GstGLSyncMeta *sync_meta = NULL;
GstSample *sample = NULL;
g_return_if_fail (GST_IS_GLIMAGE_SINK (gl_sink)); g_return_if_fail (GST_IS_GLIMAGE_SINK (gl_sink));
...@@ -1516,10 +1515,14 @@ gst_glimage_sink_on_draw (GstGLImageSink * gl_sink) ...@@ -1516,10 +1515,14 @@ gst_glimage_sink_on_draw (GstGLImageSink * gl_sink)
gl->BindTexture (GL_TEXTURE_2D, 0); gl->BindTexture (GL_TEXTURE_2D, 0);
sample = gst_sample_new (gl_sink->stored_buffer,
gst_video_info_to_caps (&gl_sink->info),
&GST_BASE_SINK (gl_sink)->segment, NULL);
g_signal_emit (gl_sink, gst_glimage_sink_signals[CLIENT_DRAW_SIGNAL], 0, g_signal_emit (gl_sink, gst_glimage_sink_signals[CLIENT_DRAW_SIGNAL], 0,
gl_sink->context, gl_sink->context, sample, &do_redisplay);
gl_sink->redisplay_texture, GST_VIDEO_INFO_WIDTH (&gl_sink->info),
GST_VIDEO_INFO_HEIGHT (&gl_sink->info), &do_redisplay); gst_sample_unref (sample);
if (!do_redisplay) { if (!do_redisplay) {
gfloat alpha = gl_sink->ignore_alpha ? 1.0f : 0.0f; gfloat alpha = gl_sink->ignore_alpha ? 1.0f : 0.0f;
......
...@@ -5,5 +5,5 @@ cube_SOURCES = main.cpp ...@@ -5,5 +5,5 @@ cube_SOURCES = main.cpp
cube_CXXFLAGS=-I$(top_srcdir)/gst-libs -I$(top_builddir)/gst-libs \ cube_CXXFLAGS=-I$(top_srcdir)/gst-libs -I$(top_builddir)/gst-libs \
$(GST_CXXFLAGS) $(GL_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CXXFLAGS) $(GL_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
cube_LDADD=$(GST_LIBS) $(GL_LIBS) cube_LDADD=$(GST_LIBS) -lgstvideo-$(GST_API_VERSION) $(GL_LIBS)
...@@ -18,11 +18,8 @@ ...@@ -18,11 +18,8 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include <GL/gl.h>
#if __WIN32__ || _WIN32
# include <GL/glext.h>
#endif
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/gl/gl.h>
#include <iostream> #include <iostream>
#include <string> #include <string>
...@@ -75,7 +72,7 @@ static gboolean reshapeCallback (void *gl_sink, void *context, GLuint width, GLu ...@@ -75,7 +72,7 @@ static gboolean reshapeCallback (void *gl_sink, void *context, GLuint width, GLu
} }
//client draw callback //client draw callback
static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLuint width, GLuint height, gpointer data) static gboolean drawCallback (GstElement * gl_sink, GstGLContext *context, GstSample * sample, gpointer data)
{ {
static GLfloat xrot = 0; static GLfloat xrot = 0;
static GLfloat yrot = 0; static GLfloat yrot = 0;
...@@ -84,6 +81,21 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu ...@@ -84,6 +81,21 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu
static glong last_sec = current_time.tv_sec; static glong last_sec = current_time.tv_sec;
static gint nbFrames = 0; static gint nbFrames = 0;
GstVideoFrame v_frame;
GstVideoInfo v_info;
guint texture = 0;
GstBuffer *buf = gst_sample_get_buffer (sample);
GstCaps *caps = gst_sample_get_caps (sample);
gst_video_info_from_caps (&v_info, caps);
if (!gst_video_frame_map (&v_frame, &v_info, buf, (GstMapFlags) (GST_MAP_READ | GST_MAP_GL))) {
g_warning ("Failed to map the video buffer");
return TRUE;
}
texture = *(guint *) v_frame.data[0];
g_get_current_time (&current_time); g_get_current_time (&current_time);
nbFrames++ ; nbFrames++ ;
...@@ -147,11 +159,12 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu ...@@ -147,11 +159,12 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd(); glEnd();
gst_video_frame_unmap (&v_frame);
xrot+=0.3f; xrot+=0.3f;
yrot+=0.2f; yrot+=0.2f;
zrot+=0.4f; zrot+=0.4f;
//return TRUE causes a postRedisplay
return TRUE; return TRUE;
} }
......
...@@ -5,5 +5,5 @@ cubeyuv_SOURCES = main.cpp ...@@ -5,5 +5,5 @@ cubeyuv_SOURCES = main.cpp
cubeyuv_CXXFLAGS=-I$(top_srcdir)/gst-libs -I$(top_builddir)/gst-libs \ cubeyuv_CXXFLAGS=-I$(top_srcdir)/gst-libs -I$(top_builddir)/gst-libs \
$(GST_CXXFLAGS) $(GL_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CXXFLAGS) $(GL_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
cubeyuv_LDADD=$(GST_LIBS) $(GL_LIBS) cubeyuv_LDADD=$(GST_LIBS) $(GL_LIBS) -lgstvideo-$(GST_API_VERSION)
...@@ -18,11 +18,8 @@ ...@@ -18,11 +18,8 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include <GL/gl.h>
#if __WIN32__ || _WIN32
# include <GL/glext.h>
#endif
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/gl/gl.h>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
...@@ -98,7 +95,7 @@ static gboolean reshapeCallback (void * gl_sink, void *context, GLuint width, GL ...@@ -98,7 +95,7 @@ static gboolean reshapeCallback (void * gl_sink, void *context, GLuint width, GL
//client draw callback //client draw callback
static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLuint width, GLuint height, gpointer data) static gboolean drawCallback (GstElement * gl_sink, GstGLContext *context, GstSample * sample, gpointer data)
{ {
static GLfloat xrot = 0; static GLfloat xrot = 0;
static GLfloat yrot = 0; static GLfloat yrot = 0;
...@@ -107,6 +104,21 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu ...@@ -107,6 +104,21 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu
static glong last_sec = current_time.tv_sec; static glong last_sec = current_time.tv_sec;
static gint nbFrames = 0; static gint nbFrames = 0;
GstVideoFrame v_frame;
GstVideoInfo v_info;
guint texture = 0;
GstBuffer *buf = gst_sample_get_buffer (sample);
GstCaps *caps = gst_sample_get_caps (sample);
gst_video_info_from_caps (&v_info, caps);
if (!gst_video_frame_map (&v_frame, &v_info, buf, (GstMapFlags) (GST_MAP_READ | GST_MAP_GL))) {
g_warning ("Failed to map the video buffer");
return TRUE;
}
texture = *(guint *) v_frame.data[0];
g_get_current_time (&current_time); g_get_current_time (&current_time);
nbFrames++ ; nbFrames++ ;
...@@ -170,20 +182,12 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu ...@@ -170,20 +182,12 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd(); glEnd();
gst_video_frame_unmap (&v_frame);
xrot+=0.03f; xrot+=0.03f;
yrot+=0.02f; yrot+=0.02f;
zrot+=0.04f; zrot+=0.04f;
//return TRUE causes a postRedisplay
//so you have to return FALSE to synchronise to have a graphic FPS
//equals to the input video frame rate
//Usually, we will not always return TRUE (or FALSE)
//For example, if you want a fixed graphic FPS equals to 60
//then you have to use the timeclock to return TRUE or FALSE
//in order to increase or decrease the FPS in real time
//to reach the 60.
return TRUE; return TRUE;
} }
......
...@@ -5,5 +5,5 @@ doublecube_SOURCES = main.cpp ...@@ -5,5 +5,5 @@ doublecube_SOURCES = main.cpp
doublecube_CXXFLAGS=-I$(top_srcdir)/gst-libs -I$(top_builddir)/gst-libs \ doublecube_CXXFLAGS=-I$(top_srcdir)/gst-libs -I$(top_builddir)/gst-libs \
$(GST_CXXFLAGS) $(GL_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CXXFLAGS) $(GL_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
doublecube_LDADD=$(GST_LIBS) $(GL_LIBS) doublecube_LDADD=$(GST_LIBS) $(GL_LIBS) -lgstvideo-$(GST_API_VERSION)
...@@ -18,11 +18,8 @@ ...@@ -18,11 +18,8 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include <GL/gl.h>
#if __WIN32__ || _WIN32
# include <GL/glext.h>
#endif
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/gl/gl.h>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
...@@ -100,7 +97,7 @@ static gboolean reshapeCallback (void *gl_sink, void *context, GLuint width, GLu ...@@ -100,7 +97,7 @@ static gboolean reshapeCallback (void *gl_sink, void *context, GLuint width, GLu
//client draw callback //client draw callback
static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLuint width, GLuint height) static gboolean drawCallback (GstElement * gl_sink, GstGLContext *context, GstSample * sample, gpointer data)
{ {
static GLfloat xrot = 0; static GLfloat xrot = 0;
static GLfloat yrot = 0; static GLfloat yrot = 0;
...@@ -109,6 +106,21 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu ...@@ -109,6 +106,21 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu
static glong last_sec = current_time.tv_sec; static glong last_sec = current_time.tv_sec;
static gint nbFrames = 0; static gint nbFrames = 0;
GstVideoFrame v_frame;
GstVideoInfo v_info;
guint texture = 0;
GstBuffer *buf = gst_sample_get_buffer (sample);
GstCaps *caps = gst_sample_get_caps (sample);
gst_video_info_from_caps (&v_info, caps);
if (!gst_video_frame_map (&v_frame, &v_info, buf, (GstMapFlags) (GST_MAP_READ | GST_MAP_GL))) {
g_warning ("Failed to map the video buffer");
return TRUE;
}
texture = *(guint *) v_frame.data[0];
g_get_current_time (&current_time); g_get_current_time (&current_time);
nbFrames++ ; nbFrames++ ;
...@@ -172,20 +184,12 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu ...@@ -172,20 +184,12 @@ static gboolean drawCallback (void * gl_sink, void *context, GLuint texture, GLu
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd(); glEnd();
gst_video_frame_unmap (&v_frame);
xrot+=0.03f; xrot+=0.03f;
yrot+=0.02f; yrot+=0.02f;
zrot+=0.04f; zrot+=0.04f;
//return TRUE causes a postRedisplay
//so you have to return FALSE to synchronise to have a graphic FPS
//equals to the input video frame rate
//Usually, we will not always return TRUE (or FALSE)
//For example, if you want a fixed graphic FPS equals to 60
//then you have to use the timeclock to return TRUE or FALSE
//in order to increase or decrease the FPS in real time
//to reach the 60.
return TRUE; return TRUE;
} }
......
...@@ -170,12 +170,27 @@ gboolean Pipeline::reshapeCallback (void *sink, void *context, guint width, guin ...@@ -170,12 +170,27 @@ gboolean Pipeline::reshapeCallback (void *sink, void *context, guint width, guin
} }
//client draw callback //client draw callback
gboolean Pipeline::drawCallback (void *sink, void *context, uint texture, uint width, uint height, gpointer data) gboolean Pipeline::drawCallback (GstElement * gl_sink, GstGLContext *context, GstSample * sample, gpointer data)
{ {
static GTimeVal current_time; static GTimeVal current_time;
static glong last_sec = current_time.tv_sec; static glong last_sec = current_time.tv_sec;
static gint nbFrames = 0; static gint nbFrames = 0;
GstVideoFrame v_frame;
GstVideoInfo v_info;
guint texture = 0;
GstBuffer *buf = gst_sample_get_buffer (sample);
GstCaps *caps = gst_sample_get_caps (sample);
gst_video_info_from_caps (&v_info, caps);
if (!gst_video_frame_map (&v_frame, &v_info, buf, (GstMapFlags) (GST_MAP_READ | GST_MAP_GL))) {
g_warning ("Failed to map the video buffer");
return TRUE;
}
texture = *(guint *) v_frame.data[0];
g_get_current_time (&current_time); g_get_current_time (&current_time);
nbFrames++ ; nbFrames++ ;
...@@ -239,7 +254,8 @@ gboolean Pipeline::drawCallback (void *sink, void *context, uint texture, uint w ...@@ -239,7 +254,8 @@ gboolean Pipeline::drawCallback (void *sink, void *context, uint texture, uint w
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd(); glEnd();
//return TRUE causes a postRedisplay gst_video_frame_unmap (&v_frame);
return TRUE; return TRUE;
} }
......
...@@ -167,7 +167,7 @@ gboolean Pipeline::reshapeCallback (void *sink, void *context, guint width, guin ...@@ -167,7 +167,7 @@ gboolean Pipeline::reshapeCallback (void *sink, void *context, guint width, guin
} }
//client draw callback //client draw callback
gboolean Pipeline::drawCallback (void *sink, void *context, guint texture, guint width, guint height, gpointer data) gboolean Pipeline::drawCallback (GstElement * gl_sink, GstGLContext *context, GstSample * sample, gpointer data)
{ {
static GLfloat xrot = 0; static GLfloat xrot = 0;
static GLfloat yrot = 0; static GLfloat yrot = 0;
...@@ -176,6 +176,21 @@ gboolean Pipeline::drawCallback (void *sink, void *context, guint texture, guint ...@@ -176,6 +176,21 @@ gboolean Pipeline::drawCallback (void *sink, void *context, guint texture, guint
static glong last_sec = current_time.tv_sec; static glong last_sec = current_time.tv_sec;
static gint nbFrames = 0; static gint nbFrames = 0;
GstVideoFrame v_frame;
GstVideoInfo v_info;
guint texture = 0;
GstBuffer *buf = gst_sample_get_buffer (sample);
GstCaps *caps = gst_sample_get_caps (sample);
gst_video_info_from_caps (&v_info, caps);
if (!gst_video_frame_map (&v_frame, &v_info, buf, (GstMapFlags) (GST_MAP_READ | GST_MAP_GL))) {
g_warning ("Failed to map the video buffer");
return TRUE;
}
texture = *(guint *) v_frame.data[0];
g_get_current_time (&current_time); g_get_current_time (&current_time);
nbFrames++ ; nbFrames++ ;
...@@ -239,11 +254,12 @@ gboolean Pipeline::drawCallback (void *sink, void *context, guint texture, guint ...@@ -239,11 +254,12 @@ gboolean Pipeline::drawCallback (void *sink, void *context, guint texture, guint
glTexCoord2f(1.0, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(1.0, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd(); glEnd();
gst_video_frame_unmap (&v_frame);
xrot+=0.03f; xrot+=0.03f;
yrot+=0.02f; yrot+=0.02f;
zrot+=0.04f; zrot+=0.04f;
//return TRUE causes a postRedisplay
return TRUE; return TRUE;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment