}
//client draw callback
-
static gboolean drawCallback (GLuint texture, GLuint width, GLuint height, gpointer data)
{
static GLfloat xrot = 0;
gst_object_unref (pipeline);
return 0;
-
}
{
GMainLoop *loop = (GMainLoop*)data;
- switch (GST_MESSAGE_TYPE (msg))
+ switch (GST_MESSAGE_TYPE (msg))
{
case GST_MESSAGE_EOS:
g_print ("End-of-stream\n");
g_main_loop_quit (loop);
break;
- case GST_MESSAGE_ERROR:
+ case GST_MESSAGE_ERROR:
{
gchar *debug = NULL;
GError *err = NULL;
g_print ("Error: %s\n", err->message);
g_error_free (err);
- if (debug)
+ if (debug)
{
g_print ("Debug deails: %s\n", debug);
g_free (debug);
g_main_loop_quit (loop);
break;
- }
+ }
default:
break;
}
static GstClockTime last_timestamp = 0;
static gint nbFrames = 0 ;
- //display estimated video FPS
+ //display estimated video FPS
nbFrames++ ;
if (GST_BUFFER_TIMESTAMP(buffer) - last_timestamp >= 1000000000)
{
std::string s(oss.str()) ;
g_object_set(G_OBJECT(textoverlay), "text", s.c_str(), NULL);
last_timestamp = GST_BUFFER_TIMESTAMP(buffer) ;
- nbFrames = 0 ;
+ nbFrames = 0 ;
}
}
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- gluPerspective(45, (gfloat)width/(gfloat)height, 0.1, 100);
- glMatrixMode(GL_MODELVIEW);
+ gluPerspective(45, (gfloat)width/(gfloat)height, 0.1, 100);
+ glMatrixMode(GL_MODELVIEW);
}
//client draw callback
static gboolean drawCallback (GLuint texture, GLuint width, GLuint height)
{
-
static GLfloat xrot = 0;
- static GLfloat yrot = 0;
+ static GLfloat yrot = 0;
static GLfloat zrot = 0;
static GTimeVal current_time;
static glong last_sec = current_time.tv_sec;
- static gint nbFrames = 0;
+ static gint nbFrames = 0;
g_get_current_time (¤t_time);
nbFrames++ ;
-
+
if ((current_time.tv_sec - last_sec) >= 1)
{
std::cout << "GRPHIC FPS = " << nbFrames << std::endl;
nbFrames = 0;
last_sec = current_time.tv_sec;
}
-
+
glEnable(GL_DEPTH_TEST);
glEnable (GL_TEXTURE_2D);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
-
+
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(xrot,1.0f,0.0f,0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(0.0f, (gfloat)height); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f((gfloat)width, (gfloat)height); glVertex3f(-1.0f, 1.0f, -1.0f);
- glEnd();
+ glEnd();
xrot+=0.03f;
yrot+=0.02f;
static void cb_new_pad (GstElement* decodebin, GstPad* pad, GstElement* identity)
{
GstPad* identity_pad = gst_element_get_static_pad (identity, "sink");
-
- //only link once
- if (GST_PAD_IS_LINKED (identity_pad))
+
+ //only link once
+ if (GST_PAD_IS_LINKED (identity_pad))
{
gst_object_unref (identity_pad);
return;
GstCaps* caps = gst_pad_get_current_caps (pad);
GstStructure* str = gst_caps_get_structure (caps, 0);
- if (!g_strrstr (gst_structure_get_name (str), "video"))
+ if (!g_strrstr (gst_structure_get_name (str), "video"))
{
gst_caps_unref (caps);
gst_object_unref (identity_pad);
gst_caps_unref (caps);
GstPadLinkReturn ret = gst_pad_link (pad, identity_pad);
- if (ret != GST_PAD_LINK_OK)
- g_warning ("Failed to link with decodebin!\n");
+ if (ret != GST_PAD_LINK_OK)
+ g_warning ("Failed to link with decodebin!\n");
}
g_warning ("usage: cubeyuv.exe videolocation\n");
return -1;
}
-
+
std::string video_location(argv[1]);
-
+
/* initialization */
gst_init (&argc, &argv);
GMainLoop* loop = g_main_loop_new (NULL, FALSE);
g_object_set(G_OBJECT(textoverlay), "font_desc", "Ahafoni CLM Bold 30", NULL);
g_object_set(G_OBJECT(glimagesink), "client-reshape-callback", reshapeCallback, NULL);
g_object_set(G_OBJECT(glimagesink), "client-draw-callback", drawCallback, NULL);
-
+
/* add elements */
gst_bin_add_many (GST_BIN (pipeline), videosrc, decodebin, identity,
textoverlay, glcolorscale, glimagesink, NULL);
g_signal_connect (decodebin, "pad-added", G_CALLBACK (cb_new_pad), identity);
- if (!gst_element_link_pads(identity, "src", textoverlay, "video_sink"))
+ if (!gst_element_link_pads(identity, "src", textoverlay, "video_sink"))
{
g_print ("Failed to link identity to textoverlay!\n");
return -1;
g_warning("Failed to link textoverlay to glimagesink!\n") ;
return -1 ;
}
-
+
/* run */
GstStateChangeReturn ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE)
+ if (ret == GST_STATE_CHANGE_FAILURE)
{
g_print ("Failed to start up pipeline!\n");
/* check if there is an error message with details on the bus */
GstMessage* msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
- if (msg)
+ if (msg)
{
GError *err = NULL;
gst_object_unref (pipeline);
return 0;
-
}
-
{
GMainLoop *loop = (GMainLoop*)data;
- switch (GST_MESSAGE_TYPE (msg))
+ switch (GST_MESSAGE_TYPE (msg))
{
case GST_MESSAGE_EOS:
g_print ("End-of-stream\n");
g_main_loop_quit (loop);
break;
- case GST_MESSAGE_ERROR:
+ case GST_MESSAGE_ERROR:
{
gchar *debug = NULL;
GError *err = NULL;
g_print ("Error: %s\n", err->message);
g_error_free (err);
- if (debug)
+ if (debug)
{
g_print ("Debug details: %s\n", debug);
g_free (debug);
g_main_loop_quit (loop);
break;
- }
+ }
default:
break;
}
static GstClockTime last_timestamp = 0;
static gint nbFrames = 0 ;
- //display estimated video FPS
+ //display estimated video FPS
nbFrames++ ;
if (GST_BUFFER_TIMESTAMP(info->data) - last_timestamp >= 1000000000)
{
- std::ostringstream oss ;
+ std::ostringstream oss;
oss << "video framerate = " << nbFrames ;
- std::string s(oss.str()) ;
+ std::string s(oss.str());
g_object_set(G_OBJECT(textoverlay), "text", s.c_str(), NULL);
last_timestamp = GST_BUFFER_TIMESTAMP(info->data) ;
- nbFrames = 0 ;
+ nbFrames = 0;
}
return GST_PAD_PROBE_OK;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- gluPerspective(45, (gfloat)width/(gfloat)height, 0.1, 100);
- glMatrixMode(GL_MODELVIEW);
+ gluPerspective(45, (gfloat)width/(gfloat)height, 0.1, 100);
+ glMatrixMode(GL_MODELVIEW);
}
static gboolean drawCallback (GLuint texture, GLuint width, GLuint height)
{
static GLfloat xrot = 0;
- static GLfloat yrot = 0;
+ static GLfloat yrot = 0;
static GLfloat zrot = 0;
static GTimeVal current_time;
static glong last_sec = current_time.tv_sec;
- static gint nbFrames = 0;
+ static gint nbFrames = 0;
g_get_current_time (¤t_time);
nbFrames++ ;
-
+
if ((current_time.tv_sec - last_sec) >= 1)
{
std::cout << "GRAPHIC FPS of the scene which contains the custom cube) = " << nbFrames << std::endl;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
-
+
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(xrot,1.0f,0.0f,0.0f);
static void cb_new_pad (GstElement* decodebin, GstPad* pad, GstElement* element)
{
GstPad* element_pad = gst_element_get_static_pad (element, "sink");
-
- //only link once
- if (!element_pad || GST_PAD_IS_LINKED (element_pad))
+
+ //only link once
+ if (!element_pad || GST_PAD_IS_LINKED (element_pad))
{
gst_object_unref (element_pad);
return;
GstCaps* caps = gst_pad_get_current_caps (pad);
GstStructure* str = gst_caps_get_structure (caps, 0);
-
+
GstCaps* caps2 = gst_pad_query_caps (element_pad, NULL);
gst_caps_unref (caps2);
-
- if (!g_strrstr (gst_structure_get_name (str), "video"))
+
+ if (!g_strrstr (gst_structure_get_name (str), "video"))
{
gst_caps_unref (caps);
gst_object_unref (element_pad);
gst_caps_unref (caps);
GstPadLinkReturn ret = gst_pad_link (pad, element_pad);
- if (ret != GST_PAD_LINK_OK)
+ if (ret != GST_PAD_LINK_OK)
g_warning ("Failed to link with decodebin %d!\n", ret);
gst_object_unref (element_pad);
}
gint main (gint argc, gchar *argv[])
{
-
if (argc != 2)
{
g_warning ("usage: doublecube.exe videolocation\n");
return -1;
}
-
+
std::string video_location(argv[1]);
/* initialization */
if (!videosrc || !decodebin || !videoconvert || !textoverlay || !tee ||
!queue0 || !glimagesink0 ||
!queue1 || !glfiltercube || !glimagesink1 ||
- !queue2 || !glimagesink2)
+ !queue2 || !glimagesink2)
{
g_warning ("one element could not be found \n");
return -1;
g_object_set(G_OBJECT(textoverlay), "font_desc", "Ahafoni CLM Bold 30", NULL);
g_object_set(G_OBJECT(glimagesink0), "client-reshape-callback", reshapeCallback, NULL);
g_object_set(G_OBJECT(glimagesink0), "client-draw-callback", drawCallback, NULL);
-
+
/* add elements */
gst_bin_add_many (GST_BIN (pipeline), videosrc, decodebin, videoconvert, textoverlay, tee,
queue0, glimagesink0,
- queue1, glfiltercube, glimagesink1,
+ queue1, glfiltercube, glimagesink1,
queue2, glimagesink2, NULL);
-
+
GstPad* textoverlay_sink_pad = gst_element_get_static_pad (textoverlay, "video_sink");
- gst_pad_add_probe (textoverlay_sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
+ gst_pad_add_probe (textoverlay_sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
(GstPadProbeCallback) textoverlay_sink_pad_probe_cb, (gpointer)textoverlay, NULL);
gst_object_unref (textoverlay_sink_pad);
- if (!gst_element_link_many(videoconvert, textoverlay, tee, NULL))
+ if (!gst_element_link_many(videoconvert, textoverlay, tee, NULL))
{
g_print ("Failed to link videoconvert to tee!\n");
return -1;
}
- if (!gst_element_link(videosrc, decodebin))
+ if (!gst_element_link(videosrc, decodebin))
{
g_print ("Failed to link videosrc to decodebin!\n");
return -1;
}
g_signal_connect (decodebin, "pad-added", G_CALLBACK (cb_new_pad), videoconvert);
-
- if (!gst_element_link_many(tee, queue0, NULL))
+
+ if (!gst_element_link_many(tee, queue0, NULL))
{
g_warning ("Failed to link one or more elements bettween tee and queue0!\n");
return -1;
return -1 ;
}
- if (!gst_element_link_many(tee, queue1, glfiltercube, glimagesink1, NULL))
+ if (!gst_element_link_many(tee, queue1, glfiltercube, glimagesink1, NULL))
{
g_warning ("Failed to link one or more elements bettween tee and glimagesink1!\n");
return -1;
}
- if (!gst_element_link_many(tee, queue2, glimagesink2, NULL))
+ if (!gst_element_link_many(tee, queue2, glimagesink2, NULL))
{
g_warning ("Failed to link one or more elements bettween tee and glimagesink2!\n");
return -1;
}
-
+
/* run */
GstStateChangeReturn ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE)
+ if (ret == GST_STATE_CHANGE_FAILURE)
{
g_print ("Failed to start up pipeline!\n");
/* check if there is an error message with details on the bus */
GstMessage* msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
- if (msg)
+ if (msg)
{
GError *err = NULL;
gst_object_unref (pipeline);
return 0;
-
}
-
{
GMainLoop *loop = (GMainLoop*)data;
- switch (GST_MESSAGE_TYPE (msg))
+ switch (GST_MESSAGE_TYPE (msg))
{
case GST_MESSAGE_EOS:
g_print ("End-of-stream\n");
g_main_loop_quit (loop);
break;
- case GST_MESSAGE_ERROR:
+ case GST_MESSAGE_ERROR:
{
gchar *debug = NULL;
GError *err = NULL;
g_print ("Error: %s\n", err->message);
g_error_free (err);
- if (debug)
+ if (debug)
{
g_print ("Debug details: %s\n", debug);
g_free (debug);
g_main_loop_quit (loop);
break;
- }
+ }
default:
break;
}
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- gluPerspective(45, (gfloat)width/(gfloat)height, 0.1, 100);
- glMatrixMode(GL_MODELVIEW);
+ gluPerspective(45, (gfloat)width/(gfloat)height, 0.1, 100);
+ glMatrixMode(GL_MODELVIEW);
}
static gboolean drawCallback (GLuint width, GLuint height, GLuint texture, gpointer data)
{
static GLfloat xrot = 0;
- static GLfloat yrot = 0;
+ static GLfloat yrot = 0;
static GLfloat zrot = 0;
static GTimeVal current_time;
static glong last_sec = current_time.tv_sec;
- static gint nbFrames = 0;
+ static gint nbFrames = 0;
g_get_current_time (¤t_time);
nbFrames++ ;
-
+
if ((current_time.tv_sec - last_sec) >= 1)
{
std::cout << "GRPHIC FPS = " << nbFrames << std::endl;
nbFrames = 0;
last_sec = current_time.tv_sec;
}
-
+
glEnable(GL_DEPTH_TEST);
glEnable (GL_TEXTURE_2D);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
-
+
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(xrot,1.0f,0.0f,0.0f);
}
-//equivalent command line:
-//gst-launch-1.0 videotestsrc num_buffers=400 ! gleffects effect=0 !
+//equivalent command line:
+//gst-launch-1.0 videotestsrc num_buffers=400 ! gleffects effect=0 !
//avenc_mpeg4 ! avimux ! filesink location="record.avi"
// or
//gst-launch-1.0 videotestsrc num_buffers=400 ! gleffects effect=0 ! "video/x-raw, width=320, height=240" ! glfiltercube ! "video/x-raw, width=720, height=576" !
filesink = gst_element_factory_make ("filesink", "filesink0");
- if (!videosrc || !glfilterapp || !avenc_mpeg4 || !avimux || !filesink)
+ if (!videosrc || !glfilterapp || !avenc_mpeg4 || !avimux || !filesink)
{
g_print ("one element could not be found \n");
return -1;
g_object_set(G_OBJECT(glfilterapp), "client-draw-callback", drawCallback, NULL);
g_object_set(G_OBJECT(glfilterapp), "client-data", NULL, NULL);
g_object_set(G_OBJECT(filesink), "location", "record.avi", NULL);
-
+
/* add elements */
- gst_bin_add_many (GST_BIN (pipeline), videosrc, glfilterapp,
+ gst_bin_add_many (GST_BIN (pipeline), videosrc, glfilterapp,
avenc_mpeg4, avimux, filesink, NULL);
-
+
/* link elements */
gboolean link_ok = gst_element_link_filtered(videosrc, glfilterapp, caps) ;
gst_caps_unref(caps) ;
g_warning("Failed to link glfilterapp to avenc_mpeg4!\n") ;
return -1 ;
}
- if (!gst_element_link_many(avenc_mpeg4, avimux, filesink, NULL))
+ if (!gst_element_link_many(avenc_mpeg4, avimux, filesink, NULL))
{
g_print ("Failed to link one or more elements!\n");
return -1;
}
-
+
/* run */
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE)
+ if (ret == GST_STATE_CHANGE_FAILURE)
{
g_print ("Failed to start up pipeline!\n");
/* check if there is an error message with details on the bus */
GstMessage* msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
- if (msg)
+ if (msg)
{
GError *err = NULL;
gst_object_unref (pipeline);
return 0;
-
}