mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-27 15:34:49 +00:00
[372/906] make sdlshare example work on linux. Fix bug #593486
This commit is contained in:
parent
008b400f4c
commit
785e001a1a
1 changed files with 114 additions and 92 deletions
|
@ -23,16 +23,17 @@
|
|||
#ifdef WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#include <OpenGL/gl.h> // Header File For The OpenGL32 Library
|
||||
#include <OpenGL/glu.h> // Header File For The GLu32 Library
|
||||
#else
|
||||
#include <GL/gl.h> // Header File For The OpenGL32 Library
|
||||
#include <GL/glu.h> // Header File For The GLu32 Library
|
||||
#endif
|
||||
#include "SDL.h"
|
||||
#include "SDL_opengl.h"
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
#include <GL/glx.h>
|
||||
#include "SDL/SDL.h"
|
||||
#include "SDL/SDL_opengl.h"
|
||||
#include "SDL/SDL_syswm.h"
|
||||
#endif
|
||||
#include <GL/gl.h> // Header File For The OpenGL32 Library
|
||||
#include <GL/glu.h> // Header File For The GLu32 Library
|
||||
|
||||
/* hack */
|
||||
typedef struct _GstGLBuffer GstGLBuffer;
|
||||
|
@ -54,7 +55,8 @@ float rtri = 0.0f;
|
|||
float rquad = 0.0f;
|
||||
|
||||
/* A general OpenGL initialization function. Sets all of the initial parameters. */
|
||||
void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
|
||||
void
|
||||
InitGL (int Width, int Height) // We call this right after our OpenGL window is created.
|
||||
{
|
||||
glViewport (0, 0, Width, Height);
|
||||
glClearColor (0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
|
||||
|
@ -72,7 +74,8 @@ void InitGL(int Width, int Height) // We call this right after our OpenG
|
|||
}
|
||||
|
||||
/* The main drawing function. */
|
||||
void DrawGLScene(GstGLBuffer *gst_gl_buf)
|
||||
void
|
||||
DrawGLScene (GstGLBuffer * gst_gl_buf)
|
||||
{
|
||||
GLuint texture = gst_gl_buf->texture;
|
||||
GLfloat width = (GLfloat) gst_gl_buf->width;
|
||||
|
@ -98,8 +101,10 @@ void DrawGLScene(GstGLBuffer *gst_gl_buf)
|
|||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
|
||||
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
|
||||
GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
|
||||
GL_CLAMP_TO_EDGE);
|
||||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
|
||||
glLoadIdentity (); // make sure we're no longer rotated.
|
||||
|
@ -128,12 +133,19 @@ void DrawGLScene(GstGLBuffer *gst_gl_buf)
|
|||
SDL_GL_SwapBuffers ();
|
||||
}
|
||||
|
||||
gboolean update_sdl_scene (GstElement *fakesink)
|
||||
gboolean
|
||||
update_sdl_scene (void *fk)
|
||||
{
|
||||
GMainLoop *loop = g_object_get_data (G_OBJECT (fakesink), "loop");
|
||||
GAsyncQueue *queue_input_buf = g_object_get_data (G_OBJECT (fakesink), "queue_input_buf");
|
||||
GAsyncQueue *queue_output_buf = g_object_get_data (G_OBJECT (fakesink), "queue_output_buf");
|
||||
GstGLBuffer *gst_gl_buf = g_async_queue_pop (queue_input_buf);
|
||||
GstElement *fakesink = (GstElement *) fk;
|
||||
GMainLoop *loop =
|
||||
(GMainLoop *) g_object_get_data (G_OBJECT (fakesink), "loop");
|
||||
GAsyncQueue *queue_input_buf =
|
||||
(GAsyncQueue *) g_object_get_data (G_OBJECT (fakesink),
|
||||
"queue_input_buf");
|
||||
GAsyncQueue *queue_output_buf =
|
||||
(GAsyncQueue *) g_object_get_data (G_OBJECT (fakesink),
|
||||
"queue_output_buf");
|
||||
GstGLBuffer *gst_gl_buf = (GstGLBuffer *) g_async_queue_pop (queue_input_buf);
|
||||
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent (&event)) {
|
||||
|
@ -157,22 +169,27 @@ gboolean update_sdl_scene (GstElement *fakesink)
|
|||
|
||||
/* fakesink handoff callback */
|
||||
void
|
||||
on_gst_buffer (GstElement *fakesink, GstBuffer *buf, GstPad *pad, gpointer data)
|
||||
on_gst_buffer (GstElement * fakesink, GstBuffer * buf, GstPad * pad,
|
||||
gpointer data)
|
||||
{
|
||||
GAsyncQueue *queue_input_buf = NULL;
|
||||
GAsyncQueue *queue_output_buf = NULL;
|
||||
|
||||
/* ref then push buffer to use it in sdl */
|
||||
gst_buffer_ref (buf);
|
||||
queue_input_buf = g_object_get_data (G_OBJECT (fakesink), "queue_input_buf");
|
||||
queue_input_buf =
|
||||
(GAsyncQueue *) g_object_get_data (G_OBJECT (fakesink),
|
||||
"queue_input_buf");
|
||||
g_async_queue_push (queue_input_buf, buf);
|
||||
if (g_async_queue_length (queue_input_buf) > 3)
|
||||
g_idle_add (update_sdl_scene, fakesink);
|
||||
g_idle_add (update_sdl_scene, (gpointer) fakesink);
|
||||
|
||||
/* pop then unref buffer we have finished to use in sdl */
|
||||
queue_output_buf = g_object_get_data (G_OBJECT (fakesink), "queue_output_buf");
|
||||
queue_output_buf =
|
||||
(GAsyncQueue *) g_object_get_data (G_OBJECT (fakesink),
|
||||
"queue_output_buf");
|
||||
if (g_async_queue_length (queue_output_buf) > 3) {
|
||||
GstBuffer *buf_old = g_async_queue_pop (queue_output_buf);
|
||||
GstBuffer *buf_old = (GstBuffer *) g_async_queue_pop (queue_output_buf);
|
||||
gst_buffer_unref (buf_old);
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +202,8 @@ end_stream_cb (GstBus *bus, GstMessage *msg, GMainLoop *loop)
|
|||
|
||||
case GST_MESSAGE_EOS:
|
||||
g_print ("End-of-stream\n");
|
||||
g_print ("For more information, try to run: GST_DEBUG=gldisplay:2 ./sdlshare\n");
|
||||
g_print
|
||||
("For more information, try to run: GST_DEBUG=gldisplay:2 ./sdlshare\n");
|
||||
break;
|
||||
|
||||
case GST_MESSAGE_ERROR:
|
||||
|
@ -213,7 +231,8 @@ end_stream_cb (GstBus *bus, GstMessage *msg, GMainLoop *loop)
|
|||
g_main_loop_quit (loop);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -231,7 +250,7 @@ int main(int argc, char **argv)
|
|||
GstBus *bus = NULL;
|
||||
GstElement *glupload = NULL;
|
||||
GstElement *fakesink = NULL;
|
||||
GstState state = 0;
|
||||
GstState state;
|
||||
GAsyncQueue *queue_input_buf = NULL;
|
||||
GAsyncQueue *queue_output_buf = NULL;
|
||||
|
||||
|
@ -251,6 +270,7 @@ int main(int argc, char **argv)
|
|||
/* Set the title bar in environments that support it */
|
||||
SDL_WM_SetCaption ("SDL and gst-plugins-gl", NULL);
|
||||
|
||||
|
||||
/* Loop, drawing and checking events */
|
||||
InitGL (640, 480);
|
||||
|
||||
|
@ -263,17 +283,18 @@ int main(int argc, char **argv)
|
|||
sdl_dc = wglGetCurrentDC ();
|
||||
wglMakeCurrent (0, 0);
|
||||
#else
|
||||
SDL_VERSION (&info.version);
|
||||
SDL_GetWMInfo (&info);
|
||||
sdl_display = info.info.x11.display;
|
||||
sdl_win = info.info.x11.wmwindow;
|
||||
sdl_win = info.info.x11.window;
|
||||
sdl_gl_context = glXGetCurrentContext ();
|
||||
glXMakeCurrent (clutter_display, None, 0);
|
||||
glXMakeCurrent (sdl_display, None, 0);
|
||||
#endif
|
||||
|
||||
pipeline =
|
||||
GST_PIPELINE (gst_parse_launch
|
||||
("videotestsrc ! video/x-raw-yuv, width=320, height=240, framerate=(fraction)30/1 ! "
|
||||
"glupload ! gleffects effect=5 ! fakesink sync=1",
|
||||
NULL));
|
||||
"glupload ! gleffects effect=5 ! fakesink sync=1", NULL));
|
||||
|
||||
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
|
||||
gst_bus_add_signal_watch (bus);
|
||||
|
@ -284,7 +305,8 @@ int main(int argc, char **argv)
|
|||
|
||||
/* sdl_gl_context is an external OpenGL context with which gst-plugins-gl want to share textures */
|
||||
glupload = gst_bin_get_by_name (GST_BIN (pipeline), "glupload0");
|
||||
g_object_set (G_OBJECT (glupload), "external-opengl-context", sdl_gl_context, NULL);
|
||||
g_object_set (G_OBJECT (glupload), "external-opengl-context",
|
||||
sdl_gl_context, NULL);
|
||||
g_object_unref (glupload);
|
||||
|
||||
/* NULL to PAUSED state pipeline to make sure the gst opengl context is created and
|
||||
|
@ -301,7 +323,7 @@ int main(int argc, char **argv)
|
|||
#ifdef WIN32
|
||||
wglMakeCurrent (sdl_dc, sdl_gl_context);
|
||||
#else
|
||||
glXMakeCurrent (sdl_display, sdl_win, clutter_gl_context);
|
||||
glXMakeCurrent (sdl_display, sdl_win, sdl_gl_context);
|
||||
#endif
|
||||
|
||||
/* append a gst-gl texture to this queue when you do not need it no more */
|
||||
|
@ -345,12 +367,12 @@ int main(int argc, char **argv)
|
|||
* between sdl and gst-gl
|
||||
*/
|
||||
while (g_async_queue_length (queue_input_buf) > 0) {
|
||||
GstBuffer *buf = g_async_queue_pop (queue_input_buf);
|
||||
GstBuffer *buf = (GstBuffer *) g_async_queue_pop (queue_input_buf);
|
||||
gst_buffer_unref (buf);
|
||||
}
|
||||
|
||||
while (g_async_queue_length (queue_output_buf) > 0) {
|
||||
GstBuffer *buf = g_async_queue_pop (queue_output_buf);
|
||||
GstBuffer *buf = (GstBuffer *) g_async_queue_pop (queue_output_buf);
|
||||
gst_buffer_unref (buf);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue